Skip to content

Commit

Permalink
Fix EmailRecoveryManagerZkSync
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Sep 12, 2024
1 parent d2166a2 commit c58db22
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/email-recovery",
"version": "0.0.3",
"version": "0.0.4",
"description": "Smart account module and related contracts to enable email recovery for validators",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -29,7 +29,7 @@
"@openzeppelin/contracts-upgradeable": "5.0.1",
"@rhinestone/modulekit": "github:rhinestonewtf/modulekit",
"@zk-email/contracts": "6.0.3",
"@zk-email/ether-email-auth-contracts": "0.0.1-preview",
"@zk-email/ether-email-auth-contracts": "0.0.2-preview",
"email-wallet-sdk": "github:zkemail/email-wallet-sdk",
"erc7579-implementation": "github:erc7579/erc7579-implementation",
"solidity-stringutils": "github:Arachnid/solidity-stringutils"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 81 additions & 1 deletion src/EmailRecoveryManagerZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,91 @@
pragma solidity ^0.8.25;

import { EmailRecoveryManager } from "./EmailRecoveryManager.sol";
import { EmailAccountRecovery } from "ether-email-auth/src/EmailAccountRecovery.sol";
import { EmailAccountRecoveryZKSync } from "ether-email-auth/src/EmailAccountRecoveryZKSync.sol";

/**
* @title EmailRecoveryManagerZkSync
* @notice Provides a mechanism for account recovery using email guardians on ZKSync networks.
* @dev The underlying EmailAccountRecoveryZkSync contract provides some base logic for deploying
* guardian contracts and handling email verification.
*/
abstract contract EmailRecoveryManagerZkSync is EmailRecoveryManager { }
abstract contract EmailRecoveryManagerZkSync is EmailRecoveryManager, EmailAccountRecoveryZKSync {
constructor(
address _verifier,
address _dkimRegistry,
address _emailAuthImpl,
address _commandHandler,
address _factoryAddr
) {
if (_verifier == address(0)) {
revert InvalidVerifier();
}
if (_dkimRegistry == address(0)) {
revert InvalidDkimRegistry();
}
if (_emailAuthImpl == address(0)) {
revert InvalidEmailAuthImpl();
}
if (_commandHandler == address(0)) {
revert InvalidCommandHandler();
}
if (_factoryAddr == address(0)) {
revert InvalidFactory();
}
verifierAddr = _verifier;
dkimAddr = _dkimRegistry;
emailAuthImplementationAddr = _emailAuthImpl;
commandHandler = _commandHandler;
factoryAddr = _factoryAddr;
}

/// @notice Computes the address for email auth contract using the CREATE2 opcode.
/// @dev This function utilizes the `ZKSyncCreate2Factory` to compute the address. The
/// computation uses a provided account address to be recovered, account salt,
/// and the hash of the encoded ERC1967Proxy creation code concatenated with the encoded email
/// auth contract implementation
/// address and the initialization call data. This ensures that the computed address is
/// deterministic and unique per account salt.
/// @param recoveredAccount The address of the account to be recovered.
/// @param accountSalt A bytes32 salt value defined as a hash of the guardian's email address
/// and an account code. This is assumed to be unique to a pair of the guardian's email address
/// and the wallet address to be recovered.
/// @return address The computed address.
function computeEmailAuthAddress(
address recoveredAccount,
bytes32 accountSalt
)
public
view
virtual
override(EmailAccountRecovery, EmailAccountRecoveryZKSync)
returns (address)
{
return EmailAccountRecoveryZKSync.computeEmailAuthAddress(recoveredAccount, accountSalt);
}

/// @notice Deploys a proxy contract for email authentication using the CREATE2 opcode.
/// @dev This function utilizes the `ZKSyncCreate2Factory` to deploy the proxy contract. The
/// deployment uses a provided account address to be recovered, account salt,
/// and the hash of the encoded ERC1967Proxy creation code concatenated with the encoded email
/// auth contract implementation
/// address and the initialization call data. This ensures that the deployed address is
/// deterministic and unique per account salt.
/// @param recoveredAccount The address of the account to be recovered.
/// @param accountSalt A bytes32 salt value defined as a hash of the guardian's email address
/// and an account code. This is assumed to be unique to a pair of the guardian's email address
/// and the wallet address to be recovered.
/// @return address The address of the deployed proxy contract.
function deployEmailAuthProxy(
address recoveredAccount,
bytes32 accountSalt
)
internal
virtual
override(EmailAccountRecovery, EmailAccountRecoveryZKSync)
returns (address)
{
return EmailAccountRecoveryZKSync.deployEmailAuthProxy(recoveredAccount, accountSalt);
}
}
1 change: 1 addition & 0 deletions src/interfaces/IEmailRecoveryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface IEmailRecoveryManager {
error InvalidDkimRegistry();
error InvalidEmailAuthImpl();
error InvalidCommandHandler();
error InvalidFactory();
error SetupAlreadyCalled();
error AccountNotConfigured();
error DelayMoreThanExpiry(uint256 delay, uint256 expiry);
Expand Down
1 change: 1 addition & 0 deletions test/unit/assertErrorSelectors.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ contract LogErrorSelectors_Test is Test {
assertEq(IEmailRecoveryManager.InvalidDkimRegistry.selector, bytes4(0x260ce05b));
assertEq(IEmailRecoveryManager.InvalidEmailAuthImpl.selector, bytes4(0xe98100fb));
assertEq(IEmailRecoveryManager.InvalidCommandHandler.selector, bytes4(0xfce1ed6f));
assertEq(IEmailRecoveryManager.InvalidFactory.selector, bytes4(0x7a44db95));
assertEq(IEmailRecoveryManager.SetupAlreadyCalled.selector, bytes4(0xb3af5593));
assertEq(IEmailRecoveryManager.AccountNotConfigured.selector, bytes4(0x66ecbd6d));
assertEq(IEmailRecoveryManager.DelayMoreThanExpiry.selector, bytes4(0xb742a43c));
Expand Down

0 comments on commit c58db22

Please sign in to comment.