@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.21caa21

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