First Flight #18: T-Swap

First Flight #18
Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: medium
Invalid

Insufficient Check in getOutputAmountBasedOnInput Function for outputReserves Validation Leads to Potential Calculation Errors

Summary

The getOutputAmountBasedOnInput function lacks a crucial check to ensure that outputReserves are greater than inputAmount, which is necessary to prevent potential errors and ensure correct calculation results.

Vulnerability Details

The function getOutputAmountBasedOnInput does not include a validation step to ensure that outputReserves are sufficient to cover inputAmount before proceeding with the calculation. This omission could lead to erroneous results or potential vulnerabilities if outputReserves are not adequately checked.

Impact

If outputReserves are not greater than inputAmount, the function may encounter a runtime error or provide incorrect output amounts, leading to unexpected Revert.

##POC

function test_getInputAmountBasedOnOutput_inputAmountBiggerThanOutputReserves() public {
uint256 outputReserve = 1000;
uint256 inputReserve = 1000;
uint256 inputAmount = 1001;
vm.expectRevert();
uint256 amountBasedOnOutput = pool.getOutputAmountBasedOnInput(inputAmount, inputReserve, outputReserve);
}

Tools Used

Manual Code review

Recommendations

Implement a check within getOutputAmountBasedOnInput to ensure that outputReserves are greater than inputAmount before proceeding with the calculation. This validation step will prevent erroneous calculations and enhance the function's robustness.

function getOutputAmountBasedOnInput(
uint256 inputAmount,
uint256 inputReserves,
uint256 outputReserves
)
public
pure
revertIfZero(inputAmount)
revertIfZero(outputReserves)
returns (uint256 outputAmount)
{
require(outputReserves > inputAmount, "Output reserves must be greater than input amount");
// Calculation logic
}
Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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