If rewards are not distributed to some gauges in an epoch, it can lead to incorrect rewards distribution in the next epoch
If rewards are not distributed to some gauges in an epoch, the reward index mechanism can miscalculate rewards in the next epoch, leading to over- or under-distribution. An attacker could intentionally skip distribution for a gauge to cause incorrect rewards or a revert.
Submitted by KupiaSec, also found by KupiaSec
Some gauges may receive more rewards, while others may not receive any rewards at all.
Proof of Concept
In the VoterUpgradeableV2.notifyRewardAmount function, the index is accumulated for every reward distribution from the minter. When distributing rewards to gauges, the reward amount is calculated using the delta index and weightsPerEpoch.
uint256 totalVotesWeight = weightsPerEpoch[currentTimestamp - _WEEK][state.pool];
uint256 delta = index - state.index;
if (delta > 0) {
L634: uint256 amount = (totalVotesWeight * delta) / 1e18;
if (state.isAlive) {
gaugesState[gauge_].claimable += amount;
} else {
IERC20Upgradeable(token).safeTransfer(minter, amount);
}
}
If rewards are not distributed to a gauge in the current epoch, they can be distributed in the next epoch. If weightsPerEpoch for that gauge changes in the next epoch, the reward amount may be calculated incorrectly, leading to unfair distribution among the gauges.
Let’s consider the following scenario:
-
There are two pools,
poolAandpoolB, with corresponding gaugesgaugeAandgaugeB. -
Users vote 50 for each pool individually in the first week:
weightsPerEpoch = 50,totalWeightsPerEpoch = 100. -
In the second week, users call the
distributefunction only forpoolA, and the minter transfers 100 FNX. Of this, 50 FNX is transferred togaugeA, while the remaining 50 FNX stays in the contract. At that time, users never call thedistributefunction forpoolB. This situation can occur if the creator ofpoolBintentionally does not call thedistributefunction and other users lack the incentive to call it.index = 100 * 1e18 / 100 = 1e18.- Rewards amount for
gaugeA:50 * 1e18 / 1e18 = 50. gaugesState[gaugeA].index = 1e18.gaugesState[gaugeB].index = 0.
-
In this week, users vote 10 for
poolAand 90 forpoolBindividually. -
In the third week, users call the
distributefunction for both pools, and the minter transfers another 100 FNX.index = index + 100 * 1e18 / 100 = 2e18.- Rewards amount for
gaugeA:10 * 1e18 / 1e18 = 10. - Rewards amount for
gaugeB:90 * 2e18 / 1e18 = 180.
Even though the VoterUpgradeableV2 contract has 150 FNX from the minter, it attempts to transfer 190 FNX to the gauges. As a result, the rewards distribution to the gauges is reverted.
As a result, if rewards are not distributed to some gauges in an epoch, it can lead to incorrect rewards distribution in the next epoch.
Recommended Mitigation Steps
Rewards should be distributed to all gauges per epoch, or the reward index mechanism should be improved.
b-hrytsak (Fenix) acknowledged and commented:
This issue is common for contracts like Voter ve(3,3), and it was also highlighted to us by the Hats audit providers here.
As you can see, we have the following mitigations:
- The main method for distributing to the gaugeі is
Voter.distributeAll(), which ensures that no gauge is skipped. In specific scenarios, other methods likeVoter.distributeare also available.- Although users may be interested in calling these methods, the protocol also itself will handle this process to ensure the protocol’s viability and prevent such cases from occurring. Additionally, a distribution window has been introduced during which these calls should be made.
- Skipping a gauge for an entire epoch is highly unlikely
alcueca (judge) decreased severity to Medium and commented:
While the sponsor seems to be aware of this issue, and have some mitigations prepared, under the audit rules this is a valid finding because it is present in the code and wasn’t disclosed by the sponsor.
Downgraded to Medium since skipping rewards in an epoch would be an unusual precondition.
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 reward index is global and not updated per gauge each epoch, so a skipped gauge's index lags and later uses a mismatched weight.
Impact
Rewards could be unfairly distributed, with some gauges receiving more and others none, or distribution could revert due to insufficient funds.
What the attacker needed
A gauge is skipped for an entire epoch; vote weights change between epochs
The fix
Rewards should be distributed to all gauges each epoch, or the reward index mechanism should be improved.
How it was found
- Two pools with gauges, users vote equally in week one.
- In week two, distribute only for poolA, leaving poolB undistributed.
- In week three, users vote differently and distribute for both pools.
- The calculation for gaugeB uses the accumulated index and new weight, resulting in an amount larger than available, causing a revert.
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 contract that receives rewards based on votes. The system tracks a running total (index) of rewards per vote. If a gauge is skipped in one week, its index stays behind. When it is finally updated later, it uses the new week's vote weight with the old index, so the reward calculation is wrong. This can give too many or too few rewards, or make the distribution fail.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.