Skip to content

Commit

Permalink
Merge pull request #151 from rhinestonewtf/fix/nexus-bootstrap
Browse files Browse the repository at this point in the history
fix: nexus bootstrap
  • Loading branch information
kopy-kat authored Nov 1, 2024
2 parents 8d4c67b + 997f74c commit 36de708
Show file tree
Hide file tree
Showing 11 changed files with 3,395 additions and 2,677 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
evm_version = "paris"
evm_version = "cancun"
src = "src"
out = "out"
script = "script"
Expand Down
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.2",
"@rhinestone/erc4337-validation": "^0.0.4",
"@rhinestone/module-bases": "github:rhinestonewtf/module-bases#d048ec28c8ea8b4155db3ce4f027bc64cd41f9a7",
"@rhinestone/safe7579": "github:rhinestonewtf/safe7579#v1.0.0",
"@rhinestone/sentinellist": "github:rhinestonewtf/sentinellist",
Expand Down
5,696 changes: 3,035 additions & 2,661 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ solarray/=node_modules/solarray/src/
@prb/math/=node_modules/@prb/math/src/
kernel/=node_modules/@zerodev/kernel/src/
ExcessivelySafeCall/=node_modules/excessively-safe-call/src/
node_modules/smartsessions/contracts/:excessively-safe-call/=node_modules/excessively-safe-call/src/
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);
}
}
13 changes: 11 additions & 2 deletions src/accounts/nexus/NexusFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
INexusBootstrap,
BootstrapConfig as NexusBootstrapConfig
} from "src/accounts/nexus/interfaces/INexusBootstrap.sol";
import { IERC7484 } from "src/Interfaces.sol";

// Constants
import { ENTRYPOINT_ADDR } from "src/test/predeploy/EntryPoint.sol";
import { REGISTRY_ADDR } from "src/test/predeploy/Registry.sol";

// Utils
import { NexusPrecompiles } from "src/test/precompiles/NexusPrecompiles.sol";
Expand Down Expand Up @@ -38,7 +40,8 @@ contract NexusFactory is IAccountFactory {
returns (address account)
{
// Note: signature in nexus account factory is below
// function createAccount(bytes calldata initData, bytes32 salt) external payable override returns (address payable)
// function createAccount(bytes calldata initData, bytes32 salt) external payable override
// returns (address payable)
account = factory.createAccount(initCode, salt);
}

Expand All @@ -65,6 +68,12 @@ contract NexusFactory is IAccountFactory {
{
NexusBootstrapConfig memory config =
NexusBootstrapConfig({ module: validator, data: initData });
return bootstrapDefault.getInitNexusWithSingleValidatorCalldata(config);

address[] memory attesters = new address[](1);
attesters[0] = address(0x000000333034E9f539ce08819E12c1b8Cb29084d);

return bootstrapDefault.getInitNexusWithSingleValidatorCalldata(
config, IERC7484(REGISTRY_ADDR), attesters, 1
);
}
}
43 changes: 38 additions & 5 deletions src/accounts/nexus/interfaces/INexusBootstrap.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import { IERC7579Module } from "src/external/ERC7579.sol";
import { IERC7484 } from "src/Interfaces.sol";

struct BootstrapConfig {
address module;
bytes data;
}

interface INexusBootstrap {
/// @notice Initializes the Nexus account with a single validator.
/// @dev Intended to be called by the Nexus with a delegatecall.
/// @param validator The address of the validator module.
/// @param data The initialization data for the validator module.
function initNexusWithSingleValidator(
IERC7579Module validator,
bytes calldata data,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external;

/// @notice Initializes the Nexus account with multiple modules.
/// @dev Intended to be called by the Nexus with a delegatecall.
/// @param validators The configuration array for validator modules.
Expand All @@ -17,7 +33,10 @@ interface INexusBootstrap {
BootstrapConfig[] calldata validators,
BootstrapConfig[] calldata executors,
BootstrapConfig calldata hook,
BootstrapConfig[] calldata fallbacks
BootstrapConfig[] calldata fallbacks,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external;

Expand All @@ -27,7 +46,10 @@ interface INexusBootstrap {
/// @param hook The configuration for the hook module.
function initNexusScoped(
BootstrapConfig[] calldata validators,
BootstrapConfig calldata hook
BootstrapConfig calldata hook,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external;

Expand All @@ -41,7 +63,10 @@ interface INexusBootstrap {
BootstrapConfig[] calldata validators,
BootstrapConfig[] calldata executors,
BootstrapConfig calldata hook,
BootstrapConfig[] calldata fallbacks
BootstrapConfig[] calldata fallbacks,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external
view
Expand All @@ -53,7 +78,10 @@ interface INexusBootstrap {
/// @return init The prepared calldata for initNexusScoped.
function getInitNexusScopedCalldata(
BootstrapConfig[] calldata validators,
BootstrapConfig calldata hook
BootstrapConfig calldata hook,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external
view
Expand All @@ -62,7 +90,12 @@ interface INexusBootstrap {
/// @notice Prepares calldata for the initNexusWithSingleValidator function.
/// @param validator The configuration for the validator module.
/// @return init The prepared calldata for initNexusWithSingleValidator.
function getInitNexusWithSingleValidatorCalldata(BootstrapConfig calldata validator)
function getInitNexusWithSingleValidatorCalldata(
BootstrapConfig calldata validator,
IERC7484 registry,
address[] calldata attesters,
uint8 threshold
)
external
view
returns (bytes memory init);
Expand Down
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 36de708

Please sign in to comment.