You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid use of default "checked" behavior in a for loop
Underflow/overflow checks are made every time ++i (or i++ or equivalent counter) is called. Such checks are unnecessary since i is already limited. Therefore, use unchecked {++i}/unchecked {i++} instead
for (uint256 i =0; i <128; i++) {
if (min >= max) break;
uint256 mid = (min + max +1) /2;
if (pointHistory[mid].blk <= _block) {
min = mid;
} else {
max = mid -1;
}
}
Suggestion:
for (uint256 i =0; i <128;) {
if (min >= max) break;
uint256 mid = (min + max +1) /2;
if (pointHistory[mid].blk <= _block) {
min = mid;
} else {
max = mid -1;
}
unchecked {
++i;
}
}
Similarly for the three for loops referenced below:
State variables should not be initialized to their default values
Initializing
uint
variables to their default value of0
is unnecessary and costs gasVotingEscrow.sol: L298
Change to:
Similarly for the additional instances below
min
is initialized to zero in both the following lines:VotingEscrow.sol: L714
VotingEscrow.sol: L737
VotingEscrow.sol: L793
dTime
is initialized to zero in both the following lines:VotingEscrow.sol: L794
VotingEscrow.sol: L889
Use
++i
instead ofi++
to increase count in afor
loopSince use of
i++
(or equivalent counter) costs more gas, it is better to use++i
in the fourfor
loops referenced below:VotingEscrow.sol: L309-347
VotingEscrow.sol: L717-725
VotingEscrow.sol: L739-748
VotingEscrow.sol: L834-855
Avoid use of default "checked" behavior in a
for
loopUnderflow/overflow checks are made every time
++i
(ori++
or equivalent counter) is called. Such checks are unnecessary sincei
is already limited. Therefore, useunchecked {++i}
/unchecked {i++}
insteadVotingEscrow.sol: L717-725
Suggestion:
Similarly for the three
for
loops referenced below:VotingEscrow.sol: L309-347
VotingEscrow.sol: L739-748
VotingEscrow.sol: L834-855
The text was updated successfully, but these errors were encountered: