diff --git a/.gas-snapshot b/.gas-snapshot index 4e77f97..97e6974 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -2,12 +2,12 @@ MultiOwnerPluginIntegration:test_ownerPlugin_successInstallation() (gas: 39749) MultiOwnerPluginIntegration:test_runtimeValidation_alwaysAllow_isValidSignature() (gas: 111927) MultiOwnerPluginIntegration:test_runtimeValidation_ownerOrSelf_standardExecute() (gas: 146828) MultiOwnerPluginIntegration:test_userOpValidation_owner_standardExecute() (gas: 332445) -MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwner(bytes32) (runs: 256, μ: 111650, ~: 111650) -MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwnerWithEOAOwner(bytes32) (runs: 256, μ: 122070, ~: 122070) -MultiOwnerPluginTest:testFuzz_isValidSignature_EOAOwner(string,bytes32) (runs: 256, μ: 134060, ~: 134053) -MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 133667, ~: 133664) -MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwnerWithEOAOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 147490, ~: 147487) -MultiOwnerPluginTest:testFuzz_userOpValidationFunction_EOAOwner(string,(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 141706, ~: 141696) +MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwner(bytes32) (runs: 256, μ: 111557, ~: 111557) +MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwnerWithEOAOwner(bytes32) (runs: 256, μ: 121977, ~: 121977) +MultiOwnerPluginTest:testFuzz_isValidSignature_EOAOwner(string,bytes32) (runs: 256, μ: 133967, ~: 133960) +MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 133574, ~: 133571) +MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwnerWithEOAOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 147397, ~: 147394) +MultiOwnerPluginTest:testFuzz_userOpValidationFunction_EOAOwner(string,(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 141613, ~: 141603) MultiOwnerPluginTest:test_eip712Domain() (gas: 36354) MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19897) MultiOwnerPluginTest:test_onInstall_success() (gas: 91236) @@ -15,8 +15,8 @@ MultiOwnerPluginTest:test_onUninstall_success() (gas: 69907) MultiOwnerPluginTest:test_pluginInitializeGuards() (gas: 155534) MultiOwnerPluginTest:test_pluginManifest() (gas: 40036) MultiOwnerPluginTest:test_runtimeValidationFunction_OwnerOrSelf() (gas: 26864) -MultiOwnerPluginTest:test_updateOwners_failWithDuplicatedAddresses() (gas: 85578) -MultiOwnerPluginTest:test_updateOwners_failWithEmptyOwners() (gas: 73965) -MultiOwnerPluginTest:test_updateOwners_failWithNotExist() (gas: 58913) -MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 62620) -MultiOwnerPluginTest:test_updateOwners_success() (gas: 115616) \ No newline at end of file +MultiOwnerPluginTest:test_updateOwners_failWithDuplicatedAddresses() (gas: 85485) +MultiOwnerPluginTest:test_updateOwners_failWithEmptyOwners() (gas: 73872) +MultiOwnerPluginTest:test_updateOwners_failWithNotExist() (gas: 58820) +MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 62527) +MultiOwnerPluginTest:test_updateOwners_success() (gas: 115523) \ No newline at end of file diff --git a/src/OwnersLib.sol b/src/OwnersLib.sol index 8db0f61..e6153ed 100644 --- a/src/OwnersLib.sol +++ b/src/OwnersLib.sol @@ -37,8 +37,8 @@ library OwnersLib { } } - function allFixed(Owners storage owners) internal view returns (PublicKey[64] memory publicKeys) { - uint256 length = owners.length; + function all64(Owners storage owners) internal view returns (uint256 length, PublicKey[64] memory publicKeys) { + length = owners.length; for (uint256 i = 0; i < length; ++i) { publicKeys[i] = owners.publicKeys[i]; } diff --git a/src/WebauthnOwnerPlugin.sol b/src/WebauthnOwnerPlugin.sol index 99ebd12..5383913 100644 --- a/src/WebauthnOwnerPlugin.sol +++ b/src/WebauthnOwnerPlugin.sol @@ -61,27 +61,23 @@ contract WebauthnOwnerPlugin is BasePlugin, IWebauthnOwnerPlugin, IERC1271 { public isInitialized(msg.sender) { - Owners storage ownersStorage = _owners[msg.sender]; - PublicKey[64] memory owners = ownersStorage.allFixed(); - uint256 ownerCount = ownersStorage.length; + Owners storage owners = _owners[msg.sender]; + (uint256 ownerCount, PublicKey[64] memory keys) = owners.all64(); uint256 addIndex = 0; - for (uint256 removeIndex = 0; removeIndex < ownersToRemove.length; ++removeIndex) { - uint256 ownerIndex = owners.find(ownersToRemove[removeIndex], ownerCount); + uint256 ownerIndex = keys.find(ownersToRemove[removeIndex], ownerCount); if (ownerIndex == type(uint256).max) revert OwnerDoesNotExist(ownersToRemove[removeIndex].toAddress()); if (--ownerCount == 0) break; - owners[ownerIndex] = addIndex < ownersToAdd.length ? ownersToAdd[addIndex++] : owners[ownerCount]; - ownersStorage.publicKeys[ownerIndex] = owners[ownerIndex]; + keys[ownerIndex] = addIndex < ownersToAdd.length ? ownersToAdd[addIndex++] : keys[ownerCount]; + owners.publicKeys[ownerIndex] = keys[ownerIndex]; } - for (; addIndex < ownersToAdd.length; ++addIndex) { - if (owners.contains(ownersToAdd[addIndex], ownerCount)) revert InvalidOwner(ownersToAdd[addIndex].toAddress()); - - owners[ownerCount] = ownersToAdd[addIndex]; - ownersStorage.publicKeys[ownerCount] = owners[ownerCount]; + if (keys.contains(ownersToAdd[addIndex], ownerCount)) revert InvalidOwner(ownersToAdd[addIndex].toAddress()); + keys[ownerCount] = ownersToAdd[addIndex]; + owners.publicKeys[ownerCount] = keys[ownerCount]; ++ownerCount; } - ownersStorage.length = ownerCount; + owners.length = ownerCount; if (ownerCount == 0) revert EmptyOwnersNotAllowed(); @@ -284,10 +280,10 @@ contract WebauthnOwnerPlugin is BasePlugin, IWebauthnOwnerPlugin, IERC1271 { } function ownerIndexOf(address account, PublicKey calldata owner) external view returns (uint256 index) { - Owners storage ownersStorage = _owners[account]; - uint256 ownerCount = ownersStorage.length; + Owners storage owners = _owners[account]; + uint256 ownerCount = owners.length; for (index = 0; index < ownerCount; ++index) { - if (ownersStorage.publicKeys[index].equals(owner)) return index; + if (owners.publicKeys[index].equals(owner)) return index; } revert OwnerDoesNotExist(owner.toAddress()); }