Flash loans: a million dollars for one heartbeat, no collateral, no questions
A flash loan lets anyone borrow any amount a pool holds without collateral, on one condition: it must be repaid with a fee inside the same transaction. If it isn't, the whole transaction is cancelled as if it never happened.
Imagine a banker in a boomtown who lends any amount to anyone, with no collateral and no name. The catch: you must hand the money back before he finishes blinking. If you can't, the loan never happened, and neither did anything you did with it.
No real banker could offer that. A smart contract can, because a blockchain transaction either completes in full or is undone in full.
That's a flash loan. It gives a stranger with a clever plan the cash of a whale for one transaction. Mostly that plan is arbitrage or tidying up a loan. Sometimes it's a claim jumper's crowbar.
What it is
A flash loan is a loan that starts and ends inside one blockchain transaction. Aave's documentation says it lets you borrow without collateral "as long as the borrowed amount and a fee are returned before the end of the same transaction". If the money isn't there at the end, "the transaction reverts" (Aave).
Revert means the blockchain throws the whole transaction away. Every swap, deposit and payment in it is undone. The lender's only real risk is a bug in its own code, because an unpaid loan simply never existed. The borrower loses only the network fee for the failed attempt.
How it works
You write a small smart contract with a list of steps, and call the lending pool. The pool sends you the money, runs your steps, then checks it has been paid back plus the fee. Aave says "The flash loan fee is set to 0.05% at deployment and can be changed by governance vote" (Aave).
A worked example. The prices are assumptions for illustration, and the example ignores price impact and the network fee.
The gap. Pool A sells ether at 1,990 dollars. Pool B buys it at 2,010 dollars.
The loan. You flash-borrow 1,000,000 dollar stablecoins. At 0.05%, the fee is 500 dollars.
The steps. Buy 502.51 ether in Pool A with the million. Sell them in Pool B for 1,010,050.25 dollars. Repay 1,000,500.
The result. About 9,550 dollars left, before gas, made with money you never owned. If the gap had closed while your transaction waited, the sale would have come up short, the repayment would fail, and the whole thing would be undone. You'd be out only the gas.
In real pools, buying 500 ether would move both prices a long way, so the profit would be much smaller or gone. Flash loans don't beat arithmetic. They only remove the need to own the money first.
Why it matters
Flash loans make everybody a whale for one transaction. That is useful: anyone can close a price gap, swap a loan's collateral or repay a debt to avoid liquidation without having the cash first.
It is also dangerous, because many protocols were built assuming that only rich people can move big money. The bZx attacks of February 2020 showed what happens when that assumption meets a flash loan.
On 15 February 2020, in the transaction in Ethereum block 9484688, an attacker took what the security firm PeckShield described as "the dYdX flashloan feature to borrow 10,000 ETH" (PeckShield; transaction on Etherscan). Within that one transaction, according to PeckShield, the attacker:
- put 5,500 ether into Compound and borrowed 112 WBTC against it;
- put 1,300 ether into bZx and opened a five-times leveraged short on ether against WBTC, whose trade was routed to Uniswap and pushed the price of 1 WBTC to around 109.8 ether there, against about 38.5 normally;
- sold the 112 borrowed WBTC on Uniswap at the inflated price;
- repaid the 10,000 ether flash loan.
PeckShield put the net gain at about 1,271 ether, "roughly $355,880 (assuming the ETH price of $280)", and called it "not an oracle attack. Instead, it is a clever arbitrage execution". On 18 February a second attack, funded by a 7,500-ether flash loan, took 2,388 ether, about 645,000 dollars, according to The Block (via The Block).
The flash loan didn't break anything by itself. It handed the outlaw enough gold to lean on a weak plank, and the plank broke. Nexus Mutual, which sold cover on bZx, records paying out 33,720.10 dollars to cover holders afterwards (Nexus Mutual).
Where people get it wrong
- "Flash loans are a hacking tool." They are a loan type. They fund attacks on weak protocols, but they also fund ordinary arbitrage and loan repairs.
- "A flash loan is free money." It's free capital for one transaction. The profit has to come from somewhere else, and the fee and gas are paid even when it doesn't.
- "Anyone can click a button and do one." It takes a custom smart contract. A website promising beginners easy "flash loan profits" deserves the suspicion you'd give any guaranteed return.
- "Protocols that were flash-loan attacked had a flash loan bug." Usually the bug was elsewhere: a price that could be pushed, or a check that trusted one big balance.
Ask what a whale could do
When you read about a protocol, ask one question: what happens if someone with unlimited money, for one transaction, trades against it? If its prices, votes or limits can be bent by a single large balance, a flash loan will find out before you do.
Then check whether its audits mention flash loans by name. If they don't, assume the outlaws already have.
Frequently asked questions
What is a flash loan?
A flash loan is an uncollateralised loan that must be borrowed and repaid, with a fee, within a single blockchain transaction. If it isn't repaid, the whole transaction is reversed. Aave and other protocols offer them.
How much does a flash loan cost?
On Aave V3, the flash loan fee is set at 0.05% of the amount borrowed at deployment and can be changed by governance vote, according to Aave's documentation. On a loan of 1,000,000 dollars, 0.05% is 500 dollars. You also pay the network fee.
Why don't flash loans need collateral?
Because the lender can't lose the money. The blockchain only accepts the transaction if the loan and fee are back in the pool at the end; otherwise everything in the transaction is undone.
Were flash loans used in hacks?
Yes. In February 2020, attackers used flash loans in two attacks on the bZx protocol, the first borrowing 10,000 ether from dYdX within one transaction. The flash loans supplied the money; the weaknesses were in how the protocols priced and checked trades.
Can a beginner use a flash loan?
Not directly. A flash loan needs a smart contract that borrows, acts and repays within one transaction. Treat offers of easy flash loan profits like any other promise of guaranteed returns.
Sources
- Aave, Flash loans (Aave V3 guide)
- PeckShield, bZx hack full disclosure (with detailed profit analysis) (17 February 2020)
- Etherscan, transaction of the first bZx attack, block 9484688 (15 February 2020)
- The Block, bZx attacked again, $645K in ETH estimated to be lost (18 February 2020)
- Nexus Mutual, Claims history: bZx hack, February 2020

