# killGauge() will lead to wrong calculation of emission

killGauge() subtracts a gauge's weight from totalWeightsPerEpoch but leaves weightsPerEpoch intact, so reward index math over-allocates emissions and strands funds.

- Payout: Audit contest
- Severity: high
- Program: Fenix Finance
- Found by: Ch\_301
- Disclosed: 2024-10-11
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-09-fenix-finance-findings/issues/8
- Library page: https://bugbountylibrary.com/r/c4%3A2024-09-fenix-finance%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** VoterUpgradeableV2.sol reward distribution / gauge lifecycle
**Root cause:** killGauge() decrements totalWeightsPerEpoch but does not delete weightsPerEpoch for the killed gauge, so notifyRewardAmount() computes index against a reduced weight denominator while _distribute() still reads the stale per-gauge weight.
**Steps:**
1. Setup: three gauges each with weightsPerEpoch[Epoch_x]=500e18, totalWeightsPerEpoch=1500e18, index=10e18, emission amount_=80e18.
2. Governance calls `killGauge(gauge)`; totalWeightsPerEpoch[Epoch_x] becomes 1000e18 but weightsPerEpoch[Epoch_x][pool] stays 500e18.
3. Minter calls `notifyRewardAmount(80e18)`: `index += (80e18*1e18)/1000e18 = 8e16`, index=10.08e18.
4. Call `distribute([g1,g2,g3])`: for each gauge `delta=0.08e18`, `amount=(500e18*0.08e18)/1e18=40e18`.
5. Killed gauge's branch transfers its 40e18 back to minter; remaining gauges over-credit, leaving insufficient emissions for later gauges.
**How found:** Code review of killGauge() state updates versus notifyRewardAmount() index formula and _distribute() weight reads; noticed weightsPerEpoch was not cleared while totalWeightsPerEpoch was decremented, then modeled the arithmetic with a three-gauge example.
**Exploitation:** Governance kills a gauge mid-epoch; the next distribute() over-allocates emissions to surviving gauges and returns the killed gauge's share to the minter, so some gauges receive zero and claimable accounting is wrong; reviving the gauge later lets it claim emissions that were already returned.
**Insight:** When a function removes a participant from a denominator (total weight) but leaves the per-participant numerator mapping intact, the reward index inflates; check every place a weight/denominator is mutated for paired cleanup of the per-entity record.

