Flash loan attacks exploiting oracle manipulation became a major DeFi threat in early 2020 with the bZx exploit (approximately $350,000 stolen). These attacks proliferated between 2020 and 2022, causing hundreds of millions in losses across many protocols.
In previous years, flash loan attacks were the most common exploits affecting decentralized finance (DeFi) protocols—malicious actors would use instant liquidity and protocol vulnerabilities to steal millions of dollars within seconds. Since then, however, strategies targeting DeFi have become more sophisticated and varied. Today, one of the most common types of DeFi attack vectors is oracle price manipulation, whereby attackers target the price feed of DeFi protocols.
In this article, we look at how oracles work, why they matter, how they can be exploited, and more, with the goal of educating DeFi participants on how to better protect themselves from these types of threats.
In blockchain ecosystems, smart contracts operate autonomously and deterministically. They do not have native access to external data sources. This isolation is a security feature, but it also introduces a critical limitation: Smart contracts remain unaware of events occurring outside of the blockchain. Oracles fill that need.
An oracle is a data delivery mechanism that supplies external information to a smart contract, such as the price of a token, the result of a sports match, or the outcome of an election. There are three major types of oracles:
Smart contracts run in real time and without intermediaries—whatever an oracle says, its corresponding protocol will believe and act on it instantly. This trust becomes a double-edged sword. Oracles have become the single most critical dependency in DeFi, influencing everything from lending, to borrowing and derivatives.
The Time-Weighted Average Price (TWAP) constitutes a specialized oracle, serving as an external data feed for smart contracts, thereby facilitating informed critical decision-making processes. The TWAP averages an asset’s price over a given period to reduce price manipulation in DeFi by smoothing volatility and protecting against price spikes.
Instead of relying on a single spot price, a TWAP samples the price of an asset at regular intervals (i.e. once per block or once per minute) and calculates the arithmetic average over a predefined time window. The protocol uses the average price for essential on-chain operations, such as collateral valuation, trade execution, and liquidation thresholds.
For example, the TWAP of an asset sampled every minute for 10 minutes, with prices 1.00, 1.02, 1.01, and 1.11, would be the mean of those values: 1.066.
TWAPs aim to mitigate brief price manipulation, but unfortunately introduce a new weakness. If a manipulator can maintain a skewed price throughout the entire TWAP calculation period, the resulting average will be as unreliable as the manipulation itself.
We can cite several examples of significant hacks, such as the April 2025 KiloEx exploit resulting in approximately
Protecting against oracle manipulation attacks requires a multi-layered defense strategy. If the data layer is vulnerable, the protocol itself becomes exploitable. Here are essential measures DeFi protocols should implement:
To learn more about best blockchain security practices, read the latest articles on our blog.