·5 min read
DeFiFlash LoansAdvancedSecurity

What Is a Flash Loan in DeFi? How They Work and Why They Matter

Flash loans let you borrow millions with no collateral — as long as you repay in the same transaction. This guide explains the mechanism, legitimate uses, and how they've been used in exploits.

A flash loan lets you borrow any amount of assets from a DeFi protocol with no collateral — as long as you repay the full amount (plus a small fee) within the same blockchain transaction.

If repayment doesn't happen, the entire transaction reverts as if it never occurred.

How It's Possible

In a normal loan, a lender takes on credit risk — the borrower might not repay. Flash loans eliminate this risk through atomicity: a blockchain transaction either completes entirely or reverts entirely. There's no in-between state.

The protocol's logic says: "At the end of this transaction, the balance must be ≥ what it was at the start." If it isn't, the whole transaction fails and no funds move.

You never actually "hold" the loan in the traditional sense — you borrow, use, and repay all within a single atomic operation.

Legitimate Uses

Arbitrage

Price differences exist across DEXes momentarily. With a flash loan:

  1. Borrow 100,000 USDC
  2. Buy SOL on DEX A where it's priced at $150
  3. Sell SOL on DEX B where it's priced at $151
  4. Repay loan + fee, keep the profit

No capital required. The arbitrage profit pays the flash loan fee.

Collateral Swapping

You have a position on Aave with ETH collateral, but want to switch to BTC collateral without closing the position:

  1. Flash loan to repay your ETH-backed loan
  2. Withdraw your ETH collateral
  3. Deposit BTC as new collateral
  4. Re-borrow to repay the flash loan

One transaction, no liquidation risk from temporary uncollateralization.

Self-Liquidation

Your position is near liquidation. Rather than waiting for a liquidator to take a penalty:

  1. Flash loan to repay your debt
  2. Retrieve your collateral
  3. Sell a portion to repay the flash loan
  4. Keep the rest

You avoid paying the liquidation penalty to external liquidators.

Flash Loans in Exploits

Flash loans have been used as an amplification tool in many DeFi attacks:

Price oracle manipulation: Borrow massive amount → move price on a low-liquidity DEX used as an oracle → exploit a protocol that trusts that oracle → repay loan → keep profits.

Governance attacks: Borrow governance tokens → vote on a malicious proposal → repay tokens. Requires governance with no time-lock — most modern protocols prevent this.

The flash loan itself isn't the exploit — it just lets attackers operate with more capital than they own, amplifying vulnerabilities that already exist.

Technical Requirements

Flash loans require custom smart contract code. You can't use them from a standard wallet UI — you write a smart contract that:

  1. Calls the flash loan function
  2. Implements the callback with your logic
  3. Approves repayment before the callback returns

Major providers:

  • Aave (Ethereum/Base): Most used, 0.09% fee
  • dYdX: Solana perpetuals platform
  • Balancer: Flash loans with 0% fee (just repay principal)

What This Means for Regular Users

Flash loans don't directly affect non-developer DeFi users — they're a developer primitive. But understanding them matters because:

  1. Flash loan attacks are a common DeFi exploit vector — knowing this helps you evaluate protocol risk
  2. Flash loan arbitrage keeps prices aligned across DEXes, which benefits all traders through better rates

Read: DeFi risk management →

Read: What is MEV and how to avoid it →

$SOVAI Presale — Q2 2026

15M tokens at $0.0005 — 50% below DEX listing

Real yield from AI trading revenue. Fixed supply. No emissions. Join the waitlist for early access.

By joining you agree to our Terms of Service and Privacy Policy.

built by gruesøme · Powered by SovereignAI