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

Asset Price and Deposit Amount Scaling Could be Different Than 1e18 #97

Closed
c4-submissions opened this issue Nov 12, 2023 · 6 comments
Closed
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-479 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-11-kelp/blob/main/src/LRTDepositPool.sol#L108-L109

Vulnerability details

Impact

The vulnerability identified concerns the assumption that both deposit amount and lrtOracle.getAssetPrice(asset) in LRTDepositPool.getRsETHAmountToMint() are scaled to 1e18 (Wei standard in Ethereum).

https://github.com/code-423n4/2023-11-kelp/blob/main/src/LRTDepositPool.sol#L108-L109

        // calculate rseth amount to mint based on asset amount and asset exchange rate
        rsethAmountToMint = (amount * lrtOracle.getAssetPrice(asset)) / lrtOracle.getRSETHPrice();

In scenarios involving multiple asset types, this assumption may not hold true, as different assets can have varying decimal places. For instance, many ERC-20 tokens use different scalings (e.g., 6, 8, or even above 18 decimal places).

Additionally, not all prices returned by Chainlink are 18 decimals. Apparently, asset prices returned by the following function could be 8 or 18 decimals per Chainlink documentation:

https://github.com/code-423n4/2023-11-kelp/blob/main/src/oracles/ChainlinkPriceOracle.sol#L34-L39

    /// @notice Fetches Asset/ETH exchange rate
    /// @param asset the asset for which exchange rate is required
    /// @return assetPrice exchange rate of asset
    function getAssetPrice(address asset) external view onlySupportedAsset(asset) returns (uint256) {
        return AggregatorInterface(assetPriceFeed[asset]).latestAnswer();
    }

Incorrectly assuming a uniform scale could lead to significant discrepancies in calculations, impacting the accuracy of minted RSETH tokens and the overall economic logic of the protocol. This issue poses a risk of financial inaccuracies, potential exploits, and could undermine the trust and integrity of the system.

Proof of Concept

Scenario 1:

  • Token A decimal() equals 18 whereas token B decimal() is 6.
  • Users depositing asset A will be minted more RSETH compared to users minting through asset B

Scenario 2:

  • Supposing token A and token B each has its decimal() equal 18.
  • However, getAssetPrice() returns price A with 8 decimals while returning price B with 18 decimals.
  • Users depositing asset A will be minted less RSETH compared to users minting through asset B

Scenario 3:

  • The combination of Scenario 1 and Scenario 2.

Tools Used

Manual

Recommended Mitigation Steps

Consider normalizing all asset amounts and Chainlink price feeds to 18 decimals. Unnormalize the asset amount when redeeming RSETH right after burning and prior to transferring asset to the staker.

Assessed type

Decimal

@c4-submissions c4-submissions 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 Nov 12, 2023
c4-submissions added a commit that referenced this issue Nov 12, 2023
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Nov 15, 2023
@c4-pre-sort
Copy link

raymondfam marked the issue as sufficient quality report

@c4-pre-sort
Copy link

raymondfam marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Nov 15, 2023
@raymondfam
Copy link

Probably wouldn't apply to LST tokens, but Chainlink maybe.

@c4-pre-sort
Copy link

raymondfam marked the issue as duplicate of #479

@c4-judge
Copy link
Contributor

c4-judge commented Dec 1, 2023

fatherGoose1 marked the issue as satisfactory

@c4-judge c4-judge added satisfactory satisfies C4 submission criteria; eligible for awards downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Dec 1, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Dec 4, 2023

fatherGoose1 changed the severity to QA (Quality Assurance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-479 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

5 participants