Should Accrue Before Change, Loss of Rewards in case of change of settings
The reward payout function was not called before governance changed the reward period or ratio, so the new settings applied retroactively from the last payout. This could unfairly change stakers' rewards or enable a governance attack.
GalloDaSballo Follow with chaduke, __141345__ and 1 other
Originally disclosed on Code4rena
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 it’s 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 that’s 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 you’re changing it’s 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.
Mitigation
Functions that change the slope or period size should accrue rewards up to that point.
This is to avoid:
- Incorrect reward distribution
- Change (positive or negative) of rewards from the past
Without accrual, the change will apply retroactively from payoutLastPaid
Which could:
- Change the period length prematurely
- Start a new period inadvertently
- Cause a gain or loss of yield to stakers
Instead of starting a new period
Suggested Refactoring
function setRewardPeriod(uint48 val) public governance {
require(val > 0 && val <= MAX_REWARD_PERIOD, "invalid rewardPeriod");
_payoutRewards(); // @audit Payout rewards for fairness
emit RewardPeriodSet(rewardPeriod, val);
rewardPeriod = val;
require(rewardPeriod * 2 <= unstakingDelay, "unstakingDelay/rewardPeriod incompatible");
}
function setRewardRatio(uint192 val) public governance {
require(val <= MAX_REWARD_RATIO, "invalid rewardRatio");
_payoutRewards(); // @audit Payout rewards for fairness
emit RewardRatioSet(rewardRatio, val);
rewardRatio = val;
}
tbrent (Reserve) confirmed and commented:
Nice finding, agree.
This PR adds a
Furnace.melt()/StRSR.payoutRewards()step when governance changes therewardRatio: reserve-protocol/protocol#622
Status: Mitigation confirmed with comments. Full details in reports from HollaDieWaldfee, 0xA5DF, and AkshaySrivastav.
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 setter functions for reward period and ratio did not accrue rewards before updating the parameters, causing retroactive application.
Impact
Stakers could gain or lose yield unfairly, and a governance attack could change the reward period prematurely or start a new period inadvertently.
What the attacker needed
Governance can change reward settings
The fix
The setters should call the payout function before changing the reward period or ratio; a mitigation was later added for the ratio change.
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 pays rewards over time based on settings like the reward rate and period length. If those settings are changed without first paying out what was already earned, the new settings apply to the whole past period, which can unfairly increase or decrease rewards. The fix is to pay out rewards before changing the settings.
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.