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 doesn't support decimals other than 8 #248

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

PegOracle doesn't support decimals other than 8 #248

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/main/src/oracles/PegOracle.sol#L73-L78

Vulnerability details

Impact

PegOracle reports wrong prices when the underlying oracle use decimals other than 8. A price reported by PegOracle
can trigger a depeg event immediately after an epoch has started.

Proof of Concept

function testPegOracleDecimals() public {
    DepegOracle ethOracle = new DepegOracle(address(oracleETH), address(admin));
    DepegOracle stethOracle = new DepegOracle(address(oracleSTETH), address(admin));
    ethOracle.setDecimals(14);
    stethOracle.setDecimals(14);

    // A peg oracle for ETH/stETH (ETH/USD and stETH/USD)
    PegOracle pegOracle = new PegOracle(address(ethOracle), address(stethOracle));

    // ETH/stETH is 1
    vm.startPrank(admin);
    ethOracle.setPriceSimulation(5000e14);
    stethOracle.setPriceSimulation(5000e14);
    vm.stopPrank();
    (,int256 nowPrice, , ,) = pegOracle.latestRoundData();

    // Expected: 1e14, actual: 100
    assertEq(nowPrice, 1e14);
}

In the above case, the underlying oracles use 14 decimals; the prices they report also use 14 decimals. It's expected
that the PegOracle reports 1e14, but it reports 100–this is way below any reasonable strike price. The Controller
won't be able to scale the price: it will multiply
100 by 10**(18-14), which equals 100e4, not 1e14.

While most Chainlink oracles use 8 decimals, some of them use 18 (all ETH pairs, e.g. LINK/ETH).

Recommended Mitigation Steps

In the latestRoundData
function of PegOracle, scale the final price to match the decimals of the underlying oracles.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Sep 19, 2022
code423n4 added a commit that referenced this issue Sep 19, 2022
@MiguelBits MiguelBits added the duplicate This issue or pull request already exists label Sep 30, 2022
@MiguelBits
Copy link
Collaborator

dup #305

@HickupHH3
Copy link
Collaborator

dup #195

@HickupHH3 HickupHH3 added 3 (High Risk) Assets can be stolen/lost/compromised directly satisfactory satisfies C4 submission criteria; eligible for awards and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 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 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants