Skip to content

fix(inspectors): report cost 0 for a step that halts exceptionally - #1111

Open
mablr wants to merge 2 commits into
alloy-rs:mainfrom
mablr:fix/geth-exceptional-halt-cost
Open

mablr wants to merge 2 commits into
alloy-rs:mainfrom
mablr:fix/geth-exceptional-halt-cost

Conversation

@mablr

@mablr mablr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Since ethereum/go-ethereum#36166 (44577c84), geth reports cost 0 for the step of an exceptional halt, as ethereum/execution-apis#986 proposes: the attempted cost depends on where each client detects the failure. evm2 reported the gas it had charged before the check, or all the gas left on out of gas. This is item 1 of #1102.

Struct logs now report gasCost 0 and omit stateGasCost on a step with an error. In the JS tracer, the hook that reports the halt sees log.getCost() 0: step for a halt before the opcode runs (stack checks, out of gas, static CREATE, SSTORE, SELFDESTRUCT and CALL with value), and fault for one while it runs (JUMP, RETURNDATACOPY, INVALID, static LOG and TSTORE). A step before a fault keeps the opcode's cost, as in geth. REVERT, the Parity vmTrace costs and the opcode gas inspector do not change.

Failing step (Amsterdam, in a callee) geth 44577c84 main this PR
MSTORE out of gas for memory 0 99994 0
SSTORE out of state gas 0 49995 0
EXP with an empty stack 0 10 0
LOG3 with an empty stack 0 375 0
ADD with an empty stack 0 3 0
invalid JUMP (fault hook) 0 8 0

The new test checks both tracers on these cases and on cold CALL out of gas, PUSH0 overflow, EXTCODESIZE underflow, RETURNDATACOPY out of bounds and LOG0 and SELFDESTRUCT in a static call, with values from debug_traceTransaction on geth 44577c84. It fails on main. I also ran #859's harness against geth 44577c84 binaries on its corpus (342 case and fork pairs): struct log gasCost differences go from 127 to 0, and no new difference appears. In Amsterdam CREATE out of state gas, geth calls step with the cost and then fault, while evm2 calls step with the error. That classification difference was there before and is not part of this PR.

This overlaps #1110 in crates/inspectors/src/tracing/js/mod.rs, so whichever lands second needs a small rebase. With both, the DUPN, SWAPN and EXCHANGE faults of #1110 report cost 0 through this change.

Geth reports cost 0 for the failing step of an exceptional halt since
ethereum/go-ethereum#36166 (44577c84), as ethereum/execution-apis#986
proposes: the attempted cost depends on where each client detects the
failure. evm2 reported the gas it had charged, or all the gas left on out
of gas (alloy-rs#1102, item 1).

Struct logs now report `gasCost` 0 and no `stateGasCost` on a step with an
error. In the JS tracer, the hook that reports the halt sees cost 0: `step`
for a halt before the opcode runs, `fault` for one while it runs. REVERT
and the Parity `vmTrace` costs do not change.

Co-authored-by: Mablr <59505383+mablr@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1f9ae-ff93-76bf-aa19-45fd3b65cb83

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Matches geth after go-ethereum#36166: an exceptional halt reports cost 0 (and no stateGasCost) in the struct logger and the JS fault hook, while the preceding step keeps the opcode's cost. Pushed a test assertion for that step cost; RETURNDATACOPY reports 3 there where geth reports 9, a pre-existing ordering difference documented in the test.

This branch was previously deployed

1 inactive (outdated) deployment
codspeed — 5339b0c4 Deployed Nov 20, 2026 by mablr via codspeed (jit-mainnet) #3351
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.

3 participants