Yashotantra Academy logo

2 · DeFi & Oracle Manipulation

2. Flash Loan Attacks & Oracle Manipulation

Spot prices vs TWAP, AMM pool manipulation, and securing ERC-4626 share calculation ratios.

11 min read · 2 MCQs

Why Spot Prices from AMM Pools are Unsafe

Querying `token0.balanceOf(pair) / token1.balanceOf(pair)` on Uniswap to determine asset prices is vulnerable to flash loan manipulation. An attacker can borrow 100M USD, dump tokens into the pool to artificially depress the price, liquidate collateralized loans at distorted valuations, and repay the flash loan in a single atomic transaction.

Decentralized Oracles & TWAP Protections

Secure protocols rely on Chainlink decentralized oracle networks with heartbeat/deviation thresholds, or compute geometric Time-Weighted Average Prices (TWAP) over multi-block observation windows that make manipulation cost-prohibitive.

Chapter quiz

2 questions · pass mark 75%
  1. 1. Why should smart contracts avoid using raw AMM pool reserves as direct price oracles?

  2. 2. What is an ERC-4626 vault inflation attack?