First Flight #18: T-Swap

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

The function `TSwapPool::getPoolTokensToDepositBasedOnWeth` does not take fees into account for it's calculation

Description

The function getPoolTokensToDepositBasedOnWeth should call the function getOutputAmountBasedOnInput to calculate the correct amount including the fees.
The current implementation does not take fees into account when it does the calculation as can be seen below.

// this function does not take fees into account.
// assuming the intention of the function is to return the number of pool tokens
// needed to get the desired value in weth rather than re-implementing the
// calculation again it should use the appropriate existing function.
// ie. getOutputAmountBasedOnInput()
function getPoolTokensToDepositBasedOnWeth(
uint256 wethToDeposit
) public view returns (uint256) {
uint256 poolTokenReserves = i_poolToken.balanceOf(address(this));
uint256 wethReserves = i_wethToken.balanceOf(address(this));
return (wethToDeposit * poolTokenReserves) / wethReserves;
}

The implementation should be changed as shown below:

// Assuming this undocumented function is intended to:
// get pool tokens to deposit,
// based on the amount of weth we want
//
// note the argument has also been renamed
function getPoolTokensToDepositBasedOnWeth(
uint256 weth
) public view returns (uint256) {
uint256 poolTokenReserves = i_poolToken.balanceOf(address(this));
uint256 wethReserves = i_wethToken.balanceOf(address(this));
return getOutputAmountBasedOnInput(
weth,
poolTokenReserves,
wethReserves
);
}

Please note: the code above is untested and should not be assumed to be the most effective solution or production ready code

Impact
The return value is not accurate as it does not include the protocol fees.

Reference
https://github.com/Cyfrin/2024-06-t-swap/blob/d1783a0ae66f4f43f47cb045e51eca822cd059be/src/TSwapPool.sol#L424

Tools Used

  • Manual Review

Updates

Appeal created

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

The function `TSwapPool::getPoolTokensToDepositBasedOnWeth` does not take fees into account for it's calculation

4rdiii Auditor
12 months ago
inallhonesty Lead Judge
12 months ago
inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

The function `TSwapPool::getPoolTokensToDepositBasedOnWeth` does not take fees into account for it's calculation

Support

FAQs

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