⚠️ Flash Loan Risks: Attacks & Defense

Learn about price manipulation, reentrancy, and oracle attacks

Borrow millions with no collateral in seconds

⚠️ Risks & Security

Flash loans have enabled some of DeFi's largest hacks. Understanding attack vectors and implementing proper security measures is critical before deploying flash loan strategies.

🔒 Security Assessment Tool

Check your smart contract against critical security requirements. Toggle each item to calculate your risk score.

Reentrancy guards on all external calls?
25pts
Secure oracle with manipulation resistance?
20pts
Access control on critical functions?
15pts
Slippage protection on DEX swaps?
15pts
Emergency pause/circuit breaker?
10pts
Professional security audit completed?
10pts
Comprehensive testing on mainnet fork?
5pts

Security Score

0/100
Critical Risk
❌ Critical security gaps. High likelihood of exploitation. Extensive work needed.

🎯 Common Attack Vectors

🔄

Reentrancy Attacks

Attacker repeatedly calls function before first call completes

Real Attack:
DAO Hack (2016): $60M stolen via recursive withdrawals
Protection:
Use checks-effects-interactions pattern, reentrancy guards (OpenZeppelin)
📊

Oracle Manipulation

Flash loan manipulates price oracle to exploit protocols

Real Attack:
Harvest Finance (2020): $34M lost via USDC/USDT price manipulation
Protection:
Use time-weighted average prices (TWAP), multiple oracles, Chainlink
🗳️

Governance Attacks

Flash loan governance tokens to pass malicious proposals

Real Attack:
Beanstalk (2022): $182M drained via flash-loaned voting power
Protection:
Voting power snapshots, time-locks on proposals, vesting periods
🥪

MEV Sandwich Attacks

Bots front-run and back-run your transaction for profit

Real Attack:
Daily MEV extraction: $10-50M from sandwich attacks
Protection:
Private mempools (Flashbots), MEV-protection RPC, limit orders

✅ Security Best Practices

🛡️

Use Battle-Tested Libraries

OpenZeppelin, Aave, Uniswap libraries

🔍

Multiple Security Audits

Trail of Bits, OpenZeppelin, Consensys Diligence

⏱️

Time-Locked Upgrades

48-hour delay on critical changes

🚨

Circuit Breakers

Pause functionality for emergencies

💰

Bug Bounty Programs

Incentivize white-hat disclosure

📡

Real-Time Monitoring

Alert systems for suspicious activity

⚡ Notable Flash Loan Attacks

Beanstalk Farms (April 2022)

$182M

Flash-loaned $1B in crypto, used it to gain 67% governance voting power, passed malicious proposal to drain treasury, executed proposal immediately.

Lesson: Snapshot voting power BEFORE proposals, require time-locks

Cream Finance (Aug 2021)

$130M

Exploited price oracle by flash-loaning tokens, manipulating their price upward, using inflated collateral to borrow all available assets, price crashed and protocol left with bad debt.

Lesson: Use TWAP oracles, circuit breakers on large price swings

PancakeBunny (May 2021)

$200M

Flash loan manipulated BNB/BUNNY price on PancakeSwap. Exploiter minted massive BUNNY rewards by inflating calculated price, dumped tokens, protocol's native token crashed 96%.

Lesson: Never use spot prices for critical calculations, validate oracle data

🛠️ Developer Checklist

Implement reentrancy guards on ALL functions that make external calls
Use Chainlink or TWAP oracles, never spot prices from single DEX
Add slippage protection on all DEX swaps (max 1-2% tolerance)
Test extensively on mainnet fork with realistic scenarios
Get professional security audit from reputable firm ($30-100K)
Launch bug bounty program (Immunefi, HackerOne)
Implement circuit breakers and emergency pause functionality
Monitor transactions in real-time with alerting systems
Use battle-tested libraries (OpenZeppelin) instead of custom code
Start small - test strategy with limited capital first