20,000 USDC
View results
Submission Details
Severity: low
Valid

Precision loss in _calculateInterest function

Summary

This report addresses a precision loss vulnerability found in the function _calculateInterest within the smart contract code. The function is responsible for calculating interest and fees for a loan, but the calculations performed within the function can lead to a loss of precision.

Vulnerability Details

When calculating the interest, the result of (l.interestRate * l.debt * timeElapsed) is divided by 10000 and then again by 365 days:

interest = (l.interestRate * l.debt * timeElapsed) / 10000 / 365 days;
fees = (lenderFee * interest) / 10000;

Additionally, there is a division before multiplication. Fees is the result of (lenderFee * interest) divided by 10000. This can cause additional precision loss.

Impact

The precision loss vulnerability in the _calculateInterest function can have significant implications for loan interest and fee calculations such as inaccurate interest and fee calculation

Tools Used

Manual review

Recommendations

Consider changing formula in the following way:

interest = (l.interestRate * l.debt * timeElapsed) / (10000 * 365 days);
fees = (lenderFee * interest) / 10000;

Support

FAQs

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