---
eip: 7907
label: EIP-7907
title: Meter Contract Code Size
status: Draft
type: Standards Track
category: Core
created: 2025-03-14
requires: 170, 2929, 7702, 7954
official: https://eips.ethereum.org/EIPS/eip-7907
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7907.md
canonical: https://eips.huatuo.xyz/eip-7907/
lang: en
tldr: Charges extra gas, 2 per 32-byte word, for loading contract code beyond 24 KB, so the larger contracts allowed by EIP-7954 pay for the extra disk reads and analysis they cause.
tags: [gas, contract-size, evm, core]
---

# EIP-7907: Meter Contract Code Size

> Adds gas metering to contract code loading beyond 24KB

**TL;DR:** Charges extra gas, 2 per 32-byte word, for loading contract code beyond 24 KB, so the larger contracts allowed by EIP-7954 pay for the extra disk reads and analysis they cause.

## What problem does it solve?

Since [EIP-170](/eip-170/), contract code has been capped at 24 KB (24,576 bytes). The cap exists because loading code costs nodes work that gas does not reflect: reading it from disk, running JUMPDEST analysis, and including it in proofs. The cost grows with size, but a `CALL` costs the same whether the target is 1 KB or 24 KB.

[EIP-7954](/eip-7954/) raises the cap to 64 KB for code and 128 KB for initcode. EIP-7907 adds the matching gas charge, so callers of large contracts pay in proportion to the extra bytes. Contracts at or below 24 KB cost nothing extra.

## How it works

- **Code becomes warm or cold**, like accounts and storage slots in [EIP-2929](/eip-2929/). The first time code is loaded in a transaction it is cold; after that it is warm.
- When an opcode that loads code (`CALL`, `STATICCALL`, `DELEGATECALL`, `CALLCODE`, `EXTCODECOPY`) touches **cold** code, it adds:

  ```
  EXCESS_CODE_COST = ceil32(max(0, len(code) - 24576)) * 2 // 32
  ```

  plus `COLD_SLOAD_COST` (2100) for the code access, on top of the usual account access cost.
- If the account is warm but its code is cold, the account part is the warm cost (100) instead of 2600.
- If the transaction's entry point is a large contract, the excess cost is charged before execution and the code is marked warm. This charge is not part of intrinsic gas.
- Calls to an [EIP-7702](/eip-7702/) delegated account also pay for the delegation target's code if it is cold.
- Warming is journaled and reverts like other state warming. Empty code is always warm.

To price this cheaply, the account tuple gains a `codesize` field, written for any account created or updated after the fork. For older accounts, clients get the size from the bytecode itself.

## Sample code

The extra charge in Python, following the spec's helpers:

```python
GAS_PER_CODE_WORD = 2
LIMIT = 0x6000  # 24,576 bytes

def ceil32(n: int) -> int:
    return ((n + 31) // 32) * 32

def excess_code_cost(code_len: int) -> int:
    excess = max(0, code_len - LIMIT)
    return ceil32(excess) * GAS_PER_CODE_WORD // 32

print(excess_code_cost(24_576))  # 0     (no change for today's contracts)
print(excess_code_cost(32_768))  # 512
print(excess_code_cost(65_536))  # 2560  (largest code under EIP-7954)
```

So the first cold call into a full 64 KB contract costs 2,560 gas more for code size, plus the separate cold code access charge.

## Things to know

- **Status: Draft.** Values and details may change, and the spec's test cases and security sections are still empty.
- The 24 KB floor is deliberate: it avoids making existing small contracts cheaper or more expensive because of size.
- `EXTCODECOPY` is charged too, even though in theory a client could load only the requested slice; a carve-out may come later.
- Wallets and `eth_estimateGas` need to account for the new charges. A transaction that touches several large cold contracts can need noticeably more gas.
- Adding an address to an [EIP-2930](/eip-2930/) access list warms the account, not the code; the code cost is still paid on first load.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7907
