@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.023c3e5

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 (150) hide show
  1. package/dest/config.d.ts +8 -8
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +12 -2
  4. package/dest/index.d.ts +1 -1
  5. package/dest/light/index.d.ts +2 -0
  6. package/dest/light/index.d.ts.map +1 -0
  7. package/dest/light/index.js +1 -0
  8. package/dest/light/lightweight_checkpoint_builder.d.ts +47 -0
  9. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  10. package/dest/light/lightweight_checkpoint_builder.js +200 -0
  11. package/dest/mocks/fixtures.d.ts +8 -8
  12. package/dest/mocks/fixtures.d.ts.map +1 -1
  13. package/dest/mocks/fixtures.js +36 -17
  14. package/dest/mocks/test_context.d.ts +43 -32
  15. package/dest/mocks/test_context.d.ts.map +1 -1
  16. package/dest/mocks/test_context.js +149 -87
  17. package/dest/orchestrator/block-building-helpers.d.ts +37 -30
  18. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  19. package/dest/orchestrator/block-building-helpers.js +170 -189
  20. package/dest/orchestrator/block-proving-state.d.ts +70 -48
  21. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  22. package/dest/orchestrator/block-proving-state.js +282 -177
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts +76 -0
  24. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  25. package/dest/orchestrator/checkpoint-proving-state.js +243 -0
  26. package/dest/orchestrator/epoch-proving-state.d.ts +43 -28
  27. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  28. package/dest/orchestrator/epoch-proving-state.js +177 -73
  29. package/dest/orchestrator/index.d.ts +1 -1
  30. package/dest/orchestrator/orchestrator.d.ts +53 -35
  31. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  32. package/dest/orchestrator/orchestrator.js +855 -302
  33. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
  34. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  35. package/dest/orchestrator/orchestrator_metrics.js +2 -6
  36. package/dest/orchestrator/tx-proving-state.d.ts +15 -12
  37. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  38. package/dest/orchestrator/tx-proving-state.js +27 -44
  39. package/dest/prover-client/factory.d.ts +3 -3
  40. package/dest/prover-client/factory.d.ts.map +1 -1
  41. package/dest/prover-client/index.d.ts +1 -1
  42. package/dest/prover-client/prover-client.d.ts +5 -5
  43. package/dest/prover-client/prover-client.d.ts.map +1 -1
  44. package/dest/prover-client/prover-client.js +11 -7
  45. package/dest/prover-client/server-epoch-prover.d.ts +16 -12
  46. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  47. package/dest/prover-client/server-epoch-prover.js +11 -11
  48. package/dest/proving_broker/broker_prover_facade.d.ts +28 -19
  49. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  50. package/dest/proving_broker/broker_prover_facade.js +62 -43
  51. package/dest/proving_broker/config.d.ts +23 -10
  52. package/dest/proving_broker/config.d.ts.map +1 -1
  53. package/dest/proving_broker/config.js +29 -6
  54. package/dest/proving_broker/factory.d.ts +2 -2
  55. package/dest/proving_broker/factory.d.ts.map +1 -1
  56. package/dest/proving_broker/factory.js +5 -1
  57. package/dest/proving_broker/fixtures.d.ts +3 -2
  58. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  59. package/dest/proving_broker/fixtures.js +3 -2
  60. package/dest/proving_broker/index.d.ts +1 -1
  61. package/dest/proving_broker/proof_store/factory.d.ts +2 -2
  62. package/dest/proving_broker/proof_store/factory.js +1 -1
  63. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
  64. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  65. package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
  66. package/dest/proving_broker/proof_store/index.d.ts +2 -1
  67. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  68. package/dest/proving_broker/proof_store/index.js +1 -0
  69. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  70. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  71. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  72. package/dest/proving_broker/proving_agent.d.ts +8 -12
  73. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  74. package/dest/proving_broker/proving_agent.js +86 -65
  75. package/dest/proving_broker/proving_broker.d.ts +13 -4
  76. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  77. package/dest/proving_broker/proving_broker.js +40 -33
  78. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  79. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  80. package/dest/proving_broker/proving_broker_database/memory.js +1 -1
  81. package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
  82. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  83. package/dest/proving_broker/proving_broker_database/persisted.js +401 -11
  84. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  85. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  86. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  87. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  88. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  89. package/dest/proving_broker/proving_job_controller.d.ts +11 -10
  90. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  91. package/dest/proving_broker/proving_job_controller.js +92 -62
  92. package/dest/proving_broker/rpc.d.ts +4 -6
  93. package/dest/proving_broker/rpc.d.ts.map +1 -1
  94. package/dest/proving_broker/rpc.js +1 -4
  95. package/dest/test/mock_proof_store.d.ts +9 -0
  96. package/dest/test/mock_proof_store.d.ts.map +1 -0
  97. package/dest/test/mock_proof_store.js +10 -0
  98. package/dest/test/mock_prover.d.ts +23 -17
  99. package/dest/test/mock_prover.d.ts.map +1 -1
  100. package/dest/test/mock_prover.js +38 -20
  101. package/package.json +33 -31
  102. package/src/config.ts +25 -9
  103. package/src/light/index.ts +1 -0
  104. package/src/light/lightweight_checkpoint_builder.ts +289 -0
  105. package/src/mocks/fixtures.ts +46 -40
  106. package/src/mocks/test_context.ts +223 -116
  107. package/src/orchestrator/block-building-helpers.ts +258 -334
  108. package/src/orchestrator/block-proving-state.ts +325 -231
  109. package/src/orchestrator/checkpoint-proving-state.ts +349 -0
  110. package/src/orchestrator/epoch-proving-state.ts +237 -111
  111. package/src/orchestrator/orchestrator.ts +653 -343
  112. package/src/orchestrator/orchestrator_metrics.ts +2 -6
  113. package/src/orchestrator/tx-proving-state.ts +48 -66
  114. package/src/prover-client/factory.ts +6 -2
  115. package/src/prover-client/prover-client.ts +41 -29
  116. package/src/prover-client/server-epoch-prover.ts +40 -22
  117. package/src/proving_broker/broker_prover_facade.ts +212 -131
  118. package/src/proving_broker/config.ts +34 -7
  119. package/src/proving_broker/factory.ts +2 -1
  120. package/src/proving_broker/fixtures.ts +8 -3
  121. package/src/proving_broker/proof_store/factory.ts +1 -1
  122. package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
  123. package/src/proving_broker/proof_store/index.ts +1 -0
  124. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  125. package/src/proving_broker/proving_agent.ts +95 -66
  126. package/src/proving_broker/proving_broker.ts +57 -41
  127. package/src/proving_broker/proving_broker_database/memory.ts +3 -2
  128. package/src/proving_broker/proving_broker_database/persisted.ts +29 -13
  129. package/src/proving_broker/proving_broker_database.ts +2 -1
  130. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  131. package/src/proving_broker/proving_job_controller.ts +100 -83
  132. package/src/proving_broker/rpc.ts +1 -6
  133. package/src/test/mock_proof_store.ts +14 -0
  134. package/src/test/mock_prover.ts +156 -64
  135. package/dest/bin/get-proof-inputs.d.ts +0 -2
  136. package/dest/bin/get-proof-inputs.d.ts.map +0 -1
  137. package/dest/bin/get-proof-inputs.js +0 -51
  138. package/dest/block_builder/index.d.ts +0 -6
  139. package/dest/block_builder/index.d.ts.map +0 -1
  140. package/dest/block_builder/index.js +0 -1
  141. package/dest/block_builder/light.d.ts +0 -33
  142. package/dest/block_builder/light.d.ts.map +0 -1
  143. package/dest/block_builder/light.js +0 -82
  144. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  145. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  146. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  147. package/src/bin/get-proof-inputs.ts +0 -59
  148. package/src/block_builder/index.ts +0 -6
  149. package/src/block_builder/light.ts +0 -101
  150. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -0,0 +1,349 @@
1
+ import {
2
+ BatchedBlobAccumulator,
3
+ type FinalBlobBatchingChallenges,
4
+ SpongeBlob,
5
+ encodeCheckpointBlobDataFromBlocks,
6
+ } from '@aztec/blob-lib';
7
+ import {
8
+ type ARCHIVE_HEIGHT,
9
+ BLOBS_PER_CHECKPOINT,
10
+ FIELDS_PER_BLOB,
11
+ type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
12
+ type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
13
+ NUM_MSGS_PER_BASE_PARITY,
14
+ OUT_HASH_TREE_HEIGHT,
15
+ } from '@aztec/constants';
16
+ import { BlockNumber } from '@aztec/foundation/branded-types';
17
+ import { padArrayEnd } from '@aztec/foundation/collection';
18
+ import { BLS12Point } from '@aztec/foundation/curves/bls12';
19
+ import { Fr } from '@aztec/foundation/curves/bn254';
20
+ import type { Tuple } from '@aztec/foundation/serialize';
21
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
22
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
24
+ 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';
35
+ import type { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
36
+ import type { BlockHeader } from '@aztec/stdlib/tx';
37
+ import type { UInt64 } from '@aztec/stdlib/types';
38
+
39
+ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-helpers.js';
40
+ 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
+
48
+ export class CheckpointProvingState {
49
+ private blockProofs: UnbalancedTreeStore<
50
+ ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
51
+ >;
52
+ private checkpointRootProof:
53
+ | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
54
+ | undefined;
55
+ 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
+ private error: string | undefined;
65
+ public readonly firstBlockNumber: BlockNumber;
66
+
67
+ constructor(
68
+ public readonly index: number,
69
+ public readonly constants: CheckpointConstantData,
70
+ public readonly totalNumBlocks: number,
71
+ private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
72
+ private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
73
+ private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
74
+ private readonly l1ToL2Messages: Fr[],
75
+ // The snapshot and sibling path before the new l1 to l2 message subtree is inserted.
76
+ private readonly lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
77
+ private readonly lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<
78
+ Fr,
79
+ typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
80
+ >,
81
+ // The snapshot and sibling path after the new l1 to l2 message subtree is inserted.
82
+ private readonly newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
83
+ private readonly newL1ToL2MessageSubtreeRootSiblingPath: Tuple<
84
+ Fr,
85
+ typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
86
+ >,
87
+ public parentEpoch: EpochProvingState,
88
+ private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
89
+ ) {
90
+ this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
91
+ this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
92
+ }
93
+
94
+ public get epochNumber(): number {
95
+ return this.parentEpoch.epochNumber;
96
+ }
97
+
98
+ public startNewBlock(
99
+ blockNumber: BlockNumber,
100
+ timestamp: UInt64,
101
+ totalNumTxs: number,
102
+ lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
103
+ lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
104
+ ): BlockProvingState {
105
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
106
+ if (index >= this.totalNumBlocks) {
107
+ throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
108
+ }
109
+
110
+ // If this is the first block, we use the snapshot and sibling path before the new l1 to l2 messages are inserted.
111
+ // Otherwise, we use the snapshot and sibling path after the new l1 to l2 messages are inserted, which will always
112
+ // happen in the first block.
113
+ const lastL1ToL2MessageTreeSnapshot =
114
+ index === 0 ? this.lastL1ToL2MessageTreeSnapshot : this.newL1ToL2MessageTreeSnapshot;
115
+ const lastL1ToL2MessageSubtreeRootSiblingPath =
116
+ index === 0 ? this.lastL1ToL2MessageSubtreeRootSiblingPath : this.newL1ToL2MessageSubtreeRootSiblingPath;
117
+
118
+ const startSpongeBlob = index === 0 ? SpongeBlob.init() : this.blocks[index - 1]?.getEndSpongeBlob();
119
+ if (!startSpongeBlob) {
120
+ throw new Error(
121
+ 'Cannot start a new block before the trees have progressed from the tx effects in the previous block.',
122
+ );
123
+ }
124
+
125
+ const block = new BlockProvingState(
126
+ index,
127
+ blockNumber,
128
+ totalNumTxs,
129
+ this.constants,
130
+ timestamp,
131
+ lastArchiveTreeSnapshot,
132
+ lastArchiveSiblingPath,
133
+ lastL1ToL2MessageTreeSnapshot,
134
+ lastL1ToL2MessageSubtreeRootSiblingPath,
135
+ this.newL1ToL2MessageTreeSnapshot,
136
+ this.headerOfLastBlockInPreviousCheckpoint,
137
+ startSpongeBlob,
138
+ this,
139
+ );
140
+ this.blocks[index] = block;
141
+
142
+ return block;
143
+ }
144
+
145
+ // Returns true if we are still able to accept blocks, false otherwise.
146
+ public isAcceptingBlocks() {
147
+ return this.blocks.filter(b => !!b).length < this.totalNumBlocks;
148
+ }
149
+
150
+ public setBlockRootRollupProof(
151
+ blockIndex: number,
152
+ provingOutput: PublicInputsAndRecursiveProof<
153
+ BlockRollupPublicInputs,
154
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
155
+ >,
156
+ ): TreeNodeLocation {
157
+ return this.blockProofs.setLeaf(blockIndex, { provingOutput });
158
+ }
159
+
160
+ public tryStartProvingBlockMerge(location: TreeNodeLocation) {
161
+ if (this.blockProofs.getNode(location)?.isProving) {
162
+ return false;
163
+ } else {
164
+ this.blockProofs.setNode(location, { isProving: true });
165
+ return true;
166
+ }
167
+ }
168
+
169
+ public setBlockMergeRollupProof(
170
+ location: TreeNodeLocation,
171
+ provingOutput: PublicInputsAndRecursiveProof<
172
+ BlockRollupPublicInputs,
173
+ typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
174
+ >,
175
+ ) {
176
+ this.blockProofs.setNode(location, { provingOutput });
177
+ }
178
+
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
+ public getBaseParityInputs(baseParityIndex: number) {
199
+ const messages = padArrayEnd(
200
+ this.l1ToL2Messages.slice(
201
+ baseParityIndex * NUM_MSGS_PER_BASE_PARITY,
202
+ (baseParityIndex + 1) * NUM_MSGS_PER_BASE_PARITY,
203
+ ),
204
+ Fr.ZERO,
205
+ NUM_MSGS_PER_BASE_PARITY,
206
+ );
207
+ return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
208
+ }
209
+
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
+ this.onBlobAccumulatorSet(this);
249
+
250
+ return this.endBlobAccumulator;
251
+ }
252
+
253
+ public getEndBlobAccumulator() {
254
+ return this.endBlobAccumulator;
255
+ }
256
+
257
+ public getParentLocation(location: TreeNodeLocation) {
258
+ return this.blockProofs.getParentLocation(location);
259
+ }
260
+
261
+ public getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation) {
262
+ const [left, right] = this.blockProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
263
+ if (!left || !right) {
264
+ throw new Error('At least one child is not ready for the block merge rollup.');
265
+ }
266
+
267
+ return new BlockMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
268
+ }
269
+
270
+ public getCheckpointRootRollupType(): CircuitName {
271
+ return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
272
+ }
273
+
274
+ public 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 } = 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
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
312
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
313
+ return this.blocks[index];
314
+ }
315
+
316
+ public isReadyForBlockMerge(location: TreeNodeLocation) {
317
+ return !!this.blockProofs.getSibling(location)?.provingOutput;
318
+ }
319
+
320
+ public isReadyForCheckpointRoot() {
321
+ const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
322
+ return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
323
+ }
324
+
325
+ public verifyState() {
326
+ return this.parentEpoch.verifyState();
327
+ }
328
+
329
+ public getError() {
330
+ return this.error;
331
+ }
332
+
333
+ // Attempts to reject the proving state promise with a reason of 'cancelled'
334
+ public cancel() {
335
+ this.reject('Proving cancelled');
336
+ }
337
+
338
+ public reject(reason: string) {
339
+ 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);
348
+ }
349
+ }