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

Lack checks if Pool deployed by the canonical UniswapV3Factory in uniswapV3SwapCallback #175

Closed
code423n4 opened this issue May 22, 2023 · 3 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working low quality report This report is of especially low quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L216
https://github.com/code-423n4/2023-05-juicebox/blob/main/juice-buyback/contracts/JBXBuybackDelegate.sol#L271

Vulnerability details

Impact

Loss of deserved tokens or DoS when users use this contract.

Proof of Concept

According to the uniswap docs:
https://docs.uniswap.org/contracts/v3/reference/core/interfaces/callback/IUniswapV3SwapCallback#uniswapv3swapcallback

The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.

However, there is no check in this contract's implementation. So a malicious user (since anyone can deploy this contract and trick other users into using it) or malicious project owner (not centralization risk I think: code-423n4/2022-10-juicebox-findings#191 (comment)) can create a fake pool, which calls uniswapV3SwapCallback. There are two attacks:

1.Reach the max allowed slippage and get extra tokens. The attacker can do the exchange himself at a low slippage but give back the user with a high allowed slippage.

2.Bypass the slippage but revert later. The attacker can pass nice parameters to uniswapv3swapcallback but doesn't transfer tokens (or few), so he can pass the slippage checks. But the transaction will later revert (DoS) either at:

        // Send the non-reserved token to the beneficiary (if any / reserved rate is not max)
        if (_nonReservedToken != 0) projectToken.transfer(_data.beneficiary, _nonReservedToken);

or

            // 1) Burn all the reserved token, which are in this address -> result: 0 here, 0 in reserve
            controller.burnTokensOf({
                _holder: address(this),
                _projectId: _data.projectId,
                _tokenCount: _reservedToken, // @audit-info is ok for the fake pool attacks above when _reservedToken is low  https://github.com/jbx-protocol/juice-contracts-v3/blob/12d852f28d372dd44987586f8009c56b0fe247a9/contracts/JBTokenStore.sol#L327
                _memo: "",
                _preferClaimedTokens: true
            });

Tools Used

VSCode

Recommended Mitigation Steps

We should use functions like UniswapV3Factory.getPool() to make sure it's a real pool.

Assessed type

Uniswap

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels May 22, 2023
code423n4 added a commit that referenced this issue May 22, 2023
@dmvt
Copy link

dmvt commented May 25, 2023

spam / self dos

@c4-pre-sort
Copy link

dmvt marked the issue as low quality report

@c4-pre-sort c4-pre-sort added the low quality report This report is of especially low quality label May 25, 2023
@c4-judge c4-judge closed this as completed Jun 2, 2023
@c4-judge
Copy link

c4-judge commented Jun 2, 2023

dmvt marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Jun 2, 2023
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 low quality report This report is of especially low quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants