@aztec/pxe 0.0.1-commit.b655e406 → 0.0.1-commit.c7c42ec

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 (350) hide show
  1. package/dest/bin/check_oracle_version.d.ts +1 -1
  2. package/dest/bin/check_oracle_version.js +105 -15
  3. package/dest/block_synchronizer/block_synchronizer.d.ts +37 -0
  4. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  5. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +20 -22
  6. package/dest/block_synchronizer/index.d.ts +2 -0
  7. package/dest/block_synchronizer/index.d.ts.map +1 -0
  8. package/dest/block_synchronizer/index.js +1 -0
  9. package/dest/config/index.d.ts +4 -12
  10. package/dest/config/index.d.ts.map +1 -1
  11. package/dest/config/index.js +7 -13
  12. package/dest/config/package_info.d.ts +1 -1
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts +43 -14
  14. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/contract_function_simulator.js +55 -29
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts +9 -7
  17. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/execution_note_cache.js +21 -13
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +2 -2
  20. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  22. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  23. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  24. package/dest/contract_function_simulator/index.d.ts +1 -1
  25. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
  26. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  28. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
  33. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -4
  34. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  36. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +2 -2
  37. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -1
  39. package/dest/contract_function_simulator/oracle/index.d.ts +1 -1
  40. package/dest/contract_function_simulator/oracle/interfaces.d.ts +19 -13
  41. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
  43. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  45. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
  46. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
  48. package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -4
  49. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/oracle.js +34 -17
  51. package/dest/contract_function_simulator/oracle/private_execution.d.ts +9 -10
  52. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/private_execution.js +12 -12
  54. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +24 -18
  55. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +41 -18
  57. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +58 -17
  58. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +147 -40
  60. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  61. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/pick_notes.js +1 -1
  63. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  64. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  66. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  67. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  68. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  69. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  70. package/dest/debug/pxe_debug_utils.js +37 -0
  71. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  72. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  73. package/dest/entrypoints/client/bundle/index.js +0 -1
  74. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  75. package/dest/entrypoints/client/bundle/utils.js +4 -4
  76. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  77. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  78. package/dest/entrypoints/client/lazy/index.js +0 -1
  79. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  80. package/dest/entrypoints/client/lazy/utils.js +4 -4
  81. package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
  82. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  83. package/dest/entrypoints/server/index.d.ts +2 -2
  84. package/dest/entrypoints/server/index.d.ts.map +1 -1
  85. package/dest/entrypoints/server/index.js +1 -1
  86. package/dest/entrypoints/server/utils.d.ts +1 -1
  87. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  88. package/dest/entrypoints/server/utils.js +5 -16
  89. package/dest/error_enriching.d.ts +4 -4
  90. package/dest/error_enriching.d.ts.map +1 -1
  91. package/dest/error_enriching.js +6 -6
  92. package/dest/events/event_service.d.ts +15 -0
  93. package/dest/events/event_service.d.ts.map +1 -0
  94. package/dest/events/event_service.js +47 -0
  95. package/dest/events/index.d.ts +2 -0
  96. package/dest/events/index.d.ts.map +1 -0
  97. package/dest/events/index.js +1 -0
  98. package/dest/events/private_event_filter_validator.d.ts +9 -0
  99. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  100. package/dest/events/private_event_filter_validator.js +39 -0
  101. package/dest/logs/log_service.d.ts +26 -0
  102. package/dest/logs/log_service.d.ts.map +1 -0
  103. package/dest/logs/log_service.js +120 -0
  104. package/dest/notes/index.d.ts +2 -0
  105. package/dest/notes/index.d.ts.map +1 -0
  106. package/dest/notes/index.js +1 -0
  107. package/dest/notes/note_service.d.ts +48 -0
  108. package/dest/notes/note_service.d.ts.map +1 -0
  109. package/dest/notes/note_service.js +152 -0
  110. package/dest/oracle_version.d.ts +3 -3
  111. package/dest/oracle_version.js +2 -2
  112. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  113. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  114. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  115. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  116. package/dest/private_kernel/hints/index.d.ts +1 -1
  117. package/dest/private_kernel/index.d.ts +1 -1
  118. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  119. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  120. package/dest/private_kernel/private_kernel_execution_prover.js +11 -10
  121. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
  122. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  123. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +8 -7
  124. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  125. package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
  126. package/dest/public_storage/public_storage_service.d.ts +24 -0
  127. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  128. package/dest/public_storage/public_storage_service.js +26 -0
  129. package/dest/pxe.d.ts +47 -48
  130. package/dest/pxe.d.ts.map +1 -1
  131. package/dest/pxe.js +142 -171
  132. package/dest/storage/address_store/address_store.d.ts +11 -0
  133. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  134. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -1
  135. package/dest/storage/address_store/index.d.ts +2 -0
  136. package/dest/storage/address_store/index.d.ts.map +1 -0
  137. package/dest/storage/address_store/index.js +1 -0
  138. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
  139. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  140. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -9
  141. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  142. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  143. package/dest/storage/anchor_block_store/index.js +1 -0
  144. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  145. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  146. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -6
  147. package/dest/storage/capsule_store/index.d.ts +2 -0
  148. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  149. package/dest/storage/capsule_store/index.js +1 -0
  150. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +7 -15
  151. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  152. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +34 -15
  153. package/dest/storage/contract_store/index.d.ts +2 -0
  154. package/dest/storage/contract_store/index.d.ts.map +1 -0
  155. package/dest/storage/contract_store/index.js +1 -0
  156. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  157. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  158. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  159. package/dest/storage/index.d.ts +8 -8
  160. package/dest/storage/index.d.ts.map +1 -1
  161. package/dest/storage/index.js +7 -7
  162. package/dest/storage/metadata.d.ts +1 -1
  163. package/dest/storage/note_store/index.d.ts +3 -0
  164. package/dest/storage/note_store/index.d.ts.map +1 -0
  165. package/dest/storage/note_store/index.js +2 -0
  166. package/dest/storage/{note_data_provider/note_data_provider.d.ts → note_store/note_store.d.ts} +14 -13
  167. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  168. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +33 -19
  169. package/dest/storage/private_event_store/private_event_store.d.ts +51 -0
  170. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  171. package/dest/storage/{private_event_data_provider/private_event_data_provider.js → private_event_store/private_event_store.js} +39 -28
  172. package/dest/storage/tagging_store/index.d.ts +4 -0
  173. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  174. package/dest/storage/tagging_store/index.js +3 -0
  175. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  176. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  177. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  178. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  179. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  180. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  181. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  182. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  183. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  184. package/dest/tagging/index.d.ts +15 -6
  185. package/dest/tagging/index.d.ts.map +1 -1
  186. package/dest/tagging/index.js +23 -5
  187. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  188. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  189. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  190. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  191. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  192. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  193. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  194. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  195. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  196. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  197. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  198. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  199. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  200. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  201. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  202. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  203. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  204. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  205. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  206. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  207. package/dest/tree_membership/tree_membership_service.js +84 -0
  208. package/package.json +20 -19
  209. package/src/bin/check_oracle_version.ts +130 -20
  210. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +19 -22
  211. package/src/block_synchronizer/index.ts +1 -0
  212. package/src/config/index.ts +10 -25
  213. package/src/contract_function_simulator/contract_function_simulator.ts +95 -28
  214. package/src/contract_function_simulator/execution_note_cache.ts +22 -11
  215. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  216. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  217. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  218. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  219. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -2
  220. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
  221. package/src/contract_function_simulator/noir-structs/utility_context.ts +1 -1
  222. package/src/contract_function_simulator/oracle/interfaces.ts +26 -11
  223. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  224. package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
  225. package/src/contract_function_simulator/oracle/oracle.ts +43 -13
  226. package/src/contract_function_simulator/oracle/private_execution.ts +17 -15
  227. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +100 -23
  228. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +223 -47
  229. package/src/contract_function_simulator/pick_notes.ts +1 -1
  230. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  231. package/src/debug/pxe_debug_utils.ts +48 -0
  232. package/src/entrypoints/client/bundle/index.ts +0 -1
  233. package/src/entrypoints/client/bundle/utils.ts +4 -4
  234. package/src/entrypoints/client/lazy/index.ts +0 -1
  235. package/src/entrypoints/client/lazy/utils.ts +4 -4
  236. package/src/entrypoints/pxe_creation_options.ts +2 -0
  237. package/src/entrypoints/server/index.ts +1 -1
  238. package/src/entrypoints/server/utils.ts +5 -19
  239. package/src/error_enriching.ts +7 -15
  240. package/src/events/event_service.ts +77 -0
  241. package/src/events/index.ts +1 -0
  242. package/src/events/private_event_filter_validator.ts +48 -0
  243. package/src/logs/log_service.ts +202 -0
  244. package/src/notes/index.ts +1 -0
  245. package/src/notes/note_service.ts +200 -0
  246. package/src/oracle_version.ts +2 -2
  247. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
  248. package/src/private_kernel/private_kernel_execution_prover.ts +12 -16
  249. package/src/private_kernel/private_kernel_oracle.ts +2 -1
  250. package/src/private_kernel/private_kernel_oracle_impl.ts +10 -9
  251. package/src/public_storage/public_storage_service.ts +33 -0
  252. package/src/pxe.ts +167 -223
  253. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -1
  254. package/src/storage/address_store/index.ts +1 -0
  255. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -11
  256. package/src/storage/anchor_block_store/index.ts +1 -0
  257. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -2
  258. package/src/storage/capsule_store/index.ts +1 -0
  259. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +45 -20
  260. package/src/storage/contract_store/index.ts +1 -0
  261. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  262. package/src/storage/index.ts +7 -7
  263. package/src/storage/note_store/index.ts +2 -0
  264. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +41 -22
  265. package/src/storage/{private_event_data_provider/private_event_data_provider.ts → private_event_store/private_event_store.ts} +61 -47
  266. package/src/storage/tagging_store/index.ts +3 -0
  267. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  268. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  269. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  270. package/src/tagging/index.ts +27 -5
  271. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  272. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  273. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  274. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  275. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
  276. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  277. package/src/tree_membership/tree_membership_service.ts +112 -0
  278. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -274
  279. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  280. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  281. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -122
  282. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  283. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  284. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  285. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  286. package/dest/storage/address_data_provider/index.d.ts +0 -2
  287. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  288. package/dest/storage/address_data_provider/index.js +0 -1
  289. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  290. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  291. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  292. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  293. package/dest/storage/capsule_data_provider/index.js +0 -1
  294. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  295. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  296. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  297. package/dest/storage/contract_data_provider/index.js +0 -1
  298. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  299. package/dest/storage/note_data_provider/index.d.ts +0 -3
  300. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  301. package/dest/storage/note_data_provider/index.js +0 -2
  302. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  303. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  304. package/dest/storage/note_data_provider/note_dao.js +0 -102
  305. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  306. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -43
  307. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  308. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  309. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  310. package/dest/storage/sync_data_provider/index.js +0 -1
  311. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -10
  312. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  313. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  314. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  315. package/dest/storage/tagging_data_provider/index.js +0 -1
  316. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  317. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  318. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  319. package/dest/synchronizer/index.d.ts +0 -2
  320. package/dest/synchronizer/index.d.ts.map +0 -1
  321. package/dest/synchronizer/index.js +0 -1
  322. package/dest/synchronizer/synchronizer.d.ts +0 -35
  323. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  324. package/dest/tagging/constants.d.ts +0 -2
  325. package/dest/tagging/constants.d.ts.map +0 -1
  326. package/dest/tagging/constants.js +0 -2
  327. package/dest/tagging/siloed_tag.d.ts +0 -14
  328. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  329. package/dest/tagging/siloed_tag.js +0 -20
  330. package/dest/tagging/tag.d.ts +0 -12
  331. package/dest/tagging/tag.d.ts.map +0 -1
  332. package/dest/tagging/tag.js +0 -17
  333. package/dest/tagging/utils.d.ts +0 -18
  334. package/dest/tagging/utils.d.ts.map +0 -1
  335. package/dest/tagging/utils.js +0 -24
  336. package/src/contract_function_simulator/execution_data_provider.ts +0 -343
  337. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1019
  338. package/src/storage/address_data_provider/index.ts +0 -1
  339. package/src/storage/capsule_data_provider/index.ts +0 -1
  340. package/src/storage/contract_data_provider/index.ts +0 -1
  341. package/src/storage/note_data_provider/index.ts +0 -2
  342. package/src/storage/note_data_provider/note_dao.ts +0 -154
  343. package/src/storage/sync_data_provider/index.ts +0 -1
  344. package/src/storage/tagging_data_provider/index.ts +0 -1
  345. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  346. package/src/synchronizer/index.ts +0 -1
  347. package/src/tagging/constants.ts +0 -2
  348. package/src/tagging/siloed_tag.ts +0 -22
  349. package/src/tagging/tag.ts +0 -16
  350. package/src/tagging/utils.ts +0 -31
@@ -1,701 +0,0 @@
1
- import { timesParallel } from '@aztec/foundation/collection';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { getFunctionArtifact } from '@aztec/stdlib/abi';
4
- import { computeUniqueNoteHash, siloNoteHash, siloNullifier, siloPrivateLog } from '@aztec/stdlib/hash';
5
- import { MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
6
- import { computeAddressSecret } from '@aztec/stdlib/keys';
7
- import { PendingTaggedLog, PrivateLogWithTxData, PublicLogWithTxData, deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
8
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
9
- import { Note } from '@aztec/stdlib/note';
10
- import { MerkleTreeId } from '@aztec/stdlib/trees';
11
- import { MessageLoadOracleInputs } from '../contract_function_simulator/oracle/message_load_oracle_inputs.js';
12
- import { ORACLE_VERSION } from '../oracle_version.js';
13
- import { NoteDao } from '../storage/note_data_provider/note_dao.js';
14
- import { DirectionalAppTaggingSecret, SiloedTag, Tag, WINDOW_HALF_SIZE, getInitialIndexesMap, getPreTagsForTheWindow } from '../tagging/index.js';
15
- import { EventValidationRequest } from './noir-structs/event_validation_request.js';
16
- import { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
17
- import { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
18
- import { NoteValidationRequest } from './noir-structs/note_validation_request.js';
19
- /**
20
- * A data layer that provides and stores information needed for simulating/proving a transaction.
21
- */ export class PXEOracleInterface {
22
- aztecNode;
23
- keyStore;
24
- contractDataProvider;
25
- noteDataProvider;
26
- capsuleDataProvider;
27
- syncDataProvider;
28
- taggingDataProvider;
29
- addressDataProvider;
30
- privateEventDataProvider;
31
- log;
32
- constructor(aztecNode, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, log = createLogger('pxe:pxe_oracle_interface')){
33
- this.aztecNode = aztecNode;
34
- this.keyStore = keyStore;
35
- this.contractDataProvider = contractDataProvider;
36
- this.noteDataProvider = noteDataProvider;
37
- this.capsuleDataProvider = capsuleDataProvider;
38
- this.syncDataProvider = syncDataProvider;
39
- this.taggingDataProvider = taggingDataProvider;
40
- this.addressDataProvider = addressDataProvider;
41
- this.privateEventDataProvider = privateEventDataProvider;
42
- this.log = log;
43
- }
44
- getKeyValidationRequest(pkMHash, contractAddress) {
45
- return this.keyStore.getKeyValidationRequest(pkMHash, contractAddress);
46
- }
47
- async getCompleteAddress(account) {
48
- const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
49
- if (!completeAddress) {
50
- throw new Error(`No public key registered for address ${account}.
51
- Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`);
52
- }
53
- return completeAddress;
54
- }
55
- async getContractInstance(address) {
56
- const instance = await this.contractDataProvider.getContractInstance(address);
57
- if (!instance) {
58
- throw new Error(`No contract instance found for address ${address.toString()}`);
59
- }
60
- return instance;
61
- }
62
- async getNotes(contractAddress, storageSlot, status, scopes) {
63
- const noteDaos = await this.noteDataProvider.getNotes({
64
- contractAddress,
65
- storageSlot,
66
- status,
67
- scopes
68
- });
69
- return noteDaos.map(({ contractAddress, storageSlot, noteNonce, note, noteHash, siloedNullifier, index })=>({
70
- contractAddress,
71
- storageSlot,
72
- noteNonce,
73
- note,
74
- noteHash,
75
- siloedNullifier,
76
- // PXE can use this index to get full MembershipWitness
77
- index
78
- }));
79
- }
80
- async getFunctionArtifact(contractAddress, selector) {
81
- const artifact = await this.contractDataProvider.getFunctionArtifact(contractAddress, selector);
82
- if (!artifact) {
83
- throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
84
- }
85
- const debug = await this.contractDataProvider.getFunctionDebugMetadata(contractAddress, selector);
86
- return {
87
- ...artifact,
88
- debug
89
- };
90
- }
91
- async getFunctionArtifactByName(contractAddress, functionName) {
92
- const instance = await this.contractDataProvider.getContractInstance(contractAddress);
93
- if (!instance) {
94
- return;
95
- }
96
- const artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
97
- return artifact && getFunctionArtifact(artifact, functionName);
98
- }
99
- /**
100
- * Fetches a message from the db, given its key.
101
- * @param contractAddress - Address of a contract by which the message was emitted.
102
- * @param messageHash - Hash of the message.
103
- * @param secret - Secret used to compute a nullifier.
104
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
105
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
106
- */ async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
107
- const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
108
- // Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
109
- return new MessageLoadOracleInputs(messageIndex, siblingPath);
110
- }
111
- async getNullifierIndex(nullifier) {
112
- return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
113
- }
114
- async #findLeafIndex(blockNumber, treeId, leafValue) {
115
- const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [
116
- leafValue
117
- ]);
118
- return leafIndex?.data;
119
- }
120
- async getMembershipWitness(blockNumber, treeId, leafValue) {
121
- const witness = await this.#tryGetMembershipWitness(blockNumber, treeId, leafValue);
122
- if (!witness) {
123
- throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block ${blockNumber}`);
124
- }
125
- return witness;
126
- }
127
- async #tryGetMembershipWitness(blockNumber, treeId, value) {
128
- switch(treeId){
129
- case MerkleTreeId.NULLIFIER_TREE:
130
- return (await this.aztecNode.getNullifierMembershipWitness(blockNumber, value))?.withoutPreimage().toFields();
131
- case MerkleTreeId.NOTE_HASH_TREE:
132
- return (await this.aztecNode.getNoteHashMembershipWitness(blockNumber, value))?.toFields();
133
- case MerkleTreeId.PUBLIC_DATA_TREE:
134
- return (await this.aztecNode.getPublicDataWitness(blockNumber, value))?.withoutPreimage().toFields();
135
- case MerkleTreeId.ARCHIVE:
136
- return (await this.aztecNode.getArchiveMembershipWitness(blockNumber, value))?.toFields();
137
- default:
138
- throw new Error('Not implemented');
139
- }
140
- }
141
- async getNullifierMembershipWitnessAtLatestBlock(nullifier) {
142
- const blockNumber = (await this.getAnchorBlockHeader()).globalVariables.blockNumber;
143
- return this.getNullifierMembershipWitness(blockNumber, nullifier);
144
- }
145
- getNullifierMembershipWitness(blockNumber, nullifier) {
146
- return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
147
- }
148
- async getLowNullifierMembershipWitness(blockNumber, nullifier) {
149
- const header = await this.getAnchorBlockHeader();
150
- if (blockNumber > header.globalVariables.blockNumber) {
151
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
152
- }
153
- return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
154
- }
155
- async getBlock(blockNumber) {
156
- const header = await this.getAnchorBlockHeader();
157
- if (blockNumber > header.globalVariables.blockNumber) {
158
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
159
- }
160
- return await this.aztecNode.getBlock(blockNumber);
161
- }
162
- async getPublicDataWitness(blockNumber, leafSlot) {
163
- const header = await this.getAnchorBlockHeader();
164
- if (blockNumber > header.globalVariables.blockNumber) {
165
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
166
- }
167
- return await this.aztecNode.getPublicDataWitness(blockNumber, leafSlot);
168
- }
169
- async getPublicStorageAt(blockNumber, contract, slot) {
170
- const header = await this.getAnchorBlockHeader();
171
- if (blockNumber > header.globalVariables.blockNumber) {
172
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
173
- }
174
- return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
175
- }
176
- getAnchorBlockHeader() {
177
- return this.syncDataProvider.getBlockHeader();
178
- }
179
- assertCompatibleOracleVersion(version) {
180
- if (version !== ORACLE_VERSION) {
181
- throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
182
- }
183
- }
184
- getDebugFunctionName(contractAddress, selector) {
185
- return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
186
- }
187
- /**
188
- * Returns the full contents of your address book.
189
- * This is used when calculating tags for incoming notes by deriving the shared secret, the contract-siloed tagging secret, and
190
- * finally the index specified tag. We will then query the node with this tag for each address in the address book.
191
- * @returns The full list of the users contact addresses.
192
- */ getSenders() {
193
- return this.taggingDataProvider.getSenderAddresses();
194
- }
195
- getLastUsedIndexAsSender(secret) {
196
- return this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
197
- }
198
- async calculateDirectionalAppTaggingSecret(contractAddress, sender, recipient) {
199
- const senderCompleteAddress = await this.getCompleteAddress(sender);
200
- const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
201
- return DirectionalAppTaggingSecret.compute(senderCompleteAddress, senderIvsk, recipient, contractAddress, recipient);
202
- }
203
- /**
204
- * Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
205
- * the senders in the address book.
206
- * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
207
- * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
208
- * so we're keeping it private for now.
209
- * @param contractAddress - The contract address to silo the secret for
210
- * @param recipient - The address receiving the notes
211
- * @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
212
- * secret was never used, the index is undefined.
213
- * TODO(benesjan): The naming here is broken as the function name does not reflect the return type. Fix when associating
214
- * indexes with tx hash.
215
- */ async #getLastUsedTaggingIndexesForSenders(contractAddress, recipient) {
216
- const recipientCompleteAddress = await this.getCompleteAddress(recipient);
217
- const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
218
- // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
219
- // (recipient = us, sender = us)
220
- const senders = [
221
- ...await this.taggingDataProvider.getSenderAddresses(),
222
- ...await this.keyStore.getAccounts()
223
- ].filter((address, index, self)=>index === self.findIndex((otherAddress)=>otherAddress.equals(address)));
224
- const secrets = await Promise.all(senders.map((contact)=>{
225
- return DirectionalAppTaggingSecret.compute(recipientCompleteAddress, recipientIvsk, contact, contractAddress, recipient);
226
- }));
227
- const indexes = await this.taggingDataProvider.getLastUsedIndexesAsRecipient(secrets);
228
- if (indexes.length !== secrets.length) {
229
- throw new Error('Indexes and directional app tagging secrets have different lengths');
230
- }
231
- return secrets.map((secret, i)=>({
232
- secret,
233
- index: indexes[i]
234
- }));
235
- }
236
- async syncTaggedLogsAsSender(secret, contractAddress) {
237
- const lastUsedIndex = await this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
238
- // If lastUsedIndex is undefined, we've never used this secret, so start from 0
239
- // Otherwise, start from one past the last used index
240
- const startIndex = lastUsedIndex === undefined ? 0 : lastUsedIndex + 1;
241
- // This algorithm works such that:
242
- // 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
243
- // we found and quit.
244
- // 2. If we don't find minimum consecutive empty logs in a window of logs we slide the window to latest log index
245
- // and repeat the process.
246
- const MIN_CONSECUTIVE_EMPTY_LOGS = 10;
247
- const WINDOW_SIZE = MIN_CONSECUTIVE_EMPTY_LOGS * 2;
248
- let [numConsecutiveEmptyLogs, currentIndex] = [
249
- 0,
250
- startIndex
251
- ];
252
- let lastFoundLogIndex = undefined;
253
- do {
254
- // We compute the tags for the current window of indexes
255
- const currentTags = await timesParallel(WINDOW_SIZE, async (i)=>{
256
- return SiloedTag.compute(await Tag.compute({
257
- secret,
258
- index: currentIndex + i
259
- }), contractAddress);
260
- });
261
- // We fetch the logs for the tags
262
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
263
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
264
- const tagsAsFr = currentTags.map((tag)=>tag.value);
265
- const possibleLogs = await this.#getPrivateLogsByTags(tagsAsFr);
266
- // We find the index of the last log in the window that is not empty
267
- const indexOfLastLogWithinArray = possibleLogs.findLastIndex((possibleLog)=>possibleLog.length !== 0);
268
- if (indexOfLastLogWithinArray === -1) {
269
- break;
270
- }
271
- // We've found logs so we update the last found log index
272
- lastFoundLogIndex = (lastFoundLogIndex ?? 0) + indexOfLastLogWithinArray;
273
- // We move the current index to that of the log right after the last found log
274
- currentIndex = lastFoundLogIndex + 1;
275
- // We compute the number of consecutive empty logs we found and repeat the process if we haven't found enough.
276
- numConsecutiveEmptyLogs = WINDOW_SIZE - indexOfLastLogWithinArray - 1;
277
- }while (numConsecutiveEmptyLogs < MIN_CONSECUTIVE_EMPTY_LOGS)
278
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
279
- if (lastFoundLogIndex !== undefined) {
280
- // Last found index is defined meaning we have actually found logs so we update the last used index
281
- await this.taggingDataProvider.setLastUsedIndexesAsSender([
282
- {
283
- secret,
284
- index: lastFoundLogIndex
285
- }
286
- ]);
287
- this.log.debug(`Syncing logs for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`, {
288
- index: currentIndex,
289
- contractName,
290
- contractAddress
291
- });
292
- } else {
293
- this.log.debug(`No new logs found for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`);
294
- }
295
- }
296
- /**
297
- * Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
298
- * logs in CapsuleArray ready for a later retrieval in Aztec.nr.
299
- * @param contractAddress - The address of the contract that the logs are tagged for.
300
- * @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged logs capsule array in which
301
- * found logs will be stored.
302
- * @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
303
- * synced.
304
- */ async syncTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, scopes) {
305
- this.log.verbose('Searching for tagged logs', {
306
- contract: contractAddress
307
- });
308
- const maxBlockNumber = await this.syncDataProvider.getBlockNumber();
309
- // Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
310
- // However it is impossible at the moment due to the language not supporting nested slices.
311
- // This nesting is necessary because for a given set of tags we don't
312
- // know how many logs we will get back. Furthermore, these logs are of undetermined
313
- // length, since we don't really know the note they correspond to until we decrypt them.
314
- const recipients = scopes ? scopes : await this.keyStore.getAccounts();
315
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
316
- for (const recipient of recipients){
317
- // Get all the secrets for the recipient and sender pairs (#9365)
318
- const indexedSecrets = await this.#getLastUsedTaggingIndexesForSenders(contractAddress, recipient);
319
- // We fetch logs for a window of indexes in a range:
320
- // <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
321
- //
322
- // We use this window approach because it could happen that a sender might have messed up and inadvertently
323
- // incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
324
- // for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
325
- // Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
326
- // some logs. For these reasons, we have to look both back and ahead of the stored index.
327
- let secretsAndWindows = indexedSecrets.map((indexedSecret)=>{
328
- if (indexedSecret.index === undefined) {
329
- return {
330
- secret: indexedSecret.secret,
331
- leftMostIndex: 0,
332
- rightMostIndex: WINDOW_HALF_SIZE
333
- };
334
- } else {
335
- return {
336
- secret: indexedSecret.secret,
337
- leftMostIndex: Math.max(0, indexedSecret.index - WINDOW_HALF_SIZE),
338
- rightMostIndex: indexedSecret.index + WINDOW_HALF_SIZE
339
- };
340
- }
341
- });
342
- // As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
343
- const newLargestIndexMapToStore = {};
344
- // The initial/unmodified indexes of the secrets stored in a key-value map where key is the directional app
345
- // tagging secret.
346
- const initialIndexesMap = getInitialIndexesMap(indexedSecrets);
347
- while(secretsAndWindows.length > 0){
348
- const preTagsForTheWholeWindow = getPreTagsForTheWindow(secretsAndWindows);
349
- const tagsForTheWholeWindow = await Promise.all(preTagsForTheWholeWindow.map(async (preTag)=>{
350
- return SiloedTag.compute(await Tag.compute(preTag), contractAddress);
351
- }));
352
- // We store the new largest indexes we find in the iteration in the following map to later on construct
353
- // a new set of secrets and windows to fetch logs for.
354
- const newLargestIndexMapForIteration = {};
355
- // Fetch the private logs for the tags and iterate over them
356
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
357
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
358
- const tagsForTheWholeWindowAsFr = tagsForTheWholeWindow.map((tag)=>tag.value);
359
- const logsByTags = await this.#getPrivateLogsByTags(tagsForTheWholeWindowAsFr);
360
- this.log.debug(`Found ${logsByTags.filter((logs)=>logs.length > 0).length} logs as recipient ${recipient}`, {
361
- recipient,
362
- contractName,
363
- contractAddress
364
- });
365
- for(let logIndex = 0; logIndex < logsByTags.length; logIndex++){
366
- const logsByTag = logsByTags[logIndex];
367
- if (logsByTag.length > 0) {
368
- // We filter out the logs that are newer than the anchor block number of the tx currently being constructed
369
- const filteredLogsByBlockNumber = logsByTag.filter((l)=>l.blockNumber <= maxBlockNumber);
370
- // We store the logs in capsules (to later be obtained in Noir)
371
- await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, filteredLogsByBlockNumber);
372
- // We retrieve the pre tag corresponding to the log as I need that to evaluate whether
373
- // a new largest index have been found.
374
- const preTagCorrespondingToLog = preTagsForTheWholeWindow[logIndex];
375
- const initialIndex = initialIndexesMap[preTagCorrespondingToLog.secret.toString()];
376
- if (preTagCorrespondingToLog.index >= initialIndex && (newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] === undefined || preTagCorrespondingToLog.index >= newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()])) {
377
- // We have found a new largest index so we store it for later processing (storing it in the db + fetching
378
- // the difference of the window sets of current and the next iteration)
379
- newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] = preTagCorrespondingToLog.index + 1;
380
- this.log.debug(`Incrementing index to ${preTagCorrespondingToLog.index + 1} at contract ${contractName}(${contractAddress})`);
381
- }
382
- }
383
- }
384
- // Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
385
- // for. Note that it's very unlikely that a new log from the current window would appear between the iterations
386
- // so we fetch the logs only for the difference of the window sets.
387
- const newSecretsAndWindows = [];
388
- for (const [directionalAppTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)){
389
- const maybeIndexedSecret = indexedSecrets.find((indexedSecret)=>indexedSecret.secret.toString() === directionalAppTaggingSecret);
390
- if (maybeIndexedSecret) {
391
- newSecretsAndWindows.push({
392
- secret: maybeIndexedSecret.secret,
393
- // We set the left most index to the new index to avoid fetching the same logs again
394
- leftMostIndex: newIndex,
395
- rightMostIndex: newIndex + WINDOW_HALF_SIZE
396
- });
397
- // We store the new largest index in the map to later store it in the db.
398
- newLargestIndexMapToStore[directionalAppTaggingSecret] = newIndex;
399
- } else {
400
- throw new Error(`Secret not found for directionalAppTaggingSecret ${directionalAppTaggingSecret}. This is a bug as it should never happen!`);
401
- }
402
- }
403
- // Now we set the new secrets and windows and proceed to the next iteration.
404
- secretsAndWindows = newSecretsAndWindows;
405
- }
406
- // At this point we have processed all the logs for the recipient so we store the last used indexes in the db.
407
- // newLargestIndexMapToStore contains "next" indexes to look for (one past the last found), so subtract 1 to get
408
- // last used.
409
- await this.taggingDataProvider.setLastUsedIndexesAsRecipient(Object.entries(newLargestIndexMapToStore).map(([directionalAppTaggingSecret, index])=>({
410
- secret: DirectionalAppTaggingSecret.fromString(directionalAppTaggingSecret),
411
- index: index - 1
412
- })));
413
- }
414
- }
415
- async #storePendingTaggedLogs(contractAddress, capsuleArrayBaseSlot, recipient, privateLogs) {
416
- // Build all pending tagged logs upfront with their tx effects
417
- const pendingTaggedLogs = await Promise.all(privateLogs.map(async (scopedLog)=>{
418
- // TODO(#9789): get these effects along with the log
419
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
420
- if (!txEffect) {
421
- throw new Error(`Could not find tx effect for tx hash ${scopedLog.txHash}`);
422
- }
423
- const pendingTaggedLog = new PendingTaggedLog(scopedLog.log.fields, scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0], recipient);
424
- return pendingTaggedLog.toFields();
425
- }));
426
- return this.capsuleDataProvider.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
427
- }
428
- async validateEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot) {
429
- // We read all note and event validation requests and process them all concurrently. This makes the process much
430
- // faster as we don't need to wait for the network round-trip.
431
- const noteValidationRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)).map(NoteValidationRequest.fromFields);
432
- const eventValidationRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)).map(EventValidationRequest.fromFields);
433
- const noteDeliveries = noteValidationRequests.map((request)=>this.deliverNote(request.contractAddress, request.storageSlot, request.noteNonce, request.content, request.noteHash, request.nullifier, request.txHash, request.recipient));
434
- const eventDeliveries = eventValidationRequests.map((request)=>this.deliverEvent(request.contractAddress, request.eventTypeId, request.serializedEvent, request.eventCommitment, request.txHash, request.recipient));
435
- await Promise.all([
436
- ...noteDeliveries,
437
- ...eventDeliveries
438
- ]);
439
- // Requests are cleared once we're done.
440
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
441
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
442
- }
443
- async deliverNote(contractAddress, storageSlot, noteNonce, content, noteHash, nullifier, txHash, recipient) {
444
- // We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
445
- // There's two things we need to check before we do this however:
446
- // - we must make sure the note does actually exist in the note hash tree
447
- // - we need to check if the note has already been nullified
448
- //
449
- // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
450
- // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
451
- // are catastrophic failure modes.
452
- //
453
- // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
454
- // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
455
- // so we must store both the note hash and nullifier block information.
456
- // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
457
- // in time of the locally synced state.
458
- // Note that while this technically results in historical queries, we perform it at the latest locally synced block
459
- // number which *should* be recent enough to be available, even for non-archive nodes.
460
- // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
461
- // logs up to the synced block making this only an additional safety check.
462
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
463
- // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
464
- // of other contracts, which would constitute a security breach.
465
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
466
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
467
- // We store notes by their index in the global note hash tree, which has the convenient side effect of validating
468
- // note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
469
- // queries in a single round-trip.
470
- const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
471
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [
472
- uniqueNoteHash
473
- ]),
474
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
475
- siloedNullifier
476
- ])
477
- ]);
478
- if (uniqueNoteHashTreeIndexInBlock === undefined) {
479
- throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`);
480
- }
481
- const noteDao = new NoteDao(new Note(content), contractAddress, storageSlot, noteNonce, noteHash, siloedNullifier, txHash, uniqueNoteHashTreeIndexInBlock?.l2BlockNumber, uniqueNoteHashTreeIndexInBlock?.l2BlockHash.toString(), uniqueNoteHashTreeIndexInBlock?.data, recipient);
482
- await this.noteDataProvider.addNotes([
483
- noteDao
484
- ], recipient);
485
- this.log.verbose('Added note', {
486
- index: noteDao.index,
487
- contract: noteDao.contractAddress.toString(),
488
- slot: noteDao.storageSlot.toString(),
489
- noteHash: noteDao.noteHash.toString(),
490
- nullifier: noteDao.siloedNullifier.toString()
491
- });
492
- if (nullifierIndex !== undefined) {
493
- const { data: _, ...blockHashAndNum } = nullifierIndex;
494
- await this.noteDataProvider.applyNullifiers([
495
- {
496
- data: siloedNullifier,
497
- ...blockHashAndNum
498
- }
499
- ]);
500
- this.log.verbose(`Removed just-added note`, {
501
- contract: contractAddress,
502
- slot: storageSlot,
503
- noteHash: noteHash,
504
- nullifier: siloedNullifier.toString()
505
- });
506
- }
507
- }
508
- async bulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot) {
509
- // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
510
- // don't need to wait for the network round-trip.
511
- const logRetrievalRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)).map(LogRetrievalRequest.fromFields);
512
- const maybeLogRetrievalResponses = await Promise.all(logRetrievalRequests.map(async (request)=>{
513
- // TODO(#14555): remove these internal functions and have node endpoints that do this instead
514
- const [publicLog, privateLog] = await Promise.all([
515
- this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
516
- this.getPrivateLogByTag(await siloPrivateLog(request.contractAddress, request.unsiloedTag))
517
- ]);
518
- if (publicLog !== null) {
519
- if (privateLog !== null) {
520
- throw new Error(`Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`);
521
- }
522
- return new LogRetrievalResponse(publicLog.logPayload, publicLog.txHash, publicLog.uniqueNoteHashesInTx, publicLog.firstNullifierInTx);
523
- } else if (privateLog !== null) {
524
- return new LogRetrievalResponse(privateLog.logPayload, privateLog.txHash, privateLog.uniqueNoteHashesInTx, privateLog.firstNullifierInTx);
525
- } else {
526
- null;
527
- }
528
- }));
529
- // Requests are cleared once we're done.
530
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
531
- // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
532
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalResponsesArrayBaseSlot, maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption));
533
- }
534
- async deliverEvent(contractAddress, selector, content, eventCommitment, txHash, recipient) {
535
- // While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
536
- // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
537
- // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
538
- // since `fetchTaggedLogs` only processes logs up to the synced block.
539
- const [syncedBlockNumber, siloedEventCommitment, txEffect] = await Promise.all([
540
- this.syncDataProvider.getBlockNumber(),
541
- siloNullifier(contractAddress, eventCommitment),
542
- this.aztecNode.getTxEffect(txHash)
543
- ]);
544
- if (!txEffect) {
545
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
546
- }
547
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
548
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
549
- }
550
- const eventInTx = txEffect.data.nullifiers.some((nullifier)=>nullifier.equals(siloedEventCommitment));
551
- if (!eventInTx) {
552
- throw new Error(`Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`);
553
- }
554
- const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
555
- siloedEventCommitment
556
- ]);
557
- if (nullifierIndex === undefined) {
558
- throw new Error(`Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`);
559
- }
560
- return this.privateEventDataProvider.storePrivateEventLog(contractAddress, recipient, selector, content, txHash, Number(nullifierIndex.data), nullifierIndex.l2BlockNumber, nullifierIndex.l2BlockHash);
561
- }
562
- // TODO(#14555): delete this function and implement this behavior in the node instead
563
- async getPublicLogByTag(tag, contractAddress) {
564
- const logs = await this.#getPublicLogsByTagsFromContract([
565
- tag
566
- ], contractAddress);
567
- const logsForTag = logs[0];
568
- this.log.debug(`Got ${logsForTag.length} public logs for tag ${tag}`);
569
- if (logsForTag.length == 0) {
570
- return null;
571
- } else if (logsForTag.length > 1) {
572
- // TODO(#11627): handle this case
573
- throw new Error(`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`);
574
- }
575
- const scopedLog = logsForTag[0];
576
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
577
- // we need to make a second call to the node for `getTxEffect`.
578
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
579
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
580
- if (txEffect == undefined) {
581
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
582
- }
583
- return new PublicLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
584
- }
585
- // TODO(#14555): delete this function and implement this behavior in the node instead
586
- async getPrivateLogByTag(siloedTag) {
587
- const logs = await this.#getPrivateLogsByTags([
588
- siloedTag
589
- ]);
590
- const logsForTag = logs[0];
591
- this.log.debug(`Got ${logsForTag.length} private logs for tag ${siloedTag}`);
592
- if (logsForTag.length == 0) {
593
- return null;
594
- } else if (logsForTag.length > 1) {
595
- // TODO(#11627): handle this case
596
- throw new Error(`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`);
597
- }
598
- const scopedLog = logsForTag[0];
599
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
600
- // we need to make a second call to the node for `getTxEffect`.
601
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
602
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
603
- if (txEffect == undefined) {
604
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
605
- }
606
- return new PrivateLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
607
- }
608
- /**
609
- * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
610
- *
611
- * Fetches notes from the NoteDataProvider and checks which nullifiers are present in the
612
- * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
613
- * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
614
- * notes are only marked nullified once their corresponding nullifier has been included in a
615
- * block up to which the PXE has synced.
616
- * This allows recent nullifications to be processed even if the node is not an archive node.
617
- *
618
- * @param contractAddress - The contract whose notes should be checked and nullified.
619
- */ async syncNoteNullifiers(contractAddress) {
620
- this.log.verbose('Searching for nullifiers of known notes', {
621
- contract: contractAddress
622
- });
623
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
624
- const contractNotes = await this.noteDataProvider.getNotes({
625
- contractAddress
626
- });
627
- if (contractNotes.length === 0) {
628
- return;
629
- }
630
- const nullifiersToCheck = contractNotes.map((note)=>note.siloedNullifier);
631
- const nullifierBatches = nullifiersToCheck.reduce((acc, nullifier)=>{
632
- if (acc[acc.length - 1].length < MAX_RPC_LEN) {
633
- acc[acc.length - 1].push(nullifier);
634
- } else {
635
- acc.push([
636
- nullifier
637
- ]);
638
- }
639
- return acc;
640
- }, [
641
- []
642
- ]);
643
- const nullifierIndexes = (await Promise.all(nullifierBatches.map((batch)=>this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, batch)))).flat();
644
- const foundNullifiers = nullifiersToCheck.map((nullifier, i)=>{
645
- if (nullifierIndexes[i] !== undefined) {
646
- return {
647
- ...nullifierIndexes[i],
648
- ...{
649
- data: nullifier
650
- }
651
- };
652
- }
653
- }).filter((nullifier)=>nullifier !== undefined);
654
- const nullifiedNotes = await this.noteDataProvider.applyNullifiers(foundNullifiers);
655
- nullifiedNotes.forEach((noteDao)=>{
656
- this.log.verbose(`Removed note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, {
657
- contract: noteDao.contractAddress,
658
- slot: noteDao.storageSlot,
659
- nullifier: noteDao.siloedNullifier.toString()
660
- });
661
- });
662
- }
663
- storeCapsule(contractAddress, slot, capsule) {
664
- return this.capsuleDataProvider.storeCapsule(contractAddress, slot, capsule);
665
- }
666
- loadCapsule(contractAddress, slot) {
667
- return this.capsuleDataProvider.loadCapsule(contractAddress, slot);
668
- }
669
- deleteCapsule(contractAddress, slot) {
670
- return this.capsuleDataProvider.deleteCapsule(contractAddress, slot);
671
- }
672
- copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
673
- return this.capsuleDataProvider.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
674
- }
675
- async getSharedSecret(address, ephPk) {
676
- // TODO(#12656): return an app-siloed secret
677
- const recipientCompleteAddress = await this.getCompleteAddress(address);
678
- const ivskM = await this.keyStore.getMasterSecretKey(recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey);
679
- const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
680
- return deriveEcdhSharedSecret(addressSecret, ephPk);
681
- }
682
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
683
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
684
- async #getPrivateLogsByTags(tags) {
685
- const allLogs = await this.aztecNode.getLogsByTags(tags);
686
- return allLogs.map((logs)=>logs.filter((log)=>!log.isFromPublic));
687
- }
688
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
689
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
690
- async #getPublicLogsByTagsFromContract(tags, contractAddress) {
691
- const allLogs = await this.aztecNode.getLogsByTags(tags);
692
- const allPublicLogs = allLogs.map((logs)=>logs.filter((log)=>log.isFromPublic));
693
- return allPublicLogs.map((logs)=>logs.filter((log)=>log.log.contractAddress.equals(contractAddress)));
694
- }
695
- getStats() {
696
- const nodeRPCCalls = typeof this.aztecNode.getStats === 'function' ? this.aztecNode.getStats() : {};
697
- return {
698
- nodeRPCCalls
699
- };
700
- }
701
- }