Mechanism For Calculation Of fee0 and fee1 In _withdraw() Is Wrong.
Summary
fee0 and fee1 calculation is wrong.
Vulnerability Detail
For calculation of fee0 and fee1, _Withdraw() doing following
It first get IUniswapV3Pool.position()
Then Burn withdrawable liquidity via IUniswapv3pool.burn()
Then again call IUniswapv3Pool.position()
To get fee0 amount (tokensOwed0After - amount0) - tokensOwed0Before same for fee1 as well
But while i exploring Iuniswapv3pool contract, i come to know that, positions() is a getter function for Position.info struct associated with a perticular bytes32 id,
And burn() simply increase token0Owed and token1Owed with corresponding amount of amount0 and amount1 considering burnedLiquidity amount and return same amount0 and amount1
So For example ::
Consider when first positions() called,
let token0beforeOwed=x and token1beforeOwed=y
Then burn() called with some liquidity amount, now let token0Owed=x+a and token1Owed=y+b in UnswapV3 PositionInfo struct,
so returned value amount0=a, amount1=b
Then again positions() called which will return token0OwedAfter = x+a, token1OwedAfter = y+b
So while i want to calculate feefee0 = (tokensOwed0After - amount0) - tokensOwed0Before
= (x+a - a) - x
= 0
0xhacksmithh
high
Mechanism For Calculation Of
fee0
andfee1
In_withdraw()
Is Wrong.Summary
fee0
andfee1
calculation is wrong.Vulnerability Detail
For calculation of
fee0
andfee1
,_Withdraw()
doing followingIUniswapV3Pool.position()
IUniswapv3pool.burn()
IUniswapv3Pool.position()
(tokensOwed0After - amount0) - tokensOwed0Before
same for fee1 as wellBut while i exploring Iuniswapv3pool contract, i come to know that,
positions()
is a getter function forPosition.info
struct associated with a perticularbytes32
id, Andburn()
simply increasetoken0Owed
andtoken1Owed
with corresponding amount of amount0 and amount1 consideringburnedLiquidity
amount and return sameamount0
andamount1
So For example ::
Consider when first
positions()
called, lettoken0beforeOwed
=x andtoken1beforeOwed
=yThen
burn()
called with some liquidity amount, now lettoken0Owed
=x+a
andtoken1Owed
=y+b
in UnswapV3 PositionInfo struct, so returned valueamount0
=a,amount1
=bThen again
positions()
called which will returntoken0OwedAfter
=x+a
,token1OwedAfter
=y+b
So while i want to calculate
fee
fee0
=(tokensOwed0After - amount0) - tokensOwed0Before
= (x+a - a) - x = 0So This will be 0 every time. Same for
fee1
Uniswapv3pool Burn()
Impact
_upFeesGrowth()
will get imapcted, which helps to get Protocol cut. As due tofee0, fee1
calculation bug Protocol revenue suffers.Code Snippet
https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L526-L527
Tool used
Manual Review
Recommendation
Use some other method for calculating fee received amount
Duplicate of #88