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

Viktor_Cortess - getPriceUSD() function in StableOracleDAI contract calculates price of WETH with inverted data. #491

Closed
sherlock-admin opened this issue May 23, 2023 · 5 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 23, 2023

Viktor_Cortess

medium

getPriceUSD() function in StableOracleDAI contract calculates price of WETH with inverted data.

Summary

One part of the formula:
https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/oracles/StableOracleDAI.sol#L50-L52

returns WETH/USD price, and another part USD/WETH price. As a result, it returns incorrect data.

Vulnerability Detail

I want to start from the point that this line: uint256 wethPriceUSD = ethOracle.getPriceUSD(); always reverts (as it tries to call 0x0 address), so we can't get info from a numerator from our formula.

But the other problem is a denominator.

Let's check the numbers that we got forking the mainnet with console.log.

Logs:
DAIWethPrice:
1815334096585302685954
priceFeedDAIETH
550219077097193

So in the denominator here we got:
https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/oracles/StableOracleDAI.sol#L52

(1815334096585302685954 + 550219077097193 * 1e10)/2

The price is 1 WETH in Dai plus 1 Dai in Weth.

As I understand the denominator is supposed to be (WETH price + WETH price)/2 to get an average WETH price from 2 Oracles, but in this case it will return an incorrect number.

Impact

Retrieving prices for WETH from Oracle doesn't work.

Code Snippet

Tool used

Manual Review

Recommendation

Frankly speaking without normal data from the numerator it's hard to be 100% sure, But regarding the denominator you can change the formula to:

((DAIWethPrice + 1/(uint256(price) * 1e10) )/ 2);

Or check the way you get data from the Oracles to change the formula in an appropriate way.

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
@T1MOH593
Copy link

Escalate for 10 USDC

This is not a duplicate of #909.
It tells about using DAI/ETH instead of ETH/DAI on Chainlink. And #909 tells about completely different issue with oracles

@sherlock-admin
Copy link
Contributor Author

Escalate for 10 USDC

This is not a duplicate of #909.
It tells about using DAI/ETH instead of ETH/DAI on Chainlink. And #909 tells about completely different issue with oracles

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.

@ctf-sec
Copy link
Collaborator

ctf-sec commented Jul 1, 2023

See my comment in #555

@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

4 participants