-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add no-return-data ERC20 support to SafeERC20. #1655
Conversation
contracts/token/ERC20/SafeERC20.sol
Outdated
* @dev Parses the return value of the last contract call and attempts to return a boolean value out of it. | ||
*/ | ||
function getBooleanReturnValue() private pure returns (bool result) { | ||
// We need to use inline assembly here, since it is the only way we can utilize the returndatasize opcode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true for the opcode, but we could be using the data
byte array returned by call
and reading data.length
. What do you think?
I don't feel so comfortable having this function use the returndata
opcodes because they're like reading from global variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data.length
sure, but I'm not sure if there's a convenient way to check for a boolean value stored inside the bytes
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's a good time to introduce that bytes conversion library. 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Reimplementation of #1344, based on discussion from there (thanks @k06a for inspiration for the assembly code!).
This adds support to
SafeERC20
forERC20
contracts that return no value (i.e. those that do nothing on success, and revert/throw when an error occurs). Solidity now performs automatic return data size checks, so prior to this patch those contracts would've caused a revert. We now resort to low level calls to workaround this.I've refactored the mocks and tests in the process, since they were getting a bit out of hand. I tried running the old contract against the updated test suite, and as expected, all tests pass except the ones in the 'with token that returns no boolean values'
describe
block.