Skip to content

Commit

Permalink
Merge pull request #344 from ethereum/baseline_opt_stack_check
Browse files Browse the repository at this point in the history
baseline: Change stack requirements checks
  • Loading branch information
chfast authored Jun 16, 2021
2 parents c84c429 + 358f951 commit 742b817
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,20 @@ inline evmc_status_code check_requirements(
{
const auto metrics = instruction_table[op];

if (metrics.gas_cost == instr::undefined)
if (INTX_UNLIKELY(metrics.gas_cost == instr::undefined))
return EVMC_UNDEFINED_INSTRUCTION;

if ((state.gas_left -= metrics.gas_cost) < 0)
if (INTX_UNLIKELY((state.gas_left -= metrics.gas_cost) < 0))
return EVMC_OUT_OF_GAS;

const auto stack_size = state.stack.size();
if (stack_size < metrics.stack_height_required)
if (INTX_UNLIKELY(stack_size == Stack::limit))
{
if (metrics.can_overflow_stack)
return EVMC_STACK_OVERFLOW;
}
else if (INTX_UNLIKELY(stack_size < metrics.stack_height_required))
return EVMC_STACK_UNDERFLOW;
if (stack_size == Stack::limit && metrics.can_overflow_stack)
return EVMC_STACK_OVERFLOW;

return EVMC_SUCCESS;
}
Expand Down

0 comments on commit 742b817

Please sign in to comment.