Back

SC07: Flash Loan Attacks - Overview

What is a Flash Loan Attack?

A flash loan is an uncollateralised loan that must be borrowed and repaid within a single transaction. Because the Ethereum Virtual Machine executes a transaction atomically—every state change either commits together or reverts together—a lending protocol can safely hand an attacker millions in tokens with no collateral: if the loan plus its fee is not returned by the end of the same transaction, the entire transaction reverts as if it never happened. The lender is never at risk.

Flash loans are not themselves a vulnerability. They are a legitimate DeFi primitive used for arbitrage, collateral swaps, and self-liquidation. The security problem is that they are a devastating amplifier: they let anyone temporarily wield an enormous amount of capital—far more than they own—for the duration of one transaction. Capital that used to be the exclusive privilege of whales is now rentable by the block. A flash loan attack is therefore not an exploit of the loan; it is the use of borrowed capital to weaponise some other weakness in a victim protocol at a scale that would otherwise be impossible.

Mental model: a flash loan does not create a new door into a protocol. It hands the attacker a battering ram large enough to walk through a door the protocol left unlocked—a manipulable price feed, a naive vote count, an accounting rounding bug—and then hands the ram back before anyone can react.

Core Concept

The atomic flash-loan attack pattern (all inside ONE transaction):

  1. BORROW      -> take a huge uncollateralised loan (e.g. 100,000,000 tokens)
  2. MANIPULATE  -> use that capital to distort shared state the victim trusts:
                    - skew a spot-price AMM pool
                    - inflate/deflate a governance vote balance
                    - trigger a mispriced mint / redeem / liquidation
  3. EXTRACT     -> trade, borrow, redeem, or vote against the victim at the
                    manipulated state, draining value into the attacker
  4. REPAY       -> return the loan + fee to the lender
  5. PROFIT      -> keep the difference

  If step 3 does not yield enough to satisfy step 4, the WHOLE transaction
  reverts -> the attacker loses only gas. The attack is effectively RISK-FREE.

Why the Atomicity Matters

Two properties of a single transaction make the attack work:

Why Does This Matter?

Business Impact

Technical Impact

Technical Context

How Flash Loans Weaponise Other Weaknesses

1. Price-Oracle Manipulation

The most common flash-loan attack class. A victim protocol prices an asset using the spot ratio of a liquidity pool. The attacker borrows a huge amount, dumps it into the pool to skew that ratio, then interacts with the victim (borrow, mint, redeem) while the price is wrong, and finally reverses the swap.

// Victim reads price from a single pool's CURRENT reserves:
uint price = reserveQuote / reserveBase;   // spot price = trivially skewable

// Attacker (one tx):
//   flashBorrow(baseToken, 50_000_000)
//   pool.swap(base -> quote)     // reserves distorted, price crashes/spikes
//   victim.borrowAgainst(base)   // over-borrows at the fake price
//   pool.swap(quote -> base)     // unwind
//   flashRepay(baseToken, 50_000_000 + fee)

2. Governance Attacks

If a governance contract counts votes from the voter's current token balance, an attacker can borrow enough governance tokens to reach quorum, cast a vote, and repay—all atomically. Because proposal execution and voting can be forced into one transaction (or a flash-mintable vote token is used), a flash loan buys temporary control.

// Vulnerable: voting power = balanceOf(msg.sender) AT VOTE TIME
uint votes = govToken.balanceOf(msg.sender);   // flash-borrowed balance counts!

3. Draining via Logic / Accounting Errors

Vaults that compute share price, fees, or rewards with a flawed formula are safe at retail size but catastrophic at scale. Flash capital turns a tiny per-unit error into a total drain.

// e.g. first-depositor share inflation, rounding in favour of the caller,
// or reward accrual that scales with a manipulable balance snapshot

4. Liquidation and Collateral/Debt Manipulation

By moving the price that a money market uses for health checks, an attacker can make a healthy position appear insolvent (then liquidate it at a discount) or make an unhealthy position appear safe (dodging fair liquidation), or mint under-collateralised debt against inflated collateral.

5. Arbitrage-Based Value Extraction

Where two protocols disagree on price, flash capital lets an attacker extract the entire spread in one shot rather than a small slice—sometimes benign arbitrage, sometimes the mechanism that realises a manipulation.

The Building Blocks an Attacker Combines

Primitive Borrowed With Flash CapitalWeakness It TargetsResult
Massive one-tx swapSpot-price oracle (SC02)False price fed to victim, over-borrow / mis-mint
Massive one-tx token balanceBalance-based votingGovernance proposal passed / blocked
Massive deposit / redeemShare-price / rounding logic (SC03)Vault drained via inflated shares
Massive callback valueMissing reentrancy guard (SC05)Repeated withdrawal beyond balance
Massive collateral swingLiquidation health checkForced or dodged liquidation

Real-World Impact

The incidents below are described as classes of well-documented DeFi attacks. Specific protocol names and dollar figures vary by source and are deliberately omitted; the patterns, not the headlines, are what matter for defence.

Case Study 1: Flash-Loan-Amplified Oracle Manipulation

Pattern:

Impact: The protocol issued far more debt or synthetic tokens than the real collateral value supported, leaving it insolvent once the price snapped back.

Root Cause: Trusting a single-block, single-source spot price that flash capital can move at will. The fix class is robust oracles (TWAP / multi-source), covered in SC02.

Case Study 2: Flash-Loan Governance Takeover

Pattern:

Impact: Temporary but decisive control of on-chain governance, used to authorise value extraction.

Root Cause: Voting weight read from a live, flash-inflatable balance instead of a snapshot from a past block, with no execution timelock.

Case Study 3: Flash-Loan-Amplified Accounting / Reentrancy Drain

Pattern:

Impact: The pool's reserves were drained in one transaction.

Root Cause: A logic/accounting or reentrancy weakness (SC03 / SC05) that was never stress-tested against an attacker holding effectively unlimited capital for one transaction.

Prevalence and Severity

Flash-loan-amplified attacks are among the most damaging and most frequently attempted exploit classes in DeFi. Because attempts are risk-free (an unprofitable attempt simply reverts and costs only gas), profitable opportunities are probed continuously by automated bots.

Rather than cite specific figures, the defensible picture is:

Note: exact loss totals differ between reports. The durable takeaway is that if any part of your protocol can be gamed by an actor with temporary near-infinite capital, a flash loan will find it—cheaply, repeatably, and without warning.

Common Misunderstandings

Myth 1: "We should block flash loans to be safe"

Reality: You usually cannot reliably block them, and it treats the symptom. Flash loans only expose weaknesses that already exist. A protocol whose prices, votes, and accounting are sound is not harmed by an attacker holding a large balance for one transaction. Fix the underlying trust in manipulable state.

Myth 2: "Flash loans are the vulnerability"

Reality: The flash loan is the amplifier, not the flaw. The vulnerability is a spot-price oracle, a balance-based vote, a rounding bug, or a missing reentrancy guard. Remove those and the amplifier has nothing to amplify.

Myth 3: "An attacker can't afford to move our price"

Reality: With a flash loan they can afford to move almost any on-chain price for one transaction, because the capital is free and returned instantly. Assume the attacker has effectively unlimited capital for the length of a transaction.

Myth 4: "Our TWAP-free oracle is fine because manipulation is expensive"

Reality: Cost-of-manipulation arguments assume the attacker must hold capital and bear risk. Flash loans remove both. Spot manipulation that would be prohibitively expensive with owned capital becomes free with borrowed capital.

Myth 5: "Requiring tokens to vote means only real holders vote"

Reality: If voting power is read from the live balance, a flash borrower is a real holder for that transaction. Only a snapshot from a past block distinguishes committed holders from flash borrowers.

Myth 6: "A tiny rounding error can't be exploited"

Reality: Multiply any per-unit error by flash-borrowed nine-figure capital and it stops being tiny. Attackers scale the input until the error becomes a drain.

How Flash Loan Attacks Relate to Other Categories

AspectFlash Loan Attacks (SC07)Price Oracle Manipulation (SC02)Reentrancy (SC05)
RoleAmplifier / capital sourceThe weakness being amplifiedThe weakness being amplified
Root causeTrusting manipulable state at scaleManipulable spot price feedState updated after external call
Typical fixDesign for infinite one-tx capitalTWAP / robust multi-source oracleCEI + reentrancy guard
RelationshipWeaponises SC02/SC03/SC05 at scaleFrequently the SC07 payloadFrequently the SC07 payload

Key Takeaways

  1. Flash loans amplify, they do not create—the real bug is a manipulable price, vote, or formula the loan wields at scale.
  2. Assume unlimited one-transaction capital—design every mechanism as if an attacker can momentarily hold any balance.
  3. Never trust single-block snapshots—spot prices and live balances can be distorted for exactly one transaction.
  4. Governance must use past-block snapshots and timelocks—so a flash-borrowed balance cannot vote.
  5. Attacks are risk-free to attempt—unprofitable tries just revert, so any exploitable gap will be found and used.

How to Identify if You're Vulnerable

Ask these questions about your protocol:

If you answered "yes" or "not sure" to several of these, you are likely exposed to flash-loan amplification today.

Next Steps