Skip to content
Business logic Audit finding Intermediate

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.

0x37 Follow with 0xNirix, 0xmystery and 9 others

Originally disclosed on Sherlock

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.

https://github.com/sherlock-audit/2024-10-usual-labs-v1/blob/main/pegasus/packages/solidity/src/token/UsualSP.sol#L376

Solidity
        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

  1. removeOriginalAllocation is called on an address that has an active reward allocation.
  2. balanceOf calculation for reward accrual depends on $.originalAllocation.

https://github.com/sherlock-audit/2024-10-usual-labs-v1/blob/main/pegasus/packages/solidity/src/token/UsualSP.sol#L443-L447

Solidity
    function balanceOf(address account) public view override returns (uint256) {
        UsualSPStorageV0 storage $ = _usualSPStorageV0();
        return
            $.liquidAllocation[account] + $.originalAllocation[account] - $.originalClaimed[account];
    }

External pre-conditions

  1. The protocol is running an active reward accrual period.

Attack Path

  1. The operator calls removeOriginalAllocation on a recipient without first updating the reward.
  2. The originalAllocation value for the recipient is reset to zero in storage.
  3. When the recipient calls claimReward, the calculation in _earned references a reduced balanceOf due to originalAllocation == 0, leading to lower rewards.

https://github.com/sherlock-audit/2024-10-usual-labs-v1/blob/main/pegasus/packages/solidity/src/modules/RewardAccrualBase.sol#L136

Solidity
    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.

https://github.com/sherlock-audit/2024-10-usual-labs-v1/blob/main/pegasus/packages/solidity/src/token/UsualSP.sol#L366-L384

Diff
        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

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. The operator calls removeOriginalAllocation on a recipient without first updating the reward.
  2. The originalAllocation value for the recipient is reset to zero in storage.
  3. 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.

More by 0x37

View all

79 more disclosed reports, best first.

More from Usual V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.