Skip to content
Business logic Audit finding Intermediate

StakingRewards.sol#notifyRewardAmount() Improper reward balance checks can make some users unable to withdraw their rewards

The notifyRewardAmount function only checks that the contract's current reward token balance covers the new reward rate, ignoring rewards already owed to users. If the rewards distributor calls it with a larger amount without transferring new tokens, some users may be unable to withdraw their earned rewards.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

StakingRewards.sol#L154-L158

    uint256 balance = rewardsToken.balanceOf(address(this));
    require(
        rewardRate <= balance / rewardsDuration,
        "Provided reward too high"
    );

In the current implementation, the contract only checks if balanceOf rewardsToken is greater than or equal to the future rewards.

However, under normal circumstances, since users can not withdraw all their rewards in time, the balance in the contract contains rewards that belong to the users but have not been withdrawn yet. This means the current checks can not be sufficient enough to make sure the contract has enough amount of rewardsToken.

As a result, if the rewardsDistribution mistakenly notifyRewardAmount with a larger amount, the contract may end up in a wrong state that makes some users unable to claim their rewards.

Proof of Concept

Given:

  • rewardsDuration = 7 days;
  • Alice stakes 1,000 stakingToken;
  • rewardsDistribution sends 100 rewardsToken to the contract;
  • rewardsDistribution calls notifyRewardAmount() with amount = 100;
  • 7 days later, Alice calls earned() and it returns 100 rewardsToken, but Alice choose not to getReward() for now;
  • rewardsDistribution calls notifyRewardAmount() with amount = 100 without send any fund to contract, the tx will succees;
  • 7 days later, Alice calls earned() 200 rewardsToken, when Alice tries to call getReward(), the transaction will fail due to insufficient balance of rewardsToken.

Expected Results:

The tx in step 5 should revert.

Recommended Mitigation Steps

Consider changing the function notifyRewardAmount to addRward and use transferFrom to transfer rewardsToken into the contract:

function addRward(uint256 reward)
    external
    updateReward(address(0))
{
    require(
        msg.sender == rewardsDistribution,
        "Caller is not RewardsDistribution contract"
    );

    if (block.timestamp >= periodFinish) {
        rewardRate = reward / rewardsDuration;
    } else {
        uint256 remaining = periodFinish - block.timestamp;
        uint256 leftover = remaining * rewardRate;
        rewardRate = (reward + leftover) / rewardsDuration;
    }

    rewardsToken.safeTransferFrom(msg.sender, address(this), reward);

    lastUpdateTime = block.timestamp;
    periodFinish = block.timestamp + rewardsDuration;
    emit RewardAdded(reward);
}

ryuheimat (Concur) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

Given the code available, the warden has shown a possible scenario where certain depositors cannot receive reward tokens.

Because this is contingent on an improper configuration and because this relates to loss of Yield, I believe Medium Severity to be more appropriate.


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

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 reward balance check uses the contract's total token balance, which includes rewards already earned but not yet claimed, instead of ensuring new rewards are actually funded.

Impact

Some users may be unable to claim their earned rewards, but this requires the rewards distributor to misconfigure the reward amount.

What the attacker needed

Rewards distributor misconfigures reward amount; users have unclaimed rewards

The fix

The function should be changed to transfer the reward tokens into the contract when adding rewards, for example by using transferFrom.

How it was found

  1. Alice stakes 1,000 stakingToken.
  2. The rewards distributor sends 100 rewardsToken and calls notifyRewardAmount with amount 100.
  3. After 7 days, Alice has 100 rewardsToken earned but does not claim them.
  4. The rewards distributor calls notifyRewardAmount with amount 100 again without sending any tokens; the transaction succeeds.
  5. After another 7 days, Alice tries to claim 200 rewardsToken but the transaction fails due to insufficient balance.

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 staking contract holds reward tokens that users can claim later. The function that sets the reward rate only looks at the total balance, not at how much is already promised to users. So if the owner sets a new reward without adding tokens, the contract may promise more than it has, and later users cannot withdraw.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Concur Finance contest

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.