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

Wrong equation

Summary

The equation seems to be calculating interest and fees wrong

Vulnerability Details

Due to the division by 365 days the numbers in the formula would have to be very big to avoid floor rounding when dividing. To achieve that we can multiply by 10**18.

Impact

Wrong calculations which leads to wrong transactions and loss of funds

Tools Used

Manual review

Recommendations

Rewrite the function in similar fashion:

function _calculateInterestFix(
Loan memory l
) internal view returns (uint256 interest, uint256 fees) {
uint256 timeElapsed = block.timestamp - l.startTimestamp;
uint256 interestRatePerSec = (l.interestRate * 10 ** 18) / 365 days;
interest = (interestRatePerSec * l.debt * timeElapsed) / 10 ** 18;
fees = (lenderFee * interest) / 10000;
interest -= fees;
}

Support

FAQs

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