@aztec/aztec-node 0.0.1-commit.6b90f3f5 → 0.0.1-commit.6bd18f1aa

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.
@@ -1,14 +1,17 @@
1
1
  import { Archiver, createArchiver } from '@aztec/archiver';
2
- import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
2
+ import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
3
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
4
  import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
5
+ import { Blob } from '@aztec/blob-lib';
4
6
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
5
7
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
6
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
7
- import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
8
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
9
11
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
10
13
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
11
- import { compactArray, pick } from '@aztec/foundation/collection';
14
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
12
15
  import { Fr } from '@aztec/foundation/curves/bn254';
13
16
  import { EthAddress } from '@aztec/foundation/eth-address';
14
17
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -16,14 +19,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
16
19
  import { count } from '@aztec/foundation/string';
17
20
  import { DateProvider, Timer } from '@aztec/foundation/timer';
18
21
  import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
19
- import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
22
+ import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
20
23
  import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
24
+ import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
21
25
  import {
22
- createForwarderL1TxUtilsFromEthSigner,
23
- createL1TxUtilsWithBlobsFromEthSigner,
24
- } from '@aztec/node-lib/factories';
25
- import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
26
+ type P2P,
27
+ type P2PClientDeps,
28
+ createP2PClient,
29
+ createTxValidatorForAcceptingTxsOverRPC,
30
+ getDefaultAllowedSetupFunctions,
31
+ } from '@aztec/p2p';
26
32
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
33
+ import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
34
+ import { createKeyStoreForProver } from '@aztec/prover-node/config';
27
35
  import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
28
36
  import { PublicProcessorFactory } from '@aztec/simulator/server';
29
37
  import {
@@ -35,7 +43,14 @@ import {
35
43
  } from '@aztec/slasher';
36
44
  import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
37
45
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
38
- import { BlockHash, type BlockParameter, type DataInBlock, L2Block, type L2BlockSource } from '@aztec/stdlib/block';
46
+ import {
47
+ type BlockData,
48
+ BlockHash,
49
+ type BlockParameter,
50
+ type DataInBlock,
51
+ L2Block,
52
+ type L2BlockSource,
53
+ } from '@aztec/stdlib/block';
39
54
  import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
40
55
  import type {
41
56
  ContractClassPublic,
@@ -63,9 +78,9 @@ import {
63
78
  type WorldStateSynchronizer,
64
79
  tryStop,
65
80
  } from '@aztec/stdlib/interfaces/server';
66
- import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
81
+ import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
82
+ import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
67
83
  import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
68
- import { P2PClientType } from '@aztec/stdlib/p2p';
69
84
  import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
70
85
  import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
71
86
  import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
@@ -95,13 +110,13 @@ import {
95
110
  FullNodeCheckpointsBuilder,
96
111
  NodeKeystoreAdapter,
97
112
  ValidatorClient,
98
- createBlockProposalHandler,
113
+ createProposalHandler,
99
114
  createValidatorClient,
100
- createValidatorForAcceptingTxs,
101
115
  } from '@aztec/validator-client';
116
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
102
117
  import { createWorldStateSynchronizer } from '@aztec/world-state';
103
118
 
104
- import { createPublicClient, fallback, http } from 'viem';
119
+ import { createPublicClient } from 'viem';
105
120
 
106
121
  import { createSentinel } from '../sentinel/factory.js';
107
122
  import { Sentinel } from '../sentinel/sentinel.js';
@@ -129,6 +144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
129
144
  protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
130
145
  protected readonly worldStateSynchronizer: WorldStateSynchronizer,
131
146
  protected readonly sequencer: SequencerClient | undefined,
147
+ protected readonly proverNode: ProverNode | undefined,
132
148
  protected readonly slasherClient: SlasherClientInterface | undefined,
133
149
  protected readonly validatorsSentinel: Sentinel | undefined,
134
150
  protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
@@ -137,16 +153,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
137
153
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
138
154
  protected readonly epochCache: EpochCacheInterface,
139
155
  protected readonly packageVersion: string,
140
- private proofVerifier: ClientProtocolCircuitVerifier,
156
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
157
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
141
158
  private telemetry: TelemetryClient = getTelemetryClient(),
142
159
  private log = createLogger('node'),
143
160
  private blobClient?: BlobClientInterface,
161
+ private validatorClient?: ValidatorClient,
162
+ private keyStoreManager?: KeystoreManager,
163
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
144
164
  ) {
145
165
  this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
146
166
  this.tracer = telemetry.getTracer('AztecNodeService');
147
167
 
148
168
  this.log.info(`Aztec Node version: ${this.packageVersion}`);
149
169
  this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
170
+
171
+ // A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
172
+ // never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
173
+ // memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
174
+ if (debugLogStore.isEnabled && config.realProofs) {
175
+ throw new Error('debugLogStore should never be enabled when realProofs are set');
176
+ }
177
+ }
178
+
179
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
180
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
181
+ return this.rpcProofVerifier;
150
182
  }
151
183
 
152
184
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
@@ -170,11 +202,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
170
202
  logger?: Logger;
171
203
  publisher?: SequencerPublisher;
172
204
  dateProvider?: DateProvider;
173
- p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
205
+ p2pClientDeps?: P2PClientDeps;
206
+ proverNodeDeps?: Partial<ProverNodeDeps>;
207
+ slashingProtectionDb?: SlashingProtectionDatabase;
174
208
  } = {},
175
209
  options: {
176
210
  prefilledPublicData?: PublicDataTreeLeaf[];
177
211
  dontStartSequencer?: boolean;
212
+ dontStartProverNode?: boolean;
178
213
  } = {},
179
214
  ): Promise<AztecNodeService> {
180
215
  const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
@@ -184,16 +219,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
184
219
  const dateProvider = deps.dateProvider ?? new DateProvider();
185
220
  const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
186
221
 
187
- // Build a key store from file if given or from environment otherwise
222
+ // Build a key store from file if given or from environment otherwise.
223
+ // We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
188
224
  let keyStoreManager: KeystoreManager | undefined;
189
225
  const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
190
226
  if (keyStoreProvided) {
191
227
  const keyStores = loadKeystores(config.keyStoreDirectory!);
192
228
  keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
193
229
  } else {
194
- const keyStore = createKeyStoreForValidator(config);
195
- if (keyStore) {
196
- keyStoreManager = new KeystoreManager(keyStore);
230
+ const rawKeyStores: KeyStore[] = [];
231
+ const validatorKeyStore = createKeyStoreForValidator(config);
232
+ if (validatorKeyStore) {
233
+ rawKeyStores.push(validatorKeyStore);
234
+ }
235
+ if (config.enableProverNode) {
236
+ const proverKeyStore = createKeyStoreForProver(config);
237
+ if (proverKeyStore) {
238
+ rawKeyStores.push(proverKeyStore);
239
+ }
240
+ }
241
+ if (rawKeyStores.length > 0) {
242
+ keyStoreManager = new KeystoreManager(
243
+ rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
244
+ );
197
245
  }
198
246
  }
199
247
 
@@ -204,10 +252,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
204
252
  if (keyStoreManager === undefined) {
205
253
  throw new Error('Failed to create key store, a requirement for running a validator');
206
254
  }
207
- if (!keyStoreProvided) {
208
- log.warn(
209
- 'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
210
- );
255
+ if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
256
+ log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
211
257
  }
212
258
  ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
213
259
  }
@@ -221,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
221
267
 
222
268
  const publicClient = createPublicClient({
223
269
  chain: ethereumChain.chainInfo,
224
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
270
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
225
271
  pollingInterval: config.viemPollingIntervalMS,
226
272
  });
227
273
 
@@ -235,10 +281,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
235
281
  config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
236
282
 
237
283
  const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
238
- const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
284
+ const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
239
285
  rollupContract.getL1GenesisTime(),
240
286
  rollupContract.getSlotDuration(),
241
287
  rollupContract.getVersion(),
288
+ rollupContract.getManaLimit().then(Number),
242
289
  ] as const);
243
290
 
244
291
  config.rollupVersion ??= Number(rollupVersionFromRollup);
@@ -249,7 +296,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
249
296
  );
250
297
  }
251
298
 
252
- const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
299
+ const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
253
300
 
254
301
  // attempt snapshot sync if possible
255
302
  await trySnapshotSync(config, log);
@@ -269,21 +316,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
269
316
  options.prefilledPublicData,
270
317
  telemetry,
271
318
  );
272
- const circuitVerifier =
273
- config.realProofs || config.debugForceTxProofVerification
274
- ? await BBCircuitVerifier.new(config)
275
- : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
319
+ const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
320
+ let peerProofVerifier: ClientProtocolCircuitVerifier;
321
+ let rpcProofVerifier: ClientProtocolCircuitVerifier;
322
+ if (useRealVerifiers) {
323
+ peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
324
+ const rpcVerifier = await BBCircuitVerifier.new(config);
325
+ rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
326
+ } else {
327
+ peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
328
+ rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
329
+ }
330
+
331
+ let debugLogStore: DebugLogStore;
276
332
  if (!config.realProofs) {
277
333
  log.warn(`Aztec node is accepting fake proofs`);
334
+
335
+ debugLogStore = new InMemoryDebugLogStore();
336
+ log.info(
337
+ 'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
338
+ );
339
+ } else {
340
+ debugLogStore = new NullDebugLogStore();
341
+ }
342
+
343
+ const proverOnly = config.enableProverNode && config.disableValidator;
344
+ if (proverOnly) {
345
+ log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
278
346
  }
279
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
280
347
 
281
348
  // create the tx pool and the p2p client, which will need the l2 block source
282
349
  const p2pClient = await createP2PClient(
283
- P2PClientType.Full,
284
350
  config,
285
351
  archiver,
286
- proofVerifier,
352
+ peerProofVerifier,
287
353
  worldStateSynchronizer,
288
354
  epochCache,
289
355
  packageVersion,
@@ -292,59 +358,72 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
292
358
  deps.p2pClientDeps,
293
359
  );
294
360
 
295
- // We should really not be modifying the config object
296
- config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
361
+ // We'll accumulate sentinel watchers here
362
+ const watchers: Watcher[] = [];
297
363
 
298
- // Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
364
+ // Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
365
+ // Override maxTxsPerCheckpoint with the validator-specific limit if set.
299
366
  const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
300
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
367
+ {
368
+ ...config,
369
+ l1GenesisTime,
370
+ slotDuration: Number(slotDuration),
371
+ rollupManaLimit,
372
+ maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
373
+ },
301
374
  worldStateSynchronizer,
302
375
  archiver,
303
376
  dateProvider,
304
377
  telemetry,
305
378
  );
306
379
 
307
- // We'll accumulate sentinel watchers here
308
- const watchers: Watcher[] = [];
380
+ let validatorClient: ValidatorClient | undefined;
309
381
 
310
- // Create validator client if required
311
- const validatorClient = await createValidatorClient(config, {
312
- checkpointsBuilder: validatorCheckpointsBuilder,
313
- worldState: worldStateSynchronizer,
314
- p2pClient,
315
- telemetry,
316
- dateProvider,
317
- epochCache,
318
- blockSource: archiver,
319
- l1ToL2MessageSource: archiver,
320
- keyStoreManager,
321
- blobClient,
322
- });
382
+ if (!proverOnly) {
383
+ // Create validator client if required
384
+ validatorClient = await createValidatorClient(config, {
385
+ checkpointsBuilder: validatorCheckpointsBuilder,
386
+ worldState: worldStateSynchronizer,
387
+ p2pClient,
388
+ telemetry,
389
+ dateProvider,
390
+ epochCache,
391
+ blockSource: archiver,
392
+ l1ToL2MessageSource: archiver,
393
+ keyStoreManager,
394
+ blobClient,
395
+ slashingProtectionDb: deps.slashingProtectionDb,
396
+ });
323
397
 
324
- // If we have a validator client, register it as a source of offenses for the slasher,
325
- // and have it register callbacks on the p2p client *before* we start it, otherwise messages
326
- // like attestations or auths will fail.
327
- if (validatorClient) {
328
- watchers.push(validatorClient);
329
- if (!options.dontStartSequencer) {
330
- await validatorClient.registerHandlers();
398
+ // If we have a validator client, register it as a source of offenses for the slasher,
399
+ // and have it register callbacks on the p2p client *before* we start it, otherwise messages
400
+ // like attestations or auths will fail.
401
+ if (validatorClient) {
402
+ watchers.push(validatorClient);
403
+ if (!options.dontStartSequencer) {
404
+ await validatorClient.registerHandlers();
405
+ }
331
406
  }
332
407
  }
333
408
 
334
- // If there's no validator client but alwaysReexecuteBlockProposals is enabled,
335
- // create a BlockProposalHandler to reexecute block proposals for monitoring
336
- if (!validatorClient && config.alwaysReexecuteBlockProposals) {
337
- log.info('Setting up block proposal reexecution for monitoring');
338
- createBlockProposalHandler(config, {
409
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
410
+ // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
411
+ // while non-reexecution is used for validating the proposals and collecting their txs.
412
+ // Checkpoint proposals are handled if the blob client can upload blobs.
413
+ if (!validatorClient) {
414
+ const reexecute = !!config.alwaysReexecuteBlockProposals;
415
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
416
+ createProposalHandler(config, {
339
417
  checkpointsBuilder: validatorCheckpointsBuilder,
340
418
  worldState: worldStateSynchronizer,
341
419
  epochCache,
342
420
  blockSource: archiver,
343
421
  l1ToL2MessageSource: archiver,
344
422
  p2pClient,
423
+ blobClient,
345
424
  dateProvider,
346
425
  telemetry,
347
- }).registerForReexecution(p2pClient);
426
+ }).register(p2pClient, reexecute);
348
427
  }
349
428
 
350
429
  // Start world state and wait for it to sync to the archiver.
@@ -353,29 +432,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
353
432
  // Start p2p. Note that it depends on world state to be running.
354
433
  await p2pClient.start();
355
434
 
356
- const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
357
- if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
358
- watchers.push(validatorsSentinel);
359
- }
360
-
435
+ let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
361
436
  let epochPruneWatcher: EpochPruneWatcher | undefined;
362
- if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
363
- epochPruneWatcher = new EpochPruneWatcher(
364
- archiver,
365
- archiver,
366
- epochCache,
367
- p2pClient.getTxProvider(),
368
- validatorCheckpointsBuilder,
369
- config,
370
- );
371
- watchers.push(epochPruneWatcher);
372
- }
373
-
374
- // We assume we want to slash for invalid attestations unless all max penalties are set to 0
375
437
  let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
376
- if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
377
- attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
378
- watchers.push(attestationsBlockWatcher);
438
+
439
+ if (!proverOnly) {
440
+ validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
441
+ if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
442
+ watchers.push(validatorsSentinel);
443
+ }
444
+
445
+ if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
446
+ epochPruneWatcher = new EpochPruneWatcher(
447
+ archiver,
448
+ archiver,
449
+ epochCache,
450
+ p2pClient.getTxProvider(),
451
+ validatorCheckpointsBuilder,
452
+ config,
453
+ );
454
+ watchers.push(epochPruneWatcher);
455
+ }
456
+
457
+ // We assume we want to slash for invalid attestations unless all max penalties are set to 0
458
+ if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
459
+ attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
460
+ watchers.push(attestationsBlockWatcher);
461
+ }
379
462
  }
380
463
 
381
464
  // Start p2p-related services once the archiver has completed sync
@@ -390,6 +473,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
390
473
  })
391
474
  .catch(err => log.error('Failed to start p2p services after archiver sync', err));
392
475
 
476
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
477
+ l1Contracts: config.l1Contracts,
478
+ ethereumSlotDuration: config.ethereumSlotDuration,
479
+ rollupVersion: BigInt(config.rollupVersion),
480
+ l1GenesisTime,
481
+ slotDuration: Number(slotDuration),
482
+ });
483
+
393
484
  // Validator enabled, create/start relevant service
394
485
  let sequencer: SequencerClient | undefined;
395
486
  let slasherClient: SlasherClientInterface | undefined;
@@ -412,34 +503,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
412
503
  );
413
504
  await slasherClient.start();
414
505
 
415
- const l1TxUtils = config.publisherForwarderAddress
416
- ? await createForwarderL1TxUtilsFromEthSigner(
506
+ const l1TxUtils = config.sequencerPublisherForwarderAddress
507
+ ? await createForwarderL1TxUtilsFromSigners(
417
508
  publicClient,
418
509
  keyStoreManager!.createAllValidatorPublisherSigners(),
419
- config.publisherForwarderAddress,
510
+ config.sequencerPublisherForwarderAddress,
420
511
  { ...config, scope: 'sequencer' },
421
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
512
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
422
513
  )
423
- : await createL1TxUtilsWithBlobsFromEthSigner(
514
+ : await createL1TxUtilsFromSigners(
424
515
  publicClient,
425
516
  keyStoreManager!.createAllValidatorPublisherSigners(),
426
517
  { ...config, scope: 'sequencer' },
427
- { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
518
+ { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
428
519
  );
429
520
 
521
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
522
+ const fundingSigner = keyStoreManager?.createFundingSigner();
523
+ let funderL1TxUtils: L1TxUtils | undefined;
524
+ if (fundingSigner) {
525
+ const [funder] = await createL1TxUtilsFromSigners(
526
+ publicClient,
527
+ [fundingSigner],
528
+ { ...config, scope: 'sequencer' },
529
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
530
+ );
531
+ funderL1TxUtils = funder;
532
+ }
533
+
430
534
  // Create and start the sequencer client
431
535
  const checkpointsBuilder = new CheckpointsBuilder(
432
- { ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
536
+ { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
433
537
  worldStateSynchronizer,
434
538
  archiver,
435
539
  dateProvider,
436
540
  telemetry,
541
+ debugLogStore,
437
542
  );
438
543
 
439
544
  sequencer = await SequencerClient.new(config, {
440
545
  ...deps,
441
546
  epochCache,
442
547
  l1TxUtils,
548
+ funderL1TxUtils,
443
549
  validatorClient,
444
550
  p2pClient,
445
551
  worldStateSynchronizer,
@@ -451,6 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
451
557
  dateProvider,
452
558
  blobClient,
453
559
  nodeKeyStore: keyStoreManager!,
560
+ globalVariableBuilder,
454
561
  });
455
562
  }
456
563
 
@@ -461,14 +568,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
461
568
  log.warn(`Sequencer created but not started`);
462
569
  }
463
570
 
464
- const globalVariableBuilder = new GlobalVariableBuilder({
465
- ...config,
466
- rollupVersion: BigInt(config.rollupVersion),
467
- l1GenesisTime,
468
- slotDuration: Number(slotDuration),
469
- });
571
+ // Create prover node subsystem if enabled
572
+ let proverNode: ProverNode | undefined;
573
+ if (config.enableProverNode) {
574
+ proverNode = await createProverNode(config, {
575
+ ...deps.proverNodeDeps,
576
+ telemetry,
577
+ dateProvider,
578
+ archiver,
579
+ worldStateSynchronizer,
580
+ p2pClient,
581
+ epochCache,
582
+ blobClient,
583
+ keyStoreManager,
584
+ });
470
585
 
471
- return new AztecNodeService(
586
+ if (!options.dontStartProverNode) {
587
+ await proverNode.start();
588
+ log.info(`Prover node subsystem started`);
589
+ } else {
590
+ log.info(`Prover node subsystem created but not started`);
591
+ }
592
+ }
593
+
594
+ const node = new AztecNodeService(
472
595
  config,
473
596
  p2pClient,
474
597
  archiver,
@@ -477,6 +600,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
477
600
  archiver,
478
601
  worldStateSynchronizer,
479
602
  sequencer,
603
+ proverNode,
480
604
  slasherClient,
481
605
  validatorsSentinel,
482
606
  epochPruneWatcher,
@@ -485,11 +609,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
485
609
  globalVariableBuilder,
486
610
  epochCache,
487
611
  packageVersion,
488
- proofVerifier,
612
+ peerProofVerifier,
613
+ rpcProofVerifier,
489
614
  telemetry,
490
615
  log,
491
616
  blobClient,
617
+ validatorClient,
618
+ keyStoreManager,
619
+ debugLogStore,
492
620
  );
621
+
622
+ return node;
493
623
  }
494
624
 
495
625
  /**
@@ -500,6 +630,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
500
630
  return this.sequencer;
501
631
  }
502
632
 
633
+ /** Returns the prover node subsystem, if enabled. */
634
+ public getProverNode(): ProverNode | undefined {
635
+ return this.proverNode;
636
+ }
637
+
503
638
  public getBlockSource(): L2BlockSource {
504
639
  return this.blockSource;
505
640
  }
@@ -525,7 +660,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
525
660
  }
526
661
 
527
662
  public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
528
- return this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
663
+ return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
529
664
  }
530
665
 
531
666
  /**
@@ -553,6 +688,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
553
688
  enr,
554
689
  l1ContractAddresses: contractAddresses,
555
690
  protocolContractAddresses: protocolContractAddresses,
691
+ realProofs: !!this.config.realProofs,
556
692
  };
557
693
 
558
694
  return nodeInfo;
@@ -619,6 +755,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
619
755
  return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
620
756
  }
621
757
 
758
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
759
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
760
+ }
761
+
622
762
  /**
623
763
  * Method to fetch the current min L2 fees.
624
764
  * @returns The current min L2 fees.
@@ -651,6 +791,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
651
791
  return await this.blockSource.getCheckpointedL2BlockNumber();
652
792
  }
653
793
 
794
+ public getCheckpointNumber(): Promise<CheckpointNumber> {
795
+ return this.blockSource.getCheckpointNumber();
796
+ }
797
+
654
798
  /**
655
799
  * Method to fetch the version of the package.
656
800
  * @returns The node package version
@@ -688,18 +832,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
688
832
  page?: number,
689
833
  referenceBlock?: BlockHash,
690
834
  ): Promise<TxScopedL2Log[][]> {
835
+ let upToBlockNumber: BlockNumber | undefined;
691
836
  if (referenceBlock) {
692
837
  const initialBlockHash = await this.#getInitialHeaderHash();
693
- if (!referenceBlock.equals(initialBlockHash)) {
838
+ if (referenceBlock.equals(initialBlockHash)) {
839
+ upToBlockNumber = BlockNumber(0);
840
+ } else {
694
841
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
695
842
  if (!header) {
696
843
  throw new Error(
697
844
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
698
845
  );
699
846
  }
847
+ upToBlockNumber = header.globalVariables.blockNumber;
700
848
  }
701
849
  }
702
- return this.logsSource.getPrivateLogsByTags(tags, page);
850
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
703
851
  }
704
852
 
705
853
  public async getPublicLogsByTagsFromContract(
@@ -708,18 +856,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
708
856
  page?: number,
709
857
  referenceBlock?: BlockHash,
710
858
  ): Promise<TxScopedL2Log[][]> {
859
+ let upToBlockNumber: BlockNumber | undefined;
711
860
  if (referenceBlock) {
712
861
  const initialBlockHash = await this.#getInitialHeaderHash();
713
- if (!referenceBlock.equals(initialBlockHash)) {
862
+ if (referenceBlock.equals(initialBlockHash)) {
863
+ upToBlockNumber = BlockNumber(0);
864
+ } else {
714
865
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
715
866
  if (!header) {
716
867
  throw new Error(
717
868
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
718
869
  );
719
870
  }
871
+ upToBlockNumber = header.globalVariables.blockNumber;
720
872
  }
721
873
  }
722
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
874
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
723
875
  }
724
876
 
725
877
  /**
@@ -761,8 +913,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
761
913
  }
762
914
 
763
915
  await this.p2pClient!.sendTx(tx);
764
- this.metrics.receivedTx(timer.ms(), true);
765
- this.log.info(`Received tx ${txHash}`, { txHash });
916
+ const duration = timer.ms();
917
+ this.metrics.receivedTx(duration, true);
918
+ this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
766
919
  }
767
920
 
768
921
  public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
@@ -774,18 +927,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
774
927
  // Then get the actual tx from the archiver, which tracks every tx in a mined block.
775
928
  const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
776
929
 
930
+ let receipt: TxReceipt;
777
931
  if (settledTxReceipt) {
778
- // If the archiver has the receipt then return it.
779
- return settledTxReceipt;
932
+ receipt = settledTxReceipt;
780
933
  } else if (isKnownToPool) {
781
934
  // If the tx is in the pool but not in the archiver, it's pending.
782
935
  // This handles race conditions between archiver and p2p, where the archiver
783
936
  // has pruned the block in which a tx was mined, but p2p has not caught up yet.
784
- return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
937
+ receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
785
938
  } else {
786
939
  // Otherwise, if we don't know the tx, we consider it dropped.
787
- return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
940
+ receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
788
941
  }
942
+
943
+ this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
944
+
945
+ return receipt;
789
946
  }
790
947
 
791
948
  public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
@@ -800,8 +957,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
800
957
  await tryStop(this.validatorsSentinel);
801
958
  await tryStop(this.epochPruneWatcher);
802
959
  await tryStop(this.slasherClient);
803
- await tryStop(this.proofVerifier);
960
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
804
961
  await tryStop(this.sequencer);
962
+ await tryStop(this.proverNode);
805
963
  await tryStop(this.p2pClient);
806
964
  await tryStop(this.worldStateSynchronizer);
807
965
  await tryStop(this.blockSource);
@@ -851,84 +1009,98 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
851
1009
  }
852
1010
 
853
1011
  public async findLeavesIndexes(
854
- block: BlockParameter,
1012
+ referenceBlock: BlockParameter,
855
1013
  treeId: MerkleTreeId,
856
1014
  leafValues: Fr[],
857
1015
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
858
- const committedDb = await this.#getWorldState(block);
1016
+ const committedDb = await this.getWorldState(referenceBlock);
859
1017
  const maybeIndices = await committedDb.findLeafIndices(
860
1018
  treeId,
861
1019
  leafValues.map(x => x.toBuffer()),
862
1020
  );
863
- // We filter out undefined values
864
- const indices = maybeIndices.filter(x => x !== undefined) as bigint[];
1021
+ // Filter out undefined values to query block numbers only for found leaves
1022
+ const definedIndices = maybeIndices.filter(x => x !== undefined);
865
1023
 
866
- // Now we find the block numbers for the indices
867
- const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
1024
+ // Now we find the block numbers for the defined indices
1025
+ const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
868
1026
 
869
- // If any of the block numbers are undefined, we throw an error.
870
- for (let i = 0; i < indices.length; i++) {
871
- if (blockNumbers[i] === undefined) {
872
- throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
1027
+ // Build a map from leaf index to block number
1028
+ const indexToBlockNumber = new Map<bigint, BlockNumber>();
1029
+ for (let i = 0; i < definedIndices.length; i++) {
1030
+ const blockNumber = blockNumbers[i];
1031
+ if (blockNumber === undefined) {
1032
+ throw new Error(
1033
+ `Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
1034
+ );
873
1035
  }
1036
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
874
1037
  }
875
1038
 
876
1039
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
877
- const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
1040
+ const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
878
1041
 
879
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
880
- // (note that block number corresponds to the leaf index in the archive tree).
1042
+ // Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
881
1043
  const blockHashes = await Promise.all(
882
1044
  uniqueBlockNumbers.map(blockNumber => {
883
1045
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
884
1046
  }),
885
1047
  );
886
1048
 
887
- // If any of the block hashes are undefined, we throw an error.
1049
+ // Build a map from block number to block hash
1050
+ const blockNumberToHash = new Map<BlockNumber, Fr>();
888
1051
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
889
- if (blockHashes[i] === undefined) {
1052
+ const blockHash = blockHashes[i];
1053
+ if (blockHash === undefined) {
890
1054
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
891
1055
  }
1056
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
892
1057
  }
893
1058
 
894
1059
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
895
- return maybeIndices.map((index, i) => {
1060
+ return maybeIndices.map(index => {
896
1061
  if (index === undefined) {
897
1062
  return undefined;
898
1063
  }
899
- const blockNumber = blockNumbers[i];
1064
+ const blockNumber = indexToBlockNumber.get(index);
900
1065
  if (blockNumber === undefined) {
901
- return undefined;
1066
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
902
1067
  }
903
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
904
- const blockHash = blockHashes[blockHashIndex];
905
- if (!blockHash) {
906
- return undefined;
1068
+ const blockHash = blockNumberToHash.get(blockNumber);
1069
+ if (blockHash === undefined) {
1070
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
907
1071
  }
908
1072
  return {
909
- l2BlockNumber: BlockNumber(Number(blockNumber)),
1073
+ l2BlockNumber: blockNumber,
910
1074
  l2BlockHash: new BlockHash(blockHash),
911
1075
  data: index,
912
1076
  };
913
1077
  });
914
1078
  }
915
1079
 
916
- public async getArchiveMembershipWitness(
917
- block: BlockParameter,
918
- archive: Fr,
1080
+ public async getBlockHashMembershipWitness(
1081
+ referenceBlock: BlockParameter,
1082
+ blockHash: BlockHash,
919
1083
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
920
- const committedDb = await this.#getWorldState(block);
921
- const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
1084
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1085
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1086
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1087
+ const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1088
+ if (referenceBlockNumber === BlockNumber.ZERO) {
1089
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1090
+ return undefined;
1091
+ }
1092
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1093
+ const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
922
1094
  return pathAndIndex === undefined
923
1095
  ? undefined
924
1096
  : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
925
1097
  }
926
1098
 
927
1099
  public async getNoteHashMembershipWitness(
928
- block: BlockParameter,
1100
+ referenceBlock: BlockParameter,
929
1101
  noteHash: Fr,
930
1102
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
931
- const committedDb = await this.#getWorldState(block);
1103
+ const committedDb = await this.getWorldState(referenceBlock);
932
1104
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
933
1105
  MerkleTreeId.NOTE_HASH_TREE,
934
1106
  [noteHash],
@@ -939,10 +1111,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
939
1111
  }
940
1112
 
941
1113
  public async getL1ToL2MessageMembershipWitness(
942
- block: BlockParameter,
1114
+ referenceBlock: BlockParameter,
943
1115
  l1ToL2Message: Fr,
944
1116
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
945
- const db = await this.#getWorldState(block);
1117
+ const db = await this.getWorldState(referenceBlock);
946
1118
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
947
1119
  if (!witness) {
948
1120
  return undefined;
@@ -952,11 +1124,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
952
1124
  return [witness.index, witness.path];
953
1125
  }
954
1126
 
955
- public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
1127
+ public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
956
1128
  const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
957
- return messageIndex
958
- ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
959
- : undefined;
1129
+ return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
960
1130
  }
961
1131
 
962
1132
  /**
@@ -977,29 +1147,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
977
1147
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
978
1148
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
979
1149
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
980
- const blocksInCheckpoints: L2Block[][] = [];
981
- let previousSlotNumber = SlotNumber.ZERO;
982
- let checkpointIndex = -1;
983
- for (const checkpointedBlock of checkpointedBlocks) {
984
- const block = checkpointedBlock.block;
985
- const slotNumber = block.header.globalVariables.slotNumber;
986
- if (slotNumber !== previousSlotNumber) {
987
- checkpointIndex++;
988
- blocksInCheckpoints.push([]);
989
- previousSlotNumber = slotNumber;
990
- }
991
- blocksInCheckpoints[checkpointIndex].push(block);
992
- }
1150
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1151
+ group => group.map(cb => cb.block),
1152
+ );
993
1153
  return blocksInCheckpoints.map(blocks =>
994
1154
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
995
1155
  );
996
1156
  }
997
1157
 
998
1158
  public async getNullifierMembershipWitness(
999
- block: BlockParameter,
1159
+ referenceBlock: BlockParameter,
1000
1160
  nullifier: Fr,
1001
1161
  ): Promise<NullifierMembershipWitness | undefined> {
1002
- const db = await this.#getWorldState(block);
1162
+ const db = await this.getWorldState(referenceBlock);
1003
1163
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1004
1164
  if (!witness) {
1005
1165
  return undefined;
@@ -1014,32 +1174,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1014
1174
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1015
1175
  }
1016
1176
 
1017
- /**
1018
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1019
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1020
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1021
- * @returns The low nullifier membership witness (if found).
1022
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1023
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1024
- * we are trying to prove non-inclusion for.
1025
- *
1026
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1027
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1028
- * index of the nullifier itself when it already exists in the tree.
1029
- * TODO: This is a confusing behavior and we should eventually address that.
1030
- */
1031
1177
  public async getLowNullifierMembershipWitness(
1032
- block: BlockParameter,
1178
+ referenceBlock: BlockParameter,
1033
1179
  nullifier: Fr,
1034
1180
  ): Promise<NullifierMembershipWitness | undefined> {
1035
- const committedDb = await this.#getWorldState(block);
1181
+ const committedDb = await this.getWorldState(referenceBlock);
1036
1182
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1037
1183
  if (!findResult) {
1038
1184
  return undefined;
1039
1185
  }
1040
1186
  const { index, alreadyPresent } = findResult;
1041
1187
  if (alreadyPresent) {
1042
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1188
+ throw new Error(
1189
+ `Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
1190
+ );
1043
1191
  }
1044
1192
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1045
1193
 
@@ -1047,8 +1195,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1047
1195
  return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
1048
1196
  }
1049
1197
 
1050
- async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1051
- const committedDb = await this.#getWorldState(block);
1198
+ async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1199
+ const committedDb = await this.getWorldState(referenceBlock);
1052
1200
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1053
1201
  if (!lowLeafResult) {
1054
1202
  return undefined;
@@ -1062,8 +1210,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1062
1210
  }
1063
1211
  }
1064
1212
 
1065
- public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1066
- const committedDb = await this.#getWorldState(block);
1213
+ public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1214
+ const committedDb = await this.getWorldState(referenceBlock);
1067
1215
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1068
1216
 
1069
1217
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1104,6 +1252,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1104
1252
  return await this.blockSource.getBlockHeaderByArchive(archive);
1105
1253
  }
1106
1254
 
1255
+ public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
1256
+ return this.blockSource.getBlockData(number);
1257
+ }
1258
+
1259
+ public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
1260
+ return this.blockSource.getBlockDataByArchive(archive);
1261
+ }
1262
+
1107
1263
  /**
1108
1264
  * Simulates the public part of a transaction with the current state.
1109
1265
  * @param tx - The transaction to simulate.
@@ -1127,7 +1283,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1127
1283
  }
1128
1284
 
1129
1285
  const txHash = tx.getTxHash();
1130
- const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1286
+ const latestBlockNumber = await this.blockSource.getBlockNumber();
1287
+ const blockNumber = BlockNumber.add(latestBlockNumber, 1);
1131
1288
 
1132
1289
  // If sequencer is not initialized, we just set these values to zero for simulation.
1133
1290
  const coinbase = EthAddress.ZERO;
@@ -1151,6 +1308,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1151
1308
  blockNumber,
1152
1309
  });
1153
1310
 
1311
+ // Ensure world-state has caught up with the latest block we loaded from the archiver
1312
+ await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
1154
1313
  const merkleTreeFork = await this.worldStateSynchronizer.fork();
1155
1314
  try {
1156
1315
  const config = PublicSimulatorConfig.from({
@@ -1166,7 +1325,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1166
1325
  const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
1167
1326
 
1168
1327
  // REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
1169
- const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
1328
+ const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
1170
1329
  // REFACTOR: Consider returning the error rather than throwing
1171
1330
  if (failedTxs.length) {
1172
1331
  this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
@@ -1180,6 +1339,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1180
1339
  processedTx.txEffect,
1181
1340
  returns,
1182
1341
  processedTx.gasUsed,
1342
+ debugLogs,
1183
1343
  );
1184
1344
  } finally {
1185
1345
  await merkleTreeFork.close();
@@ -1191,12 +1351,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1191
1351
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1192
1352
  ): Promise<TxValidationResult> {
1193
1353
  const db = this.worldStateSynchronizer.getCommitted();
1194
- const verifier = isSimulation ? undefined : this.proofVerifier;
1354
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1195
1355
 
1196
- // We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
1356
+ // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1197
1357
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1198
1358
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1199
- const validator = createValidatorForAcceptingTxs(
1359
+ const l1Constants = await this.blockSource.getL1Constants();
1360
+ const validator = createTxValidatorForAcceptingTxsOverRPC(
1200
1361
  db,
1201
1362
  this.contractDataSource,
1202
1363
  verifier,
@@ -1205,10 +1366,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1205
1366
  blockNumber,
1206
1367
  l1ChainId: this.l1ChainId,
1207
1368
  rollupVersion: this.version,
1208
- setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
1369
+ setupAllowList: [
1370
+ ...(await getDefaultAllowedSetupFunctions()),
1371
+ ...(this.config.txPublicSetupAllowListExtend ?? []),
1372
+ ],
1209
1373
  gasFees: await this.getCurrentMinFees(),
1210
1374
  skipFeeEnforcement,
1211
1375
  txsPermitted: !this.config.disableTransactions,
1376
+ rollupManaLimit: l1Constants.rollupManaLimit,
1377
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1378
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1212
1379
  },
1213
1380
  this.log.getBindings(),
1214
1381
  );
@@ -1233,7 +1400,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1233
1400
  archiver.updateConfig(config);
1234
1401
  }
1235
1402
  if (newConfig.realProofs !== this.config.realProofs) {
1236
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1403
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
1404
+ if (newConfig.realProofs) {
1405
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1406
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1407
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1408
+ } else {
1409
+ this.peerProofVerifier = new TestCircuitVerifier();
1410
+ this.rpcProofVerifier = new TestCircuitVerifier();
1411
+ }
1237
1412
  }
1238
1413
 
1239
1414
  this.config = newConfig;
@@ -1375,6 +1550,94 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1375
1550
  }
1376
1551
  }
1377
1552
 
1553
+ public async reloadKeystore(): Promise<void> {
1554
+ if (!this.config.keyStoreDirectory?.length) {
1555
+ throw new BadRequestError(
1556
+ 'Cannot reload keystore: node is not using a file-based keystore. ' +
1557
+ 'Set KEY_STORE_DIRECTORY to use file-based keystores.',
1558
+ );
1559
+ }
1560
+ if (!this.validatorClient) {
1561
+ throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
1562
+ }
1563
+
1564
+ this.log.info('Reloading keystore from disk');
1565
+
1566
+ // Re-read and validate keystore files
1567
+ const keyStores = loadKeystores(this.config.keyStoreDirectory);
1568
+ const newManager = new KeystoreManager(mergeKeystores(keyStores));
1569
+ await newManager.validateSigners();
1570
+ ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
1571
+
1572
+ // Validate that every validator's publisher keys overlap with the L1 signers
1573
+ // that were initialized at startup. Publishers cannot be hot-reloaded, so a
1574
+ // validator with a publisher key that doesn't match any existing L1 signer
1575
+ // would silently fail on every proposer slot.
1576
+ if (this.keyStoreManager && this.sequencer) {
1577
+ const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
1578
+ const availablePublishers = new Set(
1579
+ oldAdapter
1580
+ .getAttesterAddresses()
1581
+ .flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
1582
+ );
1583
+
1584
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1585
+ for (const attester of newAdapter.getAttesterAddresses()) {
1586
+ const pubs = newAdapter.getPublisherAddresses(attester);
1587
+ if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
1588
+ throw new BadRequestError(
1589
+ `Cannot reload keystore: validator ${attester} has publisher keys ` +
1590
+ `[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
1591
+ `[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
1592
+ `use an existing publisher key or restart the node.`,
1593
+ );
1594
+ }
1595
+ }
1596
+ }
1597
+
1598
+ // Build adapters for old and new keystores to compute diff
1599
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
1600
+ const newAddresses = newAdapter.getAttesterAddresses();
1601
+ const oldAddresses = this.keyStoreManager
1602
+ ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
1603
+ : [];
1604
+
1605
+ const oldSet = new Set(oldAddresses.map(a => a.toString()));
1606
+ const newSet = new Set(newAddresses.map(a => a.toString()));
1607
+ const added = newAddresses.filter(a => !oldSet.has(a.toString()));
1608
+ const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
1609
+
1610
+ if (added.length > 0) {
1611
+ this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
1612
+ }
1613
+ if (removed.length > 0) {
1614
+ this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
1615
+ }
1616
+ if (added.length === 0 && removed.length === 0) {
1617
+ this.log.info('Keystore reload: attester keys unchanged');
1618
+ }
1619
+
1620
+ // Update the validator client (coinbase, feeRecipient, attester keys)
1621
+ this.validatorClient.reloadKeystore(newManager);
1622
+
1623
+ // Update the publisher factory's keystore so newly-added validators
1624
+ // can be matched to existing publisher keys when proposing blocks.
1625
+ if (this.sequencer) {
1626
+ this.sequencer.updatePublisherNodeKeyStore(newAdapter);
1627
+ }
1628
+
1629
+ // Update slasher's "don't-slash-self" list with new validator addresses
1630
+ if (this.slasherClient && !this.config.slashSelfAllowed) {
1631
+ const slashValidatorsNever = unique(
1632
+ [...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
1633
+ ).map(EthAddress.fromString);
1634
+ this.slasherClient.updateConfig({ slashValidatorsNever });
1635
+ }
1636
+
1637
+ this.keyStoreManager = newManager;
1638
+ this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
1639
+ }
1640
+
1378
1641
  #getInitialHeaderHash(): Promise<BlockHash> {
1379
1642
  if (!this.initialHeaderHashPromise) {
1380
1643
  this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
@@ -1387,7 +1650,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1387
1650
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1388
1651
  * @returns An instance of a committed MerkleTreeOperations
1389
1652
  */
1390
- async #getWorldState(block: BlockParameter) {
1653
+ protected async getWorldState(block: BlockParameter) {
1391
1654
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1392
1655
  try {
1393
1656
  // Attempt to sync the world state if necessary
@@ -1401,6 +1664,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1401
1664
  return this.worldStateSynchronizer.getCommitted();
1402
1665
  }
1403
1666
 
1667
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1668
+ let blockNumber: BlockNumber;
1404
1669
  if (BlockHash.isBlockHash(block)) {
1405
1670
  const initialBlockHash = await this.#getInitialHeaderHash();
1406
1671
  if (block.equals(initialBlockHash)) {
@@ -1414,22 +1679,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1414
1679
  `Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
1415
1680
  );
1416
1681
  }
1417
- const blockNumber = header.getBlockNumber();
1418
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1419
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1682
+
1683
+ blockNumber = header.getBlockNumber();
1684
+ } else {
1685
+ blockNumber = block as BlockNumber;
1686
+ }
1687
+
1688
+ // Check it's within world state sync range
1689
+ if (blockNumber > blockSyncedTo) {
1690
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1420
1691
  }
1692
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1421
1693
 
1422
- // Block number provided
1423
- {
1424
- const blockNumber = block as BlockNumber;
1694
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1425
1695
 
1426
- if (blockNumber > blockSyncedTo) {
1427
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1696
+ // Double-check world-state synced to the same block hash as was requested
1697
+ if (BlockHash.isBlockHash(block)) {
1698
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1699
+ if (!blockHash || !new BlockHash(blockHash).equals(block)) {
1700
+ throw new Error(
1701
+ `Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
1702
+ );
1428
1703
  }
1704
+ }
1705
+
1706
+ return snapshot;
1707
+ }
1429
1708
 
1430
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1431
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1709
+ /** Resolves a block parameter to a block number. */
1710
+ protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
1711
+ if (block === 'latest') {
1712
+ return BlockNumber(await this.blockSource.getBlockNumber());
1713
+ }
1714
+ if (BlockHash.isBlockHash(block)) {
1715
+ const initialBlockHash = await this.#getInitialHeaderHash();
1716
+ if (block.equals(initialBlockHash)) {
1717
+ return BlockNumber.ZERO;
1718
+ }
1719
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1720
+ if (!header) {
1721
+ throw new Error(`Block hash ${block.toString()} not found.`);
1722
+ }
1723
+ return header.getBlockNumber();
1432
1724
  }
1725
+ return block as BlockNumber;
1433
1726
  }
1434
1727
 
1435
1728
  /**