Skip to content

Commit

Permalink
✨ factory: allow extension by inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Jun 28, 2024
1 parent f5ce7cf commit 91c9b39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
20 changes: 10 additions & 10 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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, μ: 365495, ~: 365541)
MultiOwnerPluginTest:testFuzz_isValidSignature_PasskeyOwner(bytes32) (runs: 256, μ: 365546, ~: 365633)
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, μ: 373680, ~: 373611)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_PasskeyOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 373539, ~: 373590)
MultiOwnerPluginTest:test_eip712Domain() (gas: 35439)
MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19772)
MultiOwnerPluginTest:test_onInstall_failWithInvalidAddress() (gas: 45223)
Expand All @@ -26,15 +26,15 @@ MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 56407)
MultiOwnerPluginTest:test_updateOwners_success() (gas: 119883)
WebauthnModularAccountFactoryTest:test_2StepOwnershipTransfer() (gas: 87560)
WebauthnModularAccountFactoryTest:test_addStake() (gas: 106151)
WebauthnModularAccountFactoryTest:test_addressMatch() (gas: 808890)
WebauthnModularAccountFactoryTest:test_addressMatch() (gas: 808941)
WebauthnModularAccountFactoryTest:test_badOwnersArray() (gas: 18409)
WebauthnModularAccountFactoryTest:test_deploy() (gas: 817428)
WebauthnModularAccountFactoryTest:test_deployCollision() (gas: 833311)
WebauthnModularAccountFactoryTest:test_deployWithDuplicateOwners() (gas: 744303)
WebauthnModularAccountFactoryTest:test_deployWithUnsortedOwners() (gas: 744325)
WebauthnModularAccountFactoryTest:test_deploy_PasskeyOwner() (gas: 804114)
WebauthnModularAccountFactoryTest:test_deployedAccountHasCorrectPlugins() (gas: 808570)
WebauthnModularAccountFactoryTest:test_getAddressWithMaxOwnersAndDeploy() (gas: 2720267)
WebauthnModularAccountFactoryTest:test_deploy() (gas: 817441)
WebauthnModularAccountFactoryTest:test_deployCollision() (gas: 833120)
WebauthnModularAccountFactoryTest:test_deployWithDuplicateOwners() (gas: 744304)
WebauthnModularAccountFactoryTest:test_deployWithUnsortedOwners() (gas: 744326)
WebauthnModularAccountFactoryTest:test_deploy_PasskeyOwner() (gas: 804127)
WebauthnModularAccountFactoryTest:test_deployedAccountHasCorrectPlugins() (gas: 808583)
WebauthnModularAccountFactoryTest:test_getAddressWithMaxOwnersAndDeploy() (gas: 2720318)
WebauthnModularAccountFactoryTest:test_getAddressWithTooManyOwners() (gas: 205715)
WebauthnModularAccountFactoryTest:test_getAddressWithUnsortedOwners() (gas: 11320)
WebauthnModularAccountFactoryTest:test_unlockStake() (gas: 147811)
Expand Down
36 changes: 21 additions & 15 deletions src/WebauthnModularAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,11 @@ 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);
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;
(alreadyDeployed, accountAddress) = IMPL.createDeterministicERC1967(_combinedSalt(salt, ownerBytes));

IAccountInitializable(accountAddress).initialize(plugins, abi.encode(manifestHashes, pluginInitBytes));
}
if (!alreadyDeployed) _initializeAccount(IAccountInitializable(accountAddress), ownerBytes);
}

/// @notice Add stake to an entry point
Expand Down Expand Up @@ -130,13 +119,30 @@ contract WebauthnModularAccountFactory is Ownable2Step {
previousOwnerAddress = ownerAddress;
}

return IMPL.predictDeterministicAddressERC1967(salt.getCombinedSalt(abi.encode(owners)), address(this));
return IMPL.predictDeterministicAddressERC1967(_combinedSalt(salt, abi.encode(owners)), address(this));
}

/// @notice Overriding to disable renounce ownership in Ownable
function renounceOwnership() public view override onlyOwner {
revert InvalidAction();
}

function _combinedSalt(uint256 salt, bytes memory owners) internal view virtual returns (bytes32 combinedSalt) {
combinedSalt = salt.getCombinedSalt(owners);
}

function _initializeAccount(IAccountInitializable accountAddress, 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;

accountAddress.initialize(plugins, abi.encode(manifestHashes, initBytes));
}
}

error InvalidAction();

0 comments on commit 91c9b39

Please sign in to comment.