Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/v3.2 #127

Merged
merged 9 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated the readability a bit more
  • Loading branch information
leekt committed Dec 11, 2024
commit 5cd08417ad0b3ea5f4569cac944b0000e0ac39b9
47 changes: 19 additions & 28 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ import {
MAGIC_VALUE_SIG_REPLAYABLE
} from "./types/Constants.sol";

import {
InstallExecutorDataFormat,
InstallFallbackDataFormat,
InstallValidatorDataFormat
} from "./types/Structs.sol";

contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager {
error ExecutionReverted();
error InvalidExecutor();
Expand Down Expand Up @@ -357,45 +363,30 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
}
ValidationConfig memory config =
ValidationConfig({nonce: vs.currentNonce, hook: IHook(address(bytes20(initData[0:20])))});
bytes calldata validatorData;
bytes calldata hookData;
bytes calldata selectorData;
InstallValidatorDataFormat calldata data;
assembly {
validatorData.offset := add(add(initData.offset, 52), calldataload(add(initData.offset, 20)))
validatorData.length := calldataload(sub(validatorData.offset, 32))
hookData.offset := add(add(initData.offset, 52), calldataload(add(initData.offset, 52)))
hookData.length := calldataload(sub(hookData.offset, 32))
selectorData.offset := add(add(initData.offset, 52), calldataload(add(initData.offset, 84)))
selectorData.length := calldataload(sub(selectorData.offset, 32))
data := add(initData.offset, 20)
}
_installValidation(vId, config, validatorData, hookData);
if (selectorData.length == 4) {
_installValidation(vId, config, data.validatorData, data.hookData);
if (data.selectorData.length == 4) {
// NOTE: we don't allow configure on selector data on v3.1+, but using bytes instead of bytes4 for selector data to make sure we are future proof
_setSelector(vId, bytes4(selectorData[0:4]), true);
_setSelector(vId, bytes4(data.selectorData[0:4]), true);
}
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
bytes calldata executorData;
bytes calldata hookData;
InstallExecutorDataFormat calldata data;
assembly {
executorData.offset := add(add(initData.offset, 52), calldataload(add(initData.offset, 20)))
executorData.length := calldataload(sub(executorData.offset, 32))
hookData.offset := add(add(initData.offset, 52), calldataload(add(initData.offset, 52)))
hookData.length := calldataload(sub(hookData.offset, 32))
data := add(initData.offset, 20)
}
IHook hook = IHook(address(bytes20(initData[0:20])));
_installExecutor(IExecutor(module), executorData, hook);
_installHook(hook, hookData);
_installExecutor(IExecutor(module), data.executorData, hook);
_installHook(hook, data.hookData);
} else if (moduleType == MODULE_TYPE_FALLBACK) {
bytes calldata selectorData;
bytes calldata hookData;
InstallFallbackDataFormat calldata data;
assembly {
selectorData.offset := add(add(initData.offset, 56), calldataload(add(initData.offset, 24)))
selectorData.length := calldataload(sub(selectorData.offset, 32))
hookData.offset := add(add(initData.offset, 56), calldataload(add(initData.offset, 56)))
hookData.length := calldataload(sub(hookData.offset, 32))
data := add(initData.offset, 24)
}
_installSelector(bytes4(initData[0:4]), module, IHook(address(bytes20(initData[4:24]))), selectorData);
_installHook(IHook(address(bytes20(initData[4:24]))), hookData);
_installSelector(bytes4(initData[0:4]), module, IHook(address(bytes20(initData[4:24]))), data.selectorData);
_installHook(IHook(address(bytes20(initData[4:24]))), data.hookData);
} else if (moduleType == MODULE_TYPE_HOOK) {
// force call onInstall for hook
// NOTE: for hook, kernel does not support independent hook install,
Expand Down
8 changes: 4 additions & 4 deletions src/core/ValidationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
PermissionSigMemory,
PermissionDisableDataFormat,
PermissionEnableDataFormat,
UserOpSigDataFormatEnable,
UserOpSigEnableDataFormat,
SelectorDataFormat,
SelectorDataFormatWithExecutorData
} from "../types/Structs.sol";
Expand Down Expand Up @@ -376,7 +376,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
internal
returns (ValidationData validationData, bytes calldata userOpSig)
{
UserOpSigDataFormatEnable calldata enableData;
UserOpSigEnableDataFormat calldata enableData;
assembly {
enableData := add(packedData.offset, 20)
}
Expand All @@ -389,7 +389,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
function _enableValidationWithSig(
ValidationId vId,
address hook,
UserOpSigDataFormatEnable calldata enableData,
UserOpSigEnableDataFormat calldata enableData,
bool isReplayable
) internal returns (ValidationData validationData) {
(ValidationConfig memory config, bytes32 digest) = _enableDigest(vId, hook, enableData, isReplayable);
Expand Down Expand Up @@ -464,7 +464,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
function _enableDigest(
ValidationId vId,
address hook,
UserOpSigDataFormatEnable calldata enableData,
UserOpSigEnableDataFormat calldata enableData,
bool isReplayable
) internal view returns (ValidationConfig memory config, bytes32 digest) {
ValidationStorage storage state = _validationStorage();
Expand Down
18 changes: 17 additions & 1 deletion src/types/Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct PermissionEnableDataFormat {
bytes[] data;
}

struct UserOpSigDataFormatEnable {
struct UserOpSigEnableDataFormat {
bytes validatorData;
bytes hookData;
bytes selectorData;
Expand All @@ -49,3 +49,19 @@ struct SelectorDataFormatWithExecutorData {
bytes hookInitData;
bytes executorHookData;
}
struct InstallValidatorDataFormat {
bytes validatorData;
bytes hookData;
bytes selectorData;
}

struct InstallExecutorDataFormat {
bytes executorData;
bytes hookData;
}

struct InstallFallbackDataFormat {
bytes selectorData;
bytes hookData;
}