From a0c889405727a0226bf7a84e38409e459ae29970 Mon Sep 17 00:00:00 2001 From: JohnGuilding Date: Tue, 2 Jul 2024 16:59:48 +0200 Subject: [PATCH 1/3] Pass dkim regsitry as module deployment arg & update recovery calldata --- script/Deploy7579Controller.s.sol | 5 ++-- src/EmailRecoveryFactory.sol | 8 +++---- src/test/OwnableValidator.sol | 2 +- .../EmailRecoveryModuleBase.t.sol | 19 +++++---------- .../UniversalEmailRecoveryModuleBase.t.sol | 24 ++++++++----------- .../SafeRecovery/SafeRecovery.t.sol | 6 ++--- .../deployEmailRecoveryModule.t.sol | 5 ++-- .../deployUniversalEmailRecoveryModule.t.sol | 10 ++++---- test/unit/SafeUnitBase.t.sol | 4 +--- test/unit/UnitBase.t.sol | 10 +++----- .../EmailRecoveryModuleBase.t.sol | 10 +++----- 11 files changed, 42 insertions(+), 61 deletions(-) diff --git a/script/Deploy7579Controller.s.sol b/script/Deploy7579Controller.s.sol index b92e7130..0177e65c 100644 --- a/script/Deploy7579Controller.s.sol +++ b/script/Deploy7579Controller.s.sol @@ -45,7 +45,7 @@ contract Deploy7579ControllerScript is Script { // ); address _factory = vm.envOr("RECOVERY_FACTORY", address(0)); if (_factory == address(0)) { - _factory = address(new EmailRecoveryFactory(verifier, dkimRegistry, emailAuthImpl)); + _factory = address(new EmailRecoveryFactory(verifier, emailAuthImpl)); // vm.setEnv("RECOVERY_FACTORY", vm.toString(_factory)); console.log("Deployed Email Recovery Factory at", _factory); } @@ -56,7 +56,8 @@ contract Deploy7579ControllerScript is Script { bytes32(uint256(0)), bytes32(uint256(0)), bytes32(uint256(0)), - type(EmailRecoverySubjectHandler).creationCode + type(EmailRecoverySubjectHandler).creationCode, + dkimRegistry ); // vm.setEnv("RECOVERY_MANAGER", vm.toString(manager)); // vm.setEnv("RECOVERY_MODULE", vm.toString(module)); diff --git a/src/EmailRecoveryFactory.sol b/src/EmailRecoveryFactory.sol index c84bbfb2..6fd181f0 100644 --- a/src/EmailRecoveryFactory.sol +++ b/src/EmailRecoveryFactory.sol @@ -8,16 +8,14 @@ import { EmailRecoveryModule } from "./modules/EmailRecoveryModule.sol"; contract EmailRecoveryFactory { address public immutable verifier; - address public immutable dkimRegistry; address public immutable emailAuthImpl; event EmailRecoveryModuleDeployed( address emailRecoveryModule, address emailRecoveryManager, address subjectHandler ); - constructor(address _verifier, address _dkimRegistry, address _emailAuthImpl) { + constructor(address _verifier, address _emailAuthImpl) { verifier = _verifier; - dkimRegistry = _dkimRegistry; emailAuthImpl = _emailAuthImpl; } @@ -26,6 +24,7 @@ contract EmailRecoveryFactory { bytes32 recoveryManagerSalt, bytes32 recoveryModuleSalt, bytes memory subjectHandlerBytecode, + address dkimRegistry, address validator, bytes4 functionSelector ) @@ -60,7 +59,8 @@ contract EmailRecoveryFactory { bytes32 subjectHandlerSalt, bytes32 recoveryManagerSalt, bytes32 recoveryModuleSalt, - bytes memory subjectHandlerBytecode + bytes memory subjectHandlerBytecode, + address dkimRegistry ) external returns (address, address, address) diff --git a/src/test/OwnableValidator.sol b/src/test/OwnableValidator.sol index 2aff8e67..eb5933e5 100644 --- a/src/test/OwnableValidator.sol +++ b/src/test/OwnableValidator.sol @@ -74,7 +74,7 @@ contract OwnableValidator is ERC7579ValidatorBase { : EIP1271_FAILED; } - function changeOwner(address account, address authorizedAccount, address newOwner) external { + function changeOwner(address newOwner) external { owners[msg.sender] = newOwner; } diff --git a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index d99ede2b..7a1d716c 100644 --- a/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -50,11 +50,9 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati validator = new OwnableValidator(); validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); + functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); emailRecoveryHandler = new EmailRecoverySubjectHandler(); // Deploy EmailRecoveryManager & EmailRecoveryModule @@ -68,20 +66,15 @@ abstract contract OwnableValidatorRecovery_EmailRecoveryModule_Base is Integrati recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode, + address(ecdsaOwnedDkimRegistry), validatorAddress, functionSelector ); emailRecoveryManager = EmailRecoveryManager(emailRecoveryManagerAddress); - recoveryCalldata1 = abi.encodeWithSelector( - functionSelector, accountAddress1, recoveryModuleAddress, newOwner1 - ); - recoveryCalldata2 = abi.encodeWithSelector( - functionSelector, accountAddress2, recoveryModuleAddress, newOwner2 - ); - recoveryCalldata3 = abi.encodeWithSelector( - functionSelector, accountAddress3, recoveryModuleAddress, newOwner3 - ); + recoveryCalldata1 = abi.encodeWithSelector(functionSelector, newOwner1); + recoveryCalldata2 = abi.encodeWithSelector(functionSelector, newOwner2); + recoveryCalldata3 = abi.encodeWithSelector(functionSelector, newOwner3); calldataHash1 = keccak256(recoveryCalldata1); calldataHash2 = keccak256(recoveryCalldata2); calldataHash3 = keccak256(recoveryCalldata3); diff --git a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol index 2592b9e1..f754d023 100644 --- a/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol +++ b/test/integration/OwnableValidatorRecovery/UniversalEmailRecoveryModule/UniversalEmailRecoveryModuleBase.t.sol @@ -46,9 +46,7 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is function setUp() public virtual override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); emailRecoveryHandler = new EmailRecoverySubjectHandler(); // Deploy EmailRecoveryManager & UniversalEmailRecoveryModule @@ -58,7 +56,11 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is bytes memory subjectHandlerBytecode = type(EmailRecoverySubjectHandler).creationCode; (recoveryModuleAddress, emailRecoveryManagerAddress,) = emailRecoveryFactory .deployUniversalEmailRecoveryModule( - subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode + subjectHandlerSalt, + recoveryManagerSalt, + recoveryModuleSalt, + subjectHandlerBytecode, + address(ecdsaOwnedDkimRegistry) ); emailRecoveryManager = EmailRecoveryManager(emailRecoveryManagerAddress); @@ -66,16 +68,10 @@ abstract contract OwnableValidatorRecovery_UniversalEmailRecoveryModule_Base is validator = new OwnableValidator(); validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - recoveryCalldata1 = abi.encodeWithSelector( - functionSelector, accountAddress1, recoveryModuleAddress, newOwner1 - ); - recoveryCalldata2 = abi.encodeWithSelector( - functionSelector, accountAddress2, recoveryModuleAddress, newOwner2 - ); - recoveryCalldata3 = abi.encodeWithSelector( - functionSelector, accountAddress3, recoveryModuleAddress, newOwner3 - ); + functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); + recoveryCalldata1 = abi.encodeWithSelector(functionSelector, newOwner1); + recoveryCalldata2 = abi.encodeWithSelector(functionSelector, newOwner2); + recoveryCalldata3 = abi.encodeWithSelector(functionSelector, newOwner3); calldataHash1 = keccak256(recoveryCalldata1); calldataHash2 = keccak256(recoveryCalldata2); calldataHash3 = keccak256(recoveryCalldata3); diff --git a/test/integration/SafeRecovery/SafeRecovery.t.sol b/test/integration/SafeRecovery/SafeRecovery.t.sol index 0e110ce6..aaa2d4f0 100644 --- a/test/integration/SafeRecovery/SafeRecovery.t.sol +++ b/test/integration/SafeRecovery/SafeRecovery.t.sol @@ -9,21 +9,21 @@ import { Safe } from "@safe-global/safe-contracts/contracts/Safe.sol"; import { IEmailRecoveryManager } from "src/interfaces/IEmailRecoveryManager.sol"; import { GuardianStorage, GuardianStatus } from "src/libraries/EnumerableGuardianMap.sol"; -import { UniversalEmailRecoveryModule } from "src/modules/UniversalEmailRecoveryModule.sol"; +import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; import { SafeIntegrationBase } from "./SafeIntegrationBase.t.sol"; contract SafeRecovery_Integration_Test is SafeIntegrationBase { using ModuleKitHelpers for *; using ModuleKitUserOp for *; - UniversalEmailRecoveryModule recoveryModule; + EmailRecoveryModule recoveryModule; address recoveryModuleAddress; bytes4 functionSelector; // function setUp() public override { // super.setUp(); - // recoveryModule = new UniversalEmailRecoveryModule(address(emailRecoveryManager)); + // recoveryModule = new EmailRecoveryModule(address(emailRecoveryManager)); // recoveryModuleAddress = address(recoveryModule); // functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); diff --git a/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol b/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol index ca63e9bf..4a28f2a8 100644 --- a/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol +++ b/test/unit/EmailRecoveryFactory/deployEmailRecoveryModule.t.sol @@ -12,9 +12,7 @@ import { EmailRecoveryModule } from "src/modules/EmailRecoveryModule.sol"; contract EmailRecoveryFactory_deployAll_Test is UnitBase { function setUp() public override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(dkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); } function test_DeployEmailRecoveryModule_Succeeds() public { @@ -54,6 +52,7 @@ contract EmailRecoveryFactory_deployAll_Test is UnitBase { recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode, + address(dkimRegistry), validatorAddress, functionSelector ); diff --git a/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol b/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol index 5a96b157..01444523 100644 --- a/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol +++ b/test/unit/EmailRecoveryFactory/deployUniversalEmailRecoveryModule.t.sol @@ -12,9 +12,7 @@ import { UniversalEmailRecoveryModule } from "src/modules/UniversalEmailRecovery contract EmailRecoveryFactory_deployUniversalEmailRecoveryModule_Test is UnitBase { function setUp() public override { super.setUp(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(dkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); } function test_DeployUniversalEmailRecoveryModule_Succeeds() public { @@ -49,7 +47,11 @@ contract EmailRecoveryFactory_deployUniversalEmailRecoveryModule_Test is UnitBas (address emailRecoveryModule, address emailRecoveryManager, address subjectHandler) = emailRecoveryFactory.deployUniversalEmailRecoveryModule( - subjectHandlerSalt, recoveryManagerSalt, recoveryModuleSalt, subjectHandlerBytecode + subjectHandlerSalt, + recoveryManagerSalt, + recoveryModuleSalt, + subjectHandlerBytecode, + address(dkimRegistry) ); assertEq(emailRecoveryManager, expectedManager); diff --git a/test/unit/SafeUnitBase.t.sol b/test/unit/SafeUnitBase.t.sol index a5c93254..afc1d760 100644 --- a/test/unit/SafeUnitBase.t.sol +++ b/test/unit/SafeUnitBase.t.sol @@ -64,9 +64,7 @@ abstract contract SafeUnitBase is IntegrationBase { // Deploy handler, manager and module safeRecoverySubjectHandler = new SafeRecoverySubjectHandlerHarness(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(ecdsaOwnedDkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), diff --git a/test/unit/UnitBase.t.sol b/test/unit/UnitBase.t.sol index 19c99efa..a552339a 100644 --- a/test/unit/UnitBase.t.sol +++ b/test/unit/UnitBase.t.sol @@ -109,9 +109,7 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { // Deploy handler, manager and module emailRecoveryHandler = new EmailRecoverySubjectHandler(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(dkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), @@ -159,10 +157,8 @@ abstract contract UnitBase is RhinestoneModuleKit, Test { validator = new OwnableValidator(); validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - recoveryCalldata = abi.encodeWithSignature( - "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner - ); + functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); + recoveryCalldata = abi.encodeWithSelector(functionSelector, newOwner); calldataHash = keccak256(recoveryCalldata); // Install modules diff --git a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol index ea91b171..841f1d9d 100644 --- a/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol +++ b/test/unit/modules/EmailRecoveryModule/EmailRecoveryModuleBase.t.sol @@ -111,17 +111,13 @@ abstract contract EmailRecoveryModuleBase is RhinestoneModuleKit, Test { validator = new OwnableValidator(); validatorAddress = address(validator); isInstalledContext = bytes("0"); - functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - recoveryCalldata = abi.encodeWithSignature( - "changeOwner(address,address,address)", accountAddress, recoveryModuleAddress, newOwner - ); + functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); + recoveryCalldata = abi.encodeWithSelector(functionSelector, newOwner); calldataHash = keccak256(recoveryCalldata); // Deploy handler, manager and module emailRecoveryHandler = new EmailRecoverySubjectHandler(); - emailRecoveryFactory = new EmailRecoveryFactory( - address(verifier), address(dkimRegistry), address(emailAuthImpl) - ); + emailRecoveryFactory = new EmailRecoveryFactory(address(verifier), address(emailAuthImpl)); emailRecoveryManager = new EmailRecoveryManagerHarness( address(verifier), From 4da249214e0771ea10449e7cbf17f0a0217d21ea Mon Sep 17 00:00:00 2001 From: JohnGuilding Date: Tue, 2 Jul 2024 17:07:20 +0200 Subject: [PATCH 2/3] Update deploy scripts --- script/Compute7579CalldataHash.s.sol | 77 ++-------------------------- script/Deploy.s.sol | 29 ----------- script/Deploy7579Controller.s.sol | 12 +---- script/Deploy7579TestAccount.s.sol | 58 ++------------------- 4 files changed, 9 insertions(+), 167 deletions(-) delete mode 100644 script/Deploy.s.sol diff --git a/script/Compute7579CalldataHash.s.sol b/script/Compute7579CalldataHash.s.sol index f91fde90..f112efe7 100644 --- a/script/Compute7579CalldataHash.s.sol +++ b/script/Compute7579CalldataHash.s.sol @@ -3,83 +3,16 @@ pragma solidity ^0.8.25; import { Script } from "forge-std/Script.sol"; import { console } from "forge-std/console.sol"; -import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol"; -import { EmailRecoveryManager } from "src/EmailRecoveryManager.sol"; -import { Verifier } from "ether-email-auth/packages/contracts/src/utils/Verifier.sol"; -import { ECDSAOwnedDKIMRegistry } from - "ether-email-auth/packages/contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; -import { EmailAuth } from "ether-email-auth/packages/contracts/src/EmailAuth.sol"; -import { EmailRecoveryFactory } from "src/EmailRecoveryFactory.sol"; contract Compute7579CalldataHash is Script { - bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); - function run() public { - address accountAddr = vm.envAddress("ACCOUNT"); - address recoveryModuleAddr = vm.envAddress("RECOVERY_MODULE"); + bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); address newOwner = vm.envAddress("NEW_OWNER"); - bytes memory recoveryCalldata = - abi.encodeWithSelector(functionSelector, accountAddr, newOwner, recoveryModuleAddr); - console.log("recoveryCalldata", vm.toString(recoveryCalldata)); - bytes32 calldataHash = keccak256(recoveryCalldata); - console.log("calldataHash", vm.toString(calldataHash)); - // vm.startBroadcast(vm.envUint("PRIVATE_KEY")); - // address verifier = vm.envOr("VERIFIER", address(0)); - // address dkimRegistry = vm.envOr("DKIM_REGISTRY", address(0)); - // address dkimRegistrySigner = vm.envOr("SIGNER", address(0)); - // address emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0)); - - // if (verifier == address(0)) { - // verifier = address(new Verifier()); - // // vm.setEnv("VERIFIER", vm.toString(verifier)); - // console.log("Deployed Verifier at", verifier); - // } - // if (dkimRegistry == address(0)) { - // require( - // dkimRegistrySigner != address(0), - // "DKIM_REGISTRY_SIGNER is required" - // ); - // dkimRegistry = address( - // new ECDSAOwnedDKIMRegistry(dkimRegistrySigner) - // ); - // // vm.setEnv("DKIM_REGISTRY", vm.toString(dkimRegistry)); - // console.log("Deployed DKIM Registry at", dkimRegistry); - // } - - // if (emailAuthImpl == address(0)) { - // emailAuthImpl = address(new EmailAuth()); - // // vm.setEnv("EMAIL_AUTH_IMPL", vm.toString(emailAuthImpl)); - // console.log("Deployed Email Auth at", emailAuthImpl); - // } - - // EmailRecoverySubjectHandler emailRecoveryHandler = new EmailRecoverySubjectHandler(); - // // vm.setEnv( - // // "RECOVERY_HANDLER", - // // vm.toString(address(emailRecoveryHandler)) - // // ); - // address _factory = vm.envOr("RECOVERY_FACTORY", address(0)); - // if (_factory == address(0)) { - // _factory = address(new EmailRecoveryFactory()); - // // vm.setEnv("RECOVERY_FACTORY", vm.toString(_factory)); - // console.log("Deployed Email Recovery Factory at", _factory); - // } - // EmailRecoveryFactory factory = EmailRecoveryFactory(_factory); - // (address manager, address module) = factory.deployUniversalEmailRecoveryModule( - // verifier, - // dkimRegistry, - // emailAuthImpl, - // address(emailRecoveryHandler) - // ); - // // vm.setEnv("RECOVERY_MANAGER", vm.toString(manager)); - // // vm.setEnv("RECOVERY_MODULE", vm.toString(module)); + bytes memory recoveryCalldata = abi.encodeWithSelector(functionSelector, newOwner); + bytes32 calldataHash = keccak256(recoveryCalldata); - // console.log( - // "Deployed Email Recovery Handler at", - // address(emailRecoveryHandler) - // ); - // console.log("Deployed Email Recovery Manager at", vm.toString(manager)); - // console.log("Deployed Email Recovery Module at", vm.toString(module)); - // vm.stopBroadcast(); + console.log("recoveryCalldata", vm.toString(recoveryCalldata)); + console.log("calldataHash", vm.toString(calldataHash)); } } diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol deleted file mode 100644 index d7c353b7..00000000 --- a/script/Deploy.s.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.25; - -import { Script } from "forge-std/Script.sol"; -import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol"; -import { EmailRecoveryManager } from "src/EmailRecoveryManager.sol"; -import { UniversalEmailRecoveryModule } from "src/modules/UniversalEmailRecoveryModule.sol"; - -contract DeployScript is Script { - function run() public { - bytes32 salt = bytes32(uint256(0)); - - address verifier = 0xEdC642bbaD91E21cCE6cd436Fdc6F040FD0fF998; - address dkimRegistry = 0xC83256CCf7B94d310e49edA05077899ca036eb78; - address emailAuthImpl = 0x1C76Aa365c17B40c7E944DcCdE4dC6e6D2A7b748; - - vm.startBroadcast(vm.envUint("PRIVATE_KEY")); - - EmailRecoverySubjectHandler emailRecoveryHandler = new EmailRecoverySubjectHandler(); - - EmailRecoveryManager emailRecoveryManager = new EmailRecoveryManager{ salt: salt }( - verifier, dkimRegistry, emailAuthImpl, address(emailRecoveryHandler) - ); - - new UniversalEmailRecoveryModule(address(emailRecoveryManager)); - - vm.stopBroadcast(); - } -} diff --git a/script/Deploy7579Controller.s.sol b/script/Deploy7579Controller.s.sol index 0177e65c..86e19ac4 100644 --- a/script/Deploy7579Controller.s.sol +++ b/script/Deploy7579Controller.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.25; import { Script } from "forge-std/Script.sol"; import { console } from "forge-std/console.sol"; import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol"; -import { EmailRecoveryManager } from "src/EmailRecoveryManager.sol"; import { Verifier } from "ether-email-auth/packages/contracts/src/utils/Verifier.sol"; import { ECDSAOwnedDKIMRegistry } from "ether-email-auth/packages/contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; @@ -21,32 +20,25 @@ contract Deploy7579ControllerScript is Script { if (verifier == address(0)) { verifier = address(new Verifier()); - // vm.setEnv("VERIFIER", vm.toString(verifier)); console.log("Deployed Verifier at", verifier); } if (dkimRegistry == address(0)) { require(dkimRegistrySigner != address(0), "DKIM_REGISTRY_SIGNER is required"); dkimRegistry = address(new ECDSAOwnedDKIMRegistry(dkimRegistrySigner)); - // vm.setEnv("DKIM_REGISTRY", vm.toString(dkimRegistry)); console.log("Deployed DKIM Registry at", dkimRegistry); } if (emailAuthImpl == address(0)) { emailAuthImpl = address(new EmailAuth()); - // vm.setEnv("EMAIL_AUTH_IMPL", vm.toString(emailAuthImpl)); console.log("Deployed Email Auth at", emailAuthImpl); } EmailRecoverySubjectHandler emailRecoveryHandler = new EmailRecoverySubjectHandler(); - // vm.setEnv( - // "RECOVERY_HANDLER", - // vm.toString(address(emailRecoveryHandler)) - // ); + address _factory = vm.envOr("RECOVERY_FACTORY", address(0)); if (_factory == address(0)) { _factory = address(new EmailRecoveryFactory(verifier, emailAuthImpl)); - // vm.setEnv("RECOVERY_FACTORY", vm.toString(_factory)); console.log("Deployed Email Recovery Factory at", _factory); } { @@ -59,8 +51,6 @@ contract Deploy7579ControllerScript is Script { type(EmailRecoverySubjectHandler).creationCode, dkimRegistry ); - // vm.setEnv("RECOVERY_MANAGER", vm.toString(manager)); - // vm.setEnv("RECOVERY_MODULE", vm.toString(module)); console.log("Deployed Email Recovery Handler at", vm.toString(subjectHandler)); console.log("Deployed Email Recovery Manager at", vm.toString(manager)); diff --git a/script/Deploy7579TestAccount.s.sol b/script/Deploy7579TestAccount.s.sol index ca1217de..0feacd9a 100644 --- a/script/Deploy7579TestAccount.s.sol +++ b/script/Deploy7579TestAccount.s.sol @@ -6,7 +6,7 @@ import { console } from "forge-std/console.sol"; import { EmailAccountRecovery } from "ether-email-auth/packages/contracts/src/EmailAccountRecovery.sol"; import { IEmailRecoveryManager } from "../src/interfaces/IEmailRecoveryManager.sol"; -import { RhinestoneModuleKit, AccountInstance } from "modulekit/ModuleKit.sol"; +import { RhinestoneModuleKit } from "modulekit/ModuleKit.sol"; import { OwnableValidator } from "src/test/OwnableValidator.sol"; import { ModuleKitHelpers, ModuleKitUserOp } from "modulekit/ModuleKit.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; @@ -48,7 +48,7 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script { PackedUserOperation userOp; bytes32 userOpHash; - bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address,address,address)"))); + bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address)"))); function run() public { privKey = vm.envUint("PRIVATE_KEY"); @@ -114,11 +114,7 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script { BootstrapConfig[] memory executors = new BootstrapConfig[](1); managerAddr = vm.envAddress("RECOVERY_MANAGER"); require(managerAddr != address(0), "RECOVERY_MANAGER is required"); - // address guardianAddr = EmailAccountRecovery(managerAddr) - // .computeEmailAuthAddress(account, accountSalt); - // console.log("Guardian's EmailAuth address", guardianAddr); - // guardians[0] = guardianAddr; - // guardianWeights[0] = 1; + bytes memory recoveryModuleInstallData = abi.encode( validatorAddr, bytes("0"), @@ -226,59 +222,11 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script { IEntryPoint(ENTRYPOINT_ADDR).handleOps{ gas: 3e6 }(userOps, payable(deployer)); console.log("changeThreshold UserOps are executed"); - // AccountInstance memory instance = makeAccountInstance(accountSalt); - - // instance.installModule({ - // moduleTypeId: MODULE_TYPE_VALIDATOR, - // module: validatorAddress, - // data: abi.encode( - // vm.envOr("OWNER", deployer), - // vm.envAddress("RECOVERY_MODULE") - // ) - // }); - - // bytes4 functionSelector = bytes4( - // keccak256(bytes("changeOwner(address,address,address)")) - // ); - // managerAddr = vm.envAddress("RECOVERY_MANAGER"); - // require(managerAddr != address(0), "RECOVERY_MANAGER is required"); - - // address guardianAddr = EmailAccountRecovery(managerAddr) - // .computeEmailAuthAddress(instance.account, accountSalt); - // console.log("Guardian's EmailAuth address", guardianAddr); - // address[] memory guardians = new address[](1); - // guardians[0] = guardianAddr; - // uint256[] memory guardianWeights = new uint256[](1); - // guardianWeights[0] = 1; - // uint threshold = 1; - // bytes memory recoveryModuleInstallData = abi.encode( - // validatorAddress, - // bytes("0"), - // functionSelector, - // guardians, - // guardianWeights, - // threshold, - // 1 seconds, - // 2 weeks - // ); - // instance.installModule({ - // moduleTypeId: MODULE_TYPE_EXECUTOR, - // module: vm.envAddress("RECOVERY_MODULE"), - // data: recoveryModuleInstallData - // }); vm.stopBroadcast(); } function getNonce(address account, address validator) internal returns (uint256 nonce) { uint192 key = uint192(bytes24(bytes20(address(validator)))); - // console.log("shifted key", uint256(key) << 64); - // console.log( - // "raw nonce", - // NonceManager(ENTRYPOINT_ADDR).nonceSequenceNumber( - // address(account), - // key - // ) - // ); nonce = IEntryPoint(ENTRYPOINT_ADDR).getNonce(address(account), key); } } From 65d06457ab8d24a11952133cb3699d76347e3986 Mon Sep 17 00:00:00 2001 From: JohnGuilding Date: Tue, 2 Jul 2024 17:38:40 +0200 Subject: [PATCH 3/3] Add deploy script for non-universal recovery module --- script/Deploy7579TestAccount.s.sol | 1 - script/DeployEmailRecoveryModule.s.sol | 70 +++++++++++++++++++ ... DeployUniversalEmailRecoveryModule.s.sol} | 6 +- 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 script/DeployEmailRecoveryModule.s.sol rename script/{Deploy7579Controller.s.sol => DeployUniversalEmailRecoveryModule.s.sol} (97%) diff --git a/script/Deploy7579TestAccount.s.sol b/script/Deploy7579TestAccount.s.sol index 0feacd9a..a5d7941f 100644 --- a/script/Deploy7579TestAccount.s.sol +++ b/script/Deploy7579TestAccount.s.sol @@ -96,7 +96,6 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script { validatorAddr = vm.envOr("VALIDATOR", address(0)); if (validatorAddr == address(0)) { validatorAddr = address(new OwnableValidator()); - // vm.setEnv("VALIDATOR", vm.toString(validatorAddress)); console.log("Deployed Ownable Validator at", validatorAddr); } OwnableValidator validator = OwnableValidator(validatorAddr); diff --git a/script/DeployEmailRecoveryModule.s.sol b/script/DeployEmailRecoveryModule.s.sol new file mode 100644 index 00000000..259d5fd0 --- /dev/null +++ b/script/DeployEmailRecoveryModule.s.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { Script } from "forge-std/Script.sol"; +import { console } from "forge-std/console.sol"; +import { EmailRecoverySubjectHandler } from "src/handlers/EmailRecoverySubjectHandler.sol"; +import { Verifier } from "ether-email-auth/packages/contracts/src/utils/Verifier.sol"; +import { ECDSAOwnedDKIMRegistry } from + "ether-email-auth/packages/contracts/src/utils/ECDSAOwnedDKIMRegistry.sol"; +import { EmailAuth } from "ether-email-auth/packages/contracts/src/EmailAuth.sol"; +import { EmailRecoveryFactory } from "src/EmailRecoveryFactory.sol"; +import { OwnableValidator } from "src/test/OwnableValidator.sol"; + +contract DeployEmailRecoveryModuleScript is Script { + function run() public { + vm.startBroadcast(vm.envUint("PRIVATE_KEY")); + address verifier = vm.envOr("VERIFIER", address(0)); + address dkimRegistry = vm.envOr("DKIM_REGISTRY", address(0)); + address dkimRegistrySigner = vm.envOr("SIGNER", address(0)); + address emailAuthImpl = vm.envOr("EMAIL_AUTH_IMPL", address(0)); + address validatorAddr = vm.envOr("VALIDATOR", address(0)); + + if (verifier == address(0)) { + verifier = address(new Verifier()); + console.log("Deployed Verifier at", verifier); + } + + if (dkimRegistry == address(0)) { + require(dkimRegistrySigner != address(0), "DKIM_REGISTRY_SIGNER is required"); + dkimRegistry = address(new ECDSAOwnedDKIMRegistry(dkimRegistrySigner)); + console.log("Deployed DKIM Registry at", dkimRegistry); + } + + if (emailAuthImpl == address(0)) { + emailAuthImpl = address(new EmailAuth()); + console.log("Deployed Email Auth at", emailAuthImpl); + } + + if (validatorAddr == address(0)) { + validatorAddr = address(new OwnableValidator()); + console.log("Deployed Ownable Validator at", validatorAddr); + } + + EmailRecoverySubjectHandler emailRecoveryHandler = new EmailRecoverySubjectHandler(); + + address _factory = vm.envOr("RECOVERY_FACTORY", address(0)); + if (_factory == address(0)) { + _factory = address(new EmailRecoveryFactory(verifier, emailAuthImpl)); + console.log("Deployed Email Recovery Factory at", _factory); + } + { + EmailRecoveryFactory factory = EmailRecoveryFactory(_factory); + (address module, address manager, address subjectHandler) = factory + .deployEmailRecoveryModule( + bytes32(uint256(0)), + bytes32(uint256(0)), + bytes32(uint256(0)), + type(EmailRecoverySubjectHandler).creationCode, + dkimRegistry, + validatorAddr, + bytes4(keccak256(bytes("changeOwner(address)"))) + ); + + console.log("Deployed Email Recovery Module at", vm.toString(module)); + console.log("Deployed Email Recovery Manager at", vm.toString(manager)); + console.log("Deployed Email Recovery Handler at", vm.toString(subjectHandler)); + vm.stopBroadcast(); + } + } +} diff --git a/script/Deploy7579Controller.s.sol b/script/DeployUniversalEmailRecoveryModule.s.sol similarity index 97% rename from script/Deploy7579Controller.s.sol rename to script/DeployUniversalEmailRecoveryModule.s.sol index 86e19ac4..2d4853e5 100644 --- a/script/Deploy7579Controller.s.sol +++ b/script/DeployUniversalEmailRecoveryModule.s.sol @@ -10,7 +10,7 @@ import { ECDSAOwnedDKIMRegistry } from import { EmailAuth } from "ether-email-auth/packages/contracts/src/EmailAuth.sol"; import { EmailRecoveryFactory } from "src/EmailRecoveryFactory.sol"; -contract Deploy7579ControllerScript is Script { +contract DeployUniversalEmailRecoveryModuleScript is Script { function run() public { vm.startBroadcast(vm.envUint("PRIVATE_KEY")); address verifier = vm.envOr("VERIFIER", address(0)); @@ -52,9 +52,9 @@ contract Deploy7579ControllerScript is Script { dkimRegistry ); - console.log("Deployed Email Recovery Handler at", vm.toString(subjectHandler)); - console.log("Deployed Email Recovery Manager at", vm.toString(manager)); console.log("Deployed Email Recovery Module at", vm.toString(module)); + console.log("Deployed Email Recovery Manager at", vm.toString(manager)); + console.log("Deployed Email Recovery Handler at", vm.toString(subjectHandler)); vm.stopBroadcast(); } }