Alert Source Discuss
⚠️ Draft Standards Track: Core

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

Authors Charles Cooper (@charles-cooper), Qi Zhou (@qizhou)
Created 2025-03-14
Discussion Link https://ethereum-magicians.org/t/eip-remove-contract-size-limit/23156
Requires EIP-170

Abstract

This EIP substantially increases the hard contract code size limit from 24KB (24576 bytes) introduced in EIP-170 to 256KB, and adds gas metering. It introduces a gas cost of 2 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.

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 any size while ensuring that users loading very 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 256KB, so that raising the gas limit does not break assumptions in the p2p layer.

Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.

  1. Update the EIP-170 contract code size limit of 24KB (0x6000 bytes) to 256KB (0x20000 bytes).
  2. Change the gas schedule for opcodes which load code. Specifically, the CALL, STATICCALL, DELEGATECALL, CALLCODE and EXTCODECOPY opcodes are modified so that ceil32(excess_contract_size) * 2 // 32 gas is added to the cold access cost, where excess_contract_size = max(0, contract_size - 0x6000). (Cf. initcode metering: EELS). If the account is warm, no change to the gas schedule occurs.

Rationale

The gas cost of 2 per word was chosen in-line with EIP-3860. 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) * 2 // 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 256KB. This is significantly larger than the limit implied by the current block gas limit of 35mm (~170KB). 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 512KB.

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.

Citation

Please cite this document as:

Charles Cooper (@charles-cooper), Qi Zhou (@qizhou), "EIP-7907: Meter Contract Code Size And Increase Limit [DRAFT]," Ethereum Improvement Proposals, no. 7907, March 2025. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7907.