{"eip":3860,"title":"Limit and meter initcode","description":"Limit the maximum size of initcode to 49152 and apply extra gas cost of 2 for every 32-byte chunk of initcode","authors":["Martin Holst Swende (@holiman)","Paweł Bylica (@chfast)","Alex Beregszaszi (@axic)","Andrei Maiboroda (@gumb0)"],"status":"Final","type":"Standards Track","category":"Core","created":"2021-07-16","requires":[170],"discussionsTo":"https://ethereum-magicians.org/t/eip-3860-limit-and-meter-initcode/7018","repo":"EIPs","label":"EIP-3860","officialUrl":"https://eips.ethereum.org/EIPS/eip-3860","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3860.md","url":"https://eips.huatuo.xyz/eip-3860/","tldr":{"en":"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.","ja":"コントラクトの initcode を 49,152 バイトに制限し、32 バイトのワードごとに 2 gas を課すことで、クライアントがデプロイコードの分析に費やす作業に上限を設け、その対価が支払われるようにする。","ko":"컨트랙트 initcode를 49,152바이트로 제한하고 32바이트 워드당 2 gas를 부과해, 클라이언트가 배포 코드를 분석하는 작업에 상한을 두고 그 대가가 지불되게 한다.","zh":"把合约 initcode 限制在 49,152 字节，并对其每 32 字节字收取 2 gas，使客户端分析部署代码所做的工作有上限且有偿。"},"tags":["evm","gas","contract-creation","initcode","core","shanghai"],"explainers":{"en":{"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"],"related":[170,1014,3855,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3860/","markdown":"## What problem does it solve?\n\nWhen 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:\n\n- 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).\n- There was no protocol cap on initcode size, which made worst-case analysis hard and complicated several other EVM proposals.\n\nEIP-3860 adds both a size limit and a per-word charge. It went live in the Shanghai upgrade (2023).\n\n## How it works\n\nTwo parameters:\n\n| Constant | Value |\n| --- | --- |\n| `MAX_INITCODE_SIZE` | `2 * MAX_CODE_SIZE` = 49152 bytes ([EIP-170](/eip-170/) sets `MAX_CODE_SIZE` = 24576) |\n| `INITCODE_WORD_COST` | 2 gas per 32-byte word |\n\n`initcode_cost(initcode) = 2 * ceil(len(initcode) / 32)`\n\nRules:\n\n1. **Create transactions** with initcode larger than `MAX_INITCODE_SIZE` are invalid and cannot be included in a block.\n2. Create transactions add `initcode_cost` to their **intrinsic gas**, so a transaction that cannot cover it is invalid.\n3. `CREATE` / `CREATE2` with initcode over the limit **abort exceptionally**, as if out of gas.\n4. `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.\n\nThe limit also means code size, `PC` and jump offsets all fit in 16 bits, a simplification for EVM implementations.\n\n## Sample code\n\nThe extra cost and limit check, as a client would compute them:\n\n```python\nMAX_CODE_SIZE = 24576\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE   # 49152\nINITCODE_WORD_COST = 2\n\ndef initcode_cost(initcode: bytes) -\u003e int:\n    return INITCODE_WORD_COST * ((len(initcode) + 31) // 32)\n\ndef check_create(initcode: bytes) -\u003e int:\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise Exception(\"exceptional abort: initcode too large\")\n    return initcode_cost(initcode)\n\nprint(initcode_cost(b\"\\x00\" * 49152))  # 3072 gas at the maximum size\n```\n\nA pre-deployment check in a script (ethers v6):\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst tx = await factory.getDeployTransaction(...args); // factory: ContractFactory\nconst size = getBytes(tx.data!).length;\nif (size \u003e 49152) throw new Error(`initcode is ${size} bytes; limit is 49152`);\n```\n\n## Things to know\n\n- **Status: Final**, active on mainnet since Shanghai.\n- 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.\n- 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.\n- 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.\n- Already deployed contracts are unaffected.\n"},"ja":{"lang":"ja","tldr":"コントラクトの initcode を 49,152 バイトに制限し、32 バイトのワードごとに 2 gas を課すことで、クライアントがデプロイコードの分析に費やす作業に上限を設け、その対価が支払われるようにする。","tags":["evm","gas","contract-creation","initcode","core","shanghai"],"related":[170,1014,3855,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3860/","markdown":"## 何を解決するのか\n\nコントラクトが作成されるとき、EVM はその **initcode**（コンストラクタとデプロイされるコード）を実行します。実行する前に、クライアントは initcode 全体について jumpdest 分析を行う必要があり、この作業は長さに比例して増えます。この EIP 以前は、その作業は制限もメータリングもされていませんでした。\n\n- create *トランザクション*は initcode に対して calldata ガスを支払いましたが、コントラクトから呼ばれる `CREATE` と `CREATE2` は、（`CREATE2` のハッシュコストを除き）initcode のサイズに比例する支払いが一切ありませんでした。\n- initcode のサイズにプロトコル上の上限がなく、最悪ケースの分析が難しく、他のいくつかの EVM 提案も複雑になっていました。\n\nEIP-3860 は、サイズ制限とワードごとの課金の両方を追加します。Shanghai アップグレード（2023 年）で稼働しました。\n\n## 仕組み\n\n2 つのパラメーターがあります。\n\n| 定数 | 値 |\n| --- | --- |\n| `MAX_INITCODE_SIZE` | `2 * MAX_CODE_SIZE` = 49152 バイト（[EIP-170](/eip-170/) が `MAX_CODE_SIZE` = 24576 を定める） |\n| `INITCODE_WORD_COST` | 32 バイトのワードあたり 2 gas |\n\n`initcode_cost(initcode) = 2 * ceil(len(initcode) / 32)`\n\nルール:\n\n1. initcode が `MAX_INITCODE_SIZE` を超える **create トランザクション**は無効であり、ブロックに含めることはできません。\n2. create トランザクションは `initcode_cost` を**固有ガス**に加えるため、それを賄えないトランザクションは無効です。\n3. 制限を超える initcode での `CREATE` / `CREATE2` は、ガス切れのように**例外的に中断**します。\n4. `CREATE` / `CREATE2` は、新しいアドレスの計算と initcode の実行に先立って、`initcode_cost` を最初に課します。`CREATE2` の場合、これは既存のワードあたり 6 gas のハッシュコスト（[EIP-1014](/eip-1014/)）に加算されるため、合計でワードあたり 8 gas を支払うことになります。\n\nこの制限により、コードサイズ、`PC`、ジャンプオフセットがすべて 16 ビットに収まるようになり、EVM の実装が簡単になります。\n\n## サンプルコード\n\n追加コストと制限チェックを、クライアントが計算するとおりに表したもの:\n\n```python\nMAX_CODE_SIZE = 24576\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE   # 49152\nINITCODE_WORD_COST = 2\n\ndef initcode_cost(initcode: bytes) -\u003e int:\n    return INITCODE_WORD_COST * ((len(initcode) + 31) // 32)\n\ndef check_create(initcode: bytes) -\u003e int:\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise Exception(\"exceptional abort: initcode too large\")\n    return initcode_cost(initcode)\n\nprint(initcode_cost(b\"\\x00\" * 49152))  # 3072 gas at the maximum size\n```\n\nスクリプトでのデプロイ前チェック（ethers v6）:\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst tx = await factory.getDeployTransaction(...args); // factory: ContractFactory\nconst size = getBytes(tx.data!).length;\nif (size \u003e 49152) throw new Error(`initcode is ${size} bytes; limit is 49152`);\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final**。Shanghai 以降、メインネットで有効です。\n- 通常のデプロイでは、この制限は 24 KB のランタイムコントラクトと、同じ大きさのコンストラクタを含められる余裕を残しています。複数のコントラクトのバイトコードを 1 つの initcode に埋め込むファクトリは、これに最も引っかかりやすいでしょう。\n- サイズ超過の create *トランザクション*は即座に拒否されます。実行中のサイズ超過の `CREATE`/`CREATE2` はその呼び出しが失敗する（ガスを消費する）だけで、外側のトランザクションは引き続き含めることができます。\n- create トランザクションのコストは、calldata の価格設定（1 バイトあたり 4/16 gas）に比べて小さく、主に一貫性と将来の拡張性のために含められました。\n- すでにデプロイされたコントラクトには影響しません。\n"},"ko":{"lang":"ko","tldr":"컨트랙트 initcode를 49,152바이트로 제한하고 32바이트 워드당 2 gas를 부과해, 클라이언트가 배포 코드를 분석하는 작업에 상한을 두고 그 대가가 지불되게 한다.","tags":["evm","gas","contract-creation","initcode","core","shanghai"],"related":[170,1014,3855,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3860/","markdown":"## 어떤 문제를 해결하나요?\n\n컨트랙트가 생성될 때 EVM은 **initcode**(생성자와 배포될 코드)를 실행합니다. 실행하기 전에 클라이언트는 initcode 전체에 대해 jumpdest 분석을 해야 하고, 이 작업은 길이에 비례해 늘어납니다. 이 EIP 이전에는 그 작업이 제한도 계량도 되지 않았습니다.\n\n- create *트랜잭션*은 initcode에 대해 calldata 가스를 냈지만, 컨트랙트에서 호출하는 `CREATE`와 `CREATE2`는(`CREATE2`의 해싱 비용을 제외하면) initcode 크기에 비례하는 비용을 전혀 내지 않았습니다.\n- initcode 크기에 프로토콜 차원의 상한이 없어 최악의 경우를 분석하기 어려웠고, 다른 여러 EVM 제안도 복잡해졌습니다.\n\nEIP-3860은 크기 제한과 워드당 요금을 모두 추가합니다. Shanghai 업그레이드(2023년)에서 적용되었습니다.\n\n## 어떻게 동작하나요?\n\n파라미터는 두 가지입니다.\n\n| 상수 | 값 |\n| --- | --- |\n| `MAX_INITCODE_SIZE` | `2 * MAX_CODE_SIZE` = 49152바이트([EIP-170](/eip-170/)이 `MAX_CODE_SIZE` = 24576으로 정함) |\n| `INITCODE_WORD_COST` | 32바이트 워드당 2 gas |\n\n`initcode_cost(initcode) = 2 * ceil(len(initcode) / 32)`\n\n규칙:\n\n1. initcode가 `MAX_INITCODE_SIZE`보다 큰 **create 트랜잭션**은 무효이며 블록에 포함될 수 없습니다.\n2. create 트랜잭션은 `initcode_cost`를 **고유 가스**에 더하므로, 이를 감당하지 못하는 트랜잭션은 무효입니다.\n3. 제한을 넘는 initcode로 `CREATE` / `CREATE2`를 하면 가스가 부족한 것처럼 **예외적으로 중단**됩니다.\n4. `CREATE` / `CREATE2`는 새 주소를 계산하고 initcode를 실행하기 전에 `initcode_cost`를 먼저 부과합니다. `CREATE2`의 경우 이는 기존의 워드당 6 gas 해싱 비용([EIP-1014](/eip-1014/))과 함께 적용되므로, 이제 총 워드당 8 gas를 냅니다.\n\n이 제한 덕분에 코드 크기, `PC`, 점프 오프셋이 모두 16비트에 들어가며, EVM 구현이 단순해집니다.\n\n## 샘플 코드\n\n추가 비용과 제한 검사를 클라이언트가 계산하는 방식대로 나타낸 것:\n\n```python\nMAX_CODE_SIZE = 24576\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE   # 49152\nINITCODE_WORD_COST = 2\n\ndef initcode_cost(initcode: bytes) -\u003e int:\n    return INITCODE_WORD_COST * ((len(initcode) + 31) // 32)\n\ndef check_create(initcode: bytes) -\u003e int:\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise Exception(\"exceptional abort: initcode too large\")\n    return initcode_cost(initcode)\n\nprint(initcode_cost(b\"\\x00\" * 49152))  # 3072 gas at the maximum size\n```\n\n스크립트에서의 배포 전 검사(ethers v6):\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst tx = await factory.getDeployTransaction(...args); // factory: ContractFactory\nconst size = getBytes(tx.data!).length;\nif (size \u003e 49152) throw new Error(`initcode is ${size} bytes; limit is 49152`);\n```\n\n## 알아둘 점\n\n- **상태: Final**이며 Shanghai 이후 메인넷에서 활성화되어 있습니다.\n- 일반적인 배포에서는 이 제한이 24 KB 전체 런타임 컨트랙트와 그만큼 큰 생성자를 담을 여유를 남겨 줍니다. 여러 컨트랙트의 바이트코드를 하나의 initcode에 넣는 팩토리가 이 한도에 걸릴 가능성이 가장 큽니다.\n- 크기가 초과된 create *트랜잭션*은 즉시 거부됩니다. 실행 중 크기가 초과된 `CREATE`/`CREATE2`는 그 호출만 실패하고(가스 소모) 바깥 트랜잭션은 여전히 포함될 수 있습니다.\n- create 트랜잭션의 비용은 calldata 가격(바이트당 4/16 gas)에 비하면 아주 작으며, 주로 일관성과 향후 확장성을 위해 포함되었습니다.\n- 이미 배포된 컨트랙트는 영향을 받지 않습니다.\n"},"zh":{"lang":"zh","tldr":"把合约 initcode 限制在 49,152 字节，并对其每 32 字节字收取 2 gas，使客户端分析部署代码所做的工作有上限且有偿。","tags":["evm","gas","contract-creation","initcode","core","shanghai"],"related":[170,1014,3855,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3860/","markdown":"## 它解决什么问题？\n\n创建合约时，EVM 会运行其 **initcode**（构造函数加上要部署的代码）。在运行之前，客户端必须对整个 initcode 做 jumpdest 分析，这项工作随长度增长。在该 EIP 之前，这项工作既没有限制，也没有计量：\n\n- 创建*交易*要为 initcode 支付 calldata gas，但从合约中调用的 `CREATE` 和 `CREATE2` 不需要支付任何与 initcode 大小成比例的费用（`CREATE2` 的哈希成本除外）。\n- 协议没有对 initcode 大小设置上限，这使得最坏情况的分析很困难，也让其他几项 EVM 提案变得复杂。\n\nEIP-3860 同时增加了大小限制和按字收费。它随 Shanghai 升级（2023 年）上线。\n\n## 它如何运作\n\n两个参数：\n\n| 常量 | 值 |\n| --- | --- |\n| `MAX_INITCODE_SIZE` | `2 * MAX_CODE_SIZE` = 49152 字节（[EIP-170](/eip-170/) 规定 `MAX_CODE_SIZE` = 24576） |\n| `INITCODE_WORD_COST` | 每 32 字节字 2 gas |\n\n`initcode_cost(initcode) = 2 * ceil(len(initcode) / 32)`\n\n规则：\n\n1. initcode 超过 `MAX_INITCODE_SIZE` 的**创建交易**无效，不能被打包进区块。\n2. 创建交易会把 `initcode_cost` 加到其**固有 gas** 上，因此无法覆盖该费用的交易无效。\n3. initcode 超出限制的 `CREATE` / `CREATE2` 会**异常中止**，就像 gas 耗尽一样。\n4. `CREATE` / `CREATE2` 在计算新地址和运行 initcode 之前，先预先收取 `initcode_cost`。对于 `CREATE2`，这与其原有的每字 6 gas 的哈希成本（[EIP-1014](/eip-1014/)）并存，因此现在总共每字支付 8 gas。\n\n该限制还意味着代码大小、`PC` 和跳转偏移量都能用 16 位表示，这对 EVM 实现是一种简化。\n\n## 示例代码\n\n额外成本和限制检查，按客户端的计算方式给出：\n\n```python\nMAX_CODE_SIZE = 24576\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE   # 49152\nINITCODE_WORD_COST = 2\n\ndef initcode_cost(initcode: bytes) -\u003e int:\n    return INITCODE_WORD_COST * ((len(initcode) + 31) // 32)\n\ndef check_create(initcode: bytes) -\u003e int:\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise Exception(\"exceptional abort: initcode too large\")\n    return initcode_cost(initcode)\n\nprint(initcode_cost(b\"\\x00\" * 49152))  # 3072 gas at the maximum size\n```\n\n脚本中的部署前检查（ethers v6）：\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst tx = await factory.getDeployTransaction(...args); // factory: ContractFactory\nconst size = getBytes(tx.data!).length;\nif (size \u003e 49152) throw new Error(`initcode is ${size} bytes; limit is 49152`);\n```\n\n## 需要注意\n\n- **状态：Final**，自 Shanghai 起在主网生效。\n- 对于普通部署，该限制给完整的 24 KB 运行时合约加上同样大的构造函数留出了空间。把多个合约的字节码嵌入同一个 initcode 的工厂合约最有可能触及该限制。\n- 超大的创建*交易*会被直接拒绝；执行中超大的 `CREATE`/`CREATE2` 只会使该次调用失败（消耗其 gas），外层交易仍然可以被打包。\n- 与 calldata 的定价（每字节 4/16 gas）相比，创建交易的成本微不足道；加入它主要是为了一致性和未来的可扩展性。\n- 已部署的合约不受影响。\n"}},"requiredBy":[3540,7830,7873,7903,7954,8311]}
