-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathboldUpgradeFunctions.ts
More file actions
352 lines (329 loc) · 10.4 KB
/
boldUpgradeFunctions.ts
File metadata and controls
352 lines (329 loc) · 10.4 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
import { BigNumber, Contract, ContractFactory, ethers, Signer } from 'ethers'
import {
BOLDUpgradeAction__factory,
Bridge__factory,
EdgeChallengeManager__factory,
OneStepProofEntry__factory,
OneStepProver0__factory,
OneStepProverHostIo__factory,
OneStepProverMath__factory,
OneStepProverMemory__factory,
Outbox__factory,
RollupAdminLogic__factory,
RollupEventInbox__factory,
RollupUserLogic__factory,
SequencerInbox__factory,
Inbox__factory,
StateHashPreImageLookup__factory,
IReader4844__factory,
IOldRollup__factory,
ERC20Bridge__factory,
ERC20Outbox__factory,
ERC20Inbox__factory,
} from '../build/types'
import { bytecode as Reader4844Bytecode } from '../out/yul/Reader4844.yul/Reader4844.json'
import { DeployedContracts, Config } from './boldUpgradeCommon'
import { AssertionStateStruct } from '../build/types/src/challengeV2/IAssertionChain'
import { verifyContract } from './deploymentUtils'
export const deployDependencies = async (
signer: Signer,
maxDataSize: number,
isUsingFeeToken: boolean,
isDelayBufferable: boolean,
isUsing4844Reader: boolean,
log: boolean = false,
verify: boolean = true
): Promise<Omit<DeployedContracts, 'boldAction' | 'preImageHashLookup'>> => {
const bridgeFac = isUsingFeeToken
? new ERC20Bridge__factory(signer)
: new Bridge__factory(signer)
const bridge = await bridgeFac.deploy()
await bridge.deployed()
if (log) {
console.log(`Bridge implementation deployed at: ${bridge.address}`)
}
if (verify) {
await bridge.deployTransaction.wait(5)
await verifyContract(
isUsingFeeToken ? 'ERC20Bridge' : 'Bridge',
bridge.address,
[],
isUsingFeeToken
? 'src/bridge/ERC20Bridge.sol:ERC20Bridge'
: 'src/bridge/Bridge.sol:Bridge'
)
}
const contractFactory = new ContractFactory(
IReader4844__factory.abi,
Reader4844Bytecode,
signer
)
let reader4844Addr = ethers.constants.AddressZero
if (isUsing4844Reader) {
const reader4844 = await contractFactory.deploy()
await reader4844.deployed()
reader4844Addr = reader4844.address
console.log(`Reader4844 deployed at ${reader4844Addr}`)
}
const seqInboxFac = new SequencerInbox__factory(signer)
const seqInbox = await seqInboxFac.deploy(
maxDataSize,
reader4844Addr,
isUsingFeeToken,
isDelayBufferable
)
await seqInbox.deployed()
if (log) {
console.log(
`Sequencer inbox implementation deployed at: ${seqInbox.address}`
)
}
if (verify) {
await seqInbox.deployTransaction.wait(5)
await verifyContract('SequencerInbox', seqInbox.address, [
maxDataSize,
reader4844Addr,
isUsingFeeToken,
isDelayBufferable,
])
}
const reiFac = new RollupEventInbox__factory(signer)
const rei = await reiFac.deploy()
await rei.deployed()
if (log) {
console.log(`Rollup event inbox implementation deployed at: ${rei.address}`)
}
if (verify) {
await rei.deployTransaction.wait(5)
await verifyContract('RollupEventInbox', rei.address, [])
}
const outboxFac = isUsingFeeToken
? new ERC20Outbox__factory(signer)
: new Outbox__factory(signer)
const outbox = await outboxFac.deploy()
await outbox.deployed()
if (log) {
console.log(`Outbox implementation deployed at: ${outbox.address}`)
}
if (verify) {
await outbox.deployTransaction.wait(5)
await verifyContract(
isUsingFeeToken ? 'ERC20Outbox' : 'Outbox',
outbox.address,
[]
)
}
const inboxFac = isUsingFeeToken
? new ERC20Inbox__factory(signer)
: new Inbox__factory(signer)
const inbox = await inboxFac.deploy(maxDataSize)
await inbox.deployed()
if (log) {
console.log(`Inbox implementation deployed at: ${inbox.address}`)
}
if (verify) {
await inbox.deployTransaction.wait(5)
await verifyContract('Inbox', inbox.address, [maxDataSize])
}
const newRollupUserFac = new RollupUserLogic__factory(signer)
const newRollupUser = await newRollupUserFac.deploy()
await newRollupUser.deployed()
if (log) {
console.log(`New rollup user logic deployed at: ${newRollupUser.address}`)
}
if (verify) {
await newRollupUser.deployTransaction.wait(5)
await verifyContract('RollupUserLogic', newRollupUser.address, [])
}
const newRollupAdminFac = new RollupAdminLogic__factory(signer)
const newRollupAdmin = await newRollupAdminFac.deploy()
await newRollupAdmin.deployed()
if (log) {
console.log(`New rollup admin logic deployed at: ${newRollupAdmin.address}`)
}
if (verify) {
await newRollupAdmin.deployTransaction.wait(5)
await verifyContract('RollupAdminLogic', newRollupAdmin.address, [])
}
const challengeManagerFac = new EdgeChallengeManager__factory(signer)
const challengeManager = await challengeManagerFac.deploy()
await challengeManager.deployed()
if (log) {
console.log(`Challenge manager deployed at: ${challengeManager.address}`)
}
if (verify) {
await challengeManager.deployTransaction.wait(5)
await verifyContract('EdgeChallengeManager', challengeManager.address, [])
}
const prover0Fac = new OneStepProver0__factory(signer)
const prover0 = await prover0Fac.deploy()
await prover0.deployed()
if (log) {
console.log(`Prover0 deployed at: ${prover0.address}`)
}
if (verify) {
await prover0.deployTransaction.wait(5)
await verifyContract('OneStepProver0', prover0.address, [])
}
const proverMemFac = new OneStepProverMemory__factory(signer)
const proverMem = await proverMemFac.deploy()
await proverMem.deployed()
if (log) {
console.log(`Prover mem deployed at: ${proverMem.address}`)
}
if (verify) {
await proverMem.deployTransaction.wait(5)
await verifyContract('OneStepProverMemory', proverMem.address, [])
}
const proverMathFac = new OneStepProverMath__factory(signer)
const proverMath = await proverMathFac.deploy()
await proverMath.deployed()
if (log) {
console.log(`Prover math deployed at: ${proverMath.address}`)
}
if (verify) {
await proverMath.deployTransaction.wait(5)
await verifyContract('OneStepProverMath', proverMath.address, [])
}
const proverHostIoFac = new OneStepProverHostIo__factory(signer)
const proverHostIo = await proverHostIoFac.deploy()
await proverHostIo.deployed()
if (log) {
console.log(`Prover host io deployed at: ${proverHostIo.address}`)
}
if (verify) {
await proverHostIo.deployTransaction.wait(5)
await verifyContract('OneStepProverHostIo', proverHostIo.address, [])
}
const proofEntryFac = new OneStepProofEntry__factory(signer)
const proofEntry = await proofEntryFac.deploy(
prover0.address,
proverMem.address,
proverMath.address,
proverHostIo.address
)
await proofEntry.deployed()
if (log) {
console.log(`Proof entry deployed at: ${proofEntry.address}`)
}
if (verify) {
await proofEntry.deployTransaction.wait(5)
await verifyContract('OneStepProofEntry', proofEntry.address, [
prover0.address,
proverMem.address,
proverMath.address,
proverHostIo.address,
])
}
return {
bridge: bridge.address,
seqInbox: seqInbox.address,
rei: rei.address,
outbox: outbox.address,
inbox: inbox.address,
newRollupUser: newRollupUser.address,
newRollupAdmin: newRollupAdmin.address,
challengeManager: challengeManager.address,
prover0: prover0.address,
proverMem: proverMem.address,
proverMath: proverMath.address,
proverHostIo: proverHostIo.address,
osp: proofEntry.address,
}
}
export const deployBoldUpgrade = async (
wallet: Signer,
config: Config,
log: boolean = false,
verify: boolean = true
): Promise<DeployedContracts> => {
const sequencerInbox = SequencerInbox__factory.connect(
config.contracts.sequencerInbox,
wallet
)
const isUsingFeeToken = await sequencerInbox.isUsingFeeToken()
const has4844Reader =
(await sequencerInbox.reader4844()) != ethers.constants.AddressZero
const deployed = await deployDependencies(
wallet,
config.settings.maxDataSize,
isUsingFeeToken,
config.settings.isDelayBufferable,
has4844Reader,
log,
verify
)
const fac = new BOLDUpgradeAction__factory(wallet)
const boldUpgradeAction = await fac.deploy(
{ ...config.contracts, osp: deployed.osp },
config.proxyAdmins,
deployed,
config.settings
)
if (log) {
console.log(`BOLD upgrade action deployed at: ${boldUpgradeAction.address}`)
}
if (verify) {
await boldUpgradeAction.deployTransaction.wait(5)
await verifyContract('BOLDUpgradeAction', boldUpgradeAction.address, [
{ ...config.contracts, osp: deployed.osp },
config.proxyAdmins,
deployed,
config.settings,
])
}
const deployedAndBold = {
...deployed,
boldAction: boldUpgradeAction.address,
preImageHashLookup: await boldUpgradeAction.PREIMAGE_LOOKUP(),
}
return deployedAndBold
}
export const populateLookup = async (
wallet: Signer,
rollupAddr: string,
preImageHashLookupAddr: string
) => {
const oldRollup = IOldRollup__factory.connect(rollupAddr, wallet)
const latestConfirmed = await oldRollup.latestConfirmed()
let latestConfirmedLog
let toBlock = await wallet.provider!.getBlockNumber()
for (let i = 0; i < 100; i++) {
latestConfirmedLog = await wallet.provider!.getLogs({
address: rollupAddr,
fromBlock: toBlock >= 1000 ? toBlock - 1000 : 0,
toBlock: toBlock,
topics: [
oldRollup.interface.getEventTopic('NodeCreated'),
ethers.utils.hexZeroPad(ethers.utils.hexlify(latestConfirmed), 32),
],
})
if (latestConfirmedLog.length == 1) break
if (toBlock == 0) {
throw new Error('Could not find latest confirmed node')
}
toBlock -= 1000
if (toBlock < 0) {
toBlock = 0
}
}
if (!latestConfirmedLog || latestConfirmedLog.length != 1) {
throw new Error('Could not find latest confirmed node')
}
const latestConfirmedEvent = oldRollup.interface.parseLog(
latestConfirmedLog[0]
).args
const afterState: AssertionStateStruct =
latestConfirmedEvent.assertion.afterState
const inboxCount: BigNumber = latestConfirmedEvent.inboxMaxCount
const lookup = StateHashPreImageLookup__factory.connect(
preImageHashLookupAddr,
wallet
)
const node = await oldRollup.getNode(latestConfirmed)
const stateHash = await lookup.stateHash(afterState, inboxCount)
if (node.stateHash != stateHash) {
throw new Error(`State hash mismatch ${node.stateHash} != ${stateHash}}`)
}
await lookup.set(stateHash, afterState, inboxCount)
}