1
1
import { BigNumber , providers } from 'ethers'
2
- import { parseEther } from 'ethers/lib/utils'
2
+ import { isAddress , parseUnits } from 'ethers/lib/utils'
3
3
import fs from 'fs'
4
4
5
5
import { configs } from './files/configs'
6
+ import { ERC20__factory } from '../build/types'
6
7
7
8
export interface DeployedContracts {
8
9
bridge : string
@@ -15,10 +16,6 @@ export interface DeployedContracts {
15
16
challengeManager : string
16
17
boldAction : string
17
18
preImageHashLookup : string
18
- prover0 : string
19
- proverMem : string
20
- proverMath : string
21
- proverHostIo : string
22
19
osp : string
23
20
}
24
21
@@ -105,6 +102,7 @@ export const validateConfig = async (
105
102
config : Config ,
106
103
l1Rpc : providers . Provider
107
104
) => {
105
+ // check all config.contracts
108
106
if ( ( await l1Rpc . getCode ( config . contracts . rollup ) ) . length <= 2 ) {
109
107
throw new Error ( 'rollup address is not a contract' )
110
108
}
@@ -126,11 +124,17 @@ export const validateConfig = async (
126
124
if ( ( await l1Rpc . getCode ( config . contracts . upgradeExecutor ) ) . length <= 2 ) {
127
125
throw new Error ( 'upgradeExecutor address is not a contract' )
128
126
}
127
+ if ( ! isAddress ( config . contracts . excessStakeReceiver ) ) {
128
+ throw new Error ( 'excessStakeReceiver is not a valid address' )
129
+ }
129
130
130
131
// check all the config.proxyAdmins exist
131
132
if ( ( await l1Rpc . getCode ( config . proxyAdmins . outbox ) ) . length <= 2 ) {
132
133
throw new Error ( 'outbox proxy admin address is not a contract' )
133
134
}
135
+ if ( ( await l1Rpc . getCode ( config . proxyAdmins . inbox ) ) . length <= 2 ) {
136
+ throw new Error ( 'inbox proxy admin address is not a contract' )
137
+ }
134
138
if ( ( await l1Rpc . getCode ( config . proxyAdmins . bridge ) ) . length <= 2 ) {
135
139
throw new Error ( 'bridge proxy admin address is not a contract' )
136
140
}
@@ -142,18 +146,22 @@ export const validateConfig = async (
142
146
}
143
147
144
148
// check all the settings exist
149
+ // Note: `challengeGracePeriodBlocks` and `validatorAfkBlocks` can both be 0
145
150
if ( config . settings . confirmPeriodBlocks === 0 ) {
146
151
throw new Error ( 'confirmPeriodBlocks is 0' )
147
152
}
148
- if ( config . settings . stakeToken . length === 0 ) {
149
- throw new Error ( 'stakeToken address is empty ' )
153
+ if ( config . settings . challengePeriodBlocks === 0 ) {
154
+ throw new Error ( 'challengePeriodBlocks is 0 ' )
150
155
}
151
156
if ( ( await l1Rpc . getCode ( config . settings . stakeToken ) ) . length <= 2 ) {
152
157
throw new Error ( 'stakeToken address is not a contract' )
153
158
}
154
159
if ( config . settings . chainId === 0 ) {
155
160
throw new Error ( 'chainId is 0' )
156
161
}
162
+ if ( config . settings . minimumAssertionPeriod === 0 ) {
163
+ throw new Error ( 'minimumAssertionPeriod is 0' )
164
+ }
157
165
if ( config . settings . blockLeafSize === 0 ) {
158
166
throw new Error ( 'blockLeafSize is 0' )
159
167
}
@@ -166,22 +174,45 @@ export const validateConfig = async (
166
174
if ( config . settings . numBigStepLevel === 0 ) {
167
175
throw new Error ( 'numBigStepLevel is 0' )
168
176
}
177
+ if ( config . settings . maxDataSize === 0 ) {
178
+ throw new Error ( 'maxDataSize is 0' )
179
+ }
169
180
181
+ // check stake token amount
170
182
const stakeAmount = BigNumber . from ( config . settings . stakeAmt )
171
- // check it's more than 1 eth
172
- if ( stakeAmount . lt ( parseEther ( '1' ) ) ) {
173
- throw new Error ( 'stakeAmt is less than 1 eth' )
183
+ if ( stakeAmount . eq ( 0 ) ) {
184
+ throw new Error ( 'stakeAmt is 0' )
174
185
}
175
- const miniStakeAmounts = config . settings . miniStakeAmounts . map ( BigNumber . from )
176
186
187
+ // check mini stakes
188
+ const miniStakeAmounts = config . settings . miniStakeAmounts . map ( BigNumber . from )
177
189
if ( miniStakeAmounts . length !== config . settings . numBigStepLevel + 2 ) {
178
190
throw new Error ( 'miniStakeAmts length is not numBigStepLevel + 2' )
179
191
}
180
192
181
- if (
182
- ! config . settings . disableValidatorWhitelist &&
183
- config . validators . length === 0
184
- ) {
185
- throw new Error ( 'no validators' )
193
+ // check validators and whitelist
194
+ if ( ! config . settings . disableValidatorWhitelist ) {
195
+ if ( config . validators . length === 0 ) {
196
+ throw new Error ( 'no validators' )
197
+ }
198
+
199
+ for ( let i = 0 ; i < config . validators . length ; i ++ ) {
200
+ if ( ! isAddress ( config . validators [ i ] ) ) {
201
+ throw new Error ( `Invalid address for validator ${ i } ` )
202
+ }
203
+ }
204
+ }
205
+
206
+ // check delaybuffer settings
207
+ if ( config . settings . isDelayBufferable ) {
208
+ if ( config . settings . bufferConfig . max === 0 ) {
209
+ throw new Error ( 'bufferConfig.max is 0' )
210
+ }
211
+ if ( config . settings . bufferConfig . threshold === 0 ) {
212
+ throw new Error ( 'bufferConfig.threshold is 0' )
213
+ }
214
+ if ( config . settings . bufferConfig . replenishRateInBasis === 0 ) {
215
+ throw new Error ( 'bufferConfig.replenishRateInBasis is 0' )
216
+ }
186
217
}
187
218
}
0 commit comments