Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Certora Audit] G-10. ++i costs less gas compared to i++ or i+=1 #897

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ contract Safe is
// we can safely ignore this malleability.
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
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions contracts/base/OwnerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager {
// Initializing Safe owners.
address currentOwner = SENTINEL_OWNERS;
uint256 ownersLength = _owners.length;
for (uint256 i = 0; i < ownersLength; i++) {
for (uint256 i = 0; i < ownersLength; ++i) {
// Owner address cannot be null.
address owner = _owners[i];
if (owner == address(0) || owner == SENTINEL_OWNERS || owner == address(this) || currentOwner == owner)
Expand All @@ -61,7 +61,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);
Expand Down Expand Up @@ -140,7 +140,7 @@ abstract contract OwnerManager is SelfAuthorized, IOwnerManager {
while (currentOwner != SENTINEL_OWNERS) {
array[index] = currentOwner;
currentOwner = owners[currentOwner];
index++;
++index;
}
return array;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/common/StorageAccessible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions contracts/handler/extensible/ERC165Handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract contract ERC165Handler is ExtensibleBase, IERC165Handler {
ISafe safe = ISafe(payable(_msgSender()));
bytes4 interfaceId;
uint256 len = handlerWithSelectors.length;
for (uint256 i = 0; i < len; i++) {
for (uint256 i = 0; i < len; ++i) {
(bool isStatic, bytes4 selector, address handlerAddress) = MarshalLib.decodeWithSelector(handlerWithSelectors[i]);
_setSafeMethod(safe, selector, MarshalLib.encode(isStatic, handlerAddress));
if (i > 0) {
Expand All @@ -79,7 +79,7 @@ abstract contract ERC165Handler is ExtensibleBase, IERC165Handler {
ISafe safe = ISafe(payable(_msgSender()));
bytes4 interfaceId;
uint256 len = selectors.length;
for (uint256 i = 0; i < len; i++) {
for (uint256 i = 0; i < len; ++i) {
_setSafeMethod(safe, selectors[i], bytes32(0));
if (i > 0) {
interfaceId ^= selectors[i];
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/SafeToL2Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ contract SafeToL2Migration is SafeStorage {
while (currentOwner != sentinelOwners) {
array[index] = currentOwner;
currentOwner = owners[currentOwner];
index++;
++index;
}
return array;
}
Expand Down
Loading