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
- Contract code size is capped at 24576 bytes (EIP-170)
- Functionality beyond the limit must be split across multiple sub-contracts
- Splitting increases the burden of development, deployment, and maintenance
After EIP-5027
- The code size limit disappears, leaving only the block gas limit
- CREATE/CREATE2 spend extra gas (CREATE_DATA_GAS) proportional to the bytes over the limit
- EXTCODECOPY/CALL-type opcodes spend extra gas (COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT) only on cold access
- A contract already accessed within the same transaction can be called again without extra gas
Who is affected
- Smart contract developers: Large contracts can be deployed without splitting them into multiple sub-contracts, reducing the burden that used to come with splitting.
- Client (node) development teams: Must implement a mapping from code hash to size so that CODESIZE/EXTCODESIZE can be looked up in O(1), and must revise the gas calculation for CREATE and CALL-type opcodes.
- Wallet and app developers who call other contracts: The first cold call to a large contract may incur extra gas, so gas estimation logic must account for this.
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.