-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fix integer overflow in analysis around gas cost of undefined instruction #93
Conversation
Codecov Report
@@ Coverage Diff @@
## master #93 +/- ##
==========================================
+ Coverage 94.89% 94.93% +0.03%
==========================================
Files 18 18
Lines 1801 1815 +14
Branches 182 184 +2
==========================================
+ Hits 1709 1723 +14
Misses 75 75
Partials 17 17 |
I found similar test in the |
Caused by integer overflow around undefined instruction's gas cost.
Prevent integer overflow when calculating block gas with undefined instructions.
e1aaab3
to
b769597
Compare
@@ -84,7 +84,8 @@ code_analysis analyze( | |||
auto& instr = jumpdest ? analysis.instrs.back() : analysis.instrs.emplace_back(fns[c]); | |||
|
|||
auto metrics = instr_table[c]; | |||
block->gas_cost += metrics.gas_cost; | |||
if (metrics.gas_cost > 0) // can be -1 for undefined instruction |
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.
If we know this instruction will be hit, shouldn't the cost be set to max instead (e.g. out of gas)?
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 then it would stop with EVMC_OUT_OF_GAS
at the beginning of the block, instead of expected EVMC_UNDEFINED_INSTRUCTION
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 believe we should set it to 0
as this is real gas cost of executing it. Setting it to "max" is a nice hack, but I don't waste 64-bits in the table just for it.
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.
Compile unittests and vmtests as C++11
Without the fix it's not only UBSAN warning, but also the test fails, returning
EVMC_OUT_OF_GAS
instead ofEVMC_UNDEFINED_INSTRUCTION
.Overflow happens not at the place of fix but later during execution here
evmone/lib/evmone/instructions.cpp
Line 1164 in 47a1d47