https://github.com/Cyfrin/2024-09-stakelink/blob/main/contracts/core/rewardsPools/RewardsPool.sol
The distributeRewards function distributes newly deposited rewards to users based on their stake in the rewards pool. However, the function calculates the total rewards available for distribution using the following logic:
While this may appear functional, it leads to inefficiencies in the reward distribution mechanism when rewards are deposited into the contract.
Code Reference
This inefficiency can result in:
Overestimation of Distributable Rewards: If the contract receives multiple deposits in a single transaction or at different times, the calculation could yield incorrect values, causing either excess rewards to be distributed (if prior rewards are not accounted correctly) or less than expected to be distributed.
Gas Inefficiency: Users may end up paying more gas fees than necessary, especially if there are multiple deposits made in a short time frame.
Poor User Experience: Users may experience confusion if their rewards appear to be inconsistent due to miscalculations in the distribution
Manual Review
Improve Reward Calculation Logic: Implement a more robust calculation that handles multiple deposits more efficiently. For instance, maintain a separate accounting for each deposit that clearly delineates between already accounted rewards and new rewards:
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.