Skip to content

fix(inspect): finalize journal on error to prevent EIP-2929 warm set leak - #3780

Merged
rakita merged 2 commits into
bluealloy:mainfrom
KyrinCode:fix/inspect-finalize-on-error
Jun 29, 2026
Merged

rakita merged 2 commits into
bluealloy:mainfrom
KyrinCode:fix/inspect-finalize-on-error

Conversation

@KyrinCode

Copy link
Copy Markdown
Contributor

Problem

Closes #3779

InspectEvm::inspect_tx (and its sibling inspect/system-call/commit variants) used
self.X(tx)? to short-circuit before calling finalize(). On error the handler calls
discard_tx, which reverts account values but keeps the entries in the state map and
increments transaction_id, so the EIP-2929 warm set and touched accounts leaked into
the next transaction.

The same latent bug also existed in ExecuteEvm::transact_commit and ExecuteEvm::replay.

Solution

Fix all affected functions to finalize the journal on the error path, matching the existing
correct pattern in ExecuteEvm::transact and transact_many:

  • crates/inspector/src/inspect.rs (8 functions): the ExecResultAndState-returning
    variants use "capture Result → finalize() unconditionally → ?"; the _commit
    variants use .inspect_err(|_| { let _ = self.finalize(); }).
  • crates/handler/src/api.rs: transact_commit (inspect_err pattern) and replay
    (.inspect_err(...).map(...) chain). replay_commit is fixed transitively via replay.

Each modified function documents the error-path behavior under a # Outcome of Error
section.

Testing

Added two regression tests (test_inspect_tx_finalizes_journal_on_error and
test_inspect_tx_commit_finalizes_journal_on_error) that trigger a nonce-mismatch
InvalidTransaction (a state-dependent error raised after load_accounts warms the
caller/coinbase) and assert the journal state is empty afterwards.

Verified both tests fail on the unfixed code (found 1 leftover accounts) and pass
after the fix
— confirming they genuinely reproduce the leak.

All checks green: cargo fmt --all --check, cargo clippy --all-targets,
cargo test -p revm-inspector -p revm-handler (19 passed), typos.

`InspectEvm::inspect_tx` (and its sibling inspect/system-call/commit
variants) used `self.X(tx)?` to short-circuit before calling
`finalize()`. On error the handler calls `discard_tx`, which reverts
account values but keeps the entries in the state map and increments
`transaction_id`, so the EIP-2929 warm set and touched accounts leaked
into the next transaction.

This mirrors the same latent bug in `ExecuteEvm::transact_commit` and
`ExecuteEvm::replay`. Fix all of them to finalize the journal on the
error path, matching the existing correct pattern in
`ExecuteEvm::transact` and `transact_many`.

Adds regression tests asserting the journal is empty after a failed
`inspect_tx` / `inspect_tx_commit`.

Closes bluealloy#3779

@rakita rakita 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.

Thanks for the fix

@KyrinCode

KyrinCode commented Jun 29, 2026 via email

Copy link
Copy Markdown
Contributor Author

Comment thread crates/inspector/src/inspect.rs Resolved
@codspeed

codspeed Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing KyrinCode:fix/inspect-finalize-on-error (a051ffe) with main (ae95b77)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@rakita
rakita merged commit fa465c4 into bluealloy:main Jun 29, 2026
34 checks passed
This was referenced Jun 24, 2026
This was referenced Jul 22, 2026
RealiCZ added a commit to megaeth-labs/revm that referenced this pull request Sep 16, 2026
@RealiCZ RealiCZ mentioned this pull request Sep 18, 2026
43 tasks done
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.

InspectEvm::inspect_tx skips finalize() on error, unlike ExecuteEvm::transact — journal (EIP-2929 warm set) leaks into the next tx

2 participants