Skip to content

fix(evm): skip DB storage lookup for newly-created accounts in inspect_storage#290

Merged
flyq merged 3 commits into
mainfrom
liquan/fix_stateless_lack_slots
May 7, 2026
Merged

fix(evm): skip DB storage lookup for newly-created accounts in inspect_storage#290
flyq merged 3 commits into
mainfrom
liquan/fix_stateless_lack_slots

Conversation

@flyq
Copy link
Copy Markdown
Member

@flyq flyq commented May 6, 2026

Journal::inspect_storage previously called self.database.storage(address, key) for any slot missing from the journal cache, including slots on accounts created within the current transaction.
Post-CREATE storage is guaranteed empty (EIP-161 / EIP-6780), so this lookup returns ZERO in the normal case — but it is unsafe under stateless replay.

When CREATE lands on a pre-funded address, the account's cache status is Loaded rather than Created, which bypasses revm's short-circuit in State::storage and forwards the call to the witness backend.
The witness backend has no entry for that slot (no pre-state value exists) and the replay fails.

This PR mirrors revm's sload_with_account behavior: capture account.is_created() before re-borrowing, then short-circuit to U256::ZERO for newly-created accounts instead of querying the database.

Observable behavior of this function is unchanged for every spec: the old code path also resolved to ZERO (via the DB), and the new path returns ZERO directly — the only difference is that no DB call is issued for newly-created accounts.

Test plan

  • cargo test -p mega-evm
  • cargo clippy --workspace --lib --examples --tests --benches --all-features --locked
  • cargo fmt --all --check

Copilot AI review requested due to automatic review settings May 6, 2026 14:30
@flyq flyq added comp:core Changes to the `mega-evm` core crate spec:unchanged No change to any `mega-evm`'s behavior api:unchanged No change to the public interface or API labels May 6, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

Review

The fix is correct and the explanation in the PR body is thorough. Mirroring revm's sload_with_account short-circuit here is the right approach: newly-created accounts are guaranteed to have empty storage (EIP-161 / EIP-6780), so U256::ZERO is always the correct answer without touching the DB.

One concern: missing automated test.

CLAUDE.md requires "Always test logic changes." The test plan's stateless-replay bullet appears to be a manual verification, not an automated test case. The bug is narrow but well-defined — a CREATE landing on a pre-funded address followed by a storage read/write on the new contract within the same transaction — and it would be straightforward to reproduce with the in-process test infrastructure used by the rest of the test suite (e.g., a factory contract that deploys to a pre-funded address and then SSTOREs/SLOADs a slot). Without an automated test, the regression path stays open.

Comment thread crates/mega-evm/src/evm/host.rs
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.4%. Comparing base (3367091) to head (47c7e3b).

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Journal::inspect_storage to avoid database storage lookups for accounts created within the current transaction, preventing stateless replay failures when a CREATE lands on a pre-funded address and touches storage. This aligns the behavior with upstream revm’s sload_with_account short-circuiting.

Changes:

  • Capture account.is_created() early in inspect_storage to survive later re-borrows.
  • Short-circuit missing-slot reads to U256::ZERO for newly-created accounts instead of calling db.storage(address, key).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/mega-evm/src/evm/host.rs
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

LGTM. My previous concern about missing an automated test has been addressed — test_inspect_storage_skips_db_for_newly_created_account directly exercises the regression path (pre-funded address, injected DB that errors on storage(), verifies no DB call is made for the newly-created account). The fix is correct and the test coverage is sufficient.

@flyq flyq merged commit 915f71e into main May 7, 2026
23 checks passed
@flyq flyq deleted the liquan/fix_stateless_lack_slots branch May 7, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:unchanged No change to the public interface or API comp:core Changes to the `mega-evm` core crate spec:unchanged No change to any `mega-evm`'s behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants