MasterChef.updatePool() Fails To Update Reward Variables If block.number >= endBlock
The updatePool function fails to update reward variables when block.number >= endBlock, so pools that have not recently called updatePool miss out on rewards they were entitled to before endBlock. This disadvantages less active pools compared to more active ones.
Submitted by leastwood, also found by CertoraInc, csanuragjain, Czar102, hickuphh3, kirk-baird, and WatchPug
The updatePool function intends to calculate the accumulated Concur rewards by tracking the number of blocks passed since the last update to correctly determine how many Concur tokens to distribute to each share. The reward distribution has a start and end block which dictates the timeframe by which rewards will be distributed to the underlying pool.
If a pool has not recently updated itself and has reached the block.number >= endBlock statement in updatePool, then any rewards that it would normally be entitled to prior to reaching endBlock will not be attributed to the pool. Therefore, once rewards are no longer being distributed, pools who had not recently called updatePool before reaching endBlock are at a disadvantage as compared to more active pools.
Proof of Concept
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint lpSupply = pool.depositToken.balanceOf(address(this));
if (lpSupply == 0 || pool.allocPoint == 0) {
pool.lastRewardBlock = block.number;
return;
}
if(block.number >= endBlock) {
pool.lastRewardBlock = block.number;
return;
}
uint multiplier = getMultiplier(pool.lastRewardBlock, block.number);
uint concurReward = multiplier.mul(concurPerBlock).mul(pool.allocPoint).div(totalAllocPoint);
pool.accConcurPerShare = pool.accConcurPerShare.add(concurReward.mul(_concurShareMultiplier).div(lpSupply));
pool.lastRewardBlock = block.number;
}
Recommended Mitigation Steps
Ensure that once the block.number >= endBlock statement has been reached, the pool.accConcurPerShare is updated to reflect the number of blocks that have passed up until endBlock. The number of blocks should be equal to endBlock - pool.lastRewardBlock. This will ensure stale pools are not negatively impacted once endBlock has been reached by the contract.
Alex the Entreprenerd (judge) commented:
The warden has identified a way in which the contract will not release rewards that are due for a depositor.
Because the check doesn’t accrue until the last eligible block, the reward loss can be quantified as: LastTimeAccrueBeforeEndBlock - endBlock
The finding is valid, but because it pertains to loss of yield, and because the loss can be quantified and reduced by simply calling at the last available block, I believe Medium Severity to be more appropriate.
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 updatePool function returns early when block.number >= endBlock without first updating accConcurPerShare for the blocks between lastRewardBlock and endBlock.
Impact
Pools that do not call updatePool before endBlock lose the rewards they were entitled to for the period up to endBlock, reducing their yield compared to more active pools.
What the attacker needed
Pool not updated before endBlock
The fix
The updatePool function should update accConcurPerShare for the blocks up to endBlock before returning when block.number >= endBlock.
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 is a smart contract bug where a function that calculates rewards stops working after a certain block number. If a pool hasn't been updated recently, it loses the rewards it should have earned before that block, so people who don't interact often get less than they deserve.
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.