@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.001888fc

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