Caloogy Article
中文

Flash Loans and Price Manipulation

Date
Jan 14, 2026
Series
Onchain
Reading
4 min
Topics
OnchainDefiFlash loanOracle

The one-sentence version

Flash loans allow anyone to borrow hundreds of millions of dollars without collateral, provided they repay the loan within the same transaction; otherwise, the entire transaction is reverted. It completely eliminates the "principal" barrier: any security assumption relying on "manipulation requires massive capital" is invalidated. The most common attack pattern is: borrow a large sum → distort the price in a specific liquidity pool → a DeFi protocol uses this pool's spot price as an oracle, leading to lending or liquidations at incorrect prices → the attacker profits → repayment. The key to defense is: never use a price that can be manipulated within a single block.

This article has three layers:

  1. Layer 1: The Intuition: A billionaire for one second
  2. Layer 2: Real-World Use: Events like bZx, Mango Markets, Euler, etc.
  3. Layer 3: Principles and Engineering details

Layer 1: The Intuition

1.1 A billionaire for one second

Imagine a bank with a rule: you can borrow any amount, as long as you pay it back before leaving the counter; otherwise, the loan is treated as if it never happened.

This is useless to an ordinary person. But if you can use that money to perform a guaranteed arbitrage during that one minute at the counter, it is pure profit with zero capital. On the blockchain, "one transaction" is that counter: all steps in a transaction either succeed entirely or roll back entirely.

1.2 How prices are distorted

In many Automated Market Makers (AMMs), the price is determined entirely by the ratio of the two assets in the pool. If you dump a large amount of Asset A into the pool, the price of A will crash.

If a lending protocol says, "I calculate your collateral value based on the current price in this pool," an attacker only needs to pump the pool's price first. Their collateral then "becomes worth" a huge amount, allowing them to borrow assets far exceeding its actual value.


Layer 2: Real-World Use

Event Description
bZx (February 2020) Early flash loan attacks: Borrowed funds, manipulated prices on exchanges with thin liquidity, and exploited vulnerabilities in lending protocols that read these prices. Two attacks occurred days apart.
Harvest Finance (2020) Repeatedly manipulated stablecoin pool prices to earn spreads between "deposit" and "withdraw," resulting in losses of approximately $34 million.
Mango Markets (2022) An attacker used two accounts to significantly pump the MNGO token price in a low-liquidity market, inflating their account's collateral value to borrow approximately $110 million. They later publicly claimed it was a "high-profit trading strategy" and were subsequently indicted by US prosecutors.
Euler Finance (2023) Exploited a logic flaw in a "donation" function via flash loans to create bad debt that could be liquidated for profit, resulting in losses of approximately $200 million; the attacker later returned most of the funds.

Commonality: Flash loans are merely an amplifier; the real vulnerability is the protocol's own logic flaw, specifically trusting a price that can be instantaneously manipulated.


Layer 3: Principles and Engineering

3.1 Constant Product Market Makers

Maintaining a Uniswap V2-style pool:

x⋅y=k,x \cdot y = k,

xx and yy are the quantities of the two assets, and the price is =y/x= y / x. Using Δy\Delta y to buy A yields

Δx=x−ky+Δy.\Delta x = x - \frac{k}{y + \Delta y}.

The smaller the pool (the smaller the kk), the further the same amount of capital can push the price.

How far a small pool can be pushed

A pool contains 100 ETH and 200,000 USDC, with a price of 2000 USDC/ETH. Invest 200,000 USDC to buy ETH: You receive 100−2×107400,000=50100 - \dfrac{2\times 10^7}{400{,}000} = 50 ETH, leaving the pool with 50 ETH and 400,000 USDC, making the price 8000, which is 4 times the original.

Borrowing $200,000 via a flash loan has almost zero cost. If a protocol reads the pool's price at this moment, the attacker's ETH collateral is suddenly "worth" 4 times as much.

3.2 Defense: Don't use spot prices

Method Principle Limitations
TWAP (Time-Weighted Average Price) Takes the average price over a period (e.g., 30 minutes). Since flash loans only affect one block, the average impact is negligible. Slow price response; long-term, high-cost manipulation may still work.
Decentralized Oracles (e.g., Chainlink) Multiple independent nodes fetch prices from multiple exchanges and aggregate them on-chain (see "Multi-source Cross-verification"). Update latency; dependency on the security of the oracle network itself.
Multi-oracle + Deviation Check Pauses if the deviation between two sources is too large (see "Fail-closed"). Increases complexity.
Restricting Low-liquidity Assets Low-liquidity tokens are not accepted as collateral, or are assigned very low collateral ratios. Limits business scope.

3.3 Testing Methods

3.4 A counter-intuitive conclusion

Flash loans themselves are not a vulnerability; they even have legitimate uses (arbitrage, liquidations, zero-capital debt refinancing). Their significance lies in revealing vulnerabilities: any security assumption stating "you can't do this unless you have enough money" does not hold in DeFi.


Summary

Layer Key points
Flash loans Uncollateralized borrowing, repaid within the same transaction; the principal barrier disappears.
Attack pattern Borrow money → Manipulate price → Protocol operates at incorrect price → Profit → Repayment.
Root cause The protocol trusts a spot price that can be manipulated within a single block.
Defense TWAP, decentralized oracles, deviation checks, mainnet fork testing.