First Flight #18: T-Swap

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

Incorrect math in getInputAmountBasedOnOutput

Summary

The function getInputAmountBasedOnOutput is multiplying by 10000 but instead it should be 1000.

Vulnerability Details

Wrong math.

Impact

Users pay more output token when doing swap using swapExactOutput.

Tools Used

Reading the code.

Recommendations

Fix the formula

function getInputAmountBasedOnOutput(
uint256 outputAmount,
uint256 inputReserves,
uint256 outputReserves
)
public
pure
revertIfZero(outputAmount)
revertIfZero(outputReserves)
returns (uint256 inputAmount)
{
return
((inputReserves * outputAmount) * 1000) / // <<< here the multiplication should be 1000 instead of 10000
((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.