-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtestLocalExecuteBoldUpgrade.ts
333 lines (286 loc) · 8.76 KB
/
testLocalExecuteBoldUpgrade.ts
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
import { Contract, ContractReceipt } from 'ethers'
import { ethers } from 'hardhat'
import { Config, DeployedContracts, getConfig, getJsonFile } from './common'
import {
BOLDUpgradeAction__factory,
EdgeChallengeManager,
EdgeChallengeManager__factory,
RollupUserLogic,
RollupUserLogic__factory,
} from '../build/types'
import { abi as UpgradeExecutorAbi } from './files/UpgradeExecutor.json'
import dotenv from 'dotenv'
import { RollupMigratedEvent } from '../build/types/src/rollup/BOLDUpgradeAction.sol/BOLDUpgradeAction'
import { abi as OldRollupAbi } from './files/OldRollupUserLogic.json'
import { JsonRpcProvider } from '@ethersproject/providers'
import { getAddress } from 'ethers/lib/utils'
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
}
async function getPreUpgradeState(l1Rpc: JsonRpcProvider, config: Config) {
const oldRollupContract = new Contract(
config.contracts.rollup,
OldRollupAbi,
l1Rpc
)
const stakerCount = await oldRollupContract.stakerCount()
const stakers: string[] = []
for (let i = 0; i < stakerCount; i++) {
stakers.push(await oldRollupContract.getStakerAddress(i))
}
return {
stakers,
}
}
async function perform(
l1Rpc: JsonRpcProvider,
config: Config,
deployedContracts: DeployedContracts
) {
await l1Rpc.send('hardhat_impersonateAccount', [
'0xE6841D92B0C345144506576eC13ECf5103aC7f49'.toLowerCase(),
])
await l1Rpc.send('hardhat_setBalance', [
'0xE6841D92B0C345144506576eC13ECf5103aC7f49',
'0x1000000000000000',
])
const timelockImposter = l1Rpc.getSigner(
'0xE6841D92B0C345144506576eC13ECf5103aC7f49'
)
const upExec = new Contract(
config.contracts.upgradeExecutor,
UpgradeExecutorAbi,
timelockImposter
)
const boldAction = BOLDUpgradeAction__factory.connect(
deployedContracts.boldAction,
timelockImposter
)
// what validators did we have in the old rollup?
const boldActionPerformData = boldAction.interface.encodeFunctionData(
'perform',
[config.validators]
)
return (await (
await upExec.execute(deployedContracts.boldAction, boldActionPerformData)
).wait()) as ContractReceipt
}
async function verifyPostUpgrade(params: VerificationParams) {
const { l1Rpc, config, deployedContracts, preUpgradeState, receipt } = params
const boldAction = BOLDUpgradeAction__factory.connect(
deployedContracts.boldAction,
l1Rpc
)
const parsedLog = boldAction.interface.parseLog(
receipt.events![receipt.events!.length - 2]
).args as RollupMigratedEvent['args']
const edgeChallengeManager = EdgeChallengeManager__factory.connect(
parsedLog.challengeManager,
l1Rpc
)
const newRollup = RollupUserLogic__factory.connect(parsedLog.rollup, l1Rpc)
await checkBridge(params)
await checkOldRollup(params)
await checkNewRollup(params, newRollup)
await checkNewChallengeManager(params, edgeChallengeManager)
}
async function checkSequencerInbox(params: VerificationParams) {
const { l1Rpc, config, deployedContracts } = params
// 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
// todo
}
async function checkBridge(params: VerificationParams) {
const { l1Rpc, config, deployedContracts } = params
// make sure the impl was updated
if (
(await getProxyImpl(l1Rpc, config.contracts.bridge)) !==
deployedContracts.bridge
) {
throw new Error('Bridge was not upgraded')
}
}
async function checkOldRollup(params: VerificationParams) {
const { l1Rpc, config, deployedContracts, preUpgradeState } = params
const oldRollupContract = new Contract(
config.contracts.rollup,
OldRollupAbi,
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')
}
}
// ensure old rollup was upgraded
if (
(await getProxyImpl(l1Rpc, config.contracts.rollup, false)) !==
getAddress(deployedContracts.oldRollupUser)
) {
throw new Error('Old rollup was not upgraded')
}
}
async function checkNewRollup(
params: VerificationParams,
newRollup: RollupUserLogic
) {
const { l1Rpc, config } = params
// 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
if (config.settings.anyTrustFastConfirmer.length != 0) {
if (
getAddress(await newRollup.anyTrustFastConfirmer()) !==
getAddress(config.settings.anyTrustFastConfirmer)
) {
throw new Error('Any trust fast confirmer does not match')
}
}
}
async function checkNewChallengeManager(
params: VerificationParams,
edgeChallengeManager: EdgeChallengeManager
) {
const { config } = params
// 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 challenge period blocks
if (
!(await edgeChallengeManager.challengePeriodBlocks()).eq(
config.settings.challengePeriodBlocks
)
) {
throw new Error('Challenge period blocks 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 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,
primary = true
) {
const primarySlot =
'0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
const secondarySlot =
'0x2b1dbce74324248c222f0ec2d5ed7bd323cfc425b336f0253c5ccfda7265546d'
const val = await l1Rpc.getStorageAt(
proxyAddr,
primary ? primarySlot : secondarySlot
)
return getAddress('0x' + val.slice(26))
}
async function main() {
const l1RpcVal = process.env.L1_RPC_URL
if (!l1RpcVal) {
throw new Error('L1_RPC_URL env variable not set')
}
const l1Rpc = new ethers.providers.JsonRpcProvider(
l1RpcVal
) as JsonRpcProvider
const deployedContractsLocation = process.env.DEPLOYED_CONTRACTS_LOCATION
if (!deployedContractsLocation) {
throw new Error('DEPLOYED_CONTRACTS_LOCATION env variable not set')
}
const configLocation = process.env.CONFIG_LOCATION
if (!configLocation) {
throw new Error('CONFIG_LOCATION env variable not set')
}
const config = await getConfig(configLocation, l1Rpc)
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)
await verifyPostUpgrade({
l1Rpc,
config,
deployedContracts,
preUpgradeState,
receipt,
})
}
main().then(() => console.log('Done.'))