@aztec/pxe 0.0.1-commit.3469e52 → 0.0.1-commit.358457c

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 (222) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +62 -16
  8. package/dest/config/index.d.ts +3 -1
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/contract_function_simulator.js +175 -74
  15. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
  16. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +2 -2
  17. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
  18. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  20. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
  21. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
  23. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/oracle/oracle.js +51 -29
  25. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
  26. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
  28. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +44 -36
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +79 -23
  31. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +62 -30
  32. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +107 -88
  34. package/dest/contract_logging.d.ts +22 -0
  35. package/dest/contract_logging.d.ts.map +1 -0
  36. package/dest/contract_logging.js +23 -0
  37. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  38. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  39. package/dest/contract_sync/contract_sync_service.js +97 -0
  40. package/dest/contract_sync/helpers.d.ts +29 -0
  41. package/dest/contract_sync/helpers.d.ts.map +1 -0
  42. package/dest/contract_sync/helpers.js +55 -0
  43. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  44. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  45. package/dest/debug/pxe_debug_utils.js +28 -17
  46. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  47. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  48. package/dest/entrypoints/client/bundle/index.js +3 -0
  49. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  50. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  51. package/dest/entrypoints/client/bundle/utils.js +21 -7
  52. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  53. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  54. package/dest/entrypoints/client/lazy/index.js +3 -0
  55. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  56. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/client/lazy/utils.js +22 -8
  58. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  59. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  60. package/dest/entrypoints/server/index.d.ts +4 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +3 -0
  63. package/dest/entrypoints/server/utils.d.ts +1 -1
  64. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  65. package/dest/entrypoints/server/utils.js +28 -9
  66. package/dest/events/event_service.d.ts +5 -6
  67. package/dest/events/event_service.d.ts.map +1 -1
  68. package/dest/events/event_service.js +6 -7
  69. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  70. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  71. package/dest/job_coordinator/job_coordinator.js +3 -2
  72. package/dest/logs/log_service.d.ts +7 -5
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +25 -29
  75. package/dest/notes/note_service.d.ts +9 -8
  76. package/dest/notes/note_service.d.ts.map +1 -1
  77. package/dest/notes/note_service.js +17 -16
  78. package/dest/notes_filter.d.ts +25 -0
  79. package/dest/notes_filter.d.ts.map +1 -0
  80. package/dest/notes_filter.js +4 -0
  81. package/dest/oracle_version.d.ts +3 -3
  82. package/dest/oracle_version.d.ts.map +1 -1
  83. package/dest/oracle_version.js +4 -3
  84. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  85. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  86. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  87. package/dest/private_kernel/hints/index.d.ts +1 -1
  88. package/dest/private_kernel/hints/index.js +1 -1
  89. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  90. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  91. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  92. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  93. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  94. package/dest/private_kernel/hints/test_utils.js +203 -0
  95. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  96. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  97. package/dest/private_kernel/private_kernel_execution_prover.js +21 -13
  98. package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
  99. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  100. package/dest/private_kernel/private_kernel_oracle.js +7 -3
  101. package/dest/pxe.d.ts +69 -23
  102. package/dest/pxe.d.ts.map +1 -1
  103. package/dest/pxe.js +102 -66
  104. package/dest/storage/address_store/address_store.d.ts +1 -1
  105. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  106. package/dest/storage/address_store/address_store.js +12 -11
  107. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  108. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  109. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  110. package/dest/storage/capsule_store/capsule_store.js +6 -8
  111. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  112. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  113. package/dest/storage/contract_store/contract_store.js +157 -84
  114. package/dest/storage/metadata.d.ts +1 -1
  115. package/dest/storage/metadata.js +1 -1
  116. package/dest/storage/note_store/note_store.d.ts +47 -49
  117. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  118. package/dest/storage/note_store/note_store.js +278 -252
  119. package/dest/storage/note_store/stored_note.d.ts +16 -0
  120. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  121. package/dest/storage/note_store/stored_note.js +43 -0
  122. package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
  123. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  124. package/dest/storage/private_event_store/private_event_store.js +198 -147
  125. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  126. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  127. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  128. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
  129. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  130. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  131. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  132. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  133. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  134. package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
  135. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  136. package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
  137. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  138. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  139. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  140. package/dest/tagging/index.d.ts +2 -1
  141. package/dest/tagging/index.d.ts.map +1 -1
  142. package/dest/tagging/index.js +1 -0
  143. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
  144. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  145. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +6 -6
  146. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  147. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
  148. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  149. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
  150. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
  151. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  152. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
  153. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  154. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  155. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
  156. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
  157. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  158. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +7 -4
  159. package/package.json +25 -16
  160. package/src/access_scopes.ts +9 -0
  161. package/src/bin/check_oracle_version.ts +1 -0
  162. package/src/block_synchronizer/block_synchronizer.ts +76 -33
  163. package/src/config/index.ts +14 -0
  164. package/src/config/package_info.ts +1 -1
  165. package/src/contract_function_simulator/contract_function_simulator.ts +324 -137
  166. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +2 -2
  167. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  168. package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
  169. package/src/contract_function_simulator/oracle/oracle.ts +56 -26
  170. package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
  171. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +115 -102
  172. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +172 -95
  173. package/src/contract_logging.ts +39 -0
  174. package/src/contract_sync/contract_sync_service.ts +152 -0
  175. package/src/contract_sync/helpers.ts +98 -0
  176. package/src/debug/pxe_debug_utils.ts +63 -18
  177. package/src/entrypoints/client/bundle/index.ts +3 -0
  178. package/src/entrypoints/client/bundle/utils.ts +16 -15
  179. package/src/entrypoints/client/lazy/index.ts +3 -0
  180. package/src/entrypoints/client/lazy/utils.ts +17 -15
  181. package/src/entrypoints/pxe_creation_options.ts +2 -1
  182. package/src/entrypoints/server/index.ts +3 -0
  183. package/src/entrypoints/server/utils.ts +22 -26
  184. package/src/events/event_service.ts +5 -7
  185. package/src/job_coordinator/job_coordinator.ts +4 -3
  186. package/src/logs/log_service.ts +37 -33
  187. package/src/notes/note_service.ts +24 -22
  188. package/src/notes_filter.ts +26 -0
  189. package/src/oracle_version.ts +4 -3
  190. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  191. package/src/private_kernel/hints/index.ts +1 -1
  192. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  193. package/src/private_kernel/hints/test_utils.ts +325 -0
  194. package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
  195. package/src/private_kernel/private_kernel_oracle.ts +9 -9
  196. package/src/pxe.ts +209 -111
  197. package/src/storage/address_store/address_store.ts +15 -15
  198. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  199. package/src/storage/capsule_store/capsule_store.ts +8 -8
  200. package/src/storage/contract_store/contract_store.ts +186 -96
  201. package/src/storage/metadata.ts +1 -1
  202. package/src/storage/note_store/note_store.ts +321 -318
  203. package/src/storage/note_store/stored_note.ts +48 -0
  204. package/src/storage/private_event_store/private_event_store.ts +250 -190
  205. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  206. package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
  207. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  208. package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
  209. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  210. package/src/tagging/index.ts +1 -0
  211. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +15 -5
  212. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  213. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
  214. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
  215. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
  216. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
  217. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  218. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  219. package/dest/tree_membership/tree_membership_service.d.ts +0 -50
  220. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  221. package/dest/tree_membership/tree_membership_service.js +0 -75
  222. package/src/tree_membership/tree_membership_service.ts +0 -97
@@ -0,0 +1,92 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { BlockHash } from '@aztec/stdlib/block';
3
+ import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
6
+
7
+ /**
8
+ * Generic pagination helper that fetches all pages of results.
9
+ * @param numTags - The number of tags being queried (determines result array size).
10
+ * @param fetchPage - Function that fetches a single page of results given a page number.
11
+ * @returns An array of arrays, one per tag, containing all results across all pages.
12
+ */
13
+ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Promise<T[][]>): Promise<T[][]> {
14
+ const allResultsPerTag: T[][] = Array.from({ length: numTags }, () => []);
15
+ let page = 0;
16
+ let hasMore = true;
17
+
18
+ while (hasMore) {
19
+ const resultsPage = await fetchPage(page);
20
+ hasMore = false;
21
+
22
+ for (let i = 0; i < resultsPage.length; i++) {
23
+ allResultsPerTag[i].push(...resultsPage[i]);
24
+ if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
25
+ hasMore = true;
26
+ }
27
+ }
28
+ page++;
29
+ }
30
+
31
+ return allResultsPerTag;
32
+ }
33
+
34
+ /**
35
+ * Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
36
+ * back into a single array preserving the original tag order.
37
+ */
38
+ async function getAllPagesInBatches<Tag, T>(
39
+ tags: Tag[],
40
+ fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
41
+ ): Promise<T[][]> {
42
+ if (tags.length <= MAX_RPC_LEN) {
43
+ return fetchAllPagesForBatch(tags);
44
+ }
45
+
46
+ const batches: Tag[][] = [];
47
+ for (let i = 0; i < tags.length; i += MAX_RPC_LEN) {
48
+ batches.push(tags.slice(i, i + MAX_RPC_LEN));
49
+ }
50
+ const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
51
+ return batchResults.flat();
52
+ }
53
+
54
+ /**
55
+ * Fetches all private logs for the given tags, automatically paginating through all pages.
56
+ * @param aztecNode - The Aztec node to query.
57
+ * @param tags - The siloed tags to search for.
58
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
59
+ * because of reorgs).
60
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
61
+ */
62
+ export function getAllPrivateLogsByTags(
63
+ aztecNode: AztecNode,
64
+ tags: SiloedTag[],
65
+ anchorBlockHash: BlockHash,
66
+ ): Promise<TxScopedL2Log[][]> {
67
+ return getAllPagesInBatches(tags, batch =>
68
+ getAllPages(batch.length, page => aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)),
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
74
+ * @param aztecNode - The Aztec node to query.
75
+ * @param contractAddress - The contract address to search logs for.
76
+ * @param tags - The tags to search for.
77
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
78
+ * because of reorgs).
79
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
80
+ */
81
+ export function getAllPublicLogsByTagsFromContract(
82
+ aztecNode: AztecNode,
83
+ contractAddress: AztecAddress,
84
+ tags: Tag[],
85
+ anchorBlockHash: BlockHash,
86
+ ): Promise<TxScopedL2Log[][]> {
87
+ return getAllPagesInBatches(tags, batch =>
88
+ getAllPages(batch.length, page =>
89
+ aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash),
90
+ ),
91
+ );
92
+ }
@@ -12,6 +12,7 @@
12
12
  export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
13
13
  export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
14
14
  export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
15
+ export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
15
16
 
16
17
  // Re-export tagging-related types from stdlib
17
18
  export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
@@ -1,5 +1,6 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { BlockHash } from '@aztec/stdlib/block';
3
4
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
5
  import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
5
6
 
@@ -21,6 +22,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
21
22
  aztecNode: AztecNode,
22
23
  taggingStore: RecipientTaggingStore,
23
24
  anchorBlockNumber: BlockNumber,
25
+ anchorBlockHash: BlockHash,
24
26
  jobId: string,
25
27
  ): Promise<TxScopedL2Log[]> {
26
28
  // # Explanation of how the algorithm works
@@ -28,7 +30,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
28
30
  // (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
29
31
  //
30
32
  // highestAgedIndex is the highest index that was used in a tx that is included in a block at least
31
- // `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds ago.
33
+ // `MAX_TX_LIFETIME` seconds ago.
32
34
  // highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
33
35
  //
34
36
  // "(" denotes an open end of the range - the index is not included in the range.
@@ -40,19 +42,19 @@ export async function loadPrivateLogsForSenderRecipientPair(
40
42
  // ever appear.
41
43
  //
42
44
  // This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
43
- // - a transaction's maximum inclusion timestamp is at most `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds after
45
+ // - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
44
46
  // the timestamp of its anchor block; and
45
47
  // - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
46
48
  //
47
49
  // Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
48
- // least `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds in the past. Then there is no possibility of any *other* device
50
+ // least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
49
51
  // trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
50
52
  // a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
51
53
  // chosen a larger index.
52
54
  // If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
53
55
  // because it would already have been expired.
54
56
  //
55
- // Therefore, once we see that index `I` has been used in a block that is at least `MAX_INCLUDE_BY_TIMESTAMP_DURATION`
57
+ // Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
56
58
  // seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
57
59
  //
58
60
  // ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
@@ -92,7 +94,15 @@ export async function loadPrivateLogsForSenderRecipientPair(
92
94
 
93
95
  while (true) {
94
96
  // Get private logs with their block timestamps and corresponding tagging indexes
95
- const privateLogsWithIndexes = await loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber);
97
+ const privateLogsWithIndexes = await loadLogsForRange(
98
+ secret,
99
+ app,
100
+ aztecNode,
101
+ start,
102
+ end,
103
+ anchorBlockNumber,
104
+ anchorBlockHash,
105
+ );
96
106
 
97
107
  if (privateLogsWithIndexes.length === 0) {
98
108
  break;
@@ -1,4 +1,4 @@
1
- import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
1
+ import { MAX_TX_LIFETIME } from '@aztec/constants';
2
2
  import type { TxScopedL2Log } from '@aztec/stdlib/logs';
3
3
 
4
4
  /**
@@ -16,7 +16,7 @@ export function findHighestIndexes(
16
16
  const ageInSeconds = currentTimestamp - log.blockTimestamp;
17
17
 
18
18
  if (
19
- ageInSeconds >= BigInt(MAX_INCLUDE_BY_TIMESTAMP_DURATION) &&
19
+ ageInSeconds >= BigInt(MAX_TX_LIFETIME) &&
20
20
  (highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
21
21
  ) {
22
22
  highestAgedIndex = taggingIndex;
@@ -1,9 +1,12 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { BlockHash } from '@aztec/stdlib/block';
3
4
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
5
  import type { DirectionalAppTaggingSecret, PreTag, TxScopedL2Log } from '@aztec/stdlib/logs';
5
6
  import { SiloedTag, Tag } from '@aztec/stdlib/logs';
6
7
 
8
+ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
9
+
7
10
  /**
8
11
  * Gets private logs with their corresponding block timestamps and tagging indexes for the given index range, `app` and
9
12
  * `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
@@ -16,6 +19,7 @@ export async function loadLogsForRange(
16
19
  start: number,
17
20
  end: number,
18
21
  anchorBlockNumber: BlockNumber,
22
+ anchorBlockHash: BlockHash,
19
23
  ): Promise<Array<{ log: TxScopedL2Log; taggingIndex: number }>> {
20
24
  // Derive tags for the window
21
25
  const preTags: PreTag[] = Array(end - start)
@@ -25,7 +29,9 @@ export async function loadLogsForRange(
25
29
  Promise.all(tags.map(tag => SiloedTag.compute(tag, app))),
26
30
  );
27
31
 
28
- const logs = await aztecNode.getPrivateLogsByTags(siloedTags);
32
+ // We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
33
+ // pagination here.
34
+ const logs = await getAllPrivateLogsByTags(aztecNode, siloedTags, anchorBlockHash);
29
35
 
30
36
  // Pair logs with their corresponding tagging indexes
31
37
  const logsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }> = [];
@@ -1,4 +1,5 @@
1
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { BlockHash } from '@aztec/stdlib/block';
2
3
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
4
  import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
4
5
 
@@ -26,6 +27,7 @@ export async function syncSenderTaggingIndexes(
26
27
  app: AztecAddress,
27
28
  aztecNode: AztecNode,
28
29
  taggingStore: SenderTaggingStore,
30
+ anchorBlockHash: BlockHash,
29
31
  jobId: string,
30
32
  ): Promise<void> {
31
33
  // # Explanation of how syncing works
@@ -57,7 +59,7 @@ export async function syncSenderTaggingIndexes(
57
59
  while (true) {
58
60
  // Load and store indexes for the current window. These indexes may already exist in the database if txs using
59
61
  // them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
60
- await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore, jobId);
62
+ await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore, anchorBlockHash, jobId);
61
63
 
62
64
  // Retrieve all indexes within the current window from storage and update their status accordingly.
63
65
  const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
@@ -9,11 +9,8 @@ export async function getStatusChangeOfPending(
9
9
  pending: TxHash[],
10
10
  aztecNode: AztecNode,
11
11
  ): Promise<{ txHashesToFinalize: TxHash[]; txHashesToDrop: TxHash[] }> {
12
- // Get receipts for all pending tx hashes and the finalized block number.
13
- const [receipts, tips] = await Promise.all([
14
- Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash))),
15
- aztecNode.getL2Tips(),
16
- ]);
12
+ // Get receipts for all pending tx hashes.
13
+ const receipts = await Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash)));
17
14
 
18
15
  const txHashesToFinalize: TxHash[] = [];
19
16
  const txHashesToDrop: TxHash[] = [];
@@ -22,25 +19,16 @@ export async function getStatusChangeOfPending(
22
19
  const receipt = receipts[i];
23
20
  const txHash = pending[i];
24
21
 
25
- if (
26
- receipt.status === TxStatus.SUCCESS &&
27
- receipt.blockNumber &&
28
- receipt.blockNumber <= tips.finalized.block.number
29
- ) {
22
+ if (receipt.status === TxStatus.FINALIZED && receipt.hasExecutionSucceeded()) {
30
23
  // Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
31
24
  // finalized.
32
25
  txHashesToFinalize.push(txHash);
33
- } else if (
34
- receipt.status === TxStatus.DROPPED ||
35
- receipt.status === TxStatus.APP_LOGIC_REVERTED ||
36
- receipt.status === TxStatus.TEARDOWN_REVERTED ||
37
- receipt.status === TxStatus.BOTH_REVERTED
38
- ) {
26
+ } else if (receipt.isDropped() || receipt.hasExecutionReverted()) {
39
27
  // Tx was dropped or reverted --> we drop the corresponding pending indexes.
40
28
  // TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
41
29
  txHashesToDrop.push(txHash);
42
30
  } else {
43
- // Tx is still pending or the corresponding block is not yet finalized --> we don't do anything.
31
+ // Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do anything.
44
32
  }
45
33
  }
46
34
 
@@ -1,10 +1,12 @@
1
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { BlockHash } from '@aztec/stdlib/block';
2
3
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
4
  import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
4
5
  import { SiloedTag, Tag } from '@aztec/stdlib/logs';
5
6
  import { TxHash } from '@aztec/stdlib/tx';
6
7
 
7
8
  import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
9
+ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
8
10
 
9
11
  /**
10
12
  * Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
@@ -27,6 +29,7 @@ export async function loadAndStoreNewTaggingIndexes(
27
29
  end: number,
28
30
  aztecNode: AztecNode,
29
31
  taggingStore: SenderTaggingStore,
32
+ anchorBlockHash: BlockHash,
30
33
  jobId: string,
31
34
  ) {
32
35
  // We compute the tags for the current window of indexes
@@ -37,7 +40,7 @@ export async function loadAndStoreNewTaggingIndexes(
37
40
  preTagsForWindow.map(async preTag => SiloedTag.compute(await Tag.compute(preTag), app)),
38
41
  );
39
42
 
40
- const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode);
43
+ const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
41
44
  const highestIndexMap = getTxHighestIndexMap(txsForTags, preTagsForWindow);
42
45
 
43
46
  // Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
@@ -49,8 +52,14 @@ export async function loadAndStoreNewTaggingIndexes(
49
52
 
50
53
  // Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
51
54
  // an array for each tag.
52
- async function getTxsContainingTags(tags: SiloedTag[], aztecNode: AztecNode): Promise<TxHash[][]> {
53
- const allLogs = await aztecNode.getPrivateLogsByTags(tags);
55
+ async function getTxsContainingTags(
56
+ tags: SiloedTag[],
57
+ aztecNode: AztecNode,
58
+ anchorBlockHash: BlockHash,
59
+ ): Promise<TxHash[][]> {
60
+ // We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
61
+ // pagination here.
62
+ const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
54
63
  return allLogs.map(logs => logs.map(log => log.txHash));
55
64
  }
56
65
 
@@ -1,4 +0,0 @@
1
- import type { PrivateKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
2
- import type { UInt64 } from '@aztec/stdlib/types';
3
- export declare function computeTxIncludeByTimestamp(previousKernel: PrivateKernelCircuitPublicInputs, maxDuration?: number): UInt64;
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcHV0ZV90eF9pbmNsdWRlX2J5X3RpbWVzdGFtcC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3ByaXZhdGVfa2VybmVsL2hpbnRzL2NvbXB1dGVfdHhfaW5jbHVkZV9ieV90aW1lc3RhbXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsZ0NBQWdDLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUM3RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXFCbEQsd0JBQWdCLDJCQUEyQixDQUN6QyxjQUFjLEVBQUUsZ0NBQWdDLEVBQ2hELFdBQVcsU0FBb0MsR0FDOUMsTUFBTSxDQStCUiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"compute_tx_include_by_timestamp.d.ts","sourceRoot":"","sources":["../../../src/private_kernel/hints/compute_tx_include_by_timestamp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAqBlD,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,gCAAgC,EAChD,WAAW,SAAoC,GAC9C,MAAM,CA+BR"}
@@ -1,50 +0,0 @@
1
- import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { SiblingPath } from '@aztec/foundation/trees';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { L2BlockHash } from '@aztec/stdlib/block';
6
- import type { AztecNode } from '@aztec/stdlib/interfaces/server';
7
- import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
8
- export declare class TreeMembershipService {
9
- #private;
10
- private readonly aztecNode;
11
- constructor(aztecNode: AztecNode);
12
- /**
13
- * Gets the index of a nullifier in the nullifier tree.
14
- * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
15
- */
16
- getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
17
- /**
18
- * Fetches the index and sibling path of a leaf at a given block from a given tree.
19
- * @param blockHash - The block hash at which to get the membership witness.
20
- * @param treeId - Id of the tree to get the sibling path from.
21
- * @param leafValue - The leaf value
22
- * @returns The index and sibling path concatenated [index, sibling_path]
23
- */
24
- getMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;
25
- /**
26
- * Returns a low nullifier membership witness for a given nullifier at a given block.
27
- * @param blockHash - The block hash at which to get the index.
28
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
29
- * @returns The low nullifier membership witness (if found).
30
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
31
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
32
- * we are trying to prove non-inclusion for.
33
- */
34
- getLowNullifierMembershipWitness(blockHash: L2BlockHash, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
35
- /**
36
- * Returns a witness for a given slot of the public data tree at a given block.
37
- * @param blockHash - The block hash at which to get the witness.
38
- * @param leafSlot - The slot of the public data in the public data tree.
39
- */
40
- getPublicDataWitness(blockHash: L2BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
41
- /**
42
- * Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
43
- * @param contractAddress - Address of a contract by which the message was emitted.
44
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
45
- * The message nullifier is computed locally, so the secret is not sent to the node.
46
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
47
- */
48
- getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;
49
- }
50
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJlZV9tZW1iZXJzaGlwX3NlcnZpY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cmVlX21lbWJlcnNoaXAvdHJlZV9tZW1iZXJzaGlwX3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFakUsT0FBTyxFQUFFLFlBQVksRUFBRSwwQkFBMEIsRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBTWxHLHFCQUFhLHFCQUFxQjs7SUFDcEIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxTQUFTO0lBQXRDLFlBQTZCLFNBQVMsRUFBRSxTQUFTLEVBQUk7SUFFckQ7OztPQUdHO0lBQ1UsaUJBQWlCLENBQUMsU0FBUyxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQUd6RTtJQUVEOzs7Ozs7T0FNRztJQUNVLG9CQUFvQixDQUFDLFNBQVMsRUFBRSxXQUFXLEVBQUUsTUFBTSxFQUFFLFlBQVksRUFBRSxTQUFTLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQVE1RztJQUVEOzs7Ozs7OztPQVFHO0lBQ0ksZ0NBQWdDLENBQ3JDLFNBQVMsRUFBRSxXQUFXLEVBQ3RCLFNBQVMsRUFBRSxFQUFFLEdBQ1osT0FBTyxDQUFDLDBCQUEwQixHQUFHLFNBQVMsQ0FBQyxDQUVqRDtJQUVEOzs7O09BSUc7SUFDSSxvQkFBb0IsQ0FBQyxTQUFTLEVBQUUsV0FBVyxFQUFFLFFBQVEsRUFBRSxFQUFFLEdBQUcsT0FBTyxDQUFDLGlCQUFpQixHQUFHLFNBQVMsQ0FBQyxDQUV4RztJQUVEOzs7Ozs7T0FNRztJQUNJLDBCQUEwQixDQUMvQixlQUFlLEVBQUUsWUFBWSxFQUM3QixXQUFXLEVBQUUsRUFBRSxFQUNmLE1BQU0sRUFBRSxFQUFFLEdBQ1QsT0FBTyxDQUFDLENBQUMsTUFBTSxFQUFFLFdBQVcsQ0FBQyxPQUFPLHdCQUF3QixDQUFDLENBQUMsQ0FBQyxDQUVqRTtDQWdCRiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"tree_membership_service.d.ts","sourceRoot":"","sources":["../../src/tree_membership/tree_membership_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMlG,qBAAa,qBAAqB;;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAAtC,YAA6B,SAAS,EAAE,SAAS,EAAI;IAErD;;;OAGG;IACU,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAGzE;IAED;;;;;;OAMG;IACU,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC,CAQ5G;IAED;;;;;;;;OAQG;IACI,gCAAgC,CACrC,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAEjD;IAED;;;;OAIG;IACI,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAExG;IAED;;;;;;OAMG;IACI,0BAA0B,CAC/B,eAAe,EAAE,YAAY,EAC7B,WAAW,EAAE,EAAE,EACf,MAAM,EAAE,EAAE,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAEjE;CAgBF"}
@@ -1,75 +0,0 @@
1
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
2
- import { MerkleTreeId } from '@aztec/stdlib/trees';
3
- // TODO: REmove this class as it no longer seems valuable. The only somewhat real functionality in this class is in
4
- // the `getMembershipWitness` method that is used by `utilityGetMembershipWitness` oracle by then in Aztec.nr we
5
- // have helper functions around that oracle for archive and note hash tree and the generic method itself is not used
6
- // anywhere else - make sense to just have simple specific handlers for the archive and note hash trees and drop this.
7
- export class TreeMembershipService {
8
- aztecNode;
9
- constructor(aztecNode){
10
- this.aztecNode = aztecNode;
11
- }
12
- /**
13
- * Gets the index of a nullifier in the nullifier tree.
14
- * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
15
- */ async getNullifierIndex(nullifier) {
16
- const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
17
- nullifier
18
- ]);
19
- return leafIndex?.data;
20
- }
21
- /**
22
- * Fetches the index and sibling path of a leaf at a given block from a given tree.
23
- * @param blockHash - The block hash at which to get the membership witness.
24
- * @param treeId - Id of the tree to get the sibling path from.
25
- * @param leafValue - The leaf value
26
- * @returns The index and sibling path concatenated [index, sibling_path]
27
- */ async getMembershipWitness(blockHash, treeId, leafValue) {
28
- const witness = await this.#tryGetMembershipWitness(blockHash, treeId, leafValue);
29
- if (!witness) {
30
- throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block hash ${blockHash.toString()}`);
31
- }
32
- return witness;
33
- }
34
- /**
35
- * Returns a low nullifier membership witness for a given nullifier at a given block.
36
- * @param blockHash - The block hash at which to get the index.
37
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
38
- * @returns The low nullifier membership witness (if found).
39
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
40
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
41
- * we are trying to prove non-inclusion for.
42
- */ getLowNullifierMembershipWitness(blockHash, nullifier) {
43
- return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
44
- }
45
- /**
46
- * Returns a witness for a given slot of the public data tree at a given block.
47
- * @param blockHash - The block hash at which to get the witness.
48
- * @param leafSlot - The slot of the public data in the public data tree.
49
- */ getPublicDataWitness(blockHash, leafSlot) {
50
- return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
51
- }
52
- /**
53
- * Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
54
- * @param contractAddress - Address of a contract by which the message was emitted.
55
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
56
- * The message nullifier is computed locally, so the secret is not sent to the node.
57
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
58
- */ getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
59
- return getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
60
- }
61
- async #tryGetMembershipWitness(blockHash, treeId, value) {
62
- switch(treeId){
63
- case MerkleTreeId.NULLIFIER_TREE:
64
- return (await this.aztecNode.getNullifierMembershipWitness(blockHash, value))?.withoutPreimage().toFields();
65
- case MerkleTreeId.NOTE_HASH_TREE:
66
- return (await this.aztecNode.getNoteHashMembershipWitness(blockHash, value))?.toFields();
67
- case MerkleTreeId.PUBLIC_DATA_TREE:
68
- return (await this.aztecNode.getPublicDataWitness(blockHash, value))?.withoutPreimage().toFields();
69
- case MerkleTreeId.ARCHIVE:
70
- return (await this.aztecNode.getArchiveMembershipWitness(blockHash, value))?.toFields();
71
- default:
72
- throw new Error('Not implemented');
73
- }
74
- }
75
- }
@@ -1,97 +0,0 @@
1
- import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { SiblingPath } from '@aztec/foundation/trees';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { L2BlockHash } from '@aztec/stdlib/block';
6
- import type { AztecNode } from '@aztec/stdlib/interfaces/server';
7
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
8
- import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
9
-
10
- // TODO: REmove this class as it no longer seems valuable. The only somewhat real functionality in this class is in
11
- // the `getMembershipWitness` method that is used by `utilityGetMembershipWitness` oracle by then in Aztec.nr we
12
- // have helper functions around that oracle for archive and note hash tree and the generic method itself is not used
13
- // anywhere else - make sense to just have simple specific handlers for the archive and note hash trees and drop this.
14
- export class TreeMembershipService {
15
- constructor(private readonly aztecNode: AztecNode) {}
16
-
17
- /**
18
- * Gets the index of a nullifier in the nullifier tree.
19
- * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
20
- */
21
- public async getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
22
- const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [nullifier]);
23
- return leafIndex?.data;
24
- }
25
-
26
- /**
27
- * Fetches the index and sibling path of a leaf at a given block from a given tree.
28
- * @param blockHash - The block hash at which to get the membership witness.
29
- * @param treeId - Id of the tree to get the sibling path from.
30
- * @param leafValue - The leaf value
31
- * @returns The index and sibling path concatenated [index, sibling_path]
32
- */
33
- public async getMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
34
- const witness = await this.#tryGetMembershipWitness(blockHash, treeId, leafValue);
35
- if (!witness) {
36
- throw new Error(
37
- `Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block hash ${blockHash.toString()}`,
38
- );
39
- }
40
- return witness;
41
- }
42
-
43
- /**
44
- * Returns a low nullifier membership witness for a given nullifier at a given block.
45
- * @param blockHash - The block hash at which to get the index.
46
- * @param nullifier - Nullifier we try to find the low nullifier witness for.
47
- * @returns The low nullifier membership witness (if found).
48
- * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
49
- * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
50
- * we are trying to prove non-inclusion for.
51
- */
52
- public getLowNullifierMembershipWitness(
53
- blockHash: L2BlockHash,
54
- nullifier: Fr,
55
- ): Promise<NullifierMembershipWitness | undefined> {
56
- return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
57
- }
58
-
59
- /**
60
- * Returns a witness for a given slot of the public data tree at a given block.
61
- * @param blockHash - The block hash at which to get the witness.
62
- * @param leafSlot - The slot of the public data in the public data tree.
63
- */
64
- public getPublicDataWitness(blockHash: L2BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
65
- return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
66
- }
67
-
68
- /**
69
- * Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
70
- * @param contractAddress - Address of a contract by which the message was emitted.
71
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
72
- * The message nullifier is computed locally, so the secret is not sent to the node.
73
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
74
- */
75
- public getL1ToL2MembershipWitness(
76
- contractAddress: AztecAddress,
77
- messageHash: Fr,
78
- secret: Fr,
79
- ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
80
- return getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
81
- }
82
-
83
- async #tryGetMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, value: Fr): Promise<Fr[] | undefined> {
84
- switch (treeId) {
85
- case MerkleTreeId.NULLIFIER_TREE:
86
- return (await this.aztecNode.getNullifierMembershipWitness(blockHash, value))?.withoutPreimage().toFields();
87
- case MerkleTreeId.NOTE_HASH_TREE:
88
- return (await this.aztecNode.getNoteHashMembershipWitness(blockHash, value))?.toFields();
89
- case MerkleTreeId.PUBLIC_DATA_TREE:
90
- return (await this.aztecNode.getPublicDataWitness(blockHash, value))?.withoutPreimage().toFields();
91
- case MerkleTreeId.ARCHIVE:
92
- return (await this.aztecNode.getArchiveMembershipWitness(blockHash, value))?.toFields();
93
- default:
94
- throw new Error('Not implemented');
95
- }
96
- }
97
- }