Skip to content

Commit fade609

Browse files
committed
Extract shared frame-exit result construction
Use shared procedure for frame exit in Baseline and Advanced.
1 parent c1a0c7c commit fade609

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

lib/evmone/advanced_execution.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ evmc_result execute(AdvancedExecutionState& state, const AdvancedCodeAnalysis& a
1616
while (instr != nullptr)
1717
instr = instr->fn(instr, state);
1818

19-
const auto gas_left =
20-
(state.status == EVMC_SUCCESS || state.status == EVMC_REVERT) ? state.gas_left : 0;
21-
const auto gas_refund = (state.status == EVMC_SUCCESS) ? state.gas_refund : 0;
22-
23-
assert(state.output_size != 0 || state.output_offset == 0);
24-
return evmc::make_result(state.status, gas_left, gas_refund,
25-
state.output_size != 0 ? &state.memory[state.output_offset] : nullptr, state.output_size);
19+
return make_execution_result(state, state.gas_left);
2620
}
2721

2822
evmc_result execute(evmc_vm* /*unused*/, const evmc_host_interface* host, evmc_host_context* ctx,

lib/evmone/baseline_execution.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,7 @@ evmc_result execute(VM& vm, const evmc_host_interface& host, evmc_host_context*
292292
gas = dispatch<false>(cost_table, state, gas, code_begin);
293293
}
294294

295-
const auto gas_left = (state.status == EVMC_SUCCESS || state.status == EVMC_REVERT) ? gas : 0;
296-
const auto gas_refund = (state.status == EVMC_SUCCESS) ? state.gas_refund : 0;
297-
298-
assert(state.output_size != 0 || state.output_offset == 0);
299-
const auto result = evmc::make_result(state.status, gas_left, gas_refund,
300-
state.output_size != 0 ? &state.memory[state.output_offset] : nullptr, state.output_size);
295+
const auto result = make_execution_result(state, gas);
301296

302297
if (INTX_UNLIKELY(tracer != nullptr))
303298
tracer->notify_execution_end(result);

lib/evmone/execution_state.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <evmc/evmc.hpp>
77
#include <intx/intx.hpp>
8+
#include <cassert>
89
#include <exception>
910
#include <memory>
1011
#include <string>
@@ -193,4 +194,21 @@ class ExecutionState
193194
return m_tx;
194195
}
195196
};
197+
198+
/// Builds the execution result for a finished frame from its final @p state and @p gas_left.
199+
///
200+
/// Applies the frame-exit rules shared by the baseline and advanced interpreters: an exceptional
201+
/// halt consumes all gas (only a success or revert keeps it), the gas refund counts only on
202+
/// success, and the output is the memory range recorded in the state.
203+
inline evmc_result make_execution_result(ExecutionState& state, int64_t gas_left) noexcept
204+
{
205+
// An exceptional halt consumes all gas; only a success or revert keeps gas_left.
206+
if (state.status != EVMC_SUCCESS && state.status != EVMC_REVERT)
207+
gas_left = 0;
208+
const auto gas_refund = (state.status == EVMC_SUCCESS) ? state.gas_refund : 0;
209+
210+
assert(state.output_size != 0 || state.output_offset == 0);
211+
return evmc::make_result(state.status, gas_left, gas_refund,
212+
state.output_size != 0 ? &state.memory[state.output_offset] : nullptr, state.output_size);
213+
}
196214
} // namespace evmone

0 commit comments

Comments
 (0)