Skip to content
Audit finding Intermediate

Incorrect Price Consultation Results

The TwapOracle.consult() function calculates the price of a token by dividing the USD-denominated sum by the native-denominated sum, instead of multiplying them, resulting in an incorrect price. An attacker could exploit this false price to manipulate other protocol actions that rely on the oracle.

leastwood Follow

Originally disclosed on Code4rena

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.

Let’s say we wanted to query the price of USDV, we would sum up any token pair where USDV == pairData.token0.

The sum consists of the following:

  • Price of USDV denominated in terms of token1 (USDV/token1).
  • Price of token1 denominated in terms of USD (token1/USD).

Consider the following example:

  • SUSHI is the only registered token pair that exists alongside USDV.
  • Hence, calculating sumNative gives us an exchange rate that is denominated as USDV/SUSHI.
  • Similarly, sumUSD gives us the following denominated pair, SUSHI/USD.
  • I’d expect the result to equal sumUSD * token.decimals() * sumNative which should give us a USDV/USD denominated result.

However, the protocol calculates it as (sumUSD * token.decimals()) / sumNative which gives us a SUSHI^2 / (USD*USDV) denominated result. This seems incorrect.

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

Similar working implementation listed below:

Tools Used

Manual code review.

Recommended Mitigation Steps

To calculate the correct consultation of a given token, the result should return sumUSD * token.decimals() * sumNative instead to ensure the target token to consult is denominated in USD and contains the correct number of decimals.

SamSteinGG (Vader) confirmed:

The description seems slightly incorrect as it uses a power where multiplication is performed but the general idea is correct.

The original report as published on Code4rena, by leastwood. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 formula for combining the two price sums used division instead of multiplication, producing an incorrectly denominated result.

Impact

The oracle returns false prices, which could lead to issues in other areas of the protocol that use this data for sensitive actions.

What the attacker needed

None

The fix

The calculation should multiply the two sums instead of dividing, so the result is correctly denominated in USD with the right number of decimals.

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 how much a token is worth. In this case, the oracle combined two price sources but used division instead of multiplication, so the final price was wrong. If other parts of the protocol trust this wrong price, an attacker might be able to take advantage of it.

More by leastwood

View all

70 more disclosed reports, best first.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.