@aztec/pxe 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (379) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +1 -1
  3. package/dest/bin/check_oracle_version.js +110 -10
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  6. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +23 -23
  7. package/dest/block_synchronizer/index.d.ts +2 -0
  8. package/dest/block_synchronizer/index.d.ts.map +1 -0
  9. package/dest/block_synchronizer/index.js +1 -0
  10. package/dest/config/index.d.ts +9 -17
  11. package/dest/config/index.d.ts.map +1 -1
  12. package/dest/config/index.js +10 -16
  13. package/dest/config/package_info.d.ts +1 -1
  14. package/dest/config/package_info.js +1 -1
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +44 -15
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +142 -57
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +11 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +28 -17
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  24. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  25. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.d.ts +4 -2
  27. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/index.js +2 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -3
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  43. package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
  44. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/index.js +1 -1
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +103 -0
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts +17 -15
  56. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/oracle/oracle.js +101 -81
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts +11 -12
  59. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  60. package/dest/contract_function_simulator/oracle/private_execution.js +15 -24
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +51 -25
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +103 -27
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -36
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  66. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +171 -69
  67. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  68. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  69. package/dest/contract_function_simulator/pick_notes.js +1 -1
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  71. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  72. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  73. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  74. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  75. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  76. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  77. package/dest/debug/pxe_debug_utils.js +37 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +4 -3
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +2 -2
  81. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +21 -12
  84. package/dest/entrypoints/client/lazy/index.d.ts +4 -3
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +2 -2
  87. package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +20 -11
  90. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.d.ts +5 -3
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +3 -2
  95. package/dest/entrypoints/server/utils.d.ts +5 -24
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +17 -45
  98. package/dest/error_enriching.d.ts +11 -0
  99. package/dest/error_enriching.d.ts.map +1 -0
  100. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
  101. package/dest/events/event_service.d.ts +15 -0
  102. package/dest/events/event_service.d.ts.map +1 -0
  103. package/dest/events/event_service.js +47 -0
  104. package/dest/events/index.d.ts +2 -0
  105. package/dest/events/index.d.ts.map +1 -0
  106. package/dest/events/index.js +1 -0
  107. package/dest/events/private_event_filter_validator.d.ts +9 -0
  108. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  109. package/dest/events/private_event_filter_validator.js +39 -0
  110. package/dest/logs/log_service.d.ts +26 -0
  111. package/dest/logs/log_service.d.ts.map +1 -0
  112. package/dest/logs/log_service.js +120 -0
  113. package/dest/notes/index.d.ts +2 -0
  114. package/dest/notes/index.d.ts.map +1 -0
  115. package/dest/notes/index.js +1 -0
  116. package/dest/notes/note_service.d.ts +48 -0
  117. package/dest/notes/note_service.d.ts.map +1 -0
  118. package/dest/notes/note_service.js +152 -0
  119. package/dest/oracle_version.d.ts +3 -3
  120. package/dest/oracle_version.js +2 -2
  121. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  122. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  123. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  124. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  125. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
  126. package/dest/private_kernel/hints/index.d.ts +1 -1
  127. package/dest/private_kernel/index.d.ts +1 -1
  128. package/dest/private_kernel/private_kernel_execution_prover.d.ts +9 -2
  129. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  130. package/dest/private_kernel/private_kernel_execution_prover.js +38 -32
  131. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
  132. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  133. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +10 -9
  134. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  135. package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
  136. package/dest/public_storage/public_storage_service.d.ts +24 -0
  137. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  138. package/dest/public_storage/public_storage_service.js +26 -0
  139. package/dest/pxe.d.ts +232 -0
  140. package/dest/pxe.d.ts.map +1 -0
  141. package/dest/{pxe_service/pxe_service.js → pxe.js} +299 -324
  142. package/dest/storage/address_store/address_store.d.ts +11 -0
  143. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  144. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -4
  145. package/dest/storage/address_store/index.d.ts +2 -0
  146. package/dest/storage/address_store/index.d.ts.map +1 -0
  147. package/dest/storage/address_store/index.js +1 -0
  148. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
  149. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  150. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -12
  151. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  152. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  153. package/dest/storage/anchor_block_store/index.js +1 -0
  154. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  155. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  156. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -10
  157. package/dest/storage/capsule_store/index.d.ts +2 -0
  158. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  159. package/dest/storage/capsule_store/index.js +1 -0
  160. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +10 -18
  161. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  162. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -18
  163. package/dest/storage/contract_store/index.d.ts +2 -0
  164. package/dest/storage/contract_store/index.d.ts.map +1 -0
  165. package/dest/storage/contract_store/index.js +1 -0
  166. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  167. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  168. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  169. package/dest/storage/index.d.ts +8 -9
  170. package/dest/storage/index.d.ts.map +1 -1
  171. package/dest/storage/index.js +7 -8
  172. package/dest/storage/metadata.d.ts +1 -1
  173. package/dest/storage/note_store/index.d.ts +3 -0
  174. package/dest/storage/note_store/index.d.ts.map +1 -0
  175. package/dest/storage/note_store/index.js +2 -0
  176. package/dest/storage/note_store/note_store.d.ts +84 -0
  177. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  178. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +144 -82
  179. package/dest/storage/private_event_store/private_event_store.d.ts +56 -0
  180. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  181. package/dest/storage/private_event_store/private_event_store.js +157 -0
  182. package/dest/storage/tagging_store/index.d.ts +4 -0
  183. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  184. package/dest/storage/tagging_store/index.js +3 -0
  185. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  186. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  187. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  188. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  189. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  190. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  191. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  192. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  193. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  194. package/dest/tagging/index.d.ts +16 -0
  195. package/dest/tagging/index.d.ts.map +1 -0
  196. package/dest/tagging/index.js +23 -0
  197. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  198. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  199. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  200. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  201. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  202. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  203. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  204. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  205. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  206. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  207. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  208. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  209. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  210. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  211. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  212. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  213. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  214. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  215. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  216. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  217. package/dest/tree_membership/tree_membership_service.js +84 -0
  218. package/package.json +22 -24
  219. package/src/bin/check_oracle_version.ts +134 -10
  220. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +22 -23
  221. package/src/block_synchronizer/index.ts +1 -0
  222. package/src/config/index.ts +18 -32
  223. package/src/config/package_info.ts +1 -1
  224. package/src/contract_function_simulator/contract_function_simulator.ts +233 -75
  225. package/src/contract_function_simulator/execution_note_cache.ts +33 -17
  226. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  227. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  228. package/src/contract_function_simulator/index.ts +3 -1
  229. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  230. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  231. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
  232. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
  233. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  234. package/src/contract_function_simulator/oracle/index.ts +1 -1
  235. package/src/contract_function_simulator/oracle/interfaces.ts +175 -0
  236. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  237. package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
  238. package/src/contract_function_simulator/oracle/oracle.ts +135 -80
  239. package/src/contract_function_simulator/oracle/private_execution.ts +22 -28
  240. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +200 -56
  241. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +260 -109
  242. package/src/contract_function_simulator/pick_notes.ts +1 -1
  243. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  244. package/src/debug/pxe_debug_utils.ts +48 -0
  245. package/src/entrypoints/client/bundle/index.ts +3 -2
  246. package/src/entrypoints/client/bundle/utils.ts +21 -23
  247. package/src/entrypoints/client/lazy/index.ts +3 -2
  248. package/src/entrypoints/client/lazy/utils.ts +20 -23
  249. package/src/entrypoints/pxe_creation_options.ts +4 -1
  250. package/src/entrypoints/server/index.ts +4 -2
  251. package/src/entrypoints/server/utils.ts +20 -68
  252. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
  253. package/src/events/event_service.ts +77 -0
  254. package/src/events/index.ts +1 -0
  255. package/src/events/private_event_filter_validator.ts +48 -0
  256. package/src/logs/log_service.ts +202 -0
  257. package/src/notes/index.ts +1 -0
  258. package/src/notes/note_service.ts +200 -0
  259. package/src/oracle_version.ts +2 -2
  260. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
  261. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
  262. package/src/private_kernel/private_kernel_execution_prover.ts +51 -43
  263. package/src/private_kernel/private_kernel_oracle.ts +2 -1
  264. package/src/private_kernel/private_kernel_oracle_impl.ts +10 -9
  265. package/src/public_storage/public_storage_service.ts +33 -0
  266. package/src/{pxe_service/pxe_service.ts → pxe.ts} +349 -410
  267. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -7
  268. package/src/storage/address_store/index.ts +1 -0
  269. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -17
  270. package/src/storage/anchor_block_store/index.ts +1 -0
  271. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -12
  272. package/src/storage/capsule_store/index.ts +1 -0
  273. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -28
  274. package/src/storage/contract_store/index.ts +1 -0
  275. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  276. package/src/storage/index.ts +7 -8
  277. package/src/storage/note_store/index.ts +2 -0
  278. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +173 -111
  279. package/src/storage/private_event_store/private_event_store.ts +213 -0
  280. package/src/storage/tagging_store/index.ts +3 -0
  281. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  282. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  283. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  284. package/src/tagging/index.ts +28 -0
  285. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  286. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  287. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  288. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  289. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
  290. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  291. package/src/tree_membership/tree_membership_service.ts +112 -0
  292. package/dest/bin/index.d.ts +0 -3
  293. package/dest/bin/index.d.ts.map +0 -1
  294. package/dest/bin/index.js +0 -48
  295. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
  296. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  297. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  298. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  299. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  300. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  301. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
  302. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  303. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  304. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  305. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  306. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  307. package/dest/pxe_service/error_enriching.d.ts +0 -11
  308. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  309. package/dest/pxe_service/index.d.ts +0 -3
  310. package/dest/pxe_service/index.d.ts.map +0 -1
  311. package/dest/pxe_service/index.js +0 -2
  312. package/dest/pxe_service/pxe_service.d.ts +0 -100
  313. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  314. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
  315. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  316. package/dest/storage/address_data_provider/index.d.ts +0 -2
  317. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  318. package/dest/storage/address_data_provider/index.js +0 -1
  319. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
  320. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  321. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  322. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  323. package/dest/storage/capsule_data_provider/index.js +0 -1
  324. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  325. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  326. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  327. package/dest/storage/contract_data_provider/index.js +0 -1
  328. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  329. package/dest/storage/data_provider.d.ts +0 -4
  330. package/dest/storage/data_provider.d.ts.map +0 -1
  331. package/dest/storage/data_provider.js +0 -1
  332. package/dest/storage/note_data_provider/index.d.ts +0 -3
  333. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  334. package/dest/storage/note_data_provider/index.js +0 -2
  335. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  336. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  337. package/dest/storage/note_data_provider/note_dao.js +0 -102
  338. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
  339. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  340. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  341. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  342. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
  343. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  344. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  345. package/dest/storage/sync_data_provider/index.js +0 -1
  346. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  347. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  348. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  349. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  350. package/dest/storage/tagging_data_provider/index.js +0 -1
  351. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  352. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  353. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
  354. package/dest/synchronizer/index.d.ts +0 -2
  355. package/dest/synchronizer/index.d.ts.map +0 -1
  356. package/dest/synchronizer/index.js +0 -1
  357. package/dest/synchronizer/synchronizer.d.ts +0 -35
  358. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  359. package/dest/test/pxe_test_suite.d.ts +0 -3
  360. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  361. package/dest/test/pxe_test_suite.js +0 -97
  362. package/src/bin/index.ts +0 -62
  363. package/src/contract_function_simulator/execution_data_provider.ts +0 -361
  364. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  365. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
  366. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  367. package/src/pxe_service/index.ts +0 -2
  368. package/src/storage/address_data_provider/index.ts +0 -1
  369. package/src/storage/capsule_data_provider/index.ts +0 -1
  370. package/src/storage/contract_data_provider/index.ts +0 -1
  371. package/src/storage/data_provider.ts +0 -3
  372. package/src/storage/note_data_provider/index.ts +0 -2
  373. package/src/storage/note_data_provider/note_dao.ts +0 -154
  374. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
  375. package/src/storage/sync_data_provider/index.ts +0 -1
  376. package/src/storage/tagging_data_provider/index.ts +0 -1
  377. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
  378. package/src/synchronizer/index.ts +0 -1
  379. package/src/test/pxe_test_suite.ts +0 -113
@@ -0,0 +1,129 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
+ import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
5
+
6
+ import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
7
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../index.js';
8
+ import { findHighestIndexes } from './utils/find_highest_indexes.js';
9
+ import { loadLogsForRange } from './utils/load_logs_for_range.js';
10
+
11
+ /**
12
+ * Loads private logs for `app` and sender-recipient pair defined by `secret` and updates the highest aged and
13
+ * finalized indexes in the db. At most load logs from blocks up to and including `anchorBlockNumber`.
14
+ *
15
+ * @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
16
+ * in the tagging data provider is indexed by the secret and hence completely disjoint.
17
+ */
18
+ export async function loadPrivateLogsForSenderRecipientPair(
19
+ secret: DirectionalAppTaggingSecret,
20
+ app: AztecAddress,
21
+ aztecNode: AztecNode,
22
+ taggingStore: RecipientTaggingStore,
23
+ anchorBlockNumber: BlockNumber,
24
+ ): Promise<TxScopedL2Log[]> {
25
+ // # Explanation of how the algorithm works
26
+ // When we perform the sync we will look at logs that correspond to the tagging index range
27
+ // (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
28
+ //
29
+ // highestAgedIndex is the highest index that was used in a tx that is included in a block at least
30
+ // `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds ago.
31
+ // highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
32
+ //
33
+ // "(" denotes an open end of the range - the index is not included in the range.
34
+ // "]" denotes a closed end of the range - the index is included in the range.
35
+ //
36
+ // ## Explanation of highestAgedIndex
37
+ //
38
+ // highestAgedIndex is chosen such that for all tagging indexes `i <= highestAgedIndex` we know that no new logs can
39
+ // ever appear.
40
+ //
41
+ // This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
42
+ // - a transaction's maximum inclusion timestamp is at most `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds after
43
+ // the timestamp of its anchor block; and
44
+ // - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
45
+ //
46
+ // Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
47
+ // least `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds in the past. Then there is no possibility of any *other* device
48
+ // trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
49
+ // a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
50
+ // chosen a larger index.
51
+ // If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
52
+ // because it would already have been expired.
53
+ //
54
+ // Therefore, once we see that index `I` has been used in a block that is at least `MAX_INCLUDE_BY_TIMESTAMP_DURATION`
55
+ // seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
56
+ //
57
+ // ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
58
+ //
59
+ // When a sender chooses a tagging index, they will select an index that is at most `WINDOW_LEN` greater than
60
+ // the highest finalized index. If that index was already used, they will throw an error. For this reason we
61
+ // don't have to look further than `highestFinalizedIndex + WINDOW_LEN`.
62
+
63
+ let finalizedBlockNumber: number, currentTimestamp: bigint;
64
+ {
65
+ const [l2Tips, latestBlockHeader] = await Promise.all([aztecNode.getL2Tips(), aztecNode.getBlockHeader('latest')]);
66
+
67
+ if (!latestBlockHeader) {
68
+ throw new Error('Node failed to return latest block header when syncing logs');
69
+ }
70
+
71
+ [finalizedBlockNumber, currentTimestamp] = [l2Tips.finalized.number, latestBlockHeader.globalVariables.timestamp];
72
+ }
73
+
74
+ let start: number, end: number;
75
+ {
76
+ const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret);
77
+ const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret);
78
+
79
+ // We don't want to include the highest aged index so we start from `currentHighestAgedIndex + 1` (or 0 if not set)
80
+ start = currentHighestAgedIndex === undefined ? 0 : currentHighestAgedIndex + 1;
81
+
82
+ // The highest index a sender can choose is "highest finalized index + window length" but given that
83
+ // `loadLogsForRange` expects an exclusive `end` we add 1.
84
+ end = (currentHighestFinalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
85
+ }
86
+
87
+ const logs: TxScopedL2Log[] = [];
88
+
89
+ while (true) {
90
+ // Get private logs with their block timestamps and corresponding tagging indexes
91
+ const privateLogsWithIndexes = await loadLogsForRange(secret, app, aztecNode, start, end, anchorBlockNumber);
92
+
93
+ if (privateLogsWithIndexes.length === 0) {
94
+ break;
95
+ }
96
+
97
+ logs.push(...privateLogsWithIndexes.map(({ log }) => log));
98
+
99
+ const { highestAgedIndex, highestFinalizedIndex } = findHighestIndexes(
100
+ privateLogsWithIndexes,
101
+ currentTimestamp,
102
+ finalizedBlockNumber,
103
+ );
104
+
105
+ // Store updates in data provider and update local variables
106
+ if (highestAgedIndex !== undefined) {
107
+ await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex);
108
+ }
109
+
110
+ if (highestFinalizedIndex === undefined) {
111
+ // We have not found a new highest finalized index, so there is no need to move the window forward.
112
+ break;
113
+ }
114
+
115
+ if (highestAgedIndex !== undefined && highestAgedIndex > highestFinalizedIndex) {
116
+ // This is just a sanity check as this should never happen.
117
+ throw new Error('Highest aged index lower than highest finalized index invariant violated');
118
+ }
119
+
120
+ await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex);
121
+
122
+ // For the next iteration we want to look only at indexes for which we have not attempted to load logs yet while
123
+ // ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
124
+ start = end;
125
+ end = highestFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1; // `end` is exclusive so we add 1.
126
+ }
127
+
128
+ return logs;
129
+ }
@@ -0,0 +1,34 @@
1
+ import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
2
+ import type { TxScopedL2Log } from '@aztec/stdlib/logs';
3
+
4
+ /**
5
+ * Finds the highest aged and the highest finalized tagging indexes.
6
+ */
7
+ export function findHighestIndexes(
8
+ privateLogsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }>,
9
+ currentTimestamp: bigint,
10
+ finalizedBlockNumber: number,
11
+ ): { highestAgedIndex: number | undefined; highestFinalizedIndex: number | undefined } {
12
+ let highestAgedIndex = undefined;
13
+ let highestFinalizedIndex = undefined;
14
+
15
+ for (const { log, taggingIndex } of privateLogsWithIndexes) {
16
+ const ageInSeconds = currentTimestamp - log.blockTimestamp;
17
+
18
+ if (
19
+ ageInSeconds >= BigInt(MAX_INCLUDE_BY_TIMESTAMP_DURATION) &&
20
+ (highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
21
+ ) {
22
+ highestAgedIndex = taggingIndex;
23
+ }
24
+
25
+ if (
26
+ log.blockNumber <= finalizedBlockNumber &&
27
+ (highestFinalizedIndex === undefined || taggingIndex > highestFinalizedIndex)
28
+ ) {
29
+ highestFinalizedIndex = taggingIndex;
30
+ }
31
+ }
32
+
33
+ return { highestAgedIndex, highestFinalizedIndex };
34
+ }
@@ -0,0 +1,43 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
+ import type { DirectionalAppTaggingSecret, PreTag, TxScopedL2Log } from '@aztec/stdlib/logs';
5
+ import { SiloedTag, Tag } from '@aztec/stdlib/logs';
6
+
7
+ /**
8
+ * Gets private logs with their corresponding block timestamps and tagging indexes for the given index range, `app` and
9
+ * `secret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and `end` is
10
+ * exclusive.
11
+ */
12
+ export async function loadLogsForRange(
13
+ secret: DirectionalAppTaggingSecret,
14
+ app: AztecAddress,
15
+ aztecNode: AztecNode,
16
+ start: number,
17
+ end: number,
18
+ anchorBlockNumber: BlockNumber,
19
+ ): Promise<Array<{ log: TxScopedL2Log; taggingIndex: number }>> {
20
+ // Derive tags for the window
21
+ const preTags: PreTag[] = Array(end - start)
22
+ .fill(0)
23
+ .map((_, i) => ({ secret, index: start + i }));
24
+ const siloedTags = await Promise.all(preTags.map(preTag => Tag.compute(preTag))).then(tags =>
25
+ Promise.all(tags.map(tag => SiloedTag.compute(tag, app))),
26
+ );
27
+
28
+ const logs = await aztecNode.getPrivateLogsByTags(siloedTags);
29
+
30
+ // Pair logs with their corresponding tagging indexes
31
+ const logsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }> = [];
32
+ for (let i = 0; i < logs.length; i++) {
33
+ const logsForTag = logs[i];
34
+ const taggingIndex = preTags[i].index;
35
+ for (const log of logsForTag) {
36
+ if (log.blockNumber <= anchorBlockNumber) {
37
+ logsWithIndexes.push({ log, taggingIndex });
38
+ }
39
+ }
40
+ }
41
+
42
+ return logsWithIndexes;
43
+ }
@@ -0,0 +1,96 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
+ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
4
+
5
+ import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
6
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../index.js';
7
+ import { getStatusChangeOfPending } from './utils/get_status_change_of_pending.js';
8
+ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_tagging_indexes.js';
9
+
10
+ /**
11
+ * Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
12
+ *
13
+ * @param secret - The secret that's unique for (sender, recipient, contract) tuple while the direction of
14
+ * sender -> recipient matters.
15
+ * @param app - The address of the contract that the logs are tagged for. Needs to be provided because we perform
16
+ * second round of siloing in this function which is necessary because kernels do it as well (they silo first field
17
+ * of the private log which corresponds to the tag).
18
+ * @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
19
+ * pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
20
+ * is simply the highest pending index plus one (or finalized if pending is undefined).
21
+ * @dev This function looks for new indexes, adds them to pending, then it checks status of each pending index and
22
+ * updates its status accordingly.
23
+ */
24
+ export async function syncSenderTaggingIndexes(
25
+ secret: DirectionalAppTaggingSecret,
26
+ app: AztecAddress,
27
+ aztecNode: AztecNode,
28
+ taggingStore: SenderTaggingStore,
29
+ ): Promise<void> {
30
+ // # Explanation of how syncing works
31
+ //
32
+ // When choosing an index, we select: highest pending index + 1 (or highest finalized index + 1 if no pending).
33
+ // If the chosen index is more than WINDOW_LEN from the highest finalized index, we throw an error. By having this
34
+ // hard limit we give a guarantee to a recipient that he doesn't need to look further than WINDOW_LEN ahead of the
35
+ // highest finalized index.
36
+ //
37
+ // This function synchronizes the finalized and pending indexes by iteratively querying the node for a window of
38
+ // indexes at a time, storing all those indexes as pending, and then checking the status of each pending index to
39
+ // update its finalization status accordingly. If we stumble upon a window with no indexes, we stop the loop.
40
+ //
41
+ // Stopping at that point is safe because of the limit described above - there can never be an index that is more
42
+ // than WINDOW_LEN from the highest finalized index.
43
+ //
44
+ // # Note on performance
45
+ // Each window advance requires two queries (logs + tx status). For example, syncing indexes 0–500 with a window of
46
+ // 100 takes at least 10 round trips (5 windows × 2 queries).
47
+
48
+ const finalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
49
+
50
+ let start = finalizedIndex === undefined ? 0 : finalizedIndex + 1;
51
+ let end = start + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN;
52
+
53
+ let previousFinalizedIndex = finalizedIndex;
54
+ let newFinalizedIndex = undefined;
55
+
56
+ while (true) {
57
+ // Load and store indexes for the current window. These indexes may already exist in the database if txs using
58
+ // them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
59
+ await loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore);
60
+
61
+ // Retrieve all indexes within the current window from storage and update their status accordingly.
62
+ const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end);
63
+ if (pendingTxHashes.length === 0) {
64
+ break;
65
+ }
66
+
67
+ const { txHashesToFinalize, txHashesToDrop } = await getStatusChangeOfPending(pendingTxHashes, aztecNode);
68
+
69
+ await taggingStore.dropPendingIndexes(txHashesToDrop);
70
+ await taggingStore.finalizePendingIndexes(txHashesToFinalize);
71
+
72
+ // We check if the finalized index has been updated.
73
+ newFinalizedIndex = await taggingStore.getLastFinalizedIndex(secret);
74
+ if (previousFinalizedIndex !== newFinalizedIndex) {
75
+ // A new finalized index was found, so we'll run the loop again. For example:
76
+ // - Previous finalized index: 10
77
+ // - New finalized index: 13
78
+ // - Window length: 10
79
+ //
80
+ // In the last iteration, we processed indexes 11-20. To avoid reprocessing the same logs,
81
+ // we'll only look at the new indexes 21-23:
82
+ //
83
+ // Previous window: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
84
+ // New window: [21, 22, 23]
85
+
86
+ const previousEnd = end;
87
+ // Add 1 because `end` is exclusive and the known finalized index is not included in the window.
88
+ end = newFinalizedIndex! + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
89
+ start = previousEnd;
90
+ previousFinalizedIndex = newFinalizedIndex;
91
+ } else {
92
+ // No new finalized index was found, so we don't need to process the next window.
93
+ break;
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,44 @@
1
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
2
+ import { TxHash, TxStatus } from '@aztec/stdlib/tx';
3
+
4
+ /**
5
+ * Based on receipts obtained from `aztecNode` returns which pending transactions changed their status to finalized or
6
+ * dropped.
7
+ */
8
+ export async function getStatusChangeOfPending(
9
+ pending: TxHash[],
10
+ aztecNode: AztecNode,
11
+ ): Promise<{ txHashesToFinalize: TxHash[]; txHashesToDrop: TxHash[] }> {
12
+ // Get receipts for all pending tx hashes and the finalized block number.
13
+ const [receipts, { finalized }] = await Promise.all([
14
+ Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash))),
15
+ aztecNode.getL2Tips(),
16
+ ]);
17
+
18
+ const txHashesToFinalize: TxHash[] = [];
19
+ const txHashesToDrop: TxHash[] = [];
20
+
21
+ for (let i = 0; i < receipts.length; i++) {
22
+ const receipt = receipts[i];
23
+ const txHash = pending[i];
24
+
25
+ if (receipt.status === TxStatus.SUCCESS && receipt.blockNumber && receipt.blockNumber <= finalized.number) {
26
+ // Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
27
+ // finalized.
28
+ txHashesToFinalize.push(txHash);
29
+ } else if (
30
+ receipt.status === TxStatus.DROPPED ||
31
+ receipt.status === TxStatus.APP_LOGIC_REVERTED ||
32
+ receipt.status === TxStatus.TEARDOWN_REVERTED ||
33
+ receipt.status === TxStatus.BOTH_REVERTED
34
+ ) {
35
+ // Tx was dropped or reverted --> we drop the corresponding pending indexes.
36
+ // TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
37
+ txHashesToDrop.push(txHash);
38
+ } else {
39
+ // Tx is still pending or the corresponding block is not yet finalized --> we don't do anything.
40
+ }
41
+ }
42
+
43
+ return { txHashesToFinalize, txHashesToDrop };
44
+ }
@@ -0,0 +1,72 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
4
+ import { SiloedTag, Tag } from '@aztec/stdlib/logs';
5
+ import { TxHash } from '@aztec/stdlib/tx';
6
+
7
+ import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
8
+
9
+ /**
10
+ * Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
11
+ * @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
12
+ * place is when a tx is being sent from this PXE.
13
+ * @param secret - The directional app tagging secret that's unique for (sender, recipient, contract) tuple.
14
+ * @param app - The address of the contract that the logs are tagged for. Used for siloing tags to match
15
+ * kernel circuit behavior.
16
+ * @param start - The starting index (inclusive) of the window to process.
17
+ * @param end - The ending index (exclusive) of the window to process.
18
+ * @param aztecNode - The Aztec node instance to query for logs.
19
+ * @param taggingStore - The data provider to store pending indexes.
20
+ */
21
+ export async function loadAndStoreNewTaggingIndexes(
22
+ secret: DirectionalAppTaggingSecret,
23
+ app: AztecAddress,
24
+ start: number,
25
+ end: number,
26
+ aztecNode: AztecNode,
27
+ taggingStore: SenderTaggingStore,
28
+ ) {
29
+ // We compute the tags for the current window of indexes
30
+ const preTagsForWindow: PreTag[] = Array(end - start)
31
+ .fill(0)
32
+ .map((_, i) => ({ secret, index: start + i }));
33
+ const siloedTagsForWindow = await Promise.all(
34
+ preTagsForWindow.map(async preTag => SiloedTag.compute(await Tag.compute(preTag), app)),
35
+ );
36
+
37
+ const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode);
38
+ const highestIndexMap = getTxHighestIndexMap(txsForTags, preTagsForWindow);
39
+
40
+ // Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
41
+ for (const [txHashStr, highestIndex] of highestIndexMap.entries()) {
42
+ const txHash = TxHash.fromString(txHashStr);
43
+ await taggingStore.storePendingIndexes([{ secret, index: highestIndex }], txHash);
44
+ }
45
+ }
46
+
47
+ // Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
48
+ // an array for each tag.
49
+ async function getTxsContainingTags(tags: SiloedTag[], aztecNode: AztecNode): Promise<TxHash[][]> {
50
+ const allLogs = await aztecNode.getPrivateLogsByTags(tags);
51
+ return allLogs.map(logs => logs.map(log => log.txHash));
52
+ }
53
+
54
+ // Returns a map of txHash to the highest index for that txHash.
55
+ function getTxHighestIndexMap(txHashesForTags: TxHash[][], preTagsForWindow: PreTag[]): Map<string, number> {
56
+ if (txHashesForTags.length !== preTagsForWindow.length) {
57
+ throw new Error(
58
+ `Number of tx hashes arrays does not match number of pre-tags. ${txHashesForTags.length} !== ${preTagsForWindow.length}`,
59
+ );
60
+ }
61
+
62
+ const highestIndexMap = new Map<string, number>();
63
+ for (let i = 0; i < txHashesForTags.length; i++) {
64
+ const taggingIndex = preTagsForWindow[i].index;
65
+ const txHashesForTag = txHashesForTags[i];
66
+ for (const txHash of txHashesForTag) {
67
+ const key = txHash.toString();
68
+ highestIndexMap.set(key, Math.max(highestIndexMap.get(key) ?? 0, taggingIndex));
69
+ }
70
+ }
71
+ return highestIndexMap;
72
+ }
@@ -0,0 +1,112 @@
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 type { BlockParameter } 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
+ import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
11
+
12
+ export class TreeMembershipService {
13
+ constructor(
14
+ private readonly aztecNode: AztecNode,
15
+ private readonly anchorBlockStore: AnchorBlockStore,
16
+ ) {}
17
+
18
+ /**
19
+ * Gets the index of a nullifier in the nullifier tree.
20
+ * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
21
+ */
22
+ public getNullifierIndex(nullifier: Fr) {
23
+ return this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
24
+ }
25
+
26
+ /**
27
+ * Fetches the index and sibling path of a leaf at a given block from a given tree.
28
+ * @param blockNumber - The block number 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(blockNumber: BlockParameter, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
34
+ const witness = await this.#tryGetMembershipWitness(blockNumber, treeId, leafValue);
35
+ if (!witness) {
36
+ throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block ${blockNumber}`);
37
+ }
38
+ return witness;
39
+ }
40
+
41
+ /**
42
+ * Returns a low nullifier membership witness for a given nullifier at a given block.
43
+ * @param blockNumber - The block number at which to get the index.
44
+ * @param nullifier - Nullifier we try to find the low nullifier witness for.
45
+ * @returns The low nullifier membership witness (if found).
46
+ * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
47
+ * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
48
+ * we are trying to prove non-inclusion for.
49
+ */
50
+ public async getLowNullifierMembershipWitness(
51
+ blockNumber: BlockParameter,
52
+ nullifier: Fr,
53
+ ): Promise<NullifierMembershipWitness | undefined> {
54
+ const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
55
+ if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
56
+ throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
57
+ }
58
+ return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
59
+ }
60
+
61
+ /**
62
+ * Returns a witness for a given slot of the public data tree at a given block.
63
+ * @param blockNumber - The block number at which to get the witness.
64
+ * @param leafSlot - The slot of the public data in the public data tree.
65
+ */
66
+ public async getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
67
+ const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
68
+ if (blockNumber !== 'latest' && blockNumber > anchorBlockNumber) {
69
+ throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
70
+ }
71
+ return await this.aztecNode.getPublicDataWitness(blockNumber, leafSlot);
72
+ }
73
+
74
+ /**
75
+ * Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
76
+ * @param contractAddress - Address of a contract by which the message was emitted.
77
+ * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
78
+ * The message nullifier is computed locally, so the secret is not sent to the node.
79
+ * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
80
+ */
81
+ public getL1ToL2MembershipWitness(
82
+ contractAddress: AztecAddress,
83
+ messageHash: Fr,
84
+ secret: Fr,
85
+ ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
86
+ return getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
87
+ }
88
+
89
+ async #tryGetMembershipWitness(
90
+ blockNumber: BlockParameter,
91
+ treeId: MerkleTreeId,
92
+ value: Fr,
93
+ ): Promise<Fr[] | undefined> {
94
+ switch (treeId) {
95
+ case MerkleTreeId.NULLIFIER_TREE:
96
+ return (await this.aztecNode.getNullifierMembershipWitness(blockNumber, value))?.withoutPreimage().toFields();
97
+ case MerkleTreeId.NOTE_HASH_TREE:
98
+ return (await this.aztecNode.getNoteHashMembershipWitness(blockNumber, value))?.toFields();
99
+ case MerkleTreeId.PUBLIC_DATA_TREE:
100
+ return (await this.aztecNode.getPublicDataWitness(blockNumber, value))?.withoutPreimage().toFields();
101
+ case MerkleTreeId.ARCHIVE:
102
+ return (await this.aztecNode.getArchiveMembershipWitness(blockNumber, value))?.toFields();
103
+ default:
104
+ throw new Error('Not implemented');
105
+ }
106
+ }
107
+
108
+ async #findLeafIndex(blockNumber: BlockParameter, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
109
+ const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]);
110
+ return leafIndex?.data;
111
+ }
112
+ }
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- export {};
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":""}
package/dest/bin/index.js DELETED
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- import { createNamespacedSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { PXESchema, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
5
- import http from 'http';
6
- import { getPXEServiceConfig } from '../config/index.js';
7
- import { createPXEService } from '../entrypoints/server/utils.js';
8
- const { PXE_PORT = 8080, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env;
9
- const logger = createLogger('pxe:service');
10
- /**
11
- * Creates an http server that forwards calls to the PXE and starts it on the given port.
12
- * @param pxeService - PXE that answers queries to the created HTTP server.
13
- * @param port - Port to listen in.
14
- * @param maxBatchSize - Maximum allowed batch size for JSON RPC batch requests.
15
- * @returns A running http server.
16
- */ function startPXEHttpServer(pxeService, port, opts = {}) {
17
- const rpcServer = createNamespacedSafeJsonRpcServer({
18
- pxe: [
19
- pxeService,
20
- PXESchema
21
- ]
22
- }, opts);
23
- const app = rpcServer.getApp();
24
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
25
- const httpServer = http.createServer(app.callback());
26
- httpServer.listen(port);
27
- return httpServer;
28
- }
29
- /**
30
- * Create and start a new PXE HTTP Server
31
- */ async function main() {
32
- logger.info(`Setting up PXE...`);
33
- const pxeConfig = getPXEServiceConfig();
34
- const nodeRpcClient = createAztecNodeClient(AZTEC_NODE_URL, {});
35
- const pxeService = await createPXEService(nodeRpcClient, pxeConfig);
36
- const shutdown = ()=>{
37
- logger.info('Shutting down...');
38
- process.exit(0);
39
- };
40
- process.once('SIGINT', shutdown);
41
- process.once('SIGTERM', shutdown);
42
- startPXEHttpServer(pxeService, PXE_PORT);
43
- logger.info(`PXE listening on port ${PXE_PORT}`);
44
- }
45
- main().catch((err)=>{
46
- logger.error(err);
47
- process.exit(1);
48
- });