Skip to content

fix(evm-rpc): a refilled account's repeated selfdestruct is not a stale entry - #703

Merged
abernatskiy merged 3 commits into
masterfrom
fix/selfdestruct-refilled-repeat
Dec 4, 2026
Merged

abernatskiy merged 3 commits into
masterfrom
fix/selfdestruct-refilled-repeat

Conversation

@abernatskiy

@abernatskiy abernatskiy commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #681. Thanks to @pisqual for the report and the suggested rule.

Problem

findDefectiveSelfdestructs flagged every selfdestruct frame that repeats an earlier value movement as a possible stale-entry (a revm-based tracer reading an old journal entry). Ethereum mainnet block 26486365, tx 0x2bd9…e5f0, has a contract funded with the same amount before each of several selfdestructs. Frames 2/0, 3/0 and 4/0 repeat 1/0 and are genuine: the beneficiary's balance rises by exactly the sum of all five frame values. The block passes only if an opcode trace confirms them. Where the upstream serves neither the built-in opcode logger nor custom JS tracers, it is rejected on every retry, in every callFrameValidation mode.

Fix

A stale frame carries the newest journal entry. So if the executing account was credited after the matched movement, the credit is newer and the frame cannot be a stale copy of that movement. A repeat is now suspect only when:

  • the executing account was not credited after the matched movement, or
  • the movement is another account's (unchanged: a credit to the executor does not explain it).

Three kinds of frame do not count as credits, because counting them would let a genuinely stale frame through:

  • DELEGATECALL: tracers report the caller's value on it, but it never reaches the account the frame names;
  • CALLCODE: the value stays in the caller;
  • a call an account makes to itself: it changes no balance and records no journal entry. Credits undone by a failed frame already drop out of the movement list.

Tests

  • New fixture complete/mainnet-refilled-repeat.json: the transaction's call tree, its block header with only this transaction, and the beneficiary's balances before and after. The test checks that the frames sum to the balance change.
  • Guard tests, which pass on master and keep passing:
    • a repeat with no credit, or only a zero-value one, stays suspect;
    • so does a repeat after a DELEGATECALL/CALLCODE "credit", after a call the account makes to itself, after a credit undone by a failed frame, or after a credit to another account;
    • so does a repeat of another account's movement.
  • RPC level: the block is accepted in off and observe with no opcode trace available. On master it fails with the rejection from the issue.
  • mainnet-legitimate-repeat-reth.json (the same pattern, an earlier block) is no longer flagged. Its repair test now states the defect explicitly.
  • Every recorded defective frame from real nodes is still flagged.

The five behaviour tests fail on master and pass here; the full evm-rpc suite passes (668).

🤖 Generated with Claude Code

…le entry

The stale-entry check suspected every selfdestruct frame that repeats an
earlier value movement. A revm-based tracer misreports a frame with the newest
journal entry, so a movement of the executing account that was followed by a
credit to that account cannot be what a stale frame carries. A contract funded
with the same amount before each sweep repeats genuinely, and the block was
rejected on every retry wherever the upstream served no opcode trace to settle
it (Ethereum mainnet 26486365).

A repeat is now suspect only when the executing account was not credited after
the matched movement. DELEGATECALL and CALLCODE frames do not count as credits:
they report a value that never reaches the account they name. A repeat of
another account's movement stays suspect.

Reported in #681.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical bug treats nonzero self-calls as balance credits, allowing stale SELFDESTRUCT transfers to evade detection and skip recovery.

1 open issue
What changed in this PR

Addresses #681 by allowing legitimate repeated SELFDESTRUCT transfers after an account is refilled, avoiding unnecessary block rejection in evm-rpc.

Changes:

  • Makes stale-entry detection account for intervening credits.
  • Adds mainnet regression coverage and guards against invalid credits.
  • Records the fix for a patch release.
File Description
evm/​evm-rpc/​test/​selfdestruct.test.ts Tests refill handling and stale-entry guards.
evm/​evm-rpc/​test/​rpc.debug-frames.test.ts Checks block acceptance without opcode traces.
evm/​evm-rpc/​test/​fixtures/​selfdestruct/​complete/​mainnet-refilled-repeat.json Adds the reported mainnet transaction fixture.
evm/​evm-rpc/​src/​verification.ts Tracks credits when evaluating repeated movements.
common/​changes/​@subsquid/​evm-rpc/​fix-selfdestruct-refilled-repeat_2026-12-05-00-00.json Adds a patch release note.

Review effort: Balanced

Comment thread evm/evm-rpc/src/verification.ts Resolved
A transfer from an account to itself changes no balance and records no journal
entry, so a stale frame after it still reads the earlier movement. Counting it
as a credit let such a frame through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The zero-value check misses padded encodings such as 0x00, allowing a stale SELFDESTRUCT to escape defect detection and opcode recovery without a refill.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Recognize padded zero hex values during SELFDESTRUCT recovery

evm/​evm-rpc/​src/​verification.ts:2086

DebugFrame.value accepts arbitrary hex bytes (rpc-data.ts:597), including zero encoded as 0x00, but zeroValue only recognizes 0x0 and 0x. Consequently, E→B(v), O→E(0x00), then a stale SELFDESTRUCT reporting E→B(v) now returns no defect and skips opcode recovery despite no refill occurring. Recognize every all-zero hex encoding and add a padded-zero regression case.

1 resolved since last review

Review effort: Balanced

Debug frame values are validated as hex bytes only, so zero can arrive as
`0x00`. Read as a nonzero value it counted as a credit and cleared a stale
frame of suspicion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@abernatskiy

Copy link
Copy Markdown
Contributor Author

(With Claude): Re the review's "previously missed issue" (padded zero values): valid. DebugFrame.value is validated as hex bytes, so 0x00 can arrive, and with this PR it would have counted as a credit. Any all-zero hex now reads as zero, and the zero-credit guard test covers 0x0, 0x, 0x00 and 0x0000; it fails on 0x00 without the fix. Fixed in 38960a0.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change allowing repeated selfdestruct transfers after genuine account refills.

No open issues 🎉

Review effort: Balanced

@abernatskiy
abernatskiy merged commit 3349042 into master Dec 4, 2026
3 checks passed
@abernatskiy
abernatskiy deleted the fix/selfdestruct-refilled-repeat branch December 4, 2026 16:59
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.

evm-rpc: stale-entry selfdestruct check rejects valid blocks when the account is refilled with the same amount

2 participants