diff --git a/.gas-snapshot b/.gas-snapshot index c8a08c0..feb1145 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -5,11 +5,11 @@ MultiOwnerPluginIntegration:test_userOpValidation_owner_standardExecute() (gas: MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwner(bytes32) (runs: 256, μ: 110100, ~: 110100) MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwnerWithEOAOwner(bytes32) (runs: 256, μ: 120441, ~: 120441) MultiOwnerPluginTest:testFuzz_isValidSignature_EOAOwner(string,bytes32) (runs: 256, μ: 130822, ~: 130815) -MultiOwnerPluginTest:testFuzz_isValidSignature_PasskeyOwner(bytes32) (runs: 256, μ: 365475, ~: 365620) +MultiOwnerPluginTest:testFuzz_isValidSignature_PasskeyOwner(bytes32) (runs: 256, μ: 365256, ~: 365198) MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 130896, ~: 130885) MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwnerWithEOAOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 144517, ~: 144506) MultiOwnerPluginTest:testFuzz_userOpValidationFunction_EOAOwner(string,(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 138771, ~: 138774) -MultiOwnerPluginTest:testFuzz_userOpValidationFunction_PasskeyOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 373527, ~: 373589) +MultiOwnerPluginTest:testFuzz_userOpValidationFunction_PasskeyOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 373817, ~: 373647) MultiOwnerPluginTest:test_eip712Domain() (gas: 35439) MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19772) MultiOwnerPluginTest:test_onInstall_failWithInvalidAddress() (gas: 45223) @@ -26,15 +26,15 @@ MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 56407) MultiOwnerPluginTest:test_updateOwners_success() (gas: 119875) WebauthnModularAccountFactoryTest:test_2StepOwnershipTransfer() (gas: 87560) WebauthnModularAccountFactoryTest:test_addStake() (gas: 106151) -WebauthnModularAccountFactoryTest:test_addressMatch() (gas: 808890) +WebauthnModularAccountFactoryTest:test_addressMatch() (gas: 808871) WebauthnModularAccountFactoryTest:test_badOwnersArray() (gas: 18409) -WebauthnModularAccountFactoryTest:test_deploy() (gas: 817424) -WebauthnModularAccountFactoryTest:test_deployCollision() (gas: 833311) -WebauthnModularAccountFactoryTest:test_deployWithDuplicateOwners() (gas: 744303) -WebauthnModularAccountFactoryTest:test_deployWithUnsortedOwners() (gas: 744325) -WebauthnModularAccountFactoryTest:test_deploy_PasskeyOwner() (gas: 804113) -WebauthnModularAccountFactoryTest:test_deployedAccountHasCorrectPlugins() (gas: 808570) -WebauthnModularAccountFactoryTest:test_getAddressWithMaxOwnersAndDeploy() (gas: 2720267) +WebauthnModularAccountFactoryTest:test_deploy() (gas: 817405) +WebauthnModularAccountFactoryTest:test_deployCollision() (gas: 833056) +WebauthnModularAccountFactoryTest:test_deployWithDuplicateOwners() (gas: 744270) +WebauthnModularAccountFactoryTest:test_deployWithUnsortedOwners() (gas: 744292) +WebauthnModularAccountFactoryTest:test_deploy_PasskeyOwner() (gas: 804094) +WebauthnModularAccountFactoryTest:test_deployedAccountHasCorrectPlugins() (gas: 808551) +WebauthnModularAccountFactoryTest:test_getAddressWithMaxOwnersAndDeploy() (gas: 2720248) WebauthnModularAccountFactoryTest:test_getAddressWithTooManyOwners() (gas: 205715) WebauthnModularAccountFactoryTest:test_getAddressWithUnsortedOwners() (gas: 11320) WebauthnModularAccountFactoryTest:test_unlockStake() (gas: 147811) diff --git a/src/WebauthnModularAccountFactory.sol b/src/WebauthnModularAccountFactory.sol index e992fe4..276f4e2 100644 --- a/src/WebauthnModularAccountFactory.sol +++ b/src/WebauthnModularAccountFactory.sol @@ -6,11 +6,12 @@ import { Ownable, Ownable2Step } from "openzeppelin-contracts/contracts/access/O import { FactoryHelpers } from "modular-account/src/helpers/FactoryHelpers.sol"; import { IAccountInitializable } from "modular-account/src/interfaces/IAccountInitializable.sol"; import { IEntryPoint } from "modular-account/src/interfaces/erc4337/IEntryPoint.sol"; +import { IMultiOwnerPlugin } from "modular-account/src/plugins/owner/IMultiOwnerPlugin.sol"; import { LibClone } from "solady/utils/LibClone.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; -import { IMultiOwnerPlugin, IWebauthnOwnerPlugin, MAX_OWNERS, PublicKey } from "./IWebauthnOwnerPlugin.sol"; +import { IWebauthnOwnerPlugin, MAX_OWNERS, PublicKey } from "./IWebauthnOwnerPlugin.sol"; import { OwnersLib } from "./OwnersLib.sol"; /// @title Webauthn Owner Plugin Modular Account Factory @@ -60,22 +61,12 @@ contract WebauthnModularAccountFactory is Ownable2Step { /// @param salt salt for create2 /// @param owners address array of the owners function createAccount(uint256 salt, PublicKey[] calldata owners) external returns (address accountAddress) { - bytes[] memory pluginInitBytes = new bytes[](1); - pluginInitBytes[0] = abi.encode(owners); - - bytes32 combinedSalt = salt.getCombinedSalt(pluginInitBytes[0]); + bytes memory ownerBytes = abi.encode(owners); + bytes32 combinedSalt = salt.getCombinedSalt(ownerBytes); bool alreadyDeployed; (alreadyDeployed, accountAddress) = IMPL.createDeterministicERC1967(combinedSalt); - if (!alreadyDeployed) { - address[] memory plugins = new address[](1); - plugins[0] = WEBAUTHN_OWNER_PLUGIN; - - bytes32[] memory manifestHashes = new bytes32[](1); - manifestHashes[0] = _WEBAUTHN_OWNER_PLUGIN_MANIFEST_HASH; - - IAccountInitializable(accountAddress).initialize(plugins, abi.encode(manifestHashes, pluginInitBytes)); - } + if (!alreadyDeployed) _initializeAccount(IAccountInitializable(accountAddress), ownerBytes); } /// @notice Add stake to an entry point @@ -137,6 +128,19 @@ contract WebauthnModularAccountFactory is Ownable2Step { function renounceOwnership() public view override onlyOwner { revert InvalidAction(); } + + function _initializeAccount(IAccountInitializable account, bytes memory owners) internal virtual { + address[] memory plugins = new address[](1); + plugins[0] = WEBAUTHN_OWNER_PLUGIN; + + bytes32[] memory manifestHashes = new bytes32[](1); + manifestHashes[0] = _WEBAUTHN_OWNER_PLUGIN_MANIFEST_HASH; + + bytes[] memory initBytes = new bytes[](1); + initBytes[0] = owners; + + account.initialize(plugins, abi.encode(manifestHashes, initBytes)); + } } error InvalidAction();