---
eip: 3860
label: EIP-3860
title: Limit and meter initcode
status: Final
type: Standards Track
category: Core
created: 2021-07-16
requires: 170
official: https://eips.ethereum.org/EIPS/eip-3860
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3860.md
canonical: https://eips.huatuo.xyz/eip-3860/
lang: en
tldr: Caps contract initcode at 49,152 bytes and charges 2 gas per 32-byte word of it, so the work clients do analysing deployment code is bounded and paid for.
tags: [evm, gas, contract-creation, initcode, core, shanghai]
---

# EIP-3860: Limit and meter initcode

> Limit the maximum size of initcode to 49152 and apply extra gas cost of 2 for every 32-byte chunk of initcode

**TL;DR:** Caps contract initcode at 49,152 bytes and charges 2 gas per 32-byte word of it, so the work clients do analysing deployment code is bounded and paid for.

## What problem does it solve?

When a contract is created, the EVM runs its **initcode** (constructor plus the code to be deployed). Before running it, a client must do jumpdest analysis over the whole initcode, work that scales with its length. Before this EIP that work was neither limited nor metered:

- A create *transaction* paid calldata gas for initcode, but `CREATE` and `CREATE2` called from a contract paid nothing proportional to initcode size (except `CREATE2`'s hashing cost).
- There was no protocol cap on initcode size, which made worst-case analysis hard and complicated several other EVM proposals.

EIP-3860 adds both a size limit and a per-word charge. It went live in the Shanghai upgrade (2023).

## How it works

Two parameters:

| Constant | Value |
| --- | --- |
| `MAX_INITCODE_SIZE` | `2 * MAX_CODE_SIZE` = 49152 bytes ([EIP-170](/eip-170/) sets `MAX_CODE_SIZE` = 24576) |
| `INITCODE_WORD_COST` | 2 gas per 32-byte word |

`initcode_cost(initcode) = 2 * ceil(len(initcode) / 32)`

Rules:

1. **Create transactions** with initcode larger than `MAX_INITCODE_SIZE` are invalid and cannot be included in a block.
2. Create transactions add `initcode_cost` to their **intrinsic gas**, so a transaction that cannot cover it is invalid.
3. `CREATE` / `CREATE2` with initcode over the limit **abort exceptionally**, as if out of gas.
4. `CREATE` / `CREATE2` charge `initcode_cost` up front, before computing the new address and running the initcode. For `CREATE2` this sits alongside its existing 6 gas/word hashing cost ([EIP-1014](/eip-1014/)), so it now pays 8 gas per word in total.

The limit also means code size, `PC` and jump offsets all fit in 16 bits, a simplification for EVM implementations.

## Sample code

The extra cost and limit check, as a client would compute them:

```python
MAX_CODE_SIZE = 24576
MAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE   # 49152
INITCODE_WORD_COST = 2

def initcode_cost(initcode: bytes) -> int:
    return INITCODE_WORD_COST * ((len(initcode) + 31) // 32)

def check_create(initcode: bytes) -> int:
    if len(initcode) > MAX_INITCODE_SIZE:
        raise Exception("exceptional abort: initcode too large")
    return initcode_cost(initcode)

print(initcode_cost(b"\x00" * 49152))  # 3072 gas at the maximum size
```

A pre-deployment check in a script (ethers v6):

```ts
import { ContractFactory, getBytes } from "ethers";

const tx = await factory.getDeployTransaction(...args); // factory: ContractFactory
const size = getBytes(tx.data!).length;
if (size > 49152) throw new Error(`initcode is ${size} bytes; limit is 49152`);
```

## Things to know

- **Status: Final**, active on mainnet since Shanghai.
- For a normal deployment the limit leaves room for a full 24 KB runtime contract plus an equally large constructor. Factories that embed several contracts' bytecode in one initcode are the most likely to hit it.
- An oversized create *transaction* is rejected outright; an oversized `CREATE`/`CREATE2` inside execution only fails that call (consuming its gas), and the outer transaction can still be included.
- The cost for create transactions is tiny next to calldata pricing (4/16 gas per byte); it was included mainly for consistency and future extensibility.
- Already deployed contracts are unaffected.


---

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