From b84939b8cb9f0f6ae5f18814e116e7cd301263bd Mon Sep 17 00:00:00 2001 From: zkfriendly Date: Wed, 18 Dec 2024 08:02:03 +0100 Subject: [PATCH] refactor: use safe singleton deployer in BaseDeployScript and revert DeployRecoveryController to original state --- .../contracts/script/BaseDeployScript.sol | 181 +++++++++++++----- 1 file changed, 129 insertions(+), 52 deletions(-) diff --git a/packages/contracts/script/BaseDeployScript.sol b/packages/contracts/script/BaseDeployScript.sol index 31eef72..32a8aa5 100644 --- a/packages/contracts/script/BaseDeployScript.sol +++ b/packages/contracts/script/BaseDeployScript.sol @@ -16,6 +16,8 @@ import {Groth16Verifier} from "../src/utils/Groth16Verifier.sol"; import {ECDSAOwnedDKIMRegistry} from "../src/utils/ECDSAOwnedDKIMRegistry.sol"; import {EmailAuth} from "../src/EmailAuth.sol"; +import {SafeSingletonDeployer} from "safe-singleton-deployer/SafeSingletonDeployer.sol"; + contract BaseDeployScript is Script { address initialOwner; uint256 deployerPrivateKey; @@ -40,19 +42,32 @@ contract BaseDeployScript is Script { address dkimSigner, uint256 timeDelay ) public returns (address) { - address dkimProxyAddress; - UserOverrideableDKIMRegistry dkimImpl = new UserOverrideableDKIMRegistry(); - dkimProxyAddress = address( - new ERC1967Proxy( - address(dkimImpl), - abi.encodeCall( - UserOverrideableDKIMRegistry.initialize, - (owner, dkimSigner, timeDelay) - ) - ) + // Deploy implementation + address dkimImpl = SafeSingletonDeployer.deploy( + type(UserOverrideableDKIMRegistry).creationCode, + "", + keccak256("DKIM_REGISTRY_IMPL") + ); + + console.log( + "UserOverrideableDKIMRegistry implementation deployed at: %s", + dkimImpl ); + + // Deploy proxy + bytes memory initData = abi.encodeCall( + UserOverrideableDKIMRegistry.initialize, + (owner, dkimSigner, timeDelay) + ); + + address dkimProxyAddress = SafeSingletonDeployer.deploy( + type(ERC1967Proxy).creationCode, + abi.encode(dkimImpl, initData), + keccak256("DKIM_REGISTRY_PROXY") + ); + console.log( - "UseroverrideableDKIMRegistry proxy deployed at: %s", + "UserOverrideableDKIMRegistry deployed at: %s", dkimProxyAddress ); return dkimProxyAddress; @@ -63,14 +78,30 @@ contract BaseDeployScript is Script { address owner, address dkimSigner ) public returns (address) { - address ecdsaDkimProxyAddress; - ECDSAOwnedDKIMRegistry ecdsaDkimImpl = new ECDSAOwnedDKIMRegistry(); - ecdsaDkimProxyAddress = address( - new ERC1967Proxy( - address(ecdsaDkimImpl), - abi.encodeCall(ecdsaDkimImpl.initialize, (owner, dkimSigner)) - ) + // Deploy implementation + address ecdsaDkimImpl = SafeSingletonDeployer.deploy( + type(ECDSAOwnedDKIMRegistry).creationCode, + "", + keccak256("ECDSA_DKIM_IMPL") + ); + + console.log( + "ECDSAOwnedDKIMRegistry implementation deployed at: %s", + ecdsaDkimImpl + ); + + // Deploy proxy + bytes memory initData = abi.encodeCall( + ECDSAOwnedDKIMRegistry.initialize, + (owner, dkimSigner) ); + + address ecdsaDkimProxyAddress = SafeSingletonDeployer.deploy( + type(ERC1967Proxy).creationCode, + abi.encode(ecdsaDkimImpl, initData), + keccak256("ECDSA_DKIM_PROXY") + ); + console.log( "ECDSAOwnedDKIMRegistry proxy deployed at: %s", ecdsaDkimProxyAddress @@ -80,27 +111,47 @@ contract BaseDeployScript is Script { /// @notice Deploys a Verifier contract with a specified owner and Groth16 verifier function deployVerifier(address owner) public returns (address) { - address verifierProxyAddress; - Verifier verifierImpl = new Verifier(); - Groth16Verifier groth16Verifier = new Groth16Verifier(); - console.log("Groth16Verifier deployed at: %s", address(groth16Verifier)); - verifierProxyAddress = address( - new ERC1967Proxy( - address(verifierImpl), - abi.encodeCall( - verifierImpl.initialize, - (owner, address(groth16Verifier)) - ) - ) + // Deploy implementation + address verifierImpl = SafeSingletonDeployer.deploy( + type(Verifier).creationCode, + "", + keccak256("VERIFIER_IMPL") + ); + + console.log("Verifier implementation deployed at: %s", verifierImpl); + + address groth16Verifier = SafeSingletonDeployer.deploy( + type(Groth16Verifier).creationCode, + "", + keccak256("GROTH16_VERIFIER") + ); + + console.log("Groth16Verifier deployed at: %s", groth16Verifier); + + // Deploy proxy + bytes memory initData = abi.encodeCall( + Verifier.initialize, + (owner, address(groth16Verifier)) + ); + + address verifierProxyAddress = SafeSingletonDeployer.deploy( + type(ERC1967Proxy).creationCode, + abi.encode(verifierImpl, initData), + keccak256("VERIFIER_PROXY") ); + console.log("Verifier deployed at: %s", verifierProxyAddress); return verifierProxyAddress; } /// @notice Deploys an EmailAuth implementation contract function deployEmailAuthImplementation() public returns (address) { - address emailAuthImplAddress; - emailAuthImplAddress = address(new EmailAuth()); + address emailAuthImplAddress = SafeSingletonDeployer.deploy( + type(EmailAuth).creationCode, + "", + keccak256("EMAIL_AUTH_IMPL") + ); + console.log( "EmailAuth implementation deployed at: %s", emailAuthImplAddress @@ -115,17 +166,30 @@ contract BaseDeployScript is Script { address dkim, address emailAuthImpl ) public returns (address) { - address recoveryControllerProxyAddress; - RecoveryController recoveryControllerImpl = new RecoveryController(); - recoveryControllerProxyAddress = address( - new ERC1967Proxy( - address(recoveryControllerImpl), - abi.encodeCall( - RecoveryController.initialize, - (owner, verifier, dkim, emailAuthImpl) - ) - ) + // Deploy implementation + address recoveryControllerImpl = SafeSingletonDeployer.deploy( + type(RecoveryController).creationCode, + "", + keccak256("RECOVERY_CONTROLLER_IMPL") + ); + + console.log( + "RecoveryController implementation deployed at: %s", + recoveryControllerImpl + ); + + // Deploy proxy + bytes memory initData = abi.encodeCall( + RecoveryController.initialize, + (owner, verifier, dkim, emailAuthImpl) + ); + + address recoveryControllerProxyAddress = SafeSingletonDeployer.deploy( + type(ERC1967Proxy).creationCode, + abi.encode(recoveryControllerImpl, initData), + keccak256("RECOVERY_CONTROLLER_PROXY") ); + console.log( "RecoveryController deployed at: %s", recoveryControllerProxyAddress @@ -180,17 +244,30 @@ contract BaseDeployScript is Script { address owner, address recoveryController ) public returns (address) { - address simpleWalletProxyAddress; - SimpleWallet simpleWalletImpl = new SimpleWallet(); - simpleWalletProxyAddress = address( - new ERC1967Proxy( - address(simpleWalletImpl), - abi.encodeCall( - simpleWalletImpl.initialize, - (owner, address(recoveryController)) - ) - ) + // Deploy implementation + address simpleWalletImpl = SafeSingletonDeployer.deploy( + type(SimpleWallet).creationCode, + "", + keccak256("SIMPLE_WALLET_IMPL") ); + + console.log( + "SimpleWallet implementation deployed at: %s", + simpleWalletImpl + ); + + // Deploy proxy + bytes memory initData = abi.encodeCall( + SimpleWallet.initialize, + (owner, address(recoveryController)) + ); + + address simpleWalletProxyAddress = SafeSingletonDeployer.deploy( + type(ERC1967Proxy).creationCode, + abi.encode(simpleWalletImpl, initData), + keccak256("SIMPLE_WALLET_PROXY") + ); + console.log("SimpleWallet deployed at: %s", simpleWalletProxyAddress); return simpleWalletProxyAddress; }