flash loan
A flash loan is a loan with no collateral and no credit check that you must borrow and repay within the very same transaction. It sounds impossible until you realize that an Ethereum transaction is atomic: either every step succeeds, or the entire transaction is rolled back as if it never happened. The protocol simply hands you the funds, calls your code, and then checks at the end that the money (plus a small fee) has been returned. If it has not, the whole transaction reverts and the loan is unwound automatically, so the lender can never lose. This makes capital that is normally enormous and unattainable available to anyone for a few hundred thousand gas.
Flash loans exist because the usual reason to demand collateral — the risk that the borrower disappears — is eliminated by atomicity. Within that single transaction you can borrow millions, do something productive with it, and pay it back. Legitimate uses are common and valuable: arbitraging a price difference between two DEXs, swapping the collateral backing a loan without first repaying it, refinancing a debt position from one protocol to another, or self-liquidating to avoid a liquidation penalty. The borrower needs essentially no starting capital, only enough to cover gas and the loan fee, often around 0.05% to 0.09% on Aave.
The same property makes flash loans a force multiplier for attacks. An attacker can borrow a fortune for free, use it to swing a thin AMM pool's price, exploit a contract that naively trusts that manipulated price, and repay the loan — all atomically, risking nothing but gas. It is crucial to be precise here: the flash loan does not create the vulnerability, it removes the capital barrier to exploiting one that already exists. The defensive lesson is that no contract should ever assume an attacker has limited funds within a single transaction, and price-sensitive logic must use manipulation-resistant oracles rather than spot pool prices.
function flashLoanCallback(uint256 amount, uint256 fee) external {
// amount is now in this contract for the duration of the tx
doArbitrage(amount); // must produce >= amount + fee
token.transfer(pool, amount + fee); // repay or the whole tx reverts
}The borrower's callback must return principal plus fee before the transaction ends.
Calling a flash loan itself an 'attack' is a common imprecision. The flash loan is a neutral tool; the attack is the underlying bug it makes affordable to exploit (usually oracle manipulation or a broken invariant). Fixing the contract, not banning flash loans, is the real defense.