ConvexStakingWrapper._calcRewardIntegral() Can Be Manipulated To Steal Tokens From Other Pools
The reward calculation in ConvexStakingWrapper uses the contract's total reward token balance to determine newly claimed tokens, allowing a user to call getReward on multiple pools and then claim a disproportionate share from one pool. This lets an attacker siphon rewards from other pools, causing loss for other stakers.
Submitted by leastwood, also found by cmichel and kirk-baird
The ConvexStakingWrapper.sol implementation makes several modifications to the original design. One of the key changes is the ability to add multiple pools into the wrapper contract, where each pool is represented by a unique _pid. By doing this, we are able to aggregate pools and their LP tokens to simplify the token distribution process.
However, the interdependence between pools introduces new problems. Because the original implementation uses the contract’s reward token balance to track newly claimed tokens, it is possible for a malicious user to abuse the unguarded getReward function to maximise the profit they are able to generate. By calling getReward on multiple pools with the same reward token (i.e. cvx), users are able to siphon rewards from other pools. This inevitably leads to certain loss of rewards for users who have deposited LP tokens into these victim pools. As crv and cvx are reward tokens by default, it is very likely that someone will want to exploit this issue.
Proof of Concept
Let’s consider the following scenario:
- There are two convex pools with
_pid0 and 1. - Both pools currently only distribute
cvxtokens. - Alice deposits LP tokens into the pool with
_pid0. - Both pools earn 100
cvxtokens which are to be distributed to the holders of the two pools. - While Alice is a sole staker of the pool with
_pid0, the pool with_pid1 has several stakers. - Alice decides she wants to maximise her potential rewards, so she directly calls the unguarded
IRewardStaking(convexPool[_pid]).getRewardfunction on both pools, resulting in 200cvxtokens being sent to the contract. - She then decides to deposit the 0 amount to execute the
_calcRewardIntegralfunction on the pool with_pid0. However, this function will calculated_rewardasbal - reward.remainingwhich is effectively the change in contract balance. As we have directly claimedcvxtokens over the two pools, thisd_rewardwill be equal to 200. - Alice is then entitled to the entire 200 tokens as she is the sole staker of her pool. So instead of receiving 100 tokens, she is able to siphon rewards from other pools.
Altogether, this will lead to the loss of rewards for other stakers as they are unable to then claim their rewards.
ConvexStakingWrapper.sol#L216-L259
function _calcRewardIntegral(
uint256 _pid,
uint256 _index,
address _account,
uint256 _balance,
uint256 _supply
) internal {
RewardType memory reward = rewards[_pid][_index];
//get difference in balance and remaining rewards
//getReward is unguarded so we use remaining to keep track of how much was actually claimed
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);
}
rewards[_pid][_index] = reward;
}
Tools Used
Manual code review. Confirmation from Taek.
Recommended Mitigation Steps
Consider redesigning this mechanism such that all pools have their getReward function called in _checkpoint. The _calcRewardIntegral function can then ensure that each pool is allocated only a fraction of the total rewards instead of the change in contract balance. Other implementations might be more ideal, so it is important that careful consideration is taken when making these changes.
Alex the Entreprenerd (judge) commented:
The warden has shown how, by having the same token as rewards for multiple pools, the math for claiming can be broken, allowing the depositor of one pool to claim a portion of the token reward earned by all pools.
Normally this would be contingent on implementation or overlap of the tokens, however, because we’re dealing with CVX we already know for certain that CVX and cvxCRV is going to be a reward for the majority of the pools.
This finding ultimately shows how to break the accounting of the reward contract while stealing yield from all other pools, and for that reason, I believe High Severity to be valid.
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 calculation uses the contract's total reward token balance change instead of tracking each pool's rewards separately, so claiming from multiple pools inflates the perceived reward for one pool.
Impact
Other stakers in the victim pools lose their rewards because the attacker can claim more than their fair share, leaving insufficient tokens for others to claim.
What the attacker needed
Multiple pools share the same reward token; attacker is sole staker in one pool; attacker can call getReward directly
The fix
The mechanism should be redesigned so that all pools' getReward functions are called in _checkpoint, and _calcRewardIntegral allocates only a fraction of total rewards per pool instead of using the contract balance change.
How it was found
- Alice deposits LP tokens into pool with _pid 0.
- Both pools earn 100 cvx tokens to be distributed.
- Alice calls getReward directly on both pools, sending 200 cvx to the contract.
- Alice deposits 0 amount to trigger _calcRewardIntegral on pool 0.
- The function calculates d_reward as 200 (the total balance change).
- Alice, as sole staker of pool 0, receives the entire 200 tokens instead of 100.
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 contract holds rewards for several pools. It tracks new rewards by looking at its total token balance, so if someone triggers reward collection for multiple pools at once, the contract thinks all that new balance belongs to the pool they are in. They can then take more than their fair share, leaving others unable to claim.
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.