Open code423n4 opened 2 years ago
The for loop has no overflow risk of i. Use an unchecked block to save gas.
i
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/lib/GlobalAccessControlManaged.sol#L48 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/SupplySchedule.sol#L111 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/SupplySchedule.sol#L208 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/CitadelMinter.sol#L152 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/CitadelMinter.sol#L344
Use unchecked blocks to avoid overflow checks, or use ++i rather than i++ if you don't use unchecked blocks.
unchecked
++i
i++
for (uint256 i = 0; i < length; ) { ... unchecked { ++i; } }
Save gas in for loops by unchecked arithmetic
The for loop has no overflow risk of
i
. Use an unchecked block to save gas.Proof of Concept
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/lib/GlobalAccessControlManaged.sol#L48 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/SupplySchedule.sol#L111 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/SupplySchedule.sol#L208 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/CitadelMinter.sol#L152 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/CitadelMinter.sol#L344
Recommendation
Use
unchecked
blocks to avoid overflow checks, or use++i
rather thani++
if you don't use unchecked blocks.