@aztec/prover-client 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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 (107) hide show
  1. package/dest/bin/get-proof-inputs.js +1 -1
  2. package/dest/block-factory/index.d.ts +2 -0
  3. package/dest/block-factory/index.d.ts.map +1 -0
  4. package/dest/block-factory/light.d.ts +36 -0
  5. package/dest/block-factory/light.d.ts.map +1 -0
  6. package/dest/{block_builder → block-factory}/light.js +35 -30
  7. package/dest/config.d.ts +6 -6
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +11 -1
  10. package/dest/mocks/fixtures.d.ts +3 -3
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +2 -2
  13. package/dest/mocks/test_context.d.ts +18 -13
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +44 -38
  16. package/dest/orchestrator/block-building-helpers.d.ts +18 -11
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +80 -63
  19. package/dest/orchestrator/block-proving-state.d.ts +19 -10
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +63 -46
  22. package/dest/orchestrator/epoch-proving-state.d.ts +13 -6
  23. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/epoch-proving-state.js +40 -14
  25. package/dest/orchestrator/orchestrator.d.ts +7 -5
  26. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  27. package/dest/orchestrator/orchestrator.js +78 -52
  28. package/dest/orchestrator/orchestrator_metrics.d.ts +2 -0
  29. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator_metrics.js +9 -0
  31. package/dest/orchestrator/tx-proving-state.d.ts +2 -2
  32. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  33. package/dest/orchestrator/tx-proving-state.js +9 -20
  34. package/dest/prover-client/prover-client.d.ts +3 -3
  35. package/dest/prover-client/prover-client.d.ts.map +1 -1
  36. package/dest/prover-client/prover-client.js +5 -4
  37. package/dest/prover-client/server-epoch-prover.d.ts +6 -4
  38. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  39. package/dest/prover-client/server-epoch-prover.js +4 -4
  40. package/dest/proving_broker/broker_prover_facade.d.ts +5 -3
  41. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  42. package/dest/proving_broker/broker_prover_facade.js +31 -21
  43. package/dest/proving_broker/config.d.ts +9 -4
  44. package/dest/proving_broker/config.d.ts.map +1 -1
  45. package/dest/proving_broker/config.js +15 -4
  46. package/dest/proving_broker/factory.d.ts +1 -1
  47. package/dest/proving_broker/factory.d.ts.map +1 -1
  48. package/dest/proving_broker/factory.js +5 -1
  49. package/dest/proving_broker/proof_store/factory.js +1 -1
  50. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  51. package/dest/proving_broker/proof_store/gcs_proof_store.js +1 -0
  52. package/dest/proving_broker/proving_agent.d.ts +3 -3
  53. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  54. package/dest/proving_broker/proving_agent.js +83 -47
  55. package/dest/proving_broker/proving_broker.d.ts +11 -2
  56. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  57. package/dest/proving_broker/proving_broker.js +6 -5
  58. package/dest/proving_broker/proving_broker_database/memory.js +1 -1
  59. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  60. package/dest/proving_broker/proving_broker_database/persisted.js +9 -8
  61. package/dest/proving_broker/proving_job_controller.d.ts +7 -8
  62. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  63. package/dest/proving_broker/proving_job_controller.js +53 -45
  64. package/dest/proving_broker/rpc.d.ts +3 -5
  65. package/dest/proving_broker/rpc.d.ts.map +1 -1
  66. package/dest/proving_broker/rpc.js +1 -4
  67. package/dest/test/mock_proof_store.d.ts +9 -0
  68. package/dest/test/mock_proof_store.d.ts.map +1 -0
  69. package/dest/test/mock_proof_store.js +10 -0
  70. package/dest/test/mock_prover.d.ts +7 -5
  71. package/dest/test/mock_prover.d.ts.map +1 -1
  72. package/dest/test/mock_prover.js +6 -3
  73. package/package.json +28 -27
  74. package/src/bin/get-proof-inputs.ts +1 -1
  75. package/src/block-factory/index.ts +1 -0
  76. package/src/{block_builder → block-factory}/light.ts +42 -29
  77. package/src/config.ts +24 -8
  78. package/src/mocks/fixtures.ts +5 -5
  79. package/src/mocks/test_context.ts +79 -59
  80. package/src/orchestrator/block-building-helpers.ts +96 -92
  81. package/src/orchestrator/block-proving-state.ts +78 -52
  82. package/src/orchestrator/epoch-proving-state.ts +51 -20
  83. package/src/orchestrator/orchestrator.ts +119 -60
  84. package/src/orchestrator/orchestrator_metrics.ts +20 -1
  85. package/src/orchestrator/tx-proving-state.ts +17 -24
  86. package/src/prover-client/prover-client.ts +16 -14
  87. package/src/prover-client/server-epoch-prover.ts +16 -7
  88. package/src/proving_broker/broker_prover_facade.ts +52 -36
  89. package/src/proving_broker/config.ts +17 -6
  90. package/src/proving_broker/factory.ts +2 -1
  91. package/src/proving_broker/proof_store/factory.ts +1 -1
  92. package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
  93. package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
  94. package/src/proving_broker/proving_agent.ts +89 -47
  95. package/src/proving_broker/proving_broker.ts +16 -15
  96. package/src/proving_broker/proving_broker_database/memory.ts +1 -1
  97. package/src/proving_broker/proving_broker_database/persisted.ts +9 -8
  98. package/src/proving_broker/proving_job_controller.ts +56 -65
  99. package/src/proving_broker/rpc.ts +1 -6
  100. package/src/test/mock_proof_store.ts +14 -0
  101. package/src/test/mock_prover.ts +27 -5
  102. package/dest/block_builder/index.d.ts +0 -6
  103. package/dest/block_builder/index.d.ts.map +0 -1
  104. package/dest/block_builder/light.d.ts +0 -33
  105. package/dest/block_builder/light.d.ts.map +0 -1
  106. package/src/block_builder/index.ts +0 -6
  107. /package/dest/{block_builder → block-factory}/index.js +0 -0
@@ -1,4 +1,4 @@
1
- import { SpongeBlob } from '@aztec/blob-lib';
1
+ import { BatchedBlobAccumulator, BlobAccumulatorPublicInputs, SpongeBlob } from '@aztec/blob-lib';
2
2
  import {
3
3
  type ARCHIVE_HEIGHT,
4
4
  BLOBS_PER_BLOCK,
@@ -7,35 +7,41 @@ import {
7
7
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
8
8
  NUM_BASE_PARITY_PER_ROOT_PARITY,
9
9
  type RECURSIVE_PROOF_LENGTH,
10
- VK_TREE_HEIGHT,
11
10
  } from '@aztec/constants';
12
11
  import { padArrayEnd } from '@aztec/foundation/collection';
13
- import { Fr } from '@aztec/foundation/fields';
14
- import type { Logger } from '@aztec/foundation/log';
12
+ import { BLS12Point, Fr } from '@aztec/foundation/fields';
15
13
  import type { Tuple } from '@aztec/foundation/serialize';
16
- import { MembershipWitness, type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
14
+ import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
17
15
  import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
18
16
  import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
19
- import type { L2Block } from '@aztec/stdlib/block';
17
+ import type { EthAddress, L2Block } from '@aztec/stdlib/block';
20
18
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
21
19
  import { type ParityPublicInputs, RootParityInput, RootParityInputs } from '@aztec/stdlib/parity';
22
20
  import {
23
21
  type BaseOrMergeRollupPublicInputs,
22
+ BlockConstantData,
24
23
  type BlockRootOrBlockMergePublicInputs,
25
24
  BlockRootRollupBlobData,
26
25
  BlockRootRollupData,
27
26
  BlockRootRollupInputs,
28
- ConstantRollupData,
29
27
  EmptyBlockRootRollupInputs,
28
+ EpochConstantData,
30
29
  MergeRollupInputs,
30
+ PaddingBlockRootRollupInputs,
31
31
  PreviousRollupData,
32
32
  SingleTxBlockRootRollupInputs,
33
33
  } from '@aztec/stdlib/rollup';
34
34
  import type { CircuitName } from '@aztec/stdlib/stats';
35
- import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
35
+ import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
36
36
  import { type BlockHeader, type GlobalVariables, StateReference } from '@aztec/stdlib/tx';
37
+ import { VkData } from '@aztec/stdlib/vks';
37
38
 
38
- import { buildBlobHints, buildHeaderFromCircuitOutputs } from './block-building-helpers.js';
39
+ import {
40
+ accumulateBlobs,
41
+ buildBlobHints,
42
+ buildHeaderFromCircuitOutputs,
43
+ getEmptyBlockBlobsHash,
44
+ } from './block-building-helpers.js';
39
45
  import type { EpochProvingState } from './epoch-proving-state.js';
40
46
  import type { TxProvingState } from './tx-proving-state.js';
41
47
 
@@ -57,6 +63,9 @@ export class BlockProvingState {
57
63
  public blockRootRollupStarted: boolean = false;
58
64
  public block: L2Block | undefined;
59
65
  public spongeBlobState: SpongeBlob | undefined;
66
+ public startBlobAccumulator: BatchedBlobAccumulator | undefined;
67
+ public endBlobAccumulator: BatchedBlobAccumulator | undefined;
68
+ public blobsHash: Fr | undefined;
60
69
  public totalNumTxs: number;
61
70
  private txs: TxProvingState[] = [];
62
71
  public error: string | undefined;
@@ -65,19 +74,25 @@ export class BlockProvingState {
65
74
  public readonly index: number,
66
75
  public readonly globalVariables: GlobalVariables,
67
76
  public readonly newL1ToL2Messages: Fr[],
77
+ public readonly l1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
68
78
  private readonly l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
69
- private readonly l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
79
+ public readonly l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
70
80
  private readonly lastArchiveSnapshot: AppendOnlyTreeSnapshot,
81
+ private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
71
82
  private readonly newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
72
83
  private readonly previousBlockHeader: BlockHeader,
84
+ private readonly proverId: EthAddress,
73
85
  private readonly parentEpoch: EpochProvingState,
74
86
  ) {
75
87
  this.baseParityProvingOutputs = Array.from({ length: NUM_BASE_PARITY_PER_ROOT_PARITY }).map(_ => undefined);
76
88
  this.totalNumTxs = 0;
89
+ if (this.blockNumber == parentEpoch.firstBlockNumber) {
90
+ this.startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(parentEpoch.finalBlobBatchingChallenges);
91
+ }
77
92
  }
78
93
 
79
94
  public get blockNumber() {
80
- return this.globalVariables.blockNumber.toNumber();
95
+ return this.globalVariables.blockNumber;
81
96
  }
82
97
 
83
98
  public startNewBlock(numTxs: number, numBlobFields: number) {
@@ -86,7 +101,7 @@ export class BlockProvingState {
86
101
  }
87
102
 
88
103
  this.baseOrMergeProvingOutputs = new UnbalancedTreeStore(numTxs);
89
- // Initialise the sponge which will eventually absorb all tx effects to be added to the blob.
104
+ // Initialize the sponge which will eventually absorb all tx effects to be added to the blob.
90
105
  // Like l1 to l2 messages, we need to know beforehand how many effects will be absorbed.
91
106
  this.spongeBlobState = SpongeBlob.init(numBlobFields);
92
107
  this.totalNumTxs = numTxs;
@@ -97,7 +112,6 @@ export class BlockProvingState {
97
112
  if (!this.spongeBlobState) {
98
113
  throw new Error(`Invalid block proving state, call startNewBlock before adding transactions.`);
99
114
  }
100
-
101
115
  const txIndex = this.txs.length;
102
116
  this.txs[txIndex] = tx;
103
117
  return txIndex;
@@ -146,6 +160,30 @@ export class BlockProvingState {
146
160
  this.blockRootProvingOutput = provingOutput;
147
161
  }
148
162
 
163
+ public setBlock(block: L2Block) {
164
+ this.block = block;
165
+ }
166
+
167
+ public setStartBlobAccumulator(accumulator: BatchedBlobAccumulator) {
168
+ this.startBlobAccumulator = accumulator;
169
+ }
170
+
171
+ public setEndBlobAccumulator(accumulator: BatchedBlobAccumulator) {
172
+ this.endBlobAccumulator = accumulator;
173
+ }
174
+
175
+ public async accumulateBlobs() {
176
+ if (!this.block || !this.startBlobAccumulator) {
177
+ // We only want to accumulate once we have all txs, so we wait until the block is set.
178
+ return;
179
+ }
180
+ const endBlobAccumulator = await accumulateBlobs(
181
+ this.allTxs.map(t => t.processedTx),
182
+ this.startBlobAccumulator,
183
+ );
184
+ this.setEndBlobAccumulator(endBlobAccumulator);
185
+ }
186
+
149
187
  // Returns the complete set of transaction proving state objects
150
188
  public get allTxs() {
151
189
  return this.txs;
@@ -169,7 +207,7 @@ export class BlockProvingState {
169
207
  return new MergeRollupInputs([this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)]);
170
208
  }
171
209
 
172
- public async getBlockRootRollupTypeAndInputs(proverId: Fr) {
210
+ public async getBlockRootRollupTypeAndInputs() {
173
211
  if (!this.rootParityProvingOutput) {
174
212
  throw new Error('Root parity is not ready.');
175
213
  }
@@ -180,28 +218,31 @@ export class BlockProvingState {
180
218
  throw new Error('At lease one child is not ready for the block root.');
181
219
  }
182
220
 
183
- const data = this.#getBlockRootRollupData(proverId);
221
+ const data = this.#getBlockRootRollupData();
184
222
 
185
223
  if (this.totalNumTxs === 0) {
186
- const constants = ConstantRollupData.from({
224
+ const constants = BlockConstantData.from({
187
225
  lastArchive: this.lastArchiveSnapshot,
226
+ newL1ToL2: this.l1ToL2MessageTreeSnapshotAfterInsertion,
188
227
  globalVariables: this.globalVariables,
189
228
  vkTreeRoot: getVKTreeRoot(),
190
229
  protocolContractTreeRoot,
191
230
  });
192
231
 
232
+ this.blobsHash = await getEmptyBlockBlobsHash();
233
+
193
234
  return {
194
235
  rollupType: 'empty-block-root-rollup' satisfies CircuitName,
195
236
  inputs: EmptyBlockRootRollupInputs.from({
196
237
  data,
197
238
  constants,
198
- isPadding: false,
199
239
  }),
200
240
  };
201
241
  }
202
242
 
203
243
  const previousRollupData = await Promise.all(nonEmptyProofs.map(p => this.#getPreviousRollupData(p!)));
204
244
  const blobData = await this.#getBlockRootRollupBlobData();
245
+ this.blobsHash = blobData.blobsHash;
205
246
 
206
247
  if (previousRollupData.length === 1) {
207
248
  return {
@@ -220,34 +261,15 @@ export class BlockProvingState {
220
261
  }
221
262
  }
222
263
 
223
- public async getPaddingBlockRootInputs(proverId: Fr) {
224
- if (!this.rootParityProvingOutput) {
225
- throw new Error('Root parity is not ready.');
226
- }
227
-
228
- // Use the new block header and archive of the current block as the previous header and archiver of the next padding block.
229
- const newBlockHeader = await this.buildHeaderFromProvingOutputs();
230
- const newArchive = this.blockRootProvingOutput!.inputs.newArchive;
231
-
232
- const data = BlockRootRollupData.from({
233
- l1ToL2Roots: this.#getRootParityData(this.rootParityProvingOutput!),
234
- l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
235
- newArchiveSiblingPath: this.newArchiveSiblingPath,
236
- previousBlockHeader: newBlockHeader,
237
- proverId,
238
- });
239
-
240
- const constants = ConstantRollupData.from({
241
- lastArchive: newArchive,
242
- globalVariables: this.globalVariables,
264
+ public getPaddingBlockRootInputs() {
265
+ const constants = EpochConstantData.from({
243
266
  vkTreeRoot: getVKTreeRoot(),
244
267
  protocolContractTreeRoot,
268
+ proverId: this.proverId.toField(),
245
269
  });
246
270
 
247
- return EmptyBlockRootRollupInputs.from({
248
- data,
271
+ return PaddingBlockRootRollupInputs.from({
249
272
  constants,
250
- isPadding: true,
251
273
  });
252
274
  }
253
275
 
@@ -267,7 +289,7 @@ export class BlockProvingState {
267
289
  return this.txs[txIndex];
268
290
  }
269
291
 
270
- public async buildHeaderFromProvingOutputs(logger?: Logger) {
292
+ public async buildHeaderFromProvingOutputs() {
271
293
  const previousRollupData =
272
294
  this.totalNumTxs === 0
273
295
  ? []
@@ -288,8 +310,8 @@ export class BlockProvingState {
288
310
  previousRollupData.map(d => d.baseOrMergeRollupPublicInputs),
289
311
  this.rootParityProvingOutput!.inputs,
290
312
  this.blockRootProvingOutput!.inputs,
313
+ this.blobsHash!,
291
314
  endState,
292
- logger,
293
315
  );
294
316
  }
295
317
 
@@ -300,7 +322,12 @@ export class BlockProvingState {
300
322
  // Returns true if we have sufficient inputs to execute the block root rollup
301
323
  public isReadyForBlockRootRollup() {
302
324
  const childProofs = this.#getChildProofsForBlockRoot();
303
- return this.block !== undefined && this.rootParityProvingOutput !== undefined && childProofs.every(p => !!p);
325
+ return (
326
+ this.block !== undefined &&
327
+ this.rootParityProvingOutput !== undefined &&
328
+ this.endBlobAccumulator !== undefined &&
329
+ childProofs.every(p => !!p)
330
+ );
304
331
  }
305
332
 
306
333
  // Returns true if we have sufficient root parity inputs to execute the root parity circuit
@@ -322,13 +349,16 @@ export class BlockProvingState {
322
349
  this.parentEpoch.reject(reason);
323
350
  }
324
351
 
325
- #getBlockRootRollupData(proverId: Fr) {
352
+ #getBlockRootRollupData() {
326
353
  return BlockRootRollupData.from({
327
354
  l1ToL2Roots: this.#getRootParityData(this.rootParityProvingOutput!),
328
355
  l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
356
+ previousArchiveSiblingPath: this.lastArchiveSiblingPath,
329
357
  newArchiveSiblingPath: this.newArchiveSiblingPath,
330
358
  previousBlockHeader: this.previousBlockHeader,
331
- proverId,
359
+ startBlobAccumulator: BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(this.startBlobAccumulator!),
360
+ finalBlobChallenges: this.startBlobAccumulator!.finalBlobChallenges,
361
+ proverId: this.proverId.toField(),
332
362
  });
333
363
  }
334
364
 
@@ -337,7 +367,7 @@ export class BlockProvingState {
337
367
  const { blobFields, blobCommitments, blobsHash } = await buildBlobHints(txEffects);
338
368
  return BlockRootRollupBlobData.from({
339
369
  blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
340
- blobCommitments: padArrayEnd(blobCommitments, [Fr.ZERO, Fr.ZERO], BLOBS_PER_BLOCK),
370
+ blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_BLOCK),
341
371
  blobsHash,
342
372
  });
343
373
  }
@@ -360,12 +390,8 @@ export class BlockProvingState {
360
390
  verificationKey,
361
391
  }: PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>) {
362
392
  const leafIndex = getVKIndex(verificationKey.keyAsFields);
363
- return new PreviousRollupData(
364
- inputs,
365
- proof,
366
- verificationKey.keyAsFields,
367
- new MembershipWitness(VK_TREE_HEIGHT, BigInt(leafIndex), getVKSiblingPath(leafIndex)),
368
- );
393
+ const vkData = new VkData(verificationKey, leafIndex, getVKSiblingPath(leafIndex));
394
+ return new PreviousRollupData(inputs, proof, vkData);
369
395
  }
370
396
 
371
397
  #getRootParityData({ inputs, proof, verificationKey }: PublicInputsAndRecursiveProof<ParityPublicInputs>) {
@@ -1,13 +1,14 @@
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, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
+ import type {
3
+ ARCHIVE_HEIGHT,
4
+ L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
5
+ NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
6
+ TUBE_PROOF_LENGTH,
7
7
  } from '@aztec/constants';
8
+ import type { EthAddress } from '@aztec/foundation/eth-address';
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 { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
11
12
  import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
12
13
  import type { ProofAndVerificationKey, PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
13
14
  import type { Proof } from '@aztec/stdlib/proofs';
@@ -20,6 +21,7 @@ import {
20
21
  } from '@aztec/stdlib/rollup';
21
22
  import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
22
23
  import type { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
24
+ import { VkData } from '@aztec/stdlib/vks';
23
25
 
24
26
  import { BlockProvingState } from './block-proving-state.js';
25
27
 
@@ -48,6 +50,7 @@ export class EpochProvingState {
48
50
  | PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
49
51
  | undefined;
50
52
  private rootRollupProvingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs> | undefined;
53
+ private finalBatchedBlob: BatchedBlob | undefined;
51
54
  private provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
52
55
 
53
56
  // Map from tx hash to tube proof promise. Used when kickstarting tube proofs before tx processing.
@@ -59,6 +62,7 @@ export class EpochProvingState {
59
62
  public readonly epochNumber: number,
60
63
  public readonly firstBlockNumber: number,
61
64
  public readonly totalNumBlocks: number,
65
+ public readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
62
66
  private completionCallback: (result: ProvingResult) => void,
63
67
  private rejectionCallback: (reason: string) => void,
64
68
  ) {
@@ -70,22 +74,28 @@ export class EpochProvingState {
70
74
  public startNewBlock(
71
75
  globalVariables: GlobalVariables,
72
76
  l1ToL2Messages: Fr[],
77
+ l1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
73
78
  l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
74
79
  l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
75
80
  lastArchiveSnapshot: AppendOnlyTreeSnapshot,
81
+ lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
76
82
  newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
77
83
  previousBlockHeader: BlockHeader,
84
+ proverId: EthAddress,
78
85
  ): BlockProvingState {
79
- const index = globalVariables.blockNumber.toNumber() - this.firstBlockNumber;
86
+ const index = globalVariables.blockNumber - this.firstBlockNumber;
80
87
  const block = new BlockProvingState(
81
88
  index,
82
89
  globalVariables,
83
90
  l1ToL2Messages,
91
+ l1ToL2MessageTreeSnapshot,
84
92
  l1ToL2MessageSubtreeSiblingPath,
85
93
  l1ToL2MessageTreeSnapshotAfterInsertion,
86
94
  lastArchiveSnapshot,
95
+ lastArchiveSiblingPath,
87
96
  newArchiveSiblingPath,
88
97
  previousBlockHeader,
98
+ proverId,
89
99
  this,
90
100
  );
91
101
  this.blocks[index] = block;
@@ -141,6 +151,31 @@ export class EpochProvingState {
141
151
  this.paddingBlockRootProvingOutput = proof;
142
152
  }
143
153
 
154
+ public setFinalBatchedBlob(batchedBlob: BatchedBlob) {
155
+ this.finalBatchedBlob = batchedBlob;
156
+ }
157
+
158
+ public async setBlobAccumulators(toBlock?: number) {
159
+ let previousAccumulator;
160
+ const end = toBlock ? toBlock - this.firstBlockNumber : this.blocks.length;
161
+ // Accumulate blobs as far as we can for this epoch.
162
+ for (let i = 0; i <= end; i++) {
163
+ const block = this.blocks[i];
164
+ if (!block || !block.block) {
165
+ // If the block proving state does not have a .block property, it may be awaiting more txs.
166
+ break;
167
+ }
168
+ if (!block.startBlobAccumulator) {
169
+ // startBlobAccumulator always exists for firstBlockNumber, so the below should never assign an undefined:
170
+ block.setStartBlobAccumulator(previousAccumulator!);
171
+ }
172
+ if (block.startBlobAccumulator && !block.endBlobAccumulator) {
173
+ await block.accumulateBlobs();
174
+ }
175
+ previousAccumulator = block.endBlobAccumulator;
176
+ }
177
+ }
178
+
144
179
  public getParentLocation(location: TreeNodeLocation) {
145
180
  return this.blockRootOrMergeProvingOutputs.getParentLocation(location);
146
181
  }
@@ -154,7 +189,7 @@ export class EpochProvingState {
154
189
  return new BlockMergeRollupInputs([this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)]);
155
190
  }
156
191
 
157
- public getRootRollupInputs(proverId: Fr) {
192
+ public getRootRollupInputs() {
158
193
  const [left, right] = this.#getChildProofsForRoot();
159
194
  if (!left || !right) {
160
195
  throw new Error('At lease one child is not ready.');
@@ -162,16 +197,15 @@ export class EpochProvingState {
162
197
 
163
198
  return RootRollupInputs.from({
164
199
  previousRollupData: [this.#getPreviousRollupData(left), this.#getPreviousRollupData(right)],
165
- proverId,
166
200
  });
167
201
  }
168
202
 
169
- public getPaddingBlockRootInputs(proverId: Fr) {
203
+ public getPaddingBlockRootInputs() {
170
204
  if (!this.blocks[0]?.isComplete()) {
171
205
  throw new Error('Epoch needs one completed block in order to be padded.');
172
206
  }
173
207
 
174
- return this.blocks[0].getPaddingBlockRootInputs(proverId);
208
+ return this.blocks[0].getPaddingBlockRootInputs();
175
209
  }
176
210
 
177
211
  // Returns a specific transaction proving state
@@ -179,14 +213,15 @@ export class EpochProvingState {
179
213
  return this.blocks.find(block => block?.blockNumber === blockNumber);
180
214
  }
181
215
 
182
- public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs } {
183
- if (!this.rootRollupProvingOutput) {
216
+ public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
217
+ if (!this.rootRollupProvingOutput || !this.finalBatchedBlob) {
184
218
  throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
185
219
  }
186
220
 
187
221
  return {
188
222
  proof: this.rootRollupProvingOutput.proof.binaryProof,
189
223
  publicInputs: this.rootRollupProvingOutput.inputs,
224
+ batchedBlobInputs: this.finalBatchedBlob,
190
225
  };
191
226
  }
192
227
 
@@ -242,11 +277,7 @@ export class EpochProvingState {
242
277
  typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
243
278
  >) {
244
279
  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
- );
280
+ const vkData = new VkData(verificationKey, leafIndex, getVKSiblingPath(leafIndex));
281
+ return new PreviousRollupBlockData(inputs, proof, vkData);
251
282
  }
252
283
  }