First Flight #18: T-Swap

First Flight #18
Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Incorrect Usage of swapExactOutput in sellPoolTokens

Summary

The sellPoolTokens function is currently utilizing swapExactOutput instead of swapExactInput to execute token swaps. This incorrect usage can lead to unpredictable and potentially disadvantageous outcomes for users, as it does not allow for precise control over the amount of input tokens required for the swap.

Vulnerability Details

The sellPoolTokens function should allow users to specify the exact amount of pool tokens they wish to sell, and in return, receive an estimated amount of the desired output token. By using swapExactOutput, the function requires the exact output amount to be specified, which can result in users needing to provide an unpredictable and potentially large amount of input tokens. This approach is less user-friendly and can expose users to higher risks due to slippage and price fluctuations.

function sellPoolTokens(uint256 poolTokenAmount) external returns (uint256 wethAmount) {
@> return swapExactOutput(i_poolToken, i_wethToken, poolTokenAmount, uint64(block.timestamp));
}

Impact

  1. User Confusion: Users may be confused or misled about the amount of input tokens required, leading to potential dissatisfaction and reduced user trust.

  2. Slippage Risk: Users are exposed to higher slippage risk as they cannot accurately predict the amount of input tokens needed for the specified output.

  3. Potential Overpayment: Users might overpay in terms of input tokens to achieve the desired output, resulting in financial loss.

Tools Used

Manual Review

Recommendations

  1. Use swapExactInput: Modify the sellPoolTokens function to use swapExactInput, allowing users to specify the exact amount of input tokens they wish to sell and receive an estimated amount of the desired output token.

  2. Improve User Control: Ensure that users have precise control over their input amounts, minimizing the risk of overpayment and slippage.

- function sellPoolTokens(uint256 poolTokenAmount) external returns (uint256 wethAmount) {
+ function sellPoolTokens(uint256 poolTokenAmount, uint256 minOutWethAmount) external returns (uint256 wethAmount) {
- return swapExactOutput(i_poolToken, i_wethToken, poolTokenAmount, uint64(block.timestamp));
+ return swapExactOutput(poolTokenAmount,i_wethToken,minOutWethAmount, uint64(block.timestamp));
)
}
Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`sellPoolTokens` mismatches input and output tokens causing users to receive the incorrect amount of tokens

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.