Skip to content

Conversation

@gumb0
Copy link
Member

@gumb0 gumb0 commented Jul 16, 2019

Without the fix it's not only UBSAN warning, but also the test fails, returning EVMC_OUT_OF_GAS instead of EVMC_UNDEFINED_INSTRUCTION.

Overflow happens not at the place of fix but later during execution here
https://github.com/ethereum/evmone/blob/47a1d47ae96b19a247d3923311735cce118a347b/lib/evmone/instructions.cpp#L1164

@codecov-io
Copy link

codecov-io commented Jul 16, 2019

Codecov Report

Merging #93 into master will increase coverage by 0.03%.
The diff coverage is 100%.

@@            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

@chfast
Copy link
Member

chfast commented Jul 16, 2019

I found similar test in the fuzzer branch. After cleaning up here is the unit test: 27ef5b0. Please integrate with this PR.

gumb0 added 2 commits July 16, 2019 14:06
Caused by integer overflow around undefined instruction's gas cost.
Prevent integer overflow when calculating block gas with undefined instructions.
@chfast chfast force-pushed the analysis-overflow branch from e1aaab3 to b769597 Compare July 16, 2019 12:07
@chfast chfast merged commit 04e22a4 into master Jul 16, 2019
@chfast chfast deleted the analysis-overflow branch July 16, 2019 12:23

auto metrics = instr_table[c];
block->gas_cost += metrics.gas_cost;
if (metrics.gas_cost > 0) // can be -1 for undefined instruction
Copy link
Member

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)?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jwasinger pushed a commit to jwasinger/evmone that referenced this pull request Apr 27, 2021
Compile unittests and vmtests as C++11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants