[Certora Audit] G-10. ++i costs less gas compared to i++ or i+=1 #897
+9
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes several changes to increment and decrement operations in various Solidity contract files. The primary goal is to decrease gas usage.
Pre-increments and pre-decrements are cheaper.
For a uint256 i variable, the following is true with the Optimizer enabled at 10k:
Increment:
Decrement:
Changes to increment and decrement operations:
contracts/Safe.sol
: Updated the for loop to use the prefix increment operator in theSafe
contract.contracts/base/ModuleManager.sol
: Changed the increment operation to use the prefix increment operator in theModuleManager
contract.contracts/base/OwnerManager.sol
: Multiple updates to use prefix increment and decrement operators in theOwnerManager
contract. [1] [2] [3] [4]contracts/common/StorageAccessible.sol
: Modified the for loop to use the prefix increment operator in theStorageAccessible
contract.contracts/handler/extensible/ERC165Handler.sol
: Updated for loops to use the prefix increment operator in theERC165Handler
contract. [1] [2]contracts/libraries/SafeToL2Migration.sol
: Changed the increment operation to use the prefix increment operator in theSafeToL2Migration
contract.