@aztec/prover-client 0.0.1-commit.a072138 → 0.0.1-commit.a5db02d

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 (129) hide show
  1. package/dest/config.d.ts +1 -1
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +16 -2
  4. package/dest/light/lightweight_checkpoint_builder.d.ts +10 -5
  5. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  6. package/dest/light/lightweight_checkpoint_builder.js +56 -23
  7. package/dest/mocks/test_context.d.ts +11 -11
  8. package/dest/mocks/test_context.d.ts.map +1 -1
  9. package/dest/mocks/test_context.js +30 -30
  10. package/dest/orchestrator/block-building-helpers.d.ts +4 -4
  11. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  12. package/dest/orchestrator/block-building-helpers.js +2 -2
  13. package/dest/orchestrator/block-proving-state.d.ts +4 -1
  14. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  15. package/dest/orchestrator/block-proving-state.js +7 -0
  16. package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -36
  17. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  18. package/dest/orchestrator/checkpoint-proving-state.js +22 -120
  19. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
  20. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  21. package/dest/orchestrator/{orchestrator.js → checkpoint-sub-tree-orchestrator.js} +285 -462
  22. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  23. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  24. package/dest/orchestrator/chonk-cache.js +80 -0
  25. package/dest/orchestrator/index.d.ts +4 -2
  26. package/dest/orchestrator/index.d.ts.map +1 -1
  27. package/dest/orchestrator/index.js +3 -1
  28. package/dest/orchestrator/proving-scheduler.d.ts +81 -0
  29. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  30. package/dest/orchestrator/proving-scheduler.js +120 -0
  31. package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
  32. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  33. package/dest/orchestrator/top-tree-orchestrator.js +232 -0
  34. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  35. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  36. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  37. package/dest/orchestrator/tx-proving-state.d.ts +3 -3
  38. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  39. package/dest/prover-client/prover-client.d.ts +64 -7
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +62 -13
  42. package/dest/proving_broker/broker_prover_facade.d.ts +3 -3
  43. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  44. package/dest/proving_broker/broker_prover_facade.js +18 -19
  45. package/dest/proving_broker/config.d.ts +11 -67
  46. package/dest/proving_broker/config.d.ts.map +1 -1
  47. package/dest/proving_broker/config.js +16 -5
  48. package/dest/proving_broker/index.d.ts +2 -1
  49. package/dest/proving_broker/index.d.ts.map +1 -1
  50. package/dest/proving_broker/index.js +1 -0
  51. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  52. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  53. package/dest/proving_broker/proof_store/factory.js +7 -30
  54. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  55. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  56. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  57. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  58. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  59. package/dest/proving_broker/proof_store/index.js +1 -1
  60. package/dest/proving_broker/proving_broker.d.ts +8 -5
  61. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker.js +119 -19
  63. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -1
  64. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_broker_database/memory.js +10 -0
  66. package/dest/proving_broker/proving_broker_database/persisted.d.ts +13 -2
  67. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  68. package/dest/proving_broker/proving_broker_database/persisted.js +32 -5
  69. package/dest/proving_broker/proving_broker_database.d.ts +15 -1
  70. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  71. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  72. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  73. package/dest/proving_broker/proving_broker_instrumentation.js +7 -0
  74. package/dest/proving_broker/rpc.d.ts +6 -2
  75. package/dest/proving_broker/rpc.d.ts.map +1 -1
  76. package/dest/proving_broker/rpc.js +87 -23
  77. package/dest/test/epoch_settlement.d.ts +36 -0
  78. package/dest/test/epoch_settlement.d.ts.map +1 -0
  79. package/dest/test/epoch_settlement.js +52 -0
  80. package/dest/test/index.d.ts +2 -0
  81. package/dest/test/index.d.ts.map +1 -0
  82. package/dest/test/index.js +1 -0
  83. package/dest/test/mock_prover.d.ts +4 -4
  84. package/dest/test/mock_prover.js +2 -2
  85. package/package.json +20 -20
  86. package/src/config.ts +18 -2
  87. package/src/light/lightweight_checkpoint_builder.ts +58 -25
  88. package/src/mocks/test_context.ts +26 -43
  89. package/src/orchestrator/block-building-helpers.ts +2 -2
  90. package/src/orchestrator/block-proving-state.ts +9 -0
  91. package/src/orchestrator/checkpoint-proving-state.ts +21 -162
  92. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
  93. package/src/orchestrator/chonk-cache.ts +99 -0
  94. package/src/orchestrator/index.ts +8 -1
  95. package/src/orchestrator/proving-scheduler.ts +160 -0
  96. package/src/orchestrator/top-tree-orchestrator.ts +384 -0
  97. package/src/orchestrator/top-tree-proving-state.ts +219 -0
  98. package/src/orchestrator/tx-proving-state.ts +3 -3
  99. package/src/prover-client/prover-client.ts +134 -25
  100. package/src/proving_broker/broker_prover_facade.ts +21 -22
  101. package/src/proving_broker/config.ts +16 -2
  102. package/src/proving_broker/index.ts +1 -0
  103. package/src/proving_broker/proof_store/factory.ts +10 -32
  104. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  105. package/src/proving_broker/proof_store/index.ts +1 -1
  106. package/src/proving_broker/proving_broker.ts +113 -17
  107. package/src/proving_broker/proving_broker_database/memory.ts +10 -0
  108. package/src/proving_broker/proving_broker_database/persisted.ts +42 -7
  109. package/src/proving_broker/proving_broker_database.ts +16 -0
  110. package/src/proving_broker/proving_broker_instrumentation.ts +9 -0
  111. package/src/proving_broker/rpc.ts +46 -20
  112. package/src/test/epoch_settlement.ts +82 -0
  113. package/src/test/index.ts +1 -0
  114. package/src/test/mock_prover.ts +2 -2
  115. package/dest/orchestrator/epoch-proving-state.d.ts +0 -75
  116. package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
  117. package/dest/orchestrator/epoch-proving-state.js +0 -267
  118. package/dest/orchestrator/orchestrator.d.ts +0 -128
  119. package/dest/orchestrator/orchestrator.d.ts.map +0 -1
  120. package/dest/prover-client/server-epoch-prover.d.ts +0 -32
  121. package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
  122. package/dest/prover-client/server-epoch-prover.js +0 -40
  123. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  124. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  125. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  126. package/src/orchestrator/epoch-proving-state.ts +0 -378
  127. package/src/orchestrator/orchestrator.ts +0 -1281
  128. package/src/prover-client/server-epoch-prover.ts +0 -69
  129. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
@@ -0,0 +1,219 @@
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
+ 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
+ }
@@ -1,4 +1,4 @@
1
- import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
1
+ import { AVM_V2_PROOF_LENGTH_IN_FIELDS, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
2
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
4
4
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
@@ -32,7 +32,7 @@ export class TxProvingState {
32
32
  PublicChonkVerifierPublicInputs,
33
33
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
34
34
  >;
35
- private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
35
+ private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>;
36
36
 
37
37
  constructor(
38
38
  public readonly processedTx: ProcessedTx,
@@ -80,7 +80,7 @@ export class TxProvingState {
80
80
  this.publicChonkVerifier = publicChonkVerifierProofAndVk;
81
81
  }
82
82
 
83
- public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>) {
83
+ public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>) {
84
84
  this.avmProof = avmProof;
85
85
  }
86
86
 
@@ -1,11 +1,13 @@
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
6
  import { type Logger, createLogger } from '@aztec/foundation/log';
7
+ import { SerialQueue } from '@aztec/foundation/queue';
5
8
  import { NativeACVMSimulator } from '@aztec/simulator/server';
6
9
  import {
7
10
  type ActualProverConfig,
8
- type EpochProver,
9
11
  type EpochProverManager,
10
12
  type ForkMerkleTreeOperations,
11
13
  type ProvingJobBroker,
@@ -15,53 +17,150 @@ import {
15
17
  type ServerCircuitProver,
16
18
  tryStop,
17
19
  } from '@aztec/stdlib/interfaces/server';
20
+ import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
21
+ import type { BlockHeader } from '@aztec/stdlib/tx';
18
22
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
19
23
 
20
24
  import type { ProverClientConfig } from '../config.js';
21
- import { ProvingOrchestrator } from '../orchestrator/orchestrator.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';
22
28
  import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
23
29
  import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
24
30
  import { ProvingAgent } from '../proving_broker/proving_agent.js';
25
- import { ServerEpochProver } from './server-epoch-prover.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
+ totalNumBlocks: number,
60
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
61
+ ): Promise<CheckpointSubTreeOrchestrator>;
62
+ createTopTreeOrchestrator(): TopTreeOrchestrator;
63
+ }
26
64
 
27
65
  /** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
28
- export class ProverClient implements EpochProverManager {
66
+ export class ProverClient implements EpochProverManager, EpochProverFactory {
29
67
  private running = false;
30
68
  private agents: ProvingAgent[] = [];
31
-
32
- private proofStore: ProofStore;
33
- private failedProofStore: ProofStore | undefined;
69
+ /**
70
+ * The single broker facade shared by every orchestrator created from this client.
71
+ * Constructed lazily on `start()` and torn down on `stop()` — see the comment on
72
+ * `EpochProverFactory` for why a single shared facade is required.
73
+ */
74
+ private facade: BrokerCircuitProverFacade | undefined;
75
+ /**
76
+ * Single deferred-proving-job queue shared across every orchestrator (sub-trees and
77
+ * top-trees, across every concurrent epoch session). Throttles the total rate of job
78
+ * submission to the broker once, rather than once per orchestrator. Started lazily
79
+ * alongside the facade and cancelled on `stop()`.
80
+ */
81
+ private deferredJobQueue: SerialQueue | undefined;
34
82
 
35
83
  private constructor(
36
84
  private config: ProverClientConfig,
37
85
  private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
38
86
  private orchestratorClient: ProvingJobProducer,
87
+ private proofStore: ProofStore,
88
+ private failedProofStore: ProofStore | undefined,
39
89
  private agentClient?: ProvingJobConsumer,
40
90
  private telemetry: TelemetryClient = getTelemetryClient(),
41
91
  private log: Logger = createLogger('prover-client:tx-prover'),
42
- ) {
43
- this.proofStore = new InlineProofStore();
44
- this.failedProofStore = this.config.failedProofStore ? createProofStore(this.config.failedProofStore) : undefined;
92
+ ) {}
93
+
94
+ /**
95
+ * Lazy-init the shared facade. The broker delivers each completed-job notification
96
+ * exactly once (drained on the first `getCompletedJobs` poll), so we cannot start
97
+ * a shared facade alongside the per-call facades that `createEpochProver` builds —
98
+ * they would race for notifications and one side would silently drop them. Starting
99
+ * the shared facade only on first use of one of the new factory methods keeps the
100
+ * legacy `createEpochProver` path race-free.
101
+ */
102
+ private getFacade(): BrokerCircuitProverFacade {
103
+ if (!this.running) {
104
+ throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
105
+ }
106
+ if (!this.facade) {
107
+ this.facade = new BrokerCircuitProverFacade(
108
+ this.orchestratorClient,
109
+ this.proofStore,
110
+ this.failedProofStore,
111
+ undefined,
112
+ this.log.getBindings(),
113
+ );
114
+ this.facade.start();
115
+ }
116
+ return this.facade;
45
117
  }
46
118
 
47
- public createEpochProver(): EpochProver {
48
- const bindings = this.log.getBindings();
49
- const facade = new BrokerCircuitProverFacade(
50
- this.orchestratorClient,
51
- this.proofStore,
52
- this.failedProofStore,
53
- undefined,
54
- bindings,
55
- );
56
- const orchestrator = new ProvingOrchestrator(
119
+ /** Lazy-init the shared deferred-job queue, started with the configured enqueue concurrency. */
120
+ private getDeferredJobQueue(): SerialQueue {
121
+ if (!this.running) {
122
+ throw new Error('ProverClient is not running; call start() before constructing orchestrators.');
123
+ }
124
+ if (!this.deferredJobQueue) {
125
+ this.deferredJobQueue = new SerialQueue();
126
+ this.deferredJobQueue.start(this.config.enqueueConcurrency);
127
+ }
128
+ return this.deferredJobQueue;
129
+ }
130
+
131
+ public createCheckpointSubTreeOrchestrator(
132
+ chonkCache: ChonkCache,
133
+ epochNumber: EpochNumber,
134
+ checkpointConstants: CheckpointConstantData,
135
+ l1ToL2Messages: Fr[],
136
+ totalNumBlocks: number,
137
+ headerOfLastBlockInPreviousCheckpoint: BlockHeader,
138
+ ): Promise<CheckpointSubTreeOrchestrator> {
139
+ return CheckpointSubTreeOrchestrator.start(
57
140
  this.worldState,
58
- facade,
141
+ this.getFacade(),
59
142
  this.config.proverId,
143
+ chonkCache,
144
+ epochNumber,
60
145
  this.config.cancelJobsOnStop,
146
+ this.getDeferredJobQueue(),
147
+ checkpointConstants,
148
+ l1ToL2Messages,
149
+ totalNumBlocks,
150
+ headerOfLastBlockInPreviousCheckpoint,
61
151
  this.telemetry,
62
- bindings,
152
+ this.log.getBindings(),
153
+ );
154
+ }
155
+
156
+ public createTopTreeOrchestrator(): TopTreeOrchestrator {
157
+ return new TopTreeOrchestrator(
158
+ this.getFacade(),
159
+ this.config.proverId,
160
+ this.getDeferredJobQueue(),
161
+ this.telemetry,
162
+ this.log.getBindings(),
63
163
  );
64
- return new ServerEpochProver(facade, orchestrator);
65
164
  }
66
165
 
67
166
  public getProverId(): EthAddress {
@@ -103,6 +202,14 @@ export class ProverClient implements EpochProverManager {
103
202
  }
104
203
  this.running = false;
105
204
  await this.stopAgents();
205
+ if (this.deferredJobQueue) {
206
+ await this.deferredJobQueue.cancel();
207
+ this.deferredJobQueue = undefined;
208
+ }
209
+ if (this.facade) {
210
+ await tryStop(this.facade, this.log);
211
+ this.facade = undefined;
212
+ }
106
213
  await tryStop(this.orchestratorClient);
107
214
  }
108
215
 
@@ -118,7 +225,9 @@ export class ProverClient implements EpochProverManager {
118
225
  broker: ProvingJobBroker,
119
226
  telemetry: TelemetryClient = getTelemetryClient(),
120
227
  ) {
121
- const prover = new ProverClient(config, worldState, broker, broker, telemetry);
228
+ const proofStore = await createProofStore(config.proofStore);
229
+ const failedProofStore = config.failedProofStore ? await createProofStore(config.failedProofStore) : undefined;
230
+ const prover = new ProverClient(config, worldState, broker, proofStore, failedProofStore, broker, telemetry);
122
231
  await prover.start();
123
232
  return prover;
124
233
  }
@@ -158,7 +267,7 @@ export class ProverClient implements EpochProverManager {
158
267
  }
159
268
 
160
269
  export function buildServerCircuitProver(
161
- config: ActualProverConfig & ACVMConfig & BBConfig,
270
+ config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
162
271
  telemetry: TelemetryClient,
163
272
  ): Promise<ServerCircuitProver> {
164
273
  if (config.realProofs) {
@@ -1,11 +1,12 @@
1
1
  import type {
2
- AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED,
2
+ AVM_V2_PROOF_LENGTH_IN_FIELDS,
3
3
  NESTED_RECURSIVE_PROOF_LENGTH,
4
4
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
5
  RECURSIVE_PROOF_LENGTH,
6
6
  } from '@aztec/constants';
7
+ import { asyncPool } from '@aztec/foundation/async-pool';
7
8
  import { EpochNumber } from '@aztec/foundation/branded-types';
8
- import { sha256 } from '@aztec/foundation/crypto/sha256';
9
+ import { chunk } from '@aztec/foundation/collection';
9
10
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
10
11
  import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
11
12
  import { truncate } from '@aztec/foundation/string';
@@ -46,6 +47,8 @@ import type {
46
47
  TxRollupPublicInputs,
47
48
  } from '@aztec/stdlib/rollup';
48
49
 
50
+ import { createHash } from 'node:crypto';
51
+
49
52
  import { InlineProofStore, type ProofStore } from './proof_store/index.js';
50
53
 
51
54
  // Perform a snapshot sync every 30 seconds
@@ -225,17 +228,11 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
225
228
  // We collect all returned notifications and return them
226
229
  const allCompleted = new Set<ProvingJobId>();
227
230
  try {
228
- let numRequests = 0;
229
- while (ids.length > 0) {
230
- const slice = ids.splice(0, SNAPSHOT_SYNC_CHECK_MAX_REQUEST_SIZE);
231
- const completed = await this.broker.getCompletedJobs(slice);
231
+ const batches = ids.length > 0 ? chunk(ids, SNAPSHOT_SYNC_CHECK_MAX_REQUEST_SIZE) : [[]];
232
+ await asyncPool(1, batches, async batch => {
233
+ const completed = await this.broker.getCompletedJobs(batch);
232
234
  completed.forEach(id => allCompleted.add(id));
233
- ++numRequests;
234
- }
235
- if (numRequests === 0) {
236
- const final = await this.broker.getCompletedJobs([]);
237
- final.forEach(id => allCompleted.add(id));
238
- }
235
+ });
239
236
  } catch (err) {
240
237
  this.log.error(`Error thrown when requesting completed job notifications from the broker`, err);
241
238
  }
@@ -291,6 +288,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
291
288
  }
292
289
  } else if (result.status === 'rejected') {
293
290
  return { success: false, reason: result.reason };
291
+ } else if (result.status === 'aborted') {
292
+ return { success: false, reason: 'Aborted' };
294
293
  } else {
295
294
  throw new Error(`Unexpected proving job status ${result.status}`);
296
295
  }
@@ -351,12 +350,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
351
350
  .map(id => this.jobs.get(id)!)
352
351
  .filter(x => x !== undefined);
353
352
  const totalJobsToRetrieve = toBeRetrieved.length;
354
- let totalJobsRetrieved = 0;
355
- while (toBeRetrieved.length > 0) {
356
- const slice = toBeRetrieved.splice(0, MAX_CONCURRENT_JOB_SETTLED_REQUESTS);
357
- const results = await Promise.all(slice.map(job => processJob(job!)));
358
- totalJobsRetrieved += results.filter(x => x).length;
359
- }
353
+ const results = await asyncPool(MAX_CONCURRENT_JOB_SETTLED_REQUESTS, toBeRetrieved, job => processJob(job));
354
+ const totalJobsRetrieved = results.filter(x => x).length;
360
355
  if (totalJobsToRetrieve > 0) {
361
356
  this.log.verbose(
362
357
  `Successfully retrieved ${totalJobsRetrieved} of ${totalJobsToRetrieve} jobs that should be ready, total ready jobs is now: ${this.jobsToRetrieve.size}`,
@@ -401,7 +396,7 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
401
396
  inputs: AvmCircuitInputs,
402
397
  signal?: AbortSignal,
403
398
  epochNumber?: EpochNumber,
404
- ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
399
+ ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
405
400
  return this.enqueueJob(
406
401
  this.generateId(ProvingRequestType.PUBLIC_VM, inputs, epochNumber),
407
402
  ProvingRequestType.PUBLIC_VM,
@@ -659,8 +654,12 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
659
654
  );
660
655
  }
661
656
 
662
- private generateId(type: ProvingRequestType, inputs: { toBuffer(): Buffer }, epochNumber = EpochNumber.ZERO) {
663
- const inputsHash = sha256(inputs.toBuffer());
664
- return makeProvingJobId(epochNumber, type, inputsHash.toString('hex'));
657
+ private generateId(
658
+ type: ProvingRequestType,
659
+ inputs: { toBuffer(): Buffer },
660
+ epochNumber = EpochNumber.ZERO,
661
+ ): ProvingJobId {
662
+ const inputsHash = createHash('sha256').update(inputs.toBuffer()).digest('hex');
663
+ return makeProvingJobId(epochNumber, type, inputsHash);
665
664
  }
666
665
  }
@@ -4,10 +4,11 @@ import {
4
4
  booleanConfigHelper,
5
5
  getDefaultConfig,
6
6
  numberConfigHelper,
7
+ optionalNumberConfigHelper,
7
8
  } from '@aztec/foundation/config';
8
9
  import { pickConfigMappings } from '@aztec/foundation/config';
9
- import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
10
10
  import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
11
+ import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
11
12
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
12
13
 
13
14
  import { z } from 'zod';
@@ -31,6 +32,8 @@ export const ProverBrokerConfig = z.object({
31
32
  proverBrokerBatchIntervalMs: z.number().int().nonnegative(),
32
33
  /** The maximum number of epochs to keep results for */
33
34
  proverBrokerMaxEpochsToKeepResultsFor: z.number().int().nonnegative(),
35
+ /** Enable debug replay mode for replaying proving jobs from stored inputs */
36
+ proverBrokerDebugReplayEnabled: z.boolean(),
34
37
  });
35
38
 
36
39
  export type ProverBrokerConfig = z.infer<typeof ProverBrokerConfig> &
@@ -71,9 +74,14 @@ export const proverBrokerConfigMappings: ConfigMappingsType<ProverBrokerConfig>
71
74
  },
72
75
  proverBrokerStoreMapSizeKb: {
73
76
  env: 'PROVER_BROKER_STORE_MAP_SIZE_KB',
74
- parseEnv: (val: string | undefined) => (val ? +val : undefined),
77
+ ...optionalNumberConfigHelper(),
75
78
  description: "The size of the prover broker's database. Will override the dataStoreMapSizeKb if set.",
76
79
  },
80
+ proverBrokerDebugReplayEnabled: {
81
+ env: 'PROVER_BROKER_DEBUG_REPLAY_ENABLED',
82
+ description: 'Enable debug replay mode for replaying proving jobs from stored inputs',
83
+ ...booleanConfigHelper(false),
84
+ },
77
85
  ...dataConfigMappings,
78
86
  ...l1ReaderConfigMappings,
79
87
  ...pickConfigMappings(chainConfigMappings, ['rollupVersion']),
@@ -102,6 +110,8 @@ export const ProverAgentConfig = z.object({
102
110
  proverTestVerificationDelayMs: z.number().optional(),
103
111
  /** Whether to abort pending proving jobs when the orchestrator is cancelled */
104
112
  cancelJobsOnStop: z.boolean(),
113
+ /** Where to store proving results. Must be accessible to both prover node and agents. If not set will inline-encode the parameters */
114
+ proofStore: z.string().optional(),
105
115
  });
106
116
 
107
117
  export type ProverAgentConfig = z.infer<typeof ProverAgentConfig>;
@@ -162,4 +172,8 @@ export const proverAgentConfigMappings: ConfigMappingsType<ProverAgentConfig> =
162
172
  'When false (default), jobs remain in the broker queue and can be reused on restart/reorg.',
163
173
  ...booleanConfigHelper(false),
164
174
  },
175
+ proofStore: {
176
+ env: 'PROVER_PROOF_STORE',
177
+ description: 'Optional proof input store for the prover',
178
+ },
165
179
  };
@@ -7,3 +7,4 @@ export * from './proving_broker_database/persisted.js';
7
7
  export * from './proof_store/index.js';
8
8
  export * from './factory.js';
9
9
  export * from './config.js';
10
+ export { BrokerCircuitProverFacade } from './broker_prover_facade.js';
@@ -1,42 +1,20 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
+ import { createFileStore } from '@aztec/stdlib/file-store';
2
3
 
3
- import { GoogleCloudStorageProofStore } from './gcs_proof_store.js';
4
+ import { FileStoreProofStore } from './file_store_proof_store.js';
4
5
  import { InlineProofStore } from './inline_proof_store.js';
5
6
  import type { ProofStore } from './proof_store.js';
6
7
 
7
- export function createProofStore(config: string | undefined, logger = createLogger('prover-client:proof-store')) {
8
- if (config === undefined) {
8
+ export async function createProofStore(
9
+ config: string | undefined,
10
+ logger = createLogger('prover-client:proof-store'),
11
+ ): Promise<ProofStore> {
12
+ if (!config) {
9
13
  logger.info('Creating inline proof store');
10
14
  return new InlineProofStore();
11
- } else if (config.startsWith('gs://')) {
12
- try {
13
- const url = new URL(config);
14
- const bucket = url.host;
15
- const path = url.pathname.replace(/^\/+/, '');
16
- logger.info(`Creating google cloud proof store at ${bucket}`, { bucket, path });
17
- return new GoogleCloudStorageProofStore(bucket, path);
18
- } catch {
19
- throw new Error(
20
- `Invalid google cloud proof store definition: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`,
21
- );
22
- }
23
- } else {
24
- throw new Error(`Unknown proof store config: '${config}'. Supported values are 'gs://bucket-name/path/to/store'.`);
25
15
  }
26
- }
27
16
 
28
- export function createProofStoreForUri(
29
- uri: string,
30
- logger = createLogger('prover-client:proof-store'),
31
- ): Pick<ProofStore, 'getProofInput' | 'getProofOutput'> {
32
- if (uri.startsWith('data://')) {
33
- return createProofStore(undefined, logger);
34
- } else if (uri.startsWith('gs://')) {
35
- const url = new URL(uri);
36
- const basePath = url.pathname.replace(/^\/+/, '').split('/').slice(0, -3);
37
- url.pathname = basePath.join('/');
38
- return createProofStore(uri, logger);
39
- } else {
40
- throw new Error(`Unknown proof store config: '${uri}'. Supported protocols are 'data://' and 'gs://'.`);
41
- }
17
+ const fileStore = await createFileStore(config, logger);
18
+ logger.info(`Creating file store proof store at ${config}`);
19
+ return new FileStoreProofStore(fileStore);
42
20
  }