EIP-5022 · Stagnant · Core · 2022-04-20
EIP-5022: Increase price of SSTORE from zero to non-zero to 40k gas
Proposed doubling the gas cost of SSTORE when it creates a new storage slot (zero to non-zero) from 20,000 to 40,000, to price state growth more honestly.
What problem does it solve?
Every new storage slot permanently grows Ethereum's state, which all full nodes must keep. As state grows, each new slot makes nodes slower and more expensive to run. Yet the price of creating a slot has been fixed at 20,000 gas.
The author argues this is underpriced: because all resources share one gas limit, users of every other opcode are effectively subsidizing state creation. State growth is also one of the main reasons the gas limit is not raised. Pricing new storage more accurately would make a higher gas limit more feasible.
How it works
One change to the gas schedule from a fork block (the spec leaves it TBD):
| Case | Before | After |
|---|---|---|
SSTORE zero to non-zero (SSTORE_SET_GAS) |
20,000 | 40,000 |
All other SSTORE cases |
unchanged | unchanged |
Things deliberately not changed:
- Non-zero to non-zero writes: they do not grow state, so they stay the same. A higher creation price also nudges developers to reuse slots.
- Refunds for clearing a slot: left open for more discussion.
The spec presents this as a short-term patch while longer-term ideas such as state rent or state expiry are researched.
Sample code
Where the change would show up in a contract: the first write to a mapping entry creates a slot.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Registry {
mapping(address => uint256) public score;
function set(uint256 v) external {
// First write for msg.sender: zero -> non-zero.
// Today: SSTORE_SET_GAS = 20,000 (plus cold-access cost).
// Under EIP-5022: 40,000.
// Later writes (non-zero -> non-zero) are unaffected.
score[msg.sender] = v;
}
}
Things to know
- Status is Stagnant: the change was not adopted.
- The spec acknowledges it would severely raise costs for many applications, and contracts with hard-coded gas amounts that create storage would break.
- The full
SSTOREcost also depends on net gas metering (EIP-2200), cold/warm access (EIP-2929) and refund rules (EIP-3529); this EIP only touches the slot-creation constant. - The spec's security considerations section is empty (
TODO).