Skip to content

Commit

Permalink
Feat/events (#120)
Browse files Browse the repository at this point in the history
* events for install/uninstall

* chore add even on install without init
  • Loading branch information
leekt authored Jun 12, 2024
1 parent 0e1c950 commit 56b8bc9
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 56 deletions.
124 changes: 124 additions & 0 deletions broadcast/DeployKernel.s.sol/11155111/run-1718039360.json

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions broadcast/DeployKernel.s.sol/11155111/run-1718039506.json

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions broadcast/DeployKernel.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,21 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
// NOTE: for hook, kernel does not support independent hook install,
// hook is expected to be paired with proper validator/executor/selector
IHook(module).onInstall(initData);
emit ModuleInstalled(moduleType, module);
} else if (moduleType == MODULE_TYPE_POLICY) {
// force call onInstall for policy
// NOTE: for policy, kernel does not support independent policy install,
// policy is expected to be paired with proper permissionId
// to "ADD" permission, use "installValidations()" function
IPolicy(module).onInstall(initData);
emit ModuleInstalled(moduleType, module);
} else if (moduleType == MODULE_TYPE_SIGNER) {
// force call onInstall for signer
// NOTE: for signer, kernel does not support independent signer install,
// signer is expected to be paired with proper permissionId
// to "ADD" permission, use "installValidations()" function
ISigner(module).onInstall(initData);
emit ModuleInstalled(moduleType, module);
} else {
revert InvalidModuleType();
}
Expand Down Expand Up @@ -458,10 +461,11 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
// remove hook on root validator to prevent kernel from being locked
_validationStorage().validationConfig[vId].hook = IHook(address(1));
}
// force call onInstall for hook
// force call onUninstall for hook
// NOTE: for hook, kernel does not support independent hook install,
// hook is expected to be paired with proper validator/executor/selector
ModuleLib.uninstallModule(module, deInitData);
emit ModuleUninstalled(moduleType, module);
} else if (moduleType == 5) {
ValidationId rootValidator = _validationStorage().rootValidator;
bytes32 permissionId = bytes32(deInitData[0:32]);
Expand All @@ -470,11 +474,12 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
revert RootValidatorCannotBeRemoved();
}
}
// force call onInstall for policy
// force call onUninstall for policy
// NOTE: for policy, kernel does not support independent policy install,
// policy is expected to be paired with proper permissionId
// to "REMOVE" permission, use "uninstallValidation()" function
ModuleLib.uninstallModule(module, deInitData);
emit ModuleUninstalled(moduleType, module);
} else if (moduleType == 6) {
ValidationId rootValidator = _validationStorage().rootValidator;
bytes32 permissionId = bytes32(deInitData[0:32]);
Expand All @@ -483,11 +488,12 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
revert RootValidatorCannotBeRemoved();
}
}
// force call onInstall for signer
// force call onUninstall for signer
// NOTE: for signer, kernel does not support independent signer install,
// signer is expected to be paired with proper permissionId
// to "REMOVE" permission, use "uninstallValidation()" function
ModuleLib.uninstallModule(module, deInitData);
emit ModuleUninstalled(moduleType, module);
} else {
revert InvalidModuleType();
}
Expand Down
11 changes: 5 additions & 6 deletions src/core/ExecutorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
pragma solidity ^0.8.0;

import {IHook, IExecutor} from "../interfaces/IERC7579Modules.sol";
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
import {ModuleLib} from "../utils/ModuleLib.sol";
import {EXECUTOR_MANAGER_STORAGE_SLOT} from "../types/Constants.sol";
import {EXECUTOR_MANAGER_STORAGE_SLOT, MODULE_TYPE_EXECUTOR} from "../types/Constants.sol";

abstract contract ExecutorManager {
struct ExecutorConfig {
Expand All @@ -29,11 +30,7 @@ abstract contract ExecutorManager {
}

function _installExecutor(IExecutor executor, bytes calldata executorData, IHook hook) internal {
if (address(hook) == address(0)) {
hook = IHook(address(1));
}
ExecutorConfig storage config = _executorConfig(executor);
config.hook = hook;
_installExecutorWithoutInit(executor, hook);
executor.onInstall(executorData);
}

Expand All @@ -43,12 +40,14 @@ abstract contract ExecutorManager {
}
ExecutorConfig storage config = _executorConfig(executor);
config.hook = hook;
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_EXECUTOR, address(executor));
}

function _uninstallExecutor(IExecutor executor, bytes calldata executorData) internal returns (IHook hook) {
ExecutorConfig storage config = _executorConfig(executor);
hook = config.hook;
config.hook = IHook(address(0));
ModuleLib.uninstallModule(address(executor), executorData);
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_EXECUTOR, address(executor));
}
}
8 changes: 5 additions & 3 deletions src/core/HookManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.0;

import {IHook} from "../interfaces/IERC7579Modules.sol";
import {ModuleLib} from "../utils/ModuleLib.sol";
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
import {MODULE_TYPE_HOOK} from "../types/Constants.sol";

abstract contract HookManager {
// NOTE: currently, all install/uninstall calls onInstall/onUninstall
Expand Down Expand Up @@ -32,12 +34,11 @@ abstract contract HookManager {
if (!hook.isInitialized(address(this))) {
// if hook is not installed, it should call onInstall
hook.onInstall(hookData[1:]);
return;
}
if (bytes1(hookData[0]) == bytes1(0xff)) {
} else if (bytes1(hookData[0]) == bytes1(0xff)) {
// 0xff means you want to explicitly call install hook
hook.onInstall(hookData[1:]);
}
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_HOOK, address(hook));
}

// @param hookData encoded as (1bytes flag + actual hookdata) flag is for identifying if the hook has to be initialized or not
Expand All @@ -49,5 +50,6 @@ abstract contract HookManager {
// 0xff means you want to call uninstall hook
ModuleLib.uninstallModule(address(hook), hookData[1:]);
}
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_HOOK, address(hook));
}
}
16 changes: 13 additions & 3 deletions src/core/SelectorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
pragma solidity ^0.8.0;

import {IHook, IFallback, IModule} from "../interfaces/IERC7579Modules.sol";
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
import {CallType} from "../utils/ExecLib.sol";
import {SELECTOR_MANAGER_STORAGE_SLOT, CALLTYPE_DELEGATECALL, CALLTYPE_SINGLE} from "../types/Constants.sol";
import {
SELECTOR_MANAGER_STORAGE_SLOT,
CALLTYPE_DELEGATECALL,
CALLTYPE_SINGLE,
MODULE_TYPE_FALLBACK
} from "../types/Constants.sol";
import {ModuleLib} from "../utils/ModuleLib.sol";

abstract contract SelectorManager {
Expand Down Expand Up @@ -44,6 +50,7 @@ abstract contract SelectorManager {
CallType callType = CallType.wrap(bytes1(selectorData[0]));
if (callType == CALLTYPE_SINGLE) {
IModule(target).onInstall(selectorData[1:]);
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_FALLBACK, target);
} else if (callType != CALLTYPE_DELEGATECALL) {
// NOTE : we are not going to call onInstall for delegatecall, and we support only CALL & DELEGATECALL
revert NotSupportedCallType();
Expand All @@ -57,8 +64,11 @@ abstract contract SelectorManager {
SelectorConfig storage ss = _selectorConfig(selector);
hook = ss.hook;
ss.hook = IHook(address(0));
ModuleLib.uninstallModule(ss.target, selectorDeinitData);
if (ss.callType == CALLTYPE_SINGLE) {
ModuleLib.uninstallModule(ss.target, selectorDeinitData);
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_FALLBACK, ss.target);
}
ss.target = address(0);
ss.callType = CallType.wrap(bytes1(0xff));
ss.callType = CallType.wrap(bytes1(0x00));
}
}
11 changes: 10 additions & 1 deletion src/core/ValidationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import {IValidator, IModule, IExecutor, IHook, IPolicy, ISigner, IFallback} from "../interfaces/IERC7579Modules.sol";
import {IERC7579Account} from "../interfaces/IERC7579Account.sol";
import {PackedUserOperation} from "../interfaces/PackedUserOperation.sol";
import {SelectorManager} from "./SelectorManager.sol";
import {HookManager} from "./HookManager.sol";
Expand All @@ -20,7 +21,7 @@ import {
} from "../utils/ValidationTypeLib.sol";

import {CallType} from "../utils/ExecLib.sol";
import {CALLTYPE_SINGLE} from "../types/Constants.sol";
import {CALLTYPE_SINGLE, MODULE_TYPE_POLICY, MODULE_TYPE_SIGNER, MODULE_TYPE_VALIDATOR} from "../types/Constants.sol";

import {PermissionId, getValidationResult} from "../types/Types.sol";
import {_intersectValidationData} from "../utils/KernelValidationResult.sol";
Expand Down Expand Up @@ -173,6 +174,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
if (vType == VALIDATION_TYPE_VALIDATOR) {
IValidator validator = ValidatorLib.getValidator(vId);
ModuleLib.uninstallModule(address(validator), validatorData);
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_VALIDATOR, address(validator));
} else if (vType == VALIDATION_TYPE_PERMISSION) {
PermissionId permission = ValidatorLib.getPermissionId(vId);
_uninstallPermission(permission, validatorData);
Expand All @@ -198,6 +200,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
ModuleLib.uninstallModule(
address(policy), abi.encodePacked(bytes32(PermissionId.unwrap(pId)), permissionDisableData[i])
);
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_POLICY, address(policy));
}
delete _validationStorage().permissionConfig[pId].policyData;
ModuleLib.uninstallModule(
Expand All @@ -206,6 +209,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
bytes32(PermissionId.unwrap(pId)), permissionDisableData[permissionDisableData.length - 1]
)
);
emit IERC7579Account.ModuleUninstalled(MODULE_TYPE_SIGNER, address(config.signer));
}
config.signer = ISigner(address(0));
config.permissionFlag = PassFlag.wrap(bytes2(0));
Expand Down Expand Up @@ -238,6 +242,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
if (vType == VALIDATION_TYPE_VALIDATOR) {
IValidator validator = ValidatorLib.getValidator(vId);
validator.onInstall(validatorData);
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_VALIDATOR, address(validator));
} else if (vType == VALIDATION_TYPE_PERMISSION) {
PermissionId permission = ValidatorLib.getPermissionId(vId);
_installPermission(permission, validatorData);
Expand Down Expand Up @@ -270,6 +275,9 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
IPolicy(address(bytes20(permissionEnableData[i][2:22]))).onInstall(
abi.encodePacked(bytes32(PermissionId.unwrap(permission)), permissionEnableData[i][22:])
);
emit IERC7579Account.ModuleInstalled(
MODULE_TYPE_POLICY, address(bytes20(permissionEnableData[i][2:22]))
);
}
// last permission data will be signer
ISigner signer = ISigner(address(bytes20(permissionEnableData[permissionEnableData.length - 1][2:22])));
Expand All @@ -281,6 +289,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
bytes32(PermissionId.unwrap(permission)), permissionEnableData[permissionEnableData.length - 1][22:]
)
);
emit IERC7579Account.ModuleInstalled(MODULE_TYPE_SIGNER, address(signer));
}
}

Expand Down

0 comments on commit 56b8bc9

Please sign in to comment.