Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers EIP3860, which extends the code size limits introduced by EIP170 by limiting the size of initialization code (initcode) and charging 2 gas for every 32-byte word of initcode.
This article translates, summarizes, and expands on the proposal below.
I have also covered a range of other EIPs.
Overview
EIP170 introduces a maximum code size for Ethereum smart contracts.
EIP3860 extends this approach to initialization code (initcode), setting the limit at twice MAX_CODE_SIZE.
Because the maximum size of a smart contract's deployed runtime code is 24,576 bytes (MAX_CODE_SIZE), the maximum initcode size is 49,152 bytes (MAX_INITCODE_SIZE).
For more on EIP170, see the following article.
[EIP170] Limiting Contract Code Size at Creation
Initcode is code executed once when a smart contract is deployed on the blockchain. It is used to produce the contract's runtime bytecode and initialize its state. Limiting its size improves blockchain efficiency and security.
Charging 2 gas for each 32-byte chunk of initcode also accounts for the cost of jump destination analysis.
This analysis identifies valid JUMPDEST positions in smart contract code so that jumps can be validated.
The additional gas charge better reflects the cost of deployment and discourages unnecessarily large initcode.
Finally, the size limit means that EVM (Ethereum Virtual Machine) code sizes, code offsets (program counters, or PCs), and valid jump offsets fit within 16-bit values. These bounded values simplify EVM implementation and optimization, contributing to more efficient execution.
The extension aims to improve Ethereum's efficiency and security by setting an upper bound on initcode size and more accurately accounting for the cost of processing it during deployment.
Motivation
Before Ethereum smart contract initcode can be executed, jump destination analysis must be performed. The work involved grows in proportion to the size of the initcode. Before EIP3860, this work was not separately metered in gas, and there was no explicit protocol-level limit on initcode size.
The following three costs existed before the change.
- Initialization code (
initcode) cost, also known as the calldata cost- Zero bytes cost 4 gas each, and nonzero bytes cost 16 gas each.
- Cost of the resulting deployed code
- Each byte costs 200 gas.
- Address computation (code hashing) cost for CREATE2
- Each word costs 6 gas.
Of these, the first is the transaction data charge for initcode, and it applies only to contract creation transactions.
CREATE and CREATE2 do not incur this calldata charge for initcode supplied from memory, so variations of initcode can be generated programmatically at relatively low cost. CREATE2 does separately incur the hashing charge described above.
Historically, a vulnerability fixed in geth 1.6.5 in 2017 made it possible to construct malicious initcode.
The absence of a size limit also led to prolonged discussions about some EVM proposals, affecting their design and in some cases delaying or canceling features.
The proposal is driven primarily by three considerations.
- Charge fairly for initcode, particularly in proportion to its length, to minimize future risks.
- Provide a cost model that can be extended in the future.
- Simplify EVM engines through explicit limits that keep code sizes, code offsets (PCs), and jump offsets within 16 bits.
The proposal aims to introduce fair metering for initcode, establish an extensible cost model, and simplify EVM implementations. These changes are intended to improve the efficiency and security of the Ethereum network.
Specification
The specification defines parameters and rules for Ethereum smart contract initialization code (initcode). The parameters are shown in the table below, followed by the rules.
Parameters
| Constant | Value |
|---|---|
| INITCODE_WORD_COST | 2 |
| MAX_INITCODE_SIZE | 2 * MAX_CODE_SIZE |
Here, MAX_CODE_SIZE is defined by EIP170 as 24,576.
It is the maximum allowed size of deployed smart contract code.
Rules
-
If the length of transaction data (initcode) exceeds
MAX_INITCODE_SIZEin a contract creation transaction, the transaction is invalid.- This is analogous to a transaction being invalid because it does not meet the intrinsic gas cost requirement.
-
For a contract creation transaction, add
initcode_cost(initcode)to the transaction data cost calculation.- Calculate
initcode_cost(initcode)asINITCODE_WORD_COST * ceil(len(initcode) / 32). - The charge is included in the intrinsic transaction cost. A transaction with insufficient gas to cover the initcode cost in addition to its other intrinsic costs is invalid.
- Calculate
-
If the length of initcode supplied to the
CREATEorCREATE2opcode exceedsMAX_INITCODE_SIZE, execution of the instruction exceptionally aborts, as with an out-of-gas error. -
Charge an additional gas cost equal to
initcode_cost(initcode)forCREATEandCREATE2.- This cost is deducted before or at the time of calculating the resulting contract address and executing the initcode. For
CREATE2, this means at or before the hashing charge is deducted.
- This cost is deducted before or at the time of calculating the resulting contract address and executing the initcode. For
These rules are designed to make smart contract deployment on Ethereum fairer and more efficient. Explicit initcode size limits and gas charges aim to improve network security and performance.
Additional Considerations
Choosing a Constant Gas Charge
Performance benchmarks informed the selection of INITCODE_WORD_COST, the gas cost constant for Ethereum smart contract initcode.
The baseline used was the performance of KECCAK256 hashing in geth 1.10.9 on a 4.0 GHz x86_64 CPU, calibrated to a target of 70 Mgas/s.
The benchmark results for the EVM implementations are shown below.
| EVM implementation | Version | MB/s | B/CPU cycle | CPU cycles/B | Cost per B | Cost per 32 B |
|---|---|---|---|---|---|---|
| geth/KECCAK256 | 1.10.9 | 357 | 1.8 | 0.6 | 0.2 | 6.0 |
| geth | 1.10.9 | 1091 | 5.5 | 0.2 | 0.1 | 2.0 |
| evmone/Baseline | 0.8.2 | 727 | 3.7 | 0.3 | 0.1 | 2.9 |
| evmone/Advanced | 0.8.2 | 155 | 0.8 | 1.3 | 0.4 | 13.8 |
- MB/s
- Megabytes processed per second.
- B/CPU cycle
- Bytes processed per CPU cycle.
- CPU cycles/B
- CPU cycles required to process one byte.
- Cost per B
- Gas cost to process one byte.
- Cost per 32 B
- Gas cost to process 32 bytes.
The benchmark shows clear performance differences among EVM implementations. For example, geth version 1.10.9 achieves a high throughput in MB/s and a low cost per byte. By contrast, evmone/Advanced version 0.8.2 has lower throughput and a higher cost per byte.
The choice of INITCODE_WORD_COST takes these benchmark results and worst-case resource considerations into account to promote efficient and fair transaction processing on Ethereum.
As the following section explains, the selected value is based on the geth comparison rather than the slowest measured implementation in the table.
Criteria for Selecting the Gas Cost
Based on the comparison between geth's jump destination analysis and KECCAK256 performance, a cost of 2 gas per word (32-byte chunk) was chosen. This corresponds to 0.0625 gas per byte for full words. Because fractional gas charges are not supported in the EVM, the cost is approximated by charging per word.
Word-based metering is also compatible with the CREATE2 hashing cost calculation introduced by EIP1014.
The same metering implementation can therefore be used for CREATE and CREATE2, with different cost constants.
Before activation, the per-word charges in question were 0 for CREATE and 6 for CREATE2. After activation, they became 2 for CREATE and 6 + 2 for CREATE2.
Why Limit Initcode Size?
An upper bound substantially reduces the search space, making worst-case scenarios easier to estimate and construct. This allows the per-byte gas cost to be selected less conservatively.
Without a limit, the cost would need to be set higher to account for unknown risks. Given that most existing initcode does not exceed the proposed limit, there is little reason to penalize contracts with an excessively conservative charge.
Impact of the Initcode Size Limit
When a new contract is created, in most cases, perhaps all typical cases, its resulting runtime code is copied from the initcode itself.
In the basic case, a limit of twice MAX_CODE_SIZE leaves room for MAX_CODE_SIZE bytes of runtime code and another MAX_CODE_SIZE bytes for the contract's constructor code.
However, the limit may become practically significant when multiple contracts are deployed through a single creation transaction, such as when the initcode embeds their code.
Initcode Cost in Contract Creation Transactions
The initcode charge for contract creation transaction data (0.0625 gas per byte for full words) is negligible compared with the transaction data cost of 4 or 16 gas per byte. Nevertheless, the proposal includes the charge for consistency and, more importantly, future compatibility.
Reporting Initcode Limit Violations
An initcode size limit violation during CREATE or CREATE2 is specified to cause an exceptional abort.
This groups the violation with the early exceptional checks, including stack underflow, memory expansion, static-call violations, initcode hashing costs, and the initcode cost introduced by this EIP.
These checks take place before the later call depth and balance checks.
This choice makes the order of checks consistent and reduces implementation complexity, as the out-of-gas checks can be performed in any order.
This concerns the order of validation checks during Ethereum smart contract execution.
Among the checks the Ethereum Virtual Machine (EVM) performs when processing transactions and contract calls, some are relatively lightweight, such as call depth and balance checks. For CREATE and CREATE2 under EIP3860, however, the early exceptional checks described above precede these lightweight checks.
What Are Lightweight Checks?
- Call depth check
- Ethereum imposes a maximum call depth for smart contracts. Exceeding the limit causes the attempted call or creation to fail.
- This helps prevent resource exhaustion from excessively deep call stacks.
- Balance check
- Before an account can transfer value, the system checks whether it has a sufficient balance. At the transaction level, the sender must also be able to cover the required transaction costs.
- If the balance is insufficient, the relevant operation cannot proceed.
These checks are relatively lightweight and occur during validation. Other checks, such as those associated with memory expansion or gas requirements, may involve more computation.
Check Ordering and Implementation Complexity
Performing checks in a consistent order simplifies EVM implementations and transaction processing. This approach allows invalid operations to be identified efficiently and rejected at an appropriate stage. It can avoid unnecessary resource consumption and improve overall network efficiency.
Consistent check ordering also helps EVM implementers follow a common approach, reducing complexity in error handling and exceptional-condition detection. This contributes to the stability and reliability of the Ethereum network.
Compatibility
The Ethereum Improvement Proposal (EIP) requires a network upgrade. A network upgrade changes Ethereum's consensus rules. This is significant because it can affect how transactions and smart contracts are executed on the network.
What a Network Upgrade Means
Changes to Consensus Rules
The Ethereum network follows a set of consensus rules to determine whether transactions and blocks are valid. Because the changes introduced by this EIP affect new transactions and contract deployments, participating nodes must follow the new rules.
Why an Upgrade Is Necessary
Implementing a change like this requires the relevant network nodes, including those operated by users, developers, and block producers, to update their software to support the new rules. This is a network upgrade.
Impact on Existing Contracts
Safety of Existing Contracts
The EIP does not alter the code of already deployed contracts. Existing smart contracts can continue to operate after the change, although their future contract-creation operations are subject to the new rules.
Impact on Certain Transactions
A transaction that invokes CREATE or CREATE2 with initcode exceeding the proposed size limit may be included in a block, but the affected execution frame exceptionally aborts when it encounters that instruction.
The oversized creation operation therefore cannot complete successfully and is treated as an execution error.
By contrast, a top-level contract creation transaction whose transaction data exceeds the initcode limit is invalid and cannot validly be included in a block. This distinction follows the specification above.
Tests
The test cases concern Ethereum smart contract creation transactions and the CREATE and CREATE2 opcodes.
They focus on initcode, the code used to initialize a smart contract, and its associated gas costs.
1. Creation Transaction with a Gas Limit That Covers Initcode Cost
This test checks whether the gas limit allocated to the transaction is sufficient to cover the required initcode charge. The initcode cost here is the additional gas charge for processing initialization code, distinct from the gas consumed by executing that code. The test is important for ensuring that a creation transaction with an appropriately specified gas limit can satisfy the new intrinsic cost requirement.
2. Creation Transaction with a Gas Limit That Covers Intrinsic Costs Excluding Initcode Cost
This case tests a transaction whose gas limit covers all other intrinsic costs, such as data transmission and the contract creation charge, but excludes the additional initcode cost. It models a situation in which the new initcode charge causes the transaction to fail the intrinsic gas requirement.
3. CREATE/CREATE2/Creation Transaction Where len(initcode) Equals MAX_INITCODE_SIZE
This test evaluates the behavior of a creation operation when the initcode length exactly equals the maximum allowed size (MAX_INITCODE_SIZE).
The objective is to verify that the system handles the boundary correctly and that the size itself does not prevent a successful creation.
4. CREATE/CREATE2/Creation Transaction Where len(initcode) Equals MAX_INITCODE_SIZE+1
This case tests a creation operation whose initcode exceeds the maximum allowed size by one byte.
It verifies how oversized initcode is handled: an exceptional abort for CREATE or CREATE2, or invalidity for a top-level creation transaction.
These tests are important for verifying that Ethereum handles different scenarios involving initcode size and cost correctly. This improves network stability and predictability.
Security
Impact on Client Implementations
The EIP mitigates attacks based on jump destination analysis. Jump destination analysis identifies valid jump targets in smart contract code. An attacker could exploit the processing cost of this analysis by deliberately supplying extremely large initcode to degrade client performance. By limiting initcode size and charging gas for every 32-byte word, the EIP increases the cost of such attacks. As a result, Ethereum clients become more robust.
Impact on Layer 2
Layer 2 systems may encounter failure modes that did not previously exist. For example, a factory contract might deploy multiple levels of nested contracts, with the first contract's initcode containing code for several other contracts. The proposal's authors were not aware of such contracts at the time, but the new size limit may affect deployment of contracts using these patterns.
Increased Attack Costs
Under the 30 million gas limit at the time of the London upgrade, it was possible to trigger jump destination analysis for approximately 1.3 GB of initcode in total. According to the historical estimate in the proposal, the new metering would add approximately 80 million gas to the cost of such an attack. This increases the cost of attacks involving large quantities of initcode and makes them less practical.
The EIP improves the robustness of Ethereum clients while potentially introducing new constraints on certain complex contract deployment patterns. It is also expected to improve network security by increasing the cost of attacks involving large quantities of initcode.
Citation
Martin Holst Swende (@holiman), Paweł Bylica (@chfast), Alex Beregszaszi (@axic), Andrei Maiboroda (@gumb0), "EIP-3860: Limit and meter initcode," Ethereum Improvement Proposals, no. 3860, July 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3860.
Conclusion
This article covered EIP3860, which extends the limits introduced by EIP170 by setting a maximum size for initcode and charging 2 gas for every 32-byte word of initcode.
If you have questions, feel free to contact me by direct message on Twitter.
I also publish material on the following platforms.


