First Flight #18: T-Swap

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

Wrong multiplier is used in `getInputAmountBasedOnOutput` function.

Summary

getInputAmountBasedOnOutput uses incorrect multiplier, resulting in incorrect calculation.

Vulnerability Details

getInputAmountBasedOnOutput calculates input amount from output amount using wrong multiplier.

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

As you can see in above code, it uses 10000 as multiplier, but it should be 1000 (based on Uniswap Math).

Impact

Since the user has to transfer 10 times the amount of input tokens than expected, this kind of transaction will have a huge impact on the pool operation, eventually causing the pool to stop functioning and users losing their funds.

Tools Used

Manual review

Recommendations

Use correct multiplier.

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

Appeal created

inallhonesty Lead Judge over 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.