@aztec/ethereum 3.0.0-nightly.20251211 → 3.0.0-nightly.20251213

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,545 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { SecretValue, getActiveNetworkName } from '@aztec/foundation/config';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import { promiseWithResolvers } from '@aztec/foundation/promise';
7
+ import type { Fr } from '@aztec/foundation/schemas';
8
+ import { fileURLToPath } from '@aztec/foundation/url';
9
+
10
+ import { bn254 } from '@noble/curves/bn254';
11
+ import type { Abi, Narrow } from 'abitype';
12
+ import { spawn } from 'child_process';
13
+ import { dirname, resolve } from 'path';
14
+ import readline from 'readline';
15
+ import type { Hex } from 'viem';
16
+ import { foundry, mainnet } from 'viem/chains';
17
+
18
+ import { createEthereumChain, isAnvilTestChain } from './chain.js';
19
+ import { createExtendedL1Client } from './client.js';
20
+ import type { L1ContractsConfig } from './config.js';
21
+ import { deployMulticall3 } from './contracts/multicall.js';
22
+ import { RollupContract } from './contracts/rollup.js';
23
+ import type { L1ContractAddresses } from './l1_contract_addresses.js';
24
+ import type { L1TxUtilsConfig } from './l1_tx_utils/config.js';
25
+ import type { ExtendedViemWalletClient } from './types.js';
26
+
27
+ const logger = createLogger('ethereum:deploy_aztec_l1_contracts');
28
+
29
+ const JSON_DEPLOY_RESULT_PREFIX = 'JSON DEPLOY RESULT:';
30
+
31
+ /**
32
+ * Runs a process with the given command, arguments, and environment.
33
+ * If the process outputs a line starting with JSON_DEPLOY_RESULT_PREFIX,
34
+ * the JSON is parsed and returned.
35
+ */
36
+ function runProcess<T>(
37
+ command: string,
38
+ args: string[],
39
+ env: Record<string, string | undefined>,
40
+ cwd: string,
41
+ ): Promise<T | undefined> {
42
+ const { promise, resolve, reject } = promiseWithResolvers<T | undefined>();
43
+ const proc = spawn(command, args, {
44
+ cwd,
45
+ env: { ...process.env, ...env },
46
+ stdio: ['ignore', 'pipe', 'pipe'],
47
+ });
48
+
49
+ let result: T | undefined;
50
+
51
+ readline.createInterface({ input: proc.stdout }).on('line', line => {
52
+ const trimmedLine = line.trim();
53
+ if (trimmedLine.startsWith(JSON_DEPLOY_RESULT_PREFIX)) {
54
+ const jsonStr = trimmedLine.slice(JSON_DEPLOY_RESULT_PREFIX.length).trim();
55
+ // TODO(AD): should this be a zod parse?
56
+ result = JSON.parse(jsonStr);
57
+ } else {
58
+ logger.info(line);
59
+ }
60
+ });
61
+ readline.createInterface({ input: proc.stderr }).on('line', logger.error.bind(logger));
62
+
63
+ proc.on('error', error => {
64
+ reject(new Error(`Failed to spawn ${command}: ${error.message}`));
65
+ });
66
+
67
+ proc.on('close', code => {
68
+ if (code !== 0) {
69
+ reject(new Error(`${command} exited with code ${code}. See logs for details.\n`));
70
+ } else {
71
+ resolve(result);
72
+ }
73
+ });
74
+
75
+ return promise;
76
+ }
77
+
78
+ // Covers an edge where where we may have a cached BlobLib that is not meant for production.
79
+ // Despite the profile apparently sometimes cached code remains (so says Lasse after his ignition-monorepo arc).
80
+ async function maybeForgeForceProductionBuild(l1ContractsPath: string, script: string, chainId: number) {
81
+ if (chainId === mainnet.id) {
82
+ logger.info(`Recompiling ${script} with production profile for mainnet deployment`);
83
+ logger.info('This may take a minute but ensures production BlobLib is used.');
84
+ await runProcess('forge', ['build', script, '--force'], { FOUNDRY_PROFILE: 'production' }, l1ContractsPath);
85
+ }
86
+ }
87
+
88
+ // Validator types for initial validator setup
89
+ export interface G2PointJson {
90
+ x0: string;
91
+ x1: string;
92
+ y0: string;
93
+ y1: string;
94
+ }
95
+
96
+ /**
97
+ * Validator data passed to Solidity for registration.
98
+ * Solidity will derive publicKeyG1 and proofOfPossession from the privateKey.
99
+ */
100
+ export interface ValidatorJson {
101
+ attester: string;
102
+ withdrawer: string;
103
+ /** BN254 secret key (private key) */
104
+ privateKey: string;
105
+ /** Pre-computed G2 public key (cannot be computed in Solidity) */
106
+ publicKeyInG2: G2PointJson;
107
+ }
108
+
109
+ /**
110
+ * Gets the path to the l1-contracts directory.
111
+ */
112
+ export function getL1ContractsPath(): string {
113
+ // Try to find l1-contracts relative to this file
114
+ const currentDir = dirname(fileURLToPath(import.meta.url));
115
+
116
+ // Go up from yarn-project/ethereum/src to yarn-project, then to repo root, then to l1-contracts
117
+ const l1ContractsPath = resolve(currentDir, '..', '..', '..', 'l1-contracts');
118
+ return l1ContractsPath;
119
+ }
120
+
121
+ /**
122
+ * Computes the validator data for passing to Solidity.
123
+ * Only computes the G2 public key (which requires scalar multiplication on G2, not available in EVM).
124
+ * Solidity will derive G1 public key and proof of possession from the private key.
125
+ */
126
+ export function computeValidatorData(operator: Operator): ValidatorJson {
127
+ const privateKey = operator.bn254SecretKey.getValue();
128
+
129
+ // Compute G2 public key: pk2 = privateKey * G2
130
+ // This is the only computation we need to do in TypeScript since G2 scalar mul
131
+ // is not available as an EVM precompile
132
+ const publicKeyG2 = bn254.G2.ProjectivePoint.BASE.multiply(privateKey);
133
+ const publicKeyG2Affine = publicKeyG2.toAffine();
134
+
135
+ return {
136
+ attester: operator.attester.toString(),
137
+ withdrawer: operator.withdrawer.toString(),
138
+ privateKey: privateKey.toString(),
139
+ publicKeyInG2: {
140
+ x0: publicKeyG2Affine.x.c0.toString(),
141
+ x1: publicKeyG2Affine.x.c1.toString(),
142
+ y0: publicKeyG2Affine.y.c0.toString(),
143
+ y1: publicKeyG2Affine.y.c1.toString(),
144
+ },
145
+ };
146
+ }
147
+
148
+ /**
149
+ * Deployed addresses from the rollup upgrade deployment.
150
+ */
151
+ export interface RollupUpgradeAddresses {
152
+ rollupAddress: string;
153
+ verifierAddress: string;
154
+ slashFactoryAddress: string;
155
+ inboxAddress: string;
156
+ outboxAddress: string;
157
+ feeJuicePortalAddress: string;
158
+ rollupVersion: number;
159
+ }
160
+
161
+ /**
162
+ * Return type for rollup upgrade via forge.
163
+ */
164
+ export interface ForgeRollupUpgradeResult {
165
+ rollupAddress: Hex;
166
+ verifierAddress: Hex;
167
+ slashFactoryAddress: Hex;
168
+ inboxAddress: Hex;
169
+ outboxAddress: Hex;
170
+ feeJuicePortalAddress: Hex;
171
+ rollupVersion: number;
172
+ }
173
+
174
+ export interface ForgeL1ContractsDeployResult extends ForgeRollupUpgradeResult {
175
+ registryAddress: Hex;
176
+ feeAssetAddress: Hex;
177
+ stakingAssetAddress: Hex;
178
+ gseAddress?: Hex;
179
+ rewardDistributorAddress: Hex;
180
+ coinIssuerAddress: Hex;
181
+ governanceProposerAddress: Hex;
182
+ governanceAddress: Hex;
183
+ dateGatedRelayerAddress?: Hex;
184
+ feeAssetHandlerAddress?: Hex;
185
+ stakingAssetHandlerAddress?: Hex;
186
+ zkPassportVerifierAddress?: Hex;
187
+ }
188
+
189
+ /**
190
+ * Deploys L1 contracts using forge and returns a result compatible with the TypeScript deployAztecL1Contracts function.
191
+ * This queries the Rollup contract to get the inbox, outbox, and feeJuicePortal addresses.
192
+ *
193
+ * All configuration is passed via environment variables to the forge script. The DeploymentConfiguration.sol
194
+ * contract reads these values and applies defaults for any unspecified parameters.
195
+ *
196
+ * @param rpcUrl - The RPC URL to use
197
+ * @param privateKey - The private key for the deployer (with 0x prefix)
198
+ * @param options - Additional deployment options (all optional with sensible defaults)
199
+ * @returns The deployment result with all contract addresses and an l1Client
200
+ */
201
+ export async function deployAztecL1Contracts(
202
+ rpcUrl: string,
203
+ privateKey: `0x${string}`,
204
+ chainId: number,
205
+ args: DeployAztecL1ContractsArgs,
206
+ ): Promise<DeployAztecL1ContractsReturnType> {
207
+ logger.info(`Deploying L1 contracts with config: ${jsonStringify(args)}`);
208
+ if (args.initialValidators && args.initialValidators.length > 0 && args.existingTokenAddress) {
209
+ throw new Error(
210
+ 'Cannot deploy with both initialValidators and existingTokenAddress. ' +
211
+ 'Initial validator funding requires minting tokens, which is not possible with an external token.',
212
+ );
213
+ }
214
+ const currentDir = dirname(fileURLToPath(import.meta.url));
215
+ const chain = createEthereumChain([rpcUrl], chainId);
216
+
217
+ const l1Client = createExtendedL1Client([rpcUrl], privateKey, chain.chainInfo);
218
+ const rpcCall = async (method: string, params: any[]) => {
219
+ logger.info(`Calling ${method} with params: ${JSON.stringify(params)}`);
220
+ return (await l1Client.transport.request({
221
+ method,
222
+ params,
223
+ })) as any;
224
+ };
225
+
226
+ logger.verbose(`Deploying contracts from ${l1Client.account.address.toString()}`);
227
+
228
+ // Deploy multicall3 if it does not exist in this network
229
+ // Sepolia and mainnet will have this.
230
+ await deployMulticall3(l1Client, logger);
231
+
232
+ if (isAnvilTestChain(chainId)) {
233
+ try {
234
+ // We are assuming that you are running this on a local anvil node which have 1s block times
235
+ // To align better with actual deployment, we update the block interval to 12s
236
+ await rpcCall('anvil_setBlockTimestampInterval', [args.ethereumSlotDuration]);
237
+ logger.warn(`Set block interval to ${args.ethereumSlotDuration}`);
238
+ } catch (e) {
239
+ logger.error(`Error setting block interval: ${e}`);
240
+ }
241
+ }
242
+
243
+ // Relative location of l1-contracts in monorepo or docker image.
244
+ const l1ContractsPath = resolve(currentDir, '..', '..', '..', 'l1-contracts');
245
+
246
+ const FORGE_SCRIPT = 'script/deploy/DeployAztecL1Contracts.s.sol';
247
+ await maybeForgeForceProductionBuild(l1ContractsPath, FORGE_SCRIPT, chainId);
248
+
249
+ // From heuristic testing. More caused issues with anvil.
250
+ const MAGIC_ANVIL_BATCH_SIZE = 12;
251
+ // Anvil seems to stall with unbounded batch size. Otherwise no max batch size is desirable.
252
+ // On sepolia and mainnet, we verify on etherscan (if etherscan API key is in env)
253
+ const forgeArgs = [
254
+ 'script',
255
+ FORGE_SCRIPT,
256
+ '--sig',
257
+ 'run()',
258
+ '--private-key',
259
+ privateKey,
260
+ '--rpc-url',
261
+ rpcUrl,
262
+ '--broadcast',
263
+ ...(chainId === foundry.id ? ['--batch-size', MAGIC_ANVIL_BATCH_SIZE.toString()] : ['--verify']),
264
+ ];
265
+ const forgeEnv = {
266
+ // Env vars required by l1-contracts/script/deploy/DeploymentConfiguration.sol.
267
+ NETWORK: getActiveNetworkName(),
268
+ FOUNDRY_PROFILE: chainId === mainnet.id ? 'production' : undefined,
269
+ ...getDeployAztecL1ContractsEnvVars(args),
270
+ };
271
+ const result = await runProcess<ForgeL1ContractsDeployResult>('forge', forgeArgs, forgeEnv, l1ContractsPath);
272
+ if (!result) {
273
+ throw new Error('Forge script did not output deployment result');
274
+ }
275
+ logger.info(`Deployed L1 contracts with L1 addresses: ${jsonStringify(result)}`);
276
+
277
+ const rollup = new RollupContract(l1Client, result.rollupAddress);
278
+
279
+ if (isAnvilTestChain(chainId)) {
280
+ // @note We make a time jump PAST the very first slot to not have to deal with the edge case of the first slot.
281
+ // The edge case being that the genesis block is already occupying slot 0, so we cannot have another block.
282
+ try {
283
+ // Need to get the time
284
+ const currentSlot = await rollup.getSlotNumber();
285
+
286
+ if (currentSlot === 0) {
287
+ const ts = Number(await rollup.getTimestampForSlot(SlotNumber(1)));
288
+ await rpcCall('evm_setNextBlockTimestamp', [ts]);
289
+ await rpcCall('hardhat_mine', [1]);
290
+ const currentSlot = await rollup.getSlotNumber();
291
+
292
+ if (currentSlot !== 1) {
293
+ throw new Error(`Error jumping time: current slot is ${currentSlot}`);
294
+ }
295
+ logger.info(`Jumped to slot 1`);
296
+ }
297
+ } catch (e) {
298
+ throw new Error(`Error jumping time: ${e}`);
299
+ }
300
+ }
301
+
302
+ return {
303
+ l1Client,
304
+ rollupVersion: result.rollupVersion,
305
+ l1ContractAddresses: {
306
+ rollupAddress: EthAddress.fromString(result.rollupAddress),
307
+ registryAddress: EthAddress.fromString(result.registryAddress),
308
+ inboxAddress: EthAddress.fromString(result.inboxAddress),
309
+ outboxAddress: EthAddress.fromString(result.outboxAddress),
310
+ feeJuiceAddress: EthAddress.fromString(result.feeAssetAddress),
311
+ feeJuicePortalAddress: EthAddress.fromString(result.feeJuicePortalAddress),
312
+ coinIssuerAddress: EthAddress.fromString(result.coinIssuerAddress),
313
+ rewardDistributorAddress: EthAddress.fromString(result.rewardDistributorAddress),
314
+ governanceProposerAddress: EthAddress.fromString(result.governanceProposerAddress),
315
+ governanceAddress: EthAddress.fromString(result.governanceAddress),
316
+ stakingAssetAddress: EthAddress.fromString(result.stakingAssetAddress),
317
+ slashFactoryAddress: result.slashFactoryAddress ? EthAddress.fromString(result.slashFactoryAddress) : undefined,
318
+ feeAssetHandlerAddress: result.feeAssetHandlerAddress
319
+ ? EthAddress.fromString(result.feeAssetHandlerAddress)
320
+ : undefined,
321
+ stakingAssetHandlerAddress: result.stakingAssetHandlerAddress
322
+ ? EthAddress.fromString(result.stakingAssetHandlerAddress)
323
+ : undefined,
324
+ zkPassportVerifierAddress: result.zkPassportVerifierAddress
325
+ ? EthAddress.fromString(result.zkPassportVerifierAddress)
326
+ : undefined,
327
+ gseAddress: result.gseAddress ? EthAddress.fromString(result.gseAddress) : undefined,
328
+ dateGatedRelayerAddress: result.dateGatedRelayerAddress
329
+ ? EthAddress.fromString(result.dateGatedRelayerAddress)
330
+ : undefined,
331
+ },
332
+ };
333
+ }
334
+
335
+ export const DEPLOYER_ADDRESS: Hex = '0x4e59b44847b379578588920cA78FbF26c0B4956C';
336
+
337
+ export type Operator = {
338
+ attester: EthAddress;
339
+ withdrawer: EthAddress;
340
+ bn254SecretKey: SecretValue<bigint>;
341
+ };
342
+
343
+ /**
344
+ * Return type of the deployAztecL1Contracts function.
345
+ */
346
+ export type DeployAztecL1ContractsReturnType = {
347
+ /** Extended Wallet Client Type. */
348
+ l1Client: ExtendedViemWalletClient;
349
+ /** The currently deployed l1 contract addresses */
350
+ l1ContractAddresses: L1ContractAddresses;
351
+ /** Version of the current rollup contract. */
352
+ rollupVersion: number;
353
+ };
354
+
355
+ export interface LinkReferences {
356
+ [fileName: string]: {
357
+ [contractName: string]: ReadonlyArray<{
358
+ start: number;
359
+ length: number;
360
+ }>;
361
+ };
362
+ }
363
+
364
+ export interface Libraries {
365
+ linkReferences: LinkReferences;
366
+ libraryCode: Record<string, ContractArtifacts>;
367
+ }
368
+
369
+ /**
370
+ * Contract artifacts
371
+ */
372
+ export interface ContractArtifacts<TAbi extends Abi | readonly unknown[] = Abi> {
373
+ /**
374
+ * The contract name.
375
+ */
376
+ name: string;
377
+ /**
378
+ * The contract abi.
379
+ */
380
+ contractAbi: Narrow<TAbi>;
381
+ /**
382
+ * The contract bytecode
383
+ */
384
+ contractBytecode: Hex;
385
+ /**
386
+ * The contract libraries
387
+ */
388
+ libraries?: Libraries;
389
+ }
390
+
391
+ export type VerificationLibraryEntry = {
392
+ file: string;
393
+ contract: string;
394
+ address: string;
395
+ };
396
+
397
+ export type VerificationRecord = {
398
+ name: string;
399
+ address: string;
400
+ constructorArgsHex: Hex;
401
+ libraries: VerificationLibraryEntry[];
402
+ };
403
+
404
+ export interface DeployAztecL1ContractsArgs extends Omit<L1ContractsConfig, keyof L1TxUtilsConfig> {
405
+ /** The vk tree root. */
406
+ vkTreeRoot: Fr;
407
+ /** The hash of the protocol contracts. */
408
+ protocolContractsHash: Fr;
409
+ /** The genesis root of the archive tree. */
410
+ genesisArchiveRoot: Fr;
411
+ /** The initial validators for the rollup contract. */
412
+ initialValidators?: Operator[];
413
+ /** The initial balance of the fee juice portal. This is the amount of fee juice that is prefunded to accounts */
414
+ feeJuicePortalInitialBalance?: bigint;
415
+ /** Whether to deploy the real verifier or the mock verifier */
416
+ realVerifier?: boolean;
417
+ /** The zk passport args */
418
+ zkPassportArgs?: ZKPassportArgs;
419
+ /** If provided, use this token for BOTH fee and staking assets (skip deployments) */
420
+ existingTokenAddress?: EthAddress;
421
+ }
422
+
423
+ export interface ZKPassportArgs {
424
+ /** The domain of the zk passport (url) */
425
+ zkPassportDomain?: string;
426
+ /** The scope of the zk passport (personhood, etc) */
427
+ zkPassportScope?: string;
428
+ }
429
+
430
+ // picked up by l1-contracts DeploymentConfiguration.sol
431
+ export function getDeployAztecL1ContractsEnvVars(args: DeployAztecL1ContractsArgs) {
432
+ return {
433
+ ...getDeployRollupForUpgradeEnvVars(args), // parsed by RollupConfiguration.sol
434
+ EXISTING_TOKEN_ADDRESS: args.existingTokenAddress?.toString(),
435
+ AZTEC_ACTIVATION_THRESHOLD: args.activationThreshold?.toString(),
436
+ AZTEC_EJECTION_THRESHOLD: args.ejectionThreshold?.toString(),
437
+ AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE: args.governanceProposerRoundSize?.toString(),
438
+ AZTEC_GOVERNANCE_PROPOSER_QUORUM: args.governanceProposerQuorum?.toString(),
439
+ ZKPASSPORT_DOMAIN: args.zkPassportArgs?.zkPassportDomain,
440
+ ZKPASSPORT_SCOPE: args.zkPassportArgs?.zkPassportScope,
441
+ } as const;
442
+ }
443
+
444
+ // picked up by l1-contracts RollupConfiguration.sol
445
+ export function getDeployRollupForUpgradeEnvVars(
446
+ args: Omit<
447
+ DeployAztecL1ContractsArgs,
448
+ | 'governanceProposerQuorum'
449
+ | 'governanceProposerRoundSize'
450
+ | 'ejectionThreshold'
451
+ | 'activationThreshold'
452
+ | 'getZkPassportArgs'
453
+ >,
454
+ ) {
455
+ return {
456
+ INITIAL_VALIDATORS: JSON.stringify((args.initialValidators ?? []).map(computeValidatorData)),
457
+ REAL_VERIFIER: args.realVerifier ? 'true' : 'false',
458
+ FEE_JUICE_PORTAL_INITIAL_BALANCE: (args.feeJuicePortalInitialBalance ?? 0n).toString(),
459
+ // Genesis state
460
+ VK_TREE_ROOT: args.vkTreeRoot.toString(),
461
+ PROTOCOL_CONTRACTS_HASH: args.protocolContractsHash.toString(),
462
+ GENESIS_ARCHIVE_ROOT: args.genesisArchiveRoot.toString(),
463
+ // Rollup config
464
+ AZTEC_SLOT_DURATION: args.aztecSlotDuration.toString(),
465
+ AZTEC_EPOCH_DURATION: args.aztecEpochDuration.toString(),
466
+ AZTEC_TARGET_COMMITTEE_SIZE: args.aztecTargetCommitteeSize.toString(),
467
+ AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET: args.lagInEpochsForValidatorSet.toString(),
468
+ AZTEC_LAG_IN_EPOCHS_FOR_RANDAO: args.lagInEpochsForRandao.toString(),
469
+ AZTEC_PROOF_SUBMISSION_EPOCHS: args.aztecProofSubmissionEpochs.toString(),
470
+ AZTEC_LOCAL_EJECTION_THRESHOLD: args.localEjectionThreshold.toString(),
471
+ AZTEC_SLASHING_LIFETIME_IN_ROUNDS: args.slashingLifetimeInRounds.toString(),
472
+ AZTEC_SLASHING_VETOER: args.slashingVetoer.toString(),
473
+ AZTEC_SLASHING_DISABLE_DURATION: args.slashingDisableDuration.toString(),
474
+ AZTEC_MANA_TARGET: args.manaTarget.toString(),
475
+ AZTEC_EXIT_DELAY_SECONDS: args.exitDelaySeconds.toString(),
476
+ AZTEC_PROVING_COST_PER_MANA: args.provingCostPerMana.toString(),
477
+ AZTEC_SLASHER_FLAVOR: args.slasherFlavor,
478
+ AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: args.slashingRoundSizeInEpochs.toString(),
479
+ AZTEC_SLASHING_QUORUM: args.slashingQuorum?.toString(),
480
+ AZTEC_SLASHING_OFFSET_IN_ROUNDS: args.slashingOffsetInRounds.toString(),
481
+ AZTEC_SLASH_AMOUNT_SMALL: args.slashAmountSmall.toString(),
482
+ AZTEC_SLASH_AMOUNT_MEDIUM: args.slashAmountMedium.toString(),
483
+ AZTEC_SLASH_AMOUNT_LARGE: args.slashAmountLarge.toString(),
484
+ } as const;
485
+ }
486
+
487
+ /**
488
+ * Deploys a new rollup, using the existing canonical version to derive certain values (addresses of assets etc).
489
+ */
490
+ export const deployRollupForUpgrade = async (
491
+ privateKey: `0x${string}`,
492
+ rpcUrl: string,
493
+ chainId: number,
494
+ registryAddress: EthAddress,
495
+ args: Omit<
496
+ DeployAztecL1ContractsArgs,
497
+ | 'governanceProposerQuorum'
498
+ | 'governanceProposerRoundSize'
499
+ | 'ejectionThreshold'
500
+ | 'activationThreshold'
501
+ | 'zkPassportArgs'
502
+ >,
503
+ ) => {
504
+ const currentDir = dirname(fileURLToPath(import.meta.url));
505
+
506
+ // Relative location of l1-contracts in monorepo or docker image.
507
+ const l1ContractsPath = resolve(currentDir, '..', '..', '..', 'l1-contracts');
508
+
509
+ const FORGE_SCRIPT = 'script/deploy/DeployRollupForUpgrade.s.sol';
510
+ await maybeForgeForceProductionBuild(l1ContractsPath, FORGE_SCRIPT, chainId);
511
+
512
+ const forgeArgs = [
513
+ 'script',
514
+ FORGE_SCRIPT,
515
+ '--sig',
516
+ 'run()',
517
+ '--private-key',
518
+ privateKey,
519
+ '--rpc-url',
520
+ rpcUrl,
521
+ '--broadcast',
522
+ ];
523
+ const forgeEnv = {
524
+ FOUNDRY_PROFILE: chainId === mainnet.id ? 'production' : undefined,
525
+ // Env vars required by l1-contracts/script/deploy/RollupConfiguration.sol.
526
+ REGISTRY_ADDRESS: registryAddress.toString(),
527
+ NETWORK: getActiveNetworkName(),
528
+ ...getDeployRollupForUpgradeEnvVars(args),
529
+ };
530
+
531
+ const result = await runProcess<ForgeRollupUpgradeResult>('forge', forgeArgs, forgeEnv, l1ContractsPath);
532
+ if (!result) {
533
+ throw new Error('Forge script did not output deployment result');
534
+ }
535
+
536
+ const extendedClient = createExtendedL1Client([rpcUrl], privateKey);
537
+
538
+ // Create RollupContract wrapper for the deployed rollup
539
+ const rollup = new RollupContract(extendedClient, result.rollupAddress);
540
+
541
+ return {
542
+ rollup,
543
+ slashFactoryAddress: result.slashFactoryAddress,
544
+ };
545
+ };