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.
EIP-4762 proposes revising the gas costs of storage and code access to prepare Ethereum for Verkle trees and enable more efficient, secure state management.
This article translates, summarizes, and expands on the following proposal.
I have also written about other EIPs.
Overview
EIP-4762 proposes changes to Ethereum's gas schedule. Its primary objective is to accurately reflect the computational cost of generating witness data in gas costs. Applying these changes requires Ethereum clients to update their database structures. This helps prevent clients with unsuitable database layouts from becoming vulnerable to denial-of-service (DoS) attacks.
Motivation
Introducing Verkle trees to Ethereum requires substantial infrastructure changes across the network. EIP-4762 was proposed as preparation for a hard fork preceding the introduction of Verkle trees, allowing dapp and client developers sufficient time to adapt to the new storage model.
Dapp developers are encouraged to adopt the new storage layout in advance, while client developers can migrate their database formats before the transition, reducing disruption and security risks.
Specification
Helper function get_storage_slot_tree_keys
def get_storage_slot_tree_keys(storage_key: int) -> [int, int]:
if storage_key < (CODE_OFFSET - HEADER_STORAGE_OFFSET):
pos = HEADER_STORAGE_OFFSET + storage_key
else:
pos = MAIN_STORAGE_OFFSET + storage_key
return (
pos // 256,
pos % 256
)This helper function determines the position of a storage slot in a Verkle tree. In the proposed Verkle-based Ethereum state structure, a slot number must be mapped to two indices, a tree key and a subkey, to manage storage efficiently. This function performs that conversion.
It takes a single storage_key (the storage slot number) and converts it to a (tree_key, sub_key) pair.
The pair identifies the precise node position in the Verkle tree.
How it works
First, the function determines whether storage_key belongs to the header storage region or the main storage region.
if storage_key < (CODE_OFFSET - HEADER_STORAGE_OFFSET):
pos = HEADER_STORAGE_OFFSET + storage_key
else:
pos = MAIN_STORAGE_OFFSET + storage_keyThis condition checks whether the storage slot belongs to the header region.
HEADER_STORAGE_OFFSETis the starting position of the header storage region.MAIN_STORAGE_OFFSETis the starting position of the main storage region.CODE_OFFSETseparates the code chunk and storage regions.
Relatively small storage_key values are assigned to the header region, while the remaining keys belong to the main region.
After this classification, the position is split into two integers, (tree_key, sub_key), as follows.
return (
pos // 256,
pos % 256
)tree_keyrepresents the index of the parent node in the Verkle tree.sub_keyrepresents the position of a child leaf within that node (from 0 to 255).
This partitioning efficiently locates the desired storage slot within Verkle nodes containing 256 slots.
Unlike the conventional hash-map-style storage layout, Verkle trees organize state in a chunked tree structure. Efficient and accurate storage access therefore requires calculating the corresponding position in the tree.
This function is central to that mapping, which directly affects witness generation and the consistency of access events. It is therefore essential to state access under the proposed Verkle tree layout.
Access events
EIP-4762 explicitly records state reads during EVM execution as access events. These events identify which information needs to be included in the Verkle witness.
Access events have the following form.
(address, sub_key, leaf_key)address- The account or contract address being accessed.
sub_key- A fixed value or chunk-related index.
leaf_key- A key corresponding to account information, code, or storage.
The events are categorized by the type of state being accessed.
Account header access events
The account header contains basic account information, such as its balance, nonce, and code hash.
An access event for the target address occurs under the following conditions.
(address, 0, BASIC_DATA_LEAF_KEY)This indicates that the address's basic account information has been read.
The conditions are as follows.
- The target is neither a precompile nor a system contract, and
CALL,CALLCODE,SELFDESTRUCT,EXTCODESIZE, orEXTCODECOPYis used. - The address is the target of
initcodeexecution during contract creation. - The
BALANCEopcode reads the balance of an address. - A deployed contract reads its own code using
CODECOPY.
However, when the target is a precompile or system contract and CALL, CALLCODE, or SELFDESTRUCT transfers no wei (value=0), this event does not occur.
The proposal treats the relevant information for these addresses as known, so it does not need to be included in the witness.
If CALL, CALLCODE, or SELFDESTRUCT transfers wei, the following additional access event occurs for the caller (sender).
(caller, 0, BASIC_DATA_LEAF_KEY)This explicitly records state access to the sender's balance and nonce.
Contract existence is determined by the existence of the extension-and-suffix tree in the Verkle structure, rather than by the presence of CODEHASH_LEAF_KEY.
Code hash access events
When EXTCODEHASH retrieves the hash of the code deployed at an address, the following access event occurs.
(address, 0, CODEHASH_LEAF_KEY)This indicates that the target address's code hash has been accessed. No such event occurs for precompiles or system contracts because their code hashes are known to the client.
Access events during contract creation
When a new contract is created, the following two access events occur for its address.
(contract_address, 0, BASIC_DATA_LEAF_KEY)
(contract_address, 0, CODEHASH_LEAF_KEY)The new contract account's basic information and code state must both be initialized.
Storage access events
When SLOAD or SSTORE reads or writes a storage slot, an access event takes the following form.
(address, tree_key, sub_key)Here, tree_key and sub_key identify the position in the Verkle tree and are calculated using get_storage_slot_tree_keys(address, key).
This indexing enables efficient storage slot access.
Code access events
Access to bytecode is also recorded at the chunk level. Code is divided into 31-byte chunks, and access to a particular chunk produces an event of the following form.
(address, (chunk_id + 128) // 256, (chunk_id + 128) % 256)Adding an offset of 128 to the chunk ID separates the storage and code regions and distinguishes their positions in the Verkle tree.
Main conditions that trigger access
- If the current instruction position (program counter
PC) is below the code length, the chunk containing thatPCis accessed. JUMPand successfulJUMPIinstructions trigger access to the destination chunk.- A
PUSHninstruction accesses every chunk covering the bytes of its immediate operand. - If
CODECOPYorEXTCODECOPYcopies a range of bytecode, all chunks corresponding to that range are accessed.
Conditions that do not trigger access
- The jump destination is outside the code (
destination >= len(code)). - The
JUMPIcondition is false, so no jump occurs. JUMPruns out of gas and execution stops.- Execution reaches the end of the code (
PC == len(code)). CODECOPYorEXTCODECOPYhas a read size of zero.CODESIZE,EXTCODESIZE, andEXTCODEHASHdo not trigger chunk access because they do not read the chunks themselves.
Special case: contract creation
When a contract is created, its entire code is considered accessed.
Based on the code length len(code), access events occur for all chunks in the following range.
chunk_id = 0 ... (len(code) + 30) // 31This records the entire code at deployment in preparation for later execution.
Write events
EIP-4762 explicitly records state changes during EVM execution as write events. A write event indicates that data is updated and consists of the same three elements as an access event.
(address, sub_key, leaf_key)The event identifies the address, the subkey, and the type of data written. It is also a type of access event. A write therefore always triggers the corresponding access event as well.
Account header write events
Operations that change an account balance or nonce update its basic account data (BASIC_DATA_LEAF_KEY) and trigger a write event.
Write events occur in the following situations.
Value transfers through CALL, CALLCODE, or SELFDESTRUCT
If these instructions transfer a nonzero amount of wei, the following events occur for the sender (caller) and recipient (callee).
(caller, 0, BASIC_DATA_LEAF_KEY)
(callee, 0, BASIC_DATA_LEAF_KEY)If the recipient account did not previously exist, its code information (empty code) is also initialized, triggering an additional write event.
(callee, 0, CODEHASH_LEAF_KEY)Contract creation
Creating a new contract initializes the account's balance, nonce, and code state, triggering the following two write events.
(contract_address, 0, BASIC_DATA_LEAF_KEY)
(contract_address, 0, CODEHASH_LEAF_KEY)Storage write events
When a smart contract state variable is changed through SSTORE, a write event occurs for the corresponding storage slot.
Write events have the following form.
(address, tree_key, sub_key)Here, tree_key and sub_key identify the exact position in the Verkle tree.
They are calculated using get_storage_slot_tree_keys(address, key).
This identifies the node to update within the Verkle tree's 256-slot grouping.
Code write events
When a new contract is created, its bytecode is stored in the code region of the Verkle tree. The code is divided into 31-byte chunks, with a write event for each chunk.
Write events have the following form.
(
address,
(CODE_OFFSET + i) // VERKLE_NODE_WIDTH,
(CODE_OFFSET + i) % VERKLE_NODE_WIDTH
)addressis the contract address.iis a chunk index in the range defined by(len(code) + 30) // 31, starting from 0.CODE_OFFSETis a constant marking the start of the code region.VERKLE_NODE_WIDTHis the number of slots in a Verkle node (normally 256).
These events identify the tree nodes in which code chunks are stored.
Before EIP-4762, code access was not tracked in access lists with a warm/cold distinction, so no warm-access discount applies to these code writes. This preserves compatibility with the previous design.
Transaction events
When an Ethereum transaction is submitted, state associated with the sender and recipient is read or modified. EIP-4762 explicitly defines the access and write events associated with transaction execution. This precisely identifies which state must be included in the Verkle witness.
Access events
Transaction execution triggers the following four access events.
(tx.origin, 0, BASIC_DATA_LEAF_KEY)
(tx.origin, 0, CODEHASH_LEAF_KEY)
(tx.target, 0, BASIC_DATA_LEAF_KEY)
(tx.target, 0, CODEHASH_LEAF_KEY)Here, tx.origin is the originating externally owned account (EOA), and tx.target is the destination address, commonly a contract account.
- Access to
BASIC_DATA_LEAF_KEYis necessary to read basic account information, including balance and nonce. - Access to
CODEHASH_LEAF_KEYis necessary to check code information, for example whether a contract destination has code.
Transaction processing therefore automatically triggers the access events corresponding to sender and recipient account and code information.
Write events
When a transaction updates account state, the following write event occurs.
(tx.origin, 0, BASIC_DATA_LEAF_KEY)This is because the originating account's nonce is incremented.
Since the nonce is always updated, this write event always occurs.
If the transaction specifies a nonzero value, the destination account's balance also changes, triggering the following additional write events.
(tx.target, 0, BASIC_DATA_LEAF_KEY)Explicitly defining the updates to transaction-related accounts allows more precise tracking of state changes and witness construction.
Witness gas costs
EIP-4762 introduces a new witness-based gas cost model in preparation for Verkle trees. Gas is charged according to the structure of the state data accessed during transaction and EVM execution. The goal is to replace parts of the previous storage-access and code-size gas model with pricing that better reflects the underlying costs.
Removed gas costs
The following existing gas costs are removed.
- The additional cost of
CALLwith a value transfer (value > 0). SSTOREgas costs defined by EIP-2200, exceptSLOAD_GAS.- The cost of 200 gas per byte of deployed contract code.
- The additional cost of
CALLCODEwith a value transfer.
Gas is instead charged according to the cost of accessing and updating the structures needed to prove the existence and modification of storage or code.
Reduced gas costs
The gas cost of the following operations is reduced.
- The gas cost of
CREATEandCREATE2is reduced to a fixed 1000.
New gas cost constants
The following costs are introduced and charged according to the type of access or update.
| Item | Cost |
|---|---|
WITNESS_BRANCH_COST |
1900 |
WITNESS_CHUNK_COST |
200 |
SUBTREE_EDIT_COST |
3000 |
CHUNK_EDIT_COST |
500 |
CHUNK_FILL_COST |
6200 |
These constants reflect the structural costs of reading and updating Verkle state.
Sets maintained during execution
Four sets are maintained during transaction execution.
accessed_subtrees- Subtrees that have been read, such as the parent nodes of storage chunks.
accessed_leaves- Individual leaves that have been read, such as account balances or code hashes.
edited_subtrees- Subtrees that have been modified.
edited_leaves- Leaves that have been modified.
These sets determine which operations incur gas charges.
Charging for access events
When a state access event ((address, sub_key, leaf_key)) occurs, the following checks and charges apply.
- Process the event only if it is not one of the initial transaction access events.
- If
(address, sub_key)is not inaccessed_subtrees, chargeWITNESS_BRANCH_COSTand add the tuple. - If
leaf_keyis present and(address, sub_key, leaf_key)is not inaccessed_leaves, chargeWITNESS_CHUNK_COSTand add the tuple.
Charging for write events
When a write event ((address, sub_key, leaf_key)) occurs, the following rules apply.
- Skip the charge for initial transaction write events.
- If
(address, sub_key)is not inedited_subtrees, chargeSUBTREE_EDIT_COSTand add it. - If
leaf_keyis present and(address, sub_key, leaf_key)is not inedited_leaves, chargeCHUNK_EDIT_COSTand add it. - If no value previously existed at the position (
None), additionally chargeCHUNK_FILL_COST.
An important rule is that once any value, including zero, has been written to a tree slot, it cannot return to the empty (None) state.
A populated slot cannot be deleted in this model, and zero remains distinct from an unused slot.
Handling insufficient gas
If insufficient gas remains to add witness-related access or write events, all remaining gas is consumed and execution stops. This prevents execution from continuing with an incomplete state witness.
Handling the 1/64 gas reservation
When executing CALL-family or CREATE-family instructions, the EVM limits the gas available to nested calls before execution under the 1/64 rule.
EIP-4762 adjusts the timing of this rule to account for witness gas charges.
- For
CALL,CALLCODE,DELEGATECALL, andSTATICCALL:- Apply the 1/64 gas limit after charging for the witness.
- For
CREATEandCREATE2:- Reserve 1/64 of the gas before charging for the witness.
This maintains the safety and predictability of the previous access-list-based approach.
Witness handling for block-level operations
EIP-4762 introduces witness construction based on the state read and modified during transaction execution. Certain special accounts and operations, however, receive exceptional treatment. These exceptions maintain consistency between gas accounting and witness construction.
Accounts that are not warm at transaction start
At the start of a transaction, the following accounts and slots are treated as cold rather than pre-accessed (warm).
- Precompile accounts, such as 0x01 through 0x09.
- System contract accounts and their storage slots.
- The coinbase account (the fee recipient).
- Accounts involved in withdrawals.
Their first access is therefore subject to the applicable witness costs.
Handling system contracts
System contracts are accounts containing special code handled by the client. Examples in the original explanation include system contracts introduced after Shanghai and code invoked internally by the EVM.
When a system contract is invoked in the following situations, access to its code chunks and account header does not need to be included in the witness.
- Ordinary system calls explicitly initiated at the system level.
- Internal calls used to resolve precompile or special opcode execution.
The relevant information is already known to clients and can be treated as trusted state.
The following operations, however, still need to be included in the witness.
- Storage reads and writes performed by the system contract.
- All other non-code-related accesses and writes.
Code and account header reads are excluded, while the remaining applicable accesses are included in the witness.
Witness costs incurred while resolving precompiles or special opcodes are charged, whereas accesses made during pure system calls are not charged. This distinction reflects the different purposes of opcode execution and system calls.
Compatibility with account abstraction
The historical proposal still had unresolved questions about integrating account abstraction into EIP-4762. The following two proposals were being considered, with no final choice at that stage.
- EIP7702
- A proposal to introduce a temporary signer slot to an EOA.
- EIP3074
- A model for delegating EOA authority using
AUTHandAUTHCALL.
- A model for delegating EOA authority using
For more on EIP-7702, see the following article.
[EIP-7702] Delegating EOA Execution to Contract Code
For more on EIP-3074, see the following article.
[EIP-3074] Delegating EOA Control to Contracts Using Two New Instructions
At that stage, EIP-4762 did not define a final specification for witness handling in account abstraction. The chosen proposal would affect state access and signature processing, which could also change witness construction and gas accounting.
Rationale
EIP-4762 redesigns the gas cost model as preparation for introducing Verkle trees to Ethereum. Its primary objective is to replace pricing optimized for the Merkle Patricia Trie (MPT) with pricing optimized for Verkle trees and more representative of processing costs.
Redesigning the gas model
The new model calculates storage and code access costs according to the structure of state witnesses. Key features include the following.
WITNESS_CHUNK_COST(a code chunk witness) is described as approximately 6.25 gas per byte, with 200 gas charged for a 31-byte chunk.WITNESS_BRANCH_COST(a branch-node witness) is approximately 13.2 gas per byte based on an average proof length of 144 bytes.- The design targets approximately 2.5 gas per byte even in the worst case.
This accommodates state accesses that produce large proofs, such as keys arranged deliberately to increase proof lengths.
Differences from the Berlin gas model
The new schedule introduces the following changes.
- Code access costs 200 gas per 31-byte chunk.
- Average gas usage was estimated to increase by approximately 6–12%.
- At a chunk cost of 350 gas, the estimated increase was 10–20%.
- Access to adjacent storage slots (for example,
key1 // 256 == key2 // 256) is reduced from 2100 gas to 200 gas, except for the first slot accessed. - Storage slots 0 through 63 all cost 200 gas, including the first slot.
- This is expected to improve the performance of many existing contracts.
Lower storage access costs are expected to offset increased code access costs. Future compiler optimizations, including in Solidity, could improve gas efficiency further.
Why access event specifications matter
The timing and precision of access events defined by EIP-4762 are essential for identifying which data belongs in the Verkle tree's period 1 tree for short-term witnesses. This is a major source of the technical complexity in the gas redesign.
Backward Compatibility
EIP-4762 changes consensus rules and therefore requires a hard fork. Applications relying on previous rules may become incompatible.
Increased code chunk access costs have a particularly significant impact. Some applications may use more gas, potentially causing transactions to exceed the block gas limit.
One proposed mitigation is to raise the block gas limit when introducing EIP-4762. This would reduce the risk of affected applications becoming unusable.
Security Considerations
Under EIP-4762, the Verkle tree layout makes reads and writes to multiple keys sharing a stem less expensive. Access to contiguous storage regions can therefore support denser data processing than before.
Realizing this benefit requires changes to client database design. A database that continues to store each slot separately would fail to exploit the Verkle structure and may become vulnerable to DoS attacks involving a high frequency of witness requests.
Required changes
- Logically separate the commitment scheme from data storage and avoid traversing the whole tree on each lookup.
- In particular, store data for a single stem (256 slots) as one 8 KB BLOB.
- This improves read and write I/O efficiency and optimizes storage for Verkle trees.
Adapting the physical database layout to Verkle witness structures allows clients to balance performance and security.
Citation
Guillaume Ballet (@gballet), Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad), Ignacio Hagopian (@jsign), Tanishq Jasoria (@tanishqjasoria), Gajinder Singh (@g11tech), "EIP-4762: Statelessness gas cost changes [DRAFT]," Ethereum Improvement Proposals, no. 4762, February 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4762.
Conclusion
This article covered EIP-4762, which proposes revising storage and code access costs in preparation for Verkle trees, with the aim of more efficient and secure Ethereum state management. I hope this explanation was helpful.
If you have questions, feel free to contact me via Twitter DM.
I also publish articles on the following platforms.



