HomeLearnCoursesHackathonsAccount
Blockchain Security Auditing
Oracle Manipulation and Price Feed Attacks · 1/2

Why a single on-chain price source is a liability

Many smart contracts need to know the real-world or market price of an asset, a lending protocol needs to know if collateral still covers a loan, a derivatives contract needs to know a settlement price. Since a smart contract can't reach out to the internet on its own, it has to read that price from somewhere on-chain, and the simplest approach is to read it directly from a single decentralized exchange pool, calculating price from the ratio of the two assets currently held in that pool. This is straightforward to implement, but it conflates two things that are usually similar but are not the same: the ratio of assets sitting in one specific pool at one specific moment, and the actual broad market price of that asset. Anyone with enough capital, including capital borrowed for the duration of a single transaction, can temporarily push that ratio far away from the real market price simply by trading a large amount into or out of the pool.

This matters because a contract that reads that distorted price and acts on it within the same transaction has no way to tell a genuine market move from a manufactured one. An attacker can, within one atomic transaction, distort the pool's price, get the vulnerable contract to act on that distorted reading, for example borrowing far more than legitimate collateral should allow or liquidating a position that wasn't actually undercollateralized, and then reverse the original trade, restoring the pool to its normal price, all before the transaction ends. Because every step happens atomically, there's no window in which anyone else could react to the temporarily wrong price, and if any step failed the entire transaction would simply revert, so the attempt costs little beyond gas and any borrowing fees.