Skip to content

What is a blockchain oracle? How smart contracts get real-world data, and the oracle problem

Why smart contracts can't read the outside world on their own, how oracles bring in prices and other data, centralized vs decentralized oracles and the risks.

Figures checked against 4 official and primary sources on . See the sources · How we check

Key points

  • Smart contracts can only see data on their own blockchain. An oracle brings in outside information, such as prices or weather, so a contract can act on it.
  • Blockchains need every node to reach the same result, which is why contracts can't simply call a website. Oracles store outside data on-chain so everyone uses the same input.
  • That creates the oracle problem: if the data is wrong or manipulated, the contract still acts on it. NIST notes there may be no way to tell from inside the blockchain whether input data reflects real events.
  • DeFi lending relies on price oracles to value collateral. Decentralized oracles aim to remove single points of failure, but none is perfect.
In this guide
  1. What an oracle is
  2. How oracles are built
  3. Why blockchains need oracles
  4. What oracles are used for
  5. The oracle problem
  6. Centralized vs decentralized oracles
  7. How decentralized oracles try to get it right
  8. A real case: when the oracle’s sources were moved
  9. What it means for users

Smart contracts are often described as code that runs exactly as written. But code can only act on the information it has, and a blockchain on its own knows nothing about the outside world: not the price of gold, not tomorrow’s weather, not who won last night’s game. The tools that bring that information in are called oracles, and they’re one of the most important, and most fragile, parts of decentralized finance.

This guide explains what oracles do, why blockchains need them, the different types and the risks.

What an oracle is

ethereum.org defines oracles as applications that source, verify and transmit external information to smart contracts. They can also work the other way, pushing information from the blockchain to outside systems, for example unlocking a smart lock once someone pays. Without an oracle, a smart contract is limited to on-chain data. See what is a smart contract?

A typical oracle has two parts, ethereum.org explains: a smart contract on-chain, which receives requests for data, and off-chain components (oracle nodes) that fetch the data, for example from an API, and send it back to the contract.

How oracles are built

ethereum.org groups oracles by where their data comes from (one source or several), by trust model (centralized or decentralized) and by design. The two designs most used by Ethereum smart contracts are:

  • Publish-subscribe: the oracle keeps a data feed that other contracts read regularly, for data that changes often. ethereum.org’s example is an oracle that provides the latest ETH-USD price.
  • Request-response: a contract asks for specific data when it needs it. The oracle’s on-chain part receives the request and passes it to an off-chain node, which fetches the answer and sends it back. This suits data sets too large to keep on-chain, where users need only a small part at a time.

Oracles can also automate contracts. Smart contracts don’t run by themselves: an account or another contract has to trigger them. ethereum.org explains that some decentralized oracle networks offer services that trigger a contract’s functions at set times or conditions, usually after the developer registers the contract and pays the oracle operator.

Why blockchains need oracles

Blockchains are deterministic: every node must get the same result from the same inputs. ethereum.org gives the reason this rules out simply calling a website: if a contract used a live ETH-to-dollar price from an external API, the figure could change between nodes, or the API could disappear or be hacked, and nodes running the same contract would reach different results. Consensus would break down.

Oracles solve this by putting the outside data on the blockchain first, where it’s fixed and public, so every node uses the same input. ethereum.org calls the result “hybrid smart contracts”: contracts that combine on-chain code with off-chain infrastructure.

What oracles are used for

ethereum.org gives examples including:

  • Price feeds for DeFi. Lending platforms use price oracles to value collateral and decide how much users can borrow. See what is DeFi?
  • Insurance, such as crop insurance that pays out when oracles confirm certain weather.
  • Prediction markets, which need to know the outcome of an event. See prediction markets explained.
  • Randomness for games and lotteries, generated off-chain with cryptographic proof that it wasn’t tampered with.

The oracle problem

Oracles solve one problem and create another. ethereum.org asks: how do you verify that the data came from the right source and wasn’t tampered with, and how do you make sure it’s always available? Relying on oracle operators also undermines the “trustless” promise of smart contracts.

NIST’s blockchain overview describes the same issue from a wider angle: a blockchain can record human or sensor data from the real world, but there may be no way to determine whether that data reflects real events. A sensor could malfunction, and people could record false information, intentionally or not. Its example: if crypto is used to buy a physical item, the blockchain itself can’t tell whether the item was shipped.

ethereum.org says oracles are judged on three things:

  • Correctness: they shouldn’t trigger contract actions based on invalid data; the data must be authentic and unaltered.
  • Availability: data should be there when needed, without interruption.
  • Incentive compatibility: the people supplying data should be rewarded for honesty and penalized for misbehavior.

Centralized vs decentralized oracles

Centralized oracle Decentralized oracle
Who supplies data A single entity Multiple participants that reach consensus
Strengths Efficient; works for data published directly by its owner Removes single points of failure
Weaknesses No way to confirm the data is correct; can go rogue, be hacked or switch off Decentralization is a spectrum; some networks still have an owner approving nodes

ethereum.org warns that with a centralized oracle, even reputable providers can go rogue or get hacked, and if the oracle is corrupted, contracts execute on bad data. NIST made a similar point in 2018: oracle services that convert web data for blockchains can be single points of failure for attackers.

How decentralized oracles try to get it right

ethereum.org describes several techniques decentralized oracles use to make their data more trustworthy:

  • Authenticity proofs. Cryptographic proofs that let anyone check where data came from and that it wasn’t altered, for example proofs of a secure web (TLS) session with a specific server, or attestations that the oracle software runs inside a sealed trusted execution environment.
  • Multiple sources and nodes. Several oracle nodes query off-chain data and their answers are compared, reducing the risk of passing on one bad figure.
  • Voting and staking. Nodes stake the network’s token on their answers. The majority answer wins, and nodes that deviate from it lose tokens to those who were right. ethereum.org notes the limits: staking can’t stop “freeloading”, where nodes copy others, or “lazy validation”, where they follow the majority without checking.
  • Schelling point mechanisms. Participants submit answers independently and are rewarded for being close to the consensus. In SchellingCoin, an early proposal, people who submitted values between the 25th and 75th percentile were rewarded and outliers penalized. ethereum.org says Maker’s oracles use this kind of mechanism.

Randomness is its own problem

Games and lotteries need random numbers, but a blockchain is deterministic. ethereum.org explains that early approaches used block data that miners could manipulate, and that after the move to proof of stake developers can no longer rely on that. Oracles built for this generate the random value off-chain and publish it with a cryptographic proof that it wasn’t tampered with.

A real case: when the oracle’s sources were moved

You don’t have to hack an oracle to make it report a wrong price. If an oracle reads prices from markets that are easy to move, moving those markets can be enough.

In January 2023, the CFTC charged a trader over a scheme on Mango Markets, which it called a purported decentralized digital asset exchange. According to the CFTC’s allegations:

  1. The trader used two anonymous accounts on Mango Markets to open large leveraged swap positions linked to its MNGO token.
  2. The trader then rapidly bought large amounts of MNGO on three exchanges that were the inputs for the oracle.
  3. The price reported by the oracle jumped more than 13-fold within 30 minutes, temporarily inflating the value of the trader’s positions.
  4. The trader used the inflated positions as collateral to withdraw over $110 million in digital assets from the platform.

These were the CFTC’s allegations when it filed the case. The lesson for users is the same either way: a lending or trading platform is only as sound as the prices it relies on, and an oracle that reads from a few markets that can be pushed around is a weak point.

What it means for users

  • DeFi depends on oracles. If you lend, borrow or use a stablecoin built on smart contracts, its safety depends partly on its price feeds. A bad price can trigger unfair liquidations or let attackers borrow against overvalued collateral.
  • Check the design. Well-documented protocols explain which oracles they use and how they protect against manipulation.
  • Be cautious with small, new protocols, where oracle design may be less tested.

For other DeFi risks, see crypto bridges explained, token approvals and crypto lending and earn accounts.

Frequently asked questions

Is an oracle a type of cryptocurrency?
No. An oracle is a service, usually a smart contract on the blockchain plus off-chain software, that supplies data to other contracts.
Why can't a smart contract just check a price website?
Because every node must get the same result when it runs the contract. ethereum.org explains that a price from an external website changes frequently, so different nodes could get different answers and consensus would break down. Oracles solve this by putting the data on the blockchain first.
What happens if an oracle reports a wrong price?
The smart contracts using it act on the wrong data, for example by valuing collateral incorrectly, which can trigger liquidations or let someone borrow too much. That's why ethereum.org stresses correctness, availability and incentives as the key tests of an oracle.
Can an oracle be manipulated without hacking it?
Yes, if the markets it reads from can be moved. In a 2023 case, the CFTC alleged that a trader pushed up a token's price on the exchanges feeding a DeFi platform's oracle, so the oracle reported a price more than 13 times higher. That's why oracle designers use several sources and safeguards.
Do bitcoin and Ethereum themselves use oracles?
The base networks don't need them to process ordinary transfers. Oracles matter for applications built with smart contracts, such as lending platforms, stablecoins, insurance and prediction markets.

Sources

  1. Oracles — ethereum.org (Ethereum documentation)
  2. NISTIR 8202: Blockchain Technology Overview (section 7.3, Beyond the Digital) — National Institute of Standards and Technology (NIST)
  3. CFTC Charges Avraham Eisenberg with Manipulative and Deceptive Scheme to Misappropriate Over $110 million from Mango Markets (Release 8647-23, 9 January 2023) — Commodity Futures Trading Commission
  4. Introduction to smart contracts — ethereum.org (Ethereum documentation)

First published . Spotted an error or an outdated figure? Tell us and we will check it against the source.