Understanding Oracles
Oracles enable smart contracts to use off-chain data by bringing it on-chain
Overview
- What Are Oracles?
- How Do Oracles Work?
- The Importance Of Oracles
- Different Types Of Oracles
- What Are Oracles Used For In DeFi?
- Summary
What Are Oracles?
Oracles are an extremely important piece of the puzzle when we’re talking about DeFi — they enable applications to source, verify, and transmit external data on-chain so smart contracts can actually read them. For any dApp trying to keep a pulse on real-world values — be it the price of gold or the exchange rate of the USD — accurate data feeds delivered by reliable oracles are indispensable.
It’s worth noting that oracles aren’t all the same. They vary based on their data sources, trust models (whether they’re decentralized or centralized), and the design of their system architecture. They’re not merely data transmitters, either. Certain oracles can also execute tasks off-chain.
How Do Oracles Work?
Users
Within the context of oracles, users represent certain entities, such as smart contracts, that request outside information that isn’t native to the blockchain to complete specific actions. So how does it all work? Typically, it starts off with a user putting forward a request to an oracle. These requests could revolve around several considerations:
- Which external sources are the go-to for the data in question?
- How is this raw information refined by reporters to pick out the relevant bits?
- What’s the maximum number of oracle nodes that can join the data-fetching party?
- If there’s a variance in the data from different oracles, how should that be squared away?
- Lastly, what’s the best way to sift through all the incoming reports and condense them into one comprehensive value?
Contract
Oracle contracts all have the following:
1. Two Essential Parts: Every oracle service has both on-chain and off-chain components for seamless operation.
2. On-chain Component Role: This is basically a contract on the blockchain that:
- Listens for data demands from other contracts.
- Sends out data queries to oracle nodes.
- Shares the received data with the client contracts.
3. Oracle Functions: The oracle contract showcases certain functions. When other contracts need data, they tap into these functions.
4. Data Request & Notification: Once a data request is made, the oracle contract lets everyone know via a log event. This log has all the details of what data is being asked for.
5. Off-chain Node Action: Nodes outside the blockchain, keeping an eye on these logs get into action. They pick up these logs, understand the data need, and work to fetch it as defined.
Nodes
Understanding the interaction between the off-chain and on-chain components is crucial. Oracle nodes, which represent the off-chain side of things, are designed to continuously pull information from external sources, such as APIs. Once this data is captured, the nodes then translate it into a readable format for smart contracts. It’s important for these nodes to remain active so they can respond when an on-chain oracle requests data.
To shed light on the behind-the-scenes of an oracle node’s operations, let's take a look at a simplified breakdown:
- Web Interactions: On a regular day, an oracle node initiates communication with the external web by sending HTTP GET requests to specific APIs.
- Data Parsing: Post receiving a response, the node sifts through it, zeroing in on the required data.
- Format Transformation: This extracted data is then converted into a format that the blockchain can understand and process.
- On-chain Transmission: The blockchain-readable data doesn’t just stay put; it’s pushed to the blockchain by including it within a transaction to the oracle contract.
- Accuracy Check: It’s not just about feeding data, sometimes, oracle nodes must vouch for the accuracy of the data they’ve presented. Authenticity proofs come into play here, ensuring the information’s credibility.
The Importance Of Oracles
Smart contracts operate with a deterministic nature, meaning they consistently produce the same outcomes given the same starting conditions and inputs. Now, imagine if blockchains directly sourced raw data from real-world APIs. This would disrupt their deterministic behavior, making it a challenge for nodes to unanimously agree on updates to the blockchain’s state.
Given the amount of Ethereum nodes globally processing transactions, it’s essential that they all have the same outcome. The primary expectation is that nodes when presented with identical transactions, should arrive at the same conclusion. A discrepancy between nodes could shatter consensus and undermine Ethereum’s decentralized nature.
To maintain this deterministic harmony, blockchains restrict nodes to simple true/false decisions based solely on the data present within the blockchain. A common example of this would be “does the account in question have the balance to cover the transaction”.
Therefore, oracles play a pivotal role in bringing external data onto the blockchain for smart contracts to utilize. While this might sound similar to direct API data, there’s a significant difference: oracle data is stored on-chain, making it immutable and transparent to everyone. This ensures Ethereum nodes can use the data without risking consensus, as the imported data is consistent and trustworthy.
Different Types Of Oracles
When considering which oracle to use, you have two main choices: centralized and decentralized oracles. Each comes with its own set of pros and cons. It’s crucial to evaluate both options carefully, as your decision can have significant implications.
Centralized Oracles
Centralized oracles, as the name implies, operate under the control of a single entity. This entity takes charge of gathering off-chain data and updating the oracle contract’s data request. One of the benefits is their efficiency; there’s just one source of truth, a single trusted entity. Such oracles might be the go-to choice when you’re dealing with proprietary datasets signed and published by a trusted owner. However, centralized oracles come with their own set of challenges:
- While they may be considered a trusted source, there’s no immediate way to verify the data’s accuracy. If a hacker tampers with the data, smart contracts will still use this possibly corrupted information.
- Centralized oracles can’t guarantee uninterrupted service. Their off-chain components could be vulnerable to attacks, posing a potential risk.
- In terms of data reliability, there’s a lingering concern. Although users might pay for data services, there’s no guarantee the data host won’t be swayed by a better deal or manipulate data directly for a higher payoff.
Decentralized Oracles
Having looked at the challenges of centralized oracles, it’s worth noting that decentralized oracles were designed to address these issues. Unlike their centralized counterparts, decentralized oracles distribute the responsibility across a peer-to-peer network. This network forms a consensus on off-chain data before feeding it to the smart contract.
Ideally, decentralized oracles would be entirely trustless, permissionless, and free of central control. However, some “semi-decentralized” oracle networks still exist. These function similarly but differ in having an owner who oversees and manages nodes based on their performance. Fully decentralized oracle networks, however, operate as independent blockchains, equipped with specific consensus mechanisms to coordinate nodes and penalize misconduct.
Several advantages make decentralized oracles highly preferable to centralized ones such as:
- They utilize multiple validation methods, ensuring data accuracy and trustworthiness from external sources. Examples include authenticity proofs such as Transport Layer Security (TLS) and Trusted Execution Environment (TEE) attestations.
- While centralized oracles hinge on a single data source, decentralized counterparts pool information from numerous oracle nodes. This method of cross-referencing data from various sources helps filter out incorrect information.
- Decentralized oracles have enhanced availability. By decentralizing both data sources and the nodes transmitting data on-chain, they offer better fault tolerance. For instance, an oracle contract can lean on several nodes to process queries. In addition, certain stake-based oracles can prompt node operators for faster responses by threatening potential slashing for delays.
- There’s a stronger incentive for decentralized oracles to operate correctly, given the number of rewards available for honest service.
What Are Oracles Used For In DeFi?
Oracles are vital tools within DeFi, especially given its focus on peer-to-peer lending, borrowing, and trading. For smooth operations, DeFi platforms need a range of financial data. This includes exchange rates for cryptocurrencies, price comparisons between tokens, and values of tokenized assets like gold or the US dollar. So, if you’re depositing ETH as collateral, oracles help fetch its current market price. This enables smart contracts to assess the collateral’s value and determine how much can be borrowed from a given protocol. At Metronome, oracles are used for tracking underlying asset prices for synthetics and collateral on the application.
Various price oracles have gained traction in the DeFi sector, most notably Chainlink. While oracles serve similar purposes, their functionalities can differ from eachother. It’s essential to grasp these distinctions before settling on one. Chainlink stands out due to its decentralized approach, robust security, and versatility. It’s widely considered among the most dependable oracle networks in DeFi. Many platforms, including Metronome, rely on Chainlink for reliable price feeds, and its resistance to vulnerabilities.
Summary
Oracles serve as bridges, connecting off-chain data with the blockchain, ensuring smart contracts have the necessary external information to function properly. In the realm of DeFi, they’re indispensable. They fetch crucial financial metrics, from cryptocurrency exchange rates to the value of tokenized assets, facilitating operations like peer-to-peer lending and trading.
The world of oracles is diverse; while they all relay data, their sources, trustworthiness, and design vary. Centralized oracles are efficient but might be prone to vulnerabilities due to their single point of control. On the other hand, decentralized oracles, like Chainlink, distribute the responsibility across networks, enhancing data accuracy and system reliability. Given these differences and their pivotal role, selecting the right oracle requires a keen understanding of their functionalities and the specific needs of the DeFi application in question.