The calculation of nextPeriod
in the BaseGauge.sol
constructor performs division before multiplication, which can lead to an unnecessary precision loss. This issue arises from integer division in Solidity, where decimal values are truncated instead of rounded, potentially causing period misalignment.
In the constructor below:
In the calculation:
Here, currentTime / _periodDuration
performs integer division, which truncates any remainder. This truncated value is then multiplied by _periodDuration
, potentially leading to a loss of precision. For example:
If currentTime = 100
and _periodDuration = 30
, then currentTime / _periodDuration = 3
(truncating the remainder 10).
The calculation becomes 3 * 30 + 30 = 120
, which is correct in this case.
However, if currentTime = 95
and _periodDuration = 30
, then currentTime / _periodDuration = 3
(truncating the remainder 5).
The calculation becomes 3 * 30 + 30 = 120
, which skips the expected 90 and jumps to 120.
The period start time might be slightly off from the intended schedule, causing misalignment in emissions or voting periods.
Small misalignments could compound over time, leading to larger discrepancies in later periods.
Manual code review
Reorder the Calculation to Avoid Precision Loss
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.