Introduced in the Cancun upgrade (Solidity 0.8.24+), transient storage via `tstore` and `tload` behaves like storage but is wiped completely at the end of the transaction. It costs only 100 gas per read/write, making reentrancy guards and ERC-20 approvals during complex atomic swaps significantly cheaper.
solidity
bytes32 constant REENTRANCY_SLOT = 0;
modifier nonReentrant() {
assembly {
if tload(REENTRANCY_SLOT) { revert(0, 0) }
tstore(REENTRANCY_SLOT, 1)
}
_;
assembly {
tstore(REENTRANCY_SLOT, 0)
}
}