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.
The problematic line of code is as follows:
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.
Initialization:
Period starts at T=0 with weight=0.
First update occurs at T=7 days with weight=5000.
TWAP Calculation:
Result:
The first period shows a TWAP of 0.
Rewards are distributed as if the protocol is inactive.
To resolve this issue, the initialization should use a reasonable default weight:
Where INITIAL_WEIGHT
could be:
Historical average from similar gauges.
Protocol-wide baseline (e.g., 1000).
Reward Distribution:
Frozen emissions lead to insufficient incentives, resulting in user attrition.
Users may disengage from the protocol due to lack of rewards.
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.
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.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.