Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/factory and script updates #17

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 5 additions & 72 deletions script/Compute7579CalldataHash.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
29 changes: 0 additions & 29 deletions script/Deploy.s.sol

This file was deleted.

59 changes: 3 additions & 56 deletions script/Deploy7579TestAccount.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -114,11 +113,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"),
Expand Down Expand Up @@ -226,59 +221,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);
}
}
70 changes: 70 additions & 0 deletions script/DeployEmailRecoveryModule.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ 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 Deploy7579ControllerScript is Script {
contract DeployUniversalEmailRecoveryModuleScript is Script {
function run() public {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
address verifier = vm.envOr("VERIFIER", address(0));
Expand All @@ -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, dkimRegistry, emailAuthImpl));
// vm.setEnv("RECOVERY_FACTORY", vm.toString(_factory));
_factory = address(new EmailRecoveryFactory(verifier, emailAuthImpl));
console.log("Deployed Email Recovery Factory at", _factory);
}
{
Expand All @@ -56,14 +48,13 @@ 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));

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();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/EmailRecoveryFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -26,6 +24,7 @@ contract EmailRecoveryFactory {
bytes32 recoveryManagerSalt,
bytes32 recoveryModuleSalt,
bytes memory subjectHandlerBytecode,
address dkimRegistry,
address validator,
bytes4 functionSelector
)
Expand Down Expand Up @@ -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)
Expand Down
Loading