What is oracle?
A service that supplies external data, such as asset prices, to a smart contract.
Not yet verifiedHow we verify
3 min read
In this entry
A service that supplies external data, such as asset prices, to a smart contract.
Contracts cannot read anything outside their own blockchain, so lending and derivatives protocols depend on oracles to know what an asset is worth. This is not a limitation anyone chose. A blockchain reaches agreement by having every node recompute the same result, and a node fetching a web page would get a different answer, so external data has to be brought in as a transaction like anything else.
Manipulating an oracle price feed has been the cause of several large DeFi exploits. That makes the oracle the single most security-critical dependency in most lending protocols, and the piece least visible to the people using them.
How it works
A price oracle is a contract on chain holding a value, updated by one or more reporters who observe outside markets and submit transactions. Applications read from it.
Design choices decide how hard it is to attack.
Source breadth. A feed aggregating many venues is expensive to move. A feed reading a single decentralized exchange pool can be moved by a flash loan in one transaction, which is exactly how several exploits worked.
Aggregation. Taking a median across independent reporters means corrupting one is not enough. Taking a simple average lets one extreme value drag the result.
Update policy. Feeds typically update on a deviation threshold or a heartbeat interval, so the on-chain price is a step function that lags the market between updates.
Time weighting. A time-weighted average price over a window makes short manipulation expensive, at the cost of reacting slowly to a genuine move.
That last trade-off has no clean answer. A fast feed is manipulable, a slow feed leaves lending positions mispriced during a crash, and every protocol picks a point between them.
Oracles also carry non-price data: proof-of-reserve attestations, randomness, and event outcomes for prediction markets, with the same trust questions attached.
Example
Illustrative manipulation. A lending protocol prices collateral from a single decentralized exchange pool holding $2,000,000 of liquidity. An attacker borrows a large sum through a flash loan, swaps it into that pool to push the reported price of the collateral asset up by 40%, and within the same transaction deposits a small amount of that asset and borrows against the inflated valuation.
The loan is repaid, the pool price reverts, and the protocol is left holding collateral worth a fraction of what it lent. The whole sequence completes in one transaction, which is why an oracle reading a single thin pool is treated as a critical flaw rather than a design preference.
Why it matters when you buy
Buying on a centralized exchange involves no oracle at all: the price is the order book. Oracles become your dependency the moment you lend, borrow, or use a synthetic product on chain, because they decide when your position gets liquidated. It is also worth knowing that a price shown by an application is not necessarily a price you can trade at. The measured spreads and depth on the liquidity pages are what a real order would face.
Related terms
- flash loan — the tool used to move thin feeds
- liquidation — what an oracle price triggers
- twap — time weighting as a defense
- index price — the centralized equivalent construction
- over collateralization — the buffer oracles protect
- defi — where oracle risk concentrates
Questions
Why can a contract not just read a price from the internet?
Because every node would fetch a slightly different answer and consensus would break. Data has to enter the chain as a transaction that all nodes see identically.
Are oracles decentralized?
They vary. Some aggregate many independent reporters with on-chain accountability, others rely on a single updater. Which one a protocol uses is in its documentation and is worth checking before depositing.
Does an oracle affect me if I only buy and hold?
No. Oracle risk applies to on-chain lending, borrowing, derivatives, and synthetics. Holding an asset in a wallet involves none of them.