Skip to main content

Flash Loans & Advanced Lending

How flash loans work, practical use cases (arbitrage, collateral swaps, liquidations), and understanding the lending protocol landscape.

From Thrive on YouTube

Watch the matching Thrive video

Watch the series
VWAP Explained: How to Use VWAP and Anchored VWAP in Crypto

VWAP Explained: How to Use VWAP and Anchored VWAP in Crypto

Part of Charting and Market Structure. Education only. Not financial advice.

What Are Flash Loans?

Flash loans are one of DeFi's most extraordinary innovations, and they have no equivalent in traditional finance. A flash loan lets you borrow an unlimited amount of capital with zero collateral, as long as the loan is repaid within the same blockchain transaction. If the loan is not repaid by the end of the transaction, the entire transaction reverts as if it never happened. No risk to the lender. No collateral needed from the borrower. It is theoretically unlimited leverage compressed into a single atomic operation.

This is possible because of how blockchain transactions work. A transaction on Ethereum is an all-or-nothing operation. If any step in a complex multi-step transaction fails, every step is reversed. Flash loans exploit this property: the lending protocol gives you $50 million, you execute a series of operations, and if the last step does not include repaying $50 million plus a small fee (typically 0.05–0.09%), the entire transaction is invalid. The lender never actually risks funds.

Flash Loan Use Cases

Flash loans have legitimate, powerful applications beyond the attack vectors they are often associated with. Understanding these use cases reveals the creative potential of programmable money.

ArbitrageBorrow $10M, buy an asset where it is cheap, sell where it is expensive, repay the loan, keep the profit. All in one transaction. No capital needed.
Collateral swapsSwap your lending collateral from one asset to another without closing the position. Flash borrow to repay debt, withdraw collateral, deposit new collateral, re-borrow to repay flash loan.
LiquidationsFlash borrow stables, liquidate an undercollateralized position, receive collateral at a discount, sell collateral, repay flash loan, keep the liquidation bonus.
Self-liquidationIf you are about to be liquidated, flash borrow to repay your own debt, withdraw your collateral, sell enough to repay the flash loan, and keep the rest. You avoid the liquidation penalty.
Leverage adjustmentIncrease or decrease your looped lending position in a single transaction instead of executing multiple loops manually.

How Flash Loans Changed DeFi

Before flash loans, capital was a barrier. Only well-funded actors could execute arbitrage, perform liquidations, or exploit pricing inefficiencies. Flash loans democratized access to large capital: anyone who can write a smart contract can borrow $100 million for a fraction of a second. This has had profound consequences.

Markets became more efficient. Pricing discrepancies across DEXs are corrected faster because any developer can flash-borrow millions to arbitrage them. Liquidation efficiency improved dramatically because liquidators no longer need to maintain capital on hand. But the flip side is that flash loans also enabled attacks that would be impossible with limited capital: manipulating prices on low-liquidity pools, exploiting oracle designs, and draining protocol treasuries in a single transaction.

1

Borrow $50M in a flash loan

The flash loan provider (Aave, dYdX, or Balancer) lends you $50 million in USDC. The only requirement: you must return $50 million + a ~0.05% fee by the end of the transaction.
2

Execute the strategy

Buy 1,000 ETH at $3,000 on DEX A where price is lower. Sell 1,000 ETH at $3,020 on DEX B where price is higher. Gross profit: $20,000 from the spread.
3

Repay the flash loan

Return the $50 million plus the $25,000 fee (0.05%). Net profit: $20,000 − $25,000 fee − gas cost. If the profit exceeds costs, the trade is successful. If not, the transaction reverts and you only lose the gas fee.
4

Zero capital risk

If prices move between the time you initiate and the execution, the trade may not be profitable. In that case, the transaction simply reverts. Your maximum loss is the gas fee for the failed transaction, typically under $50.

Flash Loan Attack Vectors

Flash loans are a tool. Like all tools, they can be used constructively or destructively. Flash loan attacks exploit vulnerabilities in protocols that were not designed to withstand an actor wielding $100 million+ in a single transaction.

Oracle Manipulation

The most common attack vector. If a lending protocol uses a single DEX pool as its price oracle, an attacker can flash borrow a massive amount, trade aggressively on that DEX to spike the price, then exploit the mispricing in the lending protocol (e.g., borrow more than their collateral is worth at the manipulated price). After the transaction, the DEX price reverts, but the attacker has already extracted value from the lending protocol.

Governance Manipulation

Flash borrow governance tokens, vote on a malicious proposal, return the tokens. Some protocols have been attacked this way because they allowed single-block voting without requiring tokens to be held for a minimum period. Most governance systems now include vote-locking periods and snapshot-based voting to prevent this.

Reentrancy Amplification

Flash loans amplify reentrancy vulnerabilities. A reentrancy bug that might allow extracting $10,000 with normal capital can extract $10 million with a flash loan providing the initial trigger. The capital amplification makes previously marginal vulnerabilities catastrophically exploitable.

Flash loans as a risk factor

When evaluating any DeFi protocol you deposit into, ask: "Could a flash loan attack drain this protocol?" Protocols that use robust oracle designs (Chainlink, TWAP), have reentrancy guards, and implement borrow caps are more resilient. Protocols using single-source spot price oracles are flash-loan-vulnerable by design.

Practical Flash Loan Example

Here is a realistic collateral swap scenario. You have a lending position with WBTC as collateral and a USDC borrow. You want to switch your collateral to ETH without closing the position and incurring slippage on a large trade.

1

Flash borrow USDC

Borrow enough USDC to repay your entire outstanding debt via a flash loan.
2

Repay your lending debt

Use the flash-borrowed USDC to repay your lending protocol debt in full. Your WBTC collateral is now unlocked.
3

Withdraw and swap collateral

Withdraw your WBTC collateral. Swap WBTC → ETH on a DEX. Deposit the ETH as new collateral in the lending protocol.
4

Re-borrow and repay the flash loan

Borrow USDC against your new ETH collateral. Use it to repay the flash loan plus the 0.05% fee. One transaction. Collateral swapped. Position never closed.

Flash Loans as a Risk Factor

As a DeFi user depositing capital into protocols, flash loans represent a systemic risk you must account for. Any protocol you deposit into could theoretically be targeted by a flash loan attack. Your due diligence should include understanding whether the protocols you use are flash-loan-resistant.

Oracle robustness

Does the protocol use Chainlink or multi-source TWAP oracles? Or does it rely on a single DEX pool that can be manipulated with a large trade?

Reentrancy protection

Does the protocol use reentrancy guards (checks-effects-interactions pattern)? Has it been audited for reentrancy vulnerabilities?

Borrow caps

Are there caps on how much can be borrowed in a single transaction or block? Caps limit the damage from flash loan attacks.

Governance safeguards

Does governance require vote-locking, time delays, and snapshot-based voting? These prevent flash loan governance attacks.

Historical resilience

Has the protocol survived through multiple market cycles without being exploited? Battle-tested protocols have a better track record than new ones.

Flash loans are a feature, not a bug

Flash loans are a fundamental DeFi primitive that makes markets more efficient, liquidations faster, and capital allocation more democratic. The problem is not flash loans. It is protocols with weak oracle designs and unaudited code. Focus your risk assessment on the protocols you deposit into, not on the existence of flash loans themselves.
Module Quiz

1.What happens if a flash loan is not repaid within the same blockchain transaction?

2.A borrower has $10,000 ETH collateral on Aave with a liquidation threshold of 82.5% and $7,000 in outstanding debt. What is their health factor?

3.Why is the 'looping' strategy on lending protocols considered high-risk?

4.What is the most common flash loan attack vector?

5.What advantage does borrowing against crypto collateral provide over selling the crypto directly?

0/5 answered

Put this lesson to work

Free on Thrive, no account needed.