Skip to content
Business logic Audit finding Intermediate

Bribe Rewards Not Collected In Current Period Will Be Lost Forever

Bribe rewards not collected in the current epoch are not carried forward and are lost forever. An attacker could cause this by simply not triggering the distribution, but the impact is limited to the uncollected tokens.

xiaoming90 Follow

Originally disclosed on Code4rena

Submitted by xiaoming90

It was observed that if the bribe rewards are not collected in the current period, they will not be accrued to future epoch, and they will be lost forever.

Proof-of-Concept

When a briber adds in a new bribe reward, the reward information are stored in the Bribe.tokenRewardsPerEpoch mapping. This mapping stored the number of rewards tokens per epoch.

Assume that a briber adds 100 DAI token as bribe reward in epoch 0 (current epoch), they will be stored in:

tokenRewardsPerEpoch[DAI][Epoch0+1(Bribe Lag)] = 100 DAI tokens

Bribe.sol#L41

function notifyRewardAmount(address token, uint amount) external lock {
    require(amount > 0);
    if (!isReward[token]) {
        require(rewards.length < MAX_REWARD_TOKENS, "too many rewards tokens");
    }
    // bribes kick in at the start of next bribe period
    uint adjustedTstamp = getEpochStart(block.timestamp);
    uint epochRewards = tokenRewardsPerEpoch[token][adjustedTstamp];

    _safeTransferFrom(token, msg.sender, address(this), amount);
    tokenRewardsPerEpoch[token][adjustedTstamp] = epochRewards + amount;

    if (!isReward[token]) {
        isReward[token] = true;
        rewards.push(token);
        IGauge(gauge).addBribeRewardToken(token);
    }

    emit NotifyReward(msg.sender, token, adjustedTstamp, amount);
}

The Voter.distribute()function only allows users to distribute the bribe rewards in the current epoch. Calling theVoter.distribute function will in turn trigger the Gauge.deliverBribes function.

In the Gauge.deliverBribes function, the code uint bribeStart = block.timestamp - (block.timestamp % (7 days)) + BRIBE_LAG; will always return the start date of current epoch + BRIBE_LAG (1 day). So, if someone call Gauge.deliverBribes in epoch 1, the bribeStart variable will be set to the Epoch 1 + 1 day. Due to the above method of fetching bribe rewards and the use of per epoch’s reward mapping, there is no way to fetch the bribe rewards in the previous epoch(s).

Assume that no one triggered the Voter.distribute() in epoch 0, the 100 DAI tokens bribe rewards will be lost forever.

Gauge.sol#L173

uint internal constant BRIBE_LAG = 1 days;

function deliverBribes() external lock {
    require(msg.sender == voter);
    IBribe sb = IBribe(bribe);
    uint bribeStart = block.timestamp - (block.timestamp % (7 days)) + BRIBE_LAG;
    uint numRewards = sb.rewardsListLength();

    for (uint i = 0; i < numRewards; i++) {
        address token = sb.rewards(i);
        // @audit - This will transfer the bribe reward token from the Bribe contract to Gauge contract
        uint epochRewards = sb.deliverReward(token, bribeStart);
        if (epochRewards > 0) {
        	// @audit - Update the reward rate accordingly
            _notifyBribeAmount(token, epochRewards, bribeStart);
        }
    }
}

Recommended Mitigation Steps

Devise a new implementation to allow bribe rewards not collected to be accured to future epochs so that the bribe rewards will not be lost. Consider referencing the Solidy’s Bribe contract, which support these requirements.

pooltypes (Velodrome) acknowledged and commented:

Assume that no one triggered the Voter.distribute() in epoch 0

Voter.distribute() will always be called as users will have the economic incentive to.

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

Given some other submissions in the contest, I believe this finding to be valid, however, the impact is contingent on:

  • Nobody calling deliverBribes through the voter
  • the impact is limited to those tokens

For those reasons Medium Severity is more appropriate.


The original report as published on Code4rena, by xiaoming90. 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

The bribe rewards are stored per epoch and the distribution function only looks at the current epoch, so unclaimed rewards from past epochs are never transferred or accrued.

Impact

Uncollected bribe rewards from past epochs are permanently lost, but only if no one triggers distribution during that epoch; the impact is limited to those tokens.

What the attacker needed

No one calls Voter.distribute() in the epoch

The fix

The bribe contract should be modified to accrue uncollected rewards to future epochs, similar to Solidly's implementation.

How it was found

  1. A briber adds 100 DAI as a bribe reward in epoch 0, which is stored for epoch 1 due to a one-day lag.
  2. No one calls Voter.distribute() during epoch 0.
  3. In epoch 1, calling Voter.distribute() only looks for rewards in epoch 1, so the epoch 0 rewards are never collected.
  4. The 100 DAI bribe rewards are lost forever.

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.

In this system, people add reward tokens (bribes) to encourage votes. These rewards are only available during a specific time window. If nobody collects them during that window, they are not saved for later and disappear permanently. This is a design flaw because rewards should roll over to future periods.

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 xiaoming90

View all

122 more disclosed reports, best first.

More from Velodrome Finance contest

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.