@aztec/aztec-node 0.0.1-commit.381b1a9 → 0.0.1-commit.3a4ae741b

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';
@@ -111,9 +113,10 @@ import {
111
113
  createBlockProposalHandler,
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,
@@ -455,6 +471,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
455
471
  })
456
472
  .catch(err => log.error('Failed to start p2p services after archiver sync', err));
457
473
 
474
+ const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
475
+ l1Contracts: config.l1Contracts,
476
+ ethereumSlotDuration: config.ethereumSlotDuration,
477
+ rollupVersion: BigInt(config.rollupVersion),
478
+ l1GenesisTime,
479
+ slotDuration: Number(slotDuration),
480
+ });
481
+
458
482
  // Validator enabled, create/start relevant service
459
483
  let sequencer: SequencerClient | undefined;
460
484
  let slasherClient: SlasherClientInterface | undefined;
@@ -492,6 +516,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
492
516
  { telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
493
517
  );
494
518
 
519
+ // Create a funder L1TxUtils from the keystore funding account (if configured)
520
+ const fundingSigner = keyStoreManager?.createFundingSigner();
521
+ let funderL1TxUtils: L1TxUtils | undefined;
522
+ if (fundingSigner) {
523
+ const [funder] = await createL1TxUtilsFromSigners(
524
+ publicClient,
525
+ [fundingSigner],
526
+ { ...config, scope: 'sequencer' },
527
+ { telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
528
+ );
529
+ funderL1TxUtils = funder;
530
+ }
531
+
495
532
  // Create and start the sequencer client
496
533
  const checkpointsBuilder = new CheckpointsBuilder(
497
534
  { ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
@@ -506,6 +543,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
506
543
  ...deps,
507
544
  epochCache,
508
545
  l1TxUtils,
546
+ funderL1TxUtils,
509
547
  validatorClient,
510
548
  p2pClient,
511
549
  worldStateSynchronizer,
@@ -517,6 +555,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
517
555
  dateProvider,
518
556
  blobClient,
519
557
  nodeKeyStore: keyStoreManager!,
558
+ globalVariableBuilder,
520
559
  });
521
560
  }
522
561
 
@@ -550,13 +589,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
550
589
  }
551
590
  }
552
591
 
553
- const globalVariableBuilder = new GlobalVariableBuilder({
554
- ...config,
555
- rollupVersion: BigInt(config.rollupVersion),
556
- l1GenesisTime,
557
- slotDuration: Number(slotDuration),
558
- });
559
-
560
592
  const node = new AztecNodeService(
561
593
  config,
562
594
  p2pClient,
@@ -575,7 +607,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
575
607
  globalVariableBuilder,
576
608
  epochCache,
577
609
  packageVersion,
578
- proofVerifier,
610
+ peerProofVerifier,
611
+ rpcProofVerifier,
579
612
  telemetry,
580
613
  log,
581
614
  blobClient,
@@ -797,18 +830,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
797
830
  page?: number,
798
831
  referenceBlock?: BlockHash,
799
832
  ): Promise<TxScopedL2Log[][]> {
833
+ let upToBlockNumber: BlockNumber | undefined;
800
834
  if (referenceBlock) {
801
835
  const initialBlockHash = await this.#getInitialHeaderHash();
802
- if (!referenceBlock.equals(initialBlockHash)) {
836
+ if (referenceBlock.equals(initialBlockHash)) {
837
+ upToBlockNumber = BlockNumber(0);
838
+ } else {
803
839
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
804
840
  if (!header) {
805
841
  throw new Error(
806
842
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
807
843
  );
808
844
  }
845
+ upToBlockNumber = header.globalVariables.blockNumber;
809
846
  }
810
847
  }
811
- return this.logsSource.getPrivateLogsByTags(tags, page);
848
+ return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
812
849
  }
813
850
 
814
851
  public async getPublicLogsByTagsFromContract(
@@ -817,18 +854,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
817
854
  page?: number,
818
855
  referenceBlock?: BlockHash,
819
856
  ): Promise<TxScopedL2Log[][]> {
857
+ let upToBlockNumber: BlockNumber | undefined;
820
858
  if (referenceBlock) {
821
859
  const initialBlockHash = await this.#getInitialHeaderHash();
822
- if (!referenceBlock.equals(initialBlockHash)) {
860
+ if (referenceBlock.equals(initialBlockHash)) {
861
+ upToBlockNumber = BlockNumber(0);
862
+ } else {
823
863
  const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
824
864
  if (!header) {
825
865
  throw new Error(
826
866
  `Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
827
867
  );
828
868
  }
869
+ upToBlockNumber = header.globalVariables.blockNumber;
829
870
  }
830
871
  }
831
- return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
872
+ return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
832
873
  }
833
874
 
834
875
  /**
@@ -914,7 +955,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
914
955
  await tryStop(this.validatorsSentinel);
915
956
  await tryStop(this.epochPruneWatcher);
916
957
  await tryStop(this.slasherClient);
917
- await tryStop(this.proofVerifier);
958
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
918
959
  await tryStop(this.sequencer);
919
960
  await tryStop(this.proverNode);
920
961
  await tryStop(this.p2pClient);
@@ -970,7 +1011,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
970
1011
  treeId: MerkleTreeId,
971
1012
  leafValues: Fr[],
972
1013
  ): Promise<(DataInBlock<bigint> | undefined)[]> {
973
- const committedDb = await this.#getWorldState(referenceBlock);
1014
+ const committedDb = await this.getWorldState(referenceBlock);
974
1015
  const maybeIndices = await committedDb.findLeafIndices(
975
1016
  treeId,
976
1017
  leafValues.map(x => x.toBuffer()),
@@ -1042,7 +1083,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1042
1083
  // which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
1043
1084
  // So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
1044
1085
  const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
1045
- const committedDb = await this.#getWorldState(BlockNumber(referenceBlockNumber - 1));
1086
+ const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
1046
1087
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
1047
1088
  return pathAndIndex === undefined
1048
1089
  ? undefined
@@ -1053,7 +1094,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1053
1094
  referenceBlock: BlockParameter,
1054
1095
  noteHash: Fr,
1055
1096
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
1056
- const committedDb = await this.#getWorldState(referenceBlock);
1097
+ const committedDb = await this.getWorldState(referenceBlock);
1057
1098
  const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
1058
1099
  MerkleTreeId.NOTE_HASH_TREE,
1059
1100
  [noteHash],
@@ -1067,7 +1108,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1067
1108
  referenceBlock: BlockParameter,
1068
1109
  l1ToL2Message: Fr,
1069
1110
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
1070
- const db = await this.#getWorldState(referenceBlock);
1111
+ const db = await this.getWorldState(referenceBlock);
1071
1112
  const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
1072
1113
  if (!witness) {
1073
1114
  return undefined;
@@ -1100,19 +1141,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1100
1141
  public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
1101
1142
  // Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
1102
1143
  const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
1103
- const blocksInCheckpoints: L2Block[][] = [];
1104
- let previousSlotNumber = SlotNumber.ZERO;
1105
- let checkpointIndex = -1;
1106
- for (const checkpointedBlock of checkpointedBlocks) {
1107
- const block = checkpointedBlock.block;
1108
- const slotNumber = block.header.globalVariables.slotNumber;
1109
- if (slotNumber !== previousSlotNumber) {
1110
- checkpointIndex++;
1111
- blocksInCheckpoints.push([]);
1112
- previousSlotNumber = slotNumber;
1113
- }
1114
- blocksInCheckpoints[checkpointIndex].push(block);
1115
- }
1144
+ const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
1145
+ group => group.map(cb => cb.block),
1146
+ );
1116
1147
  return blocksInCheckpoints.map(blocks =>
1117
1148
  blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
1118
1149
  );
@@ -1122,7 +1153,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1122
1153
  referenceBlock: BlockParameter,
1123
1154
  nullifier: Fr,
1124
1155
  ): Promise<NullifierMembershipWitness | undefined> {
1125
- const db = await this.#getWorldState(referenceBlock);
1156
+ const db = await this.getWorldState(referenceBlock);
1126
1157
  const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
1127
1158
  if (!witness) {
1128
1159
  return undefined;
@@ -1137,33 +1168,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1137
1168
  return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
1138
1169
  }
1139
1170
 
1140
- /**
1141
- * Returns a low nullifier membership witness for a given nullifier at a given block.
1142
- * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
1143
- * (which contains the root of the nullifier tree in which we are searching for the nullifier).
1144
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
1145
- * @returns The low nullifier membership witness (if found).
1146
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
1147
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
1148
- * we are trying to prove non-inclusion for.
1149
- *
1150
- * Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
1151
- * the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
1152
- * index of the nullifier itself when it already exists in the tree.
1153
- * TODO: This is a confusing behavior and we should eventually address that.
1154
- */
1155
1171
  public async getLowNullifierMembershipWitness(
1156
1172
  referenceBlock: BlockParameter,
1157
1173
  nullifier: Fr,
1158
1174
  ): Promise<NullifierMembershipWitness | undefined> {
1159
- const committedDb = await this.#getWorldState(referenceBlock);
1175
+ const committedDb = await this.getWorldState(referenceBlock);
1160
1176
  const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
1161
1177
  if (!findResult) {
1162
1178
  return undefined;
1163
1179
  }
1164
1180
  const { index, alreadyPresent } = findResult;
1165
1181
  if (alreadyPresent) {
1166
- this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
1182
+ throw new Error(
1183
+ `Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
1184
+ );
1167
1185
  }
1168
1186
  const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
1169
1187
 
@@ -1172,7 +1190,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1172
1190
  }
1173
1191
 
1174
1192
  async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
1175
- const committedDb = await this.#getWorldState(referenceBlock);
1193
+ const committedDb = await this.getWorldState(referenceBlock);
1176
1194
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
1177
1195
  if (!lowLeafResult) {
1178
1196
  return undefined;
@@ -1187,7 +1205,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1187
1205
  }
1188
1206
 
1189
1207
  public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
1190
- const committedDb = await this.#getWorldState(referenceBlock);
1208
+ const committedDb = await this.getWorldState(referenceBlock);
1191
1209
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
1192
1210
 
1193
1211
  const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
@@ -1327,7 +1345,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1327
1345
  { isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
1328
1346
  ): Promise<TxValidationResult> {
1329
1347
  const db = this.worldStateSynchronizer.getCommitted();
1330
- const verifier = isSimulation ? undefined : this.proofVerifier;
1348
+ const verifier = isSimulation ? undefined : this.rpcProofVerifier;
1331
1349
 
1332
1350
  // We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
1333
1351
  const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
@@ -1376,7 +1394,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1376
1394
  archiver.updateConfig(config);
1377
1395
  }
1378
1396
  if (newConfig.realProofs !== this.config.realProofs) {
1379
- this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
1397
+ await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
1398
+ if (newConfig.realProofs) {
1399
+ this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
1400
+ const rpcVerifier = await BBCircuitVerifier.new(newConfig);
1401
+ this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
1402
+ } else {
1403
+ this.peerProofVerifier = new TestCircuitVerifier();
1404
+ this.rpcProofVerifier = new TestCircuitVerifier();
1405
+ }
1380
1406
  }
1381
1407
 
1382
1408
  this.config = newConfig;
@@ -1618,7 +1644,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1618
1644
  * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
1619
1645
  * @returns An instance of a committed MerkleTreeOperations
1620
1646
  */
1621
- async #getWorldState(block: BlockParameter) {
1647
+ protected async getWorldState(block: BlockParameter) {
1622
1648
  let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
1623
1649
  try {
1624
1650
  // Attempt to sync the world state if necessary
@@ -1632,6 +1658,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1632
1658
  return this.worldStateSynchronizer.getCommitted();
1633
1659
  }
1634
1660
 
1661
+ // Get the block number, either directly from the parameter or by quering the archiver with the block hash
1662
+ let blockNumber: BlockNumber;
1635
1663
  if (BlockHash.isBlockHash(block)) {
1636
1664
  const initialBlockHash = await this.#getInitialHeaderHash();
1637
1665
  if (block.equals(initialBlockHash)) {
@@ -1645,22 +1673,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
1645
1673
  `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.`,
1646
1674
  );
1647
1675
  }
1648
- const blockNumber = header.getBlockNumber();
1649
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1650
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1676
+
1677
+ blockNumber = header.getBlockNumber();
1678
+ } else {
1679
+ blockNumber = block as BlockNumber;
1651
1680
  }
1652
1681
 
1653
- // Block number provided
1654
- {
1655
- const blockNumber = block as BlockNumber;
1682
+ // Check it's within world state sync range
1683
+ if (blockNumber > blockSyncedTo) {
1684
+ throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1685
+ }
1686
+ this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1656
1687
 
1657
- if (blockNumber > blockSyncedTo) {
1658
- throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
1659
- }
1688
+ const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
1660
1689
 
1661
- this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
1662
- return this.worldStateSynchronizer.getSnapshot(blockNumber);
1690
+ // Double-check world-state synced to the same block hash as was requested
1691
+ if (BlockHash.isBlockHash(block)) {
1692
+ const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
1693
+ if (!blockHash || !new BlockHash(blockHash).equals(block)) {
1694
+ throw new Error(
1695
+ `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.`,
1696
+ );
1697
+ }
1663
1698
  }
1699
+
1700
+ return snapshot;
1664
1701
  }
1665
1702
 
1666
1703
  /** Resolves a block parameter to a block number. */
@@ -1,10 +1,10 @@
1
1
  import type { EpochCache } from '@aztec/epoch-cache';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import type { DataStoreConfig } from '@aztec/kv-store/config';
4
3
  import { createStore } from '@aztec/kv-store/lmdb-v2';
5
4
  import type { P2PClient } from '@aztec/p2p';
6
5
  import type { L2BlockSource } from '@aztec/stdlib/block';
7
6
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
7
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
8
8
 
9
9
  import type { SentinelConfig } from './config.js';
10
10
  import { Sentinel } from './sentinel.js';
@@ -88,7 +88,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
88
88
 
89
89
  /** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */
90
90
  protected async init() {
91
- this.initialSlot = this.epochCache.getEpochAndSlotNow().slot;
91
+ this.initialSlot = this.epochCache.getSlotNow();
92
92
  const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
93
93
  this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
94
94
  this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, { startingBlock });
@@ -219,7 +219,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
219
219
  // Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
220
220
  return pastEpochs
221
221
  .slice(0, requiredConsecutiveEpochs)
222
- .every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
222
+ .every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
223
223
  }
224
224
 
225
225
  protected async handleProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
@@ -264,7 +264,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
264
264
  * and we don't have that data if we were offline during the period.
265
265
  */
266
266
  public async work() {
267
- const { slot: currentSlot } = this.epochCache.getEpochAndSlotNow();
267
+ const currentSlot = this.epochCache.getSlotNow();
268
268
  try {
269
269
  // Manually sync the block stream to ensure we have the latest data.
270
270
  // Note we never `start` the blockstream, so it loops at the same pace as we do.
@@ -436,7 +436,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
436
436
  ? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
437
437
  : await this.store.getHistories();
438
438
 
439
- const slotNow = this.epochCache.getEpochAndSlotNow().slot;
439
+ const slotNow = this.epochCache.getSlotNow();
440
440
  fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
441
441
  toSlot ??= this.lastProcessedSlot ?? slotNow;
442
442
 
@@ -464,7 +464,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
464
464
  return undefined;
465
465
  }
466
466
 
467
- const slotNow = this.epochCache.getEpochAndSlotNow().slot;
467
+ const slotNow = this.epochCache.getSlotNow();
468
468
  const effectiveFromSlot =
469
469
  fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
470
470
  const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;