Skip to content

Commit

Permalink
⚡️ owners: return owner count when returning all slots
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Apr 10, 2024
1 parent 3115910 commit 7359287
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
22 changes: 11 additions & 11 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ 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)
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)
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)
4 changes: 2 additions & 2 deletions src/OwnersLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
28 changes: 12 additions & 16 deletions src/WebauthnOwnerPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 7359287

Please sign in to comment.