Description:
(This is only relevant if you are using the default solidity checked arithmetic). i++ involves checked arithmetic, which is not required. This is because the value of i is always strictly less than length <= 2256 - 1. Therefore, the theoretical maximum value of i to enter the for-loop body is `2256 - 2. This means that thei++` in the for loop can never overflow. Regardless, the overflow checks are performed by the compiler.
Unfortunately, the Solidity optimizer is not smart enough to detect this and remove the checks. One can manually do this by:
for (uint i = 0; i < length; ) {
// do something that doesn't change the value of i
unchecked {
++i;
}
}
Recommendation:
Consider doing the increment in the for loop post condition in an unchecked block.
[NAZ-G1] The Increment In For Loop Post Condition Can Be Made Unchecked
Context:
Diamond.sol#L94
,Diamond.sol#L132
,Diamond.sol#L153
,Diamond.sol#L173
Description: (This is only relevant if you are using the default solidity checked arithmetic).
i++
involves checked arithmetic, which is not required. This is because the value ofi
is always strictly less than length <= 2256 - 1. Therefore, the theoretical maximum value ofi
to enter the for-loop body is `2256 - 2. This means that the
i++` in the for loop can never overflow. Regardless, the overflow checks are performed by the compiler.Unfortunately, the Solidity optimizer is not smart enough to detect this and remove the checks. One can manually do this by:
Recommendation: Consider doing the increment in the for loop post condition in an unchecked block.
[NAZ-G2] Rearanging Setters To Save gas
Context:
Governance.sol#L54
,Governance.sol#L69
,Governance.sol#L94
,Governance.sol#L104
Description: Moving the event before setting the new value can save gas EX:
Recommendation: Consider Doing a similar code structure to save gas for setters.