EIPs Explained

EIP-6046 · Stagnant · Core · 2022-11-25

EIP-6046: Replace SELFDESTRUCT with DEACTIVATE

A stagnant proposal to turn SELFDESTRUCT into DEACTIVATE: keep the account and its storage, zero the balance, and mark it with a special nonce, so the opcode no longer has to delete an unbounded amount of state.

What problem does it solve?

SELFDESTRUCT used to delete a contract's code and all of its storage for a fixed gas price. The amount of work it caused was unbounded, because a contract can have any number of storage slots. It also clashes with Verkle trees, where each storage slot has its own key and there is no practical way to find and delete every key an account used.

Many proposals simply removed the deletion. EIP-6046 tried a middle path that keeps the "destroy and later re-deploy at the same address" pattern working, without having to wipe storage.

How it works

  • The account nonce limit from EIP-2681 is lowered by one, to 2^64-2, so that 2^64-1 becomes a free marker value (applied from genesis).
  • SELFDESTRUCT, renamed DEACTIVATE, now:
    • sends the balance to the beneficiary and sets the account's balance to 0;
    • does not delete code or storage; the account stays in place;
    • sets the nonce to 2^64-1, marking the account as deactivated.
  • Calling a deactivated account (by transaction or CALL*) succeeds immediately and returns empty data. It can still receive plain ETH transfers.
  • CREATE2 is allowed onto an account whose nonce is 2^64-1. The new code replaces the old, but old storage is still there.
  • No gas refund is given (refunds for it were already removed by EIP-3529), and EIP-2929 access rules are unchanged.

The rename signals that "revival" no longer gives you a clean slate.

Sample code

Pseudocode for the proposed behaviour:

DEACTIVATED = 2**64 - 1

def op_deactivate(evm, beneficiary):
    acct = evm.state[evm.address]
    evm.state[beneficiary].balance += acct.balance
    acct.balance = 0
    acct.nonce = DEACTIVATED        # code and storage are left untouched

def execute_call(state, addr, ...):
    if state[addr].nonce == DEACTIVATED:
        return Success(output=b"")  # value transfers still credited

def create2_allowed(state, addr):
    a = state[addr]
    return a.nonce == DEACTIVATED or (a.nonce == 0 and not a.code)

A contract meant to be revived under this rule would have to treat existing storage as possibly stale:

// On re-deploy, slots written by the previous incarnation may still be set.
uint256 public generation;
function init() external { generation += 1; /* key new data by generation */ }

Things to know

  • Status: Stagnant. It was never scheduled for a network upgrade.
  • Ethereum instead adopted EIP-6780 (Dencun upgrade): SELFDESTRUCT only deletes an account if it is called in the same transaction that created the contract; otherwise it just sends the balance. A related earlier idea is EIP-4758.
  • If something like this were adopted, contracts that self-destruct and redeploy would need to cope with leftover storage, which the spec flags as a security concern.

#selfdestruct #evm #opcode #state #verkle #core

Details

Authors
Alex Beregszaszi (@axic)
Status
Stagnant
Type
Standards Track / Core
Created
2022-11-25
Requires

Machine-readable: Markdown · JSON