What is a blockchain oracle, and how does it work?
What are blockchain oracles?
Blockchain oracles are entities that connect blockchains to external systems, allowing smart contracts to execute depending on real-world inputs and outputs. Oracles give the Web 3.0 ecosystem a method to connect to existing legacy systems, data sources and advanced calculations.
Decentralized oracle networks (DONs) enable the implementation of hybrid smart contracts, in which off-chain infrastructure and on-chain code are coupled to provide complex decentralized applications (DApps) that react to real-world events and interact with traditional systems.
Let's say Alice and Bob wish to place a wager on the outcome of a horse race. The $80 total is held in escrow by a smart contract, with Alice betting $50 on team X and Bob betting $30 on team Y. How does the smart contract know whether to give the money to Alice or Bob when the game is over? The solution is that an oracle mechanism is required to retrieve accurate match outcomes off-chain and securely and reliably deliver them to the blockchain.
Because of the distributed ledger aspect of the blockchain, each node in the network must obtain the same result given the same input. For example, if a node tries to validate another node's transaction, it will get a different result. This architecture was created to be deterministic.
Consensus is the technique for agreeing on a data value in blockchain, and determinism is required for nodes to reach a consensus. Some of them may be familiar to you, such as proof-of-work (PoW) with Nakamoto consensus and proof-of-stake (PoS) with Byzantine consensus. One of the main factors that make blockchain work in the first place is consensus.
However, the blockchain world needs to connect with the actual world. To have DeFi, we need to get the price of Ether (ETH) and other cryptocurrencies into a contract. We require meteorological data to provide decentralized, trustless insurance. To use blockchain for one of its most essential uses, smart contracts, we need data. So, given this constraint, how do we connect the worlds?
This guide aims to explain what blockchain oracles do, the blockchain oracle problem and introduce various blockchain oracle projects.
Blockchain oracle problem
The blockchain oracle dilemma highlights a key restriction of smart contracts, i.e., they cannot connect with data and systems outside of their native blockchain context in any way. External resources are referred to as "off-chain," while data currently recorded on the blockchain is referred to as "on-chain."
Blockchains achieve their most beneficial qualities by being purposefully separated from external systems, such as the prevention of double-spending assaults, strong consensus on the authenticity of user transactions and the reduction of network downtime. To securely interact with off-chain systems from a blockchain and to bridge the gap between two environments, you'll need an extra piece of infrastructure called an "oracle."
Because the great majority of smart contract use cases, such as DeFi, require knowledge of real-world data and events occurring off-chain, solving the oracle problem is critical. As a result, oracles broaden the types of digital contracts that blockchains may enable by providing a universal gateway to off-chain resources while maintaining the blockchain's key security qualities.
Asset prices for finance, identity verification for government, randomness for gaming, weather information for insurance are just a few of the industries that profit from integrating oracles with smart contracts.
What do blockchain oracles do?
Any device or entity that connects a deterministic blockchain to off-chain data is referred to as a blockchain oracle. Every data input is routed through an external transaction in these oracles.
However, we can be certain that the blockchain contains all of the information needed to authenticate itself in this way. Oracles are regarded as blockchain middleware because they serve as a link between the two realms.
Chainlink is the industry standard for decentralized oracles because it overcomes both access to outside data and the centralization of smart contract problems. So, what are Chainlink oracles?
Chainlink is a decentralized oracle network that feeds real-world data to blockchain smart contracts. LINK tokens are digital asset tokens used to pay for network services.
On the other hand, a single centralized oracle causes the particular problem that a decentralized, blockchain-secured smart contract is supposed to solve: a single point of failure. So how would you know whether your data is accurate if the oracle is faulty or compromised? What good is a safe, dependable, smart contract on the blockchain if the data it relies on is suspect?
This problem is solved by Chainlink (a decentralized network of nodes), which uses oracles to provide data and information from off-blockchain sources to on-blockchain smart contracts. This technique, together with other secure technology, removes the reliability difficulties that could arise if only a single centralized source is used.
Chainlink is blockchain agnostic as it connects all major public and private blockchain environments using a single framework, which provides a typical abstraction level for cross-network communication.
Therefore, you can refer to decentralized data on-chain that has already been extracted from the real world and collected using services like Chainlink, which is similar to a public library, except for decentralized data. You can even create your modular oracle networks to obtain whatever specific information you require. Additionally, you can perform off-chain computations and transfer data to the actual world.
Other top blockchain oracles are Witnet, Paralink, Provable and Dos.Network. These services provide oracles made up of a smart contract and some off-chain components that can query application user interfaces (APIs) and then send transactions to update the data in the smart contract regularly.
Types of blockchain oracles
Oracles give a blockchain or smart contract to communicate with external data. Instead, they serve as an interface to the world outside the blockchain. Outside data must be conveyed to the closed blockchain system in many circumstances, especially when smart contracts are linked to real-world events. External data is queried, verified and authenticated by crypto oracles, which then relay it to the closed system. After that, the validated data would be utilized to validate a smart contract.
Hardware and software oracles
Although this isn't always the case, most crypto oracles analyze digital data. Hardware oracles deliver data from the physical world, while software oracles deliver data from digital sources such as websites, servers or databases. In addition, information from camera motion sensors and radio frequency identification (RFID) sensors can be delivered and relayed by hardware oracles. Real-time data, such as exchange rates, price variations and travel information, can be delivered through software oracles.
Inbound and outbound oracles
Oracles establish a two-way communication channel with blockchains, sending data in and out. While outbound oracles can deliver blockchain data to the outside world, inbound oracles are more likely to deliver off-chain — or real-world — data to the blockchain. In addition, the imported data can represent nearly anything from asset price swings to meteorological conditions to verification of completed payments.
For inbound oracles, a common programmable scenario may be: If an asset reaches a specific price, put a buy order. On the other hand, outbound oracles alert the outside world of an event that occurred on-chain.
Centralized and decentralized oracles
A centralized oracle is managed by a single entity and serves as the smart contract's sole data source. Using only one source of information can be dangerous because the contract's effectiveness is solely dependent on the entity in charge of the oracle.
A bad actor's hostile intervention will also directly affect the smart contract. The fundamental issue with centralized oracles is that they have a single point of failure, making contracts more vulnerable to attacks and weaknesses.
Some of the goals of decentralized oracles are similar to those of public blockchains, such as minimizing counterparty risk. For example, they make the information delivered to smart contracts more reliable by not depending on a single source of truth.
The smart contract consults several oracles to assess the data's validity and accuracy; this is why decentralized oracles are also known as consensus oracles. Other blockchains can use decentralized oracle services provided by some blockchain oracle projects.
Individuals with specialized knowledge in a specific sector can sometimes act as oracles. They may gather information from various sources, check its legitimacy and convert it into smart contracts. Because human oracles can use cryptography to verify their identity, the chances of a fraudster impersonating them and giving tampered data are small.
These oracles are made to work with smart contracts that are single. If the developer intends to deploy numerous smart contracts, it will be necessary to build various contract-specific oracles.
Contract-specific oracles aren't worth the time and work it takes to keep them up to date. Instead, they're inconvenient and should only be utilized in specific situations.
We've just talked about oracles in terms of seeking and supplying data so far (also known as data carrier oracles or automated oracles). However, oracles can be used to conduct any arbitrary "off-chain" compute solution, which is particularly beneficial given Ethereum's inherent block gas constraint and very high computation cost.
Computation oracles, rather than just relaying the results of a query, can be used to perform computation on a set of inputs and return a calculated result that would otherwise be impossible to calculate on-chain. For example, to estimate the yield of a bond contract, a computation oracle could be used to perform a computationally complex regression calculation.
Oracle design patterns
By definition, all oracles discussed perform a few key roles. These capabilities include the ability to:
- Collect data from a non-blockchain source.
- Using a signed message, send the data on-chain.
- Make the data accessible by storing it in the storage of a smart contract.
Once data is stored in a smart contract's storage, other automated agreements can access it via message calls that invoke the oracle's smart contract's "retrieve" function. It can also be “called” directly by Ethereum nodes or network-enabled clients by "looking into" the oracle's storage.
The three main ways to set up an oracle can be categorized as follows:
Immediate-read oracles provide information that is only required for a quick decision, such as "is this student above 25?" Those who want to query this type of data usually do so on a "just-in-time" basis, which means that the lookup is done only when the information is needed.
Examples are dial codes, academic certificates, institutional memberships, airport identification and other oracles.
An oracle that effectively provides a broadcast service for data that is likely to change (perhaps both regularly and frequently) is either polled by a smart contract on-chain or watched for updates by an off-chain daemon. Weather data, price feeds, economics or social statistics and traffic data are just a few examples of the publish-subscribe set-up.
The most challenging category is request-response: This is where the data space is too large to be stored in a smart contract, and users are only anticipated to use a small portion of the whole information at a time. It's also a viable business strategy for data providers.
In practice, an oracle like this may be implemented as a system of on-chain smart contracts and off-chain infrastructure for monitoring requests and retrieving and returning data. A data request from a decentralized application is often an asynchronous procedure with multiple steps as follows:
Applications of oracles in DApps
Oracle is a mechanism for bridging the gap between the off-chain world and smart contracts used by many DApps on the market. The following are some instances of data that oracles may provide:
Time and interval data are used for event triggers based on exact time measurements.
Data from the capital markets, such as pricing bundles of tokenized assets and securities.
Benchmark reference data, such as interest rates, included in smart financial derivatives.
Weather data, for example, is used to calculate insurance premiums based on weather forecasts.
Geolocation data, such as that used in supply chain tracking.
For insurance contracts, damage verification is required.
Sporting events are used to resolve prediction markets and fantasy sports contracts.
Flight statistics, such as those used by groups and clubs to pool flight tickets.
Beware of the security concerns
Oracles play a critical role in smart contract execution by bringing external data into the equation. On the other hand, oracles pose a huge danger since, if they are trusted sources and can be hacked, they can jeopardize the execution of the smart contracts they feed.
In general, while considering the employment of an oracle, the trust model must be carefully considered. You may be sacrificing the smart contract's security by exposing it to potentially incorrect inputs if we presume the oracle can be trusted. However, if the security assumptions are carefully considered, oracles can be valuable.
Some of these concerns can be addressed via decentralized oracles, providing Ethereum smart contracts with external data that is not trusted. You must carefully select it before you can begin exploring the oracles' bridge between Ethereum and the real world.