First Flight #18: T-Swap

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

Incorrect calculation in getInputAmountBasedOnOutput

Summary

Incorrect calculation in getInputAmountBasedOnOutput()

Vulnerability Details

In getInputAmountBasedOnOutput(), we will calculate the input amount based on the exact output. The vulnerability is that the calculation is wrong, should be 1000, not 10000.

function getInputAmountBasedOnOutput(
uint256 outputAmount,
uint256 inputReserves,
uint256 outputReserves
)
public
pure
revertIfZero(outputAmount)
revertIfZero(outputReserves)
returns (uint256 inputAmount)
{
return
// @audit should be 1000
((inputReserves * outputAmount) * 10000) /
((outputReserves - outputAmount) * 997);
}

Impact

Users have to pay more input amount than expected. If users set the proper slippage, this transaction is quite probable to be reverted.

Tools Used

Manual

Recommendations

Revisit the calculation , change 10000 to 1000.

Updates

Appeal created

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

Incorrect fee calculation in TSwapPool::getInputAmountBasedOnOutput causes protocol to take too many tokens from users, resulting in lost fees

Support

FAQs

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