Skip to content
Business logic Audit finding Intermediate

V3 Proxy does not send funds to the recipient, instead it sends to the msg.sender

The V3 Proxy swap functions ignore the caller-supplied destination address and send swapped tokens to the caller instead. An attacker could exploit this to cause a user's tokens to be sent to an unintended address, potentially losing funds if the caller is blacklisted or has compromised allowances.

josephdara Follow with 3docSec

Originally disclosed on Code4rena

Submitted by josephdara, also found by 3docSec

The functions above can be used to swap tokens, however the swaps are not sent to the provided address. Instead they are sent to the msg.sender. This could cause issues if the user has been blacklisted on a token. Or if the user has a compromised signature/allowance of the target token and they attempt to swap to the token, the user loses all value even though they provided an destination address.

Proof of Concept

//@audit-H does not send tokens to the required address

    function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts) {
        require(path.length == 2, "Direct swap only");
        ERC20 ogInAsset = ERC20(path[0]);
        ogInAsset.safeTransferFrom(msg.sender, address(this), amountIn);
        ogInAsset.safeApprove(address(ROUTER), amountIn);
        amounts = new uint[](2);
        amounts[0] = amountIn;
//@audit-issue it should be the to address not msg.sender
        amounts[1] = ROUTER.exactInputSingle(ISwapRouter.ExactInputSingleParams(path[0], path[1], feeTier, msg.sender, deadline, amountIn, amountOutMin, 0));
        ogInAsset.safeApprove(address(ROUTER), 0);
        emit Swap(msg.sender, path[0], path[1], amounts[0], amounts[1]);
    }

Here is one of the many functions with this issue, as we can see after the swap is completed, tokens are sent back to the msg.sender from the router not to the to address.

Tools Used

Manual Review. Uniswap Router: https://github.com/Uniswap/v3-periphery/blob/main/contracts/SwapRouter.sol

Recommended Mitigation Steps

The uniswap router supports inputting of a destination address. Hence the router should be called with the to address not the msg.sender.

Else remove the address to from the parameter list.

Keref (Good Entry) confirmed, but disagreed with severity and commented:

Cannot remove to from param list as the stated goal is to be compatible with uniswap v2 interface.

Although it looks like a severe issue, in our case this was actually on purpose as this is a compatibility module used for OPM only, where it’s always msg.sender == to, and to avoid potential spam under GE banner (ppl swapping spam tokens to famous addresses).

So it’s not a high risk issue, maybe low only.

gzeon (Judge) decreased severity to Medium and commented:

Recommend to restrict caller to OPM.

Keref (Good Entry) commented:

We could have several (out of this audit scope) contracts that need to swap, restricting to msg.sender is enough.

gzeon (Judge) commented:

Right, so maybe checking msg.sender == to ?

Good Entry Mitigated:

Added explicit require msg.sender == to. PR: https://github.com/GoodEntry-io/ge/pull/10

Status: Mitigation confirmed. Full details in reports from kutugu, xuwinnie and 3docSec.


The original report as published on Code4rena, by josephdara. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The contract passes msg.sender as the recipient to the Uniswap router instead of the to parameter.

Impact

A user could lose tokens if they are blacklisted or have a compromised allowance, because the swap output goes to the caller rather than the intended recipient; the team says it was intentional for a compatibility module where caller and recipient are always the same.

What the attacker needed

Caller must be a user of the V3 Proxy; user must have a token allowance or be blacklisted

The fix

The contract was fixed by adding a check that msg.sender equals to.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you swap tokens, you usually say where the new tokens should go. Here, the contract ignored that and always sent them back to the person who started the swap. If that person was blocked by the token or had a compromised account, the tokens could be lost.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by josephdara

View all

4 more disclosed reports, best first.

More from Good Entry

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.