Rewards Can Be Harvested Even When Distribution Is Marked As Finished
The finishDistribution function in StakedEXA.sol sets the finish time to the current block timestamp but does not prevent further reward harvesting. A user can still call harvest, which withdraws assets from the market and calls notifyRewardAmount, resetting the finish time and allowing rewards to be claimed after distribution was supposedly finished.
KupiaSec Follow with sakshamguruji
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/66
Found by
KupiaSec, sakshamguruji
Summary
In the contract StakedEXA.sol the finishDistribution() intends to finish the distribution of the reward token , but it fails to do so. Rewards can still be harvested from the Market and later claimed , meaning , rewards can be distributed violating the finish time of the distribution.
Vulnerability Detail
1.) The finishDistribution() intends to finish the distribution of the reward token , let's assume the admin now wants to finish the distribution , and calls the function -->
Now the finish time is set to the block.timestamp
2.) All the above function does is transfer reward token to savings address (dependent upon rate and time difference)
3.) After the finishDistribution() , a normal user can still trigger the harvest() function -->
This would firstly calculate assets to be withdrawn from the market which is dependent on the allowance of the distributor and then the assets are withdrawn from
the market.
And then notifyRewardAmount() is triggered at the last.
4.) notifyRewardAmount() the reward.rate would be calculated as
RewardData storage rewardData = rewards[reward];
if (block.timestamp >= rewardData.finishAt) {
rewardData.rate = amount / rewardData.duration;
}
Because the finishAt has been marked to the timestamp when finaliseRewards was called.
5.) And lastly rewardsData is updated
rewardData.finishAt = uint40(block.timestamp) + rewardData.duration;
rewardData.updatedAt = uint40(block.timestamp);
6.) Now the user can claim the rewards since they are harvested , triggering the claim() function
7.) Even after finalisation of rewards , the reward tokens were distributed from the market and harvested and notified. It can be seen as if provider lost those assets which were not meant to be distributed.
Impact
Rewards still being able to be harvested even after the finalisation of rewards , the provider would loose his assets if had given a infinite approval . The finalise rewards marks the Finishes the distribution of a reward token
Code Snippet
Tool used
Manual Review
Recommendation
The way to avoid starting a new distribution would be for the provider to set 0 allowances on the market or withdraw the assets
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
Root cause
Likely the finishDistribution function only updates the finish time but does not prevent subsequent harvest calls from resetting the reward rate and finish time via notifyRewardAmount.
Impact
Rewards can still be harvested and claimed after distribution is marked finished, so the provider could lose assets if they had given infinite approval.
What the attacker needed
Provider has given allowance to the market; user can call harvest and claim
The fix
The provider should set zero allowances on the market or withdraw the assets to prevent new distributions.
How it was found
- Admin calls finishDistribution to end reward distribution.
- A user calls harvest, which withdraws assets from the market.
- harvest calls notifyRewardAmount, which recalculates the reward rate and resets finishAt.
- The user calls claim to receive the newly harvested rewards.
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.
This is a smart contract bug where a function meant to stop reward payments doesn't actually stop them. After the admin calls finishDistribution, users can still trigger harvest, which restarts the reward schedule and lets them claim more rewards. The provider loses funds that were not meant to be distributed.
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.