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

DOS would happen in some instances of minting or burning an ITM option #415

Open
c4-bot-6 opened this issue Apr 22, 2024 · 4 comments
Open
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-435 grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_415_group AI based duplicate group recommendation sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@c4-bot-6
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/SemiFungiblePositionManager.sol#L435-L458
https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/README.md#L256-L257

Vulnerability details

Proof of Concept

First would be key to note that from the contest's readMe, protocol has stated that tokens that revert on zero value transfers are in scope, i.e https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/README.md#L256-L257

| [Revert on zero value approvals](https://github.com/d-xo/weird-erc20?tab=readme-ov-file#revert-on-zero-value-approvals) | ✅ Yes |

Now take a look at https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/SemiFungiblePositionManager.sol#L435-L458

    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external {
        CallbackLib.CallbackData memory decoded = abi.decode(data, (CallbackLib.CallbackData));
        CallbackLib.validateCallback(msg.sender, FACTORY, decoded.poolFeatures);

        address token = amount0Delta > 0
            ? address(decoded.poolFeatures.token0)
            : address(decoded.poolFeatures.token1);

        uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);

        // @audit
        SafeTransferLib.safeTransferFrom(token, decoded.payer, msg.sender, amountToPay);
    }

We can see that this is the function that is used and called by the pool during an ITM option mint/burn, however from this line in Uniswap's native implementation we can see that if no swaps were to occur and this function gets called, then both amount0Delta and amount1Delta will be 0, due to this check uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta); the amount1Delta ends being attempted to be sent which itself is 0 now since not all instances of mints/burns would include swaps, this would occur, and considering the first paragraph in this report proving that protocol supports tokens that revert on zero token transfers
, then this attempt of minting and burning is effectively DOS'd.

Impact

DOS to attempts of minting/burning options, cause if amount0Delta and amount1Delta is 0 the query by Uniswap to uniswapV3SwapCallback() function would fail.

Recommended Mitigation Steps

Consider checking both amount0Delta and amount1Delta before attempting to transfer, after checking if amount0Delta > 0 don't just blindly send amount1Delta if it can be 0, consider applying changing https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/SemiFungiblePositionManager.sol#L435-L458

    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external {
        CallbackLib.CallbackData memory decoded = abi.decode(data, (CallbackLib.CallbackData));
        CallbackLib.validateCallback(msg.sender, FACTORY, decoded.poolFeatures);

-        address token = amount0Delta > 0
-            ? address(decoded.poolFeatures.token0)
-            : address(decoded.poolFeatures.token1);

+        address token;
+        uint256 amountToPay;

-        uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);

+        if (amount0Delta > 0) {
+            token = address(decoded.poolFeatures.token0);
+            amountToPay = uint256(amount0Delta);
+        } else if (amount1Delta > 0) {
+            token = address(decoded.poolFeatures.token1);
+            amountToPay = uint256(amount1Delta);
+        } else {
+            return; // If both deltas are zero , no transfer needed since no swap was done
+        }


        SafeTransferLib.safeTransferFrom(token, decoded.payer, msg.sender, amountToPay);
    }

Alternatively, consider outrightly documenting that these tokens are not supported.

Assessed type

DoS

@c4-bot-6 c4-bot-6 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 Apr 22, 2024
c4-bot-8 added a commit that referenced this issue Apr 22, 2024
@c4-bot-12 c4-bot-12 added the 🤖_415_group AI based duplicate group recommendation label Apr 22, 2024
@c4-judge
Copy link
Contributor

Picodes marked the issue as primary issue

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Apr 26, 2024
@dyedm1 dyedm1 added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Apr 26, 2024
@dyedm1
Copy link
Member

dyedm1 commented Apr 26, 2024

dup #435 ?

@c4-judge c4-judge closed this as completed May 1, 2024
@c4-judge c4-judge added duplicate-435 and removed primary issue Highest quality submission among a set of duplicates labels May 1, 2024
@c4-judge
Copy link
Contributor

c4-judge commented May 1, 2024

Picodes marked the issue as duplicate of #435

@c4-judge
Copy link
Contributor

c4-judge commented May 1, 2024

Picodes changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels May 1, 2024
@C4-Staff C4-Staff reopened this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-435 grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_415_group AI based duplicate group recommendation sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

5 participants