Flash Loans: Mechanics and Applications
Uncollateralised DeFi loans that must be borrowed and repaid within a single atomic transaction — if the loan is not repaid before the transaction completes, the entire transaction reverts as if it never happened. Enables arbitrage, collateral swaps, and self-liquidation without upfront capital.
Flash loans are one of DeFi's most genuinely novel financial primitives — instruments with no counterpart in traditional finance. A flash loan allows you to borrow millions of dollars of cryptocurrency without any collateral, with no creditworthiness check, available to any Ethereum address. The only condition: the loan must be repaid within the same atomic transaction. If you borrow $10 million and the transaction you execute doesn't return $10 million plus the fee by the end of the transaction, the entire sequence reverts as if nothing happened — the loan never occurs. This atomic guarantee makes flash loans risk-free for lenders and opens powerful capabilities for sophisticated DeFi users.
The Atomic Transaction Mechanism
EVM (Ethereum Virtual Machine) transactions are atomic: every operation in a transaction either all succeeds or all reverts. Flash loans exploit this atomicity. The sequence: (1) Borrow X tokens from Aave's flash loan pool. (2) Execute any sequence of DeFi operations using those X tokens. (3) Return X + fee to Aave by the end of the same transaction. Step 3 is enforced in Aave's flash loan smart contract: before the transaction can complete, the contract checks that the loan balance has been repaid. If not, the contract triggers a revert, unwinding all state changes in the transaction — the borrow, every DeFi operation, all of it. From the blockchain's perspective, the failed transaction executed nothing; no tokens moved.
The lender (Aave's pool) is therefore taking zero risk: either the loan is repaid in full within the same block, or the transaction reverts and no loan occurred. This eliminates counterparty risk entirely, allowing Aave to offer uncollateralised loans to anyone at any scale — the only limit is the available liquidity in the pool.
Who Uses Flash Loans and For What
Arbitrageurs: The most common legitimate use. If ETH/USDC is priced at 2,000 on Uniswap and 2,020 on Curve, an arbitrageur can: flash borrow 1,000,000 USDC from Aave, buy ETH on Uniswap (receiving ETH worth 2,020 per unit), sell ETH on Curve at 2,020, repay 1,000,009 USDC to Aave (principal + 0.09% flash loan fee), and pocket the $20,000 profit minus gas. This capital-efficient arbitrage requires zero personal capital, only the execution of the trade and payment of gas. Flash loan arbitrage keeps DeFi prices aligned across protocols — the same function market makers perform in traditional finance.
Collateral swaps: A DeFi user with a $500,000 ETH-collateralised USDC loan on Aave wants to swap their collateral from ETH to WBTC without closing and reopening the position. Flash loan sequence: borrow enough USDC to repay the entire loan, repay the Aave loan (releasing ETH collateral), sell the ETH for WBTC, deposit WBTC as new collateral on Aave, borrow USDC again, repay the flash loan. The entire collateral swap happens atomically, without manually managing multiple steps or having the loan dangerously undercollateralised at any point.
Self-liquidation: A user with a DeFi loan approaching liquidation can flash borrow the collateral asset, repay their loan, recover their collateral, repay the flash loan, and emerge with whatever collateral remains — avoiding the liquidation penalty (typically 5–15%) that would be charged if a third-party liquidator closed the position. Self-liquidation is strictly better than third-party liquidation for the borrower when they have enough collateral to cover the flash loan repayment.
Protocol liquidators: Professional liquidation bots use flash loans to liquidate undercollateralised positions profitably without holding large amounts of the necessary assets. The bot flash borrows the repayment asset, triggers liquidation, receives the collateral at a discount, sells the collateral for the repayment asset, repays the flash loan, and keeps the spread as profit.
Flash Loan Fees
Aave charges 0.09% (9 basis points) on flash loans — payable in the borrowed asset. On a $1 million flash loan: $900 fee. Given the capital efficiency of flash loan arbitrage, this fee is easily absorbed by profitable strategies. Balancer offers 0% fee flash loans for certain use cases. dYdX historically offered free flash loans as part of its margin trading infrastructure.
Flash Loan Attacks
Flash loans are also the tool of choice for a significant class of DeFi exploits. The attack pattern: flash borrow a large amount of tokens to temporarily manipulate a price oracle or liquidity pool ratio, exploit a protocol that trusts the manipulated price, profit from the artificially created price discrepancy, repay the flash loan, keep the stolen funds. All within one atomic transaction. The Beanstalk exploit ($182M, April 2022) used a flash loan to temporarily gain governance power and pass a malicious proposal that drained the treasury — all in one transaction. The Cream Finance attack ($130M, October 2021) used flash loans to manipulate price oracles and drain lending pools. The Mango Markets exploit ($115M, October 2022) used flash loans to manipulate the price of MNGO tokens and borrow against the artificially inflated collateral value.
Flash loan attack vectors specifically target protocols with: spot price oracle usage (instead of TWAPs), governance systems where votes can pass within a single transaction, and lending protocols with insufficient price manipulation resistance. Well-designed protocols use Uniswap v3 TWAPs or Chainlink price feeds (which cannot be manipulated within a single transaction) and require multi-block voting periods that flash loans cannot span.
Accessing Flash Loans as a Developer
Implementing a flash loan receiver requires deploying a smart contract that implements the IFlashLoanSimpleReceiver interface (Aave) or equivalent. The contract receives the borrowed funds, executes your logic in the executeOperation callback, approves the repayment, and the Aave contract verifies repayment and completes. For non-developers, flash loan aggregators and DeFi tooling platforms (DeFi Saver, Instadapp) provide user interfaces for common flash loan use cases (collateral swaps, debt refinancing) without requiring smart contract development skills.