EIP-6190 · Stagnant · Core · 2022-12-20
EIP-6190: Verkle-compatible SELFDESTRUCT
A stagnant proposal to make SELFDESTRUCT touch a fixed, small amount of state, turning the contract into a forwarding stub instead of wiping all its storage, so it could work with Verkle trees.
What problem does it solve?
SELFDESTRUCT deletes a contract's code, balance and all of its storage for a fixed gas price. The amount of work is unbounded: a contract with millions of storage slots costs the same to destroy as an empty one.
That becomes a real obstacle with Verkle trees, the planned state structure in which every storage slot is its own key. Clients would not be able to enumerate and delete every key belonging to an account. EIP-6190 proposed a version of SELFDESTRUCT that changes only a bounded number of values, as a step toward Verkle compatibility.
How it works
Instead of deleting the contract at the end of the transaction, the opcode would:
- Set the contract's code to
0x1and its nonce to2^64-1. - Write into storage slot
0the address that aCREATEfrom this contract would produce with that nonce. - If the call reached the contract through one or more alias contracts, write that same address into each alias's slot
0. - Send the whole balance to the beneficiary address on the stack, as today.
The code 0x1 and maximal nonce come from the companion proposals EIP-6189 (alias contracts that forward calls) and EIP-6188 (nonce cap). The effect is that the old account becomes an alias pointing at a fresh address, so a later redeployment effectively starts from empty storage, without having to erase the old slots.
Gas: a base cost of 5,000, plus 5,000 per alias contract the call passed through, plus the EIP-2929 cold-access surcharge. The 5,000 figures reflect the cost of setting the nonce and slot 0.
Sample code
Pseudocode for the proposed end-of-transaction handling:
MAX_NONCE = 2**64 - 1
def apply_selfdestruct(state, contract, beneficiary, alias_chain):
state.set_code(contract, b"\x01") # mark as alias (EIP-6189)
state.set_nonce(contract, MAX_NONCE) # protected nonce (EIP-6188)
new_addr = create_address(contract, MAX_NONCE) # same rule as CREATE
state.set_storage(contract, 0, new_addr)
for alias in alias_chain: # contracts that forwarded the call
state.set_storage(alias, 0, new_addr)
state.add_balance(beneficiary, state.get_balance(contract))
state.set_balance(contract, 0)
def selfdestruct_gas(alias_chain, beneficiary_is_cold):
return 5000 + 5000 * len(alias_chain) + (2600 if beneficiary_is_cold else 0)
Things to know
- Status: Stagnant. It was never scheduled for a network upgrade, and its Security Considerations section still reads "Needs discussion".
- It only works together with EIP-6188 and EIP-6189, which are themselves non-final proposals.
- Ethereum took a different route: EIP-6780 (Cancun) restricts
SELFDESTRUCTso it only deletes an account when called in the same transaction that created it; otherwise it just sends the balance. - The cold-access figure in the sample reflects EIP-2929's usual 2,600 surcharge for a cold account and is illustrative.