Flash Loans Aren't a Vulnerability. They Make Every Bug Cheaper to Exploit.
Security Wiz team4 min read
"Flash loan attack" is one of the most used phrases in crypto security, and one of the most misleading. A flash loan isn't a flaw. It's a tool that removes the biggest obstacle to exploiting one: needing a lot of money.
What a flash loan is
A flash loan lets you borrow as much as a lending pool holds with no collateral, meaning nothing put up as security, as long as you pay it back, plus a small fee, within the same transaction. If you don't, the whole transaction is cancelled as if it never happened.
That works because a blockchain transaction is all or nothing. Either every step in it happens, or none of them do. The lender takes no risk, and a borrower with a plan gets to work with millions of dollars for a few seconds.
Why that changes who can attack you
Before flash loans, an attack that needed $50 million was limited to people who had $50 million. Now it's limited to people who can cover a few dollars in transaction fees. That changes the answer to two questions every auditor asks:
- Is the attack profitable? Borrowing costs almost nothing, so even a small gain is worth taking.
- Who can do it? Anyone.
This is why our scoring system, OVSS, counts an attack that can be funded with a flash loan as Low cost, the same as one that costs under $1,000. It's also why flash loans have an entry of their own, SC04, in the OWASP Smart Contract Top 10.
How they're used
A flash loan doesn't create a flaw. It makes an existing one pay. The common patterns:
Moving a price. Many apps work out what an asset is worth by reading the current price in a market. An attacker borrows a large sum, makes a trade big enough to move that price, uses the victim app while the price is wrong, then trades back and repays the loan. This is price oracle manipulation, SC03 on the OWASP list.
Borrowing votes. If voting power depends on how many tokens you hold at the moment of the vote, an attacker can borrow enough tokens to pass a proposal in a single transaction. Beanstalk lost roughly $182 million this way in April 2022, when borrowed voting power was used to pass a proposal that sent the protocol's funds to the attacker.
Making rounding pay. A rounding flaw that leaks a fraction of a cent on a normal deposit can leak real money on a deposit of borrowed millions.
Loans and liquidations. A lending app decides how much you can borrow from the value of your collateral, and sells that collateral off if its value falls too far. Briefly inflating that value, or pushing someone else's below the line to force a sale, is far easier when the money to do it is free.
How to design against them
Don't trust the price right now. Use a price averaged over a period of time, or an independent price feed that you check is up to date. A price that can't be moved inside one transaction can't be manipulated with a flash loan.
Count votes from an earlier moment. Base voting power on what people held before the proposal was made, so tokens borrowed during the vote count for nothing.
Don't trust a balance that can change in one step. If your code makes decisions from the number of tokens it currently holds, an attacker can send it tokens or pull them away. Keep your own record of deposits and withdrawals where you can.
Limit what one transaction can do. Caps, rate limits, and rules against repeating a sensitive action in the same block all make single-transaction attacks harder to profit from.
Check the outcome, not only the inputs. Ask "what must be true after this action, no matter what the user did before it?" and make the code enforce it.
How we test for it
Automated scanning can point out where your code reads a live market price. It can't tell you whether an attack would make money. To find that out, we carry out the attack ourselves on a fork: a private copy of the live blockchain, with the real markets and the real money in them. We borrow, move the price, use your app, repay, and check what broke. A successful attack is saved as a test you can run yourself, so it is both the proof in your report and the check we run again after your fix.
If your product deals with prices, loans, or voting, this is worth testing before launch. Request an audit, or read how fork testing differs from a standard review.
Shipping something onchain?
Send us your repo and we’ll return a quote within 24 hours.