@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,213 @@
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 { 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 PrivateEventStoreFilter = {
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
+ /** The lookup key for #eventsByContractScopeSelector, used for cleanup during rollback */
28
+ lookupKey: string;
29
+ };
30
+
31
+ type PrivateEventMetadata = InTx & {
32
+ contractAddress: AztecAddress;
33
+ scope: AztecAddress;
34
+ };
35
+
36
+ /**
37
+ * Stores decrypted private event logs.
38
+ */
39
+ export class PrivateEventStore {
40
+ #store: AztecAsyncKVStore;
41
+ /** Map storing the actual private event log entries, keyed by eventCommitmentIndex */
42
+ #eventLogs: AztecAsyncMap<number, PrivateEventEntry>;
43
+ /** Map from contractAddress_scope_eventSelector to eventCommitmentIndex[] for efficient lookup */
44
+ #eventsByContractScopeSelector: AztecAsyncMap<string, number[]>;
45
+ /** Map from block number to eventCommitmentIndex[] for rollback support */
46
+ #eventsByBlockNumber: AztecAsyncMap<number, number[]>;
47
+ /** Map from eventCommitmentIndex to boolean indicating if log has been seen. */
48
+ #seenLogs: AztecAsyncMap<number, boolean>;
49
+
50
+ logger = createLogger('private_event_store');
51
+
52
+ constructor(store: AztecAsyncKVStore) {
53
+ this.#store = store;
54
+ this.#eventLogs = this.#store.openMap('private_event_logs');
55
+ this.#eventsByContractScopeSelector = this.#store.openMap('events_by_contract_scope_selector');
56
+ this.#seenLogs = this.#store.openMap('seen_logs');
57
+ this.#eventsByBlockNumber = this.#store.openMap('events_by_block_number');
58
+ }
59
+
60
+ #keyFor(contractAddress: AztecAddress, scope: AztecAddress, eventSelector: EventSelector): string {
61
+ return `${contractAddress.toString()}_${scope.toString()}_${eventSelector.toString()}`;
62
+ }
63
+
64
+ /**
65
+ * Store a private event log.
66
+ * @param eventSelector - The event selector of the event.
67
+ * @param msgContent - The content of the event.
68
+ * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
69
+ * @param metadata
70
+ * contractAddress - The address of the contract that emitted the event.
71
+ * scope - The address to which the event is scoped.
72
+ * txHash - The transaction hash of the event log.
73
+ * blockNumber - The block number in which the event was emitted.
74
+ */
75
+ storePrivateEventLog(
76
+ eventSelector: EventSelector,
77
+ msgContent: Fr[],
78
+ eventCommitmentIndex: number,
79
+ metadata: PrivateEventMetadata,
80
+ ): Promise<void> {
81
+ const { contractAddress, scope, txHash, l2BlockNumber, l2BlockHash } = metadata;
82
+
83
+ return this.#store.transactionAsync(async () => {
84
+ const key = this.#keyFor(contractAddress, scope, eventSelector);
85
+
86
+ // Check if this exact log has already been stored using eventCommitmentIndex as unique identifier
87
+ const hasBeenSeen = await this.#seenLogs.getAsync(eventCommitmentIndex);
88
+ if (hasBeenSeen) {
89
+ this.logger.verbose('Ignoring duplicate event log', { txHash: txHash.toString(), eventCommitmentIndex });
90
+ return;
91
+ }
92
+
93
+ this.logger.verbose('storing private event log', { contractAddress, scope, msgContent, l2BlockNumber });
94
+
95
+ await this.#eventLogs.set(eventCommitmentIndex, {
96
+ msgContent: serializeToBuffer(msgContent),
97
+ l2BlockNumber,
98
+ l2BlockHash: l2BlockHash.toBuffer(),
99
+ eventCommitmentIndex,
100
+ txHash: txHash.toBuffer(),
101
+ lookupKey: key,
102
+ });
103
+
104
+ const existingIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
105
+ await this.#eventsByContractScopeSelector.set(key, [...existingIndices, eventCommitmentIndex]);
106
+
107
+ const existingBlockIndices = (await this.#eventsByBlockNumber.getAsync(l2BlockNumber)) || [];
108
+ await this.#eventsByBlockNumber.set(l2BlockNumber, [...existingBlockIndices, eventCommitmentIndex]);
109
+
110
+ // Mark this log as seen using eventCommitmentIndex
111
+ await this.#seenLogs.set(eventCommitmentIndex, true);
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Returns the private events given search parameters.
117
+ * @param eventSelector - The event selector to filter by.
118
+ * @param filter - Filtering criteria:
119
+ * contractAddress: The address of the contract to get events from.
120
+ * fromBlock: The block number to search from (inclusive).
121
+ * toBlock: The block number to search upto (exclusive).
122
+ * scope: - The addresses that decrypted the logs.
123
+ * @returns - The event log contents, augmented with metadata about
124
+ * the transaction and block it the event was included in .
125
+ */
126
+ public async getPrivateEvents(
127
+ eventSelector: EventSelector,
128
+ filter: PrivateEventStoreFilter,
129
+ ): Promise<PackedPrivateEvent[]> {
130
+ const events: Array<{ eventCommitmentIndex: number; event: PackedPrivateEvent }> = [];
131
+
132
+ for (const scope of filter.scopes) {
133
+ const key = this.#keyFor(filter.contractAddress, scope, eventSelector);
134
+ const eventCommitmentIndices = (await this.#eventsByContractScopeSelector.getAsync(key)) || [];
135
+
136
+ for (const eventCommitmentIndex of eventCommitmentIndices) {
137
+ const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
138
+ if (!entry || entry.l2BlockNumber < filter.fromBlock || entry.l2BlockNumber >= filter.toBlock) {
139
+ continue;
140
+ }
141
+
142
+ // Convert buffer back to Fr array
143
+ const reader = BufferReader.asReader(entry.msgContent);
144
+ const numFields = entry.msgContent.length / Fr.SIZE_IN_BYTES;
145
+ const msgContent = reader.readArray(numFields, Fr);
146
+ const txHash = TxHash.fromBuffer(entry.txHash);
147
+ const l2BlockHash = L2BlockHash.fromBuffer(entry.l2BlockHash);
148
+
149
+ if (filter.txHash && !txHash.equals(filter.txHash)) {
150
+ continue;
151
+ }
152
+
153
+ events.push({
154
+ eventCommitmentIndex: entry.eventCommitmentIndex,
155
+ event: {
156
+ packedEvent: msgContent,
157
+ l2BlockNumber: BlockNumber(entry.l2BlockNumber),
158
+ txHash,
159
+ l2BlockHash,
160
+ eventSelector,
161
+ },
162
+ });
163
+ }
164
+ }
165
+
166
+ // Sort by eventCommitmentIndex only
167
+ events.sort((a, b) => a.eventCommitmentIndex - b.eventCommitmentIndex);
168
+ return events.map(ev => ev.event);
169
+ }
170
+
171
+ /**
172
+ * Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
173
+ * number up to which PXE managed to sync before the reorg happened).
174
+ */
175
+ public async rollbackEventsAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void> {
176
+ await this.#store.transactionAsync(async () => {
177
+ let removedCount = 0;
178
+
179
+ for (let block = blockNumber + 1; block <= synchedBlockNumber; block++) {
180
+ const indices = await this.#eventsByBlockNumber.getAsync(block);
181
+ if (indices) {
182
+ await this.#eventsByBlockNumber.delete(block);
183
+
184
+ for (const eventCommitmentIndex of indices) {
185
+ const entry = await this.#eventLogs.getAsync(eventCommitmentIndex);
186
+ if (!entry) {
187
+ throw new Error(`Event log not found for eventCommitmentIndex ${eventCommitmentIndex}`);
188
+ }
189
+
190
+ await this.#eventLogs.delete(eventCommitmentIndex);
191
+ await this.#seenLogs.delete(eventCommitmentIndex);
192
+
193
+ // Update #eventsByContractScopeSelector using the stored lookupKey
194
+ const existingIndices = await this.#eventsByContractScopeSelector.getAsync(entry.lookupKey);
195
+ if (!existingIndices || existingIndices.length === 0) {
196
+ throw new Error(`No indices found in #eventsByContractScopeSelector for key ${entry.lookupKey}`);
197
+ }
198
+ const filteredIndices = existingIndices.filter(idx => idx !== eventCommitmentIndex);
199
+ if (filteredIndices.length === 0) {
200
+ await this.#eventsByContractScopeSelector.delete(entry.lookupKey);
201
+ } else {
202
+ await this.#eventsByContractScopeSelector.set(entry.lookupKey, filteredIndices);
203
+ }
204
+
205
+ removedCount++;
206
+ }
207
+ }
208
+ }
209
+
210
+ this.logger.verbose(`Rolled back ${removedCount} private events after block ${blockNumber}`);
211
+ });
212
+ }
213
+ }
@@ -0,0 +1,3 @@
1
+ export { SenderTaggingStore } from './sender_tagging_store.js';
2
+ export { SenderAddressBookStore } from './sender_address_book_store.js';
3
+ export { RecipientTaggingStore } from './recipient_tagging_store.js';
@@ -0,0 +1,53 @@
1
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
+ import type { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
3
+
4
+ /**
5
+ * Data provider of tagging data used when syncing the logs as a recipient. The sender counterpart of this class
6
+ * is called SenderTaggingStore. We have the providers separate for the sender and recipient because
7
+ * the algorithms are completely disjoint and there is not data reuse between the two.
8
+ *
9
+ * @dev Chain reorgs do not need to be handled here because both the finalized and aged indexes refer to finalized
10
+ * blocks, which by definition cannot be affected by reorgs.
11
+ *
12
+ * TODO(benesjan): Relocate to yarn-project/pxe/src/storage/tagging_store
13
+ */
14
+ export class RecipientTaggingStore {
15
+ #store: AztecAsyncKVStore;
16
+
17
+ #highestAgedIndex: AztecAsyncMap<string, number>;
18
+ #highestFinalizedIndex: AztecAsyncMap<string, number>;
19
+
20
+ constructor(store: AztecAsyncKVStore) {
21
+ this.#store = store;
22
+
23
+ this.#highestAgedIndex = this.#store.openMap('highest_aged_index');
24
+ this.#highestFinalizedIndex = this.#store.openMap('highest_finalized_index');
25
+ }
26
+
27
+ getHighestAgedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
28
+ return this.#highestAgedIndex.getAsync(secret.toString());
29
+ }
30
+
31
+ async updateHighestAgedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void> {
32
+ const currentIndex = await this.#highestAgedIndex.getAsync(secret.toString());
33
+ if (currentIndex !== undefined && index <= currentIndex) {
34
+ // Log sync should never set a lower highest aged index.
35
+ throw new Error(`New highest aged index (${index}) must be higher than the current one (${currentIndex})`);
36
+ }
37
+ await this.#highestAgedIndex.set(secret.toString(), index);
38
+ }
39
+
40
+ getHighestFinalizedIndex(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
41
+ return this.#highestFinalizedIndex.getAsync(secret.toString());
42
+ }
43
+
44
+ async updateHighestFinalizedIndex(secret: DirectionalAppTaggingSecret, index: number): Promise<void> {
45
+ const currentIndex = await this.#highestFinalizedIndex.getAsync(secret.toString());
46
+ if (currentIndex !== undefined && index < currentIndex) {
47
+ // Log sync should never set a lower highest finalized index but it can happen that it would try to set the same
48
+ // one because we are loading logs from highest aged index + 1 and not from the highest finalized index.
49
+ throw new Error(`New highest finalized index (${index}) must be higher than the current one (${currentIndex})`);
50
+ }
51
+ await this.#highestFinalizedIndex.set(secret.toString(), index);
52
+ }
53
+ }
@@ -0,0 +1,42 @@
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
+
5
+ /**
6
+ * Stores sender addresses. During recipient log synchronization, these senders are used, along with a given recipient,
7
+ * to derive directional app tagging secrets that are then used to sync the logs.
8
+ */
9
+ export class SenderAddressBookStore {
10
+ #store: AztecAsyncKVStore;
11
+ #addressBook: AztecAsyncMap<string, true>;
12
+
13
+ constructor(store: AztecAsyncKVStore) {
14
+ this.#store = store;
15
+
16
+ this.#addressBook = this.#store.openMap('address_book');
17
+ }
18
+
19
+ async addSender(address: AztecAddress): Promise<boolean> {
20
+ if (await this.#addressBook.hasAsync(address.toString())) {
21
+ return false;
22
+ }
23
+
24
+ await this.#addressBook.set(address.toString(), true);
25
+
26
+ return true;
27
+ }
28
+
29
+ async getSenders(): Promise<AztecAddress[]> {
30
+ return (await toArray(this.#addressBook.keysAsync())).map(AztecAddress.fromString);
31
+ }
32
+
33
+ async removeSender(address: AztecAddress): Promise<boolean> {
34
+ if (!(await this.#addressBook.hasAsync(address.toString()))) {
35
+ return false;
36
+ }
37
+
38
+ await this.#addressBook.delete(address.toString());
39
+
40
+ return true;
41
+ }
42
+ }
@@ -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/index.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 RecipientTaggingStore. 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 SenderTaggingStore {
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,28 @@
1
+ /**
2
+ * This directory contains the sender and recipient synchronization algorithms that use tagging.
3
+ *
4
+ * The objective of the sender sync algorithm is to determine which tags have already been used by a sender, thereby
5
+ * deciding which tag should be used next.
6
+ *
7
+ * The objective of the recipient sync algorithm is to load and process the corresponding logs.
8
+ *
9
+ * @module tagging
10
+ */
11
+
12
+ export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
13
+ export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
14
+
15
+ // This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
16
+ // tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
17
+ // This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
18
+ // MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
19
+ // and the note is nullified in the same tx.
20
+ //
21
+ // Having a large window significantly slowed down `e2e_l1_with_wall_time` test as there we perform sync for more than
22
+ // 1000 secrets. For this reason we set it to a relatively low value of 20. 20 should be sufficient for all the use
23
+ // cases.
24
+ export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
25
+
26
+ // Re-export tagging-related types from stdlib
27
+ export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
28
+ export { type PreTag } from '@aztec/stdlib/logs';