In traditional finance, you can't borrow $100 million without collateral and a lengthy approval process. In DeFi, you can — and the loan is approved, used, and repaid within a single Ethereum transaction. This is a flash loan, and it fundamentally changed the economics of smart contract exploitation.
What is a flash loan?
Flash loans are a DeFi primitive that allow users to borrow any amount of liquidity from a pool (Aave, dYdX, Uniswap V3) without posting collateral — provided the borrowed amount plus fees is returned within the same transaction. If the repayment condition isn't met, the entire transaction reverts, as if it never happened. The lender bears no risk.
Why flash loans enable attacks
Before flash loans, most DeFi attacks required the attacker to hold significant capital. A price manipulation attack on a $10 million liquidity pool might require $5 million to move the price meaningfully — only viable for well-capitalized actors. Flash loans remove this barrier entirely. An attacker with zero capital can borrow $50 million, manipulate markets, exploit a vulnerability, and repay the loan — all atomically.
Anatomy of a flash loan attack
A typical attack follows this structure within a single transaction:
- Borrow: Flash loan $50 million USDC from Aave.
- Manipulate: Swap the $50 million into a target asset on a low-liquidity DEX, dramatically moving the spot price.
- Exploit: Call the victim protocol's function that reads the (now manipulated) spot price as an oracle — e.g., borrow against inflated collateral, or mint tokens based on the fake price.
- Profit: Swap back the exploited assets.
- Repay: Return the $50 million plus the 0.05% flash loan fee.
Net cost: ~$25,000 in fees. Net profit: potentially millions.
Real-world examples
- bZx (February 2020) — Two attacks within days of each other. The first netted ~$360,000 using a flash loan to manipulate a margin position. The second netted ~$600,000 using oracle manipulation. These were the first major flash loan attacks and established the template.
- Harvest Finance (October 2020) — $34 million drained. The attacker used flash loans to repeatedly swing the USDC/USDT price on Curve, then deposited and withdrew from Harvest at manipulated prices.
- Cream Finance (October 2021) — $130 million. A complex flash loan attack exploiting price oracle manipulation across multiple Cream markets simultaneously.
- Mango Markets (October 2022) — $116 million. The attacker inflated the MNGO perpetual price by buying both sides of the order book with their own funds, then used the inflated positions as collateral to borrow and drain the treasury.
How protocols can prevent flash loan attacks
1. Use manipulation-resistant oracles
Replace all spot price reads from DEX pools with Chainlink price feeds or Uniswap V3 TWAP oracles (minimum 30-minute observation window). A TWAP cannot be moved significantly within a single block.
2. Add slippage and sanity checks
Before accepting an oracle price for a financial operation, check that it hasn't moved more than X% from a reference price in the last block. Revert if the deviation is suspicious.
3. Circuit breakers
Limit the size of any single transaction or the total amount that can flow through a price-sensitive function in one block. Large flash loan attacks are only possible because there are no caps on transaction size.
4. Avoid spot prices in all state-changing functions
Any function that mints tokens, adjusts collateral, or determines a payout based on a DEX price is a potential flash loan target. Audit every such function for manipulation risk.
Concerned about flash loan vulnerabilities in your contracts? Run a free AI audit that specifically models economic attack scenarios including flash loan vectors.