Lesson 4

Oracles and DeFi Risks

In the DeFi ecosystem, oracles are not just data providers—they directly impact the stability of the entire financial system. The core logic of many DeFi protocols, such as collateral ratio calculation, liquidation triggers, derivatives settlement, and asset pricing, all rely on price data supplied by oracles. If this data deviates, the protocol may make incorrect decisions, triggering a chain reaction. Therefore, in practice, oracles must address not only how to obtain data but also face more complex challenges: how to prevent price manipulation, ensure stable data updates, and avoid systemic risks. This lesson analyzes key risks and security mechanisms of oracles in DeFi systems from three perspectives: liquidation mechanisms, attack cases, and defense designs.

The Role of Price Feeds in Liquidation Mechanisms

In most DeFi lending protocols, users must collateralize assets to borrow funds. For example, a user may collateralize ETH to borrow stablecoins. The system calculates the value of collateral based on market prices provided by oracles and determines whether the account is in a safe state.

When the price of collateralized assets drops below a certain threshold, the system triggers the liquidation mechanism, selling the collateral to repay debt. This process almost entirely relies on timely price updates from oracles, so the accuracy and speed of oracle data directly determine whether the liquidation system operates normally.

If price updates are too slow, the system may fail to trigger liquidation in time, resulting in bad debt risk for the protocol. Conversely, if prices suddenly fluctuate abnormally, it could cause unnecessary mass liquidations. To reduce such risks, DeFi protocols typically combine several mechanisms for risk control:

  • Set a safe collateral ratio to provide a buffer for price volatility
  • Introduce liquidation incentives to encourage market participants to execute liquidations
  • Limit the range of single price updates to avoid extreme data triggering system errors

These designs form the basic framework of DeFi liquidation systems, with oracles serving as the core prerequisite for their operation.

Oracle Attacks and Price Manipulation Cases

While oracles aim to provide reliable data, attackers often try to manipulate price data to gain improper profits within DeFi protocols—these attacks are commonly known as oracle attacks.

A typical method is manipulating decentralized exchange prices. For instance, if a protocol uses a DEX’s spot price as oracle data, an attacker can conduct large trades to briefly change market prices and then profit from this abnormal price in lending or derivatives protocols.

Similar incidents have occurred multiple times in the DeFi ecosystem over recent years. These attacks usually share several characteristics: attackers first obtain large funds through flash loans, then manipulate prices in low-liquidity trading pairs, and finally use abnormal prices to arbitrage across other protocols. Because the entire process can be completed within a single block, the system often cannot react in time.

These cases reveal a key issue: if an oracle relies excessively on a single market’s data, its prices can be manipulated over short periods. As a result, many DeFi projects have started redesigning their oracle systems to reduce attack risks.

Defense Mechanisms: Time-Weighted Average Price (TWAP) and Multi-Source Data

To mitigate price manipulation risks, DeFi protocols generally do not use market prices at a single moment but adopt more robust data processing methods. One of the most common solutions is the time-weighted average price (TWAP).

The core idea of TWAP is to average prices over a period rather than relying on spot prices. This makes it difficult for attackers to decisively influence final data by changing market prices for a short time; manipulating prices requires sustained effort and much higher cost.

Beyond time-weighted mechanisms, many oracle systems also employ multi-source data designs. That is, the system does not rely on a single exchange or market but collects price information from multiple trading platforms and aggregates it. This reduces the impact of fluctuations in any single market.

In more complex systems, oracles may also combine additional security strategies:

  • Collect data from both centralized and decentralized exchanges
  • Use multi-node networks to submit price data
  • Filter out anomalies or extreme prices through algorithms

These mechanisms together form the security architecture of modern DeFi oracles, enabling systems to maintain stable operation amid market volatility and potential attacks.

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.