TWAPOracle.getRate does not scale the ratio
The TWAPOracle.getRate function performs integer division without scaling, causing the rate to be zero when the numerator is smaller than the denominator. This leads to incorrect values in the usdvtoVader and vaderToUsdv functions.
Submitted by cmichel
The TWAPOracle.getRate function simply performs an integer division to compute the rate.
function getRate() public view returns (uint256 result) {
uint256 tUSDInUSDV = consult(USDV);
uint256 tUSDInVader = consult(VADER);
// @audit shouldn't this scale by 1e18 first? otherwise easily 0
result = tUSDInUSDV / tUSDInVader;
}
It should first be scaled by some value, for example, 1e18.
Impact
The rate has no decimal precision and if tUSDInVader > tUSDInUSDV, the rate will always be zero.
The usdvtoVader and vaderToUsdv functions will return incorrect values.
Recommended Mitigation Steps
// return as a rate with 18 decimals instead
result = tUSDInUSDV * 1e18 / tUSDInVader;
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 integer division lacks a scaling factor, so the result is truncated to zero when the numerator is smaller than the denominator.
Impact
The rate has no decimal precision and can be zero, causing the usdvtoVader and vaderToUsdv functions to return incorrect values.
What the attacker needed
None
The fix
The rate should be scaled by a factor such as 1e18 before division, and the TWAP oracle module was later completely removed and redesigned.
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.
This report is about a smart contract function that calculates an exchange rate between two tokens. Because it divides two numbers without first multiplying by a large factor, the result loses all decimal places and can become zero when the second number is bigger than the first. That makes any conversion using this rate wrong.