-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathexecuteBoldUpgrade.ts
More file actions
858 lines (748 loc) · 23.1 KB
/
executeBoldUpgrade.ts
File metadata and controls
858 lines (748 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
import {
BigNumber,
BigNumberish,
Contract,
ContractReceipt,
Wallet,
} from 'ethers'
import { ethers } from 'hardhat'
import {
Config,
DeployedContracts,
getConfig,
getJsonFile,
} from './boldUpgradeCommon'
import {
BOLDUpgradeAction__factory,
Bridge,
Bridge__factory,
EdgeChallengeManager,
EdgeChallengeManager__factory,
ERC20Outbox__factory,
IERC20Bridge__factory,
IERC20Inbox__factory,
IOldRollup__factory,
Outbox__factory,
RollupEventInbox__factory,
RollupUserLogic,
RollupUserLogic__factory,
SequencerInbox__factory,
} from '../build/types'
import { abi as UpgradeExecutorAbi } from '@offchainlabs/upgrade-executor/build/contracts/src/UpgradeExecutor.sol/UpgradeExecutor.json'
import dotenv from 'dotenv'
import { RollupMigratedEvent } from '../build/types/src/rollup/BOLDUpgradeAction.sol/BOLDUpgradeAction'
import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers'
import { getAddress } from 'ethers/lib/utils'
import path from 'path'
import { AssertionCreatedEvent } from '../build/types/src/rollup/IRollupCore'
dotenv.config()
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T
type VerificationParams = {
l1Rpc: JsonRpcProvider
config: Config
deployedContracts: DeployedContracts
preUpgradeState: UnwrapPromise<ReturnType<typeof getPreUpgradeState>>
receipt: ContractReceipt
}
const executors: { [key: string]: string } = {
// DAO L1 Timelocks
arb1: '0xE6841D92B0C345144506576eC13ECf5103aC7f49',
nova: '0xE6841D92B0C345144506576eC13ECf5103aC7f49',
sepolia: '0x6EC62D826aDc24AeA360be9cF2647c42b9Cdb19b',
local: '0x5E1497dD1f08C87b2d8FE23e9AAB6c1De833D927',
}
async function getPreUpgradeState(l1Rpc: JsonRpcProvider, config: Config) {
const oldRollupContract = IOldRollup__factory.connect(
config.contracts.rollup,
l1Rpc
)
const seqInbox = SequencerInbox__factory.connect(
config.contracts.sequencerInbox,
l1Rpc
)
const bridge = IERC20Bridge__factory.connect(config.contracts.bridge, l1Rpc)
const stakerCount = await oldRollupContract.stakerCount()
const stakers: string[] = []
for (let i = BigNumber.from(0); i.lt(stakerCount); i = i.add(1)) {
stakers.push(await oldRollupContract.getStakerAddress(i))
}
const boxes = await getAllowedInboxesOutboxesFromBridge(
Bridge__factory.connect(config.contracts.bridge, l1Rpc)
)
const wasmModuleRoot = await oldRollupContract.wasmModuleRoot()
const feeToken = (await seqInbox.isUsingFeeToken())
? await bridge.nativeToken()
: null
return {
stakers,
wasmModuleRoot,
...boxes,
feeToken,
}
}
async function perform(
l1Rpc: JsonRpcProvider,
config: Config,
deployedContracts: DeployedContracts
) {
const l1PrivKey = process.env.L1_PRIV_KEY
if (!l1PrivKey) {
throw new Error('L1_PRIV_KEY env variable not set')
}
let timelockSigner = new Wallet(l1PrivKey, l1Rpc) as unknown as JsonRpcSigner
if (process.env.ANVILFORK === 'true') {
const executor = executors[process.env.CONFIG_NETWORK_NAME!]
if (!executor) {
throw new Error(
'no executor found for CONFIG_NETWORK_NAME or CONFIG_NETWORK_NAME not set'
)
}
timelockSigner = await l1Rpc.getSigner(executor)
await l1Rpc.send('hardhat_impersonateAccount', [executor])
await l1Rpc.send('hardhat_setBalance', [executor, '0x1000000000000000'])
}
const upExec = new Contract(
config.contracts.upgradeExecutor,
UpgradeExecutorAbi,
timelockSigner
)
const boldAction = BOLDUpgradeAction__factory.connect(
deployedContracts.boldAction,
timelockSigner
)
// what validators did we have in the old rollup?
const boldActionPerformData = boldAction.interface.encodeFunctionData(
'perform',
[config.validators]
)
const performCallData = upExec.interface.encodeFunctionData('execute', [
deployedContracts.boldAction,
boldActionPerformData,
])
const signerCanExecute = await upExec.hasRole(
'0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63',
await timelockSigner.getAddress()
)
console.log('upgrade executor:', config.contracts.upgradeExecutor)
console.log('execute(...) call to upgrade executor:', performCallData)
if (!signerCanExecute) {
process.exit(0)
}
console.log('executing the upgrade...')
const receipt = (await (
await upExec.execute(deployedContracts.boldAction, boldActionPerformData)
).wait()) as ContractReceipt
console.log('upgrade executed')
return receipt
}
async function verifyPostUpgrade(params: VerificationParams) {
console.log('verifying the upgrade...')
const { l1Rpc, deployedContracts, config, receipt } = params
const boldAction = BOLDUpgradeAction__factory.connect(
deployedContracts.boldAction,
l1Rpc
)
const rollupMigratedLogs = receipt.events!.filter(
event =>
event.topics[0] === boldAction.interface.getEventTopic('RollupMigrated')
)
if (rollupMigratedLogs.length !== 1) {
console.log(rollupMigratedLogs)
throw new Error('RollupMigratedEvent not found or have multiple')
}
const rollupMigratedLog = boldAction.interface.parseLog(rollupMigratedLogs[0])
.args as RollupMigratedEvent['args']
await boldAction.validateRollupDeployedAtAddress(
rollupMigratedLog.rollup,
config.contracts.upgradeExecutor,
config.settings.chainId
)
const boldRollup = RollupUserLogic__factory.connect(
rollupMigratedLog.rollup,
l1Rpc
)
const assertionCreatedLogs = receipt.events!.filter(
event =>
event.topics[0] === boldRollup.interface.getEventTopic('AssertionCreated')
)
if (assertionCreatedLogs.length !== 1) {
console.log(assertionCreatedLogs)
throw new Error('AssertionCreatedEvent not found or have multiple')
}
const assertionCreatedLog = boldRollup.interface.parseLog(
assertionCreatedLogs[0]
).args as AssertionCreatedEvent['args']
console.log('Old Rollup:', params.config.contracts.rollup)
console.log('BOLD Rollup:', rollupMigratedLog.rollup)
console.log('BOLD Challenge Manager:', rollupMigratedLog.challengeManager)
console.log(
'BOLD AssertionCreated assertionHash:',
assertionCreatedLog.assertionHash
)
console.log(
'BOLD AssertionCreated parentAssertionHash:',
assertionCreatedLog.parentAssertionHash
)
console.log(
'BOLD AssertionCreated assertion:',
JSON.stringify(assertionCreatedLog.assertion)
)
console.log(
'BOLD AssertionCreated afterInboxBatchAcc:',
assertionCreatedLog.afterInboxBatchAcc
)
console.log(
'BOLD AssertionCreated inboxMaxCount:',
assertionCreatedLog.inboxMaxCount
)
console.log(
'BOLD AssertionCreated wasmModuleRoot:',
assertionCreatedLog.wasmModuleRoot
)
console.log(
'BOLD AssertionCreated requiredStake:',
assertionCreatedLog.requiredStake
)
console.log(
'BOLD AssertionCreated challengeManager:',
assertionCreatedLog.challengeManager
)
console.log(
'BOLD AssertionCreated confirmPeriodBlocks:',
assertionCreatedLog.confirmPeriodBlocks
)
const edgeChallengeManager = EdgeChallengeManager__factory.connect(
rollupMigratedLog.challengeManager,
l1Rpc
)
const newRollup = RollupUserLogic__factory.connect(
rollupMigratedLog.rollup,
l1Rpc
)
await checkSequencerInbox(params, newRollup)
await checkInbox(params)
await checkBridge(params, newRollup)
await checkRollupEventInbox(params, newRollup)
await checkOutbox(params, newRollup)
const { oldLatestConfirmedStateHash } = await checkOldRollup(params)
console.log('oldLatestConfirmedStateHash', oldLatestConfirmedStateHash)
await checkNewRollup(
params,
newRollup,
edgeChallengeManager,
assertionCreatedLog.inboxMaxCount
)
await checkNewChallengeManager(params, newRollup, edgeChallengeManager)
console.log('upgrade verified')
}
async function checkSequencerInbox(
params: VerificationParams,
newRollup: RollupUserLogic
) {
const { l1Rpc, config, deployedContracts, preUpgradeState } = params
const seqInboxContract = SequencerInbox__factory.connect(
config.contracts.sequencerInbox,
l1Rpc
)
// make sure fee token-ness is correct
if (
(await seqInboxContract.isUsingFeeToken()) !==
(preUpgradeState.feeToken !== null)
) {
throw new Error('SequencerInbox isUsingFeeToken does not match')
}
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.sequencerInbox)) !==
deployedContracts.seqInbox
) {
throw new Error('SequencerInbox was not upgraded')
}
// check delay buffer parameters
const buffer = await seqInboxContract.buffer()
if (!buffer.bufferBlocks.eq(config.settings.bufferConfig.max)) {
throw new Error('bufferBlocks does not match')
}
if (!buffer.max.eq(config.settings.bufferConfig.max)) {
throw new Error('max does not match')
}
if (!buffer.threshold.eq(config.settings.bufferConfig.threshold)) {
throw new Error('threshold does not match')
}
if (
!buffer.replenishRateInBasis.eq(
config.settings.bufferConfig.replenishRateInBasis
)
) {
throw new Error('replenishRateInBasis does not match')
}
// check rollup was set
if ((await seqInboxContract.rollup()) !== newRollup.address) {
throw new Error('SequencerInbox rollup address does not match')
}
}
async function checkInbox(params: VerificationParams) {
const { l1Rpc, config, deployedContracts, preUpgradeState } = params
// make sure it's an ERC20Inbox if we're using a fee token
const inboxContract = IERC20Inbox__factory.connect(
config.contracts.inbox,
l1Rpc
)
const submissionFee = await inboxContract.calculateRetryableSubmissionFee(
100,
100
)
if (preUpgradeState.feeToken && !submissionFee.eq(0)) {
throw new Error('Inbox is not an ERC20Inbox')
}
if (!preUpgradeState.feeToken && submissionFee.eq(0)) {
throw new Error('Inbox is an ERC20Inbox')
}
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.inbox)) !==
deployedContracts.inbox
) {
throw new Error('Inbox was not upgraded')
}
}
async function checkRollupEventInbox(
params: VerificationParams,
newRollup: RollupUserLogic
) {
const { l1Rpc, config, deployedContracts } = params
const rollupEventInboxContract = RollupEventInbox__factory.connect(
config.contracts.rollupEventInbox,
l1Rpc
)
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.rollupEventInbox)) !==
deployedContracts.rei
) {
throw new Error('RollupEventInbox was not upgraded')
}
// make sure rollup was set
if ((await rollupEventInboxContract.rollup()) !== newRollup.address) {
throw new Error('RollupEventInbox rollup address does not match')
}
}
async function checkOutbox(
params: VerificationParams,
newRollup: RollupUserLogic
) {
const { l1Rpc, config, deployedContracts, preUpgradeState } = params
const outboxContract = Outbox__factory.connect(config.contracts.outbox, l1Rpc)
// make sure it's an ERC20Outbox if we're using a fee token
let feeTokenValid = true
try {
const erc20Outbox = ERC20Outbox__factory.connect(
config.contracts.outbox,
l1Rpc
)
// will revert if not an ERC20Outbox
const withdrawalAmt = await erc20Outbox.l2ToL1WithdrawalAmount()
feeTokenValid = preUpgradeState.feeToken !== null
} catch (e: any) {
if (e.code !== 'CALL_EXCEPTION') throw e
feeTokenValid = preUpgradeState.feeToken === null
}
if (!feeTokenValid) {
throw new Error('Outbox fee token does not match')
}
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.outbox)) !==
deployedContracts.outbox
) {
throw new Error('Outbox was not upgraded')
}
// make sure rollup was set
if ((await outboxContract.rollup()) !== newRollup.address) {
throw new Error('Outbox rollup address does not match')
}
}
async function checkBridge(
params: VerificationParams,
newRollup: RollupUserLogic
) {
const { l1Rpc, config, deployedContracts, preUpgradeState } = params
const bridgeContract = Bridge__factory.connect(config.contracts.bridge, l1Rpc)
// make sure the fee token was preserved
let feeTokenValid = true
try {
const erc20Bridge = IERC20Bridge__factory.connect(
config.contracts.bridge,
l1Rpc
)
const feeToken = await erc20Bridge.nativeToken()
if (feeToken !== preUpgradeState.feeToken) {
feeTokenValid = false
}
} catch (e: any) {
if (e.code !== 'CALL_EXCEPTION') throw e
feeTokenValid = preUpgradeState.feeToken === null
}
if (!feeTokenValid) {
throw new Error('Bridge fee token does not match')
}
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.bridge)) !==
deployedContracts.bridge
) {
throw new Error('Bridge was not upgraded')
}
// make sure rollup was set
if ((await bridgeContract.rollup()) !== newRollup.address) {
throw new Error('Bridge rollup address does not match')
}
// make sure allowed inbox and outbox list is unchanged
const { inboxes, outboxes } = await getAllowedInboxesOutboxesFromBridge(
bridgeContract
)
if (JSON.stringify(inboxes) !== JSON.stringify(preUpgradeState.inboxes)) {
throw new Error('Allowed inbox list has changed')
}
if (JSON.stringify(outboxes) !== JSON.stringify(preUpgradeState.outboxes)) {
throw new Error('Allowed outbox list has changed')
}
// make sure the sequencer inbox is unchanged
if (
(await bridgeContract.sequencerInbox()) !== config.contracts.sequencerInbox
) {
throw new Error('Sequencer inbox has changed')
}
}
async function checkOldRollup(
params: VerificationParams
): Promise<{ oldLatestConfirmedStateHash: string }> {
const { l1Rpc, config, preUpgradeState } = params
const oldRollupContract = IOldRollup__factory.connect(
config.contracts.rollup,
l1Rpc
)
// ensure the old rollup is paused
if (!(await oldRollupContract.paused())) {
throw new Error('Old rollup is not paused')
}
// ensure there are no stakers
if (!(await oldRollupContract.stakerCount()).eq(0)) {
throw new Error('Old rollup has stakers')
}
// ensure that the old stakers are now zombies
for (const staker of preUpgradeState.stakers) {
if (!(await oldRollupContract.isZombie(staker))) {
throw new Error('Old staker is not a zombie')
}
}
if (preUpgradeState.stakers.length > 0) {
try {
await oldRollupContract.callStatic.withdrawStakerFunds({
from: preUpgradeState.stakers[0],
})
} catch (e) {
if (e instanceof Error && e.message.includes('Pausable: paused')) {
console.warn(
'!!!!! Withdraw staker funds FAILED, old rollup need to be upgraded to enable withdrawals !!!!!'
)
} else {
throw e
}
}
}
const latestConfirmed = await oldRollupContract.latestConfirmed()
const latestConfirmedStateHash = (
await oldRollupContract.getNode(latestConfirmed)
).stateHash
return {
oldLatestConfirmedStateHash: latestConfirmedStateHash,
}
}
async function checkInitialAssertion(
params: VerificationParams,
newRollup: RollupUserLogic,
newEdgeChallengeManager: EdgeChallengeManager,
currentInboxCount: BigNumberish
): Promise<{ latestConfirmed: string }> {
const { config, l1Rpc } = params
const latestConfirmed = await newRollup.latestConfirmed()
await newRollup.validateConfig(latestConfirmed, {
wasmModuleRoot: params.preUpgradeState.wasmModuleRoot,
requiredStake: config.settings.stakeAmt,
challengeManager: newEdgeChallengeManager.address,
confirmPeriodBlocks: config.settings.confirmPeriodBlocks,
nextInboxPosition: currentInboxCount,
})
return {
latestConfirmed,
}
}
async function checkNewRollup(
params: VerificationParams,
newRollup: RollupUserLogic,
newEdgeChallengeManager: EdgeChallengeManager,
currentInboxCount: BigNumberish
) {
const { config, deployedContracts, preUpgradeState } = params
// check bridge
if (
getAddress(await newRollup.bridge()) != getAddress(config.contracts.bridge)
) {
throw new Error('Bridge address does not match')
}
// check rei
if (
getAddress(await newRollup.rollupEventInbox()) !=
getAddress(config.contracts.rollupEventInbox)
) {
throw new Error('RollupEventInbox address does not match')
}
// check inbox
if (
getAddress(await newRollup.inbox()) != getAddress(config.contracts.inbox)
) {
throw new Error('Inbox address does not match')
}
// check outbox
if (
getAddress(await newRollup.outbox()) != getAddress(config.contracts.outbox)
) {
throw new Error('Outbox address does not match')
}
// check challengeManager
if (
getAddress(await newRollup.challengeManager()) !==
newEdgeChallengeManager.address
) {
throw new Error('ChallengeManager address does not match')
}
// chainId
if (!(await newRollup.chainId()).eq(config.settings.chainId)) {
throw new Error('Chain ID does not match')
}
// wasmModuleRoot
if ((await newRollup.wasmModuleRoot()) !== preUpgradeState.wasmModuleRoot) {
throw new Error('Wasm module root does not match')
}
// challengeGracePeriodBlocks
if (
!(await newRollup.challengeGracePeriodBlocks()).eq(
config.settings.challengeGracePeriodBlocks
)
) {
throw new Error('Challenge grace period blocks does not match')
}
// loserStakeEscrow
if (
getAddress(await newRollup.loserStakeEscrow()) !==
getAddress(config.contracts.excessStakeReceiver)
) {
throw new Error('Loser stake escrow address does not match')
}
// check initial assertion
const { latestConfirmed } = await checkInitialAssertion(
params,
newRollup,
newEdgeChallengeManager,
currentInboxCount
)
console.log('BOLD latest confirmed:', latestConfirmed)
// check validator whitelist disabled
if (
(await newRollup.validatorWhitelistDisabled()) !==
config.settings.disableValidatorWhitelist
) {
throw new Error('Validator whitelist disabled does not match')
}
// make sure all validators are set
for (const val of config.validators) {
if (!(await newRollup.isValidator(val))) {
throw new Error('Validator not set')
}
}
// check stake token address
if (
getAddress(await newRollup.stakeToken()) !=
getAddress(config.settings.stakeToken)
) {
throw new Error('Stake token address does not match')
}
// check confirm period blocks
if (
!(await newRollup.confirmPeriodBlocks()).eq(
config.settings.confirmPeriodBlocks
)
) {
throw new Error('Confirm period blocks does not match')
}
// check base stake
if (!(await newRollup.baseStake()).eq(config.settings.stakeAmt)) {
throw new Error('Base stake does not match')
}
// check fast confirmer (must be 0 for the local chain)
if (
getAddress(await newRollup.anyTrustFastConfirmer()) !==
ethers.constants.AddressZero
) {
throw new Error('Any trust fast confirmer does not match')
}
}
async function checkNewChallengeManager(
params: VerificationParams,
newRollup: RollupUserLogic,
edgeChallengeManager: EdgeChallengeManager
) {
const { config, deployedContracts } = params
// check assertion chain
if (
getAddress(await edgeChallengeManager.assertionChain()) !=
getAddress(newRollup.address)
) {
throw new Error('Assertion chain address does not match')
}
// check challenge period blocks
if (
!(await edgeChallengeManager.challengePeriodBlocks()).eq(
config.settings.challengePeriodBlocks
)
) {
throw new Error('Challenge period blocks does not match')
}
// check osp entry
if (
getAddress(await edgeChallengeManager.oneStepProofEntry()) !=
getAddress(deployedContracts.osp)
) {
throw new Error('OSP address does not match')
}
// check level heights
if (
!(await edgeChallengeManager.LAYERZERO_BLOCKEDGE_HEIGHT()).eq(
config.settings.blockLeafSize
)
) {
throw new Error('Block leaf size does not match')
}
if (
!(await edgeChallengeManager.LAYERZERO_BIGSTEPEDGE_HEIGHT()).eq(
config.settings.bigStepLeafSize
)
) {
throw new Error('Big step leaf size does not match')
}
if (
!(await edgeChallengeManager.LAYERZERO_SMALLSTEPEDGE_HEIGHT()).eq(
config.settings.smallStepLeafSize
)
) {
throw new Error('Small step leaf size does not match')
}
// check stake token address
if (
getAddress(await edgeChallengeManager.stakeToken()) !=
getAddress(config.settings.stakeToken)
) {
throw new Error('Stake token address does not match')
}
// check mini stake amounts
for (let i = 0; i < config.settings.miniStakeAmounts.length; i++) {
if (
!(await edgeChallengeManager.stakeAmounts(i)).eq(
config.settings.miniStakeAmounts[i]
)
) {
throw new Error('Mini stake amount does not match')
}
}
// check excess stake receiver
if (
(await edgeChallengeManager.excessStakeReceiver()) !==
config.contracts.excessStakeReceiver
) {
throw new Error('Excess stake receiver does not match')
}
// check num bigstep levels
if (
(await edgeChallengeManager.NUM_BIGSTEP_LEVEL()) !==
config.settings.numBigStepLevel
) {
throw new Error('Number of big step level does not match')
}
}
async function getProxyImpl(
l1Rpc: JsonRpcProvider,
proxyAddr: string,
secondary = false
) {
const primarySlot =
'0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
const secondarySlot =
'0x2b1dbce74324248c222f0ec2d5ed7bd323cfc425b336f0253c5ccfda7265546d'
const val = await l1Rpc.getStorageAt(
proxyAddr,
secondary ? secondarySlot : primarySlot
)
return getAddress('0x' + val.slice(26))
}
async function getAllowedInboxesOutboxesFromBridge(bridge: Bridge) {
const inboxes: string[] = []
const outboxes: string[] = []
for (let i = 0; ; i++) {
try {
inboxes.push(await bridge.allowedDelayedInboxList(i))
} catch (e: any) {
if (e.code !== 'CALL_EXCEPTION') {
throw e
}
break
}
}
for (let i = 0; ; i++) {
try {
outboxes.push(await bridge.allowedOutboxList(i))
} catch (e: any) {
if (e.code !== 'CALL_EXCEPTION') {
throw e
}
break
}
}
return {
inboxes,
outboxes,
}
}
async function main() {
const l1Rpc = ethers.provider
const configNetworkName = process.env.CONFIG_NETWORK_NAME
if (!configNetworkName) {
throw new Error('CONFIG_NETWORK_NAME env variable not set')
}
const config = await getConfig(configNetworkName, l1Rpc)
const deployedContractsDir = process.env.DEPLOYED_CONTRACTS_DIR
if (!deployedContractsDir) {
throw new Error('DEPLOYED_CONTRACTS_DIR env variable not set')
}
const deployedContractsLocation = path.join(
deployedContractsDir,
configNetworkName + 'DeployedContracts.json'
)
const deployedContracts = getJsonFile(
deployedContractsLocation
) as DeployedContracts
if (!deployedContracts.boldAction) {
throw new Error('No boldAction contract deployed')
}
const preUpgradeState = await getPreUpgradeState(l1Rpc, config)
const receipt = await perform(l1Rpc, config, deployedContracts)
console.log('upgrade tx hash:', receipt.transactionHash)
await verifyPostUpgrade({
l1Rpc,
config,
deployedContracts,
preUpgradeState,
receipt,
})
}
main().then(() => console.log('Done.'))