Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong calculation of nowPrice in PegOracle.latestRoundData. #399

Closed
code423n4 opened this issue Sep 19, 2022 · 2 comments
Closed

Wrong calculation of nowPrice in PegOracle.latestRoundData. #399

code423n4 opened this issue Sep 19, 2022 · 2 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate This issue or pull request already exists satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-09-y2k-finance/blob/ac3e86f07bc2f1f51148d2265cc897e8b494adf7/src/oracles/PegOracle.sol#L78

Vulnerability details

Impact

Wrong calculation of nowPrice in PegOracle.latestRoundData.

PegOracle.latestRoundData always returns nowPrice = 0 for normal 18 decimals tokens.

Proof of Concept

From the below formula, we can see nowPrice <= 10000.

File: 2022-09-y2k-finance\src\oracles\PegOracle.sol
67:         if (price1 > price2) {
68:             nowPrice = (price2 * 10000) / price1;
69:         } else {
70:             nowPrice = (price1 * 10000) / price2;
71:         }

After that, it's divided by 1e6 here and it will be 0 for normal 18 decimals tokens.

Tools Used

Manual Review

Recommended Mitigation Steps

We should change nowPrice / 1000000 to nowPrice / 10000.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Sep 19, 2022
code423n4 added a commit that referenced this issue Sep 19, 2022
@3xHarry
Copy link
Collaborator

3xHarry commented Sep 21, 2022

@MiguelBits seems to be valid

@MiguelBits MiguelBits added the duplicate This issue or pull request already exists label Sep 23, 2022
@0xnexusflip 0xnexusflip added discussion closed Judge has reviewed and integrated all feedback sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) and removed discussion closed Judge has reviewed and integrated all feedback labels Sep 28, 2022
@0xnexusflip 0xnexusflip removed resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Sep 29, 2022
@HickupHH3
Copy link
Collaborator

dup of #195

@HickupHH3 HickupHH3 added the satisfactory satisfies C4 submission criteria; eligible for awards label Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate This issue or pull request already exists satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants