First Flight #18: T-Swap

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

In the function declaration of `TSwapPool::swapExactInput`, a return value is defined but never assigned a value, resulting in a default but incorrect return value

Summary

The swapExactInput function is expected to return the actual amount of tokens bought by the user. However, while it declares the named return value output, it never assigns a value to it, nor uses an explicit return statement.

Impact

The return value will always be 0, giving an incorrect information to the user.

Tools Used

Manual review, Foundry.

Recommendations

function swapExactInput(
IERC20 inputToken, // e input token to swap, e.g. sell DAI
uint256 inputAmount, // e amount of DAI to sell
IERC20 outputToken, // e token to buy, e.g. weth
uint256 minOutputAmount, // mint weth to get
uint64 deadline // deadline for the swap execution
)
public
revertIfZero(inputAmount)
revertIfDeadlinePassed(deadline)
returns (
- uint256 output
+ uint256 outputAmount
)
{
uint256 inputReserves = inputToken.balanceOf(address(this));
uint256 outputReserves = outputToken.balanceOf(address(this));
- uint256 outputAmount = getOutputAmountBasedOnInput(inputAmount, inputReserves, outputReserves);
+ outputAmount = getOutputAmountBasedOnInput(inputAmount, inputReserves, outputReserves);
if (outputAmount < minOutputAmount) {
revert TSwapPool__OutputTooLow(outputAmount, minOutputAmount);
}
_swap(inputToken, inputAmount, outputToken, outputAmount);
+ return outputAmount;
}
Updates

Appeal created

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Default value returned by TSwapPool::swapExactInput results in incorrect return value given

Support

FAQs

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