Verification Checklist: Transient Storage & Reentrancy Boundaries
- ✓ Scope Boundary Verification: Clearly distinguish Tx-scope from Frame-scope. Never assume returning from a function automatically zeroes
TSTOREslots; explicit cleanup in bytecode is mandatory. - ✓ Multicall Batch Isolation: Verify whether protocols support sequential invocations in a single transaction. Dirty reentrancy locks will cause subsequent valid calls to revert.
- ✓ Try/Catch Exception Swallowing: Audit outer contracts capturing inner execution errors. If an error is caught without full EVM state reversion, residual transient state corrupts subsequent logic.
- ✓ ERC-4337 Batch Attack Surfaces: When bundlers aggregate multiple UserOps into one L1 transaction, verify that shared transient storage cannot leak cross-user parameters or balances.
1. EIP-1153 Architecture: The Truth Behind 100 Gas TSTORE
In historical EVM versions, standard reentrancy protection (e.g., OpenZeppelin's classic ReentrancyGuard) relied on persistent contract storage via sstore. Switching state from _NOT_ENTERED (1) to _ENTERED (2) and back costs around 2,900 gas for warm storage writes under EIP-2929 rules. For high-frequency DEX swaps and flash accounting, this overhead accumulated rapidly.
EIP-1153 changed this paradigm by introducing two volatile opcodes:
TSTORE (0x5c): Writes 32 bytes to a 32-byte transient slot, strictly costing 100 Gas.TLOAD (0x5d): Reads 32 bytes from a 32-byte transient slot, strictly costing 100 Gas.
Crucially, transient storage never interacts with the Merkle Patricia State Trie. It exists purely in ephemeral execution-client memory tables and is discarded immediately after the transaction concludes. No disk writes, state root hashes, or cryptographic proofs are required, creating a 96%+ gas reduction.
2. The Fatal Misconception: Frame Scope vs. Transaction Scope
Because EIP-1153 documentation highlights that data is "discarded after the transaction," many developers incorrectly assume that transient storage behaves like EVM Memory—cleared when a call frame returns. This assumption is disastrously wrong.
In EVM execution semantics:
- Memory is private to each call frame. Entering a new external call allocates fresh memory space.
- Storage is globally persistent on-chain across all transactions.
- Transient Storage is contract-account global throughout the entire transaction.
Regardless of how many external calls, delegatecalls, or nested frames execute within one transaction, TLOAD accesses the exact same slot mapping for that contract address. If a function executes tstore(REENTRANCY_SLOT, 1), that slot remains 1 when the function finishes unless explicitly rewritten to zero.
3. Vulnerable Patterns: Multicall Deadlocks and Early Returns
Consider the following transient guard implementation commonly adopted in custom hooks and routers:
// Vulnerable transient reentrancy guard implementation
abstract contract VulnerableTransientGuard {
bytes32 private constant GUARD_SLOT = keccak256("guard.slot");
modifier nonReentrant() {
assembly {
if tload(GUARD_SLOT) {
mstore(0x00, 0x8bbb7719) // ReentrancyGuardReentrantCall()
revert(0x1c, 0x04)
}
tstore(GUARD_SLOT, 1)
}
_;
assembly {
tstore(GUARD_SLOT, 0)
}
}
}
While this appears logically identical to traditional guards, production edge cases trigger fatal errors:
Early Returns Bypassing Teardown
If an internal conditional path executes a raw return or compiler-generated jump that skips post-execution blocks, the teardown assembly tstore(GUARD_SLOT, 0) is never reached. The contract remains permanently locked for the rest of that transaction.
Multicall Execution with Swallowed Errors
Modern routers batch actions via multicall(bytes[] calldata data). If call #1 locks the guard, encounters a non-reverting soft failure (or is caught via try/catch), and exits without a state-rolling revert:
- The transient slot remains set to
1; - Call #2 in the same multicall executes;
tload(GUARD_SLOT)returns1, misidentifying a valid sequential call as an illegal reentrancy attempt and reverting the entire transaction.
4. ERC-4337 Account Abstraction: Shared Bundler Collision
An even more subtle vulnerability occurs in ERC-4337 account abstraction infrastructures. Bundlers batch multiple independent user transactions (UserOperations) into a single L1 transaction calling handleOps.
If a protocol utilizes transient storage to track flash accounting or user quotas without guaranteed end-of-call zeroing:
- User A's operation sets a transient balance or parameter;
- User B's operation executes immediately following User A within the same L1 transaction block;
- Contract logic in User B's frame reads dirty residual data left by User A, leading to parameter corruption, unauthorized execution rights, or fund drain.
5. Industrial Defense: Standardized SafeTransientReentrancyGuard
To eliminate transient context leakage, protocol development teams must adhere to strict architectural patterns:
// Production-ready transient reentrancy guard pattern (OpenZeppelin v5.1+ aligned)
abstract contract SafeTransientReentrancyGuard {
bytes32 private constant REENTRANCY_GUARD_SLOT =
0x929eee65222671e245b6613c49c7177fa7d7d8e90d57f68670868f605b082010;
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
assembly {
if tload(REENTRANCY_GUARD_SLOT) {
mstore(0x00, 0x8bbb7719) // ReentrancyGuardReentrantCall()
revert(0x1c, 0x04)
}
tstore(REENTRANCY_GUARD_SLOT, 1)
}
}
function _nonReentrantAfter() private {
assembly {
tstore(REENTRANCY_GUARD_SLOT, 0)
}
}
}
Security audit teams must mandate the following verification protocols:
- Sequential Multicall Invariant Tests: Implement fuzzing suites in Foundry that repeatedly invoke protected endpoints sequentially in single transactions to verify zero leftover lock states.
- Bytecode Control Flow Verification: Disassemble generated EVM bytecode to ensure all basic blocks terminating with
RETURNorSTOPsymmetrically zero out transient slots. - Callback Delta Assertions: For flash accounting systems (such as Uniswap v4 pool managers), verify that all caller-held debt slots are rigorously asserted to equal zero upon exit.
References & Standards
- Ethereum Improvement Proposals: EIP-1153: Transient Storage Opcodes (Cancun)
- OpenZeppelin Contracts: ReentrancyGuardTransient.sol Implementation
- Uniswap v4 Core Whitepaper: Flash Accounting & Transient Storage Invariants
- ERC-4337 Specifications: Account Abstraction Using Alternative Mempools