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

pkqs90 - SolidlyV3AMO boostPrice() may overflow. #333

Open
sherlock-admin2 opened this issue Oct 29, 2024 · 0 comments
Open

pkqs90 - SolidlyV3AMO boostPrice() may overflow. #333

sherlock-admin2 opened this issue Oct 29, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Oct 29, 2024

pkqs90

Medium

SolidlyV3AMO boostPrice() may overflow.

Summary

SolidlyV3AMO boostPrice() may overflow.

Root Cause

In the first if-branch, the price is calculated by (10 ** (boostDecimals - usdDecimals + PRICE_DECIMALS) * sqrtPriceX96 ** 2) / Q96 ** 2.

Since boostDecimals - usdDecimals == 12, in an extreme case if boost/USD is larger than 1e8, this would overflow. Because 1e8 * 1e12 * 2**192 > 2**256

    function boostPrice() public view override returns (uint256 price) {

        (uint160 _sqrtPriceX96, , , ) = ISolidlyV3Pool(pool).slot0();
        uint256 sqrtPriceX96 = uint256(_sqrtPriceX96);
        
        if (boost < usd) {
@>          price = (10 ** (boostDecimals - usdDecimals + PRICE_DECIMALS) * sqrtPriceX96 ** 2) / Q96 ** 2;
        } else {
            if (sqrtPriceX96 >= Q96) {
                price = 10 ** (boostDecimals - usdDecimals + PRICE_DECIMALS) / (sqrtPriceX96 ** 2 / Q96 ** 2);
            } else {
                price = (10 ** (boostDecimals - usdDecimals + PRICE_DECIMALS) * Q96 ** 2) / sqrtPriceX96 ** 2;
            }
        }
    }

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

N/A

Impact

boostPrice() may overflow for SolidlyV3AMO, and related features would brick, e.g. mintSellFarm(), unfarmBuyBurn().

PoC

N/A

Mitigation

Use FullMath (like UniswapV3).

@sherlock-admin2 sherlock-admin2 changed the title Fast Lemonade Hawk - SolidlyV3AMO boostPrice() may overflow. pkqs90 - SolidlyV3AMO boostPrice() may overflow. Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant