@aztec/prover-client 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928
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/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -2
- package/dest/light/lightweight_checkpoint_builder.d.ts +2 -1
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +22 -5
- package/dest/mocks/test_context.d.ts +11 -11
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +25 -28
- package/dest/orchestrator/block-building-helpers.d.ts +1 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +20 -36
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +22 -120
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +161 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/{orchestrator.js → checkpoint-sub-tree-orchestrator.js} +267 -435
- package/dest/orchestrator/chonk-cache.d.ts +39 -0
- package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
- package/dest/orchestrator/chonk-cache.js +80 -0
- package/dest/orchestrator/index.d.ts +4 -2
- package/dest/orchestrator/index.d.ts.map +1 -1
- package/dest/orchestrator/index.js +3 -1
- package/dest/orchestrator/proving-scheduler.d.ts +81 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +120 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +88 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +232 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/orchestrator/tx-proving-state.d.ts +3 -3
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +62 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +54 -7
- package/dest/proving_broker/broker_prover_facade.d.ts +3 -3
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +26 -20
- package/dest/proving_broker/config.d.ts +9 -73
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +3 -3
- package/dest/proving_broker/index.d.ts +2 -1
- package/dest/proving_broker/index.d.ts.map +1 -1
- package/dest/proving_broker/index.js +1 -0
- package/dest/proving_broker/proving_broker.d.ts +3 -2
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +219 -76
- package/dest/proving_broker/proving_broker_database/memory.d.ts +5 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/memory.js +14 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +15 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +57 -6
- package/dest/proving_broker/proving_broker_database.d.ts +27 -1
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/rpc.d.ts +3 -1
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +80 -24
- package/dest/test/epoch_settlement.d.ts +36 -0
- package/dest/test/epoch_settlement.d.ts.map +1 -0
- package/dest/test/epoch_settlement.js +52 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/mock_prover.d.ts +4 -4
- package/dest/test/mock_prover.js +2 -2
- package/package.json +19 -18
- package/src/config.ts +18 -2
- package/src/light/lightweight_checkpoint_builder.ts +27 -6
- package/src/mocks/test_context.ts +24 -41
- package/src/orchestrator/checkpoint-proving-state.ts +21 -162
- package/src/orchestrator/{orchestrator.ts → checkpoint-sub-tree-orchestrator.ts} +415 -646
- package/src/orchestrator/chonk-cache.ts +99 -0
- package/src/orchestrator/index.ts +8 -1
- package/src/orchestrator/proving-scheduler.ts +160 -0
- package/src/orchestrator/top-tree-orchestrator.ts +384 -0
- package/src/orchestrator/top-tree-proving-state.ts +219 -0
- package/src/orchestrator/tx-proving-state.ts +3 -3
- package/src/prover-client/prover-client.ts +129 -18
- package/src/proving_broker/broker_prover_facade.ts +29 -23
- package/src/proving_broker/config.ts +3 -2
- package/src/proving_broker/index.ts +1 -0
- package/src/proving_broker/proving_broker.ts +209 -78
- package/src/proving_broker/proving_broker_database/memory.ts +16 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +71 -8
- package/src/proving_broker/proving_broker_database.ts +30 -0
- package/src/proving_broker/rpc.ts +36 -24
- package/src/test/epoch_settlement.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_prover.ts +2 -2
- package/dest/orchestrator/epoch-proving-state.d.ts +0 -75
- package/dest/orchestrator/epoch-proving-state.d.ts.map +0 -1
- package/dest/orchestrator/epoch-proving-state.js +0 -269
- package/dest/orchestrator/orchestrator.d.ts +0 -128
- package/dest/orchestrator/orchestrator.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.d.ts +0 -32
- package/dest/prover-client/server-epoch-prover.d.ts.map +0 -1
- package/dest/prover-client/server-epoch-prover.js +0 -40
- package/src/orchestrator/epoch-proving-state.ts +0 -380
- package/src/prover-client/server-epoch-prover.ts +0 -69
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SpongeBlob } from '@aztec/blob-lib/types';
|
|
2
2
|
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
3
4
|
L1_TO_L2_MSG_SUBTREE_HEIGHT,
|
|
4
5
|
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
6
|
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
6
|
-
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
7
7
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
-
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
|
+
import { BlockNumber, type EpochNumber } from '@aztec/foundation/branded-types';
|
|
11
10
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
11
|
import { AbortError } from '@aztec/foundation/error';
|
|
13
|
-
import
|
|
14
|
-
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { elapsed } from '@aztec/foundation/timer';
|
|
12
|
+
import type { LoggerBindings } from '@aztec/foundation/log';
|
|
13
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
14
|
+
import type { SerialQueue } from '@aztec/foundation/queue';
|
|
15
|
+
import { type Tuple, assertLength } from '@aztec/foundation/serialize';
|
|
18
16
|
import type { TreeNodeLocation } from '@aztec/foundation/trees';
|
|
19
17
|
import { EthAddress } from '@aztec/stdlib/block';
|
|
20
18
|
import type {
|
|
21
|
-
EpochProver,
|
|
22
19
|
ForkMerkleTreeOperations,
|
|
23
20
|
MerkleTreeWriteOperations,
|
|
24
21
|
PublicInputsAndRecursiveProof,
|
|
25
22
|
ReadonlyWorldStateAccess,
|
|
26
23
|
ServerCircuitProver,
|
|
27
24
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
-
import
|
|
25
|
+
import { appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
29
26
|
import {
|
|
30
27
|
type BaseRollupHints,
|
|
28
|
+
type BlockRollupPublicInputs,
|
|
31
29
|
BlockRootEmptyTxFirstRollupPrivateInputs,
|
|
32
30
|
BlockRootFirstRollupPrivateInputs,
|
|
33
31
|
BlockRootSingleTxFirstRollupPrivateInputs,
|
|
34
32
|
BlockRootSingleTxRollupPrivateInputs,
|
|
35
33
|
CheckpointConstantData,
|
|
36
|
-
CheckpointRootSingleBlockRollupPrivateInputs,
|
|
37
34
|
PrivateTxBaseRollupPrivateInputs,
|
|
38
|
-
|
|
39
|
-
PublicChonkVerifierPublicInputs,
|
|
40
|
-
RootRollupPublicInputs,
|
|
35
|
+
type PublicChonkVerifierPublicInputs,
|
|
41
36
|
} from '@aztec/stdlib/rollup';
|
|
42
37
|
import type { CircuitName } from '@aztec/stdlib/stats';
|
|
43
38
|
import { type AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
@@ -66,48 +61,90 @@ import {
|
|
|
66
61
|
validateTx,
|
|
67
62
|
} from './block-building-helpers.js';
|
|
68
63
|
import type { BlockProvingState } from './block-proving-state.js';
|
|
69
|
-
import
|
|
70
|
-
import
|
|
64
|
+
import { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
65
|
+
import type { ChonkCache } from './chonk-cache.js';
|
|
71
66
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
67
|
+
import { ProvingScheduler } from './proving-scheduler.js';
|
|
72
68
|
import { TxProvingState } from './tx-proving-state.js';
|
|
73
69
|
|
|
74
70
|
/**
|
|
75
|
-
*
|
|
76
|
-
* 1. Transactions are provided to the scheduler post simulation.
|
|
77
|
-
* 2. Tree insertions are performed as required to generate transaction specific proofs
|
|
78
|
-
* 3. Those transaction specific proofs are generated in the necessary order accounting for dependencies
|
|
79
|
-
* 4. Once a transaction is proven, it will be incorporated into a merge proof
|
|
80
|
-
* 5. Merge proofs are produced at each level of the tree until the root proof is produced
|
|
71
|
+
* Result of proving a single checkpoint's block-level sub-tree.
|
|
81
72
|
*
|
|
82
|
-
*
|
|
73
|
+
* Contains the final block-rollup proof outputs that feed the checkpoint root rollup,
|
|
74
|
+
* plus the archive sibling path captured before any block in the checkpoint landed
|
|
75
|
+
* (the top-tree needs this to assemble the checkpoint root rollup hints).
|
|
83
76
|
*/
|
|
77
|
+
export type SubTreeResult = {
|
|
78
|
+
blockProofOutputs: PublicInputsAndRecursiveProof<
|
|
79
|
+
BlockRollupPublicInputs,
|
|
80
|
+
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
81
|
+
>[];
|
|
82
|
+
previousArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
88
|
+
* Base rollup hints as produced before proving: `PrivateBaseRollupHints` / `PublicBaseRollupHints`
|
|
89
|
+
* deliberately carry no recursive proof or verification key. The proof + VK are supplied later, when
|
|
90
|
+
* `TxProvingState.getBaseRollupTypeAndInputs` wraps these hints into the "with proof + VK" types —
|
|
91
|
+
* `PrivateTxBaseRollupPrivateInputs` (a `ChonkProofData`) or `PublicTxBaseRollupPrivateInputs` (a
|
|
92
|
+
* chonk-verifier proof + AVM proof). Those proofs are *required constructor arguments* of the wrapper
|
|
93
|
+
* types, so the only way to obtain a provable input is to populate them — they cannot be silently
|
|
94
|
+
* omitted. Naming the proof-less hints type here makes that boundary explicit at `prepareBaseRollupInputs`.
|
|
87
95
|
*/
|
|
88
|
-
|
|
89
|
-
private provingState: EpochProvingState | undefined = undefined;
|
|
90
|
-
private pendingProvingJobs: AbortController[] = [];
|
|
96
|
+
type BaseRollupHintsWithoutProofAndVK = BaseRollupHints;
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Orchestrates block-level proving for a single checkpoint, stopping at the boundary
|
|
100
|
+
* where checkpoint root rollup would otherwise begin. Used by the per-checkpoint
|
|
101
|
+
* `CheckpointProver` in production; the top-tree orchestrator then composes the
|
|
102
|
+
* sub-tree's block proofs into the epoch proof.
|
|
103
|
+
*
|
|
104
|
+
* Wiring: a single-checkpoint mini-proving session is owned by the constructor. The
|
|
105
|
+
* canonical way to obtain a fully-started sub-tree is the `start` static factory,
|
|
106
|
+
* which also drives the single internal `startCheckpoint` call. The sub-tree never
|
|
107
|
+
* escalates past the checkpoint root boundary; `getSubTreeResult()` resolves once
|
|
108
|
+
* every block-level proof in the checkpoint's tree is ready.
|
|
109
|
+
*/
|
|
110
|
+
export class CheckpointSubTreeOrchestrator extends ProvingScheduler {
|
|
111
|
+
/** The single checkpoint proving state this sub-tree owns. Allocated in the `start` factory. */
|
|
112
|
+
protected provingState: CheckpointProvingState | undefined = undefined;
|
|
113
|
+
private readonly subTreeResult: PromiseWithResolvers<SubTreeResult>;
|
|
114
|
+
private readonly metrics: ProvingOrchestratorMetrics;
|
|
95
115
|
private dbs: Map<BlockNumber, MerkleTreeWriteOperations> = new Map();
|
|
96
|
-
private logger: Logger;
|
|
97
116
|
|
|
98
117
|
constructor(
|
|
99
|
-
private dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
100
|
-
|
|
118
|
+
private readonly dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
119
|
+
protected readonly prover: ServerCircuitProver,
|
|
101
120
|
private readonly proverId: EthAddress,
|
|
121
|
+
/**
|
|
122
|
+
* Shared chonk-verifier proof cache. Every chonk-verifier proof started by this
|
|
123
|
+
* sub-tree lives on the cache and survives the sub-tree's cancellation, so a tx
|
|
124
|
+
* whose original checkpoint is reorged out and re-appears in a replacement
|
|
125
|
+
* checkpoint reuses the cached proof.
|
|
126
|
+
*/
|
|
127
|
+
private readonly chonkCache: ChonkCache,
|
|
128
|
+
/** The epoch this sub-tree proves into. */
|
|
129
|
+
private readonly epochNumber: EpochNumber,
|
|
102
130
|
private readonly cancelJobsOnStop: boolean = false,
|
|
131
|
+
deferredJobQueue: SerialQueue,
|
|
103
132
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
104
133
|
bindings?: LoggerBindings,
|
|
105
134
|
) {
|
|
106
|
-
|
|
107
|
-
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, '
|
|
135
|
+
super(deferredJobQueue, 'prover-client:checkpoint-sub-tree-orchestrator', bindings);
|
|
136
|
+
this.metrics = new ProvingOrchestratorMetrics(telemetryClient, 'CheckpointSubTreeOrchestrator');
|
|
137
|
+
|
|
138
|
+
this.subTreeResult = promiseWithResolvers<SubTreeResult>();
|
|
139
|
+
// Mark the rejection branch as observed so a `cancel()` or proving failure does not
|
|
140
|
+
// surface an unhandled rejection when no consumer awaits getSubTreeResult().
|
|
141
|
+
this.subTreeResult.promise.catch(() => {});
|
|
108
142
|
}
|
|
109
143
|
|
|
110
|
-
|
|
144
|
+
/** Tracks whether `cancel()` has been called; flows into the checkpoint state's isAlive hook. */
|
|
145
|
+
private cancelled = false;
|
|
146
|
+
|
|
147
|
+
public get tracer(): Tracer {
|
|
111
148
|
return this.metrics.tracer;
|
|
112
149
|
}
|
|
113
150
|
|
|
@@ -115,125 +152,125 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
115
152
|
return this.proverId;
|
|
116
153
|
}
|
|
117
154
|
|
|
118
|
-
public getNumActiveForks() {
|
|
155
|
+
public getNumActiveForks(): number {
|
|
119
156
|
return this.dbs.size;
|
|
120
157
|
}
|
|
121
158
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
159
|
+
/** Returns a promise that resolves when block-level proving completes for the checkpoint. */
|
|
160
|
+
public getSubTreeResult(): Promise<SubTreeResult> {
|
|
161
|
+
return this.subTreeResult.promise;
|
|
125
162
|
}
|
|
126
163
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
);
|
|
164
|
+
/**
|
|
165
|
+
* Returns the archive sibling path captured at the internal checkpoint start.
|
|
166
|
+
* Available synchronously once `start` has resolved, before block-level proving
|
|
167
|
+
* completes. The top-tree consumer uses this to assemble checkpoint root rollup hints
|
|
168
|
+
* up-front so checkpoint root proofs can pipeline against in-flight sub-tree proving.
|
|
169
|
+
*/
|
|
170
|
+
public getPreviousArchiveSiblingPath(): Tuple<Fr, typeof ARCHIVE_HEIGHT> {
|
|
171
|
+
if (!this.provingState) {
|
|
172
|
+
throw new Error('Checkpoint not started; call CheckpointSubTreeOrchestrator.start first.');
|
|
136
173
|
}
|
|
137
|
-
|
|
138
|
-
const { promise: _promise, resolve, reject } = promiseWithResolvers<ProvingResult>();
|
|
139
|
-
const promise = _promise.catch((reason): ProvingResult => ({ status: 'failure', reason }));
|
|
140
|
-
this.logger.info(`Starting epoch ${epochNumber} with ${totalNumCheckpoints} checkpoints.`);
|
|
141
|
-
this.provingState = new EpochProvingState(
|
|
142
|
-
epochNumber,
|
|
143
|
-
totalNumCheckpoints,
|
|
144
|
-
finalBlobBatchingChallenges,
|
|
145
|
-
provingState => this.checkAndEnqueueCheckpointRootRollup(provingState),
|
|
146
|
-
resolve,
|
|
147
|
-
reject,
|
|
148
|
-
);
|
|
149
|
-
this.provingPromise = promise;
|
|
174
|
+
return this.provingState.getLastArchiveSiblingPath();
|
|
150
175
|
}
|
|
151
176
|
|
|
152
177
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
178
|
+
* Constructs and starts a sub-tree for a single checkpoint. The returned sub-tree
|
|
179
|
+
* has had its single internal checkpoint state allocated; callers proceed directly
|
|
180
|
+
* to per-block `startNewBlock` / `addTxs` / `setBlockCompleted`.
|
|
181
|
+
*
|
|
182
|
+
* If the internal start rejects, the partially-constructed sub-tree is stopped
|
|
183
|
+
* before the error propagates, so no broker resources leak.
|
|
159
184
|
*/
|
|
160
|
-
public async
|
|
161
|
-
|
|
162
|
-
|
|
185
|
+
public static async start(
|
|
186
|
+
dbProvider: ReadonlyWorldStateAccess & ForkMerkleTreeOperations,
|
|
187
|
+
prover: ServerCircuitProver,
|
|
188
|
+
proverId: EthAddress,
|
|
189
|
+
chonkCache: ChonkCache,
|
|
190
|
+
epochNumber: EpochNumber,
|
|
191
|
+
cancelJobsOnStop: boolean,
|
|
192
|
+
deferredJobQueue: SerialQueue,
|
|
193
|
+
checkpointConstants: CheckpointConstantData,
|
|
163
194
|
l1ToL2Messages: Fr[],
|
|
164
195
|
totalNumBlocks: number,
|
|
165
196
|
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
197
|
+
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
198
|
+
bindings?: LoggerBindings,
|
|
199
|
+
): Promise<CheckpointSubTreeOrchestrator> {
|
|
200
|
+
const subTree = new CheckpointSubTreeOrchestrator(
|
|
201
|
+
dbProvider,
|
|
202
|
+
prover,
|
|
203
|
+
proverId,
|
|
204
|
+
chonkCache,
|
|
205
|
+
epochNumber,
|
|
206
|
+
cancelJobsOnStop,
|
|
207
|
+
deferredJobQueue,
|
|
208
|
+
telemetryClient,
|
|
209
|
+
bindings,
|
|
210
|
+
);
|
|
211
|
+
try {
|
|
212
|
+
await subTree.startCheckpoint(
|
|
213
|
+
checkpointConstants,
|
|
214
|
+
l1ToL2Messages,
|
|
215
|
+
totalNumBlocks,
|
|
216
|
+
headerOfLastBlockInPreviousCheckpoint,
|
|
217
|
+
);
|
|
218
|
+
return subTree;
|
|
219
|
+
} catch (err) {
|
|
220
|
+
await subTree.stop().catch(() => {});
|
|
221
|
+
throw err;
|
|
169
222
|
}
|
|
223
|
+
}
|
|
170
224
|
|
|
171
|
-
|
|
172
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Kickstart chonk-verifier circuits via the shared `ChonkCache`. The cache owns the
|
|
227
|
+
* broker job lifecycle, so the proof survives this sub-tree's `cancel()` — a tx that
|
|
228
|
+
* ends up in a replacement checkpoint after a reorg can pick the cached promise up
|
|
229
|
+
* and skip re-proving.
|
|
230
|
+
*/
|
|
231
|
+
public startChonkVerifierCircuits(txs: Tx[]): Promise<void> {
|
|
232
|
+
if (!this.provingState?.verifyState()) {
|
|
233
|
+
return Promise.reject(new Error('Sub-tree proving state is not active.'));
|
|
173
234
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
// Insert all the l1 to l2 messages into the db. And get the states before and after the insertion.
|
|
186
|
-
const {
|
|
187
|
-
lastL1ToL2MessageTreeSnapshot,
|
|
188
|
-
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
189
|
-
newL1ToL2MessageTreeSnapshot,
|
|
190
|
-
newL1ToL2MessageSubtreeRootSiblingPath,
|
|
191
|
-
} = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
192
|
-
|
|
193
|
-
this.provingState.startNewCheckpoint(
|
|
194
|
-
checkpointIndex,
|
|
195
|
-
constants,
|
|
196
|
-
totalNumBlocks,
|
|
197
|
-
headerOfLastBlockInPreviousCheckpoint,
|
|
198
|
-
lastArchiveSiblingPath,
|
|
199
|
-
l1ToL2Messages,
|
|
200
|
-
lastL1ToL2MessageTreeSnapshot,
|
|
201
|
-
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
202
|
-
newL1ToL2MessageTreeSnapshot,
|
|
203
|
-
newL1ToL2MessageSubtreeRootSiblingPath,
|
|
204
|
-
);
|
|
235
|
+
const publicTxs = txs.filter(tx => tx.data.forPublic);
|
|
236
|
+
for (const tx of publicTxs) {
|
|
237
|
+
const txHash = tx.getTxHash().toString();
|
|
238
|
+
const inputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.getProverId().toField());
|
|
239
|
+
// Fire and forget — getOrEnqueueChonkVerifier later picks up the cached promise
|
|
240
|
+
// when the tx is processed inside its block.
|
|
241
|
+
void this.chonkCache.getOrCompute(txHash, signal =>
|
|
242
|
+
this.prover.getPublicChonkVerifierProof(inputs, signal, this.epochNumber),
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
return Promise.resolve();
|
|
205
246
|
}
|
|
206
247
|
|
|
248
|
+
// ---------------- per-block driving (called by the per-checkpoint CheckpointProver) ----------------
|
|
249
|
+
|
|
207
250
|
/**
|
|
208
|
-
* Starts off a new block
|
|
251
|
+
* Starts off a new block.
|
|
209
252
|
* @param blockNumber - The block number
|
|
210
|
-
* @param timestamp - The timestamp of the block.
|
|
211
|
-
*
|
|
212
|
-
* @param totalNumTxs - The total number of txs in the block
|
|
253
|
+
* @param timestamp - The timestamp of the block. Required for empty blocks to construct private inputs.
|
|
254
|
+
* @param totalNumTxs - The total number of txs in the block.
|
|
213
255
|
*/
|
|
214
|
-
@trackSpan('
|
|
256
|
+
@trackSpan('CheckpointSubTreeOrchestrator.startNewBlock', blockNumber => ({
|
|
215
257
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
216
258
|
}))
|
|
217
259
|
public async startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number) {
|
|
218
260
|
if (!this.provingState) {
|
|
219
|
-
throw new Error('Empty
|
|
261
|
+
throw new Error('Empty proving state. The checkpoint sub-tree has not been started.');
|
|
220
262
|
}
|
|
221
263
|
|
|
222
|
-
|
|
223
|
-
if (!checkpointProvingState) {
|
|
224
|
-
throw new Error(`Checkpoint not started. Call startNewCheckpoint first.`);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!checkpointProvingState.isAcceptingBlocks()) {
|
|
264
|
+
if (!this.provingState.isAcceptingBlocks()) {
|
|
228
265
|
throw new Error(`Checkpoint not accepting further blocks.`);
|
|
229
266
|
}
|
|
230
267
|
|
|
231
|
-
const constants =
|
|
268
|
+
const constants = this.provingState.constants;
|
|
232
269
|
this.logger.info(`Starting block ${blockNumber} for slot ${constants.slotNumber}.`);
|
|
233
270
|
|
|
234
|
-
// Fork the db only when it's not already set. The db for the first block is set in
|
|
271
|
+
// Fork the db only when it's not already set. The db for the first block is set in startCheckpoint.
|
|
235
272
|
if (!this.dbs.has(blockNumber)) {
|
|
236
|
-
// Fork world state at the end of the immediately previous block
|
|
273
|
+
// Fork world state at the end of the immediately previous block.
|
|
237
274
|
const db = await this.dbProvider.fork(BlockNumber(blockNumber - 1));
|
|
238
275
|
this.dbs.set(blockNumber, db);
|
|
239
276
|
}
|
|
@@ -243,7 +280,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
243
280
|
const lastArchiveTreeSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
244
281
|
const lastArchiveSiblingPath = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
245
282
|
|
|
246
|
-
const blockProvingState =
|
|
283
|
+
const blockProvingState = this.provingState.startNewBlock(
|
|
247
284
|
blockNumber,
|
|
248
285
|
timestamp,
|
|
249
286
|
totalNumTxs,
|
|
@@ -254,12 +291,12 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
254
291
|
// Enqueue base parity circuits for the first block in the checkpoint.
|
|
255
292
|
if (blockProvingState.index === 0) {
|
|
256
293
|
for (let i = 0; i < NUM_BASE_PARITY_PER_ROOT_PARITY; i++) {
|
|
257
|
-
this.enqueueBaseParityCircuit(
|
|
294
|
+
this.enqueueBaseParityCircuit(this.provingState, blockProvingState, i);
|
|
258
295
|
}
|
|
259
296
|
}
|
|
260
297
|
|
|
261
|
-
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed
|
|
262
|
-
//
|
|
298
|
+
// Because `addTxs` won't be called for a block without txs, and that's where the sponge blob state is computed,
|
|
299
|
+
// set its end sponge blob here. This becomes the start sponge blob for the next block.
|
|
263
300
|
if (totalNumTxs === 0) {
|
|
264
301
|
const endState = await db.getStateReference();
|
|
265
302
|
blockProvingState.setEndState(endState);
|
|
@@ -268,29 +305,25 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
268
305
|
const blockEndBlobFields = blockProvingState.getBlockEndBlobFields();
|
|
269
306
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
270
307
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
271
|
-
|
|
272
|
-
// Try to accumulate the out hashes and blobs as far as we can:
|
|
273
|
-
await this.provingState.accumulateCheckpointOutHashes();
|
|
274
|
-
await this.provingState.setBlobAccumulators();
|
|
275
308
|
}
|
|
276
309
|
}
|
|
277
310
|
|
|
278
311
|
/**
|
|
279
|
-
* The interface to add simulated transactions to the scheduler.
|
|
312
|
+
* The interface to add simulated transactions to the scheduler. Called at most once per block.
|
|
280
313
|
* @param txs - The transactions to be proven
|
|
281
314
|
*/
|
|
282
|
-
@trackSpan('
|
|
315
|
+
@trackSpan('CheckpointSubTreeOrchestrator.addTxs', txs => ({
|
|
283
316
|
[Attributes.BLOCK_TXS_COUNT]: txs.length,
|
|
284
317
|
}))
|
|
285
318
|
public async addTxs(txs: ProcessedTx[]): Promise<void> {
|
|
286
319
|
if (!this.provingState) {
|
|
287
|
-
throw new Error(`Empty
|
|
320
|
+
throw new Error(`Empty proving state. The checkpoint sub-tree has not been started.`);
|
|
288
321
|
}
|
|
289
322
|
|
|
290
323
|
if (!txs.length) {
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
this.logger.
|
|
324
|
+
// Empty block: setBlockCompleted handles this without addTxs being called. Bail to
|
|
325
|
+
// avoid the throw below (we cannot find the blockNumber without any txs).
|
|
326
|
+
this.logger.verbose(`Provided no txs to addTxs.`);
|
|
294
327
|
return;
|
|
295
328
|
}
|
|
296
329
|
|
|
@@ -366,46 +399,13 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
366
399
|
await spongeBlobState.absorb(blockEndBlobFields);
|
|
367
400
|
|
|
368
401
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
369
|
-
|
|
370
|
-
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
371
|
-
await this.provingState.accumulateCheckpointOutHashes();
|
|
372
|
-
await this.provingState.setBlobAccumulators();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Kickstarts chonk verifier circuits for the specified txs. These will be used during epoch proving.
|
|
377
|
-
* Note that if the chonk verifier circuits are not started this way, they will be started nontheless after processing.
|
|
378
|
-
*/
|
|
379
|
-
@trackSpan('ProvingOrchestrator.startChonkVerifierCircuits')
|
|
380
|
-
public startChonkVerifierCircuits(txs: Tx[]) {
|
|
381
|
-
if (!this.provingState?.verifyState()) {
|
|
382
|
-
throw new Error(`Empty epoch proving state. call startNewEpoch before starting chonk verifier circuits.`);
|
|
383
|
-
}
|
|
384
|
-
const publicTxs = txs.filter(tx => tx.data.forPublic);
|
|
385
|
-
for (const tx of publicTxs) {
|
|
386
|
-
const txHash = tx.getTxHash().toString();
|
|
387
|
-
const privateInputs = getPublicChonkVerifierPrivateInputsFromTx(tx, this.proverId.toField());
|
|
388
|
-
const tubeProof =
|
|
389
|
-
promiseWithResolvers<
|
|
390
|
-
PublicInputsAndRecursiveProof<
|
|
391
|
-
PublicChonkVerifierPublicInputs,
|
|
392
|
-
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
393
|
-
>
|
|
394
|
-
>();
|
|
395
|
-
this.logger.debug(`Starting chonk verifier circuit for tx ${txHash}`);
|
|
396
|
-
this.doEnqueueChonkVerifier(txHash, privateInputs, proof => {
|
|
397
|
-
tubeProof.resolve(proof);
|
|
398
|
-
});
|
|
399
|
-
this.provingState.cachedChonkVerifierProofs.set(txHash, tubeProof.promise);
|
|
400
|
-
}
|
|
401
|
-
return Promise.resolve();
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
/**
|
|
405
405
|
* Marks the block as completed.
|
|
406
406
|
* Computes the block header and updates the archive tree.
|
|
407
407
|
*/
|
|
408
|
-
@trackSpan('
|
|
408
|
+
@trackSpan('CheckpointSubTreeOrchestrator.setBlockCompleted', (blockNumber: BlockNumber) => ({
|
|
409
409
|
[Attributes.BLOCK_NUMBER]: blockNumber,
|
|
410
410
|
}))
|
|
411
411
|
public async setBlockCompleted(blockNumber: BlockNumber, expectedHeader?: BlockHeader): Promise<BlockHeader> {
|
|
@@ -460,66 +460,17 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
460
460
|
return header;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
//
|
|
464
|
-
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
465
|
-
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
466
|
-
if (!builtBlockHeader) {
|
|
467
|
-
this.logger.debug('Block header not built yet, skipping header check.');
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const output = provingState.getBlockRootRollupOutput();
|
|
472
|
-
if (!output) {
|
|
473
|
-
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const newArchive = provingState.getBuiltArchive();
|
|
478
|
-
if (!newArchive) {
|
|
479
|
-
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const header = await buildHeaderFromCircuitOutputs(output);
|
|
484
|
-
|
|
485
|
-
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
486
|
-
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
487
|
-
provingState.reject(`Block header hash mismatch.`);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
const blockNumber = provingState.blockNumber;
|
|
492
|
-
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
493
|
-
if (!syncedArchive.equals(newArchive)) {
|
|
494
|
-
this.logger.error(
|
|
495
|
-
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
496
|
-
syncedArchive,
|
|
497
|
-
)} but built ${inspect(newArchive)}`,
|
|
498
|
-
);
|
|
499
|
-
provingState.reject(`Archive tree mismatch.`);
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
const circuitArchive = output.newArchive;
|
|
504
|
-
if (!newArchive.equals(circuitArchive)) {
|
|
505
|
-
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
506
|
-
provingState.reject(`New archive mismatch.`);
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
463
|
+
// ---------------- lifecycle ----------------
|
|
510
464
|
|
|
511
465
|
/**
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
* If cancelJobsOnStop is false (default), jobs remain in the broker queue and can be reused on restart/reorg.
|
|
466
|
+
* Cancels any further proving. If `cancelJobsOnStop` was set, aborts all pending broker jobs
|
|
467
|
+
* (used on reorg). Otherwise jobs remain in the broker queue and can be reused on restart.
|
|
515
468
|
*/
|
|
516
469
|
public cancel() {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
470
|
+
this.cancelled = true;
|
|
471
|
+
this.resetSchedulerState(this.cancelJobsOnStop);
|
|
472
|
+
// Reject the proving state (and hence subTreeResult) so anyone awaiting the sub-tree result
|
|
473
|
+
// is released rather than hanging — matching TopTreeOrchestrator.cancel().
|
|
523
474
|
this.provingState?.cancel();
|
|
524
475
|
|
|
525
476
|
for (const [blockNumber, db] of this.dbs.entries()) {
|
|
@@ -528,121 +479,73 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
528
479
|
this.dbs.clear();
|
|
529
480
|
}
|
|
530
481
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (!db) {
|
|
534
|
-
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
535
|
-
}
|
|
536
|
-
return db;
|
|
482
|
+
protected override cancelInternal(): void {
|
|
483
|
+
this.cancel();
|
|
537
484
|
}
|
|
538
485
|
|
|
539
|
-
|
|
540
|
-
* Returns the proof for the current epoch.
|
|
541
|
-
*/
|
|
542
|
-
public async finalizeEpoch(): Promise<{
|
|
543
|
-
publicInputs: RootRollupPublicInputs;
|
|
544
|
-
proof: Proof;
|
|
545
|
-
batchedBlobInputs: BatchedBlob;
|
|
546
|
-
}> {
|
|
547
|
-
if (!this.provingState || !this.provingPromise) {
|
|
548
|
-
throw new Error(`Invalid proving state, an epoch must be proven before it can be finalized`);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const result = await this.provingPromise!;
|
|
552
|
-
if (result.status === 'failure') {
|
|
553
|
-
throw new Error(`Epoch proving failed: ${result.reason}`);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
await this.provingState.finalizeBatchedBlob();
|
|
557
|
-
|
|
558
|
-
const epochProofResult = this.provingState.getEpochProofResult();
|
|
559
|
-
|
|
560
|
-
pushTestData('epochProofResult', {
|
|
561
|
-
proof: epochProofResult.proof.toString(),
|
|
562
|
-
publicInputs: epochProofResult.publicInputs.toString(),
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
return epochProofResult;
|
|
566
|
-
}
|
|
486
|
+
// ---------------- private: per-checkpoint init ----------------
|
|
567
487
|
|
|
568
488
|
/**
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* @param job - The actual job, returns a promise notifying of the job's completion
|
|
489
|
+
* Internal driver for the single-checkpoint init. Allocates the world-state fork,
|
|
490
|
+
* inserts L1-to-L2 messages, and creates the per-checkpoint proving state with this
|
|
491
|
+
* sub-tree as its parent. Only called once, from the `start` factory.
|
|
573
492
|
*/
|
|
574
|
-
private
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
493
|
+
private async startCheckpoint(
|
|
494
|
+
constants: CheckpointConstantData,
|
|
495
|
+
l1ToL2Messages: Fr[],
|
|
496
|
+
totalNumBlocks: number,
|
|
497
|
+
headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
498
|
+
): Promise<void> {
|
|
499
|
+
if (this.provingState) {
|
|
500
|
+
throw new Error('Checkpoint sub-tree already started.');
|
|
582
501
|
}
|
|
583
502
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
// We use a 'safeJob'. We don't want promise rejections in the proving pool, we want to capture the error here
|
|
588
|
-
// and reject the proving job whilst keeping the event loop free of rejections
|
|
589
|
-
const safeJob = async () => {
|
|
590
|
-
try {
|
|
591
|
-
// there's a delay between enqueueing this job and it actually running
|
|
592
|
-
if (controller.signal.aborted) {
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
const result = await request(controller.signal);
|
|
597
|
-
if (!provingState.verifyState()) {
|
|
598
|
-
this.logger.debug(`State no longer valid, discarding result`);
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// we could have been cancelled whilst waiting for the result
|
|
603
|
-
// and the prover ignored the signal. Drop the result in that case
|
|
604
|
-
if (controller.signal.aborted) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
503
|
+
// Fork world state at the end of the immediately previous block.
|
|
504
|
+
const lastBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber;
|
|
505
|
+
const db = await this.dbProvider.fork(lastBlockNumber);
|
|
607
506
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
if (err instanceof AbortError) {
|
|
611
|
-
// operation was cancelled, probably because the block was cancelled
|
|
612
|
-
// drop this result
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
507
|
+
const firstBlockNumber = BlockNumber(lastBlockNumber + 1);
|
|
508
|
+
this.dbs.set(firstBlockNumber, db);
|
|
615
509
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
} finally {
|
|
619
|
-
const index = this.pendingProvingJobs.indexOf(controller);
|
|
620
|
-
if (index > -1) {
|
|
621
|
-
this.pendingProvingJobs.splice(index, 1);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
};
|
|
510
|
+
// Get archive sibling path before any block in this checkpoint lands.
|
|
511
|
+
const lastArchiveSiblingPath = await getLastSiblingPath(MerkleTreeId.ARCHIVE, db);
|
|
625
512
|
|
|
626
|
-
//
|
|
627
|
-
|
|
628
|
-
|
|
513
|
+
// Insert all the l1 to l2 messages into the db. Get the states before and after the insertion.
|
|
514
|
+
const {
|
|
515
|
+
lastL1ToL2MessageTreeSnapshot,
|
|
516
|
+
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
517
|
+
newL1ToL2MessageTreeSnapshot,
|
|
518
|
+
newL1ToL2MessageSubtreeRootSiblingPath,
|
|
519
|
+
} = await this.updateL1ToL2MessageTree(l1ToL2Messages, db);
|
|
629
520
|
|
|
630
|
-
|
|
631
|
-
|
|
521
|
+
this.provingState = new CheckpointProvingState(
|
|
522
|
+
/* index */ 0,
|
|
523
|
+
constants,
|
|
524
|
+
totalNumBlocks,
|
|
525
|
+
headerOfLastBlockInPreviousCheckpoint,
|
|
526
|
+
lastArchiveSiblingPath,
|
|
632
527
|
l1ToL2Messages,
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
528
|
+
lastL1ToL2MessageTreeSnapshot,
|
|
529
|
+
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
530
|
+
newL1ToL2MessageTreeSnapshot,
|
|
531
|
+
newL1ToL2MessageSubtreeRootSiblingPath,
|
|
532
|
+
Number(this.epochNumber),
|
|
533
|
+
/* isAlive */ () => !this.cancelled,
|
|
534
|
+
/* onReject */ reason => this.subTreeResult.reject(new Error(reason)),
|
|
636
535
|
);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ---------------- private: per-block proof orchestration ----------------
|
|
637
539
|
|
|
540
|
+
private async updateL1ToL2MessageTree(l1ToL2Messages: Fr[], db: MerkleTreeWriteOperations) {
|
|
638
541
|
const lastL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
639
542
|
const lastL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
640
543
|
await getSubtreeSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, L1_TO_L2_MSG_SUBTREE_HEIGHT, db),
|
|
641
544
|
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
642
545
|
);
|
|
643
546
|
|
|
644
|
-
// Update the local trees to include the new l1 to l2 messages
|
|
645
|
-
await db
|
|
547
|
+
// Update the local trees to include the new l1 to l2 messages.
|
|
548
|
+
await appendL1ToL2MessagesToTree(db, l1ToL2Messages);
|
|
646
549
|
|
|
647
550
|
const newL1ToL2MessageTreeSnapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db);
|
|
648
551
|
const newL1ToL2MessageSubtreeRootSiblingPath = assertLength(
|
|
@@ -658,8 +561,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
658
561
|
};
|
|
659
562
|
}
|
|
660
563
|
|
|
661
|
-
// Updates the merkle trees for a transaction. The first enqueued job for a transaction
|
|
662
|
-
@trackSpan('
|
|
564
|
+
// Updates the merkle trees for a transaction. The first enqueued job for a transaction.
|
|
565
|
+
@trackSpan('CheckpointSubTreeOrchestrator.prepareBaseRollupInputs', tx => ({
|
|
663
566
|
[Attributes.TX_HASH]: tx.hash.toString(),
|
|
664
567
|
}))
|
|
665
568
|
private async prepareBaseRollupInputs(
|
|
@@ -668,21 +571,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
668
571
|
newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
669
572
|
startSpongeBlob: SpongeBlob,
|
|
670
573
|
db: MerkleTreeWriteOperations,
|
|
671
|
-
): Promise<[
|
|
672
|
-
//
|
|
673
|
-
//
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
),
|
|
574
|
+
): Promise<[BaseRollupHintsWithoutProofAndVK, TreeSnapshots]> {
|
|
575
|
+
// These hints deliberately carry no recursive proof or verification key — see
|
|
576
|
+
// BaseRollupHintsWithoutProofAndVK. The tx's proof + VK are attached later in
|
|
577
|
+
// TxProvingState.getBaseRollupTypeAndInputs from the proven chonk-verifier / kernel / AVM
|
|
578
|
+
// proofs, which are required there and so cannot be silently omitted.
|
|
579
|
+
const start = performance.now();
|
|
580
|
+
const hints = await insertSideEffectsAndBuildBaseRollupHints(
|
|
581
|
+
tx,
|
|
582
|
+
lastArchive,
|
|
583
|
+
newL1ToL2MessageTreeSnapshot,
|
|
584
|
+
startSpongeBlob,
|
|
585
|
+
this.proverId.toField(),
|
|
586
|
+
db,
|
|
683
587
|
);
|
|
684
|
-
|
|
685
|
-
this.metrics.recordBaseRollupInputs(ms);
|
|
588
|
+
this.metrics.recordBaseRollupInputs(performance.now() - start);
|
|
686
589
|
|
|
687
590
|
const promises = [MerkleTreeId.NOTE_HASH_TREE, MerkleTreeId.NULLIFIER_TREE, MerkleTreeId.PUBLIC_DATA_TREE].map(
|
|
688
591
|
async (id: MerkleTreeId) => {
|
|
@@ -694,8 +597,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
694
597
|
return [hints, treeSnapshots];
|
|
695
598
|
}
|
|
696
599
|
|
|
697
|
-
// Executes the base rollup circuit and
|
|
698
|
-
// Executes the next level of merge if all inputs are available
|
|
600
|
+
// Executes the base rollup circuit and stores the output as intermediate state for the parent merge/root circuit.
|
|
601
|
+
// Executes the next level of merge if all inputs are available.
|
|
699
602
|
private enqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
700
603
|
if (!provingState.verifyState()) {
|
|
701
604
|
this.logger.debug('Not running base rollup, state invalid');
|
|
@@ -715,17 +618,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
715
618
|
|
|
716
619
|
this.deferredProving(
|
|
717
620
|
provingState,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
? 'getPrivateTxBaseRollupProof'
|
|
723
|
-
: 'getPublicTxBaseRollupProof'
|
|
724
|
-
}`,
|
|
725
|
-
{
|
|
726
|
-
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
727
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType,
|
|
728
|
-
},
|
|
621
|
+
this.wrapCircuitCall(
|
|
622
|
+
inputs instanceof PrivateTxBaseRollupPrivateInputs
|
|
623
|
+
? 'getPrivateTxBaseRollupProof'
|
|
624
|
+
: 'getPublicTxBaseRollupProof',
|
|
729
625
|
signal => {
|
|
730
626
|
if (inputs instanceof PrivateTxBaseRollupPrivateInputs) {
|
|
731
627
|
return this.prover.getPrivateTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
@@ -733,6 +629,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
733
629
|
return this.prover.getPublicTxBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
734
630
|
}
|
|
735
631
|
},
|
|
632
|
+
{ [Attributes.TX_HASH]: processedTx.hash.toString(), [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType },
|
|
736
633
|
),
|
|
737
634
|
result => {
|
|
738
635
|
this.logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
@@ -747,72 +644,53 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
747
644
|
);
|
|
748
645
|
}
|
|
749
646
|
|
|
750
|
-
|
|
751
|
-
|
|
647
|
+
/**
|
|
648
|
+
* Route the tx's chonk-verifier dependency through the per-epoch context: read the
|
|
649
|
+
* cached promise (or enqueue if missing), then `.then(handleResult)` to progress to
|
|
650
|
+
* the base rollup once the proof lands.
|
|
651
|
+
*/
|
|
752
652
|
private getOrEnqueueChonkVerifier(provingState: BlockProvingState, txIndex: number) {
|
|
753
653
|
if (!provingState.verifyState()) {
|
|
754
|
-
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
755
654
|
return;
|
|
756
655
|
}
|
|
757
656
|
|
|
758
657
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
759
658
|
const txHash = txProvingState.processedTx.hash.toString();
|
|
760
|
-
|
|
659
|
+
|
|
761
660
|
const handleResult = (
|
|
762
661
|
result: PublicInputsAndRecursiveProof<
|
|
763
662
|
PublicChonkVerifierPublicInputs,
|
|
764
663
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
765
664
|
>,
|
|
766
665
|
) => {
|
|
767
|
-
|
|
666
|
+
if (!provingState.verifyState()) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
768
669
|
txProvingState.setPublicChonkVerifierProof(result);
|
|
769
|
-
this.provingState?.cachedChonkVerifierProofs.delete(txHash);
|
|
770
670
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
771
671
|
};
|
|
772
672
|
|
|
773
|
-
|
|
774
|
-
this.
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
this.logger.debug(`Enqueuing chonk verifier circuit for tx index: ${txIndex}`);
|
|
780
|
-
this.doEnqueueChonkVerifier(txHash, txProvingState.getPublicChonkVerifierPrivateInputs(), handleResult);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
private doEnqueueChonkVerifier(
|
|
784
|
-
txHash: string,
|
|
785
|
-
inputs: PublicChonkVerifierPrivateInputs,
|
|
786
|
-
handler: (
|
|
787
|
-
result: PublicInputsAndRecursiveProof<
|
|
788
|
-
PublicChonkVerifierPublicInputs,
|
|
789
|
-
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
790
|
-
>,
|
|
791
|
-
) => void,
|
|
792
|
-
provingState: EpochProvingState | BlockProvingState = this.provingState!,
|
|
793
|
-
) {
|
|
794
|
-
if (!provingState.verifyState()) {
|
|
795
|
-
this.logger.debug('Not running chonk verifier circuit, state invalid');
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
this.deferredProving(
|
|
800
|
-
provingState,
|
|
801
|
-
wrapCallbackInSpan(
|
|
802
|
-
this.tracer,
|
|
803
|
-
'ProvingOrchestrator.prover.getPublicChonkVerifierProof',
|
|
804
|
-
{
|
|
805
|
-
[Attributes.TX_HASH]: txHash,
|
|
806
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'chonk-verifier-public' satisfies CircuitName,
|
|
807
|
-
},
|
|
808
|
-
signal => this.prover.getPublicChonkVerifierProof(inputs, signal, provingState.epochNumber),
|
|
673
|
+
const promise = this.chonkCache.getOrCompute(txHash, signal =>
|
|
674
|
+
this.prover.getPublicChonkVerifierProof(
|
|
675
|
+
txProvingState.getPublicChonkVerifierPrivateInputs(),
|
|
676
|
+
signal,
|
|
677
|
+
this.epochNumber,
|
|
809
678
|
),
|
|
810
|
-
handler,
|
|
811
679
|
);
|
|
680
|
+
void promise.then(handleResult).catch(err => {
|
|
681
|
+
// The cache self-cleans on rejection, so a replacement sub-tree for this tx will see the
|
|
682
|
+
// miss and re-enqueue. But if this proving state is still active, the failure must abort
|
|
683
|
+
// it: otherwise the base rollup for this tx is never enqueued and the checkpoint (and
|
|
684
|
+
// epoch) orchestrators hang forever waiting for a proof that will never arrive.
|
|
685
|
+
if (err instanceof AbortError || !provingState.verifyState()) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
this.logger.error(`Chonk verifier proof failed for tx ${txHash}`, err);
|
|
689
|
+
provingState.reject(`Chonk verifier proof failed for tx ${txHash}: ${err}`);
|
|
690
|
+
});
|
|
812
691
|
}
|
|
813
692
|
|
|
814
|
-
// Executes the merge rollup circuit
|
|
815
|
-
// Enqueues the next level of merge if all inputs are available
|
|
693
|
+
// Executes the merge rollup circuit. Enqueues the next level of merge if all inputs are available.
|
|
816
694
|
private enqueueMergeRollup(provingState: BlockProvingState, location: TreeNodeLocation) {
|
|
817
695
|
if (!provingState.verifyState()) {
|
|
818
696
|
this.logger.debug('Not running merge rollup. State no longer valid.');
|
|
@@ -828,13 +706,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
828
706
|
|
|
829
707
|
this.deferredProving(
|
|
830
708
|
provingState,
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
'ProvingOrchestrator.prover.getTxMergeRollupProof',
|
|
834
|
-
{
|
|
835
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge' satisfies CircuitName,
|
|
836
|
-
},
|
|
709
|
+
this.wrapCircuitCall(
|
|
710
|
+
'getTxMergeRollupProof',
|
|
837
711
|
signal => this.prover.getTxMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
712
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-tx-merge' satisfies CircuitName },
|
|
838
713
|
),
|
|
839
714
|
result => {
|
|
840
715
|
provingState.setMergeRollupProof(location, result);
|
|
@@ -843,7 +718,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
843
718
|
);
|
|
844
719
|
}
|
|
845
720
|
|
|
846
|
-
// Executes the block root rollup circuit
|
|
721
|
+
// Executes the block root rollup circuit.
|
|
847
722
|
private enqueueBlockRootRollup(provingState: BlockProvingState) {
|
|
848
723
|
if (!provingState.verifyState()) {
|
|
849
724
|
this.logger.debug('Not running block root rollup, state no longer valid');
|
|
@@ -861,12 +736,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
861
736
|
|
|
862
737
|
this.deferredProving(
|
|
863
738
|
provingState,
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
'ProvingOrchestrator.prover.getBlockRootRollupProof',
|
|
867
|
-
{
|
|
868
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType,
|
|
869
|
-
},
|
|
739
|
+
this.wrapCircuitCall(
|
|
740
|
+
'getBlockRootRollupProof',
|
|
870
741
|
signal => {
|
|
871
742
|
if (inputs instanceof BlockRootFirstRollupPrivateInputs) {
|
|
872
743
|
return this.prover.getBlockRootFirstRollupProof(inputs, signal, provingState.epochNumber);
|
|
@@ -880,9 +751,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
880
751
|
return this.prover.getBlockRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
881
752
|
}
|
|
882
753
|
},
|
|
754
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType },
|
|
883
755
|
),
|
|
884
756
|
async result => {
|
|
885
|
-
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}
|
|
757
|
+
this.logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`, {
|
|
758
|
+
blockNumber: provingState.blockNumber,
|
|
759
|
+
checkpointIndex: provingState.parentCheckpoint.index,
|
|
760
|
+
...result.inputs.toInspect(),
|
|
761
|
+
});
|
|
886
762
|
|
|
887
763
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
888
764
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
@@ -892,16 +768,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
892
768
|
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
893
769
|
|
|
894
770
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
895
|
-
|
|
771
|
+
this.checkAndEnqueueSubTreeResolution(checkpointProvingState);
|
|
896
772
|
} else {
|
|
897
|
-
|
|
773
|
+
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
898
774
|
}
|
|
899
775
|
},
|
|
900
776
|
);
|
|
901
777
|
}
|
|
902
778
|
|
|
903
|
-
// Executes the base parity circuit
|
|
904
|
-
// Enqueues the root parity circuit if all inputs are available
|
|
779
|
+
// Executes the base parity circuit. Enqueues the root parity circuit if all inputs are available.
|
|
905
780
|
private enqueueBaseParityCircuit(
|
|
906
781
|
checkpointProvingState: CheckpointProvingState,
|
|
907
782
|
provingState: BlockProvingState,
|
|
@@ -921,13 +796,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
921
796
|
|
|
922
797
|
this.deferredProving(
|
|
923
798
|
provingState,
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
'ProvingOrchestrator.prover.getBaseParityProof',
|
|
927
|
-
{
|
|
928
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base' satisfies CircuitName,
|
|
929
|
-
},
|
|
799
|
+
this.wrapCircuitCall(
|
|
800
|
+
'getBaseParityProof',
|
|
930
801
|
signal => this.prover.getBaseParityProof(inputs, signal, provingState.epochNumber),
|
|
802
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-base' satisfies CircuitName },
|
|
931
803
|
),
|
|
932
804
|
provingOutput => {
|
|
933
805
|
provingState.setBaseParityProof(baseParityIndex, provingOutput);
|
|
@@ -940,12 +812,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
940
812
|
if (!provingState.isReadyForRootParity()) {
|
|
941
813
|
return;
|
|
942
814
|
}
|
|
943
|
-
|
|
944
815
|
this.enqueueRootParityCircuit(provingState);
|
|
945
816
|
}
|
|
946
817
|
|
|
947
|
-
// Runs the root parity circuit
|
|
948
|
-
// Enqueues the root rollup
|
|
818
|
+
// Runs the root parity circuit and stores the outputs.
|
|
819
|
+
// Enqueues the block root rollup if all inputs are available.
|
|
949
820
|
private enqueueRootParityCircuit(provingState: BlockProvingState) {
|
|
950
821
|
if (!provingState.verifyState()) {
|
|
951
822
|
this.logger.debug('Not running root parity. State no longer valid.');
|
|
@@ -961,13 +832,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
961
832
|
|
|
962
833
|
this.deferredProving(
|
|
963
834
|
provingState,
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
'ProvingOrchestrator.prover.getRootParityProof',
|
|
967
|
-
{
|
|
968
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root' satisfies CircuitName,
|
|
969
|
-
},
|
|
835
|
+
this.wrapCircuitCall(
|
|
836
|
+
'getRootParityProof',
|
|
970
837
|
signal => this.prover.getRootParityProof(inputs, signal, provingState.epochNumber),
|
|
838
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'parity-root' satisfies CircuitName },
|
|
971
839
|
),
|
|
972
840
|
result => {
|
|
973
841
|
provingState.setRootParityProof(result);
|
|
@@ -976,8 +844,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
976
844
|
);
|
|
977
845
|
}
|
|
978
846
|
|
|
979
|
-
// Executes the block merge rollup circuit
|
|
980
|
-
// Enqueues the next level of merge if all inputs are available
|
|
847
|
+
// Executes the block merge rollup circuit.
|
|
981
848
|
private enqueueBlockMergeRollup(provingState: CheckpointProvingState, location: TreeNodeLocation) {
|
|
982
849
|
if (!provingState.verifyState()) {
|
|
983
850
|
this.logger.debug('Not running block merge rollup. State no longer valid.');
|
|
@@ -992,170 +859,19 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
992
859
|
const inputs = provingState.getBlockMergeRollupInputs(location);
|
|
993
860
|
this.deferredProving(
|
|
994
861
|
provingState,
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
'ProvingOrchestrator.prover.getBlockMergeRollupProof',
|
|
998
|
-
{
|
|
999
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge' satisfies CircuitName,
|
|
1000
|
-
},
|
|
862
|
+
this.wrapCircuitCall(
|
|
863
|
+
'getBlockMergeRollupProof',
|
|
1001
864
|
signal => this.prover.getBlockMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1002
|
-
|
|
1003
|
-
async result => {
|
|
1004
|
-
provingState.setBlockMergeRollupProof(location, result);
|
|
1005
|
-
await this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1006
|
-
},
|
|
1007
|
-
);
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
private async enqueueCheckpointRootRollup(provingState: CheckpointProvingState) {
|
|
1011
|
-
if (!provingState.verifyState()) {
|
|
1012
|
-
this.logger.debug('Not running checkpoint root rollup. State no longer valid.');
|
|
1013
|
-
return;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
if (!provingState.tryStartProvingCheckpointRoot()) {
|
|
1017
|
-
this.logger.debug('Checkpoint root rollup already started.');
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
const rollupType = provingState.getCheckpointRootRollupType();
|
|
1022
|
-
|
|
1023
|
-
this.logger.debug(`Enqueuing ${rollupType} for checkpoint ${provingState.index}.`);
|
|
1024
|
-
|
|
1025
|
-
const inputs = await provingState.getCheckpointRootRollupInputs();
|
|
1026
|
-
|
|
1027
|
-
this.deferredProving(
|
|
1028
|
-
provingState,
|
|
1029
|
-
wrapCallbackInSpan(
|
|
1030
|
-
this.tracer,
|
|
1031
|
-
'ProvingOrchestrator.prover.getCheckpointRootRollupProof',
|
|
1032
|
-
{
|
|
1033
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType,
|
|
1034
|
-
},
|
|
1035
|
-
signal => {
|
|
1036
|
-
if (inputs instanceof CheckpointRootSingleBlockRollupPrivateInputs) {
|
|
1037
|
-
return this.prover.getCheckpointRootSingleBlockRollupProof(inputs, signal, provingState.epochNumber);
|
|
1038
|
-
} else {
|
|
1039
|
-
return this.prover.getCheckpointRootRollupProof(inputs, signal, provingState.epochNumber);
|
|
1040
|
-
}
|
|
1041
|
-
},
|
|
1042
|
-
),
|
|
1043
|
-
result => {
|
|
1044
|
-
const computedEndBlobAccumulatorState = provingState.getEndBlobAccumulator()!.toBlobAccumulator();
|
|
1045
|
-
const circuitEndBlobAccumulatorState = result.inputs.endBlobAccumulator;
|
|
1046
|
-
if (!circuitEndBlobAccumulatorState.equals(computedEndBlobAccumulatorState)) {
|
|
1047
|
-
this.logger.error(
|
|
1048
|
-
`Blob accumulator state mismatch.\nCircuit: ${inspect(circuitEndBlobAccumulatorState)}\nComputed: ${inspect(
|
|
1049
|
-
computedEndBlobAccumulatorState,
|
|
1050
|
-
)}`,
|
|
1051
|
-
);
|
|
1052
|
-
provingState.reject(`Blob accumulator state mismatch.`);
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
this.logger.debug(`Completed ${rollupType} proof for checkpoint ${provingState.index}.`);
|
|
1057
|
-
|
|
1058
|
-
const leafLocation = provingState.setCheckpointRootRollupProof(result);
|
|
1059
|
-
const epochProvingState = provingState.parentEpoch;
|
|
1060
|
-
|
|
1061
|
-
if (epochProvingState.totalNumCheckpoints === 1) {
|
|
1062
|
-
this.enqueueEpochPadding(epochProvingState);
|
|
1063
|
-
} else {
|
|
1064
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(epochProvingState, leafLocation);
|
|
1065
|
-
}
|
|
1066
|
-
},
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
private enqueueCheckpointMergeRollup(provingState: EpochProvingState, location: TreeNodeLocation) {
|
|
1071
|
-
if (!provingState.verifyState()) {
|
|
1072
|
-
this.logger.debug('Not running checkpoint merge rollup. State no longer valid.');
|
|
1073
|
-
return;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
if (!provingState.tryStartProvingCheckpointMerge(location)) {
|
|
1077
|
-
this.logger.debug('Checkpoint merge rollup already started.');
|
|
1078
|
-
return;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
const inputs = provingState.getCheckpointMergeRollupInputs(location);
|
|
1082
|
-
|
|
1083
|
-
this.deferredProving(
|
|
1084
|
-
provingState,
|
|
1085
|
-
wrapCallbackInSpan(
|
|
1086
|
-
this.tracer,
|
|
1087
|
-
'ProvingOrchestrator.prover.getCheckpointMergeRollupProof',
|
|
1088
|
-
{
|
|
1089
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-merge' satisfies CircuitName,
|
|
1090
|
-
},
|
|
1091
|
-
signal => this.prover.getCheckpointMergeRollupProof(inputs, signal, provingState.epochNumber),
|
|
1092
|
-
),
|
|
1093
|
-
result => {
|
|
1094
|
-
this.logger.debug('Completed proof for checkpoint merge rollup.');
|
|
1095
|
-
provingState.setCheckpointMergeRollupProof(location, result);
|
|
1096
|
-
this.checkAndEnqueueNextCheckpointMergeRollup(provingState, location);
|
|
1097
|
-
},
|
|
1098
|
-
);
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
private enqueueEpochPadding(provingState: EpochProvingState) {
|
|
1102
|
-
if (!provingState.verifyState()) {
|
|
1103
|
-
this.logger.debug('Not running epoch padding. State no longer valid.');
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
if (!provingState.tryStartProvingPaddingCheckpoint()) {
|
|
1108
|
-
this.logger.debug('Padding checkpoint already started.');
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
this.logger.debug('Padding epoch proof with a padding block root proof.');
|
|
1113
|
-
|
|
1114
|
-
const inputs = provingState.getPaddingCheckpointInputs();
|
|
1115
|
-
|
|
1116
|
-
this.deferredProving(
|
|
1117
|
-
provingState,
|
|
1118
|
-
wrapCallbackInSpan(
|
|
1119
|
-
this.tracer,
|
|
1120
|
-
'ProvingOrchestrator.prover.getCheckpointPaddingRollupProof',
|
|
1121
|
-
{
|
|
1122
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-checkpoint-padding' satisfies CircuitName,
|
|
1123
|
-
},
|
|
1124
|
-
signal => this.prover.getCheckpointPaddingRollupProof(inputs, signal, provingState.epochNumber),
|
|
1125
|
-
),
|
|
1126
|
-
result => {
|
|
1127
|
-
this.logger.debug('Completed proof for padding checkpoint.');
|
|
1128
|
-
provingState.setCheckpointPaddingProof(result);
|
|
1129
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1130
|
-
},
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
// Executes the root rollup circuit
|
|
1135
|
-
private enqueueRootRollup(provingState: EpochProvingState) {
|
|
1136
|
-
if (!provingState.verifyState()) {
|
|
1137
|
-
this.logger.debug('Not running root rollup, state no longer valid');
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
this.logger.debug(`Preparing root rollup`);
|
|
1142
|
-
|
|
1143
|
-
const inputs = provingState.getRootRollupInputs();
|
|
1144
|
-
|
|
1145
|
-
this.deferredProving(
|
|
1146
|
-
provingState,
|
|
1147
|
-
wrapCallbackInSpan(
|
|
1148
|
-
this.tracer,
|
|
1149
|
-
'ProvingOrchestrator.prover.getRootRollupProof',
|
|
1150
|
-
{
|
|
1151
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-root' satisfies CircuitName,
|
|
1152
|
-
},
|
|
1153
|
-
signal => this.prover.getRootRollupProof(inputs, signal, provingState.epochNumber),
|
|
865
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: 'rollup-block-merge' satisfies CircuitName },
|
|
1154
866
|
),
|
|
1155
867
|
result => {
|
|
1156
|
-
this.logger.
|
|
1157
|
-
|
|
1158
|
-
|
|
868
|
+
this.logger.debug(`Completed block merge rollup proof for checkpoint ${provingState.index}`, {
|
|
869
|
+
checkpointIndex: provingState.index,
|
|
870
|
+
mergeLocation: location,
|
|
871
|
+
...result.inputs.toInspect(),
|
|
872
|
+
});
|
|
873
|
+
provingState.setBlockMergeRollupProof(location, result);
|
|
874
|
+
this.checkAndEnqueueNextBlockMergeRollup(provingState, location);
|
|
1159
875
|
},
|
|
1160
876
|
);
|
|
1161
877
|
}
|
|
@@ -1164,7 +880,6 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1164
880
|
if (!provingState.isReadyForMergeRollup(currentLocation)) {
|
|
1165
881
|
return;
|
|
1166
882
|
}
|
|
1167
|
-
|
|
1168
883
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1169
884
|
if (parentLocation.level === 0) {
|
|
1170
885
|
this.checkAndEnqueueBlockRootRollup(provingState);
|
|
@@ -1178,61 +893,45 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1178
893
|
this.logger.debug('Not ready for block root rollup');
|
|
1179
894
|
return;
|
|
1180
895
|
}
|
|
1181
|
-
|
|
1182
896
|
this.enqueueBlockRootRollup(provingState);
|
|
1183
897
|
}
|
|
1184
898
|
|
|
1185
|
-
private
|
|
899
|
+
private checkAndEnqueueNextBlockMergeRollup(
|
|
1186
900
|
provingState: CheckpointProvingState,
|
|
1187
901
|
currentLocation: TreeNodeLocation,
|
|
1188
|
-
) {
|
|
902
|
+
): void {
|
|
1189
903
|
if (!provingState.isReadyForBlockMerge(currentLocation)) {
|
|
1190
904
|
return;
|
|
1191
905
|
}
|
|
1192
|
-
|
|
1193
906
|
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1194
907
|
if (parentLocation.level === 0) {
|
|
1195
|
-
|
|
908
|
+
this.checkAndEnqueueSubTreeResolution(provingState);
|
|
1196
909
|
} else {
|
|
1197
910
|
this.enqueueBlockMergeRollup(provingState, parentLocation);
|
|
1198
911
|
}
|
|
1199
912
|
}
|
|
1200
913
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
const parentLocation = provingState.getParentLocation(currentLocation);
|
|
1215
|
-
if (parentLocation.level === 0) {
|
|
1216
|
-
this.checkAndEnqueueRootRollup(provingState);
|
|
1217
|
-
} else {
|
|
1218
|
-
this.enqueueCheckpointMergeRollup(provingState, parentLocation);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
private checkAndEnqueueRootRollup(provingState: EpochProvingState) {
|
|
1223
|
-
if (!provingState.isReadyForRootRollup()) {
|
|
1224
|
-
this.logger.debug('Not ready for root rollup');
|
|
914
|
+
/**
|
|
915
|
+
* Sub-tree analogue of the orchestrator's `checkAndEnqueueCheckpointRootRollup`:
|
|
916
|
+
* resolves the sub-tree promise with the block-level proof outputs once they're all ready,
|
|
917
|
+
* instead of escalating to the checkpoint root rollup.
|
|
918
|
+
*/
|
|
919
|
+
private checkAndEnqueueSubTreeResolution(provingState: CheckpointProvingState): void {
|
|
920
|
+
const proofs = provingState.getSubTreeOutputProofs();
|
|
921
|
+
const nonEmpty = proofs.filter((p): p is NonNullable<typeof p> => !!p);
|
|
922
|
+
if (proofs.length !== nonEmpty.length) {
|
|
923
|
+
// Block merge tree not fully resolved yet — retried as more block proofs land.
|
|
1225
924
|
return;
|
|
1226
925
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
926
|
+
this.subTreeResult.resolve({
|
|
927
|
+
blockProofOutputs: nonEmpty,
|
|
928
|
+
previousArchiveSiblingPath: provingState.getLastArchiveSiblingPath(),
|
|
929
|
+
});
|
|
1229
930
|
}
|
|
1230
931
|
|
|
1231
932
|
/**
|
|
1232
|
-
* Executes the VM circuit for a public function
|
|
1233
|
-
*
|
|
1234
|
-
* @param provingState - The proving state being operated on
|
|
1235
|
-
* @param txIndex - The index of the transaction being proven
|
|
933
|
+
* Executes the VM circuit for a public function. Enqueues the base rollup once the
|
|
934
|
+
* tx's chonk-verifier + VM proofs are both ready.
|
|
1236
935
|
*/
|
|
1237
936
|
private enqueueVM(provingState: BlockProvingState, txIndex: number) {
|
|
1238
937
|
if (!provingState.verifyState()) {
|
|
@@ -1242,23 +941,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1242
941
|
|
|
1243
942
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1244
943
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
944
|
+
this.deferredProving(
|
|
945
|
+
provingState,
|
|
946
|
+
this.wrapCircuitCall(
|
|
947
|
+
'getAvmProof',
|
|
948
|
+
async (signal: AbortSignal) => {
|
|
949
|
+
const inputs = txProvingState.getAvmInputs();
|
|
950
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
951
|
+
},
|
|
952
|
+
{ [Attributes.TX_HASH]: txProvingState.processedTx.hash.toString() },
|
|
953
|
+
),
|
|
954
|
+
proof => {
|
|
955
|
+
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
956
|
+
txProvingState.setAvmProof(proof);
|
|
957
|
+
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1254
958
|
},
|
|
1255
959
|
);
|
|
1256
|
-
|
|
1257
|
-
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1258
|
-
this.logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1259
|
-
txProvingState.setAvmProof(proof);
|
|
1260
|
-
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1261
|
-
});
|
|
1262
960
|
}
|
|
1263
961
|
|
|
1264
962
|
private checkAndEnqueueBaseRollup(provingState: BlockProvingState, txIndex: number) {
|
|
@@ -1266,10 +964,81 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1266
964
|
if (!txProvingState.ready()) {
|
|
1267
965
|
return;
|
|
1268
966
|
}
|
|
1269
|
-
|
|
1270
|
-
// We must have completed all proving (chonk verifier proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
967
|
+
// All upstream proofs (chonk verifier and, if required, vm) are ready — proceed to the base rollup.
|
|
1271
968
|
this.logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1272
|
-
|
|
1273
969
|
this.enqueueBaseRollup(provingState, txIndex);
|
|
1274
970
|
}
|
|
971
|
+
|
|
972
|
+
// Flagged as protected so unit tests can override.
|
|
973
|
+
protected async verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState) {
|
|
974
|
+
const builtBlockHeader = provingState.getBuiltBlockHeader();
|
|
975
|
+
if (!builtBlockHeader) {
|
|
976
|
+
this.logger.debug('Block header not built yet, skipping header check.');
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
const output = provingState.getBlockRootRollupOutput();
|
|
981
|
+
if (!output) {
|
|
982
|
+
this.logger.debug('Block root rollup proof not built yet, skipping header check.');
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
const newArchive = provingState.getBuiltArchive();
|
|
987
|
+
if (!newArchive) {
|
|
988
|
+
this.logger.debug('Archive snapshot not yet captured, skipping header check.');
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
const header = await buildHeaderFromCircuitOutputs(output);
|
|
993
|
+
|
|
994
|
+
if (!(await header.hash()).equals(await builtBlockHeader.hash())) {
|
|
995
|
+
this.logger.error(`Block header mismatch.\nCircuit: ${inspect(header)}\nComputed: ${inspect(builtBlockHeader)}`);
|
|
996
|
+
provingState.reject(`Block header hash mismatch.`);
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const blockNumber = provingState.blockNumber;
|
|
1001
|
+
const syncedArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.dbProvider.getSnapshot(blockNumber));
|
|
1002
|
+
if (!syncedArchive.equals(newArchive)) {
|
|
1003
|
+
this.logger.error(
|
|
1004
|
+
`Archive tree mismatch for block ${blockNumber}: world state synced to ${inspect(
|
|
1005
|
+
syncedArchive,
|
|
1006
|
+
)} but built ${inspect(newArchive)}`,
|
|
1007
|
+
);
|
|
1008
|
+
provingState.reject(`Archive tree mismatch.`);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const circuitArchive = output.newArchive;
|
|
1013
|
+
if (!newArchive.equals(circuitArchive)) {
|
|
1014
|
+
this.logger.error(`New archive mismatch.\nCircuit: ${output.newArchive}\nComputed: ${newArchive}`);
|
|
1015
|
+
provingState.reject(`New archive mismatch.`);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
private getDbForBlock(blockNumber: BlockNumber): MerkleTreeWriteOperations {
|
|
1021
|
+
const db = this.dbs.get(blockNumber);
|
|
1022
|
+
if (!db) {
|
|
1023
|
+
throw new Error(`World state fork for block ${blockNumber} not found.`);
|
|
1024
|
+
}
|
|
1025
|
+
return db;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Wraps a circuit call with a tracer span and circuit attributes. Replaces the
|
|
1030
|
+
* `ProvingScheduler.wrapCircuitCall` indirection that used to live on the abstract base.
|
|
1031
|
+
*/
|
|
1032
|
+
private wrapCircuitCall<T>(
|
|
1033
|
+
circuitName: string,
|
|
1034
|
+
fn: (signal: AbortSignal) => Promise<T>,
|
|
1035
|
+
attributes: Record<string, unknown> = {},
|
|
1036
|
+
): (signal: AbortSignal) => Promise<T> {
|
|
1037
|
+
return wrapCallbackInSpan(
|
|
1038
|
+
this.tracer,
|
|
1039
|
+
`CheckpointSubTreeOrchestrator.prover.${circuitName}`,
|
|
1040
|
+
{ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName as CircuitName, ...attributes },
|
|
1041
|
+
fn,
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1275
1044
|
}
|