@aztec/prover-node 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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 (58) hide show
  1. package/dest/actions/download-epoch-proving-job.d.ts +4 -4
  2. package/dest/actions/download-epoch-proving-job.js +1 -1
  3. package/dest/actions/index.d.ts +1 -1
  4. package/dest/actions/rerun-epoch-proving-job.d.ts +5 -3
  5. package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
  6. package/dest/actions/rerun-epoch-proving-job.js +9 -7
  7. package/dest/actions/upload-epoch-proof-failure.d.ts +2 -2
  8. package/dest/actions/upload-epoch-proof-failure.d.ts.map +1 -1
  9. package/dest/bin/run-failed-epoch.d.ts +1 -1
  10. package/dest/bin/run-failed-epoch.js +6 -5
  11. package/dest/config.d.ts +8 -10
  12. package/dest/config.d.ts.map +1 -1
  13. package/dest/config.js +19 -21
  14. package/dest/factory.d.ts +20 -16
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +48 -63
  17. package/dest/index.d.ts +2 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -0
  20. package/dest/job/epoch-proving-job-data.d.ts +8 -6
  21. package/dest/job/epoch-proving-job-data.d.ts.map +1 -1
  22. package/dest/job/epoch-proving-job-data.js +25 -18
  23. package/dest/job/epoch-proving-job.d.ts +11 -13
  24. package/dest/job/epoch-proving-job.d.ts.map +1 -1
  25. package/dest/job/epoch-proving-job.js +669 -111
  26. package/dest/metrics.d.ts +24 -3
  27. package/dest/metrics.d.ts.map +1 -1
  28. package/dest/metrics.js +77 -98
  29. package/dest/monitors/epoch-monitor.d.ts +3 -2
  30. package/dest/monitors/epoch-monitor.d.ts.map +1 -1
  31. package/dest/monitors/epoch-monitor.js +14 -20
  32. package/dest/monitors/index.d.ts +1 -1
  33. package/dest/prover-node-publisher.d.ts +33 -11
  34. package/dest/prover-node-publisher.d.ts.map +1 -1
  35. package/dest/prover-node-publisher.js +248 -46
  36. package/dest/prover-node.d.ts +30 -19
  37. package/dest/prover-node.d.ts.map +1 -1
  38. package/dest/prover-node.js +512 -81
  39. package/dest/prover-publisher-factory.d.ts +10 -6
  40. package/dest/prover-publisher-factory.d.ts.map +1 -1
  41. package/dest/prover-publisher-factory.js +7 -5
  42. package/dest/test/index.d.ts +1 -1
  43. package/dest/test/index.d.ts.map +1 -1
  44. package/package.json +27 -25
  45. package/src/actions/download-epoch-proving-job.ts +1 -1
  46. package/src/actions/rerun-epoch-proving-job.ts +20 -7
  47. package/src/actions/upload-epoch-proof-failure.ts +1 -1
  48. package/src/bin/run-failed-epoch.ts +5 -3
  49. package/src/config.ts +27 -33
  50. package/src/factory.ts +81 -103
  51. package/src/index.ts +1 -0
  52. package/src/job/epoch-proving-job-data.ts +31 -25
  53. package/src/job/epoch-proving-job.ts +228 -117
  54. package/src/metrics.ts +102 -82
  55. package/src/monitors/epoch-monitor.ts +10 -17
  56. package/src/prover-node-publisher.ts +302 -66
  57. package/src/prover-node.ts +135 -86
  58. package/src/prover-publisher-factory.ts +19 -11
@@ -1,25 +1,29 @@
1
- import type { BatchedBlob } from '@aztec/blob-lib';
2
- import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
3
- import type { L1TxUtils, RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum';
1
+ import { BatchedBlob, getEthBlobEvaluationInputs } from '@aztec/blob-lib';
2
+ import { MAX_CHECKPOINTS_PER_EPOCH } from '@aztec/constants';
3
+ import type { RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum/contracts';
4
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
4
5
  import { makeTuple } from '@aztec/foundation/array';
6
+ import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
5
7
  import { areArraysEqual } from '@aztec/foundation/collection';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
9
  import { EthAddress } from '@aztec/foundation/eth-address';
7
- import { Fr } from '@aztec/foundation/fields';
8
- import { createLogger } from '@aztec/foundation/log';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
11
+ import { retryUntil } from '@aztec/foundation/retry';
9
12
  import type { Tuple } from '@aztec/foundation/serialize';
10
13
  import { Timer } from '@aztec/foundation/timer';
11
14
  import { RollupAbi } from '@aztec/l1-artifacts';
12
15
  import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
13
16
  import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
17
+ import { getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
14
18
  import type { Proof } from '@aztec/stdlib/proofs';
15
19
  import type { FeeRecipient, RootRollupPublicInputs } from '@aztec/stdlib/rollup';
16
20
  import type { L1PublishProofStats } from '@aztec/stdlib/stats';
17
21
  import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
18
22
 
19
23
  import { inspect } from 'util';
20
- import { type Hex, type TransactionReceipt, encodeFunctionData } from 'viem';
24
+ import { type Hex, type TransactionReceipt, encodeFunctionData, formatEther, formatGwei } from 'viem';
21
25
 
22
- import { ProverNodePublisherMetrics } from './metrics.js';
26
+ import { type EstimatedSubmitProofStats, ProverNodePublisherMetrics } from './metrics.js';
23
27
 
24
28
  /** Arguments to the submitEpochProof method of the rollup contract */
25
29
  export type L1SubmitEpochProofArgs = {
@@ -29,7 +33,7 @@ export type L1SubmitEpochProofArgs = {
29
33
  endTimestamp: Fr;
30
34
  outHash: Fr;
31
35
  proverId: Fr;
32
- fees: Tuple<FeeRecipient, typeof AZTEC_MAX_EPOCH_DURATION>;
36
+ fees: Tuple<FeeRecipient, typeof MAX_CHECKPOINTS_PER_EPOCH>;
33
37
  proof: Proof;
34
38
  };
35
39
 
@@ -37,7 +41,7 @@ export class ProverNodePublisher {
37
41
  private interrupted = false;
38
42
  private metrics: ProverNodePublisherMetrics;
39
43
 
40
- protected log = createLogger('prover-node:l1-tx-publisher');
44
+ protected log: Logger;
41
45
 
42
46
  protected rollupContract: RollupContract;
43
47
 
@@ -50,10 +54,12 @@ export class ProverNodePublisher {
50
54
  l1TxUtils: L1TxUtils;
51
55
  telemetry?: TelemetryClient;
52
56
  },
57
+ bindings?: LoggerBindings,
53
58
  ) {
54
59
  const telemetry = deps.telemetry ?? getTelemetryClient();
55
60
 
56
61
  this.metrics = new ProverNodePublisherMetrics(telemetry, 'ProverNode');
62
+ this.log = createLogger('prover-node:l1-tx-publisher', bindings);
57
63
 
58
64
  this.rollupContract = deps.rollupContract;
59
65
  this.l1TxUtils = deps.l1TxUtils;
@@ -85,24 +91,30 @@ export class ProverNodePublisher {
85
91
  }
86
92
 
87
93
  public async submitEpochProof(args: {
88
- epochNumber: number;
89
- fromBlock: number;
90
- toBlock: number;
94
+ epochNumber: EpochNumber;
95
+ fromCheckpoint: CheckpointNumber;
96
+ toCheckpoint: CheckpointNumber;
91
97
  publicInputs: RootRollupPublicInputs;
92
98
  proof: Proof;
93
99
  batchedBlobInputs: BatchedBlob;
94
100
  attestations: ViemCommitteeAttestation[];
95
101
  }): Promise<boolean> {
96
- const { epochNumber, fromBlock, toBlock } = args;
97
- const ctx = { epochNumber, fromBlock, toBlock };
102
+ const { epochNumber, fromCheckpoint, toCheckpoint } = args;
103
+ const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
98
104
 
99
105
  if (!this.interrupted) {
106
+ if (!(await this.waitUntilStartBuildsOnProven(args))) {
107
+ this.log.verbose('Checkpoint data syncing interrupted', ctx);
108
+ return false;
109
+ }
110
+
100
111
  const timer = new Timer();
101
112
  // Validate epoch proof range and hashes are correct before submitting
102
113
  await this.validateEpochProofSubmission(args);
103
114
 
104
115
  const txReceipt = await this.sendSubmitEpochProofTx(args);
105
116
  if (!txReceipt) {
117
+ this.log.error(`Failed to mine submitEpochProof tx`, undefined, ctx);
106
118
  return false;
107
119
  }
108
120
 
@@ -135,47 +147,98 @@ export class ProverNodePublisher {
135
147
  }
136
148
 
137
149
  this.metrics.recordFailedTx();
138
- this.log.error(`Rollup.submitEpochProof tx status failed ${txReceipt.transactionHash}`, undefined, ctx);
150
+ this.log.error(`Rollup submitEpochProof tx reverted ${txReceipt.transactionHash}`, undefined, ctx);
139
151
  }
140
152
 
141
- this.log.verbose('L2 block data syncing interrupted', ctx);
153
+ this.log.verbose('Checkpoint data syncing interrupted', ctx);
142
154
  return false;
143
155
  }
144
156
 
157
+ private async waitUntilStartBuildsOnProven(args: { epochNumber: EpochNumber; fromCheckpoint: CheckpointNumber }) {
158
+ const { epochNumber, fromCheckpoint } = args;
159
+ const provenCheckpoint = await this.getProvenCheckpoint();
160
+ if (this.isStartBuildingOnProven(fromCheckpoint, provenCheckpoint)) {
161
+ return true;
162
+ }
163
+
164
+ const timeout = await this.getSecondsUntilProofSubmissionWindowEnd(epochNumber);
165
+ this.log.info(`Waiting for proven checkpoint to reach proof start`, {
166
+ epochNumber,
167
+ fromCheckpoint,
168
+ provenCheckpoint,
169
+ timeout,
170
+ });
171
+
172
+ await retryUntil(
173
+ async () => {
174
+ if (this.interrupted) {
175
+ return true;
176
+ }
177
+
178
+ const proven = await this.getProvenCheckpoint();
179
+ this.log.verbose(`Proven checkpoint is at ${proven} (waiting for ${fromCheckpoint - 1})`, { epochNumber });
180
+ return this.isStartBuildingOnProven(fromCheckpoint, proven) ? true : undefined;
181
+ },
182
+ `proven checkpoint to reach ${fromCheckpoint - 1}`,
183
+ timeout,
184
+ 4,
185
+ );
186
+
187
+ return !this.interrupted;
188
+ }
189
+
190
+ private async getProvenCheckpoint() {
191
+ return (await this.rollupContract.getTips()).proven;
192
+ }
193
+
194
+ private isStartBuildingOnProven(fromCheckpoint: CheckpointNumber, provenCheckpoint: CheckpointNumber) {
195
+ return fromCheckpoint - 1 <= provenCheckpoint;
196
+ }
197
+
198
+ private async getSecondsUntilProofSubmissionWindowEnd(epochNumber: EpochNumber) {
199
+ const deadline = getProofSubmissionDeadlineTimestamp(epochNumber, await this.rollupContract.getRollupConstants());
200
+ const now = BigInt(Math.floor(Date.now() / 1000));
201
+ return Math.max(Number(deadline - now), 0.001);
202
+ }
203
+
145
204
  private async validateEpochProofSubmission(args: {
146
- fromBlock: number;
147
- toBlock: number;
205
+ fromCheckpoint: CheckpointNumber;
206
+ toCheckpoint: CheckpointNumber;
148
207
  publicInputs: RootRollupPublicInputs;
149
208
  proof: Proof;
150
209
  batchedBlobInputs: BatchedBlob;
151
210
  attestations: ViemCommitteeAttestation[];
152
211
  }) {
153
- const { fromBlock, toBlock, publicInputs, batchedBlobInputs } = args;
212
+ const { fromCheckpoint, toCheckpoint, publicInputs, batchedBlobInputs } = args;
154
213
 
155
- // Check that the block numbers match the expected epoch to be proven
156
- const { pendingBlockNumber: pending, provenBlockNumber: proven } = await this.rollupContract.getTips();
157
- // Don't publish if proven is beyond our toBlock, pointless to do so
158
- if (proven > BigInt(toBlock)) {
159
- throw new Error(`Cannot submit epoch proof for ${fromBlock}-${toBlock} as proven block is ${proven}`);
214
+ // Check that the checkpoint numbers match the expected epoch to be proven
215
+ const { pending, proven } = await this.rollupContract.getTips();
216
+ // Don't publish if proven is beyond our toCheckpoint, pointless to do so
217
+ if (proven > toCheckpoint) {
218
+ throw new Error(
219
+ `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proven checkpoint is ${proven}`,
220
+ );
160
221
  }
161
- // toBlock can't be greater than pending
162
- if (toBlock > pending) {
163
- throw new Error(`Cannot submit epoch proof for ${fromBlock}-${toBlock} as pending block is ${pending}`);
222
+ // toCheckpoint can't be greater than pending
223
+ if (toCheckpoint > pending) {
224
+ throw new Error(
225
+ `Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
226
+ );
164
227
  }
165
228
 
166
- // Check the archive for the immediate block before the epoch
167
- const blockLog = await this.rollupContract.getBlock(BigInt(fromBlock - 1));
168
- if (publicInputs.previousArchiveRoot.toString() !== blockLog.archive) {
229
+ // Check the archive for the immediate checkpoint before the epoch
230
+ const checkpointLog = await this.rollupContract.getCheckpoint(CheckpointNumber(fromCheckpoint - 1));
231
+ if (!publicInputs.previousArchiveRoot.equals(checkpointLog.archive)) {
169
232
  throw new Error(
170
- `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${blockLog.archive}`,
233
+ `Previous archive root mismatch: ${publicInputs.previousArchiveRoot.toString()} !== ${checkpointLog.archive.toString()}`,
171
234
  );
172
235
  }
173
236
 
174
- // Check the archive for the last block in the epoch
175
- const endBlockLog = await this.rollupContract.getBlock(BigInt(toBlock));
176
- if (publicInputs.endArchiveRoot.toString() !== endBlockLog.archive) {
237
+ // Check the archive for the last checkpoint in the epoch
238
+ const endCheckpointLog = await this.rollupContract.getCheckpoint(toCheckpoint);
239
+ if (!publicInputs.endArchiveRoot.equals(endCheckpointLog.archive)) {
177
240
  throw new Error(
178
- `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endBlockLog.archive}`,
241
+ `End archive root mismatch: ${publicInputs.endArchiveRoot.toString()} !== ${endCheckpointLog.archive.toString()}`,
179
242
  );
180
243
  }
181
244
 
@@ -193,17 +256,89 @@ export class ProverNodePublisher {
193
256
  );
194
257
  const argsPublicInputs = [...publicInputs.toFields()];
195
258
 
196
- if (!areArraysEqual(rollupPublicInputs.map(Fr.fromHexString), argsPublicInputs, (a, b) => a.equals(b))) {
197
- const fmt = (inputs: Fr[] | readonly string[]) => inputs.map(x => x.toString()).join(', ');
198
- throw new Error(
199
- `Root rollup public inputs mismatch:\nRollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
200
- );
259
+ if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
260
+ throw await reportPublicInputsMismatch({
261
+ rollupPublicInputs,
262
+ argsPublicInputs,
263
+ fromCheckpoint,
264
+ toCheckpoint,
265
+ rollupContract: this.rollupContract,
266
+ log: this.log,
267
+ });
201
268
  }
202
269
  }
203
270
 
271
+ /**
272
+ * Estimates what submitting the epoch proof would have cost on L1 without actually sending it.
273
+ * Runs the same validation as `submitEpochProof`, encodes the calldata, estimates gas, and records metrics.
274
+ * Used when proof publishing is disabled (e.g. PROVER_NODE_DISABLE_PROOF_PUBLISH=true on mainnet).
275
+ */
276
+ public async analyzeEpochProofSubmission(args: {
277
+ epochNumber: EpochNumber;
278
+ fromCheckpoint: CheckpointNumber;
279
+ toCheckpoint: CheckpointNumber;
280
+ publicInputs: RootRollupPublicInputs;
281
+ proof: Proof;
282
+ batchedBlobInputs: BatchedBlob;
283
+ attestations: ViemCommitteeAttestation[];
284
+ }): Promise<void> {
285
+ const { epochNumber, fromCheckpoint, toCheckpoint } = args;
286
+
287
+ await this.validateEpochProofSubmission(args);
288
+
289
+ const data = this.encodeSubmitEpochProofCalldata(args);
290
+ const senderAddress = this.l1TxUtils.getSenderAddress();
291
+
292
+ const [gasLimit, gasPrice, latestBlock] = await Promise.all([
293
+ this.l1TxUtils.estimateGas(senderAddress.toString() as `0x${string}`, { to: this.rollupContract.address, data }),
294
+ this.l1TxUtils.getGasPrice(),
295
+ this.l1TxUtils.client.getBlock({ blockTag: 'latest' }),
296
+ ]);
297
+
298
+ const baseFeePerGas = latestBlock.baseFeePerGas ?? 0n;
299
+ const { maxPriorityFeePerGas } = gasPrice;
300
+
301
+ const effectiveFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
302
+ const estimatedTotalFee = gasLimit * effectiveFeePerGas;
303
+
304
+ const stats: EstimatedSubmitProofStats = {
305
+ gasLimit,
306
+ baseFeePerGas,
307
+ maxPriorityFeePerGas,
308
+ estimatedTotalFee,
309
+ };
310
+
311
+ this.log.info(`Estimated epoch proof submission cost (not submitted)`, {
312
+ epochNumber,
313
+ fromCheckpoint,
314
+ toCheckpoint,
315
+ gasLimit: gasLimit.toString(),
316
+ baseFeePerGas: formatGwei(baseFeePerGas),
317
+ maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
318
+ estimatedTotalFeeEth: formatEther(estimatedTotalFee),
319
+ });
320
+
321
+ this.metrics.recordEstimatedSubmitProof(stats);
322
+ }
323
+
324
+ private encodeSubmitEpochProofCalldata(args: {
325
+ fromCheckpoint: CheckpointNumber;
326
+ toCheckpoint: CheckpointNumber;
327
+ publicInputs: RootRollupPublicInputs;
328
+ proof: Proof;
329
+ batchedBlobInputs: BatchedBlob;
330
+ attestations: ViemCommitteeAttestation[];
331
+ }): Hex {
332
+ return encodeFunctionData({
333
+ abi: RollupAbi,
334
+ functionName: 'submitEpochRootProof',
335
+ args: [this.getSubmitEpochProofArgs(args)],
336
+ });
337
+ }
338
+
204
339
  private async sendSubmitEpochProofTx(args: {
205
- fromBlock: number;
206
- toBlock: number;
340
+ fromCheckpoint: CheckpointNumber;
341
+ toCheckpoint: CheckpointNumber;
207
342
  publicInputs: RootRollupPublicInputs;
208
343
  proof: Proof;
209
344
  batchedBlobInputs: BatchedBlob;
@@ -213,8 +348,8 @@ export class ProverNodePublisher {
213
348
 
214
349
  this.log.info(`Submitting epoch proof to L1 rollup contract`, {
215
350
  proofSize: args.proof.withoutPublicInputs().length,
216
- fromBlock: args.fromBlock,
217
- toBlock: args.toBlock,
351
+ fromCheckpoint: args.fromCheckpoint,
352
+ toCheckpoint: args.toCheckpoint,
218
353
  });
219
354
  const data = encodeFunctionData({
220
355
  abi: RollupAbi,
@@ -223,53 +358,57 @@ export class ProverNodePublisher {
223
358
  });
224
359
  try {
225
360
  const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction({ to: this.rollupContract.address, data });
361
+ if (receipt.status !== 'success') {
362
+ const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
363
+ data,
364
+ {
365
+ args: [...txArgs],
366
+ functionName: 'submitEpochRootProof',
367
+ abi: RollupAbi,
368
+ address: this.rollupContract.address,
369
+ },
370
+ /*blobInputs*/ undefined,
371
+ /*stateOverride*/ [],
372
+ );
373
+ this.log.error(`Rollup submit epoch proof tx reverted with ${errorMsg ?? 'unknown error'}`);
374
+ return undefined;
375
+ }
226
376
  return receipt;
227
377
  } catch (err) {
228
378
  this.log.error(`Rollup submit epoch proof failed`, err);
229
- const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
230
- data,
231
- {
232
- args: [...txArgs],
233
- functionName: 'submitEpochRootProof',
234
- abi: RollupAbi,
235
- address: this.rollupContract.address,
236
- },
237
- /*blobInputs*/ undefined,
238
- /*stateOverride*/ [],
239
- );
240
- this.log.error(`Rollup submit epoch proof tx reverted. ${errorMsg}`);
241
379
  return undefined;
242
380
  }
243
381
  }
244
382
 
245
383
  private getEpochProofPublicInputsArgs(args: {
246
- fromBlock: number;
247
- toBlock: number;
384
+ fromCheckpoint: CheckpointNumber;
385
+ toCheckpoint: CheckpointNumber;
248
386
  publicInputs: RootRollupPublicInputs;
249
387
  batchedBlobInputs: BatchedBlob;
250
388
  attestations: ViemCommitteeAttestation[];
251
389
  }) {
252
390
  // Returns arguments for EpochProofLib.sol -> getEpochProofPublicInputs()
253
391
  return [
254
- BigInt(args.fromBlock) /*_start*/,
255
- BigInt(args.toBlock) /*_end*/,
392
+ BigInt(args.fromCheckpoint) /*_start*/,
393
+ BigInt(args.toCheckpoint) /*_end*/,
256
394
  {
257
395
  previousArchive: args.publicInputs.previousArchiveRoot.toString(),
258
396
  endArchive: args.publicInputs.endArchiveRoot.toString(),
397
+ outHash: args.publicInputs.outHash.toString(),
259
398
  proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
260
399
  } /*_args*/,
261
- makeTuple(AZTEC_MAX_EPOCH_DURATION * 2, i =>
400
+ makeTuple(MAX_CHECKPOINTS_PER_EPOCH * 2, i =>
262
401
  i % 2 === 0
263
402
  ? args.publicInputs.fees[i / 2].recipient.toField().toString()
264
403
  : args.publicInputs.fees[(i - 1) / 2].value.toString(),
265
404
  ) /*_fees*/,
266
- args.batchedBlobInputs.getEthBlobEvaluationInputs() /*_blobPublicInputs*/,
405
+ getEthBlobEvaluationInputs(args.batchedBlobInputs) /*_blobPublicInputs*/,
267
406
  ] as const;
268
407
  }
269
408
 
270
409
  private getSubmitEpochProofArgs(args: {
271
- fromBlock: number;
272
- toBlock: number;
410
+ fromCheckpoint: CheckpointNumber;
411
+ toCheckpoint: CheckpointNumber;
273
412
  publicInputs: RootRollupPublicInputs;
274
413
  proof: Proof;
275
414
  batchedBlobInputs: BatchedBlob;
@@ -283,11 +422,108 @@ export class ProverNodePublisher {
283
422
  end: argsArray[1],
284
423
  args: argsArray[2],
285
424
  fees: argsArray[3],
286
- attestations: new CommitteeAttestationsAndSigners(
425
+ attestations: CommitteeAttestationsAndSigners.packAttestations(
287
426
  args.attestations.map(a => CommitteeAttestation.fromViem(a)),
288
- ).getPackedAttestations(),
427
+ ),
289
428
  blobInputs: argsArray[4],
290
429
  proof: proofHex,
291
430
  };
292
431
  }
293
432
  }
433
+
434
+ /**
435
+ * Decodes a `Root rollup public inputs mismatch`, fetches the on-chain CheckpointLog for any
436
+ * mismatching `checkpointHeaderHashes[i]`, emits a structured error log, and returns a thrown-ready
437
+ * Error with a human-readable summary.
438
+ *
439
+ * Layout of `RootRollupPublicInputs.toFields()`:
440
+ * [0] previousArchiveRoot
441
+ * [1] endArchiveRoot
442
+ * [2] outHash
443
+ * [3 .. 3+N-1] checkpointHeaderHashes[i] for i in 0..N-1 (N = MAX_CHECKPOINTS_PER_EPOCH)
444
+ * [3+N .. 3+3N-1] fees[i] = (recipient, value) for i in 0..N-1
445
+ * [3+3N .. 3+3N+4] EpochConstantData (chainId, version, vkTreeRoot, protocolContractsHash, proverId)
446
+ * [3+3N+5 ..] blobPublicInputs (FinalBlobAccumulator)
447
+ */
448
+ async function reportPublicInputsMismatch(input: {
449
+ rollupPublicInputs: readonly Fr[];
450
+ argsPublicInputs: readonly Fr[];
451
+ fromCheckpoint: CheckpointNumber;
452
+ toCheckpoint: CheckpointNumber;
453
+ rollupContract: RollupContract;
454
+ log: Logger;
455
+ }): Promise<Error> {
456
+ const { rollupPublicInputs, argsPublicInputs, fromCheckpoint, toCheckpoint, rollupContract, log } = input;
457
+ const N = MAX_CHECKPOINTS_PER_EPOCH;
458
+ const constantsStart = 3 + 3 * N;
459
+ const blobStart = constantsStart + 5;
460
+ const constantLabels = ['chainId', 'version', 'vkTreeRoot', 'protocolContractsHash', 'proverId'];
461
+
462
+ const diffs: { index: number; label: string; rollup: Fr; computed: Fr; checkpointIndex?: number }[] = [];
463
+ const len = Math.max(rollupPublicInputs.length, argsPublicInputs.length);
464
+ for (let i = 0; i < len; i++) {
465
+ const a = rollupPublicInputs[i] ?? Fr.ZERO;
466
+ const b = argsPublicInputs[i] ?? Fr.ZERO;
467
+ if (a.equals(b)) {
468
+ continue;
469
+ }
470
+ let label: string;
471
+ let checkpointIndex: number | undefined;
472
+ if (i === 0) {
473
+ label = 'previousArchiveRoot';
474
+ } else if (i === 1) {
475
+ label = 'endArchiveRoot';
476
+ } else if (i === 2) {
477
+ label = 'outHash';
478
+ } else if (i < 3 + N) {
479
+ checkpointIndex = i - 3;
480
+ label = `checkpointHeaderHashes[${checkpointIndex}]`;
481
+ } else if (i < 3 + 3 * N) {
482
+ const feePairIndex = i - (3 + N);
483
+ const feeIndex = Math.floor(feePairIndex / 2);
484
+ const sub = feePairIndex % 2 === 0 ? 'recipient' : 'value';
485
+ label = `fees[${feeIndex}].${sub}`;
486
+ } else if (i < blobStart) {
487
+ label = `constants.${constantLabels[i - constantsStart]}`;
488
+ } else {
489
+ label = `blobPublicInputs[${i - blobStart}]`;
490
+ }
491
+ diffs.push({ index: i, label, rollup: a, computed: b, checkpointIndex });
492
+ }
493
+
494
+ // For each mismatching checkpointHeaderHash, fetch the L1 CheckpointLog so the operator can
495
+ // see what was published on-chain alongside the prover's recomputed hash.
496
+ const onChainCheckpoints = await Promise.all(
497
+ diffs
498
+ .filter(d => d.checkpointIndex !== undefined)
499
+ .map(async d => {
500
+ const checkpointNumber = CheckpointNumber(fromCheckpoint + d.checkpointIndex!);
501
+ try {
502
+ const cp = await rollupContract.getCheckpoint(checkpointNumber);
503
+ return { checkpointIndex: d.checkpointIndex!, checkpointNumber, headerHash: cp.headerHash.toString() };
504
+ } catch (err) {
505
+ return { checkpointIndex: d.checkpointIndex!, checkpointNumber, error: (err as Error).message };
506
+ }
507
+ }),
508
+ );
509
+
510
+ log.error(`Root rollup public inputs mismatch`, undefined, {
511
+ fromCheckpoint,
512
+ toCheckpoint,
513
+ numDiffs: diffs.length,
514
+ diffs: diffs.map(d => ({
515
+ index: d.index,
516
+ label: d.label,
517
+ rollup: d.rollup.toString(),
518
+ computed: d.computed.toString(),
519
+ })),
520
+ onChainCheckpoints,
521
+ });
522
+
523
+ const fmt = (inputs: readonly Fr[]) => inputs.map(x => x.toString()).join(', ');
524
+ const summary = diffs.map(d => `[${d.index} ${d.label}] L1=${d.rollup} prover=${d.computed}`).join('\n');
525
+ return new Error(
526
+ `Root rollup public inputs mismatch (${diffs.length} fields differ):\n${summary}\n` +
527
+ `Rollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
528
+ );
529
+ }