-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
why use asserts in SafeMath to take all the gas? #565
Comments
Assuming that overflows aren't a desirable feature, any time that your int overflows, you can assume that something has gone very wrong (possibly via some sort of malformed/malicious input), so bailing hard and consuming all gas is pretty reasonable. So I suppose the advice would be to write your contract such that those asserts are never reached, which means using that said, I totally see why it would be nice to use require, just from a "good citizen" perspective; it might be worth a separate SafeMath library that uses require, but changing the currently used one is probably not reasonable or doable. |
The rationale was exactly what @shrugs said, and I'd like to highlight the spot on recommendation:
Here's a good article explaining all of the differences between |
Completely disagree here, because safeMath is used widely in some Yes, I think it's better to be a good citizen then a bully to take all up the gas. IMHO, no reason to reward miners for user's errors. |
I think I see your point @rstormsf. I appreciate the discussion. Can you give some examples of those |
My apologies, I was thinking about something else. |
+ Prefix all parameters with underscore + Add gas optimization for safeMul + Consider to change `assert` to `require` since require make more gas effiency, but still keeping this by follow the rationale from here (OpenZeppelin/openzeppelin-contracts#565)
require
would safe some gas instead of eating it all up withassert
https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol#L14
https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol#L26
https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol#L32
The text was updated successfully, but these errors were encountered: