@aztec/prover-client 0.66.0 → 0.67.1-devnet

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 (83) hide show
  1. package/dest/block_builder/light.d.ts +4 -3
  2. package/dest/block_builder/light.d.ts.map +1 -1
  3. package/dest/block_builder/light.js +30 -20
  4. package/dest/index.d.ts +0 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +1 -2
  7. package/dest/mocks/fixtures.d.ts +3 -3
  8. package/dest/mocks/fixtures.d.ts.map +1 -1
  9. package/dest/mocks/fixtures.js +2 -2
  10. package/dest/mocks/test_context.d.ts +10 -9
  11. package/dest/mocks/test_context.d.ts.map +1 -1
  12. package/dest/mocks/test_context.js +24 -13
  13. package/dest/orchestrator/block-building-helpers.d.ts +10 -6
  14. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  15. package/dest/orchestrator/block-building-helpers.js +27 -16
  16. package/dest/orchestrator/block-proving-state.d.ts +6 -5
  17. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  18. package/dest/orchestrator/block-proving-state.js +16 -8
  19. package/dest/orchestrator/epoch-proving-state.d.ts +1 -1
  20. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/epoch-proving-state.js +3 -3
  22. package/dest/orchestrator/orchestrator.d.ts +11 -8
  23. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  24. package/dest/orchestrator/orchestrator.js +94 -58
  25. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  26. package/dest/orchestrator/orchestrator_metrics.js +2 -5
  27. package/dest/prover-agent/memory-proving-queue.d.ts +2 -1
  28. package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
  29. package/dest/prover-agent/memory-proving-queue.js +241 -224
  30. package/dest/prover-agent/prover-agent.d.ts +11 -2
  31. package/dest/prover-agent/prover-agent.d.ts.map +1 -1
  32. package/dest/prover-agent/prover-agent.js +187 -160
  33. package/dest/prover-client/prover-client.d.ts +2 -3
  34. package/dest/prover-client/prover-client.d.ts.map +1 -1
  35. package/dest/prover-client/prover-client.js +6 -9
  36. package/dest/proving_broker/broker_prover_facade.d.ts +26 -0
  37. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -0
  38. package/dest/proving_broker/broker_prover_facade.js +107 -0
  39. package/dest/proving_broker/proving_agent.d.ts +4 -3
  40. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  41. package/dest/proving_broker/proving_agent.js +74 -65
  42. package/dest/proving_broker/proving_broker.d.ts +27 -7
  43. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  44. package/dest/proving_broker/proving_broker.js +405 -258
  45. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  46. package/dest/proving_broker/proving_broker_database/persisted.js +4 -8
  47. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  48. package/dest/proving_broker/proving_broker_instrumentation.js +2 -8
  49. package/dest/proving_broker/proving_job_controller.d.ts +2 -1
  50. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  51. package/dest/proving_broker/proving_job_controller.js +15 -14
  52. package/dest/proving_broker/rpc.js +2 -2
  53. package/dest/test/mock_prover.d.ts +6 -6
  54. package/dest/test/mock_prover.d.ts.map +1 -1
  55. package/dest/test/mock_prover.js +5 -5
  56. package/package.json +18 -13
  57. package/src/block_builder/light.ts +31 -22
  58. package/src/index.ts +0 -1
  59. package/src/mocks/fixtures.ts +4 -4
  60. package/src/mocks/test_context.ts +39 -24
  61. package/src/orchestrator/block-building-helpers.ts +33 -20
  62. package/src/orchestrator/block-proving-state.ts +17 -6
  63. package/src/orchestrator/epoch-proving-state.ts +0 -2
  64. package/src/orchestrator/orchestrator.ts +111 -62
  65. package/src/orchestrator/orchestrator_metrics.ts +1 -11
  66. package/src/prover-agent/memory-proving-queue.ts +12 -7
  67. package/src/prover-agent/prover-agent.ts +67 -48
  68. package/src/prover-client/prover-client.ts +5 -12
  69. package/src/proving_broker/{caching_broker_facade.ts → broker_prover_facade.ts} +62 -85
  70. package/src/proving_broker/proving_agent.ts +74 -78
  71. package/src/proving_broker/proving_broker.ts +240 -73
  72. package/src/proving_broker/proving_broker_database/persisted.ts +2 -8
  73. package/src/proving_broker/proving_broker_instrumentation.ts +0 -7
  74. package/src/proving_broker/proving_job_controller.ts +13 -12
  75. package/src/proving_broker/rpc.ts +1 -1
  76. package/src/test/mock_prover.ts +7 -3
  77. package/dest/proving_broker/caching_broker_facade.d.ts +0 -30
  78. package/dest/proving_broker/caching_broker_facade.d.ts.map +0 -1
  79. package/dest/proving_broker/caching_broker_facade.js +0 -150
  80. package/dest/proving_broker/prover_cache/memory.d.ts +0 -9
  81. package/dest/proving_broker/prover_cache/memory.d.ts.map +0 -1
  82. package/dest/proving_broker/prover_cache/memory.js +0 -16
  83. package/src/proving_broker/prover_cache/memory.ts +0 -20
@@ -2,17 +2,22 @@ import { type BBProverConfig } from '@aztec/bb-prover';
2
2
  import {
3
3
  type L2Block,
4
4
  type ProcessedTx,
5
- type ProcessedTxHandler,
6
5
  type PublicExecutionRequest,
7
6
  type ServerCircuitProver,
8
7
  type Tx,
9
8
  type TxValidator,
10
9
  } from '@aztec/circuit-types';
11
10
  import { makeBloatedProcessedTx } from '@aztec/circuit-types/test';
12
- import { type AppendOnlyTreeSnapshot, type Gas, type GlobalVariables, Header } from '@aztec/circuits.js';
11
+ import {
12
+ type AppendOnlyTreeSnapshot,
13
+ BlockHeader,
14
+ type Gas,
15
+ type GlobalVariables,
16
+ TreeSnapshots,
17
+ } from '@aztec/circuits.js';
13
18
  import { times } from '@aztec/foundation/collection';
14
19
  import { Fr } from '@aztec/foundation/fields';
15
- import { type DebugLogger } from '@aztec/foundation/log';
20
+ import { type Logger } from '@aztec/foundation/log';
16
21
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types';
17
22
  import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
18
23
  import {
@@ -27,7 +32,7 @@ import { type MerkleTreeAdminDatabase } from '@aztec/world-state';
27
32
  import { NativeWorldStateService } from '@aztec/world-state/native';
28
33
 
29
34
  import { jest } from '@jest/globals';
30
- import * as fs from 'fs/promises';
35
+ import { promises as fs } from 'fs';
31
36
  import { mock } from 'jest-mock-extended';
32
37
 
33
38
  import { TestCircuitProver } from '../../../bb-prover/src/test/test_circuit_prover.js';
@@ -37,10 +42,10 @@ import { buildBlock } from '../block_builder/light.js';
37
42
  import { ProvingOrchestrator } from '../orchestrator/index.js';
38
43
  import { MemoryProvingQueue } from '../prover-agent/memory-proving-queue.js';
39
44
  import { ProverAgent } from '../prover-agent/prover-agent.js';
40
- import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixtures.js';
45
+ import { getEnvironmentConfig, getSimulationProvider, makeGlobals, updateExpectedTreesFromTxs } from './fixtures.js';
41
46
 
42
47
  export class TestContext {
43
- private headers: Map<number, Header> = new Map();
48
+ private headers: Map<number, BlockHeader> = new Map();
44
49
 
45
50
  constructor(
46
51
  public publicTxSimulator: PublicTxSimulator,
@@ -53,7 +58,7 @@ export class TestContext {
53
58
  public orchestrator: TestProvingOrchestrator,
54
59
  public blockNumber: number,
55
60
  public directoriesToCleanup: string[],
56
- public logger: DebugLogger,
61
+ public logger: Logger,
57
62
  ) {}
58
63
 
59
64
  public get epochProver() {
@@ -61,7 +66,7 @@ export class TestContext {
61
66
  }
62
67
 
63
68
  static async new(
64
- logger: DebugLogger,
69
+ logger: Logger,
65
70
  proverCount = 4,
66
71
  createProver: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver> = _ =>
67
72
  Promise.resolve(new TestCircuitProver(new NoopTelemetryClient(), new WASMSimulator())),
@@ -79,11 +84,11 @@ export class TestContext {
79
84
 
80
85
  worldStateDB.getMerkleInterface.mockReturnValue(publicDb);
81
86
 
82
- const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, telemetry, globalVariables);
87
+ const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, telemetry, globalVariables, true);
83
88
  const processor = new PublicProcessor(
84
89
  publicDb,
85
90
  globalVariables,
86
- Header.empty(),
91
+ BlockHeader.empty(),
87
92
  worldStateDB,
88
93
  publicTxSimulator,
89
94
  telemetry,
@@ -114,7 +119,7 @@ export class TestContext {
114
119
 
115
120
  const queue = new MemoryProvingQueue(telemetry);
116
121
  const orchestrator = new TestProvingOrchestrator(ws, queue, telemetry, Fr.ZERO);
117
- const agent = new ProverAgent(localProver, proverCount);
122
+ const agent = new ProverAgent(localProver, proverCount, undefined, telemetry);
118
123
 
119
124
  queue.start();
120
125
  agent.start(queue);
@@ -138,9 +143,9 @@ export class TestContext {
138
143
  return this.worldState.fork();
139
144
  }
140
145
 
141
- public getHeader(blockNumber: 0): Header;
142
- public getHeader(blockNumber: number): Header | undefined;
143
- public getHeader(blockNumber = 0) {
146
+ public getBlockHeader(blockNumber: 0): BlockHeader;
147
+ public getBlockHeader(blockNumber: number): BlockHeader | undefined;
148
+ public getBlockHeader(blockNumber = 0) {
144
149
  return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber);
145
150
  }
146
151
 
@@ -156,7 +161,7 @@ export class TestContext {
156
161
  public makeProcessedTx(seedOrOpts?: Parameters<typeof makeBloatedProcessedTx>[0] | number): ProcessedTx {
157
162
  const opts = typeof seedOrOpts === 'number' ? { seed: seedOrOpts } : seedOrOpts;
158
163
  const blockNum = (opts?.globalVariables ?? this.globalVariables).blockNumber.toNumber();
159
- const header = this.getHeader(blockNum - 1);
164
+ const header = this.getBlockHeader(blockNum - 1);
160
165
  return makeBloatedProcessedTx({
161
166
  header,
162
167
  vkTreeRoot: getVKTreeRoot(),
@@ -180,6 +185,7 @@ export class TestContext {
180
185
  const txs = times(numTxs, i =>
181
186
  this.makeProcessedTx({ seed: i + blockNum * 1000, globalVariables, ...makeProcessedTxOpts(i) }),
182
187
  );
188
+ await this.setEndTreeRoots(txs);
183
189
 
184
190
  const block = await buildBlock(txs, globalVariables, msgs, db);
185
191
  this.headers.set(blockNum, block.header);
@@ -187,12 +193,7 @@ export class TestContext {
187
193
  return { block, txs, msgs };
188
194
  }
189
195
 
190
- public async processPublicFunctions(
191
- txs: Tx[],
192
- maxTransactions: number,
193
- txHandler?: ProcessedTxHandler,
194
- txValidator?: TxValidator<ProcessedTx>,
195
- ) {
196
+ public async processPublicFunctions(txs: Tx[], maxTransactions: number, txValidator?: TxValidator<ProcessedTx>) {
196
197
  const defaultExecutorImplementation = (
197
198
  _stateManager: AvmPersistableStateManager,
198
199
  executionRequest: PublicExecutionRequest,
@@ -217,16 +218,30 @@ export class TestContext {
217
218
  return await this.processPublicFunctionsWithMockExecutorImplementation(
218
219
  txs,
219
220
  maxTransactions,
220
- txHandler,
221
221
  txValidator,
222
222
  defaultExecutorImplementation,
223
223
  );
224
224
  }
225
225
 
226
+ public async setEndTreeRoots(txs: ProcessedTx[]) {
227
+ const db = await this.worldState.fork();
228
+ for (const tx of txs) {
229
+ await updateExpectedTreesFromTxs(db, [tx]);
230
+ const stateReference = await db.getStateReference();
231
+ if (tx.avmProvingRequest) {
232
+ tx.avmProvingRequest.inputs.output.endTreeSnapshots = new TreeSnapshots(
233
+ stateReference.l1ToL2MessageTree,
234
+ stateReference.partial.noteHashTree,
235
+ stateReference.partial.nullifierTree,
236
+ stateReference.partial.publicDataTree,
237
+ );
238
+ }
239
+ }
240
+ }
241
+
226
242
  private async processPublicFunctionsWithMockExecutorImplementation(
227
243
  txs: Tx[],
228
244
  maxTransactions: number,
229
- txHandler?: ProcessedTxHandler,
230
245
  txValidator?: TxValidator<ProcessedTx>,
231
246
  executorMock?: (
232
247
  stateManager: AvmPersistableStateManager,
@@ -254,7 +269,7 @@ export class TestContext {
254
269
  if (executorMock) {
255
270
  simulateInternal.mockImplementation(executorMock);
256
271
  }
257
- return await this.publicProcessor.process(txs, maxTransactions, txHandler, txValidator);
272
+ return await this.publicProcessor.process(txs, maxTransactions, txValidator);
258
273
  }
259
274
  }
260
275
 
@@ -10,13 +10,13 @@ import {
10
10
  ARCHIVE_HEIGHT,
11
11
  AppendOnlyTreeSnapshot,
12
12
  type BaseOrMergeRollupPublicInputs,
13
+ BlockHeader,
13
14
  BlockMergeRollupInputs,
14
15
  type BlockRootOrBlockMergePublicInputs,
15
16
  ConstantRollupData,
16
17
  ContentCommitment,
17
18
  Fr,
18
19
  type GlobalVariables,
19
- Header,
20
20
  MAX_NOTE_HASHES_PER_TX,
21
21
  MAX_NULLIFIERS_PER_TX,
22
22
  MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
@@ -45,15 +45,17 @@ import {
45
45
  PublicDataTreeLeafPreimage,
46
46
  type RecursiveProof,
47
47
  RootRollupInputs,
48
+ type SpongeBlob,
48
49
  StateReference,
49
50
  VK_TREE_HEIGHT,
50
51
  type VerificationKeyAsFields,
51
52
  } from '@aztec/circuits.js';
52
53
  import { makeTuple } from '@aztec/foundation/array';
54
+ import { Blob } from '@aztec/foundation/blob';
53
55
  import { padArrayEnd } from '@aztec/foundation/collection';
54
56
  import { sha256Trunc } from '@aztec/foundation/crypto';
55
- import { type DebugLogger } from '@aztec/foundation/log';
56
- import { type Tuple, assertLength, toFriendlyJSON } from '@aztec/foundation/serialize';
57
+ import { type Logger } from '@aztec/foundation/log';
58
+ import { type Tuple, assertLength, serializeToBuffer, toFriendlyJSON } from '@aztec/foundation/serialize';
57
59
  import { computeUnbalancedMerkleRoot } from '@aztec/foundation/trees';
58
60
  import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types';
59
61
  import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
@@ -76,6 +78,7 @@ export async function buildBaseRollupHints(
76
78
  tx: ProcessedTx,
77
79
  globalVariables: GlobalVariables,
78
80
  db: MerkleTreeWriteOperations,
81
+ startSpongeBlob: SpongeBlob,
79
82
  ) {
80
83
  // Get trees info before any changes hit
81
84
  const constants = await getConstantRollupData(globalVariables, db);
@@ -95,13 +98,6 @@ export async function buildBaseRollupHints(
95
98
  i < noteHashSubtreeSiblingPathArray.length ? noteHashSubtreeSiblingPathArray[i] : Fr.ZERO,
96
99
  );
97
100
 
98
- // Create data hint for reading fee payer initial balance in Fee Juice
99
- // If no fee payer is set, read hint should be empty
100
- const leafSlot = computeFeePayerBalanceLeafSlot(tx.data.feePayer);
101
- const feePayerFeeJuiceBalanceReadHint = tx.data.feePayer.isZero()
102
- ? PublicDataHint.empty()
103
- : await getPublicDataHint(db, leafSlot.toBigInt());
104
-
105
101
  // Update the note hash trees with the new items being inserted to get the new roots
106
102
  // that will be used by the next iteration of the base rollup circuit, skipping the empty ones
107
103
  const noteHashes = padArrayEnd(tx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX);
@@ -139,6 +135,10 @@ export async function buildBaseRollupHints(
139
135
  i < nullifierSubtreeSiblingPathArray.length ? nullifierSubtreeSiblingPathArray[i] : Fr.ZERO,
140
136
  );
141
137
 
138
+ // Append new data to startSpongeBlob
139
+ const inputSpongeBlob = startSpongeBlob.clone();
140
+ startSpongeBlob.absorb(tx.txEffect.toBlobFields());
141
+
142
142
  if (tx.avmProvingRequest) {
143
143
  // Build public base rollup hints
144
144
  const stateDiffHints = PublicBaseStateDiffHints.from({
@@ -183,8 +183,8 @@ export async function buildBaseRollupHints(
183
183
 
184
184
  return PublicBaseRollupHints.from({
185
185
  start,
186
+ startSpongeBlob: inputSpongeBlob,
186
187
  stateDiffHints,
187
- feePayerFeeJuiceBalanceReadHint: feePayerFeeJuiceBalanceReadHint,
188
188
  archiveRootMembershipWitness,
189
189
  constants,
190
190
  });
@@ -197,6 +197,13 @@ export async function buildBaseRollupHints(
197
197
  throw new Error(`More than one public data write in a private only tx`);
198
198
  }
199
199
 
200
+ // Create data hint for reading fee payer initial balance in Fee Juice
201
+ // If no fee payer is set, read hint should be empty
202
+ const leafSlot = computeFeePayerBalanceLeafSlot(tx.data.feePayer);
203
+ const feePayerFeeJuiceBalanceReadHint = tx.data.feePayer.isZero()
204
+ ? PublicDataHint.empty()
205
+ : await getPublicDataHint(db, leafSlot.toBigInt());
206
+
200
207
  const feeWriteLowLeafPreimage =
201
208
  txPublicDataUpdateRequestInfo.lowPublicDataWritesPreimages[0] || PublicDataTreeLeafPreimage.empty();
202
209
  const feeWriteLowLeafMembershipWitness =
@@ -236,6 +243,7 @@ export async function buildBaseRollupHints(
236
243
 
237
244
  return PrivateBaseRollupHints.from({
238
245
  start,
246
+ startSpongeBlob: inputSpongeBlob,
239
247
  stateDiffHints,
240
248
  feePayerFeeJuiceBalanceReadHint: feePayerFeeJuiceBalanceReadHint,
241
249
  archiveRootMembershipWitness,
@@ -299,18 +307,17 @@ export function buildHeaderFromCircuitOutputs(
299
307
  parityPublicInputs: ParityPublicInputs,
300
308
  rootRollupOutputs: BlockRootOrBlockMergePublicInputs,
301
309
  updatedL1ToL2TreeSnapshot: AppendOnlyTreeSnapshot,
302
- logger?: DebugLogger,
310
+ logger?: Logger,
303
311
  ) {
312
+ const blobsHash = rootRollupOutputs.blobPublicInputs[0].getBlobsHash();
304
313
  const contentCommitment = new ContentCommitment(
305
314
  new Fr(previousMergeData[0].numTxs + previousMergeData[1].numTxs),
306
- sha256Trunc(
307
- Buffer.concat([previousMergeData[0].txsEffectsHash.toBuffer(), previousMergeData[1].txsEffectsHash.toBuffer()]),
308
- ),
315
+ blobsHash,
309
316
  parityPublicInputs.shaRoot.toBuffer(),
310
317
  sha256Trunc(Buffer.concat([previousMergeData[0].outHash.toBuffer(), previousMergeData[1].outHash.toBuffer()])),
311
318
  );
312
319
  const state = new StateReference(updatedL1ToL2TreeSnapshot, previousMergeData[1].end);
313
- const header = new Header(
320
+ const header = new BlockHeader(
314
321
  rootRollupOutputs.previousArchive,
315
322
  contentCommitment,
316
323
  state,
@@ -360,10 +367,11 @@ export async function buildHeaderAndBodyFromTxs(
360
367
  const parityShaRoot = new MerkleTreeCalculator(parityHeight, Fr.ZERO.toBuffer(), hasher).computeTreeRoot(
361
368
  l1ToL2Messages.map(msg => msg.toBuffer()),
362
369
  );
370
+ const blobsHash = getBlobsHashFromBlobs(Blob.getBlobs(body.toBlobFields()));
363
371
 
364
372
  const contentCommitment = new ContentCommitment(
365
373
  new Fr(body.numberOfTxsIncludingPadded),
366
- body.getTxsEffectsHash(),
374
+ blobsHash,
367
375
  parityShaRoot,
368
376
  outHash,
369
377
  );
@@ -371,15 +379,20 @@ export async function buildHeaderAndBodyFromTxs(
371
379
  const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO);
372
380
  const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.totalGas.l2Gas)), Fr.ZERO);
373
381
 
374
- const header = new Header(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed);
382
+ const header = new BlockHeader(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed);
375
383
 
376
384
  return { header, body };
377
385
  }
378
386
 
387
+ export function getBlobsHashFromBlobs(inputs: Blob[]): Buffer {
388
+ const blobHashes = serializeToBuffer(inputs.map(b => b.getEthVersionedBlobHash()));
389
+ return sha256Trunc(serializeToBuffer(blobHashes));
390
+ }
391
+
379
392
  // Validate that the roots of all local trees match the output of the root circuit simulation
380
393
  export async function validateBlockRootOutput(
381
394
  blockRootOutput: BlockRootOrBlockMergePublicInputs,
382
- blockHeader: Header,
395
+ blockHeader: BlockHeader,
383
396
  db: MerkleTreeReadOperations,
384
397
  ) {
385
398
  await Promise.all([
@@ -548,7 +561,7 @@ export async function getMembershipWitnessFor<N extends number>(
548
561
  return makeEmptyMembershipWitness(height);
549
562
  }
550
563
 
551
- const index = await db.findLeafIndex(treeId, value.toBuffer());
564
+ const index = (await db.findLeafIndices(treeId, [value.toBuffer()]))[0];
552
565
  if (index === undefined) {
553
566
  throw new Error(`Leaf with value ${value} not found in tree ${MerkleTreeId[treeId]}`);
554
567
  }
@@ -14,6 +14,7 @@ import {
14
14
  type RECURSIVE_PROOF_LENGTH,
15
15
  type RecursiveProof,
16
16
  type RootParityInput,
17
+ SpongeBlob,
17
18
  type VerificationKeyAsFields,
18
19
  } from '@aztec/circuits.js';
19
20
  import { type Tuple } from '@aztec/foundation/serialize';
@@ -44,12 +45,13 @@ export class BlockProvingState {
44
45
  public blockRootRollupStarted: boolean = false;
45
46
  public finalProof: Proof | undefined;
46
47
  public block: L2Block | undefined;
48
+ public spongeBlobState: SpongeBlob | undefined;
49
+ public totalNumTxs: number;
47
50
  private txs: TxProvingState[] = [];
48
51
  public error: string | undefined;
49
52
 
50
53
  constructor(
51
54
  public readonly index: number,
52
- public readonly totalNumTxs: number,
53
55
  public readonly globalVariables: GlobalVariables,
54
56
  public readonly newL1ToL2Messages: Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>,
55
57
  public readonly messageTreeSnapshot: AppendOnlyTreeSnapshot,
@@ -61,6 +63,7 @@ export class BlockProvingState {
61
63
  private readonly parentEpoch: EpochProvingState,
62
64
  ) {
63
65
  this.rootParityInputs = Array.from({ length: NUM_BASE_PARITY_PER_ROOT_PARITY }).map(_ => undefined);
66
+ this.totalNumTxs = 0;
64
67
  }
65
68
 
66
69
  public get blockNumber() {
@@ -98,8 +101,21 @@ export class BlockProvingState {
98
101
  return [mergeLevel - 1n, thisIndex >> 1n, thisIndex & 1n];
99
102
  }
100
103
 
104
+ public startNewBlock(numTxs: number, numBlobFields: number) {
105
+ if (this.spongeBlobState) {
106
+ throw new Error(`Block ${this.blockNumber} already initalised.`);
107
+ }
108
+ // Initialise the sponge which will eventually absorb all tx effects to be added to the blob.
109
+ // Like l1 to l2 messages, we need to know beforehand how many effects will be absorbed.
110
+ this.spongeBlobState = SpongeBlob.init(numBlobFields);
111
+ this.totalNumTxs = numTxs;
112
+ }
113
+
101
114
  // Adds a transaction to the proving state, returns it's index
102
115
  public addNewTx(tx: TxProvingState) {
116
+ if (!this.spongeBlobState) {
117
+ throw new Error(`Invalid block proving state, call startNewBlock before adding transactions.`);
118
+ }
103
119
  this.txs.push(tx);
104
120
  return this.txs.length - 1;
105
121
  }
@@ -199,11 +215,6 @@ export class BlockProvingState {
199
215
  return this.rootParityInputs.findIndex(p => !p) === -1;
200
216
  }
201
217
 
202
- // Returns true if we are still able to accept transactions, false otherwise
203
- public isAcceptingTransactions() {
204
- return this.totalNumTxs > this.txs.length;
205
- }
206
-
207
218
  // Returns whether the proving state is still valid
208
219
  public verifyState() {
209
220
  return this.parentEpoch.verifyState();
@@ -97,7 +97,6 @@ export class EpochProvingState {
97
97
  // Adds a block to the proving state, returns its index
98
98
  // Will update the proving life cycle if this is the last block
99
99
  public startNewBlock(
100
- numTxs: number,
101
100
  globalVariables: GlobalVariables,
102
101
  l1ToL2Messages: Fr[],
103
102
  messageTreeSnapshot: AppendOnlyTreeSnapshot,
@@ -110,7 +109,6 @@ export class EpochProvingState {
110
109
  const index = globalVariables.blockNumber.toNumber() - this.firstBlockNumber;
111
110
  const block = new BlockProvingState(
112
111
  index,
113
- numTxs,
114
112
  globalVariables,
115
113
  padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
116
114
  messageTreeSnapshot,