Skip to content

Commit

Permalink
Add a function to change the main authorizer to Useroverridable DKIM …
Browse files Browse the repository at this point in the history
…registry. (#235)

* Add changeMainAuthorizer

* Update versions
  • Loading branch information
SoraSuegami authored Oct 30, 2024
1 parent 3b3c808 commit 3e551fb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/circuits/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/circuits",
"version": "6.3.0",
"version": "6.3.1",
"license": "MIT",
"scripts": {
"publish": "yarn npm publish --access=public",
Expand Down
24 changes: 24 additions & 0 deletions packages/contracts/UserOverrideableDKIMRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ contract UserOverrideableDKIMRegistry is
address indexed authorizer
);

/// @notice Emitted when the main authorizer address is changed.
event MainAuthorizerChanged(address indexed newMainAuthorizer);

/// @notice Main authorizer address.
address public mainAuthorizer;

Expand Down Expand Up @@ -356,6 +359,27 @@ contract UserOverrideableDKIMRegistry is
emit DKIMPublicKeyHashReactivated(publicKeyHash, authorizer);
}

/**
* @notice Changes the main authorizer address.
* @param newMainAuthorizer The address of the new main authorizer.
* @custom:require Only the owner can change the main authorizer address.
* @custom:require The new main authorizer address cannot be zero.
* @custom:require The new main authorizer address cannot be the same as the current main authorizer.
* @custom:event MainAuthorizerChanged Emitted when the main authorizer address changes.
*/
function changeMainAuthorizer(address newMainAuthorizer) public onlyOwner {
require(
newMainAuthorizer != address(0),
"newMainAuthorizer address cannot be zero"
);
require(
newMainAuthorizer != mainAuthorizer,
"newMainAuthorizer address cannot be the same as the current mainAuthorizer"
);
mainAuthorizer = newMainAuthorizer;
emit MainAuthorizerChanged(newMainAuthorizer);
}

/**
* @notice Computes a signed message string for setting or revoking a DKIM public key hash.
* @param prefix The operation prefix (SET: or REVOKE:).
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/contracts",
"version": "6.3.0",
"version": "6.3.1",
"license": "MIT",
"scripts": {
"build": "forge build",
Expand Down
44 changes: 44 additions & 0 deletions packages/contracts/test/UserOverrideableDKIMRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,22 @@ contract UserOverrideableDKIMRegistryTest is Test {
vm.stopPrank();
}

function testChangeMainAuthorizer() public {
vm.startPrank(deployer);
vm.expectEmit();
emit UserOverrideableDKIMRegistry.MainAuthorizerChanged(user1);
registry.changeMainAuthorizer(user1);
vm.stopPrank();
}

function testChangeMainAuthorizerContract() public {
vm.startPrank(deployer);
vm.expectEmit();
emit UserOverrideableDKIMRegistry.MainAuthorizerChanged(user1);
registryWithContract.changeMainAuthorizer(address(user1));
vm.stopPrank();
}

function testFailIsDKIMPublicKeyHashValidByUser2() public {
testSetDKIMPublicKeyHashByUser1();

Expand Down Expand Up @@ -1099,4 +1115,32 @@ contract UserOverrideableDKIMRegistryTest is Test {
);
console.log(signedMsg);
}

function testExpectRevertChangeMainAuthorizerByNonOwner() public {
vm.startPrank(mainAuthorizer);
vm.expectRevert(
abi.encodeWithSelector(
OwnableUpgradeable.OwnableUnauthorizedAccount.selector,
mainAuthorizer
)
);
registry.changeMainAuthorizer(user1);
vm.stopPrank();
}

function testExpectRevertChangeMainAuthorizerIsZero() public {
vm.startPrank(deployer);
vm.expectRevert("newMainAuthorizer address cannot be zero");
registry.changeMainAuthorizer(address(0));
vm.stopPrank();
}

function testExpectRevertChangeMainAuthorizerIsSame() public {
vm.startPrank(deployer);
vm.expectRevert(
"newMainAuthorizer address cannot be the same as the current mainAuthorizer"
);
registry.changeMainAuthorizer(mainAuthorizer);
vm.stopPrank();
}
}
2 changes: 1 addition & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/helpers",
"version": "6.3.0",
"version": "6.3.1",
"license": "MIT",
"main": "dist",
"scripts": {
Expand Down

0 comments on commit 3e551fb

Please sign in to comment.