Liquidity can become permanently stuck in Uniswap when tokens are transferred. #206
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-256
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L1004-L1006
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L620-L621
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L627
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L614-L617
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L985-L991
Vulnerability details
Impact
It is possible for users to transfer tokens between each other within
SFPM
.But we only check the
net liquidity
when transferring tokens inSFPM
.This can lead to a permanent lock of
liquidity
that has already been deposited intoUniswap
.Proof of Concept
Users or
protocols
, such asPanoptic
, will interact withSFPM
.Individual users can mint tokens directly using
SFPM
or throughprotocols
.For the purpose, we consider the
protocols
as normal users.Let me provide an example.
Consider two tickBounds
[L1, U1]
,[L2, U2]
.User
A
mints ashort
call for[L1, U1]
and depositsX
liquidity.The position key for this is calculated as follows:
The account liquidity is then updated:
s_accountLiquidity[positionKey] = [0, X]
https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L1004-L1006
User
A
mints 2short
calls in one token.One
call
is for[L1, U1]
with liquidityX
, and the other is for[L2, U2]
with liquidityY
.The account liquidity is updated accordingly:
s_accountLiquidity[positionKey] = [0, 2X]
After some time, User
A
mints a longcall
position for[L1, U1]
and movesX
liquidity fromUniswap
.At this point, the account liquidity becomes
s_accountLiquidity[positionKey] = [X, X]
.User
A
decides to transfer token related to the long position to UserB
.It is possible because the net liquidity (
X
) of this position[L1, U1]
is the same as the liquidity of the longcall
.https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L620-L621
But the issue arises because the account liquidity for this position of User
A
is set to0
.https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L627
Despite transferring all account
liquidity
to UserB
, UserA
still holds the first 2 tokens, and these tokens cannot be transferred to UserB
because UserB
's account liquidity for this position[L1, U1]
is already not0
.https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L614-L617
User
A
cannot burn these tokens because they lack net liquidity for this position[L1, U1]
.https://github.com/code-423n4/2023-11-panoptic/blob/f75d07c345fd795f907385868c39bafcd6a56624/contracts/SemiFungiblePositionManager.sol#L985-L991
User
B
cannot use this liquidity because he does not have the tokens.The only option for User
B
is to moveX
liquidity back toUniswap
again.As we can see, the transfer results in a potential permanent lock of
X
liquidity inUniswap
.And the other
X
liquidity may be stuck inUniswap
or remain within theprotocol
.However, no user can utilize that liquidity because there are no tokens available to redeem it.
The PoC test is as below:
Tools Used
Manual
Recommended Mitigation Steps
Do not proceed with the transfer when there is removed liquidity.
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: