From b0e46c2ce31aca8c741f8a498948eb0f4b5b2e4a Mon Sep 17 00:00:00 2001 From: leekt Date: Thu, 9 May 2024 03:11:04 +0900 Subject: [PATCH] changeRootValidator --- src/Kernel.sol | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Kernel.sol b/src/Kernel.sol index ded5d5c..d1f3784 100644 --- a/src/Kernel.sol +++ b/src/Kernel.sol @@ -110,6 +110,28 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager _installValidation(_rootValidator, config, validatorData, hookData); } + function changeRootValidator( + ValidationId _rootValidator, + IHook hook, + bytes calldata validatorData, + bytes calldata hookData + ) external payable onlyEntryPointOrSelfOrRoot { + ValidationStorage storage vs = _validationStorage(); + if (ValidationId.unwrap(_rootValidator) == bytes21(0)) { + revert InvalidValidator(); + } + ValidationType vType = ValidatorLib.getType(_rootValidator); + if (vType != VALIDATION_TYPE_VALIDATOR && vType != VALIDATION_TYPE_PERMISSION) { + revert InvalidValidationType(); + } + _setRootValidator(_rootValidator); + if (_validationStorage().validationConfig[_rootValidator].hook == IHook(address(0))) { + // when new rootValidator is not installed yet + ValidationConfig memory config = ValidationConfig({nonce: uint32(vs.currentNonce), hook: hook}); + _installValidation(_rootValidator, config, validatorData, hookData); + } + } + function upgradeTo(address _newImplementation) external payable onlyEntryPointOrSelfOrRoot { assembly { sstore(ERC1967_IMPLEMENTATION_SLOT, _newImplementation)