-
Notifications
You must be signed in to change notification settings - Fork 187
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
Do over/underflow checks for addition (SafeMath) #265
Do over/underflow checks for addition (SafeMath) #265
Conversation
12a6ce7
to
2f96c9d
Compare
@@ -239,7 +239,10 @@ pub fn expr_bin_operation( | |||
.typ; | |||
|
|||
return match op.node { | |||
fe::BinOperator::Add => Ok(expression! { add([yul_left], [yul_right]) }), | |||
fe::BinOperator::Add => match typ.is_signed_integer() { |
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.
i imagine at some point we'll add more checking functions for smaller integers?
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.
Ah, good point. I will expand this PR to include checks for all integer sizes for additions.
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.
Ok, done. Additions for all supported sizes should now be checked.
2f96c9d
to
39988a5
Compare
Codecov Report
@@ Coverage Diff @@
## master #265 +/- ##
==========================================
- Coverage 94.03% 94.00% -0.04%
==========================================
Files 54 55 +1
Lines 3791 3834 +43
==========================================
+ Hits 3565 3604 +39
- Misses 226 230 +4
Continue to review full report at Codecov.
|
39988a5
to
6e51389
Compare
6e51389
to
71c7224
Compare
looks great 👍 |
What was wrong?
As explained in #153 artihmetic operations should check for under/overflows by default and revert if such are detected.
How was it fixed?
This adds checks for all additions of both signed and unsigned integers.
checked_add_u256
andchecked_add_i256
functions to runtimefe::BinOperator::Add
in mapper