@aztec/prover-client 0.71.0 → 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 (59) hide show
  1. package/dest/bin/get-proof-inputs.js +3 -3
  2. package/dest/config.js +2 -2
  3. package/dest/mocks/test_context.d.ts +4 -3
  4. package/dest/mocks/test_context.d.ts.map +1 -1
  5. package/dest/mocks/test_context.js +11 -8
  6. package/dest/orchestrator/block-building-helpers.d.ts +3 -3
  7. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  8. package/dest/orchestrator/block-building-helpers.js +14 -13
  9. package/dest/orchestrator/block-proving-state.d.ts +14 -15
  10. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  11. package/dest/orchestrator/block-proving-state.js +84 -64
  12. package/dest/orchestrator/epoch-proving-state.d.ts +7 -7
  13. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  14. package/dest/orchestrator/epoch-proving-state.js +18 -36
  15. package/dest/orchestrator/orchestrator.d.ts +4 -3
  16. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  17. package/dest/orchestrator/orchestrator.js +77 -90
  18. package/dest/orchestrator/tx-proving-state.d.ts +2 -2
  19. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  20. package/dest/orchestrator/tx-proving-state.js +14 -14
  21. package/dest/prover-agent/rpc.d.ts +1 -1
  22. package/dest/prover-agent/rpc.d.ts.map +1 -1
  23. package/dest/prover-agent/rpc.js +6 -6
  24. package/dest/prover-client/server-epoch-prover.d.ts +2 -2
  25. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  26. package/dest/prover-client/server-epoch-prover.js +4 -4
  27. package/dest/proving_broker/broker_prover_facade.js +3 -3
  28. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  29. package/dest/proving_broker/proving_broker.js +3 -4
  30. package/dest/proving_broker/proving_broker_database/memory.d.ts +1 -1
  31. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  32. package/dest/proving_broker/proving_broker_database/memory.js +3 -3
  33. package/dest/proving_broker/proving_broker_database/persisted.d.ts +1 -1
  34. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  35. package/dest/proving_broker/proving_broker_database/persisted.js +12 -12
  36. package/dest/proving_broker/proving_broker_database.d.ts +1 -1
  37. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  38. package/dest/proving_broker/rpc.d.ts +3 -3
  39. package/dest/proving_broker/rpc.d.ts.map +1 -1
  40. package/dest/proving_broker/rpc.js +7 -7
  41. package/dest/test/mock_prover.d.ts +1 -1
  42. package/package.json +11 -11
  43. package/src/bin/get-proof-inputs.ts +2 -2
  44. package/src/config.ts +1 -1
  45. package/src/mocks/test_context.ts +14 -9
  46. package/src/orchestrator/block-building-helpers.ts +13 -14
  47. package/src/orchestrator/block-proving-state.ts +95 -69
  48. package/src/orchestrator/epoch-proving-state.ts +26 -52
  49. package/src/orchestrator/orchestrator.ts +101 -122
  50. package/src/orchestrator/tx-proving-state.ts +14 -14
  51. package/src/prover-agent/rpc.ts +5 -5
  52. package/src/prover-client/server-epoch-prover.ts +8 -4
  53. package/src/proving_broker/broker_prover_facade.ts +3 -3
  54. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  55. package/src/proving_broker/proving_broker.ts +2 -4
  56. package/src/proving_broker/proving_broker_database/memory.ts +2 -2
  57. package/src/proving_broker/proving_broker_database/persisted.ts +15 -15
  58. package/src/proving_broker/proving_broker_database.ts +1 -1
  59. package/src/proving_broker/rpc.ts +13 -6
@@ -18,16 +18,13 @@ import {
18
18
  AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS,
19
19
  type AppendOnlyTreeSnapshot,
20
20
  BaseParityInputs,
21
- BlockHeader,
22
- ContentCommitment,
21
+ type BlockHeader,
23
22
  Fr,
24
- GlobalVariables,
23
+ type GlobalVariables,
25
24
  L1_TO_L2_MSG_SUBTREE_HEIGHT,
26
25
  L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
27
26
  NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
28
27
  NUM_BASE_PARITY_PER_ROOT_PARITY,
29
- PartialStateReference,
30
- StateReference,
31
28
  type TUBE_PROOF_LENGTH,
32
29
  VerificationKeyData,
33
30
  makeEmptyRecursiveProof,
@@ -39,12 +36,11 @@ import {
39
36
  SingleTxBlockRootRollupInputs,
40
37
  TubeInputs,
41
38
  } from '@aztec/circuits.js/rollup';
42
- import { makeTuple } from '@aztec/foundation/array';
43
- import { padArrayEnd } from '@aztec/foundation/collection';
39
+ import { padArrayEnd, timesParallel } from '@aztec/foundation/collection';
44
40
  import { AbortError } from '@aztec/foundation/error';
45
41
  import { createLogger } from '@aztec/foundation/log';
46
42
  import { promiseWithResolvers } from '@aztec/foundation/promise';
47
- import { type Tuple } from '@aztec/foundation/serialize';
43
+ import { assertLength } from '@aztec/foundation/serialize';
48
44
  import { pushTestData } from '@aztec/foundation/testing';
49
45
  import { elapsed } from '@aztec/foundation/timer';
50
46
  import { type TreeNodeLocation } from '@aztec/foundation/trees';
@@ -140,7 +136,7 @@ export class ProvingOrchestrator implements EpochProver {
140
136
  @trackSpan('ProvingOrchestrator.startNewBlock', globalVariables => ({
141
137
  [Attributes.BLOCK_NUMBER]: globalVariables.blockNumber.toNumber(),
142
138
  }))
143
- public async startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]) {
139
+ public async startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[], previousBlockHeader: BlockHeader) {
144
140
  if (!this.provingState) {
145
141
  throw new Error(`Invalid proving state, call startNewEpoch before starting a block`);
146
142
  }
@@ -158,70 +154,21 @@ export class ProvingOrchestrator implements EpochProver {
158
154
  this.dbs.set(globalVariables.blockNumber.toNumber(), db);
159
155
 
160
156
  // we start the block by enqueueing all of the base parity circuits
161
- let baseParityInputs: BaseParityInputs[] = [];
162
- let l1ToL2MessagesPadded: Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>;
163
- try {
164
- l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
165
- } catch (err) {
166
- throw new Error('Too many L1 to L2 messages');
167
- }
168
- baseParityInputs = Array.from({ length: NUM_BASE_PARITY_PER_ROOT_PARITY }, (_, i) =>
169
- BaseParityInputs.fromSlice(l1ToL2MessagesPadded, i, getVKTreeRoot()),
170
- );
171
-
172
- const messageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
173
-
174
- const newL1ToL2MessageTreeRootSiblingPathArray = await getSubtreeSiblingPath(
175
- MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
176
- L1_TO_L2_MSG_SUBTREE_HEIGHT,
177
- db,
178
- );
179
-
180
- const newL1ToL2MessageTreeRootSiblingPath = makeTuple(
181
- L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
182
- i =>
183
- i < newL1ToL2MessageTreeRootSiblingPathArray.length ? newL1ToL2MessageTreeRootSiblingPathArray[i] : Fr.ZERO,
184
- 0,
185
- );
186
-
187
- // Update the local trees to include the new l1 to l2 messages
188
- await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
189
- const messageTreeSnapshotAfterInsertion = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
157
+ const { l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, baseParityInputs } =
158
+ await this.prepareBaseParityInputs(l1ToL2Messages, db);
190
159
 
191
160
  // Get archive snapshot before this block lands
192
- const startArchiveSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
161
+ const lastArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
193
162
  const newArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
194
- const previousBlockHash = await db.getLeafValue(
195
- MerkleTreeId.ARCHIVE,
196
- BigInt(startArchiveSnapshot.nextAvailableLeafIndex - 1),
197
- );
198
-
199
- const partial = new PartialStateReference(
200
- await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db),
201
- await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db),
202
- await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db),
203
- );
204
- const state = new StateReference(messageTreeSnapshot, partial);
205
- // TODO: Construct the full previousBlockHeader.
206
- const previousBlockHeader = BlockHeader.from({
207
- lastArchive: startArchiveSnapshot,
208
- contentCommitment: ContentCommitment.empty(),
209
- state,
210
- globalVariables: GlobalVariables.empty(),
211
- totalFees: Fr.ZERO,
212
- totalManaUsed: Fr.ZERO,
213
- });
214
163
 
215
164
  const blockProvingState = this.provingState!.startNewBlock(
216
165
  globalVariables,
217
- l1ToL2MessagesPadded,
218
- messageTreeSnapshot,
219
- newL1ToL2MessageTreeRootSiblingPath,
220
- messageTreeSnapshotAfterInsertion,
221
- startArchiveSnapshot,
166
+ l1ToL2Messages,
167
+ l1ToL2MessageSubtreeSiblingPath,
168
+ l1ToL2MessageTreeSnapshotAfterInsertion,
169
+ lastArchive,
222
170
  newArchiveSiblingPath,
223
171
  previousBlockHeader,
224
- previousBlockHash!,
225
172
  );
226
173
 
227
174
  // Enqueue base parity circuits for the block
@@ -291,16 +238,16 @@ export class ProvingOrchestrator implements EpochProver {
291
238
  * Note that if the tube circuits are not started this way, they will be started nontheless after processing.
292
239
  */
293
240
  @trackSpan('ProvingOrchestrator.startTubeCircuits')
294
- public startTubeCircuits(txs: Tx[]) {
241
+ public async startTubeCircuits(txs: Tx[]) {
295
242
  if (!this.provingState?.verifyState()) {
296
243
  throw new Error(`Invalid proving state, call startNewEpoch before starting tube circuits`);
297
244
  }
298
245
  for (const tx of txs) {
299
- const txHash = tx.getTxHash().toString();
246
+ const txHash = (await tx.getTxHash()).toString();
300
247
  const tubeInputs = new TubeInputs(tx.clientIvcProof);
301
248
  const tubeProof = promiseWithResolvers<ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>>();
302
249
  logger.debug(`Starting tube circuit for tx ${txHash}`);
303
- this.doEnqueueTube(txHash, tubeInputs, proof => tubeProof.resolve(proof));
250
+ this.doEnqueueTube(txHash, tubeInputs, proof => Promise.resolve(tubeProof.resolve(proof)));
304
251
  this.provingState?.cachedTubeProofs.set(txHash, tubeProof.promise);
305
252
  }
306
253
  }
@@ -333,7 +280,7 @@ export class ProvingOrchestrator implements EpochProver {
333
280
  await this.buildBlock(provingState, expectedHeader);
334
281
 
335
282
  // If the proofs were faster than the block building, then we need to try the block root rollup again here
336
- this.checkAndEnqueueBlockRootRollup(provingState);
283
+ await this.checkAndEnqueueBlockRootRollup(provingState);
337
284
  return provingState.block!;
338
285
  }
339
286
 
@@ -367,7 +314,9 @@ export class ProvingOrchestrator implements EpochProver {
367
314
  throw new Error('Block header mismatch');
368
315
  }
369
316
 
370
- 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
+ );
371
320
  await db.updateArchive(header);
372
321
 
373
322
  // Assemble the L2 block
@@ -499,7 +448,34 @@ export class ProvingOrchestrator implements EpochProver {
499
448
  };
500
449
 
501
450
  // let the callstack unwind before adding the job to the queue
502
- setImmediate(safeJob);
451
+ setImmediate(() => void safeJob());
452
+ }
453
+
454
+ private async prepareBaseParityInputs(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
455
+ const l1ToL2MessagesPadded = padArrayEnd(
456
+ l1ToL2Messages,
457
+ Fr.ZERO,
458
+ NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
459
+ 'Too many L1 to L2 messages',
460
+ );
461
+ const baseParityInputs = await timesParallel(NUM_BASE_PARITY_PER_ROOT_PARITY, async i =>
462
+ BaseParityInputs.fromSlice(l1ToL2MessagesPadded, i, await getVKTreeRoot()),
463
+ );
464
+
465
+ const l1ToL2MessageSubtreeSiblingPath = assertLength(
466
+ await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db),
467
+ L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
468
+ );
469
+
470
+ // Update the local trees to include the new l1 to l2 messages
471
+ await db.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
472
+ const l1ToL2MessageTreeSnapshotAfterInsertion = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
473
+
474
+ return {
475
+ l1ToL2MessageSubtreeSiblingPath,
476
+ l1ToL2MessageTreeSnapshotAfterInsertion,
477
+ baseParityInputs,
478
+ };
503
479
  }
504
480
 
505
481
  // Updates the merkle trees for a transaction. The first enqueued job for a transaction
@@ -541,7 +517,7 @@ export class ProvingOrchestrator implements EpochProver {
541
517
 
542
518
  // Executes the base rollup circuit and stored the output as intermediate state for the parent merge/root circuit
543
519
  // Executes the next level of merge if all inputs are available
544
- private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
520
+ private async enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
545
521
  if (!provingState.verifyState()) {
546
522
  logger.debug('Not running base rollup, state invalid');
547
523
  return;
@@ -549,7 +525,7 @@ export class ProvingOrchestrator implements EpochProver {
549
525
 
550
526
  const txProvingState = provingState.getTxProvingState(txIndex);
551
527
  const { processedTx } = txProvingState;
552
- const { rollupType, inputs } = txProvingState.getBaseRollupTypeAndInputs();
528
+ const { rollupType, inputs } = await txProvingState.getBaseRollupTypeAndInputs();
553
529
 
554
530
  logger.debug(`Enqueuing deferred proving base rollup for ${processedTx.hash.toString()}`);
555
531
 
@@ -573,14 +549,14 @@ export class ProvingOrchestrator implements EpochProver {
573
549
  }
574
550
  },
575
551
  ),
576
- result => {
552
+ async result => {
577
553
  logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
578
554
  validatePartialState(result.inputs.end, txProvingState.treeSnapshots);
579
555
  const leafLocation = provingState.setBaseRollupProof(txIndex, result);
580
556
  if (provingState.totalNumTxs === 1) {
581
- this.checkAndEnqueueBlockRootRollup(provingState);
557
+ await this.checkAndEnqueueBlockRootRollup(provingState);
582
558
  } else {
583
- this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
559
+ await this.checkAndEnqueueNextMergeRollup(provingState, leafLocation);
584
560
  }
585
561
  },
586
562
  );
@@ -597,11 +573,11 @@ export class ProvingOrchestrator implements EpochProver {
597
573
  const txProvingState = provingState.getTxProvingState(txIndex);
598
574
  const txHash = txProvingState.processedTx.hash.toString();
599
575
 
600
- const handleResult = (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => {
576
+ const handleResult = async (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => {
601
577
  logger.debug(`Got tube proof for tx index: ${txIndex}`, { txHash });
602
578
  txProvingState.setTubeProof(result);
603
579
  this.provingState?.cachedTubeProofs.delete(txHash);
604
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
580
+ await this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
605
581
  };
606
582
 
607
583
  if (this.provingState?.cachedTubeProofs.has(txHash)) {
@@ -617,7 +593,7 @@ export class ProvingOrchestrator implements EpochProver {
617
593
  private doEnqueueTube(
618
594
  txHash: string,
619
595
  inputs: TubeInputs,
620
- handler: (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => void,
596
+ handler: (result: ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>) => Promise<void>,
621
597
  provingState: EpochProvingState | BlockProvingState = this.provingState!,
622
598
  ) {
623
599
  if (!provingState?.verifyState()) {
@@ -643,13 +619,13 @@ export class ProvingOrchestrator implements EpochProver {
643
619
 
644
620
  // Executes the merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
645
621
  // Enqueues the next level of merge if all inputs are available
646
- private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
622
+ private async enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
647
623
  if (!provingState.verifyState()) {
648
624
  logger.debug('Not running merge rollup. State no longer valid.');
649
625
  return;
650
626
  }
651
627
 
652
- const inputs = provingState.getMergeRollupInputs(location);
628
+ const inputs = await provingState.getMergeRollupInputs(location);
653
629
 
654
630
  this.deferredProving(
655
631
  provingState,
@@ -662,15 +638,15 @@ export class ProvingOrchestrator implements EpochProver {
662
638
  },
663
639
  signal => this.prover.getMergeRollupProof(inputs, signal, provingState.epochNumber),
664
640
  ),
665
- result => {
641
+ async result => {
666
642
  provingState.setMergeRollupProof(location, result);
667
- this.checkAndEnqueueNextMergeRollup(provingState, location);
643
+ await this.checkAndEnqueueNextMergeRollup(provingState, location);
668
644
  },
669
645
  );
670
646
  }
671
647
 
672
648
  // Executes the block root rollup circuit
673
- private enqueueBlockRootRollup(provingState: BlockProvingState) {
649
+ private async enqueueBlockRootRollup(provingState: BlockProvingState) {
674
650
  if (!provingState.verifyState()) {
675
651
  logger.debug('Not running block root rollup, state no longer valid');
676
652
  return;
@@ -678,7 +654,7 @@ export class ProvingOrchestrator implements EpochProver {
678
654
 
679
655
  provingState.blockRootRollupStarted = true;
680
656
 
681
- const { rollupType, inputs } = provingState.getBlockRootRollupTypeAndInputs(this.proverId);
657
+ const { rollupType, inputs } = await provingState.getBlockRootRollupTypeAndInputs(this.proverId);
682
658
 
683
659
  logger.debug(
684
660
  `Enqueuing ${rollupType} for block ${provingState.blockNumber} with ${provingState.newL1ToL2Messages.length} l1 to l2 msgs.`,
@@ -703,10 +679,10 @@ export class ProvingOrchestrator implements EpochProver {
703
679
  }
704
680
  },
705
681
  ),
706
- result => {
682
+ async result => {
707
683
  provingState.setBlockRootRollupProof(result);
708
- const header = provingState.buildHeaderFromProvingOutputs(logger);
709
- 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())) {
710
686
  logger.error(
711
687
  `Block header mismatch\nCircuit:${inspect(header)}\nComputed:${inspect(provingState.block!.header)}`,
712
688
  );
@@ -719,9 +695,9 @@ export class ProvingOrchestrator implements EpochProver {
719
695
  const epochProvingState = this.provingState!;
720
696
  const leafLocation = epochProvingState.setBlockRootRollupProof(provingState.index, result);
721
697
  if (epochProvingState.totalNumBlocks === 1) {
722
- this.enqueueEpochPadding(epochProvingState);
698
+ await this.enqueueEpochPadding(epochProvingState);
723
699
  } else {
724
- this.checkAndEnqueueNextBlockMergeRollup(epochProvingState, leafLocation);
700
+ await this.checkAndEnqueueNextBlockMergeRollup(epochProvingState, leafLocation);
725
701
  }
726
702
  },
727
703
  );
@@ -746,30 +722,30 @@ export class ProvingOrchestrator implements EpochProver {
746
722
  },
747
723
  signal => this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber),
748
724
  ),
749
- provingOutput => {
725
+ async provingOutput => {
750
726
  provingState.setBaseParityProof(index, provingOutput);
751
- this.checkAndEnqueueRootParityCircuit(provingState);
727
+ await this.checkAndEnqueueRootParityCircuit(provingState);
752
728
  },
753
729
  );
754
730
  }
755
731
 
756
- private checkAndEnqueueRootParityCircuit(provingState: BlockProvingState) {
732
+ private async checkAndEnqueueRootParityCircuit(provingState: BlockProvingState) {
757
733
  if (!provingState.isReadyForRootParity()) {
758
734
  return;
759
735
  }
760
736
 
761
- this.enqueueRootParityCircuit(provingState);
737
+ await this.enqueueRootParityCircuit(provingState);
762
738
  }
763
739
 
764
740
  // Runs the root parity circuit ans stored the outputs
765
741
  // Enqueues the root rollup proof if all inputs are available
766
- private enqueueRootParityCircuit(provingState: BlockProvingState) {
742
+ private async enqueueRootParityCircuit(provingState: BlockProvingState) {
767
743
  if (!provingState.verifyState()) {
768
744
  logger.debug('Not running root parity. State no longer valid.');
769
745
  return;
770
746
  }
771
747
 
772
- const inputs = provingState.getRootParityInputs();
748
+ const inputs = await provingState.getRootParityInputs();
773
749
 
774
750
  this.deferredProving(
775
751
  provingState,
@@ -782,22 +758,22 @@ export class ProvingOrchestrator implements EpochProver {
782
758
  },
783
759
  signal => this.prover.getRootParityProof(inputs, signal, provingState.epochNumber),
784
760
  ),
785
- result => {
761
+ async result => {
786
762
  provingState.setRootParityProof(result);
787
- this.checkAndEnqueueBlockRootRollup(provingState);
763
+ await this.checkAndEnqueueBlockRootRollup(provingState);
788
764
  },
789
765
  );
790
766
  }
791
767
 
792
768
  // Executes the block merge rollup circuit and stored the output as intermediate state for the parent merge/block root circuit
793
769
  // Enqueues the next level of merge if all inputs are available
794
- private enqueueBlockMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
770
+ private async enqueueBlockMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
795
771
  if (!provingState.verifyState()) {
796
772
  logger.debug('Not running block merge rollup. State no longer valid.');
797
773
  return;
798
774
  }
799
775
 
800
- const inputs = provingState.getBlockMergeRollupInputs(location);
776
+ const inputs = await provingState.getBlockMergeRollupInputs(location);
801
777
 
802
778
  this.deferredProving(
803
779
  provingState,
@@ -810,14 +786,14 @@ export class ProvingOrchestrator implements EpochProver {
810
786
  },
811
787
  signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
812
788
  ),
813
- result => {
789
+ async result => {
814
790
  provingState.setBlockMergeRollupProof(location, result);
815
- this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
791
+ await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
816
792
  },
817
793
  );
818
794
  }
819
795
 
820
- private enqueueEpochPadding(provingState: EpochProvingState) {
796
+ private async enqueueEpochPadding(provingState: EpochProvingState) {
821
797
  if (!provingState.verifyState()) {
822
798
  logger.debug('Not running epoch padding. State no longer valid.');
823
799
  return;
@@ -825,7 +801,7 @@ export class ProvingOrchestrator implements EpochProver {
825
801
 
826
802
  logger.debug('Padding epoch proof with an empty block root proof.');
827
803
 
828
- const inputs = provingState.getPaddingBlockRootInputs(this.proverId);
804
+ const inputs = await provingState.getPaddingBlockRootInputs(this.proverId);
829
805
 
830
806
  this.deferredProving(
831
807
  provingState,
@@ -838,16 +814,16 @@ export class ProvingOrchestrator implements EpochProver {
838
814
  },
839
815
  signal => this.prover.getEmptyBlockRootRollupProof(inputs, signal, provingState.epochNumber),
840
816
  ),
841
- result => {
817
+ async result => {
842
818
  logger.debug('Completed proof for padding block root.');
843
819
  provingState.setPaddingBlockRootProof(result);
844
- this.checkAndEnqueueRootRollup(provingState);
820
+ await this.checkAndEnqueueRootRollup(provingState);
845
821
  },
846
822
  );
847
823
  }
848
824
 
849
825
  // Executes the root rollup circuit
850
- private enqueueRootRollup(provingState: EpochProvingState) {
826
+ private async enqueueRootRollup(provingState: EpochProvingState) {
851
827
  if (!provingState.verifyState()) {
852
828
  logger.debug('Not running root rollup, state no longer valid');
853
829
  return;
@@ -855,7 +831,7 @@ export class ProvingOrchestrator implements EpochProver {
855
831
 
856
832
  logger.debug(`Preparing root rollup`);
857
833
 
858
- const inputs = provingState.getRootRollupInputs(this.proverId);
834
+ const inputs = await provingState.getRootRollupInputs(this.proverId);
859
835
 
860
836
  this.deferredProving(
861
837
  provingState,
@@ -876,20 +852,20 @@ export class ProvingOrchestrator implements EpochProver {
876
852
  );
877
853
  }
878
854
 
879
- private checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
855
+ private async checkAndEnqueueNextMergeRollup(provingState: BlockProvingState, currentLocation: TreeNodeLocation) {
880
856
  if (!provingState.isReadyForMergeRollup(currentLocation)) {
881
857
  return;
882
858
  }
883
859
 
884
860
  const parentLocation = provingState.getParentLocation(currentLocation);
885
861
  if (parentLocation.level === 0) {
886
- this.checkAndEnqueueBlockRootRollup(provingState);
862
+ await this.checkAndEnqueueBlockRootRollup(provingState);
887
863
  } else {
888
- this.enqueueMergeRollup(provingState, parentLocation);
864
+ await this.enqueueMergeRollup(provingState, parentLocation);
889
865
  }
890
866
  }
891
867
 
892
- private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
868
+ private async checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
893
869
  if (!provingState.isReadyForBlockRootRollup()) {
894
870
  logger.debug('Not ready for root rollup');
895
871
  return;
@@ -911,29 +887,32 @@ export class ProvingOrchestrator implements EpochProver {
911
887
  .then(() => this.dbs.delete(blockNumber))
912
888
  .catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
913
889
 
914
- this.enqueueBlockRootRollup(provingState);
890
+ await this.enqueueBlockRootRollup(provingState);
915
891
  }
916
892
 
917
- private checkAndEnqueueNextBlockMergeRollup(provingState: EpochProvingState, currentLocation: TreeNodeLocation) {
893
+ private async checkAndEnqueueNextBlockMergeRollup(
894
+ provingState: EpochProvingState,
895
+ currentLocation: TreeNodeLocation,
896
+ ) {
918
897
  if (!provingState.isReadyForBlockMerge(currentLocation)) {
919
898
  return;
920
899
  }
921
900
 
922
901
  const parentLocation = provingState.getParentLocation(currentLocation);
923
902
  if (parentLocation.level === 0) {
924
- this.checkAndEnqueueRootRollup(provingState);
903
+ await this.checkAndEnqueueRootRollup(provingState);
925
904
  } else {
926
- this.enqueueBlockMergeRollup(provingState, parentLocation);
905
+ await this.enqueueBlockMergeRollup(provingState, parentLocation);
927
906
  }
928
907
  }
929
908
 
930
- private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
909
+ private async checkAndEnqueueRootRollup(provingState: EpochProvingState) {
931
910
  if (!provingState.isReadyForRootRollup()) {
932
911
  logger.debug('Not ready for root rollup');
933
912
  return;
934
913
  }
935
914
 
936
- this.enqueueRootRollup(provingState);
915
+ await this.enqueueRootRollup(provingState);
937
916
  }
938
917
 
939
918
  /**
@@ -981,14 +960,14 @@ export class ProvingOrchestrator implements EpochProver {
981
960
  },
982
961
  );
983
962
 
984
- this.deferredProving(provingState, doAvmProving, proofAndVk => {
963
+ this.deferredProving(provingState, doAvmProving, async proofAndVk => {
985
964
  logger.debug(`Proven VM for tx index: ${txIndex}`);
986
965
  txProvingState.setAvmProof(proofAndVk);
987
- this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
966
+ await this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
988
967
  });
989
968
  }
990
969
 
991
- private checkAndEnqueueNextTxCircuit(provingState: BlockProvingState, txIndex: number) {
970
+ private async checkAndEnqueueNextTxCircuit(provingState: BlockProvingState, txIndex: number) {
992
971
  const txProvingState = provingState.getTxProvingState(txIndex);
993
972
  if (!txProvingState.ready()) {
994
973
  return;
@@ -997,6 +976,6 @@ export class ProvingOrchestrator implements EpochProver {
997
976
  // We must have completed all proving (tube proof and (if required) vm proof are generated), we now move to the base rollup.
998
977
  logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
999
978
 
1000
- this.enqueueBaseRollup(provingState, txIndex);
979
+ await this.enqueueBaseRollup(provingState, txIndex);
1001
980
  }
1002
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
  }
@@ -1,14 +1,14 @@
1
1
  import { ProverAgentApiSchema, type ProvingJobSource, ProvingJobSourceSchema } from '@aztec/circuit-types';
2
- import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
3
- import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
2
+ import { createSafeJsonRpcClient } from '@aztec/foundation/json-rpc/client';
3
+ import { createTracedJsonRpcServer, makeTracedFetch } from '@aztec/telemetry-client';
4
4
 
5
5
  import { type ProverAgent } from './prover-agent.js';
6
6
 
7
7
  export function createProvingJobSourceServer(queue: ProvingJobSource) {
8
- return createSafeJsonRpcServer(queue, ProvingJobSourceSchema);
8
+ return createTracedJsonRpcServer(queue, ProvingJobSourceSchema);
9
9
  }
10
10
 
11
- export function createProvingJobSourceClient(url: string, fetch = makeFetch([1, 2, 3], false)): ProvingJobSource {
11
+ export function createProvingJobSourceClient(url: string, fetch = makeTracedFetch([1, 2, 3], false)): ProvingJobSource {
12
12
  return createSafeJsonRpcClient(url, ProvingJobSourceSchema, false, 'provingJobSource', fetch);
13
13
  }
14
14
 
@@ -18,5 +18,5 @@ export function createProvingJobSourceClient(url: string, fetch = makeFetch([1,
18
18
  * @returns An JSON-RPC HTTP server
19
19
  */
20
20
  export function createProverAgentRpcServer(agent: ProverAgent) {
21
- return createSafeJsonRpcServer(agent, ProverAgentApiSchema);
21
+ return createTracedJsonRpcServer(agent, ProverAgentApiSchema);
22
22
  }
@@ -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);
@@ -35,8 +35,12 @@ export class ServerEpochProver implements EpochProver {
35
35
  await this.facade.stop();
36
36
  await this.orchestrator.stop();
37
37
  }
38
- startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[]): Promise<void> {
39
- return this.orchestrator.startNewBlock(globalVariables, l1ToL2Messages);
38
+ startNewBlock(
39
+ globalVariables: GlobalVariables,
40
+ l1ToL2Messages: Fr[],
41
+ previousBlockHeader: BlockHeader,
42
+ ): Promise<void> {
43
+ return this.orchestrator.startNewBlock(globalVariables, l1ToL2Messages, previousBlockHeader);
40
44
  }
41
45
  addTxs(txs: ProcessedTx[]): Promise<void> {
42
46
  return this.orchestrator.addTxs(txs);