Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token balances can be made to not correctly reflect the underlying position #527

Closed
c4-bot-2 opened this issue Dec 11, 2023 · 8 comments
Closed
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-256 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") upgraded by judge Original issue severity upgraded from QA/Gas by judge

Comments

@c4-bot-2
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L621-L630

Vulnerability details

Impact

Token balances won't reflect underlying position

Proof of Concept

When transferring, the entire liquidity position is transferred to the other user. The checks done for the sender are:

  1. the user has enough of the token (if transferring x amount of token, the user is supposed to have x amount)
  2. the liquidity amount corresponding to the token amount is equal to the current netLiquidity of the position
    https://github.com/code-423n4/2023-11-panoptic/blob/main/contracts/SemiFungiblePositionManager.sol#L621-L630
    function registerTokenTransfer(address from, address to, uint256 id, uint256 amount) internal {
        
            ........

            uint256 fromLiq = s_accountLiquidity[positionKey_from];
            if (fromLiq.rightSlot() != liquidityChunk.liquidity()) revert Errors.TransferFailed();


            int256 fromBase = s_accountFeesBase[positionKey_from];


            //update+store liquidity and fee values between accounts
            s_accountLiquidity[positionKey_to] = fromLiq;
            s_accountLiquidity[positionKey_from] = 0;


            s_accountFeesBase[positionKey_to] = fromBase;
            s_accountFeesBase[positionKey_from] = 0;

This makes many paths possible where the token balances of an address doesn't represent the underlying position
Eg:

  1. User mints short with posSize = 100 getting liquidity 100
  2. User mints long with posSize = 50 making netLiquidity = 50 and removedLiquidity = 50
  3. User transfers the short token with amount 50 amount.
    Now the user has 50 short token and 100 long token although the user's liquidity position is 0

It is also not checked whether the token being transferred represents a short even though the netLiquidity is moved

Tools Used

Manual review

Recommended Mitigation Steps

If this is not intended behaviour, seperate the transfer of removedLiquidity and netLiquidity based on long/short nature of the token leg and decrease the feeBase only for short transfers.

Assessed type

Token-Transfer

@c4-bot-2 c4-bot-2 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 11, 2023
c4-bot-2 added a commit that referenced this issue Dec 11, 2023
@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Dec 14, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as primary issue

@dyedm1
Copy link
Member

dyedm1 commented Dec 18, 2023

another dup #256

@c4-sponsor
Copy link

dyedm1 (sponsor) confirmed

@c4-sponsor c4-sponsor added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Dec 18, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #256

@c4-judge c4-judge added duplicate-256 and removed primary issue Highest quality submission among a set of duplicates labels Dec 23, 2023
@c4-judge
Copy link
Contributor

Picodes changed the severity to 3 (High Risk)

@c4-judge c4-judge added 3 (High Risk) Assets can be stolen/lost/compromised directly upgraded by judge Original issue severity upgraded from QA/Gas by judge and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Dec 26, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Dec 26, 2023
@c4-judge c4-judge added partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) and removed satisfactory satisfies C4 submission criteria; eligible for awards labels Jan 3, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Jan 3, 2024

Picodes marked the issue as partial-50

@Picodes
Copy link

Picodes commented Jan 3, 2024

The described impact is not of high severity so giving partial credit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-256 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") upgraded by judge Original issue severity upgraded from QA/Gas by judge
Projects
None yet
Development

No branches or pull requests

5 participants