Newly Registered Assets Skew Consultation Results
When a new token pair is registered, the TWAP oracle's consultation returns a skewed price because the native asset amount defaults to zero while the Chainlink price is valid, causing the sum to favour USD. An attacker could exploit this incorrect price to manipulate protocol actions that rely on the oracle.
Submitted by leastwood
Impact
The TwapOracle.consult() function iterates over all token pairs which belong to either VADER or USDV` and then calculates the price of the respective asset by using both UniswapV2 and Chainlink price data. This helps to further protect against price manipulation attacks as the price is averaged out over the various registered token pairs.
If a new asset is added by first registering the token pair and aggregator, the consultation result for that token pair will remain skewed until the next update interval. This is due to the fact that the native asset amount will return 0 due to the default price1Average value being used. However, the Chainlink oracle will return a valid result. As a result, the query will be skewed in favour of sumUSD resulting in incorrect consultations.
I’d classify this issue as high risk as the oracle returns false results upon being consulted. This can lead to issues in other areas of the protocol that use this data in performing sensitive actions.
Proof of Concept
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/twap/TwapOracle.sol#L115-L157
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/twap/TwapOracle.sol#L314
- https://github.com/code-423n4/2021-11-vader/blob/main/contracts/twap/TwapOracle.sol#L322-L369
Tools Used
Manual code review.
Recommended Mitigation Steps
Consider performing proper checks to ensure that if pairData.price1Average._x == 0, then the Chainlink aggregator is not queried and not added to sumUSD. Additionally, it may be useful to fix the current check to assert that the pairData.price1Average.mul(1).decode144() result is not 0, found here. require(sumNative != 0) is used to assert this, however, this should be require(pairData.price1Average.mul(1).decode144() != 0) instead.
The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.
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
Likely the oracle does not check that the native asset average price is non-zero before including the Chainlink price, so a default zero value skews the consultation result.
Impact
The oracle returns false results, which could lead to issues in other protocol areas that use this data for sensitive actions.
What the attacker needed
New token pair is registered; consultation occurs before next update interval
The fix
The TWAP oracle module was completely removed and redesigned from scratch as LBTwap, which is subject to a new audit.
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 the current price of an asset. Here, the oracle combines two sources: a decentralised exchange (Uniswap) and a price feed (Chainlink). When a new asset is added, one source gives zero while the other gives a real number, so the combined price is wrong. This wrong price could be used by attackers to trick the protocol.