@aztec/stdlib 4.2.0-nightly.20260319 → 4.2.0-nightly.20260321

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 (84) hide show
  1. package/dest/abi/buffer.d.ts +14 -4
  2. package/dest/abi/buffer.d.ts.map +1 -1
  3. package/dest/abi/buffer.js +25 -4
  4. package/dest/avm/avm_accumulated_data.js +2 -2
  5. package/dest/avm/avm_circuit_public_inputs.js +2 -2
  6. package/dest/block/l2_block_source.d.ts +5 -3
  7. package/dest/block/l2_block_source.d.ts.map +1 -1
  8. package/dest/checkpoint/validate.js +2 -2
  9. package/dest/epoch-helpers/index.d.ts +3 -1
  10. package/dest/epoch-helpers/index.d.ts.map +1 -1
  11. package/dest/epoch-helpers/index.js +6 -0
  12. package/dest/hash/hash.d.ts +16 -1
  13. package/dest/hash/hash.d.ts.map +1 -1
  14. package/dest/hash/hash.js +24 -0
  15. package/dest/interfaces/aztec-node-admin.d.ts +1 -4
  16. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  17. package/dest/interfaces/aztec-node.d.ts +2 -1
  18. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  19. package/dest/interfaces/block-builder.d.ts +26 -7
  20. package/dest/interfaces/block-builder.d.ts.map +1 -1
  21. package/dest/interfaces/block-builder.js +1 -4
  22. package/dest/interfaces/configs.d.ts +2 -7
  23. package/dest/interfaces/configs.d.ts.map +1 -1
  24. package/dest/interfaces/configs.js +0 -1
  25. package/dest/kernel/claimed_length_array.js +1 -1
  26. package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
  27. package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
  28. package/dest/kernel/padded_side_effects.js +1 -1
  29. package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
  30. package/dest/kernel/private_to_public_accumulated_data.js +2 -2
  31. package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
  32. package/dest/logs/private_log.js +1 -1
  33. package/dest/logs/public_log.d.ts +1 -1
  34. package/dest/logs/public_log.d.ts.map +1 -1
  35. package/dest/logs/public_log.js +7 -1
  36. package/dest/noir/index.d.ts +3 -3
  37. package/dest/noir/index.d.ts.map +1 -1
  38. package/dest/parity/parity_base_private_inputs.js +1 -1
  39. package/dest/proofs/chonk_proof.d.ts +1 -1
  40. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  41. package/dest/proofs/chonk_proof.js +7 -1
  42. package/dest/rollup/base_rollup_hints.js +2 -2
  43. package/dest/rollup/block_root_rollup_private_inputs.js +5 -5
  44. package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
  45. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
  46. package/dest/rollup/root_rollup_public_inputs.js +1 -1
  47. package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
  48. package/dest/tx/protocol_contracts.js +2 -2
  49. package/dest/tx/validator/error_texts.d.ts +5 -1
  50. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  51. package/dest/tx/validator/error_texts.js +6 -0
  52. package/dest/vks/vk_data.js +1 -1
  53. package/package.json +9 -9
  54. package/src/abi/buffer.ts +25 -4
  55. package/src/avm/avm_accumulated_data.ts +6 -6
  56. package/src/avm/avm_circuit_public_inputs.ts +4 -4
  57. package/src/block/l2_block_source.ts +4 -2
  58. package/src/checkpoint/validate.ts +2 -2
  59. package/src/epoch-helpers/index.ts +11 -0
  60. package/src/hash/hash.ts +29 -0
  61. package/src/interfaces/aztec-node.ts +1 -0
  62. package/src/interfaces/block-builder.ts +27 -9
  63. package/src/interfaces/configs.ts +1 -6
  64. package/src/kernel/claimed_length_array.ts +2 -2
  65. package/src/kernel/hints/private_kernel_reset_hints.ts +5 -2
  66. package/src/kernel/hints/read_request_hints.ts +3 -3
  67. package/src/kernel/padded_side_effects.ts +3 -3
  68. package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
  69. package/src/kernel/private_to_public_accumulated_data.ts +10 -10
  70. package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
  71. package/src/logs/private_log.ts +1 -1
  72. package/src/logs/public_log.ts +11 -1
  73. package/src/noir/index.ts +2 -2
  74. package/src/parity/parity_base_private_inputs.ts +1 -1
  75. package/src/proofs/chonk_proof.ts +9 -1
  76. package/src/rollup/base_rollup_hints.ts +2 -2
  77. package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
  78. package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
  79. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
  80. package/src/rollup/root_rollup_public_inputs.ts +2 -2
  81. package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
  82. package/src/tx/protocol_contracts.ts +2 -2
  83. package/src/tx/validator/error_texts.ts +8 -0
  84. package/src/vks/vk_data.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/stdlib",
3
- "version": "4.2.0-nightly.20260319",
3
+ "version": "4.2.0-nightly.20260321",
4
4
  "type": "module",
5
5
  "inherits": [
6
6
  "../package.common.json",
@@ -90,14 +90,14 @@
90
90
  },
91
91
  "dependencies": {
92
92
  "@aws-sdk/client-s3": "^3.892.0",
93
- "@aztec/bb.js": "4.2.0-nightly.20260319",
94
- "@aztec/blob-lib": "4.2.0-nightly.20260319",
95
- "@aztec/constants": "4.2.0-nightly.20260319",
96
- "@aztec/ethereum": "4.2.0-nightly.20260319",
97
- "@aztec/foundation": "4.2.0-nightly.20260319",
98
- "@aztec/l1-artifacts": "4.2.0-nightly.20260319",
99
- "@aztec/noir-noirc_abi": "4.2.0-nightly.20260319",
100
- "@aztec/validator-ha-signer": "4.2.0-nightly.20260319",
93
+ "@aztec/bb.js": "4.2.0-nightly.20260321",
94
+ "@aztec/blob-lib": "4.2.0-nightly.20260321",
95
+ "@aztec/constants": "4.2.0-nightly.20260321",
96
+ "@aztec/ethereum": "4.2.0-nightly.20260321",
97
+ "@aztec/foundation": "4.2.0-nightly.20260321",
98
+ "@aztec/l1-artifacts": "4.2.0-nightly.20260321",
99
+ "@aztec/noir-noirc_abi": "4.2.0-nightly.20260321",
100
+ "@aztec/validator-ha-signer": "4.2.0-nightly.20260321",
101
101
  "@google-cloud/storage": "^7.15.0",
102
102
  "axios": "^1.13.5",
103
103
  "json-stringify-deterministic": "1.0.12",
package/src/abi/buffer.ts CHANGED
@@ -26,11 +26,32 @@ export function bufferAsFields(input: Buffer, targetLength: number): Fr[] {
26
26
  }
27
27
 
28
28
  /**
29
- * Recovers a buffer from an array of fields.
30
- * @param fields - An output from bufferAsFields.
31
- * @returns The recovered buffer.
29
+ * Recovers a buffer from an array of fields previously encoded with bufferAsFields.
30
+ *
31
+ * The first field encodes the byte length of the original buffer. The remaining fields
32
+ * each carry 31 bytes of payload (the leading byte of each 32-byte field element is skipped).
33
+ *
34
+ * If the declared byte length exceeds the bytes available from the payload fields, the result
35
+ * is zero-padded to the full declared length. This is important for correctness when the field
36
+ * array has been truncated (e.g. contract class logs reconstructed from blobs using a short
37
+ * emittedLength): without padding, the resulting buffer would be shorter than declared, causing
38
+ * bytecode commitment computations to diverge from what the circuit produced.
39
+ *
40
+ * @param fields - An output from bufferAsFields: [byteLength, ...payloadFields].
41
+ * @returns A buffer of exactly `byteLength` bytes.
32
42
  */
33
43
  export function bufferFromFields(fields: Fr[]): Buffer {
34
44
  const [length, ...payload] = fields;
35
- return Buffer.concat(payload.map(f => f.toBuffer().subarray(1))).subarray(0, length.toNumber());
45
+ const byteLength = length.toNumber();
46
+ const raw = Buffer.concat(payload.map(f => f.toBuffer().subarray(1)));
47
+ if (raw.length >= byteLength) {
48
+ return raw.subarray(0, byteLength);
49
+ }
50
+ // Pad with zeros if the declared length exceeds the available payload bytes.
51
+ // This ensures the returned buffer always matches the declared length, so that
52
+ // downstream bytecode commitment computations are consistent even when the
53
+ // source field array was truncated (e.g. reconstructed from blob with a short emittedLength).
54
+ const result = Buffer.alloc(byteLength);
55
+ raw.copy(result);
56
+ return result;
36
57
  }
@@ -88,11 +88,11 @@ export class AvmAccumulatedData {
88
88
  static fromBuffer(buffer: Buffer | BufferReader) {
89
89
  const reader = BufferReader.asReader(buffer);
90
90
  return new this(
91
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
92
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
93
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
91
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
92
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
93
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
94
94
  reader.readObject(FlatPublicLogs),
95
- reader.readArray(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
95
+ reader.readTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
96
96
  );
97
97
  }
98
98
 
@@ -115,9 +115,9 @@ export class AvmAccumulatedData {
115
115
  return new this(
116
116
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
117
117
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
118
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
118
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
119
119
  reader.readObject(FlatPublicLogs),
120
- reader.readArray(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
120
+ reader.readTuple(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PublicDataWrite),
121
121
  );
122
122
  }
123
123
 
@@ -143,8 +143,8 @@ export class AvmCircuitPublicInputs {
143
143
  reader.readObject(AztecAddress),
144
144
  reader.readObject(Fr),
145
145
  reader.readObject(PublicCallRequestArrayLengths),
146
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
147
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
146
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
147
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
148
148
  reader.readObject(PublicCallRequest),
149
149
  reader.readObject(PrivateToAvmAccumulatedDataArrayLengths),
150
150
  reader.readObject(PrivateToAvmAccumulatedDataArrayLengths),
@@ -206,8 +206,8 @@ export class AvmCircuitPublicInputs {
206
206
  AztecAddress.fromFields(reader),
207
207
  reader.readField(),
208
208
  PublicCallRequestArrayLengths.fromFields(reader),
209
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
210
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
209
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
210
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
211
211
  PublicCallRequest.fromFields(reader),
212
212
  PrivateToAvmAccumulatedDataArrayLengths.fromFields(reader),
213
213
  PrivateToAvmAccumulatedDataArrayLengths.fromFields(reader),
@@ -176,8 +176,10 @@ export interface L2BlockSource {
176
176
  getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined>;
177
177
 
178
178
  /**
179
- * Returns the last L2 slot number that has been fully synchronized from L1.
180
- * An L2 slot is fully synced when all L1 blocks that fall within its time range have been processed.
179
+ * Returns the last L2 slot number for which we have all L1 data needed to build the next checkpoint.
180
+ * Determined by the max of two signals: L1 block sync progress and latest synced checkpoint slot.
181
+ * The checkpoint signal handles missed L1 blocks, since a published checkpoint seals the message tree
182
+ * for the next checkpoint via the inbox LAG mechanism.
181
183
  */
182
184
  getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
183
185
 
@@ -36,7 +36,7 @@ export function validateCheckpoint(
36
36
  ): void {
37
37
  validateCheckpointStructure(checkpoint);
38
38
  validateCheckpointLimits(checkpoint, opts);
39
- validateCheckpointBlocksGasLimits(checkpoint, opts);
39
+ validateCheckpointBlocksLimits(checkpoint, opts);
40
40
  }
41
41
 
42
42
  /**
@@ -125,7 +125,7 @@ export function validateCheckpointStructure(checkpoint: Checkpoint): void {
125
125
  }
126
126
 
127
127
  /** Validates checkpoint blocks gas limits */
128
- function validateCheckpointBlocksGasLimits(
128
+ function validateCheckpointBlocksLimits(
129
129
  checkpoint: Checkpoint,
130
130
  opts: {
131
131
  maxL2BlockGas?: number;
@@ -57,6 +57,17 @@ export function getSlotAtTimestamp(
57
57
  : SlotNumber.fromBigInt((ts - constants.l1GenesisTime) / BigInt(constants.slotDuration));
58
58
  }
59
59
 
60
+ /** Returns the timestamp of the next L1 slot boundary after the given wall-clock time. */
61
+ export function getNextL1SlotTimestamp(
62
+ nowInSeconds: number,
63
+ constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'ethereumSlotDuration'>,
64
+ ): bigint {
65
+ const now = BigInt(nowInSeconds);
66
+ const elapsed = now - constants.l1GenesisTime;
67
+ const currentL1Slot = elapsed / BigInt(constants.ethereumSlotDuration);
68
+ return constants.l1GenesisTime + (currentL1Slot + 1n) * BigInt(constants.ethereumSlotDuration);
69
+ }
70
+
60
71
  /** Returns the L2 slot number at the next L1 block based on the current timestamp. */
61
72
  export function getSlotAtNextL1Block(
62
73
  currentL1Timestamp: bigint,
package/src/hash/hash.ts CHANGED
@@ -58,6 +58,35 @@ export function siloNullifier(contract: AztecAddress, innerNullifier: Fr): Promi
58
58
  return poseidon2HashWithSeparator([contract, innerNullifier], DomainSeparator.SILOED_NULLIFIER);
59
59
  }
60
60
 
61
+ /**
62
+ * Computes the siloed private initialization nullifier for a contract, given its address and initialization hash.
63
+ * @param contract - The contract address.
64
+ * @param initializationHash - The contract's initialization hash.
65
+ * @returns The siloed private initialization nullifier.
66
+ */
67
+ export async function computeSiloedPrivateInitializationNullifier(
68
+ contract: AztecAddress,
69
+ initializationHash: Fr,
70
+ ): Promise<Fr> {
71
+ const innerNullifier = await poseidon2HashWithSeparator(
72
+ [contract, initializationHash],
73
+ DomainSeparator.PRIVATE_INITIALIZATION_NULLIFIER,
74
+ );
75
+ return siloNullifier(contract, innerNullifier);
76
+ }
77
+
78
+ /**
79
+ * Computes the siloed public initialization nullifier for a contract. Not all contracts emit this nullifier: it is only
80
+ * emitted when the contract has public functions that perform initialization checks (i.e. external public functions that
81
+ * are not `#[noinitcheck]` or `#[only_self]`).
82
+ * @param contract - The contract address.
83
+ * @returns The siloed public initialization nullifier.
84
+ */
85
+ export async function computeSiloedPublicInitializationNullifier(contract: AztecAddress): Promise<Fr> {
86
+ const innerNullifier = await poseidon2HashWithSeparator([contract], DomainSeparator.PUBLIC_INITIALIZATION_NULLIFIER);
87
+ return siloNullifier(contract, innerNullifier);
88
+ }
89
+
61
90
  /**
62
91
  * Computes the protocol nullifier, which is the hash of the initial tx request siloed with the null msg sender address.
63
92
  * @param txRequestHash - The hash of the initial tx request.
@@ -122,6 +122,7 @@ export interface AztecNode
122
122
  * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
123
123
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
124
124
  * @returns The low nullifier membership witness (if found).
125
+ * @throws If the nullifier already exists in the tree, since non-inclusion cannot be proven.
125
126
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
126
127
  * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
127
128
  * we are trying to prove non-inclusion for.
@@ -35,7 +35,8 @@ export interface IBlockFactory extends ProcessedTxHandler {
35
35
  setBlockCompleted(expectedBlockHeader?: BlockHeader): Promise<L2Block>;
36
36
  }
37
37
 
38
- export interface PublicProcessorLimits {
38
+ /** Limits passed to the public processor for tx processing within a block. */
39
+ export type PublicProcessorLimits = {
39
40
  /** Maximum number of txs to process. */
40
41
  maxTransactions?: number;
41
42
  /** L2 and DA gas limits. */
@@ -46,7 +47,30 @@ export interface PublicProcessorLimits {
46
47
  deadline?: Date;
47
48
  /** Whether this processor is building a proposal (as opposed to re-executing one). Skipping txs due to gas or blob limits is only done during proposal building. */
48
49
  isBuildingProposal?: boolean;
49
- }
50
+ };
51
+
52
+ /** Base fields shared by both proposer and validator block builder options. */
53
+ type BlockBuilderOptionsBase = PublicProcessorLimits & {
54
+ /** Minimum number of successfully processed txs required. Block is rejected if fewer succeed. */
55
+ minValidTxs: number;
56
+ };
57
+
58
+ /** Proposer mode: redistribution params are required. */
59
+ type ProposerBlockBuilderOptions = BlockBuilderOptionsBase & {
60
+ isBuildingProposal: true;
61
+ /** Maximum number of blocks per checkpoint, derived from the timetable. */
62
+ maxBlocksPerCheckpoint: number;
63
+ /** Per-block gas budget multiplier. Budget = (remaining / remainingBlocks) * multiplier. */
64
+ perBlockAllocationMultiplier: number;
65
+ };
66
+
67
+ /** Validator mode: no redistribution params needed. */
68
+ type ValidatorBlockBuilderOptions = BlockBuilderOptionsBase & {
69
+ isBuildingProposal: false;
70
+ };
71
+
72
+ /** Options for building a block within a checkpoint. When proposing, redistribution params are required. */
73
+ export type BlockBuilderOptions = ProposerBlockBuilderOptions | ValidatorBlockBuilderOptions;
50
74
 
51
75
  export interface PublicProcessorValidator {
52
76
  preprocessValidator?: TxValidator<Tx>;
@@ -64,9 +88,6 @@ export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime'
64
88
  | 'maxTxsPerCheckpoint'
65
89
  | 'maxL2BlockGas'
66
90
  | 'maxDABlockGas'
67
- | 'redistributeCheckpointBudget'
68
- | 'perBlockAllocationMultiplier'
69
- | 'maxBlocksPerCheckpoint'
70
91
  >;
71
92
 
72
93
  export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[] = [
@@ -82,9 +103,6 @@ export const FullNodeBlockBuilderConfigKeys: (keyof FullNodeBlockBuilderConfig)[
82
103
  'maxL2BlockGas',
83
104
  'maxDABlockGas',
84
105
  'rollupManaLimit',
85
- 'redistributeCheckpointBudget',
86
- 'perBlockAllocationMultiplier',
87
- 'maxBlocksPerCheckpoint',
88
106
  ] as const;
89
107
 
90
108
  /** Thrown when the number of successfully processed transactions is below the required minimum. */
@@ -115,7 +133,7 @@ export interface ICheckpointBlockBuilder {
115
133
  pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
116
134
  blockNumber: BlockNumber,
117
135
  timestamp: bigint,
118
- opts: PublicProcessorLimits & { minValidTxs?: number },
136
+ opts: BlockBuilderOptions,
119
137
  ): Promise<BuildBlockInCheckpointResult>;
120
138
  }
121
139
 
@@ -29,8 +29,6 @@ export interface SequencerConfig {
29
29
  perBlockAllocationMultiplier?: number;
30
30
  /** Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget. */
31
31
  redistributeCheckpointBudget?: boolean;
32
- /** Computed max number of blocks per checkpoint from timetable. */
33
- maxBlocksPerCheckpoint?: number;
34
32
  /** Recipient of block reward. */
35
33
  coinbase?: EthAddress;
36
34
  /** Address to receive fees. */
@@ -99,7 +97,6 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
99
97
  maxDABlockGas: z.number().optional(),
100
98
  perBlockAllocationMultiplier: z.number().optional(),
101
99
  redistributeCheckpointBudget: z.boolean().optional(),
102
- maxBlocksPerCheckpoint: z.number().optional(),
103
100
  coinbase: schemas.EthAddress.optional(),
104
101
  feeRecipient: schemas.AztecAddress.optional(),
105
102
  acvmWorkingDirectory: z.string().optional(),
@@ -148,9 +145,7 @@ type SequencerConfigOptionalKeys =
148
145
  | 'maxTxsPerCheckpoint'
149
146
  | 'maxL2BlockGas'
150
147
  | 'maxDABlockGas'
151
- | 'perBlockAllocationMultiplier'
152
- | 'redistributeCheckpointBudget'
153
- | 'maxBlocksPerCheckpoint';
148
+ | 'redistributeCheckpointBudget';
154
149
 
155
150
  export type ResolvedSequencerConfig = Prettify<
156
151
  Required<Omit<SequencerConfig, SequencerConfigOptionalKeys>> & Pick<SequencerConfig, SequencerConfigOptionalKeys>
@@ -25,7 +25,7 @@ export class ClaimedLengthArray<T extends Serializable, N extends number> {
25
25
  arrayLength: N,
26
26
  ): ClaimedLengthArray<T, N> {
27
27
  const reader = BufferReader.asReader(buffer);
28
- const array = reader.readArray(arrayLength, deserializer);
28
+ const array = reader.readArray(arrayLength, deserializer) as Tuple<T, N>;
29
29
  const claimedLength = reader.readNumber();
30
30
  return new ClaimedLengthArray(array, claimedLength);
31
31
  }
@@ -42,7 +42,7 @@ export class ClaimedLengthArray<T extends Serializable, N extends number> {
42
42
  arrayLength: N,
43
43
  ): ClaimedLengthArray<T, N> {
44
44
  const reader = FieldReader.asReader(fields);
45
- const array = reader.readArray(arrayLength, deserializer);
45
+ const array = reader.readTuple(arrayLength, deserializer);
46
46
  const claimedLength = reader.readU32();
47
47
  return new ClaimedLengthArray(array, claimedLength);
48
48
  }
@@ -105,8 +105,11 @@ export class PrivateKernelResetHints<
105
105
  fromBuffer: buf =>
106
106
  nullifierReadRequestHintsFromBuffer(buf, numNullifierReadRequestPending, numNullifierReadRequestSettled),
107
107
  }),
108
- reader.readArray(numKeyValidationHints, KeyValidationHint),
109
- reader.readArray(numTransientDataSquashingHints, TransientDataSquashingHint),
108
+ reader.readArray(numKeyValidationHints, KeyValidationHint) as Tuple<KeyValidationHint, KEY_VALIDATION_HINTS_LEN>,
109
+ reader.readArray(numTransientDataSquashingHints, TransientDataSquashingHint) as Tuple<
110
+ TransientDataSquashingHint,
111
+ TRANSIENT_DATA_HINTS_LEN
112
+ >,
110
113
  );
111
114
  }
112
115
  }
@@ -158,11 +158,11 @@ export class ReadRequestResetHints<
158
158
  > {
159
159
  const reader = BufferReader.asReader(buffer);
160
160
  return new ReadRequestResetHints(
161
- reader.readArray(readRequestLen, ReadRequestAction),
162
- reader.readArray(numPendingReads, PendingReadHint),
161
+ reader.readArray(readRequestLen, ReadRequestAction) as Tuple<ReadRequestAction, READ_REQUEST_LEN>,
162
+ reader.readArray(numPendingReads, PendingReadHint) as Tuple<PendingReadHint, PENDING_READ_HINTS_LEN>,
163
163
  reader.readArray(numSettledReads, {
164
164
  fromBuffer: r => SettledReadHint.fromBuffer(r, treeHeight, leafPreimageFromBuffer),
165
- }),
165
+ }) as Tuple<SettledReadHint<TREE_HEIGHT, LEAF_PREIMAGE>, SETTLED_READ_HINTS_LEN>,
166
166
  );
167
167
  }
168
168
 
@@ -19,9 +19,9 @@ export class PaddedSideEffects {
19
19
  static fromBuffer(buffer: Buffer | BufferReader) {
20
20
  const reader = BufferReader.asReader(buffer);
21
21
  return new PaddedSideEffects(
22
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
23
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
24
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
22
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
23
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
24
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
25
25
  );
26
26
  }
27
27
 
@@ -73,7 +73,7 @@ export class PrivateToAvmAccumulatedData {
73
73
  return new this(
74
74
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
75
75
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
76
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
76
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
77
77
  );
78
78
  }
79
79
 
@@ -94,9 +94,9 @@ export class PrivateToAvmAccumulatedData {
94
94
  static fromBuffer(buffer: Buffer | BufferReader) {
95
95
  const reader = BufferReader.asReader(buffer);
96
96
  return new PrivateToAvmAccumulatedData(
97
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
98
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
99
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
97
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
98
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
99
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
100
100
  );
101
101
  }
102
102
 
@@ -62,10 +62,10 @@ export class PrivateToPublicAccumulatedData {
62
62
  return new this(
63
63
  reader.readFieldArray(MAX_NOTE_HASHES_PER_TX),
64
64
  reader.readFieldArray(MAX_NULLIFIERS_PER_TX),
65
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
66
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
67
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
68
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
65
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
66
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
67
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
68
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
69
69
  );
70
70
  }
71
71
 
@@ -76,12 +76,12 @@ export class PrivateToPublicAccumulatedData {
76
76
  static fromBuffer(buffer: Buffer | BufferReader) {
77
77
  const reader = BufferReader.asReader(buffer);
78
78
  return new PrivateToPublicAccumulatedData(
79
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
80
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
81
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
82
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
83
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
84
- reader.readArray(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
79
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
80
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
81
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
82
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
83
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
84
+ reader.readTuple(MAX_ENQUEUED_CALLS_PER_TX, PublicCallRequest),
85
85
  );
86
86
  }
87
87
 
@@ -95,11 +95,11 @@ export class PrivateToRollupAccumulatedData {
95
95
  static fromBuffer(buffer: Buffer | BufferReader): PrivateToRollupAccumulatedData {
96
96
  const reader = BufferReader.asReader(buffer);
97
97
  return new PrivateToRollupAccumulatedData(
98
- reader.readArray(MAX_NOTE_HASHES_PER_TX, Fr),
99
- reader.readArray(MAX_NULLIFIERS_PER_TX, Fr),
100
- reader.readArray(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
101
- reader.readArray(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
102
- reader.readArray(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
98
+ reader.readTuple(MAX_NOTE_HASHES_PER_TX, Fr),
99
+ reader.readTuple(MAX_NULLIFIERS_PER_TX, Fr),
100
+ reader.readTuple(MAX_L2_TO_L1_MSGS_PER_TX, ScopedL2ToL1Message),
101
+ reader.readTuple(MAX_PRIVATE_LOGS_PER_TX, PrivateLog),
102
+ reader.readTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, ScopedLogHash),
103
103
  );
104
104
  }
105
105
 
@@ -73,7 +73,7 @@ export class PrivateLog {
73
73
 
74
74
  static fromBuffer(buffer: Buffer | BufferReader) {
75
75
  const reader = BufferReader.asReader(buffer);
76
- return new PrivateLog(reader.readArray(PRIVATE_LOG_SIZE_IN_FIELDS, Fr), reader.readNumber());
76
+ return new PrivateLog(reader.readTuple(PRIVATE_LOG_SIZE_IN_FIELDS, Fr), reader.readNumber());
77
77
  }
78
78
 
79
79
  static random(tag = Fr.random()) {
@@ -1,4 +1,8 @@
1
- import { FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH, PUBLIC_LOG_HEADER_LENGTH } from '@aztec/constants';
1
+ import {
2
+ FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH,
3
+ MAX_PUBLIC_LOG_SIZE_IN_FIELDS,
4
+ PUBLIC_LOG_HEADER_LENGTH,
5
+ } from '@aztec/constants';
2
6
  import type { FieldsOf } from '@aztec/foundation/array';
3
7
  import { Fr } from '@aztec/foundation/curves/bn254';
4
8
  import { type ZodFor, schemas } from '@aztec/foundation/schemas';
@@ -76,6 +80,9 @@ export class FlatPublicLogs {
76
80
  static fromBuffer(buffer: Buffer | BufferReader) {
77
81
  const reader = BufferReader.asReader(buffer);
78
82
  const length = reader.readNumber();
83
+ if (length > FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH) {
84
+ throw new Error(`FlatPublicLogs length ${length} exceeds maximum ${FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH}`);
85
+ }
79
86
  return this.fromUnpaddedPayload(reader.readArray(length, Fr));
80
87
  }
81
88
 
@@ -171,6 +178,9 @@ export class PublicLog {
171
178
  static fromBuffer(buffer: Buffer | BufferReader) {
172
179
  const reader = BufferReader.asReader(buffer);
173
180
  const fieldsLength = reader.readNumber();
181
+ if (fieldsLength > MAX_PUBLIC_LOG_SIZE_IN_FIELDS) {
182
+ throw new Error(`PublicLog fields length ${fieldsLength} exceeds maximum ${MAX_PUBLIC_LOG_SIZE_IN_FIELDS}`);
183
+ }
174
184
  return new PublicLog(reader.readObject(AztecAddress), reader.readArray(fieldsLength, Fr));
175
185
  }
176
186
 
package/src/noir/index.ts CHANGED
@@ -19,7 +19,7 @@ export const AZTEC_VIEW_ATTRIBUTE = 'abi_view';
19
19
  export interface NoirFunctionAbi {
20
20
  /** The parameters of the function. */
21
21
  parameters: ABIParameter[];
22
- /** The return type of the function. */
22
+ /** The return type of the function, or null for void functions. */
23
23
  return_type: {
24
24
  /**
25
25
  * The type of the return value.
@@ -29,7 +29,7 @@ export interface NoirFunctionAbi {
29
29
  * The visibility of the return value.
30
30
  */
31
31
  visibility: ABIParameterVisibility;
32
- };
32
+ } | null;
33
33
  /** Mapping of error selector => error type */
34
34
  error_types: Partial<Record<string, AbiErrorType>>;
35
35
  }
@@ -41,7 +41,7 @@ export class ParityBasePrivateInputs {
41
41
  */
42
42
  static fromBuffer(buffer: Buffer | BufferReader) {
43
43
  const reader = BufferReader.asReader(buffer);
44
- return new ParityBasePrivateInputs(reader.readArray(NUM_MSGS_PER_BASE_PARITY, Fr), Fr.fromBuffer(reader));
44
+ return new ParityBasePrivateInputs(reader.readTuple(NUM_MSGS_PER_BASE_PARITY, Fr), Fr.fromBuffer(reader));
45
45
  }
46
46
 
47
47
  /**
@@ -56,7 +56,10 @@ export class ChonkProof {
56
56
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProof {
57
57
  const reader = BufferReader.asReader(buffer);
58
58
  const proofLength = reader.readNumber();
59
- const proof = reader.readArray(proofLength, Fr);
59
+ if (proofLength !== CHONK_PROOF_LENGTH) {
60
+ throw new Error(`Invalid ChonkProof length from buffer: ${proofLength}, expected ${CHONK_PROOF_LENGTH}`);
61
+ }
62
+ const proof = reader.readArray(CHONK_PROOF_LENGTH, Fr);
60
63
  return new ChonkProof(proof);
61
64
  }
62
65
 
@@ -106,6 +109,11 @@ export class ChonkProofWithPublicInputs {
106
109
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProofWithPublicInputs {
107
110
  const reader = BufferReader.asReader(buffer);
108
111
  const proofLength = reader.readNumber();
112
+ if (proofLength < CHONK_PROOF_LENGTH) {
113
+ throw new Error(
114
+ `Invalid ChonkProofWithPublicInputs length from buffer: ${proofLength}, expected at least ${CHONK_PROOF_LENGTH}`,
115
+ );
116
+ }
109
117
  const proof = reader.readArray(proofLength, Fr);
110
118
  return new ChonkProofWithPublicInputs(proof);
111
119
  }
@@ -86,7 +86,7 @@ export class PrivateBaseRollupHints {
86
86
  reader.readObject(SpongeBlob),
87
87
  reader.readObject(TreeSnapshotDiffHints),
88
88
  reader.readObject(PublicDataTreeLeafPreimage),
89
- reader.readArray(ARCHIVE_HEIGHT, Fr),
89
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
90
90
  makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, () => reader.readObject(ContractClassLogFields)),
91
91
  reader.readObject(BlockConstantData),
92
92
  );
@@ -163,7 +163,7 @@ export class PublicBaseRollupHints {
163
163
  return new PublicBaseRollupHints(
164
164
  reader.readObject(SpongeBlob),
165
165
  reader.readObject(AppendOnlyTreeSnapshot),
166
- reader.readArray(ARCHIVE_HEIGHT, Fr),
166
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
167
167
  makeTuple(MAX_CONTRACT_CLASS_LOGS_PER_TX, () => reader.readObject(ContractClassLogFields)),
168
168
  );
169
169
  }
@@ -60,8 +60,8 @@ export class BlockRootFirstRollupPrivateInputs {
60
60
  ProofData.fromBuffer(reader, ParityPublicInputs),
61
61
  [ProofData.fromBuffer(reader, TxRollupPublicInputs), ProofData.fromBuffer(reader, TxRollupPublicInputs)],
62
62
  AppendOnlyTreeSnapshot.fromBuffer(reader),
63
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
64
- reader.readArray(ARCHIVE_HEIGHT, Fr),
63
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
64
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
65
65
  );
66
66
  }
67
67
 
@@ -124,8 +124,8 @@ export class BlockRootSingleTxFirstRollupPrivateInputs {
124
124
  ProofData.fromBuffer(reader, ParityPublicInputs),
125
125
  ProofData.fromBuffer(reader, TxRollupPublicInputs),
126
126
  AppendOnlyTreeSnapshot.fromBuffer(reader),
127
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
128
- reader.readArray(ARCHIVE_HEIGHT, Fr),
127
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
128
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
129
129
  );
130
130
  }
131
131
 
@@ -206,8 +206,8 @@ export class BlockRootEmptyTxFirstRollupPrivateInputs {
206
206
  StateReference.fromBuffer(reader),
207
207
  CheckpointConstantData.fromBuffer(reader),
208
208
  reader.readUInt64(),
209
- reader.readArray(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
210
- reader.readArray(ARCHIVE_HEIGHT, Fr),
209
+ reader.readTuple(L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH, Fr),
210
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
211
211
  );
212
212
  }
213
213
 
@@ -248,7 +248,7 @@ export class BlockRootRollupPrivateInputs {
248
248
  const reader = BufferReader.asReader(buffer);
249
249
  return new BlockRootRollupPrivateInputs(
250
250
  [ProofData.fromBuffer(reader, TxRollupPublicInputs), ProofData.fromBuffer(reader, TxRollupPublicInputs)],
251
- reader.readArray(ARCHIVE_HEIGHT, Fr),
251
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
252
252
  );
253
253
  }
254
254
 
@@ -289,7 +289,7 @@ export class BlockRootSingleTxRollupPrivateInputs {
289
289
  const reader = BufferReader.asReader(buffer);
290
290
  return new BlockRootSingleTxRollupPrivateInputs(
291
291
  ProofData.fromBuffer(reader, TxRollupPublicInputs),
292
- reader.readArray(ARCHIVE_HEIGHT, Fr),
292
+ reader.readTuple(ARCHIVE_HEIGHT, Fr),
293
293
  );
294
294
  }
295
295
 
@@ -65,8 +65,8 @@ export class CheckpointRollupPublicInputs {
65
65
  reader.readObject(AppendOnlyTreeSnapshot),
66
66
  reader.readObject(AppendOnlyTreeSnapshot),
67
67
  reader.readObject(AppendOnlyTreeSnapshot),
68
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, Fr),
69
- reader.readArray(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
68
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, Fr),
69
+ reader.readTuple(MAX_CHECKPOINTS_PER_EPOCH, FeeRecipient),
70
70
  reader.readObject(BlobAccumulator),
71
71
  reader.readObject(BlobAccumulator),
72
72
  reader.readObject(FinalBlobBatchingChallenges),