Oracle manipulation is a major threat to DeFi projects, tricking projects into using incorrect pricing information for tokens. By manipulating pricing information, attackers can acquire tokens for cheap and sell them at a higher price.
Several major DeFi hacks involved price oracle manipulation. Some of the most expensive targeted Cream Finance, BonqDAO, and Mango Markets.
What is an Oracle Manipulation Attack?
Decentralized exchanges (DEXs) and lending protocols often rely on price oracles to determine the price of various tokens. Since most cryptocurrencies (except for stablecoins) have their prices set by the market, DEX and lending protocols need insight into the rates that various tokens are being bought and sold for to support their trading operations.
Protocols can estimate these prices in a few different ways. A common – but insecure – option is to use spot prices within the liquidity pool of a single automated market maker (AMM). By comparing the relative supplies of the two tokens in a trading pair, it’s possible to estimate their relative value.
However, this method is vulnerable to manipulation via flashloans. With a flashloan, an attacker can take out a massive loan and change the balance of a trading pair within a pool for the space of a single transaction. By creating an imbalance, they will cause one of the tokens to be overvalued in relation to the other.
This imbalance – called slippage – allows an attacker to “buy low and sell high.” As a result, they’re able to drain value from the targeted liquidity pool.
The Biggest Oracle Manipulation Hacks to Date
Price oracle manipulation attacks are a relatively common type of DeFi hack, taking advantage of poor implementations of price oracles. Some of the most expensive examples of these hacks to date include the following:
Cream Finance ($130M)
In October 2021, Cream Finance was the victim of a $130 million price oracle manipulation attack. The attacker used a pair of malicious smart contracts to create a cycle of depositing and borrowing assets, allowing them to build up a supply of $1.5 billion in crYUSD.
The result of each cycle of borrowing and depositing increased the pricePerShare. At the end of the attack, this value was doubled, allowing the attacker to borrow $130 million against their collateral.
The root cause of this incident was the fact that the attacker was able to use yUSD tokens as collateral for borrows. Since the value of these tokens could be manipulated within a transaction, the protocol was vulnerable to this vicious cycle.
BonqDAO ($120M)
In February 2023, BonqDAO was the victim of a $120 million price oracle manipulation attack. The attacker exploited the fact that BonqDAO allowed users to borrow BEUR (its stablecoin) using WALBT (Wrapped AllianceBlock Token).
The prices used for WALBT came from Tellor, a decentralized price oracle platform. Tellor allowed users to submit price updates by staking TRB tokens, assuming that only legitimate users would pay to make updates. However, the attacker staked enough TRB tokens to post incorrect price data for WALBT, making it appear about 10x overvalued.
In this case, the attacker took advantage of the fact that the profit from the attack – about $120 million – far exceeded the cost to manipulate prices on Tellor. As a result, the attacker could still make a profit after staking TRB tokens to manipulate the perceived value of WALBT tokens.
Mango Markets ($117M)
Mango markets suffered a cross-market price pump of the MNGO token in October 2022. The attacker (Eisenberg) stole an estimated $117 million using large leveraged positions and manipulation of the relative prices of MNGO and USDC.
Eisenberg then created two accounts on Mango Markets and created positions within a swap contract that were based on the relative price of USDC and MNGO. Then, he bought about $4 million worth of MNGO tokens across three exchanges that Mango’s oracle relied upon within the space of about ten minutes. As a result, the perceived price of MNGO tokens jumped 13-fold.
Since Eisenberg had positions betting on the relative value of MNGO and USDC tokens, his portfolio value on Mango grew to about $116 million, which he later extracted as a loan. In negotiations, $67 million of this was later returned.
Protecting Against Oracle Manipulation Attacks
Price oracle manipulation attacks are generally made possible by a project relying on a single, manipulable price feed. In the case of Mango Markets, the attacker targeted multiple exchanges while targeting thin order books that were especially vulnerable to manipulation.
Preventing oracle manipulation attacks requires ensuring that an attacker can’t substantially change asset prices within the space of a single transaction, even with a substantial flash loan. Some security best practices include:
- Decentralized Oracle Networks: If a DEX or lending protocol relies on a single price oracle, it’s potentially possible for an attacker to manipulate that oracle enough to create an exploitable level of slippage. Decentralized oracle networks, like Chainlink, use a network of several price oracles to estimate pricing, giving a more accurate view of the real value of the token in the network and making it much more difficult for an attacker to substantially manipulate all of these feeds.
- Time-Weighted Average Prices (TWAP): Price oracle manipulation attacks are often performed within the space of a single transaction, taking advantage of the leverage provided by a flashloan. TWAP oracles base prices off of the average price of an asset across a particular window of time (30 mins, 1 hour, etc.), forcing an attacker to manipulate the asset price for a substantial period of time and making the attack much more expensive to perform.
Oracle manipulation attacks are a prime example of a major threat that can be mitigated by implementing security best practices. However, it’s not alone, and other simple errors can result in major threats to DeFi protocols. Halborn’s advisory services support projects throughout the entirety of the software development lifecycle (SDLC), ensuring that security controls are implemented from the design stage onward. To learn more about protecting your project from oracle manipulation and other top threats to DeFi, get in touch with Halborn.
