EIP-6189 Alias contract (Alias Contracts)

No call decision · EVM & execution · EIP status Stagnant · created 2022-12-20

Defines an account whose nonce is 2^64-1 and whose code is 0x1 as an 'alias contract,' so that calls, lookups, and creation targeting it are automatically forwarded to the address written in storage slot 0. Used together with EIP-6190 as a replacement for SELFDESTRUCT under Verkle trees.

Why it is needed

This EIP is useless on its own. The source text itself notes that it only adds extra computation and gas cost. However, it explains that combined with EIP-6190 it can replace SELFDESTRUCT under Verkle trees. In the EVM today, a contract's address is fixed, and there is no standard way to permanently hand off calls from one contract to another. An alias contract marks an account as 'forwarding-only to another address' by setting its nonce to 2^64-1 and its code to 0x1, and changes the CALL-family, lookup-family, and CREATE-family opcodes, along with the entire transaction validation step, to interpret this automatically. The magic nonce value 2^64-1 must be separately protected by EIP-6188.

What changes

Today

After EIP-6189

Who is affected

In depth

Definition and prerequisites of an alias contract

This EIP defines an account as an 'alias contract' when its nonce is 2^64-1 and its contract code is exactly 0x1. An alias contract automatically forwards calls not to itself but to the address stored in storage slot 0. It states that this magic nonce value (2^64-1) must be separately protected by EIP-6188 so that a normal account cannot accidentally or maliciously reach this value. The code value 0x1 was chosen arbitrarily, but a nonzero value was chosen to filter out cases where a non-alias contract's code happens to become 0x0 while its nonce is 2^64-1, or where an EOA's nonce is somehow set to 2^64-1.

Forwarding in CALL-family opcodes and EOA transactions

In CALL, CALLCODE, DELEGATECALL, STATICCALL, PAY, and transactions sent by an EOA, if the callee's nonce is 2^64-1, the call is forwarded to the address written in that account's storage slot 0. This process repeats until a non-alias contract is reached, with CALLER staying as the original caller throughout. If the chain contains two or more alias contracts, the slot 0 of every intermediate contract except the last is updated to the final address, and this update must occur even in a read-only context such as STATICCALL. For each account accessed this way (including the final account), an extra 25 gas is added on top of EIP-2929's base access cost, and 5000 gas is added for each account whose slot is updated. If the chain forms an infinite loop, the transaction reverts due to running out of gas.

EXTCODEHASH·EXTCODECOPY·EXTCODESIZE·BALANCE

The opcodes EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and BALANCE, which look up code or balance, follow the same rule. If the nonce of the accessed account is 2^64-1, the access target is switched to the address written in that account's slot 0, and this repeats until a non-alias contract is reached. The slot 0 of intermediate contracts in the chain is updated to the final address, and this also happens in a read-only context. The gas cost structure is the same as the CALL-family: an extra 25 gas per access and 5000 gas per slot update.

Handling in CREATE and CREATE2

When CREATE or CREATE2 attempts to create a contract at an address that already holds an account with code 0x1 and nonce 2^64-1 (a situation that would originally have been treated as a creation failure or revert), creation is instead attempted at the address written in that account's slot 0. This process also repeats until a non-alias contract is reached, and the slot 0 of intermediate contracts is updated to the final address. In the end, the address of the newly created contract is returned as usual. The gas cost is the same as for other opcodes: 25 gas per access and 5000 gas per slot update.

The ADDRESS opcode and transfers to the zero address

The ADDRESS opcode is unchanged. That is, ADDRESS still returns the account's actual address, prior to alias resolution, without requiring the nonce to be anything other than 2^64-1. The source text also states that a transfer to the zero address has the same effect as the CREATE opcode and incurs the same extra gas cost as CREATE processing.

Origin resolution in transaction validation and eth_getStorageAt

If the nonce of the transaction's origin is 2^64-1, the origin is replaced with the address written in that account's slot 0, and this repeats until a non-alias contract is reached. The slot 0 of intermediate accounts in the chain is updated to the final address, after which validation proceeds as usual. This process also adds 25 gas per access and 5000 gas per slot update to the validation cost. On the RPC side, eth_getStorageAt is changed to return an error if the target contract's code is 0x1 and its nonce is 2^64-1.

Gas costs and rationale for design choices

The source explains that the added 25 gas represents the cost of fetching the nonce and comparing it against 2^64-1. It states that the reason eth_getStorageAt was changed to an error is the aliased contract's special behavior. The magic nonce 2^64-1 was chosen because it is the value protected by EIP-6188, and the contract code 0x1 was chosen arbitrarily, but as a nonzero value to guard against the edge case where a non-aliased contract whose nonce happens to be 2^64-1 ends up with code 0x0, or an EOA's nonce is set to 2^64-1.

Backwards Compatibility, Security Considerations, Current Status

This EIP states that it changes consensus rules and therefore requires a protocol upgrade. However, it notes that no existing contract has a nonce of 2^64-1 or code of 0x1, so existing deployed contracts are unaffected. Under security considerations, it states that the added gas cost could enable DoS attacks if contracts frequently access arbitrary contract data or deactivate contracts, so contract authors must account for this when designing. It also notes that this could affect existing deployed code that autonomously self-destructs and respawns. The current status of this EIP is Stagnant, it lists EIP-2929 and EIP-6188 as requires, and the provided material contains no fork-inclusion decision or call record for the co-designed EIP-6190.

Original EIP · ← EIPs