1
1
import hre , { artifacts , ethers } from "hardhat" ;
2
2
import { Contract , ContractFactory , providers , utils , Wallet } from "ethers" ;
3
3
4
+ async function isContractDeployed (
5
+ contractAddress : string ,
6
+ provider : ethers . providers . Provider
7
+ ) : Promise < boolean > {
8
+ let isDeployed = false ;
9
+
10
+ try {
11
+ // Attempt to get the bytecode of the contract
12
+ const bytecode = await provider . getCode ( contractAddress ) ;
13
+
14
+ // If the bytecode is '0x', then the contract is not deployed
15
+ if ( bytecode !== "0x" ) {
16
+ isDeployed = true ;
17
+ }
18
+ } catch ( error ) {
19
+ // Log the error for debugging purposes
20
+ console . warn ( "Error fetching contract code:" , error ) ;
21
+ // Set isDeployed to false if there is an error
22
+ isDeployed = false ;
23
+ }
24
+
25
+ return isDeployed ;
26
+ }
27
+
4
28
async function main ( ) {
5
29
const netprovider = new providers . JsonRpcProvider ( process . env . L2_NODE_WEB3_URL )
6
30
const accPrivateKey = process . env . DEPLOYER_PRIVATE_KEY ?? ''
@@ -10,46 +34,88 @@ async function main() {
10
34
const numberOfMembers = process . env . NUMBER_OF_MEMBERS
11
35
const degree = process . env . DEGREE
12
36
const minDeposit = process . env . MIN_DEPOSIT ?? '0'
13
- const deployNoHelpers = process . env . DEPLOY_NO_HELPERS === 'true'
37
+ const deployPartial = process . env . DEPLOY_PARTIAL === 'true'
14
38
15
- let halo2VerifierAddress
16
39
let halo2VerifyingKeyAddress
40
+ let halo2VerifierAddress
17
41
let globalPublicParamsAddress
18
42
let pseudoRandAddress
19
43
20
- if ( deployNoHelpers ) {
21
- halo2VerifierAddress = process . env . HALO2V
44
+ if ( deployPartial ) {
45
+ // use contracts that are already deployed
46
+ // if any contract address is not provided, the contract will be re-deployed
22
47
halo2VerifyingKeyAddress = process . env . HALO2VK
48
+ halo2VerifierAddress = process . env . HALO2V
23
49
globalPublicParamsAddress = process . env . GPP
24
50
pseudoRandAddress = process . env . PSRAND
25
- } else {
51
+
52
+ // check if contracts are deployed; if not, the contracts will be re-deployed
53
+ if ( halo2VerifyingKeyAddress ) {
54
+ const isDeployed = await isContractDeployed ( halo2VerifyingKeyAddress , netprovider )
55
+ if ( ! isDeployed ) {
56
+ console . warn ( "Halo2VerifyingKey contract address provided but contract is not deployed or invalid." ) ;
57
+ halo2VerifyingKeyAddress = null
58
+ }
59
+ }
60
+
61
+ if ( halo2VerifierAddress ) {
62
+ const isDeployed = await isContractDeployed ( halo2VerifierAddress , netprovider )
63
+ if ( ! isDeployed ) {
64
+ console . warn ( "Halo2Verifier contract address provided but contract is not deployed or invalid." ) ;
65
+ halo2VerifierAddress = null
66
+ }
67
+ }
68
+
69
+ if ( globalPublicParamsAddress ) {
70
+ const isDeployed = await isContractDeployed ( globalPublicParamsAddress , netprovider )
71
+ if ( ! isDeployed ) {
72
+ console . warn ( "GlobalPublicParams contract address provided but contract is not deployed or invalid." ) ;
73
+ globalPublicParamsAddress = null
74
+ }
75
+ }
76
+
77
+ if ( pseudoRandAddress ) {
78
+ const isDeployed = await isContractDeployed ( pseudoRandAddress , netprovider )
79
+ if ( ! isDeployed ) {
80
+ console . warn ( "PseudoRand contract address provided but contract is not deployed or invalid." ) ;
81
+ pseudoRandAddress = null
82
+ }
83
+ }
84
+ }
85
+
86
+ if ( ! halo2VerifyingKeyAddress ) {
26
87
const Halo2VerifyingKey = await ethers . getContractFactory ( `contracts/Halo2VerifyingKey-${ threshold } -${ numberOfMembers } -${ degree } -g2.sol:Halo2VerifyingKey` )
27
88
const halo2VerifyingKey = await Halo2VerifyingKey . connect ( deployerWallet ) . deploy ( )
28
89
await halo2VerifyingKey . deployed ( )
29
90
30
- console . log ( "Halo2VerifyingKey deployed at" , halo2VerifyingKey . address )
91
+ console . log ( "Halo2VerifyingKey (HALO2VK) deployed at" , halo2VerifyingKey . address )
92
+ halo2VerifyingKeyAddress = halo2VerifyingKey . address
93
+ }
31
94
95
+ if ( ! halo2VerifierAddress ) {
32
96
const Halo2Verifier = await ethers . getContractFactory ( 'contracts/Halo2Verifier.sol:Halo2Verifier' )
33
97
const halo2Verifier = await Halo2Verifier . connect ( deployerWallet ) . deploy ( )
34
98
await halo2Verifier . deployed ( )
35
99
36
- console . log ( "Halo2Verifier deployed at" , halo2Verifier . address )
100
+ console . log ( "Halo2Verifier (HALO2V) deployed at" , halo2Verifier . address )
101
+ halo2VerifierAddress = halo2Verifier . address
102
+ }
37
103
104
+ if ( ! globalPublicParamsAddress ) {
38
105
const GlobalPublicParams = await ethers . getContractFactory ( 'GlobalPublicParams' )
39
106
const globalPublicParams = await GlobalPublicParams . connect ( deployerWallet ) . deploy ( )
40
107
await globalPublicParams . deployed ( )
41
108
42
- console . log ( "GlobalPublicParams deployed at" , globalPublicParams . address )
109
+ console . log ( "GlobalPublicParams (GPP) deployed at" , globalPublicParams . address )
110
+ globalPublicParamsAddress = globalPublicParams . address
111
+ }
43
112
113
+ if ( ! pseudoRandAddress ) {
44
114
const PseudoRand = await ethers . getContractFactory ( 'PseudoRand' )
45
115
const pseudoRand = await PseudoRand . connect ( deployerWallet ) . deploy ( )
46
116
await pseudoRand . deployed ( )
47
117
48
- console . log ( "PseudoRand deployed at" , pseudoRand . address )
49
-
50
- halo2VerifyingKeyAddress = halo2VerifyingKey . address
51
- halo2VerifierAddress = halo2Verifier . address
52
- globalPublicParamsAddress = globalPublicParams . address
118
+ console . log ( "PseudoRand (PSRAND) deployed at" , pseudoRand . address )
53
119
pseudoRandAddress = pseudoRand . address
54
120
}
55
121
0 commit comments