EIP-6780 · Final · Core · 2023-03-25
EIP-6780: SELFDESTRUCT only in same transaction
Neuters SELFDESTRUCT: it now only sends the contract's ETH to a target and no longer deletes code or storage, unless the contract was created in the same transaction.
What problem does it solve?
SELFDESTRUCT used to wipe an account completely: its code, every storage slot and the account itself, sending the balance to a chosen address. That is a large, unbounded state change, and it would be very hard to support in future state designs such as Verkle trees, where one account's data is spread across many unrelated keys.
The opcode was already deprecated by EIP-6049. EIP-6780 removes the destructive part while keeping the two common, harmless uses working: pulling all ETH out of a contract, and creating and destroying a contract within a single transaction.
How it works
The behaviour now depends on whether the contract was created in the current transaction.
Contract created in an earlier transaction (the normal case):
- The current execution frame halts.
- The entire balance is transferred to the target.
- Code, storage, nonce and the account itself are not deleted.
- If the target is the contract itself, nothing changes; ETH is no longer burned.
Contract created earlier in the same transaction:
- The old behaviour applies: balance sent to the target, the account and all its data deleted.
- If the target is the contract itself, that ETH is burned, as before.
"Created" means from the start of a contract-creation transaction or when a CREATE / CREATE2 begins executing, even if the address already had a balance. Gas rules from EIP-2929 are unchanged and there is still no refund (removed by EIP-3529).
Sample code
Pseudocode for the new opcode logic:
def selfdestruct(account, target):
balance = state.get_balance(account)
state.add_balance(target, balance)
state.sub_balance(account, balance) # net zero if target == account
if account in tx.created_accounts: # created in this same transaction
state.set_balance(account, 0) # burns ETH if target == account
tx.accounts_to_delete.add(account) # old behaviour: wipe code + storage
halt_frame()
A pattern that no longer works – metamorphic upgrades via CREATE2:
// Before Cancun: selfdestruct, then CREATE2 new code at the same address.
// After EIP-6780: selfdestruct leaves the code in place, so the second
// CREATE2 to that address fails because the account already has code.
function kill() external {
require(msg.sender == owner);
selfdestruct(payable(owner)); // now only moves the ETH out
}
Things to know
- Status: Final. Activated on mainnet in the Cancun/Deneb ("Dencun") upgrade, together with EIP-5656
MCOPY. - Upgrade schemes based on
SELFDESTRUCT+CREATE2redeployment are broken. Use proxy patterns such as ERC-2535 or standard upgradeable proxies. - Contracts that relied on self-targeted
SELFDESTRUCTto burn ETH no longer burn it unless created in the same transaction. SELFDESTRUCTis still deprecated. Solidity emits a warning for it and future upgrades may reduce its functionality further, so do not use it in new code.