@aztec/prover-client 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263

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 (86) hide show
  1. package/dest/light/lightweight_checkpoint_builder.d.ts +15 -6
  2. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
  3. package/dest/light/lightweight_checkpoint_builder.js +62 -12
  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.d.ts +4 -2
  8. package/dest/mocks/test_context.d.ts.map +1 -1
  9. package/dest/mocks/test_context.js +14 -3
  10. package/dest/orchestrator/block-building-helpers.d.ts +1 -1
  11. package/dest/orchestrator/block-building-helpers.js +2 -2
  12. package/dest/orchestrator/checkpoint-proving-state.d.ts +15 -2
  13. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  14. package/dest/orchestrator/checkpoint-proving-state.js +34 -1
  15. package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
  16. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  17. package/dest/orchestrator/epoch-proving-state.js +35 -1
  18. package/dest/orchestrator/orchestrator.d.ts +18 -3
  19. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  20. package/dest/orchestrator/orchestrator.js +533 -109
  21. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
  22. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  23. package/dest/orchestrator/orchestrator_metrics.js +2 -6
  24. package/dest/orchestrator/tx-proving-state.d.ts +5 -4
  25. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  26. package/dest/orchestrator/tx-proving-state.js +6 -6
  27. package/dest/prover-client/prover-client.d.ts +1 -1
  28. package/dest/prover-client/prover-client.d.ts.map +1 -1
  29. package/dest/prover-client/prover-client.js +7 -4
  30. package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
  31. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  32. package/dest/proving_broker/broker_prover_facade.js +3 -3
  33. package/dest/proving_broker/config.d.ts +5 -1
  34. package/dest/proving_broker/config.d.ts.map +1 -1
  35. package/dest/proving_broker/config.js +7 -1
  36. package/dest/proving_broker/proving_agent.d.ts +5 -9
  37. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  38. package/dest/proving_broker/proving_agent.js +4 -19
  39. package/dest/proving_broker/proving_broker.d.ts +1 -1
  40. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  41. package/dest/proving_broker/proving_broker.js +1 -10
  42. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  43. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  44. package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
  45. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  46. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  47. package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
  48. package/dest/proving_broker/proving_job_controller.d.ts +4 -3
  49. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  50. package/dest/proving_broker/proving_job_controller.js +6 -3
  51. package/dest/test/mock_proof_store.d.ts +3 -3
  52. package/dest/test/mock_proof_store.d.ts.map +1 -1
  53. package/dest/test/mock_prover.d.ts +2 -2
  54. package/dest/test/mock_prover.d.ts.map +1 -1
  55. package/dest/test/mock_prover.js +3 -3
  56. package/package.json +16 -17
  57. package/src/light/lightweight_checkpoint_builder.ts +100 -14
  58. package/src/mocks/fixtures.ts +2 -1
  59. package/src/mocks/test_context.ts +11 -1
  60. package/src/orchestrator/block-building-helpers.ts +2 -2
  61. package/src/orchestrator/checkpoint-proving-state.ts +47 -1
  62. package/src/orchestrator/epoch-proving-state.ts +56 -8
  63. package/src/orchestrator/orchestrator.ts +126 -85
  64. package/src/orchestrator/orchestrator_metrics.ts +2 -6
  65. package/src/orchestrator/tx-proving-state.ts +8 -11
  66. package/src/prover-client/prover-client.ts +22 -13
  67. package/src/proving_broker/broker_prover_facade.ts +8 -6
  68. package/src/proving_broker/config.ts +9 -0
  69. package/src/proving_broker/proving_agent.ts +6 -19
  70. package/src/proving_broker/proving_broker.ts +1 -8
  71. package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
  72. package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
  73. package/src/proving_broker/proving_job_controller.ts +9 -3
  74. package/src/test/mock_prover.ts +1 -8
  75. package/dest/block-factory/index.d.ts +0 -2
  76. package/dest/block-factory/index.d.ts.map +0 -1
  77. package/dest/block-factory/index.js +0 -1
  78. package/dest/block-factory/light.d.ts +0 -38
  79. package/dest/block-factory/light.d.ts.map +0 -1
  80. package/dest/block-factory/light.js +0 -108
  81. package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
  82. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
  83. package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
  84. package/src/block-factory/index.ts +0 -1
  85. package/src/block-factory/light.ts +0 -137
  86. package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
@@ -1,6 +1,6 @@
1
- import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, RECURSIVE_PROOF_LENGTH } from '@aztec/constants';
1
+ import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_PROOF_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH, RECURSIVE_PROOF_LENGTH } from '@aztec/constants';
2
2
  import { times } from '@aztec/foundation/collection';
3
- import { makeProofAndVerificationKey, makePublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
3
+ import { makePublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
4
4
  import { makeEmptyRecursiveProof, makeRecursiveProof } from '@aztec/stdlib/proofs';
5
5
  import { makeBlockRollupPublicInputs, makeCheckpointRollupPublicInputs, makeParityPublicInputs, makePublicChonkVerifierPublicInputs, makeRootRollupPublicInputs, makeTxRollupPublicInputs } from '@aztec/stdlib/testing';
6
6
  import { VerificationKeyData } from '@aztec/stdlib/vks';
@@ -44,7 +44,7 @@ export class TestBroker {
44
44
  export class MockProver {
45
45
  constructor(){}
46
46
  getAvmProof(_inputs, _signal, _epochNumber) {
47
- return Promise.resolve(makeProofAndVerificationKey(makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED), VerificationKeyData.makeFake(AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED)));
47
+ return Promise.resolve(makeEmptyRecursiveProof(AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED));
48
48
  }
49
49
  getBaseParityProof(_inputs, _signal, _epochNumber) {
50
50
  return Promise.resolve(makePublicInputsAndRecursiveProof(makeParityPublicInputs(), makeRecursiveProof(RECURSIVE_PROOF_LENGTH), VerificationKeyData.makeFakeHonk()));
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@aztec/prover-client",
3
- "version": "0.0.1-commit.c7c42ec",
3
+ "version": "0.0.1-commit.c80b6263",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
7
- "./block-factory": "./dest/block-factory/index.js",
8
7
  "./broker": "./dest/proving_broker/index.js",
9
8
  "./broker/config": "./dest/proving_broker/config.js",
10
9
  "./orchestrator": "./dest/orchestrator/index.js",
@@ -69,19 +68,19 @@
69
68
  ]
70
69
  },
71
70
  "dependencies": {
72
- "@aztec/bb-prover": "0.0.1-commit.c7c42ec",
73
- "@aztec/blob-lib": "0.0.1-commit.c7c42ec",
74
- "@aztec/constants": "0.0.1-commit.c7c42ec",
75
- "@aztec/ethereum": "0.0.1-commit.c7c42ec",
76
- "@aztec/foundation": "0.0.1-commit.c7c42ec",
77
- "@aztec/kv-store": "0.0.1-commit.c7c42ec",
78
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.c7c42ec",
79
- "@aztec/noir-types": "0.0.1-commit.c7c42ec",
80
- "@aztec/protocol-contracts": "0.0.1-commit.c7c42ec",
81
- "@aztec/simulator": "0.0.1-commit.c7c42ec",
82
- "@aztec/stdlib": "0.0.1-commit.c7c42ec",
83
- "@aztec/telemetry-client": "0.0.1-commit.c7c42ec",
84
- "@aztec/world-state": "0.0.1-commit.c7c42ec",
71
+ "@aztec/bb-prover": "0.0.1-commit.c80b6263",
72
+ "@aztec/blob-lib": "0.0.1-commit.c80b6263",
73
+ "@aztec/constants": "0.0.1-commit.c80b6263",
74
+ "@aztec/ethereum": "0.0.1-commit.c80b6263",
75
+ "@aztec/foundation": "0.0.1-commit.c80b6263",
76
+ "@aztec/kv-store": "0.0.1-commit.c80b6263",
77
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.c80b6263",
78
+ "@aztec/noir-types": "0.0.1-commit.c80b6263",
79
+ "@aztec/protocol-contracts": "0.0.1-commit.c80b6263",
80
+ "@aztec/simulator": "0.0.1-commit.c80b6263",
81
+ "@aztec/stdlib": "0.0.1-commit.c80b6263",
82
+ "@aztec/telemetry-client": "0.0.1-commit.c80b6263",
83
+ "@aztec/world-state": "0.0.1-commit.c80b6263",
85
84
  "@google-cloud/storage": "^7.15.0",
86
85
  "@iarna/toml": "^2.2.5",
87
86
  "commander": "^12.1.0",
@@ -91,12 +90,12 @@
91
90
  "zod": "^3.23.8"
92
91
  },
93
92
  "devDependencies": {
94
- "@aztec/noir-contracts.js": "0.0.1-commit.c7c42ec",
93
+ "@aztec/noir-contracts.js": "0.0.1-commit.c80b6263",
95
94
  "@jest/globals": "^30.0.0",
96
95
  "@types/jest": "^30.0.0",
97
96
  "@types/node": "^22.15.17",
98
97
  "@types/source-map-support": "^0.5.10",
99
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
98
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
100
99
  "get-port": "^7.1.0",
101
100
  "jest": "^30.0.0",
102
101
  "jest-mock-extended": "^4.0.0",
@@ -1,18 +1,21 @@
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 } from '@aztec/foundation/branded-types';
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';
7
- import { L2BlockNew } from '@aztec/stdlib/block';
6
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
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';
10
- import { computeCheckpointOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
10
+ import {
11
+ accumulateCheckpointOutHashes,
12
+ computeCheckpointOutHash,
13
+ computeInHashFromL1ToL2Messages,
14
+ } from '@aztec/stdlib/messaging';
11
15
  import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
12
16
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
13
17
  import {
14
18
  type CheckpointGlobalVariables,
15
- ContentCommitment,
16
19
  type GlobalVariables,
17
20
  type ProcessedTx,
18
21
  StateReference,
@@ -31,19 +34,25 @@ import {
31
34
  * Finally completes the checkpoint by computing its header.
32
35
  */
33
36
  export class LightweightCheckpointBuilder {
34
- private readonly logger = createLogger('lightweight-checkpoint-builder');
37
+ private readonly logger: Logger;
35
38
 
36
39
  private lastArchives: AppendOnlyTreeSnapshot[] = [];
37
40
  private spongeBlob: SpongeBlob;
38
- private blocks: L2BlockNew[] = [];
41
+ private blocks: L2Block[] = [];
39
42
  private blobFields: Fr[] = [];
40
43
 
41
44
  constructor(
42
45
  public readonly checkpointNumber: CheckpointNumber,
43
46
  public readonly constants: CheckpointGlobalVariables,
44
47
  public readonly l1ToL2Messages: Fr[],
48
+ private readonly previousCheckpointOutHashes: Fr[],
45
49
  public readonly db: MerkleTreeWriteOperations,
50
+ bindings?: LoggerBindings,
46
51
  ) {
52
+ this.logger = createLogger('checkpoint-builder', {
53
+ ...bindings,
54
+ instanceId: `checkpoint-${checkpointNumber}`,
55
+ });
47
56
  this.spongeBlob = SpongeBlob.init();
48
57
  this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages });
49
58
  }
@@ -52,7 +61,9 @@ export class LightweightCheckpointBuilder {
52
61
  checkpointNumber: CheckpointNumber,
53
62
  constants: CheckpointGlobalVariables,
54
63
  l1ToL2Messages: Fr[],
64
+ previousCheckpointOutHashes: Fr[],
55
65
  db: MerkleTreeWriteOperations,
66
+ bindings?: LoggerBindings,
56
67
  ): Promise<LightweightCheckpointBuilder> {
57
68
  // Insert l1-to-l2 messages into the tree.
58
69
  await db.appendLeaves(
@@ -60,7 +71,76 @@ export class LightweightCheckpointBuilder {
60
71
  padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
61
72
  );
62
73
 
63
- return new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
74
+ return new LightweightCheckpointBuilder(
75
+ checkpointNumber,
76
+ constants,
77
+ l1ToL2Messages,
78
+ previousCheckpointOutHashes,
79
+ db,
80
+ bindings,
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Resumes building a checkpoint from existing blocks. This is used for validator re-execution
86
+ * where blocks have already been built and their effects are already in the database.
87
+ * Unlike startNewCheckpoint, this does NOT append l1ToL2Messages to the tree since they
88
+ * were already added when the blocks were originally built.
89
+ */
90
+ static async resumeCheckpoint(
91
+ checkpointNumber: CheckpointNumber,
92
+ constants: CheckpointGlobalVariables,
93
+ l1ToL2Messages: Fr[],
94
+ previousCheckpointOutHashes: Fr[],
95
+ db: MerkleTreeWriteOperations,
96
+ existingBlocks: L2Block[],
97
+ bindings?: LoggerBindings,
98
+ ): Promise<LightweightCheckpointBuilder> {
99
+ const builder = new LightweightCheckpointBuilder(
100
+ checkpointNumber,
101
+ constants,
102
+ l1ToL2Messages,
103
+ previousCheckpointOutHashes,
104
+ db,
105
+ bindings,
106
+ );
107
+
108
+ builder.logger.debug('Resuming checkpoint from existing blocks', {
109
+ checkpointNumber,
110
+ numExistingBlocks: existingBlocks.length,
111
+ blockNumbers: existingBlocks.map(b => b.header.getBlockNumber()),
112
+ });
113
+
114
+ // Validate block order and consistency
115
+ for (let i = 1; i < existingBlocks.length; i++) {
116
+ const prev = existingBlocks[i - 1];
117
+ const curr = existingBlocks[i];
118
+ if (curr.number !== prev.number + 1) {
119
+ throw new Error(`Non-sequential block numbers in resumeCheckpoint: ${prev.number} -> ${curr.number}`);
120
+ }
121
+ if (!prev.archive.root.equals(curr.header.lastArchive.root)) {
122
+ throw new Error(`Archive root mismatch between blocks ${prev.number} and ${curr.number}`);
123
+ }
124
+ }
125
+
126
+ for (let i = 0; i < existingBlocks.length; i++) {
127
+ const block = existingBlocks[i];
128
+ const isFirstBlock = i === 0;
129
+
130
+ if (isFirstBlock) {
131
+ builder.lastArchives.push(block.header.lastArchive);
132
+ }
133
+
134
+ builder.lastArchives.push(block.archive);
135
+
136
+ const blockBlobFields = block.toBlobFields();
137
+ await builder.spongeBlob.absorb(blockBlobFields);
138
+ builder.blobFields.push(...blockBlobFields);
139
+
140
+ builder.blocks.push(block);
141
+ }
142
+
143
+ return builder;
64
144
  }
65
145
 
66
146
  /**
@@ -71,7 +151,7 @@ export class LightweightCheckpointBuilder {
71
151
  globalVariables: GlobalVariables,
72
152
  txs: ProcessedTx[],
73
153
  opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
74
- ): Promise<L2BlockNew> {
154
+ ): Promise<L2Block> {
75
155
  const isFirstBlock = this.blocks.length === 0;
76
156
 
77
157
  // Empty blocks are only allowed as the first block in a checkpoint
@@ -120,8 +200,8 @@ export class LightweightCheckpointBuilder {
120
200
  const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
121
201
  this.lastArchives.push(newArchive);
122
202
 
123
- const indexWithinCheckpoint = this.blocks.length;
124
- const block = new L2BlockNew(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
203
+ const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
204
+ const block = new L2Block(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
125
205
  this.blocks.push(block);
126
206
 
127
207
  await this.spongeBlob.absorb(blockBlobFields);
@@ -157,9 +237,11 @@ export class LightweightCheckpointBuilder {
157
237
 
158
238
  const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
159
239
 
160
- const outHash = computeCheckpointOutHash(blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)));
161
-
162
240
  const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
241
+ const checkpointOutHash = computeCheckpointOutHash(
242
+ blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)),
243
+ );
244
+ const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
163
245
 
164
246
  // TODO(palla/mbps): Should we source this from the constants instead?
165
247
  // timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
@@ -169,7 +251,9 @@ export class LightweightCheckpointBuilder {
169
251
 
170
252
  const header = CheckpointHeader.from({
171
253
  lastArchiveRoot: this.lastArchives[0].root,
172
- contentCommitment: new ContentCommitment(blobsHash, inHash, outHash),
254
+ blobsHash,
255
+ inHash,
256
+ epochOutHash,
173
257
  blockHeadersHash,
174
258
  slotNumber,
175
259
  timestamp,
@@ -187,7 +271,9 @@ export class LightweightCheckpointBuilder {
187
271
  this.checkpointNumber,
188
272
  this.constants,
189
273
  [...this.l1ToL2Messages],
274
+ [...this.previousCheckpointOutHashes],
190
275
  this.db,
276
+ this.logger.getBindings(),
191
277
  );
192
278
  clone.lastArchives = [...this.lastArchives];
193
279
  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
  }
@@ -44,7 +44,9 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
44
44
  export class TestContext {
45
45
  private headers: Map<number, BlockHeader> = new Map();
46
46
  private checkpoints: Checkpoint[] = [];
47
+ private checkpointOutHashes: Fr[] = [];
47
48
  private nextCheckpointIndex = 0;
49
+ private nextCheckpointNumber = CheckpointNumber(1);
48
50
  private nextBlockNumber = 1;
49
51
  private epochNumber = 1;
50
52
  private feePayerBalance: Fr;
@@ -150,6 +152,7 @@ export class TestContext {
150
152
 
151
153
  public startNewEpoch() {
152
154
  this.checkpoints = [];
155
+ this.checkpointOutHashes = [];
153
156
  this.nextCheckpointIndex = 0;
154
157
  this.epochNumber++;
155
158
  }
@@ -187,7 +190,8 @@ export class TestContext {
187
190
  }
188
191
 
189
192
  const checkpointIndex = this.nextCheckpointIndex++;
190
- const checkpointNumber = CheckpointNumber(checkpointIndex + 1);
193
+ const checkpointNumber = this.nextCheckpointNumber;
194
+ this.nextCheckpointNumber++;
191
195
  const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
192
196
 
193
197
  const constants = makeCheckpointConstants(slotNumber, constantOpts);
@@ -204,6 +208,8 @@ export class TestContext {
204
208
 
205
209
  const startBlockNumber = this.nextBlockNumber;
206
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);
207
213
 
208
214
  // Build global variables.
209
215
  const blockGlobalVariables = times(numBlocks, i =>
@@ -211,6 +217,7 @@ export class TestContext {
211
217
  coinbase: constants.coinbase,
212
218
  feeRecipient: constants.feeRecipient,
213
219
  gasFees: constants.gasFees,
220
+ timestamp,
214
221
  }),
215
222
  );
216
223
  this.nextBlockNumber += numBlocks;
@@ -240,10 +247,12 @@ export class TestContext {
240
247
  });
241
248
 
242
249
  const cleanFork = await this.worldState.fork();
250
+ const previousCheckpointOutHashes = this.checkpointOutHashes;
243
251
  const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
244
252
  checkpointNumber,
245
253
  constants,
246
254
  l1ToL2Messages,
255
+ previousCheckpointOutHashes,
247
256
  cleanFork,
248
257
  );
249
258
 
@@ -269,6 +278,7 @@ export class TestContext {
269
278
 
270
279
  const checkpoint = await builder.completeCheckpoint();
271
280
  this.checkpoints.push(checkpoint);
281
+ this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
272
282
 
273
283
  return {
274
284
  constants,
@@ -97,7 +97,7 @@ 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();
100
+ const blockHash = (await tx.data.constants.anchorBlockHeader.hash()).toField();
101
101
  const anchorBlockArchiveSiblingPath = (
102
102
  await getMembershipWitnessFor(blockHash, MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
103
103
  ).siblingPath;
@@ -282,7 +282,7 @@ export const buildHeaderFromCircuitOutputs = runInSpan(
282
282
  chainId: constants.chainId,
283
283
  version: constants.version,
284
284
  blockNumber: BlockNumber(blockRootRollupOutput.previousArchive.nextAvailableLeafIndex),
285
- timestamp: blockRootRollupOutput.endTimestamp,
285
+ timestamp: blockRootRollupOutput.timestamp,
286
286
  slotNumber: constants.slotNumber,
287
287
  coinbase: constants.coinbase,
288
288
  feeRecipient: constants.feeRecipient,
@@ -11,6 +11,7 @@ import {
11
11
  type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
12
12
  type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
13
13
  NUM_MSGS_PER_BASE_PARITY,
14
+ OUT_HASH_TREE_HEIGHT,
14
15
  } from '@aztec/constants';
15
16
  import { BlockNumber } from '@aztec/foundation/branded-types';
16
17
  import { padArrayEnd } from '@aztec/foundation/collection';
@@ -19,6 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
19
20
  import type { Tuple } from '@aztec/foundation/serialize';
20
21
  import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
21
22
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
23
+ import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
22
24
  import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
23
25
  import {
24
26
  BlockMergeRollupPrivateInputs,
@@ -38,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
38
40
  import { BlockProvingState, type ProofState } from './block-proving-state.js';
39
41
  import type { EpochProvingState } from './epoch-proving-state.js';
40
42
 
43
+ type OutHashHint = {
44
+ treeSnapshot: AppendOnlyTreeSnapshot;
45
+ siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
46
+ };
47
+
41
48
  export class CheckpointProvingState {
42
49
  private blockProofs: UnbalancedTreeStore<
43
50
  ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
@@ -46,6 +53,11 @@ export class CheckpointProvingState {
46
53
  | ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
47
54
  | undefined;
48
55
  private blocks: (BlockProvingState | undefined)[] = [];
56
+ private previousOutHashHint: OutHashHint | undefined;
57
+ private outHash: Fr | undefined;
58
+ // The snapshot and sibling path after the checkpoint's out hash is inserted.
59
+ // Stored here to be retrieved for the next checkpoint when it's added.
60
+ private newOutHashHint: OutHashHint | undefined;
49
61
  private startBlobAccumulator: BatchedBlobAccumulator | undefined;
50
62
  private endBlobAccumulator: BatchedBlobAccumulator | undefined;
51
63
  private blobFields: Fr[] | undefined;
@@ -195,6 +207,35 @@ export class CheckpointProvingState {
195
207
  return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
196
208
  }
197
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
+
198
239
  public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
199
240
  if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
200
241
  return;
@@ -236,6 +277,9 @@ export class CheckpointProvingState {
236
277
  if (proofs.length !== nonEmptyProofs.length) {
237
278
  throw new Error('At least one child is not ready for the checkpoint root rollup.');
238
279
  }
280
+ if (!this.previousOutHashHint) {
281
+ throw new Error('Out hash hint is not set.');
282
+ }
239
283
  if (!this.startBlobAccumulator) {
240
284
  throw new Error('Start blob accumulator is not set.');
241
285
  }
@@ -248,6 +292,8 @@ export class CheckpointProvingState {
248
292
  const hints = CheckpointRootRollupHints.from({
249
293
  previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
250
294
  previousArchiveSiblingPath: this.lastArchiveSiblingPath,
295
+ previousOutHash: this.previousOutHashHint.treeSnapshot,
296
+ newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
251
297
  startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
252
298
  finalBlobChallenges: this.finalBlobBatchingChallenges,
253
299
  blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
@@ -273,7 +319,7 @@ export class CheckpointProvingState {
273
319
 
274
320
  public isReadyForCheckpointRoot() {
275
321
  const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
276
- return allChildProofsReady && !!this.startBlobAccumulator;
322
+ return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
277
323
  }
278
324
 
279
325
  public verifyState() {
@@ -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
9
  import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
9
- import type { Fr } from '@aztec/foundation/curves/bn254';
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';
@@ -212,6 +218,48 @@ export class EpochProvingState {
212
218
  this.checkpointPaddingProof = { provingOutput };
213
219
  }
214
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
+
215
263
  public async setBlobAccumulators() {
216
264
  let previousAccumulator = this.startBlobAccumulator;
217
265
  // Accumulate blobs as far as we can for this epoch.