Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

Redundant Period Calculation in BaseGauge Constructor Leads to Precision Loss

Description

In BaseGauge::constructor, the period calculation contains a redundant multiplication after division that can lead to precision loss. The current implementation first divides the timestamp by period duration and then multiplies by the same value, which can truncate the result unnecessarily.

Proof of Concept

// Current implementation
uint256 currentTime = block.timestamp;
uint256 nextPeriod = ((currentTime / _periodDuration) * _periodDuration) + _periodDuration;

Let's demonstrate with an example:

  1. Assume currentTime = 1000 and _periodDuration = 7 days = 604800

  2. 1000 / 604800 = 0 (integer division truncates)

  3. 0 * 604800 = 0

  4. 0 + 604800 = 604800

The issue is that the division and multiplication by _periodDuration is unnecessary and can lead to precision loss in edge cases where the timestamp is very large.

Recommendations

Remove Redundant Calculation

uint256 currentTime = block.timestamp;
- uint256 nextPeriod = ((currentTime / _periodDuration) * _periodDuration) + _periodDuration;
+ uint256 nextPeriod = currentTime + _periodDuration;
Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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

Give us feedback!