First Flight #18: T-Swap

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

Fixed precision on `TSwapPool::getPriceOfOnePoolTokenInWeth` returns incorrect price for tokens that don't use 18 decimals

Summary

getPriceOfOnePoolTokenInWeth has a hardcoded 1e18 amount to account for one token. For tokens like USDC, that has 6 decimals, this function would return an incorrect price. Tokens with decimals higher than 18 would also return incorrect prices.

Vulnerability Details

Tokens like LowDecimals.sol and HighDecimals.sol from weird-erc20 repo are simple examples of this tokens.

Impact

Pools of tokens with decimals different than 18 would get a wrong answer when calling getPriceOfOnePoolTokenInWeth

Tools Used

Manual review

Recommendations

Make the following changes to the function:

function getPriceOfOnePoolTokenInWeth() external view returns (uint256) {
+ uint8 poolTokenDecimals = ERC20(address(i_poolToken)).decimals();
+ uint256 onePoolToken = 10**uint256(poolTokenDecimals);
return getOutputAmountBasedOnInput(
- 1e18, i_poolToken.balanceOf(address(this)), i_wethToken.balanceOf(address(this))
+ onePoolToken, i_poolToken.balanceOf(address(this)), i_wethToken.balanceOf(address(this))
);
}
Updates

Appeal created

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

Hardcoded decimal value leads to incorrect conversion when ERC20 does not use 18 decimals.

Support

FAQs

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

Give us feedback!