A missing reward update in UsualSP::removeOriginalAllocation will cause reduced reward accumulation for users
The removeOriginalAllocation function resets a user's original allocation to zero without first updating their accrued rewards. This causes the user to lose rewards that should have been earned based on the previous allocation.
Source: https://github.com/sherlock-audit/2024-10-usual-labs-v1-judging/issues/16
Found by
0x37, 0xNirix, 0xmystery, Bigsam, KupiaSec, LZ_security, PeterSR, dhank, ke1caM, nirohgo, xiaoming90, zarkk01
Summary
The missing reward update in removeOriginalAllocation will cause a reduction in reward accumulation for users as the contract directly resets the originalAllocation variable without first updating rewards.
Root Cause
In UsualSP.sol:376, the code in the removeOriginalAllocation function resets $.originalAllocation to zero without first updating rewards.
for (uint256 i; i < recipients.length;) {
$.originalAllocation[recipients[i]] = 0;
$.originalClaimed[recipients[i]] = 0;
emit RemovedOriginalAllocation(recipients[i]);
unchecked {
++i;
}
This causes an unintended reward loss as the balanceOf calculation, used for accruing rewards, will reference a reduced allocation amount on subsequent reward claims.
Internal pre-conditions
removeOriginalAllocationis called on an address that has an active reward allocation.balanceOfcalculation for reward accrual depends on$.originalAllocation.
function balanceOf(address account) public view override returns (uint256) {
UsualSPStorageV0 storage $ = _usualSPStorageV0();
return
$.liquidAllocation[account] + $.originalAllocation[account] - $.originalClaimed[account];
}
External pre-conditions
- The protocol is running an active reward accrual period.
Attack Path
- The operator calls
removeOriginalAllocationon a recipient without first updating the reward. - The
originalAllocationvalue for the recipient is reset to zero in storage. - When the recipient calls
claimReward, the calculation in_earnedreferences a reducedbalanceOfdue tooriginalAllocation == 0, leading to lower rewards.
function _earned(address account) internal view virtual returns (uint256 earned) {
RewardAccrualBaseStorageV0 storage $ = _getRewardAccrualBaseDataStorage();
uint256 accountBalance = balanceOf(account);
uint256 rewardDelta = $.rewardPerTokenStored - $.lastRewardPerTokenUsed[account];
earned = accountBalance.mulDiv(rewardDelta, 1e24, Math.Rounding.Floor) + $.rewards[account]; // 1e24 for precision loss
}
Impact
The users experience a reduced reward accumulation as their originalAllocation is zeroed out before updating rewards. This impacts the accuracy of rewards distribution and results in reward loss for affected users.
PoC
No response
Mitigation
Add _updateReward(recipients[i]) in the removeOriginalAllocation function before resetting $.originalAllocation[recipients[i]] = 0. This ensures rewards are fully accrued based on the prior allocation.
for (uint256 i; i < recipients.length;) {
+ _updateReward(recipients[i]);
$.originalAllocation[recipients[i]] = 0;
$.originalClaimed[recipients[i]] = 0;
emit RemovedOriginalAllocation(recipients[i]);
unchecked {
++i;
}
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/usual-dao/pegasus/pull/1729
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 removeOriginalAllocation function resets the originalAllocation to zero without calling _updateReward first, so the reward calculation later uses a reduced balance.
Impact
Users experience a reduced reward accumulation as their originalAllocation is zeroed out before updating rewards, resulting in reward loss for affected users.
What the attacker needed
RemoveOriginalAllocation called on an address with active…; balanceOf calculation for reward accrual depends on…; protocol is running an active reward accrual period
The fix
The protocol team fixed this issue by adding a reward update before resetting the allocation.
How it was found
- The operator calls removeOriginalAllocation on a recipient without first updating the reward.
- The originalAllocation value for the recipient is reset to zero in storage.
- When the recipient calls claimReward, the calculation in _earned references a reduced balanceOf due to originalAllocation == 0, leading to lower 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.
In a reward system, users earn rewards based on how much they have allocated. If the system resets that allocation to zero without first recording the rewards earned so far, the user loses those rewards. This report shows that a function that removes an allocation does exactly that, causing users to get less reward than they should.
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.