First Flight #18: T-Swap

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

Lack of slippage protection in TSwapPool::swapExactOutput causes users to potentially receive way fewer tokens

Summary

The swapExactOutput function in TSwapPool lacks slippage protection, which could result in users receiving significantly fewer tokens than expected due to market fluctuations

Vulnerability Details

The swapExactOutput function allows users to swap a specified amount of output tokens but does not offer any slippage protection in the form of a maximum input amount. This is different from the swapExactInput function, which specifies a minOutputAmount to protect against slippage. Without a maxInputAmount, users could end up sending significantly more input tokens than anticipated if the market conditions change while the transaction is pending.

Impact

Without slippage protection, users can be negatively impacted by significant market changes that occur between the time they initiate the transaction and when it is processed. This could lead to users losing a considerable amount of tokens, decreasing trust in the protocol and reducing overall user satisfaction.

Tools Used

Manual code review

POC

The price of 1 WETH is currently 1,000 USDC.
User initiates a swapExactOutput transaction to receive 1 WETH:
inputToken = USDC
outputToken = WETH
outputAmount = 1
deadline = ...
The function does not include a maxInputAmount.
While the transaction is pending, the market price changes drastically, and 1 WETH is now worth 10,000 USDC.
The transaction completes, but the user ends up sending 10,000 USDC instead of the expected 1,000 USDC.

Recommendations

Include a maxInputAmount parameter in the swapExactOutput function to provide slippage protection and ensure users only spend up to a specific amount. This change will help users predict their spending on the protocol and protect them from adverse market conditions.

function swapExactOutput(
IERC20 inputToken,
uint256 outputAmount,
IERC20 outputToken,
uint256 maxInputAmount,
uint64 deadline
) external returns (uint256 inputAmount) {
// Calculate input amount based on output amount
inputAmount = getInputAmountBasedOnOutput(outputAmount, inputReserves, outputReserves);
if (inputAmount > maxInputAmount) {
revert("TSwapPool: Input amount exceeds maximum allowed");
}
_swap(inputToken, inputAmount, outputToken, outputAmount);
}
Updates

Appeal created

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

Lack of slippage protection in `TSwapPool::swapExactOutput` causes users to potentially receive way fewer tokens

Support

FAQs

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