MorpheusAI

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

Logic Contradiction in Time Calculation Function in `LinearDistributionIntervalDecrease::getPeriodReward`

Summary

The error arises from conflicting logic in the function. Initially, it checks if startTime_ is greater than or equal to endTime_, returning 0 if true. Later, it assumes startTime_ equals endTime_, leading to unreachable code. This contradiction results in unnecessary computation and suggests a need for logic adjustment.

Vulnerability Details

According to the conditions if (startTime_ < payoutStart_) { startTime_ = payoutStart_; } and if (startTime_ >= endTime_) { return 0; },it can be inferred that the range of startTime_ is that payoutStart_ <= startTime_ < endTime_; Therefore, when evaluating if ((timePassedBefore_ / interval_) == ((endTime_ - payoutStart_) / interval_)), it means that ((startTime_ - payoutStart_) /interval_) == ((endTime_ - payoutStart_) / interval_). In other words, startTime_ == endTime_,which contradicts the earlier calculation if (startTime_ >= endTime_) { return 0; },leading to the subsequent code block never being executed. Furthermore, even if it is executed, because startTime_ == endTime_,the result of (intervalFullReward_ * (endTime_ - startTime_)) / interval_ will also be 0, resulting in unnecessary computation.

Therefore, based on the logic, it is suggested to change the == to <.

Additionally, there is a spelling error in the notification. It is suggested to change "then" to "than", as shown below:

LinearDistributionIntervalDecrease::getPeriodReward

- // Return 0 when calculation 'startTime_' is bigger then 'endTime_'...
+ // Return 0 when calculation 'startTime_' is bigger than 'endTime_'...
if (startTime_ >= endTime_) {
return 0;
}
- // Calculate interval that less then 'interval_' range
+ // Calculate interval that less than 'interval_' range
uint256 timePassedBefore_ = startTime_ - payoutStart_;
- if ((timePassedBefore_ / interval_) == ((endTime_ - payoutStart_) / interval_)) {
+ if ((timePassedBefore_ / interval_) < ((endTime_ - payoutStart_) / interval_)) {
uint256 intervalsPassed_ = timePassedBefore_ / interval_;
uint256 intervalFullReward_ = initialAmount_ - intervalsPassed_ * decreaseAmount_;
return (intervalFullReward_ * (endTime_ - startTime_)) / interval_;
}
- // Calculate interval that more then 'interval_' range
+ // Calculate interval that more than 'interval_' range

Impact

The contradictory logic in the function results in unreachable code and unnecessary computation.

Tools Used

Manual Review

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.