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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +1 -1
  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 +33 -14
  8. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  9. package/dest/light/lightweight_checkpoint_builder.js +116 -23
  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 +25 -11
  16. package/dest/orchestrator/block-building-helpers.d.ts +4 -4
  17. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  18. package/dest/orchestrator/block-building-helpers.js +5 -4
  19. package/dest/orchestrator/block-proving-state.d.ts +5 -4
  20. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/block-proving-state.js +1 -1
  22. package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -6
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  24. package/dest/orchestrator/checkpoint-proving-state.js +40 -5
  25. package/dest/orchestrator/epoch-proving-state.d.ts +8 -7
  26. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  27. package/dest/orchestrator/epoch-proving-state.js +36 -2
  28. package/dest/orchestrator/orchestrator.d.ts +23 -8
  29. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  30. package/dest/orchestrator/orchestrator.js +540 -137
  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 +3 -3
  40. package/dest/prover-client/prover-client.d.ts.map +1 -1
  41. package/dest/prover-client/prover-client.js +7 -4
  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 +6 -13
  47. package/dest/proving_broker/config.d.ts +6 -2
  48. package/dest/proving_broker/config.d.ts.map +1 -1
  49. package/dest/proving_broker/config.js +8 -2
  50. package/dest/proving_broker/fixtures.js +1 -1
  51. package/dest/proving_broker/proving_agent.d.ts +5 -9
  52. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  53. package/dest/proving_broker/proving_agent.js +4 -19
  54. package/dest/proving_broker/proving_broker.d.ts +1 -1
  55. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  56. package/dest/proving_broker/proving_broker.js +4 -10
  57. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  58. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  59. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  60. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  61. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  62. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  63. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  64. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  65. package/dest/proving_broker/proving_job_controller.js +8 -6
  66. package/dest/test/mock_proof_store.d.ts +3 -3
  67. package/dest/test/mock_proof_store.d.ts.map +1 -1
  68. package/dest/test/mock_prover.d.ts +2 -2
  69. package/dest/test/mock_prover.d.ts.map +1 -1
  70. package/dest/test/mock_prover.js +4 -4
  71. package/package.json +20 -19
  72. package/src/config.ts +1 -1
  73. package/src/light/index.ts +1 -0
  74. package/src/light/lightweight_checkpoint_builder.ts +178 -31
  75. package/src/mocks/fixtures.ts +6 -5
  76. package/src/mocks/test_context.ts +25 -10
  77. package/src/orchestrator/block-building-helpers.ts +5 -4
  78. package/src/orchestrator/block-proving-state.ts +3 -2
  79. package/src/orchestrator/checkpoint-proving-state.ts +56 -8
  80. package/src/orchestrator/epoch-proving-state.ts +63 -12
  81. package/src/orchestrator/orchestrator.ts +138 -121
  82. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  83. package/src/orchestrator/tx-proving-state.ts +10 -14
  84. package/src/prover-client/factory.ts +6 -2
  85. package/src/prover-client/prover-client.ts +25 -15
  86. package/src/prover-client/server-epoch-prover.ts +4 -4
  87. package/src/proving_broker/broker_prover_facade.ts +10 -17
  88. package/src/proving_broker/config.ts +10 -1
  89. package/src/proving_broker/fixtures.ts +1 -1
  90. package/src/proving_broker/proving_agent.ts +6 -19
  91. package/src/proving_broker/proving_broker.ts +4 -8
  92. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  93. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  94. package/src/proving_broker/proving_job_controller.ts +11 -6
  95. package/src/test/mock_prover.ts +2 -14
  96. package/dest/block-factory/index.d.ts +0 -2
  97. package/dest/block-factory/index.d.ts.map +0 -1
  98. package/dest/block-factory/index.js +0 -1
  99. package/dest/block-factory/light.d.ts +0 -38
  100. package/dest/block-factory/light.d.ts.map +0 -1
  101. package/dest/block-factory/light.js +0 -108
  102. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  103. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  104. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  105. package/src/block-factory/index.ts +0 -1
  106. package/src/block-factory/light.ts +0 -137
  107. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -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';
@@ -43,7 +44,9 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
43
44
  export class TestContext {
44
45
  private headers: Map<number, BlockHeader> = new Map();
45
46
  private checkpoints: Checkpoint[] = [];
47
+ private checkpointOutHashes: Fr[] = [];
46
48
  private nextCheckpointIndex = 0;
49
+ private nextCheckpointNumber = CheckpointNumber(1);
47
50
  private nextBlockNumber = 1;
48
51
  private epochNumber = 1;
49
52
  private feePayerBalance: Fr;
@@ -149,6 +152,7 @@ export class TestContext {
149
152
 
150
153
  public startNewEpoch() {
151
154
  this.checkpoints = [];
155
+ this.checkpointOutHashes = [];
152
156
  this.nextCheckpointIndex = 0;
153
157
  this.epochNumber++;
154
158
  }
@@ -186,7 +190,8 @@ export class TestContext {
186
190
  }
187
191
 
188
192
  const checkpointIndex = this.nextCheckpointIndex++;
189
- const checkpointNumber = checkpointIndex + 1;
193
+ const checkpointNumber = this.nextCheckpointNumber;
194
+ this.nextCheckpointNumber++;
190
195
  const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
191
196
 
192
197
  const constants = makeCheckpointConstants(slotNumber, constantOpts);
@@ -202,7 +207,9 @@ export class TestContext {
202
207
  const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
203
208
 
204
209
  const startBlockNumber = this.nextBlockNumber;
205
- const previousBlockHeader = this.getBlockHeader(startBlockNumber - 1);
210
+ const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
211
+ // All blocks in the same slot/checkpoint share the same timestamp.
212
+ const timestamp = BigInt(slotNumber * 26);
206
213
 
207
214
  // Build global variables.
208
215
  const blockGlobalVariables = times(numBlocks, i =>
@@ -210,6 +217,7 @@ export class TestContext {
210
217
  coinbase: constants.coinbase,
211
218
  feeRecipient: constants.feeRecipient,
212
219
  gasFees: constants.gasFees,
220
+ timestamp,
213
221
  }),
214
222
  );
215
223
  this.nextBlockNumber += numBlocks;
@@ -239,33 +247,38 @@ export class TestContext {
239
247
  });
240
248
 
241
249
  const cleanFork = await this.worldState.fork();
250
+ const previousCheckpointOutHashes = this.checkpointOutHashes;
242
251
  const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
243
252
  checkpointNumber,
244
253
  constants,
245
254
  l1ToL2Messages,
255
+ previousCheckpointOutHashes,
246
256
  cleanFork,
247
257
  );
248
258
 
249
259
  // Add tx effects to db and build block headers.
250
260
  const blocks = [];
251
261
  for (let i = 0; i < numBlocks; i++) {
252
- const isFirstBlock = i === 0;
253
262
  const txs = blockTxs[i];
254
263
  const state = blockEndStates[i];
255
264
 
256
- const block = await builder.addBlock(blockGlobalVariables[i], state, txs);
265
+ const block = await builder.addBlock(blockGlobalVariables[i], txs, {
266
+ expectedEndState: state,
267
+ insertTxsEffects: true,
268
+ });
257
269
 
258
270
  const header = block.header;
259
271
  this.headers.set(block.number, header);
260
272
 
261
- const blockMsgs = isFirstBlock ? l1ToL2Messages : [];
262
- await this.worldState.handleL2BlockAndMessages(block, blockMsgs, isFirstBlock);
273
+ const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
274
+ await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
263
275
 
264
276
  blocks.push({ header, txs });
265
277
  }
266
278
 
267
279
  const checkpoint = await builder.completeCheckpoint();
268
280
  this.checkpoints.push(checkpoint);
281
+ this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
269
282
 
270
283
  return {
271
284
  constants,
@@ -296,11 +309,13 @@ export class TestContext {
296
309
  return tx;
297
310
  }
298
311
 
299
- private getBlockHeader(blockNumber: number): BlockHeader {
300
- if (blockNumber > 0 && blockNumber >= this.nextBlockNumber) {
312
+ private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
313
+ if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
301
314
  throw new Error(`Block header not built for block number ${blockNumber}.`);
302
315
  }
303
- return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber)!;
316
+ return Number(blockNumber) === 0
317
+ ? this.worldState.getCommitted().getInitialHeader()
318
+ : this.headers.get(Number(blockNumber))!;
304
319
  }
305
320
 
306
321
  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(
@@ -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';
@@ -62,7 +63,7 @@ export class BlockProvingState {
62
63
 
63
64
  constructor(
64
65
  public readonly index: number,
65
- public readonly blockNumber: number,
66
+ public readonly blockNumber: BlockNumber,
66
67
  public readonly totalNumTxs: number,
67
68
  private readonly constants: CheckpointConstantData,
68
69
  private readonly timestamp: UInt64,
@@ -11,12 +11,16 @@ 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';
16
+ import { BlockNumber } from '@aztec/foundation/branded-types';
15
17
  import { padArrayEnd } from '@aztec/foundation/collection';
16
- import { BLS12Point, Fr } from '@aztec/foundation/fields';
18
+ import { BLS12Point } from '@aztec/foundation/curves/bls12';
19
+ import { Fr } from '@aztec/foundation/curves/bn254';
17
20
  import type { Tuple } from '@aztec/foundation/serialize';
18
21
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
19
22
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
20
24
  import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
21
25
  import {
22
26
  BlockMergeRollupPrivateInputs,
@@ -36,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
36
40
  import { BlockProvingState, type ProofState } from './block-proving-state.js';
37
41
  import type { EpochProvingState } from './epoch-proving-state.js';
38
42
 
43
+ type OutHashHint = {
44
+ treeSnapshot: AppendOnlyTreeSnapshot;
45
+ siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
46
+ };
47
+
39
48
  export class CheckpointProvingState {
40
49
  private blockProofs: UnbalancedTreeStore<
41
50
  ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
@@ -44,11 +53,16 @@ export class CheckpointProvingState {
44
53
  | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
45
54
  | undefined;
46
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;
47
61
  private startBlobAccumulator: BatchedBlobAccumulator | undefined;
48
62
  private endBlobAccumulator: BatchedBlobAccumulator | undefined;
49
63
  private blobFields: Fr[] | undefined;
50
64
  private error: string | undefined;
51
- public readonly firstBlockNumber: number;
65
+ public readonly firstBlockNumber: BlockNumber;
52
66
 
53
67
  constructor(
54
68
  public readonly index: number,
@@ -74,7 +88,7 @@ export class CheckpointProvingState {
74
88
  private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
75
89
  ) {
76
90
  this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
77
- this.firstBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1;
91
+ this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
78
92
  }
79
93
 
80
94
  public get epochNumber(): number {
@@ -82,13 +96,13 @@ export class CheckpointProvingState {
82
96
  }
83
97
 
84
98
  public startNewBlock(
85
- blockNumber: number,
99
+ blockNumber: BlockNumber,
86
100
  timestamp: UInt64,
87
101
  totalNumTxs: number,
88
102
  lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
89
103
  lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
90
104
  ): BlockProvingState {
91
- const index = blockNumber - this.firstBlockNumber;
105
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
92
106
  if (index >= this.totalNumBlocks) {
93
107
  throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
94
108
  }
@@ -193,6 +207,35 @@ export class CheckpointProvingState {
193
207
  return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
194
208
  }
195
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;
237
+ }
238
+
196
239
  public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
197
240
  if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
198
241
  return;
@@ -234,6 +277,9 @@ export class CheckpointProvingState {
234
277
  if (proofs.length !== nonEmptyProofs.length) {
235
278
  throw new Error('At least one child is not ready for the checkpoint root rollup.');
236
279
  }
280
+ if (!this.previousOutHashHint) {
281
+ throw new Error('Out hash hint is not set.');
282
+ }
237
283
  if (!this.startBlobAccumulator) {
238
284
  throw new Error('Start blob accumulator is not set.');
239
285
  }
@@ -246,6 +292,8 @@ export class CheckpointProvingState {
246
292
  const hints = CheckpointRootRollupHints.from({
247
293
  previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
248
294
  previousArchiveSiblingPath: this.lastArchiveSiblingPath,
295
+ previousOutHash: this.previousOutHashHint.treeSnapshot,
296
+ newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
249
297
  startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
250
298
  finalBlobChallenges: this.finalBlobBatchingChallenges,
251
299
  blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
@@ -260,8 +308,8 @@ export class CheckpointProvingState {
260
308
  : new CheckpointRootRollupPrivateInputs([left, right], hints);
261
309
  }
262
310
 
263
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
264
- const index = blockNumber - this.firstBlockNumber;
311
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
312
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
265
313
  return this.blocks[index];
266
314
  }
267
315
 
@@ -271,7 +319,7 @@ export class CheckpointProvingState {
271
319
 
272
320
  public isReadyForCheckpointRoot() {
273
321
  const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
274
- return allChildProofsReady && !!this.startBlobAccumulator;
322
+ return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
275
323
  }
276
324
 
277
325
  public verifyState() {
@@ -1,14 +1,20 @@
1
1
  import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
- import type {
3
- ARCHIVE_HEIGHT,
4
- L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
5
- NESTED_RECURSIVE_PROOF_LENGTH,
6
- NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
2
+ import {
3
+ type ARCHIVE_HEIGHT,
4
+ type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
5
+ type NESTED_RECURSIVE_PROOF_LENGTH,
6
+ type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
7
+ OUT_HASH_TREE_HEIGHT,
7
8
  } from '@aztec/constants';
8
- import { EpochNumber } from '@aztec/foundation/branded-types';
9
- import type { Fr } from '@aztec/foundation/fields';
9
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
11
  import type { Tuple } from '@aztec/foundation/serialize';
11
- import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
12
+ import {
13
+ MerkleTreeCalculator,
14
+ type TreeNodeLocation,
15
+ UnbalancedTreeStore,
16
+ shaMerkleHash,
17
+ } from '@aztec/foundation/trees';
12
18
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
13
19
  import type { Proof } from '@aztec/stdlib/proofs';
14
20
  import {
@@ -20,7 +26,7 @@ import {
20
26
  RootRollupPrivateInputs,
21
27
  type RootRollupPublicInputs,
22
28
  } from '@aztec/stdlib/rollup';
23
- import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
29
+ import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
24
30
  import type { BlockHeader } from '@aztec/stdlib/tx';
25
31
 
26
32
  import { toProofData } from './block-building-helpers.js';
@@ -126,13 +132,16 @@ export class EpochProvingState {
126
132
  return this.checkpoints[index];
127
133
  }
128
134
 
129
- public getCheckpointProvingStateByBlockNumber(blockNumber: number) {
135
+ public getCheckpointProvingStateByBlockNumber(blockNumber: BlockNumber) {
130
136
  return this.checkpoints.find(
131
- c => c && blockNumber >= c.firstBlockNumber && blockNumber < c.firstBlockNumber + c.totalNumBlocks,
137
+ c =>
138
+ c &&
139
+ Number(blockNumber) >= Number(c.firstBlockNumber) &&
140
+ Number(blockNumber) < Number(c.firstBlockNumber) + c.totalNumBlocks,
132
141
  );
133
142
  }
134
143
 
135
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
144
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
136
145
  return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
137
146
  }
138
147
 
@@ -209,6 +218,48 @@ export class EpochProvingState {
209
218
  this.checkpointPaddingProof = { provingOutput };
210
219
  }
211
220
 
221
+ public async accumulateCheckpointOutHashes() {
222
+ const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right) =>
223
+ Promise.resolve(shaMerkleHash(left, right)),
224
+ );
225
+
226
+ const computeOutHashHint = async (leaves: Fr[]) => {
227
+ const tree = await treeCalculator.computeTree(leaves.map(l => l.toBuffer()));
228
+ const nextAvailableLeafIndex = leaves.length;
229
+ return {
230
+ treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
231
+ siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer) as Tuple<
232
+ Fr,
233
+ typeof OUT_HASH_TREE_HEIGHT
234
+ >,
235
+ };
236
+ };
237
+
238
+ let hint = this.checkpoints[0]?.getOutHashHint();
239
+ const outHashes = [];
240
+ for (let i = 0; i < this.totalNumCheckpoints; i++) {
241
+ const checkpoint = this.checkpoints[i];
242
+ if (!checkpoint) {
243
+ break;
244
+ }
245
+
246
+ // If hints are not set yet, it must be the first checkpoint. Compute the hints with an empty tree.
247
+ hint ??= await computeOutHashHint([]);
248
+ checkpoint.setOutHashHint(hint);
249
+
250
+ // Get the out hash for this checkpoint.
251
+ const outHash = checkpoint.accumulateBlockOutHashes();
252
+ if (!outHash) {
253
+ break;
254
+ }
255
+ outHashes.push(outHash);
256
+
257
+ // Get or create hints for the next checkpoint.
258
+ hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
259
+ checkpoint.setOutHashHintForNextCheckpoint(hint);
260
+ }
261
+ }
262
+
212
263
  public async setBlobAccumulators() {
213
264
  let previousAccumulator = this.startBlobAccumulator;
214
265
  // Accumulate blobs as far as we can for this epoch.