
A smart contract cannot look at the outside world. Every node must reach the same result from the same inputs, so a contract that called a price website would break consensus. Anything a contract knows about a market price has been written onto the chain by someone. That someone, and the rules they follow, is the oracle, and it is usually the softest part of a DeFi protocol.
Reading a pool’s spot price
The simplest oracle asks an automated market maker for the current ratio of its reserves. It is also the easiest to attack. A pool’s ratio changes whenever anyone trades, and with borrowed capital an attacker can push the ratio far from the market, act on the false price in another protocol, and restore the pool, all inside one transaction where no arbitrage can intervene. The vulnerable pattern is almost always a protocol reading spot price from a pool with modest liquidity. Our explainer on how an AMM prices a swap shows why small pools move so far.
Time-weighted averages
The standard fix is to average the price over a window. Uniswap v2 built this into its pair contract: each pool keeps running sums, price0CumulativeLast and price1CumulativeLast, which add the current price multiplied by the seconds elapsed every time the reserves update, as the contract source shows. Another contract can read two snapshots and divide by the time between them to get an average. Moving that average means holding the price away from the market for much of the window, exposed to arbitrage the whole time.
The cost is lag. A time-weighted price is behind the market by design, and during a genuine fast move the protocol works with old information, which is when accuracy matters most. Longer windows resist manipulation better and react more slowly. No setting is good at both.
External reporter networks
A group of independent operators reads off-chain markets and publishes an aggregated value on-chain. This avoids on-chain pool manipulation, because the markets observed are deep and expensive to move. The trust moves to the reporter set: how many, how independent, how the values are combined, and when they publish. A common update rule combines two triggers: publish when the price has moved past a deviation threshold, or when a maximum interval, the heartbeat, has passed since the last update. Both numbers are risk parameters. A wide deviation band means the protocol accepts that its view of the price can be materially wrong between updates, and its collateral buffers have to cover that.
Staleness: the quiet failure
If a feed stops updating, a protocol that reads it naively keeps using the last value it saw. Positions are valued at a price that no longer exists; liquidations do not fire, or fire against the wrong number. Correct handling means checking the timestamp on every read and defining what happens when the value is too old: pause, refuse new borrowing, or switch to a fallback. The omission is invisible until the day the feed stalls. Our liquidations explainer covers what follows.
No oracle creates liquidity
An oracle can only be as reliable as the market it observes. A thinly traded asset has no robust price, and no architecture manufactures one; averaging a manipulable market gives a manipulable average, more slowly. Listing an illiquid asset as collateral is a decision about that asset’s market depth, not an integration detail.
The Settlement Test
- What settles: each price update is an ordinary on-chain transaction. Between updates, the protocol settles every borrow, repayment and liquidation against the last value written.
- What it costs: reporters pay gas for each update, which is one reason feeds update on thresholds rather than continuously; time-weighted designs cost readers extra calls. Current gas is on our gas and fees page.
- What breaks: a manipulated spot price, a feed that stalls without a staleness check, or a thin underlying market that no oracle design can fix.
Questions to ask of any protocol
Where does each price come from, and from one source or several? If on-chain, how deep is the pool and is it spot or time-weighted? What are the deviation threshold and heartbeat? Is staleness checked on every read, and what happens when the check fails? Has the fallback ever been used? This is description, not advice about any protocol.
Primary sources
Educational content, human-edited and possibly AI-assisted. It describes how systems work and is not financial, legal or tax advice. Report an error via our corrections page.


