@aztec/prover-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240

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 (130) hide show
  1. package/dest/config.d.ts +1 -1
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +16 -2
  4. package/dest/light/lightweight_checkpoint_builder.d.ts +16 -7
  5. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  6. package/dest/light/lightweight_checkpoint_builder.js +75 -27
  7. package/dest/mocks/fixtures.d.ts +1 -1
  8. package/dest/mocks/fixtures.d.ts.map +1 -1
  9. package/dest/mocks/fixtures.js +2 -1
  10. package/dest/mocks/test_context.d.ts +5 -2
  11. package/dest/mocks/test_context.d.ts.map +1 -1
  12. package/dest/mocks/test_context.js +23 -9
  13. package/dest/orchestrator/block-building-helpers.d.ts +5 -5
  14. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  15. package/dest/orchestrator/block-building-helpers.js +3 -3
  16. package/dest/orchestrator/block-proving-state.d.ts +4 -1
  17. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  18. package/dest/orchestrator/block-proving-state.js +7 -0
  19. package/dest/orchestrator/checkpoint-proving-state.d.ts +24 -4
  20. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/checkpoint-proving-state.js +47 -5
  22. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +107 -0
  23. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
  24. package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +151 -0
  25. package/dest/orchestrator/epoch-proving-context.d.ts +51 -0
  26. package/dest/orchestrator/epoch-proving-context.d.ts.map +1 -0
  27. package/dest/orchestrator/epoch-proving-context.js +81 -0
  28. package/dest/orchestrator/epoch-proving-state.d.ts +7 -6
  29. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  30. package/dest/orchestrator/epoch-proving-state.js +37 -1
  31. package/dest/orchestrator/index.d.ts +4 -1
  32. package/dest/orchestrator/index.d.ts.map +1 -1
  33. package/dest/orchestrator/index.js +3 -0
  34. package/dest/orchestrator/orchestrator.d.ts +29 -24
  35. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  36. package/dest/orchestrator/orchestrator.js +137 -225
  37. package/dest/orchestrator/proving-scheduler.d.ts +72 -0
  38. package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
  39. package/dest/orchestrator/proving-scheduler.js +117 -0
  40. package/dest/orchestrator/top-tree-orchestrator.d.ts +83 -0
  41. package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
  42. package/dest/orchestrator/top-tree-orchestrator.js +182 -0
  43. package/dest/orchestrator/top-tree-proving-scheduler.d.ts +62 -0
  44. package/dest/orchestrator/top-tree-proving-scheduler.d.ts.map +1 -0
  45. package/dest/orchestrator/top-tree-proving-scheduler.js +73 -0
  46. package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
  47. package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
  48. package/dest/orchestrator/top-tree-proving-state.js +185 -0
  49. package/dest/prover-client/prover-client.d.ts +64 -5
  50. package/dest/prover-client/prover-client.d.ts.map +1 -1
  51. package/dest/prover-client/prover-client.js +64 -11
  52. package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
  53. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  54. package/dest/proving_broker/broker_prover_facade.js +16 -22
  55. package/dest/proving_broker/config.d.ts +12 -64
  56. package/dest/proving_broker/config.d.ts.map +1 -1
  57. package/dest/proving_broker/config.js +22 -5
  58. package/dest/proving_broker/index.d.ts +2 -1
  59. package/dest/proving_broker/index.d.ts.map +1 -1
  60. package/dest/proving_broker/index.js +1 -0
  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 -2
  68. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  69. package/dest/proving_broker/proof_store/index.js +1 -1
  70. package/dest/proving_broker/proving_agent.d.ts +4 -3
  71. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  72. package/dest/proving_broker/proving_agent.js +4 -4
  73. package/dest/proving_broker/proving_broker.d.ts +8 -5
  74. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_broker.js +68 -11
  76. package/dest/proving_broker/proving_broker_database/persisted.js +2 -2
  77. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  78. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  79. package/dest/proving_broker/proving_broker_instrumentation.js +18 -7
  80. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  81. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  82. package/dest/proving_broker/proving_job_controller.js +6 -3
  83. package/dest/proving_broker/rpc.d.ts +6 -2
  84. package/dest/proving_broker/rpc.d.ts.map +1 -1
  85. package/dest/proving_broker/rpc.js +87 -23
  86. package/dest/test/mock_proof_store.d.ts +3 -3
  87. package/dest/test/mock_proof_store.d.ts.map +1 -1
  88. package/dest/test/mock_prover.d.ts +4 -4
  89. package/package.json +19 -21
  90. package/src/config.ts +18 -2
  91. package/src/light/lightweight_checkpoint_builder.ts +107 -36
  92. package/src/mocks/fixtures.ts +2 -1
  93. package/src/mocks/test_context.ts +18 -10
  94. package/src/orchestrator/block-building-helpers.ts +3 -3
  95. package/src/orchestrator/block-proving-state.ts +9 -0
  96. package/src/orchestrator/checkpoint-proving-state.ts +65 -6
  97. package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +271 -0
  98. package/src/orchestrator/epoch-proving-context.ts +101 -0
  99. package/src/orchestrator/epoch-proving-state.ts +59 -9
  100. package/src/orchestrator/index.ts +8 -0
  101. package/src/orchestrator/orchestrator.ts +161 -290
  102. package/src/orchestrator/proving-scheduler.ts +156 -0
  103. package/src/orchestrator/top-tree-orchestrator.ts +314 -0
  104. package/src/orchestrator/top-tree-proving-scheduler.ts +154 -0
  105. package/src/orchestrator/top-tree-proving-state.ts +220 -0
  106. package/src/prover-client/prover-client.ts +155 -15
  107. package/src/proving_broker/broker_prover_facade.ts +23 -23
  108. package/src/proving_broker/config.ts +25 -2
  109. package/src/proving_broker/index.ts +1 -0
  110. package/src/proving_broker/proof_store/factory.ts +10 -32
  111. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  112. package/src/proving_broker/proof_store/index.ts +1 -1
  113. package/src/proving_broker/proving_agent.ts +5 -2
  114. package/src/proving_broker/proving_broker.ts +64 -8
  115. package/src/proving_broker/proving_broker_database/persisted.ts +2 -2
  116. package/src/proving_broker/proving_broker_instrumentation.ts +19 -6
  117. package/src/proving_broker/proving_job_controller.ts +9 -3
  118. package/src/proving_broker/rpc.ts +46 -20
  119. package/dest/block-factory/index.d.ts +0 -2
  120. package/dest/block-factory/index.d.ts.map +0 -1
  121. package/dest/block-factory/index.js +0 -1
  122. package/dest/block-factory/light.d.ts +0 -38
  123. package/dest/block-factory/light.d.ts.map +0 -1
  124. package/dest/block-factory/light.js +0 -106
  125. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  126. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  127. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  128. package/src/block-factory/index.ts +0 -1
  129. package/src/block-factory/light.ts +0 -136
  130. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
package/src/config.ts CHANGED
@@ -44,14 +44,30 @@ export const bbConfigMappings: ConfigMappingsType<BBConfig & ACVMConfig> = {
44
44
  },
45
45
  numConcurrentIVCVerifiers: {
46
46
  env: 'BB_NUM_IVC_VERIFIERS',
47
- description: 'Max number of chonk verifiers to run concurrently',
47
+ description: 'Max concurrent verifications for the RPC verifier (QueuedIVCVerifier).',
48
48
  ...numberConfigHelper(8),
49
49
  },
50
50
  bbIVCConcurrency: {
51
51
  env: 'BB_IVC_CONCURRENCY',
52
- description: 'Number of threads to use for IVC verification',
52
+ description: 'Thread count for the RPC IVC verifier.',
53
53
  ...numberConfigHelper(1),
54
54
  },
55
+ bbChonkVerifyMaxBatch: {
56
+ env: 'BB_CHONK_VERIFY_MAX_BATCH',
57
+ description:
58
+ 'Upper bound on proofs per batch for the peer chonk batch verifier. Proofs are verified immediately as they arrive; this only caps how many can accumulate while a batch is already being processed.',
59
+ ...numberConfigHelper(16),
60
+ },
61
+ bbChonkVerifyConcurrency: {
62
+ env: 'BB_CHONK_VERIFY_BATCH_CONCURRENCY',
63
+ description: 'Thread count for the peer batch verifier parallel reduce. 0 = auto.',
64
+ ...numberConfigHelper(6),
65
+ },
66
+ bbDebugOutputDir: {
67
+ env: 'BB_DEBUG_OUTPUT_DIR',
68
+ description:
69
+ 'When set, bb.js operations write input/output files and log equivalent CLI commands to this directory',
70
+ },
55
71
  };
56
72
 
57
73
  export const proverClientConfigMappings: ConfigMappingsType<ProverClientUserConfig> = {
@@ -1,13 +1,17 @@
1
1
  import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
2
- import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
- import type { CheckpointNumber } from '@aztec/foundation/branded-types';
4
- import { padArrayEnd } from '@aztec/foundation/collection';
2
+ import { type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
5
3
  import { Fr } from '@aztec/foundation/curves/bn254';
6
- import { createLogger } from '@aztec/foundation/log';
7
- import { L2BlockNew } from '@aztec/stdlib/block';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
+ import { elapsed } from '@aztec/foundation/timer';
6
+ import { L2Block } from '@aztec/stdlib/block';
8
7
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
9
8
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
10
- import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
9
+ import {
10
+ accumulateCheckpointOutHashes,
11
+ appendL1ToL2MessagesToTree,
12
+ computeCheckpointOutHash,
13
+ computeInHashFromL1ToL2Messages,
14
+ } from '@aztec/stdlib/messaging';
11
15
  import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
12
16
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
13
17
  import {
@@ -30,36 +34,51 @@ import {
30
34
  * Finally completes the checkpoint by computing its header.
31
35
  */
32
36
  export class LightweightCheckpointBuilder {
33
- private readonly logger = createLogger('lightweight-checkpoint-builder');
37
+ private readonly logger: Logger;
34
38
 
35
39
  private lastArchives: AppendOnlyTreeSnapshot[] = [];
36
40
  private spongeBlob: SpongeBlob;
37
- private blocks: L2BlockNew[] = [];
41
+ private blocks: L2Block[] = [];
38
42
  private blobFields: Fr[] = [];
39
43
 
40
44
  constructor(
41
45
  public readonly checkpointNumber: CheckpointNumber,
42
46
  public readonly constants: CheckpointGlobalVariables,
47
+ public feeAssetPriceModifier: bigint,
43
48
  public readonly l1ToL2Messages: Fr[],
49
+ private readonly previousCheckpointOutHashes: Fr[],
44
50
  public readonly db: MerkleTreeWriteOperations,
51
+ bindings?: LoggerBindings,
45
52
  ) {
53
+ this.logger = createLogger('checkpoint-builder', {
54
+ ...bindings,
55
+ instanceId: `checkpoint-${checkpointNumber}`,
56
+ });
46
57
  this.spongeBlob = SpongeBlob.init();
47
- this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages });
58
+ this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages, feeAssetPriceModifier });
48
59
  }
49
60
 
50
61
  static async startNewCheckpoint(
51
62
  checkpointNumber: CheckpointNumber,
52
63
  constants: CheckpointGlobalVariables,
53
64
  l1ToL2Messages: Fr[],
65
+ previousCheckpointOutHashes: Fr[],
54
66
  db: MerkleTreeWriteOperations,
67
+ bindings?: LoggerBindings,
68
+ feeAssetPriceModifier: bigint = 0n,
55
69
  ): Promise<LightweightCheckpointBuilder> {
56
70
  // Insert l1-to-l2 messages into the tree.
57
- await db.appendLeaves(
58
- MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
59
- padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
60
- );
71
+ await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
61
72
 
62
- return new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
73
+ return new LightweightCheckpointBuilder(
74
+ checkpointNumber,
75
+ constants,
76
+ feeAssetPriceModifier,
77
+ l1ToL2Messages,
78
+ previousCheckpointOutHashes,
79
+ db,
80
+ bindings,
81
+ );
63
82
  }
64
83
 
65
84
  /**
@@ -71,11 +90,22 @@ export class LightweightCheckpointBuilder {
71
90
  static async resumeCheckpoint(
72
91
  checkpointNumber: CheckpointNumber,
73
92
  constants: CheckpointGlobalVariables,
93
+ feeAssetPriceModifier: bigint,
74
94
  l1ToL2Messages: Fr[],
95
+ previousCheckpointOutHashes: Fr[],
75
96
  db: MerkleTreeWriteOperations,
76
- existingBlocks: L2BlockNew[],
97
+ existingBlocks: L2Block[],
98
+ bindings?: LoggerBindings,
77
99
  ): Promise<LightweightCheckpointBuilder> {
78
- const builder = new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
100
+ const builder = new LightweightCheckpointBuilder(
101
+ checkpointNumber,
102
+ constants,
103
+ feeAssetPriceModifier,
104
+ l1ToL2Messages,
105
+ previousCheckpointOutHashes,
106
+ db,
107
+ bindings,
108
+ );
79
109
 
80
110
  builder.logger.debug('Resuming checkpoint from existing blocks', {
81
111
  checkpointNumber,
@@ -83,6 +113,10 @@ export class LightweightCheckpointBuilder {
83
113
  blockNumbers: existingBlocks.map(b => b.header.getBlockNumber()),
84
114
  });
85
115
 
116
+ if (existingBlocks.length === 0) {
117
+ throw new Error(`Cannot resume checkpoint ${checkpointNumber} with no existing blocks`);
118
+ }
119
+
86
120
  // Validate block order and consistency
87
121
  for (let i = 1; i < existingBlocks.length; i++) {
88
122
  const prev = existingBlocks[i - 1];
@@ -115,6 +149,15 @@ export class LightweightCheckpointBuilder {
115
149
  return builder;
116
150
  }
117
151
 
152
+ /** Returns how many blocks have been added to this checkpoint so far */
153
+ public getBlockCount() {
154
+ return this.blocks.length;
155
+ }
156
+
157
+ public getBlocks() {
158
+ return this.blocks;
159
+ }
160
+
118
161
  /**
119
162
  * Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
120
163
  * this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
@@ -123,7 +166,8 @@ export class LightweightCheckpointBuilder {
123
166
  globalVariables: GlobalVariables,
124
167
  txs: ProcessedTx[],
125
168
  opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
126
- ): Promise<L2BlockNew> {
169
+ ): Promise<{ block: L2Block; timings: Record<string, number> }> {
170
+ const timings: Record<string, number> = {};
127
171
  const isFirstBlock = this.blocks.length === 0;
128
172
 
129
173
  // Empty blocks are only allowed as the first block in a checkpoint
@@ -132,7 +176,9 @@ export class LightweightCheckpointBuilder {
132
176
  }
133
177
 
134
178
  if (isFirstBlock) {
135
- this.lastArchives.push(await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
179
+ const [msGetInitialArchive, initialArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
180
+ this.lastArchives.push(initialArchive);
181
+ timings.getInitialArchive = msGetInitialArchive;
136
182
  }
137
183
 
138
184
  const lastArchive = this.lastArchives.at(-1)!;
@@ -142,12 +188,17 @@ export class LightweightCheckpointBuilder {
142
188
  `Inserting side effects for ${txs.length} txs for block ${globalVariables.blockNumber} into db`,
143
189
  { txs: txs.map(tx => tx.hash.toString()) },
144
190
  );
191
+ let msInsertSideEffects = 0;
145
192
  for (const tx of txs) {
146
- await insertSideEffects(tx, this.db);
193
+ const [ms] = await elapsed(() => insertSideEffects(tx, this.db));
194
+ msInsertSideEffects += ms;
147
195
  }
196
+ timings.insertSideEffects = msInsertSideEffects;
148
197
  }
149
198
 
150
- const endState = await this.db.getStateReference();
199
+ const [msGetEndState, endState] = await elapsed(() => this.db.getStateReference());
200
+ timings.getEndState = msGetEndState;
201
+
151
202
  if (opts.expectedEndState && !endState.equals(opts.expectedEndState)) {
152
203
  this.logger.error('End state after processing txs does not match expected end state', {
153
204
  globalVariables: globalVariables.toInspect(),
@@ -157,26 +208,31 @@ export class LightweightCheckpointBuilder {
157
208
  throw new Error(`End state does not match expected end state when building block ${globalVariables.blockNumber}`);
158
209
  }
159
210
 
160
- const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
161
- txs,
162
- lastArchive,
163
- endState,
164
- globalVariables,
165
- this.spongeBlob,
166
- isFirstBlock,
211
+ const [msBuildHeaderAndBody, { header, body, blockBlobFields }] = await elapsed(() =>
212
+ buildHeaderAndBodyFromTxs(txs, lastArchive, endState, globalVariables, this.spongeBlob, isFirstBlock),
167
213
  );
214
+ timings.buildHeaderAndBody = msBuildHeaderAndBody;
168
215
 
169
216
  header.state.validate();
170
217
 
171
218
  await this.db.updateArchive(header);
172
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
219
+ const [msUpdateArchive, newArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
220
+ timings.updateArchive = msUpdateArchive;
173
221
  this.lastArchives.push(newArchive);
174
222
 
175
- const indexWithinCheckpoint = this.blocks.length;
176
- const block = new L2BlockNew(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
223
+ const expectedNextLeafIndex = Number(globalVariables.blockNumber) + 1;
224
+ if (newArchive.nextAvailableLeafIndex !== expectedNextLeafIndex) {
225
+ throw new Error(
226
+ `Archive tree next leaf index mismatch after building block ${globalVariables.blockNumber} (expected ${expectedNextLeafIndex} but got ${newArchive.nextAvailableLeafIndex})`,
227
+ );
228
+ }
229
+
230
+ const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
231
+ const block = new L2Block(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
177
232
  this.blocks.push(block);
178
233
 
179
- await this.spongeBlob.absorb(blockBlobFields);
234
+ const [msSpongeAbsorb] = await elapsed(() => this.spongeBlob.absorb(blockBlobFields));
235
+ timings.spongeAbsorb = msSpongeAbsorb;
180
236
  this.blobFields.push(...blockBlobFields);
181
237
 
182
238
  this.logger.debug(`Built block ${header.getBlockNumber()}`, {
@@ -187,7 +243,7 @@ export class LightweightCheckpointBuilder {
187
243
  txs: block.body.txEffects.map(tx => tx.txHash.toString()),
188
244
  });
189
245
 
190
- return block;
246
+ return { block, timings };
191
247
  }
192
248
 
193
249
  async completeCheckpoint(): Promise<Checkpoint> {
@@ -204,15 +260,18 @@ export class LightweightCheckpointBuilder {
204
260
 
205
261
  const newArchive = this.lastArchives[this.lastArchives.length - 1];
206
262
 
207
- const blobs = getBlobsPerL1Block(this.blobFields);
263
+ const blobs = await getBlobsPerL1Block(this.blobFields);
208
264
  const blobsHash = computeBlobsHashFromBlobs(blobs);
209
265
 
210
266
  const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
211
267
 
212
268
  const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
269
+ const checkpointOutHash = computeCheckpointOutHash(
270
+ blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)),
271
+ );
272
+ const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
213
273
 
214
- // TODO(palla/mbps): Should we source this from the constants instead?
215
- // timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
274
+ // All blocks in the checkpoint have the same timestamp
216
275
  const timestamp = blocks[blocks.length - 1].timestamp;
217
276
 
218
277
  const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
@@ -221,6 +280,7 @@ export class LightweightCheckpointBuilder {
221
280
  lastArchiveRoot: this.lastArchives[0].root,
222
281
  blobsHash,
223
282
  inHash,
283
+ epochOutHash,
224
284
  blockHeadersHash,
225
285
  slotNumber,
226
286
  timestamp,
@@ -230,15 +290,26 @@ export class LightweightCheckpointBuilder {
230
290
  totalManaUsed,
231
291
  });
232
292
 
233
- return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
293
+ this.logger.debug(`Completed checkpoint ${this.checkpointNumber}`, {
294
+ checkpointNumber: this.checkpointNumber,
295
+ headerHash: header.hash().toString(),
296
+ checkpointOutHash: checkpointOutHash.toString(),
297
+ numPreviousCheckpointOutHashes: this.previousCheckpointOutHashes.length,
298
+ ...header.toInspect(),
299
+ });
300
+
301
+ return new Checkpoint(newArchive, header, blocks, this.checkpointNumber, this.feeAssetPriceModifier);
234
302
  }
235
303
 
236
304
  clone() {
237
305
  const clone = new LightweightCheckpointBuilder(
238
306
  this.checkpointNumber,
239
307
  this.constants,
308
+ this.feeAssetPriceModifier,
240
309
  [...this.l1ToL2Messages],
310
+ [...this.previousCheckpointOutHashes],
241
311
  this.db,
312
+ this.logger.getBindings(),
242
313
  );
243
314
  clone.lastArchives = [...this.lastArchives];
244
315
  clone.spongeBlob = this.spongeBlob.clone();
@@ -75,7 +75,8 @@ export async function getSimulator(
75
75
  logger?.info(
76
76
  `Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`,
77
77
  );
78
- return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath);
78
+ const acvmLogger = logger?.createChild('acvm-native');
79
+ return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, acvmLogger);
79
80
  } catch {
80
81
  logger?.warn(`Failed to access ACVM at ${config.acvmBinaryPath}, falling back to WASM`);
81
82
  }
@@ -24,6 +24,7 @@ import {
24
24
  StateReference,
25
25
  TreeSnapshots,
26
26
  } from '@aztec/stdlib/tx';
27
+ import type { GenesisData } from '@aztec/stdlib/world-state';
27
28
  import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
28
29
  import { NativeWorldStateService } from '@aztec/world-state/native';
29
30
 
@@ -44,6 +45,7 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
44
45
  export class TestContext {
45
46
  private headers: Map<number, BlockHeader> = new Map();
46
47
  private checkpoints: Checkpoint[] = [];
48
+ private checkpointOutHashes: Fr[] = [];
47
49
  private nextCheckpointIndex = 0;
48
50
  private nextCheckpointNumber = CheckpointNumber(1);
49
51
  private nextBlockNumber = 1;
@@ -83,14 +85,13 @@ export class TestContext {
83
85
  const feePayer = AztecAddress.fromNumber(42222);
84
86
  const initialFeePayerBalance = new Fr(10n ** 20n);
85
87
  const feePayerSlot = await computeFeePayerBalanceLeafSlot(feePayer);
86
- const prefilledPublicData = [new PublicDataTreeLeaf(feePayerSlot, initialFeePayerBalance)];
88
+ const genesis: GenesisData = {
89
+ prefilledPublicData: [new PublicDataTreeLeaf(feePayerSlot, initialFeePayerBalance)],
90
+ genesisTimestamp: 0n,
91
+ };
87
92
 
88
93
  // Separated dbs for public processor and prover - see public_processor for context
89
- const ws = await NativeWorldStateService.tmp(
90
- /*rollupAddress=*/ undefined,
91
- /*cleanupTmpDir=*/ true,
92
- prefilledPublicData,
93
- );
94
+ const ws = await NativeWorldStateService.tmp(/*rollupAddress=*/ undefined, /*cleanupTmpDir=*/ true, genesis);
94
95
 
95
96
  let localProver: ServerCircuitProver;
96
97
  const config = await getEnvironmentConfig(logger);
@@ -103,8 +104,10 @@ export class TestContext {
103
104
  bbBinaryPath: config.expectedBBPath,
104
105
  bbWorkingDirectory: config.bbWorkingDirectory,
105
106
  bbSkipCleanup: config.bbSkipCleanup,
106
- numConcurrentIVCVerifiers: 2,
107
+ numConcurrentIVCVerifiers: 8,
107
108
  bbIVCConcurrency: 1,
109
+ bbChonkVerifyMaxBatch: 16,
110
+ bbChonkVerifyConcurrency: 6,
108
111
  };
109
112
  localProver = await createProver(bbConfig);
110
113
  }
@@ -115,7 +118,7 @@ export class TestContext {
115
118
 
116
119
  const broker = new TestBroker(proverCount, localProver);
117
120
  const facade = new BrokerCircuitProverFacade(broker);
118
- const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
121
+ const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO, false, 10);
119
122
 
120
123
  await broker.start();
121
124
  facade.start();
@@ -151,6 +154,7 @@ export class TestContext {
151
154
 
152
155
  public startNewEpoch() {
153
156
  this.checkpoints = [];
157
+ this.checkpointOutHashes = [];
154
158
  this.nextCheckpointIndex = 0;
155
159
  this.epochNumber++;
156
160
  }
@@ -245,10 +249,12 @@ export class TestContext {
245
249
  });
246
250
 
247
251
  const cleanFork = await this.worldState.fork();
252
+ const previousCheckpointOutHashes = this.checkpointOutHashes;
248
253
  const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
249
254
  checkpointNumber,
250
- constants,
255
+ { ...constants, timestamp },
251
256
  l1ToL2Messages,
257
+ previousCheckpointOutHashes,
252
258
  cleanFork,
253
259
  );
254
260
 
@@ -258,7 +264,7 @@ export class TestContext {
258
264
  const txs = blockTxs[i];
259
265
  const state = blockEndStates[i];
260
266
 
261
- const block = await builder.addBlock(blockGlobalVariables[i], txs, {
267
+ const { block } = await builder.addBlock(blockGlobalVariables[i], txs, {
262
268
  expectedEndState: state,
263
269
  insertTxsEffects: true,
264
270
  });
@@ -274,9 +280,11 @@ export class TestContext {
274
280
 
275
281
  const checkpoint = await builder.completeCheckpoint();
276
282
  this.checkpoints.push(checkpoint);
283
+ this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
277
284
 
278
285
  return {
279
286
  constants,
287
+ checkpoint,
280
288
  header: checkpoint.header,
281
289
  blocks,
282
290
  l1ToL2Messages,
@@ -99,7 +99,7 @@ export const insertSideEffectsAndBuildBaseRollupHints = runInSpan(
99
99
 
100
100
  const blockHash = await tx.data.constants.anchorBlockHeader.hash();
101
101
  const anchorBlockArchiveSiblingPath = (
102
- await getMembershipWitnessFor(blockHash, MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
102
+ await getMembershipWitnessFor(blockHash.toFr(), MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
103
103
  ).siblingPath;
104
104
 
105
105
  const contractClassLogsFields = makeTuple(
@@ -253,8 +253,8 @@ export function getPublicChonkVerifierPrivateInputsFromTx(tx: Tx | ProcessedTx,
253
253
  // Build "hints" as the private inputs for the checkpoint root rollup circuit.
254
254
  // The `blobCommitments` will be accumulated and checked in the root rollup against the `finalBlobChallenges`.
255
255
  // The `blobsHash` will be validated on L1 against the submitted blob data.
256
- export const buildBlobHints = (blobFields: Fr[]) => {
257
- const blobs = getBlobsPerL1Block(blobFields);
256
+ export const buildBlobHints = async (blobFields: Fr[]) => {
257
+ const blobs = await getBlobsPerL1Block(blobFields);
258
258
  const blobCommitments = getBlobCommitmentsFromBlobs(blobs);
259
259
  const blobsHash = computeBlobsHashFromBlobs(blobs);
260
260
  return { blobCommitments, blobs, blobsHash };
@@ -55,6 +55,7 @@ export class BlockProvingState {
55
55
  | ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
56
56
  | undefined;
57
57
  private builtBlockHeader: BlockHeader | undefined;
58
+ private builtArchive: AppendOnlyTreeSnapshot | undefined;
58
59
  private endState: StateReference | undefined;
59
60
  private endSpongeBlob: SpongeBlob | undefined;
60
61
  private txs: TxProvingState[] = [];
@@ -232,6 +233,14 @@ export class BlockProvingState {
232
233
  return this.builtBlockHeader;
233
234
  }
234
235
 
236
+ public setBuiltArchive(archive: AppendOnlyTreeSnapshot) {
237
+ this.builtArchive = archive;
238
+ }
239
+
240
+ public getBuiltArchive() {
241
+ return this.builtArchive;
242
+ }
243
+
235
244
  public getStartSpongeBlob() {
236
245
  return this.startSpongeBlob;
237
246
  }
@@ -11,6 +11,7 @@ import {
11
11
  type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
12
12
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
13
13
  NUM_MSGS_PER_BASE_PARITY,
14
+ OUT_HASH_TREE_HEIGHT,
14
15
  } from '@aztec/constants';
15
16
  import { BlockNumber } from '@aztec/foundation/branded-types';
16
17
  import { padArrayEnd } from '@aztec/foundation/collection';
@@ -19,6 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
19
20
  import type { Tuple } from '@aztec/foundation/serialize';
20
21
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
21
22
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
22
24
  import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
23
25
  import {
24
26
  BlockMergeRollupPrivateInputs,
@@ -38,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
38
40
  import { BlockProvingState, type ProofState } from './block-proving-state.js';
39
41
  import type { EpochProvingState } from './epoch-proving-state.js';
40
42
 
43
+ type OutHashHint = {
44
+ treeSnapshot: AppendOnlyTreeSnapshot;
45
+ siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
46
+ };
47
+
41
48
  export class CheckpointProvingState {
42
49
  private blockProofs: UnbalancedTreeStore<
43
50
  ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
@@ -46,6 +53,11 @@ export class CheckpointProvingState {
46
53
  | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
47
54
  | undefined;
48
55
  private blocks: (BlockProvingState | undefined)[] = [];
56
+ private previousOutHashHint: OutHashHint | undefined;
57
+ private outHash: Fr | undefined;
58
+ // The snapshot and sibling path after the checkpoint's out hash is inserted.
59
+ // Stored here to be retrieved for the next checkpoint when it's added.
60
+ private newOutHashHint: OutHashHint | undefined;
49
61
  private startBlobAccumulator: BatchedBlobAccumulator | undefined;
50
62
  private endBlobAccumulator: BatchedBlobAccumulator | undefined;
51
63
  private blobFields: Fr[] | undefined;
@@ -73,7 +85,7 @@ export class CheckpointProvingState {
73
85
  typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
74
86
  >,
75
87
  public parentEpoch: EpochProvingState,
76
- private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
88
+ private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
77
89
  ) {
78
90
  this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
79
91
  this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
@@ -192,7 +204,36 @@ export class CheckpointProvingState {
192
204
  Fr.ZERO,
193
205
  NUM_MSGS_PER_BASE_PARITY,
194
206
  );
195
- return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
207
+ return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot, this.constants.proverId);
208
+ }
209
+
210
+ public setOutHashHint(hint: OutHashHint) {
211
+ this.previousOutHashHint = hint;
212
+ }
213
+
214
+ public getOutHashHint() {
215
+ return this.previousOutHashHint;
216
+ }
217
+
218
+ public accumulateBlockOutHashes() {
219
+ if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
220
+ return;
221
+ }
222
+
223
+ if (!this.outHash) {
224
+ const messagesPerBlock = this.blocks.map(b => b!.getTxEffects().map(tx => tx.l2ToL1Msgs));
225
+ this.outHash = computeCheckpointOutHash(messagesPerBlock);
226
+ }
227
+
228
+ return this.outHash;
229
+ }
230
+
231
+ public setOutHashHintForNextCheckpoint(hint: OutHashHint) {
232
+ this.newOutHashHint = hint;
233
+ }
234
+
235
+ public getOutHashHintForNextCheckpoint() {
236
+ return this.newOutHashHint;
196
237
  }
197
238
 
198
239
  public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
@@ -204,7 +245,7 @@ export class CheckpointProvingState {
204
245
  this.endBlobAccumulator = await accumulateBlobs(this.blobFields!, startBlobAccumulator);
205
246
  this.startBlobAccumulator = startBlobAccumulator;
206
247
 
207
- this.onBlobAccumulatorSet(this);
248
+ await this.onBlobAccumulatorSet(this);
208
249
 
209
250
  return this.endBlobAccumulator;
210
251
  }
@@ -230,12 +271,15 @@ export class CheckpointProvingState {
230
271
  return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
231
272
  }
232
273
 
233
- public getCheckpointRootRollupInputs() {
274
+ public async getCheckpointRootRollupInputs() {
234
275
  const proofs = this.#getChildProofsForRoot();
235
276
  const nonEmptyProofs = proofs.filter(p => !!p);
236
277
  if (proofs.length !== nonEmptyProofs.length) {
237
278
  throw new Error('At least one child is not ready for the checkpoint root rollup.');
238
279
  }
280
+ if (!this.previousOutHashHint) {
281
+ throw new Error('Out hash hint is not set.');
282
+ }
239
283
  if (!this.startBlobAccumulator) {
240
284
  throw new Error('Start blob accumulator is not set.');
241
285
  }
@@ -243,11 +287,13 @@ export class CheckpointProvingState {
243
287
  // `blobFields` must've been set if `startBlobAccumulator` is set (in `accumulateBlobs`).
244
288
  const blobFields = this.blobFields!;
245
289
 
246
- const { blobCommitments, blobsHash } = buildBlobHints(blobFields);
290
+ const { blobCommitments, blobsHash } = await buildBlobHints(blobFields);
247
291
 
248
292
  const hints = CheckpointRootRollupHints.from({
249
293
  previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
250
294
  previousArchiveSiblingPath: this.lastArchiveSiblingPath,
295
+ previousOutHash: this.previousOutHashHint.treeSnapshot,
296
+ newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
251
297
  startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
252
298
  finalBlobChallenges: this.finalBlobBatchingChallenges,
253
299
  blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
@@ -273,7 +319,7 @@ export class CheckpointProvingState {
273
319
 
274
320
  public isReadyForCheckpointRoot() {
275
321
  const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
276
- return allChildProofsReady && !!this.startBlobAccumulator;
322
+ return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
277
323
  }
278
324
 
279
325
  public verifyState() {
@@ -300,4 +346,17 @@ export class CheckpointProvingState {
300
346
  ? [this.blockProofs.getNode(rootLocation)?.provingOutput] // If there's only 1 block, its proof will be stored at the root.
301
347
  : this.blockProofs.getChildren(rootLocation).map(c => c?.provingOutput);
302
348
  }
349
+
350
+ /**
351
+ * Returns the block-level proof outputs that feed into the checkpoint root rollup.
352
+ * Used by `CheckpointSubTreeOrchestrator` to surface its sub-tree result.
353
+ */
354
+ public getSubTreeOutputProofs() {
355
+ return this.#getChildProofsForRoot();
356
+ }
357
+
358
+ /** Sibling path of the archive tree captured before any block in this checkpoint landed. */
359
+ public getLastArchiveSiblingPath() {
360
+ return this.lastArchiveSiblingPath;
361
+ }
303
362
  }