How DeFi Oracles Work: A Guide to Price Feeds and Data Infrastructure
What Are DeFi Oracles?
Oracles are the infrastructure that connects blockchains to the outside world. In the context of DeFi, oracles primarily provide price data, letting smart contracts know what an asset is worth so they can calculate collateralisation ratios, execute liquidations, settle derivatives, and perform countless other operations that depend on real-world market prices.
Without oracles, DeFi as it exists today would be impossible: lending protocols could not determine when positions are undercollateralised, derivatives could not settle, and price-dependent mechanics would have no reliable input.
This guide explains how oracles work, the main design approaches in use, why oracles are a critical piece of DeFi infrastructure, and the risks they introduce into the systems that depend on them.
The Oracle Problem
Blockchains are deliberately isolated systems. Smart contracts can only directly access data that exists on their own blockchain, they cannot natively check the price of ETH on Coinbase, the outcome of a sports match, or the temperature in London. This isolation is essential for blockchain security (nodes must be able to independently verify all state transitions) but creates a challenge for applications that need external information.
The oracle problem is the challenge of bringing external data on-chain in a way that preserves the security properties of the blockchain itself. A smart contract that depends on a single external data source inherits that source's trust assumptions. If the source is wrong, manipulated, or offline, the smart contract behaves incorrectly. For billions of dollars of DeFi value dependent on accurate price feeds, getting this right is critical.
How Price Oracles Work
The most common type of DeFi oracle is a price oracle, which reports the current price of an asset to on-chain smart contracts. Price oracles typically work through a data aggregation process: off-chain services collect prices from multiple trading venues (centralised exchanges like Coinbase and Binance, plus decentralised venues), aggregate them using a specific methodology (usually a volume-weighted or median calculation), and push the result on-chain at regular intervals or when price movements exceed predefined thresholds.
The on-chain component is typically a smart contract that stores the latest reported price and serves it to querying applications. DeFi protocols read from this contract when they need pricing information. The off-chain aggregation happens through a network of node operators who each submit signed price reports; the oracle contract aggregates these into a final value and rejects submissions that deviate too far from the consensus.
The frequency of price updates is a critical design parameter. More frequent updates provide fresher data but cost more in gas fees (since each update is an on-chain transaction). Deviation-based updates (where the oracle only updates when the price has moved beyond a threshold) reduce gas costs during stable periods but can leave stale prices during rapid market movements.
Major Oracle Providers
Chainlink is the dominant oracle provider in DeFi, with its price feeds securing the majority of decentralised lending, stablecoin, and derivatives protocols. Chainlink operates a decentralised network of node operators who are financially incentivised to report accurate data, with cryptoeconomic penalties for malicious or faulty behaviour. Chainlink's extensive integration across DeFi makes it the default choice for many new protocols.
Pyth Network is a newer oracle solution that has gained significant traction, particularly on Solana and other non-EVM chains. Pyth sources data directly from market makers, exchanges, and trading firms, essentially the entities that create the prices in the first place, and uses a pull-based model where users pay for fresh price updates when they need them. This design differs from Chainlink's push-based updates and is particularly well-suited for high-frequency applications.
RedStone takes a modular approach, offering both push and pull models and serving a growing ecosystem of protocols looking for alternatives to the established providers. Other oracle solutions include API3 (which uses first-party oracles where data providers run their own nodes), UMA (optimistic oracles designed for disputable data), and Tellor (a proof-of-work based oracle network). Each makes different trade-offs between cost, speed, security, and data sources.
Pull vs Push Oracles
Push oracles update on-chain prices at regular intervals or when deviation thresholds are exceeded, regardless of whether any application currently needs the data. This is simpler for applications (the price is always available to read) but can be expensive in terms of gas fees and may provide stale data during periods when updates haven't been triggered.
Pull oracles (also called on-demand oracles) only update prices when an application requests them, usually as part of the transaction that consumes the price. The user pays for the price update, but in return gets the most recent available price. This model has become increasingly popular for high-value DeFi applications where pricing accuracy is critical and users are willing to pay for freshness.
Many modern protocols use hybrid approaches, combining multiple oracle designs for different use cases. Liquidations might use pull oracles for maximum freshness, while routine operations use push oracles for gas efficiency.
Non-Price Oracles
While price oracles dominate DeFi, oracles serve many other purposes. Event oracles report on real-world outcomes, sports results, election outcomes, weather events, which are used by prediction markets and certain derivatives. Randomness oracles (like Chainlink VRF) provide verifiable random numbers for gaming, NFT minting, and lottery-style applications. Proof-of-reserves oracles verify that custodians actually hold the assets they claim to hold, relevant for wrapped assets and regulated stablecoins.
Cross-chain oracles allow smart contracts on one chain to read data from another chain, enabling applications that span multiple ecosystems. These are essentially specialised forms of cross-chain messaging that prioritise data integrity over general message passing. Examples include Chainlink CCIP (for cross-chain data and messaging) and LayerZero's oracle system.
Weather data, flight information, and other real-world data feeds are increasingly available through oracle networks, enabling smart contract applications in insurance, supply chain, and traditional finance integration. These use cases are less developed than price oracles but represent important growth areas for the broader oracle industry.
Oracle Manipulation Attacks
Because oracles feed critical data to DeFi protocols, they are a frequent attack vector. The most common attack pattern is price manipulation, an attacker temporarily distorts the price reported by an oracle to exploit a DeFi protocol that depends on that price. Flash loan attacks have made this pattern particularly devastating: an attacker borrows a massive amount of capital via flash loan, uses it to manipulate prices on a specific DEX, reads the manipulated price through the oracle, and exploits the depending protocol.
Several infamous DeFi exploits have followed this pattern, draining tens or hundreds of millions of dollars from vulnerable protocols. The defence is to use oracles that aggregate across multiple venues (making single-venue manipulation ineffective), use time-weighted average prices (TWAPs) that smooth out short-term manipulation, and avoid using spot prices from thin liquidity pools as the sole pricing source.
Protocols building on oracles must consider what price sources the oracle uses, how resistant those sources are to manipulation, and what happens if the oracle reports an incorrect value. Defence-in-depth strategies (using multiple oracle providers, implementing sanity checks on reported values, building in circuit breakers for extreme price movements) reduce but do not eliminate oracle-related risk.
Oracle Risks in DeFi
For users of DeFi protocols, oracle risk is often invisible but important to understand. A lending protocol that uses a compromised oracle could liquidate positions incorrectly, allow undercollateralised borrows, or become insolvent. A derivatives protocol with bad oracles could settle contracts at incorrect prices. Users ultimately bear the consequences of oracle failures in the protocols they use.
Concentration risk is a relevant concern. If most DeFi protocols depend on a single oracle provider, a systemic failure or attack on that provider could cascade through the ecosystem. The oracle market's gradual diversification (with Pyth, RedStone, and others gaining share from Chainlink) is reducing this concentration but has not eliminated it.
Data source risk affects all oracles. Even a perfectly designed oracle network reports only what its data sources report. If all data sources are manipulated (for example, through a coordinated attack on multiple exchanges), the oracle will faithfully report the manipulated prices. Oracle design can make this more difficult but cannot prevent it entirely.
Evaluating Oracle Quality
Users evaluating the safety of a DeFi protocol should consider what oracles it uses and how. Key questions include:
Does the protocol rely on a single oracle or aggregate across multiple?
What data sources does the oracle use, and how resistant are those sources to manipulation?
Does the protocol use spot prices (vulnerable to flash loan attacks) or TWAPs (more resistant)?
What fallback mechanisms exist if the oracle becomes unavailable?
Well-designed DeFi protocols are typically transparent about their oracle choices and publish documentation explaining their design decisions. Protocols that obscure their oracle design or rely on single, unaudited data sources should be approached with additional caution.
Exploring Oracle-Powered DeFi via Portals.fi
Portals.fi is a DeFi aggregation platform that allows users to interact with various DeFi protocols through a unified interface. Users exploring DeFi applications that depend on oracle infrastructure can access different protocols and opportunities from a single access point.
For more information about how Portals.fi works, visit portals.fi.
This article is for informational purposes only and does not constitute financial advice. DeFi protocols carry inherent risks including smart contract vulnerabilities and oracle failures. Oracle manipulation has been a factor in numerous DeFi exploits. Always conduct your own research before interacting with any protocol. For our full disclaimer, please visit here.
Portals.fi Blog Newsletter
Join the newsletter to receive the latest updates in your inbox.