Skip to content
Smart contracts Audit finding Advanced

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.

AnomX Follow with KupiaSec

Originally disclosed on Sherlock

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:

  1. _checkpoint_gauge() function was last invoked at timestamp A.
  2. After certain time passed(timestamp B), admin invokes add_gauge() to add new gauge.
  3. 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 of add_gauge() function. This is possible, since the protocol is deployed on Ethereum. Then following happens:
    • add_gauge() will initialize as self.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 as specific_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, since t = block.timestamp.
  4. After certain time passed, _checkpoint_guage() is invoked and weighted_emissions_per_gauge[gauge] = (specific_emissions - self.specific_emissions_per_gauge[gauge]) * aw // 10**18. Here, specific_emissions is current value and self.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

VYPER
    @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)
VYPER
    @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.

The original report as published on Sherlock, by AnomX. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. The global emissions counter was last checkpointed at an earlier timestamp.
  2. Later the admin adds a new gauge, which copies the stale global counter as that gauge's baseline.
  3. 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.
  4. 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.

More by AnomX

View all

1 more disclosed report, best first.

More from Yield Basis

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.