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.
uint256 bribeEpochs = _calcPeriods(startId, lastId);
- for (uint256 i = 0; i <= bribeEpochs; ++i) {
+ for (uint256 i = 0; i < bribeEpochs; ++i) {
_rewards.push();
}
Lone Opaque Mustang
Low/Info
_rewards
is 1 larger than requiredSummary
Incorrect iteration over
bribeEpochs
pushes 1 more entry into_rewards
than necessary.Vulnerability Detail
_calcPeriods
is inclusive of the last voting periodlastId
. The number of iterations performed isbribeEpochs + 1
, so the number of empty entries pushed into_rewards
islastId + 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