Flash Loans: How They Work, Common Uses, and Hack Risks

A flash loan is a cryptocurrency loan that lets you borrow a large sum with no collateral, no credit check, and no identity verification, provided you repay the full amount plus a small fee inside the same blockchain transaction. If the repayment doesn’t land before the transaction finishes executing, the lending protocol’s smart contract automatically reverses every step as though the borrow never happened. That code-enforced guarantee drops the lender’s risk to effectively zero, which is why none of the usual lending requirements apply.

Why No Collateral Is Required

The whole model rests on a property called atomicity. An atomic transaction is all-or-nothing: every step either completes successfully, or the system rolls back to its original state. In a flash loan, the borrow, whatever you do with the funds, and the repayment all happen inside a single transaction on the blockchain. People sometimes describe this as “within one block,” but that’s imprecise. A single block contains many transactions, and a flash loan lives inside just one of them.

Before the transaction commits to the blockchain’s permanent state, the smart contract checks whether the borrowed amount plus the required fee has been returned. If the balance falls short for any reason, whether a failed trade, a coding error, or insufficient funds, the Ethereum Virtual Machine triggers a revert. The entire sequence unwinds. No tokens move, no balances change, and the liquidity pool stays exactly as it was. The borrower loses only the gas fee paid to the network for attempting the transaction.

That is a different model from traditional uncollateralized lending, where the lender takes on real default risk. Here, default is impossible at the protocol level. The code won’t allow it. Non-repayment is a technical impossibility, not a contractual violation, which is why trust in the borrower never enters the picture.

How a Flash Loan Actually Executes

The most widely used implementation comes from Aave. Your custom smart contract calls the lending pool’s flash loan function and specifies which token you want to borrow and how much. The pool runs some initial checks, then transfers the requested tokens directly to your contract. Immediately after the transfer, the pool calls a callback function on your contract. In Aave’s case, that function is called executeOperation().1Aave Protocol Documentation. Flash Loans

Inside that callback is where your actual strategy lives: the arbitrage trade, the collateral swap, or whatever operation you designed. Once your logic finishes, your contract must approve the pool to pull back the original amount plus the fee. You don’t send the funds back yourself; the pool automatically withdraws them at the end of the callback. If your contract doesn’t have enough tokens or hasn’t granted the approval, the transaction reverts.1Aave Protocol Documentation. Flash Loans

Not everyone goes this route. Platforms like DeFi Saver have built graphical interfaces that let users configure flash loan operations such as collateral swaps, debt refinancing, and leverage adjustments without writing any code. DeFi Saver’s Recipe Creator uses flash loans under the hood and lets users chain together multiple DeFi actions in a single transaction.2DeFi Saver Knowledge Base. What are Flash Loans? These tools handle contract compilation, deployment, and repayment logic for you. The tradeoff is flexibility. Pre-configured templates cover common operations but won’t support custom arbitrage strategies or novel interactions. If your use case fits the templates, the barrier to entry is low. If it doesn’t, you’re back to writing Solidity.

What a Flash Loan Costs

Flash loans are not free. Aave charges a fee initialized at 0.05% of the borrowed amount, though that figure can change through a governance vote. On a $1 million flash loan, that’s $500, a cost that needs to be factored into any profit calculation. The fee is split between the liquidity providers who supplied the tokens and the protocol’s treasury, though at launch the treasury’s share is set to zero. Aave also maintains a whitelist of approved “flash borrowers” who can execute flash loans with the fee waived entirely, typically reserved for integrations that benefit the broader ecosystem.1Aave Protocol Documentation. Flash Loans

On top of the protocol fee, you pay network gas fees to execute the transaction. On Ethereum mainnet, gas costs vary dramatically depending on network congestion and the complexity of your operations. A multi-step arbitrage transaction touching several decentralized exchanges will consume significantly more gas than a simple collateral swap. These costs can decide whether a flash loan is profitable or wasted.

What People Use Flash Loans For

Arbitrage

Arbitrage is the headline use case. The same token often trades at slightly different prices on different decentralized exchanges. You borrow a large amount via flash loan, buy where the token is cheaper, sell where it’s more expensive, repay the loan plus fee, and keep the difference. Because you’re borrowing millions of dollars for a fraction of a second, even tiny price discrepancies can produce meaningful profit, and your own capital is never at risk. Arbitrageurs constantly pushing prices toward equilibrium across exchanges also helps keep pricing consistent across the market.

Collateral Swaps

If you have an open borrowing position on a lending protocol and want to change the collateral backing it, a flash loan makes the whole thing a single transaction. You borrow enough to repay your existing debt, withdraw your original collateral, deposit the new collateral type, re-borrow against it, and repay the flash loan. Without flash loans, this would take multiple separate transactions and enough personal capital to temporarily cover the full debt.

Self-Liquidation

When your collateral’s value drops close to the liquidation threshold, a protocol will let external liquidators close your position, and they collect a liquidation bonus for doing so. On Aave V3, that bonus can be around 5% of the collateral seized.3Aave. Overview of Aave V4 Liquidation Engine A flash loan lets you repay your own debt before liquidation triggers, keeping that bonus out of a stranger’s hands. The math usually works in your favor even after the flash loan fee and gas costs.

What Can Go Wrong When You Use One

A flash loan arbitrage strategy can look profitable on paper and still lose money in practice. The biggest culprit is slippage, the gap between the price you see when you submit a transaction and the price you actually get when it executes. State changes every block. By the time your transaction is mined, someone else’s trade may have moved the price against you.

Sandwich attacks make this worse. An attacker monitoring the public transaction pool spots your pending trade, submits a buy order just before yours (driving the price up), then sells immediately after your transaction executes at the inflated price. Your trade fills at a worse rate, and the attacker pockets the difference. This is a form of Maximal Extractable Value (MEV), where validators or bots profit by reordering transactions within a block.

Setting a slippage tolerance helps. Uniswap V3, for example, defaults to 0.1% slippage tolerance, meaning a swap only executes if the price hasn’t moved more than 0.1% from what you expected. If it has, the swap either partially fills up to the price limit or doesn’t execute at all. Keeping tolerance low, generally under 1%, limits how much value an attacker can extract. Breaking large trades into smaller transactions also reduces exposure, though it raises gas costs.

Why Flash Loans Show Up in DeFi Hacks

Flash loans are a neutral tool, and some of their most damaging use has been in exploiting vulnerabilities in other DeFi protocols. The typical pattern: an attacker borrows a massive amount of capital, uses it to manipulate a price oracle another protocol relies on, exploits the mispriced data to extract value, and returns the loan, all in one transaction. The attacker keeps the profit, and the exploited protocol’s users bear the loss.

Price oracle manipulation is the most common vector. Many DeFi protocols determine token prices by looking at the ratio of assets in a liquidity pool. An attacker who can temporarily dump a huge amount of one token into a pool skews that ratio dramatically, causing the oracle to report a wildly inaccurate price. The attacker then interacts with a vulnerable protocol that trusts that oracle, often borrowing against inflated collateral values, before reversing the pool manipulation within the same transaction.

According to one security report cited in industry coverage, flash loan attacks made up over 83% of eligible DeFi exploits in 2024. The lesson for protocol developers is that any contract relying on a price oracle manipulable within a single transaction is vulnerable. Time-weighted average prices, multi-source oracles, and borrowing caps are the standard mitigations.

Flash Minting Is a Different Thing

Standard flash loans borrow tokens that already exist in a liquidity pool. Flash minting takes a different approach: it creates brand-new tokens at the start of the transaction and destroys them at the end. The borrower receives freshly minted tokens, executes a strategy, and the protocol burns the tokens (plus any fee) before the transaction commits. If the burn fails, everything reverts.

For a traditional flash loan, the maximum you can borrow is capped by the pool’s current balance. For a flash minter, the ceiling is the maximum token supply minus the current total supply, a far larger number bounded by computational constraints rather than actual asset ownership.4Ethereum Improvement Proposals. ERC-3156: Flash Loans Some protocols that issue their own native tokens allow flash minting without charging a fee, since the temporarily minted tokens cost the protocol nothing and are destroyed before affecting circulating supply. The risk profile is different, though. A flash minting implementation with a bug could theoretically inflate token supply if the burn step fails, which makes the contract’s correctness even more critical.

Tax Treatment of Flash Loan Profits

The IRS treats digital assets as property, and any profit you generate from flash loan activity is a taxable event. Crypto-to-crypto swaps count as dispositions. Swapping one token for another triggers a capital gain or loss calculation, even if you never converted to dollars.5Internal Revenue Service. Digital Assets

Flash loan arbitrage profits will almost always be short-term capital gains, since the assets are held for far less than one year (less than one second, in fact). Short-term capital gains are taxed at your ordinary income tax rate, which can be significantly higher than the long-term rate.6Internal Revenue Service. Topic No. 409, Capital Gains and Losses If you’re generating regular profits, you may also need to make quarterly estimated tax payments to avoid underpayment penalties.

You report these transactions on Form 8949 and summarize them on Schedule D of your Form 1040. Every transaction needs documentation: token types, dates, amounts, and fair market values at the time of each swap.5Internal Revenue Service. Digital Assets Because a single flash loan transaction can involve multiple internal swaps across different exchanges, clean records are essential. Failed flash loans that cost only gas fees don’t generate a capital gain, but the gas spent may be deductible depending on whether you’re operating as a business or an individual investor.