Skip to content

Commit 1869bd4

Browse files
committed
feat: run duplicate pre-hooks just once
1 parent 981bee8 commit 1869bd4

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

src/account/AccountLoupe.sol

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,7 @@ abstract contract AccountLoupe is IAccountLoupe {
4444

4545
/// @inheritdoc IAccountLoupe
4646
function getExecutionHooks(bytes4 selector) external view returns (ExecutionHooks[] memory execHooks) {
47-
execHooks = _getHooks(getAccountStorage().selectorData[selector].executionHooks);
48-
}
49-
50-
/// @inheritdoc IAccountLoupe
51-
function getPreValidationHooks(bytes4 selector)
52-
external
53-
view
54-
returns (
55-
FunctionReference[] memory preUserOpValidationHooks,
56-
FunctionReference[] memory preRuntimeValidationHooks
57-
)
58-
{
59-
preUserOpValidationHooks =
60-
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preUserOpValidationHooks);
61-
preRuntimeValidationHooks =
62-
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preRuntimeValidationHooks);
63-
}
64-
65-
/// @inheritdoc IAccountLoupe
66-
function getInstalledPlugins() external view returns (address[] memory pluginAddresses) {
67-
pluginAddresses = getAccountStorage().plugins.values();
68-
}
69-
70-
function _getHooks(HookGroup storage hooks) internal view returns (ExecutionHooks[] memory execHooks) {
47+
HookGroup storage hooks = getAccountStorage().selectorData[selector].executionHooks;
7148
uint256 preExecHooksLength = hooks.preHooks.length();
7249
uint256 postOnlyExecHooksLength = hooks.postOnlyHooks.length();
7350
uint256 maxExecHooksLength = postOnlyExecHooksLength;
@@ -129,4 +106,24 @@ abstract contract AccountLoupe is IAccountLoupe {
129106
mstore(execHooks, actualExecHooksLength)
130107
}
131108
}
109+
110+
/// @inheritdoc IAccountLoupe
111+
function getPreValidationHooks(bytes4 selector)
112+
external
113+
view
114+
returns (
115+
FunctionReference[] memory preUserOpValidationHooks,
116+
FunctionReference[] memory preRuntimeValidationHooks
117+
)
118+
{
119+
preUserOpValidationHooks =
120+
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preUserOpValidationHooks);
121+
preRuntimeValidationHooks =
122+
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preRuntimeValidationHooks);
123+
}
124+
125+
/// @inheritdoc IAccountLoupe
126+
function getInstalledPlugins() external view returns (address[] memory pluginAddresses) {
127+
pluginAddresses = getAccountStorage().plugins.values();
128+
}
132129
}

src/account/UpgradeableModularAccount.sol

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,6 @@ contract UpgradeableModularAccount is
470470
returns (PostExecToRun[] memory postHooksToRun)
471471
{
472472
HookGroup storage hooks = getAccountStorage().selectorData[selector].executionHooks;
473-
474-
return _doPreHooks(hooks, data);
475-
}
476-
477-
function _doPreHooks(HookGroup storage hooks, bytes calldata data)
478-
internal
479-
returns (PostExecToRun[] memory postHooksToRun)
480-
{
481473
uint256 preExecHooksLength = hooks.preHooks.length();
482474
uint256 postOnlyHooksLength = hooks.postOnlyHooks.length();
483475
uint256 maxPostExecHooksLength = postOnlyHooksLength;
@@ -517,21 +509,20 @@ contract UpgradeableModularAccount is
517509
revert AlwaysDenyRule();
518510
}
519511

512+
bytes memory preExecHookReturnData = _runPreExecHook(preExecHook, data);
513+
520514
uint256 associatedPostExecHooksLength = hooks.associatedPostHooks[preExecHook].length();
521515
if (associatedPostExecHooksLength > 0) {
522516
for (uint256 j = 0; j < associatedPostExecHooksLength;) {
523517
(key,) = hooks.associatedPostHooks[preExecHook].at(j);
524518
postHooksToRun[actualPostHooksToRunLength].postExecHook = _toFunctionReference(key);
525-
postHooksToRun[actualPostHooksToRunLength].preExecHookReturnData =
526-
_runPreExecHook(preExecHook, data);
519+
postHooksToRun[actualPostHooksToRunLength].preExecHookReturnData = preExecHookReturnData;
527520

528521
unchecked {
529522
++actualPostHooksToRunLength;
530523
++j;
531524
}
532525
}
533-
} else {
534-
_runPreExecHook(preExecHook, data);
535526
}
536527

537528
unchecked {

0 commit comments

Comments
 (0)