Flash Loan Attack
A flash loan attack exploits uncollateralized loans that must be borrowed and repaid within a single transaction, using the large capital to manipulate protocol state for profit.
In Depth
Flash loan attacks leverage the unique DeFi primitive of uncollateralized loans that exist only within a single atomic transaction. Attackers borrow massive amounts of capital at zero cost, use it to manipulate prices, exploit vulnerable protocol logic, or drain funds, and repay the loan before the transaction completes. Notable flash loan attacks include the bZx exploits in 2020 and the Cream Finance hack in 2021, which resulted in over $130 million in losses. Invariant testing is particularly effective at catching flash loan vulnerabilities because it can simulate large, arbitrary capital movements and verify that protocol accounting remains consistent regardless of transaction size.
Frequently Asked Questions
What is a flash loan attack?
A flash loan attack uses uncollateralized DeFi loans that must be repaid within the same transaction. The attacker borrows a large sum, uses it to manipulate a protocol (e.g., by skewing prices or exploiting logic bugs), extracts profit, repays the loan, and keeps the profit — all in one atomic transaction.
How can protocols defend against flash loan attacks?
Protocols can defend against flash loan attacks by using manipulation-resistant oracles like Chainlink or TWAPs, implementing checks that limit the impact of single-transaction capital movements, and using invariant testing to verify that protocol state remains consistent regardless of the size of deposits or trades.
Can invariant testing detect flash loan vulnerabilities?
Yes. Invariant testing can simulate extreme capital movements — deposits, swaps, and withdrawals of arbitrarily large amounts — and check that protocol invariants like solvency, correct exchange rates, and accurate accounting hold under all conditions. This naturally surfaces the same classes of bugs that flash loan attackers exploit.