@aztec-labs/prover-client 6.0.0-nightly.20260829

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 (170) hide show
  1. package/README.md +1 -0
  2. package/dest/config.d.ts +17 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +63 -0
  5. package/dest/index.d.ts +4 -0
  6. package/dest/index.d.ts.map +1 -0
  7. package/dest/index.js +2 -0
  8. package/dest/light/index.d.ts +2 -0
  9. package/dest/light/index.d.ts.map +1 -0
  10. package/dest/light/index.js +1 -0
  11. package/dest/light/lightweight_checkpoint_builder.d.ts +58 -0
  12. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  13. package/dest/light/lightweight_checkpoint_builder.js +243 -0
  14. package/dest/mocks/fixtures.d.ts +20 -0
  15. package/dest/mocks/fixtures.d.ts.map +1 -0
  16. package/dest/mocks/fixtures.js +96 -0
  17. package/dest/mocks/test_context.d.ts +93 -0
  18. package/dest/mocks/test_context.d.ts.map +1 -0
  19. package/dest/mocks/test_context.js +354 -0
  20. package/dest/orchestrator/block-building-helpers.d.ts +67 -0
  21. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -0
  22. package/dest/orchestrator/block-building-helpers.js +274 -0
  23. package/dest/orchestrator/block-proving-state.d.ts +107 -0
  24. package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
  25. package/dest/orchestrator/block-proving-state.js +339 -0
  26. package/dest/orchestrator/checkpoint-proving-state.d.ts +67 -0
  27. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  28. package/dest/orchestrator/checkpoint-proving-state.js +175 -0
  29. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +169 -0
  30. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  31. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1047 -0
  32. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  33. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  34. package/dest/orchestrator/chonk-cache.js +80 -0
  35. package/dest/orchestrator/index.d.ts +4 -0
  36. package/dest/orchestrator/index.d.ts.map +1 -0
  37. package/dest/orchestrator/index.js +3 -0
  38. package/dest/orchestrator/orchestrator_metrics.d.ts +8 -0
  39. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -0
  40. package/dest/orchestrator/orchestrator_metrics.js +13 -0
  41. package/dest/orchestrator/proving-scheduler.d.ts +81 -0
  42. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  43. package/dest/orchestrator/proving-scheduler.js +120 -0
  44. package/dest/orchestrator/top-tree-orchestrator.d.ts +89 -0
  45. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  46. package/dest/orchestrator/top-tree-orchestrator.js +233 -0
  47. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  48. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  49. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  50. package/dest/orchestrator/tx-proving-state.d.ts +37 -0
  51. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -0
  52. package/dest/orchestrator/tx-proving-state.js +77 -0
  53. package/dest/prover-client/factory.d.ts +6 -0
  54. package/dest/prover-client/factory.d.ts.map +1 -0
  55. package/dest/prover-client/factory.js +5 -0
  56. package/dest/prover-client/index.d.ts +3 -0
  57. package/dest/prover-client/index.d.ts.map +1 -0
  58. package/dest/prover-client/index.js +2 -0
  59. package/dest/prover-client/prover-client.d.ts +99 -0
  60. package/dest/prover-client/prover-client.d.ts.map +1 -0
  61. package/dest/prover-client/prover-client.js +163 -0
  62. package/dest/proving_broker/broker_prover_facade.d.ts +52 -0
  63. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -0
  64. package/dest/proving_broker/broker_prover_facade.js +360 -0
  65. package/dest/proving_broker/config.d.ts +40 -0
  66. package/dest/proving_broker/config.d.ts.map +1 -0
  67. package/dest/proving_broker/config.js +138 -0
  68. package/dest/proving_broker/factory.d.ts +5 -0
  69. package/dest/proving_broker/factory.d.ts.map +1 -0
  70. package/dest/proving_broker/factory.js +13 -0
  71. package/dest/proving_broker/fixtures.d.ts +6 -0
  72. package/dest/proving_broker/fixtures.d.ts.map +1 -0
  73. package/dest/proving_broker/fixtures.js +13 -0
  74. package/dest/proving_broker/index.d.ts +11 -0
  75. package/dest/proving_broker/index.d.ts.map +1 -0
  76. package/dest/proving_broker/index.js +10 -0
  77. package/dest/proving_broker/proof_store/factory.d.ts +3 -0
  78. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -0
  79. package/dest/proving_broker/proof_store/factory.js +13 -0
  80. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  81. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  82. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  83. package/dest/proving_broker/proof_store/index.d.ts +5 -0
  84. package/dest/proving_broker/proof_store/index.d.ts.map +1 -0
  85. package/dest/proving_broker/proof_store/index.js +4 -0
  86. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +15 -0
  87. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -0
  88. package/dest/proving_broker/proof_store/inline_proof_store.js +41 -0
  89. package/dest/proving_broker/proof_store/proof_store.d.ts +36 -0
  90. package/dest/proving_broker/proof_store/proof_store.d.ts.map +1 -0
  91. package/dest/proving_broker/proof_store/proof_store.js +3 -0
  92. package/dest/proving_broker/proving_agent.d.ts +42 -0
  93. package/dest/proving_broker/proving_agent.d.ts.map +1 -0
  94. package/dest/proving_broker/proving_agent.js +155 -0
  95. package/dest/proving_broker/proving_broker.d.ts +77 -0
  96. package/dest/proving_broker/proving_broker.d.ts.map +1 -0
  97. package/dest/proving_broker/proving_broker.js +780 -0
  98. package/dest/proving_broker/proving_broker_database/memory.d.ts +20 -0
  99. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -0
  100. package/dest/proving_broker/proving_broker_database/memory.js +67 -0
  101. package/dest/proving_broker/proving_broker_database/persisted.d.ts +40 -0
  102. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -0
  103. package/dest/proving_broker/proving_broker_database/persisted.js +623 -0
  104. package/dest/proving_broker/proving_broker_database.d.ts +66 -0
  105. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -0
  106. package/dest/proving_broker/proving_broker_database.js +3 -0
  107. package/dest/proving_broker/proving_broker_instrumentation.d.ts +31 -0
  108. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -0
  109. package/dest/proving_broker/proving_broker_instrumentation.js +97 -0
  110. package/dest/proving_broker/proving_job_controller.d.ts +34 -0
  111. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -0
  112. package/dest/proving_broker/proving_job_controller.js +184 -0
  113. package/dest/proving_broker/rpc.d.ts +38 -0
  114. package/dest/proving_broker/rpc.d.ts.map +1 -0
  115. package/dest/proving_broker/rpc.js +138 -0
  116. package/dest/test/epoch_settlement.d.ts +36 -0
  117. package/dest/test/epoch_settlement.d.ts.map +1 -0
  118. package/dest/test/epoch_settlement.js +52 -0
  119. package/dest/test/index.d.ts +2 -0
  120. package/dest/test/index.d.ts.map +1 -0
  121. package/dest/test/index.js +1 -0
  122. package/dest/test/mock_proof_store.d.ts +9 -0
  123. package/dest/test/mock_proof_store.d.ts.map +1 -0
  124. package/dest/test/mock_proof_store.js +10 -0
  125. package/dest/test/mock_prover.d.ts +38 -0
  126. package/dest/test/mock_prover.d.ts.map +1 -0
  127. package/dest/test/mock_prover.js +91 -0
  128. package/package.json +113 -0
  129. package/src/config.ts +87 -0
  130. package/src/index.ts +4 -0
  131. package/src/light/index.ts +1 -0
  132. package/src/light/lightweight_checkpoint_builder.ts +342 -0
  133. package/src/mocks/fixtures.ts +120 -0
  134. package/src/mocks/test_context.ts +477 -0
  135. package/src/orchestrator/block-building-helpers.ts +486 -0
  136. package/src/orchestrator/block-proving-state.ts +457 -0
  137. package/src/orchestrator/checkpoint-proving-state.ts +247 -0
  138. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1010 -0
  139. package/src/orchestrator/chonk-cache.ts +99 -0
  140. package/src/orchestrator/index.ts +12 -0
  141. package/src/orchestrator/orchestrator_metrics.ts +18 -0
  142. package/src/orchestrator/proving-scheduler.ts +160 -0
  143. package/src/orchestrator/top-tree-orchestrator.ts +394 -0
  144. package/src/orchestrator/top-tree-proving-state.ts +219 -0
  145. package/src/orchestrator/tx-proving-state.ts +121 -0
  146. package/src/prover-client/factory.ts +18 -0
  147. package/src/prover-client/index.ts +2 -0
  148. package/src/prover-client/prover-client.ts +286 -0
  149. package/src/proving_broker/broker_prover_facade.ts +626 -0
  150. package/src/proving_broker/config.ts +178 -0
  151. package/src/proving_broker/factory.ts +19 -0
  152. package/src/proving_broker/fixtures.ts +20 -0
  153. package/src/proving_broker/index.ts +10 -0
  154. package/src/proving_broker/proof_store/factory.ts +20 -0
  155. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  156. package/src/proving_broker/proof_store/index.ts +4 -0
  157. package/src/proving_broker/proof_store/inline_proof_store.ts +63 -0
  158. package/src/proving_broker/proof_store/proof_store.ts +54 -0
  159. package/src/proving_broker/proving_agent.ts +210 -0
  160. package/src/proving_broker/proving_broker.ts +888 -0
  161. package/src/proving_broker/proving_broker_database/memory.ts +78 -0
  162. package/src/proving_broker/proving_broker_database/persisted.ts +296 -0
  163. package/src/proving_broker/proving_broker_database.ts +75 -0
  164. package/src/proving_broker/proving_broker_instrumentation.ts +133 -0
  165. package/src/proving_broker/proving_job_controller.ts +199 -0
  166. package/src/proving_broker/rpc.ts +131 -0
  167. package/src/test/epoch_settlement.ts +82 -0
  168. package/src/test/index.ts +1 -0
  169. package/src/test/mock_proof_store.ts +14 -0
  170. package/src/test/mock_prover.ts +304 -0
@@ -0,0 +1,219 @@
1
+ import type { BatchedBlob, BatchedBlobAccumulator, FinalBlobBatchingChallenges } from '@aztec-labs/blob-lib';
2
+ import type { NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec-labs/constants';
3
+ import { EpochNumber } from '@aztec-labs/foundation/branded-types';
4
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec-labs/foundation/trees';
5
+ import type { PublicInputsAndRecursiveProof } from '@aztec-labs/stdlib/interfaces/server';
6
+ import type { Proof } from '@aztec-labs/stdlib/proofs';
7
+ import {
8
+ CheckpointMergeRollupPrivateInputs,
9
+ CheckpointPaddingRollupPrivateInputs,
10
+ CheckpointRollupPublicInputs,
11
+ RootRollupPrivateInputs,
12
+ type RootRollupPublicInputs,
13
+ } from '@aztec-labs/stdlib/rollup';
14
+
15
+ import { toProofData } from './block-building-helpers.js';
16
+ import type { ProofState } from './block-proving-state.js';
17
+
18
+ enum TOP_TREE_LIFECYCLE {
19
+ CREATED,
20
+ RESOLVED,
21
+ REJECTED,
22
+ }
23
+
24
+ /**
25
+ * Lean top-tree-only state. Owns the merge tree of checkpoint root proofs, the
26
+ * single-checkpoint padding proof slot, the final root rollup proof, and the blob
27
+ * accumulator endpoints needed to finalise the epoch's batched blob proof.
28
+ *
29
+ * Constructed with `totalNumCheckpoints` and `finalBlobBatchingChallenges` upfront —
30
+ * by the time the top tree starts, all checkpoints are known and the challenges are
31
+ * derivable from their blob fields.
32
+ */
33
+ export class TopTreeProvingState {
34
+ private checkpointProofs: UnbalancedTreeStore<
35
+ ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
36
+ >;
37
+ private checkpointPaddingProof:
38
+ | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
39
+ | undefined;
40
+ private rootRollupProof: ProofState<RootRollupPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
41
+ private endBlobAccumulator: BatchedBlobAccumulator | undefined;
42
+ private finalBatchedBlob: BatchedBlob | undefined;
43
+ private lifecycle = TOP_TREE_LIFECYCLE.CREATED;
44
+ constructor(
45
+ public readonly epochNumber: EpochNumber,
46
+ public readonly totalNumCheckpoints: number,
47
+ public readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
48
+ public readonly startBlobAccumulator: BatchedBlobAccumulator,
49
+ private readonly completionCallback: () => void,
50
+ private readonly rejectionCallback: (reason: string) => void,
51
+ ) {
52
+ if (totalNumCheckpoints < 1) {
53
+ throw new Error(`TopTreeProvingState requires at least one checkpoint; got ${totalNumCheckpoints}.`);
54
+ }
55
+ this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
56
+ }
57
+
58
+ // --- checkpoint root rollup ---
59
+
60
+ public setCheckpointRootRollupProof(
61
+ checkpointIndex: number,
62
+ provingOutput: PublicInputsAndRecursiveProof<
63
+ CheckpointRollupPublicInputs,
64
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
65
+ >,
66
+ ): TreeNodeLocation {
67
+ return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
68
+ }
69
+
70
+ // --- checkpoint merge rollup ---
71
+
72
+ public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
73
+ if (this.checkpointProofs.getNode(location)?.isProving) {
74
+ return false;
75
+ }
76
+ this.checkpointProofs.setNode(location, { isProving: true });
77
+ return true;
78
+ }
79
+
80
+ public setCheckpointMergeRollupProof(
81
+ location: TreeNodeLocation,
82
+ provingOutput: PublicInputsAndRecursiveProof<
83
+ CheckpointRollupPublicInputs,
84
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
85
+ >,
86
+ ) {
87
+ this.checkpointProofs.setNode(location, { provingOutput });
88
+ }
89
+
90
+ public isReadyForCheckpointMerge(location: TreeNodeLocation) {
91
+ return !!this.checkpointProofs.getSibling(location)?.provingOutput;
92
+ }
93
+
94
+ public getParentLocation(location: TreeNodeLocation) {
95
+ return this.checkpointProofs.getParentLocation(location);
96
+ }
97
+
98
+ public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
99
+ const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
100
+ if (!left || !right) {
101
+ throw new Error('At least one child is not ready for the checkpoint merge rollup.');
102
+ }
103
+ return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
104
+ }
105
+
106
+ // --- padding (single-checkpoint case) ---
107
+
108
+ public tryStartProvingPaddingCheckpoint() {
109
+ if (this.checkpointPaddingProof?.isProving) {
110
+ return false;
111
+ }
112
+ this.checkpointPaddingProof = { isProving: true };
113
+ return true;
114
+ }
115
+
116
+ public setCheckpointPaddingProof(
117
+ provingOutput: PublicInputsAndRecursiveProof<
118
+ CheckpointRollupPublicInputs,
119
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
120
+ >,
121
+ ) {
122
+ this.checkpointPaddingProof = { provingOutput };
123
+ }
124
+
125
+ public getPaddingCheckpointInputs() {
126
+ return new CheckpointPaddingRollupPrivateInputs();
127
+ }
128
+
129
+ // --- root rollup ---
130
+
131
+ public tryStartProvingRootRollup() {
132
+ if (this.rootRollupProof?.isProving) {
133
+ return false;
134
+ }
135
+ this.rootRollupProof = { isProving: true };
136
+ return true;
137
+ }
138
+
139
+ public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
140
+ this.rootRollupProof = { provingOutput };
141
+ }
142
+
143
+ public isReadyForRootRollup() {
144
+ const childProofs = this.#getChildProofsForRoot();
145
+ return childProofs.every(p => !!p);
146
+ }
147
+
148
+ public getRootRollupInputs() {
149
+ const [left, right] = this.#getChildProofsForRoot();
150
+ if (!left || !right) {
151
+ throw new Error('At least one child is not ready for the root rollup.');
152
+ }
153
+ return RootRollupPrivateInputs.from({
154
+ previousRollups: [toProofData(left), toProofData(right)],
155
+ });
156
+ }
157
+
158
+ // --- blob accumulator finalisation ---
159
+
160
+ /**
161
+ * Sets the end-of-epoch blob accumulator, computed by the top-tree orchestrator
162
+ * from the surviving checkpoints' blob fields. Required before `finalizeBatchedBlob`.
163
+ */
164
+ public setEndBlobAccumulator(accumulator: BatchedBlobAccumulator) {
165
+ this.endBlobAccumulator = accumulator;
166
+ }
167
+
168
+ public async finalizeBatchedBlob() {
169
+ if (!this.endBlobAccumulator) {
170
+ throw new Error('End blob accumulator not set; call setEndBlobAccumulator before finalize.');
171
+ }
172
+ this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
173
+ }
174
+
175
+ public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
176
+ const provingOutput = this.rootRollupProof?.provingOutput;
177
+ if (!provingOutput || !this.finalBatchedBlob) {
178
+ throw new Error('Top-tree proof not ready; root rollup or batched blob missing.');
179
+ }
180
+ return {
181
+ proof: provingOutput.proof.binaryProof,
182
+ publicInputs: provingOutput.inputs,
183
+ batchedBlobInputs: this.finalBatchedBlob,
184
+ };
185
+ }
186
+
187
+ // --- lifecycle ---
188
+
189
+ public verifyState() {
190
+ return this.lifecycle === TOP_TREE_LIFECYCLE.CREATED;
191
+ }
192
+
193
+ public resolve() {
194
+ if (!this.verifyState()) {
195
+ return;
196
+ }
197
+ this.lifecycle = TOP_TREE_LIFECYCLE.RESOLVED;
198
+ this.completionCallback();
199
+ }
200
+
201
+ public reject(reason: string) {
202
+ if (!this.verifyState()) {
203
+ return;
204
+ }
205
+ this.lifecycle = TOP_TREE_LIFECYCLE.REJECTED;
206
+ this.rejectionCallback(reason);
207
+ }
208
+
209
+ public cancel() {
210
+ this.reject('Top-tree proving cancelled');
211
+ }
212
+
213
+ #getChildProofsForRoot() {
214
+ const rootLocation = { level: 0, index: 0 };
215
+ return this.totalNumCheckpoints === 1
216
+ ? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
217
+ : this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
218
+ }
219
+ }
@@ -0,0 +1,121 @@
1
+ import { AVM_V2_PROOF_LENGTH_IN_FIELDS, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec-labs/constants';
2
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { getVkData } from '@aztec-labs/noir-protocol-circuits-types/server/vks';
4
+ import type { AvmCircuitInputs } from '@aztec-labs/stdlib/avm';
5
+ import type { PublicInputsAndRecursiveProof } from '@aztec-labs/stdlib/interfaces/server';
6
+ import { ProofData, ProofDataForFixedVk, RecursiveProof } from '@aztec-labs/stdlib/proofs';
7
+ import {
8
+ type BaseRollupHints,
9
+ PrivateBaseRollupHints,
10
+ PrivateTxBaseRollupPrivateInputs,
11
+ PublicBaseRollupHints,
12
+ PublicChonkVerifierPublicInputs,
13
+ PublicTxBaseRollupPrivateInputs,
14
+ } from '@aztec-labs/stdlib/rollup';
15
+ import type { CircuitName } from '@aztec-labs/stdlib/stats';
16
+ import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec-labs/stdlib/trees';
17
+ import type { ProcessedTx } from '@aztec-labs/stdlib/tx';
18
+
19
+ import {
20
+ getChonkProofFromTx,
21
+ getPublicChonkVerifierPrivateInputsFromTx,
22
+ toProofData,
23
+ } from './block-building-helpers.js';
24
+
25
+ /**
26
+ * Helper class to manage the proving cycle of a transaction
27
+ * This includes the public VMs and the public kernels
28
+ * Also stores the inputs to the base rollup for this transaction and the tree snapshots
29
+ */
30
+ export class TxProvingState {
31
+ private publicChonkVerifier?: PublicInputsAndRecursiveProof<
32
+ PublicChonkVerifierPublicInputs,
33
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
34
+ >;
35
+ private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>;
36
+
37
+ constructor(
38
+ public readonly processedTx: ProcessedTx,
39
+ private readonly baseRollupHints: BaseRollupHints,
40
+ public readonly treeSnapshots: Map<MerkleTreeId, AppendOnlyTreeSnapshot>,
41
+ private readonly proverId: Fr,
42
+ ) {}
43
+
44
+ get requireAvmProof() {
45
+ return !!this.processedTx.avmProvingRequest;
46
+ }
47
+
48
+ public ready() {
49
+ return !this.requireAvmProof || (!!this.avmProof && !!this.publicChonkVerifier);
50
+ }
51
+
52
+ public getAvmInputs(): AvmCircuitInputs {
53
+ return this.processedTx.avmProvingRequest!.inputs;
54
+ }
55
+
56
+ public getPublicChonkVerifierPrivateInputs() {
57
+ return getPublicChonkVerifierPrivateInputsFromTx(this.processedTx, this.proverId);
58
+ }
59
+
60
+ public getBaseRollupTypeAndInputs() {
61
+ if (this.requireAvmProof) {
62
+ return {
63
+ rollupType: 'rollup-tx-base-public' satisfies CircuitName,
64
+ inputs: this.#getPublicBaseInputs(),
65
+ };
66
+ } else {
67
+ return {
68
+ rollupType: 'rollup-tx-base-private' satisfies CircuitName,
69
+ inputs: this.#getPrivateBaseInputs(),
70
+ };
71
+ }
72
+ }
73
+
74
+ public setPublicChonkVerifierProof(
75
+ publicChonkVerifierProofAndVk: PublicInputsAndRecursiveProof<
76
+ PublicChonkVerifierPublicInputs,
77
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
78
+ >,
79
+ ) {
80
+ this.publicChonkVerifier = publicChonkVerifierProofAndVk;
81
+ }
82
+
83
+ public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>) {
84
+ this.avmProof = avmProof;
85
+ }
86
+
87
+ #getPrivateBaseInputs() {
88
+ if (!(this.baseRollupHints instanceof PrivateBaseRollupHints)) {
89
+ throw new Error('Mismatched base rollup hints, expected private base rollup hints');
90
+ }
91
+
92
+ const privateTailProofData = new ProofData(
93
+ this.processedTx.data.toPrivateToRollupKernelCircuitPublicInputs(),
94
+ getChonkProofFromTx(this.processedTx),
95
+ getVkData('HidingKernelToRollup'),
96
+ );
97
+
98
+ return new PrivateTxBaseRollupPrivateInputs(privateTailProofData, this.baseRollupHints);
99
+ }
100
+
101
+ #getPublicBaseInputs() {
102
+ if (!this.processedTx.avmProvingRequest) {
103
+ throw new Error('Should create private base rollup for a tx not requiring avm proof.');
104
+ }
105
+ if (!this.publicChonkVerifier) {
106
+ throw new Error('Tx not ready for proving base rollup: public chonk verifier proof undefined');
107
+ }
108
+ if (!this.avmProof) {
109
+ throw new Error('Tx not ready for proving base rollup: avm proof undefined');
110
+ }
111
+ if (!(this.baseRollupHints instanceof PublicBaseRollupHints)) {
112
+ throw new Error('Mismatched base rollup hints, expected public base rollup hints');
113
+ }
114
+
115
+ const publicChonkVerifierProofData = toProofData(this.publicChonkVerifier);
116
+
117
+ const avmProofData = new ProofDataForFixedVk(this.processedTx.avmProvingRequest.inputs.publicInputs, this.avmProof);
118
+
119
+ return new PublicTxBaseRollupPrivateInputs(publicChonkVerifierProofData, avmProofData, this.baseRollupHints);
120
+ }
121
+ }
@@ -0,0 +1,18 @@
1
+ import type {
2
+ ForkMerkleTreeOperations,
3
+ ProvingJobBroker,
4
+ ReadonlyWorldStateAccess,
5
+ } from '@aztec-labs/stdlib/interfaces/server';
6
+ import { type TelemetryClient, getTelemetryClient } from '@aztec-labs/telemetry-client';
7
+
8
+ import type { ProverClientConfig } from '../config.js';
9
+ import { ProverClient } from './prover-client.js';
10
+
11
+ export function createProverClient(
12
+ config: ProverClientConfig,
13
+ worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
14
+ broker: ProvingJobBroker,
15
+ telemetry: TelemetryClient = getTelemetryClient(),
16
+ ) {
17
+ return ProverClient.new(config, worldState, broker, telemetry);
18
+ }
@@ -0,0 +1,2 @@
1
+ export * from './factory.js';
2
+ export * from './prover-client.js';
@@ -0,0 +1,286 @@
1
+ import { type ACVMConfig, type BBConfig, BBNativeRollupProver, TestCircuitProver } from '@aztec-labs/bb-prover';
2
+ import type { EpochNumber } from '@aztec-labs/foundation/branded-types';
3
+ import { times } from '@aztec-labs/foundation/collection';
4
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
5
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
6
+ import { type Logger, createLogger } from '@aztec-labs/foundation/log';
7
+ import { SerialQueue } from '@aztec-labs/foundation/queue';
8
+ import { NativeACVMSimulator } from '@aztec-labs/simulator/server';
9
+ import {
10
+ type ActualProverConfig,
11
+ type EpochProverManager,
12
+ type ForkMerkleTreeOperations,
13
+ type ProvingJobBroker,
14
+ type ProvingJobConsumer,
15
+ type ProvingJobProducer,
16
+ type ReadonlyWorldStateAccess,
17
+ type ServerCircuitProver,
18
+ tryStop,
19
+ } from '@aztec-labs/stdlib/interfaces/server';
20
+ import type { CheckpointConstantData } from '@aztec-labs/stdlib/rollup';
21
+ import type { BlockHeader } from '@aztec-labs/stdlib/tx';
22
+ import { type TelemetryClient, getTelemetryClient } from '@aztec-labs/telemetry-client';
23
+
24
+ import type { ProverClientConfig } from '../config.js';
25
+ import { CheckpointSubTreeOrchestrator } from '../orchestrator/checkpoint-sub-tree-orchestrator.js';
26
+ import type { ChonkCache } from '../orchestrator/chonk-cache.js';
27
+ import { TopTreeOrchestrator } from '../orchestrator/top-tree-orchestrator.js';
28
+ import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
29
+ import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
30
+ import { ProvingAgent } from '../proving_broker/proving_agent.js';
31
+
32
+ /**
33
+ * The factory surface that `EpochProvingJob` (in `prover-node`) depends on. Implemented
34
+ * by `ProverClient`. Defined here rather than in stdlib because the return types
35
+ * (`CheckpointSubTreeOrchestrator`, `TopTreeOrchestrator`) are concrete classes from
36
+ * this package.
37
+ *
38
+ * A single `BrokerCircuitProverFacade` is owned by `ProverClient` and shared across
39
+ * every orchestrator (every sub-tree and every top-tree across every concurrent epoch
40
+ * job). The broker delivers each completed-job notification exactly once (drained on
41
+ * the first `getCompletedJobs` poll), so multiple facades polling the same broker
42
+ * race and lose notifications
43
+ *
44
+ * The facade's job map cleans up entries on resolve/reject, and the prover-node
45
+ * keeps `ProverClient` alive for its whole lifetime
46
+ */
47
+ export interface EpochProverFactory {
48
+ getProverId(): EthAddress;
49
+ /**
50
+ * Constructs and starts a `CheckpointSubTreeOrchestrator` for a single checkpoint
51
+ * against the supplied shared `chonkCache`. The cache is owned by the prover-node
52
+ * and survives across epochs / sessions.
53
+ */
54
+ createCheckpointSubTreeOrchestrator(
55
+ chonkCache: ChonkCache,
56
+ epochNumber: EpochNumber,
57
+ checkpointConstants: CheckpointConstantData,
58
+ l1ToL2Messages: Fr[],
59
+ startInboxRollingHash: Fr,
60
+ totalNumBlocks: number,
61
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
62
+ ): Promise<CheckpointSubTreeOrchestrator>;
63
+ createTopTreeOrchestrator(): TopTreeOrchestrator;
64
+ }
65
+
66
+ /** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
67
+ export class ProverClient implements EpochProverManager, EpochProverFactory {
68
+ private running = false;
69
+ private agents: ProvingAgent[] = [];
70
+ /**
71
+ * The single broker facade shared by every orchestrator created from this client.
72
+ * Constructed lazily on `start()` and torn down on `stop()` — see the comment on
73
+ * `EpochProverFactory` for why a single shared facade is required.
74
+ */
75
+ private facade: BrokerCircuitProverFacade | undefined;
76
+ /**
77
+ * Single deferred-proving-job queue shared across every orchestrator (sub-trees and
78
+ * top-trees, across every concurrent epoch session). Throttles the total rate of job
79
+ * submission to the broker once, rather than once per orchestrator. Started lazily
80
+ * alongside the facade and cancelled on `stop()`.
81
+ */
82
+ private deferredJobQueue: SerialQueue | undefined;
83
+
84
+ private constructor(
85
+ private config: ProverClientConfig,
86
+ private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
87
+ private orchestratorClient: ProvingJobProducer,
88
+ private proofStore: ProofStore,
89
+ private failedProofStore: ProofStore | undefined,
90
+ private agentClient?: ProvingJobConsumer,
91
+ private telemetry: TelemetryClient = getTelemetryClient(),
92
+ private log: Logger = createLogger('prover-client:tx-prover'),
93
+ ) {}
94
+
95
+ /**
96
+ * Lazy-init the shared facade. The broker delivers each completed-job notification
97
+ * exactly once (drained on the first `getCompletedJobs` poll), so we cannot start
98
+ * a shared facade alongside the per-call facades that `createEpochProver` builds —
99
+ * they would race for notifications and one side would silently drop them. Starting
100
+ * the shared facade only on first use of one of the new factory methods keeps the
101
+ * legacy `createEpochProver` path race-free.
102
+ */
103
+ private getFacade(): BrokerCircuitProverFacade {
104
+ if (!this.running) {
105
+ throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
106
+ }
107
+ if (!this.facade) {
108
+ this.facade = new BrokerCircuitProverFacade(
109
+ this.orchestratorClient,
110
+ this.proofStore,
111
+ this.failedProofStore,
112
+ undefined,
113
+ this.log.getBindings(),
114
+ );
115
+ this.facade.start();
116
+ }
117
+ return this.facade;
118
+ }
119
+
120
+ /** Lazy-init the shared deferred-job queue, started with the configured enqueue concurrency. */
121
+ private getDeferredJobQueue(): SerialQueue {
122
+ if (!this.running) {
123
+ throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
124
+ }
125
+ if (!this.deferredJobQueue) {
126
+ this.deferredJobQueue = new SerialQueue();
127
+ this.deferredJobQueue.start(this.config.enqueueConcurrency);
128
+ }
129
+ return this.deferredJobQueue;
130
+ }
131
+
132
+ public createCheckpointSubTreeOrchestrator(
133
+ chonkCache: ChonkCache,
134
+ epochNumber: EpochNumber,
135
+ checkpointConstants: CheckpointConstantData,
136
+ l1ToL2Messages: Fr[],
137
+ startInboxRollingHash: Fr,
138
+ totalNumBlocks: number,
139
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
140
+ ): Promise<CheckpointSubTreeOrchestrator> {
141
+ return CheckpointSubTreeOrchestrator.start(
142
+ this.worldState,
143
+ this.getFacade(),
144
+ this.config.proverId,
145
+ chonkCache,
146
+ epochNumber,
147
+ this.config.cancelJobsOnStop,
148
+ this.getDeferredJobQueue(),
149
+ checkpointConstants,
150
+ l1ToL2Messages,
151
+ startInboxRollingHash,
152
+ totalNumBlocks,
153
+ headerOfLastBlockInPreviousCheckpoint,
154
+ this.telemetry,
155
+ this.log.getBindings(),
156
+ );
157
+ }
158
+
159
+ public createTopTreeOrchestrator(): TopTreeOrchestrator {
160
+ return new TopTreeOrchestrator(
161
+ this.getFacade(),
162
+ this.config.proverId,
163
+ this.getDeferredJobQueue(),
164
+ this.telemetry,
165
+ this.log.getBindings(),
166
+ );
167
+ }
168
+
169
+ public getProverId(): EthAddress {
170
+ return this.config.proverId;
171
+ }
172
+
173
+ async updateProverConfig(config: Partial<ProverClientConfig>): Promise<void> {
174
+ const newConfig = { ...this.config, ...config };
175
+
176
+ if (
177
+ newConfig.realProofs !== this.config.realProofs ||
178
+ newConfig.proverAgentCount !== this.config.proverAgentCount
179
+ ) {
180
+ await this.stopAgents();
181
+ await this.createAndStartAgents();
182
+ }
183
+
184
+ this.config = newConfig;
185
+ }
186
+
187
+ /**
188
+ * Starts the prover instance
189
+ */
190
+ public async start(): Promise<void> {
191
+ if (this.running) {
192
+ return Promise.resolve();
193
+ }
194
+
195
+ this.running = true;
196
+ await this.createAndStartAgents();
197
+ }
198
+
199
+ /**
200
+ * Stops the prover instance
201
+ */
202
+ public async stop() {
203
+ if (!this.running) {
204
+ return;
205
+ }
206
+ this.running = false;
207
+ await this.stopAgents();
208
+ if (this.deferredJobQueue) {
209
+ await this.deferredJobQueue.cancel();
210
+ this.deferredJobQueue = undefined;
211
+ }
212
+ if (this.facade) {
213
+ await tryStop(this.facade, this.log);
214
+ this.facade = undefined;
215
+ }
216
+ await tryStop(this.orchestratorClient);
217
+ }
218
+
219
+ /**
220
+ * Creates a new prover client and starts it
221
+ * @param config - The prover configuration.
222
+ * @param worldState - An instance of the world state
223
+ * @returns An instance of the prover, constructed and started.
224
+ */
225
+ public static async new(
226
+ config: ProverClientConfig,
227
+ worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
228
+ broker: ProvingJobBroker,
229
+ telemetry: TelemetryClient = getTelemetryClient(),
230
+ ) {
231
+ const proofStore = await createProofStore(config.proofStore);
232
+ const failedProofStore = config.failedProofStore ? await createProofStore(config.failedProofStore) : undefined;
233
+ const prover = new ProverClient(config, worldState, broker, proofStore, failedProofStore, broker, telemetry);
234
+ await prover.start();
235
+ return prover;
236
+ }
237
+
238
+ public getProvingJobSource(): ProvingJobConsumer {
239
+ if (!this.agentClient) {
240
+ throw new Error('Agent client not provided');
241
+ }
242
+
243
+ return this.agentClient;
244
+ }
245
+
246
+ private async createAndStartAgents(): Promise<void> {
247
+ if (this.agents.length > 0) {
248
+ throw new Error('Agents already started');
249
+ }
250
+
251
+ if (!this.agentClient) {
252
+ throw new Error('Agent client not provided');
253
+ }
254
+
255
+ const proofStore = new InlineProofStore();
256
+ const prover = await buildServerCircuitProver(this.config, this.telemetry);
257
+ const bindings = this.log.getBindings();
258
+ this.agents = times(
259
+ this.config.proverAgentCount,
260
+ () =>
261
+ new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs, bindings),
262
+ );
263
+
264
+ await Promise.all(this.agents.map(agent => agent.start()));
265
+ }
266
+
267
+ private async stopAgents() {
268
+ await Promise.all(this.agents.map(agent => agent.stop()));
269
+ }
270
+ }
271
+
272
+ export function buildServerCircuitProver(
273
+ config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
274
+ telemetry: TelemetryClient,
275
+ ): Promise<ServerCircuitProver> {
276
+ if (config.realProofs) {
277
+ return BBNativeRollupProver.new(config, telemetry);
278
+ }
279
+
280
+ const logger = createLogger('prover-client:acvm-native');
281
+ const simulator = config.acvmBinaryPath
282
+ ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, logger)
283
+ : undefined;
284
+
285
+ return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
286
+ }