aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorRemco Bloemen <Recmo@users.noreply.github.com>2018-06-16 16:10:17 +0800
committerGitHub <noreply@github.com>2018-06-16 16:10:17 +0800
commit0c238448fda99c4d7997901d0fe4d72cb06b79cc (patch)
tree37d0c87eaa8618b2f0ea544098f12fc9db601441 /packages
parentff0960b174ffb8759f9f96e1486372acf54bf840 (diff)
parent2c7d6a7711e44294e64858095971a2aebc6d1829 (diff)
downloaddexon-sol-tools-0c238448fda99c4d7997901d0fe4d72cb06b79cc.tar.gz
dexon-sol-tools-0c238448fda99c4d7997901d0fe4d72cb06b79cc.tar.zst
dexon-sol-tools-0c238448fda99c4d7997901d0fe4d72cb06b79cc.zip
Merge pull request #700 from 0xProject/fix/contracts/tokenbugs
Handle tokens that do not return bool
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol30
1 files changed, 29 insertions, 1 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol
index ddcd78e93..eeddb9707 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/ERC20Proxy.sol
@@ -50,7 +50,35 @@ contract ERC20Proxy is
address token = readAddress(assetData, 0);
// Transfer tokens.
- bool success = IERC20Token(token).transferFrom(from, to, amount);
+ // We do a raw call so we can check the success separate
+ // from the return data.
+ bool success = token.call(abi.encodeWithSelector(
+ IERC20Token(token).transferFrom.selector,
+ from,
+ to,
+ amount
+ ));
+ require(
+ success,
+ TRANSFER_FAILED
+ );
+
+ // Check return data.
+ // If there is no return data, we assume the token incorrectly
+ // does not return a bool. In this case we expect it to revert
+ // on failure, which was handled above.
+ // If the token does return data, we require that it is a single
+ // value that evaluates to true.
+ assembly {
+ if returndatasize {
+ success := 0
+ if eq(returndatasize, 32) {
+ // First 64 bytes of memory are reserved scratch space
+ returndatacopy(0, 0, 32)
+ success := mload(0)
+ }
+ }
+ }
require(
success,
TRANSFER_FAILED