Chainlink price feed uses BTC, not WBTC. In case of depegging, oracles will become easier to manipulate
The protocol used the Chainlink BTC/USD price feed as the price of WBTC, which is a different asset that can depeg from BTC. If WBTC depegs, an attacker could flash-loan WBTC, skew the Salty pool spot price to match the incorrect Chainlink price, and manipulate the aggregated oracle to liquidate healthy positions.
Submitted by thekmj, also found by peanuts, Tripathi, Ward, OMEN, Toshii, J4X, grearlake, 00xSEV, juancito, Lalanda, and eeshenggoh
https://github.com/code-423n4/2024-01-salty/blob/main/src/price_feed/CoreChainlinkFeed.sol#L15
https://github.com/code-423n4/2024-01-salty/blob/main/src/price_feed/CoreSaltyFeed.sol#L32-L41
https://github.com/code-423n4/2024-01-salty/blob/main/src/price_feed/PriceAggregator.sol#L108
Chainlink BTC price feed is BTC/USD, not WBTC/USD. In the event of WBTC depegging, the oracle’s return price will deviate from its actual value. We also provide a real-life WBTC depegging event as evidence.
This alone is not enough for the price aggregator to return the incorrect price, as an adversary needs to manipulate two of three price feeds to manipulate the price. However, due to the aggregator design, we also make an argument that in case of actual depegging, the price will indeed be easier to manipulate.
Vulnerability details
According to the official Chainlink docs, there are four price feeds for BTC on Ethereum Mainnet:
- BTC / ETH
- BTC / USD
- ETH / BTC
- WBTC / BTC
Based on the following observations, we believe Salty will use BTC/USD on the Chainlink price feed, instead of WBTC:
- All test cases use BTC/USD feed, and nowhere in the code repo is the WBTC feed used.
- There is no WBTC/USD feed on Ethereum Mainnet (they are available on some other networks).
- Salty’s Chainlink price fetcher uses only one feed for the WBTC price. At least two feeds are needed (WBTC/BTC and BTC/USD) to fetch the WBTC/USD price.
Historically, WBTC has depegged down to 0.98 before, in the event of wild market swing, specifically during the LUNA crash.
- Even as of time of report writing, the Chainlink feed for WBTC/BTC does not return a price of 1. Screenshot.
This article explains some of the reasons of why WBTC can depeg.
Full oracle manipulation (PoC)
This alone is not enough to manipulate the oracle entirely, as Salty uses a triple-oracle setting, consisting of Uniswap V3 TWAP, Chainlink price, and Salty pool spot price:
- Out of the three prices, the oracle selects the two price with the lower absolute difference.
- If the two chosen prices are too different, returns 0 signalling failure. Otherwise, return the average of the chosen prices.
However, if the Chainlink price has already deviates, then an adversary will only have to manipulate one more oracle to manipulate the price feed.
The weaker Oracle out of the remaining two is the Salty WBTC pool spot price. Assuming WBTC has already depegged, an adversary can perform the following attack to gain profit:
-
Flash loan a large amount of WBTC from anywhere.
-
Perform a swap on the WBTC Salty pool, skewing its spot price to be closer to the Chainlink (wrong) price feed.
-
The aggregated price now reflects the BTC/USD price, instead of WBTC/USD.
-
With a deviated price, there is a lot that the attacker can do for free:
- Liquidate positions that is actually not yet underwater, and take profit.
-
Return the flash loan amount.
An attacker can also take an undercollateralized position. However, this is more difficult to profit from, as it also requires rapid market swing and the lack of liquation before the position becomes insolvent. This also requires that an attacker has large enough capital.
- Given the scenario where the de-peg has already occured, then this becomes more realistic.
Impact
In the event of WBTC/BTC depeg, such as rapid market swing, the price oracle will become easier to manipulate.
- Given the price of BTC, even a 2% deviation can be considered large.
Recommended mitigation steps
Collect the WBTC price from two Chainlink price feeds, the BTC/USD feed and the WBTC/BTC feed, as the source of truth.
othernet-global (Salty.IO) acknowledged and commented:
The stablecoin framework: /stablecoin, /price_feed, WBTC/WETH collateral, PriceAggregator, price feeds and USDS have been removed:
https://github.com/othernet-global/salty-io/commit/88b7fd1f3f5e037a155424a85275efd79f3e9bf9
Status: Mitigation confirmed. Full details in reports from 0xpiken, zzebra83, and t0x1c.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The protocol used a single Chainlink BTC/USD feed as the WBTC price instead of deriving WBTC/USD from both the WBTC/BTC and BTC/USD feeds.
Impact
In the event of a WBTC/BTC depeg, the price oracle could become easier to manipulate, allowing an attacker to liquidate positions that are not yet underwater; the text notes that manipulating the oracle alone is not enough because two of three feeds must be manipulated.
What the attacker needed
WBTC has depegged from BTC; Attacker can obtain a large WBTC flash loan; Salty WBTC pool has enough liquidity to skew
The fix
The protocol removed the stablecoin framework, price feeds and related components, and the mitigation was confirmed.
How it was found
- Flash loan a large amount of WBTC.
- Swap on the WBTC Salty pool to skew its spot price closer to the incorrect Chainlink BTC price.
- The aggregated price now reflects BTC/USD instead of WBTC/USD.
- Liquidate positions that are not actually underwater and take profit.
- Return the flash loan.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A price oracle is a service that tells a smart contract what an asset is worth. This protocol asked for the price of Bitcoin (BTC) but used it as if it were the price of Wrapped Bitcoin (WBTC), a separate token that is meant to track BTC but can lose its peg. If WBTC drops below BTC, the contract still sees the higher BTC price, and an attacker can use a large temporary loan to push another price source towards that wrong value and trigger unfair liquidations.