-
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
Improper use of assert() in BasicToken and other places #435
Comments
Thanks for reporting @mikhail-vladimirov! I agree with your assessment. Do you want to submit a PR changing to |
@frangio I personally strongly prefer |
@mikhail-vladimirov sorry to disagree, require is meant to be used for validations, while assert should be used in order to prevent conditions which should never be possible, in this case, we are preventing an overflow. I highly recommend this article, a detailed explanation about this subject. |
Sorry to re-vitalize this old issue but I agree @3sGgpQ8H and @frangio. The asserts in SafeMath are implicitly performing input validation and IMO should be replaced by |
Hey @b-mueller, this was discussed recently in #1120, where we decided to switch over to |
Ahh, I didn't notice! Awesome :) |
Method
transfer
ofBasicToken
smart contract uses methodsub
defined inSafeMath
library to implicitly check that sender's balance is enough to transfer:Method
sub
internally usesassert()
function like this (a
andb
and method parameters):So, when sender's balance is insufficient, assert will fail and execution will be aborted. According to Solidity docs:
but insufficient sender's balance is not internal error, so
assert()
should not be used here.Note, that
require()
does not fit as well because:and insufficient sender's balance is neither malformed input, not error in external component. So the best fit would be to use
revert()
here.The text was updated successfully, but these errors were encountered: