sherlock-audit / 2024-06-magicsea-judging

8 stars 5 forks source link

Lone Opaque Mustang - `_rewards` is 1 larger than required #706

Closed sherlock-admin4 closed 4 months ago

sherlock-admin4 commented 4 months ago

Lone Opaque Mustang

Low/Info

_rewards is 1 larger than required

Summary

Incorrect iteration over bribeEpochs pushes 1 more entry into _rewards than necessary.

Vulnerability Detail

_calcPeriods is inclusive of the last voting period lastId. The number of iterations performed is bribeEpochs + 1, so the number of empty entries pushed into _rewards is lastId + 1 epochs, which is 1 more than necessary.

Impact

Gas wastage.

Code Snippet

https://github.com/sherlock-audit/2024-06-magicsea/blob/7fd1a65b76d50f1bf2555c699ef06cde2b646674/magicsea-staking/src/rewarders/BribeRewarder.sol#L248-L251

Tool used

Manual Review

Recommendation

uint256 bribeEpochs = _calcPeriods(startId, lastId);
- for (uint256 i = 0; i <= bribeEpochs; ++i) {
+ for (uint256 i = 0; i < bribeEpochs; ++i) {
    _rewards.push();
}