Your Solidity contract RewardsPoolTimeBased has several areas to examine for potential vulnerabilities or improvements. Here's a review of some key aspects:
Check SafeMath: Although Solidity 0.8.0 and above have built-in overflow and underflow protection, it’s good practice to double-check calculations to ensure they do not exceed maximum or minimum values, particularly in arithmetic involving user inputs or externally controlled variables.
Epoch Expiry Validation: The contract relies on block.timestamp for managing epoch times. Miners can manipulate block.timestamp slightly, which could lead to unintended behavior if not properly accounted for. For example, the expiration checks (_epochExpiry < block.timestamp + minEpochDuration) could be susceptible to miner manipulation. Ensure that the logic surrounding these conditions mitigates potential exploitation.
Safe Transfers: Although you're using SafeERC20 for transferring tokens, ensure that all state changes occur before external calls (like token transfers) to prevent reentrancy attacks. In the depositRewards function, you first transfer tokens and then update state variables. This can potentially lead to issues if the token contract has malicious behavior.
Owner Functions: The onlyOwner modifier restricts functions like depositRewards, setMinEpochDuration, and setMaxEpochDuration to the contract owner. If the owner’s key is compromised, an attacker could manipulate these parameters. Consider implementing multi-signature access for critical functions.
Missing Events: The contract emits the DepositRewards event, but consider emitting events for other state-changing functions such as setMinEpochDuration, setMaxEpochDuration, and potentially updateReward. This improves transparency and allows for better tracking of state changes.
Check Logic in depositRewards: The line uint256 remainingRewards = timeOfLastRewardUpdate >= epochExpiry ? 0 : ... assumes that if timeOfLastRewardUpdate is greater than or equal to epochExpiry, there are no remaining rewards to distribute. This logic should be verified to ensure it aligns with the intended reward distribution scheme, especially during edge cases when epochs end and new epochs begin.
Check for Unused Variables: Ensure that state variables like epochRewardsAmount, epochDuration, and epochExpiry are correctly managed and utilized in all functions that depend on them. Any unintended uninitialized or poorly managed state could lead to incorrect reward calculations.
Large Loops and Gas Limits: Although not explicitly present in your code, if any future changes involve looping through arrays of users or rewards, consider the implications of gas limits.
Front-running Risk: The depositRewards function might be vulnerable to front-running if the user transaction can be predicted and manipulated. Ensure the design mitigates this risk, possibly by implementing commit-reveal patterns or similar strategies.
Thorough Testing: Implement unit tests, particularly focusing on boundary conditions, user behavior, and malicious scenarios.
Audits: Consider a third-party audit for critical components, especially if large sums will be managed by the contract.
Upgradeability: Evaluate whether this contract needs to be upgradable, especially since parameters like epoch durations can greatly affect reward distribution logic.
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.