EIP-4760 · Stagnant · Core · 2022-02-03
EIP-4760: SELFDESTRUCT bomb
A proposal to neutralise SELFDESTRUCT by doubling its gas cost every ~9 days as a warning, then turning it into SENDALL, which only moves ETH; it was not adopted.
What problem does it solve?
SELFDESTRUCT deletes a contract's code and all of its storage and sends its ETH to a target. Wiping an unbounded amount of state in one opcode is awkward for clients today, and much harder in the planned Verkle tree layout, where an account's data is spread across many keys that are not obviously linked to the account root.
Simply disabling the opcode could surprise developers who do not follow the EIP process. EIP-4760 tries to give them a loud, on-chain warning first: make SELFDESTRUCT steadily more expensive, so anyone whose contract relies on it notices before the behaviour changes.
How it works
Constants from the spec:
| Name | Value | Meaning |
|---|---|---|
OLD_SELFDESTRUCT_COST |
5000 | gas cost at the time |
HARD_FORK_BLOCK |
TBD | activation point |
DOUBLING_SLOTS |
2**16 |
about 9 days per doubling |
DOUBLINGS_BEFORE_SENDALL |
13 | about 4 months in total |
Two phases:
- Bomb phase.
SELFDESTRUCTstill works as before, but its gas cost is5000 * 2 ** ((slot - HARD_FORK_BLOCK) // DOUBLING_SLOTS), doubling every period. - SENDALL phase. After 13 doublings the cost returns to 5000 and the opcode is renamed
SENDALL. It only moves all ETH in the account to the target. Code, storage and nonce are left untouched, and allSELFDESTRUCTrefunds are removed.
Contracts that use SELFDESTRUCT only to sweep out ETH keep working. What breaks is the "metamorphic contract" pattern: destroy, then redeploy different code at the same address with CREATE2.
Sample code
Gas schedule during the bomb phase (pseudocode):
OLD_SELFDESTRUCT_COST = 5000
DOUBLING_SLOTS = 2**16
DOUBLINGS_BEFORE_SENDALL = 13
def selfdestruct_gas(slot, fork_slot):
elapsed = slot - fork_slot
if elapsed >= DOUBLING_SLOTS * DOUBLINGS_BEFORE_SENDALL:
return OLD_SELFDESTRUCT_COST # now behaves as SENDALL
return OLD_SELFDESTRUCT_COST * 2 ** (elapsed // DOUBLING_SLOTS)
# last bomb period: 5000 * 2**12 = 20,480,000 gas
Writing code that does not depend on destruction (works before and after any such change):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// Instead of selfdestruct(payable(owner)) to "close" a contract:
contract Closable {
address public immutable owner = msg.sender;
bool public closed;
function close() external {
require(msg.sender == owner, "not owner");
closed = true;
(bool ok, ) = payable(owner).call{value: address(this).balance}("");
require(ok, "transfer failed");
}
}
Things to know
- Status is Stagnant; this EIP was never activated.
- Ethereum took a different route. EIP-6049 formally deprecated
SELFDESTRUCT, and EIP-6780 (Dencun, 2024) limited it so code and storage are only deleted when the contract is created and destroyed in the same transaction; otherwise it just sends ETH, similar to theSENDALLidea here. - EIP-4758 is a sibling proposal that would have switched to
SENDALLimmediately, without the gas bomb. - The spec mixes "block" and "slot" when defining the activation point; it was never finalised.
- Do not design new contracts around
SELFDESTRUCTfor upgrades; use proxy patterns instead.