Rounding error risk, resulting in interest == 0.
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.
Interest free loans!
VSC, manual.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.