Closed c4-bot-6 closed 9 months ago
Picodes marked the issue as unsatisfactory: Invalid
It looks correct to me. Amounts are flipped before being compared to user's inputs
@Picodes , thanks for judging
Not all amounts are swapped correctly.
Only reclaimedA
and reclaimedB
are flipped. minReclaimedA
and minReclaimedB
are never flipped, so it is indeed checking slippage in the wrong order.
See following example:
When user calls withdrawLiquidityAndClaim()
and invokes removeLiquidity()
with following inputs:
tokenA = USDC
which corresponds to minReclaimedA
== minimum amount to receive in USDC.
tokenB = ETH
which corresponds to minReclaimedB
== minimum amount to receive in ETH.
Assuming flipped == true
, PRIOR to the if statement here
reclaimedA
is amount in USDC.
reclaimedB
is amount in ETH.
After swapping places here
reclaimedA
is amount in ETH.
reclaimedB
is amount in USDC.
However, minReclaimedA
and minReclaimedB
were never swapped.
The function goes on to check slippage against the wrong order here
reclaimedA(amount in ETH)
is checked against minReclaimedA(amount in USDC)
reclaimedB(amount in USDC)
is checked against minReclaimedB(amount in ETH)
This can lead to two issues mentioned in the original submission.
Perhaps, we can have the sponsor take a look at this? Thanks again for your time!
@Henrychang26 thanks. Just a side note before I dig into this: in such cases, it's preferable to provide a coded PoC.
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/main/src/pools/Pools.sol#L170 https://github.com/code-423n4/2024-01-salty/blob/main/src/staking/Liquidity.sol#L157 https://github.com/code-423n4/2024-01-salty/blob/main/src/staking/Liquidity.sol#L121 https://github.com/code-423n4/2024-01-salty/blob/main/src/pools/PoolUtils.sol#L32
Vulnerability details
Impact
In the
withdrawLiquidityAndClaim()
function, an issue arises when theflipped == true
in the removeLiquidity() function. The ordering ofminReclaimedA
andminReclaimedB
becomes incorrect, potentially resulting in unexpected reversions or substantial losses for users due to incorrect slippage protection.Proof of Concept
The problem originates in the
pools.removeLiquidity()
function, which utilizesPoolUtils._poolIDAndFlipped()
to determine the proper order of tokens.When
withdrawLiquidityAndClaim()
is invoked, calling_withdrawLiquidityAndClaim()
, the issue becomes evident:In
removeLiquidity()
, whenflipped == true
,reclaimedA
andreclaimedB
are swapped into the correct order.reclaimedA
andreclaimedB
are then used to check againstminReclaimedA
andminReclaimedB
-which should have been swapped too. The function is effectively checking incorrect slippage protection against the wrong tokens.This issue can cause 2 scenarios:
withdrawLiquidityAndClaim()
call might unexpectedly revert during the slippage protection check due to incorrect token ordering.withdrawLiquidityAndClaim()
could lead to significant user losses as slippage protection is misaligned against the wrong tokens.Tools Used
Manual Review
Recommended Mitigation Steps
Assessed type
Context