-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fixes u256 overflow in logical shift optimization rule and adds tests. #6248
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
Conversation
libevmasm/RuleList.h
Outdated
@@ -46,6 +46,11 @@ template <class S> S modWorkaround(S const& _a, S const& _b) | |||
return (S)(bigint(_a) % bigint(_b)); | |||
} | |||
|
|||
template <class S> S minOfu256Add(S const& _a, S const& _b, S const& _c) |
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.
Please move to libdevcore/CommonData.h
after bigintShiftLeftWorkaround
.
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.
Are you sure that this makes a nice helper function? It's rather cryptic - I don't think it's apparent what it does without looking at the implementation. And it's not like we're working around a bug in boost here or something like that...
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 also think it should just be inlined.
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.
Please add a changelog and a buglist entry.
Also include it in the end to end tests (where the other shift combinations are).
It's currently not possible to test this in the end to end tests. I will fix that. |
Ah sorry, I confused this with the peephole optimizer. Of course it is possible to test these via the execution framework. |
@@ -15109,11 +15109,21 @@ BOOST_AUTO_TEST_CASE(bitwise_shifting_constantinople_combined) | |||
c := shl(0xd0, shl(0x40, a)) | |||
} | |||
} | |||
function shl_combined_overflow(uint a) public returns (uint c) { | |||
assembly { | |||
c := shl(0x01, shl(not(0x00), a)) |
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 don't think there is a need for these, just supply a large value in callContractFunction
below.
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 don't understand - it only works for constants. Supply a large value where?
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 thought it has two inputs, sorry.
e0000f9
to
3b55767
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6248 +/- ##
===========================================
- Coverage 26.76% 26.76% -0.01%
===========================================
Files 381 381
Lines 36573 36577 +4
Branches 4336 4336
===========================================
Hits 9789 9789
- Misses 26115 26119 +4
Partials 669 669
|
21b7a96
to
fa693e2
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6248 +/- ##
===========================================
- Coverage 26.76% 26.76% -0.01%
===========================================
Files 381 381
Lines 36573 36577 +4
Branches 4336 4336
===========================================
Hits 9789 9789
- Misses 26115 26119 +4
Partials 669 669
|
docs/bugs.json
Outdated
"name": "DoubleShiftSizeOverflow", | ||
"summary": "Double bitwise shifts by large constants whose sum overflows 256 bits can result in unexpected values.", | ||
"description": "Nested logical shift operations whose total shift size is 2**256 or more are incorrectly optimized. This only applies to shifts by numbers of bits that are compile-time constant expressions.", | ||
"introduced": "0.5.5", |
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.
Indentation?
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.
Weird, I thought I fixed it...
fa693e2
to
2e46df7
Compare
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 think the yulOptimizer tests may fail on homestead
test/libyul/yulOptimizerTests/expressionSimplifier/shift_left_overflow.yul
Outdated
Show resolved
Hide resolved
test/libyul/yulOptimizerTests/expressionSimplifier/shift_right_overflow.yul
Outdated
Show resolved
Hide resolved
2e46df7
to
34c6cbe
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6248 +/- ##
===========================================
+ Coverage 87.96% 87.96% +<.01%
===========================================
Files 381 381
Lines 36779 36801 +22
Branches 4336 4340 +4
===========================================
+ Hits 32353 32373 +20
Misses 2952 2952
- Partials 1474 1476 +2
|
34c6cbe
to
7b5f784
Compare
Changed severity to "low". The situation is comparable to |
7b5f784
to
d725b0f
Compare
d725b0f
to
515fa87
Compare
Updated. |
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 hope I'm not missing something else, but I think it's fine now :-).
Description
(closes #6246 )
This PR fixes incorrect shift optimization due to u256 overflow in the addition of shift sizes.
Checklist