EIP-7609 · Stagnant · Core · 2024-02-01
EIP-7609: Decrease base cost of TLOAD/TSTORE
A stalled proposal to make transient storage much cheaper (TLOAD 5 gas, TSTORE 8 gas plus a growing charge per new slot), so features like reentrancy locks become almost free while DoS stays expensive.
What problem does it solve?
EIP-1153 added transient storage: TSTORE / TLOAD give contracts a key-value store that lives only for the current transaction. It is ideal for reentrancy locks and passing data between calls. It was priced at 100 gas per operation, the same as a warm storage access, partly for simplicity and partly to guard against two DoS concerns: allocating too much transient memory and the cost of rolling it back on revert.
The authors argue this is overpriced. Transient storage never touches the database, has no refunds, and needs allocation only once per contract per transaction. If the first few slots were very cheap, compilers could even enable reentrancy protection by default.
How it works
The proposal replaces the flat price with:
TLOAD: 5 gas (similar CPU cost toMULin benchmarks).TSTORE: 8 gas, plus an expansion cost when the key is new in that contract's transient storage. The expansion cost is 1 gas times the number of slots already allocated.
So writing the n-th new slot costs roughly 8 + (n - 1) gas. This is cheaper than today for common cases (the spec estimates fewer than about 95 slots written per contract) and grows quadratically for anyone trying to allocate huge amounts.
The spec's security analysis, assuming a 30M gas block: a single contract could allocate about 7,739 slots (around 248 KB). Spreading allocation across many contracts reaches about 23,000 slots (around 736 KB) per transaction, which the authors note is less memory than the current schedule allows.
Sample code
Pricing from the spec:
G_LOW = 5
G_MID = 8
SLOPE = 1
def gas_tload(_key):
return G_LOW
def gas_tstore(key, transient_mapping):
cost = G_MID
if key not in transient_mapping:
cost += SLOPE * transient_mapping.size()
return cost
The use case it targets, a transient reentrancy guard (Solidity 0.8.24+):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
abstract contract TransientReentrancyGuard {
bytes32 private constant SLOT = keccak256("reentrancy.guard");
modifier nonReentrant() {
bytes32 slot = SLOT;
assembly {
if tload(slot) { revert(0, 0) }
tstore(slot, 1)
}
_;
assembly { tstore(slot, 0) }
}
}
Today each tload/tstore costs 100 gas; under this proposal the same guard would cost about 5 + 8 + 8 gas.
Things to know
- Status is Stagnant: it has not been scheduled for any upgrade, and mainnet transient storage still uses the EIP-1153 pricing.
- The extra charge depends on how many slots the current contract has already written in this transaction, so gas for a
TSTOREwould vary with prior activity. - The DoS bounds in the spec are computed for a 30M gas limit and scale linearly with it.