@aztec/prover-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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 +15 -7
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +57 -24
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +2 -1
- package/dest/mocks/test_context.d.ts +3 -2
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +10 -2
- package/dest/orchestrator/block-building-helpers.d.ts +5 -5
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +3 -3
- package/dest/orchestrator/block-proving-state.d.ts +4 -1
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +7 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +17 -4
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +37 -4
- package/dest/orchestrator/epoch-proving-state.d.ts +7 -6
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +37 -1
- package/dest/orchestrator/orchestrator.d.ts +18 -3
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +128 -95
- package/dest/prover-client/prover-client.d.ts +3 -3
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- 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/broker_prover_facade.js +3 -3
- package/dest/proving_broker/config.d.ts +13 -1
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +19 -2
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -2
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -1
- package/dest/proving_broker/proving_agent.d.ts +4 -3
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -4
- package/dest/proving_broker/proving_broker.d.ts +7 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +36 -4
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +18 -7
- package/dest/proving_broker/proving_job_controller.d.ts +4 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +6 -3
- package/dest/proving_broker/rpc.d.ts +4 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +8 -0
- 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 +4 -4
- package/package.json +16 -17
- package/src/light/lightweight_checkpoint_builder.ts +82 -30
- package/src/mocks/fixtures.ts +2 -1
- package/src/mocks/test_context.ts +7 -2
- package/src/orchestrator/block-building-helpers.ts +3 -3
- package/src/orchestrator/block-proving-state.ts +9 -0
- package/src/orchestrator/checkpoint-proving-state.ts +51 -5
- package/src/orchestrator/epoch-proving-state.ts +59 -9
- package/src/orchestrator/orchestrator.ts +139 -104
- package/src/prover-client/prover-client.ts +29 -14
- package/src/proving_broker/broker_prover_facade.ts +6 -3
- package/src/proving_broker/config.ts +22 -0
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -1
- package/src/proving_broker/proving_agent.ts +5 -2
- package/src/proving_broker/proving_broker.ts +37 -3
- package/src/proving_broker/proving_broker_instrumentation.ts +19 -6
- package/src/proving_broker/proving_job_controller.ts +9 -3
- package/src/proving_broker/rpc.ts +14 -0
- 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 -106
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -136
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
|
@@ -1,13 +1,18 @@
|
|
|
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
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
-
import {
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { elapsed } from '@aztec/foundation/timer';
|
|
8
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
8
9
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
9
10
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
accumulateCheckpointOutHashes,
|
|
13
|
+
computeCheckpointOutHash,
|
|
14
|
+
computeInHashFromL1ToL2Messages,
|
|
15
|
+
} from '@aztec/stdlib/messaging';
|
|
11
16
|
import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
|
|
12
17
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
18
|
import {
|
|
@@ -30,28 +35,38 @@ import {
|
|
|
30
35
|
* Finally completes the checkpoint by computing its header.
|
|
31
36
|
*/
|
|
32
37
|
export class LightweightCheckpointBuilder {
|
|
33
|
-
private readonly logger
|
|
38
|
+
private readonly logger: Logger;
|
|
34
39
|
|
|
35
40
|
private lastArchives: AppendOnlyTreeSnapshot[] = [];
|
|
36
41
|
private spongeBlob: SpongeBlob;
|
|
37
|
-
private blocks:
|
|
42
|
+
private blocks: L2Block[] = [];
|
|
38
43
|
private blobFields: Fr[] = [];
|
|
39
44
|
|
|
40
45
|
constructor(
|
|
41
46
|
public readonly checkpointNumber: CheckpointNumber,
|
|
42
47
|
public readonly constants: CheckpointGlobalVariables,
|
|
48
|
+
public feeAssetPriceModifier: bigint,
|
|
43
49
|
public readonly l1ToL2Messages: Fr[],
|
|
50
|
+
private readonly previousCheckpointOutHashes: Fr[],
|
|
44
51
|
public readonly db: MerkleTreeWriteOperations,
|
|
52
|
+
bindings?: LoggerBindings,
|
|
45
53
|
) {
|
|
54
|
+
this.logger = createLogger('checkpoint-builder', {
|
|
55
|
+
...bindings,
|
|
56
|
+
instanceId: `checkpoint-${checkpointNumber}`,
|
|
57
|
+
});
|
|
46
58
|
this.spongeBlob = SpongeBlob.init();
|
|
47
|
-
this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages });
|
|
59
|
+
this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages, feeAssetPriceModifier });
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
static async startNewCheckpoint(
|
|
51
63
|
checkpointNumber: CheckpointNumber,
|
|
52
64
|
constants: CheckpointGlobalVariables,
|
|
53
65
|
l1ToL2Messages: Fr[],
|
|
66
|
+
previousCheckpointOutHashes: Fr[],
|
|
54
67
|
db: MerkleTreeWriteOperations,
|
|
68
|
+
bindings?: LoggerBindings,
|
|
69
|
+
feeAssetPriceModifier: bigint = 0n,
|
|
55
70
|
): Promise<LightweightCheckpointBuilder> {
|
|
56
71
|
// Insert l1-to-l2 messages into the tree.
|
|
57
72
|
await db.appendLeaves(
|
|
@@ -59,7 +74,15 @@ export class LightweightCheckpointBuilder {
|
|
|
59
74
|
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
60
75
|
);
|
|
61
76
|
|
|
62
|
-
return new LightweightCheckpointBuilder(
|
|
77
|
+
return new LightweightCheckpointBuilder(
|
|
78
|
+
checkpointNumber,
|
|
79
|
+
constants,
|
|
80
|
+
feeAssetPriceModifier,
|
|
81
|
+
l1ToL2Messages,
|
|
82
|
+
previousCheckpointOutHashes,
|
|
83
|
+
db,
|
|
84
|
+
bindings,
|
|
85
|
+
);
|
|
63
86
|
}
|
|
64
87
|
|
|
65
88
|
/**
|
|
@@ -71,11 +94,22 @@ export class LightweightCheckpointBuilder {
|
|
|
71
94
|
static async resumeCheckpoint(
|
|
72
95
|
checkpointNumber: CheckpointNumber,
|
|
73
96
|
constants: CheckpointGlobalVariables,
|
|
97
|
+
feeAssetPriceModifier: bigint,
|
|
74
98
|
l1ToL2Messages: Fr[],
|
|
99
|
+
previousCheckpointOutHashes: Fr[],
|
|
75
100
|
db: MerkleTreeWriteOperations,
|
|
76
|
-
existingBlocks:
|
|
101
|
+
existingBlocks: L2Block[],
|
|
102
|
+
bindings?: LoggerBindings,
|
|
77
103
|
): Promise<LightweightCheckpointBuilder> {
|
|
78
|
-
const builder = new LightweightCheckpointBuilder(
|
|
104
|
+
const builder = new LightweightCheckpointBuilder(
|
|
105
|
+
checkpointNumber,
|
|
106
|
+
constants,
|
|
107
|
+
feeAssetPriceModifier,
|
|
108
|
+
l1ToL2Messages,
|
|
109
|
+
previousCheckpointOutHashes,
|
|
110
|
+
db,
|
|
111
|
+
bindings,
|
|
112
|
+
);
|
|
79
113
|
|
|
80
114
|
builder.logger.debug('Resuming checkpoint from existing blocks', {
|
|
81
115
|
checkpointNumber,
|
|
@@ -115,6 +149,11 @@ export class LightweightCheckpointBuilder {
|
|
|
115
149
|
return builder;
|
|
116
150
|
}
|
|
117
151
|
|
|
152
|
+
/** Returns how many blocks have been added to this checkpoint so far */
|
|
153
|
+
public getBlockCount() {
|
|
154
|
+
return this.blocks.length;
|
|
155
|
+
}
|
|
156
|
+
|
|
118
157
|
/**
|
|
119
158
|
* Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
|
|
120
159
|
* this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
|
|
@@ -123,7 +162,8 @@ export class LightweightCheckpointBuilder {
|
|
|
123
162
|
globalVariables: GlobalVariables,
|
|
124
163
|
txs: ProcessedTx[],
|
|
125
164
|
opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
|
|
126
|
-
): Promise<
|
|
165
|
+
): Promise<{ block: L2Block; timings: Record<string, number> }> {
|
|
166
|
+
const timings: Record<string, number> = {};
|
|
127
167
|
const isFirstBlock = this.blocks.length === 0;
|
|
128
168
|
|
|
129
169
|
// Empty blocks are only allowed as the first block in a checkpoint
|
|
@@ -132,7 +172,9 @@ export class LightweightCheckpointBuilder {
|
|
|
132
172
|
}
|
|
133
173
|
|
|
134
174
|
if (isFirstBlock) {
|
|
135
|
-
|
|
175
|
+
const [msGetInitialArchive, initialArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
|
|
176
|
+
this.lastArchives.push(initialArchive);
|
|
177
|
+
timings.getInitialArchive = msGetInitialArchive;
|
|
136
178
|
}
|
|
137
179
|
|
|
138
180
|
const lastArchive = this.lastArchives.at(-1)!;
|
|
@@ -142,12 +184,17 @@ export class LightweightCheckpointBuilder {
|
|
|
142
184
|
`Inserting side effects for ${txs.length} txs for block ${globalVariables.blockNumber} into db`,
|
|
143
185
|
{ txs: txs.map(tx => tx.hash.toString()) },
|
|
144
186
|
);
|
|
187
|
+
let msInsertSideEffects = 0;
|
|
145
188
|
for (const tx of txs) {
|
|
146
|
-
await insertSideEffects(tx, this.db);
|
|
189
|
+
const [ms] = await elapsed(() => insertSideEffects(tx, this.db));
|
|
190
|
+
msInsertSideEffects += ms;
|
|
147
191
|
}
|
|
192
|
+
timings.insertSideEffects = msInsertSideEffects;
|
|
148
193
|
}
|
|
149
194
|
|
|
150
|
-
const endState = await this.db.getStateReference();
|
|
195
|
+
const [msGetEndState, endState] = await elapsed(() => this.db.getStateReference());
|
|
196
|
+
timings.getEndState = msGetEndState;
|
|
197
|
+
|
|
151
198
|
if (opts.expectedEndState && !endState.equals(opts.expectedEndState)) {
|
|
152
199
|
this.logger.error('End state after processing txs does not match expected end state', {
|
|
153
200
|
globalVariables: globalVariables.toInspect(),
|
|
@@ -157,26 +204,24 @@ export class LightweightCheckpointBuilder {
|
|
|
157
204
|
throw new Error(`End state does not match expected end state when building block ${globalVariables.blockNumber}`);
|
|
158
205
|
}
|
|
159
206
|
|
|
160
|
-
const { header, body, blockBlobFields } = await
|
|
161
|
-
txs,
|
|
162
|
-
lastArchive,
|
|
163
|
-
endState,
|
|
164
|
-
globalVariables,
|
|
165
|
-
this.spongeBlob,
|
|
166
|
-
isFirstBlock,
|
|
207
|
+
const [msBuildHeaderAndBody, { header, body, blockBlobFields }] = await elapsed(() =>
|
|
208
|
+
buildHeaderAndBodyFromTxs(txs, lastArchive, endState, globalVariables, this.spongeBlob, isFirstBlock),
|
|
167
209
|
);
|
|
210
|
+
timings.buildHeaderAndBody = msBuildHeaderAndBody;
|
|
168
211
|
|
|
169
212
|
header.state.validate();
|
|
170
213
|
|
|
171
214
|
await this.db.updateArchive(header);
|
|
172
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
215
|
+
const [msUpdateArchive, newArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
|
|
216
|
+
timings.updateArchive = msUpdateArchive;
|
|
173
217
|
this.lastArchives.push(newArchive);
|
|
174
218
|
|
|
175
|
-
const indexWithinCheckpoint = this.blocks.length;
|
|
176
|
-
const block = new
|
|
219
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
|
|
220
|
+
const block = new L2Block(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
|
|
177
221
|
this.blocks.push(block);
|
|
178
222
|
|
|
179
|
-
await this.spongeBlob.absorb(blockBlobFields);
|
|
223
|
+
const [msSpongeAbsorb] = await elapsed(() => this.spongeBlob.absorb(blockBlobFields));
|
|
224
|
+
timings.spongeAbsorb = msSpongeAbsorb;
|
|
180
225
|
this.blobFields.push(...blockBlobFields);
|
|
181
226
|
|
|
182
227
|
this.logger.debug(`Built block ${header.getBlockNumber()}`, {
|
|
@@ -187,7 +232,7 @@ export class LightweightCheckpointBuilder {
|
|
|
187
232
|
txs: block.body.txEffects.map(tx => tx.txHash.toString()),
|
|
188
233
|
});
|
|
189
234
|
|
|
190
|
-
return block;
|
|
235
|
+
return { block, timings };
|
|
191
236
|
}
|
|
192
237
|
|
|
193
238
|
async completeCheckpoint(): Promise<Checkpoint> {
|
|
@@ -204,15 +249,18 @@ export class LightweightCheckpointBuilder {
|
|
|
204
249
|
|
|
205
250
|
const newArchive = this.lastArchives[this.lastArchives.length - 1];
|
|
206
251
|
|
|
207
|
-
const blobs = getBlobsPerL1Block(this.blobFields);
|
|
252
|
+
const blobs = await getBlobsPerL1Block(this.blobFields);
|
|
208
253
|
const blobsHash = computeBlobsHashFromBlobs(blobs);
|
|
209
254
|
|
|
210
255
|
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
|
|
211
256
|
|
|
212
257
|
const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
|
|
258
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
259
|
+
blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
260
|
+
);
|
|
261
|
+
const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
|
|
213
262
|
|
|
214
|
-
//
|
|
215
|
-
// timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
|
|
263
|
+
// All blocks in the checkpoint have the same timestamp
|
|
216
264
|
const timestamp = blocks[blocks.length - 1].timestamp;
|
|
217
265
|
|
|
218
266
|
const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
|
|
@@ -221,6 +269,7 @@ export class LightweightCheckpointBuilder {
|
|
|
221
269
|
lastArchiveRoot: this.lastArchives[0].root,
|
|
222
270
|
blobsHash,
|
|
223
271
|
inHash,
|
|
272
|
+
epochOutHash,
|
|
224
273
|
blockHeadersHash,
|
|
225
274
|
slotNumber,
|
|
226
275
|
timestamp,
|
|
@@ -230,15 +279,18 @@ export class LightweightCheckpointBuilder {
|
|
|
230
279
|
totalManaUsed,
|
|
231
280
|
});
|
|
232
281
|
|
|
233
|
-
return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
|
|
282
|
+
return new Checkpoint(newArchive, header, blocks, this.checkpointNumber, this.feeAssetPriceModifier);
|
|
234
283
|
}
|
|
235
284
|
|
|
236
285
|
clone() {
|
|
237
286
|
const clone = new LightweightCheckpointBuilder(
|
|
238
287
|
this.checkpointNumber,
|
|
239
288
|
this.constants,
|
|
289
|
+
this.feeAssetPriceModifier,
|
|
240
290
|
[...this.l1ToL2Messages],
|
|
291
|
+
[...this.previousCheckpointOutHashes],
|
|
241
292
|
this.db,
|
|
293
|
+
this.logger.getBindings(),
|
|
242
294
|
);
|
|
243
295
|
clone.lastArchives = [...this.lastArchives];
|
|
244
296
|
clone.spongeBlob = this.spongeBlob.clone();
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -75,7 +75,8 @@ export async function getSimulator(
|
|
|
75
75
|
logger?.info(
|
|
76
76
|
`Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`,
|
|
77
77
|
);
|
|
78
|
-
|
|
78
|
+
const acvmLogger = logger?.createChild('acvm-native');
|
|
79
|
+
return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, acvmLogger);
|
|
79
80
|
} catch {
|
|
80
81
|
logger?.warn(`Failed to access ACVM at ${config.acvmBinaryPath}, falling back to WASM`);
|
|
81
82
|
}
|
|
@@ -44,6 +44,7 @@ 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;
|
|
48
49
|
private nextCheckpointNumber = CheckpointNumber(1);
|
|
49
50
|
private nextBlockNumber = 1;
|
|
@@ -151,6 +152,7 @@ export class TestContext {
|
|
|
151
152
|
|
|
152
153
|
public startNewEpoch() {
|
|
153
154
|
this.checkpoints = [];
|
|
155
|
+
this.checkpointOutHashes = [];
|
|
154
156
|
this.nextCheckpointIndex = 0;
|
|
155
157
|
this.epochNumber++;
|
|
156
158
|
}
|
|
@@ -245,10 +247,12 @@ export class TestContext {
|
|
|
245
247
|
});
|
|
246
248
|
|
|
247
249
|
const cleanFork = await this.worldState.fork();
|
|
250
|
+
const previousCheckpointOutHashes = this.checkpointOutHashes;
|
|
248
251
|
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
249
252
|
checkpointNumber,
|
|
250
|
-
constants,
|
|
253
|
+
{ ...constants, timestamp },
|
|
251
254
|
l1ToL2Messages,
|
|
255
|
+
previousCheckpointOutHashes,
|
|
252
256
|
cleanFork,
|
|
253
257
|
);
|
|
254
258
|
|
|
@@ -258,7 +262,7 @@ export class TestContext {
|
|
|
258
262
|
const txs = blockTxs[i];
|
|
259
263
|
const state = blockEndStates[i];
|
|
260
264
|
|
|
261
|
-
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
265
|
+
const { block } = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
262
266
|
expectedEndState: state,
|
|
263
267
|
insertTxsEffects: true,
|
|
264
268
|
});
|
|
@@ -274,6 +278,7 @@ export class TestContext {
|
|
|
274
278
|
|
|
275
279
|
const checkpoint = await builder.completeCheckpoint();
|
|
276
280
|
this.checkpoints.push(checkpoint);
|
|
281
|
+
this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
|
|
277
282
|
|
|
278
283
|
return {
|
|
279
284
|
constants,
|
|
@@ -99,7 +99,7 @@ export const insertSideEffectsAndBuildBaseRollupHints = runInSpan(
|
|
|
99
99
|
|
|
100
100
|
const blockHash = await tx.data.constants.anchorBlockHeader.hash();
|
|
101
101
|
const anchorBlockArchiveSiblingPath = (
|
|
102
|
-
await getMembershipWitnessFor(blockHash, MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
|
|
102
|
+
await getMembershipWitnessFor(blockHash.toFr(), MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
|
|
103
103
|
).siblingPath;
|
|
104
104
|
|
|
105
105
|
const contractClassLogsFields = makeTuple(
|
|
@@ -253,8 +253,8 @@ export function getPublicChonkVerifierPrivateInputsFromTx(tx: Tx | ProcessedTx,
|
|
|
253
253
|
// Build "hints" as the private inputs for the checkpoint root rollup circuit.
|
|
254
254
|
// The `blobCommitments` will be accumulated and checked in the root rollup against the `finalBlobChallenges`.
|
|
255
255
|
// The `blobsHash` will be validated on L1 against the submitted blob data.
|
|
256
|
-
export const buildBlobHints = (blobFields: Fr[]) => {
|
|
257
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
256
|
+
export const buildBlobHints = async (blobFields: Fr[]) => {
|
|
257
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
258
258
|
const blobCommitments = getBlobCommitmentsFromBlobs(blobs);
|
|
259
259
|
const blobsHash = computeBlobsHashFromBlobs(blobs);
|
|
260
260
|
return { blobCommitments, blobs, blobsHash };
|
|
@@ -55,6 +55,7 @@ export class BlockProvingState {
|
|
|
55
55
|
| ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
56
56
|
| undefined;
|
|
57
57
|
private builtBlockHeader: BlockHeader | undefined;
|
|
58
|
+
private builtArchive: AppendOnlyTreeSnapshot | undefined;
|
|
58
59
|
private endState: StateReference | undefined;
|
|
59
60
|
private endSpongeBlob: SpongeBlob | undefined;
|
|
60
61
|
private txs: TxProvingState[] = [];
|
|
@@ -232,6 +233,14 @@ export class BlockProvingState {
|
|
|
232
233
|
return this.builtBlockHeader;
|
|
233
234
|
}
|
|
234
235
|
|
|
236
|
+
public setBuiltArchive(archive: AppendOnlyTreeSnapshot) {
|
|
237
|
+
this.builtArchive = archive;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public getBuiltArchive() {
|
|
241
|
+
return this.builtArchive;
|
|
242
|
+
}
|
|
243
|
+
|
|
235
244
|
public getStartSpongeBlob() {
|
|
236
245
|
return this.startSpongeBlob;
|
|
237
246
|
}
|
|
@@ -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;
|
|
@@ -73,7 +85,7 @@ export class CheckpointProvingState {
|
|
|
73
85
|
typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
|
|
74
86
|
>,
|
|
75
87
|
public parentEpoch: EpochProvingState,
|
|
76
|
-
private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void
|
|
88
|
+
private onBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
|
|
77
89
|
) {
|
|
78
90
|
this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
|
|
79
91
|
this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
|
|
@@ -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;
|
|
@@ -204,7 +245,7 @@ export class CheckpointProvingState {
|
|
|
204
245
|
this.endBlobAccumulator = await accumulateBlobs(this.blobFields!, startBlobAccumulator);
|
|
205
246
|
this.startBlobAccumulator = startBlobAccumulator;
|
|
206
247
|
|
|
207
|
-
this.onBlobAccumulatorSet(this);
|
|
248
|
+
await this.onBlobAccumulatorSet(this);
|
|
208
249
|
|
|
209
250
|
return this.endBlobAccumulator;
|
|
210
251
|
}
|
|
@@ -230,12 +271,15 @@ export class CheckpointProvingState {
|
|
|
230
271
|
return this.totalNumBlocks === 1 ? 'rollup-checkpoint-root-single-block' : 'rollup-checkpoint-root';
|
|
231
272
|
}
|
|
232
273
|
|
|
233
|
-
public getCheckpointRootRollupInputs() {
|
|
274
|
+
public async getCheckpointRootRollupInputs() {
|
|
234
275
|
const proofs = this.#getChildProofsForRoot();
|
|
235
276
|
const nonEmptyProofs = proofs.filter(p => !!p);
|
|
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
|
}
|
|
@@ -243,11 +287,13 @@ export class CheckpointProvingState {
|
|
|
243
287
|
// `blobFields` must've been set if `startBlobAccumulator` is set (in `accumulateBlobs`).
|
|
244
288
|
const blobFields = this.blobFields!;
|
|
245
289
|
|
|
246
|
-
const { blobCommitments, blobsHash } = buildBlobHints(blobFields);
|
|
290
|
+
const { blobCommitments, blobsHash } = await buildBlobHints(blobFields);
|
|
247
291
|
|
|
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';
|
|
@@ -70,7 +76,7 @@ export class EpochProvingState {
|
|
|
70
76
|
public readonly epochNumber: EpochNumber,
|
|
71
77
|
public readonly totalNumCheckpoints: number,
|
|
72
78
|
private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
|
|
73
|
-
private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void
|
|
79
|
+
private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
|
|
74
80
|
private completionCallback: (result: ProvingResult) => void,
|
|
75
81
|
private rejectionCallback: (reason: string) => void,
|
|
76
82
|
) {
|
|
@@ -212,6 +218,50 @@ 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
|
+
// If this is NOT the last checkpoint, get or create the hint for the next checkpoint.
|
|
258
|
+
if (i !== this.totalNumCheckpoints - 1) {
|
|
259
|
+
hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
|
|
260
|
+
checkpoint.setOutHashHintForNextCheckpoint(hint);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
215
265
|
public async setBlobAccumulators() {
|
|
216
266
|
let previousAccumulator = this.startBlobAccumulator;
|
|
217
267
|
// Accumulate blobs as far as we can for this epoch.
|