Data Aggregation and its role in blockchain oracles - A RedStone Article

What you must know about Data Aggregation and its role in blockchain oracles

The concept of oracle plays a very important role in DeFi. Blockchain oracles act as trusted sources of information that feed real-world data into blockchains where automated processes, such as smart contracts, can be executed based on the information provided. As DeFi platforms expand, ensuring tamper-free and accurate data is crucial. Blockchain oracles ensure the integration of real-world data with smart contracts securely. This blog will look at what Blockchain oracles are and their role in making DeFi reliable and accessible.

Blockchain Oracles

Blockchain oracles are entities that act as a bridge between a blockchain smart contract and external data sources. It provides real-time data and feeds it to blockchain networks. Oracles enable smart contracts to execute based on the information received, enhancing the functionality and capabilities of DApps and DeFi platforms. The goal of oracles is to securely integrate off-chain data into on-chain processes, expanding the utility and scope of blockchain technology.

How does it work?

Blockchain oracles provide data to smart contracts on the blockchain, enabling them to carry out specific actions based on that information. For an oracle to work correctly, it must first gather data from various external sources and then format it in a way that the smart contract can understand. This process is called "data aggregation." Once the data is aggregated, it becomes "events" that are sent to the smart contract for processing.

Let’s understand this with an example.

Imagine you want a crypto loan on a DeFi platform. The loan depends on the value of your collateral, but the smart contract can't check prices itself. The smart contract asks the oracle for the real-time price of your collateral. The oracle gathers this data from multiple sources and verifies it. Once confirmed, the oracle sends the price securely back to the smart contract. Now, the smart contract can assess the risk of your loan, set an interest rate, and approve or deny it.

Types of Blockchain Oracles

Input Oracles: Input Oracles fetch data from the real world and deliver it to a blockchain for smart contracts use.

Output Oracles: Output Oracles allow smart contracts to send commands to off-chain systems to execute actions like making payments.

Cross-chain Oracles: Cross-chain oracles enable data and asset transfer between different blockchains, allowing them to work together.

Compute-Enabled Oracles: Copmute-enabled Oracles manage complex calculations of the blockchain for hard tasks to do on-chain due to various limits.

Uses of Blockchain Oracle Technology in DeFi

Blockchain oracles are essential in enhancing the capabilities of blockchain smart contracts further, enabling them to interact with various external systems and data for a broad spectrum of applications among many sectors. Below are some of the most prominent blockchain oracle use cases witnessing significant adoption:

Decentralized Finance

Oracles serve as the backbone of the DeFi sector by providing critical financial data to smart contracts. For instance, they have supply chain and price information essential for lending platforms to evaluate borrowing limits and monitor collateralization ratios to prevent undercollateralization. Synthetic asset platforms rely on oracles to align the value of digital tokens with real-world assets. Moreover, new designs of Automated Market Makers (AMMs) utilize the price feeds from these oracles to adjust liquidity pools according to the prevailing market prices, enhancing capital efficiency.

Powering Lending Markets

Let’s examine a practical example: Morpho Blue is an immutable lending protocol with permissionless market creation. Features independent lending markets with single collateral and borrowable assets, priced via decentralized oracles only. Interest rates are determined by immutable models. Users can create markets with ERC20 assets and oracles of their choice governed by predefined parameters.

MetaMorpho Vaults, uses RedStone for specific vaults, and utilizes LST price data feeds native blockchain to guarantee precise and current pricing data for assets within lending markets. This cooperation with RedStone enhances access to liquidity and expands financial opportunities in the DeFi ecosystem. End users can benefit from blockchain data to form enhanced access to liquidity and expanded financial possibilities in the DeFi ecosystem.

Oracles Preventing Black Swans

Let’s use a real-world example: On January 1, 2024, Google’s search engine experienced a significant technical glitch that led to an unprecedented spike in the exchange rates of the Euro and Dollar against the Polish zloty, erroneously showing the Euro at PLN 5.56 and the Dollar at PLN 5.03. This abrupt increase, over 28% for both currencies, caused widespread confusion and concern, with speculations around political or external events and geopolitical triggers. The situation was exacerbated by Google temporarily halting the display of current exchange rates, leading to rumors and speculation about the cause of Oracle's problem, including potential political statements or geopolitical events impacting the Zloty Oracle problem’s value.

Even Poland’s Finance Minister later clarified that the issue was due to a data source error on Google’s part, with normal exchange rates resuming once Asian markets opened, confirming the Euro at PLN 4.3450, dispelling fears stirred by the incorrect data sources.

The incident revealed vulnerabilities in relying on a single data source for critical financial information, as evidenced by the exploit on the ByBit crypto exchange. Traders capitalized on the inflated PLN rate to sell USD at a significantly higher market value, prompting ByBit to disable PLN withdrawals and fix the issue. You can learn more about it here.

The event underscores the importance of decentralized Oracles in safeguarding traditional systems against such “Black Swan” incidents. By aggregating data from multiple sources, Oracles like RedStone offer a more reliable median exchange rate than a single point, mitigating the risk of manipulation or errors from any single data point. This incident highlights the crucial role of diversified data aggregation hardware oracles in maintaining the integrity and reliability of financial data in the digital age.

Why data aggregation

The quality of data delivered by an Oracle service depends on two main criteria:

  1. Data availability — which means that the Oracle data should be always available for end users (or smart contracts) and should be updated with the promised frequency

  2. Data correctness — it may be defined in different ways and usually depends on the type of data. The correctness of objective data (like the results of a given football match) can be easily verified, but with less objective data (like ETH token price denominated in USD) it can be way more difficult to define the correctness

Data aggregation improves the quality of the Oracle data and helps Oracles meet the requirements in many ways. First of all, aggregating data from different sources increases the value correctness, because even if some small subset of sources eventually corrupts it should not corrupt the aggregated value. Besides that, the aggregated value usually represents a “more fair” or “more correct” value. Additionally, aggregation improves data availability, because even if some sources stop working — the oracle service will still be able to function properly.

As we mentioned in the previous articles, the main product-market fit for oracles today is the provision of pricing data, which is very useful for creating synthetic and derivative assets, insurance, lending, and many other protocols. That’s why this article is mainly focused on the methods of aggregating price values.

Common Aggregation Algorithms:

Average Price Value:

  • Simple but susceptible to manipulation by a small subset of corrupted sources.

  • Mitigated through the incorporation of an Interquartile Range Filter to filter out outliers and market manipulations.

Median Price Value:

  • More resistant to manipulations but not foolproof.

  • Illustrated with an example showcasing limitations in capturing the “real” market value.

Volume-Weighted Average Price (VWAP):

  • Considered one of the best aggregation methods.

  • Factors in trading volume, give more weight to sources with higher volumes.

  • Often combined with an Interquartile Range Filter for enhanced security.

Time-Weighted Average Price (TWAP):

  • Weights prices are based on the time criterion.

  • Particularly useful for decentralized exchanges (DEXes) and limiting market manipulation with limited data sources.

Selecting the Best Aggregation Method:

The deal aggregation method depends on the specific requirements of the order, considering factors like amount, buy/sell type, and order books with associated fees. It acknowledges the complexity of achieving perfection but highlights the importance of selecting an aggregation method that suits the use case while being aware of potential risks.

Official Links

Website | Docs | Blog | Discord | Twitter | Telegram