Skip to content

Commit 5c1e50e

Browse files
authored
Feature: add zksync support to v1.5.0 (#742)
**This PR:** - Implements #766 by adding the zksync support for deployment and testing contracts - It is based on #651. However, Matter Labs has published many updates in the meantime, so there are many changes - Add zksync tests to the CI **Importants changes** - The zksync team did a great job of adding a lot of interoperability features with hardhat's environment ethers object, however, there are certain features we rely on that require zksync-specific adjustments, such as compiling code from string, contract deployment, create2 address calculation. Functions specific to that had to be adjusted - we had incorrect test assumptions: for example, we assumed that `hre.ethers.getContractAt` would always return a contract instance connected to the first account returned from `hre.ethers.getSigners`. This didn't hold in zksync environment as they use the 9th account **Notes** - This PR doesn't include changes to Safe Migration contract tests for zksync, as we decided to merge this first and add the support to 1.4.1 and fix the migration contracts there, then cherry-pick it back to 1.5.0 **Proof of deployment:** ``` > hardhat deploy-contracts --network zkSyncSepolia Yul codegen is only supported for solc >= 0.8. Flag forceEVMLA will automatically be set to true by default. Yul codegen is only supported for solc >= 0.8. Flag forceEVMLA will automatically be set to true by default. The zksolc compiler version in your Hardhat config file (1.5.2) is not the latest. We recommend using the latest version 1.5.3. Nothing to compile No need to generate any newer typings. reusing "SimulateTxAccessor" at 0x1aaa95173dAA2F9B18df1277485CAd842Bb5EeFe reusing "SafeProxyFactory" at 0x9c8588F1Cfbf54845c06C6924E90b20AB0912B6F reusing "TokenCallbackHandler" at 0x94AA81a0E2e857A0e5978b7E4218DdAE2d611bCf reusing "CompatibilityFallbackHandler" at 0x7e940bC046e2a069F67e40f00A9d5749Abf59f70 reusing "CreateCall" at 0xded498F0eEEAe67E2E339a42e5c926335fDDCcf7 reusing "MultiSend" at 0xE25a6DFf1cbD91d195D87ECb90C96517fc98F581 reusing "MultiSendCallOnly" at 0x0E5006a4179dF454031800eC575F413c83d7B025 reusing "SignMessageLib" at 0x97273487793848a571054bf3a5FDc9c0982648B9 reusing "Safe" at 0xB23798CfB614f3A1a6d0820c08e004922475CD76 reusing "SafeL2" at 0x0ED239feb23632cE272A0AE5f8bfd843377897DF reusing "SafeToL2Migration" at 0x4c81Ce72dD304E27739A5607f0Ba7207eD415360 reusing "SafeMigration" at 0x80dd94053ED6075992771A2Df501eFF101fBc281 Verification status for CompatibilityFallbackHandler: SUCCESS Verification status for CreateCall: SUCCESS Verification status for MultiSend: SUCCESS Verification status for MultiSendCallOnly: SUCCESS Verification status for Safe: SUCCESS Verification status for SafeL2: SUCCESS Verification status for SafeMigration: SUCCESS Verification status for SafeProxyFactory: SUCCESS Verification status for SafeToL2Migration: SUCCESS Verification status for SignMessageLib: SUCCESS Verification status for SimulateTxAccessor: SUCCESS Verification status for TokenCallbackHandler: SUCCESS Running zk verification on block explorer Verifying CompatibilityFallbackHandler at 0x7e940bC046e2a069F67e40f00A9d5749Abf59f70... Your verification ID is: 23855 Contract successfully verified on ZKsync block explorer! Verifying CreateCall at 0xded498F0eEEAe67E2E339a42e5c926335fDDCcf7... Your verification ID is: 23856 Contract successfully verified on ZKsync block explorer! Verifying MultiSend at 0xE25a6DFf1cbD91d195D87ECb90C96517fc98F581... Your verification ID is: 23857 Contract successfully verified on ZKsync block explorer! Verifying MultiSendCallOnly at 0x0E5006a4179dF454031800eC575F413c83d7B025... Your verification ID is: 23858 Contract successfully verified on ZKsync block explorer! Verifying Safe at 0xB23798CfB614f3A1a6d0820c08e004922475CD76... Your verification ID is: 23859 Contract successfully verified on ZKsync block explorer! Verifying SafeL2 at 0x0ED239feb23632cE272A0AE5f8bfd843377897DF... Your verification ID is: 23860 Contract successfully verified on ZKsync block explorer! Verifying SafeMigration at 0x80dd94053ED6075992771A2Df501eFF101fBc281... Your verification ID is: 23861 Contract successfully verified on ZKsync block explorer! Verifying SafeProxyFactory at 0x9c8588F1Cfbf54845c06C6924E90b20AB0912B6F... Your verification ID is: 23862 Contract successfully verified on ZKsync block explorer! Verifying SafeToL2Migration at 0x4c81Ce72dD304E27739A5607f0Ba7207eD415360... Your verification ID is: 23863 Contract successfully verified on ZKsync block explorer! Verifying SignMessageLib at 0x97273487793848a571054bf3a5FDc9c0982648B9... Your verification ID is: 23864 Contract successfully verified on ZKsync block explorer! Verifying SimulateTxAccessor at 0x1aaa95173dAA2F9B18df1277485CAd842Bb5EeFe... Your verification ID is: 23865 Contract successfully verified on ZKsync block explorer! Verifying TokenCallbackHandler at 0x94AA81a0E2e857A0e5978b7E4218DdAE2d611bCf... Your verification ID is: 23866 Contract successfully verified on ZKsync block explorer! Execution time: 51.41s ```
1 parent c266ffc commit 5c1e50e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3622
-1036
lines changed

.env.sample

+4
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ SAFE_CONTRACT_UNDER_TEST="Safe"
1515
SOLIDITY_VERSION= # Example: '0.8.19'
1616
# For running coverage tests, `details` section of solidity settings are required, else could be removed.
1717
SOLIDITY_SETTINGS= # Example: '{"viaIR":true,"optimizer":{"enabled":true, "details": {"yul": true, "yulDetails": { "optimizerSteps": ""}}}}'
18+
# Set to 1 to run hardhat in zksync mode. This will enable the ZK compiler and run the hardhat node in zksync mode.
19+
HARDHAT_ENABLE_ZKSYNC=0
1820
# Sets hardhat chain id. In general, you don't need this, it's only used for testing the SafeToL2Setup contract.
1921
HARDHAT_CHAIN_ID=31337
22+
# (Optional) Hardhat-deploy only supports zksync deployment if the private key for the account is provided. Specify the private key here.
23+
ZKSYNC_DEPLOYER_PK="0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
cache: "npm"
2727
- run: npm ci
2828
- run: npm run lint:ts:prettier
29+
- run: npm run build:ts:dev # runs typecheck
2930
- run: npm run lint:ts
3031

3132
tests:

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea/
12
build/
23
node_modules/
34
.DS_Store
@@ -18,4 +19,7 @@ typechain-types
1819
# Certora Formal Verification related files
1920
.certora_internal
2021
.certora_recent_jobs.json
21-
.zip-output-url.txt
22+
.zip-output-url.txt
23+
24+
# zksync era node log
25+
era_test_node.log

.husky/pre-commit

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
npm run lint:sol:prettier
52
npm run lint:ts:prettier
63
npm run lint:sol

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This will deploy the contracts deterministically and verify the contracts on eth
5555
Preparation:
5656
- Set `MNEMONIC` in `.env`
5757
- Set `INFURA_KEY` in `.env`
58+
- For zkSync, set `ZKSYNC_DEPLOYER_PK` in `.env`
5859

5960
```bash
6061
npm run deploy-all <network>

hardhat.config.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import "@nomicfoundation/hardhat-toolbox";
22
import type { HardhatUserConfig, HttpNetworkUserConfig } from "hardhat/types";
3+
import "@matterlabs/hardhat-zksync-deploy";
4+
import "@matterlabs/hardhat-zksync-solc";
5+
import "@matterlabs/hardhat-zksync-verify";
6+
import "@matterlabs/hardhat-zksync-ethers";
7+
import "@matterlabs/hardhat-zksync-node";
38
import "hardhat-deploy";
49
import dotenv from "dotenv";
510
import yargs from "yargs";
@@ -16,7 +21,17 @@ const argv = yargs
1621

1722
// Load environment variables.
1823
dotenv.config();
19-
const { NODE_URL, INFURA_KEY, MNEMONIC, ETHERSCAN_API_KEY, PK, SOLIDITY_VERSION, SOLIDITY_SETTINGS, HARDHAT_CHAIN_ID } = process.env;
24+
const {
25+
NODE_URL,
26+
INFURA_KEY,
27+
MNEMONIC,
28+
ETHERSCAN_API_KEY,
29+
PK,
30+
SOLIDITY_VERSION,
31+
SOLIDITY_SETTINGS,
32+
HARDHAT_ENABLE_ZKSYNC = "0",
33+
HARDHAT_CHAIN_ID = 31337,
34+
} = process.env;
2035

2136
const DEFAULT_MNEMONIC = "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
2237

@@ -73,11 +88,16 @@ const userConfig: HardhatUserConfig = {
7388
solidity: {
7489
compilers: [{ version: primarySolidityVersion, settings: soliditySettings }, { version: defaultSolidityVersion }],
7590
},
91+
zksolc: {
92+
version: "1.5.3",
93+
settings: {},
94+
},
7695
networks: {
7796
hardhat: {
7897
allowUnlimitedContractSize: true,
7998
blockGasLimit: 100000000,
8099
gas: 100000000,
100+
zksync: HARDHAT_ENABLE_ZKSYNC === "1",
81101
chainId: typeof HARDHAT_CHAIN_ID === "string" && !Number.isNaN(parseInt(HARDHAT_CHAIN_ID)) ? parseInt(HARDHAT_CHAIN_ID) : 31337,
82102
},
83103
mainnet: {
@@ -116,6 +136,20 @@ const userConfig: HardhatUserConfig = {
116136
...sharedNetworkConfig,
117137
url: `https://api.avax.network/ext/bc/C/rpc`,
118138
},
139+
zkSyncMainnet: {
140+
...sharedNetworkConfig,
141+
url: "https://mainnet.era.zksync.io",
142+
ethNetwork: "mainnet",
143+
zksync: true,
144+
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
145+
},
146+
zkSyncSepolia: {
147+
...sharedNetworkConfig,
148+
url: "https://sepolia.era.zksync.dev",
149+
ethNetwork: "goerli",
150+
zksync: true,
151+
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
152+
},
119153
},
120154
deterministicDeployment,
121155
namedAccounts: {

0 commit comments

Comments
 (0)