@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,146 +1,113 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { SerialQueue } from '@aztec/foundation/queue';
4
4
  import { Timer } from '@aztec/foundation/timer';
5
5
  import { KeyStore } from '@aztec/key-store';
6
6
  import { L2TipsKVStore } from '@aztec/kv-store/stores';
7
- import { ProtocolContractAddress, protocolContractNames } from '@aztec/protocol-contracts';
8
- import { EventSelector, FunctionSelector, FunctionType, decodeFromAbi, decodeFunctionSignature, encodeArguments } from '@aztec/stdlib/abi';
7
+ import { protocolContractNames } from '@aztec/protocol-contracts';
8
+ import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
9
9
  import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
10
10
  import { SimulationError } from '@aztec/stdlib/errors';
11
- import { siloNullifier } from '@aztec/stdlib/hash';
12
- import { computeL2ToL1MembershipWitness, getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
13
- import { UniqueNote } from '@aztec/stdlib/note';
14
- import { MerkleTreeId } from '@aztec/stdlib/trees';
11
+ import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
15
12
  import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
16
13
  import { inspect } from 'util';
17
- import { getPackageInfo } from '../config/package_info.js';
18
- import { ContractFunctionSimulator, generateSimulatedProvingResult } from '../contract_function_simulator/contract_function_simulator.js';
19
- import { readCurrentClassId } from '../contract_function_simulator/oracle/private_execution.js';
20
- import { ProxiedContractDataProviderFactory } from '../contract_function_simulator/proxied_contract_data_source.js';
21
- import { ProxiedNodeFactory } from '../contract_function_simulator/proxied_node.js';
22
- import { PXEOracleInterface } from '../contract_function_simulator/pxe_oracle_interface.js';
23
- import { PrivateKernelExecutionProver } from '../private_kernel/private_kernel_execution_prover.js';
24
- import { PrivateKernelOracleImpl } from '../private_kernel/private_kernel_oracle_impl.js';
25
- import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
26
- import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
27
- import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
28
- import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
29
- import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
30
- import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
31
- import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
32
- import { Synchronizer } from '../synchronizer/index.js';
14
+ import { BlockSynchronizer } from './block_synchronizer/index.js';
15
+ import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
16
+ import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
17
+ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
18
+ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
33
19
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
20
+ import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
21
+ import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
22
+ import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
23
+ import { AddressStore } from './storage/address_store/address_store.js';
24
+ import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
25
+ import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
26
+ import { ContractStore } from './storage/contract_store/contract_store.js';
27
+ import { NoteStore } from './storage/note_store/note_store.js';
28
+ import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
29
+ import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
30
+ import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
31
+ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
34
32
  /**
35
- * A Private eXecution Environment (PXE) implementation.
36
- */ export class PXEService {
33
+ * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
34
+ * manage private state of users.
35
+ */ export class PXE {
37
36
  node;
38
- synchronizer;
37
+ blockStateSynchronizer;
39
38
  keyStore;
40
- contractDataProvider;
41
- noteDataProvider;
42
- capsuleDataProvider;
43
- syncDataProvider;
44
- taggingDataProvider;
45
- addressDataProvider;
46
- privateEventDataProvider;
39
+ contractStore;
40
+ noteStore;
41
+ capsuleStore;
42
+ anchorBlockStore;
43
+ senderTaggingStore;
44
+ senderAddressBookStore;
45
+ recipientTaggingStore;
46
+ addressStore;
47
+ privateEventStore;
47
48
  simulator;
48
- packageVersion;
49
49
  proverEnabled;
50
50
  proofCreator;
51
51
  protocolContractsProvider;
52
52
  log;
53
53
  jobQueue;
54
- #nodeInfo;
55
- constructor(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, packageVersion, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue){
54
+ debug;
55
+ constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, debug){
56
56
  this.node = node;
57
- this.synchronizer = synchronizer;
57
+ this.blockStateSynchronizer = blockStateSynchronizer;
58
58
  this.keyStore = keyStore;
59
- this.contractDataProvider = contractDataProvider;
60
- this.noteDataProvider = noteDataProvider;
61
- this.capsuleDataProvider = capsuleDataProvider;
62
- this.syncDataProvider = syncDataProvider;
63
- this.taggingDataProvider = taggingDataProvider;
64
- this.addressDataProvider = addressDataProvider;
65
- this.privateEventDataProvider = privateEventDataProvider;
59
+ this.contractStore = contractStore;
60
+ this.noteStore = noteStore;
61
+ this.capsuleStore = capsuleStore;
62
+ this.anchorBlockStore = anchorBlockStore;
63
+ this.senderTaggingStore = senderTaggingStore;
64
+ this.senderAddressBookStore = senderAddressBookStore;
65
+ this.recipientTaggingStore = recipientTaggingStore;
66
+ this.addressStore = addressStore;
67
+ this.privateEventStore = privateEventStore;
66
68
  this.simulator = simulator;
67
- this.packageVersion = packageVersion;
68
69
  this.proverEnabled = proverEnabled;
69
70
  this.proofCreator = proofCreator;
70
71
  this.protocolContractsProvider = protocolContractsProvider;
71
72
  this.log = log;
72
73
  this.jobQueue = jobQueue;
74
+ this.debug = debug;
73
75
  }
74
76
  /**
75
- * Creates an instance of a PXE Service by instantiating all the necessary data providers and services.
77
+ * Creates an instance of a PXE by instantiating all the necessary data providers and services.
76
78
  * Also triggers the registration of the protocol contracts and makes sure the provided node
77
79
  * can be contacted.
78
80
  *
79
- * @returns A promise that resolves PXE service is ready to be used.
81
+ * @returns A promise that resolves PXE is ready to be used.
80
82
  */ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
81
83
  const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
82
- const packageVersion = getPackageInfo().version;
83
84
  const proverEnabled = !!config.proverEnabled;
84
- const addressDataProvider = new AddressDataProvider(store);
85
- const privateEventDataProvider = new PrivateEventDataProvider(store);
86
- const contractDataProvider = new ContractDataProvider(store);
87
- const noteDataProvider = await NoteDataProvider.create(store);
88
- const syncDataProvider = new SyncDataProvider(store);
89
- const taggingDataProvider = new TaggingDataProvider(store);
90
- const capsuleDataProvider = new CapsuleDataProvider(store);
85
+ const addressStore = new AddressStore(store);
86
+ const privateEventStore = new PrivateEventStore(store);
87
+ const contractStore = new ContractStore(store);
88
+ const noteStore = await NoteStore.create(store);
89
+ const anchorBlockStore = new AnchorBlockStore(store);
90
+ const senderTaggingStore = new SenderTaggingStore(store);
91
+ const senderAddressBookStore = new SenderAddressBookStore(store);
92
+ const recipientTaggingStore = new RecipientTaggingStore(store);
93
+ const capsuleStore = new CapsuleStore(store);
91
94
  const keyStore = new KeyStore(store);
92
95
  const tipsStore = new L2TipsKVStore(store, 'pxe');
93
- const synchronizer = new Synchronizer(node, syncDataProvider, noteDataProvider, taggingDataProvider, tipsStore, config, loggerOrSuffix);
96
+ const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, loggerOrSuffix);
97
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore);
94
98
  const jobQueue = new SerialQueue();
95
- const pxeService = new PXEService(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, packageVersion, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue);
96
- pxeService.jobQueue.start();
97
- await pxeService.#registerProtocolContracts();
98
- const info = await pxeService.getNodeInfo();
99
+ const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, debugUtils);
100
+ debugUtils.setPXE(pxe);
101
+ pxe.jobQueue.start();
102
+ await pxe.#registerProtocolContracts();
103
+ const info = await node.getNodeInfo();
99
104
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
100
- return pxeService;
101
- }
102
- // Aztec node proxy methods
103
- isL1ToL2MessageSynced(l1ToL2Message) {
104
- return this.node.isL1ToL2MessageSynced(l1ToL2Message);
105
- }
106
- async getL2ToL1MembershipWitness(blockNumber, l2Tol1Message) {
107
- const result = await computeL2ToL1MembershipWitness(this.node, blockNumber, l2Tol1Message);
108
- if (!result) {
109
- throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
110
- }
111
- return [
112
- result.leafIndex,
113
- result.siblingPath
114
- ];
115
- }
116
- getTxReceipt(txHash) {
117
- return this.node.getTxReceipt(txHash);
118
- }
119
- getTxEffect(txHash) {
120
- return this.node.getTxEffect(txHash);
121
- }
122
- getBlockNumber() {
123
- return this.node.getBlockNumber();
124
- }
125
- getProvenBlockNumber() {
126
- return this.node.getProvenBlockNumber();
127
- }
128
- getPublicLogs(filter) {
129
- return this.node.getPublicLogs(filter);
130
- }
131
- getContractClassLogs(filter) {
132
- return this.node.getContractClassLogs(filter);
133
- }
134
- getPublicStorageAt(contract, slot) {
135
- return this.node.getPublicStorageAt('latest', contract, slot);
136
- }
137
- async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
138
- return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
105
+ return pxe;
139
106
  }
140
107
  // Internal methods
141
108
  #getSimulatorForTx(overrides) {
142
- const pxeOracleInterface = new PXEOracleInterface(ProxiedNodeFactory.create(this.node), this.keyStore, ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts), this.noteDataProvider, this.capsuleDataProvider, this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, this.privateEventDataProvider, this.log);
143
- return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
109
+ const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
110
+ return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, this.node, this.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
144
111
  }
145
112
  #contextualizeError(err, ...context) {
146
113
  let contextStr = '';
@@ -171,8 +138,8 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
171
138
  const registered = {};
172
139
  for (const name of protocolContractNames){
173
140
  const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
174
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
175
- await this.contractDataProvider.addContractInstance(instance);
141
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
142
+ await this.contractStore.addContractInstance(instance);
176
143
  registered[name] = address.toString();
177
144
  }
178
145
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
@@ -187,38 +154,20 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
187
154
  const initNullifier = await siloNullifier(address, address.toField());
188
155
  return !!await this.node.getNullifierMembershipWitness('latest', initNullifier);
189
156
  }
190
- async #getFunctionCall(functionName, args, to) {
191
- const contract = await this.contractDataProvider.getContract(to);
192
- if (!contract) {
193
- throw new Error(`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`);
194
- }
195
- const functionDao = contract.functions.find((f)=>f.name === functionName);
196
- if (!functionDao) {
197
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
198
- }
199
- return {
200
- name: functionDao.name,
201
- args: encodeArguments(functionDao, args),
202
- selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
203
- type: functionDao.functionType,
204
- to,
205
- isStatic: functionDao.isStatic,
206
- returnTypes: functionDao.returnTypes
207
- };
208
- }
209
157
  // Executes the entrypoint private function, as well as all nested private
210
158
  // functions that might arise.
211
159
  async #executePrivate(contractFunctionSimulator, txRequest, scopes) {
212
160
  const { origin: contractAddress, functionSelector } = txRequest;
213
161
  try {
214
- const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, // The sender for tags is set by contracts, typically by an account
162
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
163
+ const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
215
164
  // contract entrypoint
216
165
  undefined, scopes);
217
166
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
218
167
  return result;
219
168
  } catch (err) {
220
169
  if (err instanceof SimulationError) {
221
- await enrichSimulationError(err, this.contractDataProvider, this.log);
170
+ await enrichSimulationError(err, this.contractStore, this.log);
222
171
  }
223
172
  throw err;
224
173
  }
@@ -233,10 +182,11 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
233
182
  * @returns The simulation result containing the outputs of the utility function.
234
183
  */ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes) {
235
184
  try {
236
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
185
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
186
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
237
187
  } catch (err) {
238
188
  if (err instanceof SimulationError) {
239
- await enrichSimulationError(err, this.contractDataProvider, this.log);
189
+ await enrichSimulationError(err, this.contractStore, this.log);
240
190
  }
241
191
  throw err;
242
192
  }
@@ -258,7 +208,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
258
208
  } catch (err) {
259
209
  if (err instanceof SimulationError) {
260
210
  try {
261
- await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
211
+ await enrichPublicSimulationError(err, this.contractStore, this.log);
262
212
  } catch (enrichErr) {
263
213
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
264
214
  }
@@ -275,35 +225,33 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
275
225
  * @param proofCreator - The proof creator to use for proving the execution.
276
226
  * @param privateExecutionResult - The result of the private execution
277
227
  * @param config - The configuration for the kernel execution prover.
278
- * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled.
228
+ * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
279
229
  */ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
280
- const block = privateExecutionResult.getSimulationBlockNumber();
281
- const kernelOracle = new PrivateKernelOracleImpl(this.contractDataProvider, this.keyStore, this.node, block);
230
+ const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
231
+ const kernelOracle = new PrivateKernelOracleImpl(this.contractStore, this.keyStore, this.node, simulationAnchorBlock);
282
232
  const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
283
233
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
284
234
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
285
235
  }
286
236
  // Public API
287
- /** Returns an estimate of the db size in bytes. */ async estimateDbSize() {
288
- const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
289
- const dbSizes = await Promise.all([
290
- this.addressDataProvider.getSize(),
291
- this.capsuleDataProvider.getSize(),
292
- this.contractDataProvider.getSize(),
293
- this.noteDataProvider.getSize(),
294
- this.syncDataProvider.getSize(),
295
- this.taggingDataProvider.getSize()
296
- ]);
297
- return [
298
- ...dbSizes,
299
- treeRootsSize
300
- ].reduce((sum, size)=>sum + size, 0);
301
- }
302
237
  getContractInstance(address) {
303
- return this.contractDataProvider.getContractInstance(address);
238
+ return this.contractStore.getContractInstance(address);
304
239
  }
305
- async getContractClassMetadata(id, includeArtifact = false) {
306
- const artifact = await this.contractDataProvider.getContractArtifact(id);
240
+ /**
241
+ * Returns the contract class metadata given a contract class id.
242
+ * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
243
+ * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
244
+ * @param id - Identifier of the class.
245
+ * @param includeArtifact - Identifier of the class.
246
+ * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
247
+ * for `includeArtifact`
248
+ * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
249
+ * should the pxe query the node for contract public info, and merge it with its own definitions?
250
+ * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
251
+ * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
252
+ * do for the time being.
253
+ */ async getContractClassMetadata(id, includeArtifact = false) {
254
+ const artifact = await this.contractStore.getContractArtifact(id);
307
255
  if (!artifact) {
308
256
  this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
309
257
  }
@@ -313,10 +261,20 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
313
261
  artifact: includeArtifact ? artifact : undefined
314
262
  };
315
263
  }
316
- async getContractMetadata(address) {
264
+ /**
265
+ * Returns the contract metadata given an address.
266
+ * The metadata consists of its contract instance, which includes the contract class identifier,
267
+ * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
268
+ * and whether the contract instance with the given address has been publicly deployed.
269
+ * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
270
+ * This query is not dependent on the PXE.
271
+ * @param address - The address that the contract instance resides at.
272
+ * @returns - It returns the contract metadata
273
+ * TODO(@spalladino): Should we return the public keys in plain as well here?
274
+ */ async getContractMetadata(address) {
317
275
  let instance;
318
276
  try {
319
- instance = await this.contractDataProvider.getContractInstance(address);
277
+ instance = await this.contractStore.getContractInstance(address);
320
278
  } catch {
321
279
  this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
322
280
  }
@@ -326,7 +284,16 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
326
284
  isContractPublished: await this.#isContractPublished(address)
327
285
  };
328
286
  }
329
- async registerAccount(secretKey, partialAddress) {
287
+ /**
288
+ * Registers a user account in PXE given its master encryption private key.
289
+ * Once a new account is registered, the PXE will trial-decrypt all published notes on
290
+ * the chain and store those that correspond to the registered account. Will do nothing if the
291
+ * account is already registered.
292
+ *
293
+ * @param secretKey - Secret key of the corresponding user master public key.
294
+ * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
295
+ * @returns The complete address of the account.
296
+ */ async registerAccount(secretKey, partialAddress) {
330
297
  const accounts = await this.keyStore.getAccounts();
331
298
  const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
332
299
  if (accounts.includes(accountCompleteAddress.address)) {
@@ -336,48 +303,77 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
336
303
  this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
337
304
  this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
338
305
  }
339
- await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
340
- await this.noteDataProvider.addScope(accountCompleteAddress.address);
306
+ await this.addressStore.addCompleteAddress(accountCompleteAddress);
307
+ await this.noteStore.addScope(accountCompleteAddress.address);
341
308
  return accountCompleteAddress;
342
309
  }
343
- async registerSender(address) {
310
+ /**
311
+ * Registers a sender in this PXE.
312
+ *
313
+ * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
314
+ * Will do nothing if the address is already registered.
315
+ *
316
+ * @param sender - Address of the sender to register.
317
+ * @returns The address of the sender.
318
+ * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
319
+ */ async registerSender(sender) {
344
320
  const accounts = await this.keyStore.getAccounts();
345
- if (accounts.includes(address)) {
346
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
347
- return address;
321
+ if (accounts.includes(sender)) {
322
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
323
+ return sender;
348
324
  }
349
- const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
325
+ const wasAdded = await this.senderAddressBookStore.addSender(sender);
350
326
  if (wasAdded) {
351
- this.log.info(`Added sender:\n ${address.toString()}`);
327
+ this.log.info(`Added sender:\n ${sender.toString()}`);
352
328
  } else {
353
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
329
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
354
330
  }
355
- return address;
331
+ return sender;
356
332
  }
357
- getSenders() {
358
- return this.taggingDataProvider.getSenderAddresses();
333
+ /**
334
+ * Retrieves senders registered in this PXE.
335
+ * @returns Senders registered in this PXE.
336
+ */ getSenders() {
337
+ return this.senderAddressBookStore.getSenders();
359
338
  }
360
- async removeSender(address) {
361
- const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
339
+ /**
340
+ * Removes a sender registered in this PXE.
341
+ * @param sender - The address of the sender to remove.
342
+ */ async removeSender(sender) {
343
+ const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
362
344
  if (wasRemoved) {
363
- this.log.info(`Removed sender:\n ${address.toString()}`);
345
+ this.log.info(`Removed sender:\n ${sender.toString()}`);
364
346
  } else {
365
- this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
347
+ this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
366
348
  }
367
349
  }
368
- async getRegisteredAccounts() {
350
+ /**
351
+ * Retrieves the user accounts registered on this PXE.
352
+ * @returns An array of the accounts registered on this PXE.
353
+ */ async getRegisteredAccounts() {
369
354
  // Get complete addresses of both the recipients and the accounts
370
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
355
+ const completeAddresses = await this.addressStore.getCompleteAddresses();
371
356
  // Filter out the addresses not corresponding to accounts
372
357
  const accounts = await this.keyStore.getAccounts();
373
358
  return completeAddresses.filter((completeAddress)=>accounts.find((address)=>address.equals(completeAddress.address)));
374
359
  }
375
- async registerContractClass(artifact) {
360
+ /**
361
+ * Registers a contract class in the PXE without registering any associated contract instance with it.
362
+ *
363
+ * @param artifact - The build artifact for the contract class.
364
+ */ async registerContractClass(artifact) {
376
365
  const { id: contractClassId } = await getContractClassFromArtifact(artifact);
377
- await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
366
+ await this.contractStore.addContractArtifact(contractClassId, artifact);
378
367
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
379
368
  }
380
- async registerContract(contract) {
369
+ /**
370
+ * Adds deployed contracts to the PXE. Deployed contract information is used to access the
371
+ * contract code when simulating local transactions. This is automatically called by aztec.js when
372
+ * deploying a contract. Dapps that wish to interact with contracts already deployed should register
373
+ * these contracts in their users' PXE through this method.
374
+ *
375
+ * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
376
+ */ async registerContract(contract) {
381
377
  const { instance } = contract;
382
378
  let { artifact } = contract;
383
379
  if (artifact) {
@@ -391,90 +387,77 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
391
387
  if (!computedAddress.equals(instance.address)) {
392
388
  throw new Error('Added a contract in which the address does not match the contract instance.');
393
389
  }
394
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
390
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
395
391
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
396
392
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
397
393
  } else {
398
394
  // Otherwise, make sure there is an artifact already registered for that class id
399
- artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
395
+ artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
400
396
  if (!artifact) {
401
397
  throw new Error(`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`);
402
398
  }
403
399
  }
404
- await this.contractDataProvider.addContractInstance(instance);
400
+ await this.contractStore.addContractInstance(instance);
405
401
  this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`);
406
402
  }
407
- updateContract(contractAddress, artifact) {
403
+ /**
404
+ * Updates a deployed contract in the PXE. This is used to update the contract artifact when
405
+ * an update has happened, so the new code can be used in the simulation of local transactions.
406
+ * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
407
+ * @param contractAddress - The address of the contract to update.
408
+ * @param artifact - The updated artifact for the contract.
409
+ * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
410
+ * the current one (current one from the point of view of the node to which the PXE is connected).
411
+ */ updateContract(contractAddress, artifact) {
408
412
  // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
409
413
  // class while we're simulating it.
410
414
  return this.#putInJobQueue(async ()=>{
411
- const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
415
+ const currentInstance = await this.contractStore.getContractInstance(contractAddress);
412
416
  if (!currentInstance) {
413
417
  throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
414
418
  }
415
419
  const contractClass = await getContractClassFromArtifact(artifact);
416
- await this.synchronizer.sync();
417
- const header = await this.syncDataProvider.getBlockHeader();
420
+ await this.blockStateSynchronizer.sync();
421
+ const header = await this.anchorBlockStore.getBlockHeader();
418
422
  const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header.globalVariables.blockNumber, header.globalVariables.timestamp);
419
423
  if (!contractClass.id.equals(currentClassId)) {
420
424
  throw new Error('Could not update contract to a class different from the current one.');
421
425
  }
422
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
426
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
423
427
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
424
428
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
425
429
  currentInstance.currentContractClassId = contractClass.id;
426
- await this.contractDataProvider.addContractInstance(currentInstance);
430
+ await this.contractStore.addContractInstance(currentInstance);
427
431
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
428
432
  });
429
433
  }
430
- getContracts() {
431
- return this.contractDataProvider.getContractsAddresses();
432
- }
433
- async getNotes(filter) {
434
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
435
- await this.simulateUtility('sync_private_state', [], filter.contractAddress);
436
- const noteDaos = await this.noteDataProvider.getNotes(filter);
437
- const extendedNotes = noteDaos.map(async (dao)=>{
438
- let recipient = filter.recipient;
439
- if (recipient === undefined) {
440
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
441
- const completeAddressIndex = completeAddresses.findIndex((completeAddress)=>completeAddress.address.equals(dao.recipient));
442
- const completeAddress = completeAddresses[completeAddressIndex];
443
- if (completeAddress === undefined) {
444
- throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
445
- }
446
- recipient = completeAddress.address;
447
- }
448
- return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
449
- });
450
- return Promise.all(extendedNotes);
451
- }
452
- async getBlock(blockNumber) {
453
- // If a negative block number is provided the current block number is fetched.
454
- if (blockNumber < 0) {
455
- blockNumber = await this.node.getBlockNumber();
456
- }
457
- return await this.node.getBlock(blockNumber);
458
- }
459
- async getCurrentBaseFees() {
460
- return await this.node.getCurrentBaseFees();
434
+ /**
435
+ * Retrieves the addresses of contracts added to this PXE.
436
+ * @returns An array of contracts addresses registered on this PXE.
437
+ */ getContracts() {
438
+ return this.contractStore.getContractsAddresses();
461
439
  }
462
- proveTx(txRequest, privateExecutionResult) {
440
+ /**
441
+ * Proves the private portion of a simulated transaction, ready to send to the network
442
+ * (where validators prove the public portion).
443
+ *
444
+ * @param txRequest - An authenticated tx request ready for proving
445
+ * @returns A result containing the proof and public inputs of the tail circuit.
446
+ * @throws If contract code not found, or public simulation reverts.
447
+ * Also throws if simulatePublic is true and public simulation reverts.
448
+ */ proveTx(txRequest) {
449
+ let privateExecutionResult;
463
450
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
464
451
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
465
452
  return this.#putInJobQueue(async ()=>{
466
453
  const totalTimer = new Timer();
467
454
  try {
468
- let syncTime;
469
- let contractFunctionSimulator;
470
- if (!privateExecutionResult) {
471
- const syncTimer = new Timer();
472
- await this.synchronizer.sync();
473
- syncTime = syncTimer.ms();
474
- contractFunctionSimulator = this.#getSimulatorForTx();
475
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
476
- }
477
- const { publicInputs, clientIvcProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
455
+ const syncTimer = new Timer();
456
+ await this.blockStateSynchronizer.sync();
457
+ const syncTime = syncTimer.ms();
458
+ const contractFunctionSimulator = this.#getSimulatorForTx();
459
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
460
+ const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
478
461
  simulate: false,
479
462
  skipFeeEnforcement: false,
480
463
  profileMode: 'none'
@@ -495,16 +478,41 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
495
478
  this.log.debug(`Proving completed in ${totalTime}ms`, {
496
479
  timings
497
480
  });
498
- return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof, {
481
+ const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof, {
499
482
  timings,
500
483
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
501
484
  });
485
+ // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
486
+ // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
487
+ // transaction before this one is included in a block from this PXE, and that transaction contains a log with
488
+ // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
489
+ // storing the tags here prevents linkage of txs sent from the same PXE.
490
+ const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
491
+ if (preTagsUsedInTheTx.length > 0) {
492
+ // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
493
+ const txHash = (await txProvingResult.toTx()).txHash;
494
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
495
+ this.log.debug(`Stored used pre-tags as sender for the tx`, {
496
+ preTagsUsedInTheTx
497
+ });
498
+ } else {
499
+ this.log.debug(`No pre-tags used in the tx`);
500
+ }
501
+ return txProvingResult;
502
502
  } catch (err) {
503
503
  throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
504
504
  }
505
505
  });
506
506
  }
507
- profileTx(txRequest, profileMode, skipProofGeneration = true) {
507
+ /**
508
+ * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
509
+ *
510
+ * @param txRequest - An authenticated tx request ready for simulation
511
+ * @param msgSender - (Optional) The message sender to use for the simulation.
512
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
513
+ * @returns A trace of the program execution with gate counts.
514
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
515
+ */ profileTx(txRequest, profileMode, skipProofGeneration = true) {
508
516
  // We disable concurrent profiles for consistency with simulateTx.
509
517
  return this.#putInJobQueue(async ()=>{
510
518
  const totalTimer = new Timer();
@@ -519,7 +527,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
519
527
  };
520
528
  this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
521
529
  const syncTimer = new Timer();
522
- await this.synchronizer.sync();
530
+ await this.blockStateSynchronizer.sync();
523
531
  const syncTime = syncTimer.ms();
524
532
  const contractFunctionSimulator = this.#getSimulatorForTx();
525
533
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
@@ -556,8 +564,29 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
556
564
  }
557
565
  });
558
566
  }
559
- // TODO(#7456) Prevent msgSender being defined here for the first call
560
- simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
567
+ /**
568
+ * Simulates a transaction based on the provided preauthenticated execution request.
569
+ * This will run a local simulation of private execution (and optionally of public as well), run the
570
+ * kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
571
+ * simulation results .
572
+ *
573
+ *
574
+ * Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
575
+ * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
576
+ *
577
+ *
578
+ * @param txRequest - An authenticated tx request ready for simulation
579
+ * @param simulatePublic - Whether to simulate the public part of the transaction.
580
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
581
+ * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
582
+ * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
583
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
584
+ * @returns A simulated transaction result object that includes public and private return values.
585
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
586
+ * Also throws if simulatePublic is true and public simulation reverts.
587
+ *
588
+ * TODO(#7456) Prevent msgSender being defined here for the first call
589
+ */ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
561
590
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
562
591
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
563
592
  // delete the same read value, or reading values that another simulation is currently modifying).
@@ -574,7 +603,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
574
603
  };
575
604
  this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
576
605
  const syncTimer = new Timer();
577
- await this.synchronizer.sync();
606
+ await this.blockStateSynchronizer.sync();
578
607
  const syncTime = syncTimer.ms();
579
608
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
580
609
  // Temporary: in case there are overrides, we have to skip the kernels or validations
@@ -587,10 +616,9 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
587
616
  let executionSteps = [];
588
617
  if (skipKernels) {
589
618
  // According to the protocol rules, the nonce generator for the note hashes
590
- // can either be the first nullifier in the tx or the hash of the initial tx request
591
- // if there are none.
592
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO) ? await txRequest.toTxRequest().hash() : privateExecutionResult.firstNullifier;
593
- ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractDataProvider));
619
+ // can either be the first nullifier in the tx or the protocol nullifier if there are none.
620
+ const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO) ? await computeProtocolNullifier(await txRequest.toTxRequest().hash()) : privateExecutionResult.firstNullifier;
621
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractStore));
594
622
  } else {
595
623
  // Kernel logic, plus proving of all private functions and kernels.
596
624
  ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
@@ -654,19 +682,15 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
654
682
  }
655
683
  });
656
684
  }
657
- async sendTx(tx) {
658
- const txHash = tx.getTxHash();
659
- if (await this.node.getTxEffect(txHash)) {
660
- throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
661
- }
662
- this.log.debug(`Sending transaction ${txHash}`);
663
- await this.node.sendTx(tx).catch((err)=>{
664
- throw this.#contextualizeError(err, inspect(tx));
665
- });
666
- this.log.info(`Sent transaction ${txHash}`);
667
- return txHash;
668
- }
669
- simulateUtility(functionName, args, to, authwits, _from, scopes) {
685
+ /**
686
+ * Simulate the execution of a contract utility function.
687
+ *
688
+ * @param call - The function call containing the function details, arguments, and target contract address.
689
+ * @param authwits - (Optional) The authentication witnesses required for the function call.
690
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
691
+ * default to all.
692
+ * @returns The result of the utility function call, structured based on the function ABI.
693
+ */ simulateUtility(call, authwits, scopes) {
670
694
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
671
695
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
672
696
  // delete the same read value, or reading values that another simulation is currently modifying).
@@ -674,18 +698,17 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
674
698
  try {
675
699
  const totalTimer = new Timer();
676
700
  const syncTimer = new Timer();
677
- await this.synchronizer.sync();
701
+ await this.blockStateSynchronizer.sync();
678
702
  const syncTime = syncTimer.ms();
679
- // TODO - Should check if `from` has the permission to call the view function.
680
- const functionCall = await this.#getFunctionCall(functionName, args, to);
681
703
  const functionTimer = new Timer();
682
704
  const contractFunctionSimulator = this.#getSimulatorForTx();
683
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, functionCall, authwits ?? [], scopes);
705
+ await this.contractStore.syncPrivateState(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall));
706
+ const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
684
707
  const functionTime = functionTimer.ms();
685
708
  const totalTime = totalTimer.ms();
686
709
  const perFunction = [
687
710
  {
688
- functionName,
711
+ functionName: call.name,
689
712
  time: functionTime
690
713
  }
691
714
  ];
@@ -704,85 +727,37 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
704
727
  }
705
728
  };
706
729
  } catch (err) {
730
+ const { to, name, args } = call;
707
731
  const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
708
- throw this.#contextualizeError(err, `simulateUtility ${to}:${functionName}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
732
+ throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
709
733
  }
710
734
  });
711
735
  }
712
- async getNodeInfo() {
713
- // This assumes we're connected to a single node, so we cache the info to avoid repeated calls.
714
- // Load balancers and a myriad other configurations can break this assumption, so review this!
715
- // Temporary measure to avoid hammering full nodes with requests on testnet.
716
- if (!this.#nodeInfo) {
717
- const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
718
- this.node.getNodeVersion(),
719
- this.node.getVersion(),
720
- this.node.getChainId(),
721
- this.node.getEncodedEnr(),
722
- this.node.getL1ContractAddresses(),
723
- this.node.getProtocolContractAddresses()
724
- ]);
725
- this.#nodeInfo = {
726
- nodeVersion,
727
- l1ChainId: chainId,
728
- rollupVersion,
729
- enr,
730
- l1ContractAddresses: contractAddresses,
731
- protocolContractAddresses: protocolContractAddresses
732
- };
733
- }
734
- return this.#nodeInfo;
735
- }
736
- getPXEInfo() {
737
- return Promise.resolve({
738
- pxeVersion: this.packageVersion,
739
- protocolContractAddresses: {
740
- classRegistry: ProtocolContractAddress.ContractClassRegistry,
741
- feeJuice: ProtocolContractAddress.FeeJuice,
742
- instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
743
- multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint
744
- }
745
- });
746
- }
747
- async getPrivateEvents(contractAddress, eventMetadataDef, from, numBlocks, recipients) {
748
- if (recipients.length === 0) {
749
- throw new Error('Recipients are required to get private events');
750
- }
751
- this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
752
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
753
- await this.simulateUtility('sync_private_state', [], contractAddress);
754
- const events = await this.privateEventDataProvider.getPrivateEvents(contractAddress, from, numBlocks, recipients, eventMetadataDef.eventSelector);
755
- const decodedEvents = events.map((event)=>decodeFromAbi([
756
- eventMetadataDef.abiType
757
- ], event));
758
- return decodedEvents;
759
- }
760
- async getPublicEvents(eventMetadataDef, from, limit) {
761
- const { logs } = await this.node.getPublicLogs({
762
- fromBlock: from,
763
- toBlock: from + limit
736
+ /**
737
+ * Returns the private events given search parameters.
738
+ * @param eventSelector - Event selector to search for.
739
+ * @param filter
740
+ * contractAddress - The address of the contract to get events from. Required.
741
+ * scopes - One or more event scope addresses to filter by. Required.
742
+ * fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
743
+ * Defaults to 0.
744
+ * If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
745
+ * toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
746
+ * Defaults to the latest known block to PXE + 1.
747
+ * @returns - The packed events with block and tx metadata.
748
+ */ getPrivateEvents(eventSelector, filter) {
749
+ return this.#putInJobQueue(async ()=>{
750
+ await this.blockStateSynchronizer.sync();
751
+ const contractFunctionSimulator = this.#getSimulatorForTx();
752
+ await this.contractStore.syncPrivateState(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall));
753
+ const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
754
+ this.log.debug(`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`);
755
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
764
756
  });
765
- const decodedEvents = logs.map((log)=>{
766
- // +1 for the event selector
767
- const expectedLength = eventMetadataDef.fieldNames.length + 1;
768
- if (log.log.emittedLength !== expectedLength) {
769
- throw new Error(`Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.emittedLength}.`);
770
- }
771
- const logFields = log.log.getEmittedFields();
772
- // 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.
773
- if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) {
774
- return undefined;
775
- }
776
- return decodeFromAbi([
777
- eventMetadataDef.abiType
778
- ], log.log.fields);
779
- }).filter((log)=>log !== undefined);
780
- return decodedEvents;
781
757
  }
782
- async resetNoteSyncData() {
783
- return await this.taggingDataProvider.resetNoteSyncData();
784
- }
785
- stop() {
758
+ /**
759
+ * Stops the PXE's job queue.
760
+ */ stop() {
786
761
  return this.jobQueue.end();
787
762
  }
788
763
  }