Bribe Rewards Struck In Contract If Deposited During First Epoch
Bribe rewards deposited during the first epoch are stored under a timestamp that can never be claimed because the distribution function only looks at the current epoch's start. An attacker could cause tokens to be permanently stuck by adding rewards early, though the report frames it as a bug rather than an attack.
Originally disclosed on Code4rena
Submitted by xiaoming90
Bribe rewards added to the Bribe contract in the first epoch will not be claimable by any voters, and the rewards will struck in the Bribe contract.
Proof-of-Concept
Assume that the current epoch is epoch 0, and start date of epoch 0 is Day 0.
When a briber adds a new rewards by calling Bribe.notifyRewardAmount(), the Bribe.getEpochStart() will return the start date of current epoch (epoch 0) + 1 day (Bribe Lag)
Thus, adjustedTstamp will be set to Day 1. tokenRewardsPerEpoch[token][adjustedTstamp] will evaluate to tokenRewardsPerEpoch[DAI][Day 1] and the briber’s rewards will be stored in tokenRewardsPerEpoch[DAI][Day 1]
function getEpochStart(uint timestamp) public view returns (uint) {
uint bribeStart = timestamp - (timestamp % (7 days)) + BRIBE_LAG;
uint bribeEnd = bribeStart + DURATION - COOLDOWN;
return timestamp < bribeEnd ? bribeStart : bribeStart + 7 days;
}
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);
}
On Day 6, the voting phase has ended and the state is currently in the reward phase. Alice decided to call the Voter.distribute to trigger the distribution of bribe rewards.
However, the main issue is that calling the Voter.distribute function on Epoch 0’s Day 6 (Reward Phase) will not executed theGauge.deliverBribes() because claimable[_gauge] or _claimable is currently 0.
Gauge.deliverBribes() is the main function responsible for distributing bribe rewards. Since Gauge.deliverBribes() cannot be triggered, the bribe rewards are forever struck in the Bribe Contract.
claimable[_gauge] will always be zero on the first epoch because the gauge rewards will only come in the later epoch. The value ofclaimable[_gauge] will only increase when the Minter.update_period() function starts minting VELO and distribute them to the gauges. Per the source code of Minter contract, the VELO emission will only start from third epoch onwards (active_period = ((block.timestamp + (2 * WEEK)) / WEEK) * WEEK;). Thus, before the VELO emission, claimable[_gauge]will always remain at 0.
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();
}
}
If someone attempt to call Voter.distribute() on epoch 1 or subsequent epoch, it will fetch the bribe rewards in their respective epoch.
In the Gauge.deliverBribes function, the code uint bribeStart = block.timestamp - (block.timestamp % (7 days)) + BRIBE_LAG; will calculate 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, which is equivalent to Day 9. There is no way to fetch the bribe rewards struck in epoch 0.
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 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;
}
Recommended Mitigation Steps
Implement logic to handle the edge case where bribe rewards are added during first epoch. Consider aligning the start of bribe period with VELO emission period.
pooltypes (Velodrome) acknowledged
Alex the Entreprenerd (judge) commented:
The warden has shown how tokens can be stuck in the Bribes Contract indefinitely.
This is because bribes can be added at the beginning (day 0), while rewards can be received only after a delay (7 days), due to the need for a minimum amount of rewards to be available in order for bribes to be claimable, the logic will prevent the bribes deposited on day 0 to be claimable.
I’m conflicted on the severity as technically this can only happen for the first week, however the loss of tokens is irreversible as there’s no code that would allow rescuing them.
On further consideration, because the deployment of new Bribes and Gauges is mostly permissioneless, this bug will be present for every new pair of deployed contract, and it is highly likely that a new protocol would want to add rewards immediately.
For those reasons, I believe High Severity to be 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 bribe reward timestamp is calculated as the start of the current epoch plus a one-day lag, but the distribution function only fetches rewards for the current epoch's start, so rewards stored for the first epoch's start are never retrieved.
Impact
Bribe rewards added during the first epoch are permanently stuck in the contract, and this could happen for every new pair of deployed contracts.
What the attacker needed
Bribe rewards added during first epoch; no VELO emission yet
The fix
The code should handle the edge case where bribe rewards are added during the first epoch, for example by aligning the start of the bribe period with the VELO emission period.
How it was found
- A briber calls notifyRewardAmount during epoch 0, which stores the reward under the timestamp for day 1.
- On day 6 of epoch 0, calling Voter.distribute does not trigger Gauge.deliverBribes because claimable is zero.
- In later epochs, Gauge.deliverBribes calculates the bribe start as the current epoch plus one day, so it never looks back at epoch 0's stored rewards.
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.
This is a smart contract bug where rewards added at the very beginning of a new system get locked forever. The code that hands out rewards only checks the current week, so anything saved for the first week is never looked at again.
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.