The Oracle Problem
A blockchain smart contract can read on-chain state (token balances, other contract variables, block number, block timestamp). It cannot read off-chain data — stock prices, real-world sensor readings, weather data, or payment confirmation from a traditional banking system. An oracle provides this data to smart contracts via an on-chain transaction. The oracle problem: how do you trust the data the oracle provides? A centralized oracle is a single point of failure and a single point of manipulation. A decentralized oracle network (multiple independent nodes aggregating data with outlier resistance) is significantly more resistant to manipulation.
Oracle Types
Decentralized Price Feed Oracles (Chainlink, Pyth)
Chainlink Data Feeds: The dominant oracle network for DeFi. Multiple independent node operators each fetch price data from multiple sources, aggregate independently, and the Chainlink network produces a final aggregated price on-chain. Feeds are updated when the price moves beyond a deviation threshold or a heartbeat interval elapses. Cost: free to read from existing feeds on supported chains. Pyth Network: Real-time price data with sub-second update frequency. Sourced from financial institutions, market makers, and exchanges. Particularly useful for derivatives and options applications requiring high-frequency price updates. Cost: free to read from on-chain price stores; pull-based model where the caller pays for each price update.
Uniswap TWAP Oracle
For tokens with sufficient on-chain liquidity, the Uniswap V3 Time-Weighted Average Price provides a manipulation-resistant on-chain price oracle. A TWAP averages the price over a defined period — typically 30 minutes — making flash loan manipulation economically prohibitive. Limitation: TWAPs are only as good as the underlying pool's liquidity.
Oracle Security Patterns
- Use TWAP for manipulation-resistant prices. For any collateral valuation that determines liquidation: do not use spot prices.
- Circuit breaker for price deviation: if the oracle price deviates more than X% from its prior value in Y minutes, pause protocol operations.
- Oracle health checks: verify that the oracle's last update timestamp is recent before using its price.
- Multiple oracle confirmation for high-value operations: require confirmation from multiple independent oracle sources before executing.



