What is an oracle?

As the somewhat ambiguous name suggests, a blockchain oracle is a third-party information source whose only function is to provide data to the blockchain, thereby making the creation of smart contracts possible.

At its most basic level, a smart contract is just a self-executing code. The smart contract evaluates incoming data from an oracle and initiates the execution process based on the information received.

Let's take an example, say that John and John make a bet on the price of Bitcoin this Saturday. John thinks the price of Bitcoin will be $8,500 or higher, whereas John thinks it will be $8,000 or lower. So, they design a smart contract (to which both parties will send funds), and whoever predicts a price closer to the actual price wins the money.

In order for the smart contract to determine the price of Bitcoin and thus pay the winner, it must query the oracle for the price of Bitcoin this Saturday. Once the Bitcoin price data is queried, for example, the value returned is that the Bitcoin price on Saturday is $8,600, then the smart contract will execute according to its conditions and send all the funds to Zhang San.

02 Types of Oracles

Oracles provide additional functionality to smart contracts by providing a way for them to communicate outside of a decentralized blockchain network.

Blockchain oracles can take many forms, including but not limited to:

1. Software Oracle

This form of oracle usually consists of easily accessible online sources of information, such as websites and public databases. They often provide information such as: temperature readings, public transportation information, and current prices of various financial assets.

Software oracles are perhaps the most powerful type of oracles currently available because of their inherent interconnectivity with the internet. This connectivity allows software oracles to provide up-to-date information to smart contracts.

2. Hardware Oracle

This form of oracle is usually responsible for events that occur in the physical world and sends data to smart contracts. For example, in supply chain management, if an object with an RFID tag is about to arrive at a specific warehouse, this data can be sent to a smart contract and the hardware oracle system can track the goods throughout the supply chain.

3. Input Oracle

This form of oracle has the functionality of simply providing data to a smart contract. The data provided is external to the smart contract and execution begins after receiving the information. The news website providing the Bitcoin price in the example above can be classified as an input oracle.

4. Output Oracle

These oracles transmit smart contract data to external sources. In the example above, once John is determined to be the winner, the smart contract can communicate this information to the wallet provider so that its balance is automatically updated to reflect the increase in funds.

In this case, the smart contract itself can operate as an output oracle.

5. Consensus-based Oracles

The function of this oracle is to query multiple information sources and come up with a result based on their consensus. For example, the above example can also use 4 websites to query the price of Bitcoin. If the values ​​returned by all oracle sources (websites) are the same, the smart contract can be successfully executed.

03 Oracles require trust

Although the advantages of oracles are very obvious, there is a disadvantage: oracles require trust.

The data source that the oracle uses to obtain information and transmit it to the smart contract must be considered trustworthy. Using the example above, if Zhang San can somehow control the Bitcoin price website, he can easily make the Bitcoin price returned to be $8,600, thus winning the game.

So, if the data provided by the oracle to the smart contract turns out to be wrong, there is a security issue. A possible remedy for this problem is to request data from multiple oracle databases instead of a single oracle database.

For example, if one oracle returns a price of $8,600 for Bitcoin, and the other four oracles return a price of $8,000, other conditions can be programmed into the smart contract to resolve the conflict. The smart contract can choose to accept only the majority value, in which case John becomes the winner.