ConvexMasterChef : When _lpToken is cvx, reward calculation is incorrect
The ConvexMasterChef contract allows the owner to add a staking pool where the staked token is the same as the reward token (cvx). Because reward calculation uses the contract's balance of the staked token, minting rewards inflates that balance and makes the calculated reward per share too low for that pool.
Submitted by cccz
In the ConvexMasterChef contract, a new staking pool can be added using the add() function. The staking token for the new pool is defined using the _lpToken variable. However, there is no additional checking whether the _lpToken is the same as the reward token (cvx) or not.
function add(
uint256 _allocPoint,
IERC20 _lpToken,
IRewarder _rewarder,
bool _withUpdate
) public onlyOwner {
if (_withUpdate) {
massUpdatePools();
}
uint256 lastRewardBlock = block.number > startBlock
? block.number
: startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
allocPoint: _allocPoint,
lastRewardBlock: lastRewardBlock,
accCvxPerShare: 0,
rewarder: _rewarder
})
);
}
When the _lpToken is the same token as cvx, reward calculation for that pool in the updatePool() function can be incorrect. This is because the current balance of the _lpToken in the contract is used in the calculation of the reward. Since the _lpToken is the same token as the reward, the reward minted to the contract will inflate the value of lpSupply, causing the reward of that pool to be less than what it should be.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (lpSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint256 cvxReward = multiplier
.mul(rewardPerBlock)
.mul(pool.allocPoint)
.div(totalAllocPoint);
//cvx.mint(address(this), cvxReward);
pool.accCvxPerShare = pool.accCvxPerShare.add(
cvxReward.mul(1e12).div(lpSupply)
);
pool.lastRewardBlock = block.number;
}
Proof of Concept
ConvexMasterChef.sol#L96-L118 ConvexMasterChef.sol#L186-L206
Recommended Mitigation Steps
Add a check that _lpToken is not cvx in the add function or mint the reward token to another contract to prevent the amount of the staked token from being mixed up with the reward token.
0xMaharishi (Aura Finance) commented:
Could potentially require not to be the reward token, but I think this is just a relevant part of dao ownership.
0xMaharishi (Aura Finance) confirmed and resolved
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 contract does not prevent the staked token from being the same as the reward token, so the reward minting increases the measured staked balance and dilutes the reward per share.
Impact
Rewards for that pool could be less than they should be, but only if the owner adds such a pool.
What the attacker needed
Owner adds a pool with cvx as staked token
The fix
The add function should check that the staked token is not the reward token, or rewards should be minted to a different contract.
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 lets people deposit a token and earn rewards. It calculates rewards based on how many tokens are deposited. If the deposited token is the same as the reward token, then when the contract creates new reward tokens, it accidentally counts them as deposits, which makes the reward calculation wrong.
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.