A flash loan attack uses zero-capital borrowing to manipulate a protocol in a single transaction: borrow millions, manipulate a price oracle or exploit a logic flaw, extract profit from the manipulated state, repay the loan, and keep the difference. The entire sequence executes atomically. If any step fails, everything reverts and the attacker loses only the gas fee for the failed attempt.

What Is a Flash Loan Attack (Step by Step)?

4 min read

The short version

A flash loan attack is robbing a bank using the bank own money. You borrow $50 million from the bank vault, use it to trick the bank system into thinking your empty account has $5 million, withdraw that $5 million into your pocket, return the $50 million to the vault, and leave with $5 million profit. The whole thing takes 12 seconds and if the trick does not work, time rewinds and nothing happened.

How It Works

The typical attack pattern in five steps: Step 1 (Borrow): flash-borrow a large amount from Aave, dYdX, or Uniswap (often $10M-$200M). No collateral needed. Cost: 0.05-0.09% fee (only paid if the full transaction succeeds). Step 2 (Manipulate): use the borrowed capital to distort something the target protocol relies on. Common manipulation targets: DEX pool prices (dump tokens into a pool to crash the spot price), oracle-dependent protocols (make the oracle report a wrong price), governance systems (acquire voting power), or thin liquidity (drain one side of a pool). Step 3 (Exploit): interact with the target protocol while it is in the manipulated state. The protocol makes a bad decision based on the distorted data: liquidates healthy positions (oracle showed wrong price), allows excessive borrowing (inflated collateral value), or executes a trade at a skewed rate. Step 4 (Extract): take the profit generated by the protocol bad decision. This might be: receiving liquidation bonuses on positions that should not have been liquidated, withdrawing more than deposited due to inflated valuations, or buying tokens cheaply from a manipulated pool. Step 5 (Repay): return the flash loan plus fee. If the profit exceeds the fee, the transaction succeeds. The attacker walks away with the spread. If any step reverts (profit is less than the loan amount), the entire transaction reverts atomically and the attacker loses only the gas fee (~$10-50 for a failed attempt).

Anatomy of a real flash loan oracle manipulation ($7M profit)

A lending protocol uses the spot price of TOKEN on a single Uniswap pool as its price oracle. The pool has $5M liquidity. Attack transaction: (1) Flash borrow 10,000 ETH ($30M) from Aave. Fee if successful: $27,000. (2) Sell 8,000 ETH into the TOKEN/ETH pool on Uniswap. This crashes TOKEN price from $10 to $2 on that specific pool (massive sell pressure into thin liquidity). (3) The lending protocol reads the manipulated pool price ($2 instead of $10) and now considers all TOKEN collateral severely undercollateralized. (4) Liquidate every TOKEN-collateralized position on the lending protocol at the manipulated $2 price. Receive TOKEN at 5% bonus. (5) Buy back TOKEN on other DEXs at the real price ($10 minus small impact). Total TOKEN acquired via liquidation at $2: worth $15M at real price. Cost to acquire: $3M (liquidation price) + pool manipulation losses ($5M in ETH price impact). (6) Repay 10,000 ETH to Aave. Net profit: approximately $7M minus $27K fee. All in one block. The lending protocol is drained of its TOKEN collateral. Users wake up liquidated on positions that were actually healthy. The fix: the protocol should have used Chainlink (multi-source oracle) instead of a single-pool spot price.

What People Get Wrong

  • Flash loan attacks are a new type of hack

    The flash loan is not the attack itself. It is capital amplification that makes existing vulnerabilities exploitable at larger scale. The real vulnerability is always in the target protocol (bad oracle design, missing access controls, exploitable logic). Flash loans just provide the capital to exploit it profitably. Fixing the vulnerability makes the flash loan useless.

  • Banning flash loans would prevent these attacks

    Flash loans are just one capital source. A wealthy attacker could execute the same manipulation with their own funds (no flash loan needed, just slower and more capital-intensive). Flash loans democratized exploitation (anyone can try) but did not create the underlying vulnerabilities. Proper protocol design prevents the attack regardless of capital source.

  • If a protocol was flash-loan attacked, all protocols using flash loans are unsafe

    Flash loans are a neutral tool. Aave (which provides flash loans) has never been successfully attacked through its own flash loan mechanism. The vulnerability is always in the target protocol design, not in the lending protocol providing the capital. Protocols with robust oracles and access controls are safe regardless of flash loan availability.

Sources & Further Reading

  • Rekt.news

    Post-mortem analyses of every major flash loan attack with transaction breakdowns

  • Aave Flash Loans

    Technical documentation for the most-used flash loan provider

Questions People Also Ask

How much do flash loan attacks typically steal?
Range: $500K to $200M per incident. The largest flash-loan-assisted exploits: Cream Finance ($130M, 2021), Beanstalk ($182M via flash-loan governance, 2022), Euler Finance ($197M, though technically a logic bug amplified by flash-borrowed capital, 2023). Smaller attacks ($1-5M) happen monthly on lesser-known protocols.
Can I execute a flash loan attack?
Technically: anyone can write a flash loan contract and attempt an exploit. Practically: finding exploitable vulnerabilities requires deep smart contract expertise, and profitable opportunities are competed for by professional MEV searchers with custom infrastructure. Attempting exploitation of protocols is also increasingly prosecuted as fraud (see: Mango Markets attacker conviction, 2024). White-hat disclosure via bug bounties is the legal path.
How do protocols defend against flash loan attacks?
Use decentralized oracles (Chainlink, not single-pool spot prices), implement TWAP (Time-Weighted Average Price) that cannot be moved in one block, add access controls that check positions across multiple blocks (preventing same-block manipulation), and conduct audits specifically testing flash loan attack vectors.

More in DeFi Mechanics

See all →
Was this page helpful?

Page last checked