EIPs Explained

EIP-2937 · Stagnant · Core · 2020-09-04

EIP-2937: SET_INDESTRUCTIBLE opcode

A stagnant proposal for a SET_INDESTRUCTIBLE opcode (0xA8) that lets a contract permanently opt out of SELFDESTRUCT, so libraries can guarantee their code will never disappear.

What problem does it solve?

When this was written, any contract containing a reachable SELFDESTRUCT (directly, or through a DELEGATECALL into code that self-destructs) could wipe its own code. That is a problem for anything that other contracts depend on:

  • A shared library called via DELEGATECALL could vanish, bricking every contract that uses it.
  • Account-abstraction designs want wallets to rely on code that will "exist unmodified forever".

Auditing that no path leads to SELFDESTRUCT is error-prone. EIP-2937 offers a simple, verifiable promise instead: put one opcode at the very start of your code and self-destruction becomes impossible. Unlike proposals that disable SELFDESTRUCT for everyone, it changes nothing for existing contracts.

How it works

  • A new transaction-wide set globals.indestructible is added, starting empty (it works like the existing set of self-destructed accounts).
  • New opcode SET_INDESTRUCTIBLE at 0xA8, costing G_base (2 gas), adds the current executing account (callee) to that set.
  • If SELFDESTRUCT runs while the current callee is in the set, it throws an exception.

The intended pattern is that the first byte of the contract's code is 0xA8, so every execution marks it indestructible before anything else happens.

A global set is used rather than a per-frame flag because a local flag could be bypassed: the contract could DELEGATECALL into other code that then self-destructs in the contract's context.

Sample code

Illustrative bytecode for a contract whose runtime begins with the proposed opcode (0xA8 is not assigned on mainnet):

A8          SET_INDESTRUCTIBLE   ; mark this account for the rest of the tx
60 00       PUSH1 0x00
35          CALLDATALOAD
...                              ; normal contract logic
33          CALLER
FF          SELFDESTRUCT         ; would now throw instead of deleting the code

Pseudocode of the rule:

def op_set_indestructible(ctx):
    ctx.tx.indestructible.add(ctx.callee)

def op_selfdestruct(ctx, beneficiary):
    if ctx.callee in ctx.tx.indestructible:
        raise ExceptionalHalt("indestructible")
    ...  # usual SELFDESTRUCT behaviour

Things to know

  • Status: Stagnant. It was never adopted.
  • Ethereum instead neutralised SELFDESTRUCT for everyone: since the Cancun upgrade, EIP-6780 only deletes code when the contract was created in the same transaction. In other cases it just sends the ETH balance. Deprecation was signalled in EIP-6049, and EIP-4758 proposed turning it into SENDALL.
  • The spec notes that if SELFDESTRUCT is removed, this opcode simply becomes a no-op. It also notes a tension with state-rent schemes that would delete old contracts.

#core #evm #opcode #selfdestruct #stagnant

Details

Authors
Vitalik Buterin (@vbuterin)
Status
Stagnant
Type
Standards Track / Core
Created
2020-09-04

Machine-readable: Markdown · JSON