Security Advisory: Preventing Flash Loan Reentrancy in Cross-Pool Swaps

Sarah Jenkins
Sarah Jenkins@sarah_secSecurity Auditor
over 1 year ago#1

🛡️ 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:

  1. Transient Storage Mutex (EIP-1153): Use TSTORE / TLOAD for zero-gas cross-contract reentrancy locks.
  2. 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!

1 Post in this topic

Last activity by @alex_evm (Alex Chen)