EIP-2677 initcode size limit (Limit size of `initcode`)
No call decision · EVM & execution · EIP status Withdrawn · created 2020-05-18
A proposal to cap the size of the code executed when creating a contract (initcode) at 49152 bytes, to prevent the slow block processing caused by oversized initcode. It was withdrawn, superseded by EIP-3860.
Why it is needed
EIP-170 limits the runtime code size of a deployed contract to 24576 bytes, but places no size limit on initcode, the code that runs during contract creation. Before executing initcode, clients must perform jumpdest analysis to find valid jump destinations, and this analysis result may be cached, or the code may need to be hashed when computing an address with CREATE2. Both operations take time proportional to code size, and a transaction can expand memory only once and then reuse that same memory region repeatedly to cheaply produce a huge initcode. In practice, an attack of this kind occurred in June 2017, prompting geth to release an emergency 1.6.5 patch. This proposal seeks to cap the worst case cost of such attacks by placing an upper bound on initcode size.
What changes
Today
- Deployed runtime code is limited to 24576 bytes by EIP-170, but creation code (initcode) has no size limit.
- Expanding memory only once and reusing the same region can cheaply produce a huge initcode, repeatedly forcing jumpdest analysis and hashing operations.
- An attack of this kind in June 2017 caused geth to release an emergency 1.6.5 patch.
After EIP-2677
- For CREATE, CREATE2, and transactions with no recipient (contract creation), if the initcode length exceeds 49152 bytes (0xc000), creation fails with an Out Of Gas error.
- The initcode size falls within the range of a 16 bit value, so both instruction offsets and code size can be represented as 16 bit values.
Who is affected
- Client developers: The worst case cost of jumpdest analysis and hashing operations now has an upper bound, making block processing more stable.
- Factory contract and L2 developers: If there is a pattern of combining multi stage contract code into a single initcode for deployment, it may hit this limit and fail to deploy.
- Contract deployer: Executing initcode exceeding 49152 bytes via CREATE, CREATE2, or a transaction with no recipient causes creation to fail.
In depth
Relationship with EIP-170: deployed code versus creation code
EIP-170 limits the size of the runtime code stored after deployment completes to 24576 bytes (0x6000). Separately from that, this proposal seeks to place an upper bound on initcode, which is only executed during contract creation and is not stored. The proposed value is max_initcode_size = 49152 (0xc000), exactly twice the EIP-170 limit. Setting it this way also has the additional property that both instruction offsets within the code and the total code size fall within the range of a 16 bit integer.
Why jumpdest analysis and hashing cost become an attack surface
Before executing initcode, clients perform jumpdest analysis to find all valid JUMP/JUMPI destinations (JUMPDEST) across the entire code. This result may be cached keyed by a mapping, and is also used when hashing the code to compute an address for CREATE2. Both operations take time linear in code size, and a transaction can expand memory only once and then reuse that memory region almost as is to cheaply produce a huge initcode, forcing clients into repeated analysis and hashing and slowing block processing. This approach was actually exploited in June 2017, which is the precedent behind the geth 1.6.5 patch.
Scope of application and failure conditions
This rule applies to all three contract creation paths: CREATE, CREATE2, and transactions with no recipient (contract creation transactions). If the initcode being executed via any of these paths exceeds max_initcode_size in length, the EVM must fail with an Out Of Gas error. The source text states that the same rule should apply to any other creation methods that may be added later.
Backward compatibility
This proposal changes a consensus rule, so it requires a network upgrade (fork). Contract creation that previously deployed successfully with initcode exceeding 49152 bytes will fail with Out Of Gas after the upgrade.
Security considerations
From a client implementation standpoint, the risk of attacks based on jumpdest analysis or code hashing is reduced, improving overall stability. However, on the layer 2 side, this may introduce a new failure mode that did not previously exist. If a factory contract is structured to include multi stage contract code entirely within the initcode of the first contract for deployment, it could hit this limit, though the original authors state they are not aware of any such contract actually existing.
Test cases
The source text specifies that test cases should be included for CREATE, CREATE2, and transaction based creation, covering both the case where initcode_size is exactly max_initcode_size and the case where it is max_initcode_size+1. The Rationale and Implementation sections are both left as TBA (to be added), so no concrete implementation code or design rationale is included in the source text.
Current status: withdrawn
This EIP's status is Withdrawn, and the original front matter explicitly states the withdrawal reason as "Replaced by EIP-3860." In other words, the idea of limiting initcode size itself was carried forward and made concrete in EIP-3860, while this document remains at an earlier stage of the proposal and did not progress further on its own.