Flash Loan
Uncollateralized loan repaid within a single transaction.
A flash loan is an uncollateralized DeFi loan that must be borrowed and repaid within one atomic blockchain transaction. Smart contracts can access substantial temporary liquidity without posting assets in advance. If repayment plus fees is not completed before execution ends, the full transaction reverts under normal protocol rules.
Atomicity makes this possible. A transaction can borrow tokens, trade across several decentralized exchanges, repay the lender, and retain any remaining profit. The chain either records every step or none of them. The lender does not face an outstanding unpaid loan after partial execution, though its smart contract and asset assumptions still require security.
Flash loans matter because they improve capital efficiency. Arbitrageurs can align prices between pools, liquidators can repay unhealthy debt, and borrowers can swap collateral or refinance positions in one operation. A user might close debt in one lending market and open it in another without temporarily owning the full repayment amount.
The loan itself does not create profit. Borrowers pay protocol fees and network gas, while swaps face price impact and slippage. Competing searchers may copy or outbid a visible transaction. A reverted attempt still consumes gas. Strategies need strict minimum-output, repayment, and profit checks so execution fails safely when market conditions change.
Flash loans are often mentioned in DeFi exploits because they let attackers fund manipulation at large scale. The underlying vulnerability is usually a weak oracle, flawed accounting, missing access control, or unsafe economic assumption. The flash loan makes capital instantly available but does not break a secure protocol by itself.
Developers should test forked mainnet state, model adversarial ordering, use manipulation-resistant pricing, and audit every external call. Private transaction submission can reduce some MEV exposure without removing contract risk. Users should not run copied flash-loan code they do not understand or trust guaranteed-profit bots. Flash loans are powerful infrastructure for atomic finance, but safe use demands professional smart contract engineering, realistic cost models, and continuous monitoring.
Protocols offering flash liquidity should cap or isolate unusual assets, document fees, and monitor abnormal borrowing patterns. Emergency controls can limit damage, but privileged pause and upgrade powers need secure governance.
Frequently asked questions
- A smart contract borrows assets from a supported liquidity pool, performs one or more operations, and repays principal plus the required fee before the same blockchain transaction ends. The lender verifies repayment atomically. If any step fails or the balance is insufficient, the entire transaction reverts, although the sender still usually pays gas for attempted execution.
- Developers use flash loans for decentralized exchange arbitrage, collateral swaps, debt refinancing, liquidations, and moving positions between protocols without supplying all capital upfront. Atomic execution prevents an incomplete intermediate state. Profit is not guaranteed because pool fees, gas, slippage, MEV competition, oracle behavior, and contract errors can make a valid strategy lose money or revert.
- The loan mechanism is a tool, but strategies can contain bugs, unsafe approvals, manipulated prices, or untrusted external calls. Protocols exposed to weak oracles may be attacked with flash-loan-funded capital. Developers should use robust price sources, simulate adversarial conditions, set minimum profit and repayment checks, audit code, and limit exposure before running transactions with valuable liquidity.
