First Flight #18: T-Swap

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

Return variable in `TSwapPool::swapExactInput` is wrongly named within the function resulting default value of 0 is returned instead, giving out incorrect information

Summary

The function TSwapPool::swapExactInput specified its return variable as output but it is not referred anywhere within the function. This will result a default value of 0 being returned, affecting any offchain system that relies on this return value that could further lead to wrong information being rendered to user.

Vulnerability Details

The return variable output specified in function TSwapPool::swapExactInput is not defined in the function. Returning an undefined uint256 variable will always result a zero value, giving out wrong information. The most relevant variable that the function should return is named as outputAmount. This would render a calculated output amount that fits the function intended return value.

Impact

User will get a wrong output information following the incorrect return variable implemented by TSwapPool::swapExactInput

Tools Used

Manual review

Recommendations

Make correction to the output variable as follows:

function swapExactInput(
IERC20 inputToken,
uint256 inputAmount,
IERC20 outputToken,
uint256 minOutputAmount,
uint64 deadline
)
public
revertIfZero(inputAmount)
revertIfDeadlinePassed(deadline)
- returns (uint256 output)
+ returns (uint256 outputAmount)
{
uint256 inputReserves = inputToken.balanceOf(address(this));
uint256 outputReserves = outputToken.balanceOf(address(this));
- uint256 outputAmount = getOutputAmountBasedOnInput(
+ outputAmount = getOutputAmountBasedOnInput(
inputAmount,
inputReserves,
outputReserves
);
if (outputAmount < minOutputAmount) {
revert TSwapPool__OutputTooLow(outputAmount, minOutputAmount);
}
_swap(inputToken, inputAmount, outputToken, outputAmount);
}
Updates

Appeal created

inallhonesty Lead Judge about 1 year 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.