Skip to content

Commit a6e0fc3

Browse files
authored
chore: rename permissions hook to execution hook (#174)
1 parent 462673f commit a6e0fc3

File tree

9 files changed

+57
-57
lines changed

9 files changed

+57
-57
lines changed

src/account/AccountStorage.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ struct ValidationData {
3333
bool isUserOpValidation;
3434
// The pre validation hooks for this validation function.
3535
ModuleEntity[] preValidationHooks;
36-
// Permission hooks for this validation function.
37-
EnumerableSet.Bytes32Set permissionHooks;
36+
// Execution hooks to run with this validation function.
37+
EnumerableSet.Bytes32Set executionHooks;
3838
// The set of selectors that may be validated by this validation function.
3939
EnumerableSet.Bytes32Set selectors;
4040
}

src/account/ModularAccountView.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ abstract contract ModularAccountView is IModularAccountView {
5252
data.isUserOpValidation = validationData.isUserOpValidation;
5353
data.preValidationHooks = validationData.preValidationHooks;
5454

55-
uint256 permissionHooksLen = validationData.permissionHooks.length();
56-
data.permissionHooks = new HookConfig[](permissionHooksLen);
57-
for (uint256 i = 0; i < permissionHooksLen; ++i) {
58-
data.permissionHooks[i] = toHookConfig(validationData.permissionHooks.at(i));
55+
uint256 execHooksLen = validationData.executionHooks.length();
56+
data.executionHooks = new HookConfig[](execHooksLen);
57+
for (uint256 i = 0; i < execHooksLen; ++i) {
58+
data.executionHooks[i] = toHookConfig(validationData.executionHooks.at(i));
5959
}
6060

6161
bytes32[] memory selectors = validationData.selectors.values();

src/account/ModuleManagerInternals.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract contract ModuleManagerInternals is IModularAccount {
3939
error InterfaceNotSupported(address module);
4040
error NativeFunctionNotAllowed(bytes4 selector);
4141
error NullModule();
42-
error PermissionAlreadySet(ModuleEntity validationFunction, HookConfig hookConfig);
42+
error ExecutionHookAlreadySet(HookConfig hookConfig);
4343
error ModuleInstallCallbackFailed(address module, bytes revertReason);
4444
error ModuleNotInstalled(address module);
4545
error PreValidationHookLimitExceeded();
@@ -106,7 +106,9 @@ abstract contract ModuleManagerInternals is IModularAccount {
106106
}
107107

108108
function _addExecHooks(EnumerableSet.Bytes32Set storage hooks, HookConfig hookConfig) internal {
109-
hooks.add(toSetValue(hookConfig));
109+
if (!hooks.add(toSetValue(hookConfig))) {
110+
revert ExecutionHookAlreadySet(hookConfig);
111+
}
110112
}
111113

112114
function _removeExecHooks(EnumerableSet.Bytes32Set storage hooks, HookConfig hookConfig) internal {
@@ -247,10 +249,8 @@ abstract contract ModuleManagerInternals is IModularAccount {
247249

248250
continue;
249251
}
250-
// Hook is a permission hook
251-
if (!_validationData.permissionHooks.add(toSetValue(hookConfig))) {
252-
revert PermissionAlreadySet(moduleEntity, hookConfig);
253-
}
252+
// Hook is an execution hook
253+
_addExecHooks(_validationData.executionHooks, hookConfig);
254254

255255
_onInstall(hookConfig.module(), hookData, type(IExecutionHookModule).interfaceId);
256256
}
@@ -285,12 +285,12 @@ abstract contract ModuleManagerInternals is IModularAccount {
285285
// If any uninstall data is provided, assert it is of the correct length.
286286
if (
287287
hookUninstallDatas.length
288-
!= _validationData.preValidationHooks.length + _validationData.permissionHooks.length()
288+
!= _validationData.preValidationHooks.length + _validationData.executionHooks.length()
289289
) {
290290
revert ArrayLengthMismatch();
291291
}
292292

293-
// Hook uninstall data is provided in the order of pre validation hooks, then permission hooks.
293+
// Hook uninstall data is provided in the order of pre validation hooks, then execution hooks.
294294
uint256 hookIndex = 0;
295295
for (uint256 i = 0; i < _validationData.preValidationHooks.length; ++i) {
296296
bytes calldata hookData = hookUninstallDatas[hookIndex];
@@ -299,10 +299,10 @@ abstract contract ModuleManagerInternals is IModularAccount {
299299
hookIndex++;
300300
}
301301

302-
for (uint256 i = 0; i < _validationData.permissionHooks.length(); ++i) {
302+
for (uint256 i = 0; i < _validationData.executionHooks.length(); ++i) {
303303
bytes calldata hookData = hookUninstallDatas[hookIndex];
304304
(address hookModule,) =
305-
ModuleEntityLib.unpack(toModuleEntity(_validationData.permissionHooks.at(i)));
305+
ModuleEntityLib.unpack(toModuleEntity(_validationData.executionHooks.at(i)));
306306
onUninstallSuccess = onUninstallSuccess && _onUninstall(hookModule, hookData);
307307
hookIndex++;
308308
}
@@ -311,11 +311,11 @@ abstract contract ModuleManagerInternals is IModularAccount {
311311
// Clear all stored hooks
312312
delete _validationData.preValidationHooks;
313313

314-
EnumerableSet.Bytes32Set storage permissionHooks = _validationData.permissionHooks;
315-
uint256 permissionHookLen = permissionHooks.length();
316-
for (uint256 i = 0; i < permissionHookLen; ++i) {
317-
bytes32 permissionHook = permissionHooks.at(0);
318-
permissionHooks.remove(permissionHook);
314+
EnumerableSet.Bytes32Set storage executionHooks = _validationData.executionHooks;
315+
uint256 executionHookLen = executionHooks.length();
316+
for (uint256 i = 0; i < executionHookLen; ++i) {
317+
bytes32 executionHook = executionHooks.at(0);
318+
executionHooks.remove(executionHook);
319319
}
320320

321321
// Clear selectors

src/account/ReferenceModularAccount.sol

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ contract ReferenceModularAccount is
8484
// Wraps execution of a native function with runtime validation and hooks
8585
// Used for upgradeTo, upgradeToAndCall, execute, executeBatch, installExecution, uninstallExecution
8686
modifier wrapNativeFunction() {
87-
(PostExecToRun[] memory postPermissionHooks, PostExecToRun[] memory postExecHooks) =
87+
(PostExecToRun[] memory postValidatorExecHooks, PostExecToRun[] memory postSelectorExecHooks) =
8888
_checkPermittedCallerAndAssociatedHooks();
8989

9090
_;
9191

92-
_doCachedPostExecHooks(postExecHooks);
93-
_doCachedPostExecHooks(postPermissionHooks);
92+
_doCachedPostExecHooks(postSelectorExecHooks);
93+
_doCachedPostExecHooks(postValidatorExecHooks);
9494
}
9595

9696
constructor(IEntryPoint anEntryPoint) {
@@ -110,7 +110,7 @@ contract ReferenceModularAccount is
110110
if (execModule == address(0)) {
111111
revert UnrecognizedFunction(msg.sig);
112112
}
113-
(PostExecToRun[] memory postPermissionHooks, PostExecToRun[] memory postExecHooks) =
113+
(PostExecToRun[] memory postValidatorExecHooks, PostExecToRun[] memory postSelectorExecHooks) =
114114
_checkPermittedCallerAndAssociatedHooks();
115115

116116
// execute the function, bubbling up any reverts
@@ -123,8 +123,8 @@ contract ReferenceModularAccount is
123123
}
124124
}
125125

126-
_doCachedPostExecHooks(postExecHooks);
127-
_doCachedPostExecHooks(postPermissionHooks);
126+
_doCachedPostExecHooks(postSelectorExecHooks);
127+
_doCachedPostExecHooks(postValidatorExecHooks);
128128

129129
return execReturnData;
130130
}
@@ -139,8 +139,8 @@ contract ReferenceModularAccount is
139139

140140
ModuleEntity userOpValidationFunction = ModuleEntity.wrap(bytes24(userOp.signature[:24]));
141141

142-
PostExecToRun[] memory postPermissionHooks =
143-
_doPreHooks(getAccountStorage().validationData[userOpValidationFunction].permissionHooks, msg.data);
142+
PostExecToRun[] memory postValidatorExecHooks =
143+
_doPreHooks(getAccountStorage().validationData[userOpValidationFunction].executionHooks, msg.data);
144144

145145
(bool success, bytes memory result) = address(this).call(userOp.callData[4:]);
146146

@@ -151,7 +151,7 @@ contract ReferenceModularAccount is
151151
}
152152
}
153153

154-
_doCachedPostExecHooks(postPermissionHooks);
154+
_doCachedPostExecHooks(postValidatorExecHooks);
155155
}
156156

157157
/// @inheritdoc IModularAccount
@@ -202,9 +202,9 @@ contract ReferenceModularAccount is
202202

203203
_doRuntimeValidation(runtimeValidationFunction, data, authorization[25:]);
204204

205-
// If runtime validation passes, do runtime permission checks
206-
PostExecToRun[] memory postPermissionHooks =
207-
_doPreHooks(getAccountStorage().validationData[runtimeValidationFunction].permissionHooks, data);
205+
// If runtime validation passes, run exec hooks associated with the validator
206+
PostExecToRun[] memory postValidatorExecHooks =
207+
_doPreHooks(getAccountStorage().validationData[runtimeValidationFunction].executionHooks, data);
208208

209209
// Execute the call
210210
(bool success, bytes memory returnData) = address(this).call(data);
@@ -215,7 +215,7 @@ contract ReferenceModularAccount is
215215
}
216216
}
217217

218-
_doCachedPostExecHooks(postPermissionHooks);
218+
_doCachedPostExecHooks(postValidatorExecHooks);
219219

220220
return returnData;
221221
}
@@ -254,7 +254,7 @@ contract ReferenceModularAccount is
254254
/// @inheritdoc IModularAccount
255255
/// @notice May be validated by a global validation.
256256
/// @dev This function can be used to update (to a certain degree) previously installed validation functions.
257-
/// - preValidationHook, permissionHook, and selectors can be added later. Though they won't be deleted.
257+
/// - preValidationHook, executionHooks, and selectors can be added later. Though they won't be deleted.
258258
/// - isGlobal and isSignatureValidation can also be updated later.
259259
function installValidation(
260260
ValidationConfig validationConfig,
@@ -360,12 +360,12 @@ contract ReferenceModularAccount is
360360
isGlobalValidation ? ValidationCheckingType.GLOBAL : ValidationCheckingType.SELECTOR
361361
);
362362

363-
// Check if there are permission hooks associated with the validator, and revert if the call isn't to
363+
// Check if there are execution hooks associated with the validator, and revert if the call isn't to
364364
// `executeUserOp`
365365
// This check must be here because if context isn't passed, we can't tell in execution which hooks should
366366
// have ran
367367
if (
368-
getAccountStorage().validationData[userOpValidationFunction].permissionHooks.length() > 0
368+
getAccountStorage().validationData[userOpValidationFunction].executionHooks.length() > 0
369369
&& bytes4(userOp.callData[:4]) != this.executeUserOp.selector
370370
) {
371371
revert RequireUserOperationContext();
@@ -538,24 +538,24 @@ contract ReferenceModularAccount is
538538
/**
539539
* Order of operations:
540540
* 1. Check if the sender is the entry point, the account itself, or the selector called is public.
541-
* - Yes: Return an empty array, there are no post permissionHooks.
541+
* - Yes: Return an empty array, there are no post executionHooks.
542542
* - No: Continue
543543
* 2. Check if the called selector (msg.sig) is included in the set of selectors the msg.sender can
544544
* directly call.
545545
* - Yes: Continue
546546
* - No: Revert, the caller is not allowed to call this selector
547547
* 3. If there are runtime validation hooks associated with this caller-sig combination, run them.
548-
* 4. Run the pre permissionHooks associated with this caller-sig combination, and return the
549-
* post permissionHooks to run later.
548+
* 4. Run the pre executionHooks associated with this caller-sig combination, and return the
549+
* post executionHooks to run later.
550550
*/
551551
function _checkPermittedCallerAndAssociatedHooks()
552552
internal
553553
returns (PostExecToRun[] memory, PostExecToRun[] memory)
554554
{
555555
AccountStorage storage _storage = getAccountStorage();
556-
PostExecToRun[] memory postPermissionHooks;
556+
PostExecToRun[] memory postValidatorExecutionHooks;
557557

558-
// We only need to handle permission hooks when the sender is not the entry point or the account itself,
558+
// We only need to handle execution hooks when the sender is not the entry point or the account itself,
559559
// and the selector isn't public.
560560
if (
561561
msg.sender != address(_ENTRY_POINT) && msg.sender != address(this)
@@ -566,7 +566,7 @@ contract ReferenceModularAccount is
566566

567567
_checkIfValidationAppliesCallData(msg.data, directCallValidationKey, ValidationCheckingType.EITHER);
568568

569-
// Direct call is allowed, run associated permission & validation hooks
569+
// Direct call is allowed, run associated execution & validation hooks
570570

571571
// Validation hooks
572572
ModuleEntity[] memory preRuntimeValidationHooks =
@@ -577,16 +577,16 @@ contract ReferenceModularAccount is
577577
_doPreRuntimeValidationHook(preRuntimeValidationHooks[i], msg.data, "");
578578
}
579579

580-
// Permission hooks
581-
postPermissionHooks =
582-
_doPreHooks(_storage.validationData[directCallValidationKey].permissionHooks, msg.data);
580+
// Execution hooks associated with the validator
581+
postValidatorExecutionHooks =
582+
_doPreHooks(_storage.validationData[directCallValidationKey].executionHooks, msg.data);
583583
}
584584

585-
// Exec hooks
586-
PostExecToRun[] memory postExecutionHooks =
585+
// Exec hooks associated with the selector
586+
PostExecToRun[] memory postSelectorExecutionHooks =
587587
_doPreHooks(_storage.executionData[msg.sig].executionHooks, msg.data);
588588

589-
return (postPermissionHooks, postExecutionHooks);
589+
return (postValidatorExecutionHooks, postSelectorExecutionHooks);
590590
}
591591

592592
function _execUserOpValidation(

src/interfaces/IModularAccount.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ interface IModularAccount {
107107
/// @param uninstallData Optional data to be decoded and used by the module to clear module data for the
108108
/// account.
109109
/// @param hookUninstallData Optional data to be used by hooks for cleanup. If any are provided, the array must
110-
/// be of a length equal to existing pre validation hooks plus permission hooks. Hooks are indexed by
111-
/// pre validation hook order first, then permission hooks.
110+
/// be of a length equal to existing pre validation hooks plus execution hooks. Hooks are indexed by
111+
/// pre validation hook order first, then execution hooks.
112112
function uninstallValidation(
113113
ModuleEntity validationFunction,
114114
bytes calldata uninstallData,

src/interfaces/IModularAccountView.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct ValidationDataView {
2828
bool isUserOpValidation;
2929
// The pre validation hooks for this validation function.
3030
ModuleEntity[] preValidationHooks;
31-
// Permission hooks for this validation function.
32-
HookConfig[] permissionHooks;
31+
// Execution hooks to run with this validation function.
32+
HookConfig[] executionHooks;
3333
// The set of selectors that may be validated by this validation function.
3434
bytes4[] selectors;
3535
}

test/account/ModularAccountView.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ contract ModularAccountViewTest is CustomValidationTestBase {
121121
)
122122
);
123123

124-
assertEq(data.permissionHooks.length, 0);
124+
assertEq(data.executionHooks.length, 0);
125125
assertEq(selectors.length, 1);
126126
assertEq(selectors[0], comprehensiveModule.foo.selector);
127127
}

test/account/ReplaceModule.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ contract UpgradeModuleTest is AccountTestBase {
9898
}
9999

100100
function test_upgradeModuleValidationFunction() public {
101-
// Setup new validaiton with pre validation and permission hooks
101+
// Setup new validaiton with pre validation and execution hooks associated with a validator
102102
SingleSignerValidationModule validation1 = new SingleSignerValidationModule();
103103
SingleSignerValidationModule validation2 = new SingleSignerValidationModule();
104104
uint32 validationEntityId1 = 10;

test/mocks/modules/DirectCallModule.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ contract DirectCallModule is BaseModule, IExecutionHookModule {
3232
override
3333
returns (bytes memory)
3434
{
35-
require(sender == address(this), "mock direct call pre permission hook failed");
35+
require(sender == address(this), "mock direct call pre execution hook failed");
3636
preHookRan = true;
3737
return abi.encode(keccak256(hex"04546b"));
3838
}
3939

4040
function postExecutionHook(uint32, bytes calldata preExecHookData) external override {
4141
require(
4242
abi.decode(preExecHookData, (bytes32)) == keccak256(hex"04546b"),
43-
"mock direct call post permission hook failed"
43+
"mock direct call post execution hook failed"
4444
);
4545
postHookRan = true;
4646
}

0 commit comments

Comments
 (0)