Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broad Umber Eagle - Inaccurate Reward Timestamp Calculation #83

Open
sherlock-admin2 opened this issue Dec 22, 2024 · 0 comments
Open
Labels
Won't Fix The sponsor confirmed this issue will not be fixed

Comments

@sherlock-admin2
Copy link

Broad Umber Eagle

Medium

Inaccurate Reward Timestamp Calculation

Summary

The lastTimeRewardDistributed function in GovernanceStaker.sol has a logical flaw that can result in incorrect reward distribution timestamps. This issue can lead to miscalculated rewards and an unfair distribution of funds among stakers.

Vulnerability Details

The lastTimeRewardDistributed function is intended to return the last timestamp when rewards were distributed. Its current logic is if the current time (block.timestamp) is greater than or equal to the reward period end time (rewardEndTime), it returns rewardEndTime, otherwise, it returns the current time (block.timestamp).

This approach can fail in scenarios where the reward period is extended:

  1. A new reward period starts with rewardEndTime set 30 days into the future.
  2. Midway through this period (e.g., after 15 days), the notifyRewardAmount function is called to add more rewards, extending the reward period by updating rewardEndTime.
  3. In this case, lastTimeRewardDistributed would return the current block.timestamp, which does not accurately reflect the last time rewards were distributed.

Impact

  • Incorrect Reward Calculations: using an inaccurate timestamp from lastTimeRewardDistributed can result in incorrect reward amounts being distributed to stakers.
  • Unequal Distribution of Rewards: stakers may receive more or fewer rewards than they are entitled to, depending on the timing of their interactions with the contract.

Code Snippet

code

function lastTimeRewardDistributed() public view virtual returns (uint256) {
    if (rewardEndTime <= block.timestamp) return rewardEndTime;
    else return block.timestamp;
  }

Recommendation

To address this issue, a new state variable should be introduced to explicitly store the last reward distribution timestamp. This variable must be updated whenever notifyRewardAmount is called to ensure accuracy.

Suggested Fix:

  1. Introduce a State Variable: add a new variable lastRewardDistributionTime to track the actual last reward distribution time.
  2. Update in notifyRewardAmount: ensure this variable is updated whenever the reward period is modified.
  3. Refactor lastTimeRewardDistributed: modify the function to return the value of lastRewardDistributionTime for accurate tracking.
@sherlock-admin3 sherlock-admin3 added the Won't Fix The sponsor confirmed this issue will not be fixed label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Won't Fix The sponsor confirmed this issue will not be fixed
Projects
None yet
Development

No branches or pull requests

2 participants