Flash Loan Attack

A flash loan attack uses uncollateralized, single-transaction borrowing to exploit pricing or logic flaws in DeFi protocols.

What Is a Flash Loan Attack?

A flash loan attack is a type of exploit in decentralized finance where an attacker uses an uncollateralized flash loan to manipulate protocol mechanics and extract value, all within a single atomic transaction. Because flash loans require no upfront capital and must be repaid within the same block, attackers can temporarily command enormous sums — often tens or hundreds of millions of dollars — to bend market conditions in their favor. If any step in the attack fails, the entire transaction reverts, meaning the attacker risks nothing beyond the gas cost of submitting the transaction.

Flash loan attacks have become one of the most significant security concerns in DeFi, responsible for hundreds of millions of dollars in cumulative losses across dozens of protocols since 2020.

How a Flash Loan Attack Works

A typical flash loan attack follows a predictable sequence, though the specific vulnerability exploited varies from case to case:

  1. Borrow a large sum — The attacker takes out a flash loan for millions of dollars in cryptocurrency, usually from a protocol like Aave or dYdX.
  2. Manipulate a price feed or market — The borrowed funds are used to distort the price of an asset on a vulnerable decentralized exchange or lending market. This might involve making a massive swap that temporarily moves a price on a low-liquidity pool.
  3. Exploit the distorted state — With the manipulated price in effect, the attacker interacts with a target protocol that relies on that price. For example, they might borrow far more than they should be entitled to from a lending market that reads its prices from the manipulated pool.
  4. Repay the flash loan — The attacker returns the borrowed amount plus a small fee to the flash loan provider.
  5. Keep the profit — Whatever value was extracted from the target protocol beyond the loan repayment and fees is pure profit.

The entire sequence happens in a single transaction. If the profit is insufficient to cover the flash loan repayment, the transaction simply reverts as though it never happened.

Why Flash Loan Attacks Are So Dangerous

Flash loan attacks are uniquely dangerous because they eliminate capital requirements for attackers. In traditional finance, market manipulation requires significant resources and leaves a paper trail. With flash loans, anyone with the technical knowledge to write a smart contract can attempt an attack with zero capital risk. This dramatically lowers the barrier to entry for would-be exploiters.

Additionally, the atomic nature of these transactions means they are difficult to detect and prevent in real time. By the time the transaction is mined into a block, the attack is already complete.

Notable Flash Loan Attack Incidents

Some of the most significant flash loan attacks in DeFi history include the bZx attacks in early 2020, which were among the first to demonstrate the technique and drained roughly $1 million. The Harvest Finance attack in October 2020 extracted $34 million by manipulating Curve pool prices. Pancake Bunny lost $45 million in 2021 through a similar price manipulation strategy. These incidents collectively shaped how the industry thinks about protocol risk and oracle design.

How Protocols Defend Against Flash Loan Attacks

The DeFi ecosystem has developed several defensive strategies:

  • Decentralized oracles — Using oracle price feeds from Chainlink or other decentralized providers instead of relying on on-chain DEX prices, which are easily manipulated within a single block.
  • Time-weighted average prices (TWAPs) — Calculating prices over multiple blocks rather than using spot prices, making single-block manipulation ineffective.
  • Borrowing restrictions — Some protocols restrict the size of operations that can occur within a single transaction or block to limit flash loan utility.
  • Smart contract audits — Rigorous smart contract audits that specifically test for flash loan attack vectors have become standard practice.
  • Rate limiting and circuit breakers — Protocols may implement limits on large withdrawals or position changes to slow down potential attackers.

Despite these improvements, flash loan attacks remain an ongoing threat as attackers continuously find creative new ways to exploit protocol logic, economic assumptions, and oracle dependencies.

Related Terms