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

Feature/update deployment logic using factory #52

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0177f5e
Add ZKSyncCreate2Factory, EmailAccountRecovery test casees split by f…
wshino Aug 28, 2024
68c5399
Failed: update integration testing with foundry-zksync.
wshino Aug 28, 2024
e50c303
Update integration testing command with foundry-zksync.
wshino Aug 28, 2024
6ea336e
Failed: update integration testing with foundry.
wshino Aug 28, 2024
39b43a0
Add DeployEmailAuthWithCreate2.s.sol.
wshino Aug 30, 2024
7427a96
Merge commit '39b43a055ace204bfd3450496a87ca5ba363e61e' into feature/…
wshino Aug 30, 2024
7b0235f
Disable DeployEmailAuthWIthCreate2.s.sol.
wshino Aug 30, 2024
2769102
Merge branch 'feat/audit-fix-2024-08' into feature/update-deployment-…
wshino Sep 9, 2024
2fb6e3e
Fix integration test for foundry
wshino Sep 9, 2024
68119bc
Fail: integration testing for foundry zksync.
wshino Sep 9, 2024
9f6b16d
Fix integration testing for foundry zksync
wshino Sep 9, 2024
e7255a3
Tweak README.md
wshino Sep 9, 2024
fd6b30f
Add EmailAccountRecoveryZkSync
wshino Sep 10, 2024
cc8e115
Uncomment some contracts which are used for foundry zksync
wshino Sep 10, 2024
e2640ec
make deployEmailAuthProxy as internal function
wshino Sep 10, 2024
564bb55
Update yarn build, yarn test
wshino Sep 10, 2024
a36cf98
Remove specific foundry version
wshino Sep 10, 2024
6857cfa
Update foundry version
wshino Sep 10, 2024
5a0c283
chore: git rm --cached
wshino Sep 10, 2024
e0e1b53
chore: Update after git rm --cached
wshino Sep 10, 2024
39905c2
chore: git rm --cached
wshino Sep 10, 2024
3a61642
chore: Update after git rm --cached
wshino Sep 10, 2024
618ed4f
Fix build-test-fmt on github action
wshino Sep 10, 2024
14f0626
Rename DeployEmailAuthWIthCreate2
wshino Sep 10, 2024
0069604
Update deployment files in docs
wshino Sep 10, 2024
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
19 changes: 13 additions & 6 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,22 @@ Next, you should uncomment the following lines in `foundry.toml`.
# via-ir = true
```

And then you should uncomment the commented imports and functions in `src/utils/ZKSyncCreate2Factory.sol`
Uncomment the following commented-out files.
These are commented out in the files for ZkSync to avoid problems when testing in foundry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid commenting out those zksync files by adding an option to the command of yarn build that excludes zksync files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoraSuegami Maybe we can use --skip flag, let me try it.


Also uncomment the following lines in `src/EmailAccountRecovery.sol` too.
The following are entire files that are commented out

- L7 import `ZKSyncCreate2Factory`
- L133 - L143 in `computeEmailAuthAddress` function
- L232 - L253 in `handleAcceptance` function
- script/DeployRecoveryControllerZkSync.s.sol
- src/EmailAccountRecoveryZkSync.sol
- test/IntegrationZkSync.t.sol
- test/EmailAccountRecoveryZkSync/EmailAccountRecoveryZkSync_*.t.sol
- test/helpers/RecoveryControllerZkSync.sol
- test/ComputeCreate2Address.t.sol

Regarding test cases, you should uncomment `test/ComputeCreate2Address.t.sol`
Partial comment-out files can be found the following. Search `FOR_ZKSYNC:START` and `FOR_ZKSYNC:END`.

- src/utils/ZKSyncCreate2Factory.sol
- test/helpers/DeploymentHelper.sol

At the first forge build, you need to detect the missing libraries.

Expand Down
306 changes: 153 additions & 153 deletions packages/contracts/script/DeployRecoveryControllerZkSync.s.sol
Original file line number Diff line number Diff line change
@@ -1,164 +1,164 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// // SPDX-License-Identifier: UNLICENSED
// pragma solidity ^0.8.13;

import "forge-std/Script.sol";
// import "forge-std/Script.sol";

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "../test/helpers/SimpleWallet.sol";
import "../test/helpers/RecoveryControllerZkSync.sol";
import "../src/utils/Verifier.sol";
import "../src/utils/ECDSAOwnedDKIMRegistry.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";
// import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
// import "../test/helpers/SimpleWallet.sol";
// import "../test/helpers/RecoveryControllerZkSync.sol";
// import "../src/utils/Verifier.sol";
// import "../src/utils/ECDSAOwnedDKIMRegistry.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";

contract Deploy is Script {
using ECDSA for *;
// contract Deploy is Script {
// using ECDSA for *;

ECDSAOwnedDKIMRegistry dkim;
Verifier verifier;
EmailAuth emailAuthImpl;
SimpleWallet simpleWallet;
RecoveryControllerZkSync recoveryControllerZkSync;
ZKSyncCreate2Factory factoryImpl;
// ECDSAOwnedDKIMRegistry dkim;
// Verifier verifier;
// EmailAuth emailAuthImpl;
// SimpleWallet simpleWallet;
// RecoveryControllerZkSync recoveryControllerZkSync;
// ZKSyncCreate2Factory factoryImpl;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}
address signer = vm.envAddress("SIGNER");
if (signer == address(0)) {
console.log("SIGNER env var not set");
return;
}
// function run() external {
// uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
// if (deployerPrivateKey == 0) {
// console.log("PRIVATE_KEY env var not set");
// return;
// }
// address signer = vm.envAddress("SIGNER");
// if (signer == address(0)) {
// console.log("SIGNER env var not set");
// return;
// }

vm.startBroadcast(deployerPrivateKey);
address initialOwner = msg.sender;
// vm.startBroadcast(deployerPrivateKey);
// address initialOwner = msg.sender;

// Deploy ECDSAOwned DKIM registry
dkim = ECDSAOwnedDKIMRegistry(vm.envOr("ECDSA_DKIM", address(0)));
if (address(dkim) == address(0)) {
ECDSAOwnedDKIMRegistry ecdsaDkimImpl = new ECDSAOwnedDKIMRegistry();
console.log(
"ECDSAOwnedDKIMRegistry implementation deployed at: %s",
address(ecdsaDkimImpl)
);
ERC1967Proxy ecdsaDkimProxy = new ERC1967Proxy(
address(ecdsaDkimImpl),
abi.encodeCall(ecdsaDkimImpl.initialize, (initialOwner, signer))
);
dkim = ECDSAOwnedDKIMRegistry(address(ecdsaDkimProxy));
console.log(
"ECDSAOwnedDKIMRegistry deployed at: %s",
address(dkim)
);
vm.setEnv("ECDSA_DKIM", vm.toString(address(dkim)));
// dkimImpl = new ForwardDKIMRegistry();
// console.log(
// "ForwardDKIMRegistry implementation deployed at: %s",
// address(dkimImpl)
// );
// ERC1967Proxy dkimProxy = new ERC1967Proxy(
// address(dkimImpl),
// abi.encodeCall(dkimImpl.initialize, (initialOwner, signer))
// );
// dkim = ForwardDKIMRegistry(address(dkimProxy));
// console.log("ForwardDKIMRegistry deployed at: %s", address(dkim));
// vm.setEnv("DKIM", vm.toString(address(dkim)));
}
// Deploy Verifier
verifier = Verifier(vm.envOr("VERIFIER", address(0)));
if (address(verifier) == address(0)) {
Verifier verifierImpl = new Verifier();
console.log(
"Verifier implementation deployed at: %s",
address(verifierImpl)
);
ERC1967Proxy verifierProxy = new ERC1967Proxy(
address(verifierImpl),
abi.encodeCall(verifierImpl.initialize, (initialOwner))
);
verifier = Verifier(address(verifierProxy));
console.log("Verifier deployed at: %s", address(verifier));
vm.setEnv("VERIFIER", vm.toString(address(verifier)));
}
// // Deploy ECDSAOwned DKIM registry
// dkim = ECDSAOwnedDKIMRegistry(vm.envOr("ECDSA_DKIM", address(0)));
// if (address(dkim) == address(0)) {
// ECDSAOwnedDKIMRegistry ecdsaDkimImpl = new ECDSAOwnedDKIMRegistry();
// console.log(
// "ECDSAOwnedDKIMRegistry implementation deployed at: %s",
// address(ecdsaDkimImpl)
// );
// ERC1967Proxy ecdsaDkimProxy = new ERC1967Proxy(
// address(ecdsaDkimImpl),
// abi.encodeCall(ecdsaDkimImpl.initialize, (initialOwner, signer))
// );
// dkim = ECDSAOwnedDKIMRegistry(address(ecdsaDkimProxy));
// console.log(
// "ECDSAOwnedDKIMRegistry deployed at: %s",
// address(dkim)
// );
// vm.setEnv("ECDSA_DKIM", vm.toString(address(dkim)));
// // dkimImpl = new ForwardDKIMRegistry();
// // console.log(
// // "ForwardDKIMRegistry implementation deployed at: %s",
// // address(dkimImpl)
// // );
// // ERC1967Proxy dkimProxy = new ERC1967Proxy(
// // address(dkimImpl),
// // abi.encodeCall(dkimImpl.initialize, (initialOwner, signer))
// // );
// // dkim = ForwardDKIMRegistry(address(dkimProxy));
// // console.log("ForwardDKIMRegistry deployed at: %s", address(dkim));
// // vm.setEnv("DKIM", vm.toString(address(dkim)));
// }
// // Deploy Verifier
// verifier = Verifier(vm.envOr("VERIFIER", address(0)));
// if (address(verifier) == address(0)) {
// Verifier verifierImpl = new Verifier();
// console.log(
// "Verifier implementation deployed at: %s",
// address(verifierImpl)
// );
// ERC1967Proxy verifierProxy = new ERC1967Proxy(
// address(verifierImpl),
// abi.encodeCall(verifierImpl.initialize, (initialOwner))
// );
// verifier = Verifier(address(verifierProxy));
// console.log("Verifier deployed at: %s", address(verifier));
// vm.setEnv("VERIFIER", vm.toString(address(verifier)));
// }

// Deploy EmailAuth Implementation
emailAuthImpl = EmailAuth(vm.envOr("EMAIL_AUTH_IMPL", address(0)));
if (address(emailAuthImpl) == address(0)) {
emailAuthImpl = new EmailAuth();
console.log(
"EmailAuth implementation deployed at: %s",
address(emailAuthImpl)
);
vm.setEnv("EMAIL_AUTH_IMPL", vm.toString(address(emailAuthImpl)));
}
// // Deploy EmailAuth Implementation
// emailAuthImpl = EmailAuth(vm.envOr("EMAIL_AUTH_IMPL", address(0)));
// if (address(emailAuthImpl) == address(0)) {
// emailAuthImpl = new EmailAuth();
// console.log(
// "EmailAuth implementation deployed at: %s",
// address(emailAuthImpl)
// );
// vm.setEnv("EMAIL_AUTH_IMPL", vm.toString(address(emailAuthImpl)));
// }

// Deploy Factory
factoryImpl = ZKSyncCreate2Factory(vm.envOr("FACTORY", address(0)));
if (address(factoryImpl) == address(0)) {
factoryImpl = new ZKSyncCreate2Factory();
console.log(
"Factory implementation deployed at: %s",
address(factoryImpl)
);
vm.setEnv("FACTORY", vm.toString(address(factoryImpl)));
}
// // Deploy Factory
// factoryImpl = ZKSyncCreate2Factory(vm.envOr("FACTORY", address(0)));
// if (address(factoryImpl) == address(0)) {
// factoryImpl = new ZKSyncCreate2Factory();
// console.log(
// "Factory implementation deployed at: %s",
// address(factoryImpl)
// );
// vm.setEnv("FACTORY", vm.toString(address(factoryImpl)));
// }

// Create RecoveryControllerZkSync as EmailAccountRecovery implementation
{
RecoveryControllerZkSync recoveryControllerZkSyncImpl = new RecoveryControllerZkSync();
ERC1967Proxy recoveryControllerZkSyncProxy = new ERC1967Proxy(
address(recoveryControllerZkSyncImpl),
abi.encodeCall(
recoveryControllerZkSyncImpl.initialize,
(
signer,
address(verifier),
address(dkim),
address(emailAuthImpl),
address(factoryImpl)
)
)
);
recoveryControllerZkSync = RecoveryControllerZkSync(
payable(address(recoveryControllerZkSyncProxy))
);
console.log(
"RecoveryControllerZkSync deployed at: %s",
address(recoveryControllerZkSync)
);
vm.setEnv(
"RECOVERY_CONTROLLER_ZKSYNC",
vm.toString(address(recoveryControllerZkSync))
);
}
// // Create RecoveryControllerZkSync as EmailAccountRecovery implementation
// {
// RecoveryControllerZkSync recoveryControllerZkSyncImpl = new RecoveryControllerZkSync();
// ERC1967Proxy recoveryControllerZkSyncProxy = new ERC1967Proxy(
// address(recoveryControllerZkSyncImpl),
// abi.encodeCall(
// recoveryControllerZkSyncImpl.initialize,
// (
// signer,
// address(verifier),
// address(dkim),
// address(emailAuthImpl),
// address(factoryImpl)
// )
// )
// );
// recoveryControllerZkSync = RecoveryControllerZkSync(
// payable(address(recoveryControllerZkSyncProxy))
// );
// console.log(
// "RecoveryControllerZkSync deployed at: %s",
// address(recoveryControllerZkSync)
// );
// vm.setEnv(
// "RECOVERY_CONTROLLER_ZKSYNC",
// vm.toString(address(recoveryControllerZkSync))
// );
// }

// Deploy SimpleWallet Implementation
{
SimpleWallet simpleWalletImpl = new SimpleWallet();
console.log(
"SimpleWallet implementation deployed at: %s",
address(simpleWalletImpl)
);
vm.setEnv(
"SIMPLE_WALLET_IMPL",
vm.toString(address(simpleWalletImpl))
);
ERC1967Proxy simpleWalletProxy = new ERC1967Proxy(
address(simpleWalletImpl),
abi.encodeCall(
simpleWalletImpl.initialize,
(signer, address(recoveryControllerZkSync))
)
);
simpleWallet = SimpleWallet(payable(address(simpleWalletProxy)));
console.log("SimpleWallet deployed at: %s", address(simpleWallet));
vm.setEnv("SIMPLE_WALLET", vm.toString(address(simpleWallet)));
}
vm.stopBroadcast();
}
}
// // Deploy SimpleWallet Implementation
// {
// SimpleWallet simpleWalletImpl = new SimpleWallet();
// console.log(
// "SimpleWallet implementation deployed at: %s",
// address(simpleWalletImpl)
// );
// vm.setEnv(
// "SIMPLE_WALLET_IMPL",
// vm.toString(address(simpleWalletImpl))
// );
// ERC1967Proxy simpleWalletProxy = new ERC1967Proxy(
// address(simpleWalletImpl),
// abi.encodeCall(
// simpleWalletImpl.initialize,
// (signer, address(recoveryControllerZkSync))
// )
// );
// simpleWallet = SimpleWallet(payable(address(simpleWalletProxy)));
// console.log("SimpleWallet deployed at: %s", address(simpleWallet));
// vm.setEnv("SIMPLE_WALLET", vm.toString(address(simpleWallet)));
// }
// vm.stopBroadcast();
// }
// }
10 changes: 5 additions & 5 deletions packages/contracts/src/EmailAccountRecovery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract contract EmailAccountRecovery {
/// @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 computeProxyAddress(
function computeEmailAuthAddress(
address recoveredAccount,
bytes32 accountSalt
) public view virtual returns (address) {
Expand Down Expand Up @@ -141,7 +141,7 @@ abstract contract EmailAccountRecovery {
/// @param recoveredAccount The address of the account to be recovered.
/// @param accountSalt A bytes32 salt value used to ensure the uniqueness of the deployed proxy address.
/// @return address The address of the newly deployed proxy contract.
function deployProxy(
function deployEmailAuthProxy(
address recoveredAccount,
bytes32 accountSalt
) public virtual returns (address) {
Expand Down Expand Up @@ -207,7 +207,7 @@ abstract contract EmailAccountRecovery {
templateIdx
);
require(recoveredAccount != address(0), "invalid account in email");
address guardian = computeProxyAddress(
address guardian = computeEmailAuthAddress(
recoveredAccount,
emailAuthMsg.proof.accountSalt
);
Expand All @@ -217,7 +217,7 @@ abstract contract EmailAccountRecovery {

EmailAuth guardianEmailAuth;
if (guardian.code.length == 0) {
address proxyAddress = deployProxy(recoveredAccount, emailAuthMsg.proof.accountSalt);
address proxyAddress = deployEmailAuthProxy(recoveredAccount, emailAuthMsg.proof.accountSalt);
guardianEmailAuth = EmailAuth(proxyAddress);
guardianEmailAuth.initDKIMRegistry(dkim());
guardianEmailAuth.initVerifier(verifier());
Expand Down Expand Up @@ -270,7 +270,7 @@ abstract contract EmailAccountRecovery {
templateIdx
);
require(recoveredAccount != address(0), "invalid account in email");
address guardian = computeProxyAddress(
address guardian = computeEmailAuthAddress(
recoveredAccount,
emailAuthMsg.proof.accountSalt
);
Expand Down
Loading
Loading