HomeEIPs
EIPsEIP-5478
EIP-5478

CREATE2COPY Opcode

Reducing the gas cost of contract creation with existing code
StagnantStandards Track: Core
Created: 2022-08-17
Requires: EIP-1014, EIP-2929
Qi Zhou (@qizhou)
DiscussionsOriginal linkEdit
1 min read

The EIP-5478 proposal suggests adding a new opcode called CREATE2COPY, which is similar to CREATE2 but can potentially have a much lower gas cost by accepting an additional argument of an existing contract address that already stores the code of the new contract. This can reduce the smart contract creation cost of account abstraction contracts that have identical code. The proposal also includes specifications for parameters and security considerations.

Video
Anyone may contribute to propose contents.
Go propose
Original

Abstract

Adding a new opcode, CREATE2COPY, that is identical to CREATE2 but with potentially much lower gas cost by accepting an additional argument existing_contract_address that already stored the code of the new contract.

Motivation

This EIP aims to reduce the smart contract creation cost of account abstraction (AA) contracts that have identical code.

The major cost of creating an AA contract is the contract creation cost, especially data gas. For example, creating an AA contract with 10,000 bytes will consume 2,000,000 data gas. Considering the code for each user's AA contract is the same, CREATE2COPY can reduce the data gas cost to 2600 (cold account) or even 100 (warm account) if the contract code already exists in the local storage.

Specification

Parameters

ConstantValue
FORK_BLKNUMTBD
CREATE_DATA_GAS_PER_BYTE200
COLD_ACCOUNT_ACCESS_COST2600
WARM_ACCOUNT_ACCESS_COST100

If block.number >= FORK_BLKNUM, a new opcode is added (CREATE2COPY) at 0xf6, which takes 5 stack arguments: endowment, memory_start, memory_length, salt, existing_contract_address. CREATE2COPY behaves identically to CREATE2 (0xf5 as defined in EIP-1014), except that the code hash of the creating contract MUST be the same as that of existing_contract_address.

CREATE2COPY has the same gas schema as CREATE2, but replacing the data gas from CREATE_DATA_GAS_PER_BYTE * CONTRACT_BYTES to the gas cost of EXTCODEHASH opcode, which is COLD_ACCOUNT_ACCESS_COST if the existing_contract_address is first-time accessed in the transaction or WARM_ACCOUNT_ACCESS_COST if existing_contract_address is already in the access list according to EIP-2929.

If the code of the contract returned from the init code differs from that of existing_contract_address, the creation fails with the error "mismatched contract creation code with existing code", and will burn all gas for the contract creation.

Rationale

TBD

Security Considerations

Needs discussion.

Copyright and related rights waived via CC0.

Further reading
Anyone may contribute to propose contents.
Go propose
Adopted by projects
Anyone may contribute to propose contents.
Go propose

Not miss a beat of EIPs' update?

Subscribe EIPs Fun to receive the latest updates of EIPs Good for Buidlers to follow up.

View all
Serve Ethereum Builders, Scale the Community.
Resources
GitHub
Supported by