@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.023c3e5
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 +8 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -2
- 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 +47 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +200 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +36 -17
- package/dest/mocks/test_context.d.ts +43 -32
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +149 -87
- package/dest/orchestrator/block-building-helpers.d.ts +37 -30
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +170 -189
- package/dest/orchestrator/block-proving-state.d.ts +70 -48
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +282 -177
- package/dest/orchestrator/checkpoint-proving-state.d.ts +76 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +243 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +43 -28
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +177 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +53 -35
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +855 -302
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -1
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -6
- package/dest/orchestrator/tx-proving-state.d.ts +15 -12
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +27 -44
- 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 +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +11 -7
- package/dest/prover-client/server-epoch-prover.d.ts +16 -12
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +11 -11
- package/dest/proving_broker/broker_prover_facade.d.ts +28 -19
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +62 -43
- package/dest/proving_broker/config.d.ts +23 -10
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +29 -6
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -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/factory.js +1 -1
- 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/gcs_proof_store.js +1 -0
- package/dest/proving_broker/proof_store/index.d.ts +2 -1
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- 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 +8 -12
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +86 -65
- package/dest/proving_broker/proving_broker.d.ts +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +40 -33
- 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/memory.js +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 +401 -11
- 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 +15 -35
- package/dest/proving_broker/proving_job_controller.d.ts +11 -10
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +92 -62
- package/dest/proving_broker/rpc.d.ts +4 -6
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +1 -4
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +23 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +33 -31
- package/src/config.ts +25 -9
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +289 -0
- package/src/mocks/fixtures.ts +46 -40
- package/src/mocks/test_context.ts +223 -116
- package/src/orchestrator/block-building-helpers.ts +258 -334
- package/src/orchestrator/block-proving-state.ts +325 -231
- package/src/orchestrator/checkpoint-proving-state.ts +349 -0
- package/src/orchestrator/epoch-proving-state.ts +237 -111
- package/src/orchestrator/orchestrator.ts +653 -343
- package/src/orchestrator/orchestrator_metrics.ts +2 -6
- package/src/orchestrator/tx-proving-state.ts +48 -66
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +41 -29
- package/src/prover-client/server-epoch-prover.ts +40 -22
- package/src/proving_broker/broker_prover_facade.ts +212 -131
- package/src/proving_broker/config.ts +34 -7
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +1 -1
- package/src/proving_broker/proof_store/gcs_proof_store.ts +5 -1
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +1 -1
- package/src/proving_broker/proving_agent.ts +95 -66
- package/src/proving_broker/proving_broker.ts +57 -41
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +29 -13
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
- package/src/proving_broker/proving_job_controller.ts +100 -83
- package/src/proving_broker/rpc.ts +1 -6
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +156 -64
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/dest/block_builder/index.d.ts +0 -6
- package/dest/block_builder/index.d.ts.map +0 -1
- package/dest/block_builder/index.js +0 -1
- package/dest/block_builder/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- 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/bin/get-proof-inputs.ts +0 -59
- package/src/block_builder/index.ts +0 -6
- package/src/block_builder/light.ts +0 -101
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,56 +1,66 @@
|
|
|
1
1
|
import type { BBProverConfig } from '@aztec/bb-prover';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { TestCircuitProver } from '@aztec/bb-prover';
|
|
3
|
+
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
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';
|
|
4
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
5
|
-
import {
|
|
8
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
6
9
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
7
|
-
import {
|
|
10
|
+
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
8
11
|
import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
|
|
9
|
-
import {
|
|
10
|
-
PublicProcessor,
|
|
11
|
-
PublicTxSimulationTester,
|
|
12
|
-
PublicTxSimulator,
|
|
13
|
-
SimpleContractDataSource,
|
|
14
|
-
WorldStateDB,
|
|
15
|
-
} from '@aztec/simulator/server';
|
|
16
12
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
17
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
18
|
-
import
|
|
19
|
-
import type {
|
|
20
|
-
import {
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
14
|
+
import { EthAddress } from '@aztec/stdlib/block';
|
|
15
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
16
|
+
import type { MerkleTreeWriteOperations, ServerCircuitProver } from '@aztec/stdlib/interfaces/server';
|
|
17
|
+
import type { CheckpointConstantData } from '@aztec/stdlib/rollup';
|
|
18
|
+
import { mockProcessedTx } from '@aztec/stdlib/testing';
|
|
19
|
+
import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
20
|
+
import {
|
|
21
|
+
type BlockHeader,
|
|
22
|
+
type GlobalVariables,
|
|
23
|
+
type ProcessedTx,
|
|
24
|
+
StateReference,
|
|
25
|
+
TreeSnapshots,
|
|
26
|
+
} from '@aztec/stdlib/tx';
|
|
23
27
|
import type { MerkleTreeAdminDatabase } from '@aztec/world-state';
|
|
24
28
|
import { NativeWorldStateService } from '@aztec/world-state/native';
|
|
25
29
|
|
|
26
30
|
import { promises as fs } from 'fs';
|
|
27
31
|
|
|
28
|
-
import {
|
|
29
|
-
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';
|
|
38
|
+
import type { BlockProvingState } from '../orchestrator/block-proving-state.js';
|
|
30
39
|
import { ProvingOrchestrator } from '../orchestrator/index.js';
|
|
31
40
|
import { BrokerCircuitProverFacade } from '../proving_broker/broker_prover_facade.js';
|
|
32
41
|
import { TestBroker } from '../test/mock_prover.js';
|
|
33
|
-
import { getEnvironmentConfig,
|
|
42
|
+
import { getEnvironmentConfig, getSimulator, makeCheckpointConstants, makeGlobals } from './fixtures.js';
|
|
34
43
|
|
|
35
44
|
export class TestContext {
|
|
36
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;
|
|
37
52
|
private feePayerBalance: Fr;
|
|
38
53
|
|
|
39
54
|
constructor(
|
|
40
|
-
public publicTxSimulator: PublicTxSimulator,
|
|
41
55
|
public worldState: MerkleTreeAdminDatabase,
|
|
42
|
-
public publicProcessor: PublicProcessor,
|
|
43
|
-
public globalVariables: GlobalVariables,
|
|
44
56
|
public prover: ServerCircuitProver,
|
|
45
57
|
public broker: TestBroker,
|
|
46
58
|
public brokerProverFacade: BrokerCircuitProverFacade,
|
|
47
59
|
public orchestrator: TestProvingOrchestrator,
|
|
48
|
-
|
|
49
|
-
public feePayer: AztecAddress,
|
|
60
|
+
private feePayer: AztecAddress,
|
|
50
61
|
initialFeePayerBalance: Fr,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
public logger: Logger,
|
|
62
|
+
private directoriesToCleanup: string[],
|
|
63
|
+
private logger: Logger,
|
|
54
64
|
) {
|
|
55
65
|
this.feePayerBalance = initialFeePayerBalance;
|
|
56
66
|
}
|
|
@@ -61,13 +71,15 @@ export class TestContext {
|
|
|
61
71
|
|
|
62
72
|
static async new(
|
|
63
73
|
logger: Logger,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
new TestCircuitProver(await
|
|
67
|
-
|
|
74
|
+
{
|
|
75
|
+
proverCount = 4,
|
|
76
|
+
createProver = async (bbConfig: BBProverConfig) => new TestCircuitProver(await getSimulator(bbConfig, logger)),
|
|
77
|
+
}: {
|
|
78
|
+
proverCount?: number;
|
|
79
|
+
createProver?: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver>;
|
|
80
|
+
} = {},
|
|
68
81
|
) {
|
|
69
82
|
const directoriesToCleanup: string[] = [];
|
|
70
|
-
const globalVariables = makeGlobals(blockNumber);
|
|
71
83
|
|
|
72
84
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
73
85
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
@@ -76,25 +88,10 @@ export class TestContext {
|
|
|
76
88
|
|
|
77
89
|
// Separated dbs for public processor and prover - see public_processor for context
|
|
78
90
|
const ws = await NativeWorldStateService.tmp(
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
/*rollupAddress=*/ undefined,
|
|
92
|
+
/*cleanupTmpDir=*/ true,
|
|
81
93
|
prefilledPublicData,
|
|
82
94
|
);
|
|
83
|
-
const publicDb = await ws.fork();
|
|
84
|
-
|
|
85
|
-
const contractDataSource = new SimpleContractDataSource();
|
|
86
|
-
const worldStateDB = new WorldStateDB(publicDb, contractDataSource);
|
|
87
|
-
|
|
88
|
-
const tester = new PublicTxSimulationTester(worldStateDB, contractDataSource, publicDb);
|
|
89
|
-
|
|
90
|
-
const publicTxSimulator = new PublicTxSimulator(publicDb, worldStateDB, globalVariables, true);
|
|
91
|
-
const processor = new PublicProcessor(
|
|
92
|
-
publicDb,
|
|
93
|
-
globalVariables,
|
|
94
|
-
worldStateDB,
|
|
95
|
-
publicTxSimulator,
|
|
96
|
-
new TestDateProvider(),
|
|
97
|
-
);
|
|
98
95
|
|
|
99
96
|
let localProver: ServerCircuitProver;
|
|
100
97
|
const config = await getEnvironmentConfig(logger);
|
|
@@ -107,6 +104,8 @@ export class TestContext {
|
|
|
107
104
|
bbBinaryPath: config.expectedBBPath,
|
|
108
105
|
bbWorkingDirectory: config.bbWorkingDirectory,
|
|
109
106
|
bbSkipCleanup: config.bbSkipCleanup,
|
|
107
|
+
numConcurrentIVCVerifiers: 2,
|
|
108
|
+
bbIVCConcurrency: 1,
|
|
110
109
|
};
|
|
111
110
|
localProver = await createProver(bbConfig);
|
|
112
111
|
}
|
|
@@ -117,25 +116,20 @@ export class TestContext {
|
|
|
117
116
|
|
|
118
117
|
const broker = new TestBroker(proverCount, localProver);
|
|
119
118
|
const facade = new BrokerCircuitProverFacade(broker);
|
|
120
|
-
const orchestrator = new TestProvingOrchestrator(ws, facade,
|
|
119
|
+
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
|
|
121
120
|
|
|
122
121
|
await broker.start();
|
|
123
122
|
facade.start();
|
|
124
123
|
|
|
125
124
|
return new this(
|
|
126
|
-
publicTxSimulator,
|
|
127
125
|
ws,
|
|
128
|
-
processor,
|
|
129
|
-
globalVariables,
|
|
130
126
|
localProver,
|
|
131
127
|
broker,
|
|
132
128
|
facade,
|
|
133
129
|
orchestrator,
|
|
134
|
-
blockNumber,
|
|
135
130
|
feePayer,
|
|
136
131
|
initialFeePayerBalance,
|
|
137
132
|
directoriesToCleanup,
|
|
138
|
-
tester,
|
|
139
133
|
logger,
|
|
140
134
|
);
|
|
141
135
|
}
|
|
@@ -144,16 +138,6 @@ export class TestContext {
|
|
|
144
138
|
return this.worldState.fork();
|
|
145
139
|
}
|
|
146
140
|
|
|
147
|
-
public getBlockHeader(blockNumber: 0): BlockHeader;
|
|
148
|
-
public getBlockHeader(blockNumber: number): BlockHeader | undefined;
|
|
149
|
-
public getBlockHeader(blockNumber = 0) {
|
|
150
|
-
return blockNumber === 0 ? this.worldState.getCommitted().getInitialHeader() : this.headers.get(blockNumber);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public getPreviousBlockHeader(currentBlockNumber = this.blockNumber): BlockHeader {
|
|
154
|
-
return this.getBlockHeader(currentBlockNumber - 1)!;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
141
|
async cleanup() {
|
|
158
142
|
await this.brokerProverFacade.stop();
|
|
159
143
|
await this.broker.stop();
|
|
@@ -166,77 +150,203 @@ export class TestContext {
|
|
|
166
150
|
}
|
|
167
151
|
}
|
|
168
152
|
|
|
169
|
-
public
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
153
|
+
public startNewEpoch() {
|
|
154
|
+
this.checkpoints = [];
|
|
155
|
+
this.checkpointOutHashes = [];
|
|
156
|
+
this.nextCheckpointIndex = 0;
|
|
157
|
+
this.epochNumber++;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Return blob fields of all checkpoints in the epoch.
|
|
161
|
+
public getBlobFields() {
|
|
162
|
+
return this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public async getFinalBlobChallenges() {
|
|
166
|
+
const blobFields = this.getBlobFields();
|
|
167
|
+
return await buildFinalBlobChallenges(blobFields);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public async makeCheckpoint(
|
|
171
|
+
numBlocks: number,
|
|
172
|
+
{
|
|
173
|
+
numTxsPerBlock = 0,
|
|
174
|
+
numL1ToL2Messages = 0,
|
|
175
|
+
makeProcessedTxOpts = () => ({}),
|
|
176
|
+
...constantOpts
|
|
177
|
+
}: {
|
|
178
|
+
numTxsPerBlock?: number | number[];
|
|
179
|
+
numL1ToL2Messages?: number;
|
|
180
|
+
makeProcessedTxOpts?: (
|
|
181
|
+
blockGlobalVariables: GlobalVariables,
|
|
182
|
+
txIndex: number,
|
|
183
|
+
) => Partial<Parameters<typeof mockProcessedTx>[0]>;
|
|
184
|
+
} & Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
185
|
+
) {
|
|
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.
|
|
202
|
+
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
203
|
+
await fork.appendLeaves(
|
|
204
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
205
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
206
|
+
);
|
|
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);
|
|
213
|
+
|
|
214
|
+
// Build global variables.
|
|
215
|
+
const blockGlobalVariables = times(numBlocks, i =>
|
|
216
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
217
|
+
coinbase: constants.coinbase,
|
|
218
|
+
feeRecipient: constants.feeRecipient,
|
|
219
|
+
gasFees: constants.gasFees,
|
|
220
|
+
timestamp,
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
this.nextBlockNumber += numBlocks;
|
|
224
|
+
|
|
225
|
+
// Build txs.
|
|
226
|
+
let totalTxs = 0;
|
|
227
|
+
const blockEndStates: StateReference[] = [];
|
|
228
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
229
|
+
const txIndexOffset = totalTxs;
|
|
230
|
+
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
231
|
+
totalTxs += numTxs;
|
|
232
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
233
|
+
this.makeProcessedTx({
|
|
234
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
235
|
+
globalVariables: blockGlobalVariables[blockIndex],
|
|
236
|
+
anchorBlockHeader: previousBlockHeader,
|
|
237
|
+
newL1ToL2Snapshot,
|
|
238
|
+
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
239
|
+
}),
|
|
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;
|
|
247
|
+
});
|
|
248
|
+
|
|
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
|
+
);
|
|
258
|
+
|
|
259
|
+
// Add tx effects to db and build block headers.
|
|
260
|
+
const blocks = [];
|
|
261
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
262
|
+
const txs = blockTxs[i];
|
|
263
|
+
const state = blockEndStates[i];
|
|
264
|
+
|
|
265
|
+
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
266
|
+
expectedEndState: state,
|
|
267
|
+
insertTxsEffects: true,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const header = block.header;
|
|
271
|
+
this.headers.set(block.number, header);
|
|
272
|
+
|
|
273
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
274
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
275
|
+
|
|
276
|
+
blocks.push({ header, txs });
|
|
277
|
+
}
|
|
278
|
+
|
|
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
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
293
|
+
const tx = await mockProcessedTx({
|
|
179
294
|
vkTreeRoot: getVKTreeRoot(),
|
|
180
|
-
|
|
181
|
-
globalVariables: this.globalVariables,
|
|
295
|
+
protocolContracts: ProtocolContractsList,
|
|
182
296
|
feePayer: this.feePayer,
|
|
183
297
|
...opts,
|
|
184
298
|
});
|
|
299
|
+
|
|
185
300
|
this.feePayerBalance = new Fr(this.feePayerBalance.toBigInt() - tx.txEffect.transactionFee.toBigInt());
|
|
186
|
-
if (opts?.privateOnly) {
|
|
187
|
-
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
188
|
-
tx.txEffect.publicDataWrites[0] = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
189
|
-
}
|
|
190
|
-
return tx;
|
|
191
|
-
}
|
|
192
301
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
) {
|
|
200
|
-
const globalVariables = typeof blockNumOrGlobals === 'number' ? makeGlobals(blockNumOrGlobals) : blockNumOrGlobals;
|
|
201
|
-
const blockNum = globalVariables.blockNumber.toNumber();
|
|
202
|
-
const db = await this.worldState.fork();
|
|
203
|
-
const msgs = times(numMsgs, i => new Fr(blockNum * 100 + i));
|
|
204
|
-
const txs = await timesParallel(numTxs, i =>
|
|
205
|
-
this.makeProcessedTx({ seed: i + blockNum * 1000, globalVariables, ...makeProcessedTxOpts(i) }),
|
|
206
|
-
);
|
|
207
|
-
await this.setTreeRoots(txs);
|
|
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
|
+
}
|
|
208
308
|
|
|
209
|
-
|
|
210
|
-
this.headers.set(blockNum, block.header);
|
|
211
|
-
await this.worldState.handleL2BlockAndMessages(block, msgs);
|
|
212
|
-
return { block, txs, msgs };
|
|
309
|
+
return tx;
|
|
213
310
|
}
|
|
214
311
|
|
|
215
|
-
|
|
216
|
-
|
|
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))!;
|
|
217
319
|
}
|
|
218
320
|
|
|
219
|
-
|
|
220
|
-
|
|
321
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
322
|
+
let startStateReference = await fork.getStateReference();
|
|
323
|
+
let endStateReference = startStateReference;
|
|
221
324
|
for (const tx of txs) {
|
|
222
|
-
|
|
223
|
-
await
|
|
224
|
-
|
|
325
|
+
await insertSideEffects(tx, fork);
|
|
326
|
+
endStateReference = await fork.getStateReference();
|
|
327
|
+
|
|
225
328
|
if (tx.avmProvingRequest) {
|
|
329
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
330
|
+
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
226
331
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
227
|
-
|
|
332
|
+
l1ToL2MessageTree,
|
|
228
333
|
startStateReference.partial.noteHashTree,
|
|
229
334
|
startStateReference.partial.nullifierTree,
|
|
230
335
|
startStateReference.partial.publicDataTree,
|
|
231
336
|
);
|
|
337
|
+
|
|
232
338
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
233
|
-
|
|
339
|
+
l1ToL2MessageTree,
|
|
234
340
|
endStateReference.partial.noteHashTree,
|
|
235
341
|
endStateReference.partial.nullifierTree,
|
|
236
342
|
endStateReference.partial.publicDataTree,
|
|
237
343
|
);
|
|
238
344
|
}
|
|
345
|
+
|
|
346
|
+
startStateReference = endStateReference;
|
|
239
347
|
}
|
|
348
|
+
|
|
349
|
+
return endStateReference;
|
|
240
350
|
}
|
|
241
351
|
}
|
|
242
352
|
|
|
@@ -245,12 +355,9 @@ class TestProvingOrchestrator extends ProvingOrchestrator {
|
|
|
245
355
|
|
|
246
356
|
// Disable this check by default, since it requires seeding world state with the block being built
|
|
247
357
|
// This is only enabled in some tests with multiple blocks that populate the pending chain via makePendingBlock
|
|
248
|
-
protected override verifyBuiltBlockAgainstSyncedState(
|
|
249
|
-
l2Block: L2Block,
|
|
250
|
-
newArchive: AppendOnlyTreeSnapshot,
|
|
251
|
-
): Promise<void> {
|
|
358
|
+
protected override verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState): Promise<void> {
|
|
252
359
|
if (this.isVerifyBuiltBlockAgainstSyncedStateEnabled) {
|
|
253
|
-
return super.verifyBuiltBlockAgainstSyncedState(
|
|
360
|
+
return super.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
254
361
|
}
|
|
255
362
|
return Promise.resolve();
|
|
256
363
|
}
|