Smart Contract Building Blocks

Oracles

A blockchain oracle facilitates the execution of smart contracts by providing real-world input and output data.

What is an Oracle?

A blockchain oracle is an entity that enables smart contracts, autonomous pieces of code that self-execute once conditions are met, to execute based on inputs and outputs from the real world. Oracles connect blockchains to external systems, like data sources and other off-chain networks, feeding information from these external systems into smart contracts that rely on specific, real-world conditions. By sourcing, verifying, and transmitting external information to smart contracts on a blockchain, oracles function as bridges between on- and off-chain infrastructure.

Why are oracles important?

By nature, blockchains and smart contracts that run on a blockchain network are intentionally separate from external systems. This means that smart contracts are fundamentally limited and cannot interact with systems outside their own blockchain environments. As the necessary bridge to off-chain resources for smart contracts, oracles must service the blockchain with trustworthy and reputable data, while still upholding the values afforded by decentralization.

How do oracles work?

An oracle integrates with a given chain via a smart contract, which operates as the user of the oracle. When the user (smart contract) sends its data request to the oracle, the oracle’s on-chain component (oracle contract) queries that data by connecting to external data sources via the oracle’s off-chain component (oracle node) and extracting the necessary information. The oracle then returns the queried data from the source to the smart contract on the blockchain. Oracles can function cross-chain, meaning that they may serve data to not just one but multiple chains, by integrating with those chains.

Types of Oracles

There are numerous types of oracles, each with their own functions and capabilities.

Software oracles are the most common, pulling data from third-party sources like web APIs, such as weather or financial data. There are two types of software oracles. Input oracles request data from real-world, off-chain sources and broadcast this data to the blockchain. Use cases include triggering a function in a smart contract if a certain real-world condition is met. Output oracles allow smart contracts to send data or commands to systems outside the blockchain network they exist on, or off-chain entirely. For instance, a smart contract might use an output oracle to request that a banking network make a payment; or to unlock a home or car door via an Internet of Things (IoT) system once an on-chain rental payment has been made.

Hardware oracles use IoT sensors integrated with physical objects. They may be used for supply chain management via radio frequency identification (RFID) to broadcast data related to supply chain products to the blockchain.

Cross-chain oracles allow smart contracts to read and write data between blockchains, enabling interoperability by transferring data or assets from one blockchain to another, triggering an action on one blockchain from another, or bridging assets cross-chain so that they can be used outside the native blockchain they were issued on.

Compute-enabled oracles use a secure, off-chain computation system to provide decentralized services that may be impractical on the blockchain due to technical, legal, financial, or privacy constraints.

The Range

Levels of Decentralization

The types of oracles listed above can be implemented in ways that range from fully centralized to fully decentralized.

Centralized oracles are controlled by a single entity that aggregates off-chain data and updates the oracle’s data as requested. While centralized oracles can be efficient because they depend only on one source, they don’t benefit from the value of decentralization since they may be susceptible to manipulation, censorship, or hacks, and constitute a single point of failure if the oracle goes offline, and smart contracts, whose functions depend on that data, will not be able to execute or may execute inaccurately.

Consensus-based oracles utilize the data from several other oracles. While not quite single-source or centralized, these oracles are also not decentralized, as they still rely on the authenticity and accuracy of those other oracle sources. Semi-decentralized, consensus-based oracles may allow anyone to participate in validating off-chain data but will still rely on an owner to approve the consensus.

Decentralized oracles, unlike centralized oracles, are designed to eliminate single points of failure. A decentralized oracle relies on multiple participants in a peer-to-peer network to form a consensus on off-chain data before that data is broadcasted to a smart contract on the blockchain. At their best, decentralized oracles are permissionless, trustless, and free from administration governance by any individual entity, utilizing authenticity proofs to guarantee the high correctness of the data they are sending to the blockchain.

The "Oracle Problem"

The biggest challenge faced by oracles, known as the “Oracle Problem,” is how to make sure that the data oracles source from third parties guarantees the following crucial qualities:

Correctness: smart contracts should not execute on invalid off-chain data;

Authenticity: oracles must guarantee that the data comes from the correct source;

Integrity: the data must be intact and unaltered;

Trustlessness: oracles must reliably provide accurate data without needing the trust of a third party that might otherwise result in a single point of failure;

Availability: there should be no interruptions or delays in broadcasting data to the blockchain via an oracle, prohibiting a smart contract from executing.

Decentralized oracle solutions, which leverage consensus-based oracles, decentralized marketplaces, and various data authentication methods, work to minimize data manipulation, oracle failure, and the problem of trust. In addition to improving decentralized oracles, oracle service providers employ various strategies to enhance oracle security, from developing data verification and aggregation techniques; to improving consensus mechanisms and oracle designs; to implementing cryptographic proofs and auditing mechanisms; to exploring reputation systems that increase the transparency of the oracle network and each individual node operator in that network.

Oracle Use Cases

Oracles enable smart contracts to tap into decentralized, tamper-proof sources across industries, including:

Decentralized finance (DeFi), where price oracles are used in ecosystems to access financial data about assets and markets, including exchange rates and capital market data; to determine users’ lending and borrowing capacities; to fix the value of blockchain tokens against real-world assets; and to concentrate liquidity pools around the current market price to efficiently maximize returns.

Future Trends

As a core building block of smart contracts and blockchain technologies, oracles are powerful tools that have the potential to impact not only the uses of blockchains and smart contracts in existing industries but also the broader adoption of blockchain technologies across new and developing industries.

With the emergence and increasing adoption of technologies like artificial intelligence, machine learning, and IoT devices, oracle integrations that connect Web3 infrastructure and smart contracts in decentralized finance beyond today’s capabilities.

Smart Contracts on Stellar Network

Smart contracts are usable on the Stellar network with Soroban, Stellar’s native smart contracts platform.

Soroban is an additive feature that is integrated into the existing Stellar blockchain and is able to interact with Stellar network accounts and assets. Soroban is currently live on Futurenet, a shared test network with Mainnet launch happening later in 2023.

Get started with Soroban now by accessing our Soroban documentation.

Explore Next

Your Next Read

Swap Functionality and AMMs

Learn how Swap Functionality and Automated Market Maker work with smart contracts.

View

Lending and Borrowing Markets

Learn the power of lending and borrowing markets and how they work in a DeFi ecosystem.

View

Stellar Developer Hub

Explore documentation, tooling, & community support to help you get your blockchain project up quickly. Take advantage of learning resources to…

View

Soroban: Smart Contracts Docs

Start building on Soroban today with the help of established tools and documentation

Go