Most flash loan explainers start with "borrow millions with no collateral" and stop there. That framing is technically correct and practically useless. It skips the part that matters: why a lender would ever allow this, what constrains the borrower, and what the EVM is actually doing during execution. This guide closes that gap.
What a Flash Loan Actually Is (and Isn't)
You've probably seen the elevator pitch: borrow any amount, use it, return it — all in one transaction. The standard explanation says flash loans are "uncollateralized loans." What's actually happening is closer to this: the protocol lends you tokens, then checks at the end of the same transaction whether you've returned them plus a fee. If you haven't, the entire transaction reverts — every state change unwinds as if nothing happened. The lender's risk is zero because the loan never existed in any final state where it wasn't repaid.
This is possible because of atomicity — the property that an Ethereum transaction either completes entirely or fails entirely. There's no in-between state where you've received the funds but haven't returned them. The blockchain never records a version of events where the lender is short. This isn't a feature of flash loans specifically; it's a feature of the EVM that flash loans exploit.
The lending protocol doesn't evaluate your creditworthiness, your collateral, or your plan. It doesn't need to. The only check is mathematical: did the contract's balance increase by at least (loan amount + fee) by the time execution finishes? If yes, the transaction confirms. If no, it reverts. The protocol earns fees with zero risk of insolvency from flash loans.
⚠ Common mistake: Assuming flash loans can span multiple transactions or blocks. They cannot. Everything — borrow, use, repay — must execute within a single transaction's call stack. If your strategy requires waiting for a price to change between blocks, flash loans don't apply.
The Execution Sequence Inside One Transaction
A flash loan transaction follows a rigid sequence enforced by the lending contract. On Aave V3, the entry point is the flashLoan function on the Pool contract. You call it specifying which assets you want, how much, and a receiver contract address. The Pool transfers the requested tokens to your receiver contract, then immediately calls a specific callback function on that contract — executeOperation on Aave, onFlashLoan on protocols using the ERC-3156 standard.
Inside that callback is where your logic lives: the arbitrage, the liquidation, the collateral swap — whatever you're doing with the borrowed funds. Your contract must end by approving the Pool to pull back the loan amount plus fees. After your callback returns, the Pool contract verifies its balance. If the math doesn't check out, the entire transaction reverts.
The order is non-negotiable. If you try to repay before executing your strategy, you won't have the profits to cover the fee. If your callback doesn't approve the exact repayment amount, the transfer fails. If any sub-call in your strategy reverts — say, a DEX swap that exceeds slippage tolerance — the whole transaction reverts, including the initial loan. You pay gas for the failed transaction but lose nothing else.
⚠ Common mistake: Thinking you can use flash loans from an EOA (externally owned account, i.e., a regular wallet). You can't. Flash loans require a smart contract that implements the callback function. The protocol calls your contract's code — a regular wallet has no code to call.
Fee Structures Across Major Protocols
Flash loan fees vary by protocol and have changed over time. Aave V3 charges 0.05% on flash loans — reduced from Aave V2's 0.09%. This means borrowing 10,000 USDC costs 5 USDC in fees, regardless of duration (since duration is always one transaction). dYdX on Ethereum historically offered flash loans with zero fees, structured as a sequence of actions (withdraw, call, deposit) within their solo margin system, though dYdX has largely migrated to its own Cosmos chain. Uniswap V2 and V3 support flash swaps, which function similarly but charge the standard swap fee of the pool (0.01%, 0.05%, 0.3%, or 1% depending on the pool's fee tier).
Balancer offers flash loans at zero protocol fee on assets held in its Vault. This has made Balancer a popular source for gas-optimized flash loan strategies where the fee delta matters. On a $1M borrow, the difference between Aave's 0.05% ($500) and Balancer's 0% ($0) is significant for tight-margin arbitrage.
Gas costs are the other expense. A basic flash loan transaction on Aave V3 consumes roughly 200,000–500,000 gas units for simple operations, scaling higher with complex multi-step strategies. At 30 gwei gas price, that's approximately 0.006–0.015 ETH. Your strategy must profit more than fees plus gas, or the transaction should revert to save you the gas cost of a successful but unprofitable execution.
⚠ Common mistake: Ignoring gas costs when calculating profitability. A flash loan that nets $50 in arbitrage profit but costs $40 in gas and $5 in protocol fees leaves you $5. During gas spikes, that same trade goes negative. Sophisticated bots simulate transactions before submitting and only broadcast when profitable.
What Flash Loans Are Actually Used For
The dominant use cases are narrower than most guides suggest. Arbitrage is the most common: borrow a large amount of token A, swap it for token B on a DEX where it's cheap, swap token B back to token A on a different DEX where it's expensive, repay the loan, keep the difference. The flash loan provides the capital to exploit the price discrepancy — without it, you'd need millions in your own funds.
Self-liquidation and collateral swaps on lending protocols are the second major use. If you have ETH deposited as collateral on Aave and want to switch to stETH without closing your position manually, a flash loan lets you: borrow enough to repay your debt, withdraw your collateral, swap it, redeposit the new collateral, re-borrow, and repay the flash loan. Tools like DeFi Saver automate exactly this pattern for users.
Liquidations on lending protocols are the third. When a borrower's health factor drops below 1.0 on Aave, anyone can liquidate part of their position for a bonus (typically 5–10% of the liquidated collateral). Flash loans let liquidator bots operate without holding capital — borrow the repayment asset, liquidate the position, receive discounted collateral, swap it back, repay the loan.
The 2020 bZx attacks used flash loans to manipulate oracle prices and drain protocol funds — borrowing large amounts to skew DEX prices that a lending protocol used as its oracle, then profiting from the distorted valuation. These incidents drove widespread adoption of manipulation-resistant oracles like Chainlink and TWAP-based pricing. Flash loans didn't create the vulnerability; they removed the capital requirement to exploit it.
⚠ Common mistake: Believing flash loans are inherently an attack vector. They're a capital tool. The vulnerabilities they exploit — bad oracles, reentrancy bugs, unprotected functions — exist independently. Flash loans just make exploitation cheaper.
How Reverts Protect the System
The safety model of flash loans depends entirely on the EVM's revert mechanism. When a transaction reverts, all state changes made during execution are discarded. Storage writes, token transfers, approvals — everything rewinds to the pre-transaction state. The only cost is the gas consumed up to the revert point, which the transaction sender pays.
This means the worst-case outcome for a failed flash loan is wasted gas. You don't end up holding an unwanted position. You don't owe money. The lender doesn't lose funds. This property makes flash loans fundamentally different from traditional uncollateralized lending, where default is a real possibility that must be priced in.
Protocol developers add explicit balance checks at the end of the flash loan function. Aave's Pool contract, for instance, verifies that the token balance after your callback is at least the pre-loan balance plus the fee. This check is the final line of defense — if your callback did anything that resulted in less tokens being available for repayment, the check fails, and the revert cascades back through every sub-call.
⚠ Common mistake: Assuming reverts are free. They're not — you still pay gas for every opcode executed before the revert. A complex flash loan strategy that fails at the last step can cost significant gas. Production bots use eth_call simulation (or services like Flashbots' simulate endpoint) to test transactions off-chain before submitting them.
How to Verify Flash Loan Activity Yourself
Flash loan transactions are fully visible on-chain. On Etherscan, look for transactions interacting with Aave's Pool contract (address 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 on Ethereum mainnet for Aave V3). In the "Events" tab, flash loans emit a FlashLoan event containing the target address, asset, amount, and premium paid.
On DeFiLlama, the "Flash Loans" section under protocol dashboards tracks aggregate flash loan volume. Aave's own analytics dashboard at app.aave.com shows recent flash loan transactions. For Balancer, the Vault contract (0xBA12222222228d8Ba445958a75a0704d566BF2C8) emits FlashLoan events with the token address and amount.
To trace a specific flash loan's execution path, use Tenderly or Phalcon (by BlockSec) — these tools decode transaction traces into human-readable step-by-step breakdowns. Paste a flash loan transaction hash and you can see exactly which protocols were called, what tokens moved, and where the profit (or loss) materialized.
⚠ Common mistake: Looking only at the top-level transaction value. Flash loan transactions often show 0 ETH in value because the borrowed assets are ERC-20 tokens, not native ETH. The real action is in the internal transactions and token transfer logs.
Next Steps
- Read Aave V3's FlashLoanSimpleReceiverBase contract on GitHub to see the minimal interface your contract must implement. The structure is fewer than 30 lines.
- Trace a live flash loan on Tenderly: pick a recent FlashLoan event from Aave's Pool contract on Etherscan, copy the transaction hash, and paste it into Tenderly's transaction debugger to see every internal call.
- Study Balancer's flash loan gas optimization: compare identical arbitrage strategies executed via Aave vs. Balancer by examining gas usage and fee differences on actual transactions.
- Explore Flashbots Protect: if you plan to submit flash loan transactions, understand how MEV-protected submission via Flashbots prevents your profitable strategy from being frontrun by searcher bots in the public mempool.