what is an oracle in crypto

What Is an Oracle in Crypto?

Smart contract needs to know the price of ETH to decide whether to liquidate a loan. Problem: the blockchain has no idea what ETH costs. Can't check Binance. Can't query the internet. Completely isolated system.

Oracle solves this. External service that pushes real-world data onto the chain. Smart contract reads the oracle. Gets the price. Executes accordingly.

Without oracles, DeFi lending doesn't exist. Derivatives don't exist. Prediction markets don't exist. Anything requiring real-world data doesn't exist.

Most critical infrastructure in DeFi that most users never think about.

What Oracles Actually Feed In

Price feeds are the obvious one. Every lending protocol checking collateral values every block. Every perpetual futures platform calculating mark price. Every options protocol pricing contracts. All reading price oracles constantly.

But oracles go beyond prices.

Prediction markets need sports scores and election results. NFT mints need verifiable randomness so nobody can game the outcome. Parametric insurance needs weather data to trigger payouts. Cross-chain bridges need to verify events on other chains.

Any smart contract that needs to know something that happened outside the blockchain needs an oracle. Which is most smart contracts doing anything interesting.

Chainlink and How Decentralized Oracles Work

Chainlink dominates. Used by Aave, Compound, Synthetix, and most serious DeFi protocols. Worth understanding how it works because the model matters.

Single source for a price feed is dangerous. One bad data point or one compromised source and every protocol reading that feed gets bad data.

Chainlink uses a network of independent node operators. Each sources data from multiple providers independently. Results get aggregated. Outliers filtered. Final price published on-chain represents a consensus across many independent sources.

Much harder to corrupt than a single source. Attacker needs to compromise multiple independent nodes simultaneously rather than one API. LINK token pays node operators for their service. Economic incentive to stay honest.

Not perfect. Still introduces trust assumptions. But dramatically better than a single centralized price feed.

The Oracle Problem

Smart contracts are trustless and deterministic. Oracles aren't.

Oracle publishes wrong data, intentionally or accidentally, and every protocol built on that oracle executes based on the wrong data. Liquidations triggered incorrectly. Loans issued against overstated collateral. Payouts on wrong outcomes.

Garbage in. Garbage out. Smart contract executes perfectly according to its code. Code working as designed on bad inputs is still a disaster.

This is called the oracle problem. Fundamental tension between trustless on-chain execution and the requirement for trusted off-chain data. No perfect solution. Only better and worse approaches to managing the trust assumption.

Oracle Manipulation Attacks

Real exploits. Large ones.

Flash loans made oracle manipulation dramatically more accessible. Borrow massive capital with zero collateral. Use it to move price on a low-liquidity DEX. Protocol reading that DEX price as its oracle sees manipulated price. Execute attack based on fake price. Repay flash loan in same transaction. Done.

Mango Markets 2022. Avraham Eisenberg used roughly $10 million to artificially inflate the price of MNGO token. Inflated price made his collateral appear worth far more than it was. Borrowed $114 million against the fake valuation. Walked away with the funds. Explicitly used oracle price manipulation as the mechanism. Cost Mango Markets everything.

Dozens of smaller versions of the same attack across DeFi history. Oracle is the attack surface. Better oracle design reduces it. Doesn't eliminate it.

TWAP Oracles

Uniswap introduced on-chain TWAP oracles with V2. Time-Weighted Average Price over a set window rather than current spot price.

Flash loan can move spot price for one block. Moving a 30-minute time-weighted average requires sustained capital across many blocks. Enormously more expensive to manipulate.

Many protocols use TWAP specifically to resist flash loan attacks. Slight lag between real market price and TWAP is the tradeoff. For most use cases that lag is acceptable. For high-frequency trading it isn't.

Pyth Network

Chainlink competitor worth knowing particularly if active on Solana.

Different model. Data providers including major trading firms and exchanges push prices directly on-chain. High frequency updates. Sub-second price feeds. Designed for financial markets requiring real-time accuracy.

Originally Solana focused. Expanded to other chains. Used by many Solana DeFi protocols where Chainlink coverage was historically limited.