V3SwapRouter.V3SwapExactOutput() has the wrong implementation since it applies the #12
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
primary issue
Highest quality submission among a set of duplicates
🤖_19_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
V3SwapRouter.sol#L191-L202
Vulnerability details
Proof of Concept
First of all, let's understand how a multi-hop exact output swap should work.
In a multi-hop exact output swap, we specify the exact amount of tokens we want to receive as the final output in the last pool, and the swap logic works backward from the last pool to calculate the input needed at each preceding pool to meet this exact output requirement.
The following specifies
amountOut
as the exact amount for the output token for the LAST pool:It calls _swap() using a negative integer
-amountOut
as the first argument.The problem lies in the implementation in _swap():
Instead of passing the first argument
amount
, which is supposed to be the exact amount for the output token for the LAST pool, it applies it as the argument for calling the swap function of the FIRST pool. As a result, This results in the first pool usingamountOut
as the required output, causing incorrect calculations across the multi-hop path.Impact: loss of funds due to wrong calculation or non-function of the transaction.
Recommended Mitigation Steps
Start with the Last Pool: Decode and apply amountOut to the last pool in the path, calculating backward to determine the required input for each previous pool.
Assessed type
Math
The text was updated successfully, but these errors were encountered: