Skip to content
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

SafeERC20: add extra returndatasize check to staticInvoke() #540

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Jul 13, 2019

For good measure :).

@sohkai sohkai requested review from izqui and facuspagnuolo July 13, 2019 08:47
@coveralls
Copy link

coveralls commented Jul 13, 2019

Coverage Status

Coverage increased (+0.3%) to 99.417% when pulling ec1e0f5 on safe-erc20-check-returndatasize into 4feb97a on next.

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

allowTransfer_ = true;
}

function totalSupply() public view returns (uint256) { return totalSupply_; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm thinking of... shouldn't we provide a static version of totalSupply in SafeERC20?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JIC #543

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; we didn't have a use case for it before but it doesn't hurt to include it :).

import "../../../../lib/math/SafeMath.sol";


contract TokenBalanceOfAllowanceReturnMissingMock {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about modeling this case within TokenReturnMissingMock as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that... but what stopped me was in the TokenReturnMissingMock tests we need a working balanceOf() to check results against.

// Else, mark call as failed
default {
success := 0
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we upgraded solidity-coverage maybe we can stop using switch in favor of if-else statements, we can tackle that in a separate PR tho and migrate all at once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there's no else to go along with the if (docs) :(

}
// Else, mark call as failed
default {
success := 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: The revert reasons in staticBalanceOf and staticAllowance denote that the call to the token reverted, which is no longer always the case with this change. I don't think we should change the revert reason but we should at least make a note for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in the function header says "Reverts if the call fails for some reason (should never fail)", we could just update it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to "(should never fail for correctly implemented ERC20s)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants