@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 (149) 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 +8 -8
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +12 -2
  9. package/dest/index.d.ts +1 -1
  10. package/dest/light/index.d.ts +2 -0
  11. package/dest/light/index.d.ts.map +1 -0
  12. package/dest/light/index.js +1 -0
  13. package/dest/light/lightweight_checkpoint_builder.d.ts +36 -0
  14. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  15. package/dest/light/lightweight_checkpoint_builder.js +147 -0
  16. package/dest/mocks/fixtures.d.ts +8 -8
  17. package/dest/mocks/fixtures.d.ts.map +1 -1
  18. package/dest/mocks/fixtures.js +34 -16
  19. package/dest/mocks/test_context.d.ts +41 -32
  20. package/dest/mocks/test_context.d.ts.map +1 -1
  21. package/dest/mocks/test_context.js +138 -87
  22. package/dest/orchestrator/block-building-helpers.d.ts +37 -30
  23. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  24. package/dest/orchestrator/block-building-helpers.js +170 -189
  25. package/dest/orchestrator/block-proving-state.d.ts +70 -48
  26. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/block-proving-state.js +282 -177
  28. package/dest/orchestrator/checkpoint-proving-state.d.ts +63 -0
  29. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  30. package/dest/orchestrator/checkpoint-proving-state.js +210 -0
  31. package/dest/orchestrator/epoch-proving-state.d.ts +41 -27
  32. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  33. package/dest/orchestrator/epoch-proving-state.js +143 -73
  34. package/dest/orchestrator/index.d.ts +1 -1
  35. package/dest/orchestrator/orchestrator.d.ts +36 -33
  36. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  37. package/dest/orchestrator/orchestrator.js +379 -250
  38. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
  39. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  40. package/dest/orchestrator/tx-proving-state.d.ts +13 -11
  41. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  42. package/dest/orchestrator/tx-proving-state.js +23 -40
  43. package/dest/prover-client/factory.d.ts +1 -1
  44. package/dest/prover-client/index.d.ts +1 -1
  45. package/dest/prover-client/prover-client.d.ts +4 -4
  46. package/dest/prover-client/prover-client.d.ts.map +1 -1
  47. package/dest/prover-client/prover-client.js +5 -4
  48. package/dest/prover-client/server-epoch-prover.d.ts +16 -12
  49. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  50. package/dest/prover-client/server-epoch-prover.js +11 -11
  51. package/dest/proving_broker/broker_prover_facade.d.ts +23 -16
  52. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  53. package/dest/proving_broker/broker_prover_facade.js +59 -40
  54. package/dest/proving_broker/config.d.ts +19 -10
  55. package/dest/proving_broker/config.d.ts.map +1 -1
  56. package/dest/proving_broker/config.js +23 -6
  57. package/dest/proving_broker/factory.d.ts +2 -2
  58. package/dest/proving_broker/factory.d.ts.map +1 -1
  59. package/dest/proving_broker/factory.js +5 -1
  60. package/dest/proving_broker/fixtures.d.ts +3 -2
  61. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  62. package/dest/proving_broker/fixtures.js +3 -2
  63. package/dest/proving_broker/index.d.ts +1 -1
  64. package/dest/proving_broker/proof_store/factory.d.ts +2 -2
  65. package/dest/proving_broker/proof_store/factory.js +1 -1
  66. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
  67. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  68. package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
  69. package/dest/proving_broker/proof_store/index.d.ts +2 -1
  70. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  71. package/dest/proving_broker/proof_store/index.js +1 -0
  72. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  73. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  74. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  75. package/dest/proving_broker/proving_agent.d.ts +4 -4
  76. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  77. package/dest/proving_broker/proving_agent.js +83 -47
  78. package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
  79. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
  80. package/dest/proving_broker/proving_broker.d.ts +13 -4
  81. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  82. package/dest/proving_broker/proving_broker.js +39 -23
  83. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  84. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  85. package/dest/proving_broker/proving_broker_database/memory.js +1 -1
  86. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  87. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  88. package/dest/proving_broker/proving_broker_database/persisted.js +12 -10
  89. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  90. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  91. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  92. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  93. package/dest/proving_broker/proving_job_controller.d.ts +9 -9
  94. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  95. package/dest/proving_broker/proving_job_controller.js +87 -60
  96. package/dest/proving_broker/rpc.d.ts +4 -6
  97. package/dest/proving_broker/rpc.d.ts.map +1 -1
  98. package/dest/proving_broker/rpc.js +1 -4
  99. package/dest/test/mock_proof_store.d.ts +9 -0
  100. package/dest/test/mock_proof_store.d.ts.map +1 -0
  101. package/dest/test/mock_proof_store.js +10 -0
  102. package/dest/test/mock_prover.d.ts +23 -17
  103. package/dest/test/mock_prover.d.ts.map +1 -1
  104. package/dest/test/mock_prover.js +37 -19
  105. package/package.json +34 -31
  106. package/src/block-factory/index.ts +1 -0
  107. package/src/block-factory/light.ts +137 -0
  108. package/src/config.ts +25 -9
  109. package/src/light/index.ts +1 -0
  110. package/src/light/lightweight_checkpoint_builder.ts +198 -0
  111. package/src/mocks/fixtures.ts +44 -39
  112. package/src/mocks/test_context.ts +213 -116
  113. package/src/orchestrator/block-building-helpers.ts +258 -334
  114. package/src/orchestrator/block-proving-state.ts +325 -231
  115. package/src/orchestrator/checkpoint-proving-state.ts +303 -0
  116. package/src/orchestrator/epoch-proving-state.ts +191 -113
  117. package/src/orchestrator/orchestrator.ts +582 -314
  118. package/src/orchestrator/tx-proving-state.ts +49 -64
  119. package/src/prover-client/prover-client.ts +16 -14
  120. package/src/prover-client/server-epoch-prover.ts +40 -22
  121. package/src/proving_broker/broker_prover_facade.ts +205 -126
  122. package/src/proving_broker/config.ts +25 -7
  123. package/src/proving_broker/factory.ts +2 -1
  124. package/src/proving_broker/fixtures.ts +8 -3
  125. package/src/proving_broker/proof_store/factory.ts +1 -1
  126. package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
  127. package/src/proving_broker/proof_store/index.ts +1 -0
  128. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  129. package/src/proving_broker/proving_agent.ts +89 -47
  130. package/src/proving_broker/proving_broker.ts +56 -33
  131. package/src/proving_broker/proving_broker_database/memory.ts +3 -2
  132. package/src/proving_broker/proving_broker_database/persisted.ts +14 -12
  133. package/src/proving_broker/proving_broker_database.ts +2 -1
  134. package/src/proving_broker/proving_job_controller.ts +92 -81
  135. package/src/proving_broker/rpc.ts +1 -6
  136. package/src/test/mock_proof_store.ts +14 -0
  137. package/src/test/mock_prover.ts +158 -59
  138. package/dest/bin/get-proof-inputs.d.ts +0 -2
  139. package/dest/bin/get-proof-inputs.d.ts.map +0 -1
  140. package/dest/bin/get-proof-inputs.js +0 -51
  141. package/dest/block_builder/index.d.ts +0 -6
  142. package/dest/block_builder/index.d.ts.map +0 -1
  143. package/dest/block_builder/light.d.ts +0 -33
  144. package/dest/block_builder/light.d.ts.map +0 -1
  145. package/dest/block_builder/light.js +0 -82
  146. package/src/bin/get-proof-inputs.ts +0 -59
  147. package/src/block_builder/index.ts +0 -6
  148. package/src/block_builder/light.ts +0 -101
  149. /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 type { Fr } from '@aztec/foundation/fields';
8
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
9
+ import type { Fr } from '@aztec/foundation/curves/bn254';
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,98 @@ 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: BlockNumber) {
130
+ return this.checkpoints.find(
131
+ c =>
132
+ c &&
133
+ Number(blockNumber) >= Number(c.firstBlockNumber) &&
134
+ Number(blockNumber) < Number(c.firstBlockNumber) + c.totalNumBlocks,
135
+ );
136
+ }
137
+
138
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
139
+ return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
96
140
  }
97
141
 
98
142
  // Returns true if this proving state is still valid, false otherwise
@@ -103,95 +147,146 @@ export class EpochProvingState {
103
147
  );
104
148
  }
105
149
 
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;
150
+ // Returns true if we are still able to accept checkpoints, false otherwise.
151
+ public isAcceptingCheckpoints() {
152
+ return this.checkpoints.filter(c => !!c).length < this.totalNumCheckpoints;
109
153
  }
110
154
 
111
- public setBlockRootRollupProof(
112
- blockIndex: number,
113
- proof: PublicInputsAndRecursiveProof<
114
- BlockRootOrBlockMergePublicInputs,
155
+ public setCheckpointRootRollupProof(
156
+ checkpointIndex: number,
157
+ provingOutput: PublicInputsAndRecursiveProof<
158
+ CheckpointRollupPublicInputs,
115
159
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
116
160
  >,
117
161
  ): TreeNodeLocation {
118
- return this.blockRootOrMergeProvingOutputs.setLeaf(blockIndex, proof);
162
+ return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
163
+ }
164
+
165
+ public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
166
+ if (this.checkpointProofs.getNode(location)?.isProving) {
167
+ return false;
168
+ } else {
169
+ this.checkpointProofs.setNode(location, { isProving: true });
170
+ return true;
171
+ }
119
172
  }
120
173
 
121
- public setBlockMergeRollupProof(
174
+ public setCheckpointMergeRollupProof(
122
175
  location: TreeNodeLocation,
123
- proof: PublicInputsAndRecursiveProof<
124
- BlockRootOrBlockMergePublicInputs,
176
+ provingOutput: PublicInputsAndRecursiveProof<
177
+ CheckpointRollupPublicInputs,
125
178
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
126
179
  >,
127
180
  ) {
128
- this.blockRootOrMergeProvingOutputs.setNode(location, proof);
181
+ this.checkpointProofs.setNode(location, { provingOutput });
182
+ }
183
+
184
+ public tryStartProvingRootRollup() {
185
+ if (this.rootRollupProof?.isProving) {
186
+ return false;
187
+ } else {
188
+ this.rootRollupProof = { isProving: true };
189
+ return true;
190
+ }
129
191
  }
130
192
 
131
- public setRootRollupProof(proof: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
132
- this.rootRollupProvingOutput = proof;
193
+ public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
194
+ this.rootRollupProof = { provingOutput };
133
195
  }
134
196
 
135
- public setPaddingBlockRootProof(
136
- proof: PublicInputsAndRecursiveProof<
137
- BlockRootOrBlockMergePublicInputs,
197
+ public tryStartProvingPaddingCheckpoint() {
198
+ if (this.checkpointPaddingProof?.isProving) {
199
+ return false;
200
+ } else {
201
+ this.checkpointPaddingProof = { isProving: true };
202
+ return true;
203
+ }
204
+ }
205
+
206
+ public setCheckpointPaddingProof(
207
+ provingOutput: PublicInputsAndRecursiveProof<
208
+ CheckpointRollupPublicInputs,
138
209
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
139
210
  >,
140
211
  ) {
141
- this.paddingBlockRootProvingOutput = proof;
212
+ this.checkpointPaddingProof = { provingOutput };
213
+ }
214
+
215
+ public async setBlobAccumulators() {
216
+ let previousAccumulator = this.startBlobAccumulator;
217
+ // Accumulate blobs as far as we can for this epoch.
218
+ for (let i = 0; i < this.totalNumCheckpoints; i++) {
219
+ const checkpoint = this.checkpoints[i];
220
+ if (!checkpoint) {
221
+ break;
222
+ }
223
+
224
+ const endAccumulator =
225
+ checkpoint.getEndBlobAccumulator() || (await checkpoint.accumulateBlobs(previousAccumulator));
226
+ if (!endAccumulator) {
227
+ break;
228
+ }
229
+
230
+ previousAccumulator = endAccumulator;
231
+
232
+ // If this is the last checkpoint, set the end blob accumulator.
233
+ if (i === this.totalNumCheckpoints - 1) {
234
+ this.endBlobAccumulator = endAccumulator;
235
+ }
236
+ }
237
+ }
238
+
239
+ public async finalizeBatchedBlob() {
240
+ if (!this.endBlobAccumulator) {
241
+ throw new Error('End blob accumulator not ready.');
242
+ }
243
+ this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
142
244
  }
143
245
 
144
246
  public getParentLocation(location: TreeNodeLocation) {
145
- return this.blockRootOrMergeProvingOutputs.getParentLocation(location);
247
+ return this.checkpointProofs.getParentLocation(location);
146
248
  }
147
249
 
148
- public getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation) {
149
- const [left, right] = this.blockRootOrMergeProvingOutputs.getChildren(mergeLocation);
250
+ public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
251
+ const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
150
252
  if (!left || !right) {
151
- throw new Error('At lease one child is not ready.');
253
+ throw new Error('At least one child is not ready for the checkpoint merge rollup.');
152
254
  }
153
255
 
154
- return new BlockMergeRollupInputs([this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)]);
256
+ return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
155
257
  }
156
258
 
157
- public getRootRollupInputs(proverId: Fr) {
259
+ public getRootRollupInputs() {
158
260
  const [left, right] = this.#getChildProofsForRoot();
159
261
  if (!left || !right) {
160
- throw new Error('At lease one child is not ready.');
262
+ throw new Error('At least one child is not ready for the root rollup.');
161
263
  }
162
264
 
163
- return RootRollupInputs.from({
164
- previousRollupData: [this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)],
165
- proverId,
265
+ return RootRollupPrivateInputs.from({
266
+ previousRollups: [toProofData(left), toProofData(right)],
166
267
  });
167
268
  }
168
269
 
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);
270
+ public getPaddingCheckpointInputs() {
271
+ return new CheckpointPaddingRollupPrivateInputs();
175
272
  }
176
273
 
177
- // Returns a specific transaction proving state
178
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
179
- return this.blocks.find(block => block?.blockNumber === blockNumber);
180
- }
274
+ public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
275
+ const provingOutput = this.rootRollupProof?.provingOutput;
181
276
 
182
- public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs } {
183
- if (!this.rootRollupProvingOutput) {
277
+ if (!provingOutput || !this.finalBatchedBlob) {
184
278
  throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
185
279
  }
186
280
 
187
281
  return {
188
- proof: this.rootRollupProvingOutput.proof.binaryProof,
189
- publicInputs: this.rootRollupProvingOutput.inputs,
282
+ proof: provingOutput.proof.binaryProof,
283
+ publicInputs: provingOutput.inputs,
284
+ batchedBlobInputs: this.finalBatchedBlob,
190
285
  };
191
286
  }
192
287
 
193
- public isReadyForBlockMerge(location: TreeNodeLocation) {
194
- return this.blockRootOrMergeProvingOutputs.getSibling(location) !== undefined;
288
+ public isReadyForCheckpointMerge(location: TreeNodeLocation) {
289
+ return !!this.checkpointProofs.getSibling(location)?.provingOutput;
195
290
  }
196
291
 
197
292
  // Returns true if we have sufficient inputs to execute the block root rollup
@@ -228,25 +323,8 @@ export class EpochProvingState {
228
323
  #getChildProofsForRoot() {
229
324
  const rootLocation = { level: 0, index: 0 };
230
325
  // 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
- );
326
+ return this.totalNumCheckpoints === 1
327
+ ? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
328
+ : this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
251
329
  }
252
330
  }