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

durov - SolidlyV3AMO.sol::boostPrice() will round up the price in some cases #319

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

Comments

@sherlock-admin3
Copy link

sherlock-admin3 commented Oct 29, 2024

durov

Medium

SolidlyV3AMO.sol::boostPrice() will round up the price in some cases

Summary

SolidlyV3AMO.sol::boostPrice() has wrongly implemented division logic, which in some cases could harshly round up the actual price.

Root Cause

In SolidlyV3AMO.sol:352 the division is implemented incorrectly, so when the price of boost is less than 1 the function will return 1
because of rounding.

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;
            }
        }
    }

https://github.com/sherlock-audit/2024-10-axion/blob/main/liquidity-amo/contracts/SolidlyV3AMO.sol#L343-L355

Internal pre-conditions

  1. sqrtPriceX96 > Q96
  2. boost > usd

External pre-conditions

None

Attack Path

No response

Impact

boostPrice() will return 1 even if the price of boost is less than 1.

PoC

No response

Mitigation

Change the code line so it multiplies by Q96 ** 2 first and then divides by sqrtPriceX96 ** 2

@sherlock-admin2 sherlock-admin2 changed the title Shiny Tin Halibut - SolidlyV3AMO.sol::boostPrice() will round up the price in some cases durov - SolidlyV3AMO.sol::boostPrice() will round up the price in some cases 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