Skip to content
Crypto Audit finding Advanced

Oracle doesn’t calculate USDV/VADER price correctly

The oracle contract calculates the USDV price by averaging prices expressed in different foreign assets without converting them to a common unit, producing an invalid value. An attacker could exploit this incorrect price to mint or burn USDV at a favourable rate, causing the protocol to lose funds.

TomFrenchBlockchain Follow

Originally disclosed on Code4rena

Submitted by TomFrenchBlockchain, also found by danb and leastwood

Invalid values returned from oracle for USDV and VADER prices in situations where the oracle uses more than one foreign asset.

Proof of Concept

The USDV price is calculated as so (for simplicity we’ll consider a two pairs):

https://github.com/code-423n4/2021-12-vader/blob/fd2787013608438beae361ce1bb6d9ffba466c45/contracts/lbt/LiquidityBasedTWAP.sol#L393-L409

totalUSD =  (PriceForeign0InUSD * liquidityWeights[0] + PriceForeign1InUSD * liquidityWeights[1]) / totalUSDVLiquidityWeight;

totalUSD is then the average price of the foreign assets paired against USDV in terms of USD, weighted by the TVL of the relevant liquidity pool

totalUSDV =
  (pairData0
      .nativeTokenPriceAverage
      .mul(pairData0.foreignUnit)
      .decode144() * liquidityWeights[0] +
   pairData1
      .nativeTokenPriceAverage
      .mul(pairData1.foreignUnit)
      .decode144() * liquidityWeights[1]) /
  totalUSDVLiquidityWeight;

// in pseudocode for readability
totalUSDV = (USDVPriceInForeign0 * liquidityWeights[0] + USDVPriceInForeign1 * liquidityWeights[1]) /  totalUSDVLiquidityWeight

totalUSDV is then the average price of USDV in terms of each of the foreign assets, weighted by the TVL of the relevant liquidity pool.

It should be fairly clear that this is the incorrect calculation as all the terms in totalUSDV are in different units - you can’t average the price of USDV in ETH with the price of USDV in BTC and get a meaningful result.

It appears that the VADER team intended to calculate the price of USDV in terms of USD through a number of different paired assets and then average them at the end based on the liquidity in each pair but have started averaging too early.

High severity issue as the oracle is crucial for determining the exchange rate between VADER and USDV to be used for IL protection and minting/burning of USDV - an incorrect value will result in the protocol losing significant funds.

Recommended Mitigation Steps

Review the algorithm used for calculating the prices of assets and ensure that it’s calculating what you expect.

SamSteinGG (Vader) acknowledged


The original report as published on Code4rena, by TomFrenchBlockchain. 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 code averages USDV prices that are each denominated in a different foreign asset without first converting them to a common USD unit.

Impact

An incorrect oracle value could let the protocol lose significant funds when used for IL protection and minting or burning of USDV.

What the attacker needed

Oracle uses more than one foreign asset

The fix

The algorithm for calculating asset prices should be reviewed and corrected so that all terms are converted to a common unit before averaging.

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.

An oracle is a service that feeds price data into a smart contract. Here the contract tried to work out the price of one token by averaging its price in several other tokens, but it mixed up prices quoted in different currencies, like averaging dollars and euros without converting them first. That gives a meaningless number, and anyone trading against that wrong price could drain value from the protocol.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by TomFrenchBlockchain

View all

28 more disclosed reports, best first.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.