@aztec/prover-client 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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/light/lightweight_checkpoint_builder.d.ts +12 -4
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +55 -8
- package/dest/mocks/test_context.d.ts +4 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +14 -3
- package/dest/orchestrator/block-building-helpers.d.ts +1 -1
- package/dest/orchestrator/block-building-helpers.js +1 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +15 -2
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +34 -1
- package/dest/orchestrator/epoch-proving-state.d.ts +5 -4
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +35 -1
- package/dest/orchestrator/orchestrator.d.ts +11 -1
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +446 -38
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- package/dest/orchestrator/tx-proving-state.d.ts +5 -4
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +6 -6
- package/dest/prover-client/prover-client.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts +4 -3
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.d.ts +3 -8
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +1 -16
- package/dest/proving_broker/proving_broker.d.ts +1 -1
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +1 -10
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +389 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +11 -35
- package/dest/test/mock_proof_store.d.ts +3 -3
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +2 -2
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +3 -3
- package/package.json +16 -17
- package/src/light/lightweight_checkpoint_builder.ts +84 -8
- package/src/mocks/test_context.ts +11 -1
- package/src/orchestrator/block-building-helpers.ts +1 -1
- package/src/orchestrator/checkpoint-proving-state.ts +47 -1
- package/src/orchestrator/epoch-proving-state.ts +56 -8
- package/src/orchestrator/orchestrator.ts +40 -13
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- package/src/orchestrator/tx-proving-state.ts +8 -11
- package/src/prover-client/prover-client.ts +1 -9
- package/src/proving_broker/broker_prover_facade.ts +2 -3
- package/src/proving_broker/proving_agent.ts +1 -17
- package/src/proving_broker/proving_broker.ts +1 -8
- package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +10 -35
- package/src/test/mock_prover.ts +1 -8
- package/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -38
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -108
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -137
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
2
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
3
|
-
import type
|
|
3
|
+
import { type CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
8
8
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
9
9
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
accumulateCheckpointOutHashes,
|
|
12
|
+
computeCheckpointOutHash,
|
|
13
|
+
computeInHashFromL1ToL2Messages,
|
|
14
|
+
} from '@aztec/stdlib/messaging';
|
|
11
15
|
import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
|
|
12
16
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
17
|
import {
|
|
14
18
|
type CheckpointGlobalVariables,
|
|
15
|
-
ContentCommitment,
|
|
16
19
|
type GlobalVariables,
|
|
17
20
|
type ProcessedTx,
|
|
18
21
|
StateReference,
|
|
@@ -42,6 +45,7 @@ export class LightweightCheckpointBuilder {
|
|
|
42
45
|
public readonly checkpointNumber: CheckpointNumber,
|
|
43
46
|
public readonly constants: CheckpointGlobalVariables,
|
|
44
47
|
public readonly l1ToL2Messages: Fr[],
|
|
48
|
+
private readonly previousCheckpointOutHashes: Fr[],
|
|
45
49
|
public readonly db: MerkleTreeWriteOperations,
|
|
46
50
|
) {
|
|
47
51
|
this.spongeBlob = SpongeBlob.init();
|
|
@@ -52,6 +56,7 @@ export class LightweightCheckpointBuilder {
|
|
|
52
56
|
checkpointNumber: CheckpointNumber,
|
|
53
57
|
constants: CheckpointGlobalVariables,
|
|
54
58
|
l1ToL2Messages: Fr[],
|
|
59
|
+
previousCheckpointOutHashes: Fr[],
|
|
55
60
|
db: MerkleTreeWriteOperations,
|
|
56
61
|
): Promise<LightweightCheckpointBuilder> {
|
|
57
62
|
// Insert l1-to-l2 messages into the tree.
|
|
@@ -60,7 +65,73 @@ export class LightweightCheckpointBuilder {
|
|
|
60
65
|
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
61
66
|
);
|
|
62
67
|
|
|
63
|
-
return new LightweightCheckpointBuilder(
|
|
68
|
+
return new LightweightCheckpointBuilder(
|
|
69
|
+
checkpointNumber,
|
|
70
|
+
constants,
|
|
71
|
+
l1ToL2Messages,
|
|
72
|
+
previousCheckpointOutHashes,
|
|
73
|
+
db,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Resumes building a checkpoint from existing blocks. This is used for validator re-execution
|
|
79
|
+
* where blocks have already been built and their effects are already in the database.
|
|
80
|
+
* Unlike startNewCheckpoint, this does NOT append l1ToL2Messages to the tree since they
|
|
81
|
+
* were already added when the blocks were originally built.
|
|
82
|
+
*/
|
|
83
|
+
static async resumeCheckpoint(
|
|
84
|
+
checkpointNumber: CheckpointNumber,
|
|
85
|
+
constants: CheckpointGlobalVariables,
|
|
86
|
+
l1ToL2Messages: Fr[],
|
|
87
|
+
previousCheckpointOutHashes: Fr[],
|
|
88
|
+
db: MerkleTreeWriteOperations,
|
|
89
|
+
existingBlocks: L2BlockNew[],
|
|
90
|
+
): Promise<LightweightCheckpointBuilder> {
|
|
91
|
+
const builder = new LightweightCheckpointBuilder(
|
|
92
|
+
checkpointNumber,
|
|
93
|
+
constants,
|
|
94
|
+
l1ToL2Messages,
|
|
95
|
+
previousCheckpointOutHashes,
|
|
96
|
+
db,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
builder.logger.debug('Resuming checkpoint from existing blocks', {
|
|
100
|
+
checkpointNumber,
|
|
101
|
+
numExistingBlocks: existingBlocks.length,
|
|
102
|
+
blockNumbers: existingBlocks.map(b => b.header.getBlockNumber()),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Validate block order and consistency
|
|
106
|
+
for (let i = 1; i < existingBlocks.length; i++) {
|
|
107
|
+
const prev = existingBlocks[i - 1];
|
|
108
|
+
const curr = existingBlocks[i];
|
|
109
|
+
if (curr.number !== prev.number + 1) {
|
|
110
|
+
throw new Error(`Non-sequential block numbers in resumeCheckpoint: ${prev.number} -> ${curr.number}`);
|
|
111
|
+
}
|
|
112
|
+
if (!prev.archive.root.equals(curr.header.lastArchive.root)) {
|
|
113
|
+
throw new Error(`Archive root mismatch between blocks ${prev.number} and ${curr.number}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (let i = 0; i < existingBlocks.length; i++) {
|
|
118
|
+
const block = existingBlocks[i];
|
|
119
|
+
const isFirstBlock = i === 0;
|
|
120
|
+
|
|
121
|
+
if (isFirstBlock) {
|
|
122
|
+
builder.lastArchives.push(block.header.lastArchive);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
builder.lastArchives.push(block.archive);
|
|
126
|
+
|
|
127
|
+
const blockBlobFields = block.toBlobFields();
|
|
128
|
+
await builder.spongeBlob.absorb(blockBlobFields);
|
|
129
|
+
builder.blobFields.push(...blockBlobFields);
|
|
130
|
+
|
|
131
|
+
builder.blocks.push(block);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return builder;
|
|
64
135
|
}
|
|
65
136
|
|
|
66
137
|
/**
|
|
@@ -120,7 +191,7 @@ export class LightweightCheckpointBuilder {
|
|
|
120
191
|
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
121
192
|
this.lastArchives.push(newArchive);
|
|
122
193
|
|
|
123
|
-
const indexWithinCheckpoint = this.blocks.length;
|
|
194
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
|
|
124
195
|
const block = new L2BlockNew(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
|
|
125
196
|
this.blocks.push(block);
|
|
126
197
|
|
|
@@ -157,9 +228,11 @@ export class LightweightCheckpointBuilder {
|
|
|
157
228
|
|
|
158
229
|
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
|
|
159
230
|
|
|
160
|
-
const outHash = computeCheckpointOutHash(blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)));
|
|
161
|
-
|
|
162
231
|
const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
|
|
232
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
233
|
+
blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
234
|
+
);
|
|
235
|
+
const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
|
|
163
236
|
|
|
164
237
|
// TODO(palla/mbps): Should we source this from the constants instead?
|
|
165
238
|
// timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
|
|
@@ -169,7 +242,9 @@ export class LightweightCheckpointBuilder {
|
|
|
169
242
|
|
|
170
243
|
const header = CheckpointHeader.from({
|
|
171
244
|
lastArchiveRoot: this.lastArchives[0].root,
|
|
172
|
-
|
|
245
|
+
blobsHash,
|
|
246
|
+
inHash,
|
|
247
|
+
epochOutHash,
|
|
173
248
|
blockHeadersHash,
|
|
174
249
|
slotNumber,
|
|
175
250
|
timestamp,
|
|
@@ -187,6 +262,7 @@ export class LightweightCheckpointBuilder {
|
|
|
187
262
|
this.checkpointNumber,
|
|
188
263
|
this.constants,
|
|
189
264
|
[...this.l1ToL2Messages],
|
|
265
|
+
[...this.previousCheckpointOutHashes],
|
|
190
266
|
this.db,
|
|
191
267
|
);
|
|
192
268
|
clone.lastArchives = [...this.lastArchives];
|
|
@@ -44,7 +44,9 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
|
|
|
44
44
|
export class TestContext {
|
|
45
45
|
private headers: Map<number, BlockHeader> = new Map();
|
|
46
46
|
private checkpoints: Checkpoint[] = [];
|
|
47
|
+
private checkpointOutHashes: Fr[] = [];
|
|
47
48
|
private nextCheckpointIndex = 0;
|
|
49
|
+
private nextCheckpointNumber = CheckpointNumber(1);
|
|
48
50
|
private nextBlockNumber = 1;
|
|
49
51
|
private epochNumber = 1;
|
|
50
52
|
private feePayerBalance: Fr;
|
|
@@ -150,6 +152,7 @@ export class TestContext {
|
|
|
150
152
|
|
|
151
153
|
public startNewEpoch() {
|
|
152
154
|
this.checkpoints = [];
|
|
155
|
+
this.checkpointOutHashes = [];
|
|
153
156
|
this.nextCheckpointIndex = 0;
|
|
154
157
|
this.epochNumber++;
|
|
155
158
|
}
|
|
@@ -187,7 +190,8 @@ export class TestContext {
|
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
const checkpointIndex = this.nextCheckpointIndex++;
|
|
190
|
-
const checkpointNumber =
|
|
193
|
+
const checkpointNumber = this.nextCheckpointNumber;
|
|
194
|
+
this.nextCheckpointNumber++;
|
|
191
195
|
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
192
196
|
|
|
193
197
|
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
@@ -204,6 +208,8 @@ export class TestContext {
|
|
|
204
208
|
|
|
205
209
|
const startBlockNumber = this.nextBlockNumber;
|
|
206
210
|
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
211
|
+
// All blocks in the same slot/checkpoint share the same timestamp.
|
|
212
|
+
const timestamp = BigInt(slotNumber * 26);
|
|
207
213
|
|
|
208
214
|
// Build global variables.
|
|
209
215
|
const blockGlobalVariables = times(numBlocks, i =>
|
|
@@ -211,6 +217,7 @@ export class TestContext {
|
|
|
211
217
|
coinbase: constants.coinbase,
|
|
212
218
|
feeRecipient: constants.feeRecipient,
|
|
213
219
|
gasFees: constants.gasFees,
|
|
220
|
+
timestamp,
|
|
214
221
|
}),
|
|
215
222
|
);
|
|
216
223
|
this.nextBlockNumber += numBlocks;
|
|
@@ -240,10 +247,12 @@ export class TestContext {
|
|
|
240
247
|
});
|
|
241
248
|
|
|
242
249
|
const cleanFork = await this.worldState.fork();
|
|
250
|
+
const previousCheckpointOutHashes = this.checkpointOutHashes;
|
|
243
251
|
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
244
252
|
checkpointNumber,
|
|
245
253
|
constants,
|
|
246
254
|
l1ToL2Messages,
|
|
255
|
+
previousCheckpointOutHashes,
|
|
247
256
|
cleanFork,
|
|
248
257
|
);
|
|
249
258
|
|
|
@@ -269,6 +278,7 @@ export class TestContext {
|
|
|
269
278
|
|
|
270
279
|
const checkpoint = await builder.completeCheckpoint();
|
|
271
280
|
this.checkpoints.push(checkpoint);
|
|
281
|
+
this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
|
|
272
282
|
|
|
273
283
|
return {
|
|
274
284
|
constants,
|
|
@@ -282,7 +282,7 @@ export const buildHeaderFromCircuitOutputs = runInSpan(
|
|
|
282
282
|
chainId: constants.chainId,
|
|
283
283
|
version: constants.version,
|
|
284
284
|
blockNumber: BlockNumber(blockRootRollupOutput.previousArchive.nextAvailableLeafIndex),
|
|
285
|
-
timestamp: blockRootRollupOutput.
|
|
285
|
+
timestamp: blockRootRollupOutput.timestamp,
|
|
286
286
|
slotNumber: constants.slotNumber,
|
|
287
287
|
coinbase: constants.coinbase,
|
|
288
288
|
feeRecipient: constants.feeRecipient,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
12
12
|
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
13
13
|
NUM_MSGS_PER_BASE_PARITY,
|
|
14
|
+
OUT_HASH_TREE_HEIGHT,
|
|
14
15
|
} from '@aztec/constants';
|
|
15
16
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
16
17
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -19,6 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
19
20
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
20
21
|
import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
21
22
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
23
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
22
24
|
import { ParityBasePrivateInputs } from '@aztec/stdlib/parity';
|
|
23
25
|
import {
|
|
24
26
|
BlockMergeRollupPrivateInputs,
|
|
@@ -38,6 +40,11 @@ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-h
|
|
|
38
40
|
import { BlockProvingState, type ProofState } from './block-proving-state.js';
|
|
39
41
|
import type { EpochProvingState } from './epoch-proving-state.js';
|
|
40
42
|
|
|
43
|
+
type OutHashHint = {
|
|
44
|
+
treeSnapshot: AppendOnlyTreeSnapshot;
|
|
45
|
+
siblingPath: Tuple<Fr, typeof OUT_HASH_TREE_HEIGHT>;
|
|
46
|
+
};
|
|
47
|
+
|
|
41
48
|
export class CheckpointProvingState {
|
|
42
49
|
private blockProofs: UnbalancedTreeStore<
|
|
43
50
|
ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
@@ -46,6 +53,11 @@ export class CheckpointProvingState {
|
|
|
46
53
|
| ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
47
54
|
| undefined;
|
|
48
55
|
private blocks: (BlockProvingState | undefined)[] = [];
|
|
56
|
+
private previousOutHashHint: OutHashHint | undefined;
|
|
57
|
+
private outHash: Fr | undefined;
|
|
58
|
+
// The snapshot and sibling path after the checkpoint's out hash is inserted.
|
|
59
|
+
// Stored here to be retrieved for the next checkpoint when it's added.
|
|
60
|
+
private newOutHashHint: OutHashHint | undefined;
|
|
49
61
|
private startBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
50
62
|
private endBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
51
63
|
private blobFields: Fr[] | undefined;
|
|
@@ -195,6 +207,35 @@ export class CheckpointProvingState {
|
|
|
195
207
|
return new ParityBasePrivateInputs(messages, this.constants.vkTreeRoot);
|
|
196
208
|
}
|
|
197
209
|
|
|
210
|
+
public setOutHashHint(hint: OutHashHint) {
|
|
211
|
+
this.previousOutHashHint = hint;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public getOutHashHint() {
|
|
215
|
+
return this.previousOutHashHint;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public accumulateBlockOutHashes() {
|
|
219
|
+
if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!this.outHash) {
|
|
224
|
+
const messagesPerBlock = this.blocks.map(b => b!.getTxEffects().map(tx => tx.l2ToL1Msgs));
|
|
225
|
+
this.outHash = computeCheckpointOutHash(messagesPerBlock);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return this.outHash;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public setOutHashHintForNextCheckpoint(hint: OutHashHint) {
|
|
232
|
+
this.newOutHashHint = hint;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public getOutHashHintForNextCheckpoint() {
|
|
236
|
+
return this.newOutHashHint;
|
|
237
|
+
}
|
|
238
|
+
|
|
198
239
|
public async accumulateBlobs(startBlobAccumulator: BatchedBlobAccumulator) {
|
|
199
240
|
if (this.isAcceptingBlocks() || this.blocks.some(b => !b?.hasEndState())) {
|
|
200
241
|
return;
|
|
@@ -236,6 +277,9 @@ export class CheckpointProvingState {
|
|
|
236
277
|
if (proofs.length !== nonEmptyProofs.length) {
|
|
237
278
|
throw new Error('At least one child is not ready for the checkpoint root rollup.');
|
|
238
279
|
}
|
|
280
|
+
if (!this.previousOutHashHint) {
|
|
281
|
+
throw new Error('Out hash hint is not set.');
|
|
282
|
+
}
|
|
239
283
|
if (!this.startBlobAccumulator) {
|
|
240
284
|
throw new Error('Start blob accumulator is not set.');
|
|
241
285
|
}
|
|
@@ -248,6 +292,8 @@ export class CheckpointProvingState {
|
|
|
248
292
|
const hints = CheckpointRootRollupHints.from({
|
|
249
293
|
previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
|
|
250
294
|
previousArchiveSiblingPath: this.lastArchiveSiblingPath,
|
|
295
|
+
previousOutHash: this.previousOutHashHint.treeSnapshot,
|
|
296
|
+
newOutHashSiblingPath: this.previousOutHashHint.siblingPath,
|
|
251
297
|
startBlobAccumulator: this.startBlobAccumulator.toBlobAccumulator(),
|
|
252
298
|
finalBlobChallenges: this.finalBlobBatchingChallenges,
|
|
253
299
|
blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_CHECKPOINT),
|
|
@@ -273,7 +319,7 @@ export class CheckpointProvingState {
|
|
|
273
319
|
|
|
274
320
|
public isReadyForCheckpointRoot() {
|
|
275
321
|
const allChildProofsReady = this.#getChildProofsForRoot().every(p => !!p);
|
|
276
|
-
return allChildProofsReady && !!this.startBlobAccumulator;
|
|
322
|
+
return allChildProofsReady && !!this.previousOutHashHint && !!this.startBlobAccumulator;
|
|
277
323
|
}
|
|
278
324
|
|
|
279
325
|
public verifyState() {
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
-
import
|
|
3
|
-
ARCHIVE_HEIGHT,
|
|
4
|
-
L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
-
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
-
NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
2
|
+
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
4
|
+
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
+
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
|
+
OUT_HASH_TREE_HEIGHT,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
9
|
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
9
|
-
import
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
MerkleTreeCalculator,
|
|
14
|
+
type TreeNodeLocation,
|
|
15
|
+
UnbalancedTreeStore,
|
|
16
|
+
shaMerkleHash,
|
|
17
|
+
} from '@aztec/foundation/trees';
|
|
12
18
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
13
19
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
14
20
|
import {
|
|
@@ -20,7 +26,7 @@ import {
|
|
|
20
26
|
RootRollupPrivateInputs,
|
|
21
27
|
type RootRollupPublicInputs,
|
|
22
28
|
} from '@aztec/stdlib/rollup';
|
|
23
|
-
import
|
|
29
|
+
import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
|
|
24
30
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
25
31
|
|
|
26
32
|
import { toProofData } from './block-building-helpers.js';
|
|
@@ -212,6 +218,48 @@ export class EpochProvingState {
|
|
|
212
218
|
this.checkpointPaddingProof = { provingOutput };
|
|
213
219
|
}
|
|
214
220
|
|
|
221
|
+
public async accumulateCheckpointOutHashes() {
|
|
222
|
+
const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right) =>
|
|
223
|
+
Promise.resolve(shaMerkleHash(left, right)),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const computeOutHashHint = async (leaves: Fr[]) => {
|
|
227
|
+
const tree = await treeCalculator.computeTree(leaves.map(l => l.toBuffer()));
|
|
228
|
+
const nextAvailableLeafIndex = leaves.length;
|
|
229
|
+
return {
|
|
230
|
+
treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
|
|
231
|
+
siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer) as Tuple<
|
|
232
|
+
Fr,
|
|
233
|
+
typeof OUT_HASH_TREE_HEIGHT
|
|
234
|
+
>,
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
let hint = this.checkpoints[0]?.getOutHashHint();
|
|
239
|
+
const outHashes = [];
|
|
240
|
+
for (let i = 0; i < this.totalNumCheckpoints; i++) {
|
|
241
|
+
const checkpoint = this.checkpoints[i];
|
|
242
|
+
if (!checkpoint) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// If hints are not set yet, it must be the first checkpoint. Compute the hints with an empty tree.
|
|
247
|
+
hint ??= await computeOutHashHint([]);
|
|
248
|
+
checkpoint.setOutHashHint(hint);
|
|
249
|
+
|
|
250
|
+
// Get the out hash for this checkpoint.
|
|
251
|
+
const outHash = checkpoint.accumulateBlockOutHashes();
|
|
252
|
+
if (!outHash) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
outHashes.push(outHash);
|
|
256
|
+
|
|
257
|
+
// Get or create hints for the next checkpoint.
|
|
258
|
+
hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
|
|
259
|
+
checkpoint.setOutHashHintForNextCheckpoint(hint);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
215
263
|
public async setBlobAccumulators() {
|
|
216
264
|
let previousAccumulator = this.startBlobAccumulator;
|
|
217
265
|
// Accumulate blobs as far as we can for this epoch.
|
|
@@ -113,6 +113,10 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
113
113
|
return this.proverId;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
public getNumActiveForks() {
|
|
117
|
+
return this.dbs.size;
|
|
118
|
+
}
|
|
119
|
+
|
|
116
120
|
public stop(): Promise<void> {
|
|
117
121
|
this.cancel();
|
|
118
122
|
return Promise.resolve();
|
|
@@ -143,6 +147,14 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
143
147
|
this.provingPromise = promise;
|
|
144
148
|
}
|
|
145
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Starts a new checkpoint.
|
|
152
|
+
* @param checkpointIndex - The index of the checkpoint in the epoch.
|
|
153
|
+
* @param constants - The constants for this checkpoint.
|
|
154
|
+
* @param l1ToL2Messages - The set of L1 to L2 messages to be inserted at the beginning of this checkpoint.
|
|
155
|
+
* @param totalNumBlocks - The total number of blocks expected in the checkpoint (must be at least one).
|
|
156
|
+
* @param headerOfLastBlockInPreviousCheckpoint - The header of the last block in the previous checkpoint.
|
|
157
|
+
*/
|
|
146
158
|
public async startNewCheckpoint(
|
|
147
159
|
checkpointIndex: number,
|
|
148
160
|
constants: CheckpointConstantData,
|
|
@@ -255,7 +267,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
255
267
|
await endSpongeBlob.absorb(blockEndBlobFields);
|
|
256
268
|
blockProvingState.setEndSpongeBlob(endSpongeBlob);
|
|
257
269
|
|
|
258
|
-
//
|
|
270
|
+
// Try to accumulate the out hashes and blobs as far as we can:
|
|
271
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
259
272
|
await this.provingState.setBlobAccumulators();
|
|
260
273
|
}
|
|
261
274
|
}
|
|
@@ -352,7 +365,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
352
365
|
|
|
353
366
|
provingState.setEndSpongeBlob(spongeBlobState);
|
|
354
367
|
|
|
355
|
-
// Txs have been added to the block. Now try to accumulate the blobs as far as we can:
|
|
368
|
+
// Txs have been added to the block. Now try to accumulate the out hashes and blobs as far as we can:
|
|
369
|
+
await this.provingState.accumulateCheckpointOutHashes();
|
|
356
370
|
await this.provingState.setBlobAccumulators();
|
|
357
371
|
}
|
|
358
372
|
|
|
@@ -486,12 +500,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
486
500
|
// is aborted and never reaches this point, it will leak the fork. We need to add a global cleanup,
|
|
487
501
|
// but have to make sure it only runs once all operations are completed, otherwise some function here
|
|
488
502
|
// will attempt to access the fork after it was closed.
|
|
489
|
-
|
|
490
|
-
void this.dbs
|
|
491
|
-
.get(blockNumber)
|
|
492
|
-
?.close()
|
|
493
|
-
.then(() => this.dbs.delete(blockNumber))
|
|
494
|
-
.catch(err => logger.error(`Error closing db for block ${blockNumber}`, err));
|
|
503
|
+
void this.cleanupDBFork(blockNumber);
|
|
495
504
|
}
|
|
496
505
|
|
|
497
506
|
/**
|
|
@@ -534,6 +543,21 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
534
543
|
return epochProofResult;
|
|
535
544
|
}
|
|
536
545
|
|
|
546
|
+
private async cleanupDBFork(blockNumber: BlockNumber): Promise<void> {
|
|
547
|
+
logger.debug(`Cleaning up world state fork for ${blockNumber}`);
|
|
548
|
+
const fork = this.dbs.get(blockNumber);
|
|
549
|
+
if (!fork) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
try {
|
|
554
|
+
await fork.close();
|
|
555
|
+
this.dbs.delete(blockNumber);
|
|
556
|
+
} catch (err) {
|
|
557
|
+
logger.error(`Error closing db for block ${blockNumber}`, err);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
537
561
|
/**
|
|
538
562
|
* Enqueue a job to be scheduled
|
|
539
563
|
* @param provingState - The proving state object being operated on
|
|
@@ -851,19 +875,22 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
851
875
|
},
|
|
852
876
|
),
|
|
853
877
|
async result => {
|
|
854
|
-
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
855
|
-
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
856
|
-
|
|
857
878
|
logger.debug(`Completed ${rollupType} proof for block ${provingState.blockNumber}`);
|
|
858
879
|
|
|
859
880
|
const leafLocation = provingState.setBlockRootRollupProof(result);
|
|
860
881
|
const checkpointProvingState = provingState.parentCheckpoint;
|
|
861
882
|
|
|
883
|
+
// If the proofs were slower than the block header building, then we need to try validating the block header hashes here.
|
|
884
|
+
await this.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
885
|
+
|
|
862
886
|
if (checkpointProvingState.totalNumBlocks === 1) {
|
|
863
887
|
this.checkAndEnqueueCheckpointRootRollup(checkpointProvingState);
|
|
864
888
|
} else {
|
|
865
889
|
this.checkAndEnqueueNextBlockMergeRollup(checkpointProvingState, leafLocation);
|
|
866
890
|
}
|
|
891
|
+
|
|
892
|
+
// We are finished with the block at this point, ensure the fork is cleaned up
|
|
893
|
+
void this.cleanupDBFork(provingState.blockNumber);
|
|
867
894
|
},
|
|
868
895
|
);
|
|
869
896
|
}
|
|
@@ -1219,9 +1246,9 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1219
1246
|
},
|
|
1220
1247
|
);
|
|
1221
1248
|
|
|
1222
|
-
this.deferredProving(provingState, doAvmProving,
|
|
1249
|
+
this.deferredProving(provingState, doAvmProving, proof => {
|
|
1223
1250
|
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1224
|
-
txProvingState.setAvmProof(
|
|
1251
|
+
txProvingState.setAvmProof(proof);
|
|
1225
1252
|
this.checkAndEnqueueBaseRollup(provingState, txIndex);
|
|
1226
1253
|
});
|
|
1227
1254
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Histogram, Metrics, type TelemetryClient, type Tracer
|
|
1
|
+
import { type Histogram, Metrics, type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
|
|
2
2
|
|
|
3
3
|
export class ProvingOrchestratorMetrics {
|
|
4
4
|
public readonly tracer: Tracer;
|
|
@@ -9,11 +9,7 @@ export class ProvingOrchestratorMetrics {
|
|
|
9
9
|
this.tracer = client.getTracer(name);
|
|
10
10
|
const meter = client.getMeter(name);
|
|
11
11
|
|
|
12
|
-
this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION
|
|
13
|
-
unit: 'ms',
|
|
14
|
-
description: 'Duration to build base rollup inputs',
|
|
15
|
-
valueType: ValueType.INT,
|
|
16
|
-
});
|
|
12
|
+
this.baseRollupInputsDuration = meter.createHistogram(Metrics.PROVING_ORCHESTRATOR_BASE_ROLLUP_INPUTS_DURATION);
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
recordBaseRollupInputs(durationMs: number) {
|
|
@@ -2,8 +2,8 @@ import { AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED, NESTED_RECURSIVE_ROLLUP_HONK_PROO
|
|
|
2
2
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
4
4
|
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
5
|
-
import type {
|
|
6
|
-
import { ProofData, ProofDataForFixedVk } from '@aztec/stdlib/proofs';
|
|
5
|
+
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import { ProofData, ProofDataForFixedVk, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
7
7
|
import {
|
|
8
8
|
type BaseRollupHints,
|
|
9
9
|
PrivateBaseRollupHints,
|
|
@@ -32,7 +32,7 @@ export class TxProvingState {
|
|
|
32
32
|
PublicChonkVerifierPublicInputs,
|
|
33
33
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
34
34
|
>;
|
|
35
|
-
private
|
|
35
|
+
private avmProof?: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>;
|
|
36
36
|
|
|
37
37
|
constructor(
|
|
38
38
|
public readonly processedTx: ProcessedTx,
|
|
@@ -46,7 +46,7 @@ export class TxProvingState {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
public ready() {
|
|
49
|
-
return !this.requireAvmProof || (!!this.
|
|
49
|
+
return !this.requireAvmProof || (!!this.avmProof && !!this.publicChonkVerifier);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public getAvmInputs(): AvmCircuitInputs {
|
|
@@ -80,8 +80,8 @@ export class TxProvingState {
|
|
|
80
80
|
this.publicChonkVerifier = publicChonkVerifierProofAndVk;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public setAvmProof(
|
|
84
|
-
this.
|
|
83
|
+
public setAvmProof(avmProof: RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>) {
|
|
84
|
+
this.avmProof = avmProof;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
#getPrivateBaseInputs() {
|
|
@@ -105,7 +105,7 @@ export class TxProvingState {
|
|
|
105
105
|
if (!this.publicChonkVerifier) {
|
|
106
106
|
throw new Error('Tx not ready for proving base rollup: public chonk verifier proof undefined');
|
|
107
107
|
}
|
|
108
|
-
if (!this.
|
|
108
|
+
if (!this.avmProof) {
|
|
109
109
|
throw new Error('Tx not ready for proving base rollup: avm proof undefined');
|
|
110
110
|
}
|
|
111
111
|
if (!(this.baseRollupHints instanceof PublicBaseRollupHints)) {
|
|
@@ -114,10 +114,7 @@ export class TxProvingState {
|
|
|
114
114
|
|
|
115
115
|
const publicChonkVerifierProofData = toProofData(this.publicChonkVerifier);
|
|
116
116
|
|
|
117
|
-
const avmProofData = new ProofDataForFixedVk(
|
|
118
|
-
this.processedTx.avmProvingRequest.inputs.publicInputs,
|
|
119
|
-
this.avm.proof,
|
|
120
|
-
);
|
|
117
|
+
const avmProofData = new ProofDataForFixedVk(this.processedTx.avmProvingRequest.inputs.publicInputs, this.avmProof);
|
|
121
118
|
|
|
122
119
|
return new PublicTxBaseRollupPrivateInputs(publicChonkVerifierProofData, avmProofData, this.baseRollupHints);
|
|
123
120
|
}
|
|
@@ -130,15 +130,7 @@ export class ProverClient implements EpochProverManager {
|
|
|
130
130
|
const prover = await buildServerCircuitProver(this.config, this.telemetry);
|
|
131
131
|
this.agents = times(
|
|
132
132
|
this.config.proverAgentCount,
|
|
133
|
-
() =>
|
|
134
|
-
new ProvingAgent(
|
|
135
|
-
this.agentClient!,
|
|
136
|
-
proofStore,
|
|
137
|
-
prover,
|
|
138
|
-
[],
|
|
139
|
-
this.config.proverAgentPollIntervalMs,
|
|
140
|
-
this.telemetry,
|
|
141
|
-
),
|
|
133
|
+
() => new ProvingAgent(this.agentClient!, proofStore, prover, [], this.config.proverAgentPollIntervalMs),
|
|
142
134
|
);
|
|
143
135
|
|
|
144
136
|
await Promise.all(this.agents.map(agent => agent.start()));
|
|
@@ -11,7 +11,6 @@ import { type PromiseWithResolvers, RunningPromise, promiseWithResolvers } from
|
|
|
11
11
|
import { truncate } from '@aztec/foundation/string';
|
|
12
12
|
import type { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
13
13
|
import {
|
|
14
|
-
type ProofAndVerificationKey,
|
|
15
14
|
type ProofUri,
|
|
16
15
|
type ProvingJobId,
|
|
17
16
|
type ProvingJobInputsMap,
|
|
@@ -23,7 +22,7 @@ import {
|
|
|
23
22
|
makeProvingJobId,
|
|
24
23
|
} from '@aztec/stdlib/interfaces/server';
|
|
25
24
|
import type { ParityBasePrivateInputs, ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
|
|
26
|
-
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
25
|
+
import { ProvingRequestType, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
27
26
|
import type {
|
|
28
27
|
BlockMergeRollupPrivateInputs,
|
|
29
28
|
BlockRollupPublicInputs,
|
|
@@ -399,7 +398,7 @@ export class BrokerCircuitProverFacade implements ServerCircuitProver {
|
|
|
399
398
|
inputs: AvmCircuitInputs,
|
|
400
399
|
signal?: AbortSignal,
|
|
401
400
|
epochNumber?: EpochNumber,
|
|
402
|
-
): Promise<
|
|
401
|
+
): Promise<RecursiveProof<typeof AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED>> {
|
|
403
402
|
return this.enqueueJob(
|
|
404
403
|
this.generateId(ProvingRequestType.PUBLIC_VM, inputs, epochNumber),
|
|
405
404
|
ProvingRequestType.PUBLIC_VM,
|