@aztec/prover-client 0.0.1-commit.b655e406 → 0.0.1-commit.c7c42ec

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 (119) hide show
  1. package/dest/block-factory/index.d.ts +1 -1
  2. package/dest/block-factory/light.d.ts +8 -8
  3. package/dest/block-factory/light.d.ts.map +1 -1
  4. package/dest/block-factory/light.js +37 -23
  5. package/dest/config.d.ts +2 -2
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +1 -1
  8. package/dest/index.d.ts +1 -1
  9. package/dest/light/index.d.ts +2 -0
  10. package/dest/light/index.d.ts.map +1 -0
  11. package/dest/light/index.js +1 -0
  12. package/dest/light/lightweight_checkpoint_builder.d.ts +36 -0
  13. package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
  14. package/dest/light/lightweight_checkpoint_builder.js +147 -0
  15. package/dest/mocks/fixtures.d.ts +1 -4
  16. package/dest/mocks/fixtures.d.ts.map +1 -1
  17. package/dest/mocks/fixtures.js +7 -17
  18. package/dest/mocks/test_context.d.ts +27 -46
  19. package/dest/mocks/test_context.d.ts.map +1 -1
  20. package/dest/mocks/test_context.js +105 -116
  21. package/dest/orchestrator/block-building-helpers.d.ts +17 -19
  22. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  23. package/dest/orchestrator/block-building-helpers.js +86 -111
  24. package/dest/orchestrator/block-proving-state.d.ts +17 -11
  25. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  26. package/dest/orchestrator/block-proving-state.js +81 -20
  27. package/dest/orchestrator/checkpoint-proving-state.d.ts +8 -8
  28. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -1
  29. package/dest/orchestrator/checkpoint-proving-state.js +15 -16
  30. package/dest/orchestrator/epoch-proving-state.d.ts +9 -8
  31. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  32. package/dest/orchestrator/epoch-proving-state.js +3 -3
  33. package/dest/orchestrator/index.d.ts +1 -1
  34. package/dest/orchestrator/orchestrator.d.ts +10 -10
  35. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  36. package/dest/orchestrator/orchestrator.js +27 -56
  37. package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
  38. package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
  39. package/dest/orchestrator/orchestrator_metrics.js +0 -9
  40. package/dest/orchestrator/tx-proving-state.d.ts +2 -2
  41. package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
  42. package/dest/orchestrator/tx-proving-state.js +2 -11
  43. package/dest/prover-client/factory.d.ts +3 -3
  44. package/dest/prover-client/factory.d.ts.map +1 -1
  45. package/dest/prover-client/index.d.ts +1 -1
  46. package/dest/prover-client/prover-client.d.ts +3 -3
  47. package/dest/prover-client/prover-client.d.ts.map +1 -1
  48. package/dest/prover-client/server-epoch-prover.d.ts +8 -7
  49. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  50. package/dest/prover-client/server-epoch-prover.js +2 -2
  51. package/dest/proving_broker/broker_prover_facade.d.ts +20 -20
  52. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  53. package/dest/proving_broker/broker_prover_facade.js +6 -12
  54. package/dest/proving_broker/config.d.ts +12 -8
  55. package/dest/proving_broker/config.d.ts.map +1 -1
  56. package/dest/proving_broker/config.js +8 -2
  57. package/dest/proving_broker/factory.d.ts +1 -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 +3 -2
  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/gcs_proof_store.d.ts +1 -1
  64. package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +1 -1
  65. package/dest/proving_broker/proof_store/index.d.ts +1 -1
  66. package/dest/proving_broker/proof_store/inline_proof_store.d.ts +1 -1
  67. package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
  68. package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
  69. package/dest/proving_broker/proving_agent.d.ts +1 -1
  70. package/dest/proving_broker/proving_agent.d.ts.map +1 -1
  71. package/dest/proving_broker/proving_agent_instrumentation.d.ts +1 -1
  72. package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
  73. package/dest/proving_broker/proving_broker.d.ts +2 -2
  74. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  75. package/dest/proving_broker/proving_broker.js +5 -1
  76. package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
  77. package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
  78. package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
  79. package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
  80. package/dest/proving_broker/proving_broker_database/persisted.js +3 -2
  81. package/dest/proving_broker/proving_broker_database.d.ts +3 -2
  82. package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
  83. package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
  84. package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
  85. package/dest/proving_broker/proving_job_controller.d.ts +3 -2
  86. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  87. package/dest/proving_broker/proving_job_controller.js +2 -3
  88. package/dest/proving_broker/rpc.d.ts +4 -4
  89. package/dest/test/mock_proof_store.d.ts +3 -3
  90. package/dest/test/mock_proof_store.d.ts.map +1 -1
  91. package/dest/test/mock_prover.d.ts +3 -4
  92. package/dest/test/mock_prover.d.ts.map +1 -1
  93. package/dest/test/mock_prover.js +1 -1
  94. package/package.json +20 -17
  95. package/src/block-factory/light.ts +40 -43
  96. package/src/config.ts +1 -1
  97. package/src/light/index.ts +1 -0
  98. package/src/light/lightweight_checkpoint_builder.ts +198 -0
  99. package/src/mocks/fixtures.ts +7 -30
  100. package/src/mocks/test_context.ts +148 -177
  101. package/src/orchestrator/block-building-helpers.ts +125 -205
  102. package/src/orchestrator/block-proving-state.ts +103 -25
  103. package/src/orchestrator/checkpoint-proving-state.ts +24 -20
  104. package/src/orchestrator/epoch-proving-state.ts +9 -7
  105. package/src/orchestrator/orchestrator.ts +36 -68
  106. package/src/orchestrator/orchestrator_metrics.ts +1 -20
  107. package/src/orchestrator/tx-proving-state.ts +4 -18
  108. package/src/prover-client/factory.ts +6 -2
  109. package/src/prover-client/prover-client.ts +3 -2
  110. package/src/prover-client/server-epoch-prover.ts +6 -7
  111. package/src/proving_broker/broker_prover_facade.ts +23 -31
  112. package/src/proving_broker/config.ts +8 -1
  113. package/src/proving_broker/fixtures.ts +8 -3
  114. package/src/proving_broker/proving_broker.ts +5 -1
  115. package/src/proving_broker/proving_broker_database/memory.ts +2 -1
  116. package/src/proving_broker/proving_broker_database/persisted.ts +5 -4
  117. package/src/proving_broker/proving_broker_database.ts +2 -1
  118. package/src/proving_broker/proving_job_controller.ts +4 -4
  119. package/src/test/mock_prover.ts +1 -6
@@ -0,0 +1,198 @@
1
+ import { SpongeBlob, computeBlobsHashFromBlobs, encodeCheckpointEndMarker, getBlobsPerL1Block } from '@aztec/blob-lib';
2
+ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
3
+ import type { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { padArrayEnd } from '@aztec/foundation/collection';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import { createLogger } from '@aztec/foundation/log';
7
+ import { L2BlockNew } from '@aztec/stdlib/block';
8
+ import { Checkpoint } from '@aztec/stdlib/checkpoint';
9
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
10
+ import { computeCheckpointOutHash, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
11
+ import { CheckpointHeader, computeBlockHeadersHash } from '@aztec/stdlib/rollup';
12
+ import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import {
14
+ type CheckpointGlobalVariables,
15
+ ContentCommitment,
16
+ type GlobalVariables,
17
+ type ProcessedTx,
18
+ StateReference,
19
+ } from '@aztec/stdlib/tx';
20
+
21
+ import {
22
+ buildHeaderAndBodyFromTxs,
23
+ getTreeSnapshot,
24
+ insertSideEffects,
25
+ } from '../orchestrator/block-building-helpers.js';
26
+
27
+ /**
28
+ * Builds a checkpoint and its header and the blocks in it from a set of processed tx without running any circuits.
29
+ *
30
+ * It updates the l1-to-l2 message tree when starting a new checkpoint, and then updates the archive tree when each block is added.
31
+ * Finally completes the checkpoint by computing its header.
32
+ */
33
+ export class LightweightCheckpointBuilder {
34
+ private readonly logger = createLogger('lightweight-checkpoint-builder');
35
+
36
+ private lastArchives: AppendOnlyTreeSnapshot[] = [];
37
+ private spongeBlob: SpongeBlob;
38
+ private blocks: L2BlockNew[] = [];
39
+ private blobFields: Fr[] = [];
40
+
41
+ constructor(
42
+ public readonly checkpointNumber: CheckpointNumber,
43
+ public readonly constants: CheckpointGlobalVariables,
44
+ public readonly l1ToL2Messages: Fr[],
45
+ public readonly db: MerkleTreeWriteOperations,
46
+ ) {
47
+ this.spongeBlob = SpongeBlob.init();
48
+ this.logger.debug('Starting new checkpoint', { constants, l1ToL2Messages });
49
+ }
50
+
51
+ static async startNewCheckpoint(
52
+ checkpointNumber: CheckpointNumber,
53
+ constants: CheckpointGlobalVariables,
54
+ l1ToL2Messages: Fr[],
55
+ db: MerkleTreeWriteOperations,
56
+ ): Promise<LightweightCheckpointBuilder> {
57
+ // Insert l1-to-l2 messages into the tree.
58
+ await db.appendLeaves(
59
+ MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
60
+ padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
61
+ );
62
+
63
+ return new LightweightCheckpointBuilder(checkpointNumber, constants, l1ToL2Messages, db);
64
+ }
65
+
66
+ /**
67
+ * Adds a new block to the checkpoint. The tx effects must have already been inserted into the db if
68
+ * this is called after tx processing, if that's not the case, then set `insertTxsEffects` to true.
69
+ */
70
+ public async addBlock(
71
+ globalVariables: GlobalVariables,
72
+ txs: ProcessedTx[],
73
+ opts: { insertTxsEffects?: boolean; expectedEndState?: StateReference } = {},
74
+ ): Promise<L2BlockNew> {
75
+ const isFirstBlock = this.blocks.length === 0;
76
+
77
+ // Empty blocks are only allowed as the first block in a checkpoint
78
+ if (!isFirstBlock && txs.length === 0) {
79
+ throw new Error('Cannot add empty block that is not the first block in the checkpoint.');
80
+ }
81
+
82
+ if (isFirstBlock) {
83
+ this.lastArchives.push(await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db));
84
+ }
85
+
86
+ const lastArchive = this.lastArchives.at(-1)!;
87
+
88
+ if (opts.insertTxsEffects) {
89
+ this.logger.debug(
90
+ `Inserting side effects for ${txs.length} txs for block ${globalVariables.blockNumber} into db`,
91
+ { txs: txs.map(tx => tx.hash.toString()) },
92
+ );
93
+ for (const tx of txs) {
94
+ await insertSideEffects(tx, this.db);
95
+ }
96
+ }
97
+
98
+ const endState = await this.db.getStateReference();
99
+ if (opts.expectedEndState && !endState.equals(opts.expectedEndState)) {
100
+ this.logger.error('End state after processing txs does not match expected end state', {
101
+ globalVariables: globalVariables.toInspect(),
102
+ expectedEndState: opts.expectedEndState.toInspect(),
103
+ actualEndState: endState.toInspect(),
104
+ });
105
+ throw new Error(`End state does not match expected end state when building block ${globalVariables.blockNumber}`);
106
+ }
107
+
108
+ const { header, body, blockBlobFields } = await buildHeaderAndBodyFromTxs(
109
+ txs,
110
+ lastArchive,
111
+ endState,
112
+ globalVariables,
113
+ this.spongeBlob,
114
+ isFirstBlock,
115
+ );
116
+
117
+ header.state.validate();
118
+
119
+ await this.db.updateArchive(header);
120
+ const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
121
+ this.lastArchives.push(newArchive);
122
+
123
+ const indexWithinCheckpoint = this.blocks.length;
124
+ const block = new L2BlockNew(newArchive, header, body, this.checkpointNumber, indexWithinCheckpoint);
125
+ this.blocks.push(block);
126
+
127
+ await this.spongeBlob.absorb(blockBlobFields);
128
+ this.blobFields.push(...blockBlobFields);
129
+
130
+ this.logger.debug(`Built block ${header.getBlockNumber()}`, {
131
+ globalVariables: globalVariables.toInspect(),
132
+ archiveRoot: newArchive.root.toString(),
133
+ stateReference: header.state.toInspect(),
134
+ blockHash: (await block.hash()).toString(),
135
+ txs: block.body.txEffects.map(tx => tx.txHash.toString()),
136
+ });
137
+
138
+ return block;
139
+ }
140
+
141
+ async completeCheckpoint(): Promise<Checkpoint> {
142
+ if (!this.blocks.length) {
143
+ throw new Error('Cannot complete a checkpoint with no blocks');
144
+ }
145
+
146
+ const numBlobFields = this.blobFields.length + 1; // +1 for the checkpoint end marker.
147
+ const checkpointEndMarker = encodeCheckpointEndMarker({ numBlobFields });
148
+ this.blobFields.push(checkpointEndMarker);
149
+
150
+ const blocks = this.blocks;
151
+ const blockHeadersHash = await computeBlockHeadersHash(blocks.map(block => block.header));
152
+
153
+ const newArchive = this.lastArchives[this.lastArchives.length - 1];
154
+
155
+ const blobs = getBlobsPerL1Block(this.blobFields);
156
+ const blobsHash = computeBlobsHashFromBlobs(blobs);
157
+
158
+ const inHash = computeInHashFromL1ToL2Messages(this.l1ToL2Messages);
159
+
160
+ const outHash = computeCheckpointOutHash(blocks.map(block => block.body.txEffects.map(tx => tx.l2ToL1Msgs)));
161
+
162
+ const { slotNumber, coinbase, feeRecipient, gasFees } = this.constants;
163
+
164
+ // TODO(palla/mbps): Should we source this from the constants instead?
165
+ // timestamp of a checkpoint is the timestamp of the last block in the checkpoint.
166
+ const timestamp = blocks[blocks.length - 1].timestamp;
167
+
168
+ const totalManaUsed = blocks.reduce((acc, block) => acc.add(block.header.totalManaUsed), Fr.ZERO);
169
+
170
+ const header = CheckpointHeader.from({
171
+ lastArchiveRoot: this.lastArchives[0].root,
172
+ contentCommitment: new ContentCommitment(blobsHash, inHash, outHash),
173
+ blockHeadersHash,
174
+ slotNumber,
175
+ timestamp,
176
+ coinbase,
177
+ feeRecipient,
178
+ gasFees,
179
+ totalManaUsed,
180
+ });
181
+
182
+ return new Checkpoint(newArchive, header, blocks, this.checkpointNumber);
183
+ }
184
+
185
+ clone() {
186
+ const clone = new LightweightCheckpointBuilder(
187
+ this.checkpointNumber,
188
+ this.constants,
189
+ [...this.l1ToL2Messages],
190
+ this.db,
191
+ );
192
+ clone.lastArchives = [...this.lastArchives];
193
+ clone.spongeBlob = this.spongeBlob.clone();
194
+ clone.blocks = [...this.blocks];
195
+ clone.blobFields = [...this.blobFields];
196
+ return clone;
197
+ }
198
+ }
@@ -1,8 +1,7 @@
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';
7
6
  import type { FieldsOf } from '@aztec/foundation/types';
8
7
  import { fileURLToPath } from '@aztec/foundation/url';
@@ -11,10 +10,7 @@ import { protocolContractsHash } from '@aztec/protocol-contracts';
11
10
  import { type CircuitSimulator, NativeACVMSimulator, WASMSimulatorWithBlobs } from '@aztec/simulator/server';
12
11
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
12
  import { GasFees } from '@aztec/stdlib/gas';
14
- import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
15
13
  import { CheckpointConstantData } from '@aztec/stdlib/rollup';
16
- import { MerkleTreeId } from '@aztec/stdlib/trees';
17
- import type { ProcessedTx } from '@aztec/stdlib/tx';
18
14
  import { GlobalVariables } from '@aztec/stdlib/tx';
19
15
 
20
16
  import { promises as fs } from 'fs';
@@ -88,25 +84,6 @@ export async function getSimulator(
88
84
  return new WASMSimulatorWithBlobs();
89
85
  }
90
86
 
91
- // Updates the expectedDb trees based on the new note hashes, contracts, and nullifiers from these txs
92
- export const updateExpectedTreesFromTxs = async (db: MerkleTreeWriteOperations, txs: ProcessedTx[]) => {
93
- await db.appendLeaves(
94
- MerkleTreeId.NOTE_HASH_TREE,
95
- txs.flatMap(tx => padArrayEnd(tx.txEffect.noteHashes, Fr.zero(), MAX_NOTE_HASHES_PER_TX)),
96
- );
97
- await db.batchInsert(
98
- MerkleTreeId.NULLIFIER_TREE,
99
- txs.flatMap(tx => padArrayEnd(tx.txEffect.nullifiers, Fr.zero(), MAX_NULLIFIERS_PER_TX).map(x => x.toBuffer())),
100
- NULLIFIER_TREE_HEIGHT,
101
- );
102
- for (const tx of txs) {
103
- await db.sequentialInsert(
104
- MerkleTreeId.PUBLIC_DATA_TREE,
105
- tx.txEffect.publicDataWrites.map(write => write.toBuffer()),
106
- );
107
- }
108
- };
109
-
110
87
  export const makeGlobals = (
111
88
  blockNumber: number,
112
89
  slotNumber = blockNumber,
@@ -116,9 +93,9 @@ export const makeGlobals = (
116
93
  return GlobalVariables.from({
117
94
  chainId: checkpointConstants.chainId,
118
95
  version: checkpointConstants.version,
119
- blockNumber /** block number */,
120
- slotNumber: new Fr(slotNumber) /** slot number */,
121
- timestamp: BigInt(blockNumber) /** block number as pseudo-timestamp for testing */,
96
+ blockNumber: BlockNumber(blockNumber) /** block number */,
97
+ slotNumber: SlotNumber(slotNumber) /** slot number */,
98
+ timestamp: BigInt(blockNumber * 123) /** block number * 123 as pseudo-timestamp for testing */,
122
99
  coinbase: checkpointConstants.coinbase,
123
100
  feeRecipient: checkpointConstants.feeRecipient,
124
101
  gasFees: checkpointConstants.gasFees,
@@ -136,7 +113,7 @@ export const makeCheckpointConstants = (
136
113
  vkTreeRoot: getVKTreeRoot(),
137
114
  protocolContractsHash,
138
115
  proverId: Fr.ZERO,
139
- slotNumber: new Fr(slotNumber),
116
+ slotNumber: SlotNumber(slotNumber),
140
117
  coinbase: EthAddress.ZERO,
141
118
  feeRecipient: AztecAddress.ZERO,
142
119
  gasFees: GasFees.empty(),