Skip to content

Commit

Permalink
Remove explicit uncheck blocks for loop increments
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Jan 19, 2024
1 parent 617677a commit 0539cc7
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 257 deletions.
10 changes: 2 additions & 8 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
solc = '0.8.21'
solc = '0.8.22'
evm_version='paris'
via_ir = true
src = 'src'
Expand All @@ -14,33 +14,27 @@ ignored_error_codes = []
runs = 500

[invariant]
runs=500
runs = 500
fail_on_revert = true
depth = 10

[profile.optimized-build]
via_ir = true
evm_version='paris'
script = 'src'
test = 'src'
out = 'out-optimized'

[profile.lite]
solc = '0.8.21'
evm_version='paris'
via_ir = false
optimizer = true
optimizer_runs = 10_000
ignored_error_codes = []

[profile.deep.fuzz]
runs = 10000
evm_version='paris'

[profile.deep.invariant]
runs = 5000
depth = 32
evm_version='paris'

[fmt]
line_length = 115
Expand Down
15 changes: 4 additions & 11 deletions src/account/AccountLoupe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,28 @@ abstract contract AccountLoupe is IAccountLoupe, AccountStorageV1 {
uint256 maxExecHooksLength = postOnlyExecHooksLength;

// There can only be as many associated post hooks to run as there are pre hooks.
for (uint256 i = 0; i < preExecHooksLength;) {
for (uint256 i = 0; i < preExecHooksLength; ++i) {
unchecked {
maxExecHooksLength += storedHooks.preHooks.getCount(CastLib.toSetValue(preExecHooks[i]));
++i;
}
}

// Overallocate on length - not all of this may get filled up. We set the correct length later.
execHooks = new ExecutionHooks[](maxExecHooksLength);
uint256 actualExecHooksLength = 0;

for (uint256 i = 0; i < preExecHooksLength;) {
for (uint256 i = 0; i < preExecHooksLength; ++i) {
FunctionReference[] memory associatedPostExecHooks =
CastLib.toFunctionReferenceArray(storedHooks.associatedPostHooks[preExecHooks[i]].getAll());
uint256 associatedPostExecHooksLength = associatedPostExecHooks.length;

if (associatedPostExecHooksLength > 0) {
for (uint256 j = 0; j < associatedPostExecHooksLength;) {
for (uint256 j = 0; j < associatedPostExecHooksLength; ++j) {
execHooks[actualExecHooksLength].preExecHook = preExecHooks[i];
execHooks[actualExecHooksLength].postExecHook = associatedPostExecHooks[j];

unchecked {
++actualExecHooksLength;
++j;
}
}
} else {
Expand All @@ -118,18 +116,13 @@ abstract contract AccountLoupe is IAccountLoupe, AccountStorageV1 {
++actualExecHooksLength;
}
}

unchecked {
++i;
}
}

for (uint256 i = 0; i < postOnlyExecHooksLength;) {
for (uint256 i = 0; i < postOnlyExecHooksLength; ++i) {
execHooks[actualExecHooksLength].postExecHook = postOnlyExecHooks[i];

unchecked {
++actualExecHooksLength;
++i;
}
}

Expand Down
Loading

0 comments on commit 0539cc7

Please sign in to comment.