11import { BigNumber , providers } from 'ethers'
2- import { parseEther } from 'ethers/lib/utils'
2+ import { isAddress , parseUnits } from 'ethers/lib/utils'
33import fs from 'fs'
44
55import { configs } from './files/configs'
6+ import { ERC20__factory } from '../build/types'
67
78export interface DeployedContracts {
89 bridge : string
@@ -15,10 +16,6 @@ export interface DeployedContracts {
1516 challengeManager : string
1617 boldAction : string
1718 preImageHashLookup : string
18- prover0 : string
19- proverMem : string
20- proverMath : string
21- proverHostIo : string
2219 osp : string
2320}
2421
@@ -105,6 +102,7 @@ export const validateConfig = async (
105102 config : Config ,
106103 l1Rpc : providers . Provider
107104) => {
105+ // check all config.contracts
108106 if ( ( await l1Rpc . getCode ( config . contracts . rollup ) ) . length <= 2 ) {
109107 throw new Error ( 'rollup address is not a contract' )
110108 }
@@ -126,11 +124,17 @@ export const validateConfig = async (
126124 if ( ( await l1Rpc . getCode ( config . contracts . upgradeExecutor ) ) . length <= 2 ) {
127125 throw new Error ( 'upgradeExecutor address is not a contract' )
128126 }
127+ if ( ! isAddress ( config . contracts . excessStakeReceiver ) ) {
128+ throw new Error ( 'excessStakeReceiver is not a valid address' )
129+ }
129130
130131 // check all the config.proxyAdmins exist
131132 if ( ( await l1Rpc . getCode ( config . proxyAdmins . outbox ) ) . length <= 2 ) {
132133 throw new Error ( 'outbox proxy admin address is not a contract' )
133134 }
135+ if ( ( await l1Rpc . getCode ( config . proxyAdmins . inbox ) ) . length <= 2 ) {
136+ throw new Error ( 'inbox proxy admin address is not a contract' )
137+ }
134138 if ( ( await l1Rpc . getCode ( config . proxyAdmins . bridge ) ) . length <= 2 ) {
135139 throw new Error ( 'bridge proxy admin address is not a contract' )
136140 }
@@ -142,18 +146,22 @@ export const validateConfig = async (
142146 }
143147
144148 // check all the settings exist
149+ // Note: `challengeGracePeriodBlocks` and `validatorAfkBlocks` can both be 0
145150 if ( config . settings . confirmPeriodBlocks === 0 ) {
146151 throw new Error ( 'confirmPeriodBlocks is 0' )
147152 }
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 ' )
150155 }
151156 if ( ( await l1Rpc . getCode ( config . settings . stakeToken ) ) . length <= 2 ) {
152157 throw new Error ( 'stakeToken address is not a contract' )
153158 }
154159 if ( config . settings . chainId === 0 ) {
155160 throw new Error ( 'chainId is 0' )
156161 }
162+ if ( config . settings . minimumAssertionPeriod === 0 ) {
163+ throw new Error ( 'minimumAssertionPeriod is 0' )
164+ }
157165 if ( config . settings . blockLeafSize === 0 ) {
158166 throw new Error ( 'blockLeafSize is 0' )
159167 }
@@ -166,22 +174,45 @@ export const validateConfig = async (
166174 if ( config . settings . numBigStepLevel === 0 ) {
167175 throw new Error ( 'numBigStepLevel is 0' )
168176 }
177+ if ( config . settings . maxDataSize === 0 ) {
178+ throw new Error ( 'maxDataSize is 0' )
179+ }
169180
181+ // check stake token amount
170182 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' )
174185 }
175- const miniStakeAmounts = config . settings . miniStakeAmounts . map ( BigNumber . from )
176186
187+ // check mini stakes
188+ const miniStakeAmounts = config . settings . miniStakeAmounts . map ( BigNumber . from )
177189 if ( miniStakeAmounts . length !== config . settings . numBigStepLevel + 2 ) {
178190 throw new Error ( 'miniStakeAmts length is not numBigStepLevel + 2' )
179191 }
180192
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+ }
186217 }
187218}
0 commit comments