{"eip":2677,"title":"Limit size of `initcode`","description":"Enforce a maximum size limit (maxinitcodesize) of 49152 (0xc000) for initcode.","authors":["Martin Holst Swende (@holiman)","Paweł Bylica (@chfast)","Alex Beregszaszi (@axic)"],"status":"Withdrawn","type":"Standards Track","category":"Core","created":"2020-05-18","discussionsTo":"https://ethereum-magicians.org/t/eip-2677-limit-size-of-initcode/4550","repo":"EIPs","label":"EIP-2677","officialUrl":"https://eips.ethereum.org/EIPS/eip-2677","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2677.md","url":"https://eips.huatuo.xyz/eip-2677/","tldr":{"en":"A withdrawn proposal to cap contract creation initcode at 49152 bytes (twice the deployed-code limit) to stop cheap jumpdest-analysis and hashing DoS; it was replaced by EIP-3860, which shipped in Shanghai.","ja":"コントラクト作成の initcode を 49152 バイト（デプロイ済みコード上限の 2 倍）に制限し、安価な jumpdest 解析とハッシュ計算による DoS を防ぐ撤回済みの提案。EIP-3860 に置き換えられ、Shanghai で導入された。","ko":"컨트랙트 생성 initcode를 49152바이트(배포된 코드 한도의 두 배)로 제한해, 저렴한 jumpdest 분석과 해시 연산을 이용한 DoS를 막으려던 철회된 제안. EIP-3860으로 대체되었고 Shanghai에서 적용되었다.","zh":"一项已撤回的提案，将合约创建的 initcode 上限定为 49152 字节（已部署代码上限的两倍），以阻止廉价的 jumpdest 分析和哈希运算造成的 DoS；它被 EIP-3860 取代，后者在 Shanghai 中上线。"},"tags":["evm","contract-creation","initcode","dos","withdrawn"],"explainers":{"en":{"lang":"en","tldr":"A withdrawn proposal to cap contract creation initcode at 49152 bytes (twice the deployed-code limit) to stop cheap jumpdest-analysis and hashing DoS; it was replaced by EIP-3860, which shipped in Shanghai.","tags":["evm","contract-creation","initcode","dos","withdrawn"],"related":[3860,170,1014],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2677/","markdown":"## What problem does it solve?\n\nWhen a contract is created, the client first runs its *initcode*: the constructor code that returns the final runtime bytecode. Before executing any code, a client performs *jumpdest analysis*, a scan over every byte to find valid `JUMPDEST` positions. For `CREATE2` it also hashes the initcode to compute the new address ([EIP-1014](/eip-1014/)).\n\nBoth jobs scale with code length, but while deployed code has been capped at 24576 bytes since [EIP-170](/eip-170/), initcode had no size limit. A transaction could expand memory once and then repeatedly start creations from that same large buffer, forcing clients to analyse and hash huge blobs over and over for little gas. The spec notes this kind of abuse was exploited in June 2017, prompting a geth patch release.\n\n## How it works\n\n- Define `max_initcode_size = 49152` (`0xc000`), exactly 2× the EIP-170 code limit.\n- Apply it to every creation path: `CREATE`, `CREATE2`, and a transaction with an empty `to` field.\n- If initcode is longer than the limit, contract creation fails with an out-of-gas error.\n\nA nice side effect of the limit is that any code offset and code length fit in 16 bits, which simplifies some client and tooling designs.\n\nThe proposal required a network upgrade since it changes consensus rules. It flagged one possible breaking case: factory contracts that embed several levels of child contracts inside a single initcode might exceed the limit (the authors said they knew of none).\n\n## Sample code\n\nPseudocode for the check, as it would sit at the start of contract creation:\n\n```python\nMAX_CODE_SIZE = 0x6000          # 24576, from EIP-170\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE  # 49152 = 0xc000\n\ndef create_contract(initcode: bytes, gas: int):\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise OutOfGasError(\"initcode too large\")\n    analyse_jumpdests(initcode)\n    return execute(initcode, gas)\n```\n\nChecking your own initcode size before deploying (ethers v6):\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst deployTx = await factory.getDeployTransaction(...args);\nconst size = getBytes(deployTx.data!).length;\nif (size \u003e 49152) console.warn(`initcode is ${size} bytes, above the 49152-byte limit`);\n```\n\n## Things to know\n\n- **Status: Withdrawn**, replaced by [EIP-3860](/eip-3860/). EIP-3860 keeps the same 49152-byte limit but also charges a small gas cost per 32-byte word of initcode, and makes an oversized create transaction invalid rather than just failing.\n- EIP-3860 is the rule actually in force on mainnet since the Shanghai upgrade, so the 49152-byte figure from this proposal is still the one that matters today.\n- If a deployment hits the limit, split the contract, use libraries, or deploy via proxies rather than one giant constructor.\n"},"ja":{"lang":"ja","tldr":"コントラクト作成の initcode を 49152 バイト（デプロイ済みコード上限の 2 倍）に制限し、安価な jumpdest 解析とハッシュ計算による DoS を防ぐ撤回済みの提案。EIP-3860 に置き換えられ、Shanghai で導入された。","tags":["evm","contract-creation","initcode","dos","withdrawn"],"related":[3860,170,1014],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2677/","markdown":"## 何を解決するのか\n\nコントラクトが作成されるとき、クライアントはまず *initcode*、つまり最終的なランタイムバイトコードを返すコンストラクタコードを実行します。コードを実行する前に、クライアントは *jumpdest 解析*、つまり有効な `JUMPDEST` の位置を見つけるために全バイトを走査する処理を行います。`CREATE2` では、新しいアドレスを計算するために initcode のハッシュも取ります（[EIP-1014](/eip-1014/)）。\n\nどちらの処理もコードの長さに比例しますが、デプロイ済みコードは [EIP-170](/eip-170/) 以来 24576 バイトに制限されている一方で、initcode にはサイズ制限がありませんでした。トランザクションはメモリを一度だけ拡張し、その同じ大きなバッファから繰り返しコントラクト作成を開始できるため、クライアントはわずかなガスで巨大なデータの解析とハッシュ計算を何度も強いられます。この種の悪用は 2017 年 6 月に実際に行われ、geth のパッチリリースにつながったと仕様は述べています。\n\n## 仕組み\n\n- `max_initcode_size = 49152`（`0xc000`）を定義します。これは EIP-170 のコード上限のちょうど 2 倍です。\n- すべての作成経路に適用します。`CREATE`、`CREATE2`、`to` フィールドが空のトランザクションです。\n- initcode が上限より長い場合、コントラクト作成は out-of-gas エラーで失敗します。\n\nこの制限の良い副作用として、コードのオフセットと長さがすべて 16 ビットに収まり、クライアントやツールの設計が一部単純になります。\n\nこの提案はコンセンサスルールを変更するため、ネットワークアップグレードが必要でした。壊れる可能性のあるケースが 1 つ指摘されています。1 つの initcode に子コントラクトを何階層も埋め込むファクトリコントラクトが上限を超える可能性があるというものです（作者は該当するものを知らないとしています）。\n\n## サンプルコード\n\nコントラクト作成の冒頭に置かれるチェックの疑似コード:\n\n```python\nMAX_CODE_SIZE = 0x6000          # 24576, from EIP-170\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE  # 49152 = 0xc000\n\ndef create_contract(initcode: bytes, gas: int):\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise OutOfGasError(\"initcode too large\")\n    analyse_jumpdests(initcode)\n    return execute(initcode, gas)\n```\n\nデプロイ前に自分の initcode のサイズを確認する（ethers v6）:\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst deployTx = await factory.getDeployTransaction(...args);\nconst size = getBytes(deployTx.data!).length;\nif (size \u003e 49152) console.warn(`initcode is ${size} bytes, above the 49152-byte limit`);\n```\n\n## 知っておくべきこと\n\n- **ステータス：Withdrawn**。[EIP-3860](/eip-3860/) に置き換えられました。EIP-3860 は同じ 49152 バイトの上限を維持しつつ、initcode の 32 バイトワードごとに少額のガスも課し、サイズ超過の作成トランザクションを、単に失敗させるのではなく無効にします。\n- EIP-3860 は Shanghai アップグレード以降、メインネットで実際に有効なルールなので、この提案の 49152 バイトという数字は今でも重要です。\n- デプロイが上限に達した場合は、巨大なコンストラクタ 1 つにせず、コントラクトを分割する、ライブラリを使う、プロキシ経由でデプロイするなどしてください。\n"},"ko":{"lang":"ko","tldr":"컨트랙트 생성 initcode를 49152바이트(배포된 코드 한도의 두 배)로 제한해, 저렴한 jumpdest 분석과 해시 연산을 이용한 DoS를 막으려던 철회된 제안. EIP-3860으로 대체되었고 Shanghai에서 적용되었다.","tags":["evm","contract-creation","initcode","dos","withdrawn"],"related":[3860,170,1014],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2677/","markdown":"## 어떤 문제를 해결하나요?\n\n컨트랙트가 생성될 때 클라이언트는 먼저 그 *initcode*, 즉 최종 런타임 바이트코드를 반환하는 생성자 코드를 실행합니다. 코드를 실행하기 전에 클라이언트는 *jumpdest 분석*, 즉 유효한 `JUMPDEST` 위치를 찾기 위해 모든 바이트를 훑는 작업을 수행합니다. `CREATE2`에서는 새 주소를 계산하려고 initcode를 해시하기도 합니다([EIP-1014](/eip-1014/)).\n\n두 작업 모두 코드 길이에 비례하는데, 배포된 코드는 [EIP-170](/eip-170/) 이후 24576바이트로 제한된 반면 initcode에는 크기 제한이 없었습니다. 트랜잭션은 메모리를 한 번만 확장한 뒤 그 같은 큰 버퍼에서 반복해서 생성을 시작할 수 있어, 클라이언트가 적은 가스로 거대한 데이터를 계속 분석하고 해시하게 만들 수 있었습니다. 명세는 이런 남용이 2017년 6월에 실제로 악용되어 geth 패치 릴리스로 이어졌다고 언급합니다.\n\n## 어떻게 동작하나요?\n\n- `max_initcode_size = 49152`(`0xc000`)를 정의합니다. EIP-170 코드 한도의 정확히 2배입니다.\n- 모든 생성 경로에 적용합니다. `CREATE`, `CREATE2`, 그리고 `to` 필드가 비어 있는 트랜잭션입니다.\n- initcode가 한도보다 길면 컨트랙트 생성은 out-of-gas 오류로 실패합니다.\n\n이 제한의 좋은 부수 효과는 어떤 코드 오프셋과 코드 길이도 16비트에 들어가므로 일부 클라이언트와 도구 설계가 단순해진다는 점입니다.\n\n이 제안은 합의 규칙을 바꾸기 때문에 네트워크 업그레이드가 필요했습니다. 깨질 수 있는 사례 하나가 지적되었습니다. 하나의 initcode 안에 여러 단계의 자식 컨트랙트를 내장하는 팩토리 컨트랙트가 한도를 넘을 수 있다는 것입니다(작성자들은 그런 사례를 알지 못한다고 했습니다).\n\n## 샘플 코드\n\n컨트랙트 생성 시작 부분에 놓이게 될 검사의 의사 코드:\n\n```python\nMAX_CODE_SIZE = 0x6000          # 24576, from EIP-170\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE  # 49152 = 0xc000\n\ndef create_contract(initcode: bytes, gas: int):\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise OutOfGasError(\"initcode too large\")\n    analyse_jumpdests(initcode)\n    return execute(initcode, gas)\n```\n\n배포하기 전에 자신의 initcode 크기를 확인하기(ethers v6):\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst deployTx = await factory.getDeployTransaction(...args);\nconst size = getBytes(deployTx.data!).length;\nif (size \u003e 49152) console.warn(`initcode is ${size} bytes, above the 49152-byte limit`);\n```\n\n## 알아둘 점\n\n- **상태: Withdrawn**, [EIP-3860](/eip-3860/)으로 대체되었습니다. EIP-3860은 같은 49152바이트 한도를 유지하면서 initcode의 32바이트 워드마다 소액의 가스도 부과하고, 크기를 초과한 생성 트랜잭션을 단순히 실패시키는 대신 무효로 만듭니다.\n- EIP-3860은 Shanghai 업그레이드 이후 메인넷에서 실제로 적용되는 규칙이므로, 이 제안의 49152바이트라는 수치는 지금도 중요한 값입니다.\n- 배포가 한도에 걸리면, 거대한 생성자 하나를 쓰기보다 컨트랙트를 분할하거나 라이브러리를 쓰거나 프록시로 배포하세요.\n"},"zh":{"lang":"zh","tldr":"一项已撤回的提案，将合约创建的 initcode 上限定为 49152 字节（已部署代码上限的两倍），以阻止廉价的 jumpdest 分析和哈希运算造成的 DoS；它被 EIP-3860 取代，后者在 Shanghai 中上线。","tags":["evm","contract-creation","initcode","dos","withdrawn"],"related":[3860,170,1014],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2677/","markdown":"## 它解决什么问题？\n\n创建合约时，客户端首先运行它的 *initcode*：即返回最终运行时字节码的构造函数代码。在执行任何代码之前，客户端会做 *jumpdest 分析*，即扫描每个字节以找出有效的 `JUMPDEST` 位置。对于 `CREATE2`，还要对 initcode 做哈希以计算新地址（[EIP-1014](/eip-1014/)）。\n\n这两项工作都随代码长度增长，但自 [EIP-170](/eip-170/) 以来已部署代码被限制在 24576 字节，initcode 却没有大小限制。一笔交易可以只扩展一次内存，然后反复从同一个大缓冲区发起创建，迫使客户端花很少的 gas 一遍又一遍地分析和哈希巨大的数据块。规范指出，这类滥用曾在 2017 年 6 月被利用，促使 geth 发布了补丁版本。\n\n## 它如何运作\n\n- 定义 `max_initcode_size = 49152`（`0xc000`），恰好是 EIP-170 代码上限的 2 倍。\n- 适用于所有创建路径：`CREATE`、`CREATE2`，以及 `to` 字段为空的交易。\n- 如果 initcode 超过上限，合约创建会以 out-of-gas 错误失败。\n\n这一限制的一个附带好处是，任何代码偏移量和代码长度都能放进 16 位，这简化了一些客户端和工具的设计。\n\n该提案需要网络升级，因为它修改了共识规则。它指出了一种可能被破坏的情况：把多层子合约嵌入单个 initcode 的工厂合约可能会超出上限（作者表示不知道有这样的合约）。\n\n## 示例代码\n\n该检查的伪代码，位于合约创建的开头：\n\n```python\nMAX_CODE_SIZE = 0x6000          # 24576, from EIP-170\nMAX_INITCODE_SIZE = 2 * MAX_CODE_SIZE  # 49152 = 0xc000\n\ndef create_contract(initcode: bytes, gas: int):\n    if len(initcode) \u003e MAX_INITCODE_SIZE:\n        raise OutOfGasError(\"initcode too large\")\n    analyse_jumpdests(initcode)\n    return execute(initcode, gas)\n```\n\n部署前检查自己 initcode 的大小（ethers v6）：\n\n```ts\nimport { ContractFactory, getBytes } from \"ethers\";\n\nconst deployTx = await factory.getDeployTransaction(...args);\nconst size = getBytes(deployTx.data!).length;\nif (size \u003e 49152) console.warn(`initcode is ${size} bytes, above the 49152-byte limit`);\n```\n\n## 需要注意\n\n- **状态：Withdrawn**，被 [EIP-3860](/eip-3860/) 取代。EIP-3860 保留了同样的 49152 字节上限，同时对 initcode 的每个 32 字节字收取少量 gas，并让超长的创建交易无效，而不是仅仅失败。\n- EIP-3860 是自 Shanghai 升级以来主网上实际生效的规则，因此本提案中的 49152 字节这个数字至今仍然是关键数字。\n- 如果部署触及上限，请拆分合约、使用库或通过代理部署，而不是写一个巨大的构造函数。\n"}}}
