Skip to content

Conversation

@Skyge
Copy link
Contributor

@Skyge Skyge commented Dec 3, 2025

Fix #16

src/Staking.sol Outdated
function depositReward(uint256 _amount) external nonReentrant {
rewardToken.safeTransferFrom(msg.sender, address(this), _amount);
uint256 epoch = currentEpoch();
require(epoch > 0, "Cannot deposit reward in epoch 0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the BETH contract. what if we deposit all the BETH to the next epoch in case there is no staker in current epoch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or imagine smth like this:

if(epochTotalLocked[epoch - 1] == 0) {
   if(epochReward[epoch - 1] > 0) {
      epochReward[epoch] += epochReward[epoch - 1];
      epochReward[epoch - 1] = 0;
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the BETH contract.

I see.

Or imagine smth like this

Make sense.

But how about rewards that are deposited at epoch 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this is fixed in your PR right?

}

epochReward[epoch] += totalAmount;
emit RewardDeposited(msg.sender, epoch, totalAmount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we report total-amount or _amount here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can use _amount, it is clear match with what depositor actually sent.

And for the line 115:

epochReward[epoch - 1] = 0;

Should we add a separate event for accumulated rewards, like:
emit RewardAccumulated(epoch - 1, epoch, previousEpochReward);

@Skyge
Copy link
Contributor Author

Skyge commented Jan 8, 2026

There is another scenario:

Epoch Timeline:
Epoch n-1: No lockers, no rewards deposited      → epochReward[n-1] = 0
Epoch n:   No lockers, rewards deposited (> 0)  → epochReward[n] > 0
Epoch n+1: No lockers, no rewards deposited     → No depositReward() calls
Epoch n+2: Lockers present, rewards deposited   → Checks only epoch n+1

Rewards for Epoch n become permanently stuck because:

  1. Distribution for epoch n only triggers when someone deposits rewards for epoch n+1

  2. No one deposits rewards for epoch n+1

  3. When rewards are later deposited for epoch n+2, the system only checks epoch n+1 (which has no rewards)

  4. The system never skips empty epochs to check epoch n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewards Can Become Permanently Unclaimable Due to Epoch Logic

2 participants