Skip to content
Business logic Audit finding Advanced

ConvexStakingWrapper.sol#_calcRewardIntegral Wrong implementation can disrupt rewards calculation and distribution

The reward calculation in ConvexStakingWrapper.sol incorrectly tracks the contract's reward token balance, causing underflows and misdistribution when multiple pools share the same reward token. An attacker could cause deposits and withdrawals to revert or leave rewards frozen in the claim contract.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by cmichel, harleythedog, hickuphh3, kirk-baird, and leastwood

ConvexStakingWrapper.sol#L175-L204

    uint256 bal = IERC20(reward.token).balanceOf(address(this));
    uint256 d_reward = bal - reward.remaining;
    // send 20 % of cvx / crv reward to treasury
    if (reward.token == cvx || reward.token == crv) {
        IERC20(reward.token).transfer(treasury, d_reward / 5);
        d_reward = (d_reward * 4) / 5;
    }
    IERC20(reward.token).transfer(address(claimContract), d_reward);

    if (_supply > 0 && d_reward > 0) {
        reward.integral =
            reward.integral +
            uint128((d_reward * 1e20) / _supply);
    }

    //update user integrals
    uint256 userI = userReward[_pid][_index][_account].integral;
    if (userI < reward.integral) {
        userReward[_pid][_index][_account].integral = reward.integral;
        claimContract.pushReward(
            _account,
            reward.token,
            (_balance * (reward.integral - userI)) / 1e20
        );
    }

    //update remaining reward here since balance could have changed if claiming
    if (bal != reward.remaining) {
        reward.remaining = uint128(bal);
    }

The problems in the current implementation:

  • reward.remaining is not a global state; the reward.remaining of other rewards with the same rewardToken are not updated;
  • bal should be refreshed before reward.remaining = uint128(bal);;
  • L175 should not use balanceOf but take the diff before and after getReward().

Proof of Concept

  • convexPool[1] is incentivized with CRV as the reward token, 1000 lpToken can get 10 CRV per day;
  • convexPool[2] is incentivized with CRV as the reward token, 1000 lpToken can get 20 CRV per day.
  • Alice deposits 1,000 lpToken to _pid = 1
  • 1 day later, Alice deposits 500 lpToken to _pid = 1
  • convexPool getReward() sends 10 CRV as reward to contract
  • d_reward = 10, 2 CRV sends to treasury, 8 CRV send to claimContract
  • rewards[1][0].remaining = 10
  • 0.5 day later, Alice deposits 500 lpToken to _pid = 1, and the tx will fail:
  • convexPool getReward() sends 7.5 CRV as reward to contract
  • reward.remaining = 10
  • bal = 7.5
  • bal - reward.remaining will fail due to underflow
  • 0.5 day later, Alice deposits 500 lpToken to _pid = 1, most of the reward tokens will be left in the contract:
  • convexPool getReward() sends 15 CRV as reward to the contract;
  • d_reward = bal - reward.remaining = 5
  • 1 CRV got sent to treasury, 4 CRV sent to claimContract, 10 CRV left in the contract;
  • rewards[1][0].remaining = 15

Expected Results:

All the 15 CRV get distributed: 3 CRV to the treasury, and 12 CRV to claimContract.

Actual Results:

Only 5 CRV got distributed. The other 10 CRV got left in the contract which can be frozen in the contract, see below for the details:

  1. Bob deposits 1,000 lpToken to _pid = 2
  2. convexPool getReward() sends 0 CRV as reward to the contract
  3. d_reward = bal - reward.remaining = 10
  4. 2 CRV sent to treasury, 8 CRV sent to claimContract without calling pushReward(), so the 8 CRV are now frozen in claimContract;
  5. rewards[2][0].remaining = 10

Impact

  • The two most important methods: deposit() and withdraw() will frequently fail as the tx will revert at _calcRewardIntegral();
  • Rewards distributed to users can often be fewer than expected;
  • If there are different pools that use the same token as rewards, part of the rewards can be frozen at claimContract and no one can claim them.

Recommended Mitigation Steps

Consider comparing the balanceOf reward token before and after getReward() to get the actual rewarded amount, and reward.remaining should be removed.

leekt (Concur) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how _calcRewardIntegral can be broken in multiple ways.

While I believe a set of similar findings have been reported, this one is extremely well written so I think this can stand on it’s own.

Because _calRewardIntegral is a core functionality of the contract (giving out reward) and the warden has shown how it can be broken, I agree with High Severity.


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 code uses the contract's total balance of the reward token instead of the difference before and after claiming, and it does not update the remaining reward for all pools sharing the same token.

Impact

Deposits and withdrawals may frequently revert, rewards distributed to users can be less than expected, and rewards can become frozen in the claim contract when multiple pools share the same reward token.

What the attacker needed

Multiple pools share the same reward token; Users deposit and withdraw over time

The fix

The code should compare the balance of the reward token before and after calling getReward() to determine the actual reward amount, and remove the reward.remaining variable.

How it was found

  1. Alice deposits 1,000 lpToken to pool 1.
  2. One day later, Alice deposits another 500 lpToken to pool 1.
  3. The pool sends 10 CRV as reward to the contract.
  4. The contract sends 2 CRV to treasury and 8 CRV to claimContract, and sets remaining to 10.
  5. Half a day later, Alice deposits another 500 lpToken to pool 1, but the transaction fails due to underflow when calculating the reward difference.

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.

This smart contract handles staking and rewards. A mistake in how it calculates rewards can cause transactions to fail or rewards to get stuck, meaning users might not get what they earned.

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.