Remove the limit on contract code size
The purpose of EIP-5027 is to remove the limit on contract code size in Ethereum and only limit it by block gas limit, with minimal changes to existing code and proper gas metering adjustment to avoid possible attacks. It aims to address the issues with the current limit on contract code size by allowing users to deploy larger contracts without having to split them into several sub-contracts, which can increase the burden of developing, deploying, and maintaining smart contracts.
Remove the limit on the contract code size, i.e., only limit the contract code size by block gas limit, with minimal changes to existing code and proper gas metering adjustment to avoid possible attacks.
The motivation is to remove the limit on the code size so that users can deploy a large-code contract without worrying about splitting the contract into several sub-contracts.
With the dramatic growth of dApplications, the functionalities of smart contracts are becoming more and more complicated, and thus, the sizes of newly developed contracts are steadily increasing. As a result, we are facing more and more issues with the 24576-bytes contract size limit. Although several techniques such as splitting a large contract into several sub-contracts can alleviate the issue, these techniques inevitably increase the burden of developing/deploying/maintaining smart contracts.
The proposal implements a solution to remove the existing 24576-bytes limit of the code size. Further, the proposal aims to minimize the changes in the client implementation (e.g., Geth) with
- proper gas metering to avoid abusing the node resources for contract-related opcodes, i.e,
CODESIZE (0x38)/CODECOPY (0x39)/EXTCODESIZE (0x3B)/EXTCODECOPY (0x3C)/EXTCODEHASH (0x3F)/DELEGATECALL (0xF4)/CALL (0xF1)/CALLCODE (0xF2)/STATICCALL (0xFA)/CREATE (0xF0)/CREATE2 (0xF5); and
- no change to the existing structure of the Ethereum state.
block.number >= FORK_BLKNUM, the contract creation initialization can return data with any length, but the contract-related opcodes will take extra gas as defined below:
CODESIZE/CODECOPY/EXTCODESIZE/EXTCODEHASH, the gas is unchanged.
For CREATE/CREATE2, if the newly created contract size >
CODE_SIZE_UNIT, the opcodes will take extra write gas as
(CODE_SIZE - CODE_SIZE_UNIT) * CREATE_DATA_GAS.
EXTCODECOPY/CALL/CALLCODE/DELEGATECALL/STATICCALL, if the contract code size >
CODE_SIZE_UNIT, then the opcodes will take extra gas as
(CODE_SIZE - 1) // CODE_SIZE_UNIT * COLD_ACCOUNT_CODE_ACCESS_COST_PER_UNIT
if the contract is not in
0 if the contract is in
// is the integer divide operator, and
accessed_code_in_addresses: Set[Address] is a tranasction-context-wide set similar to
When a transactoin execution begins,
accessed_code_in_addresses will include
tx.to, and all precompiles.
CREATE/CREATE2/EXTCODECOPY/CALL/CALLCODE/DELEGATECALL/STATICCALL is called, immediately add the address to
The goal is to measure the CPU/IO cost of the contract read/write operations reusing existing gas metering so that the resources will not be abused.
For code-size-related opcodes (
EXTCODESIZE), we would expect the client to implement a mapping from the hash of code to the size, so reading the code size of a large contract should still be O(1).
CODECOPY, the data is already loaded in memory (as part of
CALL/CALLCODE/DELEGATECALL/STATICCALL), so we do not charge extra gas.
EXTCODEHASH, the value is already in the account, so we do not charge extra gas.
EXTCODECOPY/CALL/CALLCODE/DELEGATECALL/STATICCALL, since it will read extra data from the database, we will additionally charge
CREATE/CREATE2, since it will create extra data to the database, we will additionally charge
CREATE_DATA_GASper extra bytes.
All existing contracts will not be impacted by the proposal.
Only contracts deployed before EIP-170 could possibly be longer than the current max code size, and the reference implementation was able to successfully import all blocks before that fork.
The reference implementation on Geth is available at 0001-unlimit-code-size.patch.
Copyright and related rights waived via CC0.
Adopted by projects
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