Platform: Code4rena
Start Date: 01/08/2023
Pot Size: $91,500 USDC
Total HM: 14
Participants: 80
Period: 6 days
Judge: gzeon
Total Solo HM: 6
Id: 269
League: ETH
Rank: 69/80
Findings: 1
Award: $15.35
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Team_FliBit
Also found by: 0x70C9, 3docSec, 8olidity, DavidGiladi, Krace, LokiThe5th, Rolezn, Sathish9098, UniversalCrypto, banpaleo5, catellatech, digitizeworx, fatherOfBlocks, hpsb, j4ld1na, josephdara, kutugu, niser93, nonseodion, oakcobalt, osmanozdemir1, pep7siup, ravikiranweb3, said, sivanesh_808
15.3494 USDC - $15.35
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 accumulated
(amt0, amt1) = LiquidityAmounts.getAmountsForLiquidity( uint160( sqrt( (2 ** 192 * ((TOKEN0_PRICE * 10 ** TOKEN1.decimals) / TOKEN1_PRICE)) / ( 10 ** TOKEN0.decimals ) ) ), TickMath.getSqrtRatioAtTick(lowerTick), TickMath.getSqrtRatioAtTick(upperTick), liquidity);
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
(uint256 bal0, uint256 bal1) = returnExpectedBalanceWithoutFees(0, 0); // If accumulated more than 1% worth of fees, compound by adding fees to Uniswap position if ((fee0 * 100 > bal0 ) && (fee1 * 100 > bal1)) {
manual
uint160( sqrt( (2 ** 192 * TOKEN0_PRICE) / ( TOKEN1_PRICE / 10 ** (TOKEN1.decimals - TOKEN0.decimals) ) ) )
to prevent rounding to 0
Math
#0 - c4-pre-sort
2023-08-09T07:42:50Z
141345 marked the issue as duplicate of #106
#1 - c4-pre-sort
2023-08-09T08:05:52Z
141345 marked the issue as duplicate of #316
#2 - c4-pre-sort
2023-08-09T14:17:21Z
141345 marked the issue as not a duplicate
#3 - c4-pre-sort
2023-08-09T14:17:40Z
141345 marked the issue as duplicate of #162
#4 - c4-judge
2023-08-20T16:06:05Z
gzeon-c4 changed the severity to QA (Quality Assurance)
#5 - c4-judge
2023-08-20T17:24:00Z
gzeon-c4 marked the issue as grade-b