How do Oracles work?

Jul 20, 2022 2 min read
How do Oracles work?

Establishing a reliable source of truth within a trustless, decentralised network is a tricky task. Blockchains are closed systems and smart contract execution is automatic, so secure and accurate pricing data for such a system is extremely important.

Many different asset classes run on blockchains, whether natively (e.g. cryptocurrencies and NFTs) or as tokenised real-world assets such as stocks or commodities. Multiple models exist for the way that DeFi protocols price these assets, and are known collectively as Oracles.

Asset prices in free markets are determined by supply and demand, which, in the short term, are reflected in trading activity. For on-chain trading, relative prices of assets on exchanges are a direct result of the trades that run through them. Any price differences between exchanges are quickly smoothed out by arbitrageurs who can make a profit whilst stabilising prices. In the same way, price discrepancies between on- and off-chain (CEX) markets can be arbitraged.

However, smart contracts cannot simply rely on current prices in a given liquidity pool to price the assets they control, as this can be easily manipulated, often using flash loans. Despite constant innovation in internal pricing mechanisms, the complex interdependencies between protocols often creates vulnerabilities ripe for exploitation by hackers. Therefore, robust and reliable oracles are needed.

Typically, oracles are responsible for bringing aggregated price data from multiple sources (both CEX and DEX trading pairs) on-chain. Smart contracts are then able to query these price feeds and use the resulting data, for example to calculate collateral value for a loan.

Various solutions exist, ranging from centralised oracles, which require trust and present a potential single point of failure, to more decentralised versions such as Chainlink.

Decentralised oracles are in themselves a network of nodes, conceptually similar to a blockchain. Each node regularly reports data points and consensus must be reached within a given threshold in order for the output to be valid. This leverages the 'wisdom of the crowd' to maximise the robustness and reliability of information used by smart contracts, in a trustless way.

Decentralisation, by design, ensures there can be no single source of truth, and as such no single point of failure. While being one of the core aspects of blockchain security, this also leads to the problems with sourcing off-chain data in the on-chain environment.

Oracle design is of utmost importance to DeFi, as any application is only as secure as the information it uses, no matter the security of the underlying blockchain which it runs upon.

Great! Next, complete checkout for full access to Stake DAO Academy.
Welcome back! You've successfully signed in.
You've successfully subscribed to Stake DAO Academy.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.