From ff8273d823b1ee8f35d34b8ef4db79e88d370b63 Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Tue, 11 Feb 2025 15:58:46 +0200 Subject: [PATCH] fix: exec hooks behaviour when adding/removing (#281) * fix: exec hooks behaviour when adding/removing * fix: don't execute hooks which have been removed/added during current tx --- src/managers/HookManager.sol | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/managers/HookManager.sol b/src/managers/HookManager.sol index 9d9e177f..4559843d 100644 --- a/src/managers/HookManager.sol +++ b/src/managers/HookManager.sol @@ -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]); + } } }