Skip to content

Commit

Permalink
Merge branch 'dev' into future_v3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
leekt authored Jun 3, 2024
2 parents f105149 + a807c8e commit 0b3e79c
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 199 deletions.
12 changes: 8 additions & 4 deletions broadcast/DeployKernel.s.sol/11155111/run-latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"contractAddress": "0xec9aa3a41d6baf3cdb2268ef7a8b116ea74925ef",
"function": null,
"arguments": [
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390"
],
"transaction": {
"type": "0x02",
"from": "0x9775137314fe595c943712b0b336327dfa80ae8a",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x60aa8f",
Expand All @@ -31,9 +33,10 @@
"0xec9aA3A41D6bAf3cDb2268ef7a8B116EA74925Ef"
],
"transaction": {
"type": "0x02",
"from": "0x9775137314fe595c943712b0b336327dfa80ae8a",
"to": "0x4e59b44847b379578588920ca78fbf26c0b4956c",
"gas": "0x600f4",
"gas": "0x293c83",
"value": "0x0",
"input": "0x000000000000000000000000000000000000000000000000000000000000000060a034607357601f61046c38819003918201601f19168301916001600160401b03831184841017607857808492602094604052833981010312607357516001600160a01b03811681036073576080526040516103dd908161008f823960805181818160d10152818161023401526102f00152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040818152600490600436101561001757600080fd5b600092833560e01c90816348aac39214610267575080635c60da1b1461021f5763ea6d13ac1461004657600080fd5b61004f36610352565b94919083519560209661007a86828a81019486888737868201908c820152038a8101845201826103a5565b5190209483958551917fcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f36060527f5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076875261600989527f0000000000000000000000000000000000000000000000000000000000000000601e5268603d3d8160223d3973600a52605f97602192605f60212060358601523060581b855260ff855380601586015260558520993415948b3b156101fe57505050506001916101f85785388180348c5af1156101ed57505b818652846060521561016b575b505091516001600160a01b0390931683525050f35b8082859493859483378101838152039082875af1903d156101e7573d9067ffffffffffffffff82116101d3578351916101ad601f8201601f19168801846103a5565b8252853d92013e5b156101c35738808080610156565b5163487e630960e11b8152600490fd5b634e487b7160e01b81526041600452602490fd5b506101b5565b63b12d13eb8652601cfd5b50610149565b91939a5091935034f59687156102145750610149565b63301164258652601cfd5b838234610263578160031936011261026357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b5080fd5b848334610263578260209361029d8361027f36610352565b90808a879498019788378201908982015203878101845201826103a5565b51902081517fcc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f36060527f5155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076835261600985527f0000000000000000000000000000000000000000000000000000000000000000601e5268603d3d8160223d3973600a52605f6021209083528360605260ff84536035523060601b6001526015526055822091603552519060018060a01b03168152f35b9060406003198301126103a05760043567ffffffffffffffff928382116103a057806023830112156103a05781600401359384116103a057602484830101116103a057602401919060243590565b600080fd5b90601f8019910116810190811067ffffffffffffffff8211176103c757604052565b634e487b7160e01b600052604160045260246000fd000000000000000000000000ec9aa3a41d6baf3cdb2268ef7a8b116ea74925ef",
"nonce": "0x4a",
Expand All @@ -53,9 +56,10 @@
"true"
],
"transaction": {
"type": "0x02",
"from": "0x9775137314fe595c943712b0b336327dfa80ae8a",
"to": "0xd703aae79538628d27099b8c4f621be4ccd142d5",
"gas": "0x108d1",
"to": "0x5de4839a76cf55d0c90e2061ef4386d962e15ae3",
"gas": "0x10945",
"value": "0x0",
"input": "0x6e7dbabb000000000000000000000000b52f3c04aeaf9364fbf68310a8128aabb40c9abb0000000000000000000000000000000000000000000000000000000000000001",
"nonce": "0x4b",
Expand Down
52 changes: 8 additions & 44 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
if (validator.isModuleType(4)) {
bytes memory ret = IHook(address(validator)).preCheck(msg.sender, msg.value, msg.data);
_;
IHook(address(validator)).postCheck(ret);
IHook(address(validator)).postCheck(ret, true, hex""); // TODO don't support try catch hook here
} else {
revert InvalidCaller();
}
Expand All @@ -110,28 +110,6 @@ 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)
Expand Down Expand Up @@ -173,16 +151,8 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
} else {
// action installed
bytes memory context;
if (
address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
) {
if (address(config.hook) != address(1)) {
context = _doPreHook(config.hook, msg.value, msg.data);
} else if (address(config.hook) == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) {
// for selector manager, address(0) for the hook will default to type(address).max,
// and this will only allow entrypoints to interact
if (msg.sender != address(entrypoint)) {
revert InvalidCaller();
}
}
// execute action
if (config.callType == CALLTYPE_SINGLE) {
Expand All @@ -192,10 +162,8 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
} else {
revert NotSupportedCallType();
}
if (
address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
) {
_doPostHook(config.hook, context);
if (address(config.hook) != address(1)) {
_doPostHook(config.hook, context, success, result);
}
}
if (!success) {
Expand Down Expand Up @@ -279,7 +247,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
}
(bool success, bytes memory ret) = ExecLib.executeDelegatecall(address(this), userOp.callData[4:]);
if (address(hook) != address(1)) {
_doPostHook(hook, context);
_doPostHook(hook, context, success, ret);
} else if (!success) {
revert ExecutionReverted();
}
Expand All @@ -301,7 +269,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
}
returnData = ExecLib.execute(execMode, executionCalldata);
if (address(hook) != address(1)) {
_doPostHook(hook, context);
_doPostHook(hook, context, true, abi.encode(returnData));
}
}

Expand Down Expand Up @@ -344,18 +312,14 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
ValidationConfig({nonce: vs.currentNonce, hook: IHook(address(bytes20(initData[0:20])))});
bytes calldata validatorData;
bytes calldata hookData;
bytes calldata selectorData;
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))
}
_installValidation(vId, config, validatorData, hookData);
// 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);
//_installHook(config.hook, hookData); hook install is handled inside installvalidation
} else if (moduleType == MODULE_TYPE_EXECUTOR) {
bytes calldata executorData;
bytes calldata hookData;
Expand Down Expand Up @@ -506,7 +470,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
}

function accountId() external pure override returns (string memory accountImplementationId) {
return "kernel.advanced.v0.3.1";
return "kernel.advanced.v0.3.0-beta";
}

function supportsExecutionMode(ExecMode mode) external pure override returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/HookManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ abstract contract HookManager {
context = hook.preCheck(msg.sender, value, callData);
}

function _doPostHook(IHook hook, bytes memory context) internal {
function _doPostHook(IHook hook, bytes memory context, bool success, bytes memory result) internal {
// bool success,
// bytes memory result
hook.postCheck(context);
hook.postCheck(context, success, result);
}

// @notice if hook is not initialized before, kernel will call hook.onInstall no matter what flag it shows, with hookData[1:]
Expand Down
2 changes: 1 addition & 1 deletion src/core/SelectorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract contract SelectorManager {

function _installSelector(bytes4 selector, address target, IHook hook, bytes calldata selectorData) internal {
if (address(hook) == address(0)) {
hook = IHook(address(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF));
hook = IHook(address(1));
}
SelectorConfig storage ss = _selectorConfig(selector);
// we are going to install only through call/delegatecall
Expand Down
22 changes: 20 additions & 2 deletions src/interfaces/IERC7579Modules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,30 @@ interface IValidator is IModule {
interface IExecutor is IModule {}

interface IHook is IModule {
function preCheck(address msgSender, uint256 msgValue, bytes calldata msgData)
/**
* @dev Called by the smart account before execution
* @param msgSender the address that called the smart account
* @param value the value that was sent to the smart account
* @param msgData the data that was sent to the smart account
*
* MAY return arbitrary data in the `hookData` return value
*/
function preCheck(address msgSender, uint256 value, bytes calldata msgData)
external
payable
returns (bytes memory hookData);

function postCheck(bytes calldata hookData) external payable;
/**
* @dev Called by the smart account after execution
* @param hookData the data that was returned by the `preCheck` function
* @param executionSuccess whether the execution(s) was (were) successful
* @param executionReturn the return/revert data of the execution(s)
*
* MAY validate the `hookData` to validate transaction context of the `preCheck` function
*/
function postCheck(bytes calldata hookData, bool executionSuccess, bytes calldata executionReturn)
external
payable;
}

interface IFallback is IModule {}
Expand Down
2 changes: 1 addition & 1 deletion src/mock/MockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract MockHook is IHook {
return data[msg.sender];
}

function postCheck(bytes calldata hookData) external payable override {
function postCheck(bytes calldata hookData, bool success, bytes memory res) external payable override {
postHookData[msg.sender] = hookData;
}
}
5 changes: 4 additions & 1 deletion src/mock/MockValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ contract MockValidator is IValidator, IHook {
return hex"";
}

function postCheck(bytes calldata hookData) external payable {
function postCheck(bytes calldata hookData, bool executionSuccess, bytes calldata executionReturn)
external
payable
{
return;
}
}
Loading

0 comments on commit 0b3e79c

Please sign in to comment.