@aztec/prover-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (164) 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/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +38 -15
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +162 -36
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +4 -3
  13. package/dest/mocks/test_context.d.ts +15 -13
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +50 -36
  16. package/dest/orchestrator/block-building-helpers.d.ts +6 -6
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +5 -5
  19. package/dest/orchestrator/block-proving-state.d.ts +5 -2
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +8 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -23
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +23 -87
  25. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
  26. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  27. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1066 -0
  28. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  29. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  30. package/dest/orchestrator/chonk-cache.js +80 -0
  31. package/dest/orchestrator/index.d.ts +4 -2
  32. package/dest/orchestrator/index.d.ts.map +1 -1
  33. package/dest/orchestrator/index.js +3 -1
  34. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  35. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  36. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  37. package/dest/orchestrator/proving-scheduler.d.ts +81 -0
  38. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  39. package/dest/orchestrator/proving-scheduler.js +120 -0
  40. package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
  41. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  42. package/dest/orchestrator/top-tree-orchestrator.js +232 -0
  43. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  44. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  45. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  46. package/dest/orchestrator/tx-proving-state.d.ts +7 -6
  47. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  48. package/dest/orchestrator/tx-proving-state.js +8 -8
  49. package/dest/prover-client/factory.d.ts +3 -3
  50. package/dest/prover-client/factory.d.ts.map +1 -1
  51. package/dest/prover-client/prover-client.d.ts +65 -8
  52. package/dest/prover-client/prover-client.d.ts.map +1 -1
  53. package/dest/prover-client/prover-client.js +66 -14
  54. package/dest/proving_broker/broker_prover_facade.d.ts +8 -6
  55. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  56. package/dest/proving_broker/broker_prover_facade.js +18 -31
  57. package/dest/proving_broker/config.d.ts +13 -65
  58. package/dest/proving_broker/config.d.ts.map +1 -1
  59. package/dest/proving_broker/config.js +23 -6
  60. package/dest/proving_broker/fixtures.js +1 -1
  61. package/dest/proving_broker/index.d.ts +2 -1
  62. package/dest/proving_broker/index.d.ts.map +1 -1
  63. package/dest/proving_broker/index.js +1 -0
  64. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  65. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  66. package/dest/proving_broker/proof_store/factory.js +7 -30
  67. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  68. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  69. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  70. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  71. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  72. package/dest/proving_broker/proof_store/index.js +1 -1
  73. package/dest/proving_broker/proving_agent.d.ts +5 -9
  74. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_agent.js +4 -19
  76. package/dest/proving_broker/proving_broker.d.ts +8 -5
  77. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  78. package/dest/proving_broker/proving_broker.js +72 -21
  79. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  80. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  81. package/dest/proving_broker/proving_broker_database/persisted.js +391 -3
  82. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  83. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  84. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  85. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  86. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  87. package/dest/proving_broker/proving_job_controller.js +8 -6
  88. package/dest/proving_broker/rpc.d.ts +6 -2
  89. package/dest/proving_broker/rpc.d.ts.map +1 -1
  90. package/dest/proving_broker/rpc.js +87 -23
  91. package/dest/test/epoch_settlement.d.ts +36 -0
  92. package/dest/test/epoch_settlement.d.ts.map +1 -0
  93. package/dest/test/epoch_settlement.js +52 -0
  94. package/dest/test/index.d.ts +2 -0
  95. package/dest/test/index.d.ts.map +1 -0
  96. package/dest/test/index.js +1 -0
  97. package/dest/test/mock_proof_store.d.ts +3 -3
  98. package/dest/test/mock_proof_store.d.ts.map +1 -1
  99. package/dest/test/mock_prover.d.ts +5 -5
  100. package/dest/test/mock_prover.d.ts.map +1 -1
  101. package/dest/test/mock_prover.js +4 -4
  102. package/package.json +23 -22
  103. package/src/config.ts +19 -3
  104. package/src/light/index.ts +1 -0
  105. package/src/light/lightweight_checkpoint_builder.ts +229 -50
  106. package/src/mocks/fixtures.ts +4 -3
  107. package/src/mocks/test_context.ts +44 -48
  108. package/src/orchestrator/block-building-helpers.ts +5 -5
  109. package/src/orchestrator/block-proving-state.ts +10 -1
  110. package/src/orchestrator/checkpoint-proving-state.ts +22 -116
  111. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1044 -0
  112. package/src/orchestrator/chonk-cache.ts +99 -0
  113. package/src/orchestrator/index.ts +8 -1
  114. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  115. package/src/orchestrator/proving-scheduler.ts +160 -0
  116. package/src/orchestrator/top-tree-orchestrator.ts +384 -0
  117. package/src/orchestrator/top-tree-proving-state.ts +219 -0
  118. package/src/orchestrator/tx-proving-state.ts +11 -15
  119. package/src/prover-client/factory.ts +6 -2
  120. package/src/prover-client/prover-client.ts +148 -29
  121. package/src/proving_broker/broker_prover_facade.ts +27 -37
  122. package/src/proving_broker/config.ts +26 -3
  123. package/src/proving_broker/fixtures.ts +1 -1
  124. package/src/proving_broker/index.ts +1 -0
  125. package/src/proving_broker/proof_store/factory.ts +10 -32
  126. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  127. package/src/proving_broker/proof_store/index.ts +1 -1
  128. package/src/proving_broker/proving_agent.ts +6 -19
  129. package/src/proving_broker/proving_broker.ts +68 -16
  130. package/src/proving_broker/proving_broker_database/persisted.ts +17 -3
  131. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  132. package/src/proving_broker/proving_job_controller.ts +11 -6
  133. package/src/proving_broker/rpc.ts +46 -20
  134. package/src/test/epoch_settlement.ts +82 -0
  135. package/src/test/index.ts +1 -0
  136. package/src/test/mock_prover.ts +3 -15
  137. package/dest/block-factory/index.d.ts +0 -2
  138. package/dest/block-factory/index.d.ts.map +0 -1
  139. package/dest/block-factory/index.js +0 -1
  140. package/dest/block-factory/light.d.ts +0 -38
  141. package/dest/block-factory/light.d.ts.map +0 -1
  142. package/dest/block-factory/light.js +0 -108
  143. package/dest/orchestrator/epoch-proving-state.d.ts +0 -74
  144. package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
  145. package/dest/orchestrator/epoch-proving-state.js +0 -233
  146. package/dest/orchestrator/orchestrator.d.ts +0 -113
  147. package/dest/orchestrator/orchestrator.d.ts.map +0 -1
  148. package/dest/orchestrator/orchestrator.js +0 -842
  149. package/dest/prover-client/server-epoch-prover.d.ts +0 -32
  150. package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
  151. package/dest/prover-client/server-epoch-prover.js +0 -40
  152. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  153. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  154. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  155. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  156. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  157. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  158. package/src/block-factory/index.ts +0 -1
  159. package/src/block-factory/light.ts +0 -137
  160. package/src/orchestrator/epoch-proving-state.ts +0 -330
  161. package/src/orchestrator/orchestrator.ts +0 -1265
  162. package/src/prover-client/server-epoch-prover.ts +0 -69
  163. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
  164. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,52 +1,166 @@
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';
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,
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';
20
- 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';
21
28
  import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
22
29
  import { InlineProofStore, type ProofStore, createProofStore } from '../proving_broker/proof_store/index.js';
23
30
  import { ProvingAgent } from '../proving_broker/proving_agent.js';
24
- 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
+ }
25
64
 
26
65
  /** Manages proving of epochs by orchestrating the proving of individual blocks relying on a pool of prover agents. */
27
- export class ProverClient implements EpochProverManager {
66
+ export class ProverClient implements EpochProverManager, EpochProverFactory {
28
67
  private running = false;
29
68
  private agents: ProvingAgent[] = [];
30
-
31
- private proofStore: ProofStore;
32
- 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;
33
82
 
34
83
  private constructor(
35
84
  private config: ProverClientConfig,
36
- private worldState: ForkMerkleTreeOperations,
85
+ private worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
37
86
  private orchestratorClient: ProvingJobProducer,
87
+ private proofStore: ProofStore,
88
+ private failedProofStore: ProofStore | undefined,
38
89
  private agentClient?: ProvingJobConsumer,
39
90
  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;
91
+ private log: Logger = createLogger('prover-client:tx-prover'),
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;
44
117
  }
45
118
 
46
- 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);
49
- return new ServerEpochProver(facade, orchestrator);
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(
140
+ this.worldState,
141
+ this.getFacade(),
142
+ this.config.proverId,
143
+ chonkCache,
144
+ epochNumber,
145
+ this.config.cancelJobsOnStop,
146
+ this.getDeferredJobQueue(),
147
+ checkpointConstants,
148
+ l1ToL2Messages,
149
+ totalNumBlocks,
150
+ headerOfLastBlockInPreviousCheckpoint,
151
+ this.telemetry,
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(),
163
+ );
50
164
  }
51
165
 
52
166
  public getProverId(): EthAddress {
@@ -88,6 +202,14 @@ export class ProverClient implements EpochProverManager {
88
202
  }
89
203
  this.running = false;
90
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
+ }
91
213
  await tryStop(this.orchestratorClient);
92
214
  }
93
215
 
@@ -99,11 +221,13 @@ export class ProverClient implements EpochProverManager {
99
221
  */
100
222
  public static async new(
101
223
  config: ProverClientConfig,
102
- worldState: ForkMerkleTreeOperations,
224
+ worldState: ForkMerkleTreeOperations & ReadonlyWorldStateAccess,
103
225
  broker: ProvingJobBroker,
104
226
  telemetry: TelemetryClient = getTelemetryClient(),
105
227
  ) {
106
- 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);
107
231
  await prover.start();
108
232
  return prover;
109
233
  }
@@ -127,17 +251,11 @@ export class ProverClient implements EpochProverManager {
127
251
 
128
252
  const proofStore = new InlineProofStore();
129
253
  const prover = await buildServerCircuitProver(this.config, this.telemetry);
254
+ const bindings = this.log.getBindings();
130
255
  this.agents = times(
131
256
  this.config.proverAgentCount,
132
257
  () =>
133
- new ProvingAgent(
134
- this.agentClient!,
135
- proofStore,
136
- prover,
137
- [],
138
- this.config.proverAgentPollIntervalMs,
139
- this.telemetry,
140
- ),
258
+ new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs, bindings),
141
259
  );
142
260
 
143
261
  await Promise.all(this.agents.map(agent => agent.start()));
@@ -149,15 +267,16 @@ export class ProverClient implements EpochProverManager {
149
267
  }
150
268
 
151
269
  export function buildServerCircuitProver(
152
- config: ActualProverConfig & ACVMConfig & BBConfig,
270
+ config: Omit<ActualProverConfig, 'enqueueConcurrency'> & ACVMConfig & BBConfig,
153
271
  telemetry: TelemetryClient,
154
272
  ): Promise<ServerCircuitProver> {
155
273
  if (config.realProofs) {
156
274
  return BBNativeRollupProver.new(config, telemetry);
157
275
  }
158
276
 
277
+ const logger = createLogger('prover-client:acvm-native');
159
278
  const simulator = config.acvmBinaryPath
160
- ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath)
279
+ ? new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, logger)
161
280
  : undefined;
162
281
 
163
282
  return Promise.resolve(new TestCircuitProver(simulator, config, telemetry));
@@ -1,18 +1,17 @@
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';
9
- import { Fr } from '@aztec/foundation/fields';
10
- import { createLogger } from '@aztec/foundation/log';
9
+ import { chunk } from '@aztec/foundation/collection';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
11
11
  import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from '@aztec/foundation/promise';
12
12
  import { truncate } from '@aztec/foundation/string';
13
13
  import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
14
14
  import {
15
- type ProofAndVerificationKey,
16
15
  type ProofUri,
17
16
  type ProvingJobId,
18
17
  type ProvingJobInputsMap,
@@ -24,7 +23,7 @@ import {
24
23
  makeProvingJobId,
25
24
  } from '@aztec/stdlib/interfaces/server';
26
25
  import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
27
- import { ProvingRequestType } from '@aztec/stdlib/proofs';
26
+ import { ProvingRequestType, RecursiveProof } from '@aztec/stdlib/proofs';
28
27
  import type {
29
28
  BlockMergeRollupPrivateInputs,
30
29
  BlockRollupPublicInputs,
@@ -48,6 +47,8 @@ import type {
48
47
  TxRollupPublicInputs,
49
48
  } from '@aztec/stdlib/rollup';
50
49
 
50
+ import { createHash } from 'node:crypto';
51
+
51
52
  import { InlineProofStore, type ProofStore } from './proof_store/index.js';
52
53
 
53
54
  // Perform a snapshot sync every 30 seconds
@@ -70,14 +71,17 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
70
71
  private runningPromise?: RunningPromise;
71
72
  private timeOfLastSnapshotSync = Date.now();
72
73
  private jobsToRetrieve: Set<ProvingJobId> = new Set();
74
+ private log: Logger;
73
75
 
74
76
  constructor(
75
77
  private broker: ProvingJobProducer,
76
78
  private proofStore: ProofStore = new InlineProofStore(),
77
79
  private failedProofStore?: ProofStore,
78
80
  private pollIntervalMs = 1000,
79
- private log = createLogger('prover-client:broker-circuit-prover-facade'),
80
- ) {}
81
+ bindings?: LoggerBindings,
82
+ ) {
83
+ this.log = createLogger('prover-client:broker-circuit-prover-facade', bindings);
84
+ }
81
85
 
82
86
  /**
83
87
  * This is a critical section. This function can not be async since it writes
@@ -224,17 +228,11 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
224
228
  // We collect all returned notifications and return them
225
229
  const allCompleted = new Set<ProvingJobId>();
226
230
  try {
227
- let numRequests = 0;
228
- while (ids.length > 0) {
229
- const slice = ids.splice(0, SNAPSHOT_SYNC_CHECK_MAX_REQUEST_SIZE);
230
- 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);
231
234
  completed.forEach(id => allCompleted.add(id));
232
- ++numRequests;
233
- }
234
- if (numRequests === 0) {
235
- const final = await this.broker.getCompletedJobs([]);
236
- final.forEach(id => allCompleted.add(id));
237
- }
235
+ });
238
236
  } catch (err) {
239
237
  this.log.error(`Error thrown when requesting completed job notifications from the broker`, err);
240
238
  }
@@ -350,12 +348,8 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
350
348
  .map(id => this.jobs.get(id)!)
351
349
  .filter(x => x !== undefined);
352
350
  const totalJobsToRetrieve = toBeRetrieved.length;
353
- let totalJobsRetrieved = 0;
354
- while (toBeRetrieved.length > 0) {
355
- const slice = toBeRetrieved.splice(0, MAX_CONCURRENT_JOB_SETTLED_REQUESTS);
356
- const results = await Promise.all(slice.map(job => processJob(job!)));
357
- totalJobsRetrieved += results.filter(x => x).length;
358
- }
351
+ const results = await asyncPool(MAX_CONCURRENT_JOB_SETTLED_REQUESTS, toBeRetrieved, job => processJob(job));
352
+ const totalJobsRetrieved = results.filter(x => x).length;
359
353
  if (totalJobsToRetrieve > 0) {
360
354
  this.log.verbose(
361
355
  `Successfully retrieved ${totalJobsRetrieved} of ${totalJobsToRetrieve} jobs that should be ready, total ready jobs is now: ${this.jobsToRetrieve.size}`,
@@ -398,24 +392,16 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
398
392
 
399
393
  getAvmProof(
400
394
  inputs: AvmCircuitInputs,
401
- skipPublicInputsValidation?: boolean, // TODO(#14234)[Unconditional PIs validation]: remove this argument
402
395
  signal?: AbortSignal,
403
396
  epochNumber?: EpochNumber,
404
- ): Promise<ProofAndVerificationKey<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
405
- this.log.info(`getAvmProof() called with skipPublicInputsValidation: ${skipPublicInputsValidation}`);
406
-
397
+ ): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS>> {
407
398
  return this.enqueueJob(
408
399
  this.generateId(ProvingRequestType.PUBLIC_VM, inputs, epochNumber),
409
400
  ProvingRequestType.PUBLIC_VM,
410
401
  inputs,
411
402
  epochNumber,
412
403
  signal,
413
- ).then(result => {
414
- // TODO(#14234)[Unconditional PIs validation]: Remove ".then()".
415
- // Override the default value of skipPublicInputsValidation potentially set in BBNativeRollupProver.getAvmProof().
416
- result.proof.proof[0] = skipPublicInputsValidation ? new Fr(1) : new Fr(0);
417
- return result;
418
- });
404
+ );
419
405
  }
420
406
 
421
407
  getBaseParityProof(
@@ -666,8 +652,12 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
666
652
  );
667
653
  }
668
654
 
669
- private generateId(type: ProvingRequestType, inputs: { toBuffer(): Buffer }, epochNumber = EpochNumber.ZERO) {
670
- const inputsHash = sha256(inputs.toBuffer());
671
- return makeProvingJobId(epochNumber, type, inputsHash.toString('hex'));
655
+ private generateId(
656
+ type: ProvingRequestType,
657
+ inputs: { toBuffer(): Buffer },
658
+ epochNumber = EpochNumber.ZERO,
659
+ ): ProvingJobId {
660
+ const inputsHash = createHash('sha256').update(inputs.toBuffer()).digest('hex');
661
+ return makeProvingJobId(epochNumber, type, inputsHash);
672
662
  }
673
663
  }
@@ -1,13 +1,14 @@
1
- import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum';
1
+ import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
2
2
  import {
3
3
  type ConfigMappingsType,
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']),
@@ -100,6 +108,10 @@ export const ProverAgentConfig = z.object({
100
108
  proverTestDelayFactor: z.number(),
101
109
  /** The delay (ms) to inject during fake proof verification */
102
110
  proverTestVerificationDelayMs: z.number().optional(),
111
+ /** Whether to abort pending proving jobs when the orchestrator is cancelled */
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(),
103
115
  });
104
116
 
105
117
  export type ProverAgentConfig = z.infer<typeof ProverAgentConfig>;
@@ -153,4 +165,15 @@ export const proverAgentConfigMappings: ConfigMappingsType<ProverAgentConfig> =
153
165
  description: 'The delay (ms) to inject during fake proof verification',
154
166
  ...numberConfigHelper(10),
155
167
  },
168
+ cancelJobsOnStop: {
169
+ env: 'PROVER_CANCEL_JOBS_ON_STOP',
170
+ description:
171
+ 'Whether to abort pending proving jobs when the orchestrator is cancelled. ' +
172
+ 'When false (default), jobs remain in the broker queue and can be reused on restart/reorg.',
173
+ ...booleanConfigHelper(false),
174
+ },
175
+ proofStore: {
176
+ env: 'PROVER_PROOF_STORE',
177
+ description: 'Optional proof input store for the prover',
178
+ },
156
179
  };
@@ -1,5 +1,5 @@
1
1
  import { EpochNumber } from '@aztec/foundation/branded-types';
2
- import { randomBytes } from '@aztec/foundation/crypto';
2
+ import { randomBytes } from '@aztec/foundation/crypto/random';
3
3
  import { type ProofUri, type ProvingJobId, makeProvingJobId } from '@aztec/stdlib/interfaces/server';
4
4
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
5
5
 
@@ -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
  }
@@ -0,0 +1,78 @@
1
+ import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
2
+ import type { FileStore } from '@aztec/stdlib/file-store';
3
+ import {
4
+ type ProofUri,
5
+ type ProvingJobId,
6
+ type ProvingJobInputs,
7
+ type ProvingJobInputsMap,
8
+ ProvingJobResult,
9
+ type ProvingJobResultsMap,
10
+ getProvingJobInputClassFor,
11
+ } from '@aztec/stdlib/interfaces/server';
12
+ import { ProvingRequestType } from '@aztec/stdlib/proofs';
13
+
14
+ import type { ProofStore } from './proof_store.js';
15
+
16
+ const INPUTS_PATH = 'inputs';
17
+ const OUTPUTS_PATH = 'outputs';
18
+
19
+ /**
20
+ * A proof store implementation backed by a generic FileStore.
21
+ * Supports any storage backend (GCS, S3, local filesystem) via the FileStore abstraction.
22
+ */
23
+ export class FileStoreProofStore implements ProofStore {
24
+ constructor(private readonly fileStore: FileStore) {}
25
+
26
+ async saveProofInput<T extends ProvingRequestType>(
27
+ id: ProvingJobId,
28
+ type: T,
29
+ inputs: ProvingJobInputsMap[T],
30
+ ): Promise<ProofUri> {
31
+ const path = `${INPUTS_PATH}/${ProvingRequestType[type]}/${id}`;
32
+ const uri = await this.fileStore.save(path, inputs.toBuffer());
33
+ return uri as ProofUri;
34
+ }
35
+
36
+ async saveProofOutput<T extends ProvingRequestType>(
37
+ id: ProvingJobId,
38
+ type: T,
39
+ result: ProvingJobResultsMap[T],
40
+ ): Promise<ProofUri> {
41
+ const jobResult = { type, result } as ProvingJobResult;
42
+ const json = jsonStringify(jobResult);
43
+ const path = `${OUTPUTS_PATH}/${ProvingRequestType[type]}/${id}.json`;
44
+ const uri = await this.fileStore.save(path, Buffer.from(json, 'utf-8'));
45
+ return uri as ProofUri;
46
+ }
47
+
48
+ async getProofInput(uri: ProofUri): Promise<ProvingJobInputs> {
49
+ try {
50
+ const buffer = await this.fileStore.read(uri);
51
+ const type = this.extractTypeFromUri(uri);
52
+ const inputs = getProvingJobInputClassFor(type).fromBuffer(buffer);
53
+ return { inputs, type } as ProvingJobInputs;
54
+ } catch (err) {
55
+ throw new Error(`Error getting proof input at ${uri}: ${err}`);
56
+ }
57
+ }
58
+
59
+ async getProofOutput(uri: ProofUri): Promise<ProvingJobResult> {
60
+ try {
61
+ const buffer = await this.fileStore.read(uri);
62
+ return jsonParseWithSchema(buffer.toString('utf-8'), ProvingJobResult);
63
+ } catch (err) {
64
+ throw new Error(`Error getting proof output at ${uri}: ${err}`);
65
+ }
66
+ }
67
+
68
+ private extractTypeFromUri(uri: string): ProvingRequestType {
69
+ const url = new URL(uri);
70
+ const pathParts = url.pathname.split('/').filter(Boolean);
71
+ const typeString = pathParts.at(-2);
72
+ const type = typeString ? ProvingRequestType[typeString as keyof typeof ProvingRequestType] : undefined;
73
+ if (type === undefined) {
74
+ throw new Error(`Unrecognized proof type ${typeString} in URI ${uri}`);
75
+ }
76
+ return type;
77
+ }
78
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './proof_store.js';
2
2
  export * from './inline_proof_store.js';
3
3
  export * from './factory.js';
4
- export * from './gcs_proof_store.js';
4
+ export * from './file_store_proof_store.js';