Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

tank - fee calculations #46

Open
sherlock-admin opened this issue Jun 25, 2023 · 11 comments
Open

tank - fee calculations #46

sherlock-admin opened this issue Jun 25, 2023 · 11 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jun 25, 2023

tank

medium

fee calculations

Summary

refer to this LOCs: https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L722-L746, these LOCs don't allow underflow/overflow, but refering to Uniswap/v3-core#573 which allows underflow/overflow. This will lead to some transactions will revert.

Vulnerability Detail

Impact

some user transactions will revert.

Code Snippet

            if (liquidity > 0) {
                (
                    uint256 feeGrowthInside0X128Pending,
                    uint256 feeGrowthInside1X128Pending
                ) = _getFeeGrowthInside(
                        IUniswapV3Pool(position.poolAddress),
                        slots[i].tick,
                        position.lowerTick,
                        position.upperTick
                    );
                pendingFee0 += uint128(
                    FullMath.mulDiv(
                        feeGrowthInside0X128Pending - feeGrowthInside0LastX128,
                        liquidity,
                        FixedPoint128.Q128
                    )
                );
                pendingFee1 += uint128(
                    FullMath.mulDiv(
                        feeGrowthInside1X128Pending - feeGrowthInside1LastX128,
                        liquidity,
                        FixedPoint128.Q128
                    )
                );
            }

Tool used

Manual Review

Recommendation

add unchecked {} when calculate the pending fee

@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jun 28, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Jul 12, 2023
@huuducsc
Copy link

Escalate

This issue is not a duplicate of #88, and it is an invalid issue. The above calculation is similar to UniswapV3's implementation for accruing fees, so it is correct. UniswapV3 doesn't allow overflowing/underflowing while updating the position, refer to this code snippet https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/Position.sol#L61-L76
Additionally, the impact of this issue is low.

@sherlock-admin
Copy link
Contributor Author

Escalate

This issue is not a duplicate of #88, and it is an invalid issue. The above calculation is similar to UniswapV3's implementation for accruing fees, so it is correct. UniswapV3 doesn't allow overflowing/underflowing while updating the position, refer to this code snippet https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/Position.sol#L61-L76
Additionally, the impact of this issue is low.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin sherlock-admin added the Escalated This issue contains a pending escalation label Jul 13, 2023
@n1punp
Copy link

n1punp commented Jul 14, 2023

@huuducsc This is a valid issue (also dupe of #1 ) .

Your analysis is incorrect. UniswapV3 does allow overflowing / underflowing. The code snippet you're posting is for Solidity version < 0.8.0, which has not safe math by default

@JeffCX
Copy link

JeffCX commented Jul 24, 2023

@huuducsc This is a valid issue (also dupe of #1 ) .

Your analysis is incorrect. UniswapV3 does allow overflowing / underflowing. The code snippet you're posting is for Solidity version < 0.8.0, which has not safe math by default

Agree,

not a duplicate of #88, seperate valid medium based on the comments;

Uniswap/v3-core#573

the Uniswap code use compiler version before 0.8.0 so the overflow / underflow is implicitly allowed

but in the current real wagmi codebase use compiler version 0.8.18 and does not allow overflow / underflow

based on the issue 573 discussion, the implicit overflow is needed to correctly calculated the fee.

so a valid issue

as for whether the severity is medium or low

Uniswap/v3-core#573 (comment)

I think the situation above is not a uncommon case, so recommend severity is medium

unless there are further comments from both side!

@hrishibhat
Copy link

@huuducsc Do you agree with the above comments?

@hrishibhat hrishibhat added Medium A valid Medium severity issue and removed High A valid High severity issue labels Aug 5, 2023
@hrishibhat hrishibhat reopened this Aug 10, 2023
@hrishibhat
Copy link

@n1punp
Jeiwan/uniswapv3-book#45 (comment)
Do you have any comments on this?

@n1punp
Copy link

n1punp commented Aug 10, 2023

It's as Jeiwan's commented -- the subtraction should expect underflow (so this will be an issue for solidity >= 0.8.x), so this is a valid issue.

@n1punp Jeiwan/uniswapv3-book#45 (comment) Do you have any comments on this?

@hrishibhat
Copy link

hrishibhat commented Aug 10, 2023

@n1punp Thanks for clarifying. Yes, that makes sense.
Sorry if I'm missing something.
I don't see reverting during a deposit as a major issue.
but the revert during withdrawal can be a problem.
Do you have a valid example with numbers for the possibility?

Or is this example applicable in this case?
Uniswap/v3-core#573 (comment)

@n1punp
Copy link

n1punp commented Aug 10, 2023

@hrishibhat Not sure about the specific case where user can deposit but cannot withdraw. It may require very precise calculations to find it out, which could not be worth the time (since allowing underflow should be the answer anyways), but having the core functionality unavailable should give this issue a valid Medium at least. I'm fine with it being valid Medium (as in #1 ).

(if anyone can somehow prove that it can deposit but cannot withdraw, then it could be a valid High).

@hrishibhat hrishibhat removed the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Aug 11, 2023
@hrishibhat
Copy link

Result:
Medium
Has duplicates
Considering this a valid medium based on the above comments

@sherlock-admin2 sherlock-admin2 removed the Escalated This issue contains a pending escalation label Aug 11, 2023
@sherlock-admin sherlock-admin added the Escalation Resolved This issue's escalations have been approved/rejected label Aug 11, 2023
@sherlock-admin2
Copy link

Escalations have been resolved successfully!

Escalation status:

@hrishibhat hrishibhat added the Has Duplicates A valid issue with 1+ other issues describing the same vulnerability label Aug 11, 2023
@fann95 fann95 added Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed labels Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Escalation Resolved This issue's escalations have been approved/rejected Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Sponsor Disputed The sponsor disputed this issue's validity Won't Fix The sponsor confirmed this issue will not be fixed
Projects
None yet
Development

No branches or pull requests

7 participants