Skip to content
Business logic Audit finding Intermediate

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 -->

https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/main/protocol/contracts/StakedEXA.sol#L425

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 -->

https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/main/protocol/contracts/StakedEXA.sol#L344

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.

https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/main/protocol/contracts/StakedEXA.sol#L209

4.) notifyRewardAmount() the reward.rate would be calculated as

Solidity
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

Solidity
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

https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/main/protocol/contracts/StakedEXA.sol#L425-L432

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.

The original report as published on Sherlock, by KupiaSec. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Admin calls finishDistribution to end reward distribution.
  2. A user calls harvest, which withdraws assets from the market.
  3. harvest calls notifyRewardAmount, which recalculates the reward rate and resets finishAt.
  4. 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.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Exactly Protocol Update - Staking Contract

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.