MorpheusAI

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

Gas inefficiency in function getPeriodReward

Summary

At line 49, when it's checked if an interval is lesser than the interval range, the formula is inefficient.

Vulnerability Details

Current formula is the following:

uint256 timePassedBefore_ = startTime_ - payoutStart_;
if ((timePassedBefore_ / interval_) == ((endTime_ - payoutStart_) / interval_))

Computing the operation doesn't even require the "payoutStart" varaible, as it would be equivalent with testing (endTime - startTime) / interval_ == 0.
A small optimization can be further performed by storing (endTime - startTime) in an uint128 variable (proposing name timeDelta) and using it on line 53. By performing this substitution, readability is also improved.

Impact

Extra gas cost for operation

Tools Used

Manual inspection

Recommendations

Rewrite formula as suggested:
if (((endTime - startTime) / interval) == 0)

And for further optimization & readability:

uint128 timeDelta = endTime - startTime
if((timeDelta / interval) == 0) {
...
return (intervalFullReward_ * timeDelta) / interval_

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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