@aztec/prover-client 0.72.1 → 0.73.0

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.
Files changed (48) hide show
  1. package/dest/bin/get-proof-inputs.js +3 -3
  2. package/dest/mocks/test_context.d.ts +2 -2
  3. package/dest/mocks/test_context.d.ts.map +1 -1
  4. package/dest/mocks/test_context.js +6 -6
  5. package/dest/orchestrator/block-building-helpers.d.ts +3 -3
  6. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  7. package/dest/orchestrator/block-building-helpers.js +14 -13
  8. package/dest/orchestrator/block-proving-state.d.ts +6 -6
  9. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  10. package/dest/orchestrator/block-proving-state.js +27 -25
  11. package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
  12. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  13. package/dest/orchestrator/epoch-proving-state.js +11 -8
  14. package/dest/orchestrator/orchestrator.d.ts +1 -1
  15. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  16. package/dest/orchestrator/orchestrator.js +59 -59
  17. package/dest/orchestrator/tx-proving-state.d.ts +2 -2
  18. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  19. package/dest/orchestrator/tx-proving-state.js +14 -14
  20. package/dest/prover-client/server-epoch-prover.d.ts +1 -1
  21. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  22. package/dest/prover-client/server-epoch-prover.js +2 -2
  23. package/dest/proving_broker/broker_prover_facade.js +3 -3
  24. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  25. package/dest/proving_broker/proving_broker.js +3 -4
  26. package/dest/proving_broker/proving_broker_database/memory.d.ts +1 -1
  27. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  28. package/dest/proving_broker/proving_broker_database/memory.js +3 -3
  29. package/dest/proving_broker/proving_broker_database/persisted.d.ts +1 -1
  30. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  31. package/dest/proving_broker/proving_broker_database/persisted.js +12 -12
  32. package/dest/proving_broker/proving_broker_database.d.ts +1 -1
  33. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  34. package/package.json +11 -11
  35. package/src/bin/get-proof-inputs.ts +2 -2
  36. package/src/mocks/test_context.ts +9 -7
  37. package/src/orchestrator/block-building-helpers.ts +13 -14
  38. package/src/orchestrator/block-proving-state.ts +26 -24
  39. package/src/orchestrator/epoch-proving-state.ts +10 -7
  40. package/src/orchestrator/orchestrator.ts +65 -60
  41. package/src/orchestrator/tx-proving-state.ts +14 -14
  42. package/src/prover-client/server-epoch-prover.ts +2 -2
  43. package/src/proving_broker/broker_prover_facade.ts +3 -3
  44. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  45. package/src/proving_broker/proving_broker.ts +2 -4
  46. package/src/proving_broker/proving_broker_database/memory.ts +2 -2
  47. package/src/proving_broker/proving_broker_database/persisted.ts +15 -15
  48. package/src/proving_broker/proving_broker_database.ts +1 -1
@@ -36,7 +36,7 @@ import {
36
36
  SingleTxBlockRootRollupInputs,
37
37
  TubeInputs,
38
38
  } from '@aztec/circuits.js/rollup';
39
- import { padArrayEnd } from '@aztec/foundation/collection';
39
+ import { padArrayEnd, timesParallel } from '@aztec/foundation/collection';
40
40
  import { AbortError } from '@aztec/foundation/error';
41
41
  import { createLogger } from '@aztec/foundation/log';
42
42
  import { promiseWithResolvers } from '@aztec/foundation/promise';
@@ -238,16 +238,16 @@ export class ProvingOrchestrator implements EpochProver {
238
238
  * Note that if the tube circuits are not started this way, they will be started nontheless after processing.
239
239
  */
240
240
  @trackSpan('ProvingOrchestrator.startTubeCircuits')
241
- public startTubeCircuits(txs: Tx[]) {
241
+ public async startTubeCircuits(txs: Tx[]) {
242
242
  if (!this.provingState?.verifyState()) {
243
243
  throw new Error(`Invalid proving state, call startNewEpoch before starting tube circuits`);
244
244
  }
245
245
  for (const tx of txs) {
246
- const txHash = tx.getTxHash().toString();
246
+ const txHash = (await tx.getTxHash()).toString();
247
247
  const tubeInputs = new TubeInputs(tx.clientIvcProof);
248
248
  const tubeProof = promiseWithResolvers<ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>>();
249
249
  logger.debug(`Starting tube circuit for tx ${txHash}`);
250
- this.doEnqueueTube(txHash, tubeInputs, proof => tubeProof.resolve(proof));
250
+ this.doEnqueueTube(txHash, tubeInputs, proof => Promise.resolve(tubeProof.resolve(proof)));
251
251
  this.provingState?.cachedTubeProofs.set(txHash, tubeProof.promise);
252
252
  }
253
253
  }
@@ -280,7 +280,7 @@ export class ProvingOrchestrator implements EpochProver {
280
280
  await this.buildBlock(provingState, expectedHeader);
281
281
 
282
282
  // If the proofs were faster than the block building, then we need to try the block root rollup again here
283
- this.checkAndEnqueueBlockRootRollup(provingState);
283
+ await this.checkAndEnqueueBlockRootRollup(provingState);
284
284
  return provingState.block!;
285
285
  }
286
286
 
@@ -314,7 +314,9 @@ export class ProvingOrchestrator implements EpochProver {
314
314
  throw new Error('Block header mismatch');
315
315
  }
316
316
 
317
- logger.verbose(`Updating archive tree with block ${provingState.blockNumber} header ${header.hash().toString()}`);
317
+ logger.verbose(
318
+ `Updating archive tree with block ${provingState.blockNumber} header ${(await header.hash()).toString()}`,
319
+ );
318
320
  await db.updateArchive(header);
319
321
 
320
322
  // Assemble the L2 block
@@ -446,7 +448,7 @@ export class ProvingOrchestrator implements EpochProver {
446
448
  };
447
449
 
448
450
  // let the callstack unwind before adding the job to the queue
449
- setImmediate(safeJob);
451
+ setImmediate(() => void safeJob());
450
452
  }
451
453
 
452
454
  private async prepareBaseParityInputs(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
@@ -456,8 +458,8 @@ export class ProvingOrchestrator implements EpochProver {
456
458
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
457
459
  'Too many L1 to L2 messages',
458
460
  );
459
- const baseParityInputs = Array.from({ length: NUM_BASE_PARITY_PER_ROOT_PARITY }, (_, i) =>
460
- BaseParityInputs.fromSlice(l1ToL2MessagesPadded, i, getVKTreeRoot()),
461
+ const baseParityInputs = await timesParallel(NUM_BASE_PARITY_PER_ROOT_PARITY, async i =>
462
+ BaseParityInputs.fromSlice(l1ToL2MessagesPadded, i, await getVKTreeRoot()),
461
463
  );
462
464
 
463
465
  const l1ToL2MessageSubtreeSiblingPath = assertLength(
@@ -515,7 +517,7 @@ export class ProvingOrchestrator implements EpochProver {
515
517
 
516
518
  // Executes the base rollup circuit and stored the output as intermediate state for the parent merge/root circuit
517
519
  // Executes the next level of merge if all inputs are available
518
- private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
520
+ private async enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
519
521
  if (!provingState.verifyState()) {
520
522
  logger.debug('Not running base rollup, state invalid');
521
523
  return;
@@ -523,7 +525,7 @@ export class ProvingOrchestrator implements EpochProver {
523
525
 
524
526
  const txProvingState = provingState.getTxProvingState(txIndex);
525
527
  const { processedTx } = txProvingState;
526
- const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
528
+ const { rollupType, inputs } = await txProvingState.getBaseRollupTypeAndInputs();
527
529
 
528
530
  logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
529
531
 
@@ -547,14 +549,14 @@ export class ProvingOrchestrator implements EpochProver {
547
549
  }
548
550
  },
549
551
  ),
550
- result => {
552
+ async result => {
551
553
  logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
552
554
  validatePartialState(result.inputs.end, txProvingState.treeSnapshots);
553
555
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
554
556
  if (provingState.totalNumTxs === 1) {
555
- this.checkAndEnqueueBlockRootRollup(provingState);
557
+ await this.checkAndEnqueueBlockRootRollup(provingState);
556
558
  } else {
557
- this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
559
+ await this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
558
560
  }
559
561
  },
560
562
  );
@@ -571,11 +573,11 @@ export class ProvingOrchestrator implements EpochProver {
571
573
  const txProvingState = provingState.getTxProvingState(txIndex);
572
574
  const txHash = txProvingState.processedTx.hash.toString();
573
575
 
574
- const handleResult = (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => {
576
+ const handleResult = async (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => {
575
577
  logger.debug(`Got tube proof for tx index: ${txIndex}`, { txHash });
576
578
  txProvingState.setTubeProof(result);
577
579
  this.provingState?.cachedTubeProofs.delete(txHash);
578
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
580
+ await this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
579
581
  };
580
582
 
581
583
  if (this.provingState?.cachedTubeProofs.has(txHash)) {
@@ -591,7 +593,7 @@ export class ProvingOrchestrator implements EpochProver {
591
593
  private doEnqueueTube(
592
594
  txHash: string,
593
595
  inputs: TubeInputs,
594
- handler: (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => void,
596
+ handler: (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => Promise<void>,
595
597
  provingState: EpochProvingState | BlockProvingState = this.provingState!,
596
598
  ) {
597
599
  if (!provingState?.verifyState()) {
@@ -617,13 +619,13 @@ export class ProvingOrchestrator implements EpochProver {
617
619
 
618
620
  // Executes the merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
619
621
  // Enqueues the next level of merge if all inputs are available
620
- private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
622
+ private async enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
621
623
  if (!provingState.verifyState()) {
622
624
  logger.debug('Not running merge rollup. State no longer valid.');
623
625
  return;
624
626
  }
625
627
 
626
- const inputs = provingState.getMergeRollupInputs(location);
628
+ const inputs = await provingState.getMergeRollupInputs(location);
627
629
 
628
630
  this.deferredProving(
629
631
  provingState,
@@ -636,15 +638,15 @@ export class ProvingOrchestrator implements EpochProver {
636
638
  },
637
639
  signal => this.prover.getMergeRollupProof(inputs, signal, provingState.epochNumber),
638
640
  ),
639
- result => {
641
+ async result => {
640
642
  provingState.setMergeRollupProof(location, result);
641
- this.checkAndEnqueueNextMergeRollup(provingState, location);
643
+ await this.checkAndEnqueueNextMergeRollup(provingState, location);
642
644
  },
643
645
  );
644
646
  }
645
647
 
646
648
  // Executes the block root rollup circuit
647
- private enqueueBlockRootRollup(provingState: BlockProvingState) {
649
+ private async enqueueBlockRootRollup(provingState: BlockProvingState) {
648
650
  if (!provingState.verifyState()) {
649
651
  logger.debug('Not running block root rollup, state no longer valid');
650
652
  return;
@@ -652,7 +654,7 @@ export class ProvingOrchestrator implements EpochProver {
652
654
 
653
655
  provingState.blockRootRollupStarted = true;
654
656
 
655
- const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs(this.proverId);
657
+ const { rollupType, inputs } = await provingState.getBlockRootRollupTypeAndInputs(this.proverId);
656
658
 
657
659
  logger.debug(
658
660
  `Enqueuing ${rollupType} for block ${provingState.blockNumber} with ${provingState.newL1ToL2Messages.length} l1 to l2 msgs.`,
@@ -677,10 +679,10 @@ export class ProvingOrchestrator implements EpochProver {
677
679
  }
678
680
  },
679
681
  ),
680
- result => {
682
+ async result => {
681
683
  provingState.setBlockRootRollupProof(result);
682
- const header = provingState.buildHeaderFromProvingOutputs(logger);
683
- if (!header.hash().equals(provingState.block!.header.hash())) {
684
+ const header = await provingState.buildHeaderFromProvingOutputs(logger);
685
+ if (!(await header.hash()).equals(await provingState.block!.header.hash())) {
684
686
  logger.error(
685
687
  `Block header mismatch\nCircuit:${inspect(header)}\nComputed:${inspect(provingState.block!.header)}`,
686
688
  );
@@ -693,9 +695,9 @@ export class ProvingOrchestrator implements EpochProver {
693
695
  const epochProvingState = this.provingState!;
694
696
  const leafLocation = epochProvingState.setBlockRootRollupProof(provingState.index, result);
695
697
  if (epochProvingState.totalNumBlocks === 1) {
696
- this.enqueueEpochPadding(epochProvingState);
698
+ await this.enqueueEpochPadding(epochProvingState);
697
699
  } else {
698
- this.checkAndEnqueueNextBlockMergeRollup(epochProvingState, leafLocation);
700
+ await this.checkAndEnqueueNextBlockMergeRollup(epochProvingState, leafLocation);
699
701
  }
700
702
  },
701
703
  );
@@ -720,30 +722,30 @@ export class ProvingOrchestrator implements EpochProver {
720
722
  },
721
723
  signal => this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber),
722
724
  ),
723
- provingOutput => {
725
+ async provingOutput => {
724
726
  provingState.setBaseParityProof(index, provingOutput);
725
- this.checkAndEnqueueRootParityCircuit(provingState);
727
+ await this.checkAndEnqueueRootParityCircuit(provingState);
726
728
  },
727
729
  );
728
730
  }
729
731
 
730
- private checkAndEnqueueRootParityCircuit(provingState: BlockProvingState) {
732
+ private async checkAndEnqueueRootParityCircuit(provingState: BlockProvingState) {
731
733
  if (!provingState.isReadyForRootParity()) {
732
734
  return;
733
735
  }
734
736
 
735
- this.enqueueRootParityCircuit(provingState);
737
+ await this.enqueueRootParityCircuit(provingState);
736
738
  }
737
739
 
738
740
  // Runs the root parity circuit ans stored the outputs
739
741
  // Enqueues the root rollup proof if all inputs are available
740
- private enqueueRootParityCircuit(provingState: BlockProvingState) {
742
+ private async enqueueRootParityCircuit(provingState: BlockProvingState) {
741
743
  if (!provingState.verifyState()) {
742
744
  logger.debug('Not running root parity. State no longer valid.');
743
745
  return;
744
746
  }
745
747
 
746
- const inputs = provingState.getRootParityInputs();
748
+ const inputs = await provingState.getRootParityInputs();
747
749
 
748
750
  this.deferredProving(
749
751
  provingState,
@@ -756,22 +758,22 @@ export class ProvingOrchestrator implements EpochProver {
756
758
  },
757
759
  signal => this.prover.getRootParityProof(inputs, signal, provingState.epochNumber),
758
760
  ),
759
- result => {
761
+ async result => {
760
762
  provingState.setRootParityProof(result);
761
- this.checkAndEnqueueBlockRootRollup(provingState);
763
+ await this.checkAndEnqueueBlockRootRollup(provingState);
762
764
  },
763
765
  );
764
766
  }
765
767
 
766
768
  // Executes the block merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
767
769
  // Enqueues the next level of merge if all inputs are available
768
- private enqueueBlockMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
770
+ private async enqueueBlockMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
769
771
  if (!provingState.verifyState()) {
770
772
  logger.debug('Not running block merge rollup. State no longer valid.');
771
773
  return;
772
774
  }
773
775
 
774
- const inputs = provingState.getBlockMergeRollupInputs(location);
776
+ const inputs = await provingState.getBlockMergeRollupInputs(location);
775
777
 
776
778
  this.deferredProving(
777
779
  provingState,
@@ -784,14 +786,14 @@ export class ProvingOrchestrator implements EpochProver {
784
786
  },
785
787
  signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
786
788
  ),
787
- result => {
789
+ async result => {
788
790
  provingState.setBlockMergeRollupProof(location, result);
789
- this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
791
+ await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
790
792
  },
791
793
  );
792
794
  }
793
795
 
794
- private enqueueEpochPadding(provingState: EpochProvingState) {
796
+ private async enqueueEpochPadding(provingState: EpochProvingState) {
795
797
  if (!provingState.verifyState()) {
796
798
  logger.debug('Not running epoch padding. State no longer valid.');
797
799
  return;
@@ -799,7 +801,7 @@ export class ProvingOrchestrator implements EpochProver {
799
801
 
800
802
  logger.debug('Padding epoch proof with an empty block root proof.');
801
803
 
802
- const inputs = provingState.getPaddingBlockRootInputs(this.proverId);
804
+ const inputs = await provingState.getPaddingBlockRootInputs(this.proverId);
803
805
 
804
806
  this.deferredProving(
805
807
  provingState,
@@ -812,16 +814,16 @@ export class ProvingOrchestrator implements EpochProver {
812
814
  },
813
815
  signal => this.prover.getEmptyBlockRootRollupProof(inputs, signal, provingState.epochNumber),
814
816
  ),
815
- result => {
817
+ async result => {
816
818
  logger.debug('Completed proof for padding block root.');
817
819
  provingState.setPaddingBlockRootProof(result);
818
- this.checkAndEnqueueRootRollup(provingState);
820
+ await this.checkAndEnqueueRootRollup(provingState);
819
821
  },
820
822
  );
821
823
  }
822
824
 
823
825
  // Executes the root rollup circuit
824
- private enqueueRootRollup(provingState: EpochProvingState) {
826
+ private async enqueueRootRollup(provingState: EpochProvingState) {
825
827
  if (!provingState.verifyState()) {
826
828
  logger.debug('Not running root rollup, state no longer valid');
827
829
  return;
@@ -829,7 +831,7 @@ export class ProvingOrchestrator implements EpochProver {
829
831
 
830
832
  logger.debug(`Preparing root rollup`);
831
833
 
832
- const inputs = provingState.getRootRollupInputs(this.proverId);
834
+ const inputs = await provingState.getRootRollupInputs(this.proverId);
833
835
 
834
836
  this.deferredProving(
835
837
  provingState,
@@ -850,20 +852,20 @@ export class ProvingOrchestrator implements EpochProver {
850
852
  );
851
853
  }
852
854
 
853
- private checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
855
+ private async checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
854
856
  if (!provingState.isReadyForMergeRollup(currentLocation)) {
855
857
  return;
856
858
  }
857
859
 
858
860
  const parentLocation = provingState.getParentLocation(currentLocation);
859
861
  if (parentLocation.level === 0) {
860
- this.checkAndEnqueueBlockRootRollup(provingState);
862
+ await this.checkAndEnqueueBlockRootRollup(provingState);
861
863
  } else {
862
- this.enqueueMergeRollup(provingState, parentLocation);
864
+ await this.enqueueMergeRollup(provingState, parentLocation);
863
865
  }
864
866
  }
865
867
 
866
- private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
868
+ private async checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
867
869
  if (!provingState.isReadyForBlockRootRollup()) {
868
870
  logger.debug('Not ready for root rollup');
869
871
  return;
@@ -885,29 +887,32 @@ export class ProvingOrchestrator implements EpochProver {
885
887
  .then(() => this.dbs.delete(blockNumber))
886
888
  .catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
887
889
 
888
- this.enqueueBlockRootRollup(provingState);
890
+ await this.enqueueBlockRootRollup(provingState);
889
891
  }
890
892
 
891
- private checkAndEnqueueNextBlockMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
893
+ private async checkAndEnqueueNextBlockMergeRollup(
894
+ provingState: EpochProvingState,
895
+ currentLocation: TreeNodeLocation,
896
+ ) {
892
897
  if (!provingState.isReadyForBlockMerge(currentLocation)) {
893
898
  return;
894
899
  }
895
900
 
896
901
  const parentLocation = provingState.getParentLocation(currentLocation);
897
902
  if (parentLocation.level === 0) {
898
- this.checkAndEnqueueRootRollup(provingState);
903
+ await this.checkAndEnqueueRootRollup(provingState);
899
904
  } else {
900
- this.enqueueBlockMergeRollup(provingState, parentLocation);
905
+ await this.enqueueBlockMergeRollup(provingState, parentLocation);
901
906
  }
902
907
  }
903
908
 
904
- private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
909
+ private async checkAndEnqueueRootRollup(provingState: EpochProvingState) {
905
910
  if (!provingState.isReadyForRootRollup()) {
906
911
  logger.debug('Not ready for root rollup');
907
912
  return;
908
913
  }
909
914
 
910
- this.enqueueRootRollup(provingState);
915
+ await this.enqueueRootRollup(provingState);
911
916
  }
912
917
 
913
918
  /**
@@ -955,14 +960,14 @@ export class ProvingOrchestrator implements EpochProver {
955
960
  },
956
961
  );
957
962
 
958
- this.deferredProving(provingState, doAvmProving, proofAndVk => {
963
+ this.deferredProving(provingState, doAvmProving, async proofAndVk => {
959
964
  logger.debug(`Proven VM for tx index: ${txIndex}`);
960
965
  txProvingState.setAvmProof(proofAndVk);
961
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
966
+ await this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
962
967
  });
963
968
  }
964
969
 
965
- private checkAndEnqueueNextTxCircuit(provingState: BlockProvingState, txIndex: number) {
970
+ private async checkAndEnqueueNextTxCircuit(provingState: BlockProvingState, txIndex: number) {
966
971
  const txProvingState = provingState.getTxProvingState(txIndex);
967
972
  if (!txProvingState.ready()) {
968
973
  return;
@@ -971,6 +976,6 @@ export class ProvingOrchestrator implements EpochProver {
971
976
  // We must have completed all proving (tube proof and (if required) vm proof are generated), we now move to the base rollup.
972
977
  logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
973
978
 
974
- this.enqueueBaseRollup(provingState, txIndex);
979
+ await this.enqueueBaseRollup(provingState, txIndex);
975
980
  }
976
981
  }
@@ -52,16 +52,16 @@ export class TxProvingState {
52
52
  return this.processedTx.avmProvingRequest!.inputs;
53
53
  }
54
54
 
55
- public getBaseRollupTypeAndInputs() {
55
+ public async getBaseRollupTypeAndInputs() {
56
56
  if (this.requireAvmProof) {
57
57
  return {
58
58
  rollupType: 'public-base-rollup' satisfies CircuitName,
59
- inputs: this.#getPublicBaseInputs(),
59
+ inputs: await this.#getPublicBaseInputs(),
60
60
  };
61
61
  } else {
62
62
  return {
63
63
  rollupType: 'private-base-rollup' satisfies CircuitName,
64
- inputs: this.#getPrivateBaseInputs(),
64
+ inputs: await this.#getPrivateBaseInputs(),
65
65
  };
66
66
  }
67
67
  }
@@ -74,12 +74,12 @@ export class TxProvingState {
74
74
  this.avm = avmProofAndVk;
75
75
  }
76
76
 
77
- #getPrivateBaseInputs() {
77
+ async #getPrivateBaseInputs() {
78
78
  if (!this.tube) {
79
79
  throw new Error('Tx not ready for proving base rollup.');
80
80
  }
81
81
 
82
- const vkData = this.#getTubeVkData();
82
+ const vkData = await this.#getTubeVkData();
83
83
  const tubeData = new PrivateTubeData(
84
84
  this.processedTx.data.toPrivateToRollupKernelCircuitPublicInputs(),
85
85
  this.tube.proof,
@@ -92,7 +92,7 @@ export class TxProvingState {
92
92
  return new PrivateBaseRollupInputs(tubeData, this.baseRollupHints);
93
93
  }
94
94
 
95
- #getPublicBaseInputs() {
95
+ async #getPublicBaseInputs() {
96
96
  if (!this.processedTx.avmProvingRequest) {
97
97
  throw new Error('Should create private base rollup for a tx not requiring avm proof.');
98
98
  }
@@ -106,13 +106,13 @@ export class TxProvingState {
106
106
  const tubeData = new PublicTubeData(
107
107
  this.processedTx.data.toPrivateToPublicKernelCircuitPublicInputs(),
108
108
  this.tube.proof,
109
- this.#getTubeVkData(),
109
+ await this.#getTubeVkData(),
110
110
  );
111
111
 
112
112
  const avmProofData = new AvmProofData(
113
- this.processedTx.avmProvingRequest.inputs.output,
113
+ this.processedTx.avmProvingRequest.inputs.publicInputs,
114
114
  this.avm.proof,
115
- this.#getAvmVkData(),
115
+ await this.#getAvmVkData(),
116
116
  );
117
117
 
118
118
  if (!(this.baseRollupHints instanceof PublicBaseRollupHints)) {
@@ -122,21 +122,21 @@ export class TxProvingState {
122
122
  return new PublicBaseRollupInputs(tubeData, avmProofData, this.baseRollupHints);
123
123
  }
124
124
 
125
- #getTubeVkData() {
125
+ async #getTubeVkData() {
126
126
  let vkIndex = TUBE_VK_INDEX;
127
127
  try {
128
- vkIndex = getVKIndex(this.tube!.verificationKey);
128
+ vkIndex = await getVKIndex(this.tube!.verificationKey);
129
129
  } catch (_ignored) {
130
130
  // TODO(#7410) The VK for the tube won't be in the tree for now, so we manually set it to the tube vk index
131
131
  }
132
- const vkPath = getVKSiblingPath(vkIndex);
132
+ const vkPath = await getVKSiblingPath(vkIndex);
133
133
 
134
134
  return new VkWitnessData(this.tube!.verificationKey, vkIndex, vkPath);
135
135
  }
136
136
 
137
- #getAvmVkData() {
137
+ async #getAvmVkData() {
138
138
  const vkIndex = AVM_VK_INDEX;
139
- const vkPath = getVKSiblingPath(vkIndex);
139
+ const vkPath = await getVKSiblingPath(vkIndex);
140
140
  return new VkWitnessData(this.avm!.verificationKey, AVM_VK_INDEX, vkPath);
141
141
  }
142
142
  }
@@ -13,8 +13,8 @@ export class ServerEpochProver implements EpochProver {
13
13
  this.orchestrator.startNewEpoch(epochNumber, firstBlockNumber, totalNumBlocks);
14
14
  this.facade.start();
15
15
  }
16
- startTubeCircuits(txs: Tx[]): void {
17
- this.orchestrator.startTubeCircuits(txs);
16
+ startTubeCircuits(txs: Tx[]): Promise<void> {
17
+ return this.orchestrator.startTubeCircuits(txs);
18
18
  }
19
19
  setBlockCompleted(blockNumber: number, expectedBlockHeader?: BlockHeader): Promise<L2Block> {
20
20
  return this.orchestrator.setBlockCompleted(blockNumber, expectedBlockHeader);
@@ -55,7 +55,7 @@ type ProvingJob = {
55
55
  type: ProvingRequestType;
56
56
  inputsUri: ProofUri;
57
57
  promise: PromiseWithResolvers<any>;
58
- abortFn?: () => Promise<void>;
58
+ abortFn?: () => void;
59
59
  signal?: AbortSignal;
60
60
  };
61
61
 
@@ -117,9 +117,9 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
117
117
  // Create a promise for this job id, regardless of whether it was enqueued at the broker
118
118
  // The running promise will monitor for the job to be completed and resolve it either way
119
119
  const promise = promiseWithResolvers<ProvingJobResultsMap[T]>();
120
- const abortFn = async () => {
120
+ const abortFn = () => {
121
121
  signal?.removeEventListener('abort', abortFn);
122
- await this.broker.cancelProvingJob(id);
122
+ void this.broker.cancelProvingJob(id).catch(err => this.log.warn(`Error cancelling job id=${id}`, err));
123
123
  };
124
124
  const job: ProvingJob = {
125
125
  id,
@@ -52,7 +52,7 @@ export class InlineProofStore implements ProofStore {
52
52
  return (PREFIX + SEPARATOR + encoded) as ProofUri;
53
53
  }
54
54
 
55
- private decode<T>(uri: ProofUri, schema: ZodFor<T>): T {
55
+ private decode<T>(uri: ProofUri, schema: ZodFor<T>): Promise<T> {
56
56
  const [prefix, data] = uri.split(SEPARATOR);
57
57
  if (prefix !== PREFIX) {
58
58
  throw new Error('Invalid proof input URI: ' + prefix);
@@ -147,13 +147,13 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
147
147
  return count;
148
148
  };
149
149
 
150
- public start(): Promise<void> {
150
+ public async start(): Promise<void> {
151
151
  if (this.started) {
152
152
  this.logger.info('Proving Broker already started');
153
153
  return Promise.resolve();
154
154
  }
155
155
  this.logger.info('Proving Broker started');
156
- for (const [item, result] of this.database.allProvingJobs()) {
156
+ for await (const [item, result] of this.database.allProvingJobs()) {
157
157
  this.logger.info(`Restoring proving job id=${item.id} settled=${!!result}`, {
158
158
  provingJobId: item.id,
159
159
  status: result ? result.status : 'pending',
@@ -178,8 +178,6 @@ export class ProvingBroker implements ProvingJobProducer, ProvingJobConsumer, Tr
178
178
  this.instrumentation.monitorActiveJobs(this.countActiveJobs);
179
179
 
180
180
  this.started = true;
181
-
182
- return Promise.resolve();
183
181
  }
184
182
 
185
183
  public async stop(): Promise<void> {
@@ -51,8 +51,8 @@ export class InMemoryBrokerDatabase implements ProvingBrokerDatabase {
51
51
  return this.deleteProvingJobs(toDelete);
52
52
  }
53
53
 
54
- *allProvingJobs(): Iterable<[ProvingJob, ProvingJobSettledResult | undefined]> {
55
- for (const item of this.jobs.values()) {
54
+ async *allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]> {
55
+ for await (const item of this.jobs.values()) {
56
56
  yield [item, this.results.get(item.id)] as const;
57
57
  }
58
58
  }
@@ -7,8 +7,8 @@ import {
7
7
  } from '@aztec/circuit-types';
8
8
  import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
9
9
  import { type Logger, createLogger } from '@aztec/foundation/log';
10
- import { type AztecMap } from '@aztec/kv-store';
11
- import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
10
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
11
+ import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
12
12
  import { Attributes, LmdbMetrics, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
13
13
 
14
14
  import { mkdir, readdir } from 'fs/promises';
@@ -18,10 +18,10 @@ import { type ProverBrokerConfig } from '../config.js';
18
18
  import { type ProvingBrokerDatabase } from '../proving_broker_database.js';
19
19
 
20
20
  class SingleEpochDatabase {
21
- private jobs: AztecMap<ProvingJobId, string>;
22
- private jobResults: AztecMap<ProvingJobId, string>;
21
+ private jobs: AztecAsyncMap<ProvingJobId, string>;
22
+ private jobResults: AztecAsyncMap<ProvingJobId, string>;
23
23
 
24
- constructor(public readonly store: AztecLmdbStore) {
24
+ constructor(public readonly store: AztecAsyncKVStore) {
25
25
  this.jobs = store.openMap('proving_jobs');
26
26
  this.jobResults = store.openMap('proving_job_results');
27
27
  }
@@ -34,11 +34,11 @@ class SingleEpochDatabase {
34
34
  await this.jobs.set(job.id, jsonStringify(job));
35
35
  }
36
36
 
37
- *allProvingJobs(): Iterable<[ProvingJob, ProvingJobSettledResult | undefined]> {
38
- for (const jobStr of this.jobs.values()) {
39
- const job = jsonParseWithSchema(jobStr, ProvingJob);
40
- const resultStr = this.jobResults.get(job.id);
41
- const result = resultStr ? jsonParseWithSchema(resultStr, ProvingJobSettledResult) : undefined;
37
+ async *allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]> {
38
+ for await (const jobStr of this.jobs.valuesAsync()) {
39
+ const job = await jsonParseWithSchema(jobStr, ProvingJob);
40
+ const resultStr = await this.jobResults.getAsync(job.id);
41
+ const result = resultStr ? await jsonParseWithSchema(resultStr, ProvingJobSettledResult) : undefined;
42
42
  yield [job, result];
43
43
  }
44
44
  }
@@ -80,8 +80,8 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
80
80
  );
81
81
  }
82
82
 
83
- private estimateSize() {
84
- const sizes = Array.from(this.epochs.values()).map(x => x.estimateSize());
83
+ private async estimateSize() {
84
+ const sizes = await Promise.all(Array.from(this.epochs.values()).map(x => x.estimateSize()));
85
85
  return {
86
86
  mappingSize: this.config.dataStoreMapSizeKB,
87
87
  numItems: sizes.reduce((prev, curr) => prev + curr.numItems, 0),
@@ -110,7 +110,7 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
110
110
  logger.info(
111
111
  `Loading broker database for epoch ${epochNumber} from ${fullDirectory} with map size ${config.dataStoreMapSizeKB}KB`,
112
112
  );
113
- const db = AztecLmdbStore.open(fullDirectory, config.dataStoreMapSizeKB, false);
113
+ const db = await AztecLMDBStoreV2.new(fullDirectory, config.dataStoreMapSizeKB);
114
114
  const epochDb = new SingleEpochDatabase(db);
115
115
  epochs.set(epochNumber, epochDb);
116
116
  }
@@ -144,14 +144,14 @@ export class KVBrokerDatabase implements ProvingBrokerDatabase {
144
144
  this.logger.info(
145
145
  `Creating broker database for epoch ${job.epochNumber} at ${newEpochDirectory} with map size ${this.config.dataStoreMapSizeKB}`,
146
146
  );
147
- const db = AztecLmdbStore.open(newEpochDirectory, this.config.dataStoreMapSizeKB, false);
147
+ const db = await AztecLMDBStoreV2.new(newEpochDirectory, this.config.dataStoreMapSizeKB);
148
148
  epochDb = new SingleEpochDatabase(db);
149
149
  this.epochs.set(job.epochNumber, epochDb);
150
150
  }
151
151
  await epochDb.addProvingJob(job);
152
152
  }
153
153
 
154
- *allProvingJobs(): Iterable<[ProvingJob, ProvingJobSettledResult | undefined]> {
154
+ async *allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]> {
155
155
  const iterators = Array.from(this.epochs.values()).map(x => x.allProvingJobs());
156
156
  for (const it of iterators) {
157
157
  yield* it;
@@ -19,7 +19,7 @@ export interface ProvingBrokerDatabase {
19
19
  /**
20
20
  * Returns an iterator over all saved proving jobs
21
21
  */
22
- allProvingJobs(): Iterable<[ProvingJob, ProvingJobSettledResult | undefined]>;
22
+ allProvingJobs(): AsyncIterableIterator<[ProvingJob, ProvingJobSettledResult | undefined]>;
23
23
 
24
24
  /**
25
25
  * Saves the result of a proof request