@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.21caa21

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 (147) hide show
  1. package/dest/block-factory/index.d.ts +2 -0
  2. package/dest/block-factory/index.d.ts.map +1 -0
  3. package/dest/block-factory/light.d.ts +38 -0
  4. package/dest/block-factory/light.d.ts.map +1 -0
  5. package/dest/block-factory/light.js +108 -0
  6. package/dest/config.d.ts +7 -7
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +11 -1
  9. package/dest/index.d.ts +1 -1
  10. package/dest/light/lightweight_checkpoint_builder.d.ts +28 -0
  11. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  12. package/dest/light/lightweight_checkpoint_builder.js +107 -0
  13. package/dest/mocks/fixtures.d.ts +8 -8
  14. package/dest/mocks/fixtures.d.ts.map +1 -1
  15. package/dest/mocks/fixtures.js +32 -14
  16. package/dest/mocks/test_context.d.ts +40 -31
  17. package/dest/mocks/test_context.d.ts.map +1 -1
  18. package/dest/mocks/test_context.js +134 -86
  19. package/dest/orchestrator/block-building-helpers.d.ts +36 -29
  20. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  21. package/dest/orchestrator/block-building-helpers.js +168 -188
  22. package/dest/orchestrator/block-proving-state.d.ts +68 -47
  23. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/block-proving-state.js +281 -176
  25. package/dest/orchestrator/checkpoint-proving-state.d.ts +62 -0
  26. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  27. package/dest/orchestrator/checkpoint-proving-state.js +208 -0
  28. package/dest/orchestrator/epoch-proving-state.d.ts +40 -26
  29. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  30. package/dest/orchestrator/epoch-proving-state.js +143 -73
  31. package/dest/orchestrator/index.d.ts +1 -1
  32. package/dest/orchestrator/orchestrator.d.ts +35 -32
  33. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  34. package/dest/orchestrator/orchestrator.js +389 -239
  35. package/dest/orchestrator/orchestrator_metrics.d.ts +3 -1
  36. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  37. package/dest/orchestrator/orchestrator_metrics.js +9 -0
  38. package/dest/orchestrator/tx-proving-state.d.ts +13 -11
  39. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  40. package/dest/orchestrator/tx-proving-state.js +23 -40
  41. package/dest/prover-client/factory.d.ts +1 -1
  42. package/dest/prover-client/index.d.ts +1 -1
  43. package/dest/prover-client/prover-client.d.ts +4 -4
  44. package/dest/prover-client/prover-client.d.ts.map +1 -1
  45. package/dest/prover-client/prover-client.js +5 -4
  46. package/dest/prover-client/server-epoch-prover.d.ts +15 -11
  47. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  48. package/dest/prover-client/server-epoch-prover.js +11 -11
  49. package/dest/proving_broker/broker_prover_facade.d.ts +23 -16
  50. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  51. package/dest/proving_broker/broker_prover_facade.js +67 -41
  52. package/dest/proving_broker/config.d.ts +18 -9
  53. package/dest/proving_broker/config.d.ts.map +1 -1
  54. package/dest/proving_broker/config.js +22 -5
  55. package/dest/proving_broker/factory.d.ts +2 -2
  56. package/dest/proving_broker/factory.d.ts.map +1 -1
  57. package/dest/proving_broker/factory.js +5 -1
  58. package/dest/proving_broker/fixtures.d.ts +3 -2
  59. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  60. package/dest/proving_broker/fixtures.js +2 -1
  61. package/dest/proving_broker/index.d.ts +1 -1
  62. package/dest/proving_broker/proof_store/factory.d.ts +2 -2
  63. package/dest/proving_broker/proof_store/factory.js +1 -1
  64. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
  65. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  66. package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
  67. package/dest/proving_broker/proof_store/index.d.ts +2 -1
  68. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  69. package/dest/proving_broker/proof_store/index.js +1 -0
  70. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  71. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  72. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  73. package/dest/proving_broker/proving_agent.d.ts +4 -4
  74. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_agent.js +83 -47
  76. package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
  77. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
  78. package/dest/proving_broker/proving_broker.d.ts +13 -4
  79. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  80. package/dest/proving_broker/proving_broker.js +36 -23
  81. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  82. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  83. package/dest/proving_broker/proving_broker_database/memory.js +1 -1
  84. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  85. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  86. package/dest/proving_broker/proving_broker_database/persisted.js +12 -10
  87. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  88. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  89. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  90. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  91. package/dest/proving_broker/proving_job_controller.d.ts +9 -9
  92. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  93. package/dest/proving_broker/proving_job_controller.js +89 -61
  94. package/dest/proving_broker/rpc.d.ts +4 -6
  95. package/dest/proving_broker/rpc.d.ts.map +1 -1
  96. package/dest/proving_broker/rpc.js +1 -4
  97. package/dest/test/mock_proof_store.d.ts +9 -0
  98. package/dest/test/mock_proof_store.d.ts.map +1 -0
  99. package/dest/test/mock_proof_store.js +10 -0
  100. package/dest/test/mock_prover.d.ts +23 -17
  101. package/dest/test/mock_prover.d.ts.map +1 -1
  102. package/dest/test/mock_prover.js +38 -20
  103. package/package.json +32 -31
  104. package/src/block-factory/index.ts +1 -0
  105. package/src/block-factory/light.ts +137 -0
  106. package/src/config.ts +24 -8
  107. package/src/light/lightweight_checkpoint_builder.ts +142 -0
  108. package/src/mocks/fixtures.ts +42 -37
  109. package/src/mocks/test_context.ts +207 -115
  110. package/src/orchestrator/block-building-helpers.ts +256 -333
  111. package/src/orchestrator/block-proving-state.ts +323 -230
  112. package/src/orchestrator/checkpoint-proving-state.ts +301 -0
  113. package/src/orchestrator/epoch-proving-state.ts +187 -112
  114. package/src/orchestrator/orchestrator.ts +592 -299
  115. package/src/orchestrator/orchestrator_metrics.ts +20 -1
  116. package/src/orchestrator/tx-proving-state.ts +50 -64
  117. package/src/prover-client/prover-client.ts +16 -14
  118. package/src/prover-client/server-epoch-prover.ts +39 -21
  119. package/src/proving_broker/broker_prover_facade.ts +214 -126
  120. package/src/proving_broker/config.ts +24 -6
  121. package/src/proving_broker/factory.ts +2 -1
  122. package/src/proving_broker/fixtures.ts +7 -2
  123. package/src/proving_broker/proof_store/factory.ts +1 -1
  124. package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
  125. package/src/proving_broker/proof_store/index.ts +1 -0
  126. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  127. package/src/proving_broker/proving_agent.ts +89 -47
  128. package/src/proving_broker/proving_broker.ts +53 -33
  129. package/src/proving_broker/proving_broker_database/memory.ts +3 -2
  130. package/src/proving_broker/proving_broker_database/persisted.ts +14 -12
  131. package/src/proving_broker/proving_broker_database.ts +2 -1
  132. package/src/proving_broker/proving_job_controller.ts +94 -82
  133. package/src/proving_broker/rpc.ts +1 -6
  134. package/src/test/mock_proof_store.ts +14 -0
  135. package/src/test/mock_prover.ts +164 -60
  136. package/dest/bin/get-proof-inputs.d.ts +0 -2
  137. package/dest/bin/get-proof-inputs.d.ts.map +0 -1
  138. package/dest/bin/get-proof-inputs.js +0 -51
  139. package/dest/block_builder/index.d.ts +0 -6
  140. package/dest/block_builder/index.d.ts.map +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/src/bin/get-proof-inputs.ts +0 -59
  145. package/src/block_builder/index.ts +0 -6
  146. package/src/block_builder/light.ts +0 -101
  147. /package/dest/{block_builder → block-factory}/index.js +0 -0
@@ -1,27 +1,31 @@
1
- import {
2
- type ARCHIVE_HEIGHT,
3
- type L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
4
- type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
5
- type TUBE_PROOF_LENGTH,
6
- VK_TREE_HEIGHT,
1
+ import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
+ import type {
3
+ ARCHIVE_HEIGHT,
4
+ L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
5
+ NESTED_RECURSIVE_PROOF_LENGTH,
6
+ NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
7
7
  } from '@aztec/constants';
8
+ import { EpochNumber } from '@aztec/foundation/branded-types';
8
9
  import type { Fr } from '@aztec/foundation/fields';
9
10
  import type { Tuple } from '@aztec/foundation/serialize';
10
- import { MembershipWitness, type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
11
- import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
12
- import type { ProofAndVerificationKey, PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
11
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
12
+ import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
13
13
  import type { Proof } from '@aztec/stdlib/proofs';
14
14
  import {
15
- BlockMergeRollupInputs,
16
- type BlockRootOrBlockMergePublicInputs,
17
- PreviousRollupBlockData,
18
- RootRollupInputs,
15
+ CheckpointConstantData,
16
+ CheckpointMergeRollupPrivateInputs,
17
+ CheckpointPaddingRollupPrivateInputs,
18
+ CheckpointRollupPublicInputs,
19
+ PublicChonkVerifierPublicInputs,
20
+ RootRollupPrivateInputs,
19
21
  type RootRollupPublicInputs,
20
22
  } from '@aztec/stdlib/rollup';
21
23
  import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
22
- import type { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
24
+ import type { BlockHeader } from '@aztec/stdlib/tx';
23
25
 
24
- import { BlockProvingState } from './block-proving-state.js';
26
+ import { toProofData } from './block-building-helpers.js';
27
+ import type { ProofState } from './block-proving-state.js';
28
+ import { CheckpointProvingState } from './checkpoint-proving-state.js';
25
29
 
26
30
  export type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
27
31
 
@@ -41,58 +45,95 @@ export type ProvingResult = { status: 'success' } | { status: 'failure'; reason:
41
45
  * Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
42
46
  */
43
47
  export class EpochProvingState {
44
- private blockRootOrMergeProvingOutputs: UnbalancedTreeStore<
45
- PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
48
+ private checkpointProofs: UnbalancedTreeStore<
49
+ ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
46
50
  >;
47
- private paddingBlockRootProvingOutput:
48
- | PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
51
+ private checkpointPaddingProof:
52
+ | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
49
53
  | undefined;
50
- private rootRollupProvingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs> | undefined;
54
+ private rootRollupProof: ProofState<RootRollupPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
55
+ private checkpoints: (CheckpointProvingState | undefined)[] = [];
56
+ private startBlobAccumulator: BatchedBlobAccumulator;
57
+ private endBlobAccumulator: BatchedBlobAccumulator | undefined;
58
+ private finalBatchedBlob: BatchedBlob | undefined;
51
59
  private provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
52
60
 
53
- // Map from tx hash to tube proof promise. Used when kickstarting tube proofs before tx processing.
54
- public readonly cachedTubeProofs = new Map<string, Promise<ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>>>();
55
-
56
- public blocks: (BlockProvingState | undefined)[] = [];
61
+ // Map from tx hash to chonk verifier proof promise. Used when kickstarting chonk verifier proofs before tx processing.
62
+ public readonly cachedChonkVerifierProofs = new Map<
63
+ string,
64
+ Promise<
65
+ PublicInputsAndRecursiveProof<PublicChonkVerifierPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
66
+ >
67
+ >();
57
68
 
58
69
  constructor(
59
- public readonly epochNumber: number,
60
- public readonly firstBlockNumber: number,
61
- public readonly totalNumBlocks: number,
70
+ public readonly epochNumber: EpochNumber,
71
+ public readonly totalNumCheckpoints: number,
72
+ private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
73
+ private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
62
74
  private completionCallback: (result: ProvingResult) => void,
63
75
  private rejectionCallback: (reason: string) => void,
64
76
  ) {
65
- this.blockRootOrMergeProvingOutputs = new UnbalancedTreeStore(totalNumBlocks);
77
+ this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
78
+ this.startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(finalBlobBatchingChallenges);
66
79
  }
67
80
 
68
81
  // Adds a block to the proving state, returns its index
69
82
  // Will update the proving life cycle if this is the last block
70
- public startNewBlock(
71
- globalVariables: GlobalVariables,
72
- l1ToL2Messages: Fr[],
73
- l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
74
- l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
75
- lastArchiveSnapshot: AppendOnlyTreeSnapshot,
76
- newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
83
+ public startNewCheckpoint(
84
+ checkpointIndex: number,
85
+ constants: CheckpointConstantData,
86
+ totalNumBlocks: number,
77
87
  previousBlockHeader: BlockHeader,
78
- ): BlockProvingState {
79
- const index = globalVariables.blockNumber.toNumber() - this.firstBlockNumber;
80
- const block = new BlockProvingState(
81
- index,
82
- globalVariables,
83
- l1ToL2Messages,
84
- l1ToL2MessageSubtreeSiblingPath,
85
- l1ToL2MessageTreeSnapshotAfterInsertion,
86
- lastArchiveSnapshot,
87
- newArchiveSiblingPath,
88
+ lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
89
+ l1ToL2Messages: Fr[],
90
+ lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
91
+ lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH>,
92
+ newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
93
+ newL1ToL2MessageSubtreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH>,
94
+ ): CheckpointProvingState {
95
+ if (checkpointIndex >= this.totalNumCheckpoints) {
96
+ throw new Error(
97
+ `Unable to start a new checkpoint at index ${checkpointIndex}. Expected at most ${this.totalNumCheckpoints} checkpoints.`,
98
+ );
99
+ }
100
+
101
+ const checkpoint = new CheckpointProvingState(
102
+ checkpointIndex,
103
+ constants,
104
+ totalNumBlocks,
105
+ this.finalBlobBatchingChallenges,
88
106
  previousBlockHeader,
107
+ lastArchiveSiblingPath,
108
+ l1ToL2Messages,
109
+ lastL1ToL2MessageTreeSnapshot,
110
+ lastL1ToL2MessageSubtreeRootSiblingPath,
111
+ newL1ToL2MessageTreeSnapshot,
112
+ newL1ToL2MessageSubtreeRootSiblingPath,
89
113
  this,
114
+ this.onCheckpointBlobAccumulatorSet,
90
115
  );
91
- this.blocks[index] = block;
92
- if (this.blocks.filter(b => !!b).length === this.totalNumBlocks) {
116
+ this.checkpoints[checkpointIndex] = checkpoint;
117
+
118
+ if (this.checkpoints.filter(c => !!c).length === this.totalNumCheckpoints) {
93
119
  this.provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_FULL;
94
120
  }
95
- return block;
121
+
122
+ return checkpoint;
123
+ }
124
+
125
+ public getCheckpointProvingState(index: number) {
126
+ return this.checkpoints[index];
127
+ }
128
+
129
+ public getCheckpointProvingStateByBlockNumber(blockNumber: number) {
130
+ return this.checkpoints.find(
131
+ c => c && blockNumber >= c.firstBlockNumber && blockNumber < c.firstBlockNumber + c.totalNumBlocks,
132
+ );
133
+ }
134
+
135
+ public getBlockProvingStateByBlockNumber(blockNumber: number) {
136
+ return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
96
137
  }
97
138
 
98
139
  // Returns true if this proving state is still valid, false otherwise
@@ -103,95 +144,146 @@ export class EpochProvingState {
103
144
  );
104
145
  }
105
146
 
106
- // Returns true if we are still able to accept blocks, false otherwise
107
- public isAcceptingBlocks() {
108
- return this.provingStateLifecycle === PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
147
+ // Returns true if we are still able to accept checkpoints, false otherwise.
148
+ public isAcceptingCheckpoints() {
149
+ return this.checkpoints.filter(c => !!c).length < this.totalNumCheckpoints;
109
150
  }
110
151
 
111
- public setBlockRootRollupProof(
112
- blockIndex: number,
113
- proof: PublicInputsAndRecursiveProof<
114
- BlockRootOrBlockMergePublicInputs,
152
+ public setCheckpointRootRollupProof(
153
+ checkpointIndex: number,
154
+ provingOutput: PublicInputsAndRecursiveProof<
155
+ CheckpointRollupPublicInputs,
115
156
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
116
157
  >,
117
158
  ): TreeNodeLocation {
118
- return this.blockRootOrMergeProvingOutputs.setLeaf(blockIndex, proof);
159
+ return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
160
+ }
161
+
162
+ public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
163
+ if (this.checkpointProofs.getNode(location)?.isProving) {
164
+ return false;
165
+ } else {
166
+ this.checkpointProofs.setNode(location, { isProving: true });
167
+ return true;
168
+ }
119
169
  }
120
170
 
121
- public setBlockMergeRollupProof(
171
+ public setCheckpointMergeRollupProof(
122
172
  location: TreeNodeLocation,
123
- proof: PublicInputsAndRecursiveProof<
124
- BlockRootOrBlockMergePublicInputs,
173
+ provingOutput: PublicInputsAndRecursiveProof<
174
+ CheckpointRollupPublicInputs,
125
175
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
126
176
  >,
127
177
  ) {
128
- this.blockRootOrMergeProvingOutputs.setNode(location, proof);
178
+ this.checkpointProofs.setNode(location, { provingOutput });
179
+ }
180
+
181
+ public tryStartProvingRootRollup() {
182
+ if (this.rootRollupProof?.isProving) {
183
+ return false;
184
+ } else {
185
+ this.rootRollupProof = { isProving: true };
186
+ return true;
187
+ }
129
188
  }
130
189
 
131
- public setRootRollupProof(proof: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
132
- this.rootRollupProvingOutput = proof;
190
+ public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
191
+ this.rootRollupProof = { provingOutput };
133
192
  }
134
193
 
135
- public setPaddingBlockRootProof(
136
- proof: PublicInputsAndRecursiveProof<
137
- BlockRootOrBlockMergePublicInputs,
194
+ public tryStartProvingPaddingCheckpoint() {
195
+ if (this.checkpointPaddingProof?.isProving) {
196
+ return false;
197
+ } else {
198
+ this.checkpointPaddingProof = { isProving: true };
199
+ return true;
200
+ }
201
+ }
202
+
203
+ public setCheckpointPaddingProof(
204
+ provingOutput: PublicInputsAndRecursiveProof<
205
+ CheckpointRollupPublicInputs,
138
206
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
139
207
  >,
140
208
  ) {
141
- this.paddingBlockRootProvingOutput = proof;
209
+ this.checkpointPaddingProof = { provingOutput };
210
+ }
211
+
212
+ public async setBlobAccumulators() {
213
+ let previousAccumulator = this.startBlobAccumulator;
214
+ // Accumulate blobs as far as we can for this epoch.
215
+ for (let i = 0; i < this.totalNumCheckpoints; i++) {
216
+ const checkpoint = this.checkpoints[i];
217
+ if (!checkpoint) {
218
+ break;
219
+ }
220
+
221
+ const endAccumulator =
222
+ checkpoint.getEndBlobAccumulator() || (await checkpoint.accumulateBlobs(previousAccumulator));
223
+ if (!endAccumulator) {
224
+ break;
225
+ }
226
+
227
+ previousAccumulator = endAccumulator;
228
+
229
+ // If this is the last checkpoint, set the end blob accumulator.
230
+ if (i === this.totalNumCheckpoints - 1) {
231
+ this.endBlobAccumulator = endAccumulator;
232
+ }
233
+ }
234
+ }
235
+
236
+ public async finalizeBatchedBlob() {
237
+ if (!this.endBlobAccumulator) {
238
+ throw new Error('End blob accumulator not ready.');
239
+ }
240
+ this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
142
241
  }
143
242
 
144
243
  public getParentLocation(location: TreeNodeLocation) {
145
- return this.blockRootOrMergeProvingOutputs.getParentLocation(location);
244
+ return this.checkpointProofs.getParentLocation(location);
146
245
  }
147
246
 
148
- public getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation) {
149
- const [left, right] = this.blockRootOrMergeProvingOutputs.getChildren(mergeLocation);
247
+ public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
248
+ const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
150
249
  if (!left || !right) {
151
- throw new Error('At lease one child is not ready.');
250
+ throw new Error('At least one child is not ready for the checkpoint merge rollup.');
152
251
  }
153
252
 
154
- return new BlockMergeRollupInputs([this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)]);
253
+ return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
155
254
  }
156
255
 
157
- public getRootRollupInputs(proverId: Fr) {
256
+ public getRootRollupInputs() {
158
257
  const [left, right] = this.#getChildProofsForRoot();
159
258
  if (!left || !right) {
160
- throw new Error('At lease one child is not ready.');
259
+ throw new Error('At least one child is not ready for the root rollup.');
161
260
  }
162
261
 
163
- return RootRollupInputs.from({
164
- previousRollupData: [this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)],
165
- proverId,
262
+ return RootRollupPrivateInputs.from({
263
+ previousRollups: [toProofData(left), toProofData(right)],
166
264
  });
167
265
  }
168
266
 
169
- public getPaddingBlockRootInputs(proverId: Fr) {
170
- if (!this.blocks[0]?.isComplete()) {
171
- throw new Error('Epoch needs one completed block in order to be padded.');
172
- }
173
-
174
- return this.blocks[0].getPaddingBlockRootInputs(proverId);
267
+ public getPaddingCheckpointInputs() {
268
+ return new CheckpointPaddingRollupPrivateInputs();
175
269
  }
176
270
 
177
- // Returns a specific transaction proving state
178
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
179
- return this.blocks.find(block => block?.blockNumber === blockNumber);
180
- }
271
+ public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
272
+ const provingOutput = this.rootRollupProof?.provingOutput;
181
273
 
182
- public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs } {
183
- if (!this.rootRollupProvingOutput) {
274
+ if (!provingOutput || !this.finalBatchedBlob) {
184
275
  throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
185
276
  }
186
277
 
187
278
  return {
188
- proof: this.rootRollupProvingOutput.proof.binaryProof,
189
- publicInputs: this.rootRollupProvingOutput.inputs,
279
+ proof: provingOutput.proof.binaryProof,
280
+ publicInputs: provingOutput.inputs,
281
+ batchedBlobInputs: this.finalBatchedBlob,
190
282
  };
191
283
  }
192
284
 
193
- public isReadyForBlockMerge(location: TreeNodeLocation) {
194
- return this.blockRootOrMergeProvingOutputs.getSibling(location) !== undefined;
285
+ public isReadyForCheckpointMerge(location: TreeNodeLocation) {
286
+ return !!this.checkpointProofs.getSibling(location)?.provingOutput;
195
287
  }
196
288
 
197
289
  // Returns true if we have sufficient inputs to execute the block root rollup
@@ -228,25 +320,8 @@ export class EpochProvingState {
228
320
  #getChildProofsForRoot() {
229
321
  const rootLocation = { level: 0, index: 0 };
230
322
  // If there's only 1 block, its block root proof will be stored at the root.
231
- return this.totalNumBlocks === 1
232
- ? [this.blockRootOrMergeProvingOutputs.getNode(rootLocation), this.paddingBlockRootProvingOutput]
233
- : this.blockRootOrMergeProvingOutputs.getChildren(rootLocation);
234
- }
235
-
236
- #getPreviousRollupData({
237
- inputs,
238
- proof,
239
- verificationKey,
240
- }: PublicInputsAndRecursiveProof<
241
- BlockRootOrBlockMergePublicInputs,
242
- typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
243
- >) {
244
- const leafIndex = getVKIndex(verificationKey.keyAsFields);
245
- return new PreviousRollupBlockData(
246
- inputs,
247
- proof,
248
- verificationKey.keyAsFields,
249
- new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)),
250
- );
323
+ return this.totalNumCheckpoints === 1
324
+ ? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
325
+ : this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
251
326
  }
252
327
  }