Smart-contract security & auditing

flash-loan attack

A flash-loan attack uses an uncollateralized loan that is borrowed and repaid within the same transaction to give an attacker enormous, temporary capital with which to bend a protocol. The flash loan itself is a legitimate DeFi primitive: because the whole transaction reverts if the loan is not repaid by its end, the lender bears no risk. But that same atomicity hands a normally-undercapitalized attacker millions of dollars for a few milliseconds, which is exactly enough to overwhelm any mechanism whose safety quietly assumed no single actor could marshal that much money at once.

Importantly, the flash loan is rarely the bug. It is an amplifier that turns a latent weakness into a catastrophic one. The classic chain is: borrow a huge amount, use it to manipulate a spot-price oracle or to acquire a temporary majority of a governance token, exploit the contract that trusts that manipulated state, take the profit, and repay the loan, all atomically so the attacker risks only gas. Without the loan the same bug might require tens of millions of real capital and so go unexploited; with it the attack is nearly free.

Defending against flash-loan attacks therefore means removing the underlying assumption that capital is scarce. Do not price assets from instantly-movable spot sources; use TWAPs or decentralized feeds. Base governance voting power on balances snapshotted at a past block rather than the current block, so flash-borrowed tokens carry no weight. More generally, design every mechanism to remain safe even if one actor temporarily controls an unbounded amount of money, because on-chain, for the length of one transaction, they can.

Borrow 100 million in a stablecoin with a flash loan; swap a portion to distort a thin pool's price; use that distorted price to liquidate or over-borrow on a victim protocol; reverse the swap; repay the 100 million plus fee; pocket the remainder. If any step fails to leave enough to repay, the entire transaction reverts and nothing happens.

A flash-loan attack almost never exploits the loan itself. It exploits a second weakness, a manipulable price or a same-block governance vote, that only becomes dangerous when someone can wield millions of dollars for free.

Also called
flash loan exploit閃電貸漏洞利用