MorpheusAI

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

LinearDistributionIntervalDecrease::total interval passed calculation can be simplified

Summary

In LinearDistributionIntervalDecrease::_calculateFullPeriodReward() total interval passed in a period is calculated. However the calculation is bit complex which expenses more gas. We can oversimplify it.

Vulnerability Details

We can structure the time passed thing like this:

-------------------------------------------------
| | |
payoutStart startTime endTime

Here interval passed over a period was calculated here:

uint256 ip_ = ((endTime_ - payoutStart_ - intervalsPassedBefore_ * interval_) / interval_);

If we look more into intervalPassedBefore we can see how it was calculated, an private function, _divideCeil(uint256 a_, uint256 b_), was called, where a = timePassedBefore_ and b = interval_.
timePassedBefore is the timestamp from startTime to payoutStart, as we can see in the starting of the _calculateFullPeriodReward() :

uint256 timePassedBefore_ = startTime_ - payoutStart_;

As uint256 intervalsPassedBefore_ = _divideCeil(timePassedBefore_, interval_); we can say timePassedBefore_ = intervalsPassedBefore_ * interval_.
So, while calculating the total interval period i.e ip_ we can use timePassedBefore_ instead of intervalsPassedBefore_ * interval_.
So if we simplify the calculation of ip_ it will look like :

ip => (endtime - payoutStart - timePassedBefore) / interval
=> (endTime - payoutStart - (startTime - payoutStart)) / interval
=> (endtime - payoutStart - startTime + payoutStart) / interval
=> (endTime - startTime) / interval

As we can see we can get the interval passed over a period just by substracting the startTime from endTime.

Impact

Here we are unnecessarily calling a function and made the process complicated.

Tools Used

Manual analysis.

Recommendations

Calculate the ip_ like this: (endTime_ - startTime_) / 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.