What Are Flash Loans in DeFi?

Learn what flash loans are, how they work within a single transaction, their legitimate use cases like arbitrage and collateral swaps, and the risks of flash loan attacks in DeFi.

What Are Flash Loans in DeFi?

Flash loans are one of the most novel financial primitives to emerge from decentralized finance. They allow anyone to borrow an unlimited amount of cryptocurrency with zero collateral, provided the loan is repaid within the same blockchain transaction. If repayment fails, the entire transaction is reverted atomically — as though it never occurred.

This concept has no equivalent in traditional finance. It exists only because of the unique properties of smart contracts and blockchain execution environments, where transactions are processed as indivisible units.

How Flash Loans Work

The Atomic Transaction Model

To understand flash loans, you need to understand atomic transactions. On blockchains like Ethereum, a transaction either succeeds completely or fails completely — there is no partial execution. Flash loans exploit this property:

  1. Borrow: The flash loan contract lends tokens to the borrower within the transaction.
  2. Execute: The borrower performs arbitrary operations — swaps, deposits, liquidations — using the borrowed funds.
  3. Repay: The borrower returns the principal plus a small fee to the flash loan contract.
  4. Verify: The contract checks that full repayment was received. If not, the entire transaction reverts.

Because all four steps happen within a single transaction, the lender faces zero default risk. The funds are never truly "at risk" because the blockchain's execution model guarantees repayment or complete reversal.

Technical Mechanics

Flash loans are typically implemented through callback patterns. The lending protocol calls a function on the borrower's smart contract, passing the requested funds. The borrower's contract performs its logic and then approves repayment. The lending contract verifies the returned amount before the transaction finalizes.

Protocols like Aave, dYdX, and Uniswap V3 all offer flash loan functionality, each with slightly different interfaces and fee structures. Aave charges a 0.05–0.09% fee, while Uniswap V3 flash swaps charge the pool's swap fee.

Flash Loan Fees

Flash loan fees are minimal compared to traditional lending:

  • Aave V3: 0.05% for assets with flash loan premium configured at this level
  • Uniswap V3: equivalent to the pool fee tier (0.01%, 0.05%, 0.3%, or 1%)
  • Balancer: zero fee for flash loans (using their vault liquidity)

These low fees make flash loans economically viable for even small arbitrage opportunities.

Legitimate Use Cases for Flash Loans

Arbitrage

The most common use of flash loans is arbitrage — profiting from price discrepancies across decentralized exchanges. Without flash loans, arbitrage required significant capital. With flash loans, anyone can borrow millions of dollars worth of tokens, execute a multi-step arbitrage trade, repay the loan, and pocket the profit — all in a single transaction.

For example, if ETH is priced at $3,000 on Uniswap and $3,010 on SushiSwap, a flash loan allows a trader to borrow ETH, sell on SushiSwap, buy back on Uniswap, repay the loan, and keep the difference. This activity actually benefits the ecosystem by keeping prices consistent across venues.

Collateral Swaps

Suppose you have a collateralized loan position backed by ETH and you want to switch to wBTC collateral without closing the position. Without flash loans, you would need to repay the debt, withdraw collateral, swap assets, re-deposit, and re-borrow — a multi-step process requiring spare capital and exposing you to price movement.

With a flash loan, you can atomically: borrow stablecoins via flash loan, repay your existing debt, withdraw your ETH collateral, swap ETH for wBTC, deposit wBTC as new collateral, borrow stablecoins against wBTC, and repay the flash loan. Platforms like Borrow help users manage collateralized positions, and flash loan-based collateral swaps streamline these operations.

Self-Liquidation

When your collateralized loan approaches its liquidation threshold, a third-party liquidator would normally close your position and claim a liquidation bonus — a penalty that comes out of your collateral. Flash loans enable self-liquidation: you borrow enough to repay your debt, withdraw your collateral, sell just enough to cover the flash loan, and keep the rest. This avoids the liquidation penalty entirely.

Debt Refinancing

Flash loans enable instant refinancing between lending protocols. If Protocol A offers a 5% borrow rate and Protocol B offers 3%, you can use a flash loan to repay your debt on Protocol A, withdraw your collateral, deposit it on Protocol B, borrow on Protocol B, and repay the flash loan. Aggregators like Borrow already help users find optimal rates across protocols — flash loans are the mechanical backbone that enables instant protocol-to-protocol migration.

Governance Exploits (Cautionary)

Flash loans have been used to temporarily accumulate governance tokens, pass malicious proposals, and return the tokens — all within one transaction. This represents a misuse of flash loans but highlights why governance systems need time-locked voting and snapshot-based quorum mechanisms.

Flash Loan Attacks

What Is a Flash Loan Attack?

A flash loan attack occurs when someone uses flash-borrowed funds to exploit a vulnerability in a DeFi protocol's economic design. Because the attacker needs zero capital, the barrier to exploiting protocol weaknesses is dramatically lowered.

Common Attack Vectors

Oracle Manipulation: Many early DeFi protocols relied on spot prices from a single AMM pool as their price oracle. An attacker could flash-borrow a large amount, execute a massive swap to move the pool price, exploit a protocol that reads this manipulated price (e.g., borrowing at an artificially favorable rate), reverse the swap, and repay the flash loan. Modern protocols mitigate this with time-weighted average price (TWAP) oracles and decentralized oracle networks like Chainlink.

Economic Design Exploits: Some protocols have reward distribution or share-price calculations that can be gamed with large, temporary deposits. An attacker flash-borrows tokens, deposits into the protocol to inflate their share, triggers a reward distribution or accounting update, withdraws their inflated share, and repays the flash loan.

Reentrancy Combined with Flash Loans: Flash loans amplify the damage of reentrancy bugs. An attacker with $10 million in flash-borrowed funds can drain far more than one who only has $10,000 of their own capital.

Notable Flash Loan Attacks

The DeFi ecosystem has seen numerous high-profile flash loan attacks:

  • bZx (2020): Two attacks in February 2020 exploited oracle manipulation for approximately $1 million — one of the first major flash loan attacks.
  • Harvest Finance (2020): $34 million exploited via price manipulation of the USDC/USDT Curve pool.
  • Pancake Bunny (2021): $45 million extracted through price manipulation of PancakeSwap pools.
  • Cream Finance (2021): $130 million lost in a flash loan attack exploiting oracle pricing for a collateral token.

How Protocols Defend Against Flash Loan Attacks

Robust DeFi protocols employ several defensive strategies:

  • Decentralized oracles: Using Chainlink or other oracle networks rather than relying on single-source spot prices.
  • TWAP oracles: Time-weighted pricing that cannot be manipulated within a single block.
  • Flash loan guards: Preventing certain operations (like governance voting or price-sensitive calculations) within the same transaction as a flash loan.
  • Delayed accounting: Making share-price or reward updates effective in the next block, not the current one.
  • Comprehensive audits: Professional security audits specifically testing flash loan attack vectors.

Flash Loans and MEV

Flash loans are closely related to MEV (Maximal Extractable Value). MEV searchers frequently use flash loans to fund arbitrage and liquidation strategies without tying up capital. The relationship works both ways — flash loan-funded arbitrage is one of the primary sources of MEV on Ethereum.

This creates an ecosystem where:

  • Searchers find profitable opportunities and use flash loans to execute them.
  • Builders include these transactions in blocks.
  • Validators earn tips from the searchers.

Understanding both flash loans and MEV is essential for grasping how DeFi markets maintain (or fail to maintain) efficiency.

Flash Loans vs. Collateralized Borrowing

For most users, conventional collateralized borrowing — the kind aggregated by Borrow — is far more relevant than flash loans. Here is how they compare:

FeatureFlash LoansCollateralized Loans
Collateral requiredNone110–200% of loan value
DurationOne transactionIndefinite
Use caseArbitrage, swaps, liquidationsLeverage, liquidity, spending
RiskTransaction reverts if unprofitableLiquidation if collateral drops
AudienceDevelopers, MEV searchersAny DeFi user
Capital requiredNone (just gas fees)Significant (collateral deposit)

While flash loans are powerful tools for developers, they are not a substitute for the collateralized borrowing that most users need. If you are looking to borrow stablecoins against your Bitcoin holdings, a platform like Borrow aggregates the best rates across lending protocols — no flash loan knowledge required.

The Future of Flash Loans

Flash loans continue to evolve alongside DeFi infrastructure:

  • Cross-chain flash loans: As bridging technology matures, flash loans may span multiple chains.
  • Flash loan aggregators: Tools that source flash liquidity from multiple protocols to optimize fees and availability.
  • Integration with intent-based systems: Flash loans used behind the scenes in solver networks and intent protocols.
  • Improved defenses: Better oracle designs and protocol architectures that are flash loan-resistant by default.

Key Takeaways

Flash loans represent a uniquely blockchain-native financial instrument — impossible in traditional finance and made possible by the atomic execution model of smart contracts. While they enable powerful applications like arbitrage and collateral swaps, they have also been weaponized in flash loan attacks that have cost protocols hundreds of millions of dollars.

For everyday DeFi users borrowing against their crypto assets, flash loans are background infrastructure. Understanding their existence and risks, however, helps you evaluate the security posture of the protocols where your funds reside. The protocols aggregated by Borrow implement robust oracle and accounting designs that mitigate flash loan attack vectors, but staying informed about these DeFi risks is always advisable.

Common Questions

A flash loan is an uncollateralized loan that is borrowed and repaid within a single blockchain transaction. If the borrower cannot repay the loan plus fees by the end of the transaction, the entire operation is atomically reverted as if it never happened. This atomicity guarantee is what makes flash loans possible without requiring any collateral.

Related Questions