Skip to content

Commit

Permalink
Merge pull request #152 from rhinestonewtf/fix/simulate-kernel
Browse files Browse the repository at this point in the history
fix: kernel and simulate ci runs
  • Loading branch information
highskore authored Oct 31, 2024
2 parents e32cbff + 9272f1a commit 3bb0ec7
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@ERC4337/account-abstraction": "github:kopy-kat/account-abstraction#develop",
"@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0",
"@prb/math": "^4.0.2",
"@rhinestone/erc4337-validation": "^0.0.3",
"@rhinestone/erc4337-validation": "0.0.1-alpha.5",
"@rhinestone/module-bases": "github:rhinestonewtf/module-bases#d048ec28c8ea8b4155db3ce4f027bc64cd41f9a7",
"@rhinestone/safe7579": "github:rhinestonewtf/safe7579#v1.0.0",
"@rhinestone/sentinellist": "github:rhinestonewtf/sentinellist",
Expand Down
18 changes: 6 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/accounts/kernel/KernelFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ contract KernelFactory is IAccountFactory {
Kernel.initialize, (rootValidator, IHook(address(hookMultiPlexer)), initData, hex"00")
);
}

function setHookMultiPlexer(address hook) public {
hookMultiPlexer = MockHookMultiPlexer(hook);
}
}
26 changes: 25 additions & 1 deletion src/test/ModuleKitHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { PackedUserOperation } from "../external/ERC4337.sol";
import { ERC4337Helpers } from "./utils/ERC4337Helpers.sol";
import { HelperBase } from "./helpers/HelperBase.sol";
import { Execution } from "../external/ERC7579.sol";
import { Execution, MODULE_TYPE_HOOK } from "../external/ERC7579.sol";
import { prank } from "src/test/utils/Vm.sol";
import {
getAccountType as getAccountTypeFromStorage,
Expand Down Expand Up @@ -46,6 +46,7 @@ import {
import { EncodeLib, HashLib } from "src/test/helpers/SmartSessionHelpers.sol";
import { Solarray } from "solarray/Solarray.sol";
import { recordLogs, VmSafe, getRecordedLogs } from "./utils/Vm.sol";
import { KernelHelpers } from "./helpers/KernelHelpers.sol";

library ModuleKitHelpers {
/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -837,6 +838,27 @@ library ModuleKitHelpers {
);
}

/// @dev Kernel requires us to temporarily disable the hook multiplexer to use smart sessions
modifier withHookFixForKernel(AccountInstance memory instance) {
// Check if account is KERNEL
if (instance.accountType == AccountType.KERNEL) {
// Cache hook multiplexer
address hookMultiplexer =
KernelHelpers(instance.accountHelper).getHookMultiPlexer(instance);
// Uninstall MockHookMultiplexer
instance.uninstallModule(MODULE_TYPE_HOOK, hookMultiplexer, "");
// Set hook multiplexer to address(1)
KernelHelpers(instance.accountHelper).setHookMultiPlexer(instance, address(1));
_;
// Set hook multiplexer back to MockHookMultiplexer
KernelHelpers(instance.accountHelper).setHookMultiPlexer(instance, hookMultiplexer);
// Reinstall MockHookMultiplexer
instance.installModule(MODULE_TYPE_HOOK, hookMultiplexer, "");
} else {
_;
}
}

function useSession(
AccountInstance memory instance,
Session memory session,
Expand All @@ -845,6 +867,7 @@ library ModuleKitHelpers {
bytes memory callData
)
internal
withHookFixForKernel(instance)
{
// Check if smart sessions module is already installed
if (!instance.isModuleInstalled(1, address(instance.smartSession))) {
Expand Down Expand Up @@ -880,6 +903,7 @@ library ModuleKitHelpers {
Execution[] memory executions
)
internal
withHookFixForKernel(instance)
{
// Check if smart sessions module is already installed
if (!instance.isModuleInstalled(1, address(instance.smartSession))) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/RhinestoneModuleKit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { HelperBase } from "./helpers/HelperBase.sol";
import { ERC7579Helpers } from "./helpers/ERC7579Helpers.sol";
import { SafeHelpers } from "./helpers/SafeHelpers.sol";
import { KernelHelpers } from "./helpers/KernelHelpers.sol";
import { NexusHelpers } from "./helpers/NexusHelpers.sol";
import { Auxiliary, AuxiliaryFactory } from "./Auxiliary.sol";
import { PackedUserOperation, IStakeManager, IEntryPoint } from "../external/ERC4337.sol";
import { ENTRYPOINT_ADDR } from "./predeploy/EntryPoint.sol";
Expand Down Expand Up @@ -248,7 +249,7 @@ contract RhinestoneModuleKit is AuxiliaryFactory {
writeHelper(address(new ERC7579Helpers()), DEFAULT);
writeHelper(address(new SafeHelpers()), SAFE);
writeHelper(address(new KernelHelpers()), KERNEL);
writeHelper(address(new ERC7579Helpers()), NEXUS);
writeHelper(address(new NexusHelpers()), NEXUS);
writeHelper(address(new ERC7579Helpers()), CUSTOM);

// Initialize factories
Expand Down
19 changes: 15 additions & 4 deletions src/test/helpers/KernelHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ contract KernelHelpers is HelperBase {
abi.encodePacked(ValidatorLib.validatorToIdentifier(IValidator(validator)), signature);
}

function getHookMultiPlexer(AccountInstance memory instance) public view returns (address) {
return address(KernelFactory(instance.accountFactory).hookMultiPlexer());
}

function setHookMultiPlexer(
AccountInstance memory instance,
address hookMultiPlexer
)
public
virtual
deployAccountForAction(instance)
{
KernelFactory(instance.accountFactory).setHookMultiPlexer(hookMultiPlexer);
}

/*//////////////////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -475,8 +490,4 @@ contract KernelHelpers is HelperBase {
Kernel(payable(instance.account)).validationConfig(vId);
return address(validationConfig.hook);
}

function getHookMultiPlexer(AccountInstance memory instance) internal view returns (address) {
return address(KernelFactory(instance.accountFactory).hookMultiPlexer());
}
}
Loading

0 comments on commit 3bb0ec7

Please sign in to comment.