If user merges their `veNFT`, they'll lose part of their rewards
When a user merges their veNFT, the source token is burned, but rewards for the current week are not yet claimable due to a one-week lag in the rewards distributor. As a result, the user loses at least one week of rewards.
Audinarey Follow with bughuntoor, dandan and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/235
Found by
Audinarey, bughuntoor, dandan, sonny2k
Summary
If user merges their veNFT, they'll lose part of their rewards
Vulnerability Detail
When users claim rewards, they can at most claim up to the week before last_token_time.
for (uint i = 0; i < 50; i++) {
if (week_cursor >= _last_token_time) break;
And given that last_token_time can at most be this week, this means that rewards in the RewardsDistributor are lagging at least a week at a time.
Then, if we look at the code of merge we'll see that the from token is actually burned.
function merge(uint _from, uint _to) external {
require(attachments[_from] == 0 && !voted[_from], "attached");
require(_from != _to);
require(_isApprovedOrOwner(msg.sender, _from));
require(_isApprovedOrOwner(msg.sender, _to));
LockedBalance memory _locked0 = locked[_from];
LockedBalance memory _locked1 = locked[_to];
uint value0 = uint(int256(_locked0.amount));
uint end = _locked0.end >= _locked1.end ? _locked0.end : _locked1.end;
locked[_from] = LockedBalance(0, 0);
_checkpoint(_from, _locked0, LockedBalance(0, 0));
_burn(_from);
_deposit_for(_to, value0, end, _locked1, DepositType.MERGE_TYPE);
}
Since claim requires msg.sender to be approved or owner, because the token is burned, they won't be able to claim the rewards.
Any time a user merges their veNFT, they'll lose at least 1 week of rewards.
Impact
Loss of funds
Code Snippet
Tool used
Manual Review
Recommendation
Do not burn the token
Discussion
nevillehuang
Note, please consider not making an escalation for the following issues and duplicates as I will make a self escalation to avoid a long drawn out escalation on multiple different issues. For any issues relating to duplicates of this issue, please leave comments here so we can aggregate comments and reconsider validity.
- Most issues are likely invalid, user error, they can simply claim before withdrawing/merging, similar to this issue highlighted here
- #235 and #236 makes the only valid point that the current week rewards are lost as rewards are lagging by one week, and is the only one that mentions the valid attack path, so I believe it is the only issue that is valid.
- #170, #367, #606, #682 - Some has good PoCs, but unfortunately, does not identify the attack path mentioned in point 1 above
- #236 - Valid, but would consider dupe of #235 because it has the same root cause per sherlock duplication guidelines and mentioned the lagging rewards
nevillehuang
Escalate as per comments above and as discussed here
sherlock-admin3
Escalate as per comments above and as discussed here
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
sonny2k
Pointing out 1 week of lagging rewards seems like it's more of Impact elaboration rather than Attack Path elaboration itself, just more detailed than other issues as other issues simply state unclaimed rewards are lost. I think this impact elaboration is obvious, as long as the rewards are not claimed before calling merge/withdraw, the lost unclaimed rewards will be in the range of [1 week - 51 weeks]. Making this issue not so different from its dups, just more specific on the impact ofc. So if this issue is valid then all of its dups should be also valid IMO. BTW thanks for your hard work @nevillehuang! Your work judging this contest is truly sonorous.
0xklapouchy
@nevillehuang
Correct me if I'm wrong, but due to the rewards lagging by one week, when using the merge (the current week’s rewards from one tokenId are transferred to another tokenId), the rewards are actually moved to the new tokenId. There is no reward loss for the current week. (rewards can even increase if to tokenId has a longer endTime).
Rewards are calculated based on the balanceOf at each week_cursor, with no rewards calculations occurring in between. The lock in the VotingEscrow is also based on weeks, so you can’t withdraw() before the entire week has passed.
Therefore, the assumption that current week rewards are lost is invalid.
Based on the issue discussed at https://github.com/sherlock-audit/2024-06-magicsea-judging/issues/283, you should either invalidate all issues and classify them as Low, or determine that all of them are valid.
spacegliderrrr
Statement above is incorrect. When merging, current week’s rewards are not transferred to new token.
During week N, user can claim rewards up to week N - 1, based on their balance at the beginning of week N - 1. Rewards for week N will be lost, as the token will be burned, and the new tokenId will receive the amount after the week has started (so the amount will be accounted for from the next week onward)
nevillehuang
- I disagree that the precondition for attack path is not important, because without it, I would have invalidate all issues as user error since without me actually going and find the actual vulnerability path myself, there was no way I would have known that rewards of a lagging week will be lost
- Regarding @0xklapouchy claims, I would need more code/example logic to determine if it is correct. From my understanding since the
_burnwas first invoked here, the rewards will be lost .
cvetanovv
I agree with @sonny2k comment. All duplicates have stated a root cause, and it is that rewards are lost when merging and withdrawing.
They have also pointed out the impact: reward will be lost.
Because the escalation is from Lead Judge for discussion purposes and this issue will remain valid, I plan to reject the escalation but duplicate #170, #367, #606, and #682 with this issue.
WangSecurity
Result: High Has duplicates
sherlock-admin4
Escalations have been resolved successfully!
Escalation status:
- nevillehuang: rejected
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/24
spacegliderrrr
Fix looks good. Upon burning a token, the last owner is saved in mapping, which later the RewardsDistributor and Bribe check.
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
The merge function burns the source token, but the rewards distributor lags by one week, so unclaimed rewards for the current week become unclaimable.
Impact
Users lose at least one week of rewards when merging their veNFT.
What the attacker needed
User owns a veNFT with unclaimed rewards; user merges the veNFT into another
The fix
The protocol team fixed this issue by saving the last owner of a burned token so that rewards can still be claimed.
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 veNFT is a token that locks up cryptocurrency for a period and earns rewards over time. When you merge two such tokens, the old one is destroyed, but the system only lets you claim rewards up to the previous week, so the rewards for the current week are lost.
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.