Open code423n4 opened 1 year ago
141345 marked the issue as duplicate of #106
141345 marked the issue as duplicate of #316
141345 marked the issue as not a duplicate
141345 marked the issue as duplicate of #162
gzeon-c4 changed the severity to QA (Quality Assurance)
gzeon-c4 marked the issue as grade-b
Lines of code
https://github.com/code-423n4/2023-08-goodentry/blob/71c0c0eca8af957202ccdbf5ce2f2a514ffe2e24/contracts/TokenisableRange.sol#L338
Vulnerability details
Impact
The asset ratio calculation in
returnExpectedBalanceWithoutFees
may round to 0 with tokens that have a substantial price difference, returning incorrect values which may prevent the case for fees to be accumulatedProof of Concept
This function calculates sqrtPriceX96, using square root of token0Price and token1Price, corrected for difference in decimals.
The issue is caused by the inner function
(2 ** 192 * ((TOKEN0_PRICE * 10 ** TOKEN1.decimals) / TOKEN1_PRICE)) / (10 ** TOKEN0.decimals)
which may round to 0 making the whole expression 0, which incorrectly represents the expected value.If this is the case then when calling claimFees() the condition which compounds the fees will never be reached
Tools Used
manual
Recommended Mitigation Steps
uint160( sqrt( (2 ** 192 * TOKEN0_PRICE) / ( TOKEN1_PRICE / 10 ** (TOKEN1.decimals - TOKEN0.decimals) ) ) )
to prevent rounding to 0Assessed type
Math