Skip to content

fix(statedb)!: handle empty-runtime EIP-6780 SELFDESTRUCT - #1270

Open
pamla9 wants to merge 2 commits into
cosmos:mainfrom
pamla9:fix/eip6780-empty-runtime-selfdestruct
Open

pamla9 wants to merge 2 commits into
cosmos:mainfrom
pamla9:fix/eip6780-empty-runtime-selfdestruct

Conversation

@pamla9

@pamla9 pamla9 commented Aug 25, 2026

Copy link
Copy Markdown

Description

This addresses the empty-runtime edge case reported in #1269.

StateDB already tracks whether an account became a contract in the current transaction through newContract. The commit path now uses that fact when deleting a self-destructed account. Newly created contracts use a dedicated keeper method that does not require runtime code to have been persisted first. Existing DeleteAccount callers continue to require the persisted-contract check.

This replaces the existing persist-before-delete path with an explicit deletion path for contracts created in the current transaction. Code presence is no longer used as a proxy for same-transaction creation.

The integration test pre-funds the sender's next CREATE address, deploys init code that immediately executes SELFDESTRUCT, and checks that:

  • the creation transaction succeeds
  • the new account is removed
  • its balance reaches the beneficiary

The statedb.Keeper interface and the expected keeper interfaces gain DeleteNewContractAccount. The existing DeleteAccount signature and behavior are unchanged.

This is a source-level breaking change for downstream applications that implement the affected keeper interfaces. They need to add DeleteNewContractAccount. The method is intended to be called only after StateDB has established that the account became a contract in the current transaction.

Review

The main behavior change is in:

  • x/vm/statedb/statedb.go, where newContract selects the deletion path;
  • x/vm/keeper/statedb.go, where both deletion paths share the same cleanup but only an already-persisted contract requires the code check; and
  • tests/integration/x/vm/test_state_transition.go, which exercises the full transaction and block-commit path.

Focused verification:

go test -tags=test ./x/vm/statedb -run 'TestStateDBTestSuite/TestDBError$' -count=1

go test -tags=test ./tests/integration/x/vm \
  -run 'TestKeeperTestSuite/(TestApplyTransactionWithPreFundedEmptyRuntimeSelfDestruct|TestCommitIdempotencyWithSelfDestruct|TestDeleteAccount)$' \
  -count=1

Closes: #1269

@pamla9
pamla9 marked this pull request as ready for review August 25, 2026 04:02
@pamla9
pamla9 requested a review from a team as a code owner August 25, 2026 04:02
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.46%. Comparing base (3e646c4) to head (eb83e84).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1270   +/-   ##
=======================================
  Coverage   67.45%   67.46%           
=======================================
  Files         320      320           
  Lines       23457    23463    +6     
=======================================
+ Hits        15823    15829    +6     
  Misses       6455     6455           
  Partials     1179     1179           
Files with missing lines Coverage Δ
x/vm/keeper/statedb.go 92.88% <100.00%> (+0.22%) ⬆️
x/vm/statedb/statedb.go 77.23% <100.00%> (+0.50%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

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.

[Bug] EIP-6780 SELFDESTRUCT fails for pre-funded contracts with empty runtime code

1 participant