Wrong reward distribution in Bribe because deliverReward() won’t set tokenRewardsPerEpoch[token][epochStart] to 0
The Bribe contract's deliverReward function transfers epoch rewards but does not reset the stored reward amount to zero, so repeated calls in the same epoch can transfer the same rewards multiple times. An attacker could trigger multiple distributions by calling notifyRewardAmount to increase the index, causing the gauge to deliver bribes repeatedly and misallocate tokens.
Originally disclosed on Code4rena
Submitted by unforgiven, also found by csanuragjain, pcrypt0, and smilingheretic
Function deliverReward() in Bribe contract won’t set tokenRewardsPerEpoch[token][epochStart] to 0 after transferring rewards. Gauge.getReward() calls Voter.distribute() which calls Gauge.deliverBribes() which calls Bribe.deliverReward(). so if Gauge.getReward() or Voter.distribute() get called multiple times in same epoch then deliverReward() will transfer Bribe tokens multiple times because it doesn’t set tokenRewardsPerEpoch[token][epochStart] to 0 after transferring.
Proof of Concept
This is deliverReward() code in Bribe:
function deliverReward(address token, uint epochStart) external lock returns (uint) {
require(msg.sender == gauge);
uint rewardPerEpoch = tokenRewardsPerEpoch[token][epochStart];
if (rewardPerEpoch > 0) {
_safeTransfer(token, address(gauge), rewardPerEpoch);
}
return rewardPerEpoch;
}
As you can see it doesn’t set tokenRewardsPerEpoch[token][epochStart] value to 0, so if this function get called multiple times it will transfer epoch rewards multiple times (it will use other epoch’s rewards tokens).
function Gauge.deliverBribes() calls Bribe.deliverReward() and Gauge.deliverBribes() is called by Voter.distribute() if the condition claimable[_gauge] > DURATION is True. This is those functions codes:
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);
uint epochRewards = sb.deliverReward(token, bribeStart);
if (epochRewards > 0) {
_notifyBribeAmount(token, epochRewards, bribeStart);
}
}
}
function distribute(address _gauge) public lock {
require(isAlive[_gauge]); // killed gauges cannot distribute
uint dayCalc = block.timestamp % (7 days);
require((dayCalc < BRIBE_LAG) || (dayCalc > (DURATION + BRIBE_LAG)), "cannot claim during votes period");
IMinter(minter).update_period();
_updateFor(_gauge);
uint _claimable = claimable[_gauge];
if (_claimable > IGauge(_gauge).left(base) && _claimable / DURATION > 0) {
claimable[_gauge] = 0;
IGauge(_gauge).notifyRewardAmount(base, _claimable);
emit DistributeReward(msg.sender, _gauge, _claimable);
// distribute bribes & fees too
IGauge(_gauge).deliverBribes();
}
}
also Gauge.getReward() calls Voter.getReward().
condition claimable[_gauge] > DURATION in Voter.distribute() can be true multiple time in one epoch (deliverBribes() would be called multiple times) because claimable[_gauge] is based on index and index increase by notifyRewardAmount() in Voter anytime.
Tools Used
VIM
Recommended Mitigation Steps
Set tokenRewardsPerEpoch[token][epochStart] to 0 in deliverReward.
pooltypes (Velodrome) confirmed and commented:
Thanks, this is an issue we discovered in prod. Issuing a fix soon.
We’re also taking the necessary steps to alert any users who may have funds at risk from this issue.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
tokenRewardsPerEpoch[token][epochStart]is indeed not resetted on each claimProving the finding is reliant on
claimable[_gauge] += _share;which is set in_updateForWhich is contingent on
index += _ratio;innotifyRewardAmountBecause
notifyRewardAmountcan be called by anyone, at the cost of an amount that just needs to be greater than or equal tototalWeight / 1e18which may be a negligible amount, then indeedindexcan increase, allowing the bribe to be called multiple times in one epoch.In terms of impact, because the Bribe contract only allows for an extremely basic, now or in 7 days, type queueing of bribes, the accounting of bribes is mostly unnecessary (as the contract will most of the times be sending all tokens anyway).
Additionally the loss would amount to an incorrect amount of bribes emitted over 7 days instead of 14.
For those reasons, I think Medium Severity to be more appropriate.
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 deliverReward function fails to zero out tokenRewardsPerEpoch[token][epochStart] after transferring, allowing repeated transfers of the same epoch's rewards.
Impact
The bug could cause bribes to be paid out multiple times within an epoch, leading to an incorrect distribution of rewards over 7 days instead of 14, though the judge noted the accounting is mostly unnecessary and the loss is limited.
What the attacker needed
Attacker can call notifyRewardAmount; small token amount to increase index; timing within the same epoch
The fix
Set tokenRewardsPerEpoch[token][epochStart] to 0 in deliverReward after transferring.
How it was found
- Call notifyRewardAmount to increase the index and make claimable[_gauge] exceed DURATION.
- Call Voter.distribute() or Gauge.getReward() to trigger deliverBribes and then deliverReward.
- Repeat the call within the same epoch to transfer the same rewards again.
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 smart contract holds rewards for each week (epoch). When someone claims, the contract sends the rewards but forgets to mark them as paid. If the claim function is called again in the same week, it sends the same rewards again, taking tokens meant for other weeks. This means rewards are paid out too early and in the wrong amounts.
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.