Skip to content

Commit

Permalink
baseline: Move stack size computation to check_requirements()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 5, 2022
1 parent 1a47475 commit 8191ca1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace
/// @return Status code with information which check has failed
/// or EVMC_SUCCESS if everything is fine.
template <evmc_opcode Op>
inline evmc_status_code check_requirements(
const CostTable& cost_table, int64_t& gas_left, ptrdiff_t stack_size) noexcept
inline evmc_status_code check_requirements(const CostTable& cost_table, int64_t& gas_left,
const uint256* stack_top, const uint256* stack_bottom) noexcept
{
static_assert(
!instr::has_const_gas_cost(Op) || instr::gas_costs[EVMC_FRONTIER][Op] != instr::undefined,
Expand All @@ -118,6 +118,8 @@ inline evmc_status_code check_requirements(
return EVMC_UNDEFINED_INSTRUCTION;
}

const auto stack_size = stack_top - stack_bottom;

// Check stack requirements first. This is order is not required,
// but it is nicer because complete gas check may need to inspect operands.
if constexpr (instr::traits[Op].stack_height_change > 0)
Expand Down Expand Up @@ -202,8 +204,8 @@ template <evmc_opcode Op>
[[release_inline]] inline Position invoke(const CostTable& cost_table, const uint256* stack_bottom,
Position pos, ExecutionState& state) noexcept
{
const auto stack_size = pos.stack_top - stack_bottom;
if (const auto status = check_requirements<Op>(cost_table, state.gas_left, stack_size);
if (const auto status =
check_requirements<Op>(cost_table, state.gas_left, pos.stack_top, stack_bottom);
status != EVMC_SUCCESS)
{
state.status = status;
Expand Down

0 comments on commit 8191ca1

Please sign in to comment.