Submitted by Ch_301, also found by KupiaSec
https://github.com/code-423n4/2024-09-fenix-finance/blob/main/contracts/core/VoterUpgradeableV2.sol#L239
https://github.com/code-423n4/2024-09-fenix-finance/blob/main/contracts/core/VoterUpgradeableV2.sol#L630-L639
The VoterUpgradeableV2.sol contract has killGauge() that disables the gauge to prevent it from further rewards distribution, only the address with GOVERNANCE_ROLE role can call it.
the killGauge() only updates three state variables.
The distribute() function will distribute rewards to pools managed by the VoterUpgradeableV2.sol contract and it will call the Minter contract by triggering update_period() function before distributing rewards.
The timeline looks like this:
When distribute() gets invoked in the timeline it will distribute the rewards of Epoch_x, The killed gauge has no weight in this epoch because its weight gets subtracted from totalWeightsPerEpoch[] in killGauge().
When the Minter invokes VoterUpgradeableV2.sol#notifyRewardAmount() to notify the contract of the reward amount to be distributed for Epoch_x, we can also find in the same function how the index value gets increased.
The index is updated as the reward amount divided by the total weights of Epoch_x,
we know the weight of the disabled gauge is not included in totalWeightsPerEpoch[Epoch_x].
Back to _distribute():
Because killGauge() doesnt delete the values of weightsPerEpoch[], it will send back amount of emissions back to Minter, which actually should get distributed between the existing pools.
To summarize, the index is directly related by the value of totalWeightsPerEpoch[Epoch_x], and the killGauge() is subtracted from the weightsPerEpoch of the disabled gauge. Therefore, the index didnt include the weight of the killed gauge, but _distribute calculates its emission and sends it back to Minter.
To understand the impact, in case the total emissions for Epoch_x is 80e18 with three active gauges (with the same amount of votes), each pool will receive 26.5e18 tokens.
But in case one gauge gets killed, one scenario is the 1st gauge will receive 40e18 and the other 40e18 will get transferred back to Minter. This will leave the last gauge with 0 emissions (from here, the impact is related to how gauge.sol#.notifyRewardAmount() will handle this situation which is out of scope in this audit).
Another scenario is to send 40e18 to the two gauges but the disabled gauge gets revived in the next epoch and will be able to receive his 40e18 tokens because the gaugesState[gauge_].index is not updated (this will loop us to the above scenario again because the 40e18 tokens do not exist in the first time).
The impact depends on the order of the gauges array that passed to distribute() function.
Lets say now is Epoch_x +1:
Scenario 1: 
No gauge gets disabled and each gauge will receive 26.5e18 tokens as emission.
This is how we calculate it:
Scenario 2:
One gauge gets disabled, so the totalWeightsPerEpoch of Epoch_x is now weightAt = 1000e18.
With the current logic, two gauges each will receive 40e18 tokens as emission and 40e18 should be sent back to Minter; which is larger than the total emission which is 80e18.
This is how we calculate it:
One fix is to delete the weightsPerEpoch[][] in killGauge():
However, the fix should take into consideration how the Minter calculates the emissions for every epoch (is it a fixed value every time or depending on how many gauges are active).
Invalid Validation
b-hrytsak (Fenix) confirmed
alcueca (judge) commented:
