@aztec/cli 2.1.2 → 2.1.3

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,298 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/utils';
2
+ import { GSEContract, createEthereumChain } from '@aztec/ethereum';
3
+ import { computeBn254G1PublicKey, computeBn254G2PublicKey } from '@aztec/foundation/crypto';
4
+ import { decryptBn254Keystore } from '@aztec/foundation/crypto/bls/bn254_keystore';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import { Fr } from '@aztec/foundation/fields';
7
+ import type { LogFn } from '@aztec/foundation/log';
8
+ import { loadKeystoreFile } from '@aztec/node-keystore/loader';
9
+ import type {
10
+ AttesterAccount,
11
+ AttesterAccounts,
12
+ BLSAccount,
13
+ EncryptedKeyFileConfig,
14
+ EthAccount,
15
+ MnemonicConfig,
16
+ } from '@aztec/node-keystore/types';
17
+
18
+ import { Wallet } from '@ethersproject/wallet';
19
+ import { readFileSync, writeFileSync } from 'fs';
20
+ import { createPublicClient, fallback, http } from 'viem';
21
+ import { privateKeyToAddress } from 'viem/accounts';
22
+
23
+ export type StakerOptions = {
24
+ from: string;
25
+ password?: string;
26
+ output?: string;
27
+ gseAddress: EthAddress;
28
+ l1RpcUrls: string[];
29
+ l1ChainId: number;
30
+ };
31
+
32
+ export type StakerOutput = {
33
+ attester: string;
34
+ publicKeyG1: {
35
+ x: string;
36
+ y: string;
37
+ };
38
+ publicKeyG2: {
39
+ x0: string;
40
+ x1: string;
41
+ y0: string;
42
+ y1: string;
43
+ };
44
+ proofOfPossession: {
45
+ x: string;
46
+ y: string;
47
+ };
48
+ };
49
+
50
+ /**
51
+ * Check if an object is a MnemonicConfig
52
+ */
53
+ function isMnemonicConfig(obj: unknown): obj is MnemonicConfig {
54
+ return typeof obj === 'object' && obj !== null && 'mnemonic' in obj;
55
+ }
56
+
57
+ /**
58
+ * Check if a value is an encrypted keystore file config
59
+ */
60
+ function isEncryptedKeyFileConfig(value: unknown): value is EncryptedKeyFileConfig {
61
+ return typeof value === 'object' && value !== null && 'path' in value;
62
+ }
63
+
64
+ /**
65
+ * Check if a BLSAccount is a private key string (not an encrypted keystore file)
66
+ */
67
+ function isBlsPrivateKey(bls: unknown): bls is string {
68
+ return typeof bls === 'string' && bls.startsWith('0x');
69
+ }
70
+
71
+ /**
72
+ * Check if an EthAccount is a private key string (66 chars: 0x + 64 hex)
73
+ */
74
+ function isEthPrivateKey(eth: unknown): eth is string {
75
+ return typeof eth === 'string' && eth.startsWith('0x') && eth.length === 66;
76
+ }
77
+
78
+ /**
79
+ * Check if a string is an Ethereum address (42 chars: 0x + 40 hex)
80
+ */
81
+ function isEthAddress(value: unknown): value is string {
82
+ return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value);
83
+ }
84
+
85
+ /**
86
+ * Decrypt a BLS private key from an encrypted keystore file
87
+ */
88
+ function decryptBlsKey(bls: BLSAccount, password?: string): string | undefined {
89
+ if (isBlsPrivateKey(bls)) {
90
+ return bls;
91
+ }
92
+
93
+ if (isEncryptedKeyFileConfig(bls)) {
94
+ if (!password && !bls.password) {
95
+ return undefined; // Can't decrypt without password
96
+ }
97
+ const pwd = password ?? bls.password!;
98
+ return decryptBn254Keystore(bls.path, pwd);
99
+ }
100
+
101
+ return undefined;
102
+ }
103
+
104
+ /**
105
+ * Decrypt an Ethereum private key from an encrypted keystore file
106
+ */
107
+ async function decryptEthKey(eth: EthAccount, password?: string): Promise<string | undefined> {
108
+ if (isEthPrivateKey(eth)) {
109
+ return eth;
110
+ }
111
+
112
+ if (isEncryptedKeyFileConfig(eth)) {
113
+ if (!password && !eth.password) {
114
+ return undefined; // Can't decrypt without password
115
+ }
116
+ const pwd = password ?? eth.password!;
117
+ const json = readFileSync(eth.path, 'utf-8');
118
+ const wallet = await Wallet.fromEncryptedJson(json, pwd);
119
+ return wallet.privateKey as string;
120
+ }
121
+
122
+ return undefined;
123
+ }
124
+
125
+ /**
126
+ * Extract Ethereum address from an EthAccount (or private key)
127
+ */
128
+ async function getEthAddress(eth: EthAccount | string, password?: string): Promise<EthAddress | undefined> {
129
+ // Case 1: It's a private key string - derive the address
130
+ if (isEthPrivateKey(eth)) {
131
+ return privateKeyToAddress(eth as `0x${string}`) as unknown as EthAddress;
132
+ }
133
+
134
+ // Case 2: It's just an address string directly (EthRemoteSignerAccount can be just EthAddress)
135
+ if (isEthAddress(eth)) {
136
+ return eth as unknown as EthAddress;
137
+ }
138
+
139
+ // Case 3: It's an object with an address property (remote signer config)
140
+ if (typeof eth === 'object' && eth !== null && 'address' in eth) {
141
+ return (eth as any).address as EthAddress;
142
+ }
143
+
144
+ // Case 4: It's an encrypted keystore file - decrypt and derive address
145
+ if (isEncryptedKeyFileConfig(eth)) {
146
+ const privateKey = await decryptEthKey(eth, password);
147
+ if (privateKey) {
148
+ return privateKeyToAddress(privateKey as `0x${string}`) as unknown as EthAddress;
149
+ }
150
+ return undefined;
151
+ }
152
+
153
+ return undefined;
154
+ }
155
+
156
+ /**
157
+ * Extract BLS private key and Ethereum address from an AttesterAccount
158
+ */
159
+ async function extractAttesterInfo(
160
+ attester: AttesterAccount,
161
+ password?: string,
162
+ ): Promise<{ blsPrivateKey?: string; ethAddress?: EthAddress }> {
163
+ // Case 1: attester is { eth: EthAccount, bls?: BLSAccount }
164
+ if (typeof attester === 'object' && attester !== null && 'eth' in attester) {
165
+ const ethAddress = await getEthAddress(attester.eth, password);
166
+ const blsPrivateKey = attester.bls ? decryptBlsKey(attester.bls, password) : undefined;
167
+ return { blsPrivateKey, ethAddress };
168
+ }
169
+
170
+ // Case 2: attester is just an EthAccount directly (no BLS key)
171
+ return {
172
+ blsPrivateKey: undefined,
173
+ ethAddress: await getEthAddress(attester as EthAccount, password),
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Process a single attester entry and output staking JSON
179
+ */
180
+ async function processAttester(
181
+ attester: AttesterAccount,
182
+ gse: GSEContract,
183
+ password?: string,
184
+ ): Promise<StakerOutput | undefined> {
185
+ const { blsPrivateKey, ethAddress } = await extractAttesterInfo(attester, password);
186
+
187
+ // Skip if no BLS private key or no Ethereum address
188
+ if (!blsPrivateKey || !ethAddress) {
189
+ return undefined;
190
+ }
191
+
192
+ // Derive G1 and G2 public keys
193
+ const g1PublicKey = await computeBn254G1PublicKey(blsPrivateKey);
194
+ const g2PublicKey = await computeBn254G2PublicKey(blsPrivateKey);
195
+
196
+ // Generate proof of possession
197
+ const bn254SecretKeyFieldElement = Fr.fromString(blsPrivateKey);
198
+ const registrationTuple = await gse.makeRegistrationTuple(bn254SecretKeyFieldElement.toBigInt());
199
+
200
+ return {
201
+ attester: String(ethAddress),
202
+ publicKeyG1: {
203
+ x: '0x' + g1PublicKey.x.toString(16).padStart(64, '0'),
204
+ y: '0x' + g1PublicKey.y.toString(16).padStart(64, '0'),
205
+ },
206
+ publicKeyG2: {
207
+ x0: '0x' + g2PublicKey.x.c0.toString(16).padStart(64, '0'),
208
+ x1: '0x' + g2PublicKey.x.c1.toString(16).padStart(64, '0'),
209
+ y0: '0x' + g2PublicKey.y.c0.toString(16).padStart(64, '0'),
210
+ y1: '0x' + g2PublicKey.y.c1.toString(16).padStart(64, '0'),
211
+ },
212
+ proofOfPossession: {
213
+ x: '0x' + registrationTuple.proofOfPossession.x.toString(16),
214
+ y: '0x' + registrationTuple.proofOfPossession.y.toString(16),
215
+ },
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Process AttesterAccounts (which can be a single attester, array, or mnemonic)
221
+ */
222
+ export async function processAttesterAccounts(
223
+ attesterAccounts: AttesterAccounts,
224
+ gse: GSEContract,
225
+ password?: string,
226
+ ): Promise<StakerOutput[]> {
227
+ // Skip mnemonic configs
228
+ if (isMnemonicConfig(attesterAccounts)) {
229
+ return [];
230
+ }
231
+
232
+ // Handle array of attesters
233
+ if (Array.isArray(attesterAccounts)) {
234
+ const results: StakerOutput[] = [];
235
+ for (const attester of attesterAccounts) {
236
+ const result = await processAttester(attester, gse, password);
237
+ if (result) {
238
+ results.push(result);
239
+ }
240
+ }
241
+ return results;
242
+ }
243
+
244
+ // Handle single attester
245
+ const result = await processAttester(attesterAccounts, gse, password);
246
+ return result ? [result] : [];
247
+ }
248
+
249
+ /**
250
+ * Main staker command function
251
+ */
252
+ export async function generateStakerJson(options: StakerOptions, log: LogFn): Promise<void> {
253
+ const { from, password, gseAddress, l1RpcUrls, l1ChainId, output } = options;
254
+
255
+ // Load the keystore file
256
+ const keystore = loadKeystoreFile(from);
257
+
258
+ if (!gseAddress) {
259
+ throw new Error('GSE contract address is required');
260
+ }
261
+ log(`Calling GSE contract ${gseAddress} on chain ${l1ChainId}, using ${l1RpcUrls.join(', ')} to get staker outputs`);
262
+
263
+ if (!keystore.validators || keystore.validators.length === 0) {
264
+ log('No validators found in keystore');
265
+ return;
266
+ }
267
+
268
+ const allOutputs: StakerOutput[] = [];
269
+
270
+ // L1 client for proof of possession
271
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
272
+ const publicClient = createPublicClient({
273
+ chain: chain.chainInfo,
274
+ transport: fallback(l1RpcUrls.map(url => http(url))),
275
+ });
276
+ const gse = new GSEContract(publicClient, gseAddress);
277
+
278
+ // Process each validator
279
+ for (const validator of keystore.validators) {
280
+ const outputs = await processAttesterAccounts(validator.attester, gse, password);
281
+ allOutputs.push(...outputs);
282
+ }
283
+
284
+ if (allOutputs.length === 0) {
285
+ log('No attesters with BLS keys found (skipping mnemonics and encrypted keystores without password)');
286
+ return;
287
+ }
288
+
289
+ const jsonOutput = prettyPrintJSON(allOutputs);
290
+
291
+ // Write to file if output is specified, otherwise log to stdout
292
+ if (output) {
293
+ writeFileSync(output, jsonOutput, 'utf-8');
294
+ log(`Wrote staking data to ${output}`);
295
+ } else {
296
+ log(jsonOutput);
297
+ }
298
+ }
@@ -30,6 +30,7 @@ export type L2ChainConfig = L1ContractsConfig &
30
30
  autoUpdate: SharedNodeConfig['autoUpdate'];
31
31
  autoUpdateUrl?: string;
32
32
  maxTxPoolSize: number;
33
+ publicMetricsOptOut: boolean;
33
34
  publicIncludeMetrics?: string[];
34
35
  publicMetricsCollectorUrl?: string;
35
36
  publicMetricsCollectFrom?: string[];
@@ -107,7 +108,8 @@ export const stagingIgnitionL2ChainConfig: L2ChainConfig = {
107
108
  snapshotsUrls: [`${SNAPSHOTS_URL}/staging-ignition/`],
108
109
  autoUpdate: 'config-and-version',
109
110
  autoUpdateUrl: 'https://storage.googleapis.com/aztec-testnet/auto-update/staging-ignition.json',
110
- maxTxPoolSize: 100_000_000, // 100MB
111
+ maxTxPoolSize: 0,
112
+ publicMetricsOptOut: false,
111
113
  publicIncludeMetrics,
112
114
  publicMetricsCollectorUrl: 'https://telemetry.alpha-testnet.aztec-labs.com/v1/metrics',
113
115
  publicMetricsCollectFrom: ['sequencer'],
@@ -138,7 +140,7 @@ export const stagingIgnitionL2ChainConfig: L2ChainConfig = {
138
140
  slashAmountLarge: 50_000n * 10n ** 18n,
139
141
  slashingOffsetInRounds: 2,
140
142
  slasherFlavor: 'tally',
141
- slashingVetoer: EthAddress.ZERO, // TODO TMNT-329
143
+ slashingVetoer: EthAddress.ZERO,
142
144
 
143
145
  /** The mana target for the rollup */
144
146
  manaTarget: 0n,
@@ -189,6 +191,7 @@ export const stagingPublicL2ChainConfig: L2ChainConfig = {
189
191
  snapshotsUrls: [`${SNAPSHOTS_URL}/staging-public/`],
190
192
  autoUpdate: 'config-and-version',
191
193
  autoUpdateUrl: 'https://storage.googleapis.com/aztec-testnet/auto-update/staging-public.json',
194
+ publicMetricsOptOut: false,
192
195
  publicIncludeMetrics,
193
196
  publicMetricsCollectorUrl: 'https://telemetry.alpha-testnet.aztec-labs.com/v1/metrics',
194
197
  publicMetricsCollectFrom: ['sequencer'],
@@ -230,6 +233,61 @@ export const stagingPublicL2ChainConfig: L2ChainConfig = {
230
233
  ...DefaultNetworkDBMapSizeConfig,
231
234
  };
232
235
 
236
+ export const nextNetL2ChainConfig: L2ChainConfig = {
237
+ l1ChainId: 11155111,
238
+ testAccounts: true,
239
+ sponsoredFPC: true,
240
+ p2pEnabled: true,
241
+ disableTransactions: false,
242
+ p2pBootstrapNodes: [],
243
+ seqMinTxsPerBlock: 0,
244
+ seqMaxTxsPerBlock: 8,
245
+ realProofs: true,
246
+ snapshotsUrls: [],
247
+ autoUpdate: 'config-and-version',
248
+ autoUpdateUrl: '',
249
+ publicMetricsOptOut: true,
250
+ publicIncludeMetrics,
251
+ publicMetricsCollectorUrl: '',
252
+ publicMetricsCollectFrom: [''],
253
+ maxTxPoolSize: 100_000_000, // 100MB
254
+ txPoolDeleteTxsAfterReorg: false,
255
+
256
+ // Deployment stuff
257
+ /** How many seconds an L1 slot lasts. */
258
+ ethereumSlotDuration: 12,
259
+ /** How many seconds an L2 slots lasts (must be multiple of ethereum slot duration). */
260
+ aztecSlotDuration: 36,
261
+ /** How many L2 slots an epoch lasts. */
262
+ aztecEpochDuration: 32,
263
+ /** The target validator committee size. */
264
+ aztecTargetCommitteeSize: 48,
265
+ /** The number of epochs to lag behind the current epoch for validator selection. */
266
+ lagInEpochs: DefaultL1ContractsConfig.lagInEpochs,
267
+ /** The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup */
268
+ localEjectionThreshold: DefaultL1ContractsConfig.localEjectionThreshold,
269
+ /** The number of epochs after an epoch ends that proofs are still accepted. */
270
+ aztecProofSubmissionEpochs: 1,
271
+ /** The deposit amount for a validator */
272
+ activationThreshold: DefaultL1ContractsConfig.activationThreshold,
273
+ /** The minimum stake for a validator. */
274
+ ejectionThreshold: DefaultL1ContractsConfig.ejectionThreshold,
275
+ /** The slashing round size */
276
+ slashingRoundSizeInEpochs: DefaultL1ContractsConfig.slashingRoundSizeInEpochs,
277
+ /** Governance proposing round size */
278
+ governanceProposerRoundSize: DefaultL1ContractsConfig.governanceProposerRoundSize,
279
+ /** The mana target for the rollup */
280
+ manaTarget: DefaultL1ContractsConfig.manaTarget,
281
+ /** The proving cost per mana */
282
+ provingCostPerMana: DefaultL1ContractsConfig.provingCostPerMana,
283
+ /** Exit delay for stakers */
284
+ exitDelaySeconds: DefaultL1ContractsConfig.exitDelaySeconds,
285
+
286
+ ...DefaultSlashConfig,
287
+
288
+ ...DefaultNetworkDBMapSizeConfig,
289
+ };
290
+
233
291
  export const testnetL2ChainConfig: L2ChainConfig = {
234
292
  l1ChainId: 11155111,
235
293
  testAccounts: false,
@@ -244,6 +302,7 @@ export const testnetL2ChainConfig: L2ChainConfig = {
244
302
  autoUpdate: 'config-and-version',
245
303
  autoUpdateUrl: 'https://storage.googleapis.com/aztec-testnet/auto-update/testnet.json',
246
304
  maxTxPoolSize: 100_000_000, // 100MB
305
+ publicMetricsOptOut: false,
247
306
  publicIncludeMetrics,
248
307
  publicMetricsCollectorUrl: 'https://telemetry.alpha-testnet.aztec-labs.com/v1/metrics',
249
308
  publicMetricsCollectFrom: ['sequencer'],
@@ -333,10 +392,12 @@ export const mainnetL2ChainConfig: L2ChainConfig = {
333
392
  snapshotsUrls: [`${SNAPSHOTS_URL}/mainnet/`],
334
393
  autoUpdate: 'notify',
335
394
  autoUpdateUrl: 'https://storage.googleapis.com/aztec-mainnet/auto-update/mainnet.json',
336
- maxTxPoolSize: 100_000_000, // 100MB
395
+ maxTxPoolSize: 0,
396
+ publicMetricsOptOut: true,
337
397
  publicIncludeMetrics,
338
398
  publicMetricsCollectorUrl: 'https://telemetry.alpha-testnet.aztec-labs.com/v1/metrics',
339
399
  publicMetricsCollectFrom: ['sequencer'],
400
+ blobAllowEmptySources: true,
340
401
 
341
402
  /** How many seconds an L1 slot lasts. */
342
403
  ethereumSlotDuration: 12,
@@ -357,7 +418,7 @@ export const mainnetL2ChainConfig: L2ChainConfig = {
357
418
  slashingRoundSizeInEpochs: 4,
358
419
  slashingExecutionDelayInRounds: 28,
359
420
  slashingLifetimeInRounds: 34,
360
- slashingVetoer: EthAddress.ZERO, // TODO TMNT-329
421
+ slashingVetoer: EthAddress.fromString('0xBbB4aF368d02827945748b28CD4b2D42e4A37480'),
361
422
  slashingOffsetInRounds: 2,
362
423
 
363
424
  slashingDisableDuration: 259_200, // 3 days
@@ -404,6 +465,61 @@ export const mainnetL2ChainConfig: L2ChainConfig = {
404
465
  ...DefaultNetworkDBMapSizeConfig,
405
466
  };
406
467
 
468
+ export const devnetL2ChainConfig: L2ChainConfig = {
469
+ l1ChainId: 11155111,
470
+ testAccounts: true,
471
+ sponsoredFPC: true,
472
+ p2pEnabled: true,
473
+ disableTransactions: false,
474
+ p2pBootstrapNodes: [],
475
+ seqMinTxsPerBlock: 0,
476
+ seqMaxTxsPerBlock: 8,
477
+ realProofs: false,
478
+ snapshotsUrls: [],
479
+ autoUpdate: 'config-and-version',
480
+ autoUpdateUrl: '',
481
+ publicMetricsOptOut: true,
482
+ publicIncludeMetrics,
483
+ publicMetricsCollectorUrl: '',
484
+ publicMetricsCollectFrom: [''],
485
+ maxTxPoolSize: 100_000_000, // 100MB
486
+ txPoolDeleteTxsAfterReorg: true,
487
+
488
+ // Deployment stuff
489
+ /** How many seconds an L1 slot lasts. */
490
+ ethereumSlotDuration: 12,
491
+ /** How many seconds an L2 slots lasts (must be multiple of ethereum slot duration). */
492
+ aztecSlotDuration: 36,
493
+ /** How many L2 slots an epoch lasts. */
494
+ aztecEpochDuration: 8,
495
+ /** The target validator committee size. */
496
+ aztecTargetCommitteeSize: 1,
497
+ /** The number of epochs to lag behind the current epoch for validator selection. */
498
+ lagInEpochs: 1,
499
+ /** The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup */
500
+ localEjectionThreshold: DefaultL1ContractsConfig.localEjectionThreshold,
501
+ /** The number of epochs after an epoch ends that proofs are still accepted. */
502
+ aztecProofSubmissionEpochs: 1,
503
+ /** The deposit amount for a validator */
504
+ activationThreshold: DefaultL1ContractsConfig.activationThreshold,
505
+ /** The minimum stake for a validator. */
506
+ ejectionThreshold: DefaultL1ContractsConfig.ejectionThreshold,
507
+ /** The slashing round size */
508
+ slashingRoundSizeInEpochs: DefaultL1ContractsConfig.slashingRoundSizeInEpochs,
509
+ /** Governance proposing round size */
510
+ governanceProposerRoundSize: DefaultL1ContractsConfig.governanceProposerRoundSize,
511
+ /** The mana target for the rollup */
512
+ manaTarget: DefaultL1ContractsConfig.manaTarget,
513
+ /** The proving cost per mana */
514
+ provingCostPerMana: DefaultL1ContractsConfig.provingCostPerMana,
515
+ /** Exit delay for stakers */
516
+ exitDelaySeconds: DefaultL1ContractsConfig.exitDelaySeconds,
517
+
518
+ ...DefaultSlashConfig,
519
+
520
+ ...DefaultNetworkDBMapSizeConfig,
521
+ };
522
+
407
523
  export function getL2ChainConfig(networkName: NetworkNames): L2ChainConfig | undefined {
408
524
  let config: L2ChainConfig | undefined;
409
525
  if (networkName === 'staging-public') {
@@ -480,6 +596,8 @@ export function enrichEnvironmentWithChainConfig(networkName: NetworkNames) {
480
596
  enrichVar('PUBLIC_OTEL_COLLECT_FROM', config.publicMetricsCollectFrom.join(','));
481
597
  }
482
598
 
599
+ enrichVar('PUBLIC_OTEL_OPT_OUT', config.publicMetricsOptOut.toString());
600
+
483
601
  // Deployment stuff
484
602
  enrichVar('ETHEREUM_SLOT_DURATION', config.ethereumSlotDuration.toString());
485
603
  enrichVar('AZTEC_SLOT_DURATION', config.aztecSlotDuration.toString());