M-1: `BonusDistributor.finalize_period` can permanently brick all calls to `claim` for the related period
Description:
BonusDistributor's constructor initializes growth_rate_cap to BPS_PRECISION. However, BonusDistributor.set_growth_rate_cap enforces an upper bound of BPS_PRECISION * 4 // 5 on any future update.
Within BonusDistributor.finalize_period, the cap is applied to the growth_factor and the bonus token price is adjusted accordingly. With the default growth_rate_cap set to BPS_PRECISION, the local growth_rate_cap evaluates to PRECISION, allowing growth_factor to be capped at 2 * PRECISION. When this upper cap is hit, adjusted_price evaluates to 0, and is then stored in self.parameters[period] as the period's bonus_price.
This condition is reached whenever the ratio between the current ema_revenue and the previous one is greater than or equal to 2, which can occur in two scenarios:
- A period reports zero revenue. Subsequent periods will set
prev_ema_revenueto1, causinggrowth_factorto be saturated at the cap as soon as any non-trivial revenue is reported. - A revenue period whose smoothed revenue is at least double that of the previous one is encountered.
Once adjusted_price is stored as 0, every subsequent call to BonusDistributor.claim for that period reverts due to division by zero. Because claim iterates sequentially through periods starting from self.pending_claims[_team] and updates the cursor only at the end of the loop, all teams whose claim cursor has not yet advanced past the affected period are unable to claim any bonus, including for any subsequent period.
Impact:
Medium. All bonus claims for affected teams are bricked until management intervenes.
Recommendation:
Initialize growth_rate_cap in the constructor to the same maximum value enforced by set_growth_rate_cap (80%):
@@ -102,7 +102,7 @@
self.management = msg.sender
self.operator = msg.sender
self.smoothing_factor = PRECISION
- self.growth_rate_cap = BPS_PRECISION
+ self.growth_rate_cap = BPS_PRECISION * 4 // 5
self.bonus_factor = BPS_PRECISION
This ensures that 2 * PRECISION - growth_factor cannot evaluate to 0 and that adjusted_price remains strictly positive for any oracle price greater than zero.
Developer Response:
Fixed in 022243c.