Skip to content
Reading depth

Each view includes the earlier layers; the complete engineer or auditor page is shown by default.

A flash loan gives a contract temporary control of assets that must be returned with any fee before the same transaction can succeed.

Split balance category cue

A flash loan gives a receiver contract temporary control of assets only if principal plus any fee is returned before the same transaction can succeed.

Transaction atomicity can replace ordinary collateral for operations whose complete result is known before commit. A contract can borrow, trade, refinance, liquidate, or rebalance and then repay; if any required step fails, all loan and strategy state reverts together.

Intraday credit combined with delivery-versus-payment settlement is a useful analogy. A flash loan lasts one atomic transaction rather than a business day. Failed repayment normally reverts instead of becoming a collectible default, although gas and off-chain opportunity costs remain.

The initiator requests the operation. The lender transfers the asset. The receiver contract executes a callback and integrated actions. Exchanges and other protocols supply the connected state transitions. The lender holds a temporary atomic repayment entitlement:

requiredRepaymentAmount = principalAmount + flashFeeAmount

All three amounts use the borrowed token unit. Fee calculation, rounding, pull-versus-push repayment, multi-asset support, and callback interfaces vary.

  1. Validate the requested token, amount, receiver, and available liquidity.
  2. Calculate the fee and transfer temporary control of the asset.
  3. Call the receiver with authenticated initiator, token, amount, fee, and data.
  4. The receiver performs authorized swaps or protocol operations.
  5. The receiver returns or approves principal plus fee under the interface.
  6. The lender authenticates the callback result and verifies repayment.
  7. Commit every state change, or revert the complete transaction.

Capital flow transfers principal to the receiver and principal plus fee back to the lender within one atomic transaction. Claim flow creates a temporary repayment entitlement that must be satisfied before commit and leaves no persistent loan claim after success. Return flow sends the receiver’s flash fee to the lender or suppliers and sends any strategy profit from the connected operation to the receiver. Risk flow from an ordinary unsuccessful callback is contained by the transaction revert, although the receiver still bears gas and opportunity costs. An exploited integration can instead propagate persistent loss to that protocol’s traders, liquidity providers, depositors, reserves, or backstop.

The receiver’s profit must come from a connected operation. Arbitrage transfers value from executed counterparties or pool inventory relative to the chosen benchmark; a liquidation bonus comes from borrower collateral; refinancing saves future financing cost rather than creating a payment. The receiver pays the flash fee, and the lender or its suppliers receive it under pool rules. The receiver bears gas and opportunity cost when an atomic attempt reverts. If temporary capital exploits another protocol’s price or accounting failure, that protocol’s affected traders, liquidity providers, depositors, reserves, or other named backstop absorb the persisted loss under its own rules.

Authenticate lender, receiver, initiator, token, amount, fee, data, and callback return value. Test unsupported tokens, maximum amounts, zero fee, fee rounding, repayment approval, pull versus push, reentrancy, nested loans, callbacks from a fake lender, nonstandard tokens, and failure at every integrated step. Confirm no persisted debt or partial strategy state remains after a revert.

ERC-3156 specifies one single-asset flash-lender and borrower callback interface, including repayment and callback authentication requirements. Implementations can use other interfaces, so ERC-3156 compliance must be checked rather than assumed.

  • “Flash loans are ordinary uncollateralized credit.” Atomic rollback replaces future collection; the loan cannot persist successfully unpaid.
  • “Flash loans create attack bugs.” They can scale capital, while the exploitable oracle, authorization, governance, liquidity, or accounting flaw remains the root weakness.
  • “Atomic means risk-free.” Callback authentication, integrations, token behavior, fees, gas, and transaction ordering still matter.

See arbitrage for one common atomic strategy.

Machine-readable model

Key equations

Canonical expressions come from the structured concept record. KaTeX renders the notation, while the plain-text expression and variable table keep its meaning and units inspectable without JavaScript. Read the narrative above for the model's domain, assumptions, and rounding rules.

  1. Equation 1

    Plain-text equation: requiredRepayment = principal + flashFee

Assurance contract

Security properties

These structured statements define desired behavior. Their stable IDs can bind tests, invariants, specifications, audit findings, or proof results without turning descriptive review advice into an assurance claim.

Desired · not evaluated: No test, audit, or proof result is implied until scoped evidence is linked to this property.

  1. The lender authenticates the callback result and reverts unless principal plus fee is repaid under the stated interface

  2. The receiver authenticates the lender and initiator and validates token, amount, fee, and callback data

  3. Reentrancy and nested-loan behavior cannot bypass accounting or authorization

  4. Failure of any operation or repayment leaves no persisted loan, partial strategy state, or unpaid obligation

Knowledge check

Quiz

Answer in your own words, then open the model answer.

What problem does Flash loan exist to address?

Model answer

Flash loans let contracts perform capital-intensive atomic operations without maintaining collateral when transaction rollback guarantees all-or-nothing repayment.