Skip to content

Instantly share code, notes, and snippets.

@decanus
Last active September 5, 2019 18:01
Show Gist options
  • Save decanus/bdc08df5bf73af349333d1a8cae07d23 to your computer and use it in GitHub Desktop.
Save decanus/bdc08df5bf73af349333d1a8cae07d23 to your computer and use it in GitHub Desktop.

With Solidity 0.4.23 a require statement seemingly fail if a contract called has a returndatasize of less than 32. This issue was found when wrapping a transferFrom function call, which doesn't return anything, in a require.

Older contracts that use STOP to return control flow place 1 on the stack through the return of CALL and so RETURNDATASIZE is set to 0. The new require seems to enforce that at least 32 bytes must be returned by the child contract (with RETURNDATASIZE >= 0x20) which seems to break old contracts that simply check whether the return of CALL itself was 1.

The token contract used is Adex.

This issue indicates that any token transfered without a return will fail, affecting any contract using tokens transfers that are wrapped in a require as of solidity v0.4.23

To ensure this really is an issue, we have tried running the code with 2 solidity versions. Essentially wrapping the transferFrom in a require.

VM Traces are here

Example

The below example highlights the issue, if the code is deployed with solidity v0.4.23 the transfer of BadToken using the Transferer will fail, if an earlier solidity version is used. transfer on the Transferer contract will not revert.

Found by

pragma solidity ^0.4.10;
interface IToken {
function transfer(address to, uint256 amount) public returns (bool);
}
contract BadToken {
function transfer(address to, uint256 amount) public {
// @do nothing
}
}
contract GoodToken {
function transfer(address to, uint256 amount) public returns (bool) {
return true;
}
}
contract Transferer {
function transfer(address token, uint256 amount) {
require(IToken(token).transfer(msg.sender, amount));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment