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