Flash Loans
Flash loans are uncollateralized loans that must be repaid within the same transaction, enabling arbitrage, collateral swapping, and other complex DeFi strategies.
Flash loans are a type of uncollateralized loan available in decentralized finance (DeFi) protocols, most notably on blockchains like Ethereum. Their defining feature is the requirement that the borrowed amount, along with any associated fees, must be repaid within the same atomic transaction block. This means the entire process—borrowing, utilizing the funds (e.g., for arbitrage, collateral swaps, liquidations), and repaying—must occur instantaneously from the blockchain's perspective. If the repayment condition is not met by the end of the transaction, the entire transaction is automatically reverted by the blockchain's consensus mechanism, as if the loan never happened. This atomicity eliminates credit risk for the lending protocol, allowing them to offer large sums without collateral. Users typically interact with flash loan smart contracts by providing their own contract logic (a callback function) that dictates how the borrowed funds will be used and repaid. Common use cases include exploiting price discrepancies between different decentralized exchanges (DEXs), refinancing existing loans by swapping collateral, or executing complex multi-step DeFi strategies that require significant temporary liquidity. The primary risk for the user lies in the complexity of the required smart contract logic and potential vulnerabilities in the protocols they interact with.
graph LR
Center["Flash Loans"]:::main
Pre_logic["logic"]:::pre --> Center
click Pre_logic "/terms/logic"
Rel_decentralized_finance_defi["decentralized-finance-defi"]:::related -.-> Center
click Rel_decentralized_finance_defi "/terms/decentralized-finance-defi"
Rel_defi["defi"]:::related -.-> Center
click Rel_defi "/terms/defi"
Rel_flash_loan["flash-loan"]:::related -.-> Center
click Rel_flash_loan "/terms/flash-loan"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧒 Explain Like I'm 5
It's like borrowing a huge amount of money for just a few seconds to make a quick profit, and if you don't pay it back instantly, it's like you never borrowed it at all!
🤓 Expert Deep Dive
Flash loans are a product of blockchain's transactional atomicity. A user initiates a transaction calling a flash loan provider's contract, specifying the desired asset(s), amount(s), and a callback address/function. The provider contract transfers the assets to the user's contract. The user's callback function then executes a sequence of operations (e.g., interacting with multiple DEXs, performing swaps). This callback must successfully return control to the provider contract, which verifies that the original loan amount plus fees has been returned. If successful, the transaction commits. If the callback fails or the repayment is insufficient, the entire transaction is rolled back by the EVM. This mechanism makes flash loans risk-free for the lender but places the burden of complex, gas-optimized logic entirely on the borrower. Exploits often target the borrower's callback logic or vulnerabilities within the target DeFi protocols rather than the flash loan provider itself. The maximum loan size is typically constrained by the available liquidity in the provider's pool.