HomeEIPsNewsletter
EIPsEIP-7907
EIP-7907

Meter Contract Code Size And Increase Limit

Increases the contract code size limit introduced in EIP-170 and adds a gas metering to code loading
DraftStandards Track: Core
Created: 2025-03-14
Requires: EIP-170, EIP-2929, EIP-3860, EIP-7702
Charles Cooper (@charles-cooper), Qi Zhou (@qizhou), Matt (@lightclient), Dragan Rakita (@rakita)
Discussions ForumOriginal Proposal LinkEdit
1 min read
Anyone may contribute to propose contents.
Go propose
Video
Anyone may contribute to propose contents.
Go propose
Original

Abstract

This EIP substantially increases the contract code size limit from 24KB (24576 bytes) introduced in EIP-170 to 48KB (49152 bytes), and adds gas metering. It introduces a gas cost of 4 gas per (32 byte) word for contract code exceeding 24KB, allowing deployment of contracts of any size while preventing DoS attacks through appropriate gas metering. Lastly, it also commensurately increases initcode size limit from 48KB, introduced in EIP-3860, to 96KB (98304 bytes).

Motivation

EIP-170 introduced a 24KB contract code size limit to prevent potential DoS attacks, as large contract code requires O(n) resource cost in terms of disk reads, VM preprocessing, and Merkle proof sizes, all of which are not directly compensated by gas fees. However, this limit restricts legitimate use cases for large contracts.

This EIP proposes a gas-based solution that allows contracts of larger size while ensuring that users loading large contracts pay gas proportional to the additional resources they consume. This approach aligns with Ethereum's gas model philosophy of paying for the resources consumed. A new limit has been set at 48KB, so that raising the gas limit does not break assumptions in the p2p layer.

Improving developer experience is the primary motivation for increasing the contract size limit. The current 24KB ceiling forces developers to split functionality across multiple contracts, introduce proxies or delegatecall-based indirection, and rely on architectural patterns like the Diamond Standard—even when those patterns aren't otherwise necessary. These workarounds can increase code complexity, deployment costs, and audit surface. By raising the limit, developers can keep more logic in a single contract, improving readability and lowering gas usage by avoiding unnecessary cross-contract calls. This also makes smart contract development more accessible to newer developers, who can move from idea to deployment without first learning advanced contract composition patterns.

Specification

Definitions

NameValueDescription
COLD_SLOAD_COST2100The cost charged for cold loading storage as defined by EIP-2929.
WARM_STORAGE_READ_COST100The cost charged for loading warm storage as defined by EIP-2929.
COLD_ACCOUNT_ACCESS_COST2600The cost charged for loading a cold account as defined by EIP-2929.
GAS_PER_CODE_WORD4The cost charged per word of code loaded beyond the intial 24KB amount.

Helpers

def ceil32(n: int) -> int: return ((n + 31) // 32) * 32 def excess_code_size(n: int) -> int: return max(0, contract_size - 0x6000)

Behavior

  1. Update the EIP-170 contract code size limit of 24KB (0x6000 bytes) to 48KB (0xc000 bytes).
  2. Introduces a new cold/warm state for contract code. Specifically, change the gas schedule of operations that load code, e.g. the opcodes CALL, STATICCALL, DELEGATECALL, CALLCODE and EXTCODECOPY are modified so that flat COLD_SLOAD_COST=2100 and dynamic EXCESS_CODE_COST= ceil32(excess_code_size(len(code))) * GAS_CODE_LOAD_WORD_COST // 32 gas are added to the access cost if the code is cold. When the code is an EIP-7702 delegation to another account, if target account code is cold add additional gas should be accounted. Warming of the contract code is subjected to the journaling and can be reverted similar to other state warming in EIP-2930.
  3. The cost for EXTCODESIZE is updated to acknowlege the potential for two database reads: once for the account (making it warm) and second for code size if bytecode is marked as cold. Bytecode will not be marked as warm as only codesize is read. In addition to the current pricing scheme defined under EIP-2929, the instruction will also be subject to the COLD_SLOAD_COST=2100 if code is cold.
  4. Update the EIP-3860 contract initcode size limit of 48KB (0xc000 bytes) to 96KB (0x18000 bytes).
  5. If a large contract is the entry point of a transaction, the cost calculated in (2) is charged before the execution and contract code is marked as warm. This fee is not calculated towards the initial gas fee. In case of out-of-gas halt, execution will stop and the balance will not be transferred.
ContractGas changes (only opcodes that load code)How?
Cold account and codeAdd COLD_SLOAD_COST=2100, EXCESS_CODE_COST, and COLD_ACCOUNT_ACCESS_COST=2600Contract not in access list nor accessed prior in the txn
Warm account and cold codeAdd COLD_SLOAD_COST=2100, EXCESS_CODE_COST, and WARM_STORAGE_READ_COST=100Already accessed balance, storage, or included in access list (EIP-2930)
Warm account and codeWARM_STORAGE_READ_COST=100Already accessed account code

COLD_ACCOUNT_ACCESS_COST, COLD_SLOAD_COST, and WARM_STORAGE_READ_COST are defined in EIP-2929.

Rationale

The gas cost of 4 per word was chosen in-line with the per word code defined by EIP-2929's COLD_ACCOUNT_ACCESS_COST. The value is derived from the current gas per word code of ceil(2600 / (24676//32)) = 4 where 2600 is the current cold account load cost and 24676 is the maximum allow code size at that price. In general, this accounts for:

  1. The additional disk I/O for retrieving larger contract code
  2. The increased computational resources for preprocessing larger code for execution (a.k.a. "JUMPDEST analysis").
  3. The growth in Merkle proof sizes for blocks containing very large contracts

This EIP introduces the gas cost as an additional cost for contracts exceeding 24KB. It could have been specified as a simpler ceil32(contract_size) * 4 // 32, without hardcoding the existing contract size limit. However, for the sake of being conservative and avoiding lowering the cost of loading existing contracts (which could be small, under the 24KB limit), the 24KB floor was added to the formula.

The EXTCODECOPY opcode could theoretically be exempt from this, since clients could just load the parts of the bytecode which are actually requested. However, this might require a change at the protocol level, since the full code is required for the block witness. For this reason, EXTCODECOPY is included in the pricing scheme, and a carveout could be considered at a later date.

The new limit has been set at 48KB. The limit has been put in place so that increasing the gas limit won't have unexpected side effects at the db or p2p layer. For instance, in devp2p, the maximum packet size is 10MB (https://github.com/ethereum/devp2p/blob/5713591d0366da78a913a811c7502d9ca91d29a8/caps/eth.md#basic-operation). As of time of this writing, the maximum packet size in snap sync is even lower, at 96KB.

The limit for initcode has also been increased to 96KB, following the pattern set in EIP-3860 that the initcode limit is double the runtime code limit. While initcode is different from deployed code in that it does not live in the state and therefore isn't visible in devp2p or in the db, fully removing the limit could have unforeseen consequences.

Backwards Compatibility

This EIP is backward compatible with existing contracts. All contracts that were valid before this EIP will remain valid after it, and their gas costs will not change.

The only change is that new contracts larger than 24KB will be allowed, whereas they were previously rejected regardless of available gas.

Test Cases

Reference Implementation

Security Considerations

Clients should add an efficient way to determine the code size without loading the entire code, e.g. storing it in a separate table keyed by code hash. This way, they can charge for the access cost before physically loading the code. Otherwise, a client may load a contract, even when there is not enough gas left to pay for the code load.

Copyright and related rights waived via CC0.

Further reading
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