@aztec/aztec-node 0.0.1-commit.2c85e299c → 0.0.1-commit.2d9cb6034

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,15 +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';
4
5
  import { Blob } from '@aztec/blob-lib';
5
6
  import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
6
7
  import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
7
8
  import { createEthereumChain } from '@aztec/ethereum/chain';
8
- import { getPublicClient } from '@aztec/ethereum/client';
9
+ import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
9
10
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
10
11
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
12
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
11
13
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
12
- import { compactArray, pick, unique } from '@aztec/foundation/collection';
14
+ import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
13
15
  import { Fr } from '@aztec/foundation/curves/bn254';
14
16
  import { EthAddress } from '@aztec/foundation/eth-address';
15
17
  import { BadRequestError } from '@aztec/foundation/json-rpc';
@@ -108,12 +110,13 @@ import {
108
110
  FullNodeCheckpointsBuilder,
109
111
  NodeKeystoreAdapter,
110
112
  ValidatorClient,
111
- createBlockProposalHandler,
113
+ createProposalHandler,
112
114
  createValidatorClient,
113
115
  } from '@aztec/validator-client';
116
+ import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
114
117
  import { createWorldStateSynchronizer } from '@aztec/world-state';
115
118
 
116
- import { createPublicClient, fallback, http } from 'viem';
119
+ import { createPublicClient } from 'viem';
117
120
 
118
121
  import { createSentinel } from '../sentinel/factory.js';
119
122
  import { Sentinel } from '../sentinel/sentinel.js';
@@ -150,7 +153,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
150
153
  protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
151
154
  protected readonly epochCache: EpochCacheInterface,
152
155
  protected readonly packageVersion: string,
153
- private proofVerifier: ClientProtocolCircuitVerifier,
156
+ private peerProofVerifier: ClientProtocolCircuitVerifier,
157
+ private rpcProofVerifier: ClientProtocolCircuitVerifier,
154
158
  private telemetry: TelemetryClient = getTelemetryClient(),
155
159
  private log = createLogger('node'),
156
160
  private blobClient?: BlobClientInterface,
@@ -172,6 +176,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
172
176
  }
173
177
  }
174
178
 
179
+ /** @internal Exposed for testing — returns the RPC proof verifier. */
180
+ public getProofVerifier(): ClientProtocolCircuitVerifier {
181
+ return this.rpcProofVerifier;
182
+ }
183
+
175
184
  public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
176
185
  const status = await this.worldStateSynchronizer.status();
177
186
  return status.syncSummary;
@@ -195,6 +204,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
195
204
  dateProvider?: DateProvider;
196
205
  p2pClientDeps?: P2PClientDeps;
197
206
  proverNodeDeps?: Partial<ProverNodeDeps>;
207
+ slashingProtectionDb?: SlashingProtectionDatabase;
198
208
  } = {},
199
209
  options: {
200
210
  prefilledPublicData?: PublicDataTreeLeaf[];
@@ -257,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
257
267
 
258
268
  const publicClient = createPublicClient({
259
269
  chain: ethereumChain.chainInfo,
260
- transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
270
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
261
271
  pollingInterval: config.viemPollingIntervalMS,
262
272
  });
263
273
 
@@ -306,10 +316,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
306
316
  options.prefilledPublicData,
307
317
  telemetry,
308
318
  );
309
- const circuitVerifier =
310
- config.realProofs || config.debugForceTxProofVerification
311
- ? await BBCircuitVerifier.new(config)
312
- : 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
+ }
313
330
 
314
331
  let debugLogStore: DebugLogStore;
315
332
  if (!config.realProofs) {
@@ -323,8 +340,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
323
340
  debugLogStore = new NullDebugLogStore();
324
341
  }
325
342
 
326
- const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
327
-
328
343
  const proverOnly = config.enableProverNode && config.disableValidator;
329
344
  if (proverOnly) {
330
345
  log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
@@ -334,7 +349,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
334
349
  const p2pClient = await createP2PClient(
335
350
  config,
336
351
  archiver,
337
- proofVerifier,
352
+ peerProofVerifier,
338
353
  worldStateSynchronizer,
339
354
  epochCache,
340
355
  packageVersion,
@@ -377,6 +392,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
377
392
  l1ToL2MessageSource: archiver,
378
393
  keyStoreManager,
379
394
  blobClient,
395
+ slashingProtectionDb: deps.slashingProtectionDb,
380
396
  });
381
397
 
382
398
  // If we have a validator client, register it as a source of offenses for the slasher,
@@ -384,28 +400,35 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
384
400
  // like attestations or auths will fail.
385
401
  if (validatorClient) {
386
402
  watchers.push(validatorClient);
403
+
404
+ const vc = validatorClient;
405
+ const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
406
+ validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
407
+
387
408
  if (!options.dontStartSequencer) {
388
409
  await validatorClient.registerHandlers();
389
410
  }
390
411
  }
391
412
  }
392
413
 
393
- // If there's no validator client, create a BlockProposalHandler to handle block proposals
414
+ // If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
394
415
  // for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
395
416
  // while non-reexecution is used for validating the proposals and collecting their txs.
417
+ // Checkpoint proposals rebuild blobs if the blob client can upload blobs.
396
418
  if (!validatorClient) {
397
419
  const reexecute = !!config.alwaysReexecuteBlockProposals;
398
- log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
399
- createBlockProposalHandler(config, {
420
+ log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
421
+ createProposalHandler(config, {
400
422
  checkpointsBuilder: validatorCheckpointsBuilder,
401
423
  worldState: worldStateSynchronizer,
402
424
  epochCache,
403
425
  blockSource: archiver,
404
426
  l1ToL2MessageSource: archiver,
405
427
  p2pClient,
428
+ blobClient,
406
429
  dateProvider,
407
430
  telemetry,
408
- }).register(p2pClient, reexecute);
431
+ }).register(p2pClient, reexecute, archiver);
409
432
  }
410
433
 
411
434
  // Start world state and wait for it to sync to the archiver.
@@ -455,6 +478,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
455
478
  })
456
479
  .catch(err => log.error('Failed to start p2p services after archiver sync', err));
457
480
 
481
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
482
+ l1Contracts: config.l1Contracts,
483
+ ethereumSlotDuration: config.ethereumSlotDuration,
484
+ rollupVersion: BigInt(config.rollupVersion),
485
+ l1GenesisTime,
486
+ slotDuration: Number(slotDuration),
487
+ });
488
+
458
489
  // Validator enabled, create/start relevant service
459
490
  let sequencer: SequencerClient | undefined;
460
491
  let slasherClient: SlasherClientInterface | undefined;
@@ -492,6 +523,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
492
523
  { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
493
524
  );
494
525
 
526
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
527
+ const fundingSigner = keyStoreManager?.createFundingSigner();
528
+ let funderL1TxUtils: L1TxUtils | undefined;
529
+ if (fundingSigner) {
530
+ const [funder] = await createL1TxUtilsFromSigners(
531
+ publicClient,
532
+ [fundingSigner],
533
+ { ...config, scope: 'sequencer' },
534
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
535
+ );
536
+ funderL1TxUtils = funder;
537
+ }
538
+
495
539
  // Create and start the sequencer client
496
540
  const checkpointsBuilder = new CheckpointsBuilder(
497
541
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
@@ -506,6 +550,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
506
550
  ...deps,
507
551
  epochCache,
508
552
  l1TxUtils,
553
+ funderL1TxUtils,
509
554
  validatorClient,
510
555
  p2pClient,
511
556
  worldStateSynchronizer,
@@ -517,6 +562,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
517
562
  dateProvider,
518
563
  blobClient,
519
564
  nodeKeyStore: keyStoreManager!,
565
+ globalVariableBuilder,
520
566
  });
521
567
  }
522
568
 
@@ -550,13 +596,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
550
596
  }
551
597
  }
552
598
 
553
- const globalVariableBuilder = new GlobalVariableBuilder({
554
- ...config,
555
- rollupVersion: BigInt(config.rollupVersion),
556
- l1GenesisTime,
557
- slotDuration: Number(slotDuration),
558
- });
559
-
560
599
  const node = new AztecNodeService(
561
600
  config,
562
601
  p2pClient,
@@ -575,7 +614,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
575
614
  globalVariableBuilder,
576
615
  epochCache,
577
616
  packageVersion,
578
- proofVerifier,
617
+ peerProofVerifier,
618
+ rpcProofVerifier,
579
619
  telemetry,
580
620
  log,
581
621
  blobClient,
@@ -720,6 +760,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
720
760
  return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
721
761
  }
722
762
 
763
+ public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
764
+ return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
765
+ }
766
+
723
767
  /**
724
768
  * Method to fetch the current min L2 fees.
725
769
  * @returns The current min L2 fees.
@@ -793,18 +837,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
793
837
  page?: number,
794
838
  referenceBlock?: BlockHash,
795
839
  ): Promise<TxScopedL2Log[][]> {
840
+ let upToBlockNumber: BlockNumber | undefined;
796
841
  if (referenceBlock) {
797
842
  const initialBlockHash = await this.#getInitialHeaderHash();
798
- if (!referenceBlock.equals(initialBlockHash)) {
843
+ if (referenceBlock.equals(initialBlockHash)) {
844
+ upToBlockNumber = BlockNumber(0);
845
+ } else {
799
846
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
800
847
  if (!header) {
801
848
  throw new Error(
802
849
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
803
850
  );
804
851
  }
852
+ upToBlockNumber = header.globalVariables.blockNumber;
805
853
  }
806
854
  }
807
- return this.logsSource.getPrivateLogsByTags(tags, page);
855
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
808
856
  }
809
857
 
810
858
  public async getPublicLogsByTagsFromContract(
@@ -813,18 +861,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
813
861
  page?: number,
814
862
  referenceBlock?: BlockHash,
815
863
  ): Promise<TxScopedL2Log[][]> {
864
+ let upToBlockNumber: BlockNumber | undefined;
816
865
  if (referenceBlock) {
817
866
  const initialBlockHash = await this.#getInitialHeaderHash();
818
- if (!referenceBlock.equals(initialBlockHash)) {
867
+ if (referenceBlock.equals(initialBlockHash)) {
868
+ upToBlockNumber = BlockNumber(0);
869
+ } else {
819
870
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
820
871
  if (!header) {
821
872
  throw new Error(
822
873
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
823
874
  );
824
875
  }
876
+ upToBlockNumber = header.globalVariables.blockNumber;
825
877
  }
826
878
  }
827
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
879
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
828
880
  }
829
881
 
830
882
  /**
@@ -910,7 +962,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
910
962
  await tryStop(this.validatorsSentinel);
911
963
  await tryStop(this.epochPruneWatcher);
912
964
  await tryStop(this.slasherClient);
913
- await tryStop(this.proofVerifier);
965
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
914
966
  await tryStop(this.sequencer);
915
967
  await tryStop(this.proverNode);
916
968
  await tryStop(this.p2pClient);
@@ -966,58 +1018,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
966
1018
  treeId: MerkleTreeId,
967
1019
  leafValues: Fr[],
968
1020
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
969
- const committedDb = await this.#getWorldState(referenceBlock);
1021
+ const committedDb = await this.getWorldState(referenceBlock);
970
1022
  const maybeIndices = await committedDb.findLeafIndices(
971
1023
  treeId,
972
1024
  leafValues.map(x => x.toBuffer()),
973
1025
  );
974
- // We filter out undefined values
975
- const indices = maybeIndices.filter(x => x !== undefined) as bigint[];
1026
+ // Filter out undefined values to query block numbers only for found leaves
1027
+ const definedIndices = maybeIndices.filter(x => x !== undefined);
976
1028
 
977
- // Now we find the block numbers for the indices
978
- const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
1029
+ // Now we find the block numbers for the defined indices
1030
+ const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
979
1031
 
980
- // If any of the block numbers are undefined, we throw an error.
981
- for (let i = 0; i < indices.length; i++) {
982
- if (blockNumbers[i] === undefined) {
983
- throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
1032
+ // Build a map from leaf index to block number
1033
+ const indexToBlockNumber = new Map<bigint, BlockNumber>();
1034
+ for (let i = 0; i < definedIndices.length; i++) {
1035
+ const blockNumber = blockNumbers[i];
1036
+ if (blockNumber === undefined) {
1037
+ throw new Error(
1038
+ `Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
1039
+ );
984
1040
  }
1041
+ indexToBlockNumber.set(definedIndices[i], blockNumber);
985
1042
  }
986
1043
 
987
1044
  // Get unique block numbers in order to optimize num calls to getLeafValue function.
988
- const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
1045
+ const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
989
1046
 
990
- // Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
991
- // (note that block number corresponds to the leaf index in the archive tree).
1047
+ // Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
992
1048
  const blockHashes = await Promise.all(
993
1049
  uniqueBlockNumbers.map(blockNumber => {
994
1050
  return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
995
1051
  }),
996
1052
  );
997
1053
 
998
- // If any of the block hashes are undefined, we throw an error.
1054
+ // Build a map from block number to block hash
1055
+ const blockNumberToHash = new Map<BlockNumber, Fr>();
999
1056
  for (let i = 0; i < uniqueBlockNumbers.length; i++) {
1000
- if (blockHashes[i] === undefined) {
1057
+ const blockHash = blockHashes[i];
1058
+ if (blockHash === undefined) {
1001
1059
  throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
1002
1060
  }
1061
+ blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
1003
1062
  }
1004
1063
 
1005
1064
  // Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
1006
- return maybeIndices.map((index, i) => {
1065
+ return maybeIndices.map(index => {
1007
1066
  if (index === undefined) {
1008
1067
  return undefined;
1009
1068
  }
1010
- const blockNumber = blockNumbers[i];
1069
+ const blockNumber = indexToBlockNumber.get(index);
1011
1070
  if (blockNumber === undefined) {
1012
- return undefined;
1071
+ throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
1013
1072
  }
1014
- const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
1015
- const blockHash = blockHashes[blockHashIndex];
1016
- if (!blockHash) {
1017
- return undefined;
1073
+ const blockHash = blockNumberToHash.get(blockNumber);
1074
+ if (blockHash === undefined) {
1075
+ throw new Error(`Block hash not found for block number ${blockNumber}`);
1018
1076
  }
1019
1077
  return {
1020
- l2BlockNumber: BlockNumber(Number(blockNumber)),
1078
+ l2BlockNumber: blockNumber,
1021
1079
  l2BlockHash: new BlockHash(blockHash),
1022
1080
  data: index,
1023
1081
  };
@@ -1028,7 +1086,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1028
1086
  referenceBlock: BlockParameter,
1029
1087
  blockHash: BlockHash,
1030
1088
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
1031
- const committedDb = await this.#getWorldState(referenceBlock);
1089
+ // The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
1090
+ // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1091
+ // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1092
+ const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1093
+ if (referenceBlockNumber === BlockNumber.ZERO) {
1094
+ // Block 0 (the initial block) has an empty archive, so no membership witness can exist.
1095
+ return undefined;
1096
+ }
1097
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1032
1098
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
1033
1099
  return pathAndIndex === undefined
1034
1100
  ? undefined
@@ -1039,7 +1105,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1039
1105
  referenceBlock: BlockParameter,
1040
1106
  noteHash: Fr,
1041
1107
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
1042
- const committedDb = await this.#getWorldState(referenceBlock);
1108
+ const committedDb = await this.getWorldState(referenceBlock);
1043
1109
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
1044
1110
  MerkleTreeId.NOTE_HASH_TREE,
1045
1111
  [noteHash],
@@ -1053,7 +1119,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1053
1119
  referenceBlock: BlockParameter,
1054
1120
  l1ToL2Message: Fr,
1055
1121
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
1056
- const db = await this.#getWorldState(referenceBlock);
1122
+ const db = await this.getWorldState(referenceBlock);
1057
1123
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
1058
1124
  if (!witness) {
1059
1125
  return undefined;
@@ -1086,19 +1152,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1086
1152
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1087
1153
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1088
1154
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1089
- const blocksInCheckpoints: L2Block[][] = [];
1090
- let previousSlotNumber = SlotNumber.ZERO;
1091
- let checkpointIndex = -1;
1092
- for (const checkpointedBlock of checkpointedBlocks) {
1093
- const block = checkpointedBlock.block;
1094
- const slotNumber = block.header.globalVariables.slotNumber;
1095
- if (slotNumber !== previousSlotNumber) {
1096
- checkpointIndex++;
1097
- blocksInCheckpoints.push([]);
1098
- previousSlotNumber = slotNumber;
1099
- }
1100
- blocksInCheckpoints[checkpointIndex].push(block);
1101
- }
1155
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1156
+ group => group.map(cb => cb.block),
1157
+ );
1102
1158
  return blocksInCheckpoints.map(blocks =>
1103
1159
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1104
1160
  );
@@ -1108,7 +1164,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1108
1164
  referenceBlock: BlockParameter,
1109
1165
  nullifier: Fr,
1110
1166
  ): Promise<NullifierMembershipWitness | undefined> {
1111
- const db = await this.#getWorldState(referenceBlock);
1167
+ const db = await this.getWorldState(referenceBlock);
1112
1168
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1113
1169
  if (!witness) {
1114
1170
  return undefined;
@@ -1123,33 +1179,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1123
1179
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1124
1180
  }
1125
1181
 
1126
- /**
1127
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1128
- * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1129
- * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1130
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1131
- * @returns The low nullifier membership witness (if found).
1132
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1133
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1134
- * we are trying to prove non-inclusion for.
1135
- *
1136
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1137
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1138
- * index of the nullifier itself when it already exists in the tree.
1139
- * TODO: This is a confusing behavior and we should eventually address that.
1140
- */
1141
1182
  public async getLowNullifierMembershipWitness(
1142
1183
  referenceBlock: BlockParameter,
1143
1184
  nullifier: Fr,
1144
1185
  ): Promise<NullifierMembershipWitness | undefined> {
1145
- const committedDb = await this.#getWorldState(referenceBlock);
1186
+ const committedDb = await this.getWorldState(referenceBlock);
1146
1187
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1147
1188
  if (!findResult) {
1148
1189
  return undefined;
1149
1190
  }
1150
1191
  const { index, alreadyPresent } = findResult;
1151
1192
  if (alreadyPresent) {
1152
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1193
+ throw new Error(
1194
+ `Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
1195
+ );
1153
1196
  }
1154
1197
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1155
1198
 
@@ -1158,7 +1201,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1158
1201
  }
1159
1202
 
1160
1203
  async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1161
- const committedDb = await this.#getWorldState(referenceBlock);
1204
+ const committedDb = await this.getWorldState(referenceBlock);
1162
1205
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1163
1206
  if (!lowLeafResult) {
1164
1207
  return undefined;
@@ -1173,7 +1216,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1173
1216
  }
1174
1217
 
1175
1218
  public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1176
- const committedDb = await this.#getWorldState(referenceBlock);
1219
+ const committedDb = await this.getWorldState(referenceBlock);
1177
1220
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1178
1221
 
1179
1222
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1313,11 +1356,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1313
1356
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1314
1357
  ): Promise<TxValidationResult> {
1315
1358
  const db = this.worldStateSynchronizer.getCommitted();
1316
- const verifier = isSimulation ? undefined : this.proofVerifier;
1359
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1317
1360
 
1318
1361
  // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1319
1362
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
1320
1363
  const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
1364
+ const l1Constants = await this.blockSource.getL1Constants();
1321
1365
  const validator = createTxValidatorForAcceptingTxsOverRPC(
1322
1366
  db,
1323
1367
  this.contractDataSource,
@@ -1334,6 +1378,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1334
1378
  gasFees: await this.getCurrentMinFees(),
1335
1379
  skipFeeEnforcement,
1336
1380
  txsPermitted: !this.config.disableTransactions,
1381
+ rollupManaLimit: l1Constants.rollupManaLimit,
1382
+ maxBlockL2Gas: this.config.validateMaxL2BlockGas,
1383
+ maxBlockDAGas: this.config.validateMaxDABlockGas,
1337
1384
  },
1338
1385
  this.log.getBindings(),
1339
1386
  );
@@ -1358,7 +1405,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1358
1405
  archiver.updateConfig(config);
1359
1406
  }
1360
1407
  if (newConfig.realProofs !== this.config.realProofs) {
1361
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1408
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
1409
+ if (newConfig.realProofs) {
1410
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1411
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1412
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1413
+ } else {
1414
+ this.peerProofVerifier = new TestCircuitVerifier();
1415
+ this.rpcProofVerifier = new TestCircuitVerifier();
1416
+ }
1362
1417
  }
1363
1418
 
1364
1419
  this.config = newConfig;
@@ -1600,7 +1655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1600
1655
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1601
1656
  * @returns An instance of a committed MerkleTreeOperations
1602
1657
  */
1603
- async #getWorldState(block: BlockParameter) {
1658
+ protected async getWorldState(block: BlockParameter) {
1604
1659
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1605
1660
  try {
1606
1661
  // Attempt to sync the world state if necessary
@@ -1614,6 +1669,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1614
1669
  return this.worldStateSynchronizer.getCommitted();
1615
1670
  }
1616
1671
 
1672
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1673
+ let blockNumber: BlockNumber;
1617
1674
  if (BlockHash.isBlockHash(block)) {
1618
1675
  const initialBlockHash = await this.#getInitialHeaderHash();
1619
1676
  if (block.equals(initialBlockHash)) {
@@ -1627,22 +1684,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1627
1684
  `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.`,
1628
1685
  );
1629
1686
  }
1630
- const blockNumber = header.getBlockNumber();
1631
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1632
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1687
+
1688
+ blockNumber = header.getBlockNumber();
1689
+ } else {
1690
+ blockNumber = block as BlockNumber;
1691
+ }
1692
+
1693
+ // Check it's within world state sync range
1694
+ if (blockNumber > blockSyncedTo) {
1695
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1633
1696
  }
1697
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1634
1698
 
1635
- // Block number provided
1636
- {
1637
- const blockNumber = block as BlockNumber;
1699
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1638
1700
 
1639
- if (blockNumber > blockSyncedTo) {
1640
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1701
+ // Double-check world-state synced to the same block hash as was requested
1702
+ if (BlockHash.isBlockHash(block)) {
1703
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1704
+ if (!blockHash || !new BlockHash(blockHash).equals(block)) {
1705
+ throw new Error(
1706
+ `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.`,
1707
+ );
1641
1708
  }
1709
+ }
1642
1710
 
1643
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1644
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1711
+ return snapshot;
1712
+ }
1713
+
1714
+ /** Resolves a block parameter to a block number. */
1715
+ protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
1716
+ if (block === 'latest') {
1717
+ return BlockNumber(await this.blockSource.getBlockNumber());
1718
+ }
1719
+ if (BlockHash.isBlockHash(block)) {
1720
+ const initialBlockHash = await this.#getInitialHeaderHash();
1721
+ if (block.equals(initialBlockHash)) {
1722
+ return BlockNumber.ZERO;
1723
+ }
1724
+ const header = await this.blockSource.getBlockHeaderByHash(block);
1725
+ if (!header) {
1726
+ throw new Error(`Block hash ${block.toString()} not found.`);
1727
+ }
1728
+ return header.getBlockNumber();
1645
1729
  }
1730
+ return block as BlockNumber;
1646
1731
  }
1647
1732
 
1648
1733
  /**