ConvexMasterChef : When using add() and set() , it should always call massUpdatePools() to update all pools
The add() and set() functions in the staking contract can change the total allocation points without first updating pending rewards, so the reward accounting for every pool can be calculated incorrectly. An owner who calls these functions with the update flag off could cause pools to receive wrong reward amounts.
Submitted by cccz
Same as IDX-003 in https://public-stg.inspex.co/report/Inspex_AUDIT2021024_LuckyLion_Farm_FullReport_v2.0.pdf The totalAllocPoint variable is used to determine the portion that each pool would get from the total reward, so it is one of the main factors used in the rewards calculation. Therefore, whenever the totalAllocPoint variable is modified without updating the pending reward first, the reward of each pool will be incorrectly calculated. For example, when _withUpdate is false, in the add() shown below, the totalAllocPoint variable will be modified without updating the rewards (massUpdatePools()).
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
})
);
}
Proof of Concept
Recommended Mitigation Steps
Removing the _withUpdate variable in the add() and set() functions and always calling the massUpdatePools() function before updating totalAllocPoint variable.
0xMaharishi (Aura Finance) confirmed and commented:
We didn’t change this from the Convex implementation. I believe it is there to protect the contract from bricking in case there are too many pools added. The choice here is between giving admin the ability to brick, and giving admin the responsibility of adding the correct alloc points. I think we should remove as advised, because we are only likely to have a few pools.
0xMaharishi (Aura Finance) resolved:
code4rena aurafinance/aura-contracts#84 All code4rena fixes code-423n4/2022-05-aura#6
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 add() and set() functions allow totalAllocPoint to change while skipping massUpdatePools(), so pending rewards are computed against a new allocation instead of the old one.
Impact
Rewards for each pool could be calculated incorrectly when the owner adds or changes a pool without triggering a mass update.
What the attacker needed
Owner calls add() or set() with update off
The fix
The _withUpdate flag was removed from add() and set() so massUpdatePools() is always called before totalAllocPoint changes, and the fix was merged.
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 hands out rewards to several pools, and each pool's share depends on a number called its allocation points. If an admin changes those points without first recalculating what everyone has earned so far, the maths for past rewards gets mixed up and pools can be paid the wrong amount.
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.