@aztec/prover-client 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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/block-factory/index.d.ts +1 -1
- package/dest/block-factory/light.d.ts +5 -3
- package/dest/block-factory/light.d.ts.map +1 -1
- package/dest/block-factory/light.js +32 -11
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -2
- package/dest/index.d.ts +1 -1
- 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 +36 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +147 -0
- package/dest/mocks/fixtures.d.ts +5 -5
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +33 -15
- package/dest/mocks/test_context.d.ts +38 -33
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +133 -82
- package/dest/orchestrator/block-building-helpers.d.ts +35 -35
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +151 -187
- package/dest/orchestrator/block-proving-state.d.ts +68 -55
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +273 -185
- package/dest/orchestrator/checkpoint-proving-state.d.ts +63 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +210 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +38 -31
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +128 -84
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +35 -34
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +777 -292
- 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 +0 -9
- package/dest/orchestrator/tx-proving-state.d.ts +12 -10
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +23 -29
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- 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 +1 -1
- package/dest/prover-client/server-epoch-prover.d.ts +13 -11
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +9 -9
- package/dest/proving_broker/broker_prover_facade.d.ts +23 -18
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +42 -33
- package/dest/proving_broker/config.d.ts +18 -14
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +12 -6
- package/dest/proving_broker/factory.d.ts +1 -1
- package/dest/proving_broker/factory.js +1 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +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 +2 -2
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +35 -29
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +397 -8
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -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_job_controller.d.ts +3 -2
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +40 -21
- package/dest/proving_broker/rpc.d.ts +4 -4
- 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 +23 -19
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +36 -21
- package/package.json +21 -19
- package/src/block-factory/light.ts +40 -17
- package/src/config.ts +2 -2
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +198 -0
- package/src/mocks/fixtures.ts +41 -36
- package/src/mocks/test_context.ts +196 -114
- package/src/orchestrator/block-building-helpers.ts +233 -313
- package/src/orchestrator/block-proving-state.ts +315 -247
- package/src/orchestrator/checkpoint-proving-state.ts +303 -0
- package/src/orchestrator/epoch-proving-state.ts +176 -129
- package/src/orchestrator/orchestrator.ts +558 -348
- package/src/orchestrator/orchestrator_metrics.ts +1 -20
- package/src/orchestrator/tx-proving-state.ts +47 -55
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +4 -11
- package/src/prover-client/server-epoch-prover.ts +30 -21
- package/src/proving_broker/broker_prover_facade.ts +175 -112
- package/src/proving_broker/config.ts +14 -7
- package/src/proving_broker/factory.ts +1 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proving_agent.ts +1 -17
- package/src/proving_broker/proving_broker.ts +42 -27
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +25 -10
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +42 -22
- package/src/test/mock_prover.ts +143 -66
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- 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/bin/get-proof-inputs.ts +0 -59
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,52 +1,65 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
|
+
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
2
3
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { padArrayEnd, times, timesAsync } from '@aztec/foundation/collection';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
6
|
-
import {
|
|
8
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
7
9
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
8
|
-
import {
|
|
10
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
9
11
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
10
|
-
import { SimpleContractDataSource } from '@aztec/simulator/public/fixtures';
|
|
11
|
-
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
12
12
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
13
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
-
import { EthAddress
|
|
15
|
-
import type {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
14
|
+
import { EthAddress } from '@aztec/stdlib/block';
|
|
15
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
16
|
+
import type { MerkleTreeWriteOperations, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
17
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
18
|
+
import { mockProcessedTx } from '@aztec/stdlib/testing';
|
|
19
|
+
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
20
|
+
import {
|
|
21
|
+
type BlockHeader,
|
|
22
|
+
type GlobalVariables,
|
|
23
|
+
type ProcessedTx,
|
|
24
|
+
StateReference,
|
|
25
|
+
TreeSnapshots,
|
|
26
|
+
} from '@aztec/stdlib/tx';
|
|
19
27
|
import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
|
|
20
28
|
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
21
29
|
|
|
22
30
|
import { promises as fs } from 'fs';
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
import { LightweightCheckpointBuilder } from '../light/lightweight_checkpoint_builder.js';
|
|
33
|
+
import {
|
|
34
|
+
buildFinalBlobChallenges,
|
|
35
|
+
getTreeSnapshot,
|
|
36
|
+
insertSideEffects,
|
|
37
|
+
} from '../orchestrator/block-building-helpers.js';
|
|
38
|
+
import type { BlockProvingState } from '../orchestrator/block-proving-state.js';
|
|
29
39
|
import { ProvingOrchestrator } from '../orchestrator/index.js';
|
|
30
40
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
31
41
|
import { TestBroker } from '../test/mock_prover.js';
|
|
32
|
-
import { getEnvironmentConfig, getSimulator,
|
|
42
|
+
import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobals } from './fixtures.js';
|
|
33
43
|
|
|
34
44
|
export class TestContext {
|
|
35
45
|
private headers: Map<number, BlockHeader> = new Map();
|
|
46
|
+
private checkpoints: Checkpoint[] = [];
|
|
47
|
+
private nextCheckpointIndex = 0;
|
|
48
|
+
private nextCheckpointNumber = CheckpointNumber(1);
|
|
49
|
+
private nextBlockNumber = 1;
|
|
50
|
+
private epochNumber = 1;
|
|
36
51
|
private feePayerBalance: Fr;
|
|
37
52
|
|
|
38
53
|
constructor(
|
|
39
54
|
public worldState: MerkleTreeAdminDatabase,
|
|
40
|
-
public globalVariables: GlobalVariables,
|
|
41
55
|
public prover: ServerCircuitProver,
|
|
42
56
|
public broker: TestBroker,
|
|
43
57
|
public brokerProverFacade: BrokerCircuitProverFacade,
|
|
44
58
|
public orchestrator: TestProvingOrchestrator,
|
|
45
|
-
|
|
46
|
-
public feePayer: AztecAddress,
|
|
59
|
+
private feePayer: AztecAddress,
|
|
47
60
|
initialFeePayerBalance: Fr,
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
private directoriesToCleanup: string[],
|
|
62
|
+
private logger: Logger,
|
|
50
63
|
) {
|
|
51
64
|
this.feePayerBalance = initialFeePayerBalance;
|
|
52
65
|
}
|
|
@@ -60,15 +73,12 @@ export class TestContext {
|
|
|
60
73
|
{
|
|
61
74
|
proverCount = 4,
|
|
62
75
|
createProver = async (bbConfig: BBProverConfig) => new TestCircuitProver(await getSimulator(bbConfig, logger)),
|
|
63
|
-
blockNumber = 1,
|
|
64
76
|
}: {
|
|
65
77
|
proverCount?: number;
|
|
66
78
|
createProver?: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver>;
|
|
67
|
-
blockNumber?: number;
|
|
68
79
|
} = {},
|
|
69
80
|
) {
|
|
70
81
|
const directoriesToCleanup: string[] = [];
|
|
71
|
-
const globalVariables = makeGlobals(blockNumber);
|
|
72
82
|
|
|
73
83
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
74
84
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
@@ -112,12 +122,10 @@ export class TestContext {
|
|
|
112
122
|
|
|
113
123
|
return new this(
|
|
114
124
|
ws,
|
|
115
|
-
globalVariables,
|
|
116
125
|
localProver,
|
|
117
126
|
broker,
|
|
118
127
|
facade,
|
|
119
128
|
orchestrator,
|
|
120
|
-
blockNumber,
|
|
121
129
|
feePayer,
|
|
122
130
|
initialFeePayerBalance,
|
|
123
131
|
directoriesToCleanup,
|
|
@@ -129,20 +137,6 @@ export class TestContext {
|
|
|
129
137
|
return this.worldState.fork();
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
public getBlockHeader(blockNumber: 0): BlockHeader;
|
|
133
|
-
public getBlockHeader(blockNumber: number): BlockHeader | undefined;
|
|
134
|
-
public getBlockHeader(blockNumber = 0) {
|
|
135
|
-
return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public setBlockHeader(header: BlockHeader, blockNumber: number) {
|
|
139
|
-
this.headers.set(blockNumber, header);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public getPreviousBlockHeader(currentBlockNumber = this.blockNumber): BlockHeader {
|
|
143
|
-
return this.getBlockHeader(currentBlockNumber - 1)!;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
140
|
async cleanup() {
|
|
147
141
|
await this.brokerProverFacade.stop();
|
|
148
142
|
await this.broker.stop();
|
|
@@ -155,93 +149,179 @@ export class TestContext {
|
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
header,
|
|
163
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
164
|
-
protocolContractTreeRoot,
|
|
165
|
-
globalVariables: this.globalVariables,
|
|
166
|
-
feePayer: this.feePayer,
|
|
167
|
-
...opts,
|
|
168
|
-
});
|
|
169
|
-
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
170
|
-
if (opts?.privateOnly) {
|
|
171
|
-
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
172
|
-
tx.txEffect.publicDataWrites[0] = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
173
|
-
}
|
|
174
|
-
return tx;
|
|
152
|
+
public startNewEpoch() {
|
|
153
|
+
this.checkpoints = [];
|
|
154
|
+
this.nextCheckpointIndex = 0;
|
|
155
|
+
this.epochNumber++;
|
|
175
156
|
}
|
|
176
157
|
|
|
177
|
-
|
|
178
|
-
public
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
blockNumOrGlobals: GlobalVariables | number = this.globalVariables,
|
|
182
|
-
makeProcessedTxOpts: (index: number) => Partial<Parameters<typeof makeBloatedProcessedTx>[0]> = () => ({}),
|
|
183
|
-
) {
|
|
184
|
-
const globalVariables = typeof blockNumOrGlobals === 'number' ? makeGlobals(blockNumOrGlobals) : blockNumOrGlobals;
|
|
185
|
-
const blockNum = globalVariables.blockNumber;
|
|
186
|
-
const db = await this.worldState.fork();
|
|
187
|
-
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(blockNum * 100 + i));
|
|
188
|
-
const merkleTrees = await this.worldState.fork();
|
|
189
|
-
await merkleTrees.appendLeaves(
|
|
190
|
-
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
191
|
-
padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
192
|
-
);
|
|
193
|
-
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, merkleTrees);
|
|
194
|
-
const txs = await timesParallel(numTxs, i =>
|
|
195
|
-
this.makeProcessedTx({
|
|
196
|
-
seed: i + blockNum * 1000,
|
|
197
|
-
globalVariables,
|
|
198
|
-
newL1ToL2Snapshot,
|
|
199
|
-
...makeProcessedTxOpts(i),
|
|
200
|
-
}),
|
|
201
|
-
);
|
|
202
|
-
await this.setTreeRoots(txs);
|
|
158
|
+
// Return blob fields of all checkpoints in the epoch.
|
|
159
|
+
public getBlobFields() {
|
|
160
|
+
return this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
161
|
+
}
|
|
203
162
|
|
|
204
|
-
|
|
205
|
-
this.
|
|
206
|
-
await
|
|
207
|
-
return { block, txs, l1ToL2Messages };
|
|
163
|
+
public async getFinalBlobChallenges() {
|
|
164
|
+
const blobFields = this.getBlobFields();
|
|
165
|
+
return await buildFinalBlobChallenges(blobFields);
|
|
208
166
|
}
|
|
209
167
|
|
|
210
|
-
public async
|
|
211
|
-
|
|
168
|
+
public async makeCheckpoint(
|
|
169
|
+
numBlocks: number,
|
|
212
170
|
{
|
|
213
|
-
|
|
171
|
+
numTxsPerBlock = 0,
|
|
214
172
|
numL1ToL2Messages = 0,
|
|
215
|
-
|
|
173
|
+
makeProcessedTxOpts = () => ({}),
|
|
174
|
+
...constantOpts
|
|
216
175
|
}: {
|
|
217
|
-
|
|
176
|
+
numTxsPerBlock?: number | number[];
|
|
218
177
|
numL1ToL2Messages?: number;
|
|
219
|
-
|
|
220
|
-
|
|
178
|
+
makeProcessedTxOpts?: (
|
|
179
|
+
blockGlobalVariables: GlobalVariables,
|
|
180
|
+
txIndex: number,
|
|
181
|
+
) => Partial<Parameters<typeof mockProcessedTx>[0]>;
|
|
182
|
+
} & Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
221
183
|
) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
184
|
+
if (numBlocks === 0) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
'Cannot make a checkpoint with 0 blocks. Crate an empty block (numTxsPerBlock = 0) if there are no txs.',
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const checkpointIndex = this.nextCheckpointIndex++;
|
|
191
|
+
const checkpointNumber = this.nextCheckpointNumber;
|
|
192
|
+
this.nextCheckpointNumber++;
|
|
193
|
+
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
194
|
+
|
|
195
|
+
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
196
|
+
|
|
197
|
+
const fork = await this.worldState.fork();
|
|
198
|
+
|
|
199
|
+
// Build l1 to l2 messages.
|
|
200
|
+
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
201
|
+
await fork.appendLeaves(
|
|
225
202
|
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
226
|
-
padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
203
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
227
204
|
);
|
|
205
|
+
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
|
|
228
206
|
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
207
|
+
const startBlockNumber = this.nextBlockNumber;
|
|
208
|
+
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
209
|
+
// All blocks in the same slot/checkpoint share the same timestamp.
|
|
210
|
+
const timestamp = BigInt(slotNumber * 26);
|
|
211
|
+
|
|
212
|
+
// Build global variables.
|
|
213
|
+
const blockGlobalVariables = times(numBlocks, i =>
|
|
214
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
215
|
+
coinbase: constants.coinbase,
|
|
216
|
+
feeRecipient: constants.feeRecipient,
|
|
217
|
+
gasFees: constants.gasFees,
|
|
218
|
+
timestamp,
|
|
219
|
+
}),
|
|
232
220
|
);
|
|
233
|
-
|
|
221
|
+
this.nextBlockNumber += numBlocks;
|
|
234
222
|
|
|
235
|
-
|
|
223
|
+
// Build txs.
|
|
224
|
+
let totalTxs = 0;
|
|
225
|
+
const blockEndStates: StateReference[] = [];
|
|
226
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
227
|
+
const txIndexOffset = totalTxs;
|
|
228
|
+
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
229
|
+
totalTxs += numTxs;
|
|
230
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
231
|
+
this.makeProcessedTx({
|
|
232
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
233
|
+
globalVariables: blockGlobalVariables[blockIndex],
|
|
234
|
+
anchorBlockHeader: previousBlockHeader,
|
|
235
|
+
newL1ToL2Snapshot,
|
|
236
|
+
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// Insert side effects into the trees.
|
|
241
|
+
const endState = await this.updateTrees(txs, fork);
|
|
242
|
+
blockEndStates.push(endState);
|
|
243
|
+
|
|
244
|
+
return txs;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const cleanFork = await this.worldState.fork();
|
|
248
|
+
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
249
|
+
checkpointNumber,
|
|
250
|
+
constants,
|
|
251
|
+
l1ToL2Messages,
|
|
252
|
+
cleanFork,
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Add tx effects to db and build block headers.
|
|
256
|
+
const blocks = [];
|
|
257
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
258
|
+
const txs = blockTxs[i];
|
|
259
|
+
const state = blockEndStates[i];
|
|
260
|
+
|
|
261
|
+
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
262
|
+
expectedEndState: state,
|
|
263
|
+
insertTxsEffects: true,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const header = block.header;
|
|
267
|
+
this.headers.set(block.number, header);
|
|
268
|
+
|
|
269
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
270
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
271
|
+
|
|
272
|
+
blocks.push({ header, txs });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
276
|
+
this.checkpoints.push(checkpoint);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
constants,
|
|
280
|
+
header: checkpoint.header,
|
|
281
|
+
blocks,
|
|
282
|
+
l1ToL2Messages,
|
|
283
|
+
previousBlockHeader,
|
|
284
|
+
};
|
|
236
285
|
}
|
|
237
286
|
|
|
238
|
-
private async
|
|
239
|
-
const
|
|
287
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
288
|
+
const tx = await mockProcessedTx({
|
|
289
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
290
|
+
protocolContracts: ProtocolContractsList,
|
|
291
|
+
feePayer: this.feePayer,
|
|
292
|
+
...opts,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
296
|
+
|
|
297
|
+
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
298
|
+
const feePaymentPublicDataWrite = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
299
|
+
tx.txEffect.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
300
|
+
if (tx.avmProvingRequest) {
|
|
301
|
+
tx.avmProvingRequest.inputs.publicInputs.accumulatedData.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return tx;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
|
|
308
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
309
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
310
|
+
}
|
|
311
|
+
return Number(blockNumber) === 0
|
|
312
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
313
|
+
: this.headers.get(Number(blockNumber))!;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
317
|
+
let startStateReference = await fork.getStateReference();
|
|
318
|
+
let endStateReference = startStateReference;
|
|
240
319
|
for (const tx of txs) {
|
|
241
|
-
|
|
242
|
-
await
|
|
243
|
-
|
|
320
|
+
await insertSideEffects(tx, fork);
|
|
321
|
+
endStateReference = await fork.getStateReference();
|
|
322
|
+
|
|
244
323
|
if (tx.avmProvingRequest) {
|
|
324
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
245
325
|
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
246
326
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
247
327
|
l1ToL2MessageTree,
|
|
@@ -249,6 +329,7 @@ export class TestContext {
|
|
|
249
329
|
startStateReference.partial.nullifierTree,
|
|
250
330
|
startStateReference.partial.publicDataTree,
|
|
251
331
|
);
|
|
332
|
+
|
|
252
333
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
253
334
|
l1ToL2MessageTree,
|
|
254
335
|
endStateReference.partial.noteHashTree,
|
|
@@ -256,7 +337,11 @@ export class TestContext {
|
|
|
256
337
|
endStateReference.partial.publicDataTree,
|
|
257
338
|
);
|
|
258
339
|
}
|
|
340
|
+
|
|
341
|
+
startStateReference = endStateReference;
|
|
259
342
|
}
|
|
343
|
+
|
|
344
|
+
return endStateReference;
|
|
260
345
|
}
|
|
261
346
|
}
|
|
262
347
|
|
|
@@ -265,12 +350,9 @@ class TestProvingOrchestrator extends ProvingOrchestrator {
|
|
|
265
350
|
|
|
266
351
|
// Disable this check by default, since it requires seeding world state with the block being built
|
|
267
352
|
// This is only enabled in some tests with multiple blocks that populate the pending chain via makePendingBlock
|
|
268
|
-
protected override verifyBuiltBlockAgainstSyncedState(
|
|
269
|
-
l2Block: L2Block,
|
|
270
|
-
newArchive: AppendOnlyTreeSnapshot,
|
|
271
|
-
): Promise<void> {
|
|
353
|
+
protected override verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState): Promise<void> {
|
|
272
354
|
if (this.isVerifyBuiltBlockAgainstSyncedStateEnabled) {
|
|
273
|
-
return super.verifyBuiltBlockAgainstSyncedState(
|
|
355
|
+
return super.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
274
356
|
}
|
|
275
357
|
return Promise.resolve();
|
|
276
358
|
}
|