Case Study 2: Aave's Flash Loans — How an Impossible Financial Instrument Became Real
The Invention
In January 2020, Aave launched version 1 of its lending protocol with a feature that no other DeFi protocol — and no traditional financial institution — had ever offered: flash loans. The concept, first proposed by Aave developer (and later core contributor) Emilio Frangella, was simple in theory and radical in implication: borrow any amount of any asset, with zero collateral, as long as you repay within the same Ethereum transaction. If you fail to repay, the entire transaction reverts. It never happened.
The financial world's reaction ranged from confusion to dismissal. "A loan you take and repay in 13 seconds? That's not a loan." But within weeks of launch, flash loans were processing millions of dollars per day. Within a year, they had been used to execute billions in arbitrage, power novel DeFi strategies, and — in several spectacular cases — drain hundreds of millions from vulnerable protocols.
Flash loans are, by any measure, the most genuinely novel financial instrument to emerge from blockchain technology. They have no analogue in traditional finance. They cannot exist without the atomic transaction model of blockchains. And they have permanently changed the threat model for every smart contract deployed on Ethereum.
This case study examines how flash loans work in practice, documents their most important use cases (both constructive and destructive), and evaluates their impact on the DeFi ecosystem.
How Flash Loans Changed DeFi's Architecture
The Capital Barrier Disappears
Before flash loans, exploiting an arbitrage opportunity between two DEXes required capital. If ETH was $2,500 on Uniswap and $2,510 on SushiSwap, you needed to hold enough ETH or USDC to execute the trade. A 0.4% price difference on a $100,000 trade yields only $400 — barely enough to cover gas and swap fees. To make meaningful profit, you needed millions in capital.
Flash loans eliminated this barrier entirely. An arbitrageur with $0 in capital (but the skill to write a smart contract) could borrow $10 million, execute the arbitrage, repay the loan plus a 0.05% fee ($5,000), and keep the remaining profit — all in one transaction. The only cost: the flash loan fee and gas.
This had profound implications for market efficiency. Before flash loans, only well-capitalized trading firms could profitably arbitrage small price discrepancies. After flash loans, anyone with technical skill could do it. The result: price discrepancies between DEXes closed faster, liquidity improved, and markets became more efficient.
The Security Model Inverts
Flash loans also inverted the security model for every DeFi protocol. Before flash loans, exploiting a vulnerability in a lending protocol — say, a bug that allowed you to borrow more than your collateral warranted — required you to have collateral in the first place. The capital requirement was a de facto security barrier.
After flash loans, that barrier vanished. Any vulnerability that could be exploited with sufficient capital could now be exploited with zero capital. The attacker's cost was reduced to the flash loan fee (0.05-0.09% of the borrowed amount, often less than $10,000) plus gas fees.
This meant that DeFi protocols could no longer rely on "this exploit requires $50 million in capital, so it's impractical" as a security assumption. If the exploit was theoretically possible, flash loans made it practically executable. The security standard for smart contracts increased dramatically — and retroactively. Protocols that had been "safe" for months were suddenly vulnerable because flash loans lowered the barrier to attack.
Case A: The Constructive — Collateral Swap on Aave
The Problem
Sarah is a DeFi user with the following position on Aave: - Collateral: 100 WBTC ($4,000,000 at $40,000/BTC) - Debt: 2,500,000 USDC - Health factor: 1.32
Sarah wants to switch her collateral from WBTC to ETH. She believes ETH will outperform BTC in the coming months, and she wants her collateral earning staking yield (via stETH) rather than sitting idle as WBTC.
Without flash loans, Sarah's process would be: 1. Find 2,500,000 USDC somewhere (she does not have it in liquid form). 2. Repay the 2,500,000 USDC debt on Aave. 3. Withdraw 100 WBTC. 4. Swap 100 WBTC for ~1,600 ETH on a DEX. 5. Stake 1,600 ETH for stETH. 6. Deposit stETH as collateral on Aave. 7. Borrow 2,500,000 USDC against stETH. 8. Return the 2,500,000 USDC she borrowed in step 1.
Step 1 is the problem. She needs $2.5 million in liquid USDC just to unwind her position. She does not have it. Without a flash loan, she is stuck.
The Flash Loan Solution
With a flash loan, Sarah deploys a smart contract that executes the following in a single transaction:
- Flash borrow 2,500,000 USDC from Aave.
- Repay Aave debt (2,500,000 USDC). WBTC collateral is released.
- Withdraw 100 WBTC from Aave.
- Swap 100 WBTC for ~1,600 ETH on Uniswap or Curve.
- Stake 1,600 ETH for stETH via Lido.
- Deposit stETH as collateral on Aave.
- Borrow 2,500,000 USDC against stETH.
- Repay flash loan: 2,500,000 USDC + 0.05% fee (1,250 USDC).
Total cost to Sarah: 1,250 USDC (the flash loan fee) + gas (~$50-200) + DEX swap fees (~0.3% on the WBTC/ETH trade). She has completely restructured a $4 million position for under $15,000 in total costs, in a single atomic transaction, without ever holding $2.5 million in liquid capital.
If any step fails — the swap gets bad slippage, the borrow against stETH is insufficient to cover the flash loan repayment, the staking transaction fails — the entire operation reverts. Sarah's original position (WBTC collateral, USDC debt) is untouched. The risk of partial execution is zero.
Why This Matters
This is not a toy example. Collateral swaps via flash loans are one of the most common flash loan use cases, processing hundreds of millions of dollars per month. They enable portfolio restructuring that would be impractical or impossible without the ability to temporarily borrow at scale.
Services like DeFi Saver and Instadapp have built user-friendly interfaces on top of flash loans, allowing non-technical users to execute collateral swaps, leverage adjustments, and position migrations with a single button click. The flash loan mechanics are abstracted away — the user sees "swap collateral from WBTC to stETH" and clicks "execute."
Case B: The Constructive — DEX Arbitrage
The Mechanics
On April 15, 2023, a bot detected the following prices: - USDC/ETH on Uniswap V3: 1 ETH = 2,103.40 USDC - USDC/ETH on Curve: 1 ETH = 2,107.85 USDC - Price difference: $4.45 per ETH (0.21%)
The bot executed the following flash loan arbitrage:
- Flash borrow 5,000 ETH from Aave (~$10.5M).
- Sell 5,000 ETH for USDC on Curve: received 10,539,250 USDC.
- Buy ETH with USDC on Uniswap: received ~5,008.4 ETH.
- Repay flash loan: 5,000 ETH + 2.5 ETH fee (0.05%).
- Profit: ~5.9 ETH (~$12,400), minus gas (~$80).
Net profit: approximately $12,320 in a single transaction lasting 12 seconds. No capital required other than gas.
Market Impact
This arbitrage transaction had a positive externality: it closed the price gap between Uniswap and Curve. After the trade, ETH was priced consistently at ~$2,105 on both exchanges. Traders on both platforms got better prices as a result.
Flash loan arbitrage is one of the primary mechanisms for price consistency across decentralized exchanges. Without it, prices would diverge more frequently and more severely, creating worse execution for regular traders. In this sense, flash loan arbitrageurs provide a public good — more efficient markets — while profiting privately.
The total volume of flash loan arbitrage across DeFi is estimated at $5-10 billion per month. The vast majority of these transactions are executed by automated bots, competing on speed and sophistication. The profit margins have compressed over time as competition increased — the "easy" arbitrage opportunities are now captured in milliseconds.
Case C: The Destructive — bZx Exploit (February 2020)
The Attack
On February 15, 2020 — just weeks after Aave launched flash loans — an attacker executed one of the first flash loan exploits, targeting the bZx protocol's margin trading platform. The attack was elegant in its complexity and devastating in its effectiveness.
Here is the step-by-step execution:
- Flash borrow 10,000 ETH (~$2.7M) from dYdX (which offered free flash loans at the time).
- Deposit 5,500 ETH as collateral on Compound and borrow 112 WBTC.
- Open a 5x short position on ETH/BTC on bZx's Fulcrum platform using 1,300 ETH. This caused bZx to execute a large sell order on Uniswap (selling ETH for BTC), which pushed the ETH/BTC price on Uniswap significantly downward.
- Sell the 112 WBTC on Uniswap at the now-favorable (manipulated) price, receiving more ETH than expected.
- Repay the 10,000 ETH flash loan to dYdX.
- Keep the profit: approximately 71 ETH (~$350,000).
The key insight: the attacker used the flash-borrowed capital to create a position so large that it moved the market on Uniswap. They then profited from that artificial price movement. Without the flash loan, they would have needed $2.7 million in capital to execute the attack. With it, they needed approximately $8 in gas fees.
The Vulnerability
The exploit was possible because bZx relied on Uniswap's spot price as its price oracle. Uniswap's price reflects the ratio of tokens in the pool and can be moved by large trades. A single massive trade (funded by a flash loan) could push the oracle price to an extreme level, and bZx would use that manipulated price for its margin calculations.
This was not a bug in bZx's code in the traditional sense — the code executed exactly as written. The bug was in the design — specifically, the assumption that Uniswap's spot price was a reliable oracle. For normal-sized trades, it was. For flash-loan-sized trades, it was trivially manipulable.
The Aftermath
bZx lost approximately $350,000 in the first attack and $600,000 in a second, similar attack four days later. The protocol paused operations, patched the oracle mechanism, and eventually resumed.
But the damage extended far beyond bZx. The attacks demonstrated a fundamental truth about DeFi: any protocol that uses manipulable on-chain price data is vulnerable to flash loan attacks. This triggered a mass migration from spot-price oracles to time-weighted average price (TWAP) oracles and Chainlink's off-chain aggregated price feeds, which are far more resistant to single-transaction manipulation.
Case D: The Destructive — Euler Finance (March 2023)
Scale of the Attack
On March 13, 2023, an attacker exploited Euler Finance — a lending protocol on Ethereum — using a flash loan to drain approximately $197 million in various assets. It was the largest flash loan exploit in DeFi history.
The Vulnerability
The exploit was based on a flaw in Euler's liquidation logic related to how the protocol handled "donations" of collateral. The attacker:
- Flash borrowed DAI from Aave.
- Deposited DAI into Euler and received eDAI (Euler receipt tokens).
- Used eDAI as collateral to borrow more DAI.
- "Donated" eDAI to Euler's reserves (a function that should have been restricted but was not).
- The donation created an imbalanced position — the attacker had debt but their collateral had been "donated" away, making the position appear unhealthy.
- The attacker then liquidated their own position, acquiring the donated collateral at a discount.
- By repeating this loop with different amounts and assets, the attacker drained the protocol.
The Recovery
In a remarkable twist, the attacker returned the stolen funds. After Euler's team made contact, offered a $1 million bounty, and the attacker's identity appeared to be partially exposed through on-chain analysis, the attacker returned the full $197 million over a series of transactions between March 25 and April 4, 2023.
The attacker sent an on-chain message (via transaction input data): "I did not plan this. I apologize for any trouble." Whether this was remorse or pragmatism (avoiding prosecution) is debated, but the full recovery was unprecedented for an exploit of this scale.
Lessons
-
Audit coverage is not complete coverage. Euler had been audited by multiple reputable firms. The donation-related vulnerability was not caught. Audits reduce risk but do not eliminate it.
-
Novel features create novel attack surfaces. The "donation" function — allowing users to contribute tokens to protocol reserves — was a unique feature of Euler. It created an interaction between the collateral accounting and liquidation logic that was not anticipated.
-
Flash loans amplify every vulnerability. The exploit required large amounts of capital to create the imbalanced positions. Without flash loans, the attacker would have needed hundreds of millions in assets. With flash loans, they needed only gas fees.
Case E: Governance Manipulation
The Threat
In October 2020, an attacker used a flash loan to borrow a large quantity of AAVE governance tokens from Aave itself, used the borrowed tokens to vote on a governance proposal, and returned the tokens — all in one transaction. The vote did not pass (it required more tokens than the attacker could borrow), but it demonstrated the vulnerability.
The theoretical attack: borrow enough governance tokens to constitute a majority, vote to transfer all protocol funds to the attacker's address, and return the tokens. The entire protocol could be drained through its own governance mechanism.
Defenses
DeFi protocols have implemented several defenses against governance manipulation via flash loans:
- Snapshot voting: Instead of counting tokens at the time of the vote, governance uses a "snapshot" of token balances from a previous block — typically one or more blocks before the proposal was created. Flash-borrowed tokens do not appear in the snapshot.
- Vote delegation with time locks: Tokens must be delegated to a voting address before they can be used, with a time delay between delegation and voting eligibility.
- Timelock on execution: Even if a malicious proposal passes, it cannot be executed for several days, giving the community time to respond (via emergency multisig, guardian mechanisms, or counter-proposals).
These defenses are effective against flash loan governance attacks but add complexity and centralization (emergency multisigs, guardian addresses) that tension with the "fully decentralized" ethos.
Flash Loan Volume and Evolution
Growth Trajectory
Flash loan volume has grown dramatically since inception:
| Period | Estimated Monthly Flash Loan Volume |
|---|---|
| Q1 2020 | $10-50M |
| Q3 2020 | $500M-1B |
| Q1 2021 | $2-5B |
| Q3 2021 | $5-10B |
| 2022 | $3-8B (declining with market) |
| 2023 | $5-15B (recovering) |
| 2024 | $10-20B+ |
The majority of this volume is legitimate arbitrage and position management. Exploits, while headline-grabbing, represent a small fraction of total flash loan usage.
Fee Revenue
Aave's flash loan fees (0.05-0.09% per transaction) have generated tens of millions in protocol revenue. This is pure profit for the protocol — the lent assets are never at risk, and the fee is collected atomically.
For Aave, flash loans are a no-risk revenue stream. The worst case is that a flash loan transaction reverts (generating no fee but causing no loss). The best case is billions in monthly volume at a small fee per transaction.
Cross-Chain Flash Loans
As DeFi has expanded to Layer 2 networks (Arbitrum, Optimism, Base) and alternative Layer 1s (Avalanche, Polygon), flash loans have followed. Aave v3 supports flash loans on all deployed chains. Lower gas costs on L2s have made flash loans accessible for smaller arbitrage opportunities that would be unprofitable on Ethereum mainnet.
However, cross-chain flash loans (borrowing on one chain and using funds on another) remain impractical. A flash loan requires atomic execution — all steps in the same transaction. Cross-chain transactions are not atomic (there is no guarantee that a transaction on Arbitrum will settle in the same block as a transaction on Ethereum). This limitation confines flash loans to single-chain operations.
Evaluating Flash Loans: Innovation or Weapon?
The Innovation Argument
Flash loans democratize capital. Before flash loans, DeFi was a system where capital determined access. Only wealthy users could arbitrage price discrepancies, restructure large positions, or execute sophisticated strategies. Flash loans make these capabilities available to anyone who can write a smart contract.
Flash loans improve market efficiency. Arbitrage via flash loans closes price discrepancies between exchanges, benefiting all traders with more consistent pricing.
Flash loans generate protocol revenue with zero risk to the lending pool — a pure positive for protocol economics.
The Weapon Argument
Flash loans have enabled hundreds of millions in exploits. While the underlying vulnerabilities existed without flash loans, the attacks would have required millions in capital — a barrier that many attackers could not have overcome.
Flash loans compress the time between vulnerability discovery and exploitation. In traditional finance, an exploit might take days or weeks to set up (raising capital, positioning assets). With flash loans, exploitation can happen within hours of vulnerability discovery — or even within the same transaction that discovers the vulnerability.
Flash loans create a permanent arms race between protocol security and potential attackers. Every new protocol must assume that any vulnerability will be exploited with unlimited capital, because flash loans provide that unlimited capital.
The Synthesis
Flash loans are a tool. Like most powerful tools, they amplify both constructive and destructive intent. The appropriate response is not to ban them (which is practically impossible on permissionless blockchains) but to build systems that are secure assuming unlimited capital attacks.
This is, ultimately, a higher standard of security — and the DeFi ecosystem is better for having been forced to meet it.
Discussion Questions
-
Should Aave (or similar protocols) implement restrictions on flash loan usage — for example, blacklisting contracts known to be used for exploits? What are the tradeoffs between security and permissionlessness?
-
The bZx attacker argued that they did not "hack" anything — they used the protocol exactly as designed. The Euler attacker returned the funds. Eisenberg claimed "profitable trading strategy." Where should the legal and ethical line be drawn for flash loan usage?
-
Flash loans only work within a single transaction on a single chain. If cross-chain atomic transactions become possible, how would cross-chain flash loans change the DeFi landscape? What new opportunities and risks would emerge?
-
Some protocols have proposed "flash loan-resistant" oracle designs that use time-weighted average prices over multiple blocks. What are the tradeoffs of this approach compared to using real-time spot prices?
-
Flash loans effectively give anyone access to unlimited short-term capital. In traditional finance, access to capital is one of the primary advantages of institutional investors. What are the implications of eliminating this advantage for market structure and fairness?
Key Takeaways
-
Flash loans are the most genuinely novel financial instrument created by blockchain technology, with no analogue in traditional finance.
-
Constructive uses — arbitrage, collateral swaps, self-liquidation, position management — account for the vast majority of flash loan volume and improve overall DeFi efficiency.
-
Destructive uses — oracle manipulation, governance attacks, vulnerability exploitation — have caused hundreds of millions in losses but represent a small fraction of total usage.
-
Flash loans did not create vulnerabilities; they lowered the capital barrier to exploiting existing vulnerabilities, forcing a higher standard of smart contract security across the entire ecosystem.
-
The appropriate response to flash loan risks is not restriction but robust protocol design that assumes unlimited-capital attacks.