@aztec/pxe 0.0.1-commit.d3ec352c → 0.0.1-commit.d6f2b3f94

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 (387) hide show
  1. package/dest/bin/check_oracle_version.js +105 -15
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +45 -0
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  4. package/dest/block_synchronizer/block_synchronizer.js +153 -0
  5. package/dest/block_synchronizer/index.d.ts +2 -0
  6. package/dest/block_synchronizer/index.d.ts.map +1 -0
  7. package/dest/block_synchronizer/index.js +1 -0
  8. package/dest/config/index.d.ts +6 -4
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +17 -0
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +42 -14
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +74 -33
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +21 -12
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +48 -31
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  23. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  24. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/index.d.ts +2 -2
  26. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/index.js +1 -1
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -4
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -3
  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 +2 -2
  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 +1 -1
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -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 +1 -1
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  43. package/dest/contract_function_simulator/oracle/interfaces.d.ts +22 -18
  44. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +4 -2
  46. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  48. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +11 -7
  49. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/note_packing_utils.js +14 -10
  51. package/dest/contract_function_simulator/oracle/oracle.d.ts +11 -9
  52. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/oracle.js +82 -48
  54. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -28
  55. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/private_execution.js +2 -38
  57. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +34 -25
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +41 -45
  60. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +88 -32
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +201 -74
  63. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  64. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/pick_notes.js +1 -1
  66. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  67. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  69. package/dest/contract_sync/contract_sync_service.d.ts +41 -0
  70. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  71. package/dest/contract_sync/contract_sync_service.js +82 -0
  72. package/dest/contract_sync/helpers.d.ts +28 -0
  73. package/dest/contract_sync/helpers.d.ts.map +1 -0
  74. package/dest/contract_sync/helpers.js +55 -0
  75. package/dest/debug/pxe_debug_utils.d.ts +44 -0
  76. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  77. package/dest/debug/pxe_debug_utils.js +48 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +0 -1
  81. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +23 -8
  84. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +0 -1
  87. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +24 -9
  90. package/dest/entrypoints/pxe_creation_options.d.ts +7 -3
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.d.ts +4 -2
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +3 -1
  95. package/dest/entrypoints/server/utils.d.ts +1 -1
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +30 -15
  98. package/dest/error_enriching.d.ts +4 -4
  99. package/dest/error_enriching.d.ts.map +1 -1
  100. package/dest/error_enriching.js +6 -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 +44 -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 +38 -0
  110. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  111. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  112. package/dest/job_coordinator/job_coordinator.js +94 -0
  113. package/dest/logs/log_service.d.ts +28 -0
  114. package/dest/logs/log_service.d.ts.map +1 -0
  115. package/dest/logs/log_service.js +123 -0
  116. package/dest/notes/index.d.ts +2 -0
  117. package/dest/notes/index.d.ts.map +1 -0
  118. package/dest/notes/index.js +1 -0
  119. package/dest/notes/note_service.d.ts +48 -0
  120. package/dest/notes/note_service.d.ts.map +1 -0
  121. package/dest/notes/note_service.js +147 -0
  122. package/dest/oracle_version.d.ts +3 -3
  123. package/dest/oracle_version.d.ts.map +1 -1
  124. package/dest/oracle_version.js +4 -3
  125. package/dest/private_kernel/hints/index.d.ts +2 -2
  126. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  127. package/dest/private_kernel/hints/index.js +1 -1
  128. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  129. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  130. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +13 -7
  131. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  132. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  133. package/dest/private_kernel/private_kernel_execution_prover.js +10 -11
  134. package/dest/private_kernel/private_kernel_oracle.d.ts +26 -29
  135. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  136. package/dest/private_kernel/private_kernel_oracle.js +90 -2
  137. package/dest/pxe.d.ts +56 -81
  138. package/dest/pxe.d.ts.map +1 -1
  139. package/dest/pxe.js +209 -217
  140. package/dest/storage/address_store/address_store.d.ts +11 -0
  141. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  142. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  143. package/dest/storage/address_store/index.d.ts +2 -0
  144. package/dest/storage/address_store/index.d.ts.map +1 -0
  145. package/dest/storage/address_store/index.js +1 -0
  146. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  147. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  148. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +10 -10
  149. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  150. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  151. package/dest/storage/anchor_block_store/index.js +1 -0
  152. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  153. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  154. package/dest/storage/capsule_store/capsule_store.js +253 -0
  155. package/dest/storage/capsule_store/index.d.ts +2 -0
  156. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  157. package/dest/storage/capsule_store/index.js +1 -0
  158. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +7 -5
  159. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  160. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +56 -16
  161. package/dest/storage/contract_store/index.d.ts +2 -0
  162. package/dest/storage/contract_store/index.d.ts.map +1 -0
  163. package/dest/storage/contract_store/index.js +1 -0
  164. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  165. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  166. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  167. package/dest/storage/index.d.ts +8 -8
  168. package/dest/storage/index.d.ts.map +1 -1
  169. package/dest/storage/index.js +7 -7
  170. package/dest/storage/metadata.d.ts +1 -1
  171. package/dest/storage/metadata.js +1 -1
  172. package/dest/storage/note_store/index.d.ts +3 -0
  173. package/dest/storage/note_store/index.d.ts.map +1 -0
  174. package/dest/storage/note_store/index.js +2 -0
  175. package/dest/storage/note_store/note_store.d.ts +83 -0
  176. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  177. package/dest/storage/note_store/note_store.js +344 -0
  178. package/dest/storage/note_store/stored_note.d.ts +16 -0
  179. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  180. package/dest/storage/note_store/stored_note.js +43 -0
  181. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  182. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  183. package/dest/storage/private_event_store/private_event_store.js +273 -0
  184. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  185. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  186. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  187. package/dest/storage/tagging_store/index.d.ts +4 -0
  188. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  189. package/dest/storage/tagging_store/index.js +3 -0
  190. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  191. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  192. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  193. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  194. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  195. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  196. package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
  197. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  198. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  199. package/dest/tagging/constants.d.ts +2 -2
  200. package/dest/tagging/constants.d.ts.map +1 -1
  201. package/dest/tagging/constants.js +10 -2
  202. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  203. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  204. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  205. package/dest/tagging/index.d.ts +16 -6
  206. package/dest/tagging/index.d.ts.map +1 -1
  207. package/dest/tagging/index.js +15 -5
  208. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
  209. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  210. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  211. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  212. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  213. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  214. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
  215. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  216. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  217. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
  218. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  219. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  220. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  221. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  222. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
  223. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
  224. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  225. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
  226. package/package.json +27 -18
  227. package/src/bin/check_oracle_version.ts +131 -20
  228. package/src/block_synchronizer/block_synchronizer.ts +178 -0
  229. package/src/block_synchronizer/index.ts +1 -0
  230. package/src/config/index.ts +17 -3
  231. package/src/config/package_info.ts +1 -1
  232. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  233. package/src/contract_function_simulator/contract_function_simulator.ts +117 -34
  234. package/src/contract_function_simulator/execution_note_cache.ts +51 -29
  235. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  236. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  237. package/src/contract_function_simulator/index.ts +1 -1
  238. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +6 -2
  239. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  240. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
  241. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  242. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  243. package/src/contract_function_simulator/oracle/interfaces.ts +27 -17
  244. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  245. package/src/contract_function_simulator/oracle/note_packing_utils.ts +27 -13
  246. package/src/contract_function_simulator/oracle/oracle.ts +97 -51
  247. package/src/contract_function_simulator/oracle/private_execution.ts +2 -69
  248. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +121 -59
  249. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +294 -91
  250. package/src/contract_function_simulator/pick_notes.ts +1 -1
  251. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  252. package/src/contract_sync/contract_sync_service.ts +129 -0
  253. package/src/contract_sync/helpers.ts +93 -0
  254. package/src/debug/pxe_debug_utils.ts +91 -0
  255. package/src/entrypoints/client/bundle/index.ts +0 -1
  256. package/src/entrypoints/client/bundle/utils.ts +15 -16
  257. package/src/entrypoints/client/lazy/index.ts +0 -1
  258. package/src/entrypoints/client/lazy/utils.ts +16 -17
  259. package/src/entrypoints/pxe_creation_options.ts +6 -2
  260. package/src/entrypoints/server/index.ts +3 -1
  261. package/src/entrypoints/server/utils.ts +26 -34
  262. package/src/error_enriching.ts +7 -15
  263. package/src/events/event_service.ts +71 -0
  264. package/src/events/index.ts +1 -0
  265. package/src/events/private_event_filter_validator.ts +46 -0
  266. package/src/job_coordinator/job_coordinator.ts +150 -0
  267. package/src/logs/log_service.ts +220 -0
  268. package/src/notes/index.ts +1 -0
  269. package/src/notes/note_service.ts +195 -0
  270. package/src/oracle_version.ts +4 -3
  271. package/src/private_kernel/hints/index.ts +1 -1
  272. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +34 -23
  273. package/src/private_kernel/private_kernel_execution_prover.ts +13 -12
  274. package/src/private_kernel/private_kernel_oracle.ts +118 -37
  275. package/src/pxe.ts +299 -280
  276. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  277. package/src/storage/address_store/index.ts +1 -0
  278. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -12
  279. package/src/storage/anchor_block_store/index.ts +1 -0
  280. package/src/storage/capsule_store/capsule_store.ts +315 -0
  281. package/src/storage/capsule_store/index.ts +1 -0
  282. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -14
  283. package/src/storage/contract_store/index.ts +1 -0
  284. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  285. package/src/storage/index.ts +7 -7
  286. package/src/storage/metadata.ts +1 -1
  287. package/src/storage/note_store/index.ts +2 -0
  288. package/src/storage/note_store/note_store.ts +415 -0
  289. package/src/storage/note_store/stored_note.ts +48 -0
  290. package/src/storage/private_event_store/private_event_store.ts +384 -0
  291. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  292. package/src/storage/tagging_store/index.ts +3 -0
  293. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  294. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  295. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  296. package/src/tagging/constants.ts +10 -2
  297. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  298. package/src/tagging/index.ts +18 -5
  299. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
  300. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  301. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
  302. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
  303. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
  304. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  305. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -267
  306. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  307. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  308. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  309. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  310. package/dest/contract_function_simulator/proxied_node.js +0 -27
  311. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -123
  312. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  313. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -696
  314. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  315. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  316. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  317. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  318. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  319. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  320. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  321. package/dest/storage/address_data_provider/index.d.ts +0 -2
  322. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  323. package/dest/storage/address_data_provider/index.js +0 -1
  324. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  325. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  326. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -118
  327. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  328. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  329. package/dest/storage/capsule_data_provider/index.js +0 -1
  330. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  331. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  332. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  333. package/dest/storage/contract_data_provider/index.js +0 -1
  334. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  335. package/dest/storage/note_data_provider/index.d.ts +0 -3
  336. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  337. package/dest/storage/note_data_provider/index.js +0 -2
  338. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -83
  339. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  340. package/dest/storage/note_data_provider/note_data_provider.js +0 -314
  341. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  342. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  343. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -105
  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 -11
  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 -40
  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 -89
  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 -36
  358. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  359. package/dest/synchronizer/synchronizer.js +0 -102
  360. package/dest/tagging/siloed_tag.d.ts +0 -14
  361. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  362. package/dest/tagging/siloed_tag.js +0 -20
  363. package/dest/tagging/tag.d.ts +0 -12
  364. package/dest/tagging/tag.d.ts.map +0 -1
  365. package/dest/tagging/tag.js +0 -17
  366. package/dest/tagging/utils.d.ts +0 -18
  367. package/dest/tagging/utils.d.ts.map +0 -1
  368. package/dest/tagging/utils.js +0 -24
  369. package/src/contract_function_simulator/execution_data_provider.ts +0 -342
  370. package/src/contract_function_simulator/proxied_node.ts +0 -33
  371. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1023
  372. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  373. package/src/storage/address_data_provider/index.ts +0 -1
  374. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -147
  375. package/src/storage/capsule_data_provider/index.ts +0 -1
  376. package/src/storage/contract_data_provider/index.ts +0 -1
  377. package/src/storage/note_data_provider/index.ts +0 -2
  378. package/src/storage/note_data_provider/note_data_provider.ts +0 -403
  379. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -143
  380. package/src/storage/sync_data_provider/index.ts +0 -1
  381. package/src/storage/tagging_data_provider/index.ts +0 -1
  382. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  383. package/src/synchronizer/index.ts +0 -1
  384. package/src/synchronizer/synchronizer.ts +0 -121
  385. package/src/tagging/siloed_tag.ts +0 -22
  386. package/src/tagging/tag.ts +0 -16
  387. package/src/tagging/utils.ts +0 -31
@@ -0,0 +1,429 @@
1
+ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
2
+ import type { DirectionalAppTaggingSecret, PreTag } from '@aztec/stdlib/logs';
3
+ import { TxHash } from '@aztec/stdlib/tx';
4
+
5
+ import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
6
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../../tagging/constants.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 data stores separate for sender and recipient because
11
+ * the algorithms are completely disjoint and there is not data reuse between the two.
12
+ */
13
+ export class SenderTaggingStore implements StagedStore {
14
+ readonly storeName = 'sender_tagging';
15
+
16
+ #store: AztecAsyncKVStore;
17
+
18
+ // Stores the pending indexes for each directional app tagging secret. Pending here means that the tx that contained
19
+ // the private logs with tags corresponding to these indexes has not been finalized yet.
20
+ //
21
+ // We don't store just the highest index because if their transaction is dropped we'd then need the information about
22
+ // the lower pending indexes. For each secret-tx pair however we only store the largest index used in that tx, since
23
+ // the smaller ones are irrelevant due to tx atomicity.
24
+ //
25
+ // TODO(#17615): This assumes no logs are used in the non-revertible phase.
26
+ //
27
+ // directional app tagging secret => { pending index, txHash }[]
28
+ #pendingIndexes: AztecAsyncMap<string, { index: number; txHash: string }[]>;
29
+
30
+ // jobId => directional app tagging secret => { pending index, txHash }[]
31
+ #pendingIndexesForJob: Map<string, Map<string, { index: number; txHash: string }[]>>;
32
+
33
+ // Stores the last (highest) finalized index for each directional app tagging secret. We care only about the last
34
+ // index because unlike the pending indexes, it will never happen that a finalized index would be removed and hence
35
+ // we don't need to store the history.
36
+ //
37
+ // directional app tagging secret => highest finalized index
38
+ #lastFinalizedIndexes: AztecAsyncMap<string, number>;
39
+
40
+ // jobId => directional app tagging secret => highest finalized index
41
+ #lastFinalizedIndexesForJob: Map<string, Map<string, number>>;
42
+
43
+ constructor(store: AztecAsyncKVStore) {
44
+ this.#store = store;
45
+
46
+ this.#pendingIndexes = this.#store.openMap('pending_indexes');
47
+ this.#lastFinalizedIndexes = this.#store.openMap('last_finalized_indexes');
48
+
49
+ this.#pendingIndexesForJob = new Map();
50
+ this.#lastFinalizedIndexesForJob = new Map();
51
+ }
52
+
53
+ #getPendingIndexesForJob(jobId: string): Map<string, { index: number; txHash: string }[]> {
54
+ let pendingIndexesForJob = this.#pendingIndexesForJob.get(jobId);
55
+ if (!pendingIndexesForJob) {
56
+ pendingIndexesForJob = new Map();
57
+ this.#pendingIndexesForJob.set(jobId, pendingIndexesForJob);
58
+ }
59
+ return pendingIndexesForJob;
60
+ }
61
+
62
+ #getLastFinalizedIndexesForJob(jobId: string): Map<string, number> {
63
+ let jobStagedLastFinalizedIndexes = this.#lastFinalizedIndexesForJob.get(jobId);
64
+ if (!jobStagedLastFinalizedIndexes) {
65
+ jobStagedLastFinalizedIndexes = new Map();
66
+ this.#lastFinalizedIndexesForJob.set(jobId, jobStagedLastFinalizedIndexes);
67
+ }
68
+ return jobStagedLastFinalizedIndexes;
69
+ }
70
+
71
+ async #readPendingIndexes(jobId: string, secret: string): Promise<{ index: number; txHash: string }[]> {
72
+ // Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
73
+ // are no pending read requests). The staged value still takes precedence if it exists.
74
+ const dbValue = await this.#pendingIndexes.getAsync(secret);
75
+ const staged = this.#getPendingIndexesForJob(jobId).get(secret);
76
+ return staged !== undefined ? staged : (dbValue ?? []);
77
+ }
78
+
79
+ #writePendingIndexes(jobId: string, secret: string, pendingIndexes: { index: number; txHash: string }[]) {
80
+ this.#getPendingIndexesForJob(jobId).set(secret, pendingIndexes);
81
+ }
82
+
83
+ async #readLastFinalizedIndex(jobId: string, secret: string): Promise<number | undefined> {
84
+ // Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
85
+ // are no pending read requests). The staged value still takes precedence if it exists.
86
+ const dbValue = await this.#lastFinalizedIndexes.getAsync(secret);
87
+ const staged = this.#getLastFinalizedIndexesForJob(jobId).get(secret);
88
+ return staged ?? dbValue;
89
+ }
90
+
91
+ #writeLastFinalizedIndex(jobId: string, secret: string, lastFinalizedIndex: number) {
92
+ this.#getLastFinalizedIndexesForJob(jobId).set(secret, lastFinalizedIndex);
93
+ }
94
+
95
+ /**
96
+ * Writes all job-specific in-memory data to persistent storage.
97
+ *
98
+ * @remark This method must run in a DB transaction context. It's designed to be called from JobCoordinator#commitJob.
99
+ */
100
+ async commit(jobId: string): Promise<void> {
101
+ const pendingIndexesForJob = this.#pendingIndexesForJob.get(jobId);
102
+ if (pendingIndexesForJob) {
103
+ for (const [secret, pendingIndexes] of pendingIndexesForJob.entries()) {
104
+ if (pendingIndexes.length === 0) {
105
+ await this.#pendingIndexes.delete(secret);
106
+ } else {
107
+ await this.#pendingIndexes.set(secret, pendingIndexes);
108
+ }
109
+ }
110
+ }
111
+
112
+ const lastFinalizedIndexesForJob = this.#lastFinalizedIndexesForJob.get(jobId);
113
+ if (lastFinalizedIndexesForJob) {
114
+ for (const [secret, lastFinalizedIndex] of lastFinalizedIndexesForJob.entries()) {
115
+ await this.#lastFinalizedIndexes.set(secret, lastFinalizedIndex);
116
+ }
117
+ }
118
+
119
+ return this.discardStaged(jobId);
120
+ }
121
+
122
+ discardStaged(jobId: string): Promise<void> {
123
+ this.#pendingIndexesForJob.delete(jobId);
124
+ this.#lastFinalizedIndexesForJob.delete(jobId);
125
+ return Promise.resolve();
126
+ }
127
+
128
+ /**
129
+ * Stores pending indexes.
130
+ * @remarks Ignores the index if the same preTag + txHash combination already exists in the db with the same index.
131
+ * This is expected to happen because whenever we start sync we start from the last finalized index and we can have
132
+ * pending indexes already stored from previous syncs.
133
+ * @param preTags - The pre-tags containing the directional app tagging secrets and the indexes that are to be
134
+ * stored in the db.
135
+ * @param txHash - The tx in which the pretags were used in private logs.
136
+ * @param jobId - job context for staged writes to this store. See `JobCoordinator` for more details.
137
+ * @throws If any two pre-tags contain the same directional app tagging secret. This is enforced because we care
138
+ * only about the highest index for a given secret that was used in the tx. Hence this check is a good way to catch
139
+ * bugs.
140
+ * @throws If the newly stored pending index is further than window length from the highest finalized index for the
141
+ * same secret. This is enforced in order to give a guarantee to a recipient that he doesn't need to look further than
142
+ * window length ahead of the highest finalized index.
143
+ * @throws If a secret + txHash pair already exists in the db with a different index value. It should never happen
144
+ * that we would attempt to store a different index for a given secret-txHash pair because we always store just the
145
+ * highest index for a given secret-txHash pair. Hence this is a good way to catch bugs.
146
+ * @throws If the newly stored pending index is lower than or equal to the last finalized index for the same secret.
147
+ * This is enforced because this should never happen if the syncing is done correctly as we look for logs from higher
148
+ * indexes than finalized ones.
149
+ */
150
+ storePendingIndexes(preTags: PreTag[], txHash: TxHash, jobId: string): Promise<void> {
151
+ if (preTags.length === 0) {
152
+ return Promise.resolve();
153
+ }
154
+
155
+ // The secrets in pre-tags should be unique because we always store just the highest index per given secret-txHash
156
+ // pair. Below we check that this is the case.
157
+ const secretsSet = new Set(preTags.map(preTag => preTag.secret.toString()));
158
+ if (secretsSet.size !== preTags.length) {
159
+ return Promise.reject(new Error(`Duplicate secrets found when storing pending indexes`));
160
+ }
161
+
162
+ const txHashStr = txHash.toString();
163
+
164
+ return this.#store.transactionAsync(async () => {
165
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
166
+ const preTagReadPromises = preTags.map(({ secret, index }) => {
167
+ const secretStr = secret.toString();
168
+ return {
169
+ secret,
170
+ secretStr,
171
+ index,
172
+ pending: this.#readPendingIndexes(jobId, secretStr),
173
+ finalized: this.#readLastFinalizedIndex(jobId, secretStr),
174
+ };
175
+ });
176
+
177
+ // Await all reads together
178
+ const preTagData = await Promise.all(
179
+ preTagReadPromises.map(async item => ({
180
+ ...item,
181
+ pendingData: await item.pending,
182
+ finalizedIndex: await item.finalized,
183
+ })),
184
+ );
185
+
186
+ // Process in memory and validate
187
+ for (const { secretStr, index, pendingData, finalizedIndex } of preTagData) {
188
+ // First we check that for any secret the highest used index in tx is not further than window length from
189
+ // the highest finalized index.
190
+ if (index > (finalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN) {
191
+ throw new Error(
192
+ `Highest used index ${index} is further than window length from the highest finalized index ${finalizedIndex ?? 0}.
193
+ Tagging window length ${UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN} is configured too low. Contact the Aztec team
194
+ to increase it!`,
195
+ );
196
+ }
197
+
198
+ // Throw if the new pending index is lower than or equal to the last finalized index
199
+ if (finalizedIndex !== undefined && index <= finalizedIndex) {
200
+ throw new Error(
201
+ `Cannot store pending index ${index} for secret ${secretStr}: ` +
202
+ `it is lower than or equal to the last finalized index ${finalizedIndex}`,
203
+ );
204
+ }
205
+
206
+ // Check if this secret + txHash combination already exists
207
+ const existingForSecretAndTx = pendingData.find(entry => entry.txHash === txHashStr);
208
+
209
+ if (existingForSecretAndTx) {
210
+ // If it exists with a different index, throw an error
211
+ if (existingForSecretAndTx.index !== index) {
212
+ throw new Error(
213
+ `Cannot store index ${index} for secret ${secretStr} and txHash ${txHashStr}: ` +
214
+ `a different index ${existingForSecretAndTx.index} already exists for this secret-txHash pair`,
215
+ );
216
+ }
217
+ // If it exists with the same index, ignore the update (no-op)
218
+ } else {
219
+ // If it doesn't exist, add it
220
+ this.#writePendingIndexes(jobId, secretStr, [...pendingData, { index, txHash: txHashStr }]);
221
+ }
222
+ }
223
+ });
224
+ }
225
+
226
+ /**
227
+ * Returns the transaction hashes of all pending transactions that contain indexes within a specified range
228
+ * for a given directional app tagging secret.
229
+ * @param secret - The directional app tagging secret to query pending indexes for.
230
+ * @param startIndex - The lower bound of the index range (inclusive).
231
+ * @param endIndex - The upper bound of the index range (exclusive).
232
+ * @returns An array of unique transaction hashes for pending transactions that contain indexes in the range
233
+ * [startIndex, endIndex). Returns an empty array if no pending indexes exist in the range.
234
+ */
235
+ getTxHashesOfPendingIndexes(
236
+ secret: DirectionalAppTaggingSecret,
237
+ startIndex: number,
238
+ endIndex: number,
239
+ jobId: string,
240
+ ): Promise<TxHash[]> {
241
+ return this.#store.transactionAsync(async () => {
242
+ const existing = await this.#readPendingIndexes(jobId, secret.toString());
243
+ const txHashes = existing
244
+ .filter(entry => entry.index >= startIndex && entry.index < endIndex)
245
+ .map(entry => entry.txHash);
246
+ return Array.from(new Set(txHashes)).map(TxHash.fromString);
247
+ });
248
+ }
249
+
250
+ /**
251
+ * Returns the last (highest) finalized index for a given secret.
252
+ * @param secret - The secret to get the last finalized index for.
253
+ * @returns The last (highest) finalized index for the given secret.
254
+ */
255
+ getLastFinalizedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
256
+ return this.#store.transactionAsync(() => this.#readLastFinalizedIndex(jobId, secret.toString()));
257
+ }
258
+
259
+ /**
260
+ * Returns the last used index for a given directional app tagging secret, considering both finalized and pending
261
+ * indexes.
262
+ * @param secret - The directional app tagging secret to query the last used index for.
263
+ * @returns The last used index.
264
+ */
265
+ getLastUsedIndex(secret: DirectionalAppTaggingSecret, jobId: string): Promise<number | undefined> {
266
+ const secretStr = secret.toString();
267
+
268
+ return this.#store.transactionAsync(async () => {
269
+ const pendingPromise = this.#readPendingIndexes(jobId, secretStr);
270
+ const finalizedPromise = this.#readLastFinalizedIndex(jobId, secretStr);
271
+
272
+ const [pendingTxScopedIndexes, lastFinalized] = await Promise.all([pendingPromise, finalizedPromise]);
273
+ const pendingIndexes = pendingTxScopedIndexes.map(entry => entry.index);
274
+
275
+ if (pendingTxScopedIndexes.length === 0) {
276
+ return lastFinalized;
277
+ }
278
+
279
+ // As the last used index we return the highest one from the pending indexes. Note that this value will be always
280
+ // higher than the last finalized index because we prune lower pending indexes when a tx is finalized.
281
+ return Math.max(...pendingIndexes);
282
+ });
283
+ }
284
+
285
+ /**
286
+ * Drops all pending indexes corresponding to the given transaction hashes.
287
+ */
288
+ dropPendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
289
+ if (txHashes.length === 0) {
290
+ return Promise.resolve();
291
+ }
292
+
293
+ const txHashStrings = new Set<string>(txHashes.map(txHash => txHash.toString()));
294
+
295
+ return this.#store.transactionAsync(async () => {
296
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
297
+ const secretReadPromises: Map<string, Promise<{ index: number; txHash: string }[]>> = new Map();
298
+
299
+ for await (const secret of this.#pendingIndexes.keysAsync()) {
300
+ secretReadPromises.set(secret, this.#readPendingIndexes(jobId, secret));
301
+ }
302
+
303
+ // Add staged-only secrets (sync, no DB)
304
+ for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
305
+ if (!secretReadPromises.has(secret)) {
306
+ secretReadPromises.set(secret, Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []));
307
+ }
308
+ }
309
+
310
+ // Await all reads together
311
+ const secrets = [...secretReadPromises.keys()];
312
+ const pendingDataResults = await Promise.all(secretReadPromises.values());
313
+
314
+ // Process in memory
315
+ for (let i = 0; i < secrets.length; i++) {
316
+ const secret = secrets[i];
317
+ const pendingData = pendingDataResults[i];
318
+
319
+ if (pendingData && pendingData.length > 0) {
320
+ const filtered = pendingData.filter(item => !txHashStrings.has(item.txHash));
321
+ if (filtered.length === 0) {
322
+ this.#writePendingIndexes(jobId, secret, []);
323
+ } else if (filtered.length !== pendingData.length) {
324
+ // Some items were filtered out, so update the pending data
325
+ this.#writePendingIndexes(jobId, secret, filtered);
326
+ }
327
+ // else: No items were filtered out (txHashes not found for this secret) --> no-op
328
+ }
329
+ }
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Updates pending indexes corresponding to the given transaction hashes to be finalized and prunes any lower pending
335
+ * indexes.
336
+ */
337
+ finalizePendingIndexes(txHashes: TxHash[], jobId: string): Promise<void> {
338
+ if (txHashes.length === 0) {
339
+ return Promise.resolve();
340
+ }
341
+
342
+ const txHashStrings = new Set(txHashes.map(tx => tx.toString()));
343
+
344
+ return this.#store.transactionAsync(async () => {
345
+ // Prefetch all data, start reads during iteration to keep IndexedDB transaction alive
346
+ const secretDataPromises: Map<
347
+ string,
348
+ { pending: Promise<{ index: number; txHash: string }[]>; finalized: Promise<number | undefined> }
349
+ > = new Map();
350
+
351
+ for await (const secret of this.#pendingIndexes.keysAsync()) {
352
+ secretDataPromises.set(secret, {
353
+ pending: this.#readPendingIndexes(jobId, secret),
354
+ finalized: this.#readLastFinalizedIndex(jobId, secret),
355
+ });
356
+ }
357
+
358
+ // Add staged-only secrets (sync, no DB)
359
+ for (const secret of this.#getPendingIndexesForJob(jobId).keys()) {
360
+ if (!secretDataPromises.has(secret)) {
361
+ secretDataPromises.set(secret, {
362
+ pending: Promise.resolve(this.#getPendingIndexesForJob(jobId).get(secret) ?? []),
363
+ finalized: Promise.resolve(this.#getLastFinalizedIndexesForJob(jobId).get(secret)),
364
+ });
365
+ }
366
+ }
367
+
368
+ // Await all reads together
369
+ const secrets = [...secretDataPromises.keys()];
370
+ const dataResults = await Promise.all(
371
+ secrets.map(async secret => ({
372
+ secret,
373
+ pendingData: await secretDataPromises.get(secret)!.pending,
374
+ lastFinalized: await secretDataPromises.get(secret)!.finalized,
375
+ })),
376
+ );
377
+
378
+ // Process all txHashes for each secret in memory
379
+ for (const { secret, pendingData, lastFinalized } of dataResults) {
380
+ if (!pendingData || pendingData.length === 0) {
381
+ continue;
382
+ }
383
+
384
+ let currentPending = pendingData;
385
+ let currentFinalized = lastFinalized;
386
+
387
+ // Process all txHashes for this secret
388
+ for (const txHashStr of txHashStrings) {
389
+ const matchingIndexes = currentPending.filter(item => item.txHash === txHashStr).map(item => item.index);
390
+ if (matchingIndexes.length === 0) {
391
+ continue;
392
+ }
393
+
394
+ if (matchingIndexes.length > 1) {
395
+ // We should always just store the highest pending index for a given tx hash and secret because the lower
396
+ // values are irrelevant.
397
+ throw new Error(`Multiple pending indexes found for tx hash ${txHashStr} and secret ${secret}`);
398
+ }
399
+
400
+ const newFinalized = matchingIndexes[0];
401
+
402
+ if (newFinalized < (currentFinalized ?? 0)) {
403
+ // This should never happen because when last finalized index was finalized we should have pruned the lower
404
+ // pending indexes.
405
+ throw new Error(
406
+ `New finalized index ${newFinalized} is smaller than the current last finalized index ${currentFinalized}`,
407
+ );
408
+ }
409
+
410
+ currentFinalized = newFinalized;
411
+
412
+ // When we add pending indexes, we ensure they are higher than the last finalized index. However, because we
413
+ // cannot control the order in which transactions are finalized, there may be pending indexes that are now
414
+ // obsolete because they are lower than the most recently finalized index. For this reason, we prune these
415
+ // outdated pending indexes.
416
+ currentPending = currentPending.filter(item => item.index > currentFinalized!);
417
+ }
418
+
419
+ // Write final state if changed
420
+ if (currentFinalized !== lastFinalized) {
421
+ this.#writeLastFinalizedIndex(jobId, secret, currentFinalized!);
422
+ }
423
+ if (currentPending !== pendingData) {
424
+ this.#writePendingIndexes(jobId, secret, currentPending);
425
+ }
426
+ }
427
+ });
428
+ }
429
+ }
@@ -1,2 +1,10 @@
1
- // Half the size of the window we slide over the tagging indexes.
2
- export const WINDOW_HALF_SIZE = 10;
1
+ // This window has to be as large as the largest expected number of logs emitted in a tx for a given directional app
2
+ // tagging secret. If we get more tag indexes consumed than this window, an error is thrown in `PXE::proveTx` function.
3
+ // This is set to a larger value than MAX_PRIVATE_LOGS_PER_TX (currently 64) because there could be more than
4
+ // MAX_PRIVATE_LOGS_PER_TX indexes consumed in case the logs are squashed. This happens when the log contains a note
5
+ // and the note is nullified in the same tx.
6
+ //
7
+ // Having a large window significantly slowed down `e2e_l1_with_wall_time` test as there we perform sync for more than
8
+ // 1000 secrets. For this reason we set it to a relatively low value of 20. 20 should be sufficient for all the use
9
+ // cases.
10
+ export const UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN = 20;
@@ -0,0 +1,68 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { BlockHash } from '@aztec/stdlib/block';
3
+ import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
6
+
7
+ /**
8
+ * Generic pagination helper that fetches all pages of results.
9
+ * @param numTags - The number of tags being queried (determines result array size).
10
+ * @param fetchPage - Function that fetches a single page of results given a page number.
11
+ * @returns An array of arrays, one per tag, containing all results across all pages.
12
+ */
13
+ async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Promise<T[][]>): Promise<T[][]> {
14
+ const allResultsPerTag: T[][] = Array.from({ length: numTags }, () => []);
15
+ let page = 0;
16
+ let hasMore = true;
17
+
18
+ while (hasMore) {
19
+ const resultsPage = await fetchPage(page);
20
+ hasMore = false;
21
+
22
+ for (let i = 0; i < resultsPage.length; i++) {
23
+ allResultsPerTag[i].push(...resultsPage[i]);
24
+ if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
25
+ hasMore = true;
26
+ }
27
+ }
28
+ page++;
29
+ }
30
+
31
+ return allResultsPerTag;
32
+ }
33
+
34
+ /**
35
+ * Fetches all private logs for the given tags, automatically paginating through all pages.
36
+ * @param aztecNode - The Aztec node to query.
37
+ * @param tags - The siloed tags to search for.
38
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
39
+ * because of reorgs).
40
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
41
+ */
42
+ export function getAllPrivateLogsByTags(
43
+ aztecNode: AztecNode,
44
+ tags: SiloedTag[],
45
+ anchorBlockHash: BlockHash,
46
+ ): Promise<TxScopedL2Log[][]> {
47
+ return getAllPages(tags.length, page => aztecNode.getPrivateLogsByTags(tags, page, anchorBlockHash));
48
+ }
49
+
50
+ /**
51
+ * Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
52
+ * @param aztecNode - The Aztec node to query.
53
+ * @param contractAddress - The contract address to search logs for.
54
+ * @param tags - The tags to search for.
55
+ * @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
56
+ * because of reorgs).
57
+ * @returns An array of log arrays, one per tag, containing all logs across all pages.
58
+ */
59
+ export function getAllPublicLogsByTagsFromContract(
60
+ aztecNode: AztecNode,
61
+ contractAddress: AztecAddress,
62
+ tags: Tag[],
63
+ anchorBlockHash: BlockHash,
64
+ ): Promise<TxScopedL2Log[][]> {
65
+ return getAllPages(tags.length, page =>
66
+ aztecNode.getPublicLogsByTagsFromContract(contractAddress, tags, page, anchorBlockHash),
67
+ );
68
+ }
@@ -1,6 +1,19 @@
1
- export * from './tag.js';
2
- export * from './constants.js';
3
- export * from './siloed_tag.js';
4
- export * from './utils.js';
5
- export { DirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
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
+ export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
15
+ export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
16
+
17
+ // Re-export tagging-related types from stdlib
18
+ export { DirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
6
19
  export { type PreTag } from '@aztec/stdlib/logs';
@@ -0,0 +1,143 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { BlockHash } from '@aztec/stdlib/block';
4
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { DirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
6
+
7
+ import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
8
+ import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
9
+ import { findHighestIndexes } from './utils/find_highest_indexes.js';
10
+ import { loadLogsForRange } from './utils/load_logs_for_range.js';
11
+
12
+ /**
13
+ * Loads private logs for `app` and sender-recipient pair defined by `secret` and updates the highest aged and
14
+ * finalized indexes in the db. At most load logs from blocks up to and including `anchorBlockNumber`.
15
+ *
16
+ * @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
17
+ * in the tagging data provider is indexed by the secret and hence completely disjoint.
18
+ */
19
+ export async function loadPrivateLogsForSenderRecipientPair(
20
+ secret: DirectionalAppTaggingSecret,
21
+ app: AztecAddress,
22
+ aztecNode: AztecNode,
23
+ taggingStore: RecipientTaggingStore,
24
+ anchorBlockNumber: BlockNumber,
25
+ anchorBlockHash: BlockHash,
26
+ jobId: string,
27
+ ): Promise<TxScopedL2Log[]> {
28
+ // # Explanation of how the algorithm works
29
+ // When we perform the sync we will look at logs that correspond to the tagging index range
30
+ // (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
31
+ //
32
+ // highestAgedIndex is the highest index that was used in a tx that is included in a block at least
33
+ // `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds ago.
34
+ // highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
35
+ //
36
+ // "(" denotes an open end of the range - the index is not included in the range.
37
+ // "]" denotes a closed end of the range - the index is included in the range.
38
+ //
39
+ // ## Explanation of highestAgedIndex
40
+ //
41
+ // highestAgedIndex is chosen such that for all tagging indexes `i <= highestAgedIndex` we know that no new logs can
42
+ // ever appear.
43
+ //
44
+ // This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
45
+ // - a transaction's maximum inclusion timestamp is at most `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds after
46
+ // the timestamp of its anchor block; and
47
+ // - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
48
+ //
49
+ // Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
50
+ // least `MAX_INCLUDE_BY_TIMESTAMP_DURATION` seconds in the past. Then there is no possibility of any *other* device
51
+ // trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
52
+ // a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
53
+ // chosen a larger index.
54
+ // If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
55
+ // because it would already have been expired.
56
+ //
57
+ // Therefore, once we see that index `I` has been used in a block that is at least `MAX_INCLUDE_BY_TIMESTAMP_DURATION`
58
+ // seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
59
+ //
60
+ // ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
61
+ //
62
+ // When a sender chooses a tagging index, they will select an index that is at most `WINDOW_LEN` greater than
63
+ // the highest finalized index. If that index was already used, they will throw an error. For this reason we
64
+ // don't have to look further than `highestFinalizedIndex + WINDOW_LEN`.
65
+
66
+ let finalizedBlockNumber: number, currentTimestamp: bigint;
67
+ {
68
+ const [l2Tips, latestBlockHeader] = await Promise.all([aztecNode.getL2Tips(), aztecNode.getBlockHeader('latest')]);
69
+
70
+ if (!latestBlockHeader) {
71
+ throw new Error('Node failed to return latest block header when syncing logs');
72
+ }
73
+
74
+ [finalizedBlockNumber, currentTimestamp] = [
75
+ l2Tips.finalized.block.number,
76
+ latestBlockHeader.globalVariables.timestamp,
77
+ ];
78
+ }
79
+
80
+ let start: number, end: number;
81
+ {
82
+ const currentHighestAgedIndex = await taggingStore.getHighestAgedIndex(secret, jobId);
83
+ const currentHighestFinalizedIndex = await taggingStore.getHighestFinalizedIndex(secret, jobId);
84
+
85
+ // We don't want to include the highest aged index so we start from `currentHighestAgedIndex + 1` (or 0 if not set)
86
+ start = currentHighestAgedIndex === undefined ? 0 : currentHighestAgedIndex + 1;
87
+
88
+ // The highest index a sender can choose is "highest finalized index + window length" but given that
89
+ // `loadLogsForRange` expects an exclusive `end` we add 1.
90
+ end = (currentHighestFinalizedIndex ?? 0) + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1;
91
+ }
92
+
93
+ const logs: TxScopedL2Log[] = [];
94
+
95
+ while (true) {
96
+ // Get private logs with their block timestamps and corresponding tagging indexes
97
+ const privateLogsWithIndexes = await loadLogsForRange(
98
+ secret,
99
+ app,
100
+ aztecNode,
101
+ start,
102
+ end,
103
+ anchorBlockNumber,
104
+ anchorBlockHash,
105
+ );
106
+
107
+ if (privateLogsWithIndexes.length === 0) {
108
+ break;
109
+ }
110
+
111
+ logs.push(...privateLogsWithIndexes.map(({ log }) => log));
112
+
113
+ const { highestAgedIndex, highestFinalizedIndex } = findHighestIndexes(
114
+ privateLogsWithIndexes,
115
+ currentTimestamp,
116
+ finalizedBlockNumber,
117
+ );
118
+
119
+ // Store updates in data provider and update local variables
120
+ if (highestAgedIndex !== undefined) {
121
+ await taggingStore.updateHighestAgedIndex(secret, highestAgedIndex, jobId);
122
+ }
123
+
124
+ if (highestFinalizedIndex === undefined) {
125
+ // We have not found a new highest finalized index, so there is no need to move the window forward.
126
+ break;
127
+ }
128
+
129
+ if (highestAgedIndex !== undefined && highestAgedIndex > highestFinalizedIndex) {
130
+ // This is just a sanity check as this should never happen.
131
+ throw new Error('Highest aged index lower than highest finalized index invariant violated');
132
+ }
133
+
134
+ await taggingStore.updateHighestFinalizedIndex(secret, highestFinalizedIndex, jobId);
135
+
136
+ // For the next iteration we want to look only at indexes for which we have not attempted to load logs yet while
137
+ // ensuring that we do not look further than WINDOW_LEN ahead of the highest finalized index.
138
+ start = end;
139
+ end = highestFinalizedIndex + UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN + 1; // `end` is exclusive so we add 1.
140
+ }
141
+
142
+ return logs;
143
+ }