Skip to content
Smart contracts Audit finding Intermediate

TwapOracle doesn’t calculate VADER:USDV exchange rate correctly

The TwapOracle contract incorrectly calculates the VADER:USDV exchange rate by using the token's decimals as a multiplier instead of a scaling factor. This could lead to incorrect minting of VADER tokens.

TomFrenchBlockchain Follow

Originally disclosed on Code4rena

Submitted by TomFrenchBlockchain

Impact

Detailed description of the impact of this finding.

Proof of Concept

https://github.com/code-423n4/2021-11-vader/blob/3a43059e33d549f03b021d6b417b7eeba66cf62e/contracts/twap/TwapOracle.sol#L156

On L156 of TwapOracle we perform the calculation:

result = ((sumUSD * IERC20Metadata(token).decimals()) / sumNative);

This seems extremely odd as for an 18 decimal token we’re then calculating

result = ((sumUSD * 18) / sumNative);

This is just plain weird. I expect what was meant is to replace this line with the below so we’re properly scaling for token’s number of decimals.

uint256 scalingFactor = 10 ** IERC20Metadata(token).decimals()
result = (sumUSD * scalingFactor) / sumNative;

Marked as high severity as this exchange rate appears to be used in some form of minting mechanism and correctness of the oracle is listed as one of the key focuses of the audit.

Recommended Mitigation Steps

As above.

SamSteinGG (Vader) confirmed

The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.

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 used the token's decimal count directly as a multiplier rather than raising 10 to that power to create a proper scaling factor.

Impact

The incorrect exchange rate could lead to improper minting of VADER tokens, as the oracle's correctness is critical for the minting mechanism.

What the attacker needed

None

The fix

The TWAP oracle module was completely removed and redesigned from scratch as LBTwap.

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 smart contract oracle is supposed to give the correct price between two tokens. Here, the code multiplied by the number of decimals (like 18) instead of by 10 to the power of decimals (like 10^18), so the price would be far too small. That wrong price could cause the system to mint the wrong amount of tokens.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.