From 2e69f78eddbd7bd1bdc368fddc42700d521b3020 Mon Sep 17 00:00:00 2001 From: Shebin John Date: Thu, 9 Jan 2025 15:10:41 +0100 Subject: [PATCH] G-10. ++i costs less gas compared to i++ or i+=1 --- contracts/Safe.sol | 2 +- contracts/base/ModuleManager.sol | 2 +- contracts/base/OwnerManager.sol | 8 ++++---- contracts/common/StorageAccessible.sol | 2 +- contracts/handler/extensible/ERC165Handler.sol | 4 ++-- contracts/libraries/SafeToL2Migration.sol | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/contracts/Safe.sol b/contracts/Safe.sol index b75eedb50..8ccd69303 100644 --- a/contracts/Safe.sol +++ b/contracts/Safe.sol @@ -293,7 +293,7 @@ contract Safe is bytes32 r; bytes32 s; uint256 i; - for (i = 0; i < requiredSignatures; i++) { + for (i = 0; i < requiredSignatures; ++i) { (v, r, s) = signatureSplit(signatures, i); if (v == 0) { // If v is 0 then it is a contract signature diff --git a/contracts/base/ModuleManager.sol b/contracts/base/ModuleManager.sol index b3985be85..9b1c9d409 100644 --- a/contracts/base/ModuleManager.sol +++ b/contracts/base/ModuleManager.sol @@ -212,7 +212,7 @@ abstract contract ModuleManager is SelfAuthorized, Executor, IModuleManager { while (next != address(0) && next != SENTINEL_MODULES && moduleCount < pageSize) { array[moduleCount] = next; next = modules[next]; - moduleCount++; + ++moduleCount; } /** diff --git a/contracts/base/OwnerManager.sol b/contracts/base/OwnerManager.sol index a74493b40..a4c04bc12 100644 --- a/contracts/base/OwnerManager.sol +++ b/contracts/base/OwnerManager.sol @@ -35,7 +35,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager { if (_threshold == 0) revertWithError("GS202"); // Initializing Safe owners. address currentOwner = SENTINEL_OWNERS; - for (uint256 i = 0; i < _owners.length; i++) { + for (uint256 i = 0; i < _owners.length; ++i) { // Owner address cannot be null. address owner = _owners[i]; if (owner == address(0) || owner == SENTINEL_OWNERS || owner == address(this) || currentOwner == owner) @@ -60,7 +60,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager { if (owners[owner] != address(0)) revertWithError("GS204"); owners[owner] = owners[SENTINEL_OWNERS]; owners[SENTINEL_OWNERS] = owner; - ownerCount++; + ++ownerCount; emit AddedOwner(owner); // Change threshold if threshold was changed. if (threshold != _threshold) changeThreshold(_threshold); @@ -77,7 +77,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager { if (owners[prevOwner] != owner) revertWithError("GS205"); owners[prevOwner] = owners[owner]; owners[owner] = address(0); - ownerCount--; + --ownerCount; emit RemovedOwner(owner); // Change threshold if threshold was changed. if (threshold != _threshold) changeThreshold(_threshold); @@ -139,7 +139,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager { while (currentOwner != SENTINEL_OWNERS) { array[index] = currentOwner; currentOwner = owners[currentOwner]; - index++; + ++index; } return array; } diff --git a/contracts/common/StorageAccessible.sol b/contracts/common/StorageAccessible.sol index 9b4e6a9c3..c9862910f 100644 --- a/contracts/common/StorageAccessible.sol +++ b/contracts/common/StorageAccessible.sol @@ -16,7 +16,7 @@ abstract contract StorageAccessible { */ function getStorageAt(uint256 offset, uint256 length) public view returns (bytes memory) { bytes memory result = new bytes(length * 32); - for (uint256 index = 0; index < length; index++) { + for (uint256 index = 0; index < length; ++index) { /* solhint-disable no-inline-assembly */ /// @solidity memory-safe-assembly assembly { diff --git a/contracts/handler/extensible/ERC165Handler.sol b/contracts/handler/extensible/ERC165Handler.sol index 4833ddcdf..fa4e59c68 100644 --- a/contracts/handler/extensible/ERC165Handler.sol +++ b/contracts/handler/extensible/ERC165Handler.sol @@ -53,7 +53,7 @@ abstract contract ERC165Handler is ExtensibleBase, IERC165Handler { function addSupportedInterfaceBatch(bytes4 _interfaceId, bytes32[] calldata handlerWithSelectors) external override onlySelf { ISafe safe = ISafe(payable(_msgSender())); bytes4 interfaceId; - for (uint256 i = 0; i < handlerWithSelectors.length; i++) { + for (uint256 i = 0; i < handlerWithSelectors.length; ++i) { (bool isStatic, bytes4 selector, address handlerAddress) = MarshalLib.decodeWithSelector(handlerWithSelectors[i]); _setSafeMethod(safe, selector, MarshalLib.encode(isStatic, handlerAddress)); if (i > 0) { @@ -75,7 +75,7 @@ abstract contract ERC165Handler is ExtensibleBase, IERC165Handler { function removeSupportedInterfaceBatch(bytes4 _interfaceId, bytes4[] calldata selectors) external override onlySelf { ISafe safe = ISafe(payable(_msgSender())); bytes4 interfaceId; - for (uint256 i = 0; i < selectors.length; i++) { + for (uint256 i = 0; i < selectors.length; ++i) { _setSafeMethod(safe, selectors[i], bytes32(0)); if (i > 0) { interfaceId ^= selectors[i]; diff --git a/contracts/libraries/SafeToL2Migration.sol b/contracts/libraries/SafeToL2Migration.sol index 680b17385..176f2e926 100644 --- a/contracts/libraries/SafeToL2Migration.sol +++ b/contracts/libraries/SafeToL2Migration.sol @@ -185,7 +185,7 @@ contract SafeToL2Migration is SafeStorage { while (currentOwner != sentinelOwners) { array[index] = currentOwner; currentOwner = owners[currentOwner]; - index++; + ++index; } return array; }