@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.c7c42ec
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 +8 -8
- package/dest/block-factory/light.d.ts.map +1 -1
- package/dest/block-factory/light.js +37 -23
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- 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 +1 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +7 -17
- package/dest/mocks/test_context.d.ts +27 -46
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +105 -116
- package/dest/orchestrator/block-building-helpers.d.ts +17 -19
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +86 -111
- package/dest/orchestrator/block-proving-state.d.ts +17 -11
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +81 -20
- package/dest/orchestrator/checkpoint-proving-state.d.ts +8 -8
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +15 -16
- package/dest/orchestrator/epoch-proving-state.d.ts +9 -8
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +3 -3
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +10 -10
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +27 -56
- 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 +2 -2
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +2 -11
- 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/server-epoch-prover.d.ts +8 -7
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +2 -2
- package/dest/proving_broker/broker_prover_facade.d.ts +20 -20
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +6 -12
- package/dest/proving_broker/config.d.ts +12 -8
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +8 -2
- package/dest/proving_broker/factory.d.ts +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 +1 -1
- 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 +1 -1
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
- 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 +5 -1
- 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 +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +3 -2
- 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 +2 -3
- 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 +3 -4
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +1 -1
- package/package.json +20 -17
- package/src/block-factory/light.ts +40 -43
- package/src/config.ts +1 -1
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +198 -0
- package/src/mocks/fixtures.ts +7 -30
- package/src/mocks/test_context.ts +148 -177
- package/src/orchestrator/block-building-helpers.ts +125 -205
- package/src/orchestrator/block-proving-state.ts +103 -25
- package/src/orchestrator/checkpoint-proving-state.ts +24 -20
- package/src/orchestrator/epoch-proving-state.ts +9 -7
- package/src/orchestrator/orchestrator.ts +36 -68
- package/src/orchestrator/orchestrator_metrics.ts +1 -20
- package/src/orchestrator/tx-proving-state.ts +4 -18
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +3 -2
- package/src/prover-client/server-epoch-prover.ts +6 -7
- package/src/proving_broker/broker_prover_facade.ts +23 -31
- package/src/proving_broker/config.ts +8 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proving_broker.ts +5 -1
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +5 -4
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +4 -4
- package/src/test/mock_prover.ts +1 -6
|
@@ -1,62 +1,64 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
2
|
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
3
|
-
import { SpongeBlob } from '@aztec/blob-lib';
|
|
4
3
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
5
|
-
import {
|
|
6
|
-
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';
|
|
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,175 @@ 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 checkpointNumber = CheckpointNumber(checkpointIndex + 1);
|
|
191
|
+
const slotNumber = checkpointNumber * 15; // times an arbitrary number to make it different to the checkpoint number
|
|
192
|
+
|
|
193
|
+
const constants = makeCheckpointConstants(slotNumber, constantOpts);
|
|
194
|
+
|
|
195
|
+
const fork = await this.worldState.fork();
|
|
196
|
+
|
|
197
|
+
// Build l1 to l2 messages.
|
|
259
198
|
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
260
|
-
|
|
261
|
-
await merkleTrees.appendLeaves(
|
|
199
|
+
await fork.appendLeaves(
|
|
262
200
|
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
263
201
|
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
264
202
|
);
|
|
265
|
-
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
203
|
+
const newL1ToL2Snapshot = await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, fork);
|
|
266
204
|
|
|
205
|
+
const startBlockNumber = this.nextBlockNumber;
|
|
206
|
+
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
207
|
+
|
|
208
|
+
// Build global variables.
|
|
267
209
|
const blockGlobalVariables = times(numBlocks, i =>
|
|
268
|
-
makeGlobals(
|
|
210
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
211
|
+
coinbase: constants.coinbase,
|
|
212
|
+
feeRecipient: constants.feeRecipient,
|
|
213
|
+
gasFees: constants.gasFees,
|
|
214
|
+
}),
|
|
269
215
|
);
|
|
216
|
+
this.nextBlockNumber += numBlocks;
|
|
217
|
+
|
|
218
|
+
// Build txs.
|
|
270
219
|
let totalTxs = 0;
|
|
271
|
-
const
|
|
220
|
+
const blockEndStates: StateReference[] = [];
|
|
221
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
272
222
|
const txIndexOffset = totalTxs;
|
|
273
223
|
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
274
224
|
totalTxs += numTxs;
|
|
275
|
-
|
|
225
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
276
226
|
this.makeProcessedTx({
|
|
277
|
-
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456,
|
|
227
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
278
228
|
globalVariables: blockGlobalVariables[blockIndex],
|
|
279
|
-
|
|
229
|
+
anchorBlockHeader: previousBlockHeader,
|
|
280
230
|
newL1ToL2Snapshot,
|
|
281
231
|
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
282
232
|
}),
|
|
283
233
|
);
|
|
234
|
+
|
|
235
|
+
// Insert side effects into the trees.
|
|
236
|
+
const endState = await this.updateTrees(txs, fork);
|
|
237
|
+
blockEndStates.push(endState);
|
|
238
|
+
|
|
239
|
+
return txs;
|
|
284
240
|
});
|
|
285
241
|
|
|
286
|
-
const
|
|
287
|
-
const
|
|
242
|
+
const cleanFork = await this.worldState.fork();
|
|
243
|
+
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
244
|
+
checkpointNumber,
|
|
245
|
+
constants,
|
|
246
|
+
l1ToL2Messages,
|
|
247
|
+
cleanFork,
|
|
248
|
+
);
|
|
288
249
|
|
|
289
|
-
|
|
250
|
+
// Add tx effects to db and build block headers.
|
|
251
|
+
const blocks = [];
|
|
290
252
|
for (let i = 0; i < numBlocks; i++) {
|
|
291
|
-
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
|
-
|
|
299
|
-
|
|
300
|
-
const block = await buildBlockWithCleanDB(txs, globalVariables, blockMsgs, fork, spongeBlobState, isFirstBlock);
|
|
256
|
+
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
257
|
+
expectedEndState: state,
|
|
258
|
+
insertTxsEffects: true,
|
|
259
|
+
});
|
|
301
260
|
|
|
302
|
-
const header = block.
|
|
303
|
-
this.headers.set(
|
|
261
|
+
const header = block.header;
|
|
262
|
+
this.headers.set(block.number, header);
|
|
304
263
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const blockBlobFields = block.body.toBlobFields();
|
|
308
|
-
await spongeBlobState.absorb(blockBlobFields);
|
|
264
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
265
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
309
266
|
|
|
310
267
|
blocks.push({ header, txs });
|
|
311
268
|
}
|
|
312
269
|
|
|
313
|
-
|
|
314
|
-
|
|
270
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
271
|
+
this.checkpoints.push(checkpoint);
|
|
315
272
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
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
|
-
);
|
|
273
|
+
return {
|
|
274
|
+
constants,
|
|
275
|
+
header: checkpoint.header,
|
|
276
|
+
blocks,
|
|
277
|
+
l1ToL2Messages,
|
|
278
|
+
previousBlockHeader,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
334
281
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
clientInitiatedSimulation: false,
|
|
282
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
283
|
+
const tx = await mockProcessedTx({
|
|
284
|
+
vkTreeRoot: getVKTreeRoot(),
|
|
285
|
+
protocolContracts: ProtocolContractsList,
|
|
286
|
+
feePayer: this.feePayer,
|
|
287
|
+
...opts,
|
|
342
288
|
});
|
|
343
289
|
|
|
344
|
-
|
|
290
|
+
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
291
|
+
|
|
292
|
+
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
293
|
+
const feePaymentPublicDataWrite = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
294
|
+
tx.txEffect.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
295
|
+
if (tx.avmProvingRequest) {
|
|
296
|
+
tx.avmProvingRequest.inputs.publicInputs.accumulatedData.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return tx;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
|
|
303
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
304
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
305
|
+
}
|
|
306
|
+
return Number(blockNumber) === 0
|
|
307
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
308
|
+
: this.headers.get(Number(blockNumber))!;
|
|
345
309
|
}
|
|
346
310
|
|
|
347
|
-
private async
|
|
348
|
-
|
|
311
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
312
|
+
let startStateReference = await fork.getStateReference();
|
|
313
|
+
let endStateReference = startStateReference;
|
|
349
314
|
for (const tx of txs) {
|
|
350
|
-
|
|
351
|
-
await
|
|
352
|
-
|
|
315
|
+
await insertSideEffects(tx, fork);
|
|
316
|
+
endStateReference = await fork.getStateReference();
|
|
317
|
+
|
|
353
318
|
if (tx.avmProvingRequest) {
|
|
319
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
354
320
|
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
355
321
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
356
322
|
l1ToL2MessageTree,
|
|
@@ -358,6 +324,7 @@ export class TestContext {
|
|
|
358
324
|
startStateReference.partial.nullifierTree,
|
|
359
325
|
startStateReference.partial.publicDataTree,
|
|
360
326
|
);
|
|
327
|
+
|
|
361
328
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
362
329
|
l1ToL2MessageTree,
|
|
363
330
|
endStateReference.partial.noteHashTree,
|
|
@@ -365,7 +332,11 @@ export class TestContext {
|
|
|
365
332
|
endStateReference.partial.publicDataTree,
|
|
366
333
|
);
|
|
367
334
|
}
|
|
335
|
+
|
|
336
|
+
startStateReference = endStateReference;
|
|
368
337
|
}
|
|
338
|
+
|
|
339
|
+
return endStateReference;
|
|
369
340
|
}
|
|
370
341
|
}
|
|
371
342
|
|