@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472

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 (129) 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/index.d.ts +1 -1
  5. package/dest/light/index.d.ts +2 -0
  6. package/dest/light/index.d.ts.map +1 -0
  7. package/dest/light/index.js +1 -0
  8. package/dest/light/lightweight_checkpoint_builder.d.ts +45 -0
  9. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  10. package/dest/light/lightweight_checkpoint_builder.js +197 -0
  11. package/dest/mocks/fixtures.d.ts +1 -4
  12. package/dest/mocks/fixtures.d.ts.map +1 -1
  13. package/dest/mocks/fixtures.js +9 -18
  14. package/dest/mocks/test_context.d.ts +29 -46
  15. package/dest/mocks/test_context.d.ts.map +1 -1
  16. package/dest/mocks/test_context.js +116 -116
  17. package/dest/orchestrator/block-building-helpers.d.ts +17 -19
  18. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  19. package/dest/orchestrator/block-building-helpers.js +88 -113
  20. package/dest/orchestrator/block-proving-state.d.ts +17 -11
  21. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  22. package/dest/orchestrator/block-proving-state.js +81 -20
  23. package/dest/orchestrator/checkpoint-proving-state.d.ts +22 -9
  24. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  25. package/dest/orchestrator/checkpoint-proving-state.js +49 -17
  26. package/dest/orchestrator/epoch-proving-state.d.ts +12 -10
  27. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  28. package/dest/orchestrator/epoch-proving-state.js +38 -4
  29. package/dest/orchestrator/index.d.ts +1 -1
  30. package/dest/orchestrator/orchestrator.d.ts +26 -11
  31. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  32. package/dest/orchestrator/orchestrator.js +556 -161
  33. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  34. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  35. package/dest/orchestrator/orchestrator_metrics.js +2 -15
  36. package/dest/orchestrator/tx-proving-state.d.ts +6 -5
  37. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  38. package/dest/orchestrator/tx-proving-state.js +7 -16
  39. package/dest/prover-client/factory.d.ts +3 -3
  40. package/dest/prover-client/factory.d.ts.map +1 -1
  41. package/dest/prover-client/index.d.ts +1 -1
  42. package/dest/prover-client/prover-client.d.ts +3 -3
  43. package/dest/prover-client/prover-client.d.ts.map +1 -1
  44. package/dest/prover-client/prover-client.js +7 -4
  45. package/dest/prover-client/server-epoch-prover.d.ts +8 -7
  46. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  47. package/dest/prover-client/server-epoch-prover.js +2 -2
  48. package/dest/proving_broker/broker_prover_facade.d.ts +25 -23
  49. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  50. package/dest/proving_broker/broker_prover_facade.js +9 -15
  51. package/dest/proving_broker/config.d.ts +16 -8
  52. package/dest/proving_broker/config.d.ts.map +1 -1
  53. package/dest/proving_broker/config.js +14 -2
  54. package/dest/proving_broker/factory.d.ts +1 -1
  55. package/dest/proving_broker/fixtures.d.ts +3 -2
  56. package/dest/proving_broker/fixtures.d.ts.map +1 -1
  57. package/dest/proving_broker/fixtures.js +3 -2
  58. package/dest/proving_broker/index.d.ts +1 -1
  59. package/dest/proving_broker/proof_store/factory.d.ts +2 -2
  60. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
  61. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  62. package/dest/proving_broker/proof_store/index.d.ts +1 -1
  63. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  64. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  65. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  66. package/dest/proving_broker/proving_agent.d.ts +5 -9
  67. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  68. package/dest/proving_broker/proving_agent.js +4 -19
  69. package/dest/proving_broker/proving_broker.d.ts +2 -2
  70. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  71. package/dest/proving_broker/proving_broker.js +6 -11
  72. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  73. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  74. package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
  75. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  76. package/dest/proving_broker/proving_broker_database/persisted.js +392 -3
  77. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  78. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  79. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  80. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  81. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  82. package/dest/proving_broker/proving_job_controller.d.ts +5 -3
  83. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  84. package/dest/proving_broker/proving_job_controller.js +8 -6
  85. package/dest/proving_broker/rpc.d.ts +4 -4
  86. package/dest/test/mock_proof_store.d.ts +1 -1
  87. package/dest/test/mock_proof_store.d.ts.map +1 -1
  88. package/dest/test/mock_prover.d.ts +3 -4
  89. package/dest/test/mock_prover.d.ts.map +1 -1
  90. package/dest/test/mock_prover.js +4 -4
  91. package/package.json +20 -18
  92. package/src/config.ts +1 -1
  93. package/src/light/index.ts +1 -0
  94. package/src/light/lightweight_checkpoint_builder.ts +284 -0
  95. package/src/mocks/fixtures.ts +9 -31
  96. package/src/mocks/test_context.ts +158 -177
  97. package/src/orchestrator/block-building-helpers.ts +127 -207
  98. package/src/orchestrator/block-proving-state.ts +103 -25
  99. package/src/orchestrator/checkpoint-proving-state.ts +71 -21
  100. package/src/orchestrator/epoch-proving-state.ts +64 -14
  101. package/src/orchestrator/orchestrator.ts +158 -149
  102. package/src/orchestrator/orchestrator_metrics.ts +2 -25
  103. package/src/orchestrator/tx-proving-state.ts +10 -27
  104. package/src/prover-client/factory.ts +6 -2
  105. package/src/prover-client/prover-client.ts +25 -15
  106. package/src/prover-client/server-epoch-prover.ts +6 -7
  107. package/src/proving_broker/broker_prover_facade.ts +31 -37
  108. package/src/proving_broker/config.ts +17 -1
  109. package/src/proving_broker/fixtures.ts +8 -3
  110. package/src/proving_broker/proving_agent.ts +6 -19
  111. package/src/proving_broker/proving_broker.ts +6 -9
  112. package/src/proving_broker/proving_broker_database/memory.ts +2 -1
  113. package/src/proving_broker/proving_broker_database/persisted.ts +20 -5
  114. package/src/proving_broker/proving_broker_database.ts +2 -1
  115. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  116. package/src/proving_broker/proving_job_controller.ts +13 -7
  117. package/src/test/mock_prover.ts +2 -14
  118. package/dest/block-factory/index.d.ts +0 -2
  119. package/dest/block-factory/index.d.ts.map +0 -1
  120. package/dest/block-factory/index.js +0 -1
  121. package/dest/block-factory/light.d.ts +0 -38
  122. package/dest/block-factory/light.d.ts.map +0 -1
  123. package/dest/block-factory/light.js +0 -94
  124. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  125. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  126. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  127. package/src/block-factory/index.ts +0 -1
  128. package/src/block-factory/light.ts +0 -140
  129. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,18 +1,26 @@
1
- import { BatchedBlobAccumulator, type FinalBlobBatchingChallenges, SpongeBlob } from '@aztec/blob-lib';
1
+ import {
2
+ BatchedBlobAccumulator,
3
+ type FinalBlobBatchingChallenges,
4
+ SpongeBlob,
5
+ encodeCheckpointBlobDataFromBlocks,
6
+ } from '@aztec/blob-lib';
2
7
  import {
3
8
  type ARCHIVE_HEIGHT,
4
- BLOBS_PER_BLOCK,
9
+ BLOBS_PER_CHECKPOINT,
5
10
  FIELDS_PER_BLOB,
6
11
  type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
7
12
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
8
13
  NUM_MSGS_PER_BASE_PARITY,
14
+ OUT_HASH_TREE_HEIGHT,
9
15
  } from '@aztec/constants';
16
+ import { BlockNumber } from '@aztec/foundation/branded-types';
10
17
  import { padArrayEnd } from '@aztec/foundation/collection';
11
- import { BLS12Point, Fr } from '@aztec/foundation/fields';
18
+ import { BLS12Point } from '@aztec/foundation/curves/bls12';
19
+ import { Fr } from '@aztec/foundation/curves/bn254';
12
20
  import type { Tuple } from '@aztec/foundation/serialize';
13
21
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
14
- import { getCheckpointBlobFields } from '@aztec/stdlib/checkpoint';
15
22
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
16
24
  import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
17
25
  import {
18
26
  BlockMergeRollupPrivateInputs,
@@ -32,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
32
40
  import { BlockProvingState, type ProofState } from './block-proving-state.js';
33
41
  import type { EpochProvingState } from './epoch-proving-state.js';
34
42
 
43
+ type OutHashHint = {
44
+ treeSnapshot: AppendOnlyTreeSnapshot;
45
+ siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
46
+ };
47
+
35
48
  export class CheckpointProvingState {
36
49
  private blockProofs: UnbalancedTreeStore<
37
50
  ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
@@ -40,17 +53,21 @@ export class CheckpointProvingState {
40
53
  | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
41
54
  | undefined;
42
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;
43
61
  private startBlobAccumulator: BatchedBlobAccumulator | undefined;
44
62
  private endBlobAccumulator: BatchedBlobAccumulator | undefined;
45
63
  private blobFields: Fr[] | undefined;
46
64
  private error: string | undefined;
47
- public readonly firstBlockNumber: number;
65
+ public readonly firstBlockNumber: BlockNumber;
48
66
 
49
67
  constructor(
50
68
  public readonly index: number,
51
69
  public readonly constants: CheckpointConstantData,
52
70
  public readonly totalNumBlocks: number,
53
- private readonly totalNumBlobFields: number,
54
71
  private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
55
72
  private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
56
73
  private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
@@ -71,21 +88,21 @@ export class CheckpointProvingState {
71
88
  private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
72
89
  ) {
73
90
  this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
74
- this.firstBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1;
91
+ this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
75
92
  }
76
93
 
77
94
  public get epochNumber(): number {
78
95
  return this.parentEpoch.epochNumber;
79
96
  }
80
97
 
81
- public async startNewBlock(
82
- blockNumber: number,
98
+ public startNewBlock(
99
+ blockNumber: BlockNumber,
83
100
  timestamp: UInt64,
84
101
  totalNumTxs: number,
85
102
  lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
86
103
  lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
87
- ): Promise<BlockProvingState> {
88
- const index = blockNumber - this.firstBlockNumber;
104
+ ): BlockProvingState {
105
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
89
106
  if (index >= this.totalNumBlocks) {
90
107
  throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
91
108
  }
@@ -98,8 +115,7 @@ export class CheckpointProvingState {
98
115
  const lastL1ToL2MessageSubtreeRootSiblingPath =
99
116
  index === 0 ? this.lastL1ToL2MessageSubtreeRootSiblingPath : this.newL1ToL2MessageSubtreeRootSiblingPath;
100
117
 
101
- const startSpongeBlob =
102
- index === 0 ? await SpongeBlob.init(this.totalNumBlobFields) : this.blocks[index - 1]?.getEndSpongeBlob();
118
+ const startSpongeBlob = index === 0 ? SpongeBlob.init() : this.blocks[index - 1]?.getEndSpongeBlob();
103
119
  if (!startSpongeBlob) {
104
120
  throw new Error(
105
121
  'Cannot start a new block before the trees have progressed from the tx effects in the previous block.',
@@ -191,13 +207,42 @@ export class CheckpointProvingState {
191
207
  return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
192
208
  }
193
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
+
194
239
  public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
195
- if (this.isAcceptingBlocks() || this.blocks.some(b => b!.isAcceptingTxs())) {
240
+ if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
196
241
  return;
197
242
  }
198
243
 
199
- this.blobFields = getCheckpointBlobFields(this.blocks.map(b => b!.getTxEffects()));
200
- this.endBlobAccumulator = await accumulateBlobs(this.blobFields, startBlobAccumulator);
244
+ this.blobFields = encodeCheckpointBlobDataFromBlocks(this.blocks.map(b => b!.getBlockBlobData()));
245
+ this.endBlobAccumulator = await accumulateBlobs(this.blobFields!, startBlobAccumulator);
201
246
  this.startBlobAccumulator = startBlobAccumulator;
202
247
 
203
248
  this.onBlobAccumulatorSet(this);
@@ -232,6 +277,9 @@ export class CheckpointProvingState {
232
277
  if (proofs.length !== nonEmptyProofs.length) {
233
278
  throw new Error('At least one child is not ready for the checkpoint root rollup.');
234
279
  }
280
+ if (!this.previousOutHashHint) {
281
+ throw new Error('Out hash hint is not set.');
282
+ }
235
283
  if (!this.startBlobAccumulator) {
236
284
  throw new Error('Start blob accumulator is not set.');
237
285
  }
@@ -244,10 +292,12 @@ export class CheckpointProvingState {
244
292
  const hints = CheckpointRootRollupHints.from({
245
293
  previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
246
294
  previousArchiveSiblingPath: this.lastArchiveSiblingPath,
295
+ previousOutHash: this.previousOutHashHint.treeSnapshot,
296
+ newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
247
297
  startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
248
298
  finalBlobChallenges: this.finalBlobBatchingChallenges,
249
- blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
250
- blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_BLOCK),
299
+ blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
300
+ blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_CHECKPOINT),
251
301
  blobsHash,
252
302
  });
253
303
 
@@ -258,8 +308,8 @@ export class CheckpointProvingState {
258
308
  : new CheckpointRootRollupPrivateInputs([left, right], hints);
259
309
  }
260
310
 
261
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
262
- const index = blockNumber - this.firstBlockNumber;
311
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
312
+ const index = Number(blockNumber) - Number(this.firstBlockNumber);
263
313
  return this.blocks[index];
264
314
  }
265
315
 
@@ -269,7 +319,7 @@ export class CheckpointProvingState {
269
319
 
270
320
  public isReadyForCheckpointRoot() {
271
321
  const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
272
- return allChildProofsReady && !!this.startBlobAccumulator;
322
+ return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
273
323
  }
274
324
 
275
325
  public verifyState() {
@@ -1,13 +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 type { Fr } from '@aztec/foundation/fields';
9
+ import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
11
  import type { Tuple } from '@aztec/foundation/serialize';
10
- import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
12
+ import {
13
+ MerkleTreeCalculator,
14
+ type TreeNodeLocation,
15
+ UnbalancedTreeStore,
16
+ shaMerkleHash,
17
+ } from '@aztec/foundation/trees';
11
18
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
12
19
  import type { Proof } from '@aztec/stdlib/proofs';
13
20
  import {
@@ -19,7 +26,7 @@ import {
19
26
  RootRollupPrivateInputs,
20
27
  type RootRollupPublicInputs,
21
28
  } from '@aztec/stdlib/rollup';
22
- import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
29
+ import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
23
30
  import type { BlockHeader } from '@aztec/stdlib/tx';
24
31
 
25
32
  import { toProofData } from './block-building-helpers.js';
@@ -66,7 +73,7 @@ export class EpochProvingState {
66
73
  >();
67
74
 
68
75
  constructor(
69
- public readonly epochNumber: number,
76
+ public readonly epochNumber: EpochNumber,
70
77
  public readonly totalNumCheckpoints: number,
71
78
  private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
72
79
  private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void,
@@ -83,7 +90,6 @@ export class EpochProvingState {
83
90
  checkpointIndex: number,
84
91
  constants: CheckpointConstantData,
85
92
  totalNumBlocks: number,
86
- totalNumBlobFields: number,
87
93
  previousBlockHeader: BlockHeader,
88
94
  lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
89
95
  l1ToL2Messages: Fr[],
@@ -102,7 +108,6 @@ export class EpochProvingState {
102
108
  checkpointIndex,
103
109
  constants,
104
110
  totalNumBlocks,
105
- totalNumBlobFields,
106
111
  this.finalBlobBatchingChallenges,
107
112
  previousBlockHeader,
108
113
  lastArchiveSiblingPath,
@@ -127,13 +132,16 @@ export class EpochProvingState {
127
132
  return this.checkpoints[index];
128
133
  }
129
134
 
130
- public getCheckpointProvingStateByBlockNumber(blockNumber: number) {
135
+ public getCheckpointProvingStateByBlockNumber(blockNumber: BlockNumber) {
131
136
  return this.checkpoints.find(
132
- 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,
133
141
  );
134
142
  }
135
143
 
136
- public getBlockProvingStateByBlockNumber(blockNumber: number) {
144
+ public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
137
145
  return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
138
146
  }
139
147
 
@@ -210,6 +218,48 @@ export class EpochProvingState {
210
218
  this.checkpointPaddingProof = { provingOutput };
211
219
  }
212
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
+
213
263
  public async setBlobAccumulators() {
214
264
  let previousAccumulator = this.startBlobAccumulator;
215
265
  // Accumulate blobs as far as we can for this epoch.