Core Contracts

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

# Redundant Conditional Logic in `_updateWeights` Function in BaseGauge Contract

Summary

The _updateWeights function in the BaseGauge contract contains an if-else block where both branches execute the same logic. This redundancy suggests that the intended differentiated handling for the initial period and subsequent periods is either missing or improperly implemented.

Vulnerability Details

Affected Function:

function _updateWeights(uint256 newWeight) internal {
uint256 currentTime = block.timestamp;
uint256 duration = getPeriodDuration();
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;
TimeWeightedAverage.createPeriod(
weightPeriod,
nextPeriodStart,
duration,
newWeight,
WEIGHT_PRECISION
);
}
}

Root Cause:

  • The condition if (weightPeriod.startTime == 0) is meant to handle the initial period differently from subsequent periods.

  • However, both branches (the if and the else) execute the exact same logic: calculating nextPeriodStart in the same way and calling TimeWeightedAverage.createPeriod with identical parameters.

  • This results in redundant code and suggests that the intended distinction between the initial period and later periods is not implemented.

Impact

  • Confusion in Code: The presence of redundant conditional branches might mislead developers into thinking there is a different handling mechanism for the initial period and subsequent periods, even though the logic is the same.

  • Potential Miscalculations: If there was an intention to handle the initial period differently (e.g., with specific rules or adjustments), the current implementation may result in incorrect calculations of time-weighted averages, leading to improper reward distributions or other issues.

Tools Used

  • Manual Code Review

Recommendations

  1. Clarify the Intended Behavior: Ensure that the logic for handling the initial period is clear. If different handling is necessary for the first period, implement distinct logic in each branch.

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.