An introduction to Chainlink: Oracle problem and Hybrid smart contracts

crypto_astronuts
10 min readDec 31, 2021

--

Part 1: In this post, we are going to mainly read about the Oracle problem, hybrid smart contracts, and Chainlink.

What does oracle mean and what is the oracle problem?

Word “Oracle” Root

The term oracle comes from Greek mythology and means a mediator who can communicate with god and foresee the future. According to stories when people hadn’t enough information to decide based on them, they went to oracles to find an answer that could help them on the decision.

Oracle problem

The oracle problem

A blockchain is a deterministic system, and this determinism means that they (blockchains) are well-guarded and everything that happens in a smart contract happens in the blockchain and they cannot pull in data from or push data out to any external system as built-in functionality(per their design, smart contracts can only manage data on the blockchain).

We want these smart contracts to be actual digital superior agreements that people could rely on, so there is a need to be able to communicate to real-world and exchange information with the outside world (external blockchain computation) for example, financial smart contracts need market information to determine settlements, insurance smart contracts need IoT and web data to make decisions on policy payouts, trade finance contracts need trade documents and digital signatures to know when to release payments, None of this information is inherently generated within the blockchain, nor are these traditional services directly accessible. And this problem of not being able to communicate with real-world data is called the Oracle problem.

As the blockchain problem is to reach consensus, extrinsic information cannot be provided along with transaction data, since other nodes would detect information coming from an “untrusted” source. Therefore, information coming from the real world should come from a third-party univocal source, whose reliability is undisputed for all nodes.

Note: For more read about the Consensus methods

Oracles

Bridging the connection between the blockchain (on-chain) and the outside world (off-chain) requires an additional and separate piece of infrastructure known as an oracle.

Oracles are actually devices(a secure piece of middleware) that make it possible for a blockchain to talk to real-world off-chain systems (including data providers, web APIs, enterprise backends, cloud providers, IoT devices, e-signatures, payment systems, other blockchains, and more.), gather and exchange information. And as a result, smart contracts can execute based on the particular information flowing from the data feed.

Data feeds in real-world markets and web APIs are usually not deterministic like blockchains and smart contracts. Oracles act as a bridge that can digest external and non-deterministic information into a format that a blockchain can understand and execute particular conditions with.

Oracle main functions are as follows:

  • Listen — monitor the blockchain network to check for any incoming user or smart contract requests for off-chain data.
  • Extract — fetch data from one or multiple external systems such as off-chain APIs hosted on third-party web servers.
  • Format — format data retrieved from external APIs into a blockchain readable format (input) and/or making blockchain data compatible with an external API (output).
  • Validate — generate a cryptographic proof attesting to the performance of an oracle service using any combination of data signing, blockchain transaction signing, TLS signatures, Trusted Execution Environment (TEE) attestations, or zero-knowledge proofs.
  • Compute — perform some type of secure off-chain computation for the smart contract, such as calculating a median from multiple oracle submissions or generating a verifiable random number for a gaming application.
  • Broadcast — sign and broadcast a transaction on the blockchain in order to send data and any corresponding proof on-chain for consumption by the smart contract.
  • Output (optional) — send data to an external system upon the execution of a smart contract, such as relaying payment instructions to a traditional payment network or triggering actions from a cyber-physical system.

There are several forms of oracles

Given the extensive range of off-chain resources, blockchain oracles come in many shapes and sizes. Not only do hybrid smart contracts need various types of external data and computation, but they require various mechanisms for delivery and different levels of security. Generally, each type of oracle involves some combination of fetching, validating, computing upon, and delivering data to a destination.

  • Hardware Oracles
  • Software Oracles
  • Consensus Oracles
  • Inbound Oracles
  • Outbound Oracles

Hardware Oracles are sensors integrated with tangible physical objects. Primary examples would be in supply chain tracking with the use of RFID tags for feeding data like environmental conditions of products to the blockchain.

Software Oracles are the most common form that pulls data from third-party sources such as web APIs and can include real-world information like flight statuses and weather data.

Consensus Oracles represent a step towards decentralized oracles and rely on aggregating data from several oracles with proprietary methods for determining their authenticity and accuracy.

Inbound Oracles reflect “if this happens then do that” scenarios associated with software oracles such as “if this price is met by an asset, then trigger a sell.

Outbound Oracles allow smart contracts to send data to sources outside of the blockchain network they exist on and are also software oracles.

Decentralized VS Centralized oracles

Centralized oracles

All smart contracts need some sort of conditional test. A question must be answered to complete the transaction. In a centralized approach, we rely on a centralized system to serve as the Oracle -broadcasting whether or not the conditions were met and triggering the appropriate response.

So these centralized Oracles answer questions like:
Did the required sum get raised to release the funds (crowdfunding)?
Have the terms of the bounty award been met?
Has the prediction come true?
Did the Red Sox win?
Who won this round of match?
And so on and so on. Let’s have an analogy for better understanding

Let’s say we wanted to build a decentralized crowdfunding app using Bitcoin. We only want the person raising the funds to get the sum if a certain minimal threshold is met. If you raise $2,000 or more you get it all, but otherwise, all the payments are returned.

So the oracle first needs to provide trustworthy data!
second, the data need to be accurate!
And above all, we need to trust the oracle because it is a centralized system! so the whole concept of minimal trust is thrown away and the use of smart contracts is nothing more than a twist in the usage of technology! A decentralized system that takes its answers from a centralized point!

A decentralized oracle network and hybrid smart contracts

Smart contracts are decentralized applications and in order for them to stay in that way, they need their data and external computation from a decentralized manner as well. Your on-chain logic will stay decentralized on the blockchain but you need also your off-chain data and external computation decentralized as well. Combining this on-chain logic and off-chain data and computation are called hybrid smart contracts and a large number of Defi applications are these hybrid smart contracts.

Event this (decentralized) oracle’s trustworthiness is somehow objective since, even if the oracle sets the price autonomously by merely browsing exchange prices online, any agent can verify if the exchange rate is correct or not. Different is the case where smart contracts operate in a situation in which oracles provide information that is hardly verifiable by the agents (centralized oracles). In those environments, the trustworthiness of oracles is fundamental. If the contracts involve highly valuable agreements, the oracle’s chance to be compromised to benefit a particular party increases dramatically. When all the parties cannot verify the oracle’s data, and contract value increases, the oracle itself becomes a “problem”.

Types of Blockchain Oracles

Given the extensive range of off-chain resources, blockchain oracles come in many shapes and sizes. Not only do hybrid smart contracts need various types of external data and computation, but they require various mechanisms for delivery and different levels of security. Generally, each type of oracle involves some combination of fetching, validating, computing upon, and delivering data to a destination.

Input Oracles

The most widely recognized type of oracle today is known as an “input oracle,” which fetches data from the real-world (off-chain) and delivers it onto a blockchain network for smart contract consumption. These types of oracles are used to power Chainlink Price Feeds, providing DeFi smart contracts with on-chain access to financial market data.

Output Oracles

The opposite of input oracles are“output oracles,” which allow smart contracts to send commands to off-chain systems that trigger them to execute certain actions. This can include informing a banking network to make a payment, telling a storage provider to store the supplied data, or pinging an IoT system to unlock a car door once the on-chain rental payment is made.

Cross-Chain Oracles

Another type of oracles are cross-chain oracles that can read and write information between different blockchains. Cross-chain oracles enable interoperability for moving both data and assets between blockchains, such as using data on one blockchain to trigger an action on another or bridging assets cross-chain so they can be used outside the native blockchain they were issued on.

Compute-Enabled Oracles

A new type of oracle becoming more widely used by smart contract applications are “compute-enabled oracles,” which use secure off-chain computation to provide decentralized services that are impractical to do on-chain due to technical, legal, or financial constraints. This can include using keepers to automate the running of smart contracts when predefined events take place, computing zero-knowledge proof to generate data privacy, or running a verifiable random number to provide a tamper-proof and provably fair source of randomness to smart contracts.

Blockchain Oracle Use Cases

Decentralized Finance (DeFi)

A large portion of the DeFi ecosystem requires oracles to access financial data about assets and markets. For example, decentralized money markets use price oracles to determine users’ borrowing capacity and check if users’ positions are undercollateralized and subject to liquidation. Similarly, synthetic asset platforms use price oracles to peg the value of tokens to real-world assets, and automated market makers (AMMs) use price oracles to help concentrate liquidity at the current market price to improve capital efficiency.

Dynamic NFTs and Gaming

Oracles enable non-financial use cases for smart contracts too such as dynamic NFTs— Non-Fungible Tokens that can change in appearance, value, or distribution based on external events like the time of day or the weather. Additionally, compute oracles are used to generate verifiable randomness that projects then use to assign randomized traits to NFTs or to select random lucky winners in high-demand NFT drops. On-chain gaming applications also use verifiable randomness to create more engaging and unpredictable gameplay experiences like the appearance of random loot boxes or randomized matchmaking during a tournament.

Insurance

Insurance smart contracts use input oracles to verify the occurrence of insurable events during claims processing, opening up access to physical sensors, web APIs, satellite imagery, and legal data. Output oracles can also provide insurance smart contracts with a way to make payouts on claims using other blockchains or traditional payment networks.

Enterprise

Cross-chain oracles offer enterprises a secure blockchain middleware that allows them to connect their backend systems to any blockchain network. In doing so, enterprise systems can read/write to any blockchain and perform complex logic on how to deploy assets and data across chains and with counterparties using the same oracle network. The result is institutions being able to quickly join blockchains in high demand by their counterparties and swiftly create support for smart contract services wanted by their users without having to spend time and development resources integrating with each individual blockchain.

Sustainability

Hybrid smart contracts are advancing environmental sustainability by creating better incentives to partake in green practices through advanced verification techniques around the true impact of green initiatives. Oracles are a critical tool for supplying smart contracts with environmental data from sensor readings, satellite imagery, and advanced ML computation, which then allow smart contracts to dispense rewards to people practicing reforestation or engaging in conscious consumption. Oracles are also supporting many new forms of carbon credits to offset the impact of climate change.

--

--

crypto_astronuts

This page is only intended to be used as a knowledge system for myself and others who enjoy reading it.