Rewards can be locked in Bribe contract because distributing them depends on base token reward amount and Gauge.deliverBribes() is not always called by Voter.distribute()
The Voter.distribute() function only calls Gauge.deliverBribes() when the gauge's base token claimable amount divided by DURATION is greater than zero. If new bribe rewards are added but that condition is false, those rewards remain stuck in the Bribe contract.
Originally disclosed on Code4rena
Submitted by unforgiven
Voter.distribute() calls Gauge.deliverBribes() if claimable[_gauge] / DURATION > 0 was True and claimable[_gauge] shows base token rewards for gauge. Gauge.deliverBribes() calls Bribe.deliverReward() which transfers the rewards to Gauge. so for Bribe rewards to been transferred and distributed claimable[_gauge] / DURATION > 0 most be True and if there was some new rewards in Bribe and that condition is not True then those rewards will stuck in Bribe contract.
Proof of Concept
This is Voter.distribute() code:
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();
}
}
As you can see IGauge(_gauge).deliverBribes(); is inside and if which checks _claimable / DURATION > 0 for that Gauge. Bribe is transferring rewards in Bribe.deliverReward() which is called by Gauge.deliverBribes() and it is called by Voter.distribute() if some base token claimable amount of that Gauge is bigger than DURATION, so if this condition isn’t true, then rewards in Bribe for that epoch will stuck in Bribe.
Voter.distribute() can be called multiple times in each time claimable[_gauge] will set to 0 so if Bribe rewards was after that call then those rewards will stuck in Bribe for sure.
Tools Used
VIM
Recommended Mitigation Steps
Move the line IGauge(_gauge).deliverBribes(); out of If in Voter.distribute().
pooltypes (Velodrome) disputed
Alex the Entreprenerd (judge) invalidated and commented:
It seems to me like the finding is invalid.
The check will check if the gauge has any rewards left (via
IGauge(_gauge).left(base)) (*claimable > IGauge(*gauge).left(base) && _claimable / DURATION > 0) {And the
_claimable / DURATIONis checking that the amount is more than a dust amount, as in there’s more than 1 wei of token per second.Given the information that I have, in lack of a coded POC that shows and quantifies the amount of tokens stuck, I believe the finding to be invalid.
Alex the Entreprenerd (judge) set severity to Medium and commented:
After further review of various findings from the contest, another warden has submitted a convincing POC that shows that this indeed is an enactable vulnerability.
However, in this finding the warden hasn’t shown how the Bribe rewards could be lost.
Because of that, 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 call to deliverBribes() is placed inside a conditional block that checks the base token reward amount, so bribe distribution is skipped when that amount is too small or zero.
Impact
Bribe rewards could become permanently stuck in the Bribe contract if the base token claimable amount does not meet the condition when distribute() is called.
What the attacker needed
Bribe rewards added when base claimable is low
The fix
The line IGauge(_gauge).deliverBribes(); should be moved outside the if block in Voter.distribute().
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, a 'gauge' distributes rewards to people who vote for it. The 'Voter' contract decides when to send out those rewards. It only sends out 'bribe' rewards if a separate condition about the main token reward is met. If that condition is not met, the bribe rewards stay locked in the Bribe contract and nobody can claim them.
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.