Skip to content

Commit

Permalink
⚡️ owners: cache array lengths
Browse files Browse the repository at this point in the history
resolves quantstamp EXA-S-4
  • Loading branch information
cruzdanilo committed Jun 28, 2024
1 parent f5ce7cf commit c05ec78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 9 additions & 9 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
MultiOwnerPluginIntegration:test_ownerPlugin_successInstallation() (gas: 39139)
MultiOwnerPluginIntegration:test_ownerPlugin_successInstallation() (gas: 39135)
MultiOwnerPluginIntegration:test_runtimeValidation_alwaysAllow_isValidSignature() (gas: 104093)
MultiOwnerPluginIntegration:test_runtimeValidation_ownerOrSelf_standardExecute() (gas: 145057)
MultiOwnerPluginIntegration:test_userOpValidation_owner_standardExecute() (gas: 347849)
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, μ: 365475, ~: 365620)
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, μ: 373527, ~: 373589)
MultiOwnerPluginTest:test_eip712Domain() (gas: 35439)
MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19772)
MultiOwnerPluginTest:test_onInstall_failWithInvalidAddress() (gas: 45223)
MultiOwnerPluginTest:test_onInstall_success() (gas: 101663)
MultiOwnerPluginTest:test_onUninstall_success() (gas: 84932)
MultiOwnerPluginTest:test_pluginInitializeGuards() (gas: 170794)
MultiOwnerPluginTest:test_onInstall_success() (gas: 101662)
MultiOwnerPluginTest:test_onUninstall_success() (gas: 84913)
MultiOwnerPluginTest:test_pluginInitializeGuards() (gas: 170787)
MultiOwnerPluginTest:test_pluginManifest() (gas: 38791)
MultiOwnerPluginTest:test_runtimeValidationFunction_OwnerOrSelf() (gas: 26747)
MultiOwnerPluginTest:test_updateOwnersPublicKeys_failWithInvalidAddress() (gas: 55705)
MultiOwnerPluginTest:test_updateOwners_failWithDuplicatedAddresses() (gas: 85515)
MultiOwnerPluginTest:test_updateOwners_failWithEmptyOwners() (gas: 70738)
MultiOwnerPluginTest:test_updateOwners_failWithNotExist() (gas: 58568)
MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 56407)
MultiOwnerPluginTest:test_updateOwners_success() (gas: 119883)
MultiOwnerPluginTest:test_updateOwners_success() (gas: 119875)
WebauthnModularAccountFactoryTest:test_2StepOwnershipTransfer() (gas: 87560)
WebauthnModularAccountFactoryTest:test_addStake() (gas: 106151)
WebauthnModularAccountFactoryTest:test_addressMatch() (gas: 808890)
WebauthnModularAccountFactoryTest:test_badOwnersArray() (gas: 18409)
WebauthnModularAccountFactoryTest:test_deploy() (gas: 817428)
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: 804114)
WebauthnModularAccountFactoryTest:test_deploy_PasskeyOwner() (gas: 804113)
WebauthnModularAccountFactoryTest:test_deployedAccountHasCorrectPlugins() (gas: 808570)
WebauthnModularAccountFactoryTest:test_getAddressWithMaxOwnersAndDeploy() (gas: 2720267)
WebauthnModularAccountFactoryTest:test_getAddressWithTooManyOwners() (gas: 205715)
Expand Down
10 changes: 6 additions & 4 deletions src/OwnersLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ library OwnersLib {
}

function all(Owners storage owners) internal view returns (PublicKey[] memory publicKeys) {
publicKeys = new PublicKey[](owners.length);
for (uint256 i = 0; i < publicKeys.length; ++i) {
uint256 length = owners.length;
publicKeys = new PublicKey[](length);
for (uint256 i = 0; i < length; ++i) {
publicKeys[i] = owners.publicKeys[i];
}
}

function allAddresses(Owners storage owners) internal view returns (address[] memory addresses) {
addresses = new address[](owners.length);
for (uint256 i = 0; i < addresses.length; ++i) {
uint256 length = owners.length;
addresses = new address[](length);
for (uint256 i = 0; i < length; ++i) {
addresses[i] = owners.publicKeys[i].y == 0
? address(uint160(uint256(owners.publicKeys[i].x)))
: address(bytes20(keccak256(abi.encode(owners.publicKeys[i]))));
Expand Down

0 comments on commit c05ec78

Please sign in to comment.