EIP-6190 SELFDESTRUCT redesign for Verkle trees (Verkle-compatible SELFDESTRUCT)
No call decision · EVM & execution · EIP status Stagnant · created 2022-12-20
Instead of SELFDESTRUCT wiping out the contract and all of its storage slots at once, it changes only the code, nonce, and a single storage slot to fixed values and moves only the balance, capping the number of state changes at a fixed amount.
Why it is needed
Right now SELFDESTRUCT has a fixed gas cost even though the number of storage keys that actually need to be erased varies per contract and has no limit. In the Verkle tree to be introduced in the future, an account's code, nonce, and storage slots are each stored scattered under independent keys, so there is no way to enumerate all the keys that were used. This means the current SELFDESTRUCT behavior of erasing every storage slot a contract has used cannot be implemented as-is under Verkle trees. This EIP is preparatory work that fixes the state SELFDESTRUCT changes to exactly one code, one nonce, and one storage slot, so that it continues to work correctly once the transition to Verkle trees happens.
What changes
Today
- When SELFDESTRUCT is called, the contract account and all of its storage slots are deleted in their entirety
- The gas cost is fixed, but the number of storage keys that actually need to be erased is unlimited
- Under Verkle trees there is no way to find all the keys that were used, so this deletion behavior cannot be implemented
After EIP-6190
- When SELFDESTRUCT is called, the contract's code changes to 0x1 and its nonce changes to the fixed value 2^64-1
- Only storage slot 0 is written, recording the address the contract would have received if it had been created via CREATE
- The full balance is transferred to the address on top of the stack, and the state changes are limited to these few items
- The gas cost is a base of 5000 plus 5000 for each alias contract the call was forwarded through
Who is affected
- Smart contract developers: After SELFDESTRUCT, the contract's address still holds code 0x1, nonce 2^64-1, and the value in slot 0, so any logic written on the assumption that it "disappears completely and leaves nothing behind" needs to be revisited.
- Client and protocol teams: Because the state changes SELFDESTRUCT makes become finite, the scope of work becomes predictable when transitioning to Verkle trees.
- Wallet and explorer developers: Display logic needs to account for the fact that a self-destructed contract remains as an account with code 0x1 and a specific nonce.
In depth
SELFDESTRUCT's new behavior
Instead of the contract disappearing immediately when the transaction ends, the state changes in the following order. First, the code is set to 0x1 and the nonce to 2^64-1. Next, storage slot 0 records the address that would have been issued had the CREATE opcode been used (keccak256(contractAddress, nonce), where nonce is always 2^64-1). If the call was routed through one or more alias contracts, the same address is also recorded in slot 0 of those alias contracts. Then the contract's entire balance is transferred to the address on top of the stack. Finally, the value on top of the stack is popped.
Why the address is computed the same way as CREATE
The address recorded in slot 0 is keccak256(contractAddress, nonce), the same formula the CREATE opcode uses to determine a new contract's address. The Rationale explains this as a deliberate choice "to reduce the attack surface by not introducing a new mechanism for creating accounts at arbitrary addresses."
Gas cost calculation
The base gas cost of SELFDESTRUCT is 5000. An additional 5000 is added for each alias contract through which the call was forwarded, and finally the gas cost increase from EIP-2929 is applied. According to the Rationale, the base value of 5000 reflects the cost of setting an account nonce and one storage slot at index 0.
Why the fixed values 0x1 and 2^64-1 were chosen
The nonce is fixed at 2^64-1 because that is the nonce value protected by EIP-6188, and the code is fixed at 0x1 because that is the code value specified by EIP-6189. In other words, rather than defining a new special value of its own, this EIP simply reuses the values already defined by the two preceding EIPs.
Prerequisite EIPs
For this EIP to work correctly, EIP-6188 and EIP-6189 must both be applied alongside it. Each of those two EIPs defines the meaning of a special value, nonce 2^64-1 and code 0x1 respectively, and this EIP is responsible for actually writing those values upon SELFDESTRUCT.
Backward compatibility, and what's still unresolved
This EIP changes consensus rules and therefore requires a protocol upgrade (hard fork). The original status is Stagnant, and the Security Considerations section only states 'Needs discussion,' meaning the security review has not yet been completed. There is no record in call notes of a decision to include this EIP in any specific fork.