Lesson 2

The Basic Working Mechanism of Oracles

In the previous lesson, we understood why blockchains need oracles: because a blockchain is a closed system, smart contracts cannot directly access real-world data, so there must be a mechanism to securely bring off-chain information on-chain. Oracles serve as the crucial infrastructure connecting the on-chain and off-chain worlds. However, oracles are not simply about reading data and uploading it to the blockchain. A reliable oracle system usually consists of multiple components, including data collection, data validation, on-chain publishing, and update mechanisms. If these components are not properly designed, incorrect data may be written to the blockchain, affecting the security of the entire DeFi ecosystem. This lesson will systematically break down the basic workflow of oracles to help you understand how off-chain data is collected, verified, and ultimately used by smart contracts.

Data Acquisition: How Off-Chain Information Is Collected

The first step in an oracle system is to acquire the required data from the real world or the internet. This data may come from exchange prices, financial market indices, weather information, sports results, or even data from IoT devices.

In practice, oracles usually collect data from multiple sources rather than relying on a single source. This is because a single data source may be erroneous, delayed, or even manipulated. By collecting data from multiple sources, the system can improve data reliability and reduce risk.

Common data sources include:

  • Centralized exchange data (such as spot or derivatives market prices)
  • On-chain trading data (DEX transaction prices or TWAP indicators)
  • Professional data providers (financial data platforms or index providers)
  • Real-world information systems (weather, flights, sports events, etc.)

Data collection is typically performed by oracle nodes. These nodes run specific software, continuously monitor external data sources, and send the latest information to the oracle network for further processing.

Data Validation: Preventing Errors and Manipulation

If an oracle simply uploads data to the blockchain, the system would still be vulnerable to errors or manipulation. Therefore, most oracle systems perform validation and aggregation before data is uploaded on-chain.

This process is usually carried out through multi-node collaboration. Different nodes submit the data they have collected, which is then aggregated using algorithms such as averaging or calculating the median. In this way, even if some nodes submit incorrect data, it will not have a significant impact on the final result.

Some oracle networks also introduce additional security mechanisms such as:

  • Node reputation systems: assessing node reliability based on historical performance
  • Staking and penalty mechanisms: nodes must stake tokens and may be penalized for submitting incorrect data
  • Anomaly detection algorithms: identifying outlier values that deviate significantly from most data

Through these mechanisms, oracle systems can prevent malicious data manipulation to some extent and improve overall data quality.

On-Chain Data: How Smart Contracts Access External Data

After validation and aggregation, oracle nodes submit the final result to the blockchain and write it into specific smart contracts. This process is commonly known as “price feed.”

From the perspective of smart contracts, oracle data does not come directly from the external world but is stored in an on-chain data contract. Other DeFi protocols only need to call this contract interface to read the latest data.

For example, when a lending protocol determines whether an account needs to be liquidated, it might execute the following logic:

  1. Call the oracle contract to obtain asset prices
  2. Calculate the value of collateral assets
  3. Determine if it falls below the liquidation threshold
  4. If conditions are met, execute liquidation

In this way, oracles become a key data entry point for on-chain applications, enabling smart contracts to execute automated logic based on real-world information.

Data Update Frequency and Price Synchronization Mechanisms

In financial applications, the timeliness of data is also very important. If price updates are too slow, it may cause liquidation delays, increase arbitrage opportunities, or even trigger systemic risk. Therefore, oracle systems usually implement specific data update mechanisms.

Different application scenarios have different requirements for update frequency. Some protocols require near real-time price updates, while others prioritize data stability. To balance efficiency and cost, oracles typically adopt multiple update strategies.

Common mechanisms include:

  • Scheduled updates: updating data at fixed time intervals
  • Price deviation triggers: updating when market prices change beyond a certain threshold
  • On-chain demand triggers: updating only when smart contracts request data

The design of these mechanisms needs to consider network costs, data accuracy, and market volatility. If updates are too frequent, on-chain transaction costs will increase significantly; if updates are too slow, prices may lag severely.

Therefore, finding a balance between efficiency, cost, and security is a key challenge in oracle system design.

Disclaimer
* Crypto investment involves significant risks. Please proceed with caution. The course is not intended as investment advice.
* The course is created by the author who has joined Gate Learn. Any opinion shared by the author does not represent Gate Learn.