diff --git a/src/EncryptionRegistry.sol b/src/EncryptionRegistry.sol index 559df62..4454ba8 100644 --- a/src/EncryptionRegistry.sol +++ b/src/EncryptionRegistry.sol @@ -78,7 +78,7 @@ contract EncryptionRegistry is IEncryptionRegistry { else if ( accounts[msg.sender].appointedWallet != address(0) && accounts[msg.sender].appointedWallet != msg.sender ) { - revert CannotSetPubKeyForAppointedWallets(); + revert MustResetAppointment(); } _setPublicKey(msg.sender, _publicKey); diff --git a/src/interfaces/IEncryptionRegistry.sol b/src/interfaces/IEncryptionRegistry.sol index 4a5c2ac..e096e46 100644 --- a/src/interfaces/IEncryptionRegistry.sol +++ b/src/interfaces/IEncryptionRegistry.sol @@ -21,8 +21,8 @@ interface IEncryptionRegistry { /// @notice Raised when a non appointed wallet tries to define the public key error MustBeAppointed(); - /// @notice Raised when an account attempts to define the public key of the appointed wallet - error CannotSetPubKeyForAppointedWallets(); + /// @notice Raised when someone else is appointed and the account owner tries to override the public key of the appointed wallet. The appointed value should be set to address(0) or msg.sender first. + error MustResetAppointment(); /// @notice Raised when the caller is not an addresslist compatible contract error InvalidAddressList(); @@ -44,6 +44,9 @@ interface IEncryptionRegistry { /// @return appointerAddress The address of the appointer account or zero. function appointedBy(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); + /// @notice Returns the list of addresses on the registry /// @dev Use this function to get all addresses in a single call. You can still call registeredAccounts[idx] to resolve them one by one. function getRegisteredAccounts() external view returns (address[] memory); diff --git a/test/EncryptionRegistry.t.sol b/test/EncryptionRegistry.t.sol index d74073b..40698e2 100644 --- a/test/EncryptionRegistry.t.sol +++ b/test/EncryptionRegistry.t.sol @@ -3,7 +3,8 @@ pragma solidity ^0.8.17; import {AragonTest} from "./base/AragonTest.sol"; import {Addresslist} from "@aragon/osx/plugins/utils/Addresslist.sol"; -import {EncryptionRegistry} from "../src/EncryptionRegistry.sol"; +import {EncryptionRegistry, IEncryptionRegistry} from "../src/EncryptionRegistry.sol"; +import {SignerList} from "../src/SignerList.sol"; import {DaoBuilder} from "./helpers/DaoBuilder.sol"; import {DAO} from "@aragon/osx/core/dao/DAO.sol"; import {Multisig} from "../src/Multisig.sol"; @@ -21,17 +22,16 @@ contract EncryptionRegistryTest is AragonTest { function setUp() public { builder = new DaoBuilder(); - (dao,, multisig,,,) = builder.withMultisigMember(alice).withMultisigMember(bob).withMultisigMember(carol) - .withMultisigMember(david).build(); - - registry = new EncryptionRegistry(multisig); + (dao,, multisig,,,, registry,) = builder.withMultisigMember(alice).withMultisigMember(bob).withMultisigMember( + carol + ).withMultisigMember(david).build(); } function test_ShouldAppointWallets() public { address addrValue; bytes32 bytesValue; - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -39,7 +39,7 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(alice); registry.appointWallet(address(0x1234000000000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(bytesValue, 0); assertEq(addrValue, address(0x1234000000000000000000000000000000000000)); @@ -47,10 +47,10 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(bob); registry.appointWallet(address(0x0000567800000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(bytesValue, 0); assertEq(addrValue, address(0x1234000000000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(bytesValue, 0); assertEq(addrValue, address(0x0000567800000000000000000000000000000000)); @@ -58,13 +58,13 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(carol); registry.appointWallet(address(0x0000000090aB0000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(bytesValue, 0); assertEq(addrValue, address(0x1234000000000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(bytesValue, 0); assertEq(addrValue, address(0x0000567800000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(bytesValue, 0); assertEq(addrValue, address(0x0000000090aB0000000000000000000000000000)); @@ -72,16 +72,16 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(david); registry.appointWallet(address(0x000000000000cdEf000000000000000000000000)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(bytesValue, 0); assertEq(addrValue, address(0x1234000000000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(bytesValue, 0); assertEq(addrValue, address(0x0000567800000000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(bytesValue, 0); assertEq(addrValue, address(0x0000000090aB0000000000000000000000000000)); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(bytesValue, 0); assertEq(addrValue, address(0x000000000000cdEf000000000000000000000000)); } @@ -90,7 +90,7 @@ contract EncryptionRegistryTest is AragonTest { address addrValue; bytes32 bytesValue; - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -98,7 +98,7 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(alice); registry.setOwnPublicKey(0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); @@ -106,10 +106,10 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(bob); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); @@ -117,13 +117,13 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(carol); registry.setOwnPublicKey(0x0000000090ab0000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); @@ -131,16 +131,16 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(david); registry.setOwnPublicKey(0x000000000000cdef000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x000000000000cdef000000000000000000000000000000000000000000000000); } @@ -151,7 +151,7 @@ contract EncryptionRegistryTest is AragonTest { address addrValue; bytes32 bytesValue; - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -161,7 +161,7 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(alice, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); @@ -171,10 +171,10 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(bob, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); @@ -184,13 +184,13 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(carol, 0x0000000090ab0000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); @@ -200,16 +200,16 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(david, 0x000000000000cdef000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x000000000000cdef000000000000000000000000000000000000000000000000); } @@ -221,73 +221,73 @@ contract EncryptionRegistryTest is AragonTest { address addrValue; bytes32 bytesValue; - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // Alice vm.startPrank(alice); registry.setOwnPublicKey(0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); registry.appointWallet(appointedWallet); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // Bob vm.startPrank(bob); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); registry.appointWallet(appointedWallet); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // Carol vm.startPrank(carol); registry.setOwnPublicKey(0x0000000090ab0000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(bytesValue, 0x0000000090ab0000000000000000000000000000000000000000000000000000); registry.appointWallet(appointedWallet); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // David vm.startPrank(david); registry.setOwnPublicKey(0x000000000000cdef000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(bytesValue, 0x000000000000cdef000000000000000000000000000000000000000000000000); registry.appointWallet(appointedWallet); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); } @@ -296,7 +296,7 @@ contract EncryptionRegistryTest is AragonTest { address addrValue; bytes32 bytesValue; - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -304,7 +304,7 @@ contract EncryptionRegistryTest is AragonTest { // OK registry.appointWallet(address(0x1234)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0x1234)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -314,23 +314,23 @@ contract EncryptionRegistryTest is AragonTest { registry.appointWallet(david); // KO - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.CannotAppointContracts.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(dao)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, david); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // KO - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.CannotAppointContracts.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(multisig)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, david); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // KO - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.CannotAppointContracts.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.CannotAppointContracts.selector)); registry.appointWallet(address(registry)); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, david); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); } @@ -338,14 +338,14 @@ contract EncryptionRegistryTest is AragonTest { function test_ShouldRevertIfNotListed(address appointedWallet) public { if (Address.isContract(appointedWallet)) return; + SignerList signerList; address addrValue; bytes32 bytesValue; // Only Alice - (,, multisig,,,) = new DaoBuilder().withMultisigMember(alice).build(); - registry = new EncryptionRegistry(multisig); + (,, multisig,,, signerList, registry,) = new DaoBuilder().withMultisigMember(alice).build(); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -353,10 +353,10 @@ contract EncryptionRegistryTest is AragonTest { // Alice vm.startPrank(alice); - assertEq(multisig.isMember(alice), true); + assertEq(signerList.isListed(alice), true); registry.setOwnPublicKey(0x5678000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x5678000000000000000000000000000000000000000000000000000000000000); @@ -365,7 +365,7 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(alice); registry.setPublicKey(alice, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, alice); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); @@ -373,61 +373,61 @@ contract EncryptionRegistryTest is AragonTest { // Bob vm.startPrank(bob); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.appointWallet(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); vm.startPrank(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(bob, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, alice); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // Carol vm.startPrank(carol); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.appointWallet(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); vm.startPrank(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(carol, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, alice); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); // David vm.startPrank(david); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.appointWallet(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); vm.startPrank(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.RegistrationForbidden.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeListed.selector)); registry.setPublicKey(david, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, alice); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(carol); + (addrValue, bytesValue) = registry.accounts(carol); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(david); + (addrValue, bytesValue) = registry.accounts(david); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); } @@ -441,10 +441,10 @@ contract EncryptionRegistryTest is AragonTest { // Alice vm.startPrank(alice); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.NotAppointed.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeAppointed.selector)); registry.setPublicKey(alice, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -454,17 +454,17 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(alice, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); // Bob vm.startPrank(bob); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.NotAppointed.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustBeAppointed.selector)); registry.setPublicKey(bob, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, address(0)); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -474,7 +474,7 @@ contract EncryptionRegistryTest is AragonTest { vm.startPrank(appointedWallet); registry.setPublicKey(bob, 0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); } @@ -489,10 +489,10 @@ contract EncryptionRegistryTest is AragonTest { // Alice vm.startPrank(alice); registry.appointWallet(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.OwnerNotAppointed.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustResetAppointment.selector)); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -500,17 +500,17 @@ contract EncryptionRegistryTest is AragonTest { registry.appointWallet(alice); registry.setOwnPublicKey(0x0000567800000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(alice); + (addrValue, bytesValue) = registry.accounts(alice); assertEq(addrValue, alice); assertEq(bytesValue, 0x0000567800000000000000000000000000000000000000000000000000000000); // Bob vm.startPrank(bob); registry.appointWallet(appointedWallet); - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.OwnerNotAppointed.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.MustResetAppointment.selector)); registry.setOwnPublicKey(0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, appointedWallet); assertEq(bytesValue, 0x0000000000000000000000000000000000000000000000000000000000000000); @@ -518,7 +518,7 @@ contract EncryptionRegistryTest is AragonTest { registry.appointWallet(bob); registry.setOwnPublicKey(0x1234000000000000000000000000000000000000000000000000000000000000); - (addrValue, bytesValue) = registry.members(bob); + (addrValue, bytesValue) = registry.accounts(bob); assertEq(addrValue, bob); assertEq(bytesValue, 0x1234000000000000000000000000000000000000000000000000000000000000); } @@ -571,42 +571,42 @@ contract EncryptionRegistryTest is AragonTest { registry.setOwnPublicKey(0x0000123400000000000000000000000000000000000000000000000000000000); } - function test_ShouldCountRegisteredAddresses() public { - assertEq(registry.getRegisteredAddressesLength(), 0, "Incorrect count"); + function test_RegisteredAddressShouldHaveTheRightLength() public { + assertEq(registry.getRegisteredAccounts().length, 0, "Incorrect length"); // Set public key first // Alice vm.startPrank(alice); registry.setOwnPublicKey(bytes32(uint256(1234))); - assertEq(registry.getRegisteredAddressesLength(), 1, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 1, "Incorrect length"); registry.appointWallet(address(0x1234)); - assertEq(registry.getRegisteredAddressesLength(), 1, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 1, "Incorrect length"); // Bob vm.startPrank(bob); registry.setOwnPublicKey(bytes32(uint256(2345))); - assertEq(registry.getRegisteredAddressesLength(), 2, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 2, "Incorrect length"); registry.appointWallet(address(0x5678)); - assertEq(registry.getRegisteredAddressesLength(), 2, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 2, "Incorrect length"); // Appoint first // Carol vm.startPrank(carol); registry.appointWallet(address(0x90ab)); - assertEq(registry.getRegisteredAddressesLength(), 3, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 3, "Incorrect length"); registry.appointWallet(carol); registry.setPublicKey(carol, bytes32(uint256(3456))); - assertEq(registry.getRegisteredAddressesLength(), 3, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 3, "Incorrect length"); // David vm.startPrank(david); registry.appointWallet(address(0xcdef)); - assertEq(registry.getRegisteredAddressesLength(), 4, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 4, "Incorrect length"); registry.appointWallet(david); registry.setPublicKey(david, bytes32(uint256(4567))); - assertEq(registry.getRegisteredAddressesLength(), 4, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 4, "Incorrect length"); } function test_ShouldEnumerateRegisteredAddresses() public { @@ -615,41 +615,41 @@ contract EncryptionRegistryTest is AragonTest { // Alice vm.startPrank(alice); registry.setOwnPublicKey(bytes32(uint256(1234))); - assertEq(registry.registeredAddresses(0), alice); + assertEq(registry.registeredAccounts(0), alice); registry.appointWallet(address(0x1234)); - assertEq(registry.registeredAddresses(0), alice); + assertEq(registry.registeredAccounts(0), alice); // Bob vm.startPrank(bob); registry.setOwnPublicKey(bytes32(uint256(2345))); - assertEq(registry.registeredAddresses(1), bob); + assertEq(registry.registeredAccounts(1), bob); registry.appointWallet(address(0x5678)); - assertEq(registry.registeredAddresses(1), bob); + assertEq(registry.registeredAccounts(1), bob); // Appoint first // Carol vm.startPrank(carol); registry.appointWallet(address(0x90ab)); - assertEq(registry.registeredAddresses(2), carol); + assertEq(registry.registeredAccounts(2), carol); registry.appointWallet(carol); registry.setPublicKey(carol, bytes32(uint256(3456))); - assertEq(registry.registeredAddresses(2), carol); + assertEq(registry.registeredAccounts(2), carol); // David vm.startPrank(david); registry.appointWallet(address(0xcdef)); - assertEq(registry.registeredAddresses(3), david); + assertEq(registry.registeredAccounts(3), david); registry.appointWallet(david); registry.setPublicKey(david, bytes32(uint256(4567))); - assertEq(registry.registeredAddresses(3), david); + assertEq(registry.registeredAccounts(3), david); - assertEq(registry.getRegisteredAddressesLength(), 4, "Incorrect count"); + assertEq(registry.getRegisteredAccounts().length, 4, "Incorrect length"); - assertEq(registry.registeredAddresses(0), alice); - assertEq(registry.registeredAddresses(1), bob); - assertEq(registry.registeredAddresses(2), carol); - assertEq(registry.registeredAddresses(3), david); + assertEq(registry.registeredAccounts(0), alice); + assertEq(registry.registeredAccounts(1), bob); + assertEq(registry.registeredAccounts(2), carol); + assertEq(registry.registeredAccounts(3), david); } function test_ShouldLoadTheRegisteredAddresses() public { @@ -658,36 +658,36 @@ contract EncryptionRegistryTest is AragonTest { // Alice vm.startPrank(alice); registry.setOwnPublicKey(bytes32(uint256(1234))); - assertEq(registry.registeredAddresses(0), alice); + assertEq(registry.registeredAccounts(0), alice); registry.appointWallet(address(0x1234)); - assertEq(registry.registeredAddresses(0), alice); + assertEq(registry.registeredAccounts(0), alice); // Bob vm.startPrank(bob); registry.setOwnPublicKey(bytes32(uint256(2345))); - assertEq(registry.registeredAddresses(1), bob); + assertEq(registry.registeredAccounts(1), bob); registry.appointWallet(address(0x5678)); - assertEq(registry.registeredAddresses(1), bob); + assertEq(registry.registeredAccounts(1), bob); // Appoint first // Carol vm.startPrank(carol); registry.appointWallet(address(0x90ab)); - assertEq(registry.registeredAddresses(2), carol); + assertEq(registry.registeredAccounts(2), carol); registry.appointWallet(carol); registry.setPublicKey(carol, bytes32(uint256(3456))); - assertEq(registry.registeredAddresses(2), carol); + assertEq(registry.registeredAccounts(2), carol); // David vm.startPrank(david); registry.appointWallet(address(0xcdef)); - assertEq(registry.registeredAddresses(3), david); + assertEq(registry.registeredAccounts(3), david); registry.appointWallet(david); registry.setPublicKey(david, bytes32(uint256(4567))); - assertEq(registry.registeredAddresses(3), david); + assertEq(registry.registeredAccounts(3), david); - address[] memory addresses = registry.getRegisteredAddresses(); + address[] memory addresses = registry.getRegisteredAccounts(); assertEq(addresses.length, 4); assertEq(addresses[0], alice); assertEq(addresses[1], bob); @@ -697,12 +697,11 @@ contract EncryptionRegistryTest is AragonTest { function test_TheConstructorShouldRevertIfInvalidAddressList() public { // Fail - vm.expectRevert(abi.encodeWithSelector(EncryptionRegistry.InvalidAddressList.selector)); + vm.expectRevert(abi.encodeWithSelector(IEncryptionRegistry.InvalidAddressList.selector)); new EncryptionRegistry(Addresslist(address(this))); // OK - (,, multisig,,,) = new DaoBuilder().withMultisigMember(alice).build(); - new EncryptionRegistry(multisig); + (,, multisig,,,,,) = new DaoBuilder().withMultisigMember(alice).build(); } /// @dev mock function for test_TheConstructorShouldRevertIfInvalidAddressList() diff --git a/test/SignerList.t.sol b/test/SignerList.t.sol new file mode 100644 index 0000000..873413e --- /dev/null +++ b/test/SignerList.t.sol @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.17; + +import {AragonTest} from "./base/AragonTest.sol"; +import {Addresslist} from "@aragon/osx/plugins/utils/Addresslist.sol"; +import {EncryptionRegistry} from "../src/EncryptionRegistry.sol"; +import {SignerList} from "../src/SignerList.sol"; +import {DaoBuilder} from "./helpers/DaoBuilder.sol"; +import {DAO} from "@aragon/osx/core/dao/DAO.sol"; +import {Multisig} from "../src/Multisig.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; + +contract EncryptionRegistryTest is AragonTest { + SignerList signerList; + EncryptionRegistry encryptionRegistry; + DaoBuilder builder; + DAO dao; + Multisig multisig; + address[] signers; + + // Events/errors to be tested here (duplicate) + error SignerListLengthOutOfBounds(uint16 limit, uint256 actual); + error InvalidEncryptionRegitry(address givenAddress); + + function setUp() public { + builder = new DaoBuilder(); + (dao,, multisig,,, signerList, encryptionRegistry,) = builder.withMultisigMember(alice).withMultisigMember(bob) + .withMultisigMember(carol).withMultisigMember(david).build(); + + signers = new address[](4); + signers[0] = alice; + signers[1] = bob; + signers[2] = carol; + signers[3] = david; + } + + // Initialize + function test_InitializeRevertsIfInitialized() public { + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + + vm.expectRevert(bytes("Initializable: contract is already initialized")); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + } + + function test_InitializeSetsTheRightValues() public { + // 1 + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + + (EncryptionRegistry reg, uint16 minSignerListLength) = signerList.settings(); + vm.assertEq(address(reg), address(0), "Incorrect address"); + vm.assertEq(minSignerListLength, 0); + vm.assertEq(signerList.addresslistLength(), 4, "Incorrect length"); + vm.assertEq(signerList.isListed(alice), true, "Should be a signer"); + vm.assertEq(signerList.isListed(bob), true, "Should be a signer"); + vm.assertEq(signerList.isListed(carol), true, "Should be a signer"); + vm.assertEq(signerList.isListed(david), true, "Should be a signer"); + + // 2 + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(encryptionRegistry), 0)); + + (reg, minSignerListLength) = signerList.settings(); + vm.assertEq(address(reg), address(encryptionRegistry), "Incorrect address"); + vm.assertEq(minSignerListLength, 0); + vm.assertEq(signerList.addresslistLength(), 4, "Incorrect length"); + vm.assertEq(signerList.isListed(alice), true, "Should be a signer"); + vm.assertEq(signerList.isListed(bob), true, "Should be a signer"); + vm.assertEq(signerList.isListed(carol), true, "Should be a signer"); + vm.assertEq(signerList.isListed(david), true, "Should be a signer"); + + // 3 + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(encryptionRegistry), 2)); + + (reg, minSignerListLength) = signerList.settings(); + vm.assertEq(address(reg), address(encryptionRegistry), "Incorrect address"); + vm.assertEq(minSignerListLength, 2); + vm.assertEq(signerList.addresslistLength(), 4, "Incorrect length"); + vm.assertEq(signerList.isListed(alice), true, "Should be a signer"); + vm.assertEq(signerList.isListed(bob), true, "Should be a signer"); + vm.assertEq(signerList.isListed(carol), true, "Should be a signer"); + vm.assertEq(signerList.isListed(david), true, "Should be a signer"); + vm.assertEq(signerList.isListed(address(100)), false, "Should not be a signer"); + vm.assertEq(signerList.isListed(address(200)), false, "Should not be a signer"); + + // 4 + signers = new address[](2); + signers[0] = address(100); + signers[0] = address(200); + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(encryptionRegistry), 1)); + + (reg, minSignerListLength) = signerList.settings(); + vm.assertEq(address(reg), address(encryptionRegistry), "Incorrect address"); + vm.assertEq(minSignerListLength, 1); + vm.assertEq(signerList.addresslistLength(), 2, "Incorrect length"); + vm.assertEq(signerList.isListed(alice), false, "Should not be a signer"); + vm.assertEq(signerList.isListed(bob), false, "Should not be a signer"); + vm.assertEq(signerList.isListed(carol), false, "Should not be a signer"); + vm.assertEq(signerList.isListed(david), false, "Should not be a signer"); + vm.assertEq(signerList.isListed(address(100)), true, "Should be a signer"); + vm.assertEq(signerList.isListed(address(200)), true, "Should be a signer"); + } + + function test_InitializingWithAnInvalidRegistryShouldRevert() public { + // 1 + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(alice)), 2)); + + vm.expectRevert(InvalidEncryptionRegitry.selector); + + // 2 + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(bob)), 3)); + + vm.expectRevert(InvalidEncryptionRegitry.selector); + + // OK + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(encryptionRegistry), 2)); + } + + function test_InitializingWithTooManySignersReverts() public { + // 1 + signers = new address[](type(uint16).max + 1); + + signerList = new SignerList(); + vm.expectRevert( + abi.encodeWithSelector(SignerListLengthOutOfBounds.selector, type(uint16).max, type(uint16).max + 1) + ); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + + // 2 + signers = new address[](type(uint16).max + 10); + + signerList = new SignerList(); + vm.expectRevert( + abi.encodeWithSelector(SignerListLengthOutOfBounds.selector, type(uint16).max, type(uint16).max + 10) + ); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + } +} diff --git a/test/helpers/DaoBuilder.sol b/test/helpers/DaoBuilder.sol index 94b8fc9..f1896e1 100644 --- a/test/helpers/DaoBuilder.sol +++ b/test/helpers/DaoBuilder.sol @@ -6,6 +6,8 @@ import {DAO} from "@aragon/osx/core/dao/DAO.sol"; import {Multisig} from "../../src/Multisig.sol"; import {EmergencyMultisig} from "../../src/EmergencyMultisig.sol"; import {OptimisticTokenVotingPlugin} from "../../src/OptimisticTokenVotingPlugin.sol"; +import {SignerList} from "../../src/SignerList.sol"; +import {EncryptionRegistry} from "../../src/EncryptionRegistry.sol"; import {createProxyAndCall} from "../../src/helpers/proxy.sol"; import {RATIO_BASE} from "@aragon/osx/plugins/utils/Ratio.sol"; import {TaikoL1Mock, TaikoL1PausedMock, TaikoL1WithOldLastBlock, TaikoL1Incompatible} from "../mocks/TaikoL1Mock.sol"; @@ -147,7 +149,9 @@ contract DaoBuilder is Test { } function withMinApprovals(uint16 newMinApprovals) public returns (DaoBuilder) { - if (newMinApprovals > multisigMembers.length) revert("You should add enough multisig members first"); + if (newMinApprovals > multisigMembers.length) { + revert("You should add enough multisig members first"); + } minApprovals = newMinApprovals; return this; } @@ -162,6 +166,8 @@ contract DaoBuilder is Test { Multisig multisig, EmergencyMultisig emergencyMultisig, GovernanceERC20Mock votingToken, + SignerList signerList, + EncryptionRegistry encryptionRegistry, ITaikoL1 taikoL1 ) { @@ -217,15 +223,8 @@ contract DaoBuilder is Test { ); } - // Standard multisig + // Encryption registry and signer list { - Multisig.MultisigSettings memory settings = Multisig.MultisigSettings({ - onlyListed: onlyListed, - minApprovals: minApprovals, - destinationProposalDuration: stdProposalDuration, - proposalExpirationPeriod: multisigProposalExpirationPeriod - }); - address[] memory signers; if (multisigMembers.length > 0) { signers = multisigMembers; @@ -234,10 +233,25 @@ contract DaoBuilder is Test { signers = new address[](1); signers[0] = owner; } + + signerList = new SignerList(); + signerList.initialize(dao, signers, SignerList.Settings(EncryptionRegistry(address(0)), 0)); + encryptionRegistry = new EncryptionRegistry(signerList); + signerList.updateSettings(SignerList.Settings(encryptionRegistry, uint16(signers.length))); + } + + // Standard multisig + { + Multisig.MultisigSettings memory settings = Multisig.MultisigSettings({ + onlyListed: onlyListed, + minApprovals: minApprovals, + destinationProposalDuration: stdProposalDuration, + signerList: signerList, + proposalExpirationPeriod: multisigProposalExpirationPeriod + }); + multisig = Multisig( - createProxyAndCall( - address(MULTISIG_BASE), abi.encodeCall(Multisig.initialize, (dao, signers, settings)) - ) + createProxyAndCall(address(MULTISIG_BASE), abi.encodeCall(Multisig.initialize, (dao, settings))) ); } @@ -246,7 +260,7 @@ contract DaoBuilder is Test { EmergencyMultisig.MultisigSettings memory settings = EmergencyMultisig.MultisigSettings({ onlyListed: onlyListed, minApprovals: minApprovals, - addresslistSource: multisig, + signerList: signerList, proposalExpirationPeriod: multisigProposalExpirationPeriod });