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

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 (78) hide show
  1. package/dest/light/lightweight_checkpoint_builder.d.ts +1 -1
  2. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  3. package/dest/light/lightweight_checkpoint_builder.js +3 -1
  4. package/dest/mocks/test_context.d.ts +9 -11
  5. package/dest/mocks/test_context.d.ts.map +1 -1
  6. package/dest/mocks/test_context.js +13 -22
  7. package/dest/orchestrator/block-building-helpers.d.ts +1 -1
  8. package/dest/orchestrator/checkpoint-proving-state.d.ts +13 -36
  9. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  10. package/dest/orchestrator/checkpoint-proving-state.js +18 -125
  11. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +116 -62
  12. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -1
  13. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1005 -90
  14. package/dest/orchestrator/chonk-cache.d.ts +39 -0
  15. package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
  16. package/dest/orchestrator/chonk-cache.js +80 -0
  17. package/dest/orchestrator/index.d.ts +2 -3
  18. package/dest/orchestrator/index.d.ts.map +1 -1
  19. package/dest/orchestrator/index.js +1 -2
  20. package/dest/orchestrator/proving-scheduler.d.ts +26 -17
  21. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -1
  22. package/dest/orchestrator/proving-scheduler.js +28 -25
  23. package/dest/orchestrator/top-tree-orchestrator.d.ts +11 -6
  24. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -1
  25. package/dest/orchestrator/top-tree-orchestrator.js +71 -21
  26. package/dest/orchestrator/top-tree-proving-state.d.ts +1 -1
  27. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -1
  28. package/dest/orchestrator/tx-proving-state.d.ts +3 -3
  29. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  30. package/dest/prover-client/prover-client.d.ts +17 -19
  31. package/dest/prover-client/prover-client.d.ts.map +1 -1
  32. package/dest/prover-client/prover-client.js +24 -25
  33. package/dest/proving_broker/broker_prover_facade.d.ts +3 -3
  34. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  35. package/dest/test/epoch_settlement.d.ts +36 -0
  36. package/dest/test/epoch_settlement.d.ts.map +1 -0
  37. package/dest/test/epoch_settlement.js +52 -0
  38. package/dest/test/index.d.ts +2 -0
  39. package/dest/test/index.d.ts.map +1 -0
  40. package/dest/test/index.js +1 -0
  41. package/dest/test/mock_prover.d.ts +1 -1
  42. package/dest/test/mock_prover.js +2 -2
  43. package/package.json +17 -16
  44. package/src/light/lightweight_checkpoint_builder.ts +2 -0
  45. package/src/mocks/test_context.ts +14 -34
  46. package/src/orchestrator/checkpoint-proving-state.ts +14 -168
  47. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +902 -129
  48. package/src/orchestrator/chonk-cache.ts +99 -0
  49. package/src/orchestrator/index.ts +1 -2
  50. package/src/orchestrator/proving-scheduler.ts +29 -25
  51. package/src/orchestrator/top-tree-orchestrator.ts +114 -44
  52. package/src/orchestrator/top-tree-proving-state.ts +0 -1
  53. package/src/orchestrator/tx-proving-state.ts +3 -3
  54. package/src/prover-client/prover-client.ts +35 -49
  55. package/src/proving_broker/broker_prover_facade.ts +2 -2
  56. package/src/test/epoch_settlement.ts +82 -0
  57. package/src/test/index.ts +1 -0
  58. package/src/test/mock_prover.ts +2 -2
  59. package/dest/orchestrator/epoch-proving-context.d.ts +0 -51
  60. package/dest/orchestrator/epoch-proving-context.d.ts.map +0 -1
  61. package/dest/orchestrator/epoch-proving-context.js +0 -81
  62. package/dest/orchestrator/epoch-proving-state.d.ts +0 -75
  63. package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
  64. package/dest/orchestrator/epoch-proving-state.js +0 -269
  65. package/dest/orchestrator/orchestrator.d.ts +0 -118
  66. package/dest/orchestrator/orchestrator.d.ts.map +0 -1
  67. package/dest/orchestrator/orchestrator.js +0 -1113
  68. package/dest/orchestrator/top-tree-proving-scheduler.d.ts +0 -62
  69. package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +0 -1
  70. package/dest/orchestrator/top-tree-proving-scheduler.js +0 -73
  71. package/dest/prover-client/server-epoch-prover.d.ts +0 -32
  72. package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
  73. package/dest/prover-client/server-epoch-prover.js +0 -40
  74. package/src/orchestrator/epoch-proving-context.ts +0 -101
  75. package/src/orchestrator/epoch-proving-state.ts +0 -380
  76. package/src/orchestrator/orchestrator.ts +0 -1111
  77. package/src/orchestrator/top-tree-proving-scheduler.ts +0 -154
  78. package/src/prover-client/server-epoch-prover.ts +0 -69
@@ -1,66 +1,30 @@
1
- import {
2
- BatchedBlobAccumulator,
3
- type FinalBlobBatchingChallenges,
4
- SpongeBlob,
5
- encodeCheckpointBlobDataFromBlocks,
6
- } from '@aztec/blob-lib';
1
+ import { SpongeBlob } from '@aztec/blob-lib';
7
2
  import {
8
3
  type ARCHIVE_HEIGHT,
9
- BLOBS_PER_CHECKPOINT,
10
- FIELDS_PER_BLOB,
11
4
  type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
12
5
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
13
6
  NUM_MSGS_PER_BASE_PARITY,
14
- OUT_HASH_TREE_HEIGHT,
15
7
  } from '@aztec/constants';
16
8
  import { BlockNumber } from '@aztec/foundation/branded-types';
17
9
  import { padArrayEnd } from '@aztec/foundation/collection';
18
- import { BLS12Point } from '@aztec/foundation/curves/bls12';
19
10
  import { Fr } from '@aztec/foundation/curves/bn254';
20
11
  import type { Tuple } from '@aztec/foundation/serialize';
21
12
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
22
13
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
- import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
24
14
  import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
25
- import {
26
- BlockMergeRollupPrivateInputs,
27
- BlockRollupPublicInputs,
28
- CheckpointConstantData,
29
- CheckpointRollupPublicInputs,
30
- CheckpointRootRollupHints,
31
- CheckpointRootRollupPrivateInputs,
32
- CheckpointRootSingleBlockRollupPrivateInputs,
33
- } from '@aztec/stdlib/rollup';
34
- import type { CircuitName } from '@aztec/stdlib/stats';
15
+ import { BlockMergeRollupPrivateInputs, BlockRollupPublicInputs, CheckpointConstantData } from '@aztec/stdlib/rollup';
35
16
  import type { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
36
17
  import type { BlockHeader } from '@aztec/stdlib/tx';
37
18
  import type { UInt64 } from '@aztec/stdlib/types';
38
19
 
39
- import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-helpers.js';
20
+ import { toProofData } from './block-building-helpers.js';
40
21
  import { BlockProvingState, type ProofState } from './block-proving-state.js';
41
- import type { EpochProvingState } from './epoch-proving-state.js';
42
-
43
- type OutHashHint = {
44
- treeSnapshot: AppendOnlyTreeSnapshot;
45
- siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
46
- };
47
22
 
48
23
  export class CheckpointProvingState {
49
24
  private blockProofs: UnbalancedTreeStore<
50
25
  ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
51
26
  >;
52
- private checkpointRootProof:
53
- | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
54
- | undefined;
55
27
  private blocks: (BlockProvingState | undefined)[] = [];
56
- private previousOutHashHint: OutHashHint | undefined;
57
- private outHash: Fr | undefined;
58
- // The snapshot and sibling path after the checkpoint's out hash is inserted.
59
- // Stored here to be retrieved for the next checkpoint when it's added.
60
- private newOutHashHint: OutHashHint | undefined;
61
- private startBlobAccumulator: BatchedBlobAccumulator | undefined;
62
- private endBlobAccumulator: BatchedBlobAccumulator | undefined;
63
- private blobFields: Fr[] | undefined;
64
28
  private error: string | undefined;
65
29
  public readonly firstBlockNumber: BlockNumber;
66
30
 
@@ -68,7 +32,6 @@ export class CheckpointProvingState {
68
32
  public readonly index: number,
69
33
  public readonly constants: CheckpointConstantData,
70
34
  public readonly totalNumBlocks: number,
71
- private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
72
35
  private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
73
36
  private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
74
37
  private readonly l1ToL2Messages: Fr[],
@@ -84,17 +47,16 @@ export class CheckpointProvingState {
84
47
  Fr,
85
48
  typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
86
49
  >,
87
- public parentEpoch: EpochProvingState,
88
- private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
50
+ public readonly epochNumber: number,
51
+ /** Owner's liveness check. `verifyState()` returns false once this returns false. */
52
+ private readonly isAlive: () => boolean,
53
+ /** Owner's failure callback. Invoked from `reject` to surface the error upward. */
54
+ private readonly onReject: (reason: string) => void,
89
55
  ) {
90
56
  this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
91
57
  this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
92
58
  }
93
59
 
94
- public get epochNumber(): number {
95
- return this.parentEpoch.epochNumber;
96
- }
97
-
98
60
  public startNewBlock(
99
61
  blockNumber: BlockNumber,
100
62
  timestamp: UInt64,
@@ -176,25 +138,6 @@ export class CheckpointProvingState {
176
138
  this.blockProofs.setNode(location, { provingOutput });
177
139
  }
178
140
 
179
- public tryStartProvingCheckpointRoot() {
180
- if (this.checkpointRootProof?.isProving) {
181
- return false;
182
- } else {
183
- this.checkpointRootProof = { isProving: true };
184
- return true;
185
- }
186
- }
187
-
188
- public setCheckpointRootRollupProof(
189
- provingOutput: PublicInputsAndRecursiveProof<
190
- CheckpointRollupPublicInputs,
191
- typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
192
- >,
193
- ): TreeNodeLocation {
194
- this.checkpointRootProof = { provingOutput };
195
- return this.parentEpoch.setCheckpointRootRollupProof(this.index, provingOutput);
196
- }
197
-
198
141
  public getBaseParityInputs(baseParityIndex: number) {
199
142
  const messages = padArrayEnd(
200
143
  this.l1ToL2Messages.slice(
@@ -207,53 +150,6 @@ export class CheckpointProvingState {
207
150
  return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot, this.constants.proverId);
208
151
  }
209
152
 
210
- public setOutHashHint(hint: OutHashHint) {
211
- this.previousOutHashHint = hint;
212
- }
213
-
214
- public getOutHashHint() {
215
- return this.previousOutHashHint;
216
- }
217
-
218
- public accumulateBlockOutHashes() {
219
- if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
220
- return;
221
- }
222
-
223
- if (!this.outHash) {
224
- const messagesPerBlock = this.blocks.map(b => b!.getTxEffects().map(tx => tx.l2ToL1Msgs));
225
- this.outHash = computeCheckpointOutHash(messagesPerBlock);
226
- }
227
-
228
- return this.outHash;
229
- }
230
-
231
- public setOutHashHintForNextCheckpoint(hint: OutHashHint) {
232
- this.newOutHashHint = hint;
233
- }
234
-
235
- public getOutHashHintForNextCheckpoint() {
236
- return this.newOutHashHint;
237
- }
238
-
239
- public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
240
- if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
241
- return;
242
- }
243
-
244
- this.blobFields = encodeCheckpointBlobDataFromBlocks(this.blocks.map(b => b!.getBlockBlobData()));
245
- this.endBlobAccumulator = await accumulateBlobs(this.blobFields!, startBlobAccumulator);
246
- this.startBlobAccumulator = startBlobAccumulator;
247
-
248
- await this.onBlobAccumulatorSet(this);
249
-
250
- return this.endBlobAccumulator;
251
- }
252
-
253
- public getEndBlobAccumulator() {
254
- return this.endBlobAccumulator;
255
- }
256
-
257
153
  public getParentLocation(location: TreeNodeLocation) {
258
154
  return this.blockProofs.getParentLocation(location);
259
155
  }
@@ -267,47 +163,6 @@ export class CheckpointProvingState {
267
163
  return new BlockMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
268
164
  }
269
165
 
270
- public getCheckpointRootRollupType(): CircuitName {
271
- return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
272
- }
273
-
274
- public async getCheckpointRootRollupInputs() {
275
- const proofs = this.#getChildProofsForRoot();
276
- const nonEmptyProofs = proofs.filter(p => !!p);
277
- if (proofs.length !== nonEmptyProofs.length) {
278
- throw new Error('At least one child is not ready for the checkpoint root rollup.');
279
- }
280
- if (!this.previousOutHashHint) {
281
- throw new Error('Out hash hint is not set.');
282
- }
283
- if (!this.startBlobAccumulator) {
284
- throw new Error('Start blob accumulator is not set.');
285
- }
286
-
287
- // `blobFields` must've been set if `startBlobAccumulator` is set (in `accumulateBlobs`).
288
- const blobFields = this.blobFields!;
289
-
290
- const { blobCommitments, blobsHash } = await buildBlobHints(blobFields);
291
-
292
- const hints = CheckpointRootRollupHints.from({
293
- previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
294
- previousArchiveSiblingPath: this.lastArchiveSiblingPath,
295
- previousOutHash: this.previousOutHashHint.treeSnapshot,
296
- newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
297
- startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
298
- finalBlobChallenges: this.finalBlobBatchingChallenges,
299
- blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
300
- blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_CHECKPOINT),
301
- blobsHash,
302
- });
303
-
304
- const [left, right] = nonEmptyProofs.map(p => toProofData(p));
305
-
306
- return !right
307
- ? new CheckpointRootSingleBlockRollupPrivateInputs(left, hints)
308
- : new CheckpointRootRollupPrivateInputs([left, right], hints);
309
- }
310
-
311
166
  public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
312
167
  const index = Number(blockNumber) - Number(this.firstBlockNumber);
313
168
  return this.blocks[index];
@@ -317,13 +172,8 @@ export class CheckpointProvingState {
317
172
  return !!this.blockProofs.getSibling(location)?.provingOutput;
318
173
  }
319
174
 
320
- public isReadyForCheckpointRoot() {
321
- const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
322
- return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
323
- }
324
-
325
175
  public verifyState() {
326
- return this.parentEpoch.verifyState();
176
+ return this.isAlive();
327
177
  }
328
178
 
329
179
  public getError() {
@@ -337,14 +187,7 @@ export class CheckpointProvingState {
337
187
 
338
188
  public reject(reason: string) {
339
189
  this.error = reason;
340
- this.parentEpoch.reject(reason);
341
- }
342
-
343
- #getChildProofsForRoot() {
344
- const rootLocation = { level: 0, index: 0 };
345
- return this.totalNumBlocks === 1
346
- ? [this.blockProofs.getNode(rootLocation)?.provingOutput] // If there's only 1 block, its proof will be stored at the root.
347
- : this.blockProofs.getChildren(rootLocation).map(c => c?.provingOutput);
190
+ this.onReject(reason);
348
191
  }
349
192
 
350
193
  /**
@@ -352,7 +195,10 @@ export class CheckpointProvingState {
352
195
  * Used by `CheckpointSubTreeOrchestrator` to surface its sub-tree result.
353
196
  */
354
197
  public getSubTreeOutputProofs() {
355
- return this.#getChildProofsForRoot();
198
+ const rootLocation = { level: 0, index: 0 };
199
+ return this.totalNumBlocks === 1
200
+ ? [this.blockProofs.getNode(rootLocation)?.provingOutput] // If there's only 1 block, its proof will be stored at the root.
201
+ : this.blockProofs.getChildren(rootLocation).map(c => c?.provingOutput);
356
202
  }
357
203
 
358
204
  /** Sibling path of the archive tree captured before any block in this checkpoint landed. */