EIP-5027 Removing the contract code size limit (Remove the limit on contract code size)

No call decision · EVM & execution · EIP status Stagnant · created 2022-04-21

A proposal to remove the existing limit (EIP-170) that caps Ethereum contract code size at 24576 bytes, leaving only the block gas limit as a constraint, while charging gas for reading and writing large contracts.

Why it is needed

Ethereum currently limits contract code size to 24576 bytes under EIP-170. However, as dApp functionality grows more complex, newly created contracts keep growing larger, and more cases are hitting this limit. Developers work around it by splitting large contracts into multiple smaller sub-contracts, which increases the burden of development, deployment, and maintenance. This proposal removes the cap on code size itself and instead charges extra gas on opcodes that read or write large contracts, to prevent node resources from being abused, while keeping the existing client architecture and state structure unchanged as much as possible.

What changes

Today

After EIP-5027

Who is affected

In depth

Core change: replacing the code size cap with gas

The 24576-byte contract code size cap set by EIP-170 is removed, and contract size is instead constrained only by the block gas limit. After FORK_BLKNUM, contract creation (initcode) can return code of any length, but if the code size exceeds CODE_SIZE_UNIT (24576 bytes), related opcodes deduct extra gas.

CREATE/CREATE2 extra gas

If a newly created contract's size exceeds CODE_SIZE_UNIT, extra gas is spent equal to the number of bytes over the limit multiplied by CREATE_DATA_GAS (200 per byte). The formula is (CODE_SIZE - CODE_SIZE_UNIT) * CREATE_DATA_GAS. This reflects the cost of writing more code into the database.

EXTCODECOPY/CALL-type extra gas and cold/warm access

EXTCODECOPY, CALL, CALLCODE, DELEGATECALL, and STATICCALL deduct extra gas equal to (CODE_SIZE - 1) // CODE_SIZE_UNIT * COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT (2600) when the target contract's code size exceeds CODE_SIZE_UNIT and its address is not yet in accessed_code_in_addresses (cold). If the address is already accessed (warm), the extra gas is 0. accessed_code_in_addresses is a transaction-scoped set similar to access_addresses in EIP-2929: at the start of a transaction it includes tx.sender, tx.to, and all precompiles, and the relevant address is added immediately whenever CREATE/CREATE2/EXTCODECOPY/CALL-type opcodes are invoked.

Cases where no extra gas is charged

CODESIZE and EXTCODESIZE keep their existing gas cost, since once a client implements a mapping from code hash to size, size lookups remain O(1) even for large contracts. CODECOPY also incurs no extra gas, since it copies data already loaded into memory during a CALL/CALLCODE/DELEGATECALL/STATICCALL. EXTCODEHASH likewise incurs no extra gas, since that value is already stored in account data.

No change to state structure, compatible with past blocks

This proposal does not change the existing structure of Ethereum's state. Already-deployed contracts are unaffected, and only contracts deployed before EIP-170 that exceed the current maximum size would fall within its scope; the reference implementation imported all blocks before that fork without issue.

Open items and current status

This EIP's status is Stagnant, the FORK_BLKNUM value remains TBD, and the Security Considerations section is likewise marked only TBD. Since inclusion in a fork, specific figures, and the results of a security review have not been finalized, the content of this article is independent of actual adoption status and may change.

Original EIP · ← EIPs