EIP-2937 SET_INDESTRUCTIBLE opcode

No call decision · EVM & execution · EIP status Stagnant · created 2020-09-04

EIP-2937 is a proposal that adds a new opcode preventing a contract from using SELFDESTRUCT on itself, guaranteeing that its code can never change.

Why it is needed

Currently, a smart contract can delete itself using the SELFDESTRUCT opcode. In cases such as account abstraction, where other contracts depend on a given contract as if it were a shared library, that dependency cannot be trusted if there is a risk the code could disappear or change partway through. The text notes that banning SELFDESTRUCT outright would cause major backward compatibility problems with existing contracts, and instead proposes adding a new opcode that lets a contract voluntarily declare that it will never self-destruct. This way, the behavior of existing contracts is left completely unchanged, while it becomes possible to create library contracts guaranteed to exist forever.

What changes

Today

After EIP-2937

Who is affected

In depth

Opcode definitions

SET_INDESTRUCTIBLE is added as opcode value 0xA8 with a gas cost of G_base. Executing this opcode adds the address of the currently executing contract (the callee) to globals.indestructible, a transaction-wide global variable. A contract uses this by placing the opcode as the first byte of its code, so that it executes first on every call and registers itself in the set.

The global state globals.indestructible

globals.indestructible: Set[Address] is a transaction-scoped global variable that behaves the same way as the selfdestructs set, and is reset to an empty set at the start of every transaction. This means that even if a contract registers itself as indestructible, the effect is valid only within that transaction, and SET_INDESTRUCTIBLE must be executed again in the next transaction.

Condition for blocking SELFDESTRUCT

If the callee is present in globals.indestructible within the same execution context, the SELFDESTRUCT opcode fails by throwing an exception. If a contract places SET_INDESTRUCTIBLE at the start of its code, it registers itself in the set the moment it is called, and any attempt to execute SELFDESTRUCT later in that same call is blocked.

Design rationale: a global variable instead of a local variable

The original text explains why a global variable was used instead of a local variable. If indestructibility were stored as a local variable, this guarantee could be broken because code invoked via DELEGATECALL executes in the caller's context. For this reason, the proposal adopts the same global-variable approach as the selfdestructs set.

Alternative: banning SELFDESTRUCT outright

The original text explains that banning the SELFDESTRUCT opcode entirely would be ideal, but poses major backward compatibility problems with existing contracts. Instead, this EIP adds an opcode that lets a contract opt in to blocking its own self-destruction, leaving the behavior of existing contracts completely unchanged.

Security considerations

This proposal notes that it could break forward compatibility with some state rent approaches that delete old contracts if their maintenance fees go unpaid. However, it explains that this is not an issue for other state-size management approaches such as ReGenesis. It also notes that if the SELFDESTRUCT opcode is ever removed entirely in the future, this EIP becomes a meaningless no-op.

Current status

This EIP's status is Stagnant, and its Backwards Compatibility section is left as TBD, meaning detailed review has not yet concluded. No call records show a decision to include this EIP in a fork.

Original EIP · ← EIPs