@aztec/stdlib 4.0.0-nightly.20260119 → 4.0.0-nightly.20260121

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 (88) hide show
  1. package/dest/avm/avm.d.ts +300 -300
  2. package/dest/block/block_hash.d.ts +7 -1
  3. package/dest/block/block_hash.d.ts.map +1 -1
  4. package/dest/block/block_hash.js +12 -0
  5. package/dest/block/block_parameter.d.ts +4 -3
  6. package/dest/block/block_parameter.d.ts.map +1 -1
  7. package/dest/block/block_parameter.js +2 -0
  8. package/dest/block/checkpointed_l2_block.d.ts +10 -127
  9. package/dest/block/checkpointed_l2_block.d.ts.map +1 -1
  10. package/dest/block/checkpointed_l2_block.js +2 -41
  11. package/dest/block/in_block.d.ts +3 -3
  12. package/dest/block/in_block.d.ts.map +1 -1
  13. package/dest/block/index.d.ts +1 -3
  14. package/dest/block/index.d.ts.map +1 -1
  15. package/dest/block/index.js +0 -2
  16. package/dest/block/l2_block_new.d.ts +11 -9
  17. package/dest/block/l2_block_new.d.ts.map +1 -1
  18. package/dest/block/l2_block_new.js +5 -5
  19. package/dest/block/l2_block_source.d.ts +20 -11
  20. package/dest/block/l2_block_source.d.ts.map +1 -1
  21. package/dest/checkpoint/checkpoint.d.ts +10 -8
  22. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  23. package/dest/checkpoint/checkpoint.js +2 -2
  24. package/dest/checkpoint/published_checkpoint.d.ts +11 -9
  25. package/dest/checkpoint/published_checkpoint.d.ts.map +1 -1
  26. package/dest/interfaces/archiver.d.ts +1 -1
  27. package/dest/interfaces/archiver.d.ts.map +1 -1
  28. package/dest/interfaces/archiver.js +9 -8
  29. package/dest/interfaces/aztec-node.d.ts +35 -40
  30. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  31. package/dest/interfaces/aztec-node.js +6 -8
  32. package/dest/interfaces/block-builder.d.ts +18 -17
  33. package/dest/interfaces/block-builder.d.ts.map +1 -1
  34. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +1 -1
  35. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
  36. package/dest/kernel/hints/build_note_hash_read_request_hints.js +16 -6
  37. package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts +1 -1
  38. package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts.map +1 -1
  39. package/dest/kernel/hints/build_nullifier_read_request_hints.js +14 -4
  40. package/dest/p2p/block_proposal.d.ts +9 -9
  41. package/dest/p2p/block_proposal.d.ts.map +1 -1
  42. package/dest/p2p/block_proposal.js +6 -5
  43. package/dest/p2p/checkpoint_proposal.d.ts +4 -4
  44. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  45. package/dest/p2p/checkpoint_proposal.js +3 -3
  46. package/dest/p2p/consensus_payload.d.ts +1 -3
  47. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  48. package/dest/p2p/consensus_payload.js +0 -3
  49. package/dest/tests/factories.d.ts +2 -4
  50. package/dest/tests/factories.d.ts.map +1 -1
  51. package/dest/tests/factories.js +3 -13
  52. package/dest/tests/jest.d.ts +4 -4
  53. package/dest/tests/jest.js +9 -9
  54. package/dest/tests/mocks.d.ts +12 -12
  55. package/dest/tests/mocks.d.ts.map +1 -1
  56. package/dest/tests/mocks.js +33 -21
  57. package/package.json +9 -9
  58. package/src/block/block_hash.ts +22 -0
  59. package/src/block/block_parameter.ts +4 -2
  60. package/src/block/checkpointed_l2_block.ts +2 -53
  61. package/src/block/in_block.ts +2 -2
  62. package/src/block/index.ts +0 -2
  63. package/src/block/l2_block_new.ts +14 -7
  64. package/src/block/l2_block_source.ts +21 -11
  65. package/src/checkpoint/checkpoint.ts +8 -2
  66. package/src/interfaces/archiver.ts +9 -8
  67. package/src/interfaces/aztec-node.ts +39 -57
  68. package/src/interfaces/block-builder.ts +33 -28
  69. package/src/kernel/hints/build_note_hash_read_request_hints.ts +17 -6
  70. package/src/kernel/hints/build_nullifier_read_request_hints.ts +22 -10
  71. package/src/p2p/block_proposal.ts +10 -10
  72. package/src/p2p/checkpoint_proposal.ts +4 -4
  73. package/src/p2p/consensus_payload.ts +0 -5
  74. package/src/tests/factories.ts +2 -25
  75. package/src/tests/jest.ts +9 -9
  76. package/src/tests/mocks.ts +35 -28
  77. package/dest/block/l2_block.d.ts +0 -150
  78. package/dest/block/l2_block.d.ts.map +0 -1
  79. package/dest/block/l2_block.js +0 -201
  80. package/dest/block/l2_block_code_to_purge.d.ts +0 -11
  81. package/dest/block/l2_block_code_to_purge.d.ts.map +0 -1
  82. package/dest/block/l2_block_code_to_purge.js +0 -55
  83. package/dest/block/l2_block_header.d.ts +0 -106
  84. package/dest/block/l2_block_header.d.ts.map +0 -1
  85. package/dest/block/l2_block_header.js +0 -167
  86. package/src/block/l2_block.ts +0 -274
  87. package/src/block/l2_block_code_to_purge.ts +0 -81
  88. package/src/block/l2_block_header.ts +0 -268
@@ -24,9 +24,8 @@ import { z } from 'zod';
24
24
 
25
25
  import type { AztecAddress } from '../aztec-address/index.js';
26
26
  import { type BlockParameter, BlockParameterSchema } from '../block/block_parameter.js';
27
- import { CheckpointedL2Block, PublishedL2Block } from '../block/checkpointed_l2_block.js';
27
+ import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
28
28
  import { type DataInBlock, dataInBlockSchemaFor } from '../block/in_block.js';
29
- import { L2Block } from '../block/l2_block.js';
30
29
  import { L2BlockNew } from '../block/l2_block_new.js';
31
30
  import { type L2BlockSource, type L2Tips, L2TipsSchema } from '../block/l2_block_source.js';
32
31
  import { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
@@ -99,72 +98,63 @@ export interface AztecNode
99
98
  /**
100
99
  * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
101
100
  * the leaves were inserted.
102
- * @param blockNumber - The block number at which to get the data or 'latest' for latest data.
101
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
103
102
  * @param treeId - The tree to search in.
104
103
  * @param leafValues - The values to search for.
105
104
  * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
106
105
  */
107
106
  findLeavesIndexes(
108
- blockNumber: BlockParameter,
107
+ block: BlockParameter,
109
108
  treeId: MerkleTreeId,
110
109
  leafValues: Fr[],
111
110
  ): Promise<(DataInBlock<bigint> | undefined)[]>;
112
111
 
113
112
  /**
114
113
  * Returns a sibling path for the given index in the nullifier tree.
115
- * @param blockNumber - The block number at which to get the data.
114
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
116
115
  * @param leafIndex - The index of the leaf for which the sibling path is required.
117
116
  * @returns The sibling path for the leaf index.
118
117
  */
119
- getNullifierSiblingPath(
120
- blockNumber: BlockParameter,
121
- leafIndex: bigint,
122
- ): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>>;
118
+ getNullifierSiblingPath(block: BlockParameter, leafIndex: bigint): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>>;
123
119
 
124
120
  /**
125
121
  * Returns a sibling path for the given index in the note hash tree.
126
- * @param blockNumber - The block number at which to get the data.
122
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
127
123
  * @param leafIndex - The index of the leaf for which the sibling path is required.
128
124
  * @returns The sibling path for the leaf index.
129
125
  */
130
- getNoteHashSiblingPath(
131
- blockNumber: BlockParameter,
132
- leafIndex: bigint,
133
- ): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>>;
126
+ getNoteHashSiblingPath(block: BlockParameter, leafIndex: bigint): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>>;
134
127
 
135
128
  /**
136
129
  * Returns a sibling path for a leaf in the committed historic blocks tree.
137
- * @param blockNumber - The block number at which to get the data.
130
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
138
131
  * @param leafIndex - Index of the leaf in the tree.
139
132
  * @returns The sibling path.
140
133
  */
141
- getArchiveSiblingPath(blockNumber: BlockParameter, leafIndex: bigint): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>>;
134
+ getArchiveSiblingPath(block: BlockParameter, leafIndex: bigint): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>>;
142
135
 
143
136
  /**
144
137
  * Returns a sibling path for a leaf in the committed public data tree.
145
- * @param blockNumber - The block number at which to get the data.
138
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
146
139
  * @param leafIndex - Index of the leaf in the tree.
147
140
  * @returns The sibling path.
148
141
  */
149
142
  getPublicDataSiblingPath(
150
- blockNumber: BlockParameter,
143
+ block: BlockParameter,
151
144
  leafIndex: bigint,
152
145
  ): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>>;
153
146
 
154
147
  /**
155
148
  * Returns a nullifier membership witness for a given nullifier at a given block.
156
- * @param blockNumber - The block number at which to get the data.
149
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
157
150
  * @param nullifier - Nullifier we try to find witness for.
158
151
  * @returns The nullifier membership witness (if found).
159
152
  */
160
- getNullifierMembershipWitness(
161
- blockNumber: BlockParameter,
162
- nullifier: Fr,
163
- ): Promise<NullifierMembershipWitness | undefined>;
153
+ getNullifierMembershipWitness(block: BlockParameter, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
164
154
 
165
155
  /**
166
156
  * Returns a low nullifier membership witness for a given nullifier at a given block.
167
- * @param blockNumber - The block number at which to get the data.
157
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
168
158
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
169
159
  * @returns The low nullifier membership witness (if found).
170
160
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -172,49 +162,49 @@ export interface AztecNode
172
162
  * we are trying to prove non-inclusion for.
173
163
  */
174
164
  getLowNullifierMembershipWitness(
175
- blockNumber: BlockParameter,
165
+ block: BlockParameter,
176
166
  nullifier: Fr,
177
167
  ): Promise<NullifierMembershipWitness | undefined>;
178
168
 
179
169
  /**
180
170
  * Returns a public data tree witness for a given leaf slot at a given block.
181
- * @param blockNumber - The block number at which to get the data.
171
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
182
172
  * @param leafSlot - The leaf slot we try to find the witness for.
183
173
  * @returns The public data witness (if found).
184
174
  * @remarks The witness can be used to compute the current value of the public data tree leaf. If the low leaf preimage corresponds to an
185
175
  * "in range" slot, means that the slot doesn't exist and the value is 0. If the low leaf preimage corresponds to the exact slot, the current value
186
176
  * is contained in the leaf preimage.
187
177
  */
188
- getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
178
+ getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
189
179
 
190
180
  /**
191
181
  * Returns a membership witness for a given archive leaf at a given block.
192
- * @param blockNumber - The block number at which to get the data.
182
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
193
183
  * @param archive - The archive leaf we try to find the witness for.
194
184
  */
195
185
  getArchiveMembershipWitness(
196
- blockNumber: BlockParameter,
186
+ block: BlockParameter,
197
187
  archive: Fr,
198
188
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined>;
199
189
 
200
190
  /**
201
191
  * Returns a membership witness for a given note hash at a given block.
202
- * @param blockNumber - The block number at which to get the data.
192
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
203
193
  * @param noteHash - The note hash we try to find the witness for.
204
194
  */
205
195
  getNoteHashMembershipWitness(
206
- blockNumber: BlockParameter,
196
+ block: BlockParameter,
207
197
  noteHash: Fr,
208
198
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined>;
209
199
 
210
200
  /**
211
201
  * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
212
- * @param blockNumber - The block number at which to get the data.
202
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
213
203
  * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
214
204
  * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
215
205
  */
216
206
  getL1ToL2MessageMembershipWitness(
217
- blockNumber: BlockParameter,
207
+ block: BlockParameter,
218
208
  l1ToL2Message: Fr,
219
209
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined>;
220
210
 
@@ -238,25 +228,25 @@ export interface AztecNode
238
228
  getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]>;
239
229
 
240
230
  /**
241
- * Get a block specified by its number.
242
- * @param number - The block number being requested.
231
+ * Get a block specified by its block number or 'latest'.
232
+ * @param number - The block number or 'latest'.
243
233
  * @returns The requested block.
244
234
  */
245
- getBlock(number: BlockParameter): Promise<L2Block | undefined>;
235
+ getBlock(number: BlockParameter): Promise<L2BlockNew | undefined>;
246
236
 
247
237
  /**
248
238
  * Get a block specified by its hash.
249
239
  * @param blockHash - The block hash being requested.
250
240
  * @returns The requested block.
251
241
  */
252
- getBlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
242
+ getBlockByHash(blockHash: Fr): Promise<L2BlockNew | undefined>;
253
243
 
254
244
  /**
255
245
  * Get a block specified by its archive root.
256
246
  * @param archive - The archive root being requested.
257
247
  * @returns The requested block.
258
248
  */
259
- getBlockByArchive(archive: Fr): Promise<L2Block | undefined>;
249
+ getBlockByArchive(archive: Fr): Promise<L2BlockNew | undefined>;
260
250
 
261
251
  /**
262
252
  * Method to fetch the latest block number synchronized by the node.
@@ -289,7 +279,7 @@ export interface AztecNode
289
279
  * @param limit - The maximum number of blocks to return.
290
280
  * @returns The blocks requested.
291
281
  */
292
- getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]>;
282
+ getBlocks(from: BlockNumber, limit: number): Promise<L2BlockNew[]>;
293
283
 
294
284
  /**
295
285
  * Method to fetch the current min fees.
@@ -420,25 +410,19 @@ export interface AztecNode
420
410
  * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
421
411
  * Aztec's version of `eth_getStorageAt`.
422
412
  *
413
+ * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
423
414
  * @param contract - Address of the contract to query.
424
415
  * @param slot - Slot to query.
425
- * @param blockNumber - The block number at which to get the data or 'latest'.
426
416
  * @returns Storage value at the given contract slot.
427
417
  */
428
- getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr>;
418
+ getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr>;
429
419
 
430
420
  /**
431
- * Returns the currently committed block header.
432
- * @returns The current committed block header.
433
- */
434
- getBlockHeader(blockNumber?: BlockParameter): Promise<BlockHeader | undefined>;
435
-
436
- /**
437
- * Get a block header specified by its hash.
438
- * @param blockHash - The block hash being requested.
421
+ * Returns the block header for a given block number, block hash, or 'latest'.
422
+ * @param block - The block parameter (block number, block hash, or 'latest'). Defaults to 'latest'.
439
423
  * @returns The requested block header.
440
424
  */
441
- getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined>;
425
+ getBlockHeader(block?: BlockParameter): Promise<BlockHeader | undefined>;
442
426
 
443
427
  /**
444
428
  * Get a block header specified by its archive root.
@@ -570,11 +554,11 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
570
554
  .args(EpochNumberSchema)
571
555
  .returns(z.array(z.array(z.array(z.array(schemas.Fr))))),
572
556
 
573
- getBlock: z.function().args(BlockParameterSchema).returns(L2Block.schema.optional()),
557
+ getBlock: z.function().args(BlockParameterSchema).returns(L2BlockNew.schema.optional()),
574
558
 
575
- getBlockByHash: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
559
+ getBlockByHash: z.function().args(schemas.Fr).returns(L2BlockNew.schema.optional()),
576
560
 
577
- getBlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
561
+ getBlockByArchive: z.function().args(schemas.Fr).returns(L2BlockNew.schema.optional()),
578
562
 
579
563
  getBlockNumber: z.function().returns(BlockNumberSchema),
580
564
 
@@ -587,12 +571,12 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
587
571
  getBlocks: z
588
572
  .function()
589
573
  .args(BlockNumberPositiveSchema, z.number().gt(0).lte(MAX_RPC_BLOCKS_LEN))
590
- .returns(z.array(L2Block.schema)),
574
+ .returns(z.array(L2BlockNew.schema)),
591
575
 
592
576
  getPublishedBlocks: z
593
577
  .function()
594
578
  .args(BlockNumberPositiveSchema, z.number().gt(0).lte(MAX_RPC_BLOCKS_LEN))
595
- .returns(z.array(PublishedL2Block.schema)),
579
+ .returns(z.array(CheckpointedL2Block.schema)),
596
580
 
597
581
  getPublishedCheckpoints: z
598
582
  .function()
@@ -663,8 +647,6 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
663
647
 
664
648
  getBlockHeader: z.function().args(optional(BlockParameterSchema)).returns(BlockHeader.schema.optional()),
665
649
 
666
- getBlockHeaderByHash: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
667
-
668
650
  getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
669
651
 
670
652
  getValidatorsStats: z.function().returns(ValidatorsStatsSchema),
@@ -1,17 +1,16 @@
1
- import type { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { Timer } from '@aztec/foundation/timer';
4
3
 
5
- import type { L2Block } from '../block/l2_block.js';
4
+ import type { L2BlockNew } from '../block/l2_block_new.js';
6
5
  import type { ChainConfig, SequencerConfig } from '../config/chain-config.js';
7
6
  import type { L1RollupConstants } from '../epoch-helpers/index.js';
8
7
  import type { Gas } from '../gas/gas.js';
9
- import type { MerkleTreeWriteOperations } from '../trees/index.js';
10
8
  import type { BlockHeader } from '../tx/block_header.js';
11
- import type { GlobalVariables } from '../tx/global_variables.js';
9
+ import type { CheckpointGlobalVariables, GlobalVariables } from '../tx/global_variables.js';
12
10
  import type { FailedTx, ProcessedTx } from '../tx/processed_tx.js';
13
11
  import { Tx } from '../tx/tx.js';
14
12
  import type { TxValidator } from '../tx/validator/tx_validator.js';
13
+ import type { MerkleTreeWriteOperations } from './merkle_tree_operations.js';
15
14
  import type { ProcessedTxHandler } from './processed-tx-handler.js';
16
15
 
17
16
  /** The interface to a block builder. Generates an L2 block out of a set of processed txs. */
@@ -32,7 +31,7 @@ export interface IBlockFactory extends ProcessedTxHandler {
32
31
  /**
33
32
  * Assembles the block and updates the archive tree.
34
33
  */
35
- setBlockCompleted(expectedBlockHeader?: BlockHeader): Promise<L2Block>;
34
+ setBlockCompleted(expectedBlockHeader?: BlockHeader): Promise<L2BlockNew>;
36
35
  }
37
36
 
38
37
  export interface PublicProcessorLimits {
@@ -47,17 +46,6 @@ export interface PublicProcessorValidator {
47
46
  preprocessValidator?: TxValidator<Tx>;
48
47
  nullifierCache?: { addNullifiers: (nullifiers: Buffer[]) => void };
49
48
  }
50
- export interface BuildBlockResult {
51
- block: L2Block;
52
- publicGas: Gas;
53
- publicProcessorDuration: number;
54
- numMsgs: number;
55
- numTxs: number;
56
- failedTxs: FailedTx[];
57
- blockBuildingTimer: Timer;
58
- usedTxs: Tx[];
59
- usedTxBlobFields: number;
60
- }
61
49
 
62
50
  export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'> &
63
51
  Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> &
@@ -73,19 +61,36 @@ export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[
73
61
  'fakeThrowAfterProcessingTxCount',
74
62
  ] as const;
75
63
 
76
- export interface IFullNodeBlockBuilder {
77
- getConfig(): FullNodeBlockBuilderConfig;
78
-
79
- updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
64
+ /** Result of building a block within a checkpoint. */
65
+ export interface BuildBlockInCheckpointResult {
66
+ block: L2BlockNew;
67
+ publicGas: Gas;
68
+ publicProcessorDuration: number;
69
+ numTxs: number;
70
+ failedTxs: FailedTx[];
71
+ usedTxs: Tx[];
72
+ usedTxBlobFields: number;
73
+ }
80
74
 
75
+ /** Interface for building blocks within a checkpoint context. */
76
+ export interface ICheckpointBlockBuilder {
81
77
  buildBlock(
82
- txs: Iterable<Tx> | AsyncIterable<Tx>,
83
- l1ToL2Messages: Fr[],
84
- previousCheckpointOutHashes: Fr[],
85
- globalVariables: GlobalVariables,
86
- options: PublicProcessorLimits,
87
- fork?: MerkleTreeWriteOperations,
88
- ): Promise<BuildBlockResult>;
78
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
79
+ blockNumber: BlockNumber,
80
+ timestamp: bigint,
81
+ opts: PublicProcessorLimits,
82
+ ): Promise<BuildBlockInCheckpointResult>;
83
+ }
89
84
 
85
+ /** Interface for creating checkpoint builders. */
86
+ export interface ICheckpointsBuilder {
90
87
  getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations>;
88
+
89
+ startCheckpoint(
90
+ checkpointNumber: CheckpointNumber,
91
+ constants: CheckpointGlobalVariables,
92
+ l1ToL2Messages: Fr[],
93
+ previousCheckpointOutHashes: Fr[],
94
+ fork: MerkleTreeWriteOperations,
95
+ ): Promise<ICheckpointBlockBuilder>;
91
96
  }
@@ -76,17 +76,28 @@ export async function buildNoteHashReadRequestHintsFromResetActions<PENDING exte
76
76
  builder.addPendingReadRequest(hint.readRequestIndex, hint.pendingValueIndex);
77
77
  });
78
78
 
79
+ // Collect all settled read requests
80
+ const settledRequests: { index: number; readRequest: ScopedReadRequest }[] = [];
79
81
  for (let i = 0; i < resetActions.actions.length; i++) {
80
82
  if (resetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
81
- const readRequest = noteHashReadRequests.array[i];
82
- const membershipWitness = await oracle.getNoteHashMembershipWitness(readRequest.value);
83
- if (!membershipWitness) {
84
- throw new Error('Read request is reading an unknown note hash.');
85
- }
86
- builder.addSettledReadRequest(i, membershipWitness, readRequest.value);
83
+ settledRequests.push({ index: i, readRequest: noteHashReadRequests.array[i] });
87
84
  }
88
85
  }
89
86
 
87
+ // Fetch all membership witnesses in parallel
88
+ const membershipWitnesses = await Promise.all(
89
+ settledRequests.map(({ readRequest }) => oracle.getNoteHashMembershipWitness(readRequest.value)),
90
+ );
91
+
92
+ // Add settled read requests to builder
93
+ for (let i = 0; i < settledRequests.length; i++) {
94
+ const membershipWitness = membershipWitnesses[i];
95
+ if (!membershipWitness) {
96
+ throw new Error('Read request is reading an unknown note hash.');
97
+ }
98
+ builder.addSettledReadRequest(settledRequests[i].index, membershipWitness, settledRequests[i].readRequest.value);
99
+ }
100
+
90
101
  const noteHashMap: Map<bigint, { noteHash: ScopedNoteHash; index: number }[]> = new Map();
91
102
  noteHashes.getActiveItems().forEach((noteHash, index) => {
92
103
  const value = noteHash.value.toBigInt();
@@ -82,21 +82,33 @@ export async function buildNullifierReadRequestHintsFromResetActions<PENDING ext
82
82
  builder.addPendingReadRequest(hint.readRequestIndex, hint.pendingValueIndex);
83
83
  });
84
84
 
85
+ // Collect all settled read requests
86
+ const settledRequests: { index: number; readRequest: ScopedReadRequest }[] = [];
85
87
  for (let i = 0; i < resetActions.actions.length; i++) {
86
88
  if (resetActions.actions[i] === ReadRequestActionEnum.READ_AS_SETTLED) {
87
- const readRequest = nullifierReadRequests.array[i];
88
- const siloedValue = siloed
89
- ? readRequest.value
90
- : await siloNullifier(readRequest.contractAddress, readRequest.value);
91
- const membershipWitnessWithPreimage = await oracle.getNullifierMembershipWitness(siloedValue);
92
- builder.addSettledReadRequest(
93
- i,
94
- membershipWitnessWithPreimage.membershipWitness,
95
- membershipWitnessWithPreimage.leafPreimage,
96
- );
89
+ settledRequests.push({ index: i, readRequest: nullifierReadRequests.array[i] });
97
90
  }
98
91
  }
99
92
 
93
+ // Compute siloed values in parallel (if not already siloed)
94
+ const siloedValues = siloed
95
+ ? settledRequests.map(({ readRequest }) => readRequest.value)
96
+ : await Promise.all(
97
+ settledRequests.map(({ readRequest }) => siloNullifier(readRequest.contractAddress, readRequest.value)),
98
+ );
99
+
100
+ // Fetch all membership witnesses in parallel
101
+ const membershipWitnesses = await Promise.all(siloedValues.map(value => oracle.getNullifierMembershipWitness(value)));
102
+
103
+ // Add settled read requests to builder
104
+ for (let i = 0; i < settledRequests.length; i++) {
105
+ builder.addSettledReadRequest(
106
+ settledRequests[i].index,
107
+ membershipWitnesses[i].membershipWitness,
108
+ membershipWitnesses[i].leafPreimage,
109
+ );
110
+ }
111
+
100
112
  return builder.toHints();
101
113
  }
102
114
 
@@ -1,4 +1,4 @@
1
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
4
  import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
@@ -8,8 +8,8 @@ import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
9
9
  import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
10
10
 
11
- import type { L2Block } from '../block/l2_block.js';
12
11
  import type { L2BlockInfo } from '../block/l2_block_info.js';
12
+ import type { L2BlockNew } from '../block/l2_block_new.js';
13
13
  import { MAX_TXS_PER_BLOCK } from '../deserialization/index.js';
14
14
  import { BlockHeader } from '../tx/block_header.js';
15
15
  import { TxHash } from '../tx/index.js';
@@ -52,7 +52,7 @@ export class BlockProposal extends Gossipable {
52
52
  // TODO(palla/mbps): Is this really needed? Can we just derive it from the indexWithinCheckpoint of the parent block and the slot number?
53
53
  // See the block-proposal-handler, we have a lot of extra validations to check this is correct, so maybe we can avoid storing it here.
54
54
  /** Index of this block within the checkpoint (0-indexed) */
55
- public readonly indexWithinCheckpoint: number,
55
+ public readonly indexWithinCheckpoint: IndexWithinCheckpoint,
56
56
 
57
57
  /** Hash of L1 to L2 messages for this checkpoint (constant across all blocks in checkpoint) */
58
58
  public readonly inHash: Fr,
@@ -121,7 +121,7 @@ export class BlockProposal extends Gossipable {
121
121
 
122
122
  static async createProposalFromSigner(
123
123
  blockHeader: BlockHeader,
124
- indexWithinCheckpoint: number,
124
+ indexWithinCheckpoint: IndexWithinCheckpoint,
125
125
  inHash: Fr,
126
126
  archiveRoot: Fr,
127
127
  txHashes: TxHash[],
@@ -212,7 +212,7 @@ export class BlockProposal extends Gossipable {
212
212
  const reader = BufferReader.asReader(buf);
213
213
 
214
214
  const blockHeader = reader.readObject(BlockHeader);
215
- const indexWithinCheckpoint = reader.readNumber();
215
+ const indexWithinCheckpoint = IndexWithinCheckpoint(reader.readNumber());
216
216
  const inHash = reader.readObject(Fr);
217
217
  const archiveRoot = reader.readObject(Fr);
218
218
  const signature = reader.readObject(Signature);
@@ -256,13 +256,13 @@ export class BlockProposal extends Gossipable {
256
256
  }
257
257
 
258
258
  static empty(): BlockProposal {
259
- return new BlockProposal(BlockHeader.empty(), 0, Fr.ZERO, Fr.ZERO, [], Signature.empty());
259
+ return new BlockProposal(BlockHeader.empty(), IndexWithinCheckpoint(0), Fr.ZERO, Fr.ZERO, [], Signature.empty());
260
260
  }
261
261
 
262
262
  static random(): BlockProposal {
263
263
  return new BlockProposal(
264
264
  BlockHeader.random(),
265
- Math.floor(Math.random() * 5),
265
+ IndexWithinCheckpoint(Math.floor(Math.random() * 5)),
266
266
  Fr.random(),
267
267
  Fr.random(),
268
268
  [TxHash.random(), TxHash.random()],
@@ -284,11 +284,11 @@ export class BlockProposal extends Gossipable {
284
284
  /**
285
285
  * Check if this proposal matches the given block.
286
286
  * Compares the archive root and block header.
287
- * @param block - The L2Block to compare against
287
+ * @param block - The L2BlockNew to compare against
288
288
  * @returns True if the proposal matches the block
289
289
  */
290
- matchesBlock(block: L2Block): boolean {
291
- return this.archiveRoot.equals(block.archive.root) && this.blockHeader.equals(block.getBlockHeader());
290
+ matchesBlock(block: L2BlockNew): boolean {
291
+ return this.archiveRoot.equals(block.archive.root) && this.blockHeader.equals(block.header);
292
292
  }
293
293
 
294
294
  /**
@@ -1,4 +1,4 @@
1
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
4
4
  import { tryRecoverAddress } from '@aztec/foundation/crypto/secp256k1-signer';
@@ -42,7 +42,7 @@ export type CheckpointLastBlockData = {
42
42
  /** The per-block header for the last block in the checkpoint */
43
43
  blockHeader: BlockHeader;
44
44
  /** Index of this block within the checkpoint (should be the last index, e.g., numBlocks - 1) */
45
- indexWithinCheckpoint: number; // REFACTOR(palla): Use branded type
45
+ indexWithinCheckpoint: IndexWithinCheckpoint;
46
46
  /** The sequence of transactions in the last block */
47
47
  txHashes: TxHash[];
48
48
  /** The tx in the last block (optional, for DA guarantees) */
@@ -253,7 +253,7 @@ export class CheckpointProposal extends Gossipable {
253
253
 
254
254
  if (hasLastBlock) {
255
255
  const blockHeader = reader.readObject(BlockHeader);
256
- const indexWithinCheckpoint = reader.readNumber();
256
+ const indexWithinCheckpoint = IndexWithinCheckpoint(reader.readNumber());
257
257
  const blockSignature = reader.readObject(Signature);
258
258
  const txHashCount = reader.readNumber();
259
259
  if (txHashCount > MAX_TXS_PER_BLOCK) {
@@ -309,7 +309,7 @@ export class CheckpointProposal extends Gossipable {
309
309
  static random(): CheckpointProposal {
310
310
  return new CheckpointProposal(CheckpointHeader.random(), Fr.random(), Signature.random(), {
311
311
  blockHeader: BlockHeader.random(),
312
- indexWithinCheckpoint: Math.floor(Math.random() * 5),
312
+ indexWithinCheckpoint: IndexWithinCheckpoint(Math.floor(Math.random() * 5)),
313
313
  txHashes: [TxHash.random(), TxHash.random()],
314
314
  signature: Signature.random(),
315
315
  });
@@ -7,7 +7,6 @@ import type { FieldsOf } from '@aztec/foundation/types';
7
7
  import { encodeAbiParameters, parseAbiParameters } from 'viem';
8
8
  import { z } from 'zod';
9
9
 
10
- import type { L2Block } from '../block/l2_block.js';
11
10
  import type { Checkpoint } from '../checkpoint/checkpoint.js';
12
11
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
13
12
  import type { CheckpointProposal, CheckpointProposalCore } from './checkpoint_proposal.js';
@@ -76,10 +75,6 @@ export class ConsensusPayload implements Signable {
76
75
  return new ConsensusPayload(fields.header, fields.archive);
77
76
  }
78
77
 
79
- static fromBlock(block: L2Block): ConsensusPayload {
80
- return new ConsensusPayload(block.header.toCheckpointHeader(), block.archive.root);
81
- }
82
-
83
78
  static fromCheckpoint(checkpoint: Checkpoint): ConsensusPayload {
84
79
  return new ConsensusPayload(checkpoint.header, checkpoint.archive.root);
85
80
  }
@@ -87,7 +87,6 @@ import {
87
87
  import { PublicDataRead } from '../avm/public_data_read.js';
88
88
  import { PublicDataWrite } from '../avm/public_data_write.js';
89
89
  import { AztecAddress } from '../aztec-address/index.js';
90
- import { L2BlockHeader } from '../block/l2_block_header.js';
91
90
  import type { L2Tips } from '../block/l2_block_source.js';
92
91
  import {
93
92
  type ContractClassPublic,
@@ -911,30 +910,7 @@ export function makeBlockHeader(
911
910
  });
912
911
  }
913
912
 
914
- export function makeL2BlockHeader(
915
- seed = 0,
916
- blockNumber?: number,
917
- slotNumber?: number,
918
- overrides: Partial<FieldsOf<L2BlockHeader>> = {},
919
- ) {
920
- return new L2BlockHeader(
921
- makeAppendOnlyTreeSnapshot(seed + 0x100),
922
- overrides?.blobsHash ?? fr(seed + 0x200),
923
- overrides?.inHash ?? fr(seed + 0x300),
924
- overrides?.epochOutHash ?? fr(seed + 0x400),
925
- overrides?.state ?? makeStateReference(seed + 0x600),
926
- makeGlobalVariables((seed += 0x700), {
927
- ...(blockNumber !== undefined ? { blockNumber: BlockNumber(blockNumber) } : {}),
928
- ...(slotNumber !== undefined ? { slotNumber: SlotNumber(slotNumber) } : {}),
929
- }),
930
- new Fr(seed + 0x800),
931
- new Fr(seed + 0x900),
932
- new Fr(seed + 0xa00),
933
- new Fr(seed + 0xb00),
934
- );
935
- }
936
-
937
- export function makeCheckpointHeader(seed = 0) {
913
+ export function makeCheckpointHeader(seed = 0, overrides: Partial<FieldsOf<CheckpointHeader>> = {}) {
938
914
  return CheckpointHeader.from({
939
915
  lastArchiveRoot: fr(seed + 0x100),
940
916
  blockHeadersHash: fr(seed + 0x150),
@@ -947,6 +923,7 @@ export function makeCheckpointHeader(seed = 0) {
947
923
  feeRecipient: makeAztecAddress(seed + 0x600),
948
924
  gasFees: makeGasFees(seed + 0x700),
949
925
  totalManaUsed: fr(seed + 0x800),
926
+ ...overrides,
950
927
  });
951
928
  }
952
929
 
package/src/tests/jest.ts CHANGED
@@ -1,26 +1,26 @@
1
- import { L2Block } from '../block/l2_block.js';
1
+ import { L2BlockNew } from '../block/l2_block_new.js';
2
2
 
3
3
  /**
4
- * Checks if two objects are the same L2Block.
4
+ * Checks if two objects are the same L2BlockNew.
5
5
  *
6
- * Sometimes we might be comparing two L2Block instances that represent the same block but one of them might not have
6
+ * Sometimes we might be comparing two L2BlockNew instances that represent the same block but one of them might not have
7
7
  * calculated and filled its `blockHash` property (which is computed on demand). This function ensures both objects
8
- * are really the same L2Block.
8
+ * are really the same L2BlockNew.
9
9
  *
10
10
  * @param a - An object
11
11
  * @param b - Another object
12
- * @returns True if both a and b are the same L2Block
12
+ * @returns True if both a and b are the same L2BlockNew
13
13
  */
14
14
  export function equalL2Blocks(a: any, b: any) {
15
- const aAsL2Block = a && a instanceof L2Block ? a : undefined;
16
- const bAsL2Block = b && b instanceof L2Block ? b : undefined;
15
+ const aAsL2Block = a && a instanceof L2BlockNew ? a : undefined;
16
+ const bAsL2Block = b && b instanceof L2BlockNew ? b : undefined;
17
17
 
18
18
  if (aAsL2Block && bAsL2Block) {
19
- // we got two L2Block instances, so we can compare them
19
+ // we got two L2BlockNew instances, so we can compare them
20
20
  // use a custom comparator because the blockHash property is lazily computed and one instance might not have it
21
21
  return aAsL2Block.toBuffer().equals(bAsL2Block.toBuffer());
22
22
  } else if (aAsL2Block || bAsL2Block) {
23
- // one value is an L2block and the other isn't. Definitely not equal.
23
+ // one value is an L2BlockNew and the other isn't. Definitely not equal.
24
24
  return false;
25
25
  } else {
26
26
  // we don't know what they are, tell Jest to keep looking