@aztec/prover-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9badcec54
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 +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -3
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +38 -14
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -1
- package/dest/light/lightweight_checkpoint_builder.js +148 -32
- package/dest/mocks/fixtures.d.ts +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -5
- package/dest/mocks/test_context.d.ts +5 -3
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +40 -18
- package/dest/orchestrator/block-building-helpers.d.ts +6 -6
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +7 -6
- package/dest/orchestrator/block-proving-state.d.ts +8 -4
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +8 -1
- package/dest/orchestrator/checkpoint-proving-state.d.ts +22 -8
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +43 -8
- package/dest/orchestrator/epoch-proving-state.d.ts +10 -9
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +38 -2
- package/dest/orchestrator/orchestrator.d.ts +25 -8
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +568 -158
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/tx-proving-state.d.ts +6 -5
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +8 -8
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/prover-client.d.ts +6 -6
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- package/dest/prover-client/server-epoch-prover.d.ts +5 -5
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.d.ts +7 -5
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +18 -31
- package/dest/proving_broker/config.d.ts +15 -3
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +22 -5
- package/dest/proving_broker/fixtures.js +1 -1
- 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 +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- 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 +60 -18
- 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 +3 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +22 -35
- 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 +8 -6
- package/dest/proving_broker/rpc.d.ts +6 -2
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +24 -15
- 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 +5 -5
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +4 -4
- package/package.json +22 -22
- package/src/config.ts +14 -3
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +215 -45
- package/src/mocks/fixtures.ts +6 -5
- package/src/mocks/test_context.ts +36 -19
- package/src/orchestrator/block-building-helpers.ts +7 -6
- package/src/orchestrator/block-proving-state.ts +12 -2
- package/src/orchestrator/checkpoint-proving-state.ts +60 -12
- package/src/orchestrator/epoch-proving-state.ts +66 -13
- package/src/orchestrator/orchestrator.ts +173 -147
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +10 -14
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +33 -24
- package/src/prover-client/server-epoch-prover.ts +4 -4
- package/src/proving_broker/broker_prover_facade.ts +26 -36
- package/src/proving_broker/config.ts +25 -3
- package/src/proving_broker/fixtures.ts +1 -1
- 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 +6 -19
- package/src/proving_broker/proving_broker.ts +59 -13
- package/src/proving_broker/proving_broker_database/persisted.ts +15 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +23 -35
- package/src/proving_broker/proving_job_controller.ts +11 -6
- package/src/proving_broker/rpc.ts +26 -3
- package/src/test/mock_prover.ts +2 -14
- 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/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/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/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,15 +1,26 @@
|
|
|
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 CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
5
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import {
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
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';
|
|
7
9
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
8
10
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
+
import {
|
|
12
|
+
accumulateCheckpointOutHashes,
|
|
13
|
+
computeCheckpointOutHash,
|
|
14
|
+
computeInHashFromL1ToL2Messages,
|
|
15
|
+
} from '@aztec/stdlib/messaging';
|
|
16
|
+
import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
|
|
11
17
|
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
12
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
type CheckpointGlobalVariables,
|
|
20
|
+
type GlobalVariables,
|
|
21
|
+
type ProcessedTx,
|
|
22
|
+
StateReference,
|
|
23
|
+
} from '@aztec/stdlib/tx';
|
|
13
24
|
|
|
14
25
|
import {
|
|
15
26
|
buildHeaderAndBodyFromTxs,
|
|
@@ -20,31 +31,42 @@ import {
|
|
|
20
31
|
/**
|
|
21
32
|
* Builds a checkpoint and its header and the blocks in it from a set of processed tx without running any circuits.
|
|
22
33
|
*
|
|
23
|
-
* It updates the l1-to-l2 message tree when starting a new checkpoint,
|
|
24
|
-
*
|
|
34
|
+
* It updates the l1-to-l2 message tree when starting a new checkpoint, and then updates the archive tree when each block is added.
|
|
35
|
+
* Finally completes the checkpoint by computing its header.
|
|
25
36
|
*/
|
|
26
37
|
export class LightweightCheckpointBuilder {
|
|
27
|
-
private readonly logger
|
|
38
|
+
private readonly logger: Logger;
|
|
39
|
+
|
|
28
40
|
private lastArchives: AppendOnlyTreeSnapshot[] = [];
|
|
29
41
|
private spongeBlob: SpongeBlob;
|
|
30
|
-
private blocks:
|
|
42
|
+
private blocks: L2Block[] = [];
|
|
31
43
|
private blobFields: Fr[] = [];
|
|
32
44
|
|
|
33
45
|
constructor(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
public readonly checkpointNumber: CheckpointNumber,
|
|
47
|
+
public readonly constants: CheckpointGlobalVariables,
|
|
48
|
+
public feeAssetPriceModifier: bigint,
|
|
49
|
+
public readonly l1ToL2Messages: Fr[],
|
|
50
|
+
private readonly previousCheckpointOutHashes: Fr[],
|
|
51
|
+
public readonly db: MerkleTreeWriteOperations,
|
|
52
|
+
bindings?: LoggerBindings,
|
|
38
53
|
) {
|
|
54
|
+
this.logger = createLogger('checkpoint-builder', {
|
|
55
|
+
...bindings,
|
|
56
|
+
instanceId: `checkpoint-${checkpointNumber}`,
|
|
57
|
+
});
|
|
39
58
|
this.spongeBlob = SpongeBlob.init();
|
|
40
|
-
this.logger.debug('Starting new checkpoint', { constants
|
|
59
|
+
this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages, feeAssetPriceModifier });
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
static async startNewCheckpoint(
|
|
44
|
-
checkpointNumber:
|
|
45
|
-
constants:
|
|
63
|
+
checkpointNumber: CheckpointNumber,
|
|
64
|
+
constants: CheckpointGlobalVariables,
|
|
46
65
|
l1ToL2Messages: Fr[],
|
|
66
|
+
previousCheckpointOutHashes: Fr[],
|
|
47
67
|
db: MerkleTreeWriteOperations,
|
|
68
|
+
bindings?: LoggerBindings,
|
|
69
|
+
feeAssetPriceModifier: bigint = 0n,
|
|
48
70
|
): Promise<LightweightCheckpointBuilder> {
|
|
49
71
|
// Insert l1-to-l2 messages into the tree.
|
|
50
72
|
await db.appendLeaves(
|
|
@@ -52,38 +74,165 @@ export class LightweightCheckpointBuilder {
|
|
|
52
74
|
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
53
75
|
);
|
|
54
76
|
|
|
55
|
-
return new LightweightCheckpointBuilder(
|
|
77
|
+
return new LightweightCheckpointBuilder(
|
|
78
|
+
checkpointNumber,
|
|
79
|
+
constants,
|
|
80
|
+
feeAssetPriceModifier,
|
|
81
|
+
l1ToL2Messages,
|
|
82
|
+
previousCheckpointOutHashes,
|
|
83
|
+
db,
|
|
84
|
+
bindings,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Resumes building a checkpoint from existing blocks. This is used for validator re-execution
|
|
90
|
+
* where blocks have already been built and their effects are already in the database.
|
|
91
|
+
* Unlike startNewCheckpoint, this does NOT append l1ToL2Messages to the tree since they
|
|
92
|
+
* were already added when the blocks were originally built.
|
|
93
|
+
*/
|
|
94
|
+
static async resumeCheckpoint(
|
|
95
|
+
checkpointNumber: CheckpointNumber,
|
|
96
|
+
constants: CheckpointGlobalVariables,
|
|
97
|
+
feeAssetPriceModifier: bigint,
|
|
98
|
+
l1ToL2Messages: Fr[],
|
|
99
|
+
previousCheckpointOutHashes: Fr[],
|
|
100
|
+
db: MerkleTreeWriteOperations,
|
|
101
|
+
existingBlocks: L2Block[],
|
|
102
|
+
bindings?: LoggerBindings,
|
|
103
|
+
): Promise<LightweightCheckpointBuilder> {
|
|
104
|
+
const builder = new LightweightCheckpointBuilder(
|
|
105
|
+
checkpointNumber,
|
|
106
|
+
constants,
|
|
107
|
+
feeAssetPriceModifier,
|
|
108
|
+
l1ToL2Messages,
|
|
109
|
+
previousCheckpointOutHashes,
|
|
110
|
+
db,
|
|
111
|
+
bindings,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
builder.logger.debug('Resuming checkpoint from existing blocks', {
|
|
115
|
+
checkpointNumber,
|
|
116
|
+
numExistingBlocks: existingBlocks.length,
|
|
117
|
+
blockNumbers: existingBlocks.map(b => b.header.getBlockNumber()),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Validate block order and consistency
|
|
121
|
+
for (let i = 1; i < existingBlocks.length; i++) {
|
|
122
|
+
const prev = existingBlocks[i - 1];
|
|
123
|
+
const curr = existingBlocks[i];
|
|
124
|
+
if (curr.number !== prev.number + 1) {
|
|
125
|
+
throw new Error(`Non-sequential block numbers in resumeCheckpoint: ${prev.number} -> ${curr.number}`);
|
|
126
|
+
}
|
|
127
|
+
if (!prev.archive.root.equals(curr.header.lastArchive.root)) {
|
|
128
|
+
throw new Error(`Archive root mismatch between blocks ${prev.number} and ${curr.number}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < existingBlocks.length; i++) {
|
|
133
|
+
const block = existingBlocks[i];
|
|
134
|
+
const isFirstBlock = i === 0;
|
|
135
|
+
|
|
136
|
+
if (isFirstBlock) {
|
|
137
|
+
builder.lastArchives.push(block.header.lastArchive);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
builder.lastArchives.push(block.archive);
|
|
141
|
+
|
|
142
|
+
const blockBlobFields = block.toBlobFields();
|
|
143
|
+
await builder.spongeBlob.absorb(blockBlobFields);
|
|
144
|
+
builder.blobFields.push(...blockBlobFields);
|
|
145
|
+
|
|
146
|
+
builder.blocks.push(block);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return builder;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Returns how many blocks have been added to this checkpoint so far */
|
|
153
|
+
public getBlockCount() {
|
|
154
|
+
return this.blocks.length;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public getBlocks() {
|
|
158
|
+
return this.blocks;
|
|
56
159
|
}
|
|
57
160
|
|
|
58
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
|
|
163
|
+
* this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
|
|
164
|
+
*/
|
|
165
|
+
public async addBlock(
|
|
166
|
+
globalVariables: GlobalVariables,
|
|
167
|
+
txs: ProcessedTx[],
|
|
168
|
+
opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
|
|
169
|
+
): Promise<{ block: L2Block; timings: Record<string, number> }> {
|
|
170
|
+
const timings: Record<string, number> = {};
|
|
59
171
|
const isFirstBlock = this.blocks.length === 0;
|
|
172
|
+
|
|
173
|
+
// Empty blocks are only allowed as the first block in a checkpoint
|
|
174
|
+
if (!isFirstBlock && txs.length === 0) {
|
|
175
|
+
throw new Error('Cannot add empty block that is not the first block in the checkpoint.');
|
|
176
|
+
}
|
|
177
|
+
|
|
60
178
|
if (isFirstBlock) {
|
|
61
|
-
|
|
179
|
+
const [msGetInitialArchive, initialArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
|
|
180
|
+
this.lastArchives.push(initialArchive);
|
|
181
|
+
timings.getInitialArchive = msGetInitialArchive;
|
|
62
182
|
}
|
|
63
183
|
|
|
64
184
|
const lastArchive = this.lastArchives.at(-1)!;
|
|
65
185
|
|
|
66
|
-
|
|
67
|
-
|
|
186
|
+
if (opts.insertTxsEffects) {
|
|
187
|
+
this.logger.debug(
|
|
188
|
+
`Inserting side effects for ${txs.length} txs for block ${globalVariables.blockNumber} into db`,
|
|
189
|
+
{ txs: txs.map(tx => tx.hash.toString()) },
|
|
190
|
+
);
|
|
191
|
+
let msInsertSideEffects = 0;
|
|
192
|
+
for (const tx of txs) {
|
|
193
|
+
const [ms] = await elapsed(() => insertSideEffects(tx, this.db));
|
|
194
|
+
msInsertSideEffects += ms;
|
|
195
|
+
}
|
|
196
|
+
timings.insertSideEffects = msInsertSideEffects;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const [msGetEndState, endState] = await elapsed(() => this.db.getStateReference());
|
|
200
|
+
timings.getEndState = msGetEndState;
|
|
201
|
+
|
|
202
|
+
if (opts.expectedEndState && !endState.equals(opts.expectedEndState)) {
|
|
203
|
+
this.logger.error('End state after processing txs does not match expected end state', {
|
|
204
|
+
globalVariables: globalVariables.toInspect(),
|
|
205
|
+
expectedEndState: opts.expectedEndState.toInspect(),
|
|
206
|
+
actualEndState: endState.toInspect(),
|
|
207
|
+
});
|
|
208
|
+
throw new Error(`End state does not match expected end state when building block ${globalVariables.blockNumber}`);
|
|
68
209
|
}
|
|
69
210
|
|
|
70
|
-
const { header, body, blockBlobFields } = await
|
|
71
|
-
txs,
|
|
72
|
-
lastArchive,
|
|
73
|
-
endState,
|
|
74
|
-
globalVariables,
|
|
75
|
-
this.spongeBlob,
|
|
76
|
-
isFirstBlock,
|
|
211
|
+
const [msBuildHeaderAndBody, { header, body, blockBlobFields }] = await elapsed(() =>
|
|
212
|
+
buildHeaderAndBodyFromTxs(txs, lastArchive, endState, globalVariables, this.spongeBlob, isFirstBlock),
|
|
77
213
|
);
|
|
214
|
+
timings.buildHeaderAndBody = msBuildHeaderAndBody;
|
|
215
|
+
|
|
216
|
+
header.state.validate();
|
|
78
217
|
|
|
79
218
|
await this.db.updateArchive(header);
|
|
80
|
-
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
|
|
219
|
+
const [msUpdateArchive, newArchive] = await elapsed(() => getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
|
|
220
|
+
timings.updateArchive = msUpdateArchive;
|
|
81
221
|
this.lastArchives.push(newArchive);
|
|
82
222
|
|
|
83
|
-
const
|
|
223
|
+
const expectedNextLeafIndex = Number(globalVariables.blockNumber) + 1;
|
|
224
|
+
if (newArchive.nextAvailableLeafIndex !== expectedNextLeafIndex) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Archive tree next leaf index mismatch after building block ${globalVariables.blockNumber} (expected ${expectedNextLeafIndex} but got ${newArchive.nextAvailableLeafIndex})`,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(this.blocks.length);
|
|
231
|
+
const block = new L2Block(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
|
|
84
232
|
this.blocks.push(block);
|
|
85
233
|
|
|
86
|
-
await this.spongeBlob.absorb(blockBlobFields);
|
|
234
|
+
const [msSpongeAbsorb] = await elapsed(() => this.spongeBlob.absorb(blockBlobFields));
|
|
235
|
+
timings.spongeAbsorb = msSpongeAbsorb;
|
|
87
236
|
this.blobFields.push(...blockBlobFields);
|
|
88
237
|
|
|
89
238
|
this.logger.debug(`Built block ${header.getBlockNumber()}`, {
|
|
@@ -94,12 +243,12 @@ export class LightweightCheckpointBuilder {
|
|
|
94
243
|
txs: block.body.txEffects.map(tx => tx.txHash.toString()),
|
|
95
244
|
});
|
|
96
245
|
|
|
97
|
-
return block;
|
|
246
|
+
return { block, timings };
|
|
98
247
|
}
|
|
99
248
|
|
|
100
249
|
async completeCheckpoint(): Promise<Checkpoint> {
|
|
101
250
|
if (!this.blocks.length) {
|
|
102
|
-
throw new Error('
|
|
251
|
+
throw new Error('Cannot complete a checkpoint with no blocks');
|
|
103
252
|
}
|
|
104
253
|
|
|
105
254
|
const numBlobFields = this.blobFields.length + 1; // +1 for the checkpoint end marker.
|
|
@@ -111,32 +260,53 @@ export class LightweightCheckpointBuilder {
|
|
|
111
260
|
|
|
112
261
|
const newArchive = this.lastArchives[this.lastArchives.length - 1];
|
|
113
262
|
|
|
114
|
-
const blobs = getBlobsPerL1Block(this.blobFields);
|
|
263
|
+
const blobs = await getBlobsPerL1Block(this.blobFields);
|
|
115
264
|
const blobsHash = computeBlobsHashFromBlobs(blobs);
|
|
116
265
|
|
|
117
266
|
const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
|
|
118
267
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
268
|
+
const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
|
|
269
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
270
|
+
blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
271
|
+
);
|
|
272
|
+
const epochOutHash = accumulateCheckpointOutHashes([...this.previousCheckpointOutHashes, checkpointOutHash]);
|
|
122
273
|
|
|
123
|
-
//
|
|
274
|
+
// All blocks in the checkpoint have the same timestamp
|
|
124
275
|
const timestamp = blocks[blocks.length - 1].timestamp;
|
|
125
276
|
|
|
126
277
|
const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
|
|
127
278
|
|
|
128
279
|
const header = CheckpointHeader.from({
|
|
129
280
|
lastArchiveRoot: this.lastArchives[0].root,
|
|
281
|
+
blobsHash,
|
|
282
|
+
inHash,
|
|
283
|
+
epochOutHash,
|
|
130
284
|
blockHeadersHash,
|
|
131
|
-
|
|
132
|
-
slotNumber: constants.slotNumber,
|
|
285
|
+
slotNumber,
|
|
133
286
|
timestamp,
|
|
134
|
-
coinbase
|
|
135
|
-
feeRecipient
|
|
136
|
-
gasFees
|
|
287
|
+
coinbase,
|
|
288
|
+
feeRecipient,
|
|
289
|
+
gasFees,
|
|
137
290
|
totalManaUsed,
|
|
138
291
|
});
|
|
139
292
|
|
|
140
|
-
return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
|
|
293
|
+
return new Checkpoint(newArchive, header, blocks, this.checkpointNumber, this.feeAssetPriceModifier);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
clone() {
|
|
297
|
+
const clone = new LightweightCheckpointBuilder(
|
|
298
|
+
this.checkpointNumber,
|
|
299
|
+
this.constants,
|
|
300
|
+
this.feeAssetPriceModifier,
|
|
301
|
+
[...this.l1ToL2Messages],
|
|
302
|
+
[...this.previousCheckpointOutHashes],
|
|
303
|
+
this.db,
|
|
304
|
+
this.logger.getBindings(),
|
|
305
|
+
);
|
|
306
|
+
clone.lastArchives = [...this.lastArchives];
|
|
307
|
+
clone.spongeBlob = this.spongeBlob.clone();
|
|
308
|
+
clone.blocks = [...this.blocks];
|
|
309
|
+
clone.blobFields = [...this.blobFields];
|
|
310
|
+
return clone;
|
|
141
311
|
}
|
|
142
312
|
}
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { randomBytes } from '@aztec/foundation/crypto';
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import type { Logger } from '@aztec/foundation/log';
|
|
6
6
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
7
7
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
@@ -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
|
}
|
|
@@ -93,7 +94,7 @@ export const makeGlobals = (
|
|
|
93
94
|
return GlobalVariables.from({
|
|
94
95
|
chainId: checkpointConstants.chainId,
|
|
95
96
|
version: checkpointConstants.version,
|
|
96
|
-
blockNumber /** block number */,
|
|
97
|
+
blockNumber: BlockNumber(blockNumber) /** block number */,
|
|
97
98
|
slotNumber: SlotNumber(slotNumber) /** slot number */,
|
|
98
99
|
timestamp: BigInt(blockNumber * 123) /** block number * 123 as pseudo-timestamp for testing */,
|
|
99
100
|
coinbase: checkpointConstants.coinbase,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
2
|
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
3
3
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
4
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import { padArrayEnd, times, timesAsync } from '@aztec/foundation/collection';
|
|
5
|
-
import { Fr } from '@aztec/foundation/
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
7
8
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
8
9
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
StateReference,
|
|
24
25
|
TreeSnapshots,
|
|
25
26
|
} from '@aztec/stdlib/tx';
|
|
27
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
26
28
|
import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
|
|
27
29
|
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
28
30
|
|
|
@@ -43,7 +45,9 @@ import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobal
|
|
|
43
45
|
export class TestContext {
|
|
44
46
|
private headers: Map<number, BlockHeader> = new Map();
|
|
45
47
|
private checkpoints: Checkpoint[] = [];
|
|
48
|
+
private checkpointOutHashes: Fr[] = [];
|
|
46
49
|
private nextCheckpointIndex = 0;
|
|
50
|
+
private nextCheckpointNumber = CheckpointNumber(1);
|
|
47
51
|
private nextBlockNumber = 1;
|
|
48
52
|
private epochNumber = 1;
|
|
49
53
|
private feePayerBalance: Fr;
|
|
@@ -81,14 +85,13 @@ export class TestContext {
|
|
|
81
85
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
82
86
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
83
87
|
const feePayerSlot = await computeFeePayerBalanceLeafSlot(feePayer);
|
|
84
|
-
const
|
|
88
|
+
const genesis: GenesisData = {
|
|
89
|
+
prefilledPublicData: [new PublicDataTreeLeaf(feePayerSlot, initialFeePayerBalance)],
|
|
90
|
+
genesisTimestamp: 0n,
|
|
91
|
+
};
|
|
85
92
|
|
|
86
93
|
// Separated dbs for public processor and prover - see public_processor for context
|
|
87
|
-
const ws = await NativeWorldStateService.tmp(
|
|
88
|
-
/*rollupAddress=*/ undefined,
|
|
89
|
-
/*cleanupTmpDir=*/ true,
|
|
90
|
-
prefilledPublicData,
|
|
91
|
-
);
|
|
94
|
+
const ws = await NativeWorldStateService.tmp(/*rollupAddress=*/ undefined, /*cleanupTmpDir=*/ true, genesis);
|
|
92
95
|
|
|
93
96
|
let localProver: ServerCircuitProver;
|
|
94
97
|
const config = await getEnvironmentConfig(logger);
|
|
@@ -101,8 +104,10 @@ export class TestContext {
|
|
|
101
104
|
bbBinaryPath: config.expectedBBPath,
|
|
102
105
|
bbWorkingDirectory: config.bbWorkingDirectory,
|
|
103
106
|
bbSkipCleanup: config.bbSkipCleanup,
|
|
104
|
-
numConcurrentIVCVerifiers:
|
|
107
|
+
numConcurrentIVCVerifiers: 8,
|
|
105
108
|
bbIVCConcurrency: 1,
|
|
109
|
+
bbChonkVerifyMaxBatch: 16,
|
|
110
|
+
bbChonkVerifyConcurrency: 6,
|
|
106
111
|
};
|
|
107
112
|
localProver = await createProver(bbConfig);
|
|
108
113
|
}
|
|
@@ -113,7 +118,7 @@ export class TestContext {
|
|
|
113
118
|
|
|
114
119
|
const broker = new TestBroker(proverCount, localProver);
|
|
115
120
|
const facade = new BrokerCircuitProverFacade(broker);
|
|
116
|
-
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
|
|
121
|
+
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO, false, 10);
|
|
117
122
|
|
|
118
123
|
await broker.start();
|
|
119
124
|
facade.start();
|
|
@@ -149,6 +154,7 @@ export class TestContext {
|
|
|
149
154
|
|
|
150
155
|
public startNewEpoch() {
|
|
151
156
|
this.checkpoints = [];
|
|
157
|
+
this.checkpointOutHashes = [];
|
|
152
158
|
this.nextCheckpointIndex = 0;
|
|
153
159
|
this.epochNumber++;
|
|
154
160
|
}
|
|
@@ -186,7 +192,8 @@ export class TestContext {
|
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
const checkpointIndex = this.nextCheckpointIndex++;
|
|
189
|
-
const checkpointNumber =
|
|
195
|
+
const checkpointNumber = this.nextCheckpointNumber;
|
|
196
|
+
this.nextCheckpointNumber++;
|
|
190
197
|
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
191
198
|
|
|
192
199
|
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
@@ -202,7 +209,9 @@ export class TestContext {
|
|
|
202
209
|
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
|
|
203
210
|
|
|
204
211
|
const startBlockNumber = this.nextBlockNumber;
|
|
205
|
-
const previousBlockHeader = this.getBlockHeader(startBlockNumber - 1);
|
|
212
|
+
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
213
|
+
// All blocks in the same slot/checkpoint share the same timestamp.
|
|
214
|
+
const timestamp = BigInt(slotNumber * 26);
|
|
206
215
|
|
|
207
216
|
// Build global variables.
|
|
208
217
|
const blockGlobalVariables = times(numBlocks, i =>
|
|
@@ -210,6 +219,7 @@ export class TestContext {
|
|
|
210
219
|
coinbase: constants.coinbase,
|
|
211
220
|
feeRecipient: constants.feeRecipient,
|
|
212
221
|
gasFees: constants.gasFees,
|
|
222
|
+
timestamp,
|
|
213
223
|
}),
|
|
214
224
|
);
|
|
215
225
|
this.nextBlockNumber += numBlocks;
|
|
@@ -239,33 +249,38 @@ export class TestContext {
|
|
|
239
249
|
});
|
|
240
250
|
|
|
241
251
|
const cleanFork = await this.worldState.fork();
|
|
252
|
+
const previousCheckpointOutHashes = this.checkpointOutHashes;
|
|
242
253
|
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
243
254
|
checkpointNumber,
|
|
244
|
-
constants,
|
|
255
|
+
{ ...constants, timestamp },
|
|
245
256
|
l1ToL2Messages,
|
|
257
|
+
previousCheckpointOutHashes,
|
|
246
258
|
cleanFork,
|
|
247
259
|
);
|
|
248
260
|
|
|
249
261
|
// Add tx effects to db and build block headers.
|
|
250
262
|
const blocks = [];
|
|
251
263
|
for (let i = 0; i < numBlocks; i++) {
|
|
252
|
-
const isFirstBlock = i === 0;
|
|
253
264
|
const txs = blockTxs[i];
|
|
254
265
|
const state = blockEndStates[i];
|
|
255
266
|
|
|
256
|
-
const block = await builder.addBlock(blockGlobalVariables[i],
|
|
267
|
+
const { block } = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
268
|
+
expectedEndState: state,
|
|
269
|
+
insertTxsEffects: true,
|
|
270
|
+
});
|
|
257
271
|
|
|
258
272
|
const header = block.header;
|
|
259
273
|
this.headers.set(block.number, header);
|
|
260
274
|
|
|
261
|
-
const blockMsgs =
|
|
262
|
-
await this.worldState.handleL2BlockAndMessages(block, blockMsgs
|
|
275
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
276
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
263
277
|
|
|
264
278
|
blocks.push({ header, txs });
|
|
265
279
|
}
|
|
266
280
|
|
|
267
281
|
const checkpoint = await builder.completeCheckpoint();
|
|
268
282
|
this.checkpoints.push(checkpoint);
|
|
283
|
+
this.checkpointOutHashes.push(checkpoint.getCheckpointOutHash());
|
|
269
284
|
|
|
270
285
|
return {
|
|
271
286
|
constants,
|
|
@@ -296,11 +311,13 @@ export class TestContext {
|
|
|
296
311
|
return tx;
|
|
297
312
|
}
|
|
298
313
|
|
|
299
|
-
private getBlockHeader(blockNumber:
|
|
300
|
-
if (blockNumber > 0 && blockNumber >= this.nextBlockNumber) {
|
|
314
|
+
private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
|
|
315
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
301
316
|
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
302
317
|
}
|
|
303
|
-
return blockNumber === 0
|
|
318
|
+
return Number(blockNumber) === 0
|
|
319
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
320
|
+
: this.headers.get(Number(blockNumber))!;
|
|
304
321
|
}
|
|
305
322
|
|
|
306
323
|
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
21
21
|
} from '@aztec/constants';
|
|
22
22
|
import { makeTuple } from '@aztec/foundation/array';
|
|
23
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
23
24
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
24
|
-
import { Fr } from '@aztec/foundation/
|
|
25
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
25
26
|
import { type Bufferable, assertLength, toFriendlyJSON } from '@aztec/foundation/serialize';
|
|
26
27
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
27
28
|
import { getVkData } from '@aztec/noir-protocol-circuits-types/server/vks';
|
|
@@ -98,7 +99,7 @@ export const insertSideEffectsAndBuildBaseRollupHints = runInSpan(
|
|
|
98
99
|
|
|
99
100
|
const blockHash = await tx.data.constants.anchorBlockHeader.hash();
|
|
100
101
|
const anchorBlockArchiveSiblingPath = (
|
|
101
|
-
await getMembershipWitnessFor(blockHash, MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
|
|
102
|
+
await getMembershipWitnessFor(blockHash.toFr(), MerkleTreeId.ARCHIVE, ARCHIVE_HEIGHT, db)
|
|
102
103
|
).siblingPath;
|
|
103
104
|
|
|
104
105
|
const contractClassLogsFields = makeTuple(
|
|
@@ -252,8 +253,8 @@ export function getPublicChonkVerifierPrivateInputsFromTx(tx: Tx | ProcessedTx,
|
|
|
252
253
|
// Build "hints" as the private inputs for the checkpoint root rollup circuit.
|
|
253
254
|
// The `blobCommitments` will be accumulated and checked in the root rollup against the `finalBlobChallenges`.
|
|
254
255
|
// The `blobsHash` will be validated on L1 against the submitted blob data.
|
|
255
|
-
export const buildBlobHints = (blobFields: Fr[]) => {
|
|
256
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
256
|
+
export const buildBlobHints = async (blobFields: Fr[]) => {
|
|
257
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
257
258
|
const blobCommitments = getBlobCommitmentsFromBlobs(blobs);
|
|
258
259
|
const blobsHash = computeBlobsHashFromBlobs(blobs);
|
|
259
260
|
return { blobCommitments, blobs, blobsHash };
|
|
@@ -280,8 +281,8 @@ export const buildHeaderFromCircuitOutputs = runInSpan(
|
|
|
280
281
|
const globalVariables = GlobalVariables.from({
|
|
281
282
|
chainId: constants.chainId,
|
|
282
283
|
version: constants.version,
|
|
283
|
-
blockNumber: blockRootRollupOutput.previousArchive.nextAvailableLeafIndex,
|
|
284
|
-
timestamp: blockRootRollupOutput.
|
|
284
|
+
blockNumber: BlockNumber(blockRootRollupOutput.previousArchive.nextAvailableLeafIndex),
|
|
285
|
+
timestamp: blockRootRollupOutput.timestamp,
|
|
285
286
|
slotNumber: constants.slotNumber,
|
|
286
287
|
coinbase: constants.coinbase,
|
|
287
288
|
feeRecipient: constants.feeRecipient,
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
7
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
-
import {
|
|
9
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import { type Tuple, assertLength } from '@aztec/foundation/serialize';
|
|
11
12
|
import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
12
13
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
@@ -54,6 +55,7 @@ export class BlockProvingState {
|
|
|
54
55
|
| ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
55
56
|
| undefined;
|
|
56
57
|
private builtBlockHeader: BlockHeader | undefined;
|
|
58
|
+
private builtArchive: AppendOnlyTreeSnapshot | undefined;
|
|
57
59
|
private endState: StateReference | undefined;
|
|
58
60
|
private endSpongeBlob: SpongeBlob | undefined;
|
|
59
61
|
private txs: TxProvingState[] = [];
|
|
@@ -62,7 +64,7 @@ export class BlockProvingState {
|
|
|
62
64
|
|
|
63
65
|
constructor(
|
|
64
66
|
public readonly index: number,
|
|
65
|
-
public readonly blockNumber:
|
|
67
|
+
public readonly blockNumber: BlockNumber,
|
|
66
68
|
public readonly totalNumTxs: number,
|
|
67
69
|
private readonly constants: CheckpointConstantData,
|
|
68
70
|
private readonly timestamp: UInt64,
|
|
@@ -231,6 +233,14 @@ export class BlockProvingState {
|
|
|
231
233
|
return this.builtBlockHeader;
|
|
232
234
|
}
|
|
233
235
|
|
|
236
|
+
public setBuiltArchive(archive: AppendOnlyTreeSnapshot) {
|
|
237
|
+
this.builtArchive = archive;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public getBuiltArchive() {
|
|
241
|
+
return this.builtArchive;
|
|
242
|
+
}
|
|
243
|
+
|
|
234
244
|
public getStartSpongeBlob() {
|
|
235
245
|
return this.startSpongeBlob;
|
|
236
246
|
}
|