@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.d3ec352c
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 +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 +1 -4
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +5 -15
- 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 +99 -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 +85 -110
- package/dest/orchestrator/block-proving-state.d.ts +16 -10
- 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 +7 -7
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/checkpoint-proving-state.js +13 -15
- package/dest/orchestrator/epoch-proving-state.d.ts +8 -7
- 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 +7 -7
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +24 -30
- 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 +7 -6
- 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 +143 -0
- package/src/mocks/fixtures.ts +5 -28
- package/src/mocks/test_context.ts +143 -174
- package/src/orchestrator/block-building-helpers.ts +124 -204
- package/src/orchestrator/block-proving-state.ts +102 -24
- package/src/orchestrator/checkpoint-proving-state.ts +22 -19
- package/src/orchestrator/epoch-proving-state.ts +8 -6
- package/src/orchestrator/orchestrator.ts +31 -38
- package/src/orchestrator/tx-proving-state.ts +3 -16
- package/src/prover-client/server-epoch-prover.ts +5 -6
- 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,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 {
|
|
4
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
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,173 @@ 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);
|
|
204
|
+
|
|
205
|
+
const startBlockNumber = this.nextBlockNumber;
|
|
206
|
+
const previousBlockHeader = this.getBlockHeader(BlockNumber(startBlockNumber - 1));
|
|
266
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
253
|
const isFirstBlock = i === 0;
|
|
292
|
-
const blockNumber = firstBlockNumber + i;
|
|
293
|
-
const globalVariables = blockGlobalVariables[i];
|
|
294
254
|
const txs = blockTxs[i];
|
|
255
|
+
const state = blockEndStates[i];
|
|
295
256
|
|
|
296
|
-
await
|
|
257
|
+
const block = await builder.addBlock(blockGlobalVariables[i], state, txs);
|
|
297
258
|
|
|
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);
|
|
259
|
+
const header = block.header;
|
|
260
|
+
this.headers.set(block.number, header);
|
|
304
261
|
|
|
262
|
+
const blockMsgs = isFirstBlock ? l1ToL2Messages : [];
|
|
305
263
|
await this.worldState.handleL2BlockAndMessages(block, blockMsgs, isFirstBlock);
|
|
306
264
|
|
|
307
|
-
const blockBlobFields = block.body.toBlobFields();
|
|
308
|
-
await spongeBlobState.absorb(blockBlobFields);
|
|
309
|
-
|
|
310
265
|
blocks.push({ header, txs });
|
|
311
266
|
}
|
|
312
267
|
|
|
313
|
-
|
|
314
|
-
|
|
268
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
269
|
+
this.checkpoints.push(checkpoint);
|
|
315
270
|
|
|
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
|
-
);
|
|
271
|
+
return {
|
|
272
|
+
constants,
|
|
273
|
+
header: checkpoint.header,
|
|
274
|
+
blocks,
|
|
275
|
+
l1ToL2Messages,
|
|
276
|
+
previousBlockHeader,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
334
279
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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: BlockNumber): BlockHeader {
|
|
301
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
302
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
303
|
+
}
|
|
304
|
+
return Number(blockNumber) === 0
|
|
305
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
306
|
+
: this.headers.get(Number(blockNumber))!;
|
|
345
307
|
}
|
|
346
308
|
|
|
347
|
-
private async
|
|
348
|
-
|
|
309
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
310
|
+
let startStateReference = await fork.getStateReference();
|
|
311
|
+
let endStateReference = startStateReference;
|
|
349
312
|
for (const tx of txs) {
|
|
350
|
-
|
|
351
|
-
await
|
|
352
|
-
|
|
313
|
+
await insertSideEffects(tx, fork);
|
|
314
|
+
endStateReference = await fork.getStateReference();
|
|
315
|
+
|
|
353
316
|
if (tx.avmProvingRequest) {
|
|
317
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
354
318
|
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
355
319
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
356
320
|
l1ToL2MessageTree,
|
|
@@ -358,6 +322,7 @@ export class TestContext {
|
|
|
358
322
|
startStateReference.partial.nullifierTree,
|
|
359
323
|
startStateReference.partial.publicDataTree,
|
|
360
324
|
);
|
|
325
|
+
|
|
361
326
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
362
327
|
l1ToL2MessageTree,
|
|
363
328
|
endStateReference.partial.noteHashTree,
|
|
@@ -365,7 +330,11 @@ export class TestContext {
|
|
|
365
330
|
endStateReference.partial.publicDataTree,
|
|
366
331
|
);
|
|
367
332
|
}
|
|
333
|
+
|
|
334
|
+
startStateReference = endStateReference;
|
|
368
335
|
}
|
|
336
|
+
|
|
337
|
+
return endStateReference;
|
|
369
338
|
}
|
|
370
339
|
}
|
|
371
340
|
|