@aztec/prover-node 5.0.0-private.20260319 → 5.0.0-rc.2
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.
- package/README.md +518 -0
- package/dest/actions/download-epoch-proving-job.js +1 -1
- package/dest/actions/rerun-epoch-proving-job.d.ts +4 -3
- package/dest/actions/rerun-epoch-proving-job.d.ts.map +1 -1
- package/dest/actions/rerun-epoch-proving-job.js +103 -21
- package/dest/bin/run-failed-epoch.js +1 -3
- package/dest/checkpoint-store.d.ts +87 -0
- package/dest/checkpoint-store.d.ts.map +1 -0
- package/dest/checkpoint-store.js +186 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +22 -8
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/job/checkpoint-prover.d.ts +134 -0
- package/dest/job/checkpoint-prover.d.ts.map +1 -0
- package/dest/job/checkpoint-prover.js +353 -0
- package/dest/job/epoch-session.d.ts +146 -0
- package/dest/job/epoch-session.d.ts.map +1 -0
- package/dest/job/epoch-session.js +720 -0
- package/dest/job/top-tree-job.d.ts +82 -0
- package/dest/job/top-tree-job.d.ts.map +1 -0
- package/dest/job/top-tree-job.js +152 -0
- package/dest/metrics.d.ts +35 -8
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +86 -14
- package/dest/monitors/epoch-monitor.js +6 -2
- package/dest/proof-publishing-service.d.ts +161 -0
- package/dest/proof-publishing-service.d.ts.map +1 -0
- package/dest/proof-publishing-service.js +335 -0
- package/dest/prover-node-publisher.d.ts +22 -15
- package/dest/prover-node-publisher.d.ts.map +1 -1
- package/dest/prover-node-publisher.js +197 -60
- package/dest/prover-node.d.ts +105 -67
- package/dest/prover-node.d.ts.map +1 -1
- package/dest/prover-node.js +482 -224
- package/dest/prover-publisher-factory.d.ts +2 -2
- package/dest/prover-publisher-factory.d.ts.map +1 -1
- package/dest/prover-publisher-factory.js +3 -3
- package/dest/session-manager.d.ts +158 -0
- package/dest/session-manager.d.ts.map +1 -0
- package/dest/session-manager.js +452 -0
- package/dest/test/index.d.ts +7 -6
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/actions/download-epoch-proving-job.ts +1 -1
- package/src/actions/rerun-epoch-proving-job.ts +114 -28
- package/src/bin/run-failed-epoch.ts +1 -2
- package/src/checkpoint-store.ts +218 -0
- package/src/config.ts +2 -1
- package/src/factory.ts +18 -10
- package/src/index.ts +1 -0
- package/src/job/checkpoint-prover.ts +468 -0
- package/src/job/epoch-session.ts +436 -0
- package/src/job/top-tree-job.ts +227 -0
- package/src/metrics.ts +102 -23
- package/src/monitors/epoch-monitor.ts +2 -2
- package/src/proof-publishing-service.ts +427 -0
- package/src/prover-node-publisher.ts +231 -77
- package/src/prover-node.ts +552 -251
- package/src/prover-publisher-factory.ts +3 -3
- package/src/session-manager.ts +552 -0
- package/src/test/index.ts +6 -6
- package/dest/job/epoch-proving-job.d.ts +0 -63
- package/dest/job/epoch-proving-job.d.ts.map +0 -1
- package/dest/job/epoch-proving-job.js +0 -762
- package/src/job/epoch-proving-job.ts +0 -465
|
@@ -2,26 +2,24 @@ import { BatchedBlob, getEthBlobEvaluationInputs } from '@aztec/blob-lib';
|
|
|
2
2
|
import { MAX_CHECKPOINTS_PER_EPOCH } from '@aztec/constants';
|
|
3
3
|
import type { RollupContract, ViemCommitteeAttestation } from '@aztec/ethereum/contracts';
|
|
4
4
|
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
5
|
-
import { makeTuple } from '@aztec/foundation/array';
|
|
6
5
|
import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
7
6
|
import { areArraysEqual } from '@aztec/foundation/collection';
|
|
8
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
9
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
|
-
import type { Tuple } from '@aztec/foundation/serialize';
|
|
12
10
|
import { Timer } from '@aztec/foundation/timer';
|
|
13
11
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
14
12
|
import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client';
|
|
15
13
|
import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
16
14
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
17
|
-
import type {
|
|
15
|
+
import type { CheckpointHeader, RootRollupPublicInputs } from '@aztec/stdlib/rollup';
|
|
18
16
|
import type { L1PublishProofStats } from '@aztec/stdlib/stats';
|
|
19
17
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
20
18
|
|
|
21
19
|
import { inspect } from 'util';
|
|
22
|
-
import { type Hex, type TransactionReceipt, encodeFunctionData } from 'viem';
|
|
20
|
+
import { type Hex, type TransactionReceipt, encodeFunctionData, formatEther, formatGwei } from 'viem';
|
|
23
21
|
|
|
24
|
-
import { ProverNodePublisherMetrics } from './metrics.js';
|
|
22
|
+
import { type EstimatedSubmitProofStats, ProverNodePublisherMetrics } from './metrics.js';
|
|
25
23
|
|
|
26
24
|
/** Arguments to the submitEpochProof method of the rollup contract */
|
|
27
25
|
export type L1SubmitEpochProofArgs = {
|
|
@@ -31,12 +29,11 @@ export type L1SubmitEpochProofArgs = {
|
|
|
31
29
|
endTimestamp: Fr;
|
|
32
30
|
outHash: Fr;
|
|
33
31
|
proverId: Fr;
|
|
34
|
-
|
|
32
|
+
headers: CheckpointHeader[];
|
|
35
33
|
proof: Proof;
|
|
36
34
|
};
|
|
37
35
|
|
|
38
36
|
export class ProverNodePublisher {
|
|
39
|
-
private interrupted = false;
|
|
40
37
|
private metrics: ProverNodePublisherMetrics;
|
|
41
38
|
|
|
42
39
|
protected log: Logger;
|
|
@@ -67,23 +64,6 @@ export class ProverNodePublisher {
|
|
|
67
64
|
return this.rollupContract;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
/**
|
|
71
|
-
* Calling `interrupt` will cause any in progress call to `publishRollup` to return `false` asap.
|
|
72
|
-
* Be warned, the call may return false even if the tx subsequently gets successfully mined.
|
|
73
|
-
* In practice this shouldn't matter, as we'll only ever be calling `interrupt` when we know it's going to fail.
|
|
74
|
-
* A call to `restart` is required before you can continue publishing.
|
|
75
|
-
*/
|
|
76
|
-
public interrupt() {
|
|
77
|
-
this.interrupted = true;
|
|
78
|
-
this.l1TxUtils.interrupt();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** Restarts the publisher after calling `interrupt`. */
|
|
82
|
-
public restart() {
|
|
83
|
-
this.interrupted = false;
|
|
84
|
-
this.l1TxUtils.restart();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
67
|
public getSenderAddress() {
|
|
88
68
|
return this.l1TxUtils.getSenderAddress();
|
|
89
69
|
}
|
|
@@ -96,54 +76,53 @@ export class ProverNodePublisher {
|
|
|
96
76
|
proof: Proof;
|
|
97
77
|
batchedBlobInputs: BatchedBlob;
|
|
98
78
|
attestations: ViemCommitteeAttestation[];
|
|
79
|
+
headers: CheckpointHeader[];
|
|
80
|
+
/** Wall-clock deadline (proof-submission window end) past which the L1 tx should stop retrying. */
|
|
81
|
+
deadline?: Date;
|
|
99
82
|
}): Promise<boolean> {
|
|
100
83
|
const { epochNumber, fromCheckpoint, toCheckpoint } = args;
|
|
101
84
|
const ctx = { epochNumber, fromCheckpoint, toCheckpoint };
|
|
102
85
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await this.validateEpochProofSubmission(args);
|
|
107
|
-
|
|
108
|
-
const txReceipt = await this.sendSubmitEpochProofTx(args);
|
|
109
|
-
if (!txReceipt) {
|
|
110
|
-
this.log.error(`Failed to mine submitEpochProof tx`, undefined, ctx);
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
86
|
+
const timer = new Timer();
|
|
87
|
+
// Validate epoch proof range and hashes are correct before submitting
|
|
88
|
+
await this.validateEpochProofSubmission(args);
|
|
113
89
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
} catch (err) {
|
|
120
|
-
this.log.warn(`Failed to record the ETH balance of the prover node: ${err}`);
|
|
121
|
-
}
|
|
90
|
+
const txReceipt = await this.sendSubmitEpochProofTx(args);
|
|
91
|
+
if (!txReceipt) {
|
|
92
|
+
this.log.error(`Failed to mine submitEpochProof tx`, undefined, ctx);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
122
95
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
calldataSize: tx!.calldataSize,
|
|
132
|
-
sender: tx!.sender,
|
|
133
|
-
blobDataGas: 0n,
|
|
134
|
-
blobGasUsed: 0n,
|
|
135
|
-
eventName: 'proof-published-to-l1',
|
|
136
|
-
};
|
|
137
|
-
this.log.info(`Published epoch proof to L1 rollup contract`, { ...stats, ...ctx });
|
|
138
|
-
this.metrics.recordSubmitProof(timer.ms(), stats);
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
96
|
+
try {
|
|
97
|
+
this.metrics.recordSenderBalance(
|
|
98
|
+
await this.l1TxUtils.getSenderBalance(),
|
|
99
|
+
this.l1TxUtils.getSenderAddress().toString(),
|
|
100
|
+
);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
this.log.warn(`Failed to record the ETH balance of the prover node: ${err}`);
|
|
103
|
+
}
|
|
141
104
|
|
|
142
|
-
|
|
143
|
-
|
|
105
|
+
// Tx was mined successfully
|
|
106
|
+
if (txReceipt.status === 'success') {
|
|
107
|
+
const tx = await this.l1TxUtils.getTransactionStats(txReceipt.transactionHash);
|
|
108
|
+
const stats: L1PublishProofStats = {
|
|
109
|
+
gasPrice: txReceipt.effectiveGasPrice,
|
|
110
|
+
gasUsed: txReceipt.gasUsed,
|
|
111
|
+
transactionHash: txReceipt.transactionHash,
|
|
112
|
+
calldataGas: tx!.calldataGas,
|
|
113
|
+
calldataSize: tx!.calldataSize,
|
|
114
|
+
sender: tx!.sender,
|
|
115
|
+
blobDataGas: 0n,
|
|
116
|
+
blobGasUsed: 0n,
|
|
117
|
+
eventName: 'proof-published-to-l1',
|
|
118
|
+
};
|
|
119
|
+
this.log.info(`Published epoch proof to L1 rollup contract`, { ...stats, ...ctx });
|
|
120
|
+
this.metrics.recordSubmitProof(timer.ms(), stats);
|
|
121
|
+
return true;
|
|
144
122
|
}
|
|
145
123
|
|
|
146
|
-
this.
|
|
124
|
+
this.metrics.recordFailedTx();
|
|
125
|
+
this.log.error(`Rollup submitEpochProof tx reverted ${txReceipt.transactionHash}`, undefined, ctx);
|
|
147
126
|
return false;
|
|
148
127
|
}
|
|
149
128
|
|
|
@@ -154,6 +133,7 @@ export class ProverNodePublisher {
|
|
|
154
133
|
proof: Proof;
|
|
155
134
|
batchedBlobInputs: BatchedBlob;
|
|
156
135
|
attestations: ViemCommitteeAttestation[];
|
|
136
|
+
headers: CheckpointHeader[];
|
|
157
137
|
}) {
|
|
158
138
|
const { fromCheckpoint, toCheckpoint, publicInputs, batchedBlobInputs } = args;
|
|
159
139
|
|
|
@@ -168,7 +148,7 @@ export class ProverNodePublisher {
|
|
|
168
148
|
// toCheckpoint can't be greater than pending
|
|
169
149
|
if (toCheckpoint > pending) {
|
|
170
150
|
throw new Error(
|
|
171
|
-
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as
|
|
151
|
+
`Cannot submit epoch proof for ${fromCheckpoint}-${toCheckpoint} as proposed checkpoint is ${pending}`,
|
|
172
152
|
);
|
|
173
153
|
}
|
|
174
154
|
|
|
@@ -203,20 +183,96 @@ export class ProverNodePublisher {
|
|
|
203
183
|
const argsPublicInputs = [...publicInputs.toFields()];
|
|
204
184
|
|
|
205
185
|
if (!areArraysEqual(rollupPublicInputs, argsPublicInputs, (a, b) => a.equals(b))) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
186
|
+
throw await reportPublicInputsMismatch({
|
|
187
|
+
rollupPublicInputs,
|
|
188
|
+
argsPublicInputs,
|
|
189
|
+
fromCheckpoint,
|
|
190
|
+
toCheckpoint,
|
|
191
|
+
rollupContract: this.rollupContract,
|
|
192
|
+
log: this.log,
|
|
193
|
+
});
|
|
210
194
|
}
|
|
211
195
|
}
|
|
212
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Estimates what submitting the epoch proof would have cost on L1 without actually sending it.
|
|
199
|
+
* Runs the same validation as `submitEpochProof`, encodes the calldata, estimates gas, and records metrics.
|
|
200
|
+
* Used when proof publishing is disabled (e.g. PROVER_NODE_DISABLE_PROOF_PUBLISH=true on mainnet).
|
|
201
|
+
*/
|
|
202
|
+
public async analyzeEpochProofSubmission(args: {
|
|
203
|
+
epochNumber: EpochNumber;
|
|
204
|
+
fromCheckpoint: CheckpointNumber;
|
|
205
|
+
toCheckpoint: CheckpointNumber;
|
|
206
|
+
publicInputs: RootRollupPublicInputs;
|
|
207
|
+
proof: Proof;
|
|
208
|
+
batchedBlobInputs: BatchedBlob;
|
|
209
|
+
attestations: ViemCommitteeAttestation[];
|
|
210
|
+
headers: CheckpointHeader[];
|
|
211
|
+
}): Promise<void> {
|
|
212
|
+
const { epochNumber, fromCheckpoint, toCheckpoint } = args;
|
|
213
|
+
|
|
214
|
+
await this.validateEpochProofSubmission(args);
|
|
215
|
+
|
|
216
|
+
const data = this.encodeSubmitEpochProofCalldata(args);
|
|
217
|
+
const senderAddress = this.l1TxUtils.getSenderAddress();
|
|
218
|
+
|
|
219
|
+
const [gasLimit, gasPrice, latestBlock] = await Promise.all([
|
|
220
|
+
this.l1TxUtils.estimateGas(senderAddress.toString() as `0x${string}`, { to: this.rollupContract.address, data }),
|
|
221
|
+
this.l1TxUtils.getGasPrice(),
|
|
222
|
+
this.l1TxUtils.client.getBlock({ blockTag: 'latest' }),
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
const baseFeePerGas = latestBlock.baseFeePerGas ?? 0n;
|
|
226
|
+
const { maxPriorityFeePerGas } = gasPrice;
|
|
227
|
+
|
|
228
|
+
const effectiveFeePerGas = baseFeePerGas + maxPriorityFeePerGas;
|
|
229
|
+
const estimatedTotalFee = gasLimit * effectiveFeePerGas;
|
|
230
|
+
|
|
231
|
+
const stats: EstimatedSubmitProofStats = {
|
|
232
|
+
gasLimit,
|
|
233
|
+
baseFeePerGas,
|
|
234
|
+
maxPriorityFeePerGas,
|
|
235
|
+
estimatedTotalFee,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
this.log.info(`Estimated epoch proof submission cost (not submitted)`, {
|
|
239
|
+
epochNumber,
|
|
240
|
+
fromCheckpoint,
|
|
241
|
+
toCheckpoint,
|
|
242
|
+
gasLimit: gasLimit.toString(),
|
|
243
|
+
baseFeePerGas: formatGwei(baseFeePerGas),
|
|
244
|
+
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
245
|
+
estimatedTotalFeeEth: formatEther(estimatedTotalFee),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
this.metrics.recordEstimatedSubmitProof(stats);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private encodeSubmitEpochProofCalldata(args: {
|
|
252
|
+
fromCheckpoint: CheckpointNumber;
|
|
253
|
+
toCheckpoint: CheckpointNumber;
|
|
254
|
+
publicInputs: RootRollupPublicInputs;
|
|
255
|
+
proof: Proof;
|
|
256
|
+
batchedBlobInputs: BatchedBlob;
|
|
257
|
+
attestations: ViemCommitteeAttestation[];
|
|
258
|
+
headers: CheckpointHeader[];
|
|
259
|
+
}): Hex {
|
|
260
|
+
return encodeFunctionData({
|
|
261
|
+
abi: RollupAbi,
|
|
262
|
+
functionName: 'submitEpochRootProof',
|
|
263
|
+
args: [this.getSubmitEpochProofArgs(args)],
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
213
267
|
private async sendSubmitEpochProofTx(args: {
|
|
214
268
|
fromCheckpoint: CheckpointNumber;
|
|
215
269
|
toCheckpoint: CheckpointNumber;
|
|
270
|
+
deadline?: Date;
|
|
216
271
|
publicInputs: RootRollupPublicInputs;
|
|
217
272
|
proof: Proof;
|
|
218
273
|
batchedBlobInputs: BatchedBlob;
|
|
219
274
|
attestations: ViemCommitteeAttestation[];
|
|
275
|
+
headers: CheckpointHeader[];
|
|
220
276
|
}): Promise<TransactionReceipt | undefined> {
|
|
221
277
|
const txArgs = [this.getSubmitEpochProofArgs(args)] as const;
|
|
222
278
|
|
|
@@ -231,7 +287,10 @@ export class ProverNodePublisher {
|
|
|
231
287
|
args: txArgs,
|
|
232
288
|
});
|
|
233
289
|
try {
|
|
234
|
-
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction(
|
|
290
|
+
const { receipt } = await this.l1TxUtils.sendAndMonitorTransaction(
|
|
291
|
+
{ to: this.rollupContract.address, data },
|
|
292
|
+
{ txTimeoutAt: args.deadline },
|
|
293
|
+
);
|
|
235
294
|
if (receipt.status !== 'success') {
|
|
236
295
|
const errorMsg = await this.l1TxUtils.tryGetErrorFromRevertedTx(
|
|
237
296
|
data,
|
|
@@ -260,6 +319,7 @@ export class ProverNodePublisher {
|
|
|
260
319
|
publicInputs: RootRollupPublicInputs;
|
|
261
320
|
batchedBlobInputs: BatchedBlob;
|
|
262
321
|
attestations: ViemCommitteeAttestation[];
|
|
322
|
+
headers: CheckpointHeader[];
|
|
263
323
|
}) {
|
|
264
324
|
// Returns arguments for EpochProofLib.sol -> getEpochProofPublicInputs()
|
|
265
325
|
return [
|
|
@@ -271,11 +331,7 @@ export class ProverNodePublisher {
|
|
|
271
331
|
outHash: args.publicInputs.outHash.toString(),
|
|
272
332
|
proverId: EthAddress.fromField(args.publicInputs.constants.proverId).toString(),
|
|
273
333
|
} /*_args*/,
|
|
274
|
-
|
|
275
|
-
i % 2 === 0
|
|
276
|
-
? args.publicInputs.fees[i / 2].recipient.toField().toString()
|
|
277
|
-
: args.publicInputs.fees[(i - 1) / 2].value.toString(),
|
|
278
|
-
) /*_fees*/,
|
|
334
|
+
args.headers.map(header => header.toViem()) /*_headers*/,
|
|
279
335
|
getEthBlobEvaluationInputs(args.batchedBlobInputs) /*_blobPublicInputs*/,
|
|
280
336
|
] as const;
|
|
281
337
|
}
|
|
@@ -287,6 +343,7 @@ export class ProverNodePublisher {
|
|
|
287
343
|
proof: Proof;
|
|
288
344
|
batchedBlobInputs: BatchedBlob;
|
|
289
345
|
attestations: ViemCommitteeAttestation[];
|
|
346
|
+
headers: CheckpointHeader[];
|
|
290
347
|
}) {
|
|
291
348
|
// Returns arguments for EpochProofLib.sol -> submitEpochRootProof()
|
|
292
349
|
const proofHex: Hex = `0x${args.proof.withoutPublicInputs().toString('hex')}`;
|
|
@@ -295,12 +352,109 @@ export class ProverNodePublisher {
|
|
|
295
352
|
start: argsArray[0],
|
|
296
353
|
end: argsArray[1],
|
|
297
354
|
args: argsArray[2],
|
|
298
|
-
|
|
299
|
-
attestations:
|
|
355
|
+
headers: argsArray[3],
|
|
356
|
+
attestations: CommitteeAttestationsAndSigners.packAttestations(
|
|
300
357
|
args.attestations.map(a => CommitteeAttestation.fromViem(a)),
|
|
301
|
-
)
|
|
358
|
+
),
|
|
302
359
|
blobInputs: argsArray[4],
|
|
303
360
|
proof: proofHex,
|
|
304
361
|
};
|
|
305
362
|
}
|
|
306
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Decodes a `Root rollup public inputs mismatch`, fetches the on-chain CheckpointLog for any
|
|
367
|
+
* mismatching `checkpointHeaderHashes[i]`, emits a structured error log, and returns a thrown-ready
|
|
368
|
+
* Error with a human-readable summary.
|
|
369
|
+
*
|
|
370
|
+
* Layout of `RootRollupPublicInputs.toFields()`:
|
|
371
|
+
* [0] previousArchiveRoot
|
|
372
|
+
* [1] endArchiveRoot
|
|
373
|
+
* [2] outHash
|
|
374
|
+
* [3 .. 3+N-1] checkpointHeaderHashes[i] for i in 0..N-1 (N = MAX_CHECKPOINTS_PER_EPOCH)
|
|
375
|
+
* [3+N .. 3+3N-1] fees[i] = (recipient, value) for i in 0..N-1
|
|
376
|
+
* [3+3N .. 3+3N+4] EpochConstantData (chainId, version, vkTreeRoot, protocolContractsHash, proverId)
|
|
377
|
+
* [3+3N+5 ..] blobPublicInputs (FinalBlobAccumulator)
|
|
378
|
+
*/
|
|
379
|
+
async function reportPublicInputsMismatch(input: {
|
|
380
|
+
rollupPublicInputs: readonly Fr[];
|
|
381
|
+
argsPublicInputs: readonly Fr[];
|
|
382
|
+
fromCheckpoint: CheckpointNumber;
|
|
383
|
+
toCheckpoint: CheckpointNumber;
|
|
384
|
+
rollupContract: RollupContract;
|
|
385
|
+
log: Logger;
|
|
386
|
+
}): Promise<Error> {
|
|
387
|
+
const { rollupPublicInputs, argsPublicInputs, fromCheckpoint, toCheckpoint, rollupContract, log } = input;
|
|
388
|
+
const N = MAX_CHECKPOINTS_PER_EPOCH;
|
|
389
|
+
const constantsStart = 3 + 3 * N;
|
|
390
|
+
const blobStart = constantsStart + 5;
|
|
391
|
+
const constantLabels = ['chainId', 'version', 'vkTreeRoot', 'protocolContractsHash', 'proverId'];
|
|
392
|
+
|
|
393
|
+
const diffs: { index: number; label: string; rollup: Fr; computed: Fr; checkpointIndex?: number }[] = [];
|
|
394
|
+
const len = Math.max(rollupPublicInputs.length, argsPublicInputs.length);
|
|
395
|
+
for (let i = 0; i < len; i++) {
|
|
396
|
+
const a = rollupPublicInputs[i] ?? Fr.ZERO;
|
|
397
|
+
const b = argsPublicInputs[i] ?? Fr.ZERO;
|
|
398
|
+
if (a.equals(b)) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
let label: string;
|
|
402
|
+
let checkpointIndex: number | undefined;
|
|
403
|
+
if (i === 0) {
|
|
404
|
+
label = 'previousArchiveRoot';
|
|
405
|
+
} else if (i === 1) {
|
|
406
|
+
label = 'endArchiveRoot';
|
|
407
|
+
} else if (i === 2) {
|
|
408
|
+
label = 'outHash';
|
|
409
|
+
} else if (i < 3 + N) {
|
|
410
|
+
checkpointIndex = i - 3;
|
|
411
|
+
label = `checkpointHeaderHashes[${checkpointIndex}]`;
|
|
412
|
+
} else if (i < 3 + 3 * N) {
|
|
413
|
+
const feePairIndex = i - (3 + N);
|
|
414
|
+
const feeIndex = Math.floor(feePairIndex / 2);
|
|
415
|
+
const sub = feePairIndex % 2 === 0 ? 'recipient' : 'value';
|
|
416
|
+
label = `fees[${feeIndex}].${sub}`;
|
|
417
|
+
} else if (i < blobStart) {
|
|
418
|
+
label = `constants.${constantLabels[i - constantsStart]}`;
|
|
419
|
+
} else {
|
|
420
|
+
label = `blobPublicInputs[${i - blobStart}]`;
|
|
421
|
+
}
|
|
422
|
+
diffs.push({ index: i, label, rollup: a, computed: b, checkpointIndex });
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// For each mismatching checkpointHeaderHash, fetch the L1 CheckpointLog so the operator can
|
|
426
|
+
// see what was published on-chain alongside the prover's recomputed hash.
|
|
427
|
+
const onChainCheckpoints = await Promise.all(
|
|
428
|
+
diffs
|
|
429
|
+
.filter(d => d.checkpointIndex !== undefined)
|
|
430
|
+
.map(async d => {
|
|
431
|
+
const checkpointNumber = CheckpointNumber(fromCheckpoint + d.checkpointIndex!);
|
|
432
|
+
try {
|
|
433
|
+
const cp = await rollupContract.getCheckpoint(checkpointNumber);
|
|
434
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, headerHash: cp.headerHash.toString() };
|
|
435
|
+
} catch (err) {
|
|
436
|
+
return { checkpointIndex: d.checkpointIndex!, checkpointNumber, error: (err as Error).message };
|
|
437
|
+
}
|
|
438
|
+
}),
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
log.error(`Root rollup public inputs mismatch`, undefined, {
|
|
442
|
+
fromCheckpoint,
|
|
443
|
+
toCheckpoint,
|
|
444
|
+
numDiffs: diffs.length,
|
|
445
|
+
diffs: diffs.map(d => ({
|
|
446
|
+
index: d.index,
|
|
447
|
+
label: d.label,
|
|
448
|
+
rollup: d.rollup.toString(),
|
|
449
|
+
computed: d.computed.toString(),
|
|
450
|
+
})),
|
|
451
|
+
onChainCheckpoints,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const fmt = (inputs: readonly Fr[]) => inputs.map(x => x.toString()).join(', ');
|
|
455
|
+
const summary = diffs.map(d => `[${d.index} ${d.label}] L1=${d.rollup} prover=${d.computed}`).join('\n');
|
|
456
|
+
return new Error(
|
|
457
|
+
`Root rollup public inputs mismatch (${diffs.length} fields differ):\n${summary}\n` +
|
|
458
|
+
`Rollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`,
|
|
459
|
+
);
|
|
460
|
+
}
|