The Staking contract for LoveToken allows users to stake tokens and claim rewards on a per-week basis. Users stake LoveTokens and can claim 1 LoveToken per staked token per week. The contract calculates rewards based on the number of weeks elapsed since the last claim, using integer division, which results in rounding down any fractional weeks. This mechanism could lead to potential loss of rewards for users who claim rewards at intervals that don't align exactly with full weeks, as any partial week's worth of rewards is not accounted for and effectively lost.
The issue arises in the claimRewards
function, which calculates the amount of rewards a user can claim based on the number of weeks elapsed since their last claim. The calculation uses integer division to determine the number of elapsed weeks:
Since Solidity does not support fractional numbers for this type of calculation, any remainder from the division is discarded. This means that if a user claims rewards after a period that isn't exactly a multiple of a week (e.g., 1.8 weeks), the calculation rounds down to 1 week, and the user loses the rewards for the remaining 0.8 weeks. This issue could discourage optimal engagement from users and lead to discrepancies in expected vs. actual rewards.
Users who make claims at intervals not perfectly aligned with full weeks consistently lose a portion of their rewards. Over time, this could significantly affect the total rewards users could claim, especially for users engaging frequently with the contract. This issue not only impacts user satisfaction but could also affect the overall participation rate in the staking mechanism.
Manual Code Review
Solidity Compiler (for understanding precision and data types)
To mitigate this issue and ensure users receive the full value of their staked tokens, consider implementing a mechanism to track fractional weeks or adjust the reward calculation to account for partial weeks. Two potential solutions are:
Accrue Partial Weeks as Credit: Modify the contract to track not only the last claim timestamp but also any unclaimed reward time as a form of credit. This credit would then be added to the next claim period's calculation, ensuring no rewards are lost due to rounding.
Change the Reward Calculation Mechanism: Instead of basing rewards on discrete weeks, consider a system that can accumulate rewards continuously. This could involve tracking the exact time since the last claim and calculating rewards based on the exact number of seconds elapsed, rather than rounding down to the nearest week.
Both solutions require careful consideration to ensure they do not introduce new vulnerabilities, such as increased complexity leading to potential errors or exploits. Additionally, changing the rewards calculation mechanism could have implications for the contract's gas costs and should be optimized for efficiency.
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.