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-1087, which proposes reducing unnecessary gas consumption for storage changes and enabling more flexible smart contract designs.
This article translates, summarizes, and supplements the material linked below.
I have also covered other EIPs.
Overview
EIP-1087 proposes revising gas accounting for the EVM's SSTORE operation, which writes to contract storage.
Under the historical accounting rules discussed by the proposal, temporary changes and operations that ultimately restore the original state can consume substantial gas. The proposal seeks to rationalize these charges.
By addressing cases where storage gas costs do not accurately reflect resource usage, EIP-1087 aims to reduce unnecessary costs and enable additional use cases.
Motivation
The historical SSTORE gas rules described in the Japanese article are as follows.
- Changing a slot from
0to a nonzero value.20,000gas.
- Other changes, including nonzero-to-nonzero and nonzero-to-zero writes.
- 5,000 gas.
- Changing a nonzero value to
0.- The article states a subsequent 10,000-gas refund.
The Japanese source uses 10,000 in this description; the historical refund rule cited in EIP-1087 should be checked separately. These are not current Ethereum gas parameters.
Although such rules may appear reasonable in isolation, multiple writes in one transaction can consume substantial gas even when no lasting storage change needs to be written to disk.
For example, an empty storage slot may be set to 1 and immediately reset to 0. The article illustrates a total cost of 15,000 gas (20,000 + 5,000 - 10,000), despite there being no persistent storage change.
It also illustrates repeated increments using a historical estimate of 45,000 gas (20,000 + 5 × 5,000). This formula counts an initial write followed by five further writes.
Similarly, sequential balance transfers from address A to B and then from B to C may involve charges for intermediate storage updates that do not reflect the final persistent changes.
Revising inefficient gas accounting makes additional use cases more practical.
Examples include mutexes for preventing reentrancy, where a temporary flag is written and restored before the transaction finishes, and mechanisms that pass contextual information between function calls.
One example is approveAndCall, which combines token approval and a subsequent call in one transaction, potentially allowing an approved transfer without requiring a separate transaction. This can improve contract usability without changing the underlying token standard.
Many such patterns were expensive under the earlier gas accounting scheme. EIP-1087 seeks to make them more practical.
Specification
EIP-1087 revises the calculation of gas costs for EVM storage writes, reducing the cost of repeated modifications within a transaction.
The proposal uses a per-transaction dirty map.
What Is a Dirty Map?
A dirty map records storage slots modified during the current transaction.
As the transaction executes, the EVM records modified storage slots for each contract and uses this information to calculate gas charges and refunds.
If an internal call reverts, changes to the dirty map within that call must also be reverted. Dirty-map changes follow the same rollback scope as storage changes.
Gas Charges for Storage Writes
The proposed accounting rules are as follows.
Writing the same value already present in the slot (a no-op) costs 200 gas.
If the slot has not previously been modified in the transaction:
- An original value of zero incurs a cost of 20,000 gas.
- An original nonzero value incurs a cost of 5,000 gas.
The slot is then marked dirty.
Subsequent writes to an already dirty slot cost only 200 gas, reflecting the absence of an additional persistent storage write.
Gas Refunds at the End of a Transaction
At the end of a transaction, each slot in the dirty map is considered for a refund.
- If the original and final values are both zero, refund 19,800 gas.
- If the original value is nonzero and the final value equals the original value, refund 4,800 gas.
- If the original value is nonzero and the final value is zero, refund 15,000 gas.
Temporary changes that restore the original value can therefore incur a smaller net gas cost reflecting their limited persistent resource usage.
Actual transaction-level refunds remain subject to the applicable refund cap.
Examples of Cost Reductions
The following comparisons reproduce the numerical examples given in the Japanese article.
- Setting an empty slot to 1 and immediately resetting it to 0.
- Earlier accounting: 15,000 gas.
- Proposed accounting: 400 gas (20,000 + 200 - 19,800).
- Repeated increments of an initially empty slot.
- Earlier accounting: 45,000 gas.
- Proposed accounting: 21,000 gas (20,000 + 5 × 200).
- Sequential transfers A → B → C, with nonzero balances.
- Earlier accounting: 20,000 gas.
- Proposed accounting: 10,400 gas (5,000 × 3 + 200 - 4,800).
The original examples contain a potential mismatch with the historical refund value and the number of increment operations. The figures are retained for comparison with the source, not presented as current gas estimates.
Significance of the Change
The proposal introduces more appropriate gas accounting for contract logic that repeatedly modifies the same storage slot within one transaction.
It is intended to make sophisticated contract designs practical where their storage costs were previously prohibitive.
Temporary on-chain state, reentrancy mutexes, and contracts involving complex state transitions could particularly benefit.
Compatibility
Implementing EIP-1087 would require a hard fork: a coordinated change to the protocol rules followed by Ethereum nodes.
The proposal is intended to preserve existing smart contract behavior while reducing gas costs in many cases, minimizing compatibility problems at the contract layer.
However, contracts that depend on exact gas costs or gas-limited execution still need compatibility assessment when gas schedules change.
Test Cases
The proposal defines test cases for its revised gas and refund accounting.
They cover combinations of original and new slot values as well as transaction behavior such as reverts.
Representative cases described in the Japanese article include:
- Writing a nonzero value into an initially zero slot costs 20,000 gas without a refund.
- Changing an existing nonzero value to another nonzero value costs 5,000 gas without a refund.
- Clearing a nonzero slot costs 5,000 gas. The Japanese test description states a 10,000-gas refund, which is inconsistent with the 15,000-gas rule described above and should be reviewed against the original EIP.
- Writing zero to an already zero slot costs 200 gas with no refund.
- Writing the same existing value costs 200 gas with no refund.
- Writing x to an initially zero slot and then writing a distinct y costs 20,000 + 200 = 20,200 gas with no refund.
- The first modification is expensive; the second is cheaper.
- Sequential nonzero changes x → y → z can cost approximately 5,200 gas with no refund.
- Writing x to an initially zero slot and then restoring zero costs 20,200 gas, with a refund counter increase of 19,800 gas.
- Changing an original value y to x and then restoring y costs 5,200 gas, with a refund counter increase of 4,800 gas.
- Reverted storage operations still consume gas, but their rolled-back changes do not remain in the dirty map for refund accounting.
- In a nested call, writing x and subsequently restoring an originally zero slot can also qualify for the 19,800-gas refund.
These cases illustrate how the proposed accounting handles temporary changes and rollback without unnecessarily charging for persistent storage writes.
The tests are intended to verify correct implementation and more predictable gas accounting. EIP-1087 is a historical proposal; the values should not be used as the current Ethereum gas schedule.
Citation
Nick Johnson (@arachnid), "EIP-1087: Net gas metering for SSTORE operations [DRAFT]," Ethereum Improvement Proposals, no. 1087, May 2018. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-1087.
Conclusion
EIP-1087 proposes net gas metering for storage operations, reducing unnecessary costs associated with temporary changes and repeated writes.
If you have questions, feel free to contact me on Twitter.
I also publish articles on the following platforms.



