Skip to content

Commit

Permalink
Remove ForwardDKIMRegistry and Add scripts for UseroverridableDKIMReg…
Browse files Browse the repository at this point in the history
…istry
  • Loading branch information
SoraSuegami committed Oct 21, 2024
1 parent d75815e commit 9995f1f
Show file tree
Hide file tree
Showing 24 changed files with 596 additions and 444 deletions.
4 changes: 0 additions & 4 deletions packages/contracts/script/ChangeOwners.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.13;
import "forge-std/Script.sol";

import "../src/utils/Verifier.sol";
import "../src/utils/ForwardDKIMRegistry.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract ChangeOwners is Script {
Expand Down Expand Up @@ -32,9 +31,6 @@ contract ChangeOwners is Script {
}
if (dkim != address(0)) {
OwnableUpgradeable(dkim).transferOwnership(newOwner);
OwnableUpgradeable(
address(ForwardDKIMRegistry(dkim).sourceDKIMRegistry())
).transferOwnership(newOwner);
}
vm.stopBroadcast();
}
Expand Down
30 changes: 0 additions & 30 deletions packages/contracts/script/ChangeSourceInForwardDKIMRegistry.s.sol

This file was deleted.

49 changes: 0 additions & 49 deletions packages/contracts/script/DeployForwardDKIMRegistry.s.sol

This file was deleted.

29 changes: 11 additions & 18 deletions packages/contracts/script/DeployRecoveryController.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import "../test/helpers/SimpleWallet.sol";
import "../test/helpers/RecoveryController.sol";
import "../src/utils/Verifier.sol";
import "../src/utils/Groth16Verifier.sol";
import "../src/utils/ForwardDKIMRegistry.sol";
import "../src/EmailAuth.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";

contract Deploy is Script {
using ECDSA for *;

ForwardDKIMRegistry dkim;
UserOverrideableDKIMRegistry dkim;
Verifier verifier;
EmailAuth emailAuthImpl;
SimpleWallet simpleWallet;
Expand All @@ -38,33 +37,27 @@ contract Deploy is Script {
address initialOwner = vm.addr(deployerPrivateKey);

// Deploy Useroverridable and Forward DKIM registries
dkim = ForwardDKIMRegistry(vm.envOr("DKIM", address(0)));
dkim = UserOverrideableDKIMRegistry(vm.envOr("DKIM", address(0)));
uint setTimeDelay = vm.envOr("DKIM_DELAY", uint(0));
console.log("DKIM_DELAY: %s", setTimeDelay);
if (address(dkim) == address(0)) {
UserOverrideableDKIMRegistry overrideableDkimImpl = new UserOverrideableDKIMRegistry();
UserOverrideableDKIMRegistry dkimImpl = new UserOverrideableDKIMRegistry();
console.log(
"UserOverrideableDKIMRegistry implementation deployed at: %s",
address(overrideableDkimImpl)
address(dkimImpl)
);
ForwardDKIMRegistry forwardDkimImpl = new ForwardDKIMRegistry();
ERC1967Proxy forwardDkimProxy = new ERC1967Proxy(
address(forwardDkimImpl),
ERC1967Proxy dkimProxy = new ERC1967Proxy(
address(dkimImpl),
abi.encodeCall(
forwardDkimImpl.initializeWithUserOverrideableDKIMRegistry,
(
initialOwner,
address(overrideableDkimImpl),
signer,
setTimeDelay
)
dkimImpl.initialize,
(initialOwner, signer, setTimeDelay)
)
);
dkim = ForwardDKIMRegistry(address(forwardDkimProxy));
dkim = UserOverrideableDKIMRegistry(address(dkimProxy));
console.log(
"UseroverrideableDKIMRegistry proxy deployed at: %s",
address(dkim.sourceDKIMRegistry())
address(dkim)
);
console.log("ForwardDKIMRegistry deployed at: %s", address(dkim));
}
// Deploy Verifier
verifier = Verifier(vm.envOr("VERIFIER", address(0)));
Expand Down
29 changes: 10 additions & 19 deletions packages/contracts/script/DeployRecoveryControllerZKSync.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import "../test/helpers/SimpleWallet.sol";
import "../test/helpers/RecoveryControllerZKSync.sol";
import "../src/utils/Verifier.sol";
import "../src/utils/Groth16Verifier.sol";
import "../src/utils/ForwardDKIMRegistry.sol";
// import "../src/utils/ForwardDKIMRegistry.sol";
import "../src/EmailAuth.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {ZKSyncCreate2Factory} from "../src/utils/ZKSyncCreate2Factory.sol";
Expand All @@ -18,7 +16,7 @@ import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideable
contract Deploy is Script {
using ECDSA for *;

ForwardDKIMRegistry dkim;
UserOverrideableDKIMRegistry dkim;
Verifier verifier;
EmailAuth emailAuthImpl;
SimpleWallet simpleWallet;
Expand Down Expand Up @@ -46,33 +44,26 @@ contract Deploy is Script {
address initialOwner = vm.addr(deployerPrivateKey);

// Deploy Useroverridable and Forward DKIM registries
dkim = ForwardDKIMRegistry(vm.envOr("DKIM", address(0)));
dkim = UserOverrideableDKIMRegistry(vm.envOr("DKIM", address(0)));
uint setTimeDelay = vm.envOr("DKIM_DELAY", uint(0));
if (address(dkim) == address(0)) {
UserOverrideableDKIMRegistry overrideableDkimImpl = new UserOverrideableDKIMRegistry();
UserOverrideableDKIMRegistry dkimImpl = new UserOverrideableDKIMRegistry();
console.log(
"UserOverrideableDKIMRegistry implementation deployed at: %s",
address(overrideableDkimImpl)
address(dkimImpl)
);
ForwardDKIMRegistry forwardDkimImpl = new ForwardDKIMRegistry();
ERC1967Proxy forwardDkimProxy = new ERC1967Proxy(
address(forwardDkimImpl),
ERC1967Proxy dkimProxy = new ERC1967Proxy(
address(dkimImpl),
abi.encodeCall(
forwardDkimImpl.initializeWithUserOverrideableDKIMRegistry,
(
initialOwner,
address(overrideableDkimImpl),
signer,
setTimeDelay
)
dkimImpl.initialize,
(initialOwner, signer, setTimeDelay)
)
);
dkim = ForwardDKIMRegistry(address(forwardDkimProxy));
dkim = UserOverrideableDKIMRegistry(address(dkimProxy));
console.log(
"UseroverrideableDKIMRegistry proxy deployed at: %s",
address(dkim.sourceDKIMRegistry())
address(dkim)
);
console.log("ForwardDKIMRegistry deployed at: %s", address(dkim));
}
// Deploy Verifier
verifier = Verifier(vm.envOr("VERIFIER", address(0)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "../test/helpers/SimpleWallet.sol";
import "../test/helpers/RecoveryController.sol";
import "../src/utils/Verifier.sol";
import "../src/utils/Groth16Verifier.sol";
import "../src/EmailAuth.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

contract ReactivatePublicKeyHash is Script {
using ECDSA for *;

UserOverrideableDKIMRegistry dkim;
RecoveryController recoveryController;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}
address dkimAddr = vm.envAddress("DKIM");
if (dkimAddr == address(0)) {
console.log("DKIM env var not set");
return;
}
address walletAddr = vm.envAddress("SIMPLE_WALLET");
if (walletAddr == address(0)) {
console.log("SIMPLE_WALLET env var not set");
return;
}
dkim = UserOverrideableDKIMRegistry(dkimAddr);
string memory domainName = vm.envString("DOMAIN");
if (bytes(domainName).length == 0) {
console.log("DOMAIN env var not set");
return;
}
bytes32 publicKeyHash = vm.envBytes32("PUBLIC_KEY_HASH");
if (publicKeyHash == bytes32(0)) {
console.log("PUBLIC_KEY_HASH env var not set");
return;
}
string memory signedMsg = dkim.computeSignedMsg(
dkim.REACTIVATE_PREFIX(),
domainName,
publicKeyHash
);
bytes32 digest = MessageHashUtils.toEthSignedMessageHash(
bytes(signedMsg)
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(deployerPrivateKey, digest);
bytes memory signature = abi.encodePacked(r, s, v);
vm.startBroadcast(deployerPrivateKey);
dkim.reactivateDKIMPublicKeyHash(
domainName,
publicKeyHash,
walletAddr,
signature
);
vm.stopBroadcast();
}
}
4 changes: 0 additions & 4 deletions packages/contracts/script/RenounceOwners.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "forge-std/Script.sol";

import "../src/utils/Verifier.sol";
import "../src/utils/ECDSAOwnedDKIMRegistry.sol";
import "../src/utils/ForwardDKIMRegistry.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract RenounceOwners is Script {
Expand All @@ -28,9 +27,6 @@ contract RenounceOwners is Script {
}
if (dkim != address(0)) {
OwnableUpgradeable(dkim).renounceOwnership();
OwnableUpgradeable(
address(ForwardDKIMRegistry(dkim).sourceDKIMRegistry())
).renounceOwnership();
}
vm.stopBroadcast();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "../test/helpers/SimpleWallet.sol";
import "../test/helpers/RecoveryController.sol";
import "../src/utils/Verifier.sol";
import "../src/utils/Groth16Verifier.sol";
import "../src/EmailAuth.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {UserOverrideableDKIMRegistry} from "@zk-email/contracts/UserOverrideableDKIMRegistry.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

contract RevokePublicKeyHash is Script {
using ECDSA for *;

UserOverrideableDKIMRegistry dkim;
RecoveryController recoveryController;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}
address dkimAddr = vm.envAddress("DKIM");
if (dkimAddr == address(0)) {
console.log("DKIM env var not set");
return;
}
address walletAddr = vm.envAddress("SIMPLE_WALLET");
if (walletAddr == address(0)) {
console.log("SIMPLE_WALLET env var not set");
return;
}
dkim = UserOverrideableDKIMRegistry(dkimAddr);
string memory domainName = vm.envString("DOMAIN");
if (bytes(domainName).length == 0) {
console.log("DOMAIN env var not set");
return;
}
bytes32 publicKeyHash = vm.envBytes32("PUBLIC_KEY_HASH");
if (publicKeyHash == bytes32(0)) {
console.log("PUBLIC_KEY_HASH env var not set");
return;
}
string memory signedMsg = dkim.computeSignedMsg(
dkim.REVOKE_PREFIX(),
domainName,
publicKeyHash
);
bytes32 digest = MessageHashUtils.toEthSignedMessageHash(
bytes(signedMsg)
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(deployerPrivateKey, digest);
bytes memory signature = abi.encodePacked(r, s, v);
vm.startBroadcast(deployerPrivateKey);
dkim.revokeDKIMPublicKeyHash(
domainName,
publicKeyHash,
walletAddr,
signature
);
vm.stopBroadcast();
}
}
Loading

0 comments on commit 9995f1f

Please sign in to comment.