@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97

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 (174) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +17 -3
  4. package/dest/index.d.ts +1 -1
  5. package/dest/light/index.d.ts +2 -0
  6. package/dest/light/index.d.ts.map +1 -0
  7. package/dest/light/index.js +1 -0
  8. package/dest/light/lightweight_checkpoint_builder.d.ts +52 -0
  9. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  10. package/dest/light/lightweight_checkpoint_builder.js +231 -0
  11. package/dest/mocks/fixtures.d.ts +1 -4
  12. package/dest/mocks/fixtures.d.ts.map +1 -1
  13. package/dest/mocks/fixtures.js +9 -18
  14. package/dest/mocks/test_context.d.ts +31 -46
  15. package/dest/mocks/test_context.d.ts.map +1 -1
  16. package/dest/mocks/test_context.js +133 -123
  17. package/dest/orchestrator/block-building-helpers.d.ts +18 -20
  18. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  19. package/dest/orchestrator/block-building-helpers.js +90 -115
  20. package/dest/orchestrator/block-proving-state.d.ts +20 -11
  21. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  22. package/dest/orchestrator/block-proving-state.js +87 -19
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts +29 -9
  24. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  25. package/dest/orchestrator/checkpoint-proving-state.js +62 -21
  26. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
  27. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  28. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
  29. package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
  30. package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
  31. package/dest/orchestrator/epoch-proving-context.js +81 -0
  32. package/dest/orchestrator/epoch-proving-state.d.ts +12 -10
  33. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  34. package/dest/orchestrator/epoch-proving-state.js +40 -4
  35. package/dest/orchestrator/index.d.ts +4 -1
  36. package/dest/orchestrator/index.d.ts.map +1 -1
  37. package/dest/orchestrator/index.js +3 -0
  38. package/dest/orchestrator/orchestrator.d.ts +37 -32
  39. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  40. package/dest/orchestrator/orchestrator.js +568 -303
  41. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  42. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  43. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  44. package/dest/orchestrator/proving-scheduler.d.ts +72 -0
  45. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  46. package/dest/orchestrator/proving-scheduler.js +117 -0
  47. package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
  48. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  49. package/dest/orchestrator/top-tree-orchestrator.js +182 -0
  50. package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
  51. package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
  52. package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
  53. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  54. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  55. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  56. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  57. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  58. package/dest/orchestrator/tx-proving-state.js +7 -16
  59. package/dest/prover-client/factory.d.ts +3 -3
  60. package/dest/prover-client/factory.d.ts.map +1 -1
  61. package/dest/prover-client/index.d.ts +1 -1
  62. package/dest/prover-client/prover-client.d.ts +66 -7
  63. package/dest/prover-client/prover-client.d.ts.map +1 -1
  64. package/dest/prover-client/prover-client.js +64 -11
  65. package/dest/prover-client/server-epoch-prover.d.ts +8 -7
  66. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  67. package/dest/prover-client/server-epoch-prover.js +2 -2
  68. package/dest/proving_broker/broker_prover_facade.d.ts +25 -23
  69. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  70. package/dest/proving_broker/broker_prover_facade.js +21 -33
  71. package/dest/proving_broker/config.d.ts +14 -62
  72. package/dest/proving_broker/config.d.ts.map +1 -1
  73. package/dest/proving_broker/config.js +29 -6
  74. package/dest/proving_broker/factory.d.ts +1 -1
  75. package/dest/proving_broker/fixtures.d.ts +3 -2
  76. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  77. package/dest/proving_broker/fixtures.js +3 -2
  78. package/dest/proving_broker/index.d.ts +2 -1
  79. package/dest/proving_broker/index.d.ts.map +1 -1
  80. package/dest/proving_broker/index.js +1 -0
  81. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  82. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  83. package/dest/proving_broker/proof_store/factory.js +7 -30
  84. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  85. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  86. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  87. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  88. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  89. package/dest/proving_broker/proof_store/index.js +1 -1
  90. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  91. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  92. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  93. package/dest/proving_broker/proving_agent.d.ts +5 -9
  94. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  95. package/dest/proving_broker/proving_agent.js +4 -19
  96. package/dest/proving_broker/proving_broker.d.ts +8 -5
  97. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  98. package/dest/proving_broker/proving_broker.js +74 -22
  99. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  100. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  101. package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
  102. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  103. package/dest/proving_broker/proving_broker_database/persisted.js +394 -5
  104. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  105. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  106. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  107. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  108. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  109. package/dest/proving_broker/proving_job_controller.d.ts +5 -3
  110. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  111. package/dest/proving_broker/proving_job_controller.js +8 -6
  112. package/dest/proving_broker/rpc.d.ts +9 -5
  113. package/dest/proving_broker/rpc.d.ts.map +1 -1
  114. package/dest/proving_broker/rpc.js +87 -23
  115. package/dest/test/mock_proof_store.d.ts +1 -1
  116. package/dest/test/mock_proof_store.d.ts.map +1 -1
  117. package/dest/test/mock_prover.d.ts +5 -6
  118. package/dest/test/mock_prover.d.ts.map +1 -1
  119. package/dest/test/mock_prover.js +4 -4
  120. package/package.json +23 -22
  121. package/src/config.ts +19 -3
  122. package/src/light/index.ts +1 -0
  123. package/src/light/lightweight_checkpoint_builder.ts +320 -0
  124. package/src/mocks/fixtures.ts +9 -31
  125. package/src/mocks/test_context.ts +170 -185
  126. package/src/orchestrator/block-building-helpers.ts +129 -209
  127. package/src/orchestrator/block-proving-state.ts +109 -22
  128. package/src/orchestrator/checkpoint-proving-state.ts +89 -26
  129. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
  130. package/src/orchestrator/epoch-proving-context.ts +101 -0
  131. package/src/orchestrator/epoch-proving-state.ts +67 -15
  132. package/src/orchestrator/index.ts +8 -0
  133. package/src/orchestrator/orchestrator.ts +193 -354
  134. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  135. package/src/orchestrator/proving-scheduler.ts +156 -0
  136. package/src/orchestrator/top-tree-orchestrator.ts +314 -0
  137. package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
  138. package/src/orchestrator/top-tree-proving-state.ts +220 -0
  139. package/src/orchestrator/tx-proving-state.ts +10 -27
  140. package/src/prover-client/factory.ts +6 -2
  141. package/src/prover-client/prover-client.ts +157 -24
  142. package/src/prover-client/server-epoch-prover.ts +6 -7
  143. package/src/proving_broker/broker_prover_facade.ts +46 -55
  144. package/src/proving_broker/config.ts +33 -3
  145. package/src/proving_broker/fixtures.ts +8 -3
  146. package/src/proving_broker/index.ts +1 -0
  147. package/src/proving_broker/proof_store/factory.ts +10 -32
  148. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  149. package/src/proving_broker/proof_store/index.ts +1 -1
  150. package/src/proving_broker/proving_agent.ts +6 -19
  151. package/src/proving_broker/proving_broker.ts +70 -17
  152. package/src/proving_broker/proving_broker_database/memory.ts +2 -1
  153. package/src/proving_broker/proving_broker_database/persisted.ts +22 -7
  154. package/src/proving_broker/proving_broker_database.ts +2 -1
  155. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  156. package/src/proving_broker/proving_job_controller.ts +13 -7
  157. package/src/proving_broker/rpc.ts +46 -20
  158. package/src/test/mock_prover.ts +2 -14
  159. package/dest/block-factory/index.d.ts +0 -2
  160. package/dest/block-factory/index.d.ts.map +0 -1
  161. package/dest/block-factory/index.js +0 -1
  162. package/dest/block-factory/light.d.ts +0 -38
  163. package/dest/block-factory/light.d.ts.map +0 -1
  164. package/dest/block-factory/light.js +0 -94
  165. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  166. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  167. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  168. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  169. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  170. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  171. package/src/block-factory/index.ts +0 -1
  172. package/src/block-factory/light.ts +0 -140
  173. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
  174. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -0,0 +1,220 @@
1
+ import type { BatchedBlob, BatchedBlobAccumulator, FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
+ import type { NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
3
+ import { EpochNumber } from '@aztec/foundation/branded-types';
4
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
5
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
6
+ import type { Proof } from '@aztec/stdlib/proofs';
7
+ import {
8
+ CheckpointMergeRollupPrivateInputs,
9
+ CheckpointPaddingRollupPrivateInputs,
10
+ CheckpointRollupPublicInputs,
11
+ RootRollupPrivateInputs,
12
+ type RootRollupPublicInputs,
13
+ } from '@aztec/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
+
45
+ constructor(
46
+ public readonly epochNumber: EpochNumber,
47
+ public readonly totalNumCheckpoints: number,
48
+ public readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
49
+ public readonly startBlobAccumulator: BatchedBlobAccumulator,
50
+ private readonly completionCallback: () => void,
51
+ private readonly rejectionCallback: (reason: string) => void,
52
+ ) {
53
+ if (totalNumCheckpoints < 1) {
54
+ throw new Error(`TopTreeProvingState requires at least one checkpoint; got ${totalNumCheckpoints}.`);
55
+ }
56
+ this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
57
+ }
58
+
59
+ // --- checkpoint root rollup ---
60
+
61
+ public setCheckpointRootRollupProof(
62
+ checkpointIndex: number,
63
+ provingOutput: PublicInputsAndRecursiveProof<
64
+ CheckpointRollupPublicInputs,
65
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
66
+ >,
67
+ ): TreeNodeLocation {
68
+ return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
69
+ }
70
+
71
+ // --- checkpoint merge rollup ---
72
+
73
+ public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
74
+ if (this.checkpointProofs.getNode(location)?.isProving) {
75
+ return false;
76
+ }
77
+ this.checkpointProofs.setNode(location, { isProving: true });
78
+ return true;
79
+ }
80
+
81
+ public setCheckpointMergeRollupProof(
82
+ location: TreeNodeLocation,
83
+ provingOutput: PublicInputsAndRecursiveProof<
84
+ CheckpointRollupPublicInputs,
85
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
86
+ >,
87
+ ) {
88
+ this.checkpointProofs.setNode(location, { provingOutput });
89
+ }
90
+
91
+ public isReadyForCheckpointMerge(location: TreeNodeLocation) {
92
+ return !!this.checkpointProofs.getSibling(location)?.provingOutput;
93
+ }
94
+
95
+ public getParentLocation(location: TreeNodeLocation) {
96
+ return this.checkpointProofs.getParentLocation(location);
97
+ }
98
+
99
+ public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
100
+ const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
101
+ if (!left || !right) {
102
+ throw new Error('At least one child is not ready for the checkpoint merge rollup.');
103
+ }
104
+ return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
105
+ }
106
+
107
+ // --- padding (single-checkpoint case) ---
108
+
109
+ public tryStartProvingPaddingCheckpoint() {
110
+ if (this.checkpointPaddingProof?.isProving) {
111
+ return false;
112
+ }
113
+ this.checkpointPaddingProof = { isProving: true };
114
+ return true;
115
+ }
116
+
117
+ public setCheckpointPaddingProof(
118
+ provingOutput: PublicInputsAndRecursiveProof<
119
+ CheckpointRollupPublicInputs,
120
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
121
+ >,
122
+ ) {
123
+ this.checkpointPaddingProof = { provingOutput };
124
+ }
125
+
126
+ public getPaddingCheckpointInputs() {
127
+ return new CheckpointPaddingRollupPrivateInputs();
128
+ }
129
+
130
+ // --- root rollup ---
131
+
132
+ public tryStartProvingRootRollup() {
133
+ if (this.rootRollupProof?.isProving) {
134
+ return false;
135
+ }
136
+ this.rootRollupProof = { isProving: true };
137
+ return true;
138
+ }
139
+
140
+ public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
141
+ this.rootRollupProof = { provingOutput };
142
+ }
143
+
144
+ public isReadyForRootRollup() {
145
+ const childProofs = this.#getChildProofsForRoot();
146
+ return childProofs.every(p => !!p);
147
+ }
148
+
149
+ public getRootRollupInputs() {
150
+ const [left, right] = this.#getChildProofsForRoot();
151
+ if (!left || !right) {
152
+ throw new Error('At least one child is not ready for the root rollup.');
153
+ }
154
+ return RootRollupPrivateInputs.from({
155
+ previousRollups: [toProofData(left), toProofData(right)],
156
+ });
157
+ }
158
+
159
+ // --- blob accumulator finalisation ---
160
+
161
+ /**
162
+ * Sets the end-of-epoch blob accumulator, computed by the top-tree orchestrator
163
+ * from the surviving checkpoints' blob fields. Required before `finalizeBatchedBlob`.
164
+ */
165
+ public setEndBlobAccumulator(accumulator: BatchedBlobAccumulator) {
166
+ this.endBlobAccumulator = accumulator;
167
+ }
168
+
169
+ public async finalizeBatchedBlob() {
170
+ if (!this.endBlobAccumulator) {
171
+ throw new Error('End blob accumulator not set; call setEndBlobAccumulator before finalize.');
172
+ }
173
+ this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
174
+ }
175
+
176
+ public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
177
+ const provingOutput = this.rootRollupProof?.provingOutput;
178
+ if (!provingOutput || !this.finalBatchedBlob) {
179
+ throw new Error('Top-tree proof not ready; root rollup or batched blob missing.');
180
+ }
181
+ return {
182
+ proof: provingOutput.proof.binaryProof,
183
+ publicInputs: provingOutput.inputs,
184
+ batchedBlobInputs: this.finalBatchedBlob,
185
+ };
186
+ }
187
+
188
+ // --- lifecycle ---
189
+
190
+ public verifyState() {
191
+ return this.lifecycle === TOP_TREE_LIFECYCLE.CREATED;
192
+ }
193
+
194
+ public resolve() {
195
+ if (!this.verifyState()) {
196
+ return;
197
+ }
198
+ this.lifecycle = TOP_TREE_LIFECYCLE.RESOLVED;
199
+ this.completionCallback();
200
+ }
201
+
202
+ public reject(reason: string) {
203
+ if (!this.verifyState()) {
204
+ return;
205
+ }
206
+ this.lifecycle = TOP_TREE_LIFECYCLE.REJECTED;
207
+ this.rejectionCallback(reason);
208
+ }
209
+
210
+ public cancel() {
211
+ this.reject('Top-tree proving cancelled');
212
+ }
213
+
214
+ #getChildProofsForRoot() {
215
+ const rootLocation = { level: 0, index: 0 };
216
+ return this.totalNumCheckpoints === 1
217
+ ? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
218
+ : this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
219
+ }
220
+ }
@@ -1,14 +1,9 @@
1
- import {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
3
- AVM_VK_INDEX,
4
- NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
- } from '@aztec/constants';
6
- import type { Fr } from '@aztec/foundation/fields';
1
+ import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
7
3
  import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
8
- import { getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
9
4
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
10
- import type { ProofAndVerificationKey, PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
11
- import { ProofData } from '@aztec/stdlib/proofs';
5
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
6
+ import { ProofData, ProofDataForFixedVk, RecursiveProof } from '@aztec/stdlib/proofs';
12
7
  import {
13
8
  type BaseRollupHints,
14
9
  PrivateBaseRollupHints,
@@ -20,7 +15,6 @@ import {
20
15
  import type { CircuitName } from '@aztec/stdlib/stats';
21
16
  import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
22
17
  import type { ProcessedTx } from '@aztec/stdlib/tx';
23
- import { VerificationKeyData, VkData } from '@aztec/stdlib/vks';
24
18
 
25
19
  import {
26
20
  getChonkProofFromTx,
@@ -38,7 +32,7 @@ export class TxProvingState {
38
32
  PublicChonkVerifierPublicInputs,
39
33
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
40
34
  >;
41
- private avm?: ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
35
+ private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
42
36
 
43
37
  constructor(
44
38
  public readonly processedTx: ProcessedTx,
@@ -52,7 +46,7 @@ export class TxProvingState {
52
46
  }
53
47
 
54
48
  public ready() {
55
- return !this.requireAvmProof || (!!this.avm && !!this.publicChonkVerifier);
49
+ return !this.requireAvmProof || (!!this.avmProof && !!this.publicChonkVerifier);
56
50
  }
57
51
 
58
52
  public getAvmInputs(): AvmCircuitInputs {
@@ -86,8 +80,8 @@ export class TxProvingState {
86
80
  this.publicChonkVerifier = publicChonkVerifierProofAndVk;
87
81
  }
88
82
 
89
- public setAvmProof(avmProofAndVk: ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>) {
90
- this.avm = avmProofAndVk;
83
+ public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>) {
84
+ this.avmProof = avmProof;
91
85
  }
92
86
 
93
87
  #getPrivateBaseInputs() {
@@ -111,7 +105,7 @@ export class TxProvingState {
111
105
  if (!this.publicChonkVerifier) {
112
106
  throw new Error('Tx not ready for proving base rollup: public chonk verifier proof undefined');
113
107
  }
114
- if (!this.avm) {
108
+ if (!this.avmProof) {
115
109
  throw new Error('Tx not ready for proving base rollup: avm proof undefined');
116
110
  }
117
111
  if (!(this.baseRollupHints instanceof PublicBaseRollupHints)) {
@@ -120,19 +114,8 @@ export class TxProvingState {
120
114
 
121
115
  const publicChonkVerifierProofData = toProofData(this.publicChonkVerifier);
122
116
 
123
- const avmProofData = new ProofData(
124
- this.processedTx.avmProvingRequest.inputs.publicInputs,
125
- this.avm.proof,
126
- this.#getVkData(this.avm!.verificationKey, AVM_VK_INDEX),
127
- );
117
+ const avmProofData = new ProofDataForFixedVk(this.processedTx.avmProvingRequest.inputs.publicInputs, this.avmProof);
128
118
 
129
119
  return new PublicTxBaseRollupPrivateInputs(publicChonkVerifierProofData, avmProofData, this.baseRollupHints);
130
120
  }
131
-
132
- #getVkData(verificationKey: VerificationKeyData, vkIndex: number) {
133
- // TODO(#17162): Add avm vk hash to the tree and call `getVkData('AVM')` instead.
134
- // Below will return a path to an empty leaf.
135
- const vkPath = getVKSiblingPath(vkIndex);
136
- return new VkData(verificationKey, vkIndex, vkPath);
137
- }
138
121
  }
@@ -1,4 +1,8 @@
1
- import type { ForkMerkleTreeOperations, ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
1
+ import type {
2
+ ForkMerkleTreeOperations,
3
+ ProvingJobBroker,
4
+ ReadonlyWorldStateAccess,
5
+ } from '@aztec/stdlib/interfaces/server';
2
6
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
3
7
 
4
8
  import type { ProverClientConfig } from '../config.js';
@@ -6,7 +10,7 @@ import { ProverClient } from './prover-client.js';
6
10
 
7
11
  export function createProverClient(
8
12
  config: ProverClientConfig,
9
- worldState: ForkMerkleTreeOperations,
13
+ worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
10
14
  broker: ProvingJobBroker,
11
15
  telemetry: TelemetryClient = getTelemetryClient(),
12
16
  ) {
@@ -1,7 +1,9 @@
1
1
  import { type ACVMConfig, type BBConfig, BBNativeRollupProver, TestCircuitProver } from '@aztec/bb-prover';
2
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
3
  import { times } from '@aztec/foundation/collection';
4
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
- import { createLogger } from '@aztec/foundation/log';
6
+ import { type Logger, createLogger } from '@aztec/foundation/log';
5
7
  import { NativeACVMSimulator } from '@aztec/simulator/server';
6
8
  import {
7
9
  type ActualProverConfig,
@@ -11,44 +13,170 @@ import {
11
13
  type ProvingJobBroker,
12
14
  type ProvingJobConsumer,
13
15
  type ProvingJobProducer,
16
+ type ReadonlyWorldStateAccess,
14
17
  type ServerCircuitProver,
15
18
  tryStop,
16
19
  } from '@aztec/stdlib/interfaces/server';
20
+ import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
21
+ import type { BlockHeader } from '@aztec/stdlib/tx';
17
22
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
18
23
 
19
24
  import type { ProverClientConfig } from '../config.js';
25
+ import { CheckpointSubTreeOrchestrator } from '../orchestrator/checkpoint-sub-tree-orchestrator.js';
26
+ import { EpochProvingContext } from '../orchestrator/epoch-proving-context.js';
20
27
  import { ProvingOrchestrator } from '../orchestrator/orchestrator.js';
28
+ import { TopTreeOrchestrator } from '../orchestrator/top-tree-orchestrator.js';
21
29
  import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
22
30
  import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
23
31
  import { ProvingAgent } from '../proving_broker/proving_agent.js';
24
32
  import { ServerEpochProver } from './server-epoch-prover.js';
25
33
 
34
+ /**
35
+ * The factory surface that `EpochProvingJob` (in `prover-node`) depends on. Implemented
36
+ * by `ProverClient`. Defined here rather than in stdlib because the return types
37
+ * (`CheckpointSubTreeOrchestrator`, `TopTreeOrchestrator`) are concrete classes from
38
+ * this package.
39
+ *
40
+ * A single `BrokerCircuitProverFacade` is owned by `ProverClient` and shared across
41
+ * every orchestrator (every sub-tree and every top-tree across every concurrent epoch
42
+ * job). The broker delivers each completed-job notification exactly once (drained on
43
+ * the first `getCompletedJobs` poll), so multiple facades polling the same broker
44
+ * race and lose notifications
45
+ *
46
+ * The facade's job map cleans up entries on resolve/reject, and the prover-node
47
+ * keeps `ProverClient` alive for its whole lifetime
48
+ */
49
+ export interface EpochProverFactory {
50
+ getProverId(): EthAddress;
51
+ /**
52
+ * Constructs a per-epoch shared context for the caching of e.g. chonk verifier results
53
+ */
54
+ createEpochProvingContext(epochNumber: EpochNumber): EpochProvingContext;
55
+ /**
56
+ * Constructs and starts a `CheckpointSubTreeOrchestrator` for a single checkpoint.
57
+ */
58
+ createCheckpointSubTreeOrchestrator(
59
+ epochContext: EpochProvingContext,
60
+ checkpointConstants: CheckpointConstantData,
61
+ l1ToL2Messages: Fr[],
62
+ totalNumBlocks: number,
63
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
64
+ ): Promise<CheckpointSubTreeOrchestrator>;
65
+ createTopTreeOrchestrator(): TopTreeOrchestrator;
66
+ }
67
+
26
68
  /** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
27
- export class ProverClient implements EpochProverManager {
69
+ export class ProverClient implements EpochProverManager, EpochProverFactory {
28
70
  private running = false;
29
71
  private agents: ProvingAgent[] = [];
30
-
31
- private proofStore: ProofStore;
32
- private failedProofStore: ProofStore | undefined;
72
+ /**
73
+ * The single broker facade shared by every orchestrator created from this client.
74
+ * Constructed lazily on `start()` and torn down on `stop()` — see the comment on
75
+ * `EpochProverFactory` for why a single shared facade is required.
76
+ */
77
+ private facade: BrokerCircuitProverFacade | undefined;
33
78
 
34
79
  private constructor(
35
80
  private config: ProverClientConfig,
36
- private worldState: ForkMerkleTreeOperations,
81
+ private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
37
82
  private orchestratorClient: ProvingJobProducer,
83
+ private proofStore: ProofStore,
84
+ private failedProofStore: ProofStore | undefined,
38
85
  private agentClient?: ProvingJobConsumer,
39
86
  private telemetry: TelemetryClient = getTelemetryClient(),
40
- private log = createLogger('prover-client:tx-prover'),
41
- ) {
42
- this.proofStore = new InlineProofStore();
43
- this.failedProofStore = this.config.failedProofStore ? createProofStore(this.config.failedProofStore) : undefined;
87
+ private log: Logger = createLogger('prover-client:tx-prover'),
88
+ ) {}
89
+
90
+ /**
91
+ * Lazy-init the shared facade. The broker delivers each completed-job notification
92
+ * exactly once (drained on the first `getCompletedJobs` poll), so we cannot start
93
+ * a shared facade alongside the per-call facades that `createEpochProver` builds —
94
+ * they would race for notifications and one side would silently drop them. Starting
95
+ * the shared facade only on first use of one of the new factory methods keeps the
96
+ * legacy `createEpochProver` path race-free.
97
+ */
98
+ private getFacade(): BrokerCircuitProverFacade {
99
+ if (!this.running) {
100
+ throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
101
+ }
102
+ if (!this.facade) {
103
+ this.facade = new BrokerCircuitProverFacade(
104
+ this.orchestratorClient,
105
+ this.proofStore,
106
+ this.failedProofStore,
107
+ undefined,
108
+ this.log.getBindings(),
109
+ );
110
+ this.facade.start();
111
+ }
112
+ return this.facade;
44
113
  }
45
114
 
115
+ /**
116
+ * Legacy single-class epoch prover. Each call constructs its own
117
+ * `BrokerCircuitProverFacade`; the new factory methods (`createCheckpointSubTreeOrchestrator`,
118
+ * `createTopTreeOrchestrator`, `createEpochProvingContext`) share a single facade
119
+ * owned by `ProverClient`. Both APIs coexist while the prover-node migrates onto
120
+ * the new pair.
121
+ */
46
122
  public createEpochProver(): EpochProver {
47
- const facade = new BrokerCircuitProverFacade(this.orchestratorClient, this.proofStore, this.failedProofStore);
48
- const orchestrator = new ProvingOrchestrator(this.worldState, facade, this.config.proverId, this.telemetry);
123
+ const bindings = this.log.getBindings();
124
+ const facade = new BrokerCircuitProverFacade(
125
+ this.orchestratorClient,
126
+ this.proofStore,
127
+ this.failedProofStore,
128
+ undefined,
129
+ bindings,
130
+ );
131
+ const orchestrator = new ProvingOrchestrator(
132
+ this.worldState,
133
+ facade,
134
+ this.config.proverId,
135
+ this.config.cancelJobsOnStop,
136
+ this.config.enqueueConcurrency,
137
+ this.telemetry,
138
+ bindings,
139
+ );
49
140
  return new ServerEpochProver(facade, orchestrator);
50
141
  }
51
142
 
143
+ public createEpochProvingContext(epochNumber: EpochNumber): EpochProvingContext {
144
+ return new EpochProvingContext(this.getFacade(), epochNumber, this.log.getBindings());
145
+ }
146
+
147
+ public createCheckpointSubTreeOrchestrator(
148
+ epochContext: EpochProvingContext,
149
+ checkpointConstants: CheckpointConstantData,
150
+ l1ToL2Messages: Fr[],
151
+ totalNumBlocks: number,
152
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
153
+ ): Promise<CheckpointSubTreeOrchestrator> {
154
+ return CheckpointSubTreeOrchestrator.start(
155
+ this.worldState,
156
+ this.getFacade(),
157
+ this.config.proverId,
158
+ epochContext,
159
+ this.config.cancelJobsOnStop,
160
+ this.config.enqueueConcurrency,
161
+ checkpointConstants,
162
+ l1ToL2Messages,
163
+ totalNumBlocks,
164
+ headerOfLastBlockInPreviousCheckpoint,
165
+ this.telemetry,
166
+ this.log.getBindings(),
167
+ );
168
+ }
169
+
170
+ public createTopTreeOrchestrator(): TopTreeOrchestrator {
171
+ return new TopTreeOrchestrator(
172
+ this.getFacade(),
173
+ this.config.proverId,
174
+ this.config.enqueueConcurrency,
175
+ this.telemetry,
176
+ this.log.getBindings(),
177
+ );
178
+ }
179
+
52
180
  public getProverId(): EthAddress {
53
181
  return this.config.proverId;
54
182
  }
@@ -88,6 +216,14 @@ export class ProverClient implements EpochProverManager {
88
216
  }
89
217
  this.running = false;
90
218
  await this.stopAgents();
219
+ if (this.facade) {
220
+ try {
221
+ await this.facade.stop();
222
+ } catch (err) {
223
+ this.log.error('Error stopping shared broker facade', err);
224
+ }
225
+ this.facade = undefined;
226
+ }
91
227
  await tryStop(this.orchestratorClient);
92
228
  }
93
229
 
@@ -99,11 +235,13 @@ export class ProverClient implements EpochProverManager {
99
235
  */
100
236
  public static async new(
101
237
  config: ProverClientConfig,
102
- worldState: ForkMerkleTreeOperations,
238
+ worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
103
239
  broker: ProvingJobBroker,
104
240
  telemetry: TelemetryClient = getTelemetryClient(),
105
241
  ) {
106
- const prover = new ProverClient(config, worldState, broker, broker, telemetry);
242
+ const proofStore = await createProofStore(config.proofStore);
243
+ const failedProofStore = config.failedProofStore ? await createProofStore(config.failedProofStore) : undefined;
244
+ const prover = new ProverClient(config, worldState, broker, proofStore, failedProofStore, broker, telemetry);
107
245
  await prover.start();
108
246
  return prover;
109
247
  }
@@ -127,17 +265,11 @@ export class ProverClient implements EpochProverManager {
127
265
 
128
266
  const proofStore = new InlineProofStore();
129
267
  const prover = await buildServerCircuitProver(this.config, this.telemetry);
268
+ const bindings = this.log.getBindings();
130
269
  this.agents = times(
131
270
  this.config.proverAgentCount,
132
271
  () =>
133
- new ProvingAgent(
134
- this.agentClient!,
135
- proofStore,
136
- prover,
137
- [],
138
- this.config.proverAgentPollIntervalMs,
139
- this.telemetry,
140
- ),
272
+ new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs, bindings),
141
273
  );
142
274
 
143
275
  await Promise.all(this.agents.map(agent => agent.start()));
@@ -149,15 +281,16 @@ export class ProverClient implements EpochProverManager {
149
281
  }
150
282
 
151
283
  export function buildServerCircuitProver(
152
- config: ActualProverConfig & ACVMConfig & BBConfig,
284
+ config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
153
285
  telemetry: TelemetryClient,
154
286
  ): Promise<ServerCircuitProver> {
155
287
  if (config.realProofs) {
156
288
  return BBNativeRollupProver.new(config, telemetry);
157
289
  }
158
290
 
291
+ const logger = createLogger('prover-client:acvm-native');
159
292
  const simulator = config.acvmBinaryPath
160
- ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath)
293
+ ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, logger)
161
294
  : undefined;
162
295
 
163
296
  return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
@@ -1,5 +1,6 @@
1
- import type { BatchedBlob, FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { BatchedBlob, FinalBlobBatchingChallenges } from '@aztec/blob-lib/types';
2
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
3
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { EthAddress } from '@aztec/stdlib/block';
4
5
  import type { EpochProver } from '@aztec/stdlib/interfaces/server';
5
6
  import type { Proof } from '@aztec/stdlib/proofs';
@@ -18,7 +19,7 @@ export class ServerEpochProver implements EpochProver {
18
19
  ) {}
19
20
 
20
21
  startNewEpoch(
21
- epochNumber: number,
22
+ epochNumber: EpochNumber,
22
23
  totalNumCheckpoints: number,
23
24
  finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
24
25
  ): void {
@@ -30,7 +31,6 @@ export class ServerEpochProver implements EpochProver {
30
31
  constants: CheckpointConstantData,
31
32
  l1ToL2Messages: Fr[],
32
33
  totalNumBlocks: number,
33
- totalNumBlobFields: number,
34
34
  headerOfLastBlockInPreviousCheckpoint: BlockHeader,
35
35
  ): Promise<void> {
36
36
  return this.orchestrator.startNewCheckpoint(
@@ -38,14 +38,13 @@ export class ServerEpochProver implements EpochProver {
38
38
  constants,
39
39
  l1ToL2Messages,
40
40
  totalNumBlocks,
41
- totalNumBlobFields,
42
41
  headerOfLastBlockInPreviousCheckpoint,
43
42
  );
44
43
  }
45
44
  startChonkVerifierCircuits(txs: Tx[]): Promise<void> {
46
45
  return this.orchestrator.startChonkVerifierCircuits(txs);
47
46
  }
48
- setBlockCompleted(blockNumber: number, expectedBlockHeader?: BlockHeader): Promise<BlockHeader> {
47
+ setBlockCompleted(blockNumber: BlockNumber, expectedBlockHeader?: BlockHeader): Promise<BlockHeader> {
49
48
  return this.orchestrator.setBlockCompleted(blockNumber, expectedBlockHeader);
50
49
  }
51
50
  finalizeEpoch(): Promise<{ publicInputs: RootRollupPublicInputs; proof: Proof; batchedBlobInputs: BatchedBlob }> {
@@ -61,7 +60,7 @@ export class ServerEpochProver implements EpochProver {
61
60
  await this.facade.stop();
62
61
  await this.orchestrator.stop();
63
62
  }
64
- startNewBlock(blockNumber: number, timestamp: UInt64, totalNumTxs: number): Promise<void> {
63
+ startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number): Promise<void> {
65
64
  return this.orchestrator.startNewBlock(blockNumber, timestamp, totalNumTxs);
66
65
  }
67
66
  addTxs(txs: ProcessedTx[]): Promise<void> {