From 324ecc8fd5731db9f1450d9457d16117e3423b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8r=E2=88=82=C2=A1?= Date: Fri, 22 Nov 2024 18:11:23 +0700 Subject: [PATCH] Ensuring that self appointing resets the appointed address --- src/EncryptionRegistry.sol | 35 +++- src/SignerList.sol | 6 +- src/interfaces/IEncryptionRegistry.sol | 5 +- test/EncryptionRegistry.t.sol | 275 +++++++++++++++++++------ 4 files changed, 246 insertions(+), 75 deletions(-) diff --git a/src/EncryptionRegistry.sol b/src/EncryptionRegistry.sol index 32df6a9..bebf0f4 100644 --- a/src/EncryptionRegistry.sol +++ b/src/EncryptionRegistry.sol @@ -24,7 +24,7 @@ contract EncryptionRegistry is IEncryptionRegistry, ERC165 { mapping(address => AccountEntry) public accounts; /// @notice A reference to the account that appointed each wallet - mapping(address => address) public appointedBy; + mapping(address => address) public appointerOf; /// @dev The contract to check whether the caller is a multisig member Addresslist addresslist; @@ -39,25 +39,44 @@ contract EncryptionRegistry is IEncryptionRegistry, ERC165 { /// @inheritdoc IEncryptionRegistry function appointWallet(address _newWallet) public { + // Appointing ourselves is the same as unappointing + if (_newWallet == msg.sender) _newWallet = address(0); + if (!addresslist.isListed(msg.sender)) { revert MustBeListed(); } else if (Address.isContract(_newWallet)) { revert CannotAppointContracts(); - } else if (appointedBy[_newWallet] != address(0)) { + } else if (addresslist.isListed(_newWallet)) { + // Appointing an already listed signer is not allowed, as votes would be locked + revert AlreadyListed(); + } else if (_newWallet == accounts[msg.sender].appointedWallet) { + return; // done + } else if (appointerOf[_newWallet] != address(0)) { revert AlreadyAppointed(); } + bool exists; + for (uint256 i = 0; i < registeredAccounts.length;) { + if (registeredAccounts[i] == msg.sender) { + exists = true; + break; + } + unchecked { + i++; + } + } + // New account? - if (accounts[msg.sender].appointedWallet == address(0) && accounts[msg.sender].publicKey == bytes32(0)) { + if (!exists) { registeredAccounts.push(msg.sender); } // Existing account else { - // Clear the old appointedBy[], if needed + // Clear the current appointerOf[], if needed if (accounts[msg.sender].appointedWallet != address(0)) { - appointedBy[accounts[msg.sender].appointedWallet] = address(0); + appointerOf[accounts[msg.sender].appointedWallet] = address(0); } - // Clear the old public key, if needed + // Clear the current public key, if needed if (accounts[msg.sender].publicKey != bytes32(0)) { // The old appointed wallet should no longer be able to see new content accounts[msg.sender].publicKey = bytes32(0); @@ -65,7 +84,9 @@ contract EncryptionRegistry is IEncryptionRegistry, ERC165 { } accounts[msg.sender].appointedWallet = _newWallet; - appointedBy[_newWallet] = msg.sender; + if (_newWallet != address(0)) { + appointerOf[_newWallet] = msg.sender; + } emit WalletAppointed(msg.sender, _newWallet); } diff --git a/src/SignerList.sol b/src/SignerList.sol index bf121d3..1904e1c 100644 --- a/src/SignerList.sol +++ b/src/SignerList.sol @@ -106,7 +106,7 @@ contract SignerList is ISignerList, Addresslist, ERC165Upgradeable, DaoAuthoriza function isListedOrAppointedByListed(address _address) public view returns (bool listedOrAppointedByListed) { if (isListed(_address)) { return true; - } else if (isListed(settings.encryptionRegistry.appointedBy(_address))) { + } else if (isListed(settings.encryptionRegistry.appointerOf(_address))) { return true; } @@ -122,7 +122,7 @@ contract SignerList is ISignerList, Addresslist, ERC165Upgradeable, DaoAuthoriza if (isListedAtBlock(_address, _blockNumber)) { return _address; } - address _appointer = settings.encryptionRegistry.appointedBy(_address); + address _appointer = settings.encryptionRegistry.appointerOf(_address); if (isListedAtBlock(_appointer, _blockNumber)) { return _appointer; } @@ -141,7 +141,7 @@ contract SignerList is ISignerList, Addresslist, ERC165Upgradeable, DaoAuthoriza return (_address, settings.encryptionRegistry.getAppointedWallet(_address)); } - address _appointer = settings.encryptionRegistry.appointedBy(_address); + address _appointer = settings.encryptionRegistry.appointerOf(_address); if (this.isListedAtBlock(_appointer, _blockNumber)) { // The appointed wallet votes return (_appointer, _address); diff --git a/src/interfaces/IEncryptionRegistry.sol b/src/interfaces/IEncryptionRegistry.sol index e096e46..7413300 100644 --- a/src/interfaces/IEncryptionRegistry.sol +++ b/src/interfaces/IEncryptionRegistry.sol @@ -15,6 +15,9 @@ interface IEncryptionRegistry { /// @notice Raised when attempting to register a contract instead of a wallet error CannotAppointContracts(); + /// @notice Raised when attempting to appoint an address which is already a listed signer + error AlreadyListed(); + /// @notice Raised when attempting to appoint an already appointed address error AlreadyAppointed(); @@ -42,7 +45,7 @@ interface IEncryptionRegistry { /// @notice Returns the address of the account that appointed the given wallet, if any. /// @return appointerAddress The address of the appointer account or zero. - function appointedBy(address wallet) external returns (address appointerAddress); + function appointerOf(address wallet) external returns (address appointerAddress); /// @notice Returns the address of the account registered at the given index function registeredAccounts(uint256) external view returns (address); diff --git a/test/EncryptionRegistry.t.sol b/test/EncryptionRegistry.t.sol index 252060f..bc5a562 100644 --- a/test/EncryptionRegistry.t.sol +++ b/test/EncryptionRegistry.t.sol @@ -146,10 +146,14 @@ contract EncryptionRegistryTest is AragonTest { } function testFuzz_ShouldRegisterMemberPublicKeys(address appointedWallet) public { - if (Address.isContract(appointedWallet)) return; - else if (Address.isContract(address(uint160(appointedWallet) + 1))) return; - else if (Address.isContract(address(uint160(appointedWallet) + 2))) return; - else if (Address.isContract(address(uint160(appointedWallet) + 3))) return; + if ( + appointedWallet == address(0) || appointedWallet == alice || appointedWallet == bob + || appointedWallet == carol || appointedWallet == david + ) return; + else if (Address.isContract(appointedWallet)) return; + else if (Address.isContract(address(uint160(appointedWallet) + 100))) return; + else if (Address.isContract(address(uint160(appointedWallet) + 200))) return; + else if (Address.isContract(address(uint160(appointedWallet) + 300))) return; address addrValue; bytes32 bytesValue; @@ -170,59 +174,62 @@ contract EncryptionRegistryTest is AragonTest { // Bob vm.startPrank(bob); - registry.appointWallet(address(uint160(appointedWallet) + 1)); - vm.startPrank(address(uint160(appointedWallet) + 1)); + registry.appointWallet(address(uint160(appointedWallet) + 100)); + vm.startPrank(address(uint160(appointedWallet) + 100)); registry.setPublicKey(bob, 0x0000567800000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); // Carol vm.startPrank(carol); - registry.appointWallet(address(uint160(appointedWallet) + 2)); - vm.startPrank(address(uint160(appointedWallet) + 2)); + registry.appointWallet(address(uint160(appointedWallet) + 200)); + vm.startPrank(address(uint160(appointedWallet) + 200)); registry.setPublicKey(carol, 0x0000000090ab0000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(carol); - assertEq(addrValue, address(uint160(appointedWallet) + 2)); + assertEq(addrValue, address(uint160(appointedWallet) + 200)); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); // David vm.startPrank(david); - registry.appointWallet(address(uint160(appointedWallet) + 3)); - vm.startPrank(address(uint160(appointedWallet) + 3)); + registry.appointWallet(address(uint160(appointedWallet) + 300)); + vm.startPrank(address(uint160(appointedWallet) + 300)); registry.setPublicKey(david, 0x000000000000cdef000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(carol); - assertEq(addrValue, address(uint160(appointedWallet) + 2)); + assertEq(addrValue, address(uint160(appointedWallet) + 200)); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(david); - assertEq(addrValue, address(uint160(appointedWallet) + 3)); + assertEq(addrValue, address(uint160(appointedWallet) + 300)); assertEq(bytesValue, 0x000000000000cdef000000000000000000000000000000000000000000000000); } - function test_ShouldClearPublicKeyAfterAppointing(address appointedWallet) public { - if (appointedWallet == address(0)) return; + function testFuzz_ShouldClearPublicKeyAfterAppointing(address appointedWallet) public { + if ( + appointedWallet == address(0) || appointedWallet == alice || appointedWallet == bob + || appointedWallet == carol || appointedWallet == david + ) return; else if (Address.isContract(appointedWallet)) return; - else if (Address.isContract(address(uint160(appointedWallet) + 1))) return; - else if (Address.isContract(address(uint160(appointedWallet) + 2))) return; - else if (Address.isContract(address(uint160(appointedWallet) + 3))) return; + else if (Address.isContract(address(uint160(appointedWallet) + 100))) return; + else if (Address.isContract(address(uint160(appointedWallet) + 200))) return; + else if (Address.isContract(address(uint160(appointedWallet) + 300))) return; address addrValue; bytes32 bytesValue; @@ -249,13 +256,13 @@ contract EncryptionRegistryTest is AragonTest { (addrValue, bytesValue) = registry.accounts(bob); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); - registry.appointWallet(address(uint160(appointedWallet) + 1)); + registry.appointWallet(address(uint160(appointedWallet) + 100)); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // Carol @@ -264,16 +271,16 @@ contract EncryptionRegistryTest is AragonTest { (addrValue, bytesValue) = registry.accounts(carol); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); - registry.appointWallet(address(uint160(appointedWallet) + 2)); + registry.appointWallet(address(uint160(appointedWallet) + 200)); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(carol); - assertEq(addrValue, address(uint160(appointedWallet) + 2)); + assertEq(addrValue, address(uint160(appointedWallet) + 200)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // David @@ -282,19 +289,19 @@ contract EncryptionRegistryTest is AragonTest { (addrValue, bytesValue) = registry.accounts(david); assertEq(bytesValue, 0x000000000000cdef000000000000000000000000000000000000000000000000); - registry.appointWallet(address(uint160(appointedWallet) + 3)); + registry.appointWallet(address(uint160(appointedWallet) + 300)); (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(carol); - assertEq(addrValue, address(uint160(appointedWallet) + 2)); + assertEq(addrValue, address(uint160(appointedWallet) + 200)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(david); - assertEq(addrValue, address(uint160(appointedWallet) + 3)); + assertEq(addrValue, address(uint160(appointedWallet) + 300)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); } @@ -315,33 +322,163 @@ contract EncryptionRegistryTest is AragonTest { assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // OK - registry.appointWallet(bob); - registry.appointWallet(carol); - registry.appointWallet(david); + registry.appointWallet(address(0x1111)); + registry.appointWallet(address(0x2222)); + registry.appointWallet(address(0x3333)); // KO vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(dao)); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, david); + assertEq(addrValue, address(0x3333)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // KO vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(multisig)); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, david); + assertEq(addrValue, address(0x3333)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // KO vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(registry)); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, david); + assertEq(addrValue, address(0x3333)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + } + + function test_shouldAllowToAppointBackAndForth() public { + address addrValue; + bytes32 bytesValue; + + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + vm.startPrank(alice); + + // Neutral + registry.appointWallet(address(0x0)); + + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x0)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + // Repeated appointments + registry.appointWallet(address(0x1234)); + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x1234)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + registry.appointWallet(address(0x1234)); + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x1234)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + // Bob + registry.appointWallet(address(0x1111)); + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x1111)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + registry.appointWallet(address(0x1111)); + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x1111)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + registry.appointWallet(address(0x1111)); + (addrValue, bytesValue) = registry.accounts(alice); + assertEq(addrValue, address(0x1111)); + assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); + + // More + registry.appointWallet(address(0x2222)); + registry.appointWallet(address(0x2222)); + registry.appointWallet(address(0x2222)); + + registry.appointWallet(address(0x3333)); + registry.appointWallet(address(0x3333)); + registry.appointWallet(address(0x3333)); + + // OK again + registry.appointWallet(address(0x1234)); + registry.appointWallet(address(0x1111)); + registry.appointWallet(address(0x2222)); + registry.appointWallet(address(0x3333)); + } + + function test_getRegisteredAccountsOnlyReturnsAddressesOnce() public { + uint256 count = registry.getRegisteredAccounts().length; + assertEq(count, 0); + + vm.startPrank(alice); + + // Neutral + registry.appointWallet(address(0x0)); + + count = registry.getRegisteredAccounts().length; + assertEq(count, 0); + + // Appoint + registry.appointWallet(address(0x1111)); + + count = registry.getRegisteredAccounts().length; + assertEq(count, 1); + + registry.appointWallet(address(0x2222)); + + count = registry.getRegisteredAccounts().length; + assertEq(count, 1); + + registry.appointWallet(address(0x3333)); + + count = registry.getRegisteredAccounts().length; + assertEq(count, 1); + } + + function test_shouldRevertIfAppointingAnotherSigner() public { + vm.startPrank(alice); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(bob); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(carol); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(david); + + vm.startPrank(bob); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(alice); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(carol); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyListed.selector)); + registry.appointWallet(david); + + // ok + registry.appointWallet(address(0x5555)); + } + + function test_shouldRevertWhenAlreadyAppointed() public { + vm.startPrank(alice); + registry.appointWallet(address(0x1234)); + + vm.startPrank(bob); + registry.appointWallet(address(0x2345)); + + // Fail + vm.startPrank(alice); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyAppointed.selector)); + registry.appointWallet(address(0x2345)); + + vm.startPrank(bob); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.AlreadyAppointed.selector)); + registry.appointWallet(address(0x1234)); + + // ok + registry.appointWallet(address(0x5555)); } - function test_ShouldRevertIfNotListed(address appointedWallet) public { + function testFuzz_AppointShouldRevertIfNotListed(address appointedWallet) public { if (Address.isContract(appointedWallet)) return; SignerList signerList; @@ -350,6 +487,7 @@ contract EncryptionRegistryTest is AragonTest { // Only Alice (,, multisig,,, signerList, registry,) = new DaoBuilder().withMultisigMember(alice).build(); + if (signerList.isListed(appointedWallet)) return; (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); @@ -367,12 +505,12 @@ contract EncryptionRegistryTest is AragonTest { assertEq(bytesValue, 0x5678000000000000000000000000000000000000000000000000000000000000); // Appoint self - registry.appointWallet(alice); - vm.startPrank(alice); + registry.appointWallet(appointedWallet); + vm.startPrank(appointedWallet); registry.setPublicKey(alice, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, alice); + assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); // NOT OK @@ -380,15 +518,15 @@ contract EncryptionRegistryTest is AragonTest { // Bob vm.startPrank(bob); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); - registry.appointWallet(address(uint160(appointedWallet) + 1)); + registry.appointWallet(address(uint160(appointedWallet) + 100)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - vm.startPrank(address(uint160(appointedWallet) + 1)); + vm.startPrank(address(uint160(appointedWallet) + 100)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(bob, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, alice); + assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); @@ -397,15 +535,15 @@ contract EncryptionRegistryTest is AragonTest { // Carol vm.startPrank(carol); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); - registry.appointWallet(address(uint160(appointedWallet) + 2)); + registry.appointWallet(address(uint160(appointedWallet) + 200)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - vm.startPrank(address(uint160(appointedWallet) + 2)); + vm.startPrank(address(uint160(appointedWallet) + 200)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(carol, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, alice); + assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); @@ -417,15 +555,15 @@ contract EncryptionRegistryTest is AragonTest { // David vm.startPrank(david); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); - registry.appointWallet(address(uint160(appointedWallet) + 3)); + registry.appointWallet(address(uint160(appointedWallet) + 300)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - vm.startPrank(address(uint160(appointedWallet) + 3)); + vm.startPrank(address(uint160(appointedWallet) + 300)); vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(david, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, alice); + assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); @@ -438,8 +576,8 @@ contract EncryptionRegistryTest is AragonTest { assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); } - function test_ShouldRevertOnSetPublicKeyIfNotAppointed(address appointedWallet) public { - if (Address.isContract(appointedWallet) || Address.isContract(address(uint160(appointedWallet) + 1))) return; + function testFuzz_ShouldRevertOnSetPublicKeyIfNotAppointed(address appointedWallet) public { + if (Address.isContract(appointedWallet) || Address.isContract(address(uint160(appointedWallet) + 100))) return; address addrValue; bytes32 bytesValue; @@ -474,19 +612,22 @@ contract EncryptionRegistryTest is AragonTest { assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - registry.appointWallet(address(uint160(appointedWallet) + 1)); + registry.appointWallet(address(uint160(appointedWallet) + 100)); // Appointed - vm.startPrank(address(uint160(appointedWallet) + 1)); + vm.startPrank(address(uint160(appointedWallet) + 100)); registry.setPublicKey(bob, 0x0000567800000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, address(uint160(appointedWallet) + 1)); + assertEq(addrValue, address(uint160(appointedWallet) + 100)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); } - function test_ShouldRevertIfOwnerNotAppointed(address appointedWallet) public { - if (appointedWallet == address(0)) return; + function testFuzz_ShouldRevertOnSetOwnPublicKeyIfOwnerIsAppointing(address appointedWallet) public { + if ( + appointedWallet == address(0) || appointedWallet == alice || appointedWallet == bob + || appointedWallet == carol || appointedWallet == david + ) return; else if (Address.isContract(appointedWallet)) return; address addrValue; @@ -507,7 +648,7 @@ contract EncryptionRegistryTest is AragonTest { registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(alice); - assertEq(addrValue, alice); + assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); // Bob @@ -525,7 +666,7 @@ contract EncryptionRegistryTest is AragonTest { registry.setOwnPublicKey(0x1234000000000000000000000000000000000000000000000000000000000000); (addrValue, bytesValue) = registry.accounts(bob); - assertEq(addrValue, bob); + assertEq(addrValue, address(0)); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); } @@ -602,7 +743,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(carol); registry.appointWallet(address(0x90ab)); assertEq(registry.getRegisteredAccounts().length, 3, "Incorrect length"); - registry.appointWallet(carol); + registry.appointWallet(address(0x6666)); + vm.startPrank(address(0x6666)); registry.setPublicKey(carol, bytes32(uint256(3456))); assertEq(registry.getRegisteredAccounts().length, 3, "Incorrect length"); @@ -610,7 +752,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(david); registry.appointWallet(address(0xcdef)); assertEq(registry.getRegisteredAccounts().length, 4, "Incorrect length"); - registry.appointWallet(david); + registry.appointWallet(address(0x7777)); + vm.startPrank(address(0x7777)); registry.setPublicKey(david, bytes32(uint256(4567))); assertEq(registry.getRegisteredAccounts().length, 4, "Incorrect length"); } @@ -638,7 +781,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(carol); registry.appointWallet(address(0x90ab)); assertEq(registry.registeredAccounts(2), carol); - registry.appointWallet(carol); + registry.appointWallet(address(0x6666)); + vm.startPrank(address(0x6666)); registry.setPublicKey(carol, bytes32(uint256(3456))); assertEq(registry.registeredAccounts(2), carol); @@ -646,7 +790,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(david); registry.appointWallet(address(0xcdef)); assertEq(registry.registeredAccounts(3), david); - registry.appointWallet(david); + registry.appointWallet(address(0x7777)); + vm.startPrank(address(0x7777)); registry.setPublicKey(david, bytes32(uint256(4567))); assertEq(registry.registeredAccounts(3), david); @@ -681,7 +826,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(carol); registry.appointWallet(address(0x90ab)); assertEq(registry.registeredAccounts(2), carol); - registry.appointWallet(carol); + registry.appointWallet(address(0x6666)); + vm.startPrank(address(0x6666)); registry.setPublicKey(carol, bytes32(uint256(3456))); assertEq(registry.registeredAccounts(2), carol); @@ -689,7 +835,8 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(david); registry.appointWallet(address(0xcdef)); assertEq(registry.registeredAccounts(3), david); - registry.appointWallet(david); + registry.appointWallet(address(0x7777)); + vm.startPrank(address(0x7777)); registry.setPublicKey(david, bytes32(uint256(4567))); assertEq(registry.registeredAccounts(3), david);