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