Skip to content

Commit 742b817

Browse files
authored
Merge pull request #344 from ethereum/baseline_opt_stack_check
baseline: Change stack requirements checks
2 parents c84c429 + 358f951 commit 742b817

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/evmone/baseline.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ inline evmc_status_code check_requirements(
9090
{
9191
const auto metrics = instruction_table[op];
9292

93-
if (metrics.gas_cost == instr::undefined)
93+
if (INTX_UNLIKELY(metrics.gas_cost == instr::undefined))
9494
return EVMC_UNDEFINED_INSTRUCTION;
9595

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

9999
const auto stack_size = state.stack.size();
100-
if (stack_size < metrics.stack_height_required)
100+
if (INTX_UNLIKELY(stack_size == Stack::limit))
101+
{
102+
if (metrics.can_overflow_stack)
103+
return EVMC_STACK_OVERFLOW;
104+
}
105+
else if (INTX_UNLIKELY(stack_size < metrics.stack_height_required))
101106
return EVMC_STACK_UNDERFLOW;
102-
if (stack_size == Stack::limit && metrics.can_overflow_stack)
103-
return EVMC_STACK_OVERFLOW;
104107

105108
return EVMC_SUCCESS;
106109
}

0 commit comments

Comments
 (0)