@aztec/prover-client 0.0.0-test.1 → 0.0.1-commit.017a351

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