https://github.com/Cyfrin/2024-09-stakelink/blob/main/contracts/core/rewardsPools/RewardsPool.sol
The _updateRewardPerToken function is responsible for updating the rewardPerToken variable when new rewards are distributed. If the function is called when there are no stakers in the contract (i.e., totalStaked == 0), it reverts due to the following condition:
Code Reference
This vulnerability leads to significant issues:
**Stuck Rewards: ** If there are no active stakers, any rewards deposited into the contract cannot be distributed. This results in the rewards remaining stuck indefinitely until at least one user stakes their tokens again.
User Frustration: Users expecting rewards from their deposits may become frustrated if they find that rewards are not being distributed due to the lack of stakers.
Increased Complexity: The system complexity increases as it relies on user behavior to reset the reward distribution mechanism.
The following scenario illustrates how this vulnerability can impact the contract:
An external entity (e.g., a user or a contract) deposits rewards into the RewardsPool:
The distributeRewards function is called:
If controller.totalStaked() returns 0 (i.e., there are no active stakers), the following will occur:
Manual Review
To mitigate this vulnerability, the following changes should be made:
Allow for No-Staking Scenario: Modify the _updateRewardPerToken function to handle the case where there are no stakers. Instead of reverting, it could simply return without modifying the rewardPerToken:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.