Submitted by hash, also found by Rhaydden, seaona, lanrebayode77, lian886, and novamanbg
Incorrect reward distribution causing some pools to gain more while others to gain less.
The _massUpdatePools function always sets lastAllPoolUpdate = block.timestamp:
But the individualPool update timestamp can become lower than block.timestamp if it surpasses the endRewardTime; i.e., the time in which the entire assets deposited is supposed to be depleted.
Furthermore, the endRewardTime is calculated as newEndTime = (unclaimedRewards + extra) / rewardsPerSecond + lastAllPoolUpdate whenever the rewardsPerSecond is non-zero:
If a _massUpdatePools call occurs when block.timestamp is greater than the endRewardTime, it will set the lastRewardTime of pools to be less than lastAllPoolUpdate; following which even if there are no more rewards, the new endRewardTime would be the timestamp of lastAllPoolUpdate. This will allow a pool to claim rewards worth (lastAllPoolUpdate - initialEndTime) * rewardPerSecond which is not an expected behaviour and not handled with the endRewardTime constant.
The above scenario can occur if the registerRewardDeposit function is invoked with a low amount of deposits (i.e., the deposited amount shouldnt cause the new end time to be >= block.timestamp) when the endRewardTime has been surpassed.
Example:
registerRewardDeposit is invoked such that the new endRewardTime (i.e., even after including the newly deposited assets) is 105.
Now, the first massUpdatePools call will result in:
The entire rewards of the contract are used up, but when massUpdatePools gets invoked again (e.g., via claim -> _updateEmissions -> _massUpdatePools), the new endTime will be 110 (i.e., lastPoolUpdate + 0).
claim is called for pool A in the same block, and As lastRewardTime gets updated to 110 while Bs remain 105. At 120 registerRewardDeposit is invoked with a lot of assets and B will accrue a reward of (120 - 105)/2 while A will only accrue (120 - 110)/2.
In case endTime > block.timestamp, can set the lastPoolUpdate to endTime or always ensure that the registerRewardDeposit function will only be called with amounts such that the above issue doesnt occur.
Context
amarcu (LoopFi) confirmed
