DittoETH

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

TWAP price uses `USDC` instead of `USD`

Summary

LibOracle.sol:getOraclePrice() can return an incorrect USD/ETH price in case the TWAP price is used, as it is using USDC instead of USD.

Vulnerability Details

LibOracle.sol:baseOracleCircuitBreaker() falls back to the TWAP price if there is an issue with the Chainlink base oracle price.

However, in this case, the WETH/USDC price is used. In the past, USDC has depegged from the dollar as much as a 3% difference and it is not unimaginable that it could depeg even more in the future. Given that these events usually happen in moments of high volatility, these are the moments when the Chainlink oracle is most likely to fail and the TWAP price is used.

The calculation of the TWAP price has also other remarkable issues.

For one, in the normalization of the price, division is performed before multiplication, which can lead to a loss of precision.

85 uint256 twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1 ether;

As for the liquidity check, it is only performed in the case of the Chainlink price being invalid (not in the case of it deviating too much from the previous price) and in any case, the liquidity could be manipulated with a flash loan.

101 //@dev In case USDC_WETH suddenly has no liquidity
102 IERC20 weth = IERC20(Constants.WETH);
103 uint256 wethBal = weth.balanceOf(Constants.USDC_WETH);
104 if (wethBal < 100 ether) revert Errors.InsufficientEthInLiquidityPool();

Impact

The incorrect USD price can be used, which can lead to many problems, including users being required to deposit more/less collateral than expected or being liquidated when they shouldn't be.

Tools Used

Manual review.

Recommendations

Use another oracle service as a fallback or revert the transaction if the Chainlink oracle fails.

Updates

Lead Judging Commences

0xnevi Lead Judge
almost 2 years ago
0xnevi Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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