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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +1 -1
  3. package/dest/bin/check_oracle_version.js +110 -10
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  6. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +23 -23
  7. package/dest/block_synchronizer/index.d.ts +2 -0
  8. package/dest/block_synchronizer/index.d.ts.map +1 -0
  9. package/dest/block_synchronizer/index.js +1 -0
  10. package/dest/config/index.d.ts +9 -17
  11. package/dest/config/index.d.ts.map +1 -1
  12. package/dest/config/index.js +10 -16
  13. package/dest/config/package_info.d.ts +1 -1
  14. package/dest/config/package_info.js +1 -1
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +44 -15
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +142 -57
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +11 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +28 -17
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  24. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  25. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.d.ts +4 -2
  27. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/index.js +2 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -3
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  39. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  43. package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
  44. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  45. package/dest/contract_function_simulator/oracle/index.js +1 -1
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +103 -0
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts +17 -15
  56. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/oracle/oracle.js +101 -81
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts +11 -12
  59. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  60. package/dest/contract_function_simulator/oracle/private_execution.js +15 -24
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +51 -25
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +103 -27
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -36
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  66. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +171 -69
  67. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  68. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  69. package/dest/contract_function_simulator/pick_notes.js +1 -1
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  71. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  72. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  73. package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
  74. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
  75. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  76. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  77. package/dest/debug/pxe_debug_utils.js +37 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +4 -3
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +2 -2
  81. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +21 -12
  84. package/dest/entrypoints/client/lazy/index.d.ts +4 -3
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +2 -2
  87. package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +20 -11
  90. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.d.ts +5 -3
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +3 -2
  95. package/dest/entrypoints/server/utils.d.ts +5 -24
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +17 -45
  98. package/dest/error_enriching.d.ts +11 -0
  99. package/dest/error_enriching.d.ts.map +1 -0
  100. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
  101. package/dest/events/event_service.d.ts +15 -0
  102. package/dest/events/event_service.d.ts.map +1 -0
  103. package/dest/events/event_service.js +47 -0
  104. package/dest/events/index.d.ts +2 -0
  105. package/dest/events/index.d.ts.map +1 -0
  106. package/dest/events/index.js +1 -0
  107. package/dest/events/private_event_filter_validator.d.ts +9 -0
  108. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  109. package/dest/events/private_event_filter_validator.js +39 -0
  110. package/dest/logs/log_service.d.ts +26 -0
  111. package/dest/logs/log_service.d.ts.map +1 -0
  112. package/dest/logs/log_service.js +120 -0
  113. package/dest/notes/index.d.ts +2 -0
  114. package/dest/notes/index.d.ts.map +1 -0
  115. package/dest/notes/index.js +1 -0
  116. package/dest/notes/note_service.d.ts +48 -0
  117. package/dest/notes/note_service.d.ts.map +1 -0
  118. package/dest/notes/note_service.js +152 -0
  119. package/dest/oracle_version.d.ts +3 -3
  120. package/dest/oracle_version.js +2 -2
  121. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
  122. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  123. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
  124. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
  125. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
  126. package/dest/private_kernel/hints/index.d.ts +1 -1
  127. package/dest/private_kernel/index.d.ts +1 -1
  128. package/dest/private_kernel/private_kernel_execution_prover.d.ts +9 -2
  129. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  130. package/dest/private_kernel/private_kernel_execution_prover.js +38 -32
  131. package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
  132. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  133. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +10 -9
  134. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  135. package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
  136. package/dest/public_storage/public_storage_service.d.ts +24 -0
  137. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  138. package/dest/public_storage/public_storage_service.js +26 -0
  139. package/dest/pxe.d.ts +232 -0
  140. package/dest/pxe.d.ts.map +1 -0
  141. package/dest/{pxe_service/pxe_service.js → pxe.js} +299 -324
  142. package/dest/storage/address_store/address_store.d.ts +11 -0
  143. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  144. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -4
  145. package/dest/storage/address_store/index.d.ts +2 -0
  146. package/dest/storage/address_store/index.d.ts.map +1 -0
  147. package/dest/storage/address_store/index.js +1 -0
  148. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
  149. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  150. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -12
  151. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  152. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  153. package/dest/storage/anchor_block_store/index.js +1 -0
  154. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  155. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  156. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -10
  157. package/dest/storage/capsule_store/index.d.ts +2 -0
  158. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  159. package/dest/storage/capsule_store/index.js +1 -0
  160. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +10 -18
  161. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  162. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -18
  163. package/dest/storage/contract_store/index.d.ts +2 -0
  164. package/dest/storage/contract_store/index.d.ts.map +1 -0
  165. package/dest/storage/contract_store/index.js +1 -0
  166. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  167. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  168. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  169. package/dest/storage/index.d.ts +8 -9
  170. package/dest/storage/index.d.ts.map +1 -1
  171. package/dest/storage/index.js +7 -8
  172. package/dest/storage/metadata.d.ts +1 -1
  173. package/dest/storage/note_store/index.d.ts +3 -0
  174. package/dest/storage/note_store/index.d.ts.map +1 -0
  175. package/dest/storage/note_store/index.js +2 -0
  176. package/dest/storage/note_store/note_store.d.ts +84 -0
  177. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  178. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +144 -82
  179. package/dest/storage/private_event_store/private_event_store.d.ts +56 -0
  180. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  181. package/dest/storage/private_event_store/private_event_store.js +157 -0
  182. package/dest/storage/tagging_store/index.d.ts +4 -0
  183. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  184. package/dest/storage/tagging_store/index.js +3 -0
  185. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  186. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  187. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  188. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  189. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  190. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  191. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  192. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  193. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  194. package/dest/tagging/index.d.ts +16 -0
  195. package/dest/tagging/index.d.ts.map +1 -0
  196. package/dest/tagging/index.js +23 -0
  197. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  198. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  199. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  200. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  201. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  202. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  203. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  204. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  205. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  206. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  207. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  208. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  209. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  210. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  211. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  212. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  213. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  214. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  215. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  216. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  217. package/dest/tree_membership/tree_membership_service.js +84 -0
  218. package/package.json +22 -24
  219. package/src/bin/check_oracle_version.ts +134 -10
  220. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +22 -23
  221. package/src/block_synchronizer/index.ts +1 -0
  222. package/src/config/index.ts +18 -32
  223. package/src/config/package_info.ts +1 -1
  224. package/src/contract_function_simulator/contract_function_simulator.ts +233 -75
  225. package/src/contract_function_simulator/execution_note_cache.ts +33 -17
  226. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  227. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  228. package/src/contract_function_simulator/index.ts +3 -1
  229. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  230. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  231. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
  232. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
  233. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  234. package/src/contract_function_simulator/oracle/index.ts +1 -1
  235. package/src/contract_function_simulator/oracle/interfaces.ts +175 -0
  236. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  237. package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
  238. package/src/contract_function_simulator/oracle/oracle.ts +135 -80
  239. package/src/contract_function_simulator/oracle/private_execution.ts +22 -28
  240. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +200 -56
  241. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +260 -109
  242. package/src/contract_function_simulator/pick_notes.ts +1 -1
  243. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  244. package/src/debug/pxe_debug_utils.ts +48 -0
  245. package/src/entrypoints/client/bundle/index.ts +3 -2
  246. package/src/entrypoints/client/bundle/utils.ts +21 -23
  247. package/src/entrypoints/client/lazy/index.ts +3 -2
  248. package/src/entrypoints/client/lazy/utils.ts +20 -23
  249. package/src/entrypoints/pxe_creation_options.ts +4 -1
  250. package/src/entrypoints/server/index.ts +4 -2
  251. package/src/entrypoints/server/utils.ts +20 -68
  252. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
  253. package/src/events/event_service.ts +77 -0
  254. package/src/events/index.ts +1 -0
  255. package/src/events/private_event_filter_validator.ts +48 -0
  256. package/src/logs/log_service.ts +202 -0
  257. package/src/notes/index.ts +1 -0
  258. package/src/notes/note_service.ts +200 -0
  259. package/src/oracle_version.ts +2 -2
  260. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
  261. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
  262. package/src/private_kernel/private_kernel_execution_prover.ts +51 -43
  263. package/src/private_kernel/private_kernel_oracle.ts +2 -1
  264. package/src/private_kernel/private_kernel_oracle_impl.ts +10 -9
  265. package/src/public_storage/public_storage_service.ts +33 -0
  266. package/src/{pxe_service/pxe_service.ts → pxe.ts} +349 -410
  267. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -7
  268. package/src/storage/address_store/index.ts +1 -0
  269. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -17
  270. package/src/storage/anchor_block_store/index.ts +1 -0
  271. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -12
  272. package/src/storage/capsule_store/index.ts +1 -0
  273. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -28
  274. package/src/storage/contract_store/index.ts +1 -0
  275. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  276. package/src/storage/index.ts +7 -8
  277. package/src/storage/note_store/index.ts +2 -0
  278. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +173 -111
  279. package/src/storage/private_event_store/private_event_store.ts +213 -0
  280. package/src/storage/tagging_store/index.ts +3 -0
  281. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  282. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  283. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  284. package/src/tagging/index.ts +28 -0
  285. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  286. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  287. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  288. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  289. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
  290. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  291. package/src/tree_membership/tree_membership_service.ts +112 -0
  292. package/dest/bin/index.d.ts +0 -3
  293. package/dest/bin/index.d.ts.map +0 -1
  294. package/dest/bin/index.js +0 -48
  295. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
  296. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  297. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  298. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  299. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  300. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  301. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
  302. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  303. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  304. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  305. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  306. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  307. package/dest/pxe_service/error_enriching.d.ts +0 -11
  308. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  309. package/dest/pxe_service/index.d.ts +0 -3
  310. package/dest/pxe_service/index.d.ts.map +0 -1
  311. package/dest/pxe_service/index.js +0 -2
  312. package/dest/pxe_service/pxe_service.d.ts +0 -100
  313. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  314. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
  315. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  316. package/dest/storage/address_data_provider/index.d.ts +0 -2
  317. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  318. package/dest/storage/address_data_provider/index.js +0 -1
  319. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
  320. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  321. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  322. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  323. package/dest/storage/capsule_data_provider/index.js +0 -1
  324. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  325. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  326. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  327. package/dest/storage/contract_data_provider/index.js +0 -1
  328. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  329. package/dest/storage/data_provider.d.ts +0 -4
  330. package/dest/storage/data_provider.d.ts.map +0 -1
  331. package/dest/storage/data_provider.js +0 -1
  332. package/dest/storage/note_data_provider/index.d.ts +0 -3
  333. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  334. package/dest/storage/note_data_provider/index.js +0 -2
  335. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  336. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  337. package/dest/storage/note_data_provider/note_dao.js +0 -102
  338. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
  339. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  340. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  341. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  342. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
  343. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  344. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  345. package/dest/storage/sync_data_provider/index.js +0 -1
  346. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  347. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  348. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  349. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  350. package/dest/storage/tagging_data_provider/index.js +0 -1
  351. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  352. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  353. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
  354. package/dest/synchronizer/index.d.ts +0 -2
  355. package/dest/synchronizer/index.d.ts.map +0 -1
  356. package/dest/synchronizer/index.js +0 -1
  357. package/dest/synchronizer/synchronizer.d.ts +0 -35
  358. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  359. package/dest/test/pxe_test_suite.d.ts +0 -3
  360. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  361. package/dest/test/pxe_test_suite.js +0 -97
  362. package/src/bin/index.ts +0 -62
  363. package/src/contract_function_simulator/execution_data_provider.ts +0 -361
  364. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  365. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
  366. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  367. package/src/pxe_service/index.ts +0 -2
  368. package/src/storage/address_data_provider/index.ts +0 -1
  369. package/src/storage/capsule_data_provider/index.ts +0 -1
  370. package/src/storage/contract_data_provider/index.ts +0 -1
  371. package/src/storage/data_provider.ts +0 -3
  372. package/src/storage/note_data_provider/index.ts +0 -2
  373. package/src/storage/note_data_provider/note_dao.ts +0 -154
  374. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
  375. package/src/storage/sync_data_provider/index.ts +0 -1
  376. package/src/storage/tagging_data_provider/index.ts +0 -1
  377. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
  378. package/src/synchronizer/index.ts +0 -1
  379. package/src/test/pxe_test_suite.ts +0 -113
@@ -1,64 +1,41 @@
1
- import { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { SerialQueue } from '@aztec/foundation/queue';
5
5
  import { Timer } from '@aztec/foundation/timer';
6
- import type { SiblingPath } from '@aztec/foundation/trees';
7
6
  import { KeyStore } from '@aztec/key-store';
8
7
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
8
  import { L2TipsKVStore } from '@aztec/kv-store/stores';
10
- import {
11
- ProtocolContractAddress,
12
- type ProtocolContractsProvider,
13
- protocolContractNames,
14
- } from '@aztec/protocol-contracts';
9
+ import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
15
10
  import type { CircuitSimulator } from '@aztec/simulator/client';
16
11
  import {
17
12
  type ContractArtifact,
18
13
  EventSelector,
19
14
  FunctionCall,
20
- FunctionSelector,
21
15
  FunctionType,
22
- decodeFromAbi,
23
16
  decodeFunctionSignature,
24
- encodeArguments,
25
17
  } from '@aztec/stdlib/abi';
26
18
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
27
19
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
28
- import type { L2Block } from '@aztec/stdlib/block';
29
20
  import {
30
21
  CompleteAddress,
31
22
  type ContractClassWithId,
32
23
  type ContractInstanceWithAddress,
33
- type NodeInfo,
34
24
  type PartialAddress,
35
25
  computeContractAddressFromInstance,
36
26
  getContractClassFromArtifact,
37
27
  } from '@aztec/stdlib/contract';
38
28
  import { SimulationError } from '@aztec/stdlib/errors';
39
- import type { GasFees } from '@aztec/stdlib/gas';
40
- import { siloNullifier } from '@aztec/stdlib/hash';
41
- import type {
42
- AztecNode,
43
- EventMetadataDefinition,
44
- GetContractClassLogsResponse,
45
- GetPublicLogsResponse,
46
- PXE,
47
- PXEInfo,
48
- PrivateKernelProver,
49
- } from '@aztec/stdlib/interfaces/client';
29
+ import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
+ import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
50
31
  import type {
51
32
  PrivateExecutionStep,
52
33
  PrivateKernelExecutionProofOutput,
53
34
  PrivateKernelTailCircuitPublicInputs,
54
35
  } from '@aztec/stdlib/kernel';
55
- import type { LogFilter } from '@aztec/stdlib/logs';
56
- import { computeL2ToL1MembershipWitness, getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
57
- import { type NotesFilter, UniqueNote } from '@aztec/stdlib/note';
58
- import { MerkleTreeId } from '@aztec/stdlib/trees';
59
36
  import {
60
37
  type ContractOverrides,
61
- type IndexedTxEffect,
38
+ type InTx,
62
39
  PrivateExecutionResult,
63
40
  PrivateSimulationResult,
64
41
  type ProvingTimings,
@@ -67,73 +44,78 @@ import {
67
44
  type SimulationTimings,
68
45
  Tx,
69
46
  TxExecutionRequest,
70
- type TxHash,
71
47
  TxProfileResult,
72
48
  TxProvingResult,
73
- type TxReceipt,
74
49
  TxSimulationResult,
75
50
  UtilitySimulationResult,
76
51
  } from '@aztec/stdlib/tx';
77
52
 
78
53
  import { inspect } from 'util';
79
54
 
80
- import type { PXEServiceConfig } from '../config/index.js';
81
- import { getPackageInfo } from '../config/package_info.js';
55
+ import { BlockSynchronizer } from './block_synchronizer/index.js';
56
+ import type { PXEConfig } from './config/index.js';
82
57
  import {
83
58
  ContractFunctionSimulator,
84
59
  generateSimulatedProvingResult,
85
- } from '../contract_function_simulator/contract_function_simulator.js';
86
- import { readCurrentClassId } from '../contract_function_simulator/oracle/private_execution.js';
87
- import { ProxiedContractDataProviderFactory } from '../contract_function_simulator/proxied_contract_data_source.js';
88
- import { ProxiedNodeFactory } from '../contract_function_simulator/proxied_node.js';
89
- import { PXEOracleInterface } from '../contract_function_simulator/pxe_oracle_interface.js';
60
+ } from './contract_function_simulator/contract_function_simulator.js';
61
+ import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
+ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
+ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
+ import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
+ import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
90
66
  import {
91
67
  PrivateKernelExecutionProver,
92
68
  type PrivateKernelExecutionProverConfig,
93
- } from '../private_kernel/private_kernel_execution_prover.js';
94
- import { PrivateKernelOracleImpl } from '../private_kernel/private_kernel_oracle_impl.js';
95
- import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
96
- import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
97
- import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
98
- import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
99
- import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
100
- import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
101
- import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
102
- import { Synchronizer } from '../synchronizer/index.js';
103
- import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
69
+ } from './private_kernel/private_kernel_execution_prover.js';
70
+ import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
71
+ import { AddressStore } from './storage/address_store/address_store.js';
72
+ import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
73
+ import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
74
+ import { ContractStore } from './storage/contract_store/contract_store.js';
75
+ import { NoteStore } from './storage/note_store/note_store.js';
76
+ import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
77
+ import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
78
+ import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
79
+ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
80
+
81
+ export type PackedPrivateEvent = InTx & {
82
+ packedEvent: Fr[];
83
+ eventSelector: EventSelector;
84
+ };
104
85
 
105
86
  /**
106
- * A Private eXecution Environment (PXE) implementation.
87
+ * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
88
+ * manage private state of users.
107
89
  */
108
- export class PXEService implements PXE {
109
- #nodeInfo?: NodeInfo;
110
-
90
+ export class PXE {
111
91
  private constructor(
112
92
  private node: AztecNode,
113
- private synchronizer: Synchronizer,
93
+ private blockStateSynchronizer: BlockSynchronizer,
114
94
  private keyStore: KeyStore,
115
- private contractDataProvider: ContractDataProvider,
116
- private noteDataProvider: NoteDataProvider,
117
- private capsuleDataProvider: CapsuleDataProvider,
118
- private syncDataProvider: SyncDataProvider,
119
- private taggingDataProvider: TaggingDataProvider,
120
- private addressDataProvider: AddressDataProvider,
121
- private privateEventDataProvider: PrivateEventDataProvider,
95
+ private contractStore: ContractStore,
96
+ private noteStore: NoteStore,
97
+ private capsuleStore: CapsuleStore,
98
+ private anchorBlockStore: AnchorBlockStore,
99
+ private senderTaggingStore: SenderTaggingStore,
100
+ private senderAddressBookStore: SenderAddressBookStore,
101
+ private recipientTaggingStore: RecipientTaggingStore,
102
+ private addressStore: AddressStore,
103
+ private privateEventStore: PrivateEventStore,
122
104
  private simulator: CircuitSimulator,
123
- private packageVersion: string,
124
105
  private proverEnabled: boolean,
125
106
  private proofCreator: PrivateKernelProver,
126
107
  private protocolContractsProvider: ProtocolContractsProvider,
127
108
  private log: Logger,
128
109
  private jobQueue: SerialQueue,
110
+ public debug: PXEDebugUtils,
129
111
  ) {}
130
112
 
131
113
  /**
132
- * Creates an instance of a PXE Service by instantiating all the necessary data providers and services.
114
+ * Creates an instance of a PXE by instantiating all the necessary data providers and services.
133
115
  * Also triggers the registration of the protocol contracts and makes sure the provided node
134
116
  * can be contacted.
135
117
  *
136
- * @returns A promise that resolves PXE service is ready to be used.
118
+ * @returns A promise that resolves PXE is ready to be used.
137
119
  */
138
120
  public static async create(
139
121
  node: AztecNode,
@@ -141,7 +123,7 @@ export class PXEService implements PXE {
141
123
  proofCreator: PrivateKernelProver,
142
124
  simulator: CircuitSimulator,
143
125
  protocolContractsProvider: ProtocolContractsProvider,
144
- config: PXEServiceConfig,
126
+ config: PXEConfig,
145
127
  loggerOrSuffix?: string | Logger,
146
128
  ) {
147
129
  const log =
@@ -149,126 +131,83 @@ export class PXEService implements PXE {
149
131
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
150
132
  : loggerOrSuffix;
151
133
 
152
- const packageVersion = getPackageInfo().version;
153
134
  const proverEnabled = !!config.proverEnabled;
154
- const addressDataProvider = new AddressDataProvider(store);
155
- const privateEventDataProvider = new PrivateEventDataProvider(store);
156
- const contractDataProvider = new ContractDataProvider(store);
157
- const noteDataProvider = await NoteDataProvider.create(store);
158
- const syncDataProvider = new SyncDataProvider(store);
159
- const taggingDataProvider = new TaggingDataProvider(store);
160
- const capsuleDataProvider = new CapsuleDataProvider(store);
135
+ const addressStore = new AddressStore(store);
136
+ const privateEventStore = new PrivateEventStore(store);
137
+ const contractStore = new ContractStore(store);
138
+ const noteStore = await NoteStore.create(store);
139
+ const anchorBlockStore = new AnchorBlockStore(store);
140
+ const senderTaggingStore = new SenderTaggingStore(store);
141
+ const senderAddressBookStore = new SenderAddressBookStore(store);
142
+ const recipientTaggingStore = new RecipientTaggingStore(store);
143
+ const capsuleStore = new CapsuleStore(store);
161
144
  const keyStore = new KeyStore(store);
162
145
  const tipsStore = new L2TipsKVStore(store, 'pxe');
163
- const synchronizer = new Synchronizer(
146
+ const synchronizer = new BlockSynchronizer(
164
147
  node,
165
- syncDataProvider,
166
- noteDataProvider,
167
- taggingDataProvider,
148
+ anchorBlockStore,
149
+ noteStore,
150
+ privateEventStore,
168
151
  tipsStore,
169
152
  config,
170
153
  loggerOrSuffix,
171
154
  );
172
155
 
156
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore);
157
+
173
158
  const jobQueue = new SerialQueue();
174
159
 
175
- const pxeService = new PXEService(
160
+ const pxe = new PXE(
176
161
  node,
177
162
  synchronizer,
178
163
  keyStore,
179
- contractDataProvider,
180
- noteDataProvider,
181
- capsuleDataProvider,
182
- syncDataProvider,
183
- taggingDataProvider,
184
- addressDataProvider,
185
- privateEventDataProvider,
164
+ contractStore,
165
+ noteStore,
166
+ capsuleStore,
167
+ anchorBlockStore,
168
+ senderTaggingStore,
169
+ senderAddressBookStore,
170
+ recipientTaggingStore,
171
+ addressStore,
172
+ privateEventStore,
186
173
  simulator,
187
- packageVersion,
188
174
  proverEnabled,
189
175
  proofCreator,
190
176
  protocolContractsProvider,
191
177
  log,
192
178
  jobQueue,
179
+ debugUtils,
193
180
  );
194
181
 
195
- pxeService.jobQueue.start();
182
+ debugUtils.setPXE(pxe);
196
183
 
197
- await pxeService.#registerProtocolContracts();
198
- const info = await pxeService.getNodeInfo();
199
- log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
200
- return pxeService;
201
- }
184
+ pxe.jobQueue.start();
202
185
 
203
- // Aztec node proxy methods
204
-
205
- public isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
206
- return this.node.isL1ToL2MessageSynced(l1ToL2Message);
207
- }
208
-
209
- public async getL2ToL1MembershipWitness(
210
- blockNumber: number,
211
- l2Tol1Message: Fr,
212
- ): Promise<[bigint, SiblingPath<number>]> {
213
- const result = await computeL2ToL1MembershipWitness(this.node, blockNumber, l2Tol1Message);
214
- if (!result) {
215
- throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
216
- }
217
- return [result.leafIndex, result.siblingPath];
218
- }
219
-
220
- public getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
221
- return this.node.getTxReceipt(txHash);
222
- }
223
-
224
- public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
225
- return this.node.getTxEffect(txHash);
226
- }
227
-
228
- public getBlockNumber(): Promise<number> {
229
- return this.node.getBlockNumber();
230
- }
231
-
232
- public getProvenBlockNumber(): Promise<number> {
233
- return this.node.getProvenBlockNumber();
234
- }
235
-
236
- public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
237
- return this.node.getPublicLogs(filter);
238
- }
239
-
240
- public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
241
- return this.node.getContractClassLogs(filter);
242
- }
243
-
244
- public getPublicStorageAt(contract: AztecAddress, slot: Fr) {
245
- return this.node.getPublicStorageAt('latest', contract, slot);
246
- }
247
-
248
- public async getL1ToL2MembershipWitness(
249
- contractAddress: AztecAddress,
250
- messageHash: Fr,
251
- secret: Fr,
252
- ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
253
- return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
186
+ await pxe.#registerProtocolContracts();
187
+ const info = await node.getNodeInfo();
188
+ log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
189
+ return pxe;
254
190
  }
255
191
 
256
192
  // Internal methods
257
193
 
258
194
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
259
- const pxeOracleInterface = new PXEOracleInterface(
260
- ProxiedNodeFactory.create(this.node),
195
+ const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
196
+
197
+ return new ContractFunctionSimulator(
198
+ proxyContractStore,
199
+ this.noteStore,
261
200
  this.keyStore,
262
- ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts),
263
- this.noteDataProvider,
264
- this.capsuleDataProvider,
265
- this.syncDataProvider,
266
- this.taggingDataProvider,
267
- this.addressDataProvider,
268
- this.privateEventDataProvider,
269
- this.log,
201
+ this.addressStore,
202
+ this.node,
203
+ this.anchorBlockStore,
204
+ this.senderTaggingStore,
205
+ this.recipientTaggingStore,
206
+ this.senderAddressBookStore,
207
+ this.capsuleStore,
208
+ this.privateEventStore,
209
+ this.simulator,
270
210
  );
271
- return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
272
211
  }
273
212
 
274
213
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -307,8 +246,8 @@ export class PXEService implements PXE {
307
246
  for (const name of protocolContractNames) {
308
247
  const { address, contractClass, instance, artifact } =
309
248
  await this.protocolContractsProvider.getProtocolContractArtifact(name);
310
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
311
- await this.contractDataProvider.addContractInstance(instance);
249
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
250
+ await this.contractStore.addContractInstance(instance);
312
251
  registered[name] = address.toString();
313
252
  }
314
253
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
@@ -327,30 +266,6 @@ export class PXEService implements PXE {
327
266
  return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
328
267
  }
329
268
 
330
- async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
331
- const contract = await this.contractDataProvider.getContract(to);
332
- if (!contract) {
333
- throw new Error(
334
- `Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
335
- );
336
- }
337
-
338
- const functionDao = contract.functions.find(f => f.name === functionName);
339
- if (!functionDao) {
340
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
341
- }
342
-
343
- return {
344
- name: functionDao.name,
345
- args: encodeArguments(functionDao, args),
346
- selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
347
- type: functionDao.functionType,
348
- to,
349
- isStatic: functionDao.isStatic,
350
- returnTypes: functionDao.returnTypes,
351
- };
352
- }
353
-
354
269
  // Executes the entrypoint private function, as well as all nested private
355
270
  // functions that might arise.
356
271
  async #executePrivate(
@@ -361,11 +276,14 @@ export class PXEService implements PXE {
361
276
  const { origin: contractAddress, functionSelector } = txRequest;
362
277
 
363
278
  try {
279
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
280
+
364
281
  const result = await contractFunctionSimulator.run(
365
282
  txRequest,
366
283
  contractAddress,
367
284
  functionSelector,
368
285
  undefined,
286
+ anchorBlockHeader,
369
287
  // The sender for tags is set by contracts, typically by an account
370
288
  // contract entrypoint
371
289
  undefined, // senderForTags
@@ -375,7 +293,7 @@ export class PXEService implements PXE {
375
293
  return result;
376
294
  } catch (err) {
377
295
  if (err instanceof SimulationError) {
378
- await enrichSimulationError(err, this.contractDataProvider, this.log);
296
+ await enrichSimulationError(err, this.contractStore, this.log);
379
297
  }
380
298
  throw err;
381
299
  }
@@ -397,10 +315,11 @@ export class PXEService implements PXE {
397
315
  scopes?: AztecAddress[],
398
316
  ) {
399
317
  try {
400
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
318
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
319
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
401
320
  } catch (err) {
402
321
  if (err instanceof SimulationError) {
403
- await enrichSimulationError(err, this.contractDataProvider, this.log);
322
+ await enrichSimulationError(err, this.contractStore, this.log);
404
323
  }
405
324
  throw err;
406
325
  }
@@ -424,7 +343,7 @@ export class PXEService implements PXE {
424
343
  } catch (err) {
425
344
  if (err instanceof SimulationError) {
426
345
  try {
427
- await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
346
+ await enrichPublicSimulationError(err, this.contractStore, this.log);
428
347
  } catch (enrichErr) {
429
348
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
430
349
  }
@@ -442,7 +361,7 @@ export class PXEService implements PXE {
442
361
  * @param proofCreator - The proof creator to use for proving the execution.
443
362
  * @param privateExecutionResult - The result of the private execution
444
363
  * @param config - The configuration for the kernel execution prover.
445
- * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled.
364
+ * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
446
365
  */
447
366
  async #prove(
448
367
  txExecutionRequest: TxExecutionRequest,
@@ -450,8 +369,13 @@ export class PXEService implements PXE {
450
369
  privateExecutionResult: PrivateExecutionResult,
451
370
  config: PrivateKernelExecutionProverConfig,
452
371
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
453
- const block = privateExecutionResult.getSimulationBlockNumber();
454
- const kernelOracle = new PrivateKernelOracleImpl(this.contractDataProvider, this.keyStore, this.node, block);
372
+ const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
373
+ const kernelOracle = new PrivateKernelOracleImpl(
374
+ this.contractStore,
375
+ this.keyStore,
376
+ this.node,
377
+ simulationAnchorBlock,
378
+ );
455
379
  const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
456
380
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
457
381
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
@@ -459,24 +383,24 @@ export class PXEService implements PXE {
459
383
 
460
384
  // Public API
461
385
 
462
- /** Returns an estimate of the db size in bytes. */
463
- public async estimateDbSize() {
464
- const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
465
- const dbSizes = await Promise.all([
466
- this.addressDataProvider.getSize(),
467
- this.capsuleDataProvider.getSize(),
468
- this.contractDataProvider.getSize(),
469
- this.noteDataProvider.getSize(),
470
- this.syncDataProvider.getSize(),
471
- this.taggingDataProvider.getSize(),
472
- ]);
473
- return [...dbSizes, treeRootsSize].reduce((sum, size) => sum + size, 0);
474
- }
475
-
476
386
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
477
- return this.contractDataProvider.getContractInstance(address);
387
+ return this.contractStore.getContractInstance(address);
478
388
  }
479
389
 
390
+ /**
391
+ * Returns the contract class metadata given a contract class id.
392
+ * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
393
+ * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
394
+ * @param id - Identifier of the class.
395
+ * @param includeArtifact - Identifier of the class.
396
+ * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
397
+ * for `includeArtifact`
398
+ * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
399
+ * should the pxe query the node for contract public info, and merge it with its own definitions?
400
+ * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
401
+ * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
402
+ * do for the time being.
403
+ */
480
404
  public async getContractClassMetadata(
481
405
  id: Fr,
482
406
  includeArtifact: boolean = false,
@@ -485,7 +409,7 @@ export class PXEService implements PXE {
485
409
  isContractClassPubliclyRegistered: boolean;
486
410
  artifact: ContractArtifact | undefined;
487
411
  }> {
488
- const artifact = await this.contractDataProvider.getContractArtifact(id);
412
+ const artifact = await this.contractStore.getContractArtifact(id);
489
413
  if (!artifact) {
490
414
  this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
491
415
  }
@@ -497,6 +421,17 @@ export class PXEService implements PXE {
497
421
  };
498
422
  }
499
423
 
424
+ /**
425
+ * Returns the contract metadata given an address.
426
+ * The metadata consists of its contract instance, which includes the contract class identifier,
427
+ * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
428
+ * and whether the contract instance with the given address has been publicly deployed.
429
+ * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
430
+ * This query is not dependent on the PXE.
431
+ * @param address - The address that the contract instance resides at.
432
+ * @returns - It returns the contract metadata
433
+ * TODO(@spalladino): Should we return the public keys in plain as well here?
434
+ */
500
435
  public async getContractMetadata(address: AztecAddress): Promise<{
501
436
  contractInstance: ContractInstanceWithAddress | undefined;
502
437
  isContractInitialized: boolean;
@@ -504,7 +439,7 @@ export class PXEService implements PXE {
504
439
  }> {
505
440
  let instance;
506
441
  try {
507
- instance = await this.contractDataProvider.getContractInstance(address);
442
+ instance = await this.contractStore.getContractInstance(address);
508
443
  } catch {
509
444
  this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
510
445
  }
@@ -515,6 +450,16 @@ export class PXEService implements PXE {
515
450
  };
516
451
  }
517
452
 
453
+ /**
454
+ * Registers a user account in PXE given its master encryption private key.
455
+ * Once a new account is registered, the PXE will trial-decrypt all published notes on
456
+ * the chain and store those that correspond to the registered account. Will do nothing if the
457
+ * account is already registered.
458
+ *
459
+ * @param secretKey - Secret key of the corresponding user master public key.
460
+ * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
461
+ * @returns The complete address of the account.
462
+ */
518
463
  public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
519
464
  const accounts = await this.keyStore.getAccounts();
520
465
  const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
@@ -526,46 +471,68 @@ export class PXEService implements PXE {
526
471
  this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
527
472
  }
528
473
 
529
- await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
530
- await this.noteDataProvider.addScope(accountCompleteAddress.address);
474
+ await this.addressStore.addCompleteAddress(accountCompleteAddress);
475
+ await this.noteStore.addScope(accountCompleteAddress.address);
531
476
  return accountCompleteAddress;
532
477
  }
533
478
 
534
- public async registerSender(address: AztecAddress): Promise<AztecAddress> {
479
+ /**
480
+ * Registers a sender in this PXE.
481
+ *
482
+ * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
483
+ * Will do nothing if the address is already registered.
484
+ *
485
+ * @param sender - Address of the sender to register.
486
+ * @returns The address of the sender.
487
+ * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
488
+ */
489
+ public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
535
490
  const accounts = await this.keyStore.getAccounts();
536
- if (accounts.includes(address)) {
537
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
538
- return address;
491
+ if (accounts.includes(sender)) {
492
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
493
+ return sender;
539
494
  }
540
495
 
541
- const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
496
+ const wasAdded = await this.senderAddressBookStore.addSender(sender);
542
497
 
543
498
  if (wasAdded) {
544
- this.log.info(`Added sender:\n ${address.toString()}`);
499
+ this.log.info(`Added sender:\n ${sender.toString()}`);
545
500
  } else {
546
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
501
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
547
502
  }
548
503
 
549
- return address;
504
+ return sender;
550
505
  }
551
506
 
507
+ /**
508
+ * Retrieves senders registered in this PXE.
509
+ * @returns Senders registered in this PXE.
510
+ */
552
511
  public getSenders(): Promise<AztecAddress[]> {
553
- return this.taggingDataProvider.getSenderAddresses();
512
+ return this.senderAddressBookStore.getSenders();
554
513
  }
555
514
 
556
- public async removeSender(address: AztecAddress): Promise<void> {
557
- const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
515
+ /**
516
+ * Removes a sender registered in this PXE.
517
+ * @param sender - The address of the sender to remove.
518
+ */
519
+ public async removeSender(sender: AztecAddress): Promise<void> {
520
+ const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
558
521
 
559
522
  if (wasRemoved) {
560
- this.log.info(`Removed sender:\n ${address.toString()}`);
523
+ this.log.info(`Removed sender:\n ${sender.toString()}`);
561
524
  } else {
562
- this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
525
+ this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
563
526
  }
564
527
  }
565
528
 
529
+ /**
530
+ * Retrieves the user accounts registered on this PXE.
531
+ * @returns An array of the accounts registered on this PXE.
532
+ */
566
533
  public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
567
534
  // Get complete addresses of both the recipients and the accounts
568
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
535
+ const completeAddresses = await this.addressStore.getCompleteAddresses();
569
536
  // Filter out the addresses not corresponding to accounts
570
537
  const accounts = await this.keyStore.getAccounts();
571
538
  return completeAddresses.filter(completeAddress =>
@@ -573,12 +540,25 @@ export class PXEService implements PXE {
573
540
  );
574
541
  }
575
542
 
543
+ /**
544
+ * Registers a contract class in the PXE without registering any associated contract instance with it.
545
+ *
546
+ * @param artifact - The build artifact for the contract class.
547
+ */
576
548
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
577
549
  const { id: contractClassId } = await getContractClassFromArtifact(artifact);
578
- await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
550
+ await this.contractStore.addContractArtifact(contractClassId, artifact);
579
551
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
580
552
  }
581
553
 
554
+ /**
555
+ * Adds deployed contracts to the PXE. Deployed contract information is used to access the
556
+ * contract code when simulating local transactions. This is automatically called by aztec.js when
557
+ * deploying a contract. Dapps that wish to interact with contracts already deployed should register
558
+ * these contracts in their users' PXE through this method.
559
+ *
560
+ * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
561
+ */
582
562
  public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
583
563
  const { instance } = contract;
584
564
  let { artifact } = contract;
@@ -596,7 +576,7 @@ export class PXEService implements PXE {
596
576
  if (!computedAddress.equals(instance.address)) {
597
577
  throw new Error('Added a contract in which the address does not match the contract instance.');
598
578
  }
599
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
579
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
600
580
 
601
581
  const publicFunctionSignatures = artifact.functions
602
582
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -604,7 +584,7 @@ export class PXEService implements PXE {
604
584
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
605
585
  } else {
606
586
  // Otherwise, make sure there is an artifact already registered for that class id
607
- artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
587
+ artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
608
588
  if (!artifact) {
609
589
  throw new Error(
610
590
  `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
@@ -612,24 +592,33 @@ export class PXEService implements PXE {
612
592
  }
613
593
  }
614
594
 
615
- await this.contractDataProvider.addContractInstance(instance);
595
+ await this.contractStore.addContractInstance(instance);
616
596
  this.log.info(
617
597
  `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
618
598
  );
619
599
  }
620
600
 
601
+ /**
602
+ * Updates a deployed contract in the PXE. This is used to update the contract artifact when
603
+ * an update has happened, so the new code can be used in the simulation of local transactions.
604
+ * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
605
+ * @param contractAddress - The address of the contract to update.
606
+ * @param artifact - The updated artifact for the contract.
607
+ * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
608
+ * the current one (current one from the point of view of the node to which the PXE is connected).
609
+ */
621
610
  public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
622
611
  // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
623
612
  // class while we're simulating it.
624
613
  return this.#putInJobQueue(async () => {
625
- const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
614
+ const currentInstance = await this.contractStore.getContractInstance(contractAddress);
626
615
  if (!currentInstance) {
627
616
  throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
628
617
  }
629
618
  const contractClass = await getContractClassFromArtifact(artifact);
630
- await this.synchronizer.sync();
619
+ await this.blockStateSynchronizer.sync();
631
620
 
632
- const header = await this.syncDataProvider.getBlockHeader();
621
+ const header = await this.anchorBlockStore.getBlockHeader();
633
622
 
634
623
  const currentClassId = await readCurrentClassId(
635
624
  contractAddress,
@@ -642,7 +631,7 @@ export class PXEService implements PXE {
642
631
  throw new Error('Could not update contract to a class different from the current one.');
643
632
  }
644
633
 
645
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
634
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
646
635
 
647
636
  const publicFunctionSignatures = artifact.functions
648
637
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -650,72 +639,44 @@ export class PXEService implements PXE {
650
639
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
651
640
 
652
641
  currentInstance.currentContractClassId = contractClass.id;
653
- await this.contractDataProvider.addContractInstance(currentInstance);
642
+ await this.contractStore.addContractInstance(currentInstance);
654
643
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
655
644
  });
656
645
  }
657
646
 
647
+ /**
648
+ * Retrieves the addresses of contracts added to this PXE.
649
+ * @returns An array of contracts addresses registered on this PXE.
650
+ */
658
651
  public getContracts(): Promise<AztecAddress[]> {
659
- return this.contractDataProvider.getContractsAddresses();
652
+ return this.contractStore.getContractsAddresses();
660
653
  }
661
654
 
662
- public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
663
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
664
- await this.simulateUtility('sync_private_state', [], filter.contractAddress);
665
-
666
- const noteDaos = await this.noteDataProvider.getNotes(filter);
667
-
668
- const extendedNotes = noteDaos.map(async dao => {
669
- let recipient = filter.recipient;
670
- if (recipient === undefined) {
671
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
672
- const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
673
- completeAddress.address.equals(dao.recipient),
674
- );
675
- const completeAddress = completeAddresses[completeAddressIndex];
676
- if (completeAddress === undefined) {
677
- throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
678
- }
679
- recipient = completeAddress.address;
680
- }
681
- return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
682
- });
683
- return Promise.all(extendedNotes);
684
- }
685
-
686
- public async getBlock(blockNumber: number): Promise<L2Block | undefined> {
687
- // If a negative block number is provided the current block number is fetched.
688
- if (blockNumber < 0) {
689
- blockNumber = await this.node.getBlockNumber();
690
- }
691
- return await this.node.getBlock(blockNumber);
692
- }
693
-
694
- public async getCurrentBaseFees(): Promise<GasFees> {
695
- return await this.node.getCurrentBaseFees();
696
- }
697
-
698
- public proveTx(
699
- txRequest: TxExecutionRequest,
700
- privateExecutionResult?: PrivateExecutionResult,
701
- ): Promise<TxProvingResult> {
655
+ /**
656
+ * Proves the private portion of a simulated transaction, ready to send to the network
657
+ * (where validators prove the public portion).
658
+ *
659
+ * @param txRequest - An authenticated tx request ready for proving
660
+ * @returns A result containing the proof and public inputs of the tail circuit.
661
+ * @throws If contract code not found, or public simulation reverts.
662
+ * Also throws if simulatePublic is true and public simulation reverts.
663
+ */
664
+ public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
665
+ let privateExecutionResult: PrivateExecutionResult;
702
666
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
703
667
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
704
668
  return this.#putInJobQueue(async () => {
705
669
  const totalTimer = new Timer();
706
670
  try {
707
- let syncTime: number | undefined;
708
- let contractFunctionSimulator: ContractFunctionSimulator | undefined;
709
- if (!privateExecutionResult) {
710
- const syncTimer = new Timer();
711
- await this.synchronizer.sync();
712
- syncTime = syncTimer.ms();
713
- contractFunctionSimulator = this.#getSimulatorForTx();
714
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
715
- }
671
+ const syncTimer = new Timer();
672
+ await this.blockStateSynchronizer.sync();
673
+ const syncTime = syncTimer.ms();
674
+ const contractFunctionSimulator = this.#getSimulatorForTx();
675
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
676
+
716
677
  const {
717
678
  publicInputs,
718
- clientIvcProof,
679
+ chonkProof,
719
680
  executionSteps,
720
681
  timings: { proving } = {},
721
682
  } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
@@ -742,16 +703,46 @@ export class PXEService implements PXE {
742
703
  };
743
704
 
744
705
  this.log.debug(`Proving completed in ${totalTime}ms`, { timings });
745
- return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!, {
706
+
707
+ const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof!, {
746
708
  timings,
747
709
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
748
710
  });
711
+
712
+ // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
713
+ // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
714
+ // transaction before this one is included in a block from this PXE, and that transaction contains a log with
715
+ // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
716
+ // storing the tags here prevents linkage of txs sent from the same PXE.
717
+ const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
718
+ if (preTagsUsedInTheTx.length > 0) {
719
+ // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
720
+ const txHash = (await txProvingResult.toTx()).txHash;
721
+
722
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
723
+ this.log.debug(`Stored used pre-tags as sender for the tx`, {
724
+ preTagsUsedInTheTx,
725
+ });
726
+ } else {
727
+ this.log.debug(`No pre-tags used in the tx`);
728
+ }
729
+
730
+ return txProvingResult;
749
731
  } catch (err: any) {
750
732
  throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
751
733
  }
752
734
  });
753
735
  }
754
736
 
737
+ /**
738
+ * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
739
+ *
740
+ * @param txRequest - An authenticated tx request ready for simulation
741
+ * @param msgSender - (Optional) The message sender to use for the simulation.
742
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
743
+ * @returns A trace of the program execution with gate counts.
744
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
745
+ */
755
746
  public profileTx(
756
747
  txRequest: TxExecutionRequest,
757
748
  profileMode: 'full' | 'execution-steps' | 'gates',
@@ -774,7 +765,7 @@ export class PXEService implements PXE {
774
765
  txInfo,
775
766
  );
776
767
  const syncTimer = new Timer();
777
- await this.synchronizer.sync();
768
+ await this.blockStateSynchronizer.sync();
778
769
  const syncTime = syncTimer.ms();
779
770
 
780
771
  const contractFunctionSimulator = this.#getSimulatorForTx();
@@ -824,7 +815,29 @@ export class PXEService implements PXE {
824
815
  });
825
816
  }
826
817
 
827
- // TODO(#7456) Prevent msgSender being defined here for the first call
818
+ /**
819
+ * Simulates a transaction based on the provided preauthenticated execution request.
820
+ * This will run a local simulation of private execution (and optionally of public as well), run the
821
+ * kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
822
+ * simulation results .
823
+ *
824
+ *
825
+ * Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
826
+ * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
827
+ *
828
+ *
829
+ * @param txRequest - An authenticated tx request ready for simulation
830
+ * @param simulatePublic - Whether to simulate the public part of the transaction.
831
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
832
+ * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
833
+ * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
834
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
835
+ * @returns A simulated transaction result object that includes public and private return values.
836
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
837
+ * Also throws if simulatePublic is true and public simulation reverts.
838
+ *
839
+ * TODO(#7456) Prevent msgSender being defined here for the first call
840
+ */
828
841
  public simulateTx(
829
842
  txRequest: TxExecutionRequest,
830
843
  simulatePublic: boolean,
@@ -852,7 +865,7 @@ export class PXEService implements PXE {
852
865
  txInfo,
853
866
  );
854
867
  const syncTimer = new Timer();
855
- await this.synchronizer.sync();
868
+ await this.blockStateSynchronizer.sync();
856
869
  const syncTime = syncTimer.ms();
857
870
 
858
871
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
@@ -869,15 +882,14 @@ export class PXEService implements PXE {
869
882
 
870
883
  if (skipKernels) {
871
884
  // According to the protocol rules, the nonce generator for the note hashes
872
- // can either be the first nullifier in the tx or the hash of the initial tx request
873
- // if there are none.
885
+ // can either be the first nullifier in the tx or the protocol nullifier if there are none.
874
886
  const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
875
- ? await txRequest.toTxRequest().hash()
887
+ ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
876
888
  : privateExecutionResult.firstNullifier;
877
889
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
878
890
  privateExecutionResult,
879
891
  nonceGenerator,
880
- this.contractDataProvider,
892
+ this.contractStore,
881
893
  ));
882
894
  } else {
883
895
  // Kernel logic, plus proving of all private functions and kernels.
@@ -961,25 +973,18 @@ export class PXEService implements PXE {
961
973
  });
962
974
  }
963
975
 
964
- public async sendTx(tx: Tx): Promise<TxHash> {
965
- const txHash = tx.getTxHash();
966
- if (await this.node.getTxEffect(txHash)) {
967
- throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
968
- }
969
- this.log.debug(`Sending transaction ${txHash}`);
970
- await this.node.sendTx(tx).catch(err => {
971
- throw this.#contextualizeError(err, inspect(tx));
972
- });
973
- this.log.info(`Sent transaction ${txHash}`);
974
- return txHash;
975
- }
976
-
976
+ /**
977
+ * Simulate the execution of a contract utility function.
978
+ *
979
+ * @param call - The function call containing the function details, arguments, and target contract address.
980
+ * @param authwits - (Optional) The authentication witnesses required for the function call.
981
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
982
+ * default to all.
983
+ * @returns The result of the utility function call, structured based on the function ABI.
984
+ */
977
985
  public simulateUtility(
978
- functionName: string,
979
- args: any[],
980
- to: AztecAddress,
986
+ call: FunctionCall,
981
987
  authwits?: AuthWitness[],
982
- _from?: AztecAddress,
983
988
  scopes?: AztecAddress[],
984
989
  ): Promise<UtilitySimulationResult> {
985
990
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
@@ -989,23 +994,21 @@ export class PXEService implements PXE {
989
994
  try {
990
995
  const totalTimer = new Timer();
991
996
  const syncTimer = new Timer();
992
- await this.synchronizer.sync();
997
+ await this.blockStateSynchronizer.sync();
993
998
  const syncTime = syncTimer.ms();
994
- // TODO - Should check if `from` has the permission to call the view function.
995
- const functionCall = await this.#getFunctionCall(functionName, args, to);
996
999
  const functionTimer = new Timer();
997
1000
  const contractFunctionSimulator = this.#getSimulatorForTx();
998
- const executionResult = await this.#simulateUtility(
999
- contractFunctionSimulator,
1000
- functionCall,
1001
- authwits ?? [],
1002
- scopes,
1001
+
1002
+ await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1003
+ this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
1003
1004
  );
1005
+
1006
+ const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
1004
1007
  const functionTime = functionTimer.ms();
1005
1008
 
1006
1009
  const totalTime = totalTimer.ms();
1007
1010
 
1008
- const perFunction = [{ functionName, time: functionTime }];
1011
+ const perFunction = [{ functionName: call.name, time: functionTime }];
1009
1012
 
1010
1013
  const timings: SimulationTimings = {
1011
1014
  total: totalTime,
@@ -1017,118 +1020,54 @@ export class PXEService implements PXE {
1017
1020
  const simulationStats = contractFunctionSimulator.getStats();
1018
1021
  return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1019
1022
  } catch (err: any) {
1023
+ const { to, name, args } = call;
1020
1024
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1021
1025
  throw this.#contextualizeError(
1022
1026
  err,
1023
- `simulateUtility ${to}:${functionName}(${stringifiedArgs})`,
1027
+ `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1024
1028
  `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1025
1029
  );
1026
1030
  }
1027
1031
  });
1028
1032
  }
1029
1033
 
1030
- public async getNodeInfo(): Promise<NodeInfo> {
1031
- // This assumes we're connected to a single node, so we cache the info to avoid repeated calls.
1032
- // Load balancers and a myriad other configurations can break this assumption, so review this!
1033
- // Temporary measure to avoid hammering full nodes with requests on testnet.
1034
- if (!this.#nodeInfo) {
1035
- const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] =
1036
- await Promise.all([
1037
- this.node.getNodeVersion(),
1038
- this.node.getVersion(),
1039
- this.node.getChainId(),
1040
- this.node.getEncodedEnr(),
1041
- this.node.getL1ContractAddresses(),
1042
- this.node.getProtocolContractAddresses(),
1043
- ]);
1044
-
1045
- this.#nodeInfo = {
1046
- nodeVersion,
1047
- l1ChainId: chainId,
1048
- rollupVersion,
1049
- enr,
1050
- l1ContractAddresses: contractAddresses,
1051
- protocolContractAddresses: protocolContractAddresses,
1052
- };
1053
- }
1054
-
1055
- return this.#nodeInfo;
1056
- }
1057
-
1058
- public getPXEInfo(): Promise<PXEInfo> {
1059
- return Promise.resolve({
1060
- pxeVersion: this.packageVersion,
1061
- protocolContractAddresses: {
1062
- classRegistry: ProtocolContractAddress.ContractClassRegistry,
1063
- feeJuice: ProtocolContractAddress.FeeJuice,
1064
- instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
1065
- multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
1066
- },
1067
- });
1068
- }
1069
-
1070
- public async getPrivateEvents<T>(
1071
- contractAddress: AztecAddress,
1072
- eventMetadataDef: EventMetadataDefinition,
1073
- from: number,
1074
- numBlocks: number,
1075
- recipients: AztecAddress[],
1076
- ): Promise<T[]> {
1077
- if (recipients.length === 0) {
1078
- throw new Error('Recipients are required to get private events');
1079
- }
1080
-
1081
- this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
1082
-
1083
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
1084
- await this.simulateUtility('sync_private_state', [], contractAddress);
1034
+ /**
1035
+ * Returns the private events given search parameters.
1036
+ * @param eventSelector - Event selector to search for.
1037
+ * @param filter
1038
+ * contractAddress - The address of the contract to get events from. Required.
1039
+ * scopes - One or more event scope addresses to filter by. Required.
1040
+ * fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
1041
+ * Defaults to 0.
1042
+ * If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
1043
+ * toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
1044
+ * Defaults to the latest known block to PXE + 1.
1045
+ * @returns - The packed events with block and tx metadata.
1046
+ */
1047
+ public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1048
+ return this.#putInJobQueue(async () => {
1049
+ await this.blockStateSynchronizer.sync();
1050
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1085
1051
 
1086
- const events = await this.privateEventDataProvider.getPrivateEvents(
1087
- contractAddress,
1088
- from,
1089
- numBlocks,
1090
- recipients,
1091
- eventMetadataDef.eventSelector,
1092
- );
1052
+ await this.contractStore.syncPrivateState(
1053
+ filter.contractAddress,
1054
+ null,
1055
+ async privateSyncCall => await this.#simulateUtility(contractFunctionSimulator, privateSyncCall),
1056
+ );
1093
1057
 
1094
- const decodedEvents = events.map((event: Fr[]): T => decodeFromAbi([eventMetadataDef.abiType], event) as T);
1058
+ const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1095
1059
 
1096
- return decodedEvents;
1097
- }
1060
+ this.log.debug(
1061
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1062
+ );
1098
1063
 
1099
- async getPublicEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
1100
- const { logs } = await this.node.getPublicLogs({
1101
- fromBlock: from,
1102
- toBlock: from + limit,
1064
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1065
  });
1104
-
1105
- const decodedEvents = logs
1106
- .map(log => {
1107
- // +1 for the event selector
1108
- const expectedLength = eventMetadataDef.fieldNames.length + 1;
1109
- if (log.log.emittedLength !== expectedLength) {
1110
- throw new Error(
1111
- `Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.emittedLength}.`,
1112
- );
1113
- }
1114
-
1115
- const logFields = log.log.getEmittedFields();
1116
- // We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission.
1117
- if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) {
1118
- return undefined;
1119
- }
1120
-
1121
- return decodeFromAbi([eventMetadataDef.abiType], log.log.fields) as T;
1122
- })
1123
- .filter(log => log !== undefined) as T[];
1124
-
1125
- return decodedEvents;
1126
- }
1127
-
1128
- async resetNoteSyncData() {
1129
- return await this.taggingDataProvider.resetNoteSyncData();
1130
1066
  }
1131
1067
 
1068
+ /**
1069
+ * Stops the PXE's job queue.
1070
+ */
1132
1071
  public stop(): Promise<void> {
1133
1072
  return this.jobQueue.end();
1134
1073
  }