Core Contracts

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

Initialization Issue in Time-Weighted Average Calculation

Initialization Issue in Time-Weighted Average Calculation

Summary

The current implementation of the TimeWeightedAverage in the BaseGauge contract initializes the first period with a weight of zero. This leads to incorrect calculations of time-weighted averages (TWAP), resulting in ineffective reward distribution and potential user attrition. The report outlines the implications of this flaw, provides a concrete example, and presents recommended fixes.

Current Code Issue

The problematic line of code is as follows:

TimeWeightedAverage.createPeriod(..., 0, 10000); // Initial weight = 0

What's Wrong?

  • Zero Initialization: Time-weighted averages (TWAP) start at zero, making the first period's calculations meaningless until updated.

  • Impact on Reward Distribution: If the first period is initialized with a weight of zero, the TWAP will remain zero until the next update, leading to no rewards being distributed.

Concrete Example

  1. Initialization:

    • Period starts at T=0 with weight=0.

    • First update occurs at T=7 days with weight=5000.

  2. TWAP Calculation:

    TWAP = (sum(weight * time)) / totalTime
    = (0 * 7 days + 5000 * 0) / 7 days
    = 0
  3. Result:

    • The first period shows a TWAP of 0.

    • Rewards are distributed as if the protocol is inactive.

Visual Timeline

Time (days) | Weight | Contribution to TWAP
------------------------------------------
0 | 0 | 0 * 7 = 0
7 | 5000 | 5000 * 0 = 0
------------------------------------------
TWAP = (0 + 0) / 7 = 0

Fix

To resolve this issue, the initialization should use a reasonable default weight:

TimeWeightedAverage.createPeriod(..., INITIAL_WEIGHT, 10000);

Where INITIAL_WEIGHT could be:

  • Historical average from similar gauges.

  • Protocol-wide baseline (e.g., 1000).

Fixed Timeline

Time (days) | Weight | Contribution to TWAP
------------------------------------------
0 | 1000 | 1000 * 7 = 7000
7 | 5000 | 5000 * 0 = 0
------------------------------------------
TWAP = (7000 + 0) / 7 = 1000

Combined Impact

  1. Reward Distribution:

    • Frozen emissions lead to insufficient incentives, resulting in user attrition.

    • Users may disengage from the protocol due to lack of rewards.

  2. Time-Weighted Averages:

    • Zero-weight bootstrap results in misreported activity, leading to a loss of trust in the system.

    • Users may perceive the protocol as inactive or ineffective.

Recommendations

  1. Reward Distribution Fix:

    • Allow emission increases up to a global cap to ensure that rewards can be distributed effectively.

    • Implement an emergency override for growth phases to adapt to changing conditions.

  2. TWAP Fix:

    • Initialize periods with historical or baseline weights to ensure meaningful calculations from the start.

    • Consider adding a warm-up period for new gauges to gradually adjust to their expected weights.

Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

BaseGauge constructor initializes votingPeriod with value=0, causing updatePeriod to always calculate avgWeight=0, permanently breaking time-weighted average tracking

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

BaseGauge constructor initializes votingPeriod with value=0, causing updatePeriod to always calculate avgWeight=0, permanently breaking time-weighted average tracking

Support

FAQs

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