@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.03f7ef2
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 +2 -0
- package/dest/block-factory/index.d.ts.map +1 -0
- package/dest/block-factory/light.d.ts +38 -0
- package/dest/block-factory/light.d.ts.map +1 -0
- package/dest/block-factory/light.js +108 -0
- 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 +36 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +147 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +34 -16
- package/dest/mocks/test_context.d.ts +41 -32
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +138 -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 +63 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +210 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +41 -27
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +143 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +36 -33
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +379 -250
- 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 +13 -11
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +23 -40
- 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 +4 -4
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +5 -4
- 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 +23 -16
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +59 -40
- package/dest/proving_broker/config.d.ts +19 -10
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +23 -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 +4 -4
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +83 -47
- 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 +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +39 -23
- 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 +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +12 -10
- 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 +9 -9
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +87 -60
- 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 +37 -19
- package/package.json +34 -31
- package/src/block-factory/index.ts +1 -0
- package/src/block-factory/light.ts +137 -0
- package/src/config.ts +25 -9
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +198 -0
- package/src/mocks/fixtures.ts +44 -39
- package/src/mocks/test_context.ts +213 -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 +303 -0
- package/src/orchestrator/epoch-proving-state.ts +191 -113
- package/src/orchestrator/orchestrator.ts +582 -314
- package/src/orchestrator/tx-proving-state.ts +49 -64
- package/src/prover-client/prover-client.ts +16 -14
- package/src/prover-client/server-epoch-prover.ts +40 -22
- package/src/proving_broker/broker_prover_facade.ts +205 -126
- package/src/proving_broker/config.ts +25 -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 +89 -47
- package/src/proving_broker/proving_broker.ts +56 -33
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +14 -12
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +92 -81
- package/src/proving_broker/rpc.ts +1 -6
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +158 -59
- 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/light.d.ts +0 -33
- package/dest/block_builder/light.d.ts.map +0 -1
- package/dest/block_builder/light.js +0 -82
- 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/dest/{block_builder → block-factory}/index.js +0 -0
|
@@ -1,56 +1,64 @@
|
|
|
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 nextCheckpointIndex = 0;
|
|
48
|
+
private nextBlockNumber = 1;
|
|
49
|
+
private epochNumber = 1;
|
|
37
50
|
private feePayerBalance: Fr;
|
|
38
51
|
|
|
39
52
|
constructor(
|
|
40
|
-
public publicTxSimulator: PublicTxSimulator,
|
|
41
53
|
public worldState: MerkleTreeAdminDatabase,
|
|
42
|
-
public publicProcessor: PublicProcessor,
|
|
43
|
-
public globalVariables: GlobalVariables,
|
|
44
54
|
public prover: ServerCircuitProver,
|
|
45
55
|
public broker: TestBroker,
|
|
46
56
|
public brokerProverFacade: BrokerCircuitProverFacade,
|
|
47
57
|
public orchestrator: TestProvingOrchestrator,
|
|
48
|
-
|
|
49
|
-
public feePayer: AztecAddress,
|
|
58
|
+
private feePayer: AztecAddress,
|
|
50
59
|
initialFeePayerBalance: Fr,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
public logger: Logger,
|
|
60
|
+
private directoriesToCleanup: string[],
|
|
61
|
+
private logger: Logger,
|
|
54
62
|
) {
|
|
55
63
|
this.feePayerBalance = initialFeePayerBalance;
|
|
56
64
|
}
|
|
@@ -61,13 +69,15 @@ export class TestContext {
|
|
|
61
69
|
|
|
62
70
|
static async new(
|
|
63
71
|
logger: Logger,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
new TestCircuitProver(await
|
|
67
|
-
|
|
72
|
+
{
|
|
73
|
+
proverCount = 4,
|
|
74
|
+
createProver = async (bbConfig: BBProverConfig) => new TestCircuitProver(await getSimulator(bbConfig, logger)),
|
|
75
|
+
}: {
|
|
76
|
+
proverCount?: number;
|
|
77
|
+
createProver?: (bbConfig: BBProverConfig) => Promise<ServerCircuitProver>;
|
|
78
|
+
} = {},
|
|
68
79
|
) {
|
|
69
80
|
const directoriesToCleanup: string[] = [];
|
|
70
|
-
const globalVariables = makeGlobals(blockNumber);
|
|
71
81
|
|
|
72
82
|
const feePayer = AztecAddress.fromNumber(42222);
|
|
73
83
|
const initialFeePayerBalance = new Fr(10n ** 20n);
|
|
@@ -76,25 +86,10 @@ export class TestContext {
|
|
|
76
86
|
|
|
77
87
|
// Separated dbs for public processor and prover - see public_processor for context
|
|
78
88
|
const ws = await NativeWorldStateService.tmp(
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
/*rollupAddress=*/ undefined,
|
|
90
|
+
/*cleanupTmpDir=*/ true,
|
|
81
91
|
prefilledPublicData,
|
|
82
92
|
);
|
|
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
93
|
|
|
99
94
|
let localProver: ServerCircuitProver;
|
|
100
95
|
const config = await getEnvironmentConfig(logger);
|
|
@@ -107,6 +102,8 @@ export class TestContext {
|
|
|
107
102
|
bbBinaryPath: config.expectedBBPath,
|
|
108
103
|
bbWorkingDirectory: config.bbWorkingDirectory,
|
|
109
104
|
bbSkipCleanup: config.bbSkipCleanup,
|
|
105
|
+
numConcurrentIVCVerifiers: 2,
|
|
106
|
+
bbIVCConcurrency: 1,
|
|
110
107
|
};
|
|
111
108
|
localProver = await createProver(bbConfig);
|
|
112
109
|
}
|
|
@@ -117,25 +114,20 @@ export class TestContext {
|
|
|
117
114
|
|
|
118
115
|
const broker = new TestBroker(proverCount, localProver);
|
|
119
116
|
const facade = new BrokerCircuitProverFacade(broker);
|
|
120
|
-
const orchestrator = new TestProvingOrchestrator(ws, facade,
|
|
117
|
+
const orchestrator = new TestProvingOrchestrator(ws, facade, EthAddress.ZERO);
|
|
121
118
|
|
|
122
119
|
await broker.start();
|
|
123
120
|
facade.start();
|
|
124
121
|
|
|
125
122
|
return new this(
|
|
126
|
-
publicTxSimulator,
|
|
127
123
|
ws,
|
|
128
|
-
processor,
|
|
129
|
-
globalVariables,
|
|
130
124
|
localProver,
|
|
131
125
|
broker,
|
|
132
126
|
facade,
|
|
133
127
|
orchestrator,
|
|
134
|
-
blockNumber,
|
|
135
128
|
feePayer,
|
|
136
129
|
initialFeePayerBalance,
|
|
137
130
|
directoriesToCleanup,
|
|
138
|
-
tester,
|
|
139
131
|
logger,
|
|
140
132
|
);
|
|
141
133
|
}
|
|
@@ -144,16 +136,6 @@ export class TestContext {
|
|
|
144
136
|
return this.worldState.fork();
|
|
145
137
|
}
|
|
146
138
|
|
|
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
139
|
async cleanup() {
|
|
158
140
|
await this.brokerProverFacade.stop();
|
|
159
141
|
await this.broker.stop();
|
|
@@ -166,77 +148,195 @@ export class TestContext {
|
|
|
166
148
|
}
|
|
167
149
|
}
|
|
168
150
|
|
|
169
|
-
public
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
151
|
+
public startNewEpoch() {
|
|
152
|
+
this.checkpoints = [];
|
|
153
|
+
this.nextCheckpointIndex = 0;
|
|
154
|
+
this.epochNumber++;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Return blob fields of all checkpoints in the epoch.
|
|
158
|
+
public getBlobFields() {
|
|
159
|
+
return this.checkpoints.map(checkpoint => checkpoint.toBlobFields());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public async getFinalBlobChallenges() {
|
|
163
|
+
const blobFields = this.getBlobFields();
|
|
164
|
+
return await buildFinalBlobChallenges(blobFields);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public async makeCheckpoint(
|
|
168
|
+
numBlocks: number,
|
|
169
|
+
{
|
|
170
|
+
numTxsPerBlock = 0,
|
|
171
|
+
numL1ToL2Messages = 0,
|
|
172
|
+
makeProcessedTxOpts = () => ({}),
|
|
173
|
+
...constantOpts
|
|
174
|
+
}: {
|
|
175
|
+
numTxsPerBlock?: number | number[];
|
|
176
|
+
numL1ToL2Messages?: number;
|
|
177
|
+
makeProcessedTxOpts?: (
|
|
178
|
+
blockGlobalVariables: GlobalVariables,
|
|
179
|
+
txIndex: number,
|
|
180
|
+
) => Partial<Parameters<typeof mockProcessedTx>[0]>;
|
|
181
|
+
} & Partial<FieldsOf<CheckpointConstantData>> = {},
|
|
182
|
+
) {
|
|
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.
|
|
198
|
+
const l1ToL2Messages = times(numL1ToL2Messages, i => new Fr(slotNumber * 100 + i));
|
|
199
|
+
await fork.appendLeaves(
|
|
200
|
+
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
201
|
+
padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
202
|
+
);
|
|
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));
|
|
207
|
+
|
|
208
|
+
// Build global variables.
|
|
209
|
+
const blockGlobalVariables = times(numBlocks, i =>
|
|
210
|
+
makeGlobals(startBlockNumber + i, slotNumber, {
|
|
211
|
+
coinbase: constants.coinbase,
|
|
212
|
+
feeRecipient: constants.feeRecipient,
|
|
213
|
+
gasFees: constants.gasFees,
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
this.nextBlockNumber += numBlocks;
|
|
217
|
+
|
|
218
|
+
// Build txs.
|
|
219
|
+
let totalTxs = 0;
|
|
220
|
+
const blockEndStates: StateReference[] = [];
|
|
221
|
+
const blockTxs = await timesAsync(numBlocks, async blockIndex => {
|
|
222
|
+
const txIndexOffset = totalTxs;
|
|
223
|
+
const numTxs = typeof numTxsPerBlock === 'number' ? numTxsPerBlock : numTxsPerBlock[blockIndex];
|
|
224
|
+
totalTxs += numTxs;
|
|
225
|
+
const txs = await timesAsync(numTxs, txIndex =>
|
|
226
|
+
this.makeProcessedTx({
|
|
227
|
+
seed: (txIndexOffset + txIndex + 1) * 321 + (checkpointIndex + 1) * 123456 + this.epochNumber * 0x99999,
|
|
228
|
+
globalVariables: blockGlobalVariables[blockIndex],
|
|
229
|
+
anchorBlockHeader: previousBlockHeader,
|
|
230
|
+
newL1ToL2Snapshot,
|
|
231
|
+
...makeProcessedTxOpts(blockGlobalVariables[blockIndex], txIndexOffset + txIndex),
|
|
232
|
+
}),
|
|
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;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const cleanFork = await this.worldState.fork();
|
|
243
|
+
const builder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
244
|
+
checkpointNumber,
|
|
245
|
+
constants,
|
|
246
|
+
l1ToL2Messages,
|
|
247
|
+
cleanFork,
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// Add tx effects to db and build block headers.
|
|
251
|
+
const blocks = [];
|
|
252
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
253
|
+
const txs = blockTxs[i];
|
|
254
|
+
const state = blockEndStates[i];
|
|
255
|
+
|
|
256
|
+
const block = await builder.addBlock(blockGlobalVariables[i], txs, {
|
|
257
|
+
expectedEndState: state,
|
|
258
|
+
insertTxsEffects: true,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const header = block.header;
|
|
262
|
+
this.headers.set(block.number, header);
|
|
263
|
+
|
|
264
|
+
const blockMsgs = block.indexWithinCheckpoint === 0 ? l1ToL2Messages : [];
|
|
265
|
+
await this.worldState.handleL2BlockAndMessages(block, blockMsgs);
|
|
266
|
+
|
|
267
|
+
blocks.push({ header, txs });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const checkpoint = await builder.completeCheckpoint();
|
|
271
|
+
this.checkpoints.push(checkpoint);
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
constants,
|
|
275
|
+
header: checkpoint.header,
|
|
276
|
+
blocks,
|
|
277
|
+
l1ToL2Messages,
|
|
278
|
+
previousBlockHeader,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private async makeProcessedTx(opts: Parameters<typeof mockProcessedTx>[0] = {}): Promise<ProcessedTx> {
|
|
283
|
+
const tx = await mockProcessedTx({
|
|
179
284
|
vkTreeRoot: getVKTreeRoot(),
|
|
180
|
-
|
|
181
|
-
globalVariables: this.globalVariables,
|
|
285
|
+
protocolContracts: ProtocolContractsList,
|
|
182
286
|
feePayer: this.feePayer,
|
|
183
287
|
...opts,
|
|
184
288
|
});
|
|
289
|
+
|
|
185
290
|
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
291
|
|
|
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);
|
|
292
|
+
const feePayerSlot = await computeFeePayerBalanceLeafSlot(this.feePayer);
|
|
293
|
+
const feePaymentPublicDataWrite = new PublicDataWrite(feePayerSlot, this.feePayerBalance);
|
|
294
|
+
tx.txEffect.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
295
|
+
if (tx.avmProvingRequest) {
|
|
296
|
+
tx.avmProvingRequest.inputs.publicInputs.accumulatedData.publicDataWrites[0] = feePaymentPublicDataWrite;
|
|
297
|
+
}
|
|
208
298
|
|
|
209
|
-
|
|
210
|
-
this.headers.set(blockNum, block.header);
|
|
211
|
-
await this.worldState.handleL2BlockAndMessages(block, msgs);
|
|
212
|
-
return { block, txs, msgs };
|
|
299
|
+
return tx;
|
|
213
300
|
}
|
|
214
301
|
|
|
215
|
-
|
|
216
|
-
|
|
302
|
+
private getBlockHeader(blockNumber: BlockNumber): BlockHeader {
|
|
303
|
+
if (Number(blockNumber) > 0 && Number(blockNumber) >= this.nextBlockNumber) {
|
|
304
|
+
throw new Error(`Block header not built for block number ${blockNumber}.`);
|
|
305
|
+
}
|
|
306
|
+
return Number(blockNumber) === 0
|
|
307
|
+
? this.worldState.getCommitted().getInitialHeader()
|
|
308
|
+
: this.headers.get(Number(blockNumber))!;
|
|
217
309
|
}
|
|
218
310
|
|
|
219
|
-
|
|
220
|
-
|
|
311
|
+
private async updateTrees(txs: ProcessedTx[], fork: MerkleTreeWriteOperations) {
|
|
312
|
+
let startStateReference = await fork.getStateReference();
|
|
313
|
+
let endStateReference = startStateReference;
|
|
221
314
|
for (const tx of txs) {
|
|
222
|
-
|
|
223
|
-
await
|
|
224
|
-
|
|
315
|
+
await insertSideEffects(tx, fork);
|
|
316
|
+
endStateReference = await fork.getStateReference();
|
|
317
|
+
|
|
225
318
|
if (tx.avmProvingRequest) {
|
|
319
|
+
// Update the trees in the avm public inputs so that the proof won't fail.
|
|
320
|
+
const l1ToL2MessageTree = tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots.l1ToL2MessageTree;
|
|
226
321
|
tx.avmProvingRequest.inputs.publicInputs.startTreeSnapshots = new TreeSnapshots(
|
|
227
|
-
|
|
322
|
+
l1ToL2MessageTree,
|
|
228
323
|
startStateReference.partial.noteHashTree,
|
|
229
324
|
startStateReference.partial.nullifierTree,
|
|
230
325
|
startStateReference.partial.publicDataTree,
|
|
231
326
|
);
|
|
327
|
+
|
|
232
328
|
tx.avmProvingRequest.inputs.publicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
233
|
-
|
|
329
|
+
l1ToL2MessageTree,
|
|
234
330
|
endStateReference.partial.noteHashTree,
|
|
235
331
|
endStateReference.partial.nullifierTree,
|
|
236
332
|
endStateReference.partial.publicDataTree,
|
|
237
333
|
);
|
|
238
334
|
}
|
|
335
|
+
|
|
336
|
+
startStateReference = endStateReference;
|
|
239
337
|
}
|
|
338
|
+
|
|
339
|
+
return endStateReference;
|
|
240
340
|
}
|
|
241
341
|
}
|
|
242
342
|
|
|
@@ -245,12 +345,9 @@ class TestProvingOrchestrator extends ProvingOrchestrator {
|
|
|
245
345
|
|
|
246
346
|
// Disable this check by default, since it requires seeding world state with the block being built
|
|
247
347
|
// 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> {
|
|
348
|
+
protected override verifyBuiltBlockAgainstSyncedState(provingState: BlockProvingState): Promise<void> {
|
|
252
349
|
if (this.isVerifyBuiltBlockAgainstSyncedStateEnabled) {
|
|
253
|
-
return super.verifyBuiltBlockAgainstSyncedState(
|
|
350
|
+
return super.verifyBuiltBlockAgainstSyncedState(provingState);
|
|
254
351
|
}
|
|
255
352
|
return Promise.resolve();
|
|
256
353
|
}
|