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

Potential for precision loss in `getCalculatedFee`

Summary

Potential for precision loss in getCalculatedFee

Vulnerability Details

We calculate the valueOfBorrowedToken and fee as shown in the code excerpt below.

uint256 valueOfBorrowedToken = (amount * getPriceInWeth(address(token))) / s_feePrecision;
//slither-disable-next-line divide-before-multiply
fee = (valueOfBorrowedToken * s_flashLoanFee) / s_feePrecision;

We can see that, valueOfBorrowedToken is later on multiplied by s_flashLoanFee even though the value of valueOfBorrowedToken was derived by the division with s_feePrecision on the first line in the above excerpt. Therein lies the potential for some precision loss.

Impact

There's some precision loss during the determination of fee.

Tools Used

Manual review

Recommendations

`ThunderLoan::getCalculatedFee` and `ThunderLoanUpgraded::getCalculatedFee`
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;
+ fee = (amount * getPriceInWeth(address(token)) * s_flashLoanFee) / (s_feePrecision * s_feePrecision);
}
Updates

Lead Judging Commences

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

precision loss valueOfBorrowedToken

Support

FAQs

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