Smart-contract security & auditing

oracle manipulation

Oracle manipulation is tricking a contract into acting on a price or data feed the attacker can move. A lending protocol, a stablecoin, or a derivatives contract needs to know the price of an asset, and it asks an oracle. If that oracle is something an attacker can push around within a single transaction, then the contract's whole notion of value is corrupted: collateral can be made to look worth more than it is, debts can be erased, or assets bought far below fair value.

The canonical mistake is reading a spot price directly from an on-chain pool, for example calling getReserves on a Uniswap pair and dividing. That number reflects the pool's current balances, which an attacker can swing by making a large swap, especially in a shallow, low-liquidity pool. Combined with a flash loan to supply temporary capital, the attacker pushes the price, exploits a contract that trusts that distorted number, and unwinds, all atomically. Real cases include bZx, Harvest Finance, and Mango Markets, which together lost hundreds of millions to this pattern.

Robust designs never trust a single, instantly movable price. Mitigations include time-weighted average prices (TWAPs) that average over many blocks so a one-block spike barely moves the average; decentralized oracle networks such as Chainlink that aggregate many off-chain sources; using multiple independent feeds and rejecting outliers; and sanity checks on deviation and staleness. None is a silver bullet: TWAPs lag and can still be manipulated over several blocks in thin markets, and even reputable feeds can have downtime or extreme-volatility gaps.

An attacker flash-borrows a large sum, dumps it into a thin token pool to crash that token's on-chain spot price, then uses a lending market that reads that exact spot price to borrow far more than their (now under-priced) collateral should allow, and repays the flash loan, keeping the difference.

A price you can move within one transaction is not an oracle, it is an attack surface. Reading the spot price from a single on-chain pool is the single most exploited oracle mistake in DeFi.

Also called
price oracle manipulation價格操縱攻擊