The FjordPoints contract contains a potential Faulty Division Operation vulnerability in its distributePoints
function, which could lead to precision loss and incorrect calculation of distribution periods.
The vulnerable line is in the distributePoints
function:
This operation performs integer division to calculate the number of weeks pending for point distribution. However, integer division in Solidity truncates any remainder, potentially leading to lost precision and underestimation of the actual time elapsed.
The imprecise calculation of weeksPending
can result in:
Underestimation of distribution periods, leading to fewer points being distributed than intended.
Inconsistent distribution timing, as fractional weeks are ignored.
Potential for manipulation by timing transactions to maximize or minimize the weeksPending
calculation.
Consider the following scenario:
EPOCH_DURATION
is set to 1 week (604,800 seconds)
lastDistribution
was 10 days ago (864,000 seconds)
The calculation would be:
This results in only 1 week of points being distributed, despite nearly 1.5 weeks having passed, leading to an underdistribution of points.
Manual code review
Use a Precision Factor:
Multiply by a large factor before division to retain more precision:
Then adjust subsequent calculations to account for this precision factor.
Track Time in Smaller Units:
Consider tracking time in days or hours instead of weeks for finer granularity:
Use OpenZeppelin's Math Library:
Utilize OpenZeppelin's Math library for more precise calculations:
Accumulate Leftover Time:
Keep track of the remainder and include it in the next calculation:
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.