@aztec/prover-client 0.0.1-commit.fffb133c → 0.0.1-dev

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 (80) hide show
  1. package/dest/light/lightweight_checkpoint_builder.d.ts +9 -4
  2. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  3. package/dest/light/lightweight_checkpoint_builder.js +28 -13
  4. package/dest/mocks/fixtures.d.ts +1 -1
  5. package/dest/mocks/fixtures.d.ts.map +1 -1
  6. package/dest/mocks/fixtures.js +2 -1
  7. package/dest/mocks/test_context.js +5 -2
  8. package/dest/orchestrator/block-building-helpers.d.ts +4 -4
  9. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  10. package/dest/orchestrator/block-building-helpers.js +4 -4
  11. package/dest/orchestrator/block-proving-state.d.ts +4 -1
  12. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  13. package/dest/orchestrator/block-proving-state.js +7 -0
  14. package/dest/orchestrator/checkpoint-proving-state.d.ts +3 -3
  15. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  16. package/dest/orchestrator/checkpoint-proving-state.js +3 -3
  17. package/dest/orchestrator/epoch-proving-state.d.ts +3 -3
  18. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  19. package/dest/orchestrator/epoch-proving-state.js +5 -3
  20. package/dest/orchestrator/orchestrator.d.ts +7 -3
  21. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  22. package/dest/orchestrator/orchestrator.js +125 -117
  23. package/dest/prover-client/prover-client.d.ts +4 -4
  24. package/dest/prover-client/prover-client.d.ts.map +1 -1
  25. package/dest/prover-client/prover-client.js +15 -10
  26. package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
  27. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  28. package/dest/proving_broker/broker_prover_facade.js +6 -6
  29. package/dest/proving_broker/config.d.ts +9 -1
  30. package/dest/proving_broker/config.d.ts.map +1 -1
  31. package/dest/proving_broker/config.js +13 -2
  32. package/dest/proving_broker/proof_store/factory.d.ts +2 -5
  33. package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
  34. package/dest/proving_broker/proof_store/factory.js +7 -30
  35. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
  36. package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
  37. package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
  38. package/dest/proving_broker/proof_store/index.d.ts +2 -2
  39. package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
  40. package/dest/proving_broker/proof_store/index.js +1 -1
  41. package/dest/proving_broker/proving_agent.d.ts +4 -3
  42. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  43. package/dest/proving_broker/proving_agent.js +4 -4
  44. package/dest/proving_broker/proving_broker.d.ts +7 -4
  45. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  46. package/dest/proving_broker/proving_broker.js +36 -4
  47. package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
  48. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  49. package/dest/proving_broker/proving_broker_instrumentation.js +18 -7
  50. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  51. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  52. package/dest/proving_broker/proving_job_controller.js +6 -3
  53. package/dest/proving_broker/rpc.d.ts +6 -2
  54. package/dest/proving_broker/rpc.d.ts.map +1 -1
  55. package/dest/proving_broker/rpc.js +24 -15
  56. package/dest/test/mock_prover.d.ts +4 -4
  57. package/package.json +15 -16
  58. package/src/light/lightweight_checkpoint_builder.ts +38 -7
  59. package/src/mocks/fixtures.ts +2 -1
  60. package/src/mocks/test_context.ts +2 -2
  61. package/src/orchestrator/block-building-helpers.ts +4 -4
  62. package/src/orchestrator/block-proving-state.ts +9 -0
  63. package/src/orchestrator/checkpoint-proving-state.ts +4 -4
  64. package/src/orchestrator/epoch-proving-state.ts +6 -4
  65. package/src/orchestrator/orchestrator.ts +135 -125
  66. package/src/prover-client/prover-client.ts +24 -14
  67. package/src/proving_broker/broker_prover_facade.ts +15 -7
  68. package/src/proving_broker/config.ts +13 -0
  69. package/src/proving_broker/proof_store/factory.ts +10 -32
  70. package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
  71. package/src/proving_broker/proof_store/index.ts +1 -1
  72. package/src/proving_broker/proving_agent.ts +5 -2
  73. package/src/proving_broker/proving_broker.ts +37 -3
  74. package/src/proving_broker/proving_broker_instrumentation.ts +19 -6
  75. package/src/proving_broker/proving_job_controller.ts +9 -3
  76. package/src/proving_broker/rpc.ts +26 -3
  77. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
  78. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
  79. package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
  80. package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
@@ -3,7 +3,7 @@ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
3
  import { type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
4
4
  import { padArrayEnd } from '@aztec/foundation/collection';
5
5
  import { Fr } from '@aztec/foundation/curves/bn254';
6
- import { createLogger } from '@aztec/foundation/log';
6
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
7
7
  import { L2Block } from '@aztec/stdlib/block';
8
8
  import { Checkpoint } from '@aztec/stdlib/checkpoint';
9
9
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
@@ -34,7 +34,7 @@ import {
34
34
  * Finally completes the checkpoint by computing its header.
35
35
  */
36
36
  export class LightweightCheckpointBuilder {
37
- private readonly logger = createLogger('lightweight-checkpoint-builder');
37
+ private readonly logger: Logger;
38
38
 
39
39
  private lastArchives: AppendOnlyTreeSnapshot[] = [];
40
40
  private spongeBlob: SpongeBlob;
@@ -44,12 +44,18 @@ export class LightweightCheckpointBuilder {
44
44
  constructor(
45
45
  public readonly checkpointNumber: CheckpointNumber,
46
46
  public readonly constants: CheckpointGlobalVariables,
47
+ public feeAssetPriceModifier: bigint,
47
48
  public readonly l1ToL2Messages: Fr[],
48
49
  private readonly previousCheckpointOutHashes: Fr[],
49
50
  public readonly db: MerkleTreeWriteOperations,
51
+ bindings?: LoggerBindings,
50
52
  ) {
53
+ this.logger = createLogger('checkpoint-builder', {
54
+ ...bindings,
55
+ instanceId: `checkpoint-${checkpointNumber}`,
56
+ });
51
57
  this.spongeBlob = SpongeBlob.init();
52
- this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages });
58
+ this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages, feeAssetPriceModifier });
53
59
  }
54
60
 
55
61
  static async startNewCheckpoint(
@@ -58,6 +64,8 @@ export class LightweightCheckpointBuilder {
58
64
  l1ToL2Messages: Fr[],
59
65
  previousCheckpointOutHashes: Fr[],
60
66
  db: MerkleTreeWriteOperations,
67
+ bindings?: LoggerBindings,
68
+ feeAssetPriceModifier: bigint = 0n,
61
69
  ): Promise<LightweightCheckpointBuilder> {
62
70
  // Insert l1-to-l2 messages into the tree.
63
71
  await db.appendLeaves(
@@ -68,9 +76,11 @@ export class LightweightCheckpointBuilder {
68
76
  return new LightweightCheckpointBuilder(
69
77
  checkpointNumber,
70
78
  constants,
79
+ feeAssetPriceModifier,
71
80
  l1ToL2Messages,
72
81
  previousCheckpointOutHashes,
73
82
  db,
83
+ bindings,
74
84
  );
75
85
  }
76
86
 
@@ -83,17 +93,21 @@ export class LightweightCheckpointBuilder {
83
93
  static async resumeCheckpoint(
84
94
  checkpointNumber: CheckpointNumber,
85
95
  constants: CheckpointGlobalVariables,
96
+ feeAssetPriceModifier: bigint,
86
97
  l1ToL2Messages: Fr[],
87
98
  previousCheckpointOutHashes: Fr[],
88
99
  db: MerkleTreeWriteOperations,
89
100
  existingBlocks: L2Block[],
101
+ bindings?: LoggerBindings,
90
102
  ): Promise<LightweightCheckpointBuilder> {
91
103
  const builder = new LightweightCheckpointBuilder(
92
104
  checkpointNumber,
93
105
  constants,
106
+ feeAssetPriceModifier,
94
107
  l1ToL2Messages,
95
108
  previousCheckpointOutHashes,
96
109
  db,
110
+ bindings,
97
111
  );
98
112
 
99
113
  builder.logger.debug('Resuming checkpoint from existing blocks', {
@@ -134,6 +148,15 @@ export class LightweightCheckpointBuilder {
134
148
  return builder;
135
149
  }
136
150
 
151
+ /** Returns how many blocks have been added to this checkpoint so far */
152
+ public getBlockCount() {
153
+ return this.blocks.length;
154
+ }
155
+
156
+ public getBlocks() {
157
+ return this.blocks;
158
+ }
159
+
137
160
  /**
138
161
  * Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
139
162
  * this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
@@ -191,6 +214,13 @@ export class LightweightCheckpointBuilder {
191
214
  const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
192
215
  this.lastArchives.push(newArchive);
193
216
 
217
+ const expectedNextLeafIndex = Number(globalVariables.blockNumber) + 1;
218
+ if (newArchive.nextAvailableLeafIndex !== expectedNextLeafIndex) {
219
+ throw new Error(
220
+ `Archive tree next leaf index mismatch after building block ${globalVariables.blockNumber} (expected ${expectedNextLeafIndex} but got ${newArchive.nextAvailableLeafIndex})`,
221
+ );
222
+ }
223
+
194
224
  const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
195
225
  const block = new L2Block(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
196
226
  this.blocks.push(block);
@@ -223,7 +253,7 @@ export class LightweightCheckpointBuilder {
223
253
 
224
254
  const newArchive = this.lastArchives[this.lastArchives.length - 1];
225
255
 
226
- const blobs = getBlobsPerL1Block(this.blobFields);
256
+ const blobs = await getBlobsPerL1Block(this.blobFields);
227
257
  const blobsHash = computeBlobsHashFromBlobs(blobs);
228
258
 
229
259
  const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
@@ -234,8 +264,7 @@ export class LightweightCheckpointBuilder {
234
264
  );
235
265
  const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
236
266
 
237
- // TODO(palla/mbps): Should we source this from the constants instead?
238
- // timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
267
+ // All blocks in the checkpoint have the same timestamp
239
268
  const timestamp = blocks[blocks.length - 1].timestamp;
240
269
 
241
270
  const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
@@ -254,16 +283,18 @@ export class LightweightCheckpointBuilder {
254
283
  totalManaUsed,
255
284
  });
256
285
 
257
- return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
286
+ return new Checkpoint(newArchive, header, blocks, this.checkpointNumber, this.feeAssetPriceModifier);
258
287
  }
259
288
 
260
289
  clone() {
261
290
  const clone = new LightweightCheckpointBuilder(
262
291
  this.checkpointNumber,
263
292
  this.constants,
293
+ this.feeAssetPriceModifier,
264
294
  [...this.l1ToL2Messages],
265
295
  [...this.previousCheckpointOutHashes],
266
296
  this.db,
297
+ this.logger.getBindings(),
267
298
  );
268
299
  clone.lastArchives = [...this.lastArchives];
269
300
  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
  }
@@ -116,7 +116,7 @@ export class TestContext {
116
116
 
117
117
  const broker = new TestBroker(proverCount, localProver);
118
118
  const facade = new BrokerCircuitProverFacade(broker);
119
- const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
119
+ const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO, false, 10);
120
120
 
121
121
  await broker.start();
122
122
  facade.start();
@@ -250,7 +250,7 @@ export class TestContext {
250
250
  const previousCheckpointOutHashes = this.checkpointOutHashes;
251
251
  const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
252
252
  checkpointNumber,
253
- constants,
253
+ { ...constants, timestamp },
254
254
  l1ToL2Messages,
255
255
  previousCheckpointOutHashes,
256
256
  cleanFork,
@@ -97,9 +97,9 @@ export const insertSideEffectsAndBuildBaseRollupHints = runInSpan(
97
97
 
98
98
  const { nullifierInsertionResult, publicDataInsertionResult } = await insertSideEffects(tx, db);
99
99
 
100
- const blockHash = (await tx.data.constants.anchorBlockHeader.hash()).toField();
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
  }
@@ -85,7 +85,7 @@ export class CheckpointProvingState {
85
85
  typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
86
86
  >,
87
87
  public parentEpoch: EpochProvingState,
88
- private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
88
+ private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
89
89
  ) {
90
90
  this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
91
91
  this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
@@ -245,7 +245,7 @@ export class CheckpointProvingState {
245
245
  this.endBlobAccumulator = await accumulateBlobs(this.blobFields!, startBlobAccumulator);
246
246
  this.startBlobAccumulator = startBlobAccumulator;
247
247
 
248
- this.onBlobAccumulatorSet(this);
248
+ await this.onBlobAccumulatorSet(this);
249
249
 
250
250
  return this.endBlobAccumulator;
251
251
  }
@@ -271,7 +271,7 @@ export class CheckpointProvingState {
271
271
  return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
272
272
  }
273
273
 
274
- public getCheckpointRootRollupInputs() {
274
+ public async getCheckpointRootRollupInputs() {
275
275
  const proofs = this.#getChildProofsForRoot();
276
276
  const nonEmptyProofs = proofs.filter(p => !!p);
277
277
  if (proofs.length !== nonEmptyProofs.length) {
@@ -287,7 +287,7 @@ export class CheckpointProvingState {
287
287
  // `blobFields` must've been set if `startBlobAccumulator` is set (in `accumulateBlobs`).
288
288
  const blobFields = this.blobFields!;
289
289
 
290
- const { blobCommitments, blobsHash } = buildBlobHints(blobFields);
290
+ const { blobCommitments, blobsHash } = await buildBlobHints(blobFields);
291
291
 
292
292
  const hints = CheckpointRootRollupHints.from({
293
293
  previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
@@ -76,7 +76,7 @@ export class EpochProvingState {
76
76
  public readonly epochNumber: EpochNumber,
77
77
  public readonly totalNumCheckpoints: number,
78
78
  private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
79
- private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
79
+ private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
80
80
  private completionCallback: (result: ProvingResult) => void,
81
81
  private rejectionCallback: (reason: string) => void,
82
82
  ) {
@@ -254,9 +254,11 @@ export class EpochProvingState {
254
254
  }
255
255
  outHashes.push(outHash);
256
256
 
257
- // Get or create hints for the next checkpoint.
258
- hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
259
- checkpoint.setOutHashHintForNextCheckpoint(hint);
257
+ // If this is NOT the last checkpoint, get or create the hint for the next checkpoint.
258
+ if (i !== this.totalNumCheckpoints - 1) {
259
+ hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
260
+ checkpoint.setOutHashHintForNextCheckpoint(hint);
261
+ }
260
262
  }
261
263
  }
262
264