@aztec/aztec-node 0.0.1-commit.e2b2873ed → 0.0.1-commit.e304674f1

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