DeFi
Flash loans: borrowing that must end in the same transaction
A flash loan is a loan that lasts for one transaction. The lender sends the assets, the borrower’s code runs, and unless the amount and a fee are back before the transaction ends, the whole thing is reverted as if it had never been sent. That removes the lender’s risk of default and the borrower’s need for collateral. It is why flash loans pay for arbitrage and liquidations, and why they turn up in so many exploits, where they seldom contain the flaw but remove the need to own the money that using a flaw requires.
A loan with no time to default
Credit normally carries the risk that the borrower will not pay, which is why lenders ask for collateral. Aave’s flash loan documentation describes the exception: an asset borrowed without collateral, on condition that the amount and a fee are returned before the end of the same transaction. The page adds that flash loans have no real-world equivalent.
The condition can be enforced because an Ethereum transaction is atomic. It either completes or is reverted, and a reverted transaction changes nothing except the gas it used, which the sender still pays, as what gas is explains. Uniswap’s flash swap guide builds on the same property. Its pairs send tokens out before checking that they have been paid, since a swap that is still unpaid at the end can be rolled back entirely, and the guide notes that under the hood every v2 swap works this way.
Attacking the DeFi Ecosystem with Flash Loans for Fun and Profit, by Kaihua Qin, Liyi Zhou, Benjamin Livshits and Arthur Gervais of Imperial College London, was first submitted in March 2020 and is, to its authors’ knowledge, the first paper to investigate flash loans. It sets out three properties that follow. The lender bears no risk of default, apart from the risk of bugs in the contracts themselves. The borrower posts no collateral. And any borrower can take the whole of a public pool at once. The paper credits the Marble Protocol with introducing the concept and names Aave as one of the first platforms to advertise it widely, from January 2020. It counted 5,616 flash loans from Aave’s contract between 8 January and 20 September 2020, and found arbitrage and liquidation to be the dominant uses.
How the call works
Aave’s documentation gives the sequence. The borrower’s contract asks the
lending pool for one or more assets. The pool transfers them, then calls a
function named executeOperation on the receiving contract, which can do
whatever its code allows with the money. When that code finishes, the receiver
must have approved the pool to take back the amount plus the fee, and the pool
pulls it. If the funds are not there, through a missing balance, a missing
approval or insufficient collateral, the transaction reverts. All of it happens
in one transaction, and so in one block.
There are two versions of the call. flashLoanSimple borrows a single asset
and always charges the fee. flashLoan borrows several, waives the fee for
borrowers on an approved list, and lets the borrower keep an asset as an
ordinary variable-rate loan instead of repaying it, provided collateral or
credit delegation stands behind it. The fee was set at 0.05% at deployment and
can be changed by a governance vote, and it can be split between depositors
and the protocol’s treasury. The Imperial paper recorded a fee of 0.09%
in 2020.
For scale, as of 22 November 2026, per DefiLlama, Aave V3 held $15.1B in total value locked across 21 chains. For a lending market that figure is deposits less what has been borrowed, as what TVL measures explains, and it is spread over many assets and chains. A flash loan draws on one chain’s pool in one transaction, and only on reserves with borrowing enabled.
Other lenders offer the same thing through different doors.
ERC-3156, a standard created in
November 2020 and now final, gives them a common interface. maxFlashLoan says
how much is available and flashFee what it costs; flashLoan sends the
tokens and calls onFlashLoan on the receiver, after which the lender must
take back the amount and fee or revert. The standard’s motivation notes that
some lenders flash mint their own token instead of lending it, so that the
only limit on the loan is computational and has nothing to do with what anyone
owns. Maker’s flash mint
module is one such lender, built to the
standard. Uniswap’s version 3
pools
carry a flash function that sends either token and expects it back, with a
fee, in the callback.
None of this is a button in a wallet. The borrower has to be a contract that implements the callback, and Aave’s page warns that flash loans require a good understanding of the EVM and smart contracts.
What they are used for
Aave’s page lists two common uses: arbitrage between assets without holding the principal the trade needs, and liquidating a loan without holding the debt, using the discounted collateral received to repay the flash loan and its fee. Aave also uses flash loans in its own liquidity switch feature. The Imperial paper adds collateral swapping, in which a borrower closes a position with borrowed funds and at once reopens it against a different asset, without ever holding enough to repay the debt in between. Uniswap’s flash swap page puts the economic point plainly: arbitrage is otherwise open only to those with the capital for it, and flash swaps, it says, remove that barrier entirely.
A liquidation shows the mechanics. This is an illustration with invented numbers, gas ignored. A borrower’s position on a lending market has crossed its liquidation threshold, and the market lets a liquidator repay 5,000 units of the debt, which is in a dollar stablecoin, in exchange for collateral worth 5% more. A liquidator who holds no stablecoin:
- borrows 5,000 in a flash loan, at a 0.05% fee of 2.50;
- repays 5,000 of the borrower’s debt and receives collateral worth 5,250;
- sells the collateral into a pool, where price impact and the pool’s fee leave, say, 5,215;
- returns 5,002.50 to the lender and keeps 212.50.
Had the sale fetched less than 5,002.50, step 4 would have failed and the whole transaction would have reverted, costing the liquidator the gas and nothing else. The bonus and threshold are the lending market’s own parameters, which how DeFi lending works sets out. The sale depends on the pool’s depth, as what an AMM is shows. Many searchers race for the same bonus, which makes liquidation one of the forms of value described in what MEV is; what the flash loan does is let a searcher with no capital enter that race.
Why exploits use them
The same property works for anyone. The Imperial paper says flash loans give anyone instantaneous access to massive capital, and it dissects two attacks from February 2020. In the first, on 15 February, a flash loan of 10,000 ETH from dYdX funded a sequence through Compound, bZx and Uniswap that the authors call a pump attack and arbitrage, which they say made a profit of 1,193.69 ETH, about $350,000. The second, on 18 February, was an oracle manipulation. DefiLlama’s record lists two incidents on those dates under the name Ooki, the name bZx later took, both classed as Oracle Manipulation.
ERC-3156 is frank about flash minting in particular. The quantities involved, its security section says, will give rise to new attack vectors, and its first example is a lending protocol whose fixed interest rate can be pushed close to zero by a deposit that exists for a single transaction.
What a flash loan adds to an attack is size, and the removal of risk: if the attack fails, the transaction reverts and the attacker is out only the gas. What it does not add is the flaw. The loan must be repaid in full, so it can only ever take value from a contract that pays out more than it should. The hacks record reflects this. As of 22 November 2026, per DefiLlama, just one of its technique labels mentions flash loans: Flashloan Governance Attack, five incidents and $186.9M, all in the Governance class. The record does not say which other incidents used a flash loan. It files each by the flaw, so the two cases below that were funded by one sit under Token & Share Accounting and Oracle Manipulation. The largest technique in the second class, Spot Price Manipulation, has 134 incidents and $835.1M. How crypto gets hacked sets out the classes and what the record leaves out.
Three cases from the record
Euler, March 2023. Euler was a lending protocol on Ethereum. According to
Chainalysis,
the attacker flash-borrowed about $30 million of DAI from Aave, deposited
$20 million in Euler, borrowed ten times the deposit, used the other
$10 million to repay part of that debt and borrowed again. Euler Labs’
account
traces the cause to a single missing line of code. A function called
donateToReserves, added in an audited upgrade to fix an earlier bug, lacked a
health check, so the attacker could donate collateral until its own position
could be liquidated, then liquidate itself for a bonus larger than the donation
had cost. Euler Labs put the stolen assets at about $197 million at the time.
DefiLlama files the incident under Token & Share Accounting, technique Donation
Attack; the Euler V1 page has the full account.
What an audit of an upgrade like that one can be expected to catch is the
subject of smart contract audits explained.
CREAM, October 2021. The attack on CREAM Lending ran in one transaction. Immunefi’s analysis traces the capital to a $500 million flash mint of DAI from MakerDAO and a flash loan of more than 500,000 ether from Aave V2. The attacker supplied a Yearn vault token to CREAM as collateral, several times over, then withdrew the vault’s underlying Curve tokens, shrinking its supply of shares, and sent $10 million of them straight back in. That doubled the value the vault reported per share, which CREAM’s price feed used to value the collateral, and the attacker borrowed out the roughly $130 million CREAM had available. Immunefi narrows most of the damage to two causes, a hybrid oracle that was easy to manipulate and no cap on how much of a token could be supplied, and neither has anything to do with how the attack was funded.
Beanstalk, April 2022. In Beanstalk the
borrowed money was the point of failure. The protocol let a proposal be executed
early through emergencyCommit once 24 hours had passed, if it held two-thirds
of the vote, and it counted as votes the deposits made in the same transaction.
A day earlier the attacker had filed a proposal transferring the protocol’s
funds to itself. Immunefi
says it then flash-borrowed more than $1 billion from Aave, Uniswap and
SushiSwap, deposited it for voting power, passed the proposal and repaid the
loans, all in one transaction. CertiK
names the root cause as deposits used for voting that could be created with a
flash loan, in a protocol with no defence against one. The sources do not
agree on the size. CertiK puts the loss at about $182 million and the
attacker’s profit at about $76 million; Beanstalk Farms, the protocol’s
development team, put the theft
at about $77 million in non-Beanstalk user assets; and DefiLlama’s record lists
$181.0M, as of 22 November 2026.
Read together, the cases separate the funding from the fault. At Euler and CREAM the defect sat in the victim’s own accounting and pricing, and the loan supplied the scale. At Beanstalk the defect was a governance design that treated money present for one transaction as a stake in the protocol.
What a defence has to assume
Each fault has a known answer, and none of them involves stopping flash loans. A vote can count balances from an earlier block instead of the current one: in OpenZeppelin’s governance design, voting power is read from past snapshots rather than current balances, so tokens borrowed for a single transaction carry no weight. A price can be read as an average over time instead of from one pool at one moment. Uniswap’s oracle documentation estimates that the cost of manipulating such an average rises roughly in line with the pool’s liquidity and with the length of the window, and what a blockchain oracle is compares the designs. And a lending contract can check an account’s health after every action that changes it, which is the line Euler’s upgrade left out. Each answer starts from the assumption that anyone may turn up holding an entire lending pool for the length of one transaction.
The borrower’s side has its own hazards. ERC-3156 says a receiver that keeps an approval standing for a lender must check, in its callback, that whoever started the loan is trusted. It also warns that a contract or account which approves a lender without using the approval at once can be drained up to its allowance or balance by someone else starting a flash loan in its name, if the lender does not verify the callback’s reply as the standard requires. Aave’s page tells developers never to keep funds on their receiver contract, because an attacker can use them in a griefing attack.
Reading “flash loan attack” in a report
The phrase describes how an attack was paid for, not what broke. The useful questions about any incident described that way are what the borrowed money was spent on, which contract paid out more than it should have, and why. The size of the loan says how much capital the flaw needed in order to be worth using; it says nothing about where the flaw was. The project’s post-mortem is where those answers are, when one exists, and DefiLlama’s class and technique for the incident name the kind of flaw in two labels.