@aztec/prover-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54

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 (127) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +13 -3
  4. package/dest/light/index.d.ts +2 -0
  5. package/dest/light/index.d.ts.map +1 -0
  6. package/dest/light/index.js +1 -0
  7. package/dest/light/lightweight_checkpoint_builder.d.ts +38 -14
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +148 -32
  10. package/dest/mocks/fixtures.d.ts +1 -1
  11. package/dest/mocks/fixtures.d.ts.map +1 -1
  12. package/dest/mocks/fixtures.js +6 -5
  13. package/dest/mocks/test_context.d.ts +5 -3
  14. package/dest/mocks/test_context.d.ts.map +1 -1
  15. package/dest/mocks/test_context.js +40 -18
  16. package/dest/orchestrator/block-building-helpers.d.ts +6 -6
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +7 -6
  19. package/dest/orchestrator/block-proving-state.d.ts +8 -4
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +8 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +22 -8
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +43 -8
  25. package/dest/orchestrator/epoch-proving-state.d.ts +10 -9
  26. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/epoch-proving-state.js +38 -2
  28. package/dest/orchestrator/orchestrator.d.ts +25 -8
  29. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator.js +568 -158
  31. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  32. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  33. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  34. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  35. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  36. package/dest/orchestrator/tx-proving-state.js +8 -8
  37. package/dest/prover-client/factory.d.ts +3 -3
  38. package/dest/prover-client/factory.d.ts.map +1 -1
  39. package/dest/prover-client/prover-client.d.ts +6 -6
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +15 -10
  42. package/dest/prover-client/server-epoch-prover.d.ts +5 -5
  43. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  44. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  45. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  46. package/dest/proving_broker/broker_prover_facade.js +18 -31
  47. package/dest/proving_broker/config.d.ts +15 -3
  48. package/dest/proving_broker/config.d.ts.map +1 -1
  49. package/dest/proving_broker/config.js +22 -5
  50. package/dest/proving_broker/fixtures.js +1 -1
  51. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  52. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  53. package/dest/proving_broker/proof_store/factory.js +7 -30
  54. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  55. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  56. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  57. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  58. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  59. package/dest/proving_broker/proof_store/index.js +1 -1
  60. package/dest/proving_broker/proving_agent.d.ts +5 -9
  61. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_agent.js +4 -19
  63. package/dest/proving_broker/proving_broker.d.ts +7 -4
  64. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_broker.js +60 -18
  66. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  67. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  68. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  69. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  70. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  71. package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
  72. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  73. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  74. package/dest/proving_broker/proving_job_controller.js +8 -6
  75. package/dest/proving_broker/rpc.d.ts +6 -2
  76. package/dest/proving_broker/rpc.d.ts.map +1 -1
  77. package/dest/proving_broker/rpc.js +24 -15
  78. package/dest/test/mock_proof_store.d.ts +3 -3
  79. package/dest/test/mock_proof_store.d.ts.map +1 -1
  80. package/dest/test/mock_prover.d.ts +5 -5
  81. package/dest/test/mock_prover.d.ts.map +1 -1
  82. package/dest/test/mock_prover.js +4 -4
  83. package/package.json +22 -22
  84. package/src/config.ts +14 -3
  85. package/src/light/index.ts +1 -0
  86. package/src/light/lightweight_checkpoint_builder.ts +215 -45
  87. package/src/mocks/fixtures.ts +6 -5
  88. package/src/mocks/test_context.ts +36 -19
  89. package/src/orchestrator/block-building-helpers.ts +7 -6
  90. package/src/orchestrator/block-proving-state.ts +12 -2
  91. package/src/orchestrator/checkpoint-proving-state.ts +60 -12
  92. package/src/orchestrator/epoch-proving-state.ts +66 -13
  93. package/src/orchestrator/orchestrator.ts +173 -147
  94. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  95. package/src/orchestrator/tx-proving-state.ts +10 -14
  96. package/src/prover-client/factory.ts +6 -2
  97. package/src/prover-client/prover-client.ts +33 -24
  98. package/src/prover-client/server-epoch-prover.ts +4 -4
  99. package/src/proving_broker/broker_prover_facade.ts +26 -36
  100. package/src/proving_broker/config.ts +25 -3
  101. package/src/proving_broker/fixtures.ts +1 -1
  102. package/src/proving_broker/proof_store/factory.ts +10 -32
  103. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  104. package/src/proving_broker/proof_store/index.ts +1 -1
  105. package/src/proving_broker/proving_agent.ts +6 -19
  106. package/src/proving_broker/proving_broker.ts +59 -13
  107. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  108. package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
  109. package/src/proving_broker/proving_job_controller.ts +11 -6
  110. package/src/proving_broker/rpc.ts +26 -3
  111. package/src/test/mock_prover.ts +2 -14
  112. package/dest/block-factory/index.d.ts +0 -2
  113. package/dest/block-factory/index.d.ts.map +0 -1
  114. package/dest/block-factory/index.js +0 -1
  115. package/dest/block-factory/light.d.ts +0 -38
  116. package/dest/block-factory/light.d.ts.map +0 -1
  117. package/dest/block-factory/light.js +0 -108
  118. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  119. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  120. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  121. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  122. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  123. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  124. package/src/block-factory/index.ts +0 -1
  125. package/src/block-factory/light.ts +0 -137
  126. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
  127. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,15 +1,26 @@
1
1
  import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
2
2
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
+ import { type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
3
4
  import { padArrayEnd } from '@aztec/foundation/collection';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import { L2BlockNew } from '@aztec/stdlib/block';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
7
+ import { elapsed } from '@aztec/foundation/timer';
8
+ import { L2Block } from '@aztec/stdlib/block';
7
9
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
8
10
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
9
- import { computeCheckpointOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
10
- import { CheckpointConstantData, CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
11
+ import {
12
+ accumulateCheckpointOutHashes,
13
+ computeCheckpointOutHash,
14
+ computeInHashFromL1ToL2Messages,
15
+ } from '@aztec/stdlib/messaging';
16
+ import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
11
17
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
12
- import { ContentCommitment, type GlobalVariables, type ProcessedTx, StateReference } from '@aztec/stdlib/tx';
18
+ import {
19
+ type CheckpointGlobalVariables,
20
+ type GlobalVariables,
21
+ type ProcessedTx,
22
+ StateReference,
23
+ } from '@aztec/stdlib/tx';
13
24
 
14
25
  import {
15
26
  buildHeaderAndBodyFromTxs,
@@ -20,31 +31,42 @@ import {
20
31
  /**
21
32
  * Builds a checkpoint and its header and the blocks in it from a set of processed tx without running any circuits.
22
33
  *
23
- * It updates the l1-to-l2 message tree when starting a new checkpoint, inserts the side effects to note hash,
24
- * nullifier, and public data trees, then updates the archive tree when a block is added.
34
+ * It updates the l1-to-l2 message tree when starting a new checkpoint, and then updates the archive tree when each block is added.
35
+ * Finally completes the checkpoint by computing its header.
25
36
  */
26
37
  export class LightweightCheckpointBuilder {
27
- private readonly logger = createLogger('lightweight-checkpoint-builder');
38
+ private readonly logger: Logger;
39
+
28
40
  private lastArchives: AppendOnlyTreeSnapshot[] = [];
29
41
  private spongeBlob: SpongeBlob;
30
- private blocks: L2BlockNew[] = [];
42
+ private blocks: L2Block[] = [];
31
43
  private blobFields: Fr[] = [];
32
44
 
33
45
  constructor(
34
- private checkpointNumber: number,
35
- private constants: CheckpointConstantData,
36
- private l1ToL2Messages: Fr[],
37
- private db: MerkleTreeWriteOperations,
46
+ public readonly checkpointNumber: CheckpointNumber,
47
+ public readonly constants: CheckpointGlobalVariables,
48
+ public feeAssetPriceModifier: bigint,
49
+ public readonly l1ToL2Messages: Fr[],
50
+ private readonly previousCheckpointOutHashes: Fr[],
51
+ public readonly db: MerkleTreeWriteOperations,
52
+ bindings?: LoggerBindings,
38
53
  ) {
54
+ this.logger = createLogger('checkpoint-builder', {
55
+ ...bindings,
56
+ instanceId: `checkpoint-${checkpointNumber}`,
57
+ });
39
58
  this.spongeBlob = SpongeBlob.init();
40
- this.logger.debug('Starting new checkpoint', { constants: constants.toInspect(), l1ToL2Messages });
59
+ this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages, feeAssetPriceModifier });
41
60
  }
42
61
 
43
62
  static async startNewCheckpoint(
44
- checkpointNumber: number,
45
- constants: CheckpointConstantData,
63
+ checkpointNumber: CheckpointNumber,
64
+ constants: CheckpointGlobalVariables,
46
65
  l1ToL2Messages: Fr[],
66
+ previousCheckpointOutHashes: Fr[],
47
67
  db: MerkleTreeWriteOperations,
68
+ bindings?: LoggerBindings,
69
+ feeAssetPriceModifier: bigint = 0n,
48
70
  ): Promise<LightweightCheckpointBuilder> {
49
71
  // Insert l1-to-l2 messages into the tree.
50
72
  await db.appendLeaves(
@@ -52,38 +74,165 @@ export class LightweightCheckpointBuilder {
52
74
  padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
53
75
  );
54
76
 
55
- return new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
77
+ return new LightweightCheckpointBuilder(
78
+ checkpointNumber,
79
+ constants,
80
+ feeAssetPriceModifier,
81
+ l1ToL2Messages,
82
+ previousCheckpointOutHashes,
83
+ db,
84
+ bindings,
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Resumes building a checkpoint from existing blocks. This is used for validator re-execution
90
+ * where blocks have already been built and their effects are already in the database.
91
+ * Unlike startNewCheckpoint, this does NOT append l1ToL2Messages to the tree since they
92
+ * were already added when the blocks were originally built.
93
+ */
94
+ static async resumeCheckpoint(
95
+ checkpointNumber: CheckpointNumber,
96
+ constants: CheckpointGlobalVariables,
97
+ feeAssetPriceModifier: bigint,
98
+ l1ToL2Messages: Fr[],
99
+ previousCheckpointOutHashes: Fr[],
100
+ db: MerkleTreeWriteOperations,
101
+ existingBlocks: L2Block[],
102
+ bindings?: LoggerBindings,
103
+ ): Promise<LightweightCheckpointBuilder> {
104
+ const builder = new LightweightCheckpointBuilder(
105
+ checkpointNumber,
106
+ constants,
107
+ feeAssetPriceModifier,
108
+ l1ToL2Messages,
109
+ previousCheckpointOutHashes,
110
+ db,
111
+ bindings,
112
+ );
113
+
114
+ builder.logger.debug('Resuming checkpoint from existing blocks', {
115
+ checkpointNumber,
116
+ numExistingBlocks: existingBlocks.length,
117
+ blockNumbers: existingBlocks.map(b => b.header.getBlockNumber()),
118
+ });
119
+
120
+ // Validate block order and consistency
121
+ for (let i = 1; i < existingBlocks.length; i++) {
122
+ const prev = existingBlocks[i - 1];
123
+ const curr = existingBlocks[i];
124
+ if (curr.number !== prev.number + 1) {
125
+ throw new Error(`Non-sequential block numbers in resumeCheckpoint: ${prev.number} -> ${curr.number}`);
126
+ }
127
+ if (!prev.archive.root.equals(curr.header.lastArchive.root)) {
128
+ throw new Error(`Archive root mismatch between blocks ${prev.number} and ${curr.number}`);
129
+ }
130
+ }
131
+
132
+ for (let i = 0; i < existingBlocks.length; i++) {
133
+ const block = existingBlocks[i];
134
+ const isFirstBlock = i === 0;
135
+
136
+ if (isFirstBlock) {
137
+ builder.lastArchives.push(block.header.lastArchive);
138
+ }
139
+
140
+ builder.lastArchives.push(block.archive);
141
+
142
+ const blockBlobFields = block.toBlobFields();
143
+ await builder.spongeBlob.absorb(blockBlobFields);
144
+ builder.blobFields.push(...blockBlobFields);
145
+
146
+ builder.blocks.push(block);
147
+ }
148
+
149
+ return builder;
150
+ }
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;
56
159
  }
57
160
 
58
- async addBlock(globalVariables: GlobalVariables, endState: StateReference, txs: ProcessedTx[]): Promise<L2BlockNew> {
161
+ /**
162
+ * Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
163
+ * this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
164
+ */
165
+ public async addBlock(
166
+ globalVariables: GlobalVariables,
167
+ txs: ProcessedTx[],
168
+ opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
169
+ ): Promise<{ block: L2Block; timings: Record<string, number> }> {
170
+ const timings: Record<string, number> = {};
59
171
  const isFirstBlock = this.blocks.length === 0;
172
+
173
+ // Empty blocks are only allowed as the first block in a checkpoint
174
+ if (!isFirstBlock && txs.length === 0) {
175
+ throw new Error('Cannot add empty block that is not the first block in the checkpoint.');
176
+ }
177
+
60
178
  if (isFirstBlock) {
61
- 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;
62
182
  }
63
183
 
64
184
  const lastArchive = this.lastArchives.at(-1)!;
65
185
 
66
- for (const tx of txs) {
67
- await insertSideEffects(tx, this.db);
186
+ if (opts.insertTxsEffects) {
187
+ this.logger.debug(
188
+ `Inserting side effects for ${txs.length} txs for block ${globalVariables.blockNumber} into db`,
189
+ { txs: txs.map(tx => tx.hash.toString()) },
190
+ );
191
+ let msInsertSideEffects = 0;
192
+ for (const tx of txs) {
193
+ const [ms] = await elapsed(() => insertSideEffects(tx, this.db));
194
+ msInsertSideEffects += ms;
195
+ }
196
+ timings.insertSideEffects = msInsertSideEffects;
197
+ }
198
+
199
+ const [msGetEndState, endState] = await elapsed(() => this.db.getStateReference());
200
+ timings.getEndState = msGetEndState;
201
+
202
+ if (opts.expectedEndState && !endState.equals(opts.expectedEndState)) {
203
+ this.logger.error('End state after processing txs does not match expected end state', {
204
+ globalVariables: globalVariables.toInspect(),
205
+ expectedEndState: opts.expectedEndState.toInspect(),
206
+ actualEndState: endState.toInspect(),
207
+ });
208
+ throw new Error(`End state does not match expected end state when building block ${globalVariables.blockNumber}`);
68
209
  }
69
210
 
70
- const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
71
- txs,
72
- lastArchive,
73
- endState,
74
- globalVariables,
75
- this.spongeBlob,
76
- isFirstBlock,
211
+ const [msBuildHeaderAndBody, { header, body, blockBlobFields }] = await elapsed(() =>
212
+ buildHeaderAndBodyFromTxs(txs, lastArchive, endState, globalVariables, this.spongeBlob, isFirstBlock),
77
213
  );
214
+ timings.buildHeaderAndBody = msBuildHeaderAndBody;
215
+
216
+ header.state.validate();
78
217
 
79
218
  await this.db.updateArchive(header);
80
- const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
219
+ const [msUpdateArchive, newArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
220
+ timings.updateArchive = msUpdateArchive;
81
221
  this.lastArchives.push(newArchive);
82
222
 
83
- const block = new L2BlockNew(newArchive, header, body);
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);
84
232
  this.blocks.push(block);
85
233
 
86
- await this.spongeBlob.absorb(blockBlobFields);
234
+ const [msSpongeAbsorb] = await elapsed(() => this.spongeBlob.absorb(blockBlobFields));
235
+ timings.spongeAbsorb = msSpongeAbsorb;
87
236
  this.blobFields.push(...blockBlobFields);
88
237
 
89
238
  this.logger.debug(`Built block ${header.getBlockNumber()}`, {
@@ -94,12 +243,12 @@ export class LightweightCheckpointBuilder {
94
243
  txs: block.body.txEffects.map(tx => tx.txHash.toString()),
95
244
  });
96
245
 
97
- return block;
246
+ return { block, timings };
98
247
  }
99
248
 
100
249
  async completeCheckpoint(): Promise<Checkpoint> {
101
250
  if (!this.blocks.length) {
102
- throw new Error('No blocks added to checkpoint.');
251
+ throw new Error('Cannot complete a checkpoint with no blocks');
103
252
  }
104
253
 
105
254
  const numBlobFields = this.blobFields.length + 1; // +1 for the checkpoint end marker.
@@ -111,32 +260,53 @@ export class LightweightCheckpointBuilder {
111
260
 
112
261
  const newArchive = this.lastArchives[this.lastArchives.length - 1];
113
262
 
114
- const blobs = getBlobsPerL1Block(this.blobFields);
263
+ const blobs = await getBlobsPerL1Block(this.blobFields);
115
264
  const blobsHash = computeBlobsHashFromBlobs(blobs);
116
265
 
117
266
  const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
118
267
 
119
- const outHash = computeCheckpointOutHash(blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)));
120
-
121
- const constants = this.constants!;
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]);
122
273
 
123
- // timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
274
+ // All blocks in the checkpoint have the same timestamp
124
275
  const timestamp = blocks[blocks.length - 1].timestamp;
125
276
 
126
277
  const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
127
278
 
128
279
  const header = CheckpointHeader.from({
129
280
  lastArchiveRoot: this.lastArchives[0].root,
281
+ blobsHash,
282
+ inHash,
283
+ epochOutHash,
130
284
  blockHeadersHash,
131
- contentCommitment: new ContentCommitment(blobsHash, inHash, outHash),
132
- slotNumber: constants.slotNumber,
285
+ slotNumber,
133
286
  timestamp,
134
- coinbase: constants.coinbase,
135
- feeRecipient: constants.feeRecipient,
136
- gasFees: constants.gasFees,
287
+ coinbase,
288
+ feeRecipient,
289
+ gasFees,
137
290
  totalManaUsed,
138
291
  });
139
292
 
140
- return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
293
+ return new Checkpoint(newArchive, header, blocks, this.checkpointNumber, this.feeAssetPriceModifier);
294
+ }
295
+
296
+ clone() {
297
+ const clone = new LightweightCheckpointBuilder(
298
+ this.checkpointNumber,
299
+ this.constants,
300
+ this.feeAssetPriceModifier,
301
+ [...this.l1ToL2Messages],
302
+ [...this.previousCheckpointOutHashes],
303
+ this.db,
304
+ this.logger.getBindings(),
305
+ );
306
+ clone.lastArchives = [...this.lastArchives];
307
+ clone.spongeBlob = this.spongeBlob.clone();
308
+ clone.blocks = [...this.blocks];
309
+ clone.blobFields = [...this.blobFields];
310
+ return clone;
141
311
  }
142
312
  }
@@ -1,7 +1,7 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import { randomBytes } from '@aztec/foundation/crypto';
1
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { randomBytes } from '@aztec/foundation/crypto/random';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import type { Logger } from '@aztec/foundation/log';
6
6
  import type { FieldsOf } from '@aztec/foundation/types';
7
7
  import { fileURLToPath } from '@aztec/foundation/url';
@@ -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
  }
@@ -93,7 +94,7 @@ export const makeGlobals = (
93
94
  return GlobalVariables.from({
94
95
  chainId: checkpointConstants.chainId,
95
96
  version: checkpointConstants.version,
96
- blockNumber /** block number */,
97
+ blockNumber: BlockNumber(blockNumber) /** block number */,
97
98
  slotNumber: SlotNumber(slotNumber) /** slot number */,
98
99
  timestamp: BigInt(blockNumber * 123) /** block number * 123 as pseudo-timestamp for testing */,
99
100
  coinbase: checkpointConstants.coinbase,
@@ -1,8 +1,9 @@
1
1
  import type { BBProverConfig } from '@aztec/bb-prover';
2
2
  import { TestCircuitProver } from '@aztec/bb-prover';
3
3
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
4
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
4
5
  import { padArrayEnd, times, timesAsync } from '@aztec/foundation/collection';
5
- import { Fr } from '@aztec/foundation/fields';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
7
  import type { Logger } from '@aztec/foundation/log';
7
8
  import type { FieldsOf } from '@aztec/foundation/types';
8
9
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
@@ -23,6 +24,7 @@ import {
23
24
  StateReference,
24
25
  TreeSnapshots,
25
26
  } from '@aztec/stdlib/tx';
27
+ import type { GenesisData } from '@aztec/stdlib/world-state';
26
28
  import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
27
29
  import { NativeWorldStateService } from '@aztec/world-state/native';
28
30
 
@@ -43,7 +45,9 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
43
45
  export class TestContext {
44
46
  private headers: Map<number, BlockHeader> = new Map();
45
47
  private checkpoints: Checkpoint[] = [];
48
+ private checkpointOutHashes: Fr[] = [];
46
49
  private nextCheckpointIndex = 0;
50
+ private nextCheckpointNumber = CheckpointNumber(1);
47
51
  private nextBlockNumber = 1;
48
52
  private epochNumber = 1;
49
53
  private feePayerBalance: Fr;
@@ -81,14 +85,13 @@ export class TestContext {
81
85
  const feePayer = AztecAddress.fromNumber(42222);
82
86
  const initialFeePayerBalance = new Fr(10n ** 20n);
83
87
  const feePayerSlot = await computeFeePayerBalanceLeafSlot(feePayer);
84
- const prefilledPublicData = [new PublicDataTreeLeaf(feePayerSlot, initialFeePayerBalance)];
88
+ const genesis: GenesisData = {
89
+ prefilledPublicData: [new PublicDataTreeLeaf(feePayerSlot, initialFeePayerBalance)],
90
+ genesisTimestamp: 0n,
91
+ };
85
92
 
86
93
  // Separated dbs for public processor and prover - see public_processor for context
87
- const ws = await NativeWorldStateService.tmp(
88
- /*rollupAddress=*/ undefined,
89
- /*cleanupTmpDir=*/ true,
90
- prefilledPublicData,
91
- );
94
+ const ws = await NativeWorldStateService.tmp(/*rollupAddress=*/ undefined, /*cleanupTmpDir=*/ true, genesis);
92
95
 
93
96
  let localProver: ServerCircuitProver;
94
97
  const config = await getEnvironmentConfig(logger);
@@ -101,8 +104,10 @@ export class TestContext {
101
104
  bbBinaryPath: config.expectedBBPath,
102
105
  bbWorkingDirectory: config.bbWorkingDirectory,
103
106
  bbSkipCleanup: config.bbSkipCleanup,
104
- numConcurrentIVCVerifiers: 2,
107
+ numConcurrentIVCVerifiers: 8,
105
108
  bbIVCConcurrency: 1,
109
+ bbChonkVerifyMaxBatch: 16,
110
+ bbChonkVerifyConcurrency: 6,
106
111
  };
107
112
  localProver = await createProver(bbConfig);
108
113
  }
@@ -113,7 +118,7 @@ export class TestContext {
113
118
 
114
119
  const broker = new TestBroker(proverCount, localProver);
115
120
  const facade = new BrokerCircuitProverFacade(broker);
116
- const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
121
+ const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO, false, 10);
117
122
 
118
123
  await broker.start();
119
124
  facade.start();
@@ -149,6 +154,7 @@ export class TestContext {
149
154
 
150
155
  public startNewEpoch() {
151
156
  this.checkpoints = [];
157
+ this.checkpointOutHashes = [];
152
158
  this.nextCheckpointIndex = 0;
153
159
  this.epochNumber++;
154
160
  }
@@ -186,7 +192,8 @@ export class TestContext {
186
192
  }
187
193
 
188
194
  const checkpointIndex = this.nextCheckpointIndex++;
189
- const checkpointNumber = checkpointIndex + 1;
195
+ const checkpointNumber = this.nextCheckpointNumber;
196
+ this.nextCheckpointNumber++;
190
197
  const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
191
198
 
192
199
  const constants = makeCheckpointConstants(slotNumber, constantOpts);
@@ -202,7 +209,9 @@ export class TestContext {
202
209
  const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
203
210
 
204
211
  const startBlockNumber = this.nextBlockNumber;
205
- const previousBlockHeader = this.getBlockHeader(startBlockNumber - 1);
212
+ const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
213
+ // All blocks in the same slot/checkpoint share the same timestamp.
214
+ const timestamp = BigInt(slotNumber * 26);
206
215
 
207
216
  // Build global variables.
208
217
  const blockGlobalVariables = times(numBlocks, i =>
@@ -210,6 +219,7 @@ export class TestContext {
210
219
  coinbase: constants.coinbase,
211
220
  feeRecipient: constants.feeRecipient,
212
221
  gasFees: constants.gasFees,
222
+ timestamp,
213
223
  }),
214
224
  );
215
225
  this.nextBlockNumber += numBlocks;
@@ -239,33 +249,38 @@ export class TestContext {
239
249
  });
240
250
 
241
251
  const cleanFork = await this.worldState.fork();
252
+ const previousCheckpointOutHashes = this.checkpointOutHashes;
242
253
  const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
243
254
  checkpointNumber,
244
- constants,
255
+ { ...constants, timestamp },
245
256
  l1ToL2Messages,
257
+ previousCheckpointOutHashes,
246
258
  cleanFork,
247
259
  );
248
260
 
249
261
  // Add tx effects to db and build block headers.
250
262
  const blocks = [];
251
263
  for (let i = 0; i < numBlocks; i++) {
252
- const isFirstBlock = i === 0;
253
264
  const txs = blockTxs[i];
254
265
  const state = blockEndStates[i];
255
266
 
256
- const block = await builder.addBlock(blockGlobalVariables[i], state, txs);
267
+ const { block } = await builder.addBlock(blockGlobalVariables[i], txs, {
268
+ expectedEndState: state,
269
+ insertTxsEffects: true,
270
+ });
257
271
 
258
272
  const header = block.header;
259
273
  this.headers.set(block.number, header);
260
274
 
261
- const blockMsgs = isFirstBlock ? l1ToL2Messages : [];
262
- await this.worldState.handleL2BlockAndMessages(block, blockMsgs, isFirstBlock);
275
+ const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
276
+ await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
263
277
 
264
278
  blocks.push({ header, txs });
265
279
  }
266
280
 
267
281
  const checkpoint = await builder.completeCheckpoint();
268
282
  this.checkpoints.push(checkpoint);
283
+ this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
269
284
 
270
285
  return {
271
286
  constants,
@@ -296,11 +311,13 @@ export class TestContext {
296
311
  return tx;
297
312
  }
298
313
 
299
- private getBlockHeader(blockNumber: number): BlockHeader {
300
- if (blockNumber > 0 && blockNumber >= this.nextBlockNumber) {
314
+ private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
315
+ if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
301
316
  throw new Error(`Block header not built for block number ${blockNumber}.`);
302
317
  }
303
- return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber)!;
318
+ return Number(blockNumber) === 0
319
+ ? this.worldState.getCommitted().getInitialHeader()
320
+ : this.headers.get(Number(blockNumber))!;
304
321
  }
305
322
 
306
323
  private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
@@ -20,8 +20,9 @@ import {
20
20
  PUBLIC_DATA_TREE_HEIGHT,
21
21
  } from '@aztec/constants';
22
22
  import { makeTuple } from '@aztec/foundation/array';
23
+ import { BlockNumber } from '@aztec/foundation/branded-types';
23
24
  import { padArrayEnd } from '@aztec/foundation/collection';
24
- import { Fr } from '@aztec/foundation/fields';
25
+ import { Fr } from '@aztec/foundation/curves/bn254';
25
26
  import { type Bufferable, assertLength, toFriendlyJSON } from '@aztec/foundation/serialize';
26
27
  import { MembershipWitness } from '@aztec/foundation/trees';
27
28
  import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
@@ -98,7 +99,7 @@ export const insertSideEffectsAndBuildBaseRollupHints = runInSpan(
98
99
 
99
100
  const blockHash = await tx.data.constants.anchorBlockHeader.hash();
100
101
  const anchorBlockArchiveSiblingPath = (
101
- await getMembershipWitnessFor(blockHash, MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
102
+ await getMembershipWitnessFor(blockHash.toFr(), MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
102
103
  ).siblingPath;
103
104
 
104
105
  const contractClassLogsFields = makeTuple(
@@ -252,8 +253,8 @@ export function getPublicChonkVerifierPrivateInputsFromTx(tx: Tx | ProcessedTx,
252
253
  // Build "hints" as the private inputs for the checkpoint root rollup circuit.
253
254
  // The `blobCommitments` will be accumulated and checked in the root rollup against the `finalBlobChallenges`.
254
255
  // The `blobsHash` will be validated on L1 against the submitted blob data.
255
- export const buildBlobHints = (blobFields: Fr[]) => {
256
- const blobs = getBlobsPerL1Block(blobFields);
256
+ export const buildBlobHints = async (blobFields: Fr[]) => {
257
+ const blobs = await getBlobsPerL1Block(blobFields);
257
258
  const blobCommitments = getBlobCommitmentsFromBlobs(blobs);
258
259
  const blobsHash = computeBlobsHashFromBlobs(blobs);
259
260
  return { blobCommitments, blobs, blobsHash };
@@ -280,8 +281,8 @@ export const buildHeaderFromCircuitOutputs = runInSpan(
280
281
  const globalVariables = GlobalVariables.from({
281
282
  chainId: constants.chainId,
282
283
  version: constants.version,
283
- blockNumber: blockRootRollupOutput.previousArchive.nextAvailableLeafIndex,
284
- timestamp: blockRootRollupOutput.endTimestamp,
284
+ blockNumber: BlockNumber(blockRootRollupOutput.previousArchive.nextAvailableLeafIndex),
285
+ timestamp: blockRootRollupOutput.timestamp,
285
286
  slotNumber: constants.slotNumber,
286
287
  coinbase: constants.coinbase,
287
288
  feeRecipient: constants.feeRecipient,
@@ -6,7 +6,8 @@ import {
6
6
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
7
7
  NUM_BASE_PARITY_PER_ROOT_PARITY,
8
8
  } from '@aztec/constants';
9
- import { Fr } from '@aztec/foundation/fields';
9
+ import { BlockNumber } from '@aztec/foundation/branded-types';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
11
  import { type Tuple, assertLength } from '@aztec/foundation/serialize';
11
12
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
12
13
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
@@ -54,6 +55,7 @@ export class BlockProvingState {
54
55
  | ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
55
56
  | undefined;
56
57
  private builtBlockHeader: BlockHeader | undefined;
58
+ private builtArchive: AppendOnlyTreeSnapshot | undefined;
57
59
  private endState: StateReference | undefined;
58
60
  private endSpongeBlob: SpongeBlob | undefined;
59
61
  private txs: TxProvingState[] = [];
@@ -62,7 +64,7 @@ export class BlockProvingState {
62
64
 
63
65
  constructor(
64
66
  public readonly index: number,
65
- public readonly blockNumber: number,
67
+ public readonly blockNumber: BlockNumber,
66
68
  public readonly totalNumTxs: number,
67
69
  private readonly constants: CheckpointConstantData,
68
70
  private readonly timestamp: UInt64,
@@ -231,6 +233,14 @@ export class BlockProvingState {
231
233
  return this.builtBlockHeader;
232
234
  }
233
235
 
236
+ public setBuiltArchive(archive: AppendOnlyTreeSnapshot) {
237
+ this.builtArchive = archive;
238
+ }
239
+
240
+ public getBuiltArchive() {
241
+ return this.builtArchive;
242
+ }
243
+
234
244
  public getStartSpongeBlob() {
235
245
  return this.startSpongeBlob;
236
246
  }