Oracles on Tezos
Getting started with oracles on Tezos
To be widely useful, many blockchain-based applications need to access real-world data.
Enter oracles. Oracles connect blockchain-external data or events to smart contracts. This allows blockchain-based applications and contracts to interact with real-world data (e.g. external prices, IoT data) and encode real-world obligations.
In this post, we provide a brief introduction of how oracles bridge real-world data to blockchain-based applications and present a type-agnostic oracle contract on Tezos that may be administered using a multisig (or a DAO).
We also provide a simple Dockerized Flask app in Python based on a Tezos smart contract. This application has been publishing the stock price of Apple (AAPL) at every block (~30 seconds) on Babylonnet for the past several months and now is live on Carthagenet.
Oracles in the wild
In practice, oracles support a significant number of valuable blockchain applications, especially whenever a smart contract-based system needs to interact with external data from the real-world. For example, if there is a smart contract that executes based on the value of a currency, say the Indian Rupee, applications would use a price-feed oracle to retrieve and interact with that data.
Oracles that serve current data, e.g. price-feeds, are limited by how much data is feasible to store on-chain: a “two-way” oracle can serve much more data or even arbitrary off-chain computation by accepting requests for data.
Oracles and Trust
Described differently, oracles mediate trust about off-chain data or events and this trust can be mediated through either centralized or decentralized mechanisms.
In the case of centralized oracles, a trusted party simply attests to the validity of the data using cryptographic signature(s). However, as implied, the data is only as trustworthy as the data provider, a problem sometimes referred to as “The Oracle Problem”. This challenge is often regarded as one of the great limitations of blockchain technology’s applicability in traditional domains.
In the case of decentralized oracles, different on-chain governance or economic mechanisms are used to mediate trust. In some systems, these economic mechanisms have a naive similarity to the reward / slashing mechanisms seen in Proof-of-Stake systems like the one that secures Tezos.
Other approaches, such as Town Crier, use trusted execution environments such as Intel SGX to provide authenticated data feeds to smart contracts (or private/confidential information).
Some practical examples
- An oracle that provides weather data could allow a tsunami insurance contract: users purchase coverage from the contract, which pays out when there’s a sufficiently severe tsunami in their area.
- A combination of different oracles could be used to provide consensus, for example, where only results published by a majority of the oracles are considered valid.
- An oracle that provides XTZ/USD prices could allow users to deposit funds that are immediately converted to some on-chain asset and represented as fiat.
- An off-chain computation oracle and price-feed oracle could be combined to charge fees based on current cloud spot-instance prices.
- Trusted parties could expose REST API’s on-chain.
- Banks could use oracles to either publish Payment Services Directive (PSD2) data directly or provide an off-chain computation oracle to allow users to request it.
For other practical tutorials, check out the Assets Portal.