Anyone will DoS setting a new rewards duration which harms the protocol/users as they will receive too much or too little rewards
The setRewardsDuration function reverts if the current reward period has not finished, and because automated harvesting keeps notifying new rewards, the finish time is constantly reset, making it impossible to change the duration. This denial of service prevents the protocol from adjusting reward rates, potentially causing users to receive too many or too few rewards.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/46
Found by
0x73696d616f
Summary
Rewards are destributed via StakedEXA::notifyRewardAmount() over a certain duration and amount, which originates a rate. The protocol may intend to change this rate by altering the duration, making users receive more or less rewards depending on intent. The duration of the rewards is set in StakedEXA::setRewardsDuration(), but it will be near impossible to set as there is an automatic mechanism to harvest rewards from the provider.
Root Cause
In StakedEXA::443, it's not possible to set a new duration if the current rewards are still not finished. This will always be the case as the automated provider harvesting will keep notifying new rewards and resetting the finish time of the rewards.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- Provider harvests new rewards.
StakedEXA::harvest()is called, which notifies new rewards and updates the finish time.StakedEXA::setRewardsDuration()reverts asblock.timestamphas not reachedrewardData.finishAt.
Impact
The ability to change the duration of rewards is DoSed which will impact the amount of rewards users get over time.
PoC
The function StakedEXA::setRewardsDistribution() shows that it's not possible to update the duration if the current reward period is not finished:
function setRewardsDuration(IERC20 reward, uint40 duration) public onlyRole(DEFAULT_ADMIN_ROLE) {
RewardData storage rewardData = rewards[reward];
if (rewardData.finishAt > block.timestamp) revert NotFinished(); //@audit DoS this
rewardData.duration = duration;
emit RewardsDurationSet(reward, msg.sender, duration);
}
StakedEXA::harvest() notifies new rewards, which updates the current reward period finish, making it impossible to change the duration.
Mitigation
The duration can be set by carefully adjusting the current reward rate to reflect the new duration. One example solution is doing:
function setRewardsDuration(uint256 _rewardsDuration) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint256 periodFinish_ = periodFinish;
if (block.timestamp < periodFinish_) {
uint256 leftover = (periodFinish_ - block.timestamp) * rewardRate;
rewardRate = leftover / _rewardsDuration;
periodFinish = block.timestamp + _rewardsDuration;
}
rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(rewardsDuration);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/exactly/protocol/pull/753
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
What the attacker needed
None
The fix
The issue was fixed by the protocol team, and the fix was reviewed and signed off by the Lead Senior Watson.
How it was found
- Provider harvests new rewards.
- StakedEXA::harvest() is called, which notifies new rewards and updates the finish time.
- StakedEXA::setRewardsDuration() reverts as block.timestamp has not reached rewardData.finishAt.
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 smart contract distributes rewards over a set period. The admin can change that period, but only if the current period has ended. However, the contract automatically adds new rewards regularly, which always extends the end time. So the admin can never change the period, and users might get the wrong amount of rewards.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.