Submitted by GalloDaSballo, also found by chaduke, __141345__, and __141345__
In StRSR.sol, _payoutRewards is used to accrue the value of rewards based on the time that has passed since payoutLastPaid
Because of its dependence on totalStakes, stakeRate and time, the function is rightfully called on every stake and unstake.
There is a specific instance, in which _payoutRewards should also be called, which could create either an unfair reward stream or a governance attack and thats when setRewardPeriod and setRewardRatio are called.
If you imagine the ratio at which rewards are paid out as a line, then you can see that by changing rewardRatio and period youre changing its slope.
You should then agree, that while governance can rightfully change those settings, it should _payoutRewards first, to ensure that the slope of rewards changes only for rewards to be distributed after the setting has changed.
Functions that change the slope or period size should accrue rewards up to that point.
This is to avoid:
Without accrual, the change will apply retroactively from payoutLastPaid
Which could:
Instead of starting a new period
tbrent (Reserve) confirmed and commented:
tbrent (Reserve) mitigated:
Status: Mitigation confirmed with comments. Full details in reports from HollaDieWaldfee, 0xA5DF, and AkshaySrivastav.
