fix(database): allow EIP161 state clear for empty Loaded and Changed accounts#3421
Merged
rakita merged 6 commits intobluealloy:mainfrom Feb 23, 2026
Merged
Conversation
Previously, on_touched_empty_post_eip161() panicked with unreachable!() when called on a Loaded AccountStatus. This is reachable when an EOA with balance is loaded from DB, then its balance is drained to zero via a meta-transaction (relayer pays gas, no nonce change). The balance change is tracked in the Journal but CacheAccount::change() is never called, so the CacheAccount status remains Loaded. Allow Loaded → Destroyed unconditionally. This is safe because touch_empty_eip161 is only reachable when account.is_empty() is true, which requires code_hash == KECCAK_EMPTY. A contract in Loaded status cannot reach this path since SELFDESTRUCT (the only way to remove code) is handled by the is_selfdestructed() early return before this point. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
msheth-circle
commented
Feb 12, 2026
rakita
reviewed
Feb 16, 2026
msheth-circle
commented
Feb 17, 2026
msheth-circle
commented
Feb 17, 2026
msheth-circle
commented
Feb 17, 2026
msheth-circle
commented
Feb 17, 2026
msheth-circle
commented
Feb 17, 2026
msheth-circle
commented
Feb 17, 2026
Contributor
Author
|
@rakita Mind taking another look? |
rakita
approved these changes
Feb 23, 2026
Member
|
Merging after CI |
Contributor
Author
|
Thanks @rakita! CI is looking good |
Member
|
Will make release soon, in next few days |
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
on_touched_empty_post_eip161()panic when called on aLoadedAccountStatusLoadedandChanged→Destroyedtransition unconditionallyOn EVM chains where the native token is an ERC20, an EOA can hold the native token (balance > 0, nonce=0, no code) and spend it all as an ERC20 via a meta-transaction (relayer pays gas, no nonce change on the EOA), making the account empty. In this scenario, the account was loaded from DB with
Loadedstatus, and since the balance change is tracked in the Journal — not throughCacheAccount::change()— theCacheAccountstatus remainsLoadedwhentouch_empty_eip161is called.The fix allows
Loaded→Destroyedunconditionally. This is safe becausetouch_empty_eip161is only reachable whenaccount.is_empty()is true on the Journal output, which requires no code (code_hash == KECCAK_EMPTY). A contract inLoadedstatus cannot reach this path — SELFDESTRUCT is the only way to remove code, and it's handled by theis_selfdestructed()early return before this point. This is consistent with geth, which has no status distinction and simply deletes any dirty empty account inFinalise().Test plan
Loaded→Destroyedtransition inon_touched_empty_post_eip161#[should_panic]test confirmingChangedstill panicscargo test -p revm-database— 31 passedcargo nextest run --workspace— 369 passed, 0 failedcargo clippy --workspace --all-targets --all-features— 0 warnings