fix(evm): emit step event before dynamic-gas OOG exceptions#4343
Open
GiHoon1123 wants to merge 1 commit into
Open
fix(evm): emit step event before dynamic-gas OOG exceptions#4343GiHoon1123 wants to merge 1 commit into
GiHoon1123 wants to merge 1 commit into
Conversation
If an opcode has a dynamic gas handler (e.g. CALL) and that handler itself throws out-of-gas, runStep() never reached the step-event hook, so debuggers/tracers silently lost the last instruction executed. Static-gas opcodes didn't have this problem, since useGas() (where their OOG is thrown) already runs after the step hook. Catch OUT_OF_GAS errors thrown by the dynamic gas handler, emit the step event for the current opcode (matching what already happens for static-gas OOG), then rethrow the original error unchanged. Gas consumption and the resulting error are untouched -- this only makes step-event emission consistent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4313.
The
stepevent (used by debuggers/tracers to observe each instruction before it executes) was inconsistently emitted when an instruction ran out of gas:stepevent before theOUT_OF_GASexception, becauseuseGas()(which throws it) runs after the step hook inInterpreter.runStep().CALL) could throwOUT_OF_GASfrom inside the handler itself (e.g. during memory-expansion cost calculation), before the step hook ever ran -- so nostepevent was emitted for that instruction at all.Fix
In
Interpreter.runStep(), wrap the dynamic gas handler call in atry/catch. If it throwsOUT_OF_GAS, emit the step event for the current opcode (mirroring what the static-gas path already does), then rethrow the original error unchanged. Gas accounting and the resulting error are untouched -- this only makesstep-event emission consistent between the two paths.Test plan
Locally:
packages/evm/test/runCall.spec.ts): aCALLwith a small gas limit and a largeoutLength(forcing memory-expansion cost to exceed the limit during dynamic gas calculation) now showsCALLas the last opcode observed via thestepevent, and confirms gas consumption / error type (OUT_OF_GAS) are unchanged.expected 'PUSH1' to equal 'CALL') against the code before this fix, and passes with it.packages/evmfull test suite: 1178 passed. The 2 failing suites are unrelated (missingethereum-testsgit submodule fixtures) and fail identically on unmodifiedmaster.biome checkclean on changed files.