EIP-1153 · Final · Core · 2018-06-15
EIP-1153: Transient storage opcodes
Adds TLOAD and TSTORE, a storage-like key/value space that is wiped at the end of every transaction, making reentrancy locks and in-transaction callbacks cheap.
What problem does it solve?
A single transaction can run through many nested calls, and the same contract can be re-entered several times. Those call frames often need to share a bit of state: "am I already inside this function?" for a reentrancy lock, "how much does the caller owe me so far?" for a flash-swap style callback.
Before this EIP the only shared place was regular storage (SSTORE/SLOAD). That is expensive, and since EIP-3529 refunds for clearing a slot are capped at 20 % of the transaction's gas, so the "set then reset" pattern rarely gets its money back. Passing values through calldata does not work when an untrusted contract sits in the middle of the call chain.
How it works
Two new opcodes:
| Opcode | Byte | Stack | Gas |
|---|---|---|---|
TLOAD |
0x5c |
key → value |
100 (like a warm SLOAD) |
TSTORE |
0x5d |
key, value → |
100 (like a warm SSTORE of a dirty slot) |
- Addressing is the same as storage: each contract has its own map of 32-byte keys to 32-byte values.
- Everything is discarded at the end of the transaction. Nothing ever touches disk, so there are no cold/warm surprises and no refunds.
- It is private to the contract, like storage. Under
DELEGATECALL/CALLCODEthe caller's transient storage is used; underCALL/STATICCALLthe callee's. - If a call frame reverts, its transient writes (including those of inner calls) are reverted too.
TSTOREinside aSTATICCALLthrows;TLOADis allowed.- Unlike
SSTORE,TSTOREdoes not have the EIP-2200 rule that fails when only the 2,300-gas stipend is left.
Use cases listed in the spec include reentrancy locks, single-transaction ERC-20 approvals, "till" patterns that check balances are settled at the end of a callback, and passing metadata to proxies without calldata.
Sample code
A reentrancy guard using transient storage (Solidity inline assembly, 0.8.24 or later):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
abstract contract TransientReentrancyGuard {
// Any fixed slot works; it is cleared automatically after the tx.
bytes32 private constant LOCK = keccak256("example.reentrancy.lock");
modifier nonReentrant() {
bytes32 slot = LOCK;
assembly {
if tload(slot) { revert(0, 0) }
tstore(slot, 1)
}
_;
assembly {
tstore(slot, 0) // reset so later calls in the same tx work
}
}
}
contract Vault is TransientReentrancyGuard {
mapping(address => uint256) public balance;
function withdraw(uint256 amount) external nonReentrant {
balance[msg.sender] -= amount;
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok);
}
}
Things to know
- Final and live on Ethereum Mainnet since the Cancun upgrade (Dencun), together with other EVM changes such as
MCOPY(EIP-5656). - "Transient" means per transaction, not per call. Values survive across calls within the same transaction, so reset slots you rely on (e.g. a lock) instead of assuming they start at zero on the next call.
- Do not use it as a substitute for memory: memory is cleared when a call returns, transient storage is not, which can cause surprising behaviour on reentrancy.
- Newer Solidity versions also offer a
transientkeyword for state variables; check your compiler version and EVM target before relying on it. - EIP-7609 proposed lowering the cost of these opcodes further, but it is Stagnant.