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 examines EIP-2200, which introduces a more flexible gas accounting mechanism for Ethereum storage writes to better reflect the work performed and reduce unnecessary gas consumption.

The explanation below translates, summarizes, and expands on the original proposal. The gas parameters discussed are historical EIP-2200 parameters; subsequent EIPs have changed Ethereum's gas and refund rules.

I also cover a range of other EIPs.

Overview

EIP-2200 revises gas accounting for the SSTORE opcode used to modify smart contract storage in Ethereum. It combines EIP-1283 and EIP-1706 into a more structured definition, facilitating integration with other gas-related changes such as EIP-1884.

For more on EIP-1706, see the following article.

[EIP-1706] Understanding the 2,300-Gas Restriction on SSTORE

For more on EIP-1884, see the following article.

[EIP-1884] Repricing Resource-Intensive Opcodes

EIP-1283 introduced net gas metering, a mechanism intended to avoid charging unnecessarily high gas costs for storage changes that do not ultimately change the persistent state.

For more on EIP-1283, see the following article.

[EIP-1283] Understanding SSTORE Gas Optimization

EIP-2200 builds on this approach by accounting for the following information when evaluating storage writes.

  • The original value of the storage slot at the beginning of the transaction.
  • Its current value, which may have changed during execution.
  • The refund counter, which tracks potential gas refunds arising from storage changes.

Together with the new value being written, this information supports more flexible and efficient storage gas accounting.

Motivation

The primary motivation for EIP-2200 is to make SSTORE gas accounting better reflect actual implementation and usage patterns. Under earlier rules, storage operations that made no meaningful persistent state change could still incur excessive gas costs, making certain use cases inefficient.

Examples include writing repeatedly to the same storage slot within a function call, communicating error information, and temporarily exchanging state through storage. Even when an application restores the original value before the transaction finishes, earlier gas accounting could charge substantial costs. EIP-2200 reduces the cost of such temporary storage modifications.

EIP-1283 also introduced a potential reentrancy risk when combined with Solidity's value-transfer mechanisms that provide a 2,300-gas stipend. EIP-2200 addresses that concern by preventing SSTORE from executing when the remaining gas is at or below the stipend.

The proposal also replaces hard-coded gas constants with named parameters, making subsequent changes and optimizations easier to specify.

These improvements aim to address shortcomings in previous storage pricing and make Ethereum contract development more efficient while preserving relevant security assumptions.

Specification

Gas parameter definitions and changes

EIP-2200 defines several gas parameters to specify storage-write accounting precisely.

  • SLOAD_GAS
    • Gas cost associated with storage reads.
    • Increased from 200 to 800.
  • SSTORE_SET_GAS
    • Gas charged when setting a previously zero storage slot to a nonzero value.
    • 20,000, unchanged.
  • SSTORE_RESET_GAS
    • Gas charged when changing a clean slot whose original value is nonzero.
    • 5,000, unchanged.
  • SSTORE_CLEARS_SCHEDULE
    • Amount added to the refund counter when a qualifying nonzero slot is cleared.
    • 15,000, unchanged.

These parameters are used to express the combined rules of EIP-1283 and EIP-1706.

New SSTORE gas accounting logic

EIP-2200 defines more precise rules for gas charges and refunds when executing SSTORE. Three values associated with the storage slot are particularly important.

  • original value
    • The slot's value at the beginning of the transaction.
  • current value
    • The latest value visible during execution.
  • new value
    • The value to be written by the current SSTORE operation.

Gas accounting proceeds as follows.

First, if gasleft is less than or equal to the gas stipend, execution fails with an out-of-gas exception.

If the current value equals the new value, the operation is a no-op and consumes only SLOAD_GAS.

If the current and new values differ, the charge and refund adjustments depend on the slot's state.

Case 1: A clean storage slot (original = current)

The slot currently contains its original value.

  • If the original value is zero, charge SSTORE_SET_GAS (20,000).
  • Otherwise, charge SSTORE_RESET_GAS (5,000).
  • If the original value is nonzero and the new value is zero, add SSTORE_CLEARS_SCHEDULE (15,000) to the refund counter.

Case 2: A dirty storage slot (original ≠ current)

The slot's current value differs from its original value.

  • Charge only SLOAD_GAS (800), and apply the following refund adjustments.
  • If the original value is nonzero:

    • If the current value is zero and the new value is nonzero, subtract SSTORE_CLEARS_SCHEDULE from the refund counter.
    • If the new value is zero and the current value is nonzero, add SSTORE_CLEARS_SCHEDULE to the refund counter.
  • If the new value equals the original value:

    • If the original value is zero, add SSTORE_SET_GAS - SLOAD_GAS (19,200) to the refund counter.
    • Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS (4,200).

The resulting gas charges and refund adjustments therefore depend on the pattern of storage transitions.

Implementation considerations

Under EIP-2200, a refund counter maintained separately for each call frame can temporarily become negative. If refunds are tracked across the transaction as a whole, the counter remains nonnegative. EVM implementers must therefore account for the scope at which gas refunds are tracked.

Rationale

Supporting temporary storage use cases

EIP-2200 aims to support many use cases associated with the storage optimizations proposed by EIP-1087 and the transient storage concept proposed by EIP-1153, using a simpler accounting mechanism. It enables efficient writes within existing persistent storage without requiring a separate dirty map or additional storage structure. Unlike actual transient storage, ordinary storage does not automatically clear at the end of the transaction.

For more on EIP-1153, see the following article.

[EIP-1153] Understanding Transient Storage in the EVM

EIP-1087 relied on a dirty map to track changes to storage. This assumes a model in which all storage changes are committed to the state trie (Merkle Patricia Trie) at the end of a transaction. Not every Ethereum client uses that model.

For more on EIP-1087, see the following article.

[EIP-1087] Reducing Gas Costs for Storage Writes

Implementation efficiency and flexibility

Efficient clients, particularly in the context of EIP-658, may temporarily retain storage changes in memory using lightweight trie structures without RLP encoding or immutable data structures. For these clients, iterating over the complete set of modified storage slots introduces unnecessary computational and memory overhead.

For more on EIP-658, see the following article.

[EIP-658] Making Transaction Success and Failure Easier to Determine

EIP-2200 operates using the original and current storage values, avoiding additional processing solely to identify dirty slots. It does not require an additional runtime dirty map, allowing existing client storage mechanisms to be reused.

Gas cost consistency

An important objective of EIP-2200 is to avoid increasing the absolute net cost of comparable storage operations under the assumptions used in its rationale. This comparison concerns storage gas accounting and refunds, rather than guaranteeing identical costs for every possible transaction or subsequent gas schedule.

The proposal also offers savings comparable to those discussed in EIP-1087. The following historical examples use SLOAD_GAS = 200, rather than EIP-2200's actual 800-gas parameter.

  • Setting slot 0 to 1 and then restoring it to 0 costs 400 net gas (20000 + 200 - 19800).
  • The example of incrementing an initially empty slot uses a calculation of 21000 gas (20000 + 5 × 200), corresponding to the initial set plus five additional 200-gas operations.
  • Transferring through accounts A, B, and C with existing balances costs 10400 net gas (5000 × 3 + 200 - 4800).

These examples describe net accounting before any transaction-wide refund cap is applied.

Security and compatibility considerations

EIP-1283 raised concerns that storage could be modified within the 2,300-gas stipend provided by Solidity's transfer and send, potentially exposing contracts to reentrancy risks.

EIP-2200 adds a rule prohibiting SSTORE when the remaining gas is at or below the stipend, preserving the relevant assumptions of existing contracts. This restriction is not a general guarantee against reentrancy.

Alternative approaches and their limitations

Several other approaches were proposed, each with disadvantages.

  • Reverting EIP-1283
    • Discards useful functionality and creates inconsistencies with existing testnet and client implementations.
  • Introducing a new call type that prohibits state modification
    • Increases specification complexity.
  • Raising SSTORE costs to at least the stipend
    • Sacrifices the benefits of net gas metering.
  • Reducing the stipend itself
    • Reduces the usefulness of transfer.
  • Increasing gas refunds
    • Requires users to provide additional gas upfront and receive refunds later.
  • Assigning an EVM version to each contract
    • Substantially increases protocol complexity.

By comparison, EIP-2200 offers a practical solution with relatively limited implementation changes, balancing flexibility and security while remaining consistent with existing design assumptions.

Compatibility

Implementing EIP-2200 requires a hard fork. The proposal aims to preserve existing contracts' storage behavior. In particular, the previous minimum charge for an ordinary state-changing SSTORE was 5,000 gas, already above the stipend restriction introduced by EIP-2200.

Many contracts can instead benefit from reduced net gas costs, especially when storage is modified temporarily. These use cases can perform operations more efficiently than under earlier gas accounting rules.

Gas estimation must nevertheless account for the new requirements, because the rules for gas charges and refunds have changed.

Test cases

The following table shows bytecode examples, gas consumption, refunds, and changes to storage slot values.

Bytecode Gas used Gas refund Original value First Second Third
0x60006000556000600055 1612 0 0 0 0
0x60006000556001600055 20812 0 0 0 1
0x60016000556000600055 20812 19200 0 1 0
0x60016000556002600055 20812 0 0 1 2
0x60016000556001600055 20812 0 0 1 1
0x60006000556000600055 5812 15000 1 0 0
0x60006000556001600055 5812 4200 1 0 1
0x60006000556002600055 5812 0 1 0 2
0x60026000556000600055 5812 15000 1 2 0
0x60026000556003600055 5812 0 1 2 3
0x60026000556001600055 5812 4200 1 2 1
0x60026000556002600055 5812 0 1 2 2
0x60016000556000600055 5812 15000 1 1 0
0x60016000556002600055 5812 0 1 1 2
0x60016000556001600055 1612 0 1 1 1
0x600160005560006000556001600055 40818 19200 0 1 0 1
0x600060005560016000556000600055 10818 19200 1 0 1 0

Security design and proof

EIP-2200 provides theoretical justification for the consistency of SSTORE gas charges and refunds. The original storage value is defined relative to the beginning of the transaction, rather than being redefined for each call frame. This provides a consistent reference point for accounting across nested calls.

The design analyzes gas costs for several storage transition patterns.

Proof cases with an original value of zero

  • If the final value is zero, the net storage cost is 200 * N gas in the historical 200-gas parameter example.
  • If the final value is nonzero, the net charge is based on an initial 20,000-gas set plus 200 gas for each remaining operation.

Proof cases with a nonzero original value

  • If the final value equals the original value, the net storage cost is 200 * N gas.
  • If the final value is zero, the net accounting is 5000 - 15000 + 200 * (N - 1), including the refund adjustment.
  • If the final value is a different nonzero value, the net accounting is 5000 + 200 * (N - 1).

These examples use the historical 200-gas read parameter discussed in the rationale. The proposal establishes the correctness of its accounting across state transitions through inductive proofs.

Citation

Wei Tang (@sorpaas), "EIP-2200: Structured Definitions for Net Gas Metering," Ethereum Improvement Proposals, no. 2200, July 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2200.

Conclusion

This article covered EIP-2200, which revises gas accounting for Ethereum storage writes to better reflect storage transitions and reduce unnecessary gas consumption.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/