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

sam_gmk - Loss in precision in StableOracleDAI #687

Closed
sherlock-admin opened this issue May 24, 2023 · 0 comments
Closed

sam_gmk - Loss in precision in StableOracleDAI #687

sherlock-admin opened this issue May 24, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label 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

sam_gmk

medium

Loss in precision in StableOracleDAI

Summary

Vulnerability Detail

getPriceUSD in StableOracleDAI is used to get the price of DAI from multiple sources and return the average.

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

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

Both DAIWethPrice and price return 1e18 decimals. Therefore there is no need to multiply the value by 1e10. Since price is an ETH pair, the returned decimals are 1e18 and not 1e8.

POC:

address public priceFeedDAIETH = 0x773616E4d11A78F511299002da57A0a94577F1f4;

function testGetPriceUsd() external view returns (uint256) {
     uint8 numberOfDecimals = AggregatorV3Interface(priceFeedDAIETH).decimals();
      console.log("NUMBER OF DECIMALS:", numberOfDecimals);


     (, int256 price, , , ) = AggregatorV3Interface(priceFeedDAIETH).latestRoundData();
       uint256 finalPrice = uint256(price) * 1e10;
     console.log("REAL PRICE:", uint256(price));
     console.log("SUPER LARGE NUMBER:", finalPrice);


   }

Logs:
NUMBER OF DECIMALS: 18
REAL PRICE: 549993804800023
SUPER LARGE NUMBER: 5499938048000230000000000

Impact

Loss in precision when performing calculations

Code Snippet

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

Tool used

Manual Review

Recommendation

Remove the 1e10 multiplication

Duplicate of #236

@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
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 High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant