DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: medium
Invalid

Incorrect inverted usage Time Weighted Average Prices TWAP

Summary

Oracle uses inverted Uniswap TWAP price which may be inappropriate and can lead to incorrect results

Vulnerability Details

It is common when dealing with token prices to use inversion as in function below LibOracle.sol

uint256 basePriceInEth = basePrice > 0
? uint256(basePrice * Constants.BASE_ORACLE_DECIMALS).inv()
: 0;

The above is appropriate as its spot price of token0/token1 can be inverted to get the spot price of token1/token0.

However the above is not the case when working with TWAP price of token0/token1 due to how TWAP is calculated. Yet in the protocol when Oracle defaults to Uniswap TWAP inversion is still used to get the price. See below

//@dev if there is issue with chainlink, get twap price. Compare twap and chainlink
if (invalidFetchData || priceDeviation) {
uint256 twapPrice = IDiamond(payable(address(this))).estimateWETHInUSDC(
Constants.UNISWAP_WETH_BASE_AMT, 30 minutes
);
uint256 twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1 ether;
uint256 twapPriceInv = twapPriceInEther.inv(); // <----- inversion inappropriately used here
if (twapPriceInEther == 0) {
revert Errors.InvalidTwapPrice();
}

Impact

This may lead to incorrect or inappropriate price values, extremely deviated prices especially if the more volatile the price of token0/token1

See following report for similar finding => Incorrect Use Time-Weighted Average Prices

Tools Used

Manual Analysis

Recommendations

It is recommended not to invert the prices when using TWAP prices. It may be ideal to perform own accumulator based inversion, or use such other appropriate mechanisms to avoid direct inversion prices

Updates

Lead Judging Commences

0xnevi Lead Judge
about 2 years ago
0xnevi Lead Judge about 2 years ago
Submission Judgement Published
Invalidated
Reason: Other
aballok Submitter
about 2 years ago
0xnevi Lead Judge about 2 years ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.