@aztec/stdlib 0.0.1-commit.cf93bcc56 → 0.0.1-commit.d0fcfb7f

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 (233) hide show
  1. package/dest/abi/decoder.d.ts +2 -2
  2. package/dest/abi/decoder.d.ts.map +1 -1
  3. package/dest/abi/decoder.js +7 -5
  4. package/dest/abi/encoder.d.ts +1 -1
  5. package/dest/abi/encoder.d.ts.map +1 -1
  6. package/dest/abi/encoder.js +37 -6
  7. package/dest/abi/event_metadata_definition.d.ts +3 -1
  8. package/dest/abi/event_metadata_definition.d.ts.map +1 -1
  9. package/dest/abi/event_metadata_definition.js +1 -1
  10. package/dest/abi/utils.d.ts +14 -1
  11. package/dest/abi/utils.d.ts.map +1 -1
  12. package/dest/abi/utils.js +15 -0
  13. package/dest/avm/avm.d.ts +300 -300
  14. package/dest/avm/avm_proving_request.d.ts +166 -166
  15. package/dest/avm/revert_code.d.ts +16 -1
  16. package/dest/avm/revert_code.d.ts.map +1 -1
  17. package/dest/avm/revert_code.js +15 -5
  18. package/dest/block/l2_block.d.ts +9 -1
  19. package/dest/block/l2_block.d.ts.map +1 -1
  20. package/dest/block/l2_block.js +12 -2
  21. package/dest/block/l2_block_source.d.ts +12 -5
  22. package/dest/block/l2_block_source.d.ts.map +1 -1
  23. package/dest/block/l2_block_stream/l2_block_stream.d.ts +1 -1
  24. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  25. package/dest/block/l2_block_stream/l2_block_stream.js +10 -0
  26. package/dest/checkpoint/checkpoint.d.ts +2 -1
  27. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  28. package/dest/checkpoint/checkpoint.js +9 -4
  29. package/dest/checkpoint/index.d.ts +2 -1
  30. package/dest/checkpoint/index.d.ts.map +1 -1
  31. package/dest/checkpoint/index.js +1 -0
  32. package/dest/checkpoint/validate.d.ts +36 -0
  33. package/dest/checkpoint/validate.d.ts.map +1 -0
  34. package/dest/checkpoint/validate.js +120 -0
  35. package/dest/config/sequencer-config.d.ts +2 -2
  36. package/dest/config/sequencer-config.d.ts.map +1 -1
  37. package/dest/config/sequencer-config.js +11 -0
  38. package/dest/contract/contract_class.d.ts +2 -3
  39. package/dest/contract/contract_class.d.ts.map +1 -1
  40. package/dest/epoch-helpers/index.d.ts +5 -1
  41. package/dest/epoch-helpers/index.d.ts.map +1 -1
  42. package/dest/epoch-helpers/index.js +4 -2
  43. package/dest/interfaces/allowed_element.d.ts +26 -20
  44. package/dest/interfaces/allowed_element.d.ts.map +1 -1
  45. package/dest/interfaces/allowed_element.js +8 -8
  46. package/dest/interfaces/archiver.d.ts +1 -1
  47. package/dest/interfaces/archiver.d.ts.map +1 -1
  48. package/dest/interfaces/archiver.js +3 -2
  49. package/dest/interfaces/aztec-node-admin.d.ts +64 -27
  50. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  51. package/dest/interfaces/aztec-node.d.ts +11 -6
  52. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  53. package/dest/interfaces/aztec-node.js +5 -2
  54. package/dest/interfaces/block-builder.d.ts +17 -9
  55. package/dest/interfaces/block-builder.d.ts.map +1 -1
  56. package/dest/interfaces/block-builder.js +13 -6
  57. package/dest/interfaces/configs.d.ts +62 -32
  58. package/dest/interfaces/configs.d.ts.map +1 -1
  59. package/dest/interfaces/configs.js +6 -2
  60. package/dest/interfaces/merkle_tree_operations.d.ts +9 -19
  61. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  62. package/dest/interfaces/p2p.d.ts +3 -8
  63. package/dest/interfaces/p2p.d.ts.map +1 -1
  64. package/dest/interfaces/prover-client.d.ts +6 -1
  65. package/dest/interfaces/prover-client.d.ts.map +1 -1
  66. package/dest/interfaces/prover-client.js +7 -1
  67. package/dest/interfaces/validator.d.ts +67 -25
  68. package/dest/interfaces/validator.d.ts.map +1 -1
  69. package/dest/interfaces/validator.js +6 -2
  70. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts +3 -3
  71. package/dest/kernel/hints/build_note_hash_read_request_hints.d.ts.map +1 -1
  72. package/dest/kernel/hints/build_note_hash_read_request_hints.js +13 -10
  73. package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts +3 -3
  74. package/dest/kernel/hints/build_nullifier_read_request_hints.d.ts.map +1 -1
  75. package/dest/kernel/hints/build_nullifier_read_request_hints.js +13 -10
  76. package/dest/kernel/hints/build_transient_data_hints.d.ts +5 -2
  77. package/dest/kernel/hints/build_transient_data_hints.d.ts.map +1 -1
  78. package/dest/kernel/hints/build_transient_data_hints.js +9 -3
  79. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts +2 -1
  80. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts.map +1 -1
  81. package/dest/kernel/private_kernel_tail_circuit_public_inputs.js +4 -0
  82. package/dest/logs/debug_log_store.d.ts +30 -0
  83. package/dest/logs/debug_log_store.d.ts.map +1 -0
  84. package/dest/logs/debug_log_store.js +30 -0
  85. package/dest/logs/extended_directional_app_tagging_secret.d.ts +47 -0
  86. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -0
  87. package/dest/logs/{directional_app_tagging_secret.js → extended_directional_app_tagging_secret.js} +23 -15
  88. package/dest/logs/index.d.ts +3 -2
  89. package/dest/logs/index.d.ts.map +1 -1
  90. package/dest/logs/index.js +2 -1
  91. package/dest/logs/log_filter.d.ts +4 -1
  92. package/dest/logs/log_filter.d.ts.map +1 -1
  93. package/dest/logs/log_filter.js +2 -1
  94. package/dest/logs/pre_tag.d.ts +16 -11
  95. package/dest/logs/pre_tag.d.ts.map +1 -1
  96. package/dest/logs/pre_tag.js +2 -2
  97. package/dest/logs/public_log.d.ts +4 -3
  98. package/dest/logs/public_log.d.ts.map +1 -1
  99. package/dest/logs/public_log.js +2 -1
  100. package/dest/logs/siloed_tag.d.ts +5 -3
  101. package/dest/logs/siloed_tag.d.ts.map +1 -1
  102. package/dest/logs/siloed_tag.js +6 -1
  103. package/dest/logs/tag.js +1 -1
  104. package/dest/messaging/l2_to_l1_membership.d.ts +32 -6
  105. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  106. package/dest/messaging/l2_to_l1_membership.js +69 -26
  107. package/dest/p2p/attestation_utils.d.ts +11 -1
  108. package/dest/p2p/attestation_utils.d.ts.map +1 -1
  109. package/dest/p2p/attestation_utils.js +45 -0
  110. package/dest/p2p/checkpoint_proposal.d.ts +1 -6
  111. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  112. package/dest/p2p/checkpoint_proposal.js +0 -12
  113. package/dest/p2p/client_type.d.ts +2 -5
  114. package/dest/p2p/client_type.d.ts.map +1 -1
  115. package/dest/p2p/client_type.js +0 -7
  116. package/dest/p2p/index.d.ts +1 -2
  117. package/dest/p2p/index.d.ts.map +1 -1
  118. package/dest/p2p/index.js +0 -1
  119. package/dest/p2p/peer_error.d.ts +3 -1
  120. package/dest/p2p/peer_error.d.ts.map +1 -1
  121. package/dest/p2p/peer_error.js +5 -0
  122. package/dest/p2p/topic_type.d.ts +3 -4
  123. package/dest/p2p/topic_type.d.ts.map +1 -1
  124. package/dest/p2p/topic_type.js +7 -24
  125. package/dest/slashing/tally.d.ts +7 -2
  126. package/dest/slashing/tally.d.ts.map +1 -1
  127. package/dest/slashing/tally.js +30 -2
  128. package/dest/tests/factories.d.ts +3 -1
  129. package/dest/tests/factories.d.ts.map +1 -1
  130. package/dest/tests/factories.js +8 -0
  131. package/dest/tests/mocks.d.ts +5 -3
  132. package/dest/tests/mocks.d.ts.map +1 -1
  133. package/dest/tests/mocks.js +18 -13
  134. package/dest/tx/block_header.d.ts +3 -1
  135. package/dest/tx/block_header.d.ts.map +1 -1
  136. package/dest/tx/block_header.js +4 -0
  137. package/dest/tx/profiling.d.ts +4 -4
  138. package/dest/tx/profiling.d.ts.map +1 -1
  139. package/dest/tx/profiling.js +3 -3
  140. package/dest/tx/public_simulation_output.d.ts +4 -2
  141. package/dest/tx/public_simulation_output.d.ts.map +1 -1
  142. package/dest/tx/public_simulation_output.js +7 -3
  143. package/dest/tx/simulated_tx.d.ts +5 -2
  144. package/dest/tx/simulated_tx.d.ts.map +1 -1
  145. package/dest/tx/simulated_tx.js +4 -1
  146. package/dest/tx/tx.d.ts +6 -5
  147. package/dest/tx/tx.d.ts.map +1 -1
  148. package/dest/tx/tx.js +18 -6
  149. package/dest/tx/tx_receipt.d.ts +22 -3
  150. package/dest/tx/tx_receipt.d.ts.map +1 -1
  151. package/dest/tx/tx_receipt.js +15 -4
  152. package/dest/tx/validator/error_texts.d.ts +5 -1
  153. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  154. package/dest/tx/validator/error_texts.js +4 -0
  155. package/dest/update-checker/index.d.ts +3 -2
  156. package/dest/update-checker/index.d.ts.map +1 -1
  157. package/dest/update-checker/index.js +2 -1
  158. package/dest/update-checker/package_version.d.ts +3 -0
  159. package/dest/update-checker/package_version.d.ts.map +1 -0
  160. package/dest/update-checker/package_version.js +24 -0
  161. package/dest/update-checker/version_checker.d.ts +25 -0
  162. package/dest/update-checker/version_checker.d.ts.map +1 -0
  163. package/dest/update-checker/version_checker.js +50 -0
  164. package/dest/validators/errors.d.ts +6 -1
  165. package/dest/validators/errors.d.ts.map +1 -1
  166. package/dest/validators/errors.js +7 -0
  167. package/dest/versioning/versioning.d.ts +4 -2
  168. package/dest/versioning/versioning.d.ts.map +1 -1
  169. package/dest/versioning/versioning.js +4 -1
  170. package/package.json +10 -10
  171. package/src/abi/decoder.ts +15 -6
  172. package/src/abi/encoder.ts +49 -6
  173. package/src/abi/event_metadata_definition.ts +2 -0
  174. package/src/abi/utils.ts +25 -0
  175. package/src/avm/revert_code.ts +15 -0
  176. package/src/block/l2_block.ts +13 -1
  177. package/src/block/l2_block_source.ts +12 -4
  178. package/src/block/l2_block_stream/l2_block_stream.ts +21 -0
  179. package/src/checkpoint/checkpoint.ts +12 -3
  180. package/src/checkpoint/index.ts +1 -0
  181. package/src/checkpoint/validate.ts +230 -0
  182. package/src/config/sequencer-config.ts +16 -1
  183. package/src/contract/contract_class.ts +3 -3
  184. package/src/epoch-helpers/index.ts +3 -0
  185. package/src/interfaces/allowed_element.ts +29 -9
  186. package/src/interfaces/archiver.ts +3 -2
  187. package/src/interfaces/aztec-node.ts +23 -5
  188. package/src/interfaces/block-builder.ts +34 -12
  189. package/src/interfaces/configs.ts +26 -8
  190. package/src/interfaces/merkle_tree_operations.ts +8 -18
  191. package/src/interfaces/p2p.ts +2 -13
  192. package/src/interfaces/prover-client.ts +8 -0
  193. package/src/interfaces/validator.ts +18 -2
  194. package/src/kernel/hints/build_note_hash_read_request_hints.ts +14 -18
  195. package/src/kernel/hints/build_nullifier_read_request_hints.ts +15 -18
  196. package/src/kernel/hints/build_transient_data_hints.ts +17 -2
  197. package/src/kernel/private_kernel_tail_circuit_public_inputs.ts +9 -0
  198. package/src/logs/debug_log_store.ts +54 -0
  199. package/src/logs/{directional_app_tagging_secret.ts → extended_directional_app_tagging_secret.ts} +24 -16
  200. package/src/logs/index.ts +2 -1
  201. package/src/logs/log_filter.ts +5 -0
  202. package/src/logs/pre_tag.ts +5 -5
  203. package/src/logs/public_log.ts +4 -2
  204. package/src/logs/siloed_tag.ts +8 -2
  205. package/src/logs/tag.ts +1 -1
  206. package/src/messaging/l2_to_l1_membership.ts +98 -33
  207. package/src/p2p/attestation_utils.ts +56 -0
  208. package/src/p2p/checkpoint_proposal.ts +0 -17
  209. package/src/p2p/client_type.ts +0 -6
  210. package/src/p2p/index.ts +0 -1
  211. package/src/p2p/peer_error.ts +7 -0
  212. package/src/p2p/topic_type.ts +8 -15
  213. package/src/slashing/tally.ts +34 -1
  214. package/src/tests/factories.ts +9 -0
  215. package/src/tests/mocks.ts +25 -10
  216. package/src/tx/block_header.ts +6 -0
  217. package/src/tx/profiling.ts +5 -5
  218. package/src/tx/public_simulation_output.ts +4 -0
  219. package/src/tx/simulated_tx.ts +8 -1
  220. package/src/tx/tx.ts +20 -11
  221. package/src/tx/tx_receipt.ts +16 -1
  222. package/src/tx/validator/error_texts.ts +4 -0
  223. package/src/update-checker/index.ts +2 -1
  224. package/src/update-checker/package_version.ts +30 -0
  225. package/src/update-checker/version_checker.ts +65 -0
  226. package/src/validators/errors.ts +9 -0
  227. package/src/versioning/versioning.ts +4 -1
  228. package/dest/logs/directional_app_tagging_secret.d.ts +0 -40
  229. package/dest/logs/directional_app_tagging_secret.d.ts.map +0 -1
  230. package/dest/update-checker/update-checker.d.ts +0 -49
  231. package/dest/update-checker/update-checker.d.ts.map +0 -1
  232. package/dest/update-checker/update-checker.js +0 -130
  233. package/src/update-checker/update-checker.ts +0 -166
@@ -5,22 +5,28 @@ import type { Point } from '@aztec/foundation/curves/grumpkin';
5
5
 
6
6
  import { z } from 'zod';
7
7
 
8
- import type { AztecAddress } from '../aztec-address/index.js';
8
+ import { AztecAddress } from '../aztec-address/index.js';
9
9
  import type { CompleteAddress } from '../contract/complete_address.js';
10
10
  import { computeAddressSecret, computePreaddress } from '../keys/derivation.js';
11
11
 
12
12
  /**
13
- * Directional application tagging secret used for log tagging.
13
+ * Extended directional application tagging secret used for log tagging.
14
14
  *
15
- * "Directional" because the derived secret is bound to the recipient
16
- * address: A→B differs from B→A even with the same participants and app.
15
+ * "Extended" because it bundles the directional app tagging secret with the app (contract) address. This bundling was
16
+ * done because where this type is used we commonly need access to both the secret and the address.
17
17
  *
18
- * Note: It's a bit unfortunate that this type resides in `stdlib` as the rest of the tagging functionality resides
19
- * in `pxe/src/tagging`. We need to use this type in `PreTag` that in turn is used by other types
20
- * in stdlib hence there doesn't seem to be a good way around this.
18
+ * "Directional" because the derived secret is bound to the recipient address: A→B differs from B→A even with the same
19
+ * participants and app.
20
+ *
21
+ * Note: It's a bit unfortunate that this type resides in `stdlib` as the rest of the tagging functionality resides in
22
+ * `pxe/src/tagging`. We need to use this type in `PreTag` that in turn is used by other types in stdlib hence there
23
+ * doesn't seem to be a good way around this.
21
24
  */
22
- export class DirectionalAppTaggingSecret {
23
- private constructor(public readonly value: Fr) {}
25
+ export class ExtendedDirectionalAppTaggingSecret {
26
+ private constructor(
27
+ public readonly secret: Fr,
28
+ public readonly app: AztecAddress,
29
+ ) {}
24
30
 
25
31
  /**
26
32
  * Derives shared tagging secret and from that, the app address and recipient derives the directional app tagging
@@ -39,20 +45,21 @@ export class DirectionalAppTaggingSecret {
39
45
  externalAddress: AztecAddress,
40
46
  app: AztecAddress,
41
47
  recipient: AztecAddress,
42
- ): Promise<DirectionalAppTaggingSecret> {
48
+ ): Promise<ExtendedDirectionalAppTaggingSecret> {
43
49
  const taggingSecretPoint = await computeSharedTaggingSecret(localAddress, localIvsk, externalAddress);
44
50
  const appTaggingSecret = await poseidon2Hash([taggingSecretPoint.x, taggingSecretPoint.y, app]);
45
51
  const directionalAppTaggingSecret = await poseidon2Hash([appTaggingSecret, recipient]);
46
52
 
47
- return new DirectionalAppTaggingSecret(directionalAppTaggingSecret);
53
+ return new ExtendedDirectionalAppTaggingSecret(directionalAppTaggingSecret, app);
48
54
  }
49
55
 
50
56
  toString(): string {
51
- return this.value.toString();
57
+ return `${this.secret.toString()}:${this.app.toString()}`;
52
58
  }
53
59
 
54
- static fromString(str: string): DirectionalAppTaggingSecret {
55
- return new DirectionalAppTaggingSecret(Fr.fromString(str));
60
+ static fromString(str: string): ExtendedDirectionalAppTaggingSecret {
61
+ const [secretStr, appStr] = str.split(':');
62
+ return new ExtendedDirectionalAppTaggingSecret(Fr.fromString(secretStr), AztecAddress.fromString(appStr));
56
63
  }
57
64
  }
58
65
 
@@ -74,6 +81,7 @@ async function computeSharedTaggingSecret(
74
81
  return Grumpkin.mul(externalAddressPoint, await computeAddressSecret(knownPreaddress, localIvsk));
75
82
  }
76
83
 
77
- export const DirectionalAppTaggingSecretSchema = z.object({
78
- value: Fr.schema,
84
+ export const ExtendedDirectionalAppTaggingSecretSchema = z.object({
85
+ secret: Fr.schema,
86
+ app: AztecAddress.schema,
79
87
  });
package/src/logs/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './directional_app_tagging_secret.js';
1
+ export * from './extended_directional_app_tagging_secret.js';
2
2
  export * from './pre_tag.js';
3
3
  export * from './contract_class_log.js';
4
4
  export * from './public_log.js';
@@ -12,5 +12,6 @@ export * from './shared_secret_derivation.js';
12
12
  export * from './tx_scoped_l2_log.js';
13
13
  export * from './message_context.js';
14
14
  export * from './debug_log.js';
15
+ export * from './debug_log_store.js';
15
16
  export * from './tag.js';
16
17
  export * from './siloed_tag.js';
@@ -1,3 +1,5 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+
1
3
  import { z } from 'zod';
2
4
 
3
5
  import type { AztecAddress } from '../aztec-address/index.js';
@@ -20,6 +22,8 @@ export type LogFilter = {
20
22
  afterLog?: LogId;
21
23
  /** The contract address to filter logs by. */
22
24
  contractAddress?: AztecAddress;
25
+ /** The tag (first field of the log) to filter logs by. */
26
+ tag?: Fr;
23
27
  };
24
28
 
25
29
  export const LogFilterSchema: ZodFor<LogFilter> = z.object({
@@ -28,4 +32,5 @@ export const LogFilterSchema: ZodFor<LogFilter> = z.object({
28
32
  toBlock: schemas.Integer.optional(),
29
33
  afterLog: LogId.schema.optional(),
30
34
  contractAddress: schemas.AztecAddress.optional(),
35
+ tag: schemas.Fr.optional(),
31
36
  });
@@ -3,9 +3,9 @@ import { schemas } from '@aztec/foundation/schemas';
3
3
  import { z } from 'zod';
4
4
 
5
5
  import {
6
- type DirectionalAppTaggingSecret,
7
- DirectionalAppTaggingSecretSchema,
8
- } from './directional_app_tagging_secret.js';
6
+ type ExtendedDirectionalAppTaggingSecret,
7
+ ExtendedDirectionalAppTaggingSecretSchema,
8
+ } from './extended_directional_app_tagging_secret.js';
9
9
 
10
10
  /**
11
11
  * Represents a preimage of a private log tag (see `Tag` in `pxe/src/tagging`).
@@ -15,11 +15,11 @@ import {
15
15
  * around this.
16
16
  */
17
17
  export type PreTag = {
18
- secret: DirectionalAppTaggingSecret;
18
+ extendedSecret: ExtendedDirectionalAppTaggingSecret;
19
19
  index: number;
20
20
  };
21
21
 
22
22
  export const PreTagSchema = z.object({
23
- secret: DirectionalAppTaggingSecretSchema,
23
+ extendedSecret: ExtendedDirectionalAppTaggingSecretSchema,
24
24
  index: schemas.Integer,
25
25
  });
@@ -120,8 +120,8 @@ export class FlatPublicLogs {
120
120
 
121
121
  export class PublicLog {
122
122
  constructor(
123
- public contractAddress: AztecAddress,
124
- public fields: Fr[],
123
+ public readonly contractAddress: AztecAddress,
124
+ public readonly fields: Fr[],
125
125
  ) {}
126
126
 
127
127
  static from(fields: FieldsOf<PublicLog>) {
@@ -146,7 +146,9 @@ export class PublicLog {
146
146
  return this.fields.length + PUBLIC_LOG_HEADER_LENGTH;
147
147
  }
148
148
 
149
+ /** Returns the serialized log (field as in noir field and not a struct field). */
149
150
  getEmittedFields() {
151
+ // We slice from 0 to return a shallow copy.
150
152
  return this.fields.slice(0);
151
153
  }
152
154
 
@@ -4,7 +4,8 @@ import type { ZodFor } from '@aztec/foundation/schemas';
4
4
  import type { AztecAddress } from '../aztec-address/index.js';
5
5
  import { computeSiloedPrivateLogFirstField } from '../hash/hash.js';
6
6
  import { schemas } from '../schemas/schemas.js';
7
- import type { Tag } from './tag.js';
7
+ import type { PreTag } from './pre_tag.js';
8
+ import { Tag } from './tag.js';
8
9
 
9
10
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
10
11
 
@@ -21,7 +22,12 @@ export interface SiloedTag {
21
22
  export class SiloedTag {
22
23
  constructor(public readonly value: Fr) {}
23
24
 
24
- static async compute(tag: Tag, app: AztecAddress): Promise<SiloedTag> {
25
+ static async compute(preTag: PreTag): Promise<SiloedTag> {
26
+ const tag = await Tag.compute(preTag);
27
+ return SiloedTag.computeFromTagAndApp(tag, preTag.extendedSecret.app);
28
+ }
29
+
30
+ static async computeFromTagAndApp(tag: Tag, app: AztecAddress): Promise<SiloedTag> {
25
31
  const siloedTag = await computeSiloedPrivateLogFirstField(app, tag.value);
26
32
  return new SiloedTag(siloedTag);
27
33
  }
package/src/logs/tag.ts CHANGED
@@ -20,7 +20,7 @@ export class Tag {
20
20
  constructor(public readonly value: Fr) {}
21
21
 
22
22
  static async compute(preTag: PreTag): Promise<Tag> {
23
- const tag = await poseidon2Hash([preTag.secret.value, preTag.index]);
23
+ const tag = await poseidon2Hash([preTag.extendedSecret.secret, preTag.index]);
24
24
  return new Tag(tag);
25
25
  }
26
26
 
@@ -3,6 +3,9 @@ import type { EpochNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { SiblingPath, UnbalancedMerkleTreeCalculator, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
5
5
 
6
+ import type { AztecNode } from '../interfaces/aztec-node.js';
7
+ import { TxHash } from '../tx/tx_hash.js';
8
+
6
9
  /**
7
10
  * # L2-to-L1 Message Tree Structure and Leaf IDs
8
11
  *
@@ -92,59 +95,94 @@ export function getL2ToL1MessageLeafId(
92
95
  return 2n ** BigInt(membershipWitness.siblingPath.pathSize) + membershipWitness.leafIndex;
93
96
  }
94
97
 
95
- export interface MessageRetrieval {
96
- getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]>;
97
- }
98
-
99
98
  export type L2ToL1MembershipWitness = {
100
99
  root: Fr;
101
100
  leafIndex: bigint;
102
101
  siblingPath: SiblingPath<number>;
102
+ epochNumber: EpochNumber;
103
103
  };
104
104
 
105
+ /**
106
+ * Computes the L2 to L1 membership witness for a given message in a transaction.
107
+ *
108
+ * @param node - The Aztec node to query for block/tx/epoch data.
109
+ * @param message - The L2 to L1 message hash to prove membership of.
110
+ * @param txHash - The hash of the transaction that emitted the message.
111
+ * @param messageIndexInTx - Optional index of the message within the transaction's L2-to-L1 messages.
112
+ * If not provided, the message is found by scanning the tx's messages (throws if duplicates exist).
113
+ * @returns The membership witness and epoch number, or undefined if the tx is not yet in a block/epoch.
114
+ */
105
115
  export async function computeL2ToL1MembershipWitness(
106
- messageRetriever: MessageRetrieval,
107
- epoch: EpochNumber,
116
+ node: Pick<
117
+ AztecNode,
118
+ 'getL2ToL1Messages' | 'getTxReceipt' | 'getTxEffect' | 'getBlock' | 'getCheckpointsDataForEpoch'
119
+ >,
108
120
  message: Fr,
121
+ txHash: TxHash,
122
+ messageIndexInTx?: number,
109
123
  ): Promise<L2ToL1MembershipWitness | undefined> {
110
- const messagesInEpoch = await messageRetriever.getL2ToL1Messages(epoch);
111
- if (messagesInEpoch.length === 0) {
124
+ const { epochNumber, blockNumber } = await node.getTxReceipt(txHash);
125
+ if (epochNumber === undefined || blockNumber === undefined) {
126
+ return undefined;
127
+ }
128
+
129
+ const [messagesInEpoch, block, txEffect, checkpointsData] = await Promise.all([
130
+ node.getL2ToL1Messages(epochNumber),
131
+ node.getBlock(blockNumber),
132
+ node.getTxEffect(txHash),
133
+ node.getCheckpointsDataForEpoch(epochNumber),
134
+ ]);
135
+
136
+ if (messagesInEpoch.length === 0 || !block || !txEffect) {
137
+ return undefined;
138
+ }
139
+
140
+ const checkpointIndex = checkpointsData.findIndex(c => c.checkpointNumber === block.checkpointNumber);
141
+ if (checkpointIndex === -1) {
112
142
  return undefined;
113
143
  }
114
144
 
115
- return computeL2ToL1MembershipWitnessFromMessagesInEpoch(messagesInEpoch, message);
145
+ const blockIndex = block.indexWithinCheckpoint;
146
+ const txIndex = txEffect.txIndexInBlock;
147
+
148
+ const { root, leafIndex, siblingPath } = computeL2ToL1MembershipWitnessFromMessagesInEpoch(
149
+ messagesInEpoch,
150
+ message,
151
+ checkpointIndex,
152
+ blockIndex,
153
+ txIndex,
154
+ messageIndexInTx,
155
+ );
156
+ return { epochNumber, root, leafIndex, siblingPath };
116
157
  }
117
158
 
118
- // TODO: Allow to specify the message to consume by its index or by an offset, in case there are multiple messages with
119
- // the same value.
159
+ /**
160
+ * Computes a membership witness for a message in the epoch's L2-to-L1 message tree, given explicit position indices.
161
+ *
162
+ * @param messagesInEpoch - All L2-to-L1 messages in the epoch, organized as checkpoints → blocks → txs → messages.
163
+ * @param message - The message hash to prove membership of.
164
+ * @param checkpointIndex - Index of the checkpoint within the epoch's message array.
165
+ * @param blockIndex - Index of the block within the checkpoint.
166
+ * @param txIndex - Index of the transaction within the block.
167
+ * @param messageIndexInTx - Optional index of the message within the transaction's messages.
168
+ * If not provided, the message is found by scanning (throws if duplicates exist within the tx).
169
+ */
170
+ /** @internal Exported for testing only. */
120
171
  export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
121
172
  messagesInEpoch: Fr[][][][],
122
173
  message: Fr,
123
- ): L2ToL1MembershipWitness {
124
- // Find the index of the message in the tx, index of the tx in the block, and index of the block in the epoch.
125
- let messageIndexInTx = -1;
126
- let txIndex = -1;
127
- let blockIndex = -1;
128
- const checkpointIndex = messagesInEpoch.findIndex(messagesInCheckpoint => {
129
- blockIndex = messagesInCheckpoint.findIndex(messagesInBlock => {
130
- txIndex = messagesInBlock.findIndex(messagesInTx => {
131
- messageIndexInTx = messagesInTx.findIndex(msg => msg.equals(message));
132
- return messageIndexInTx !== -1;
133
- });
134
- return txIndex !== -1;
135
- });
136
- return blockIndex !== -1;
137
- });
138
-
139
- if (checkpointIndex === -1) {
140
- throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
141
- }
174
+ checkpointIndex: number,
175
+ blockIndex: number,
176
+ txIndex: number,
177
+ messageIndexInTx?: number,
178
+ ): { root: Fr; leafIndex: bigint; siblingPath: SiblingPath<number> } {
179
+ const messagesInTx = messagesInEpoch[checkpointIndex][blockIndex][txIndex];
180
+ const resolvedMessageIndex = resolveMessageIndex(messagesInTx, message, messageIndexInTx);
142
181
 
143
182
  // Build the tx tree.
144
- const messagesInTx = messagesInEpoch[checkpointIndex][blockIndex][txIndex];
145
183
  const txTree = UnbalancedMerkleTreeCalculator.create(messagesInTx.map(msg => msg.toBuffer()));
146
184
  // Get the sibling path of the target message in the tx tree.
147
- const pathToMessageInTxSubtree = txTree.getSiblingPathByLeafIndex(messageIndexInTx);
185
+ const pathToMessageInTxSubtree = txTree.getSiblingPathByLeafIndex(resolvedMessageIndex);
148
186
 
149
187
  // Build the tree of the block containing the target message.
150
188
  const blockTree = buildBlockTree(messagesInEpoch[checkpointIndex][blockIndex]);
@@ -189,7 +227,7 @@ export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
189
227
  // Compute the combined index.
190
228
  // It is the index of the message in the balanced tree (by filling up the wonky tree with empty nodes) at its current
191
229
  // height. It's used to validate the membership proof.
192
- const messageLeafPosition = txTree.getLeafLocation(messageIndexInTx);
230
+ const messageLeafPosition = txTree.getLeafLocation(resolvedMessageIndex);
193
231
  const txLeafPosition = blockTree.getLeafLocation(txIndex);
194
232
  const blockLeafPosition = checkpointTree.getLeafLocation(blockIndex);
195
233
  const checkpointLeafPosition = epochTree.getLeafLocation(checkpointIndex);
@@ -207,6 +245,33 @@ export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
207
245
  };
208
246
  }
209
247
 
248
+ function resolveMessageIndex(messagesInTx: Fr[], message: Fr, messageIndexInTx?: number): number {
249
+ if (messageIndexInTx !== undefined) {
250
+ if (!messagesInTx[messageIndexInTx]?.equals(message)) {
251
+ throw new Error(`Message at index ${messageIndexInTx} in tx does not match the expected message ${message}`);
252
+ }
253
+ return messageIndexInTx;
254
+ }
255
+
256
+ const indices = messagesInTx.reduce<number[]>((acc, msg, i) => {
257
+ if (msg.equals(message)) {
258
+ acc.push(i);
259
+ }
260
+ return acc;
261
+ }, []);
262
+
263
+ if (indices.length === 0) {
264
+ throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
265
+ }
266
+ if (indices.length > 1) {
267
+ throw new Error(
268
+ `Multiple messages with the same value ${message} found in tx (indices: ${indices.join(', ')}). ` +
269
+ `Provide messageIndexInTx to disambiguate.`,
270
+ );
271
+ }
272
+ return indices[0];
273
+ }
274
+
210
275
  function buildCheckpointTree(messagesInCheckpoint: Fr[][][]) {
211
276
  const blockOutHashes = messagesInCheckpoint.map(messagesInBlock => buildBlockTree(messagesInBlock).getRoot());
212
277
  return buildCompressedTree(blockOutHashes);
@@ -33,3 +33,59 @@ export function orderAttestations(
33
33
 
34
34
  return orderedAttestations;
35
35
  }
36
+
37
+ /**
38
+ * Trims attestations to the minimum required number to save L1 calldata gas.
39
+ * Each signature costs 65 bytes of calldata vs 20 bytes for just an address.
40
+ *
41
+ * Priority order for keeping attestations:
42
+ * 1. The proposer's attestation (required by L1 contract - MissingProposerSignature revert)
43
+ * 2. Attestations from the local node's validator keys
44
+ * 3. Remaining attestations filled to reach the required count
45
+ */
46
+ export function trimAttestations(
47
+ attestations: CheckpointAttestation[],
48
+ required: number,
49
+ proposerAddress: EthAddress,
50
+ localAddresses: EthAddress[],
51
+ ): CheckpointAttestation[] {
52
+ if (attestations.length <= required) {
53
+ return attestations;
54
+ }
55
+
56
+ const proposerAttestation: CheckpointAttestation[] = [];
57
+ const localAttestations: CheckpointAttestation[] = [];
58
+ const otherAttestations: CheckpointAttestation[] = [];
59
+
60
+ for (const attestation of attestations) {
61
+ const sender = attestation.getSender();
62
+ if (!sender) {
63
+ continue;
64
+ }
65
+ if (sender.equals(proposerAddress)) {
66
+ proposerAttestation.push(attestation);
67
+ } else if (localAddresses.some(addr => addr.equals(sender))) {
68
+ localAttestations.push(attestation);
69
+ } else {
70
+ otherAttestations.push(attestation);
71
+ }
72
+ }
73
+
74
+ const result: CheckpointAttestation[] = [...proposerAttestation];
75
+
76
+ for (const att of localAttestations) {
77
+ if (result.length >= required) {
78
+ break;
79
+ }
80
+ result.push(att);
81
+ }
82
+
83
+ for (const att of otherAttestations) {
84
+ if (result.length >= required) {
85
+ break;
86
+ }
87
+ result.push(att);
88
+ }
89
+
90
+ return result;
91
+ }
@@ -101,23 +101,6 @@ export class CheckpointProposal extends Gossipable {
101
101
  return this.checkpointHeader.slotNumber;
102
102
  }
103
103
 
104
- get blockNumber(): BlockNumber {
105
- if (!this.lastBlock) {
106
- throw new Error('Cannot get blockNumber without lastBlock');
107
- }
108
- return this.lastBlock.blockHeader.getBlockNumber();
109
- }
110
-
111
- /** Convenience getter for txHashes from lastBlock */
112
- get txHashes(): TxHash[] {
113
- return this.lastBlock?.txHashes ?? [];
114
- }
115
-
116
- /** Convenience getter for txs from lastBlock */
117
- get txs(): Tx[] | undefined {
118
- return this.lastBlock?.signedTxs?.txs;
119
- }
120
-
121
104
  /**
122
105
  * Extract a BlockProposal from the last block info.
123
106
  * Uses inHash from checkpointHeader.contentCommitment.inHash
@@ -1,6 +0,0 @@
1
- export enum P2PClientType {
2
- // Full p2p clients will subscribe to all gossip topics
3
- Full,
4
- // Prove p2p clients will only subscribe to transaction and proving topics
5
- Prover,
6
- }
package/src/p2p/index.ts CHANGED
@@ -8,7 +8,6 @@ export * from './interface.js';
8
8
  export * from './signature_utils.js';
9
9
  export * from './signed_txs.js';
10
10
  export * from './topic_type.js';
11
- export * from './client_type.js';
12
11
  export * from './message_validator.js';
13
12
  export * from './peer_error.js';
14
13
  export * from './constants.js';
@@ -15,3 +15,10 @@ export enum PeerErrorSeverity {
15
15
  */
16
16
  HighToleranceError = 'HighToleranceError',
17
17
  }
18
+
19
+ /** Severities ordered from mildest to harshest. */
20
+ export const PeerErrorSeverityByHarshness = [
21
+ PeerErrorSeverity.HighToleranceError,
22
+ PeerErrorSeverity.MidToleranceError,
23
+ PeerErrorSeverity.LowToleranceError,
24
+ ] as const;
@@ -1,5 +1,3 @@
1
- import { P2PClientType } from './client_type.js';
2
-
3
1
  /**
4
2
  * Creates the topic channel identifier string from a given topic type
5
3
  */
@@ -27,19 +25,14 @@ export enum TopicType {
27
25
  checkpoint_attestation = 'checkpoint_attestation',
28
26
  }
29
27
 
30
- export function getTopicTypeForClientType(clientType: P2PClientType) {
31
- if (clientType === P2PClientType.Full) {
32
- return [TopicType.tx, TopicType.block_proposal, TopicType.checkpoint_proposal, TopicType.checkpoint_attestation];
33
- } else if (clientType === P2PClientType.Prover) {
34
- return [TopicType.tx, TopicType.block_proposal, TopicType.checkpoint_proposal];
35
- } else {
36
- const _: never = clientType;
37
- return [TopicType.tx];
38
- }
39
- }
40
-
41
- export function getTopicsForClientAndConfig(clientType: P2PClientType, disableTransactions: boolean) {
42
- const topics = getTopicTypeForClientType(clientType);
28
+ /** Returns all gossip topics, optionally filtering out transactions. */
29
+ export function getTopicsForConfig(disableTransactions: boolean) {
30
+ const topics = [
31
+ TopicType.tx,
32
+ TopicType.block_proposal,
33
+ TopicType.checkpoint_proposal,
34
+ TopicType.checkpoint_attestation,
35
+ ];
43
36
  if (disableTransactions) {
44
37
  return topics.filter(topic => topic !== TopicType.tx);
45
38
  }
@@ -1,6 +1,7 @@
1
1
  import { sumBigint } from '@aztec/foundation/bigint';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import type { PartialBy } from '@aztec/foundation/types';
5
6
 
6
7
  import { getEpochForOffense } from './helpers.js';
@@ -12,6 +13,9 @@ import type { Offense, ValidatorSlashVote } from './types.js';
12
13
  * @param committees - Array of committees (each containing array of validator addresses)
13
14
  * @param epochsForCommittees - Array of epochs corresponding to each committee
14
15
  * @param settings - Settings including slashingAmounts and optional validator override lists
16
+ * @param settings.maxSlashedValidators - If set, limits the total number of [validator, epoch] pairs
17
+ * with non-zero votes. The lowest-vote pairs are zeroed out to stay within the limit.
18
+ * @param logger - Logger, logs which validators were dropped.
15
19
  * @returns Array of ValidatorSlashVote, where each vote is how many slash units the validator in that position should be slashed
16
20
  */
17
21
  export function getSlashConsensusVotesFromOffenses(
@@ -22,9 +26,11 @@ export function getSlashConsensusVotesFromOffenses(
22
26
  slashingAmounts: [bigint, bigint, bigint];
23
27
  epochDuration: number;
24
28
  targetCommitteeSize: number;
29
+ maxSlashedValidators?: number;
25
30
  },
31
+ logger: Logger = createLogger('slasher:tally'),
26
32
  ): ValidatorSlashVote[] {
27
- const { slashingAmounts, targetCommitteeSize } = settings;
33
+ const { slashingAmounts, targetCommitteeSize, maxSlashedValidators } = settings;
28
34
 
29
35
  if (committees.length !== epochsForCommittees.length) {
30
36
  throw new Error('committees and epochsForCommittees must have the same length');
@@ -53,6 +59,33 @@ export function getSlashConsensusVotesFromOffenses(
53
59
  return padArrayEnd(votes, 0, targetCommitteeSize);
54
60
  });
55
61
 
62
+ // if a cap is set, zero out the lowest-vote [validator, epoch] pairs so that the most severe slashes stay.
63
+ if (maxSlashedValidators === undefined) {
64
+ return votes;
65
+ }
66
+
67
+ const nonZeroByDescendingVote = [...votes.entries()].filter(([, vote]) => vote > 0).sort(([, a], [, b]) => b - a);
68
+
69
+ const toTruncate = nonZeroByDescendingVote.slice(maxSlashedValidators);
70
+ for (const [idx] of toTruncate) {
71
+ votes[idx] = 0;
72
+ }
73
+
74
+ if (toTruncate.length > 0) {
75
+ const truncated = toTruncate.map(([idx]) => {
76
+ const committeeIndex = Math.floor(idx / targetCommitteeSize);
77
+ const positionInCommittee = idx % targetCommitteeSize;
78
+ return {
79
+ validator: committees[committeeIndex][positionInCommittee].toString(),
80
+ epoch: epochsForCommittees[committeeIndex],
81
+ };
82
+ });
83
+ logger.warn(
84
+ `Truncated ${toTruncate.length} validator-epoch pairs to stay within limit of ${maxSlashedValidators}`,
85
+ { truncated },
86
+ );
87
+ }
88
+
56
89
  return votes;
57
90
  }
58
91
 
@@ -128,6 +128,7 @@ import {
128
128
  PublicCallRequestArrayLengths,
129
129
  } from '../kernel/public_call_request.js';
130
130
  import { PublicKeys, computeAddress } from '../keys/index.js';
131
+ import { ExtendedDirectionalAppTaggingSecret } from '../logs/extended_directional_app_tagging_secret.js';
131
132
  import { ContractClassLog, ContractClassLogFields } from '../logs/index.js';
132
133
  import { PrivateLog } from '../logs/private_log.js';
133
134
  import { FlatPublicLogs, PublicLog } from '../logs/public_log.js';
@@ -1757,3 +1758,11 @@ export function makeL2Tips(
1757
1758
  },
1758
1759
  };
1759
1760
  }
1761
+
1762
+ export async function randomExtendedDirectionalAppTaggingSecret(): Promise<ExtendedDirectionalAppTaggingSecret> {
1763
+ const resolvedApp = await AztecAddress.random();
1764
+ // Using the fromString method like this is messy as it leaks the underlying serialization format but I don't want to
1765
+ // expose the type's constructor just for tests since in prod the secret is always constructed via compute. Also this
1766
+ // method is tested in extended_directional_app_tagging_secret.test.ts hence all should be fine.
1767
+ return ExtendedDirectionalAppTaggingSecret.fromString(`${Fr.random().toString()}:${resolvedApp.toString()}`);
1768
+ }