---
title: "Price oracle manipulation"
url: https://dontgetrekt.today/dev/oracle-manipulation
section: "What does it trust?"
owasp: SC03:2026
---

# Price oracle manipulation

The protocol reads a price that the attacker can move in the same transaction, usually the spot price of one AMM pool. The attacker borrows against a fake price.

## How the attack works

1. A lending market or vault reads the price of a token from the reserves of one DEX pool, or from `balanceOf` of a contract.
2. The attacker takes a flash loan and makes a large swap in that pool. The price moves.
3. In the same transaction, the attacker borrows, mints or liquidates at the wrong price.
4. The attacker swaps back, repays the flash loan and keeps the difference. Variants: a stale Chainlink price, an LP token priced from its reserves, a donation that changes an exchange rate.

## Vulnerable code

```solidity
function price() public view returns (uint256) {
    (uint112 r0, uint112 r1,) = pair.getReserves();
    return uint256(r1) * 1e18 / r0;   // spot price: one swap moves it
}
```

## Fixed code

```solidity
function price() public view returns (uint256) {
    (, int256 p,, uint256 updatedAt,) = feed.latestRoundData();
    require(p > 0, "bad price");
    require(block.timestamp - updatedAt <= MAX_DELAY, "stale price");
    return uint256(p) * 1e10;         // scale 8 decimals to 18
}
// If no feed exists: use a TWAP over a long window, and cap
// how much the price can change between two reads.
```

## Review checklist

- Never use a spot price (pool reserves, `balanceOf`, `getAmountsOut`) as an oracle.
- Use a decentralized feed (Chainlink, Pyth, Redstone). Check the answer is positive and fresh. Check the sequencer uptime feed on L2s.
- For a TWAP, use a window that costs too much to move (30 minutes or more), and a pool with deep liquidity.
- Price LP tokens with a fair-reserves formula, not with their reserves.
- Add a circuit breaker: pause when the price moves more than a limit between reads.

## How to test for it

- Fork mainnet in Foundry. Swap a large amount in the pool, then call your function. The result must not change.
- Test with a stale feed answer and with a zero or negative answer.

## Real exploits (121)

- 2021-10-27 Cream Finance ($130.0M): Cream Finance lost about $130M when an attacker used flash loans to manipulate the yUSDVault price (pricePerShare) read by Cream's PriceOracleProxy, then borrowed against the inflated collateral. [rekt.news](https://rekt.news/cream-rekt-2) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2021-10/Cream_2_exp.sol)
- 2026-08-30 Tectonic ($120.4M): Tectonic on Cronos lost $120.4M in nominal borrowing (about $9.19M unrecovered after a chain rollback) when an attacker pumped the thinly traded TONIC governance token and borrowed against it as collateral. [rekt.news](https://rekt.news/tectonic-rekt)
- 2023-02-01 BonqDAO ($120.0M): BonqDAO on Polygon lost a reported $120M (attacker realised under $2M) because it used the instantly updatable Tellor price of WALBT, which anyone could set by staking 10 TRB. [rekt.news](https://rekt.news/bonq-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-02/BonqDAO_exp.sol)
- 2022-10-11 Mango Markets ($115.0M): Mango Markets on Solana lost about $115M after an attacker pumped the thinly traded MNGO price and borrowed against the unrealised profit on an MNGO-PERP position. [rekt.news](https://rekt.news/mango-markets-rekt)
- 2020-11-26 Compound Finance ($110.0M): Compound Finance saw over $110m of loans liquidated after its single Coinbase price oracle reported DAI at about $1.3, whether through error or manipulation. [rekt.news](https://rekt.news/coinbase-the-oracle)
- 2021-05-19 PancakeBunny ($45.0M): PancakeBunny lost about $45M on BNB Chain when an attacker used flash loans to skew PancakeSwap pool prices used to value LP tokens, so getReward() minted huge amounts of BUNNY. [rekt.news](https://rekt.news/pancakebunny-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2021-05/PancakeBunny_exp.sol)
- 2021-09-21 Vee Finance ($34.0M): Vee Finance on Avalanche lost about $34M when an attacker manipulated its single-source Pangolin pool price oracle, helped by missing decimal handling in price acquisition. [rekt.news](https://rekt.news/veefinance-rekt)
- 2021-05-02 Spartan Protocol ($30.5M): Spartan Protocol lost about $30.5M from its SPARTA/WBNB pool because calcLiquidityShare() used the manipulable current pool balance when LP tokens were burned. [rekt.news](https://rekt.news/spartan-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2021-05/Spartan_exp.sol)
- 2020-10-26 Harvest Finance ($25.0M): Harvest Finance lost about $25M from its FARM_USDT and FARM_USDC vaults when an attacker used flash loans to skew Curve Y pool prices that the vaults used to price deposits and withdrawals. [rekt.news](https://rekt.news/harvest-finance-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2020-10/HarvestFinance_exp.sol)
- 2021-05-12 XToken ($24.0M): XToken lost about $24M from its xSNXa and xBNTa pools when a flash-loan attacker pushed the SNX price down on Uniswap and minted tokens almost for free. [rekt.news](https://rekt.news/xtoken-rekt)

## References

- [OWASP SC03:2026](https://scs.owasp.org/sctop10/SC03-PriceOracleManipulation/)
- [Chainlink: Data feeds best practices](https://docs.chain.link/data-feeds/selecting-data-feeds)
- [Uniswap V3: Oracle](https://docs.uniswap.org/concepts/protocol/oracle)
