Submitted by hyh, also found by smiling_heretic, unforgiven, and xiaoming90
Any user balance affecting action, i.e. deposit, withdraw/withdrawToken or getReward, calls _writeCheckpoint to update the balance records used for the earned reward estimation. The issue is that _writeCheckpoint always sets false to voted flag for the each new checkpoint due to wrong index used in the mapping access, while only voted periods are eligible for accruing the rewards.
This way any balance changing action of a voted user will lead to stopping of the rewards accrual for the user, until next vote will be cast. I.e. any action that has no relation to voting and should have only balance change as the reward accruing process impact, in fact removes any future rewards from the user until the next vote.
Setting the severity to be high as the impact here violates system logic and means next periods accrued rewards loss for a user.
_writeCheckpoint adds a new checkpoint if block.timestamp is not found in the last checkpoint:
Gauge.sol#L302-L313
However, instead of moving vote status from the previous checkpoint it records false to prevVoteStatus all the time as last status is checkpoints[account][_nCheckPoints-1].voted, while checkpoints[account][_nCheckPoints] isnt created yet and is empty:
Gauge.sol#L309
Notice that checkpoints is a mapping and no range check violation happens:
Gauge.sol#L74-L75
This will effectively lead to rewards removal on any user action, as earned() used in rewards estimation counts only voted periods:
Gauge.sol#L483-L502
I.e. if a user has voted, then performed any of the operations that call _writeCheckpoint update: deposit, withdraw/withdrawToken or getReward, then this user will not have any rewards for the period between this operation and the next vote as all checkpoints that were created by _writeCheckpoint will have voted == false.
Update the index to be _nCheckPoints-1:
https://github.com/code-423n4/2022-05-velodrome/blob/7fda97c570b758bbfa7dd6724a336c43d4041740/contracts/contracts/Gauge.sol#L309
pooltypes (Velodrome) disputed
Alex the Entreprenerd (judge) commented:
