@aztec/pxe 0.0.0-test.1 → 0.0.1-commit.03f7ef2

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 (402) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +2 -0
  3. package/dest/bin/check_oracle_version.d.ts.map +1 -0
  4. package/dest/bin/check_oracle_version.js +129 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  7. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +36 -32
  8. package/dest/block_synchronizer/index.d.ts +2 -0
  9. package/dest/block_synchronizer/index.d.ts.map +1 -0
  10. package/dest/block_synchronizer/index.js +1 -0
  11. package/dest/config/index.d.ts +11 -24
  12. package/dest/config/index.d.ts.map +1 -1
  13. package/dest/config/index.js +18 -33
  14. package/dest/config/package_info.d.ts +1 -1
  15. package/dest/config/package_info.js +1 -1
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts +83 -0
  17. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/contract_function_simulator.js +325 -0
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts +95 -0
  20. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/execution_note_cache.js +191 -0
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  25. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  26. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  27. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  28. package/dest/contract_function_simulator/index.d.ts +14 -0
  29. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/index.js +12 -0
  31. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
  32. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +16 -0
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +26 -0
  37. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
  38. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
  40. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +24 -0
  41. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +51 -0
  43. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  44. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  46. package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
  47. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/oracle/index.js +2 -0
  49. package/dest/contract_function_simulator/oracle/interfaces.d.ts +103 -0
  50. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  51. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  52. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +17 -0
  53. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  54. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  55. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +28 -0
  56. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  57. package/dest/contract_function_simulator/oracle/note_packing_utils.js +54 -0
  58. package/dest/contract_function_simulator/oracle/oracle.d.ts +58 -0
  59. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  60. package/dest/contract_function_simulator/oracle/oracle.js +345 -0
  61. package/dest/contract_function_simulator/oracle/private_execution.d.ts +47 -0
  62. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  63. package/dest/contract_function_simulator/oracle/private_execution.js +123 -0
  64. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +240 -0
  65. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  66. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +439 -0
  67. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +195 -0
  68. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  69. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +372 -0
  70. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  71. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  72. package/dest/contract_function_simulator/pick_notes.js +51 -0
  73. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
  74. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
  75. package/dest/contract_function_simulator/proxied_contract_data_source.js +80 -0
  76. package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
  77. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
  78. package/dest/contract_function_simulator/proxied_node.js +27 -0
  79. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  80. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  81. package/dest/debug/pxe_debug_utils.js +37 -0
  82. package/dest/entrypoints/client/bundle/index.d.ts +4 -3
  83. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  84. package/dest/entrypoints/client/bundle/index.js +2 -2
  85. package/dest/entrypoints/client/bundle/utils.d.ts +10 -10
  86. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  87. package/dest/entrypoints/client/bundle/utils.js +18 -12
  88. package/dest/entrypoints/client/lazy/index.d.ts +4 -3
  89. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  90. package/dest/entrypoints/client/lazy/index.js +2 -2
  91. package/dest/entrypoints/client/lazy/utils.d.ts +9 -9
  92. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  93. package/dest/entrypoints/client/lazy/utils.js +17 -11
  94. package/dest/entrypoints/pxe_creation_options.d.ts +16 -0
  95. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  96. package/dest/entrypoints/server/index.d.ts +6 -4
  97. package/dest/entrypoints/server/index.d.ts.map +1 -1
  98. package/dest/entrypoints/server/index.js +4 -3
  99. package/dest/entrypoints/server/utils.d.ts +8 -16
  100. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  101. package/dest/entrypoints/server/utils.js +31 -36
  102. package/dest/error_enriching.d.ts +11 -0
  103. package/dest/error_enriching.d.ts.map +1 -0
  104. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +26 -18
  105. package/dest/events/event_service.d.ts +15 -0
  106. package/dest/events/event_service.d.ts.map +1 -0
  107. package/dest/events/event_service.js +47 -0
  108. package/dest/events/index.d.ts +2 -0
  109. package/dest/events/index.d.ts.map +1 -0
  110. package/dest/events/index.js +1 -0
  111. package/dest/events/private_event_filter_validator.d.ts +9 -0
  112. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  113. package/dest/events/private_event_filter_validator.js +39 -0
  114. package/dest/logs/log_service.d.ts +43 -0
  115. package/dest/logs/log_service.d.ts.map +1 -0
  116. package/dest/logs/log_service.js +239 -0
  117. package/dest/notes/index.d.ts +2 -0
  118. package/dest/notes/index.d.ts.map +1 -0
  119. package/dest/notes/index.js +1 -0
  120. package/dest/notes/note_service.d.ts +48 -0
  121. package/dest/notes/note_service.d.ts.map +1 -0
  122. package/dest/notes/note_service.js +152 -0
  123. package/dest/oracle_version.d.ts +3 -0
  124. package/dest/oracle_version.d.ts.map +1 -0
  125. package/dest/oracle_version.js +10 -0
  126. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +28 -0
  127. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
  128. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
  129. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  130. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  131. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  132. package/dest/private_kernel/hints/index.d.ts +3 -0
  133. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  134. package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
  135. package/dest/private_kernel/index.d.ts +3 -0
  136. package/dest/private_kernel/index.d.ts.map +1 -0
  137. package/dest/private_kernel/index.js +2 -0
  138. package/dest/private_kernel/private_kernel_execution_prover.d.ts +44 -0
  139. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  140. package/dest/private_kernel/private_kernel_execution_prover.js +286 -0
  141. package/dest/private_kernel/private_kernel_oracle.d.ts +63 -0
  142. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  143. package/dest/private_kernel/private_kernel_oracle.js +4 -0
  144. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +46 -0
  145. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
  146. package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
  147. package/dest/public_storage/public_storage_service.d.ts +24 -0
  148. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  149. package/dest/public_storage/public_storage_service.js +26 -0
  150. package/dest/pxe.d.ts +231 -0
  151. package/dest/pxe.d.ts.map +1 -0
  152. package/dest/pxe.js +756 -0
  153. package/dest/storage/address_data_provider/address_data_provider.d.ts +2 -4
  154. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  155. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  156. package/dest/storage/address_data_provider/index.d.ts +1 -1
  157. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts +9 -0
  158. package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +1 -0
  159. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_data_provider/anchor_block_data_provider.js} +2 -12
  160. package/dest/storage/anchor_block_data_provider/index.d.ts +2 -0
  161. package/dest/storage/anchor_block_data_provider/index.d.ts.map +1 -0
  162. package/dest/storage/anchor_block_data_provider/index.js +1 -0
  163. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +48 -7
  164. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  165. package/dest/storage/capsule_data_provider/capsule_data_provider.js +117 -28
  166. package/dest/storage/capsule_data_provider/index.d.ts +1 -1
  167. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +16 -59
  168. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  169. package/dest/storage/contract_data_provider/contract_data_provider.js +121 -80
  170. package/dest/storage/contract_data_provider/index.d.ts +1 -2
  171. package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
  172. package/dest/storage/contract_data_provider/index.js +0 -1
  173. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +3 -42
  174. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  175. package/dest/storage/contract_data_provider/private_functions_tree.js +10 -62
  176. package/dest/storage/index.d.ts +4 -5
  177. package/dest/storage/index.d.ts.map +1 -1
  178. package/dest/storage/index.js +3 -4
  179. package/dest/storage/metadata.d.ts +2 -0
  180. package/dest/storage/metadata.d.ts.map +1 -0
  181. package/dest/storage/metadata.js +1 -0
  182. package/dest/storage/note_data_provider/index.d.ts +2 -2
  183. package/dest/storage/note_data_provider/index.d.ts.map +1 -1
  184. package/dest/storage/note_data_provider/index.js +1 -1
  185. package/dest/storage/note_data_provider/note_data_provider.d.ts +75 -11
  186. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  187. package/dest/storage/note_data_provider/note_data_provider.js +155 -82
  188. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +51 -0
  189. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
  190. package/dest/storage/private_event_data_provider/private_event_data_provider.js +115 -0
  191. package/dest/storage/tagging_data_provider/index.d.ts +3 -2
  192. package/dest/storage/tagging_data_provider/index.d.ts.map +1 -1
  193. package/dest/storage/tagging_data_provider/index.js +2 -1
  194. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +31 -0
  195. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +1 -0
  196. package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +65 -0
  197. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts +67 -0
  198. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +1 -0
  199. package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +196 -0
  200. package/dest/tagging/constants.d.ts +2 -0
  201. package/dest/tagging/constants.d.ts.map +1 -0
  202. package/dest/tagging/constants.js +3 -0
  203. package/dest/tagging/index.d.ts +5 -0
  204. package/dest/tagging/index.d.ts.map +1 -0
  205. package/dest/tagging/index.js +3 -0
  206. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  207. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  208. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  209. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +21 -0
  210. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +1 -0
  211. package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +42 -0
  212. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  213. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  214. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  215. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  216. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  217. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  218. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +21 -0
  219. package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  220. package/dest/tagging/sync/sync_sender_tagging_indexes.js +89 -0
  221. package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts +11 -0
  222. package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  223. package/dest/tagging/sync/utils/get_status_change_of_pending.js +32 -0
  224. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  225. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  226. package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  227. package/dest/tagging/utils.d.ts +18 -0
  228. package/dest/tagging/utils.d.ts.map +1 -0
  229. package/dest/tagging/utils.js +25 -0
  230. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  231. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  232. package/dest/tree_membership/tree_membership_service.js +84 -0
  233. package/package.json +37 -34
  234. package/src/bin/check_oracle_version.ts +160 -0
  235. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +39 -35
  236. package/src/block_synchronizer/index.ts +1 -0
  237. package/src/config/index.ts +27 -55
  238. package/src/config/package_info.ts +1 -1
  239. package/src/contract_function_simulator/contract_function_simulator.ts +618 -0
  240. package/src/contract_function_simulator/execution_note_cache.ts +233 -0
  241. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  242. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  243. package/src/contract_function_simulator/index.ts +13 -0
  244. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
  245. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +28 -0
  246. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
  247. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +64 -0
  248. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  249. package/src/contract_function_simulator/oracle/index.ts +16 -0
  250. package/src/contract_function_simulator/oracle/interfaces.ts +175 -0
  251. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  252. package/src/contract_function_simulator/oracle/note_packing_utils.ts +68 -0
  253. package/src/contract_function_simulator/oracle/oracle.ts +605 -0
  254. package/src/contract_function_simulator/oracle/private_execution.ts +209 -0
  255. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +704 -0
  256. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +532 -0
  257. package/src/contract_function_simulator/pick_notes.ts +141 -0
  258. package/src/contract_function_simulator/proxied_contract_data_source.ts +83 -0
  259. package/src/contract_function_simulator/proxied_node.ts +33 -0
  260. package/src/debug/pxe_debug_utils.ts +48 -0
  261. package/src/entrypoints/client/bundle/index.ts +3 -2
  262. package/src/entrypoints/client/bundle/utils.ts +36 -36
  263. package/src/entrypoints/client/lazy/index.ts +3 -2
  264. package/src/entrypoints/client/lazy/utils.ts +36 -31
  265. package/src/entrypoints/pxe_creation_options.ts +12 -0
  266. package/src/entrypoints/server/index.ts +5 -3
  267. package/src/entrypoints/server/utils.ts +59 -51
  268. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +36 -27
  269. package/src/events/event_service.ts +77 -0
  270. package/src/events/index.ts +1 -0
  271. package/src/events/private_event_filter_validator.ts +48 -0
  272. package/src/logs/log_service.ts +364 -0
  273. package/src/notes/index.ts +1 -0
  274. package/src/notes/note_service.ts +200 -0
  275. package/src/oracle_version.ts +11 -0
  276. package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +159 -147
  277. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  278. package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
  279. package/src/private_kernel/index.ts +2 -0
  280. package/src/private_kernel/private_kernel_execution_prover.ts +432 -0
  281. package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +19 -30
  282. package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +33 -17
  283. package/src/public_storage/public_storage_service.ts +33 -0
  284. package/src/pxe.ts +1063 -0
  285. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  286. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_data_provider/anchor_block_data_provider.ts} +2 -17
  287. package/src/storage/anchor_block_data_provider/index.ts +1 -0
  288. package/src/storage/capsule_data_provider/capsule_data_provider.ts +130 -31
  289. package/src/storage/contract_data_provider/contract_data_provider.ts +152 -94
  290. package/src/storage/contract_data_provider/index.ts +0 -1
  291. package/src/storage/contract_data_provider/private_functions_tree.ts +12 -76
  292. package/src/storage/index.ts +3 -5
  293. package/src/storage/metadata.ts +1 -0
  294. package/src/storage/note_data_provider/index.ts +1 -1
  295. package/src/storage/note_data_provider/note_data_provider.ts +188 -121
  296. package/src/storage/private_event_data_provider/private_event_data_provider.ts +162 -0
  297. package/src/storage/tagging_data_provider/index.ts +2 -1
  298. package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +86 -0
  299. package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +244 -0
  300. package/src/tagging/constants.ts +3 -0
  301. package/src/tagging/index.ts +4 -0
  302. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  303. package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +53 -0
  304. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  305. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  306. package/src/tagging/sync/sync_sender_tagging_indexes.ts +112 -0
  307. package/src/tagging/sync/utils/get_status_change_of_pending.ts +44 -0
  308. package/src/tagging/sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  309. package/src/tagging/utils.ts +32 -0
  310. package/src/tree_membership/tree_membership_service.ts +112 -0
  311. package/dest/bin/index.d.ts +0 -3
  312. package/dest/bin/index.d.ts.map +0 -1
  313. package/dest/bin/index.js +0 -28
  314. package/dest/entrypoints/client/pxe_creation_options.d.ts +0 -11
  315. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  316. package/dest/kernel_oracle/index.d.ts +0 -45
  317. package/dest/kernel_oracle/index.d.ts.map +0 -1
  318. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  319. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  320. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
  321. package/dest/kernel_prover/hints/index.d.ts +0 -2
  322. package/dest/kernel_prover/hints/index.d.ts.map +0 -1
  323. package/dest/kernel_prover/index.d.ts +0 -3
  324. package/dest/kernel_prover/index.d.ts.map +0 -1
  325. package/dest/kernel_prover/index.js +0 -2
  326. package/dest/kernel_prover/kernel_prover.d.ts +0 -38
  327. package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
  328. package/dest/kernel_prover/kernel_prover.js +0 -217
  329. package/dest/kernel_prover/proving_data_oracle.d.ts +0 -73
  330. package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
  331. package/dest/kernel_prover/proving_data_oracle.js +0 -4
  332. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
  333. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
  334. package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
  335. package/dest/pxe_http/index.d.ts +0 -2
  336. package/dest/pxe_http/index.d.ts.map +0 -1
  337. package/dest/pxe_http/index.js +0 -1
  338. package/dest/pxe_http/pxe_http_server.d.ts +0 -16
  339. package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
  340. package/dest/pxe_http/pxe_http_server.js +0 -27
  341. package/dest/pxe_oracle_interface/index.d.ts +0 -159
  342. package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
  343. package/dest/pxe_oracle_interface/index.js +0 -692
  344. package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
  345. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  346. package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
  347. package/dest/pxe_service/error_enriching.d.ts +0 -11
  348. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  349. package/dest/pxe_service/index.d.ts +0 -3
  350. package/dest/pxe_service/index.d.ts.map +0 -1
  351. package/dest/pxe_service/index.js +0 -2
  352. package/dest/pxe_service/pxe_service.d.ts +0 -111
  353. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  354. package/dest/pxe_service/pxe_service.js +0 -664
  355. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
  356. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
  357. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
  358. package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
  359. package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
  360. package/dest/storage/auth_witness_data_provider/index.js +0 -1
  361. package/dest/storage/data_provider.d.ts +0 -4
  362. package/dest/storage/data_provider.d.ts.map +0 -1
  363. package/dest/storage/data_provider.js +0 -1
  364. package/dest/storage/note_data_provider/note_dao.d.ts +0 -106
  365. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  366. package/dest/storage/note_data_provider/note_dao.js +0 -106
  367. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  368. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  369. package/dest/storage/sync_data_provider/index.js +0 -1
  370. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  371. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  372. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  373. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  374. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -65
  375. package/dest/synchronizer/index.d.ts +0 -2
  376. package/dest/synchronizer/index.d.ts.map +0 -1
  377. package/dest/synchronizer/index.js +0 -1
  378. package/dest/synchronizer/synchronizer.d.ts +0 -37
  379. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  380. package/dest/test/pxe_test_suite.d.ts +0 -3
  381. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  382. package/dest/test/pxe_test_suite.js +0 -97
  383. package/src/bin/index.ts +0 -38
  384. package/src/entrypoints/client/pxe_creation_options.ts +0 -7
  385. package/src/kernel_prover/index.ts +0 -2
  386. package/src/kernel_prover/kernel_prover.ts +0 -351
  387. package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
  388. package/src/pxe_http/index.ts +0 -1
  389. package/src/pxe_http/pxe_http_server.ts +0 -29
  390. package/src/pxe_oracle_interface/index.ts +0 -925
  391. package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
  392. package/src/pxe_service/index.ts +0 -2
  393. package/src/pxe_service/pxe_service.ts +0 -949
  394. package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
  395. package/src/storage/auth_witness_data_provider/index.ts +0 -1
  396. package/src/storage/data_provider.ts +0 -3
  397. package/src/storage/note_data_provider/note_dao.ts +0 -162
  398. package/src/storage/sync_data_provider/index.ts +0 -1
  399. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -92
  400. package/src/synchronizer/index.ts +0 -1
  401. package/src/test/pxe_test_suite.ts +0 -111
  402. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
@@ -0,0 +1,162 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
+ import type { AztecAsyncArray, AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
6
+ import type { EventSelector } from '@aztec/stdlib/abi';
7
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import { L2BlockHash } from '@aztec/stdlib/block';
9
+ import { type InTx, TxHash } from '@aztec/stdlib/tx';
10
+
11
+ import type { PackedPrivateEvent } from '../../pxe.js';
12
+
13
+ export type PrivateEventDataProviderFilter = {
14
+ contractAddress: AztecAddress;
15
+ fromBlock: number;
16
+ toBlock: number;
17
+ scopes: AztecAddress[];
18
+ txHash?: TxHash;
19
+ };
20
+
21
+ type PrivateEventEntry = {
22
+ msgContent: Buffer;
23
+ eventCommitmentIndex: number;
24
+ l2BlockNumber: number;
25
+ l2BlockHash: Buffer;
26
+ txHash: Buffer;
27
+ };
28
+
29
+ type PrivateEventMetadata = InTx & {
30
+ contractAddress: AztecAddress;
31
+ scope: AztecAddress;
32
+ };
33
+
34
+ /**
35
+ * Stores decrypted private event logs.
36
+ */
37
+ export class PrivateEventDataProvider {
38
+ #store: AztecAsyncKVStore;
39
+ /** Array storing the actual private event log entries containing the log content and block number */
40
+ #eventLogs: AztecAsyncArray<PrivateEventEntry>;
41
+ /** Map from contract_address_scope_eventSelector to array of indices into #eventLogs for efficient lookup */
42
+ #eventLogIndex: AztecAsyncMap<string, number[]>;
43
+ /** Map from eventCommitmentIndex to boolean indicating if log has been seen. */
44
+ #seenLogs: AztecAsyncMap<number, boolean>;
45
+
46
+ logger = createLogger('private_event_data_provider');
47
+
48
+ constructor(store: AztecAsyncKVStore) {
49
+ this.#store = store;
50
+ this.#eventLogs = this.#store.openArray('private_event_logs');
51
+ this.#eventLogIndex = this.#store.openMap('private_event_log_index');
52
+ this.#seenLogs = this.#store.openMap('seen_logs');
53
+ }
54
+
55
+ #keyFor(contractAddress: AztecAddress, scope: AztecAddress, eventSelector: EventSelector): string {
56
+ return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
57
+ }
58
+
59
+ /**
60
+ * Store a private event log.
61
+ * @param eventSelector - The event selector of the event.
62
+ * @param msgContent - The content of the event.
63
+ * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
64
+ * @param metadata
65
+ * contractAddress - The address of the contract that emitted the event.
66
+ * scope - The address to which the event is scoped.
67
+ * txHash - The transaction hash of the event log.
68
+ * blockNumber - The block number in which the event was emitted.
69
+ */
70
+ storePrivateEventLog(
71
+ eventSelector: EventSelector,
72
+ msgContent: Fr[],
73
+ eventCommitmentIndex: number,
74
+ metadata: PrivateEventMetadata,
75
+ ): Promise<void> {
76
+ const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash } = metadata;
77
+
78
+ return this.#store.transactionAsync(async () => {
79
+ const key = this.#keyFor(contractAddress, scope, eventSelector);
80
+
81
+ // Check if this exact log has already been stored using eventCommitmentIndex as unique identifier
82
+ const hasBeenSeen = await this.#seenLogs.getAsync(eventCommitmentIndex);
83
+ if (hasBeenSeen) {
84
+ this.logger.verbose('Ignoring duplicate event log', { txHash: txHash.toString(), eventCommitmentIndex });
85
+ return;
86
+ }
87
+
88
+ this.logger.verbose('storing private event log', { contractAddress, scope, msgContent, l2BlockNumber });
89
+
90
+ const index = await this.#eventLogs.lengthAsync();
91
+ await this.#eventLogs.push({
92
+ msgContent: serializeToBuffer(msgContent),
93
+ l2BlockNumber,
94
+ l2BlockHash: l2BlockHash.toBuffer(),
95
+ eventCommitmentIndex,
96
+ txHash: txHash.toBuffer(),
97
+ });
98
+
99
+ const existingIndices = (await this.#eventLogIndex.getAsync(key)) || [];
100
+ await this.#eventLogIndex.set(key, [...existingIndices, index]);
101
+
102
+ // Mark this log as seen using eventCommitmentIndex
103
+ await this.#seenLogs.set(eventCommitmentIndex, true);
104
+ });
105
+ }
106
+
107
+ /**
108
+ * Returns the private events given search parameters.
109
+ * @param eventSelector - The event selector to filter by.
110
+ * @param filter - Filtering criteria:
111
+ * contractAddress: The address of the contract to get events from.
112
+ * fromBlock: The block number to search from (inclusive).
113
+ * toBlock: The block number to search upto (exclusive).
114
+ * scope: - The addresses that decrypted the logs.
115
+ * @returns - The event log contents, augmented with metadata about
116
+ * the transaction and block it the event was included in .
117
+ */
118
+ public async getPrivateEvents(
119
+ eventSelector: EventSelector,
120
+ filter: PrivateEventDataProviderFilter,
121
+ ): Promise<PackedPrivateEvent[]> {
122
+ const events: Array<{ eventCommitmentIndex: number; event: PackedPrivateEvent }> = [];
123
+
124
+ for (const scope of filter.scopes) {
125
+ const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
126
+ const indices = (await this.#eventLogIndex.getAsync(key)) || [];
127
+
128
+ for (const index of indices) {
129
+ const entry = await this.#eventLogs.atAsync(index);
130
+ if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
131
+ continue;
132
+ }
133
+
134
+ // Convert buffer back to Fr array
135
+ const reader = BufferReader.asReader(entry.msgContent);
136
+ const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
137
+ const msgContent = reader.readArray(numFields, Fr);
138
+ const txHash = TxHash.fromBuffer(entry.txHash);
139
+ const l2BlockHash = L2BlockHash.fromBuffer(entry.l2BlockHash);
140
+
141
+ if (filter.txHash && !txHash.equals(filter.txHash)) {
142
+ continue;
143
+ }
144
+
145
+ events.push({
146
+ eventCommitmentIndex: entry.eventCommitmentIndex,
147
+ event: {
148
+ packedEvent: msgContent,
149
+ l2BlockNumber: BlockNumber(entry.l2BlockNumber),
150
+ txHash,
151
+ l2BlockHash,
152
+ eventSelector,
153
+ },
154
+ });
155
+ }
156
+ }
157
+
158
+ // Sort by eventCommitmentIndex only
159
+ events.sort((a, b) => a.eventCommitmentIndex - b.eventCommitmentIndex);
160
+ return events.map(ev => ev.event);
161
+ }
162
+ }
@@ -1 +1,2 @@
1
- export { TaggingDataProvider } from './tagging_data_provider.js';
1
+ export { SenderTaggingDataProvider } from './sender_tagging_data_provider.js';
2
+ export { RecipientTaggingDataProvider } from './recipient_tagging_data_provider.js';
@@ -0,0 +1,86 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
5
+
6
+ /**
7
+ * Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class is
8
+ * called SenderTaggingDataProvider. We have the providers separate for the sender and recipient because
9
+ * the algorithms are completely disjoint and there is not data reuse between the 2.
10
+ */
11
+ export class RecipientTaggingDataProvider {
12
+ #store: AztecAsyncKVStore;
13
+ #addressBook: AztecAsyncMap<string, true>;
14
+
15
+ // Stores the last used index for each directional app tagging secret.
16
+ #lastUsedIndexes: AztecAsyncMap<string, number>;
17
+
18
+ constructor(store: AztecAsyncKVStore) {
19
+ this.#store = store;
20
+
21
+ this.#addressBook = this.#store.openMap('address_book');
22
+ this.#lastUsedIndexes = this.#store.openMap('last_used_indexes');
23
+ }
24
+
25
+ /**
26
+ * Sets the last used indexes when looking for logs.
27
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
28
+ * updated in the db.
29
+ * @throws If any two pre-tags contain the same directional app tagging secret
30
+ */
31
+ setLastUsedIndexes(preTags: PreTag[]) {
32
+ // Non-unique secrets would indicate a bug in the caller function.
33
+ const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
34
+ if (secretsSet.size !== preTags.length) {
35
+ throw new Error(`Duplicate secrets found when setting last used indexes`);
36
+ }
37
+
38
+ return Promise.all(preTags.map(({ secret, index }) => this.#lastUsedIndexes.set(secret.toString(), index)));
39
+ }
40
+
41
+ /**
42
+ * Returns the last used indexes when looking for logs.
43
+ * @param secrets - The directional app tagging secrets to obtain the indexes for.
44
+ * @returns The last used indexes for the given directional app tagging secrets, or undefined if have never yet found
45
+ * a log for a given secret.
46
+ */
47
+ getLastUsedIndexes(secrets: DirectionalAppTaggingSecret[]): Promise<(number | undefined)[]> {
48
+ return Promise.all(secrets.map(secret => this.#lastUsedIndexes.getAsync(secret.toString())));
49
+ }
50
+
51
+ resetNoteSyncData(): Promise<void> {
52
+ return this.#store.transactionAsync(async () => {
53
+ const keys = await toArray(this.#lastUsedIndexes.keysAsync());
54
+ await Promise.all(keys.map(secret => this.#lastUsedIndexes.delete(secret)));
55
+ });
56
+ }
57
+
58
+ // It might seem weird that the following 3 methods are in RecipientTaggingDataProvider and not
59
+ // in SenderTaggingDataProvider but that is because this data is truly only used for the purposes of syncing logs
60
+ // as a recipient. When sending logs or when syncing sender tagging indexes we only receive directional app tagging
61
+ // secret from Aztec.nr via an oracle and we don't need to access sender addresses.
62
+
63
+ async addSenderAddress(address: AztecAddress): Promise<boolean> {
64
+ if (await this.#addressBook.hasAsync(address.toString())) {
65
+ return false;
66
+ }
67
+
68
+ await this.#addressBook.set(address.toString(), true);
69
+
70
+ return true;
71
+ }
72
+
73
+ async getSenderAddresses(): Promise<AztecAddress[]> {
74
+ return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
75
+ }
76
+
77
+ async removeSenderAddress(address: AztecAddress): Promise<boolean> {
78
+ if (!(await this.#addressBook.hasAsync(address.toString()))) {
79
+ return false;
80
+ }
81
+
82
+ await this.#addressBook.delete(address.toString());
83
+
84
+ return true;
85
+ }
86
+ }
@@ -0,0 +1,244 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
3
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
4
+ import { TxHash } from '@aztec/stdlib/tx';
5
+
6
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/sync/sync_sender_tagging_indexes.js';
7
+
8
+ /**
9
+ * Data provider of tagging data used when syncing the sender tagging indexes. The recipient counterpart of this class
10
+ * is called RecipientTaggingDataProvider. We have the providers separate for the sender and recipient because
11
+ * the algorithms are completely disjoint and there is not data reuse between the two.
12
+ */
13
+ export class SenderTaggingDataProvider {
14
+ #store: AztecAsyncKVStore;
15
+
16
+ // Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
17
+ // the private logs with tags corresponding to these indexes has not been finalized yet.
18
+ //
19
+ // We don't store just the highest index because if their transaction is dropped we'd then need the information about
20
+ // the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
21
+ // the smaller ones are irrelevant due to tx atomicity.
22
+ //
23
+ // TODO(#17615): This assumes no logs are used in the non-revertible phase.
24
+ #pendingIndexes: AztecAsyncMap<string, { index: number; txHash: string }[]>;
25
+
26
+ // Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
27
+ // index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
28
+ // we don't need to store the history.
29
+ #lastFinalizedIndexes: AztecAsyncMap<string, number>;
30
+
31
+ constructor(store: AztecAsyncKVStore) {
32
+ this.#store = store;
33
+
34
+ this.#pendingIndexes = this.#store.openMap('pending_indexes');
35
+ this.#lastFinalizedIndexes = this.#store.openMap('last_finalized_indexes');
36
+ }
37
+
38
+ /**
39
+ * Stores pending indexes.
40
+ * @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
41
+ * This is expected to happen because whenever we start sync we start from the last finalized index and we can have
42
+ * pending indexes already stored from previous syncs.
43
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
44
+ * stored in the db.
45
+ * @param txHash - The tx in which the pretags were used in private logs.
46
+ * @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
47
+ * only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
48
+ * bugs.
49
+ * @throws If the newly stored pending index is further than window length from the highest finalized index for the
50
+ * same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
51
+ * window length ahead of the highest finalized index.
52
+ * @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
53
+ * that we would attempt to store a different index for a given secret-txHash pair because we always store just the
54
+ * highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
55
+ * @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
56
+ * This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
57
+ * indexes than finalized ones.
58
+ */
59
+ async storePendingIndexes(preTags: PreTag[], txHash: TxHash) {
60
+ // The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
61
+ // pair. Below we check that this is the case.
62
+ const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
63
+ if (secretsSet.size !== preTags.length) {
64
+ throw new Error(`Duplicate secrets found when storing pending indexes`);
65
+ }
66
+
67
+ for (const { secret, index } of preTags) {
68
+ // First we check that for any secret the highest used index in tx is not further than window length from
69
+ // the highest finalized index.
70
+ const finalizedIndex = (await this.getLastFinalizedIndex(secret)) ?? 0;
71
+ if (index > finalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
72
+ throw new Error(
73
+ `Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex}.
74
+ Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
75
+ to increase it!`,
76
+ );
77
+ }
78
+
79
+ // Throw if the new pending index is lower than or equal to the last finalized index
80
+ const secretStr = secret.toString();
81
+ const lastFinalizedIndex = await this.#lastFinalizedIndexes.getAsync(secretStr);
82
+ if (lastFinalizedIndex !== undefined && index <= lastFinalizedIndex) {
83
+ throw new Error(
84
+ `Cannot store pending index ${index} for secret ${secretStr}: ` +
85
+ `it is lower than or equal to the last finalized index ${lastFinalizedIndex}`,
86
+ );
87
+ }
88
+
89
+ // Check if this secret + txHash combination already exists
90
+ const txHashStr = txHash.toString();
91
+ const existingForSecret = (await this.#pendingIndexes.getAsync(secretStr)) ?? [];
92
+ const existingForSecretAndTx = existingForSecret.find(entry => entry.txHash === txHashStr);
93
+
94
+ if (existingForSecretAndTx) {
95
+ // If it exists with a different index, throw an error
96
+ if (existingForSecretAndTx.index !== index) {
97
+ throw new Error(
98
+ `Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` +
99
+ `a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`,
100
+ );
101
+ }
102
+ // If it exists with the same index, ignore the update (no-op)
103
+ } else {
104
+ // If it doesn't exist, add it
105
+ await this.#pendingIndexes.set(secretStr, [...existingForSecret, { index, txHash: txHashStr }]);
106
+ }
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Returns the transaction hashes of all pending transactions that contain indexes within a specified range
112
+ * for a given directional app tagging secret.
113
+ * @param secret - The directional app tagging secret to query pending indexes for.
114
+ * @param startIndex - The lower bound of the index range (inclusive).
115
+ * @param endIndex - The upper bound of the index range (exclusive).
116
+ * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
117
+ * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
118
+ */
119
+ async getTxHashesOfPendingIndexes(
120
+ secret: DirectionalAppTaggingSecret,
121
+ startIndex: number,
122
+ endIndex: number,
123
+ ): Promise<TxHash[]> {
124
+ const existing = (await this.#pendingIndexes.getAsync(secret.toString())) ?? [];
125
+ const txHashes = existing
126
+ .filter(entry => entry.index >= startIndex && entry.index < endIndex)
127
+ .map(entry => entry.txHash);
128
+ return Array.from(new Set(txHashes)).map(TxHash.fromString);
129
+ }
130
+
131
+ /**
132
+ * Returns the last (highest) finalized index for a given secret.
133
+ * @param secret - The secret to get the last finalized index for.
134
+ * @returns The last (highest) finalized index for the given secret.
135
+ */
136
+ getLastFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
137
+ return this.#lastFinalizedIndexes.getAsync(secret.toString());
138
+ }
139
+
140
+ /**
141
+ * Returns the last used index for a given directional app tagging secret, considering both finalized and pending
142
+ * indexes.
143
+ * @param secret - The directional app tagging secret to query the last used index for.
144
+ * @returns The last used index.
145
+ */
146
+ async getLastUsedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
147
+ const secretStr = secret.toString();
148
+ const pendingTxScopedIndexes = (await this.#pendingIndexes.getAsync(secretStr)) ?? [];
149
+ const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
150
+
151
+ if (pendingTxScopedIndexes.length === 0) {
152
+ return this.#lastFinalizedIndexes.getAsync(secretStr);
153
+ }
154
+
155
+ // As the last used index we return the highest one from the pending indexes. Note that this value will be always
156
+ // higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
157
+ return Math.max(...pendingIndexes);
158
+ }
159
+
160
+ /**
161
+ * Drops all pending indexes corresponding to the given transaction hashes.
162
+ */
163
+ async dropPendingIndexes(txHashes: TxHash[]) {
164
+ if (txHashes.length === 0) {
165
+ return;
166
+ }
167
+
168
+ const txHashStrs = new Set<string>(txHashes.map(txHash => txHash.toString()));
169
+ const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
170
+
171
+ for (const secret of allSecrets) {
172
+ const pendingData = await this.#pendingIndexes.getAsync(secret);
173
+ if (pendingData) {
174
+ const filtered = pendingData.filter(item => !txHashStrs.has(item.txHash));
175
+ if (filtered.length === 0) {
176
+ await this.#pendingIndexes.delete(secret);
177
+ } else if (filtered.length !== pendingData.length) {
178
+ // Some items were filtered out, so update the pending data
179
+ await this.#pendingIndexes.set(secret, filtered);
180
+ }
181
+ // else: No items were filtered out (txHashes not found for this secret) --> no-op
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
188
+ * indexes.
189
+ */
190
+ async finalizePendingIndexes(txHashes: TxHash[]) {
191
+ if (txHashes.length === 0) {
192
+ return;
193
+ }
194
+
195
+ for (const txHash of txHashes) {
196
+ const txHashStr = txHash.toString();
197
+
198
+ const allSecrets = await toArray(this.#pendingIndexes.keysAsync());
199
+
200
+ for (const secret of allSecrets) {
201
+ const pendingData = await this.#pendingIndexes.getAsync(secret);
202
+ if (!pendingData) {
203
+ continue;
204
+ }
205
+
206
+ const matchingIndexes = pendingData.filter(item => item.txHash === txHashStr).map(item => item.index);
207
+ if (matchingIndexes.length === 0) {
208
+ continue;
209
+ }
210
+
211
+ if (matchingIndexes.length > 1) {
212
+ // We should always just store the highest pending index for a given tx hash and secret because the lower
213
+ // values are irrelevant.
214
+ throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
215
+ }
216
+
217
+ let lastFinalized = await this.#lastFinalizedIndexes.getAsync(secret);
218
+ const newFinalized = matchingIndexes[0];
219
+
220
+ if (newFinalized < (lastFinalized ?? 0)) {
221
+ // This should never happen because when last finalized index was finalized we should have pruned the lower
222
+ // pending indexes.
223
+ throw new Error(
224
+ `New finalized index ${newFinalized} is smaller than the current last finalized index ${lastFinalized}`,
225
+ );
226
+ }
227
+
228
+ await this.#lastFinalizedIndexes.set(secret, newFinalized);
229
+ lastFinalized = newFinalized;
230
+
231
+ // When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
232
+ // cannot control the order in which transactions are finalized, there may be pending indexes that are now
233
+ // obsolete because they are lower than the most recently finalized index. For this reason, we prune these
234
+ // outdated pending indexes.
235
+ const remainingItemsOfHigherIndex = pendingData.filter(item => item.index > (lastFinalized ?? 0));
236
+ if (remainingItemsOfHigherIndex.length === 0) {
237
+ await this.#pendingIndexes.delete(secret);
238
+ } else {
239
+ await this.#pendingIndexes.set(secret, remainingItemsOfHigherIndex);
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
@@ -0,0 +1,3 @@
1
+ // Half the size of the window we slide over the tagging indexes.
2
+ // TODO(#17775): Move this to the recipient log sync function once it's implemented in this directory.
3
+ export const WINDOW_HALF_SIZE = 10;
@@ -0,0 +1,4 @@
1
+ export * from './constants.js';
2
+ export * from './utils.js';
3
+ export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
4
+ export { type PreTag } from '@aztec/stdlib/logs';
@@ -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 { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../sync/sync_sender_tagging_indexes.js';
7
+ import type { NewRecipientTaggingDataProvider } from './new_recipient_tagging_data_provider.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
+ taggingDataProvider: NewRecipientTaggingDataProvider,
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 taggingDataProvider.getHighestAgedIndex(secret);
77
+ const currentHighestFinalizedIndex = await taggingDataProvider.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 taggingDataProvider.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 taggingDataProvider.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
+ }