The incorrect initialize of `specific_emissions_per_gauge` in `GaugeController::add_gauge()`
When a new gauge is added, its per-gauge emissions baseline is set from a stale global value that was last updated at an earlier checkpoint. A voter who votes for the new gauge in the same block as its addition causes the gauge to later credit emissions from before it existed, so the new gauge receives excess YB emissions.
Source: https://github.com/sherlock-audit/2025-08-yield-basis-judging/issues/350
Found by
AnomX, KupiaSec
Summary
When new gauge is added to GaugeController the specific_emissions_per_gauge is initialized by self.specific_emissions, which is stale data.
GaugeController updates the specific_emissions via _checkpoint_gauge(). The _checkpoint_gauge() function calculates the d_emissions with adjusted_gauge_weightand adjusted_gauge_weight_sum, which was updated at last update. Then specific_emissions is increased by d_emissions / aw_sum.
The issue arises from specific_emissions is not updated when new gauge is added. This makes possible to take excess YB emissions. Let's consider following scenario:
_checkpoint_gauge()function was last invoked at timestamp A.- After certain time passed(timestamp B), admin invokes
add_gauge()to add new gauge. - At the moment, user who holding voting power invokes
vote_for_gauge_weights()to vote new gauge. The main point is that user should vote new gauge in same block ofadd_gauge()function. This is possible, since the protocol is deployed on Ethereum. Then following happens:add_gauge()will initialize asself.specific_emissions_per_gauge[gauge] = self.specific_emissions.vote_for_gauge_weights()will invoke_checkpoint_gauge()for new gauge._checkpoint_guage()updates the state, such asspecific_emissions, to timestamp B.- However,
_checkpoint_guage()function doesn't update gauge state(self.weighted_emissions_per_gauge[gauge],self.specific_emissions_per_gauge[gauge]) to timestamp B, since it can't pass check:if block.timestamp > t. Voting for new gauge in same block makes the function not pass this check, sincet = block.timestamp.
- After certain time passed,
_checkpoint_guage()is invoked andweighted_emissions_per_gauge[gauge] = (specific_emissions - self.specific_emissions_per_gauge[gauge]) * aw // 10**18. Here,specific_emissionsis current value andself.specific_emissions_per_gauge[gauge]is the value of timestamp A. The YB amount should be value of between timestamp B to current time. But this also involves timestamp A to timestamp B.
As result, new gauge take excess YB emission.
Root Cause
@external
def add_gauge(gauge: address):
"""
@notice Add gauge `gauge`
@param gauge Gauge address
"""
ownable._check_owner()
assert self.time_weight[gauge] == 0, "Gauge already added"
n: uint256 = self.n_gauges
self.n_gauges = n + 1
self.gauges[n] = gauge
self.time_weight[gauge] = block.timestamp
>> self.specific_emissions_per_gauge[gauge] = self.specific_emissions
log NewGauge(addr=gauge)
@internal
def _checkpoint_gauge(gauge: address) -> Point:
assert self.time_weight[gauge] > 0, "Gauge not alive"
adjustment: uint256 = min(staticcall Gauge(gauge).get_adjustment(), 10**18)
t: uint256 = self.time_weight[gauge]
w: uint256 = self.gauge_weight[gauge]
aw: uint256 = self.adjusted_gauge_weight[gauge]
w_sum: uint256 = self.gauge_weight_sum
aw_sum: uint256 = self.adjusted_gauge_weight_sum
pt: Point = self._get_weight(gauge)
self.point_weight[gauge] = pt
w_new: uint256 = pt.bias
aw_new: uint256 = w_new * adjustment // 10**18
self.gauge_weight[gauge] = w_new
self.gauge_weight_sum = w_sum + w_new - w
self.adjusted_gauge_weight[gauge] = aw_new
self.adjusted_gauge_weight_sum = aw_sum + aw_new - aw
>> d_emissions: uint256 = extcall TOKEN.emit(self, unsafe_div(aw_sum * 10**18, w_sum))
self.time_weight[gauge] = block.timestamp
specific_emissions: uint256 = self.specific_emissions + unsafe_div(d_emissions * 10**18, aw_sum)
if d_emissions > 0:
self.specific_emissions = specific_emissions
>> if block.timestamp > t: # Guaranteed to have no new emissions if same time
self.weighted_emissions_per_gauge[gauge] += (specific_emissions - self.specific_emissions_per_gauge[gauge]) * aw // 10**18
self.specific_emissions_per_gauge[gauge] = specific_emissions
return pt
Internal pre-conditions
Admin tries to add new gauge to GaugeController.
External pre-conditions
Attack Path
Explained above.
Impact
Medium: New gauge can take excess YB emission.
Mitigation
When adding new gauge, initialize with updated specific_emissions.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the new gauge's baseline is initialised from the global emissions counter without first checkpointing it to the current block, so the baseline lags behind the value used later in the payout calculation.
Impact
The new gauge could take excess YB emissions, rated medium by the finder.
What the attacker needed
Admin adds a new gauge; voter votes for it in the same block; attacker holds voting power
The fix
When adding a gauge, the baseline should be initialised from an up-to-date emissions value rather than the stale stored one.
How it was found
- The global emissions counter was last checkpointed at an earlier timestamp.
- Later the admin adds a new gauge, which copies the stale global counter as that gauge's baseline.
- In the same block a holder of voting power votes for the new gauge, which checkpoints the global counter but skips the per-gauge update because the timestamp check fails.
- At a later checkpoint the gauge is credited using the current global counter minus the stale baseline, including time before the gauge existed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A gauge is a staking pool that receives token rewards. The contract tracks a running total of emissions and remembers a starting number for each gauge so it can pay out only what accrued since that gauge was added. Here the starting number was copied from an old, not-yet-refreshed total, so the new gauge was paid for time before it existed.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.