fix(api): abort EVM execution when the trace timeout fires#4918
Open
raullenchai wants to merge 1 commit into
Open
fix(api): abort EVM execution when the trace timeout fires#4918raullenchai wants to merge 1 commit into
raullenchai wants to merge 1 commit into
Conversation
Stopping the tracer alone only stops result collection — the EVM kept executing until gas exhaustion, undercutting the timeout's DoS protection. Pair tracer.Stop with EVM cancellation like upstream geth: a TraceCanceller travels in the context from the trace entry points (traceContext/traceBlock), executeInEVM registers each EVM's Cancel with it, and the parseTracer watchdog fires both. Once fired, EVMs created later in a block trace abort immediately at registration. The consensus path never carries a canceller. Verified by a regression test executing an infinite-loop contract (JUMPDEST;PUSH1 0;JUMP) with a 100M gas budget: cancelled run returns in ~100ms without consuming the gas budget; uncancelled it burns the full limit to out-of-gas. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
envestcc
approved these changes
Jul 13, 2026
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.



Context
Follow-up to #4886 (merged), which made
debug_traceenforce its timeout by stopping the tracer. Review of that PR flagged that stopping the tracer alone doesn't cancel the EVM — for the struct logger and native tracers,Stoponly sets tracer state so hooks return early andGetResultreports the timeout; the EVM keeps executing opcodes until gas exhaustion. Upstream geth pairstracer.Stopwithevm.Cancel()for exactly this reason. This PR completes that fix. (It was developed alongside #4886 but missed the merge; carrying it here as its own PR.)Fix
A
TraceCancellertravels in the context from the trace entry points (traceContext/traceBlock).executeInEVMregisters each EVM'sCancelwith it, and theparseTracertimeout watchdog firestracer.Stopandcanceller.Cancel(). EVMs registered after the watchdog fires abort immediately at registration. The consensus path (block production/validation vianewWorkingSet/PutBlock) never carries a canceller, so opcode execution there is never abortable.Non-consensus, non-hardfork — trace/simulation path only.
Testing
TestTraceCancellerAbortsEVM: an infinite-loop contract (JUMPDEST;PUSH1 0;JUMP) with a 100M gas budget returns in ~100ms without consuming the budget when cancelled; uncancelled it burns the full limit to out-of-gas.go build, evm + api trace tests pass.🤖 Generated with Claude Code