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