EIP-3298 · Draft · Core · 2021-02-26
EIP-3298: Remove storage-clear refund and refund cap
Draft that removes the SSTORE storage-clearing refund and the 20% refund cap, keeping only the refund for undoing a write within the same transaction.
What problem does it solve?
Since Frontier, Ethereum has refunded gas when a contract clears a storage slot, to reward "state hygiene". In practice the incentive never worked well, and it was abused (gas tokens) until EIP-3529 cut refunds and capped them at 20% of gas used.
Today, state growth is being addressed by charging for state creation directly (EIP-8037), not by rebates for cleanup. Meanwhile the refund counter and its cap complicate gas settlement, interacting with the calldata floor of EIP-7623 and the separate gas dimensions of EIP-8037. This EIP removes the last cross-transaction refund and the cap that exists mainly to contain it.
How it works
The spec is written as a change on top of EIP-8037 and EIP-8038, and assumes those plus EIP-2780 and EIP-7778 are active.
Removed: STORAGE_CLEAR_REFUND (11,616 gas under EIP-8038) and both rules that use it: the refund for clearing a slot whose original value was non-zero, and the reversal of that refund if the slot is restored.
Kept: one rule. If an SSTORE sets a slot back to its original value (its value at the start of the transaction) and that differs from its current value, STORAGE_WRITE is refunded. This is net metering: a round trip like x → y → x pays only access costs, not for a write that was undone.
Cap removed: the transaction refund is simply the refund counter.
tx_gas_used_before_refund = tx.gas - gas_left - state_gas_reservoir
tx_gas_used_after_refund = tx_gas_used_before_refund - refund_counter # no // 5 cap
tx_gas_used = max(tx_gas_used_after_refund, calldata_floor_gas_cost)
The cap is safe to drop because the remaining refund is self-bounded: each refund reverses exactly one STORAGE_WRITE already charged in the same transaction, and refunds from reverted frames are discarded. Block-level gas accounting already ignores refunds under EIP-7778, so worst-case block resource use does not change.
Sample code
Refund counter for one warm slot under this EIP (W = STORAGE_WRITE), from the spec:
| Sequence (original first) | Charged | Refunded | Net write cost |
|---|---|---|---|
0 → x |
W |
0 | W |
0 → x → 0 |
W |
W |
0 |
x → 0 |
W |
0 | W (no clearing refund) |
x → y → x |
W |
W |
0 |
x → y → x → z |
W, W |
W |
W |
A pattern that stays cheap, a re-entrancy lock that ends where it started:
uint256 private locked = 1;
modifier nonReentrant() {
require(locked == 1);
locked = 2; // write: charged
_;
locked = 1; // back to original: write refunded
}
Things to know
- Status: Draft. It depends on several proposals that are themselves not final, and the spec describes it as targeting the fork after the one that ships EIP-8038.
- Contracts that clear storage to collect refunds (batch cleanup, gas-token-style tricks) would pay more: clearing a slot would no longer return gas.
- Gas estimators and wallets would need to drop clearing-refund and refund-cap logic.
- The spec warns that any future refund not backed by a same-transaction charge must bring back a cap or an equivalent bound.
- For temporary flags like locks, transient storage (EIP-1153) avoids persistent writes entirely.