mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-04-29 03:16:26 -04:00
use abi.decode in token transfer
This commit is contained in:
parent
c00e553299
commit
ae889b5ad2
@ -44,45 +44,25 @@ contract ERC20Mixer is Mixer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _safeErc20TransferFrom(address _from, address _to, uint256 _amount) internal {
|
function _safeErc20TransferFrom(address _from, address _to, uint256 _amount) internal {
|
||||||
bool success;
|
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd /* transferFrom */, _from, _to, _amount));
|
||||||
bytes memory data;
|
|
||||||
bytes4 transferFromSelector = 0x23b872dd;
|
|
||||||
(success, data) = token.call(
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
transferFromSelector,
|
|
||||||
_from, _to, _amount
|
|
||||||
)
|
|
||||||
);
|
|
||||||
require(success, "not enough allowed tokens");
|
require(success, "not enough allowed tokens");
|
||||||
|
|
||||||
// if contract returns some data let's make sure that is `true` according to standard
|
// if contract returns some data let's make sure that is `true` according to standard
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
require(data.length == 32, "data length should be either 0 or 32 bytes");
|
require(data.length == 32, "data length should be either 0 or 32 bytes");
|
||||||
assembly {
|
success = abi.decode(data, (bool));
|
||||||
success := mload(add(data, 0x20))
|
|
||||||
}
|
|
||||||
require(success, "not enough allowed tokens");
|
require(success, "not enough allowed tokens");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _safeErc20Transfer(address _to, uint256 _amount) internal {
|
function _safeErc20Transfer(address _to, uint256 _amount) internal {
|
||||||
bool success;
|
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb /* transfer */, _to, _amount));
|
||||||
bytes memory data;
|
|
||||||
bytes4 transferSelector = 0xa9059cbb;
|
|
||||||
(success, data) = token.call(
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
transferSelector,
|
|
||||||
_to, _amount
|
|
||||||
)
|
|
||||||
);
|
|
||||||
require(success, "not enough tokens");
|
require(success, "not enough tokens");
|
||||||
|
|
||||||
// if contract returns some data let's make sure that is `true` according to standard
|
// if contract returns some data let's make sure that is `true` according to standard
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
require(data.length == 32, "data length should be either 0 or 32 bytes");
|
require(data.length == 32, "data length should be either 0 or 32 bytes");
|
||||||
assembly {
|
success = abi.decode(data, (bool));
|
||||||
success := mload(add(data, 0x20))
|
|
||||||
}
|
|
||||||
require(success, "not enough tokens");
|
require(success, "not enough tokens");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user