When migrating the owner users will lose their rewards
When a user migrates their vesting position to a new owner after losing their private key, the rewards belonging to the old owner are updated on the old account and cannot be claimed, resulting in a loss of rewards.
Source: https://github.com/sherlock-audit/2023-12-truflation-judging/issues/80
Found by
0xmystery, Bauer, IllIllI, Krace, VAD37, ZdravkoHr., dany.armstrong90, mstpr-brainbot, s1ce
Summary
When a user migrates the owner due to a lost private key, the rewards belonging to the previous owner remain recorded in their account and cannot be claimed, resulting in the loss of user rewards.
Vulnerability Detail
According to the documentation, migrateUser() is used when a user loses their private key to migrate the old vesting owner to a new owner.
/**
* @notice Migrate owner of vesting. Used when user lost his private key
* @dev Only admin can migrate users vesting
* @param categoryId Category id
* @param vestingId Vesting id
* @param prevUser previous user address
* @param newUser new user address
*/
In this function, the protocol calls migrateVestingLock() to obtain a new ID.
if (lockupId != 0) {
newLockupId = veTRUF.migrateVestingLock(prevUser, newUser, lockupId - 1) + 1;
lockupIds[categoryId][vestingId][newUser] = newLockupId;
delete lockupIds[categoryId][vestingId][prevUser];
newVesting.locked = prevVesting.locked;
}
However, in the migrateVestingLock() function, the protocol calls stakingRewards.withdraw() to withdraw the user's stake, burning points. In the withdraw() function, the protocol first calls updateReward() to update the user's rewards and records them in the user's account.
function withdraw(address user, uint256 amount) public updateReward(user) onlyOperator {
if (amount == 0) {
revert ZeroAmount();
}
_totalSupply -= amount;
_balances[user] -= amount;
emit Withdrawn(user, amount);
}
However, stakingRewards.withdraw() is called with the old owner as a parameter, meaning that the rewards will be updated on the old account.
uint256 points = oldLockup.points;
stakingRewards.withdraw(oldUser, points);
_burn(oldUser, points);
As mentioned earlier, the old owner has lost their private key and cannot claim the rewards, resulting in the loss of these rewards.
Impact
The user's rewards are lost
Code Snippet
Tool used
Manual Review
Recommendation
When migrating the owner, the rewards belonging to the previous owner should be transferred to the new owner.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
0xLogos commented:
loss of private key is extreme case, so i think better do not add additional complexity to the code
ryuheimat
https://github.com/truflation/truflation-contracts/pull/10
Added to param to getReward function, and call it when migrating.
nevillehuang
@securitygrid I considered the same exact point during judging, but considering the protocol has an explicit function just to migrate users for private keys, this constitute at the very least medium for me, because it is intended protocol functionality to fully migrate users position.
If not, why not say the vested position is also users responsibility too, so I think your argument is moot.
securitygrid
Escalate Loss of the private key should be an uncommon scenario. Therefore the problem should be M.
sherlock-admin2
Escalate Loss of the private key should be an uncommon scenario. Therefore the problem should be M.
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.
nevillehuang
Since this directly contradicts the intended functionality of the function of transferring ALL of the users intended vested position and rewards, which means likely a definite loss of funds for them, I think this should remain high severity.
Czar102
This is a backup mechanism, and users won't intentionally lose their private keys because the funds can be retrieved.
I'd classify it as a loss of intended functionality and not a loss of funds (because the funds can still be used by the pre-migration address owner), hence planning to consider this a medium severity issue.
nevillehuang
@Czar102 I don't understand your following statement, if they lose their private keys how can they use the funds? Whatever it is I will take it into account the special case of losing private keys in the future.
because the funds can still be used by the pre-migration address owner
Czar102
I understand the confusion. The past owner remains the owner of the funds. I detached the address identity (with whoever may still own it, even if it's no one) from the new owner.
sleepriverfish
@Czar102 Both users who lost their private keys and the new owner are unable to use these funds.
Czar102
@sleepriverfish I'm not following. From my understanding, the report states that the rewards are sent to the old address.
nevillehuang
@Czar102 For your info, I still don’t get what your are pointing to, but I accept the severity downgrade only because of my own understanding that private key loss is an exceptional case
Czar102
Result: Medium Has duplicates
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- securitygrid: accepted
mstpr
Fix LGTM
ryuheimat
Merged
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 migration function calls the staking rewards withdrawal with the old user address, which updates and records rewards on the old account instead of transferring them to the new owner.
Impact
The user's rewards are lost.
What the attacker needed
User loses private key; admin initiates migration
The fix
The migration should transfer the previous owner's rewards to the new owner; a fix was later merged that added a recipient parameter to the reward function and called it during migration.
How it was found
- A user loses their private key and requests migration to a new owner.
- The admin calls migrateUser, which calls migrateVestingLock.
- migrateVestingLock calls stakingRewards.withdraw with the old user address.
- The withdraw function updates rewards for the old user, recording them on the old account.
- The old user cannot claim the rewards because they lost their private key.
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 user can move their locked tokens to a new address if they lose their private key. However, any rewards earned before the move stay tied to the old address, which the user can no longer access. So the user loses those rewards.
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.