First Flight #18: T-Swap

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

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

Summary:

The getInputAmountBasedOnOutput function is intended to calculate the amount of tokens a user should deposit given an amount of tokens of output tokens. However, the function currently miscalculates the resulting amount. When calculating the fee, it scales the amount by 10_000
instead of 1_000.

Vulnerability Details:

Impact:

Protocol takes more fees than expected from users.

Tools Used:

manual

Recommendations:

function getInputAmountBasedOnOutput(
  uint256 outputAmount,
  uint256 inputReserves,
  uint256 outputReserves
 )
 public
 pure
  revertIfZero(outputAmount)
  revertIfZero(outputReserves)
  returns (uint256 inputAmount)
   {
 - return ((inputReserves * outputAmount) * 10_000) / (( outputReserves - outputAmount) * 997);
+ return ((inputReserves * outputAmount) * 1_000) / (( `outputReserves - outputAmount) * 997);

}

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.