Voting overwrites checkpoint.voted in last checkpoint, so users can just vote right before claiming rewards
The gauge's reward calculation checks a 'voted' flag from the last checkpoint, but voting overwrites that flag without creating a new checkpoint. An attacker could vote just before claiming rewards and reset immediately after, receiving full rewards without maintaining a vote for the period.
Originally disclosed on Code4rena
Submitted by smiling_heretic
Gauge.sol#L195 Gauge.sol#L489-L490 Gauge.sol#L499-L500
if (cp0.voted) {
reward += cp0.balanceOf * (_rewardPerTokenStored1 - _rewardPerTokenStored0) / PRECISION;
this line in gauge.earned function looks like the intention here is to incentivize users to keep their escrow.balanceOfNft voted for this gauge.
However, it’s enough to vote just before claiming rewards (even in the same transaction) and voter.reset just after receiving rewards to pass this if and get rewards for full period since last interaction with the gauge.
Proof of Concept
See original submission for test file.
Note, that Bob kept his votes for this gauge for full 6-day period but Alice just voted before claiming rewards. In logs, we can see that they both received the same (non-zero) amount of VELO tokens.
Alice can reset her votes in the same transaction after claiming rewards, if she decides to do so.
Tools Used
Foundry
Recommended Mitigation Steps
A partial solution would be to create a new checkpoint each time user’s voted status changes (setVoteStatus is called) instead of overwriting the voted in last one.
However, even then, users can just assign very small weight to this gauge, and lock very little VELO, so I don’t think this if statement helps with anything. I think, it’s better to rethink how to incentivize users to vote for specific gauges.
pooltypes (Velodrome) acknowledged and commented:
Patched in mainnet deployment.
Alex the Entreprenerd (judge) increased severity to High and commented:
The warden has found a way to sidestep the loss of rewards that automatically happens due to the faulty checkpoint system that always sets voted to false.
In doing so they also showed how the system can fall apart and provided a POC to replicate.
Because I’ve rated issues related to the
votedcheckpoints and loss of rewards with High Severity, at this time I believe this finding should also be bumped as it shows how the system is broken and the way to avoid a loss of rewards.The sponsor seems to have remedied by deleting the voted logic.
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 checkpoint system overwrites the 'voted' status in the last checkpoint instead of creating a new checkpoint when the vote status changes, so the reward calculation cannot tell how long the user actually voted.
Impact
Users could receive full rewards without keeping their votes for the required period, undermining the incentive mechanism.
What the attacker needed
A user with voting power; ability to claim rewards
The fix
The sponsor patched the issue in the mainnet deployment, and the judge noted the voted logic was deleted.
How it was found
- Vote for the gauge just before claiming rewards.
- Claim the rewards, which pass the voted check and pay for the full period.
- Reset the votes immediately after claiming, optionally in the same transaction.
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 gives extra rewards to users who keep their tokens voted for a particular gauge. The contract only checks whether you voted at the last checkpoint, not whether you voted for the whole period. So you can vote right before claiming, get the full reward, and then remove your vote.
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.