Skip to content

7708 fix: SELFDESTRUCT finalization logs#4263

Open
ScottyPoi wants to merge 3 commits intomasterfrom
7708-fix
Open

7708 fix: SELFDESTRUCT finalization logs#4263
ScottyPoi wants to merge 3 commits intomasterfrom
7708-fix

Conversation

@ScottyPoi
Copy link
Contributor

This fixes the remaining Amsterdam EIP-7708 execution-spec failures around SELFDESTRUCT finalization logs.

The bug was that we treated SELFDESTRUCT logging as an opcode-time concern only. That works for immediate balance transfers, but it is wrong for the Amsterdam cases where a contract selfdestructs, then later in the same transaction receives more ETH or priority-fee proceeds. In those cases, the spec expects a finalization log based on the contract’s residual balance at tx cleanup time, not just the balance that existed when the opcode executed.

There were two related problems:

  1. We emitted SELFDESTRUCT-related EIP-7708 logs too early.

    • The interpreter created the log when the opcode executed, using the contract balance at that moment.
    • That misses ETH the account can receive later in the same transaction, including miner/priority-fee effects.
  2. We built the tx bloom before selfdestruct finalization was processed.

    • Even after appending finalization logs during tx cleanup, the receipt bloom had already been computed.
    • That caused receiptsRoot and logsBloom mismatches in the execution-spec fixtures.

Fixes:

1. Preserve selfdestruct metadata across execution

I changed selfdestruct tracking in the EVM from a bare Set to a map keyed by selfdestructed address.

That fixes an information loss problem: nested calls and creates now propagate selfdestruct context explicitly instead of only remembering that “some account selfdestructed”. This makes finalization handling deterministic and gives the VM enough information to reason about selfdestructed accounts during tx cleanup.

2. Emit finalization logs during tx cleanup

In runTx, processSelfdestructs() now:

  • walks selfdestructed accounts in lexicographic order
  • reads each account’s final residual balance just before deletion
  • emits an EIP-7708 selfdestruct burn log when that residual balance is non-zero
  • appends those logs before the receipt is generated

This matches the Amsterdam spec behavior: finalization logs are based on the post-execution/post-fee balance that actually exists when the account is cleaned up.

3. Recompute the tx bloom after finalization logs exist

I moved tx bloom generation to happen after processSelfdestructs().

That fixes the header mismatches directly, because the receipt bloom and receipt trie now include the finalization logs that were previously missing from the receipt payload.

Copilot AI review requested due to automatic review settings March 13, 2026 21:53
Copy link
Contributor

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

This PR fixes EIP-7708 execution-spec failures related to SELFDESTRUCT finalization logs in the Amsterdam fork by deferring log emission to transaction cleanup time and recomputing the bloom filter afterward.

Changes:

  • Changed selfdestruct tracking from Set<PrefixedHexString> to Map<PrefixedHexString, PrefixedHexString> (address → beneficiary) across the EVM package
  • Added finalization log emission in processSelfdestructs() to capture residual balance at cleanup time
  • Moved bloom filter generation to after selfdestruct finalization so receipts include finalization logs

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/evm/src/types.ts New SelfdestructMap type; updated selfdestruct field types
packages/evm/src/message.ts Updated selfdestruct field type to SelfdestructMap
packages/evm/src/interpreter.ts Changed selfdestruct from Set to Map, storing beneficiary address
packages/evm/src/evm.ts Updated Set→Map defaults for selfdestruct
packages/evm/src/eip7708.ts New createEIP7708SelfdestructLog helper
packages/evm/src/index.ts Exported new type and eip7708 module
packages/vm/src/runTx.ts Finalization logs in processSelfdestructs, bloom moved after

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

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.24%. Comparing base (186f20d) to head (bd37b21).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 87.33% <ø> (ø)
blockchain 88.85% <ø> (ø)
common 93.44% <ø> (ø)
evm 61.24% <62.50%> (-0.05%) ⬇️
mpt 90.07% <ø> (+0.42%) ⬆️
statemanager 78.10% <ø> (ø)
static 91.35% <ø> (ø)
tx 88.01% <ø> (ø)
util 80.81% <ø> (ø)
vm 55.42% <35.71%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link

📦 Bundle Size Analysis

Package Size (min+gzip) Δ
binarytree 17.5 KB ⚪ ±0%
block 43.7 KB ⚪ ±0%
blockchain 69.8 KB ⚪ ±0%
common 25.4 KB ⚪ ±0%
devp2p 17.7 KB ⚪ ±0%
e2store 87.2 KB ⚪ ±0%
ethash 61.6 KB ⚪ ±0%
evm 62.5 KB 🔴 +0.1 KB (+0.22%)
genesis 272.2 KB ⚪ ±0%
mpt 21.9 KB ⚪ ±0%
rlp 1.7 KB ⚪ ±0%
statemanager 41.3 KB ⚪ ±0%
testdata 43.8 KB ⚪ ±0%
tx 20.8 KB ⚪ ±0%
util 13.1 KB ⚪ ±0%
vm 154.7 KB 🔴 +0.1 KB (+0.08%)
wallet 15.0 KB ⚪ ±0%

Values are minified+gzipped bundles of each package entry. Workspace deps are bundled; external deps are excluded.

Generated by bundle-size workflow

@ScottyPoi ScottyPoi changed the title 7708-fix 7708: SELFDESTRUCT finalization logs Mar 13, 2026
@ScottyPoi ScottyPoi changed the title 7708: SELFDESTRUCT finalization logs 7708 fix: SELFDESTRUCT finalization logs Mar 13, 2026
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.

2 participants