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

PegOracle:latestRoundData will always return zero for the nowPrice if the decimals are 18. #76

Closed
code423n4 opened this issue Sep 16, 2022 · 1 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 old-submission-method satisfactory satisfies C4 submission criteria; eligible for awards sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-09-y2k-finance/blob/2175c044af98509261e4147edeb48e1036773771/src/oracles/PegOracle.sol#L67-L82

Vulnerability details

Impact

The function PegOracle:latestRoundData will always return zero for the nowPrice if the priceFeed1.decimals are 18. Even if the priceFeed1.decimals are less than 18 it still returns a wrong value for the nowPrice.

Proof of Concept

In the below code snippet, if the priceFeed1.decimals is 18, then the returned nowPrice will be 0; if it is smaller than 18 it returns a wrong value for the nowPrice.

// PegOracle
// latestRoundData
67        if (price1 > price2) {
68            nowPrice = (price2 * 10000) / price1;
69        } else {
70            nowPrice = (price1 * 10000) / price2;
71        }
72
73        int256 decimals10 = int256(10**(18 - priceFeed1.decimals()));
74        nowPrice = nowPrice * decimals10;
75
76        return (
77            roundID1,
78            nowPrice / 1000000,
79            startedAt1,
80            timeStamp1,
81            answeredInRound1
82        );

Tools Used

None

Recommended Mitigation Steps

Use a fixed precision (decimals) for the price.

Example:

int256 precision = 10000;

if (price1 > price2) {
            nowPrice = (price2 * precision) / price1;
        } else {
            nowPrice = (price1 * precision) / price2;
        }

        int256 decimals10 = int256(10**(18 - priceFeed1.decimals()));
        nowPrice = nowPrice * decimals10;

        return (
            roundID1,
            nowPrice,
            startedAt1,
            timeStamp1,
            answeredInRound1
        );
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working old-submission-method labels Sep 16, 2022
code423n4 added a commit that referenced this issue Sep 16, 2022
@MiguelBits MiguelBits added the duplicate This issue or pull request already exists label Sep 23, 2022
@0xnexusflip 0xnexusflip added 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 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
@MiguelBits MiguelBits added sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons and removed duplicate This issue or pull request already exists labels Oct 3, 2022
@HickupHH3
Copy link
Collaborator

dup of #195

@HickupHH3 HickupHH3 added satisfactory satisfies C4 submission criteria; eligible for awards duplicate This issue or pull request already exists labels 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 old-submission-method satisfactory satisfies C4 submission criteria; eligible for awards sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

4 participants