@aztec/prover-client 3.0.0-canary.a9708bd → 3.0.0-manual.20251030

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 (74) hide show
  1. package/dest/block-factory/light.d.ts +5 -3
  2. package/dest/block-factory/light.d.ts.map +1 -1
  3. package/dest/block-factory/light.js +16 -9
  4. package/dest/config.js +1 -1
  5. package/dest/mocks/fixtures.d.ts +4 -1
  6. package/dest/mocks/fixtures.d.ts.map +1 -1
  7. package/dest/mocks/fixtures.js +31 -3
  8. package/dest/mocks/test_context.d.ts +32 -9
  9. package/dest/mocks/test_context.d.ts.map +1 -1
  10. package/dest/mocks/test_context.js +78 -22
  11. package/dest/orchestrator/block-building-helpers.d.ts +33 -31
  12. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  13. package/dest/orchestrator/block-building-helpers.js +126 -137
  14. package/dest/orchestrator/block-proving-state.d.ts +60 -53
  15. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  16. package/dest/orchestrator/block-proving-state.js +214 -187
  17. package/dest/orchestrator/checkpoint-proving-state.d.ts +63 -0
  18. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  19. package/dest/orchestrator/checkpoint-proving-state.js +211 -0
  20. package/dest/orchestrator/epoch-proving-state.d.ts +34 -28
  21. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  22. package/dest/orchestrator/epoch-proving-state.js +128 -84
  23. package/dest/orchestrator/orchestrator.d.ts +31 -30
  24. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  25. package/dest/orchestrator/orchestrator.js +368 -236
  26. package/dest/orchestrator/tx-proving-state.d.ts +11 -9
  27. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  28. package/dest/orchestrator/tx-proving-state.js +26 -23
  29. package/dest/prover-client/server-epoch-prover.d.ts +9 -8
  30. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  31. package/dest/prover-client/server-epoch-prover.js +9 -9
  32. package/dest/proving_broker/broker_prover_facade.d.ts +20 -15
  33. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  34. package/dest/proving_broker/broker_prover_facade.js +36 -21
  35. package/dest/proving_broker/config.d.ts +8 -8
  36. package/dest/proving_broker/config.js +5 -5
  37. package/dest/proving_broker/factory.js +1 -1
  38. package/dest/proving_broker/fixtures.js +1 -1
  39. package/dest/proving_broker/proof_store/index.d.ts +1 -0
  40. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  41. package/dest/proving_broker/proof_store/index.js +1 -0
  42. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  43. package/dest/proving_broker/proving_broker.js +29 -18
  44. package/dest/proving_broker/proving_broker_database/persisted.js +5 -5
  45. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  46. package/dest/proving_broker/proving_job_controller.js +38 -18
  47. package/dest/test/mock_prover.d.ts +22 -17
  48. package/dest/test/mock_prover.d.ts.map +1 -1
  49. package/dest/test/mock_prover.js +35 -20
  50. package/package.json +16 -17
  51. package/src/block-factory/light.ts +35 -9
  52. package/src/config.ts +1 -1
  53. package/src/mocks/fixtures.ts +39 -11
  54. package/src/mocks/test_context.ts +137 -31
  55. package/src/orchestrator/block-building-helpers.ts +211 -211
  56. package/src/orchestrator/block-proving-state.ts +235 -245
  57. package/src/orchestrator/checkpoint-proving-state.ts +299 -0
  58. package/src/orchestrator/epoch-proving-state.ts +172 -127
  59. package/src/orchestrator/orchestrator.ts +545 -303
  60. package/src/orchestrator/tx-proving-state.ts +49 -43
  61. package/src/prover-client/server-epoch-prover.ts +28 -18
  62. package/src/proving_broker/broker_prover_facade.ts +157 -86
  63. package/src/proving_broker/config.ts +7 -7
  64. package/src/proving_broker/factory.ts +1 -1
  65. package/src/proving_broker/fixtures.ts +1 -1
  66. package/src/proving_broker/proof_store/index.ts +1 -0
  67. package/src/proving_broker/proving_broker.ts +36 -18
  68. package/src/proving_broker/proving_broker_database/persisted.ts +5 -5
  69. package/src/proving_broker/proving_job_controller.ts +38 -18
  70. package/src/test/mock_prover.ts +142 -60
  71. package/dest/bin/get-proof-inputs.d.ts +0 -2
  72. package/dest/bin/get-proof-inputs.d.ts.map +0 -1
  73. package/dest/bin/get-proof-inputs.js +0 -51
  74. package/src/bin/get-proof-inputs.ts +0 -59
@@ -0,0 +1,299 @@
1
+ import { BatchedBlobAccumulator, type FinalBlobBatchingChallenges, SpongeBlob } from '@aztec/blob-lib';
2
+ import {
3
+ type ARCHIVE_HEIGHT,
4
+ BLOBS_PER_BLOCK,
5
+ FIELDS_PER_BLOB,
6
+ type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
7
+ type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
8
+ NUM_MSGS_PER_BASE_PARITY,
9
+ } from '@aztec/constants';
10
+ import { padArrayEnd } from '@aztec/foundation/collection';
11
+ import { BLS12Point, Fr } from '@aztec/foundation/fields';
12
+ import type { Tuple } from '@aztec/foundation/serialize';
13
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
14
+ import { getCheckpointBlobFields } from '@aztec/stdlib/checkpoint';
15
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
16
+ import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
17
+ import {
18
+ BlockMergeRollupPrivateInputs,
19
+ BlockRollupPublicInputs,
20
+ CheckpointConstantData,
21
+ CheckpointRollupPublicInputs,
22
+ CheckpointRootRollupHints,
23
+ CheckpointRootRollupPrivateInputs,
24
+ CheckpointRootSingleBlockRollupPrivateInputs,
25
+ } from '@aztec/stdlib/rollup';
26
+ import type { CircuitName } from '@aztec/stdlib/stats';
27
+ import type { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
28
+ import type { BlockHeader } from '@aztec/stdlib/tx';
29
+ import type { UInt64 } from '@aztec/stdlib/types';
30
+
31
+ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-helpers.js';
32
+ import { BlockProvingState, type ProofState } from './block-proving-state.js';
33
+ import type { EpochProvingState } from './epoch-proving-state.js';
34
+
35
+ export class CheckpointProvingState {
36
+ private blockProofs: UnbalancedTreeStore<
37
+ ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
38
+ >;
39
+ private checkpointRootProof:
40
+ | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
41
+ | undefined;
42
+ private blocks: (BlockProvingState | undefined)[] = [];
43
+ private startBlobAccumulator: BatchedBlobAccumulator | undefined;
44
+ private endBlobAccumulator: BatchedBlobAccumulator | undefined;
45
+ private blobFields: Fr[] | undefined;
46
+ private error: string | undefined;
47
+ public readonly firstBlockNumber: number;
48
+
49
+ constructor(
50
+ public readonly index: number,
51
+ public readonly constants: CheckpointConstantData,
52
+ public readonly totalNumBlocks: number,
53
+ private readonly totalNumBlobFields: number,
54
+ private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
55
+ private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
56
+ private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
57
+ private readonly l1ToL2Messages: Fr[],
58
+ // The snapshot and sibling path before the new l1 to l2 message subtree is inserted.
59
+ private readonly lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
60
+ private readonly lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<
61
+ Fr,
62
+ typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
63
+ >,
64
+ // The snapshot and sibling path after the new l1 to l2 message subtree is inserted.
65
+ private readonly newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
66
+ private readonly newL1ToL2MessageSubtreeRootSiblingPath: Tuple<
67
+ Fr,
68
+ typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
69
+ >,
70
+ public parentEpoch: EpochProvingState,
71
+ private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
72
+ ) {
73
+ this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
74
+ this.firstBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1;
75
+ }
76
+
77
+ public get epochNumber(): number {
78
+ return this.parentEpoch.epochNumber;
79
+ }
80
+
81
+ public async startNewBlock(
82
+ blockNumber: number,
83
+ timestamp: UInt64,
84
+ totalNumTxs: number,
85
+ lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
86
+ lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
87
+ ): Promise<BlockProvingState> {
88
+ const index = blockNumber - this.firstBlockNumber;
89
+ if (index >= this.totalNumBlocks) {
90
+ throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
91
+ }
92
+
93
+ // If this is the first block, we use the snapshot and sibling path before the new l1 to l2 messages are inserted.
94
+ // Otherwise, we use the snapshot and sibling path after the new l1 to l2 messages are inserted, which will always
95
+ // happen in the first block.
96
+ const lastL1ToL2MessageTreeSnapshot =
97
+ index === 0 ? this.lastL1ToL2MessageTreeSnapshot : this.newL1ToL2MessageTreeSnapshot;
98
+ const lastL1ToL2MessageSubtreeRootSiblingPath =
99
+ index === 0 ? this.lastL1ToL2MessageSubtreeRootSiblingPath : this.newL1ToL2MessageSubtreeRootSiblingPath;
100
+
101
+ const startSpongeBlob =
102
+ index === 0 ? await SpongeBlob.init(this.totalNumBlobFields) : this.blocks[index - 1]?.getEndSpongeBlob();
103
+ if (!startSpongeBlob) {
104
+ throw new Error(
105
+ 'Cannot start a new block before the trees have progressed from the tx effects in the previous block.',
106
+ );
107
+ }
108
+
109
+ const block = new BlockProvingState(
110
+ index,
111
+ blockNumber,
112
+ totalNumTxs,
113
+ this.constants,
114
+ timestamp,
115
+ lastArchiveTreeSnapshot,
116
+ lastArchiveSiblingPath,
117
+ lastL1ToL2MessageTreeSnapshot,
118
+ lastL1ToL2MessageSubtreeRootSiblingPath,
119
+ this.newL1ToL2MessageTreeSnapshot,
120
+ this.headerOfLastBlockInPreviousCheckpoint,
121
+ startSpongeBlob,
122
+ this,
123
+ );
124
+ this.blocks[index] = block;
125
+
126
+ return block;
127
+ }
128
+
129
+ // Returns true if we are still able to accept blocks, false otherwise.
130
+ public isAcceptingBlocks() {
131
+ return this.blocks.filter(b => !!b).length < this.totalNumBlocks;
132
+ }
133
+
134
+ public setBlockRootRollupProof(
135
+ blockIndex: number,
136
+ provingOutput: PublicInputsAndRecursiveProof<
137
+ BlockRollupPublicInputs,
138
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
139
+ >,
140
+ ): TreeNodeLocation {
141
+ return this.blockProofs.setLeaf(blockIndex, { provingOutput });
142
+ }
143
+
144
+ public tryStartProvingBlockMerge(location: TreeNodeLocation) {
145
+ if (this.blockProofs.getNode(location)?.isProving) {
146
+ return false;
147
+ } else {
148
+ this.blockProofs.setNode(location, { isProving: true });
149
+ return true;
150
+ }
151
+ }
152
+
153
+ public setBlockMergeRollupProof(
154
+ location: TreeNodeLocation,
155
+ provingOutput: PublicInputsAndRecursiveProof<
156
+ BlockRollupPublicInputs,
157
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
158
+ >,
159
+ ) {
160
+ this.blockProofs.setNode(location, { provingOutput });
161
+ }
162
+
163
+ public tryStartProvingCheckpointRoot() {
164
+ if (this.checkpointRootProof?.isProving) {
165
+ return false;
166
+ } else {
167
+ this.checkpointRootProof = { isProving: true };
168
+ return true;
169
+ }
170
+ }
171
+
172
+ public setCheckpointRootRollupProof(
173
+ provingOutput: PublicInputsAndRecursiveProof<
174
+ CheckpointRollupPublicInputs,
175
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
176
+ >,
177
+ ): TreeNodeLocation {
178
+ this.checkpointRootProof = { provingOutput };
179
+ return this.parentEpoch.setCheckpointRootRollupProof(this.index, provingOutput);
180
+ }
181
+
182
+ public getBaseParityInputs(baseParityIndex: number) {
183
+ const messages = padArrayEnd(
184
+ this.l1ToL2Messages.slice(
185
+ baseParityIndex * NUM_MSGS_PER_BASE_PARITY,
186
+ (baseParityIndex + 1) * NUM_MSGS_PER_BASE_PARITY,
187
+ ),
188
+ Fr.ZERO,
189
+ NUM_MSGS_PER_BASE_PARITY,
190
+ );
191
+ return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
192
+ }
193
+
194
+ public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
195
+ if (this.isAcceptingBlocks() || this.blocks.some(b => b!.isAcceptingTxs())) {
196
+ return;
197
+ }
198
+
199
+ this.blobFields = getCheckpointBlobFields(this.blocks.map(b => b!.getTxEffects()));
200
+ this.endBlobAccumulator = await accumulateBlobs(this.blobFields, startBlobAccumulator);
201
+ this.startBlobAccumulator = startBlobAccumulator;
202
+
203
+ this.onBlobAccumulatorSet(this);
204
+
205
+ return this.endBlobAccumulator;
206
+ }
207
+
208
+ public getEndBlobAccumulator() {
209
+ return this.endBlobAccumulator;
210
+ }
211
+
212
+ public getParentLocation(location: TreeNodeLocation) {
213
+ return this.blockProofs.getParentLocation(location);
214
+ }
215
+
216
+ public getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation) {
217
+ const [left, right] = this.blockProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
218
+ if (!left || !right) {
219
+ throw new Error('At least one child is not ready for the block merge rollup.');
220
+ }
221
+
222
+ return new BlockMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
223
+ }
224
+
225
+ public getCheckpointRootRollupType(): CircuitName {
226
+ return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
227
+ }
228
+
229
+ public getCheckpointRootRollupInputs() {
230
+ const proofs = this.#getChildProofsForRoot();
231
+ const nonEmptyProofs = proofs.filter(p => !!p);
232
+ if (proofs.length !== nonEmptyProofs.length) {
233
+ throw new Error('At least one child is not ready for the checkpoint root rollup.');
234
+ }
235
+ if (!this.startBlobAccumulator) {
236
+ throw new Error('Start blob accumulator is not set.');
237
+ }
238
+
239
+ // `blobFields` must've been set if `startBlobAccumulator` is set (in `accumulateBlobs`).
240
+ const blobFields = this.blobFields!;
241
+
242
+ const { blobCommitments, blobsHash } = buildBlobHints(blobFields);
243
+
244
+ const hints = CheckpointRootRollupHints.from({
245
+ previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
246
+ previousArchiveSiblingPath: this.lastArchiveSiblingPath,
247
+ startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
248
+ finalBlobChallenges: this.finalBlobBatchingChallenges,
249
+ blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
250
+ blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_BLOCK),
251
+ blobsHash,
252
+ });
253
+
254
+ const [left, right] = nonEmptyProofs.map(p => toProofData(p));
255
+
256
+ return !right
257
+ ? new CheckpointRootSingleBlockRollupPrivateInputs(left, hints)
258
+ : new CheckpointRootRollupPrivateInputs([left, right], hints);
259
+ }
260
+
261
+ public getBlockProvingStateByBlockNumber(blockNumber: number) {
262
+ const index = blockNumber - this.firstBlockNumber;
263
+ return this.blocks[index];
264
+ }
265
+
266
+ public isReadyForBlockMerge(location: TreeNodeLocation) {
267
+ return !!this.blockProofs.getSibling(location)?.provingOutput;
268
+ }
269
+
270
+ public isReadyForCheckpointRoot() {
271
+ const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
272
+ return allChildProofsReady && !!this.startBlobAccumulator;
273
+ }
274
+
275
+ public verifyState() {
276
+ return this.parentEpoch.verifyState();
277
+ }
278
+
279
+ public getError() {
280
+ return this.error;
281
+ }
282
+
283
+ // Attempts to reject the proving state promise with a reason of 'cancelled'
284
+ public cancel() {
285
+ this.reject('Proving cancelled');
286
+ }
287
+
288
+ public reject(reason: string) {
289
+ this.error = reason;
290
+ this.parentEpoch.reject(reason);
291
+ }
292
+
293
+ #getChildProofsForRoot() {
294
+ const rootLocation = { level: 0, index: 0 };
295
+ return this.totalNumBlocks === 1
296
+ ? [this.blockProofs.getNode(rootLocation)?.provingOutput] // If there's only 1 block, its proof will be stored at the root.
297
+ : this.blockProofs.getChildren(rootLocation).map(c => c?.provingOutput);
298
+ }
299
+ }