MorpheusAI

MorpheusAI
Foundry
22,500 USDC
View results
Submission Details
Severity: high
Invalid

Possible Integer Overflow in `getPeriodReward` which may result in incorrect reward calculations

Summary

The getPeriodReward function in the provided contract is susceptible to integer overflow, which may result in incorrect reward calculations. This vulnerability can be exploited by an attacker to manipulate reward amounts or disrupt the intended functioning of the contract.

Vulnerability Details

The vulnerability arises from arithmetic operations within the getPeriodReward function that are not protected against integer overflow or underflow. These operations involve calculations of reward amounts, and if the result exceeds the maximum representable value for the data type used, it can lead to unexpected behavior and incorrect rewards.

Impact

An attacker could exploit this vulnerability to manipulate reward calculations, potentially receiving more rewards than intended or disrupting the normal operation of the contract.

Tools Used

Manual code review.

Recommendations and Mitigation Steps

To address this vulnerability, consider using the SafeMath library or an equivalent mechanism to perform arithmetic operations securely. SafeMath protects against overflows and underflows by reverting the transaction if the result is not within the valid range.

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract YourContract {
using SafeMath for uint256;
function getPeriodReward(uint256 poolId_, uint128 startTime_, uint128 endTime_) external view returns (uint256) {
// Existing code
// Replace direct arithmetic operations with SafeMath functions
uint256 totalReward = initialReward.mul(rewardDecrease).div(decreaseInterval);
uint256 periodInSeconds = endTime_.sub(startTime_);
uint256 reward = totalReward.mul(periodInSeconds).div(decreaseInterval);
// Existing code
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
over 1 year ago
inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.