Beginner FriendlyFoundryDeFiOracle
100 EXP
View results
Submission Details
Severity: high
Valid

fee are less for non standard ERC20 Token

Summary

Within the functions ThunderLoan::getCalculatedFee() and ThunderLoanUpgraded::getCalculatedFee(), an issue arises with the calculated fee value when dealing with non-standard ERC20 tokens. Specifically, the calculated value for non-standard tokens appears significantly lower compared to that of standard ERC20 tokens.

Vulnerability Details

//ThunderLoan.sol

function getCalculatedFee(IERC20 token, uint256 amount) public view returns (uint256 fee) {
//slither-disable-next-line divide-before-multiply
@> uint256 valueOfBorrowedToken = (amount * getPriceInWeth(address(token))) / s_feePrecision;
@> //slither-disable-next-line divide-before-multiply
fee = (valueOfBorrowedToken * s_flashLoanFee) / s_feePrecision;
}
//ThunderLoanUpgraded.sol
function getCalculatedFee(IERC20 token, uint256 amount) public view returns (uint256 fee) {
//slither-disable-next-line divide-before-multiply
@> uint256 valueOfBorrowedToken = (amount * getPriceInWeth(address(token))) / FEE_PRECISION;
//slither-disable-next-line divide-before-multiply
@> fee = (valueOfBorrowedToken * s_flashLoanFee) / FEE_PRECISION;
}

Impact

Let's say:

  • user_1 asks a flashloan for 1 ETH.

  • user_2 asks a flashloan for 2000 USDT.

function getCalculatedFee(IERC20 token, uint256 amount) public view returns (uint256 fee) {
//1 ETH = 1e18 WEI
//2000 USDT = 2 * 1e9 WEI
uint256 valueOfBorrowedToken = (amount * getPriceInWeth(address(token))) / s_feePrecision;
// valueOfBorrowedToken ETH = 1e18 * 1e18 / 1e18 WEI
// valueOfBorrowedToken USDT= 2 * 1e9 * 1e18 / 1e18 WEI
fee = (valueOfBorrowedToken * s_flashLoanFee) / s_feePrecision;
//fee ETH = 1e18 * 3e15 / 1e18 = 3e15 WEI = 0,003 ETH
//fee USDT: 2 * 1e9 * 3e15 / 1e18 = 6e6 WEI = 0,000000000006 ETH
}

The fee for the user_2 are much lower then user_1 despite they asks a flashloan for the same value (hypotesis 1 ETH = 2000 USDT).

Tools Used

Manual review

Recommendations

Adjust the precision accordinly with the allowed tokens considering that the non standard ERC20 haven't 18 decimals.

Updates

Lead Judging Commences

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

flashloan with differing fees/prices for different decimal tokens

Support

FAQs

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