Flash loan
A flash loan gives a contract temporary control of assets that must be returned with any fee before the same transaction can succeed.
Category: LendingSplit balance category cue
System record
Start with the economic purpose, participants, resources, and entitlements before studying implementation detail.
Why it exists
Flash loans let contracts perform capital-intensive atomic operations without maintaining collateral when transaction rollback guarantees all-or-nothing repayment.
Traditional-finance analogy
Intraday credit with delivery-versus-payment settlement is the closest comparison recorded for this concept.
Where the analogy stops
- The borrowing interval is one atomic transaction and failed repayment reverts state rather than creating an ordinary default collection process.
- Flash capital can amplify an existing oracle, governance, accounting, or liquidity weakness but is not itself proof that the affected protocol was insecure.
Main actors
- ActorFlash lender
- ActorInitiator
- ActorReceiver contract
- ActorIntegrated exchanges or protocols
- ActorValidator, sequencer, or block builder
Assets and claims
Assets — controlled or transformed resources
Assets are resources the mechanism moves, holds, values, or transforms.
- AssetTemporarily borrowed asset
- AssetRepayment asset and fee
Claims — entitlements and corresponding dependencies
Claims are rights to value, repayment, redemption, control, or another party's performance; each depends on an obligation or system that must honor it.
- ClaimAtomic repayment obligation
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.
Why it exists
Section titled “Why it exists”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.
Traditional-finance analogy
Section titled “Traditional-finance analogy”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.
Actors, assets, and claim
Section titled “Actors, assets, and claim”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 + flashFeeAmountAll three amounts use the borrowed token unit. Fee calculation, rounding, pull-versus-push repayment, multi-asset support, and callback interfaces vary.
Atomic lifecycle
Section titled “Atomic lifecycle”- Validate the requested token, amount, receiver, and available liquidity.
- Calculate the fee and transfer temporary control of the asset.
- Call the receiver with authenticated initiator, token, amount, fee, and data.
- The receiver performs authorized swaps or protocol operations.
- The receiver returns or approves principal plus fee under the interface.
- The lender authenticates the callback result and verifies repayment.
- Commit every state change, or revert the complete transaction.
| Outcome | Lender | Receiver strategy | Persistent loan claim |
|---|---|---|---|
| Success | Principal and fee received | Final intended position remains | None |
| Callback failure | Transfer reverts | All strategy state reverts | None |
| Underpayment | Transaction reverts | All strategy state reverts | None |
| Broken integration | Depends on actual code, not intended atomicity | May expose another protocol flaw | Must be audited |
Four-flow view
Section titled “Four-flow view”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.
Return source and risk allocation
Section titled “Return source and risk allocation”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.
Engineer or auditor lens
Section titled “Engineer or auditor lens”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.
Common misunderstandings
Section titled “Common misunderstandings”- “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.
Equation 1 Plain-text equation:
requiredRepayment = principal + flashFeeVariables and units for equation 1 Symbol Meaning Unit requiredRepaymentRequired Repayment selected underlying-asset units principalPrincipal selected underlying-asset units flashFeeFlash Fee selected underlying-asset units
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.
The lender authenticates the callback result and reverts unless principal plus fee is repaid under the stated interface
The receiver authenticates the lender and initiator and validates token, amount, fee, and callback data
Reentrancy and nested-loan behavior cannot bypass accounting or authorization
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.