Core Contracts

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

Redundant Period Calculation Logic Creates Potential for Gaps in Time-Weighted Averages

Link to Affected Code:

https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/governance/gauges/BaseGauge.sol#L185-L210

function _updateWeights(uint256 newWeight) internal {
uint256 currentTime = block.timestamp;
uint256 duration = getPeriodDuration(); // 7 days
if (weightPeriod.startTime == 0) {
// For initial period, start from next period boundary
uint256 nextPeriodStart = ((currentTime / duration) + 1) * duration;
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
} else {
// For subsequent periods, ensure we're creating a future period
uint256 nextPeriodStart = ((currentTime / duration) + 1) * duration; // @audit use the start time + duration??
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
}
}

Description:
\

The _updateWeights function contains redundant logic that calculates period start times incorrectly. Both the initial and subsequent period branches use calendar-based alignment (currentTime / duration) instead of maintaining continuous periods( since weightPeriod.startTime !== 0). This can create gaps in time-weighted average calculations when:

  1. Initial period starts mid-way through a calendar period

  2. Subsequent updates occur after period gaps

Impact:

  1. Potential gaps in time-weighted average calculations

  2. Inaccurate reward distributions based on weights

  3. Periods that don't properly sequence from previous period end

Proof of Concept:
\

Consider this sequence with 7-day periods:

// 1. Initial Setup (Jan 5)
currentTime = Jan 5
duration = 7 days
nextPeriodStart = ((Jan 5 / 7 days) + 1) * 7 days = Jan 7
// Creates 2-day gap from Jan 5-7
// 2. Update on Jan 15
currentTime = Jan 15
nextPeriodStart = ((Jan 15 / 7 days) + 1) * 7 days = Jan 21
// Should be Jan 14 (Jan 7 + 7 days) for continuity
// Creates 7-day gap in weight tracking

Recommended Mitigation:
\

Modify implementation to maintain continuous periods:

function _updateWeights(uint256 newWeight) internal {
uint256 duration = getPeriodDuration();
uint256 nextPeriodStart;
if (weightPeriod.startTime == 0) {
// Initial period - align to calendar boundary
nextPeriodStart = ((block.timestamp / duration) + 1) * duration;
} else {
// Subsequent periods - continue from last period
nextPeriodStart = weightPeriod.startTime + duration;
}
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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