Bridging the Gap Between On-Chain and Off-Chain Worlds

Oracles: Bridging the Gap Between On-Chain and Off-Chain Worlds

1. Introduction

Oracles are essential in the blockchain ecosystem, serving as the bridge between on-chain and off-chain worlds. Without oracles, blockchain applications would be isolated, unable to interact with real-world data. Their importance continues to grow with the rise of decentralized finance (DeFi), NFTs, insurance, and beyond, enabling smart contracts to become truly functional and adaptable to real-world situations.

2. What Are Oracles?

An oracle is a service that provides external data to a blockchain. Since blockchain networks are deterministic, meaning that given the same input they always produce the same output. This predictability ensures consensus among all nodes in the network, but it also means that blockchains cannot autonomously access or validate external data, oracles act as trusted intermediaries. They allow smart contracts to consume information like financial data, weather conditions, and much more.

3. Types of Oracles

There are three dimensions :

  • Centralzed vs decentralized
  • Inbound vs outbound
  • Contract specific vs universal

Centralzed vs decentralized

Centralized Oracles

These rely on a single data source or provider, which can lead to vulnerabilities like a single point of failure. Centralized oracles often rely on off-chain servers that cannot directly communicate with the blockchain. For example, a Solidity smart contract cannot natively call an API directly due to the deterministic nature of the Ethereum Virtual Machine (EVM). Instead, centralized oracle services like Provable are used. Provable is a blockchain oracle service that allows smart contracts to fetch data from external APIs in a secure manner. It acts as a bridge between blockchains and the off-chain world, enabling smart contracts to interact with external information sources. Below is an example of how a centralized oracle can be used in Solidity to call an API:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "provableAPI.sol";

contract ExampleOracle is usingProvable {
    string public data;
    event LogNewProvableQuery(string description);
    event LogNewData(string data);

    function updateData() public payable {
        require(msg.value >= provable_getPrice("URL"), "Not enough ETH for query");
        emit LogNewProvableQuery("Provable query was sent, waiting for the answer...");
        provable_query("URL", "json(https://api.example.com/data).result");
    }

    function __callback(bytes32 _myid, string memory _result) public override {
        require(msg.sender == provable_cbAddress());
        data = _result;
        emit LogNewData(data);
    }
}

In this example, the provable_query function is used to call an external API, and the result is handled in the __callback function. However, this introduces a centralized dependency on the Provable service, which makes it less secure than decentralized alternatives. While simpler, they are less secure compared to their decentralized counterparts.

Decentralized Oracles

Chainlink, a popular decentralized oracle, works by using a decentralized network of nodes to provide data to smart contracts. When a smart contract needs off-chain data, it creates a request that Chainlink nodes compete to fulfill. These nodes retrieve data from multiple sources, aggregate the responses, and deliver the result back to the smart contract. Chainlink also uses staking mechanisms to incentivize honest behavior and penalize malicious actors, ensuring high-quality data feeds. Decentralized oracles like Chainlink aggregate data from multiple sources, ensuring redundancy and reducing the risks associated with relying on one source. For example, Chainlink aggregates data from multiple price feeds to ensure accuracy and security in DeFi applications, minimizing the risk of a single point of failure. Popular decentralized oracles include Chainlink and Band Protocol.

Inbound vs outbound

Inbound

They deliver off-chain data to a blockchain. Inbound oracles play a crucial role in enhancing the utility of smart contracts by providing real-world data that blockchain applications need to function effectively. For example, an inbound oracle can provide up-to-date financial market prices to a DeFi application or supply weather data to a parametric insurance contract. By acting as a bridge to bring external information onto the blockchain, inbound oracles ensure that smart contracts can execute based on conditions from the physical world, thus making them far more dynamic and relevant for real-world applications.

Outbound

They deliver blockchain datas to external systems, triggering real world events based on-chains activities. It doesn’t have to be confused with an RPC (Remote Procedure Call) node. Instead, an RPC node is a fundamental component of a blockchain network that provides an interface for applications to interact with the blockchain. It allows reading and writing data to the blockchain, such as querying transaction information or submitting new transactions.

In contrast, an outbound oracle is an artifact that sends information from the blockchain to external systems, triggering actions outside the blockchain based on on-chain events. For example, an outbound oracle might notify an external IoT system to turn off a device if a certain condition on the blockchain is met. RPC nodes, however, do not handle this off-chain action capability—they are primarily about accessing blockchain data and submitting transactions.

Contract specific vs universal

Contract-Specific

Contract-Specific Oracles serve specific smart contracts and have bespoke data requirements. These oracles are designed to fulfill the unique data needs of a particular smart contract. For example, a custom-built oracle might be created specifically to provide supply chain information for a particular logistics dApp. The data used is often highly specific and not applicable beyond the particular use case it was designed for. This type of oracle is typically tightly integrated with the contract logic, ensuring that the exact data required is delivered.

Universal

Universal Oracles like Chainlink serve a variety of applications across different blockchain ecosystems. Universal oracles are built to be versatile and provide a broad range of data feeds that can be utilized by multiple smart contracts across different blockchains. For instance, Chainlink can provide price feeds for DeFi applications, weather data for insurance contracts, or any other off-chain information that many contracts might need. These oracles are scalable, allowing developers to use pre-existing, well-audited data feeds instead of building bespoke oracle solutions from scratch.

4. How Oracles Work

Mainly four step :

  • Data Request: A smart contract initiates a request for off-chain data.
  • Oracle Selection and Data Retrieval: An oracle, either centralized or decentralized, retrieves the data from a relevant off-chain source.
  • Data Verification: In decentralized systems, multiple data providers ensure the accuracy of the data through consensus mechanisms.
  • Data Delivery: The verified data is fed back into the smart contract, which then executes based on the received data.

Example Use Case: In a DeFi lending protocol, an oracle provides up-to-date price feeds for collateral assets, ensuring that loans remain adequately backed and liquidation events are triggered accurately when thresholds are breached.

Centralized oracle

Decentralized oracle

5. Key Players in the Oracle Space

Oracle NetworkDescriptionKey FeaturesLimitations
ChainlinkThe most well-known decentralized oracle network, used widely across different blockchain ecosystems.Decentralized, node competition, staking mechanisms for data reliability.Chainlink depends on its node operators; if nodes collude or provide incorrect data, it may affect reliability. High gas fees can also make it costly.
Band ProtocolA decentralized oracle platform focusing on cross-chain compatibility, providing data feeds across multiple networks.Cross-chain compatibility, dPoS consensus, fast data availability.Relatively smaller network compared to Chainlink, which may result in less security through limited node diversity.
Pyth NetworkSpecializes in providing low-latency data, particularly for trading and finance on Solana.Low-latency data aggregation, Solana-specific integration.Limited mainly to the Solana ecosystem, which restricts its use for multi-chain applications.

Other Players: Tellor, API3, and Switchboard are other oracle solutions providing various forms of data integrity and availability.

6. Challenges and Risks

Data Integrity and Trustworthiness

The integrity of the data being fed by oracles is crucial. For example, if a centralized weather oracle is compromised, an insurance smart contract relying on it might issue payouts incorrectly. Ensuring trustworthiness involves verifying data sources and using multiple nodes to aggregate results.

Centralization Risks

Single-source oracles can undermine the decentralization of blockchain applications by introducing a single point of failure. For instance, a centralized price feed oracle could be targeted by attackers to manipulate asset prices on DeFi platforms, leading to significant financial loss. Centralized oracles are particularly vulnerable to outages or attacks since all data originates from a single provider. This centralization poses a risk that an entire application could fail or be manipulated if the data source becomes unavailable or compromised.

Security Vulnerabilities

Oracles can be targets for attacks like data manipulation, as seen in oracle manipulation attacks where attackers target vulnerabilities to profit unfairly. For example, in 2020, the bZx DeFi protocol experienced an oracle manipulation attack that led to the wrongful liquidation of loans. These attacks involve feeding inaccurate data to manipulate smart contract outcomes, such as in DeFi lending and borrowing protocols. A manipulated price feed could result in a wrongful liquidation event, causing significant losses.

Data Reliability

The reliability of an oracle is only as strong as the data source it uses. For example, during the 2021 crypto market volatility, some price feed oracles delivered outdated data, leading to discrepancies in DeFi contracts. If an oracle feeds incorrect or outdated data, the associated smart contract may fail or lead to unintended consequences. In decentralized systems, using multiple data sources can mitigate this risk, but it also adds complexity and cost. Ensuring high-quality data through robust aggregation mechanisms is essential for reliable oracle services.

To protect against the outdated data uniswap introduce the TWAP protocol

Economic Costs

Using a decentralized oracle service can be costly due to network fees and the need for multi-sourced data verification. For example, using Chainlink on Ethereum can involve high gas fees, making operations expensive for smaller DeFi projects. The complexity of aggregating data from multiple providers, validating it, and delivering it to the blockchain involves computational and financial resources. High gas fees, especially on networks like Ethereum, can significantly add to the operational costs, making decentralized oracle solutions more expensive compared to centralized ones.

7. Oracle’s economy

As we can see oracles play a crucial role in ensuring that blockchain applications are functional and reliable, but what incentivizes participants to join the oracle network and provide accurate data? Let’s explore the economic model that motivates oracle operators.

Incentives for Oracle Nodes:

  • Data Fees Oracle nodes, like those in Chainlink’s network, are paid fees for the data they provide. Smart contracts requesting data are required to pay nodes, typically in the form of the native cryptocurrency. For Chainlink, nodes are paid in LINK tokens. This creates a direct economic incentive for nodes to participate actively and provide reliable data.

  • Staking Rewards: Decentralized oracles often require nodes to stake a certain amount of tokens (e.g., LINK in Chainlink) as collateral. This stake serves as an assurance mechanism—if the node provides faulty or incorrect data, it can lose a portion of its stake. Conversely, honest behavior can lead to rewards, thus incentivizing nodes to remain trustworthy.

  • Reputation Systems: In many decentralized oracle networks, nodes build reputations over time. Nodes with better reputations are more likely to be selected for future data requests and thus earn more fees. The combination of staking and reputation means that providing accurate and timely data directly impacts a node’s profitability.

If you use Link, you should use a blockchain that have a *RC20 version of the link token (binance, eth, polygon….), your smartcontract need to have link within and you transfer those link on the chain you are.

Why Participants Accept the Game

  • Economic Gain: The primary motivation for participating in oracle networks is economic. For example, Chainlink nodes are compensated through the fees collected from smart contracts needing data, and these fees can be substantial, especially in high-demand environments like DeFi. The more accurate and reliable a node is, the more requests it will receive, leading to higher earnings.
  • Network Growth and Token Appreciation: Participants are also incentivized to accept the game because they believe in the future of the ecosystem. By being early adopters or consistent participants, they not only earn rewards but also hold tokens that could appreciate in value as the oracle network grows. For example, an increase in the use of Chainlink services can lead to an appreciation in the value of LINK tokens, directly benefiting nodes holding these tokens.

8. Ecosystem on the main oracle blockchain

Please find the ecosystem as in november 2024

pyth

Band

9. Conclusion

Oracles are a key piece of the puzzle for integrating blockchain technology with real-world applications. By providing reliable, verifiable data, oracles make smart contracts capable of interacting with the off-chain environment, thus extending the utility of blockchain networks far beyond isolated ecosystems.

The current landscape of oracles features both centralized and decentralized models, each with its own strengths and challenges. Decentralized oracles, like Chainlink and Band Protocol, offer a high level of security and trust by relying on multiple nodes and data sources. They mitigate the risks of centralization and ensure data integrity through competitive, trustless mechanisms. On the other hand, centralized oracles like Provable provide simplicity and faster integration, but come with increased vulnerability due to their reliance on a single provider.

In essence, oracles are not just data providers; they are the vital connectors that enable smart contracts to impact and interact with the real world, turning the promise of blockchain technology into practical, everyday use cases. The continued innovation in oracle technology is fundamental for scaling and realizing the full potential of decentralized economies, ultimately paving the way for a more interconnected, transparent future.

⬆️ Top
comments powered by Disqus