Flash loan

On this page 7

A flash loan is an uncollateralized loan that is borrowed and repaid within a single blockchain transaction. If the borrowed amount plus a fee is not returned before the transaction ends, the entire transaction reverts as if it never happened, so the lender never bears credit risk. Flash loans exist only in DeFi, because they depend on the atomic execution of smart contracts on programmable blockchains such as Ethereum.

In the Crypto & blockchain ecosystem, flash loans give anyone temporary access to very large amounts of liquidity, which enables arbitrage, collateral swaps and self-liquidation. The same property has also made them a common tool in protocol exploits, where attackers borrow millions to manipulate prices for a few seconds.

How a flash loan executes atomically

A flash loan relies on transaction atomicity: every step of a blockchain transaction either completes or none of it does. The borrower deploys a contract that requests funds from a lending pool, receives them, runs arbitrary logic and returns the principal plus a fee, all in one call sequence. At the end, the pool checks its balance; if it is short, it throws an error and the network discards every state change.

The steps below show the standard sequence used by large lending protocols such as Aave and by the flash swap feature of Uniswap.

StepActionWho performs it
1. RequestBorrower contract calls the pool’s flash loan functionBorrower contract
2. TransferPool sends the requested tokensLending pool
3. CallbackPool calls the borrower’s receiver functionLending pool
4. ExecuteBorrower runs trades, swaps or repaymentsBorrower contract
5. RepayBorrower approves or returns principal plus feeBorrower contract
6. VerifyPool checks balance and reverts on shortfallLending pool
Steps inside one flash loan transaction

Because a failed loan costs the borrower only the gas fee of the reverted transaction, the lender’s capital is never exposed to default. This is why no collateral, credit score or identity is required.

Key parameters and costs

Flash loan economics depend on a small set of parameters: the fee charged by the pool, the liquidity available, the gas consumed and any slippage incurred during the trades. A strategy is profitable only when its gain exceeds the sum of all of these.

ParameterTypical rangeWhat it affects
Pool fee0 to 0.09 percent of principalFixed cost per loan
Available liquidityLimited by pool reservesMaximum loan size
Gas costHundreds of thousands to millions of gasCost even when the loan fails
SlippageGrows with trade size versus pool depthErodes arbitrage margin
Block competitionVaries with network activityRisk of being outbid by others
Parameters that determine flash loan profitability

Fees differ by protocol and can be changed through governance, so the ranges above are indicative rather than fixed. The maximum size of a flash loan equals whatever the pool holds at that moment, which on deep pools can reach hundreds of millions of dollars.

Legitimate uses in DeFi

Flash loans make capital efficiency available to anyone who can write a contract, not only to large holders. Their legitimate uses share one feature: the borrowed funds create value that can be realized and repaid in the same transaction.

Use caseWhat the loan fundsOutcome
ArbitrageBuying on one DEX and selling on anotherCaptures price differences between pools
Collateral swapRepaying a debt to release collateralReplaces one collateral asset with another
Self-liquidationRepaying a risky position before liquidators doAvoids the liquidation penalty
Debt refinancingMoving a loan between lending protocolsObtains a lower interest rate
Leverage loopsRepeated deposit and borrow cyclesBuilds a leveraged position in one step
Common legitimate flash loan strategies

Arbitrage also helps the wider market, because it pulls the prices of automated market makers back into line. Many liquidation bots use flash loans as well, which keeps crypto lending markets solvent without requiring the bot operator to hold large reserves.

Flash loans compared with other crypto loans

A flash loan differs from ordinary crypto lending in duration, collateral and risk distribution. Standard DeFi loans are overcollateralized and can stay open for months; centralized loans add counterparty and custody risk.

FeatureFlash loanOvercollateralized DeFi loanCentralized crypto loan
DurationOne transactionOpen-endedFixed or open term
CollateralNoneTypically 120 to 200 percentVaries by lender
Default risk for lenderNone by designManaged by liquidationCounterparty credit risk
Required skillSmart contract programmingWallet and interfaceAccount and verification
Typical userBots, developers, tradersHolders seeking liquidityRetail and institutions
Flash loans versus other forms of crypto borrowing

Flash loan attacks and protocol risks

Flash loans do not create vulnerabilities by themselves, but they remove the capital barrier to exploiting existing ones. An attacker who needs one hundred million dollars for ten seconds can obtain it for a small fee, which turns a theoretical weakness into a practical attack.

The most common pattern is oracle manipulation. A protocol reads an asset price from the spot reserves of a single liquidity pool; the attacker borrows a large amount, distorts that pool, borrows or mints against the inflated price, restores the pool and repays the loan. Other attacks combine flash loans with governance tokens to pass a malicious proposal, or with reentrancy and rounding errors.

  • Use time-weighted average prices or decentralized oracle networks instead of spot reserves.
  • Require governance tokens to be held for several blocks before voting.
  • Limit how much value can move in a single block or transaction.
  • Commission a smart contract audit that models flash loan scenarios explicitly.

A frequent misconception is that banning flash loans would end these exploits. In practice, well-funded attackers could use their own capital; the root cause is the flawed price or logic, and robust design is the only durable defense.

The idea in brief

Imagine borrowing a large sum of money on the condition that you return it before you leave the bank counter. If you cannot return it, the bank simply rewinds time so the loan never happened. Nobody loses anything except a small processing cost.

A flash loan works like that on a blockchain. Borrowing, using and repaying all happen in one step, so the lender needs no guarantee. People use it to profit from price differences or to reorganize their loans, and occasionally to attack poorly designed systems.

A practical scenario

A trader notices that a token trades at 1.000 USDC on one decentralized exchange and at 1.012 USDC on another, a gap of 1.2 percent. The trader’s contract takes a flash loan of 2,000,000 USDC from a lending pool with a 0.05 percent fee.

Within the same transaction, the contract buys the token on the cheaper exchange, sells it on the more expensive one and receives about 2,016,000 USDC after slippage. It repays 2,001,000 USDC, including the 1,000 USDC fee, and keeps roughly 15,000 USDC before gas.

If another bot had closed the gap first, the sale would have returned less than the loan, the repayment check would have failed and the transaction would have reverted. The trader would have lost only the gas fee, which illustrates why flash loans shift risk from capital to speed and execution accuracy.