Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

0xPkhatri - Incorrect Calculation return in StableOracleDAI#getPriceUSD Function #758

Closed
sherlock-admin opened this issue May 24, 2023 · 4 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented May 24, 2023

0xPkhatri

high

Incorrect Calculation return in StableOracleDAI#getPriceUSD Function

Summary

The StableOracleDAI#getPriceUSD function is incorrectly computing the DAI/USD price due to improper handling of exchange rates and decimal precision. A detailed given below.

Vulnerability Detail

In the StableOracleDAI#getPriceUSD function, three prices are used: wethPriceUSD, DAIWethPrice, and priceFeedDAIETH price to calculate the DAI/USD rate. However, there are two issues in the computation of the DAI/USD price:

  1. while taking average we need to consider that DAIWethPriceis giving $\frac{WETH}{DAI}$ rate but chainlink priceFeedDAIETH price giving $\frac{DAI}{WETH}$ rate so while calculating average we calculate wrong rate.
        return
            (wethPriceUSD * 1e18) /
            ((DAIWethPrice + uint256(price) * 1e10) / 2);
  1. The priceFeedDAIETH returns an 18-decimal rate, not an 8-decimal rate. This can be verified on Etherscan. Thus, when calculating the average, it's incorrect to multiply the price by $10^{10}$.
        // chainlink price data is 8 decimals for WETH/USD, so multiply by 10 decimals to get 18 decimal fractional

        (, int256 price, , , ) = priceFeedDAIETH.latestRoundData();

Impact

The incorrect DAI price calculation can result in a wrong price return from getPriceUSD function.

Code Snippet

https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/oracles/StableOracleDAI.sol#L46-L53

Tool used

Manual Review

Recommendation

It's recommended to revise the calculation method used in the getPriceUSD function to correctly account for the different exchange rates and decimal precision.

Duplicate of #102

@github-actions github-actions bot closed this as completed Jun 5, 2023
@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jun 5, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Jun 23, 2023
@0xPkhatri
Copy link

Escalate for 10 USDC

This is not a duplicate of #236
this is duplicate of #795

@sherlock-admin
Copy link
Contributor Author

Escalate for 10 USDC

This is not a duplicate of #236
this is duplicate of #795

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin sherlock-admin added the Escalated This issue contains a pending escalation label Jun 23, 2023
@hrishibhat
Copy link
Contributor

Result:
High
Duplicate of #102

@sherlock-admin sherlock-admin removed the Escalated This issue contains a pending escalation label Jul 4, 2023
@sherlock-admin
Copy link
Contributor Author

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin sherlock-admin added the Escalation Resolved This issue's escalations have been approved/rejected label Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

3 participants