Core Contracts

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

Incorrect Weight Update Implementation in BaseGauge

Summary

The _updateWeights function in BaseGauge contains redundant logic in its period management and uses incorrect weight update patterns that could affect time-weighted average (TWA) calculations if implemented.

Vulnerability Details

The function _updateWeights uses identical code in both branches, it creates new periods instead of updating existing ones in the else block

even though this function was not used in the contract, it is documented in the docs that it is an internal function, so this might be a feature that will be implemented later.

function _updateWeights(uint256 newWeight) internal {
uint256 currentTime = block.timestamp;
uint256 duration = getPeriodDuration();
if (weightPeriod.startTime == 0) {
// For initial period
uint256 nextPeriodStart = ((currentTime / duration) + 1) * duration;
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
} else {
//@audit For subsequent periods - Same code as initial period
uint256 nextPeriodStart = ((currentTime / duration) + 1) * duration;
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
}
}

Impact

If implemented, this would:

  1. Break time-weighted average calculations by creating new periods instead of updating

  2. Lose historical weight data

  3. Lead to incorrect voting power tracking

  4. Affect reward distribution calculations based on weights

Tools Used

Manual code review

Recommendations

The updateValue function in the timeWeightAverage library be used in the else block instead of the createPeriod function.

function _updateWeights(uint256 newWeight) internal {
if (newWeight > WEIGHT_PRECISION) revert InvalidWeight();
uint256 currentTime = block.timestamp;
uint256 duration = getPeriodDuration();
if (weightPeriod.startTime == 0) {
// Initial period setup
uint256 nextPeriodStart = ((currentTime / duration) + 1) * duration;
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
} else {
// Update existing period
TimeWeightedAverage.updateValue(
weightPeriod,
newWeight,
currentTime
);
}
emit WeightUpdated(newWeight, currentTime);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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