Skip to content
Business logic Audit finding Intermediate

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.

KupiaSec Follow with KupiaSec

Originally disclosed on Code4rena

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:

  1. There are two pools, poolA and poolB, with corresponding gauges gaugeA and gaugeB.

  2. Users vote 50 for each pool individually in the first week: weightsPerEpoch = 50, totalWeightsPerEpoch = 100.

  3. In the second week, users call the distribute function only for poolA, and the minter transfers 100 FNX. Of this, 50 FNX is transferred to gaugeA, while the remaining 50 FNX stays in the contract. At that time, users never call the distribute function for poolB. This situation can occur if the creator of poolB intentionally does not call the distribute function 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.
  4. In this week, users vote 10 for poolA and 90 for poolB individually.

  5. In the third week, users call the distribute function 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:

  1. The main method for distributing to the gaugeі is Voter.distributeAll(), which ensures that no gauge is skipped. In specific scenarios, other methods like Voter.distribute are also available.
  2. 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.
  3. 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.


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

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

  1. Two pools with gauges, users vote equally in week one.
  2. In week two, distribute only for poolA, leaving poolB undistributed.
  3. In week three, users vote differently and distribute for both pools.
  4. 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.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Fenix Finance Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.