Skip to content

refactor(revme): separate bytecode from account in test state - #3803

Merged
rakita merged 2 commits into
mainfrom
revme-separate-code-from-account
Jul 16, 2026
Merged

rakita merged 2 commits into
mainfrom
revme-separate-code-from-account

Conversation

@rakita

@rakita rakita commented Jul 16, 2026

Copy link
Copy Markdown
Member

Motivation

A recent bug (delegate bytecode not loaded at first-frame creation, found as a glamsterdam-devnet-7 gas divergence) went unnoticed by the fixture suites because the revme test databases inline bytecode into AccountInfo, so Database::basic always returns code and paths that forget to fetch it through code_by_hash are masked. Real node providers (e.g. reth) serve code separately.

Changes

  • statetest / blockchaintest pre-state: accounts are seeded with code: None and the bytecode goes into the cache's contracts map keyed by code hash. Execution now has to fetch code through Database::code_by_hash, so the standard fixtures exercise every code-loading path.
  • blockchaintest post-state validation falls back to code_by_hash when the final account carries only a code hash (untouched accounts no longer have code inline). The --print-env-on-error pre-state dump keeps code inlined for readable output.
  • fix(handler): the refactor immediately exposed a latent bug — the EIP-8037 auth-refund bookkeeping derived delegated_before_tx from original_info().code, which is None with a provider-style database, so clearing a pre-existing delegation under-counted the refund. It now derives the fact from the original code hash (sound because an accepted authorization's code is guaranteed empty-or-delegation).

Testing

  • devnet state tests: failure set byte-identical to main baseline (the pre-existing fixture divergences); without the handler fix the refactor surfaces 5 delegation-clearing failures, confirming the added coverage works.
  • devnet blockchain tests: 71509 passed, 0 failed.
  • legacy Cancun + Constantinople GeneralStateTests: all pass.
  • cargo nextest run --workspace, clippy all-features and fmt are clean.

rakita added 2 commits July 16, 2026 12:06
The EIP-8037 auth-refund bookkeeping read the authority's pre-transaction
bytecode from the account's original info, which carries no code when the
database serves bytecode separately from the account (code only via
code_by_hash). A pre-existing delegation was then missed and the clearing
refund under-counted. Derive the fact from the original code hash instead:
an accepted authorization's code is guaranteed empty-or-delegation, so a
non-empty hash is necessarily a delegation.
Seed statetest and blockchaintest pre-state with the bytecode stored
separately from the account (contracts map keyed by code hash) instead of
inlined in AccountInfo. Execution now has to fetch code through
Database::code_by_hash, the way a node's state provider serves it, so the
fixtures exercise every code-loading path and catch loads that forget to
fetch bytecode.

Post-state code validation in blockchaintest falls back to code_by_hash
when the account carries only a hash, and the debug pre-state keeps the
code inlined for readable output.
@codspeed

codspeed Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing revme-separate-code-from-account (0beafa5) with main (a094a93)

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 4c5cc3a into main Jul 16, 2026
32 of 34 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 16, 2026
@rakita
rakita deleted the revme-separate-code-from-account branch July 16, 2026 11:23
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.

1 participant