@aztec/pxe 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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 (521) hide show
  1. package/dest/bin/check_oracle_version.d.ts +1 -1
  2. package/dest/bin/check_oracle_version.js +54 -20
  3. package/dest/bin/index.d.ts +2 -0
  4. package/dest/bin/index.d.ts.map +1 -0
  5. package/dest/bin/index.js +1 -0
  6. package/dest/bin/oracle_version_helpers.d.ts +26 -0
  7. package/dest/bin/oracle_version_helpers.d.ts.map +1 -0
  8. package/dest/bin/oracle_version_helpers.js +93 -0
  9. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  10. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  11. package/dest/block_synchronizer/block_stream_source.js +62 -0
  12. package/dest/block_synchronizer/block_synchronizer.d.ts +49 -0
  13. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  14. package/dest/block_synchronizer/block_synchronizer.js +173 -0
  15. package/dest/block_synchronizer/index.d.ts +2 -0
  16. package/dest/block_synchronizer/index.d.ts.map +1 -0
  17. package/dest/block_synchronizer/index.js +1 -0
  18. package/dest/config/index.d.ts +13 -13
  19. package/dest/config/index.d.ts.map +1 -1
  20. package/dest/config/index.js +24 -15
  21. package/dest/config/package_info.d.ts +1 -1
  22. package/dest/config/package_info.js +1 -1
  23. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  24. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  25. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  26. package/dest/contract_function_simulator/contract_function_simulator.d.ts +89 -26
  27. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/contract_function_simulator.js +267 -88
  29. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  30. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  31. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  32. package/dest/contract_function_simulator/execution_note_cache.d.ts +26 -15
  33. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/execution_note_cache.js +59 -34
  35. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -11
  36. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -15
  38. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  39. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/index.d.ts +15 -3
  41. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  42. package/dest/contract_function_simulator/index.js +12 -1
  43. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +48 -0
  44. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +45 -0
  46. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts +37 -0
  47. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/noir-structs/ephemeral_array.js +59 -0
  49. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +6 -6
  50. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +12 -10
  52. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +16 -5
  53. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +39 -7
  55. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +4 -4
  56. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +3 -5
  58. package/dest/contract_function_simulator/noir-structs/note_data.d.ts +27 -0
  59. package/dest/contract_function_simulator/noir-structs/note_data.d.ts.map +1 -0
  60. package/dest/contract_function_simulator/noir-structs/note_data.js +3 -0
  61. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +7 -7
  62. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +15 -10
  64. package/dest/contract_function_simulator/noir-structs/option.d.ts +61 -0
  65. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
  66. package/dest/contract_function_simulator/noir-structs/option.js +62 -0
  67. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +11 -0
  68. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -0
  69. package/dest/contract_function_simulator/noir-structs/provided_secret.js +24 -0
  70. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  71. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  72. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  73. package/dest/contract_function_simulator/oracle/index.d.ts +1 -1
  74. package/dest/contract_function_simulator/oracle/interfaces.d.ts +16 -88
  75. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  76. package/dest/contract_function_simulator/oracle/interfaces.js +2 -2
  77. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -2
  78. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  79. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  80. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +14 -8
  81. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  82. package/dest/contract_function_simulator/oracle/note_packing_utils.js +17 -12
  83. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -43
  84. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  85. package/dest/contract_function_simulator/oracle/oracle.js +475 -251
  86. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +127 -0
  87. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
  88. package/dest/contract_function_simulator/oracle/oracle_registry.js +786 -0
  89. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +139 -0
  90. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -0
  91. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +560 -0
  92. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -27
  93. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  94. package/dest/contract_function_simulator/oracle/private_execution.js +6 -40
  95. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +78 -102
  96. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  97. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +177 -137
  98. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +189 -60
  99. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  100. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +507 -118
  101. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  102. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  103. package/dest/contract_function_simulator/pick_notes.js +21 -4
  104. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  105. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  106. package/dest/contract_function_simulator/proxied_contract_data_source.js +39 -50
  107. package/dest/contract_logging.d.ts +27 -0
  108. package/dest/contract_logging.d.ts.map +1 -0
  109. package/dest/contract_logging.js +38 -0
  110. package/dest/contract_sync/contract_sync_service.d.ts +42 -0
  111. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  112. package/dest/contract_sync/contract_sync_service.js +135 -0
  113. package/dest/contract_sync/helpers.d.ts +27 -0
  114. package/dest/contract_sync/helpers.d.ts.map +1 -0
  115. package/dest/contract_sync/helpers.js +53 -0
  116. package/dest/debug/pxe_debug_utils.d.ts +40 -0
  117. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  118. package/dest/debug/pxe_debug_utils.js +42 -0
  119. package/dest/entrypoints/client/bundle/index.d.ts +3 -2
  120. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  121. package/dest/entrypoints/client/bundle/index.js +2 -1
  122. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  123. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  124. package/dest/entrypoints/client/bundle/utils.js +43 -12
  125. package/dest/entrypoints/client/lazy/index.d.ts +3 -2
  126. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  127. package/dest/entrypoints/client/lazy/index.js +2 -1
  128. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  129. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  130. package/dest/entrypoints/client/lazy/utils.js +44 -13
  131. package/dest/entrypoints/pxe_creation_options.d.ts +15 -3
  132. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  133. package/dest/entrypoints/pxe_creation_options.js +3 -1
  134. package/dest/entrypoints/server/index.d.ts +7 -3
  135. package/dest/entrypoints/server/index.d.ts.map +1 -1
  136. package/dest/entrypoints/server/index.js +6 -2
  137. package/dest/entrypoints/server/utils.d.ts +4 -3
  138. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  139. package/dest/entrypoints/server/utils.js +50 -30
  140. package/dest/error_enriching.d.ts +4 -4
  141. package/dest/error_enriching.d.ts.map +1 -1
  142. package/dest/error_enriching.js +6 -6
  143. package/dest/events/event_service.d.ts +24 -0
  144. package/dest/events/event_service.d.ts.map +1 -0
  145. package/dest/events/event_service.js +77 -0
  146. package/dest/events/index.d.ts +2 -0
  147. package/dest/events/index.d.ts.map +1 -0
  148. package/dest/events/index.js +1 -0
  149. package/dest/events/private_event_filter_validator.d.ts +10 -0
  150. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  151. package/dest/events/private_event_filter_validator.js +53 -0
  152. package/dest/hooks/authorize_utility_call.d.ts +41 -0
  153. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  154. package/dest/hooks/authorize_utility_call.js +4 -0
  155. package/dest/hooks/execution_hooks.d.ts +42 -0
  156. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  157. package/dest/hooks/execution_hooks.js +9 -0
  158. package/dest/hooks/index.d.ts +4 -0
  159. package/dest/hooks/index.d.ts.map +1 -0
  160. package/dest/hooks/index.js +1 -0
  161. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  162. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  163. package/dest/job_coordinator/job_coordinator.js +94 -0
  164. package/dest/logs/log_service.d.ts +29 -0
  165. package/dest/logs/log_service.d.ts.map +1 -0
  166. package/dest/logs/log_service.js +172 -0
  167. package/dest/messages/message_context_service.d.ts +17 -0
  168. package/dest/messages/message_context_service.d.ts.map +1 -0
  169. package/dest/messages/message_context_service.js +55 -0
  170. package/dest/notes/index.d.ts +2 -0
  171. package/dest/notes/index.d.ts.map +1 -0
  172. package/dest/notes/index.js +1 -0
  173. package/dest/notes/note_service.d.ts +70 -0
  174. package/dest/notes/note_service.d.ts.map +1 -0
  175. package/dest/notes/note_service.js +172 -0
  176. package/dest/notes_filter.d.ts +24 -0
  177. package/dest/notes_filter.d.ts.map +1 -0
  178. package/dest/notes_filter.js +4 -0
  179. package/dest/oracle_version.d.ts +4 -3
  180. package/dest/oracle_version.d.ts.map +1 -1
  181. package/dest/oracle_version.js +20 -9
  182. package/dest/private_kernel/batch_planner.d.ts +47 -0
  183. package/dest/private_kernel/batch_planner.d.ts.map +1 -0
  184. package/dest/private_kernel/batch_planner.js +104 -0
  185. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  186. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  187. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  188. package/dest/private_kernel/hints/index.d.ts +3 -3
  189. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  190. package/dest/private_kernel/hints/index.js +2 -2
  191. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  192. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  193. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +145 -78
  194. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  195. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  196. package/dest/private_kernel/hints/test_utils.js +202 -0
  197. package/dest/private_kernel/index.d.ts +1 -1
  198. package/dest/private_kernel/private_kernel_execution_prover.d.ts +7 -2
  199. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  200. package/dest/private_kernel/private_kernel_execution_prover.js +177 -76
  201. package/dest/private_kernel/private_kernel_oracle.d.ts +30 -29
  202. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  203. package/dest/private_kernel/private_kernel_oracle.js +96 -2
  204. package/dest/pxe.d.ts +170 -103
  205. package/dest/pxe.d.ts.map +1 -1
  206. package/dest/pxe.js +356 -306
  207. package/dest/storage/address_store/address_store.d.ts +11 -0
  208. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  209. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -12
  210. package/dest/storage/address_store/index.d.ts +2 -0
  211. package/dest/storage/address_store/index.d.ts.map +1 -0
  212. package/dest/storage/address_store/index.js +1 -0
  213. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  214. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  215. package/dest/storage/anchor_block_store/anchor_block_store.js +26 -0
  216. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  217. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  218. package/dest/storage/anchor_block_store/index.js +1 -0
  219. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  220. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  221. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  222. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  223. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  224. package/dest/storage/backwards_compatibility_tests/schema_tests.js +591 -0
  225. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  226. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  227. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  228. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  229. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  230. package/dest/storage/capsule_store/capsule_service.js +50 -0
  231. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  232. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  233. package/dest/storage/capsule_store/capsule_store.js +261 -0
  234. package/dest/storage/capsule_store/index.d.ts +3 -0
  235. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  236. package/dest/storage/capsule_store/index.js +2 -0
  237. package/dest/storage/contract_store/contract_store.d.ts +93 -0
  238. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  239. package/dest/storage/contract_store/contract_store.js +292 -0
  240. package/dest/storage/contract_store/index.d.ts +2 -0
  241. package/dest/storage/contract_store/index.d.ts.map +1 -0
  242. package/dest/storage/contract_store/index.js +1 -0
  243. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  244. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  245. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  246. package/dest/storage/index.d.ts +8 -8
  247. package/dest/storage/index.d.ts.map +1 -1
  248. package/dest/storage/index.js +7 -7
  249. package/dest/storage/metadata.d.ts +2 -2
  250. package/dest/storage/metadata.js +1 -1
  251. package/dest/storage/note_store/index.d.ts +3 -0
  252. package/dest/storage/note_store/index.d.ts.map +1 -0
  253. package/dest/storage/note_store/index.js +2 -0
  254. package/dest/storage/note_store/note_store.d.ts +83 -0
  255. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  256. package/dest/storage/note_store/note_store.js +343 -0
  257. package/dest/storage/note_store/stored_note.d.ts +16 -0
  258. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  259. package/dest/storage/note_store/stored_note.js +43 -0
  260. package/dest/storage/open_pxe_stores.d.ts +33 -0
  261. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  262. package/dest/storage/open_pxe_stores.js +27 -0
  263. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  264. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  265. package/dest/storage/private_event_store/private_event_store.js +276 -0
  266. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  267. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  268. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  269. package/dest/storage/tagging_store/index.d.ts +4 -0
  270. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  271. package/dest/storage/tagging_store/index.js +3 -0
  272. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  273. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  274. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  275. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  276. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  277. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  278. package/dest/storage/tagging_store/sender_tagging_store.d.ts +78 -0
  279. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  280. package/dest/storage/tagging_store/sender_tagging_store.js +374 -0
  281. package/dest/tagging/constants.d.ts +2 -2
  282. package/dest/tagging/constants.d.ts.map +1 -1
  283. package/dest/tagging/constants.js +10 -2
  284. package/dest/tagging/get_all_logs_by_tags.d.ts +48 -0
  285. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  286. package/dest/tagging/get_all_logs_by_tags.js +59 -0
  287. package/dest/tagging/index.d.ts +18 -7
  288. package/dest/tagging/index.d.ts.map +1 -1
  289. package/dest/tagging/index.js +16 -5
  290. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  291. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  292. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  293. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +56 -0
  294. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  295. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +163 -0
  296. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  297. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  298. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  299. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  300. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  301. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  302. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +16 -0
  303. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  304. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +92 -0
  305. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +17 -0
  306. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  307. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +60 -0
  308. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +19 -0
  309. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  310. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +72 -0
  311. package/package.json +33 -20
  312. package/src/bin/check_oracle_version.ts +63 -25
  313. package/src/bin/index.ts +1 -0
  314. package/src/bin/oracle_version_helpers.ts +121 -0
  315. package/src/block_synchronizer/block_stream_source.ts +81 -0
  316. package/src/block_synchronizer/block_synchronizer.ts +200 -0
  317. package/src/block_synchronizer/index.ts +1 -0
  318. package/src/config/index.ts +31 -26
  319. package/src/config/package_info.ts +1 -1
  320. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  321. package/src/contract_function_simulator/contract_function_simulator.ts +462 -122
  322. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  323. package/src/contract_function_simulator/execution_note_cache.ts +59 -29
  324. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -18
  325. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  326. package/src/contract_function_simulator/index.ts +52 -2
  327. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +55 -0
  328. package/src/contract_function_simulator/noir-structs/ephemeral_array.ts +66 -0
  329. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +15 -10
  330. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +40 -6
  331. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +4 -7
  332. package/src/contract_function_simulator/noir-structs/note_data.ts +27 -0
  333. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +17 -10
  334. package/src/contract_function_simulator/noir-structs/option.ts +69 -0
  335. package/src/contract_function_simulator/noir-structs/provided_secret.ts +27 -0
  336. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  337. package/src/contract_function_simulator/oracle/interfaces.ts +12 -151
  338. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  339. package/src/contract_function_simulator/oracle/note_packing_utils.ts +31 -15
  340. package/src/contract_function_simulator/oracle/oracle.ts +570 -434
  341. package/src/contract_function_simulator/oracle/oracle_registry.ts +585 -0
  342. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +553 -0
  343. package/src/contract_function_simulator/oracle/private_execution.ts +6 -72
  344. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +230 -188
  345. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +751 -142
  346. package/src/contract_function_simulator/pick_notes.ts +23 -4
  347. package/src/contract_function_simulator/proxied_contract_data_source.ts +47 -53
  348. package/src/contract_logging.ts +52 -0
  349. package/src/contract_sync/contract_sync_service.ts +189 -0
  350. package/src/contract_sync/helpers.ts +86 -0
  351. package/src/debug/pxe_debug_utils.ts +85 -0
  352. package/src/entrypoints/client/bundle/index.ts +2 -1
  353. package/src/entrypoints/client/bundle/utils.ts +33 -21
  354. package/src/entrypoints/client/lazy/index.ts +2 -1
  355. package/src/entrypoints/client/lazy/utils.ts +35 -23
  356. package/src/entrypoints/pxe_creation_options.ts +20 -2
  357. package/src/entrypoints/server/index.ts +6 -2
  358. package/src/entrypoints/server/utils.ts +47 -60
  359. package/src/error_enriching.ts +7 -15
  360. package/src/events/event_service.ts +119 -0
  361. package/src/events/index.ts +1 -0
  362. package/src/events/private_event_filter_validator.ts +66 -0
  363. package/src/hooks/authorize_utility_call.ts +44 -0
  364. package/src/hooks/execution_hooks.ts +48 -0
  365. package/src/hooks/index.ts +7 -0
  366. package/src/job_coordinator/job_coordinator.ts +150 -0
  367. package/src/logs/log_service.ts +237 -0
  368. package/src/messages/message_context_service.ts +62 -0
  369. package/src/notes/index.ts +1 -0
  370. package/src/notes/note_service.ts +230 -0
  371. package/src/notes_filter.ts +24 -0
  372. package/src/oracle_version.ts +20 -9
  373. package/src/private_kernel/batch_planner.ts +169 -0
  374. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  375. package/src/private_kernel/hints/index.ts +2 -2
  376. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +200 -146
  377. package/src/private_kernel/hints/test_utils.ts +318 -0
  378. package/src/private_kernel/private_kernel_execution_prover.ts +272 -110
  379. package/src/private_kernel/private_kernel_oracle.ts +130 -39
  380. package/src/pxe.ts +606 -414
  381. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
  382. package/src/storage/address_store/index.ts +1 -0
  383. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +11 -12
  384. package/src/storage/anchor_block_store/index.ts +1 -0
  385. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  386. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  387. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  388. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  389. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  390. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +46 -0
  391. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +36 -0
  392. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  393. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
  394. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +16 -0
  395. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
  396. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +97 -0
  397. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  398. package/src/storage/backwards_compatibility_tests/schema_tests.ts +712 -0
  399. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  400. package/src/storage/capsule_store/capsule_service.ts +90 -0
  401. package/src/storage/capsule_store/capsule_store.ts +333 -0
  402. package/src/storage/capsule_store/index.ts +2 -0
  403. package/src/storage/contract_store/contract_store.ts +408 -0
  404. package/src/storage/contract_store/index.ts +1 -0
  405. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  406. package/src/storage/index.ts +7 -7
  407. package/src/storage/metadata.ts +1 -1
  408. package/src/storage/note_store/index.ts +2 -0
  409. package/src/storage/note_store/note_store.ts +415 -0
  410. package/src/storage/note_store/stored_note.ts +48 -0
  411. package/src/storage/open_pxe_stores.ts +49 -0
  412. package/src/storage/private_event_store/private_event_store.ts +388 -0
  413. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  414. package/src/storage/tagging_store/index.ts +3 -0
  415. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  416. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  417. package/src/storage/tagging_store/sender_tagging_store.ts +476 -0
  418. package/src/tagging/constants.ts +10 -2
  419. package/src/tagging/get_all_logs_by_tags.ts +120 -0
  420. package/src/tagging/index.ts +20 -6
  421. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  422. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +240 -0
  423. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  424. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  425. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +134 -0
  426. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +66 -0
  427. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  428. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -274
  429. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  430. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  431. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  432. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  433. package/dest/contract_function_simulator/proxied_node.js +0 -27
  434. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -122
  435. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  436. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  437. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  438. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  439. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  440. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  441. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  442. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  443. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  444. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  445. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  446. package/dest/storage/address_data_provider/index.d.ts +0 -2
  447. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  448. package/dest/storage/address_data_provider/index.js +0 -1
  449. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  450. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  451. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -118
  452. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  453. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  454. package/dest/storage/capsule_data_provider/index.js +0 -1
  455. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -74
  456. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  457. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -205
  458. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  459. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  460. package/dest/storage/contract_data_provider/index.js +0 -1
  461. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  462. package/dest/storage/note_data_provider/index.d.ts +0 -3
  463. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  464. package/dest/storage/note_data_provider/index.js +0 -2
  465. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  466. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  467. package/dest/storage/note_data_provider/note_dao.js +0 -102
  468. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -83
  469. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  470. package/dest/storage/note_data_provider/note_data_provider.js +0 -308
  471. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -43
  472. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  473. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -104
  474. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  475. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  476. package/dest/storage/sync_data_provider/index.js +0 -1
  477. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -10
  478. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  479. package/dest/storage/sync_data_provider/sync_data_provider.js +0 -26
  480. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  481. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  482. package/dest/storage/tagging_data_provider/index.js +0 -1
  483. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  484. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  485. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  486. package/dest/synchronizer/index.d.ts +0 -2
  487. package/dest/synchronizer/index.d.ts.map +0 -1
  488. package/dest/synchronizer/index.js +0 -1
  489. package/dest/synchronizer/synchronizer.d.ts +0 -35
  490. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  491. package/dest/synchronizer/synchronizer.js +0 -101
  492. package/dest/tagging/siloed_tag.d.ts +0 -14
  493. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  494. package/dest/tagging/siloed_tag.js +0 -20
  495. package/dest/tagging/tag.d.ts +0 -12
  496. package/dest/tagging/tag.d.ts.map +0 -1
  497. package/dest/tagging/tag.js +0 -17
  498. package/dest/tagging/utils.d.ts +0 -18
  499. package/dest/tagging/utils.d.ts.map +0 -1
  500. package/dest/tagging/utils.js +0 -24
  501. package/src/contract_function_simulator/execution_data_provider.ts +0 -343
  502. package/src/contract_function_simulator/proxied_node.ts +0 -33
  503. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1019
  504. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  505. package/src/storage/address_data_provider/index.ts +0 -1
  506. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -147
  507. package/src/storage/capsule_data_provider/index.ts +0 -1
  508. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -294
  509. package/src/storage/contract_data_provider/index.ts +0 -1
  510. package/src/storage/note_data_provider/index.ts +0 -2
  511. package/src/storage/note_data_provider/note_dao.ts +0 -154
  512. package/src/storage/note_data_provider/note_data_provider.ts +0 -393
  513. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -148
  514. package/src/storage/sync_data_provider/index.ts +0 -1
  515. package/src/storage/tagging_data_provider/index.ts +0 -1
  516. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  517. package/src/synchronizer/index.ts +0 -1
  518. package/src/synchronizer/synchronizer.ts +0 -120
  519. package/src/tagging/siloed_tag.ts +0 -22
  520. package/src/tagging/tag.ts +0 -16
  521. package/src/tagging/utils.ts +0 -31
package/src/pxe.ts CHANGED
@@ -1,43 +1,41 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
1
+ import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
5
  import { SerialQueue } from '@aztec/foundation/queue';
4
6
  import { Timer } from '@aztec/foundation/timer';
5
7
  import { KeyStore } from '@aztec/key-store';
6
8
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
- import { L2TipsKVStore } from '@aztec/kv-store/stores';
8
9
  import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
9
10
  import type { CircuitSimulator } from '@aztec/simulator/client';
10
11
  import {
11
12
  type ContractArtifact,
12
- type EventMetadataDefinition,
13
+ EventSelector,
13
14
  FunctionCall,
14
- FunctionSelector,
15
15
  FunctionType,
16
- decodeFromAbi,
17
16
  decodeFunctionSignature,
18
- encodeArguments,
19
17
  } from '@aztec/stdlib/abi';
20
18
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
21
19
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
+ import { GENESIS_BLOCK_HEADER_HASH, type L2TipsProvider } from '@aztec/stdlib/block';
22
21
  import {
23
22
  CompleteAddress,
24
- type ContractClassWithId,
25
23
  type ContractInstanceWithAddress,
26
24
  type PartialAddress,
27
25
  computeContractAddressFromInstance,
28
26
  getContractClassFromArtifact,
29
27
  } from '@aztec/stdlib/contract';
30
28
  import { SimulationError } from '@aztec/stdlib/errors';
31
- import { siloNullifier } from '@aztec/stdlib/hash';
32
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
33
30
  import type {
34
31
  PrivateExecutionStep,
35
32
  PrivateKernelExecutionProofOutput,
36
33
  PrivateKernelTailCircuitPublicInputs,
37
34
  } from '@aztec/stdlib/kernel';
38
- import { type NotesFilter, UniqueNote } from '@aztec/stdlib/note';
39
35
  import {
36
+ BlockHeader,
40
37
  type ContractOverrides,
38
+ type InTx,
41
39
  PrivateExecutionResult,
42
40
  PrivateSimulationResult,
43
41
  type ProvingTimings,
@@ -49,37 +47,136 @@ import {
49
47
  TxProfileResult,
50
48
  TxProvingResult,
51
49
  TxSimulationResult,
52
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
53
51
  } from '@aztec/stdlib/tx';
54
52
 
55
53
  import { inspect } from 'util';
56
54
 
55
+ import { BlockSynchronizer } from './block_synchronizer/index.js';
57
56
  import type { PXEConfig } from './config/index.js';
57
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
58
58
  import {
59
59
  ContractFunctionSimulator,
60
60
  generateSimulatedProvingResult,
61
61
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
63
- import { ProxiedContractDataProviderFactory } from './contract_function_simulator/proxied_contract_data_source.js';
64
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
65
- import { PXEOracleInterface } from './contract_function_simulator/pxe_oracle_interface.js';
62
+ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
66
+ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
66
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
68
+ import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
+ import type { ExecutionHooks } from './hooks/index.js';
70
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
67
72
  import {
68
73
  PrivateKernelExecutionProver,
69
74
  type PrivateKernelExecutionProverConfig,
70
75
  } from './private_kernel/private_kernel_execution_prover.js';
71
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
72
- import { AddressDataProvider } from './storage/address_data_provider/address_data_provider.js';
73
- import { CapsuleDataProvider } from './storage/capsule_data_provider/capsule_data_provider.js';
74
- import { ContractDataProvider } from './storage/contract_data_provider/contract_data_provider.js';
75
- import { NoteDataProvider } from './storage/note_data_provider/note_data_provider.js';
76
- import {
77
- type PrivateEvent,
78
- PrivateEventDataProvider,
79
- } from './storage/private_event_data_provider/private_event_data_provider.js';
80
- import { SyncDataProvider } from './storage/sync_data_provider/sync_data_provider.js';
81
- import { TaggingDataProvider } from './storage/tagging_data_provider/tagging_data_provider.js';
82
- import { Synchronizer } from './synchronizer/index.js';
76
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
77
+ import { AddressStore } from './storage/address_store/address_store.js';
78
+ import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
79
+ import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
80
+ import { ContractStore } from './storage/contract_store/contract_store.js';
81
+ import { NoteStore } from './storage/note_store/note_store.js';
82
+ import { openPxeStores } from './storage/open_pxe_stores.js';
83
+ import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
84
+ import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
85
+ import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
86
+ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
87
+ import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
88
+
89
+ export type PackedPrivateEvent = InTx & {
90
+ packedEvent: Fr[];
91
+ eventSelector: EventSelector;
92
+ };
93
+
94
+ /** Options for PXE.proveTx. */
95
+ export type ProveTxOpts = {
96
+ /** Addresses whose private state and keys are accessible during private execution. */
97
+ scopes: AztecAddress[];
98
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
99
+ senderForTags?: AztecAddress;
100
+ };
101
+
102
+ /** Options for PXE.profileTx. */
103
+ export type ProfileTxOpts = {
104
+ /** The profiling mode to use. */
105
+ profileMode: 'full' | 'execution-steps' | 'gates';
106
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
107
+ skipProofGeneration?: boolean;
108
+ /** Addresses whose private state and keys are accessible during private execution. */
109
+ scopes: AztecAddress[];
110
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
111
+ senderForTags?: AztecAddress;
112
+ };
113
+
114
+ /** Options for PXE.simulateTx. */
115
+ export type SimulateTxOpts = {
116
+ /** Whether to simulate the public part of the transaction. */
117
+ simulatePublic: boolean;
118
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
119
+ skipTxValidation?: boolean;
120
+ /** If false, fees are enforced. */
121
+ skipFeeEnforcement?: boolean;
122
+ /** If true, kernel logic is emulated in TS for simulation */
123
+ skipKernels?: boolean;
124
+ /**
125
+ * Pre-simulation overrides applied to the ephemeral fork and contract DB. Bundles publicStorage
126
+ * writes (no skipKernels required) and per-address (instance, artifact?) overrides used by both
127
+ * AVM-side public dispatch and PXE-side ACIR private dispatch (requires skipKernels: true).
128
+ */
129
+ overrides?: SimulationOverrides;
130
+ /** Addresses whose private state and keys are accessible during private execution */
131
+ scopes: AztecAddress[];
132
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
133
+ senderForTags?: AztecAddress;
134
+ };
135
+
136
+ /** Options for PXE.executeUtility. */
137
+ export type ExecuteUtilityOpts = {
138
+ /** The authentication witnesses required for the function call. */
139
+ authwits?: AuthWitness[];
140
+ /** The accounts whose notes we can access in this call */
141
+ scopes: AztecAddress[];
142
+ };
143
+
144
+ /**
145
+ * Supplies the set of "nice to have" contracts that every PXE preloads regardless of which wallet
146
+ * drives it. Today this is just the standard multi-call entrypoint: the SDK's self-paid account
147
+ * deploy flow ({@link DeployAccountMethod} with `from = NO_FROM`) routes its payload through it, so a
148
+ * PXE that did not register it would fail contract sync with an opaque "no contract instance" error.
149
+ *
150
+ * Returning a list keeps this extensible: a wallet may supply its own provider that preloads
151
+ * additional contracts. Injected the same way as {@link ProtocolContractsProvider} so the PXE never
152
+ * statically imports the bundled artifacts, keeping the bundle/lazy split intact.
153
+ */
154
+ export type PreloadedContractsProvider = {
155
+ /** Returns the contract instances and artifacts the PXE should preload on startup. */
156
+ getPreloadedContracts: () => Promise<Array<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>>;
157
+ };
158
+
159
+ /** Args for PXE.create. */
160
+ export type PXECreateArgs = {
161
+ /** The Aztec node to connect to. */
162
+ node: AztecNode;
163
+ /** The key-value store for persisting PXE state. */
164
+ store: AztecAsyncKVStore;
165
+ /** The prover for generating private kernel proofs. */
166
+ proofCreator: PrivateKernelProver;
167
+ /** The circuit simulator for executing ACIR circuits. */
168
+ simulator: CircuitSimulator;
169
+ /** Provider for protocol contract artifacts and instances. */
170
+ protocolContractsProvider: ProtocolContractsProvider;
171
+ /** Provider for the "nice to have" contracts the PXE preloads. */
172
+ preloadedContractsProvider: PreloadedContractsProvider;
173
+ /** PXE configuration options. */
174
+ config: PXEConfig;
175
+ /** Optional logger instance or string suffix for the logger name. */
176
+ loggerOrSuffix?: string | Logger;
177
+ /** Optional hooks to observe and influence contract execution. */
178
+ hooks?: ExecutionHooks;
179
+ };
83
180
 
84
181
  /**
85
182
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
@@ -88,21 +185,32 @@ import { Synchronizer } from './synchronizer/index.js';
88
185
  export class PXE {
89
186
  private constructor(
90
187
  private node: AztecNode,
91
- private synchronizer: Synchronizer,
188
+ private db: AztecAsyncKVStore,
189
+ private blockStateSynchronizer: BlockSynchronizer,
92
190
  private keyStore: KeyStore,
93
- private contractDataProvider: ContractDataProvider,
94
- private noteDataProvider: NoteDataProvider,
95
- private capsuleDataProvider: CapsuleDataProvider,
96
- private syncDataProvider: SyncDataProvider,
97
- private taggingDataProvider: TaggingDataProvider,
98
- private addressDataProvider: AddressDataProvider,
99
- private privateEventDataProvider: PrivateEventDataProvider,
191
+ private contractStore: ContractStore,
192
+ private noteStore: NoteStore,
193
+ private capsuleStore: CapsuleStore,
194
+ private anchorBlockStore: AnchorBlockStore,
195
+ private senderTaggingStore: SenderTaggingStore,
196
+ private senderAddressBookStore: SenderAddressBookStore,
197
+ private recipientTaggingStore: RecipientTaggingStore,
198
+ private addressStore: AddressStore,
199
+ private privateEventStore: PrivateEventStore,
200
+ private contractSyncService: ContractSyncService,
201
+ private messageContextService: MessageContextService,
202
+ private l2TipsStore: L2TipsProvider,
100
203
  private simulator: CircuitSimulator,
101
204
  private proverEnabled: boolean,
205
+ private autoSync: boolean,
102
206
  private proofCreator: PrivateKernelProver,
103
207
  private protocolContractsProvider: ProtocolContractsProvider,
208
+ private preloadedContractsProvider: PreloadedContractsProvider,
104
209
  private log: Logger,
105
210
  private jobQueue: SerialQueue,
211
+ private jobCoordinator: JobCoordinator,
212
+ public debug: PXEDebugUtils,
213
+ private hooks: ExecutionHooks | undefined,
106
214
  ) {}
107
215
 
108
216
  /**
@@ -112,65 +220,123 @@ export class PXE {
112
220
  *
113
221
  * @returns A promise that resolves PXE is ready to be used.
114
222
  */
115
- public static async create(
116
- node: AztecNode,
117
- store: AztecAsyncKVStore,
118
- proofCreator: PrivateKernelProver,
119
- simulator: CircuitSimulator,
120
- protocolContractsProvider: ProtocolContractsProvider,
121
- config: PXEConfig,
122
- loggerOrSuffix?: string | Logger,
123
- ) {
223
+ public static async create({
224
+ node,
225
+ store,
226
+ proofCreator,
227
+ simulator,
228
+ protocolContractsProvider,
229
+ preloadedContractsProvider,
230
+ config,
231
+ loggerOrSuffix,
232
+ hooks,
233
+ }: PXECreateArgs) {
234
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
235
+ const bindings: LoggerBindings | undefined =
236
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
237
+
124
238
  const log =
125
239
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
126
240
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
127
241
  : loggerOrSuffix;
128
242
 
129
- const proverEnabled = !!config.proverEnabled;
130
- const addressDataProvider = new AddressDataProvider(store);
131
- const privateEventDataProvider = new PrivateEventDataProvider(store);
132
- const contractDataProvider = new ContractDataProvider(store);
133
- const noteDataProvider = await NoteDataProvider.create(store);
134
- const syncDataProvider = new SyncDataProvider(store);
135
- const taggingDataProvider = new TaggingDataProvider(store);
136
- const capsuleDataProvider = new CapsuleDataProvider(store);
137
- const keyStore = new KeyStore(store);
138
- const tipsStore = new L2TipsKVStore(store, 'pxe');
139
- const synchronizer = new Synchronizer(
243
+ const info = await node.getNodeInfo();
244
+
245
+ // Source the genesis block hash from the node so PXE's L2BlockStream agrees with the node's
246
+ // archiver on the dynamic initial header hash. Without this the tip store would fall back to
247
+ // the static `GENESIS_BLOCK_HEADER_HASH` constant, which only matches deployments with the
248
+ // default empty genesis (timestamp 0, no prefilled public data) and diverges otherwise — the
249
+ // sync at block 0 would then get stuck in `areBlockHashesEqualAt` and abort. If the node does
250
+ // not return a genesis block (older node or test fixture) we fall back to the static constant.
251
+ const initialBlockHash = (await node.getBlock(BlockNumber.ZERO))?.hash ?? GENESIS_BLOCK_HEADER_HASH;
252
+
253
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
254
+ const {
255
+ addressStore,
256
+ privateEventStore,
257
+ contractStore,
258
+ noteStore,
259
+ anchorBlockStore,
260
+ senderTaggingStore,
261
+ senderAddressBookStore,
262
+ recipientTaggingStore,
263
+ capsuleStore,
264
+ keyStore,
265
+ l2TipsStore,
266
+ } = openPxeStores(store, initialBlockHash);
267
+ const contractSyncService = new ContractSyncService(
268
+ node,
269
+ contractStore,
270
+ noteStore,
271
+ createLogger('pxe:contract_sync', bindings),
272
+ );
273
+ const messageContextService = new MessageContextService(node);
274
+
275
+ const synchronizer = new BlockSynchronizer(
140
276
  node,
141
- syncDataProvider,
142
- noteDataProvider,
143
- taggingDataProvider,
144
- tipsStore,
277
+ store,
278
+ anchorBlockStore,
279
+ noteStore,
280
+ privateEventStore,
281
+ l2TipsStore,
282
+ contractSyncService,
145
283
  config,
146
- loggerOrSuffix,
284
+ bindings,
147
285
  );
148
286
 
287
+ const jobCoordinator = new JobCoordinator(store, bindings);
288
+ jobCoordinator.registerStores([
289
+ capsuleStore,
290
+ senderTaggingStore,
291
+ recipientTaggingStore,
292
+ privateEventStore,
293
+ noteStore,
294
+ contractSyncService,
295
+ ]);
296
+
297
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
298
+
149
299
  const jobQueue = new SerialQueue();
150
300
 
151
301
  const pxe = new PXE(
152
302
  node,
303
+ store,
153
304
  synchronizer,
154
305
  keyStore,
155
- contractDataProvider,
156
- noteDataProvider,
157
- capsuleDataProvider,
158
- syncDataProvider,
159
- taggingDataProvider,
160
- addressDataProvider,
161
- privateEventDataProvider,
306
+ contractStore,
307
+ noteStore,
308
+ capsuleStore,
309
+ anchorBlockStore,
310
+ senderTaggingStore,
311
+ senderAddressBookStore,
312
+ recipientTaggingStore,
313
+ addressStore,
314
+ privateEventStore,
315
+ contractSyncService,
316
+ messageContextService,
317
+ l2TipsStore,
162
318
  simulator,
163
319
  proverEnabled,
320
+ config.autoSync,
164
321
  proofCreator,
165
322
  protocolContractsProvider,
323
+ preloadedContractsProvider,
166
324
  log,
167
325
  jobQueue,
326
+ jobCoordinator,
327
+ debugUtils,
328
+ hooks,
329
+ );
330
+
331
+ debugUtils.setPXEHelpers(
332
+ pxe.#putInJobQueue.bind(pxe),
333
+ pxe.#getSimulatorForTx.bind(pxe),
334
+ pxe.#executeUtility.bind(pxe),
168
335
  );
169
336
 
170
337
  pxe.jobQueue.start();
171
338
 
172
- await pxe.#registerProtocolContracts();
173
- const info = await node.getNodeInfo();
339
+ await Promise.all([pxe.#registerProtocolContracts(), pxe.#registerPreloadedContracts()]);
174
340
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
175
341
  return pxe;
176
342
  }
@@ -178,19 +344,25 @@ export class PXE {
178
344
  // Internal methods
179
345
 
180
346
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
181
- const pxeOracleInterface = new PXEOracleInterface(
182
- ProxiedNodeFactory.create(this.node),
183
- this.keyStore,
184
- ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts),
185
- this.noteDataProvider,
186
- this.capsuleDataProvider,
187
- this.syncDataProvider,
188
- this.taggingDataProvider,
189
- this.addressDataProvider,
190
- this.privateEventDataProvider,
191
- this.log,
192
- );
193
- return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
347
+ const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
348
+
349
+ return new ContractFunctionSimulator({
350
+ contractStore: proxyContractStore,
351
+ noteStore: this.noteStore,
352
+ keyStore: this.keyStore,
353
+ addressStore: this.addressStore,
354
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
355
+ l2TipsStore: this.l2TipsStore,
356
+ senderTaggingStore: this.senderTaggingStore,
357
+ recipientTaggingStore: this.recipientTaggingStore,
358
+ senderAddressBookStore: this.senderAddressBookStore,
359
+ capsuleStore: this.capsuleStore,
360
+ privateEventStore: this.privateEventStore,
361
+ simulator: this.simulator,
362
+ contractSyncService: this.contractSyncService,
363
+ messageContextService: this.messageContextService,
364
+ hooks: this.hooks,
365
+ });
194
366
  }
195
367
 
196
368
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -213,7 +385,7 @@ export class PXE {
213
385
  *
214
386
  * Useful for tasks that cannot run concurrently, such as contract function simulation.
215
387
  */
216
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
388
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
217
389
  // TODO(#12636): relax the conditions under which we forbid concurrency.
218
390
  if (this.jobQueue.length() != 0) {
219
391
  this.log.warn(
@@ -221,109 +393,125 @@ export class PXE {
221
393
  );
222
394
  }
223
395
 
224
- return this.jobQueue.put(fn);
396
+ return this.jobQueue.put(async () => {
397
+ const jobId = this.jobCoordinator.beginJob();
398
+ this.log.verbose(`Beginning job ${jobId}`);
399
+
400
+ try {
401
+ const result = await fn(jobId);
402
+ this.log.verbose(`Committing job ${jobId}`);
403
+
404
+ await this.jobCoordinator.commitJob(jobId);
405
+ return result;
406
+ } catch (err) {
407
+ this.log.verbose(`Aborting job ${jobId}`);
408
+ await this.jobCoordinator.abortJob(jobId);
409
+ throw err;
410
+ }
411
+ });
225
412
  }
226
413
 
227
414
  async #registerProtocolContracts() {
228
- const registered: Record<string, string> = {};
229
- for (const name of protocolContractNames) {
230
- const { address, contractClass, instance, artifact } =
231
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
232
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
233
- await this.contractDataProvider.addContractInstance(instance);
234
- registered[name] = address.toString();
235
- }
415
+ const registered = Object.fromEntries(
416
+ await Promise.all(
417
+ protocolContractNames.map(async name => {
418
+ const { address, instance, artifact } =
419
+ await this.protocolContractsProvider.getProtocolContractArtifact(name);
420
+ await this.contractStore.addContractArtifact(artifact);
421
+ await this.contractStore.addContractInstance(instance);
422
+ return [name, address.toString()] as const;
423
+ }),
424
+ ),
425
+ );
236
426
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
237
427
  }
238
428
 
239
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
240
- return !!(await this.node.getContractClass(id));
241
- }
242
-
243
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
244
- return !!(await this.node.getContract(address));
245
- }
246
-
247
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
248
- const initNullifier = await siloNullifier(address, address.toField());
249
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
250
- }
251
-
252
- async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
253
- const contract = await this.contractDataProvider.getContract(to);
254
- if (!contract) {
255
- throw new Error(
256
- `Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
257
- );
258
- }
259
-
260
- const functionDao = contract.functions.find(f => f.name === functionName);
261
- if (!functionDao) {
262
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
263
- }
264
-
265
- return {
266
- name: functionDao.name,
267
- args: encodeArguments(functionDao, args),
268
- selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
269
- type: functionDao.functionType,
270
- to,
271
- hideMsgSender: false,
272
- isStatic: functionDao.isStatic,
273
- returnTypes: functionDao.returnTypes,
274
- };
429
+ async #registerPreloadedContracts() {
430
+ const contracts = await this.preloadedContractsProvider.getPreloadedContracts();
431
+ await Promise.all(contracts.map(({ instance, artifact }) => this.registerContract({ instance, artifact })));
432
+ this.log.verbose(`Registered preloaded contracts in pxe`, {
433
+ contracts: contracts.map(({ instance }) => instance.address.toString()),
434
+ });
275
435
  }
276
436
 
277
437
  // Executes the entrypoint private function, as well as all nested private
278
438
  // functions that might arise.
279
- async #executePrivate(
280
- contractFunctionSimulator: ContractFunctionSimulator,
281
- txRequest: TxExecutionRequest,
282
- scopes?: AztecAddress[],
283
- ): Promise<PrivateExecutionResult> {
439
+ async #executePrivate({
440
+ contractFunctionSimulator,
441
+ txRequest,
442
+ anchorBlockHeader,
443
+ scopes,
444
+ jobId,
445
+ senderForTags,
446
+ }: {
447
+ contractFunctionSimulator: ContractFunctionSimulator;
448
+ txRequest: TxExecutionRequest;
449
+ anchorBlockHeader: BlockHeader;
450
+ scopes: AztecAddress[];
451
+ jobId: string;
452
+ senderForTags?: AztecAddress;
453
+ }): Promise<PrivateExecutionResult> {
284
454
  const { origin: contractAddress, functionSelector } = txRequest;
285
455
 
286
456
  try {
287
- const result = await contractFunctionSimulator.run(
288
- txRequest,
457
+ await this.contractSyncService.ensureContractSynced(
289
458
  contractAddress,
290
459
  functionSelector,
291
- undefined,
292
- // The sender for tags is set by contracts, typically by an account
293
- // contract entrypoint
294
- undefined, // senderForTags
460
+ (privateSyncCall, execScopes) =>
461
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
462
+ anchorBlockHeader,
463
+ jobId,
295
464
  scopes,
296
465
  );
466
+
467
+ const result = await contractFunctionSimulator.run(txRequest, {
468
+ contractAddress,
469
+ selector: functionSelector,
470
+ anchorBlockHeader,
471
+ scopes,
472
+ jobId,
473
+ senderForTags,
474
+ });
297
475
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
298
476
  return result;
299
477
  } catch (err) {
300
478
  if (err instanceof SimulationError) {
301
- await enrichSimulationError(err, this.contractDataProvider, this.log);
479
+ await enrichSimulationError(err, this.contractStore, this.log);
302
480
  }
303
481
  throw err;
304
482
  }
305
483
  }
306
484
 
307
485
  /**
308
- * Simulate a utility function call on the given contract.
486
+ * Execute a utility function call on the given contract.
309
487
  * @param contractFunctionSimulator - The simulator to use for the function call.
310
488
  * @param call - The function call to execute.
311
489
  * @param authWitnesses - Authentication witnesses required for the function call.
312
490
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
313
491
  * accounts if not specified.
314
- * @returns The simulation result containing the outputs of the utility function.
492
+ * @param jobId - The job ID for staged writes.
493
+ * @returns The execution result containing the outputs of the utility function.
315
494
  */
316
- async #simulateUtility(
495
+ async #executeUtility(
317
496
  contractFunctionSimulator: ContractFunctionSimulator,
318
497
  call: FunctionCall,
319
- authWitnesses?: AuthWitness[],
320
- scopes?: AztecAddress[],
498
+ authWitnesses: AuthWitness[] | undefined,
499
+ scopes: AztecAddress[],
500
+ jobId: string,
321
501
  ) {
322
502
  try {
323
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
503
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
504
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
505
+ call,
506
+ authWitnesses ?? [],
507
+ anchorBlockHeader,
508
+ scopes,
509
+ jobId,
510
+ );
511
+ return { result, offchainEffects };
324
512
  } catch (err) {
325
513
  if (err instanceof SimulationError) {
326
- await enrichSimulationError(err, this.contractDataProvider, this.log);
514
+ await enrichSimulationError(err, this.contractStore, this.log);
327
515
  }
328
516
  throw err;
329
517
  }
@@ -335,11 +523,11 @@ export class PXE {
335
523
  * It can also be used for estimating gas in the future.
336
524
  * @param tx - The transaction to be simulated.
337
525
  */
338
- async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
526
+ async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean, overrides?: SimulationOverrides) {
339
527
  // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
340
528
  // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
341
529
  try {
342
- const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
530
+ const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
343
531
  if (result.revertReason) {
344
532
  throw result.revertReason;
345
533
  }
@@ -347,7 +535,7 @@ export class PXE {
347
535
  } catch (err) {
348
536
  if (err instanceof SimulationError) {
349
537
  try {
350
- await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
538
+ await enrichPublicSimulationError(err, this.contractStore, this.log);
351
539
  } catch (enrichErr) {
352
540
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
353
541
  }
@@ -371,87 +559,68 @@ export class PXE {
371
559
  txExecutionRequest: TxExecutionRequest,
372
560
  proofCreator: PrivateKernelProver,
373
561
  privateExecutionResult: PrivateExecutionResult,
562
+ anchorBlockHeader: BlockHeader,
374
563
  config: PrivateKernelExecutionProverConfig,
375
564
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
376
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
377
- const kernelOracle = new PrivateKernelOracleImpl(
378
- this.contractDataProvider,
379
- this.keyStore,
380
- this.node,
381
- simulationAnchorBlock,
565
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
566
+ const kernelTraceProver = new PrivateKernelExecutionProver(
567
+ kernelOracle,
568
+ proofCreator,
569
+ !this.proverEnabled,
570
+ this.log.getBindings(),
382
571
  );
383
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
384
572
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
385
573
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
386
574
  }
387
575
 
576
+ /**
577
+ * Syncs with the node only when `autoSync` is enabled.
578
+ * When `autoSync` is disabled, callers (typically a wallet) are
579
+ * responsible for invoking `pxe.sync()` at the right granularity.
580
+ */
581
+ async #maybeSync(): Promise<void> {
582
+ if (this.autoSync) {
583
+ await this.blockStateSynchronizer.sync();
584
+ }
585
+ }
586
+
388
587
  // Public API
389
588
 
390
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
391
- return this.contractDataProvider.getContractInstance(address);
589
+ /**
590
+ * Triggers a sync of PXE state with the node, regardless of the `autoSync` config flag. Use this to
591
+ * batch syncs across composite flows when `autoSync` is disabled (e.g. one sync per simulate+send
592
+ * instead of one per inner PXE call). Serialized through the job queue.
593
+ */
594
+ public sync(): Promise<void> {
595
+ return this.#putInJobQueue(() => this.blockStateSynchronizer.sync());
392
596
  }
393
597
 
394
598
  /**
395
- * Returns the contract class metadata given a contract class id.
396
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
397
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
398
- * @param id - Identifier of the class.
399
- * @param includeArtifact - Identifier of the class.
400
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
401
- * for `includeArtifact`
402
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
403
- * should the pxe query the node for contract public info, and merge it with its own definitions?
404
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
405
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
406
- * do for the time being.
599
+ * Returns the block header up to which the PXE has synced.
600
+ * @returns The synced block header
407
601
  */
408
- public async getContractClassMetadata(
409
- id: Fr,
410
- includeArtifact: boolean = false,
411
- ): Promise<{
412
- contractClass: ContractClassWithId | undefined;
413
- isContractClassPubliclyRegistered: boolean;
414
- artifact: ContractArtifact | undefined;
415
- }> {
416
- const artifact = await this.contractDataProvider.getContractArtifact(id);
417
- if (!artifact) {
418
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
419
- }
602
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
603
+ return this.#putInJobQueue(() => {
604
+ return this.anchorBlockStore.getBlockHeader();
605
+ });
606
+ }
420
607
 
421
- return {
422
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
423
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
424
- artifact: includeArtifact ? artifact : undefined,
425
- };
608
+ /**
609
+ * Returns the contract instance for a given address, if it's registered in the PXE.
610
+ * @param address - The contract address.
611
+ * @returns The contract instance if found, undefined otherwise.
612
+ */
613
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
614
+ return this.contractStore.getContractInstance(address);
426
615
  }
427
616
 
428
617
  /**
429
- * Returns the contract metadata given an address.
430
- * The metadata consists of its contract instance, which includes the contract class identifier,
431
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
432
- * and whether the contract instance with the given address has been publicly deployed.
433
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
434
- * This query is not dependent on the PXE.
435
- * @param address - The address that the contract instance resides at.
436
- * @returns - It returns the contract metadata
437
- * TODO(@spalladino): Should we return the public keys in plain as well here?
618
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
619
+ * @param id - Identifier of the contract class.
620
+ * @returns The contract artifact if found, undefined otherwise.
438
621
  */
439
- public async getContractMetadata(address: AztecAddress): Promise<{
440
- contractInstance: ContractInstanceWithAddress | undefined;
441
- isContractInitialized: boolean;
442
- isContractPublished: boolean;
443
- }> {
444
- let instance;
445
- try {
446
- instance = await this.contractDataProvider.getContractInstance(address);
447
- } catch {
448
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
449
- }
450
- return {
451
- contractInstance: instance,
452
- isContractInitialized: await this.#isContractInitialized(address),
453
- isContractPublished: await this.#isContractPublished(address),
454
- };
622
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
623
+ return await this.contractStore.getContractArtifact(id);
455
624
  }
456
625
 
457
626
  /**
@@ -467,7 +636,7 @@ export class PXE {
467
636
  public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
468
637
  const accounts = await this.keyStore.getAccounts();
469
638
  const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
470
- if (accounts.includes(accountCompleteAddress.address)) {
639
+ if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
471
640
  this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
472
641
  return accountCompleteAddress;
473
642
  } else {
@@ -475,56 +644,66 @@ export class PXE {
475
644
  this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
476
645
  }
477
646
 
478
- await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
479
- await this.noteDataProvider.addScope(accountCompleteAddress.address);
647
+ await this.addressStore.addCompleteAddress(accountCompleteAddress);
480
648
  return accountCompleteAddress;
481
649
  }
482
650
 
483
651
  /**
484
- * Registers a user contact in PXE.
652
+ * Registers a sender in this PXE.
485
653
  *
486
- * Once a new contact is registered, the PXE will be able to receive notes tagged from this contact.
487
- * Will do nothing if the account is already registered.
654
+ * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
655
+ * Will do nothing if the address is already registered.
488
656
  *
489
- * @param address - Address of the user to add to the address book
490
- * @returns The address address of the account.
657
+ * @param sender - Address of the sender to register.
658
+ * @returns The address of the sender.
659
+ * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
491
660
  */
492
- public async registerSender(address: AztecAddress): Promise<AztecAddress> {
661
+ public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
662
+ if (!(await sender.isValid())) {
663
+ throw new Error(
664
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
665
+ );
666
+ }
667
+
493
668
  const accounts = await this.keyStore.getAccounts();
494
- if (accounts.includes(address)) {
495
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
496
- return address;
669
+ if (accounts.some(a => a.equals(sender))) {
670
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
671
+ return sender;
497
672
  }
498
673
 
499
- const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
674
+ const wasAdded = await this.senderAddressBookStore.addSender(sender);
500
675
 
501
676
  if (wasAdded) {
502
- this.log.info(`Added sender:\n ${address.toString()}`);
677
+ this.log.info(`Added sender:\n ${sender.toString()}`);
678
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
679
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
680
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
503
681
  } else {
504
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
682
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
505
683
  }
506
684
 
507
- return address;
685
+ return sender;
508
686
  }
509
687
 
510
688
  /**
511
- * Retrieves the addresses stored as senders on this PXE.
512
- * @returns An array of the senders on this PXE.
689
+ * Retrieves senders registered in this PXE.
690
+ * @returns Senders registered in this PXE.
513
691
  */
514
692
  public getSenders(): Promise<AztecAddress[]> {
515
- return this.taggingDataProvider.getSenderAddresses();
693
+ return this.senderAddressBookStore.getSenders();
516
694
  }
517
695
 
518
696
  /**
519
- * Removes a sender in the address book.
697
+ * Removes a sender registered in this PXE.
698
+ * @param sender - The address of the sender to remove.
520
699
  */
521
- public async removeSender(address: AztecAddress): Promise<void> {
522
- const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
700
+ public async removeSender(sender: AztecAddress): Promise<void> {
701
+ const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
523
702
 
524
703
  if (wasRemoved) {
525
- this.log.info(`Removed sender:\n ${address.toString()}`);
704
+ this.log.info(`Removed sender:\n ${sender.toString()}`);
526
705
  } else {
527
- this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
706
+ this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
528
707
  }
529
708
  }
530
709
 
@@ -534,7 +713,7 @@ export class PXE {
534
713
  */
535
714
  public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
536
715
  // Get complete addresses of both the recipients and the accounts
537
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
716
+ const completeAddresses = await this.addressStore.getCompleteAddresses();
538
717
  // Filter out the addresses not corresponding to accounts
539
718
  const accounts = await this.keyStore.getAccounts();
540
719
  return completeAddresses.filter(completeAddress =>
@@ -548,8 +727,7 @@ export class PXE {
548
727
  * @param artifact - The build artifact for the contract class.
549
728
  */
550
729
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
551
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
552
- await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
730
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
553
731
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
554
732
  }
555
733
 
@@ -568,25 +746,27 @@ export class PXE {
568
746
  if (artifact) {
569
747
  // If the user provides an artifact, validate it against the expected class id and register it
570
748
  const contractClass = await getContractClassFromArtifact(artifact);
571
- const contractClassId = contractClass.id;
572
- if (!contractClassId.equals(instance.currentContractClassId)) {
749
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
573
750
  throw new Error(
574
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
751
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
575
752
  );
576
753
  }
577
754
  const computedAddress = await computeContractAddressFromInstance(instance);
578
755
  if (!computedAddress.equals(instance.address)) {
579
756
  throw new Error('Added a contract in which the address does not match the contract instance.');
580
757
  }
581
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
758
+
759
+ await this.contractStore.addContractArtifact(artifact, contractClass);
582
760
 
583
761
  const publicFunctionSignatures = artifact.functions
584
762
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
585
763
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
586
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
764
+ if (publicFunctionSignatures.length > 0) {
765
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
766
+ }
587
767
  } else {
588
768
  // Otherwise, make sure there is an artifact already registered for that class id
589
- artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
769
+ artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
590
770
  if (!artifact) {
591
771
  throw new Error(
592
772
  `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
@@ -594,7 +774,7 @@ export class PXE {
594
774
  }
595
775
  }
596
776
 
597
- await this.contractDataProvider.addContractInstance(instance);
777
+ await this.contractStore.addContractInstance(instance);
598
778
  this.log.info(
599
779
  `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
600
780
  );
@@ -613,35 +793,32 @@ export class PXE {
613
793
  // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
614
794
  // class while we're simulating it.
615
795
  return this.#putInJobQueue(async () => {
616
- const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
796
+ const currentInstance = await this.contractStore.getContractInstance(contractAddress);
617
797
  if (!currentInstance) {
618
798
  throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
619
799
  }
620
800
  const contractClass = await getContractClassFromArtifact(artifact);
621
- await this.synchronizer.sync();
801
+ await this.#maybeSync();
622
802
 
623
- const header = await this.syncDataProvider.getBlockHeader();
803
+ const header = await this.anchorBlockStore.getBlockHeader();
624
804
 
625
- const currentClassId = await readCurrentClassId(
626
- contractAddress,
627
- currentInstance,
628
- this.node,
629
- header.globalVariables.blockNumber,
630
- header.globalVariables.timestamp,
631
- );
805
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
632
806
  if (!contractClass.id.equals(currentClassId)) {
633
807
  throw new Error('Could not update contract to a class different from the current one.');
634
808
  }
635
809
 
636
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
637
-
638
810
  const publicFunctionSignatures = artifact.functions
639
811
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
640
812
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
641
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
813
+ if (publicFunctionSignatures.length > 0) {
814
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
815
+ }
642
816
 
643
817
  currentInstance.currentContractClassId = contractClass.id;
644
- await this.contractDataProvider.addContractInstance(currentInstance);
818
+ await Promise.all([
819
+ this.contractStore.addContractArtifact(artifact, contractClass),
820
+ this.contractStore.addContractInstance(currentInstance),
821
+ ]);
645
822
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
646
823
  });
647
824
  }
@@ -651,39 +828,7 @@ export class PXE {
651
828
  * @returns An array of contracts addresses registered on this PXE.
652
829
  */
653
830
  public getContracts(): Promise<AztecAddress[]> {
654
- return this.contractDataProvider.getContractsAddresses();
655
- }
656
-
657
- /**
658
- * A debugging utility to get notes based on the provided filter.
659
- *
660
- * Note that this should not be used in production code because the structure of notes is considered to be
661
- * an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
662
- * note-related information in production code, please implement a custom utility function on your contract and call
663
- * that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
664
- *
665
- * @param filter - The filter to apply to the notes.
666
- * @returns The requested notes.
667
- */
668
- public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
669
- // We need to manually trigger private state sync to have a guarantee that all the notes are available.
670
- await this.simulateUtility('sync_private_state', [], filter.contractAddress);
671
-
672
- const noteDaos = await this.noteDataProvider.getNotes(filter);
673
-
674
- const uniqueNotes = noteDaos.map(async dao => {
675
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
676
- const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
677
- completeAddress.address.equals(dao.recipient),
678
- );
679
- const completeAddress = completeAddresses[completeAddressIndex];
680
- if (completeAddress === undefined) {
681
- throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
682
- }
683
- const recipient = completeAddress.address;
684
- return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
685
- });
686
- return Promise.all(uniqueNotes);
831
+ return this.contractStore.getContractsAddresses();
687
832
  }
688
833
 
689
834
  /**
@@ -691,29 +836,38 @@ export class PXE {
691
836
  * (where validators prove the public portion).
692
837
  *
693
838
  * @param txRequest - An authenticated tx request ready for proving
839
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
694
840
  * @returns A result containing the proof and public inputs of the tail circuit.
695
841
  * @throws If contract code not found, or public simulation reverts.
696
842
  * Also throws if simulatePublic is true and public simulation reverts.
697
843
  */
698
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
844
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
699
845
  let privateExecutionResult: PrivateExecutionResult;
700
846
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
701
847
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
702
- return this.#putInJobQueue(async () => {
848
+ return this.#putInJobQueue(async jobId => {
703
849
  const totalTimer = new Timer();
704
850
  try {
705
851
  const syncTimer = new Timer();
706
- await this.synchronizer.sync();
852
+ await this.#maybeSync();
853
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
707
854
  const syncTime = syncTimer.ms();
708
855
  const contractFunctionSimulator = this.#getSimulatorForTx();
709
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
856
+ privateExecutionResult = await this.#executePrivate({
857
+ contractFunctionSimulator,
858
+ txRequest,
859
+ anchorBlockHeader,
860
+ scopes,
861
+ jobId,
862
+ senderForTags,
863
+ });
710
864
 
711
865
  const {
712
866
  publicInputs,
713
867
  chonkProof,
714
868
  executionSteps,
715
869
  timings: { proving } = {},
716
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
870
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
717
871
  simulate: false,
718
872
  skipFeeEnforcement: false,
719
873
  profileMode: 'none',
@@ -743,15 +897,20 @@ export class PXE {
743
897
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
744
898
  });
745
899
 
746
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
747
- if (preTagsUsedInTheTx.length > 0) {
748
- await this.taggingDataProvider.setLastUsedIndexesAsSender(preTagsUsedInTheTx);
749
- this.log.debug(`Stored used pre tags as sender for the tx`, {
750
- preTagsUsedInTheTx,
751
- });
752
- } else {
753
- this.log.debug(`No pre tags used in the tx`);
754
- }
900
+ // We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
901
+ // (which would link them) without having to rely on this tx being mined (and us seeing the indices being used
902
+ // onchain).
903
+ // Note that this must happen _after_ proving as it requires the proof's public inputs, from which the kernels
904
+ // may have removed some logs due to note-nullifier squashing - this may lead to range of tagging indices we've
905
+ // actually used to being reduced.
906
+ await persistSenderTaggingIndexRangesForTx(
907
+ this.senderTaggingStore,
908
+ privateExecutionResult.entrypoint.taggingIndexRanges,
909
+ publicInputs,
910
+ () => txProvingResult.getTxHash(),
911
+ jobId,
912
+ this.log,
913
+ );
755
914
 
756
915
  return txProvingResult;
757
916
  } catch (err: any) {
@@ -762,20 +921,16 @@ export class PXE {
762
921
 
763
922
  /**
764
923
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
765
- *
766
- * @param txRequest - An authenticated tx request ready for simulation
767
- * @param msgSender - (Optional) The message sender to use for the simulation.
768
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
924
+ * @param txRequest - An authenticated tx request ready for simulation.
769
925
  * @returns A trace of the program execution with gate counts.
770
926
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
771
927
  */
772
928
  public profileTx(
773
929
  txRequest: TxExecutionRequest,
774
- profileMode: 'full' | 'execution-steps' | 'gates',
775
- skipProofGeneration: boolean = true,
930
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
776
931
  ): Promise<TxProfileResult> {
777
932
  // We disable concurrent profiles for consistency with simulateTx.
778
- return this.#putInJobQueue(async () => {
933
+ return this.#putInJobQueue(async jobId => {
779
934
  const totalTimer = new Timer();
780
935
  try {
781
936
  const txInfo = {
@@ -791,16 +946,25 @@ export class PXE {
791
946
  txInfo,
792
947
  );
793
948
  const syncTimer = new Timer();
794
- await this.synchronizer.sync();
949
+ await this.#maybeSync();
950
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
795
951
  const syncTime = syncTimer.ms();
796
952
 
797
953
  const contractFunctionSimulator = this.#getSimulatorForTx();
798
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
954
+ const privateExecutionResult = await this.#executePrivate({
955
+ contractFunctionSimulator,
956
+ txRequest,
957
+ anchorBlockHeader,
958
+ scopes,
959
+ jobId,
960
+ senderForTags,
961
+ });
799
962
 
800
963
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
801
964
  txRequest,
802
965
  this.proofCreator,
803
966
  privateExecutionResult,
967
+ anchorBlockHeader,
804
968
  {
805
969
  simulate: skipProofGeneration,
806
970
  skipFeeEnforcement: false,
@@ -852,12 +1016,7 @@ export class PXE {
852
1016
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
853
1017
  *
854
1018
  *
855
- * @param txRequest - An authenticated tx request ready for simulation
856
- * @param simulatePublic - Whether to simulate the public part of the transaction.
857
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
858
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
859
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
860
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
1019
+ * @param txRequest - An authenticated tx request ready for simulation.
861
1020
  * @returns A simulated transaction result object that includes public and private return values.
862
1021
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
863
1022
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -866,16 +1025,20 @@ export class PXE {
866
1025
  */
867
1026
  public simulateTx(
868
1027
  txRequest: TxExecutionRequest,
869
- simulatePublic: boolean,
870
- skipTxValidation: boolean = false,
871
- skipFeeEnforcement: boolean = false,
872
- overrides?: SimulationOverrides,
873
- scopes?: AztecAddress[],
1028
+ {
1029
+ simulatePublic,
1030
+ skipTxValidation = false,
1031
+ skipFeeEnforcement = false,
1032
+ skipKernels = true,
1033
+ overrides,
1034
+ scopes,
1035
+ senderForTags,
1036
+ }: SimulateTxOpts,
874
1037
  ): Promise<TxSimulationResult> {
875
1038
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
876
1039
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
877
1040
  // delete the same read value, or reading values that another simulation is currently modifying).
878
- return this.#putInJobQueue(async () => {
1041
+ return this.#putInJobQueue(async jobId => {
879
1042
  try {
880
1043
  const totalTimer = new Timer();
881
1044
  const txInfo = {
@@ -891,40 +1054,49 @@ export class PXE {
891
1054
  txInfo,
892
1055
  );
893
1056
  const syncTimer = new Timer();
894
- await this.synchronizer.sync();
1057
+ await this.#maybeSync();
1058
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
895
1059
  const syncTime = syncTimer.ms();
896
1060
 
1061
+ if (overrides?.contracts && Object.keys(overrides.contracts).length > 0 && !skipKernels) {
1062
+ throw new Error(
1063
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
1064
+ );
1065
+ }
897
1066
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
898
- // Temporary: in case there are overrides, we have to skip the kernels or validations
899
- // will fail. Consider handing control to the user/wallet on whether they want to run them
900
- // or not.
901
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
902
1067
 
903
1068
  // Execution of private functions only; no proving, and no kernel logic.
904
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
1069
+ const privateExecutionResult = await this.#executePrivate({
1070
+ contractFunctionSimulator,
1071
+ txRequest,
1072
+ anchorBlockHeader,
1073
+ scopes,
1074
+ jobId,
1075
+ senderForTags,
1076
+ });
905
1077
 
906
1078
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
907
1079
  let executionSteps: PrivateExecutionStep[] = [];
908
1080
 
909
1081
  if (skipKernels) {
910
- // According to the protocol rules, the nonce generator for the note hashes
911
- // can either be the first nullifier in the tx or the hash of the initial tx request
912
- // if there are none.
913
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
914
- ? await txRequest.toTxRequest().hash()
915
- : privateExecutionResult.firstNullifier;
916
1082
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
917
1083
  privateExecutionResult,
918
- nonceGenerator,
919
- this.contractDataProvider,
1084
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
1085
+ this.node,
920
1086
  ));
921
1087
  } else {
922
1088
  // Kernel logic, plus proving of all private functions and kernels.
923
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
924
- simulate: true,
925
- skipFeeEnforcement,
926
- profileMode: 'none',
927
- }));
1089
+ ({ publicInputs, executionSteps } = await this.#prove(
1090
+ txRequest,
1091
+ this.proofCreator,
1092
+ privateExecutionResult,
1093
+ anchorBlockHeader,
1094
+ {
1095
+ simulate: true,
1096
+ skipFeeEnforcement,
1097
+ profileMode: 'none',
1098
+ },
1099
+ ));
928
1100
  }
929
1101
 
930
1102
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -933,8 +1105,11 @@ export class PXE {
933
1105
  let publicOutput: PublicSimulationOutput | undefined;
934
1106
  if (simulatePublic && publicInputs.forPublic) {
935
1107
  const publicSimulationTimer = new Timer();
936
- publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
1108
+ publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
937
1109
  publicSimulationTime = publicSimulationTimer.ms();
1110
+ if (publicOutput?.debugLogs?.length) {
1111
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
1112
+ }
938
1113
  }
939
1114
 
940
1115
  let validationTime: number | undefined;
@@ -943,7 +1118,8 @@ export class PXE {
943
1118
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
944
1119
  validationTime = validationTimer.ms();
945
1120
  if (validationResult.result === 'invalid') {
946
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1121
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1122
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
947
1123
  }
948
1124
  }
949
1125
 
@@ -994,55 +1170,55 @@ export class PXE {
994
1170
  inspect(txRequest),
995
1171
  `simulatePublic=${simulatePublic}`,
996
1172
  `skipTxValidation=${skipTxValidation}`,
997
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1173
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
998
1174
  );
999
1175
  }
1000
1176
  });
1001
1177
  }
1002
1178
 
1003
1179
  /**
1004
- * Simulate the execution of a contract utility function.
1005
- *
1006
- * @param functionName - The name of the utility contract function to be called.
1007
- * @param args - The arguments to be provided to the function.
1008
- * @param to - The address of the contract to be called.
1009
- * @param authwits - (Optional) The authentication witnesses required for the function call.
1010
- * @param from - (Optional) The msg sender to set for the call.
1011
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
- * default to all.
1013
- * @returns The result of the utility function call, structured based on the function ABI.
1180
+ * Executes a contract utility function.
1181
+ * @param call - The function call containing the function details, arguments, and target contract address.
1014
1182
  */
1015
- public simulateUtility(
1016
- functionName: string,
1017
- args: any[],
1018
- to: AztecAddress,
1019
- authwits?: AuthWitness[],
1020
- _from?: AztecAddress,
1021
- scopes?: AztecAddress[],
1022
- ): Promise<UtilitySimulationResult> {
1023
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1183
+ public executeUtility(
1184
+ call: FunctionCall,
1185
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1186
+ ): Promise<UtilityExecutionResult> {
1187
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1024
1188
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1025
- // delete the same read value, or reading values that another simulation is currently modifying).
1026
- return this.#putInJobQueue(async () => {
1189
+ // delete the same read value, or reading values that another execution is currently modifying).
1190
+ return this.#putInJobQueue(async jobId => {
1027
1191
  try {
1028
1192
  const totalTimer = new Timer();
1029
1193
  const syncTimer = new Timer();
1030
- await this.synchronizer.sync();
1194
+ await this.#maybeSync();
1031
1195
  const syncTime = syncTimer.ms();
1032
- const functionCall = await this.#getFunctionCall(functionName, args, to);
1033
1196
  const functionTimer = new Timer();
1034
1197
  const contractFunctionSimulator = this.#getSimulatorForTx();
1035
- const executionResult = await this.#simulateUtility(
1198
+
1199
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1200
+ await this.contractSyncService.ensureContractSynced(
1201
+ call.to,
1202
+ call.selector,
1203
+ (privateSyncCall, execScopes) =>
1204
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1205
+ anchorBlockHeader,
1206
+ jobId,
1207
+ scopes,
1208
+ );
1209
+
1210
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1036
1211
  contractFunctionSimulator,
1037
- functionCall,
1212
+ call,
1038
1213
  authwits ?? [],
1039
1214
  scopes,
1215
+ jobId,
1040
1216
  );
1041
1217
  const functionTime = functionTimer.ms();
1042
1218
 
1043
1219
  const totalTime = totalTimer.ms();
1044
1220
 
1045
- const perFunction = [{ functionName, time: functionTime }];
1221
+ const perFunction = [{ functionName: call.name, time: functionTime }];
1046
1222
 
1047
1223
  const timings: SimulationTimings = {
1048
1224
  total: totalTime,
@@ -1052,13 +1228,19 @@ export class PXE {
1052
1228
  };
1053
1229
 
1054
1230
  const simulationStats = contractFunctionSimulator.getStats();
1055
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1231
+ return {
1232
+ result: executionResult,
1233
+ offchainEffects,
1234
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1235
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1236
+ };
1056
1237
  } catch (err: any) {
1238
+ const { to, name, args } = call;
1057
1239
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1058
1240
  throw this.#contextualizeError(
1059
1241
  err,
1060
- `simulateUtility ${to}:${functionName}(${stringifiedArgs})`,
1061
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1242
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1243
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1062
1244
  );
1063
1245
  }
1064
1246
  });
@@ -1066,48 +1248,58 @@ export class PXE {
1066
1248
 
1067
1249
  /**
1068
1250
  * Returns the private events given search parameters.
1069
- * @param contractAddress - The address of the contract to get events from.
1070
- * @param eventMetadata - Metadata of the event. This should be the class generated from the contract. e.g. Contract.events.Event
1071
- * @param from - The block number to search from.
1072
- * @param numBlocks - The amount of blocks to search.
1073
- * @param recipients - The addresses that decrypted the logs.
1074
- * @returns - The deserialized events.
1251
+ * @param eventSelector - Event selector to search for.
1252
+ * @param filter
1253
+ * contractAddress - The address of the contract to get events from. Required.
1254
+ * scopes - One or more event scope addresses to filter by. Required.
1255
+ * fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
1256
+ * Defaults to 0.
1257
+ * If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
1258
+ * toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
1259
+ * Defaults to the latest known block to PXE + 1.
1260
+ * @returns - The packed events with block and tx metadata.
1075
1261
  */
1076
- public async getPrivateEvents<T>(
1077
- contractAddress: AztecAddress,
1078
- eventMetadataDef: EventMetadataDefinition,
1079
- from: number,
1080
- numBlocks: number,
1081
- recipients: AztecAddress[],
1082
- ): Promise<T[]> {
1083
- if (recipients.length === 0) {
1084
- throw new Error('Recipients are required to get private events');
1085
- }
1086
-
1087
- this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
1088
-
1089
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
1090
- await this.simulateUtility('sync_private_state', [], contractAddress);
1262
+ public async getPrivateEvents(
1263
+ eventSelector: EventSelector,
1264
+ filter: PrivateEventFilter,
1265
+ ): Promise<PackedPrivateEvent[]> {
1266
+ let anchorBlockNumber: BlockNumber;
1267
+
1268
+ await this.#putInJobQueue(async jobId => {
1269
+ await this.#maybeSync();
1270
+
1271
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1272
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1273
+
1274
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1275
+
1276
+ await this.contractSyncService.ensureContractSynced(
1277
+ filter.contractAddress,
1278
+ null,
1279
+ async (privateSyncCall, execScopes) =>
1280
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1281
+ anchorBlockHeader,
1282
+ jobId,
1283
+ filter.scopes,
1284
+ );
1285
+ });
1091
1286
 
1092
- const events = await this.privateEventDataProvider.getPrivateEvents(
1093
- contractAddress,
1094
- from,
1095
- numBlocks,
1096
- recipients,
1097
- eventMetadataDef.eventSelector,
1098
- );
1287
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1288
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1099
1289
 
1100
- const decodedEvents = events.map(
1101
- (event: PrivateEvent): T => decodeFromAbi([eventMetadataDef.abiType], event.msgContent) as T,
1290
+ this.log.debug(
1291
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1102
1292
  );
1103
1293
 
1104
- return decodedEvents;
1294
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1105
1295
  }
1106
1296
 
1107
1297
  /**
1108
- * Stops the PXE's job queue.
1298
+ * Stops the PXE's job queue and closes the backing store.
1109
1299
  */
1110
- public stop(): Promise<void> {
1111
- return this.jobQueue.end();
1300
+ public async stop(): Promise<void> {
1301
+ await this.jobQueue.end();
1302
+ await this.blockStateSynchronizer.stop();
1303
+ await this.db.close();
1112
1304
  }
1113
1305
  }