EIPs Explained

EIP-6049 · Final · Meta · 2022-11-27

EIP-6049: Deprecate SELFDESTRUCT

A Meta EIP that formally deprecated the SELFDESTRUCT opcode and warned developers that its behaviour would change, which EIP-6780 later did in the Cancun upgrade.

What problem does it solve?

SELFDESTRUCT deletes a contract's code and storage and sends its ETH to a beneficiary. Core developers had long wanted to change or remove it. It complicates client design and stateless-Ethereum plans, and it lets a contract be destroyed and redeployed with different code at the same address (via CREATE2). But many contracts relied on it, and every year without a warning made any eventual change more disruptive.

EIP-6049 changes nothing in the protocol. It is the official notice: do not use SELFDESTRUCT; a breaking change is coming. Developers got a clear signal before the actual change landed.

How it works

  • Documentation of the opcode (including non-normative text in the Yellow Paper) is updated to mark it deprecated and to warn of a future breaking change.
  • No client changes: the opcode kept working exactly as before when this EIP was accepted.
  • Compiler tooling followed suit. Solidity emits a deprecation warning for selfdestruct starting with 0.8.18.

What happened next: EIP-6780, activated in the Cancun upgrade (March 2024), restricted SELFDESTRUCT. It now only deletes the account if called in the same transaction the contract was created. Otherwise it just sends the contract's ETH to the beneficiary and leaves code and storage in place.

Sample code

Patterns that relied on SELFDESTRUCT, and what to do instead:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Legacy {
    address immutable owner = msg.sender;

    // DEPRECATED: after EIP-6780 this no longer deletes code or storage
    // (unless called in the creating transaction). It only moves the ETH.
    function kill() external {
        require(msg.sender == owner);
        selfdestruct(payable(owner)); // compiler warning since 0.8.18
    }
}

contract Modern {
    address immutable owner = msg.sender;
    bool public disabled;

    // Prefer an explicit "off switch" plus a normal withdrawal.
    function disable() external {
        require(msg.sender == owner);
        disabled = true;
        (bool ok, ) = owner.call{value: address(this).balance}("");
        require(ok);
    }

    modifier whenEnabled() { require(!disabled, "disabled"); _; }
}

Things to know

  • Status: Final. Type: Meta. It is a documentation and process change only.
  • Do not design upgrade schemes around "selfdestruct then redeploy with CREATE2" (metamorphic contracts). Since Cancun this no longer works outside the creation transaction.
  • Sending ETH via SELFDESTRUCT still bypasses the recipient's receive/fallback. Contracts should never assume their balance only changes through their own functions.
  • Earlier proposals to neuter the opcode include EIP-4758 (Stagnant). EIP-3529 had already removed the gas refund for SELFDESTRUCT in the London upgrade.

#selfdestruct #opcode #deprecation #meta #evm

Details

Authors
William Entriken (@fulldecent)
Status
Final
Type
Meta
Created
2022-11-27

Machine-readable: Markdown · JSON