Key takeaways
- A smart contract can only see data already on its own blockchain. Blockchain oracles are the services that bring outside facts, such as prices, onto the chain.
- Most DeFi lending and trading apps depend on price oracles. Chainlink and Pyth are the best known.
- Push oracles write prices on-chain on a timer or when prices move; pull oracles deliver a signed price only when a transaction asks for one.
- Weak price feeds are a common way for DeFi apps to lose money: Chainalysis counted 41 oracle manipulation attacks costing $386.2 million in 2022.
A smart contract is good at following rules, but it cannot see anything outside its own blockchain. It has no way to check the price of bitcoin on an exchange, the result of a football match or the balance of a bank account. Blockchain oracles fill that gap: they collect outside data, check it and publish it on-chain, where contracts can use it. This guide explains how blockchain oracles work, the difference between push and pull designs, and how attackers have exploited weak price feeds. It builds on our guide to smart contracts and how they fail.
Why smart contracts need blockchain oracles
Every node on a blockchain has to reach the same result when it runs a transaction. If a contract could call a website directly, different nodes might get different answers, or the site might be offline, and the network could not agree. So blockchains are closed by design: contracts only see what is already recorded on the chain.
Developers call this the oracle problem. A lending app needs to know what your collateral is worth so it can liquidate a loan before it turns into a loss. A derivatives exchange needs a price to settle trades. A stablecoin backed by other crypto needs to know when its collateral is falling. All of that information comes from outside, and something has to bring it in.
That something is the oracle. Because a contract accepts whatever its oracle reports, the oracle becomes part of the security of every app that relies on it. A contract can be written perfectly and still lose money if it is fed a wrong number.
How a price oracle works
Most oracles used in DeFi follow the same pattern. Several independent operators, called nodes, collect prices from many sources such as exchanges and data aggregators. Their reports are combined into one figure, usually the median, so that one faulty or dishonest node cannot move the result much. The final number is signed and published on-chain.
Chainlink, the largest oracle network, works this way. In its Data Feeds, nodes agree on a report off-chain and one of them submits it; the contract on the chain checks the signatures and takes the median, according to a technical review by security firm Ackee Blockchain. Each feed updates on two triggers. A deviation threshold writes a new price when the market moves far enough from the last value on the chain, for example 0.5% for a volatile asset, Chainlink says, with tighter limits for stable pairs such as USDC/USD. A heartbeat writes an update after a set time even if the price has barely moved, so the feed never goes quiet for too long.
Apps read the latest value from the feed, along with the time it was last updated. That timestamp matters, as the section on defences below explains.
Push vs pull oracles
Oracles differ in who sends the price to the blockchain, and when.
A push oracle writes prices on-chain itself, on a timer or when the price moves. Chainlink’s Data Feeds are the classic example. The price is always sitting on the chain, ready to read, which keeps things simple for developers. The downside is that updates happen whether or not anyone needs them, and between updates the stored price can lag the market, Pine Analytics notes in its comparison of the two designs.
A pull oracle turns that around. Pyth Network publishes signed prices off-chain at high frequency. When an app needs a price, the user’s transaction fetches the latest signed update and brings it along; the contract verifies the signature and then uses the number. As Pyth’s documentation puts it, “each transaction carries a signed price, verified on the spot.” The person sending the transaction pays the update fee, according to Pine Analytics.
| Push oracle | Pull oracle | |
|---|---|---|
| Example | Chainlink Data Feeds | Pyth Network |
| When the price updates | On a timer, or when it moves past a threshold | When a transaction asks for it |
| Main strength | Always on-chain and simple to read | Fresh at the moment it is used |
| Main weakness | Can lag between updates | The app must fetch and check every update |
| Cost of updates | Spent even when no one reads the price | Paid by the user sending the transaction |
Neither design is safe by default. A push feed can be out of date between updates, and a pull feed is only as good as the app’s checks on the price it is handed.
Oracles beyond prices
Prices are the biggest use, but the same idea works for any outside fact that can be checked. Proof-of-reserve feeds publish how much of an asset a custodian or stablecoin issuer reports holding. In October Chainlink launched CustodySync, which lets institutions borrow in DeFi against assets that stay with their custodian, and began publishing S&P Global’s risk grades for crypto lending vaults on-chain. Prediction markets need oracles too, to report the outcome of an event before contracts pay out.
Oracle manipulation: how attacks work
If you can fool an oracle, you can fool every contract that trusts it. Chainalysis counted 41 oracle manipulation attacks in 2022, which took $386.2 million from DeFi protocols.
Most follow a simple recipe. The attacker picks a token that trades thinly, so its price is easy to move. They push the price up with a burst of buying, often funded by a flash loan, which lets anyone borrow a large sum with no collateral as long as it is repaid within the same transaction. The protocol’s oracle reads the inflated price, the attacker posts the token as collateral at that value and borrows real assets against it. When the price falls back, the protocol is left with bad debt.
Two well-known cases show the pattern:
- Mango Markets, October 2022. The attacker drove the price of Mango’s own MNGO token up about 300% within ten minutes, and Mango’s oracle, which took prices from centralised exchanges, picked it up. Using the inflated MNGO as collateral, the attacker borrowed about $112 million from the platform, Blockworks reported, citing security firm OtterSec. According to Chainalysis, the buying “pushed the price of MNGO up very quickly on spot exchanges.”
- Inverse Finance, April 2022. An attacker manipulated the oracle for the INV/ETH pair so INV looked more valuable than it was, then borrowed about $15.6 million in other tokens against it, according to Web3 Is Going Great.
The weak spot in both cases was the same: a price that one large trader could move. Feeds that combine many markets and many independent nodes are much harder to push around. Our guide to DeFi risks covers oracle failures alongside the other ways DeFi apps lose money.
How protocols defend against bad data
A well-built oracle is only half the job. The app reading the data has to use it carefully. Common safeguards, several of them listed in Ackee Blockchain’s review, include:
- Checking freshness. Compare the feed’s last update time with the current block time, and refuse to act if the gap is longer than the feed’s heartbeat allows.
- Sanity checks. Reject a price of zero or below, and consider limits on how far a price can jump in one update.
- A backup source. Fall back to a second oracle or a time-weighted average price (TWAP) if the main feed fails.
- Watching layer 2 sequencers. On rollups such as Arbitrum or Optimism, a stopped sequencer can leave prices stale while some users can still act through Ethereum; Chainlink offers a sequencer uptime feed so apps can pause.
- Careful collateral lists. Thinly traded tokens are the easiest to manipulate, Chainalysis found, so lending apps limit how much can be borrowed against them.
The oracle operator is also a point of trust. Ackee notes that a Chainlink-run multisig wallet, with nine owners and a threshold of four, can upgrade its feeds, so users rely on that group not to make mistakes or abuse the power.
What blockchain oracles mean for you
You do not need to read a protocol’s code to make better choices. Before you deposit in a lending or trading app:
- Check its documentation for which oracle it uses for each asset. A well-known feed built from many sources is a better sign than a price taken from a single exchange or pool.
- Be careful with markets built around small tokens, especially ones the protocol issued itself, as Mango’s MNGO showed.
- Remember that an oracle failure can hurt you even if you did nothing wrong: liquidations can fire on a bad price, and bad debt can leave lenders short.
Oracles rarely make headlines when they work. They are the quiet layer that lets smart contracts react to the world, and when that layer fails, the losses are usually large.
You might also like
Sources: Chainlink, Ackee Blockchain, Pine Analytics, Pyth Network, Chainalysis via The Daily Hodl, Blockworks, Web3 Is Going Great





