🛡️ Preventing Flash Loan Reentrancy in Cross-Pool Swaps
In multi-pool AMMs, traditional nonReentrant modifiers may not protect against read-only reentrancy where an external contract queries intermediate reserves while a pool is in an unbalanced flash loan state.
Recommended Defense:
- Transient Storage Mutex (EIP-1153): Use
TSTORE/TLOADfor zero-gas cross-contract reentrancy locks. - Oracle Observation Lag: Always query TWAP or require the lock status check before serving price data to lending protocols.
// Global protocol reentrancy lock via transient storage
modifier globalReentrancyGuard() {
assembly {
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_;
assembly {
tstore(0, 0)
}
}
Stay safe and always run fuzzing tests before mainnet deployments!
