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

fix: exec hooks behaviour when adding/removing #281

Merged
merged 2 commits into from
Feb 11, 2025
Merged
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
18 changes: 9 additions & 9 deletions src/managers/HookManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ abstract contract HookManager is IHookManager, SelfAuth {

// Runs the execution hooks that are enabled by the account before and after _executeTransaction
modifier runExecutionHooks(Transaction calldata transaction) {
EnumerableSet.AddressSet storage hookList = _executionHooks();
uint256 totalHooks = hookList.length();
address[] memory hookList = _executionHooks().values();
uint256 totalHooks = hookList.length;
bytes[] memory context = new bytes[](totalHooks);

for (uint256 i = 0; i < totalHooks; i++) {
context[i] = IExecutionHook(hookList.at(i)).preExecutionHook(transaction);
context[i] = IExecutionHook(hookList[i]).preExecutionHook(transaction);
}

_;

// If we removed any hooks, we have to update totalHooks.
// If we added any hooks, we don't want them to run yet.
if (totalHooks > hookList.length()) {
totalHooks = hookList.length();
}
EnumerableSet.AddressSet storage newHookList = _executionHooks();

for (uint256 i = 0; i < totalHooks; i++) {
IExecutionHook(hookList.at(i)).postExecutionHook(context[i]);
// Only execute hooks which are both in the old `hookList` and the `newHookList`,
// and we don't want to execute hooks that were removed and/or added during this transaction.
if (newHookList.contains(hookList[i])) {
IExecutionHook(hookList[i]).postExecutionHook(context[i]);
}
}
}

Expand Down