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

Rounding error risk, resulting in interest == 0

Summary

Rounding error risk, resulting in interest == 0.

Vulnerability Details

PoC:

Given:

  • l.interestRate = 10000

  • l.debt = 100 wei

  • timeElapsed = 1 day (86400 seconds)

  • 1 day = 86400 seconds

Calculation:

interest = (10000 * 100 wei * 86400 seconds) / 10000 / 365 days
= 100 wei * 86400 seconds / 365 days
= 100 wei * 86400 seconds / 365 days
= 100 wei * 1 day / 365 days
= 100 wei / 365 days
= 0

As you can see, due to the rounding error, the value of interest becomes zero.

Impact

Interest free loans!

Tools Used

VSC, manual.

Recommendations

To mitigate the rounding error risk in the interest calculation, consider using higher precision data types such as fixed-point arithmetic or well-established decimal libraries. By working with higher precision, you can reduce the risk of rounding errors and ensure more accurate interest calculations. Additionally, consider using integer arithmetic whenever possible to avoid floating-point arithmetic and eliminate potential fractional components.

Support

FAQs

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