@aztec/stdlib 0.0.1-commit.9ef841308 → 0.0.1-commit.a89ec08

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/abi/abi.d.ts +26 -191
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +45 -4
  4. package/dest/abi/selector.d.ts +2 -2
  5. package/dest/abi/selector.d.ts.map +1 -1
  6. package/dest/abi/selector.js +1 -1
  7. package/dest/avm/avm.d.ts +300 -300
  8. package/dest/avm/avm_accumulated_data.js +2 -2
  9. package/dest/avm/avm_circuit_public_inputs.js +2 -2
  10. package/dest/avm/revert_code.d.ts +8 -18
  11. package/dest/avm/revert_code.d.ts.map +1 -1
  12. package/dest/avm/revert_code.js +15 -30
  13. package/dest/block/l2_block_stream/interfaces.d.ts +6 -3
  14. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  15. package/dest/config/index.d.ts +1 -2
  16. package/dest/config/index.d.ts.map +1 -1
  17. package/dest/config/index.js +0 -1
  18. package/dest/config/sequencer-config.d.ts +1 -3
  19. package/dest/config/sequencer-config.d.ts.map +1 -1
  20. package/dest/config/sequencer-config.js +0 -1
  21. package/dest/contract/contract_address.d.ts +3 -3
  22. package/dest/contract/contract_address.js +3 -3
  23. package/dest/contract/contract_class_id.d.ts +2 -2
  24. package/dest/contract/contract_class_id.js +2 -2
  25. package/dest/contract/index.d.ts +3 -1
  26. package/dest/contract/index.d.ts.map +1 -1
  27. package/dest/contract/index.js +2 -0
  28. package/dest/contract/interfaces/contract_class.d.ts +156 -3
  29. package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
  30. package/dest/contract/interfaces/contract_class.js +28 -1
  31. package/dest/contract/private_function_membership_proof.d.ts +32 -0
  32. package/dest/contract/private_function_membership_proof.d.ts.map +1 -0
  33. package/dest/contract/private_function_membership_proof.js +124 -0
  34. package/dest/contract/utility_function_membership_proof.d.ts +27 -0
  35. package/dest/contract/utility_function_membership_proof.d.ts.map +1 -0
  36. package/dest/contract/utility_function_membership_proof.js +87 -0
  37. package/dest/file-store/factory.d.ts +3 -4
  38. package/dest/file-store/factory.d.ts.map +1 -1
  39. package/dest/file-store/factory.js +2 -2
  40. package/dest/file-store/http.d.ts +2 -9
  41. package/dest/file-store/http.d.ts.map +1 -1
  42. package/dest/file-store/http.js +9 -20
  43. package/dest/file-store/index.d.ts +1 -2
  44. package/dest/file-store/index.d.ts.map +1 -1
  45. package/dest/gas/gas_settings.d.ts +40 -3
  46. package/dest/gas/gas_settings.d.ts.map +1 -1
  47. package/dest/gas/gas_settings.js +50 -6
  48. package/dest/interfaces/aztec-node-admin.d.ts +7 -13
  49. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  50. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  51. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  52. package/dest/interfaces/aztec-node-debug.js +18 -0
  53. package/dest/interfaces/client.d.ts +2 -1
  54. package/dest/interfaces/client.d.ts.map +1 -1
  55. package/dest/interfaces/client.js +1 -0
  56. package/dest/interfaces/l2_logs_source.d.ts +3 -5
  57. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  58. package/dest/interfaces/proving-job.d.ts +200 -200
  59. package/dest/interfaces/validator.d.ts +26 -38
  60. package/dest/interfaces/validator.d.ts.map +1 -1
  61. package/dest/interfaces/validator.js +3 -2
  62. package/dest/kernel/claimed_length_array.js +1 -1
  63. package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
  64. package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
  65. package/dest/kernel/padded_side_effects.js +1 -1
  66. package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
  67. package/dest/kernel/private_to_public_accumulated_data.js +2 -2
  68. package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
  69. package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
  70. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
  71. package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
  72. package/dest/logs/private_log.js +1 -1
  73. package/dest/logs/public_log.d.ts +1 -1
  74. package/dest/logs/public_log.d.ts.map +1 -1
  75. package/dest/logs/public_log.js +7 -1
  76. package/dest/messaging/l1_to_l2_message_source.d.ts +2 -4
  77. package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
  78. package/dest/p2p/block_proposal.d.ts +2 -2
  79. package/dest/p2p/block_proposal.d.ts.map +1 -1
  80. package/dest/p2p/block_proposal.js +1 -1
  81. package/dest/p2p/checkpoint_proposal.d.ts +2 -2
  82. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  83. package/dest/p2p/checkpoint_proposal.js +1 -1
  84. package/dest/parity/parity_base_private_inputs.js +1 -1
  85. package/dest/proofs/chonk_proof.d.ts +2 -46
  86. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  87. package/dest/proofs/chonk_proof.js +15 -84
  88. package/dest/rollup/base_rollup_hints.js +2 -2
  89. package/dest/rollup/block_root_rollup_private_inputs.js +5 -5
  90. package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
  91. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
  92. package/dest/rollup/root_rollup_public_inputs.js +1 -1
  93. package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
  94. package/dest/tests/factories.d.ts +4 -2
  95. package/dest/tests/factories.d.ts.map +1 -1
  96. package/dest/tests/factories.js +28 -1
  97. package/dest/tests/mocks.d.ts +1 -1
  98. package/dest/tests/mocks.d.ts.map +1 -1
  99. package/dest/tests/mocks.js +2 -2
  100. package/dest/tx/protocol_contracts.js +2 -2
  101. package/dest/tx/simulated_tx.d.ts +29 -154
  102. package/dest/tx/simulated_tx.d.ts.map +1 -1
  103. package/dest/tx/simulated_tx.js +3 -3
  104. package/dest/tx/tx_receipt.d.ts +8 -4
  105. package/dest/tx/tx_receipt.d.ts.map +1 -1
  106. package/dest/tx/tx_receipt.js +8 -15
  107. package/dest/vks/vk_data.js +1 -1
  108. package/package.json +10 -11
  109. package/src/abi/abi.ts +67 -14
  110. package/src/abi/selector.ts +1 -1
  111. package/src/avm/avm_accumulated_data.ts +6 -6
  112. package/src/avm/avm_circuit_public_inputs.ts +4 -4
  113. package/src/avm/revert_code.ts +25 -39
  114. package/src/block/l2_block_stream/interfaces.ts +6 -2
  115. package/src/config/index.ts +0 -1
  116. package/src/config/sequencer-config.ts +0 -3
  117. package/src/contract/contract_address.ts +3 -3
  118. package/src/contract/contract_class_id.ts +2 -2
  119. package/src/contract/index.ts +2 -0
  120. package/src/contract/interfaces/contract_class.ts +82 -2
  121. package/src/contract/private_function_membership_proof.ts +167 -0
  122. package/src/contract/utility_function_membership_proof.ts +118 -0
  123. package/src/file-store/factory.ts +4 -13
  124. package/src/file-store/http.ts +10 -29
  125. package/src/file-store/index.ts +0 -1
  126. package/src/gas/gas_settings.ts +65 -12
  127. package/src/interfaces/aztec-node-debug.ts +40 -0
  128. package/src/interfaces/client.ts +1 -0
  129. package/src/interfaces/l2_logs_source.ts +1 -4
  130. package/src/interfaces/validator.ts +36 -38
  131. package/src/kernel/claimed_length_array.ts +2 -2
  132. package/src/kernel/hints/private_kernel_reset_hints.ts +5 -2
  133. package/src/kernel/hints/read_request_hints.ts +3 -3
  134. package/src/kernel/padded_side_effects.ts +3 -3
  135. package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
  136. package/src/kernel/private_to_public_accumulated_data.ts +10 -10
  137. package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
  138. package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
  139. package/src/logs/private_log.ts +1 -1
  140. package/src/logs/public_log.ts +11 -1
  141. package/src/messaging/l1_to_l2_message_source.ts +1 -3
  142. package/src/p2p/block_proposal.ts +1 -1
  143. package/src/p2p/checkpoint_proposal.ts +1 -1
  144. package/src/parity/parity_base_private_inputs.ts +1 -1
  145. package/src/proofs/chonk_proof.ts +12 -90
  146. package/src/rollup/base_rollup_hints.ts +2 -2
  147. package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
  148. package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
  149. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
  150. package/src/rollup/root_rollup_public_inputs.ts +2 -2
  151. package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
  152. package/src/tests/factories.ts +34 -1
  153. package/src/tests/mocks.ts +2 -2
  154. package/src/tx/protocol_contracts.ts +2 -2
  155. package/src/tx/simulated_tx.ts +6 -2
  156. package/src/tx/tx_receipt.ts +11 -14
  157. package/src/vks/vk_data.ts +1 -1
  158. package/dest/config/pipelining-config.d.ts +0 -19
  159. package/dest/config/pipelining-config.d.ts.map +0 -1
  160. package/dest/config/pipelining-config.js +0 -18
  161. package/dest/ha-signing/config.d.ts +0 -136
  162. package/dest/ha-signing/config.d.ts.map +0 -1
  163. package/dest/ha-signing/config.js +0 -97
  164. package/dest/ha-signing/index.d.ts +0 -4
  165. package/dest/ha-signing/index.d.ts.map +0 -1
  166. package/dest/ha-signing/index.js +0 -3
  167. package/dest/ha-signing/local_config.d.ts +0 -63
  168. package/dest/ha-signing/local_config.d.ts.map +0 -1
  169. package/dest/ha-signing/local_config.js +0 -24
  170. package/dest/ha-signing/types.d.ts +0 -85
  171. package/dest/ha-signing/types.d.ts.map +0 -1
  172. package/dest/ha-signing/types.js +0 -32
  173. package/dest/kv-store/config.d.ts +0 -17
  174. package/dest/kv-store/config.d.ts.map +0 -1
  175. package/dest/kv-store/config.js +0 -26
  176. package/dest/kv-store/index.d.ts +0 -2
  177. package/dest/kv-store/index.d.ts.map +0 -1
  178. package/dest/kv-store/index.js +0 -1
  179. package/src/config/pipelining-config.ts +0 -31
  180. package/src/ha-signing/config.ts +0 -156
  181. package/src/ha-signing/index.ts +0 -27
  182. package/src/ha-signing/local_config.ts +0 -46
  183. package/src/ha-signing/types.ts +0 -112
  184. package/src/kv-store/config.ts +0 -36
  185. package/src/kv-store/index.ts +0 -1
package/src/abi/abi.ts CHANGED
@@ -224,13 +224,20 @@ export const FunctionDebugMetadataSchema = z.object({
224
224
  acir_locations: z.record(z.number()),
225
225
  brillig_locations: z.record(z.record(z.number())),
226
226
  }),
227
- files: z.record(
228
- z.object({
229
- source: z.string(),
230
- path: z.string(),
231
- function_locations: z.array(z.object({ start: z.number(), name: z.string() })),
232
- }),
233
- ),
227
+ // `function_locations` is required in the static `DebugFileMap` type (noir-types compat), but legacy v4-next
228
+ // artifacts were compiled before this field existed — see {@link fillMissingFunctionLocations} for the full
229
+ // rationale. The preprocessor injects `[]` for missing entries so parsing succeeds; the cast restores the
230
+ // output type since `z.preprocess` widens the schema's input type to `unknown`.
231
+ files: z.preprocess(
232
+ fillMissingFunctionLocations,
233
+ z.record(
234
+ z.object({
235
+ source: z.string(),
236
+ path: z.string(),
237
+ function_locations: z.array(z.object({ start: z.number(), name: z.string() })),
238
+ }),
239
+ ),
240
+ ) as z.ZodType<DebugFileMap>,
234
241
  }) satisfies z.ZodType<FunctionDebugMetadata>;
235
242
 
236
243
  /** The artifact entry of a function. */
@@ -332,6 +339,45 @@ export type DebugFileMap = Record<
332
339
  }
333
340
  >;
334
341
 
342
+ /**
343
+ * Preprocessor for {@link FunctionDebugMetadataSchema} / {@link ContractArtifactSchema} that injects an empty
344
+ * `function_locations` array on any file map entry missing it. Invoked via `z.preprocess(...)` before the strict
345
+ * object schema runs, so legacy inputs do not fail validation.
346
+ *
347
+ * Why this exists on v4-next (and not on `next` / v5):
348
+ *
349
+ * - The Noir submodule on `next` was bumped past nightly-2026-03-19, which added `function_locations` to the
350
+ * debug file map in the Noir `@aztec/noir-types` package and to every freshly-compiled artifact's `file_map`
351
+ * entries. The matching stdlib change (making `DebugFileMap.function_locations` required) was done in one
352
+ * go on `next`, so there `function_locations` is always present both at compile time and at runtime.
353
+ *
354
+ * - On v4-next we had to cherry-pick the Noir bump (chore: Update Noir to nightly-2026-04-10 (#22393)) without
355
+ * re-running the full noir-projects compilation pipeline, so the on-disk contract and protocol-circuit
356
+ * artifacts (e.g. `yarn-project/protocol-contracts/artifacts/AuthRegistry.json`) still carry the pre-update
357
+ * `file_map` shape with only `source` + `path`. Separately, `ivc-integration` compares our `DebugFileMap`
358
+ * against the Noir-types `DebugFileMap`, which *does* require `function_locations`, so we cannot simply make
359
+ * our own field optional — that would break the structural compatibility check.
360
+ *
361
+ * - To satisfy both constraints at once we keep `function_locations` required in the static TypeScript type
362
+ * (so `ivc-integration` keeps compiling) but relax the runtime input shape via this preprocessor (so legacy
363
+ * artifacts keep parsing). Once all v4-next artifacts get regenerated with the new Noir compiler, this
364
+ * helper — and both `z.preprocess(...)` wrappers — can be removed.
365
+ */
366
+ function fillMissingFunctionLocations(val: unknown): unknown {
367
+ if (val && typeof val === 'object') {
368
+ for (const entry of Object.values(val as Record<string, unknown>)) {
369
+ if (
370
+ entry &&
371
+ typeof entry === 'object' &&
372
+ (entry as { function_locations?: unknown }).function_locations === undefined
373
+ ) {
374
+ (entry as { function_locations: FunctionLocation[] }).function_locations = [];
375
+ }
376
+ }
377
+ }
378
+ return val;
379
+ }
380
+
335
381
  /** Type representing a field layout in the storage of a contract. */
336
382
  export type FieldLayout = {
337
383
  /** Slot in which the field is stored. */
@@ -383,13 +429,20 @@ export const ContractArtifactSchema = zodFor<ContractArtifact>()(
383
429
  globals: z.record(z.array(AbiValueSchema)),
384
430
  }),
385
431
  storageLayout: z.record(z.object({ slot: schemas.Fr })),
386
- fileMap: z.record(
387
- z.coerce.number(),
388
- z.object({
389
- source: z.string(),
390
- path: z.string(),
391
- function_locations: z.array(z.object({ start: z.number(), name: z.string() })),
392
- }),
432
+ // Legacy v4-next contract artifacts (e.g. `protocol-contracts/artifacts/AuthRegistry.json`) were emitted
433
+ // before Noir started including `function_locations` in their `file_map` entries — see
434
+ // {@link fillMissingFunctionLocations} for the full rationale. The preprocessor injects `[]` for missing
435
+ // entries so parsing succeeds without weakening the static `DebugFileMap` type.
436
+ fileMap: z.preprocess(
437
+ fillMissingFunctionLocations,
438
+ z.record(
439
+ z.coerce.number(),
440
+ z.object({
441
+ source: z.string(),
442
+ path: z.string(),
443
+ function_locations: z.array(z.object({ start: z.number(), name: z.string() })),
444
+ }),
445
+ ),
393
446
  ),
394
447
  }),
395
448
  );
@@ -4,7 +4,7 @@ import { bufferToHex } from '@aztec/foundation/string';
4
4
 
5
5
  import { inspect } from 'util';
6
6
 
7
- /** A selector is the first 4 bytes of the hash of a signature. */
7
+ /** A selector is the low 4 bytes of the poseidon2 hash of a signature. */
8
8
  export abstract class Selector {
9
9
  /** The size of the selector in bytes. */
10
10
  public static SIZE = 4;
@@ -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),
@@ -5,35 +5,17 @@ import { BufferReader, FieldReader } from '@aztec/foundation/serialize';
5
5
  import { inspect } from 'util';
6
6
  import { z } from 'zod';
7
7
 
8
- /**
9
- * Tracks which revertible phases of a transaction's public execution reverted.
10
- *
11
- * A transaction executes in three sequential phases:
12
- * 1. SETUP – non-revertible; if this fails the entire transaction is rejected.
13
- * 2. APP_LOGIC – revertible; its state changes are rolled back on failure.
14
- * 3. TEARDOWN – revertible; always runs (even after app-logic revert) so the fee-payment contract can clean up.
15
- *
16
- * Only APP_LOGIC and TEARDOWN can produce a revert code. SETUP failures throw instead and discard the transaction
17
- * entirely.
18
- */
8
+ /** Whether a transaction's public execution reverted. */
19
9
  export enum RevertCodeEnum {
20
10
  /** All phases completed successfully; no state was rolled back. */
21
11
  OK = 0,
22
- /** APP_LOGIC reverted; its state changes were discarded. If present, TEARDOWN still ran and succeeded. */
23
- APP_LOGIC_REVERTED = 1,
24
- /** TEARDOWN reverted; its state changes were discarded. APP_LOGIC succeeded. */
25
- TEARDOWN_REVERTED = 2,
26
- /** Both APP_LOGIC and TEARDOWN reverted; only SETUP effects are kept. */
27
- BOTH_REVERTED = 3,
12
+ /** One or more revertible phases reverted; their state changes were discarded. */
13
+ REVERTED = 1,
28
14
  }
29
15
 
30
- function isRevertCodeEnum(value: number): value is RevertCodeEnum {
31
- return (
32
- (value as RevertCodeEnum) === RevertCodeEnum.OK ||
33
- (value as RevertCodeEnum) === RevertCodeEnum.APP_LOGIC_REVERTED ||
34
- (value as RevertCodeEnum) === RevertCodeEnum.TEARDOWN_REVERTED ||
35
- (value as RevertCodeEnum) === RevertCodeEnum.BOTH_REVERTED
36
- );
16
+ /** Returns a valid RevertCodeEnum, coercing any value >= 1 to REVERTED. */
17
+ function toRevertCodeEnum(value: number): RevertCodeEnum {
18
+ return value >= 1 ? RevertCodeEnum.REVERTED : RevertCodeEnum.OK;
37
19
  }
38
20
 
39
21
  /**
@@ -45,9 +27,13 @@ export class RevertCode {
45
27
  this.code = e.valueOf();
46
28
  }
47
29
  static readonly OK: RevertCode = new RevertCode(RevertCodeEnum.OK);
48
- static readonly APP_LOGIC_REVERTED: RevertCode = new RevertCode(RevertCodeEnum.APP_LOGIC_REVERTED);
49
- static readonly TEARDOWN_REVERTED: RevertCode = new RevertCode(RevertCodeEnum.TEARDOWN_REVERTED);
50
- static readonly BOTH_REVERTED: RevertCode = new RevertCode(RevertCodeEnum.BOTH_REVERTED);
30
+ static readonly REVERTED: RevertCode = new RevertCode(RevertCodeEnum.REVERTED);
31
+ /** @deprecated Use REVERTED instead. */
32
+ static readonly APP_LOGIC_REVERTED: RevertCode = RevertCode.REVERTED;
33
+ /** @deprecated Use REVERTED instead. */
34
+ static readonly TEARDOWN_REVERTED: RevertCode = RevertCode.REVERTED;
35
+ /** @deprecated Use REVERTED instead. */
36
+ static readonly BOTH_REVERTED: RevertCode = RevertCode.REVERTED;
51
37
 
52
38
  public getCode(): RevertCodeEnum {
53
39
  return this.code;
@@ -65,12 +51,8 @@ export class RevertCode {
65
51
  switch (this.code as RevertCodeEnum) {
66
52
  case RevertCodeEnum.OK:
67
53
  return 'OK';
68
- case RevertCodeEnum.APP_LOGIC_REVERTED:
69
- return 'Application logic reverted';
70
- case RevertCodeEnum.TEARDOWN_REVERTED:
71
- return 'Teardown reverted';
72
- case RevertCodeEnum.BOTH_REVERTED:
73
- return 'Both reverted';
54
+ case RevertCodeEnum.REVERTED:
55
+ return 'Reverted';
74
56
  default:
75
57
  return `Unknown RevertCode: ${this.code}`;
76
58
  }
@@ -81,7 +63,11 @@ export class RevertCode {
81
63
  }
82
64
 
83
65
  static get schema(): ZodFor<RevertCode> {
84
- return z.nativeEnum(RevertCodeEnum).transform(value => new RevertCode(value));
66
+ return z
67
+ .number()
68
+ .int()
69
+ .min(0)
70
+ .transform(value => new RevertCode(toRevertCodeEnum(value)));
85
71
  }
86
72
 
87
73
  /**
@@ -96,10 +82,10 @@ export class RevertCode {
96
82
  return obj;
97
83
  }
98
84
  const code = typeof obj === 'number' ? obj : (obj.code ?? obj);
99
- if (!isRevertCodeEnum(code)) {
85
+ if (typeof code !== 'number' || code < 0) {
100
86
  throw new Error(`Invalid RevertCode: ${code}`);
101
87
  }
102
- return new RevertCode(code);
88
+ return new RevertCode(toRevertCodeEnum(code));
103
89
  }
104
90
 
105
91
  /**
@@ -131,10 +117,10 @@ export class RevertCode {
131
117
  }
132
118
 
133
119
  public static fromNumber(code: number): RevertCode {
134
- if (!isRevertCodeEnum(code)) {
120
+ if (code < 0) {
135
121
  throw new Error(`Invalid RevertCode: ${code}`);
136
122
  }
137
- return new RevertCode(code);
123
+ return new RevertCode(toRevertCodeEnum(code));
138
124
  }
139
125
 
140
126
  public static fromField(field: Fr): RevertCode {
@@ -152,7 +138,7 @@ export class RevertCode {
152
138
  return RevertCode.fromNumber(code);
153
139
  }
154
140
 
155
- private static readonly NUM_OPTIONS = 4;
141
+ private static readonly NUM_OPTIONS = 2;
156
142
  static random(): RevertCode {
157
143
  return new RevertCode(Math.floor(Math.random() * RevertCode.NUM_OPTIONS));
158
144
  }
@@ -2,10 +2,14 @@ import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.
2
2
  import type { L2Block } from '../l2_block.js';
3
3
  import type { CheckpointId, L2BlockId, L2Tips } from '../l2_block_source.js';
4
4
 
5
+ /** Provides the current chain tips. Implemented by world-state, l2-tips-store, and AztecNode. */
6
+ export interface L2TipsProvider {
7
+ getL2Tips(): Promise<L2Tips>;
8
+ }
9
+
5
10
  /** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
6
- export interface L2BlockStreamLocalDataProvider {
11
+ export interface L2BlockStreamLocalDataProvider extends L2TipsProvider {
7
12
  getL2BlockHash(number: number): Promise<string | undefined>;
8
- getL2Tips(): Promise<L2Tips>;
9
13
  }
10
14
 
11
15
  /** Interface to a handler of events emitted. */
@@ -1,4 +1,3 @@
1
1
  export * from './chain-config.js';
2
2
  export * from './node-rpc-config.js';
3
- export * from './pipelining-config.js';
4
3
  export * from './sequencer-config.js';
@@ -2,9 +2,6 @@ import type { ConfigMappingsType } from '@aztec/foundation/config';
2
2
 
3
3
  import type { SequencerConfig } from '../interfaces/configs.js';
4
4
 
5
- /** Default maximum number of transactions per block. */
6
- export const DEFAULT_MAX_TXS_PER_BLOCK = 32;
7
-
8
5
  /**
9
6
  * Partial sequencer config mappings for fields that need to be shared across packages.
10
7
  * The full sequencer config mappings remain in sequencer-client, but shared fields
@@ -13,9 +13,9 @@ import type { ContractInstance } from './interfaces/contract_instance.js';
13
13
  /**
14
14
  * Returns the deployment address for a given contract instance.
15
15
  * ```
16
- * salted_initialization_hash = poseidon2(DOM_SEP__PARTIAL_ADDRESS, [salt, initialization_hash, deployer])
17
- * partial_address = poseidon2(DOM_SEP__PARTIAL_ADDRESS, [contract_class_id, salted_initialization_hash])
18
- * address = ((poseidon2(DOM_SEP__CONTRACT_ADDRESS_V1, [public_keys_hash, partial_address]) * G) + ivpk_m).x <- the x-coordinate of the address point
16
+ * salted_initialization_hash = pedersen([salt, initialization_hash, deployer], GENERATOR__SALTED_INITIALIZATION_HASH)
17
+ * partial_address = pedersen([contract_class_id, salted_initialization_hash], GENERATOR__CONTRACT_PARTIAL_ADDRESS_V1)
18
+ * address = ((poseidon2Hash([public_keys_hash, partial_address, GENERATOR__CONTRACT_ADDRESS_V1]) * G) + ivpk_m).x <- the x-coordinate of the address point
19
19
  * ```
20
20
  * @param instance - A contract instance for which to calculate the deployment address.
21
21
  */
@@ -13,10 +13,10 @@ import { computePrivateFunctionsRoot } from './private_function.js';
13
13
  *
14
14
  * ```
15
15
  * version = 1
16
- * private_function_leaves = private_functions.map(fn => poseidon2(DOM_SEP__PRIVATE_FUNCTION_LEAF, [fn.function_selector as Field, fn.vk_hash]))
16
+ * private_function_leaves = private_functions.map(fn => pedersen([fn.function_selector as Field, fn.vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF))
17
17
  * private_functions_root = merkleize(private_function_leaves)
18
18
  * bytecode_commitment = calculate_commitment(packed_bytecode)
19
- * contract_class_id = poseidon2(DOM_SEP__CONTRACT_CLASS_ID, [version, artifact_hash, private_functions_root, bytecode_commitment])
19
+ * contract_class_id = pedersen([version, artifact_hash, private_functions_root, bytecode_commitment], GENERATOR__CLASS_IDENTIFIER)
20
20
  * ```
21
21
  * @param contractClass - Contract class.
22
22
  * @returns The identifier.
@@ -6,6 +6,8 @@ export * from './contract_deployment_data.js';
6
6
  export * from './contract_instance.js';
7
7
  export * from './contract_instance_update.js';
8
8
  export * from './private_function.js';
9
+ export * from './private_function_membership_proof.js';
10
+ export * from './utility_function_membership_proof.js';
9
11
  export * from './interfaces/index.js';
10
12
  export * from './contract_function_dao.js';
11
13
  export * from './partial_address.js';
@@ -42,6 +42,79 @@ const PrivateFunctionSchema = zodFor<PrivateFunction>()(
42
42
  }),
43
43
  );
44
44
 
45
+ /** Private function definition with executable bytecode. */
46
+ export interface ExecutablePrivateFunction extends PrivateFunction {
47
+ /** ACIR and Brillig bytecode */
48
+ bytecode: Buffer;
49
+ }
50
+
51
+ const ExecutablePrivateFunctionSchema = zodFor<ExecutablePrivateFunction>()(
52
+ PrivateFunctionSchema.and(z.object({ bytecode: schemas.Buffer })),
53
+ );
54
+
55
+ /** Utility function definition. */
56
+ export interface UtilityFunction {
57
+ /** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
58
+ selector: FunctionSelector;
59
+ /** Brillig. */
60
+ bytecode: Buffer;
61
+ }
62
+
63
+ const UtilityFunctionSchema = zodFor<UtilityFunction>()(
64
+ z.object({
65
+ selector: FunctionSelector.schema,
66
+ bytecode: schemas.Buffer,
67
+ }),
68
+ );
69
+
70
+ /** Sibling paths and sibling commitments for proving membership of a private function within a contract class. */
71
+ export type PrivateFunctionMembershipProof = {
72
+ artifactMetadataHash: Fr;
73
+ functionMetadataHash: Fr;
74
+ utilityFunctionsTreeRoot: Fr;
75
+ privateFunctionTreeSiblingPath: Fr[];
76
+ privateFunctionTreeLeafIndex: number;
77
+ artifactTreeSiblingPath: Fr[];
78
+ artifactTreeLeafIndex: number;
79
+ };
80
+
81
+ const PrivateFunctionMembershipProofSchema = zodFor<PrivateFunctionMembershipProof>()(
82
+ z.object({
83
+ artifactMetadataHash: schemas.Fr,
84
+ functionMetadataHash: schemas.Fr,
85
+ utilityFunctionsTreeRoot: schemas.Fr,
86
+ privateFunctionTreeSiblingPath: z.array(schemas.Fr),
87
+ privateFunctionTreeLeafIndex: schemas.Integer,
88
+ artifactTreeSiblingPath: z.array(schemas.Fr),
89
+ artifactTreeLeafIndex: schemas.Integer,
90
+ }),
91
+ );
92
+
93
+ /** A private function with a membership proof. */
94
+ export type ExecutablePrivateFunctionWithMembershipProof = ExecutablePrivateFunction & PrivateFunctionMembershipProof;
95
+
96
+ /** Sibling paths and commitments for proving membership of a utility function within a contract class. */
97
+ export type UtilityFunctionMembershipProof = {
98
+ artifactMetadataHash: Fr;
99
+ functionMetadataHash: Fr;
100
+ privateFunctionsArtifactTreeRoot: Fr;
101
+ artifactTreeSiblingPath: Fr[];
102
+ artifactTreeLeafIndex: number;
103
+ };
104
+
105
+ const UtilityFunctionMembershipProofSchema = zodFor<UtilityFunctionMembershipProof>()(
106
+ z.object({
107
+ artifactMetadataHash: schemas.Fr,
108
+ functionMetadataHash: schemas.Fr,
109
+ privateFunctionsArtifactTreeRoot: schemas.Fr,
110
+ artifactTreeSiblingPath: z.array(schemas.Fr),
111
+ artifactTreeLeafIndex: schemas.Integer,
112
+ }),
113
+ );
114
+
115
+ /** A utility function with a membership proof. */
116
+ export type UtilityFunctionWithMembershipProof = UtilityFunction & UtilityFunctionMembershipProof;
117
+
45
118
  export const ContractClassSchema = zodFor<ContractClass>()(
46
119
  z.object({
47
120
  version: z.literal(VERSION),
@@ -70,8 +143,11 @@ export const ContractClassWithIdSchema = zodFor<ContractClassWithId>()(
70
143
  }),
71
144
  );
72
145
 
73
- /** A contract class with public bytecode information. */
74
- export type ContractClassPublic = Pick<ContractClassCommitments, 'id' | 'privateFunctionsRoot'> &
146
+ /** A contract class with public bytecode information, and optional private and utility functions. */
147
+ export type ContractClassPublic = {
148
+ privateFunctions: ExecutablePrivateFunctionWithMembershipProof[];
149
+ utilityFunctions: UtilityFunctionWithMembershipProof[];
150
+ } & Pick<ContractClassCommitments, 'id' | 'privateFunctionsRoot'> &
75
151
  Omit<ContractClass, 'privateFunctions'>;
76
152
 
77
153
  export type ContractClassPublicWithCommitment = ContractClassPublic &
@@ -82,6 +158,8 @@ export const ContractClassPublicSchema = zodFor<ContractClassPublic>()(
82
158
  .object({
83
159
  id: schemas.Fr,
84
160
  privateFunctionsRoot: schemas.Fr,
161
+ privateFunctions: z.array(ExecutablePrivateFunctionSchema.and(PrivateFunctionMembershipProofSchema)),
162
+ utilityFunctions: z.array(UtilityFunctionSchema.and(UtilityFunctionMembershipProofSchema)),
85
163
  })
86
164
  .and(ContractClassSchema.omit({ privateFunctions: true })),
87
165
  );
@@ -101,6 +179,8 @@ export function contractClassPublicFromPlainObject(obj: any): ContractClassPubli
101
179
  version: 1,
102
180
  artifactHash: Fr.fromPlainObject(obj.artifactHash),
103
181
  privateFunctionsRoot: Fr.fromPlainObject(obj.privateFunctionsRoot),
182
+ privateFunctions: [],
183
+ utilityFunctions: [],
104
184
  packedBytecode: obj.packedBytecode instanceof Buffer ? obj.packedBytecode : Buffer.from(obj.packedBytecode),
105
185
  };
106
186
  }
@@ -0,0 +1,167 @@
1
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
5
+
6
+ import { type ContractArtifact, FunctionSelector, FunctionType } from '../abi/index.js';
7
+ import {
8
+ computeArtifactFunctionTree,
9
+ computeArtifactHash,
10
+ computeArtifactHashPreimage,
11
+ computeFunctionArtifactHash,
12
+ computeFunctionMetadataHash,
13
+ getArtifactMerkleTreeHasher,
14
+ } from './artifact_hash.js';
15
+ import { getContractClassPrivateFunctionFromArtifact } from './contract_class.js';
16
+ import type {
17
+ ContractClassPublic,
18
+ ExecutablePrivateFunctionWithMembershipProof,
19
+ PrivateFunctionMembershipProof,
20
+ } from './interfaces/index.js';
21
+ import { computePrivateFunctionLeaf, computePrivateFunctionsTree } from './private_function.js';
22
+
23
+ /**
24
+ * Creates a membership proof for a private function in a contract class, to be verified via `isValidPrivateFunctionMembershipProof`.
25
+ * @param selector - Selector of the function to create the proof for.
26
+ * @param artifact - Artifact of the contract class where the function is defined.
27
+ */
28
+ export async function createPrivateFunctionMembershipProof(
29
+ selector: FunctionSelector,
30
+ artifact: ContractArtifact,
31
+ ): Promise<PrivateFunctionMembershipProof> {
32
+ const log = createLogger('circuits:function_membership_proof');
33
+
34
+ // Locate private function definition and artifact
35
+ const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
36
+ const privateFunctionsFromArtifact = await Promise.all(
37
+ privateFunctions.map(getContractClassPrivateFunctionFromArtifact),
38
+ );
39
+ const privateFunction = privateFunctionsFromArtifact.find(fn => fn.selector.equals(selector));
40
+ const privateFunctionsAndSelectors = await Promise.all(
41
+ privateFunctions.map(async fn => ({
42
+ fn,
43
+ selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
44
+ })),
45
+ );
46
+ const privateFunctionArtifact = privateFunctionsAndSelectors.find(fnAndSelector =>
47
+ selector.equals(fnAndSelector.selector),
48
+ )?.fn;
49
+ if (!privateFunction || !privateFunctionArtifact) {
50
+ throw new Error(`Private function with selector ${selector.toString()} not found`);
51
+ }
52
+
53
+ // Compute preimage for the artifact hash
54
+ const { utilityFunctionRoot: utilityFunctionsTreeRoot, metadataHash: artifactMetadataHash } =
55
+ await computeArtifactHashPreimage(artifact);
56
+
57
+ // We need two sibling paths because private function information is split across two trees:
58
+ // The "private function tree" captures the selectors and verification keys, and is used in the kernel circuit for verifying the proof generated by the app circuit.
59
+ const functionLeaf = await computePrivateFunctionLeaf(privateFunction);
60
+ const functionsTree = await computePrivateFunctionsTree(privateFunctionsFromArtifact);
61
+ const functionsTreeLeafIndex = functionsTree.getIndex(functionLeaf);
62
+ const functionsTreeSiblingPath = functionsTree.getSiblingPath(functionsTreeLeafIndex).map(Fr.fromBuffer);
63
+
64
+ // And the "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits.
65
+ const functionMetadataHash = computeFunctionMetadataHash(privateFunctionArtifact);
66
+ const functionArtifactHash = await computeFunctionArtifactHash({ ...privateFunctionArtifact, functionMetadataHash });
67
+ const artifactTree = (await computeArtifactFunctionTree(artifact, FunctionType.PRIVATE))!;
68
+ const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
69
+ const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
70
+
71
+ log.debug(`Computed proof for private function with selector ${selector.toString()}`, {
72
+ functionArtifactHash,
73
+ functionMetadataHash,
74
+ functionLeaf: '0x' + functionLeaf.toString('hex'),
75
+ artifactMetadataHash,
76
+ privateFunctionsTreeRoot: '0x' + functionsTree.root.toString('hex'),
77
+ utilityFunctionsTreeRoot,
78
+ artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
79
+ privateFunctionTreeSiblingPath: functionsTreeSiblingPath.map(fr => fr.toString()).join(','),
80
+ });
81
+
82
+ return {
83
+ artifactTreeSiblingPath,
84
+ artifactTreeLeafIndex,
85
+ artifactMetadataHash,
86
+ functionMetadataHash,
87
+ utilityFunctionsTreeRoot,
88
+ privateFunctionTreeSiblingPath: functionsTreeSiblingPath,
89
+ privateFunctionTreeLeafIndex: functionsTreeLeafIndex,
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Verifies that a private function with a membership proof as emitted by the ClassRegistry contract is valid,
95
+ * as defined in the protocol specs at contract-deployment/classes:
96
+ *
97
+ * ```
98
+ * // Load contract class from local db
99
+ * contract_class = db.get_contract_class(contract_class_id)
100
+ *
101
+ * // Compute function leaf and assert it belongs to the private functions tree
102
+ * function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
103
+ * computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
104
+ * assert computed_private_function_tree_root == contract_class.private_functions_root
105
+ *
106
+ * // Compute artifact leaf and assert it belongs to the artifact
107
+ * artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
108
+ * computed_artifact_private_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path)
109
+ * computed_artifact_hash = sha256(computed_artifact_private_function_tree_root, utility_functions_artifact_tree_root, artifact_metadata_hash)
110
+ * assert computed_artifact_hash == contract_class.artifact_hash
111
+ * ```
112
+ * @param fn - Function to check membership proof for.
113
+ * @param contractClass - In which contract class the function is expected to be.
114
+ */
115
+ export async function isValidPrivateFunctionMembershipProof(
116
+ fn: ExecutablePrivateFunctionWithMembershipProof,
117
+ contractClass: Pick<ContractClassPublic, 'privateFunctionsRoot' | 'artifactHash'>,
118
+ ) {
119
+ const log = createLogger('circuits:function_membership_proof');
120
+
121
+ // Check private function tree membership
122
+ const functionLeaf = await computePrivateFunctionLeaf(fn);
123
+ const rootBuffer = await computeRootFromSiblingPath(
124
+ functionLeaf,
125
+ fn.privateFunctionTreeSiblingPath.map(fr => fr.toBuffer()),
126
+ fn.privateFunctionTreeLeafIndex,
127
+ async (left, right) => (await poseidon2Hash([left, right])).toBuffer(),
128
+ );
129
+ const computedPrivateFunctionTreeRoot = Fr.fromBuffer(rootBuffer);
130
+ if (!contractClass.privateFunctionsRoot.equals(computedPrivateFunctionTreeRoot)) {
131
+ log.debug(`Private function tree root mismatch`, {
132
+ expectedPrivateFunctionTreeRoot: contractClass.privateFunctionsRoot,
133
+ computedPrivateFunctionTreeRoot: computedPrivateFunctionTreeRoot,
134
+ computedFunctionLeaf: '0x' + functionLeaf.toString('hex'),
135
+ });
136
+ return false;
137
+ }
138
+
139
+ // Check artifact hash
140
+ const functionArtifactHash = await computeFunctionArtifactHash(fn);
141
+ const computedArtifactPrivateFunctionTreeRootBuffer = await computeRootFromSiblingPath(
142
+ functionArtifactHash.toBuffer(),
143
+ fn.artifactTreeSiblingPath.map(fr => fr.toBuffer()),
144
+ fn.artifactTreeLeafIndex,
145
+ getArtifactMerkleTreeHasher(),
146
+ );
147
+ const computedArtifactPrivateFunctionTreeRoot = Fr.fromBuffer(computedArtifactPrivateFunctionTreeRootBuffer);
148
+ const computedArtifactHash = await computeArtifactHash({
149
+ privateFunctionRoot: computedArtifactPrivateFunctionTreeRoot,
150
+ utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
151
+ metadataHash: fn.artifactMetadataHash,
152
+ });
153
+ if (!contractClass.artifactHash.equals(computedArtifactHash)) {
154
+ log.debug(`Artifact hash mismatch`, {
155
+ expected: contractClass.artifactHash,
156
+ computedArtifactHash,
157
+ computedFunctionArtifactHash: functionArtifactHash,
158
+ computedArtifactPrivateFunctionTreeRoot,
159
+ utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
160
+ metadataHash: fn.artifactMetadataHash,
161
+ artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map(fr => fr.toString()).join(','),
162
+ });
163
+ return false;
164
+ }
165
+
166
+ return true;
167
+ }