AlertSourceDiscuss
Skip to content
On this page

EIP-6189: Alias Contracts

Allows the creation of contracts that forward calls to other contracts

⚠️ ReviewCore

Peer Review Notice

This EIP is in the process of being peer-reviewed. If you are interested in this EIP, and have feedback to share, please participate using this discussion link. Thank you!

AuthorsGavin John (@Pandapip1)
Created2023-01-10

Abstract

This EIP allows contracts to be turned into "alias contracts" using a magic nonce. Alias contracts automatically forward calls to other contracts.

Motivation

This EIP is not terribly useful on its own, as it adds additional computation and gas costs without any useful side effects. However, in conjunction with another EIP, it can be used to make SELFDESTRUCT compatible with Verkle trees.

Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.

Definitions

A contract is an alias contract if its nonce is 2^64-1, and its contract code is equal to 0x1.

Prerequisites

EIP-6188 MUST be used to protect the magic nonce value of 2^64-1.

Opcode Changes

CALL, CALLCODE, DELEGATECALL, STATICCALL, PAY, and EOA Transactions

The "callee" refers to the account that is being called or being paid.

If the nonce of the callee is 2^64-1, the call is forwarded to the address stored in the 0th storage slot of the callee (as if the callee was the address stored in the 0th storage slot of the callee). This repeats until a non-alias contract is reached. The CALLER remains unchanged.

If there is more than one alias contract in the chain, the original callee and all subsequent callees (except the last one) have their 0th storage slot set to the address of the final non-alias contract. Then, the call is forwarded as usual. This occurs even in a read-only context.

For example, if A is an alias contract that forwards calls to B, which is an alias contract that forwards calls to C, then A's 0th storage slot is set to C's address. Then, the call is forwarded to C.

The CALL, CALLCODE, DELEGATECALL, and STATICCALL opcodes and EOA Transactions MUST cost an 25 gas per account accessed in this manner (including the final one, and including if no aliased accounts were used), in addition to all the regular costs incurred by accessing accounts (see EIP-2929). For every account whose 0th storage slot is updated, those opcodes must also cost an additional 5000 gas.

If an infinite loop occurs, the transaction runs out of gas and reverts.

EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and BALANCE

The "accessed account" refers to the account that is being accessed (i.e. the account whose code is being accessed, or the account whose balance is being accessed).

Similar to the CALL family of opcodes, if the nonce of the accessed account is 2^64-1, the accessed account is replaced with the address stored in the 0th storage slot of the accessed account. This repeats until a non-alias contract is reached.

If there is more than one alias contract in the chain, the original accessed account and all subsequent accessed accounts (except the last one) have their 0th storage slot set to the address of the final non-alias contract. Then, the accessed account is replaced as usual.

The EXTCODEHASH, EXTCODECOPY, EXTCODESIZE, and BALANCE opcodes MUST cost an 25 gas per account accessed in this manner (including the final one, and including if no aliased accounts were used), in addition to all the regular costs incurred by accessing accounts (see EIP-2929). For every account whose 0th storage slot is updated, those opcodes must also cost an additional 5000 gas.

If an infinite loop occurs, the transaction runs out of gas and reverts.

CREATE and CREATE2

If CREATE or CREATE2 would fail because there is already a an account at the address, and that contract's code is 0x1, and its nonce is 2^64-1, then instead of failing, an attempt should be made to create a contract at the address stored in the 0th storage slot of the existing contract. This repeats until a non-alias contract is reached, at which point either the creation succeeds, or it fails because there is already an account at the address.

Regardless of if creation succeeds, if there is more than one alias contract in the chain, the original accessed account and all subsequent accessed accounts (except the last one) have their 0th storage slot set to the address of the final non-alias contract. Then, the accessed account is replaced as usual.

The CREATE and CREATE2 opcodes MUST cost an 25 gas per account accessed in this manner (including the final one, and including if no aliased accounts were used), in addition to all the regular costs incurred by accessing accounts (see EIP-2929). For every account whose 0th storage slot is updated, those opcodes must also cost an additional 5000 gas.

If an infinite loop occurs, the transaction runs out of gas and reverts.

RPC Endpoint Changes

eth_getStorageAt

The eth_getStorageAt RPC endpoint must error if the target contract has a contract code of 0x1 and a nonce of 2^64-1.

Rationale

The additional gas cost of 25 represents the cost of fetching the nonce and comparing it to the given value.

eth_getStorageAt was modified to throw an error because of alias contracts' special behavior.

The nonce of 2^64-1 was chosen since it is the nonce protected by EIP-6188.

The contract code of 0x1 was chosen arbitrarily. A nonzero code was chosen just in case a non-alias contract with nonce 2^64-1 somehow had its code set to 0x0, or an EOA had its nonce set to 2^64-1.

Backwards Compatibility

This EIP requires a protocol upgrade, since it modifies consensus rules. No existing contracts should be affected, as they will not have a nonce of 2^64-1, nor will they have the contract code 0x1.

Security Considerations

The additional gas costs may cause potential DoS attacks if they access an arbitrary contract's data or make frequent contract deactivations. Contract authors must be aware and design contracts accordingly. There may be an effect on existing deployed code performing autonomous destruction and revival.

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Gavin John, "EIP-6189: Alias Contracts[DRAFT]," Ethereum Improvement Proposals, no. 6189, 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6189.