@aztec/pxe 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065

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 (503) hide show
  1. package/dest/bin/check_oracle_version.js +45 -111
  2. package/dest/bin/index.d.ts +2 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +1 -0
  5. package/dest/bin/oracle_version_helpers.d.ts +51 -0
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -0
  7. package/dest/bin/oracle_version_helpers.js +254 -0
  8. package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
  9. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
  10. package/dest/block_synchronizer/block_stream_source.js +37 -0
  11. package/dest/block_synchronizer/block_synchronizer.d.ts +24 -14
  12. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  13. package/dest/block_synchronizer/block_synchronizer.js +92 -30
  14. package/dest/config/index.d.ts +9 -2
  15. package/dest/config/index.d.ts.map +1 -1
  16. package/dest/config/index.js +14 -15
  17. package/dest/config/package_info.js +1 -1
  18. package/dest/contract/contract_class_service.d.ts +31 -0
  19. package/dest/contract/contract_class_service.d.ts.map +1 -0
  20. package/dest/contract/contract_class_service.js +68 -0
  21. package/dest/contract/contract_sync_service.d.ts +48 -0
  22. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  23. package/dest/contract/contract_sync_service.js +116 -0
  24. package/dest/contract/helpers.d.ts +7 -0
  25. package/dest/contract/helpers.d.ts.map +1 -0
  26. package/dest/contract/helpers.js +20 -0
  27. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  28. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  29. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  30. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
  31. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
  32. package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
  33. package/dest/contract_function_simulator/contract_function_simulator.d.ts +72 -36
  34. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/contract_function_simulator.js +265 -97
  36. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  37. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  38. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  39. package/dest/contract_function_simulator/execution_note_cache.d.ts +4 -10
  40. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/execution_note_cache.js +8 -28
  42. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -11
  43. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -15
  45. package/dest/contract_function_simulator/index.d.ts +26 -5
  46. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  47. package/dest/contract_function_simulator/index.js +12 -3
  48. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +29 -0
  49. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
  50. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +30 -0
  51. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  52. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  53. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  54. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  55. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  56. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  57. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts +37 -0
  58. package/dest/contract_function_simulator/noir-structs/ephemeral_array.d.ts.map +1 -0
  59. package/dest/contract_function_simulator/noir-structs/ephemeral_array.js +59 -0
  60. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -4
  61. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +9 -10
  63. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  64. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  65. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  66. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  67. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  68. package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
  69. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +19 -10
  70. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  71. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +12 -24
  72. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +11 -9
  73. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  74. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -63
  75. package/dest/contract_function_simulator/noir-structs/note_data.d.ts +27 -0
  76. package/dest/contract_function_simulator/noir-structs/note_data.d.ts.map +1 -0
  77. package/dest/contract_function_simulator/noir-structs/note_data.js +3 -0
  78. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -5
  79. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  80. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +8 -12
  81. package/dest/contract_function_simulator/noir-structs/option.d.ts +59 -0
  82. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
  83. package/dest/contract_function_simulator/noir-structs/option.js +67 -0
  84. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  85. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  86. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  87. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  88. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  89. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  90. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +8 -0
  91. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -0
  92. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -0
  93. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
  94. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  95. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +50 -0
  96. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
  97. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  98. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
  99. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
  100. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  101. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  102. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
  103. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  104. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
  105. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +21 -0
  106. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -0
  107. package/dest/contract_function_simulator/oracle/acir_callback.js +115 -0
  108. package/dest/contract_function_simulator/oracle/index.d.ts +2 -13
  109. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  110. package/dest/contract_function_simulator/oracle/index.js +1 -1
  111. package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -98
  112. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  113. package/dest/contract_function_simulator/oracle/interfaces.js +2 -2
  114. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  115. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  116. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
  117. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
  118. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  119. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
  120. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +2 -2
  121. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  122. package/dest/contract_function_simulator/oracle/note_packing_utils.js +2 -2
  123. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +138 -0
  124. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
  125. package/dest/contract_function_simulator/oracle/oracle_registry.js +1007 -0
  126. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +222 -0
  127. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -0
  128. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +1243 -0
  129. package/dest/contract_function_simulator/oracle/private_execution.d.ts +1 -1
  130. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  131. package/dest/contract_function_simulator/oracle/private_execution.js +7 -6
  132. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +82 -97
  133. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  134. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +257 -115
  135. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +206 -88
  136. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  137. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +592 -194
  138. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  139. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  140. package/dest/contract_function_simulator/pick_notes.js +20 -3
  141. package/dest/contract_function_simulator/transient_array_service.d.ts +31 -0
  142. package/dest/contract_function_simulator/transient_array_service.d.ts.map +1 -0
  143. package/dest/contract_function_simulator/transient_array_service.js +62 -0
  144. package/dest/contract_logging.d.ts +27 -0
  145. package/dest/contract_logging.d.ts.map +1 -0
  146. package/dest/contract_logging.js +38 -0
  147. package/dest/debug/pxe_debug_utils.d.ts +19 -10
  148. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  149. package/dest/debug/pxe_debug_utils.js +22 -18
  150. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  151. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  152. package/dest/entrypoints/client/bundle/index.js +2 -0
  153. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  154. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  155. package/dest/entrypoints/client/bundle/utils.js +39 -12
  156. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  157. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  158. package/dest/entrypoints/client/lazy/index.js +2 -0
  159. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  160. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  161. package/dest/entrypoints/client/lazy/utils.js +40 -13
  162. package/dest/entrypoints/pxe_creation_options.d.ts +18 -3
  163. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  164. package/dest/entrypoints/pxe_creation_options.js +3 -1
  165. package/dest/entrypoints/server/index.d.ts +7 -3
  166. package/dest/entrypoints/server/index.d.ts.map +1 -1
  167. package/dest/entrypoints/server/index.js +5 -2
  168. package/dest/entrypoints/server/utils.d.ts +4 -3
  169. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  170. package/dest/entrypoints/server/utils.js +47 -14
  171. package/dest/error_enriching.d.ts +5 -3
  172. package/dest/error_enriching.d.ts.map +1 -1
  173. package/dest/error_enriching.js +13 -11
  174. package/dest/events/event_service.d.ts +16 -8
  175. package/dest/events/event_service.d.ts.map +1 -1
  176. package/dest/events/event_service.js +46 -14
  177. package/dest/events/private_event_filter_validator.d.ts +3 -2
  178. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  179. package/dest/events/private_event_filter_validator.js +15 -0
  180. package/dest/hooks/authorize_utility_call.d.ts +41 -0
  181. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  182. package/dest/hooks/authorize_utility_call.js +4 -0
  183. package/dest/hooks/execution_hooks.d.ts +62 -0
  184. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  185. package/dest/hooks/execution_hooks.js +9 -0
  186. package/dest/hooks/index.d.ts +5 -0
  187. package/dest/hooks/index.d.ts.map +1 -0
  188. package/dest/hooks/index.js +2 -0
  189. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  190. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  191. package/dest/hooks/resolve_custom_request.js +3 -0
  192. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +50 -0
  193. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  194. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  195. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  196. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  197. package/dest/job_coordinator/job_coordinator.js +3 -2
  198. package/dest/logs/log_service.d.ts +16 -13
  199. package/dest/logs/log_service.d.ts.map +1 -1
  200. package/dest/logs/log_service.js +192 -97
  201. package/dest/messages/tx_resolver_service.d.ts +17 -0
  202. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  203. package/dest/messages/tx_resolver_service.js +55 -0
  204. package/dest/notes/note_service.d.ts +29 -8
  205. package/dest/notes/note_service.d.ts.map +1 -1
  206. package/dest/notes/note_service.js +89 -65
  207. package/dest/notes_filter.d.ts +24 -0
  208. package/dest/notes_filter.d.ts.map +1 -0
  209. package/dest/notes_filter.js +4 -0
  210. package/dest/oracle_version.d.ts +4 -3
  211. package/dest/oracle_version.d.ts.map +1 -1
  212. package/dest/oracle_version.js +20 -10
  213. package/dest/private_kernel/batch_planner.d.ts +47 -0
  214. package/dest/private_kernel/batch_planner.d.ts.map +1 -0
  215. package/dest/private_kernel/batch_planner.js +104 -0
  216. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  217. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  218. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  219. package/dest/private_kernel/hints/index.d.ts +1 -1
  220. package/dest/private_kernel/hints/index.js +1 -1
  221. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  222. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  223. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +135 -70
  224. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  225. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  226. package/dest/private_kernel/hints/test_utils.js +202 -0
  227. package/dest/private_kernel/private_kernel_execution_prover.d.ts +7 -2
  228. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  229. package/dest/private_kernel/private_kernel_execution_prover.js +165 -83
  230. package/dest/private_kernel/private_kernel_oracle.d.ts +17 -11
  231. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  232. package/dest/private_kernel/private_kernel_oracle.js +47 -29
  233. package/dest/pxe.d.ts +228 -66
  234. package/dest/pxe.d.ts.map +1 -1
  235. package/dest/pxe.js +411 -229
  236. package/dest/storage/address_store/address_store.d.ts +1 -1
  237. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  238. package/dest/storage/address_store/address_store.js +12 -11
  239. package/dest/storage/allowed_scopes.d.ts +6 -0
  240. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  241. package/dest/storage/allowed_scopes.js +7 -0
  242. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +12 -1
  243. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  244. package/dest/storage/anchor_block_store/anchor_block_store.js +12 -3
  245. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  246. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  247. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  248. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  249. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  250. package/dest/storage/backwards_compatibility_tests/schema_tests.js +671 -0
  251. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  252. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  253. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  254. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  255. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  256. package/dest/storage/capsule_store/capsule_service.js +47 -0
  257. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  258. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  259. package/dest/storage/capsule_store/capsule_store.js +42 -36
  260. package/dest/storage/capsule_store/index.d.ts +2 -1
  261. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  262. package/dest/storage/capsule_store/index.js +1 -0
  263. package/dest/storage/contract_store/contract_store.d.ts +63 -33
  264. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  265. package/dest/storage/contract_store/contract_store.js +192 -135
  266. package/dest/storage/fact_store/fact_service.d.ts +22 -0
  267. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  268. package/dest/storage/fact_store/fact_service.js +45 -0
  269. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  270. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  271. package/dest/storage/fact_store/fact_store.js +408 -0
  272. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  273. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  274. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  275. package/dest/storage/fact_store/index.d.ts +6 -0
  276. package/dest/storage/fact_store/index.d.ts.map +1 -0
  277. package/dest/storage/fact_store/index.js +4 -0
  278. package/dest/storage/fact_store/origin_state.d.ts +57 -0
  279. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  280. package/dest/storage/fact_store/origin_state.js +53 -0
  281. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  282. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  283. package/dest/storage/fact_store/stored_fact.js +64 -0
  284. package/dest/storage/index.d.ts +3 -2
  285. package/dest/storage/index.d.ts.map +1 -1
  286. package/dest/storage/index.js +2 -1
  287. package/dest/storage/metadata.d.ts +2 -2
  288. package/dest/storage/metadata.d.ts.map +1 -1
  289. package/dest/storage/metadata.js +1 -1
  290. package/dest/storage/note_store/note_store.d.ts +48 -29
  291. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  292. package/dest/storage/note_store/note_store.js +261 -192
  293. package/dest/storage/note_store/stored_note.d.ts +3 -8
  294. package/dest/storage/note_store/stored_note.d.ts.map +1 -1
  295. package/dest/storage/note_store/stored_note.js +4 -20
  296. package/dest/storage/open_pxe_stores.d.ts +35 -0
  297. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  298. package/dest/storage/open_pxe_stores.js +29 -0
  299. package/dest/storage/private_event_store/private_event_store.d.ts +13 -16
  300. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  301. package/dest/storage/private_event_store/private_event_store.js +102 -79
  302. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  303. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  304. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  305. package/dest/storage/tagging_store/index.d.ts +2 -2
  306. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  307. package/dest/storage/tagging_store/index.js +1 -1
  308. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  309. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  310. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  311. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  312. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  313. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  314. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  315. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  316. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
  317. package/dest/tagging/constants.d.ts +2 -2
  318. package/dest/tagging/constants.d.ts.map +1 -1
  319. package/dest/tagging/constants.js +18 -9
  320. package/dest/tagging/get_all_logs_by_tags.d.ts +35 -11
  321. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  322. package/dest/tagging/get_all_logs_by_tags.js +45 -32
  323. package/dest/tagging/index.d.ts +6 -5
  324. package/dest/tagging/index.d.ts.map +1 -1
  325. package/dest/tagging/index.js +4 -3
  326. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  327. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  328. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  329. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +69 -0
  330. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  331. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +203 -0
  332. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +3 -3
  333. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -1
  334. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  335. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  336. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  337. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  338. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -10
  339. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  340. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +32 -14
  341. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +13 -7
  342. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  343. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +41 -10
  344. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  345. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  346. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +37 -25
  347. package/package.json +29 -17
  348. package/src/bin/check_oracle_version.ts +51 -133
  349. package/src/bin/index.ts +5 -0
  350. package/src/bin/oracle_version_helpers.ts +311 -0
  351. package/src/block_synchronizer/block_stream_source.ts +42 -0
  352. package/src/block_synchronizer/block_synchronizer.ts +117 -50
  353. package/src/config/index.ts +16 -9
  354. package/src/config/package_info.ts +1 -1
  355. package/src/contract/contract_class_service.ts +83 -0
  356. package/src/contract/contract_sync_service.ts +176 -0
  357. package/src/contract/helpers.ts +35 -0
  358. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  359. package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
  360. package/src/contract_function_simulator/contract_function_simulator.ts +466 -159
  361. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  362. package/src/contract_function_simulator/execution_note_cache.ts +8 -29
  363. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -18
  364. package/src/contract_function_simulator/index.ts +69 -4
  365. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +43 -0
  366. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  367. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  368. package/src/contract_function_simulator/noir-structs/ephemeral_array.ts +66 -0
  369. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -9
  370. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  371. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  372. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -20
  373. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +14 -64
  374. package/src/contract_function_simulator/noir-structs/note_data.ts +27 -0
  375. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -11
  376. package/src/contract_function_simulator/noir-structs/option.ts +75 -0
  377. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  378. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  379. package/src/contract_function_simulator/noir-structs/provided_secret.ts +5 -0
  380. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
  381. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
  382. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
  383. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  384. package/src/contract_function_simulator/oracle/acir_callback.ts +154 -0
  385. package/src/contract_function_simulator/oracle/index.ts +1 -15
  386. package/src/contract_function_simulator/oracle/interfaces.ts +11 -176
  387. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  388. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  389. package/src/contract_function_simulator/oracle/note_packing_utils.ts +3 -3
  390. package/src/contract_function_simulator/oracle/oracle_registry.ts +706 -0
  391. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +964 -0
  392. package/src/contract_function_simulator/oracle/private_execution.ts +6 -7
  393. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +315 -219
  394. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +921 -276
  395. package/src/contract_function_simulator/pick_notes.ts +22 -3
  396. package/src/contract_function_simulator/transient_array_service.ts +91 -0
  397. package/src/contract_logging.ts +52 -0
  398. package/src/debug/pxe_debug_utils.ts +55 -19
  399. package/src/entrypoints/client/bundle/index.ts +2 -0
  400. package/src/entrypoints/client/bundle/utils.ts +34 -21
  401. package/src/entrypoints/client/lazy/index.ts +2 -0
  402. package/src/entrypoints/client/lazy/utils.ts +36 -22
  403. package/src/entrypoints/pxe_creation_options.ts +23 -2
  404. package/src/entrypoints/server/index.ts +7 -2
  405. package/src/entrypoints/server/utils.ts +46 -33
  406. package/src/error_enriching.ts +27 -11
  407. package/src/events/event_service.ts +70 -24
  408. package/src/events/private_event_filter_validator.ts +21 -1
  409. package/src/hooks/authorize_utility_call.ts +44 -0
  410. package/src/hooks/execution_hooks.ts +68 -0
  411. package/src/hooks/index.ts +13 -0
  412. package/src/hooks/resolve_custom_request.ts +24 -0
  413. package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
  414. package/src/job_coordinator/job_coordinator.ts +4 -3
  415. package/src/logs/log_service.ts +236 -165
  416. package/src/messages/tx_resolver_service.ts +69 -0
  417. package/src/notes/note_service.ts +124 -91
  418. package/src/notes_filter.ts +24 -0
  419. package/src/oracle_version.ts +20 -10
  420. package/src/private_kernel/batch_planner.ts +169 -0
  421. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  422. package/src/private_kernel/hints/index.ts +1 -1
  423. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +176 -119
  424. package/src/private_kernel/hints/test_utils.ts +318 -0
  425. package/src/private_kernel/private_kernel_execution_prover.ts +257 -119
  426. package/src/private_kernel/private_kernel_oracle.ts +65 -36
  427. package/src/pxe.ts +712 -303
  428. package/src/storage/address_store/address_store.ts +15 -15
  429. package/src/storage/allowed_scopes.ts +14 -0
  430. package/src/storage/anchor_block_store/anchor_block_store.ts +12 -2
  431. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  432. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  433. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  434. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  435. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  436. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  437. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +40 -0
  438. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +56 -0
  439. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  440. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +26 -0
  441. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +30 -0
  442. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  443. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +117 -0
  444. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  445. package/src/storage/backwards_compatibility_tests/schema_tests.ts +803 -0
  446. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  447. package/src/storage/capsule_store/capsule_service.ts +85 -0
  448. package/src/storage/capsule_store/capsule_store.ts +52 -34
  449. package/src/storage/capsule_store/index.ts +1 -0
  450. package/src/storage/contract_store/contract_store.ts +249 -167
  451. package/src/storage/fact_store/fact_service.ts +69 -0
  452. package/src/storage/fact_store/fact_store.ts +487 -0
  453. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  454. package/src/storage/fact_store/index.ts +14 -0
  455. package/src/storage/fact_store/origin_state.ts +75 -0
  456. package/src/storage/fact_store/stored_fact.ts +80 -0
  457. package/src/storage/index.ts +2 -1
  458. package/src/storage/metadata.ts +1 -1
  459. package/src/storage/note_store/note_store.ts +297 -224
  460. package/src/storage/note_store/stored_note.ts +5 -27
  461. package/src/storage/open_pxe_stores.ts +52 -0
  462. package/src/storage/private_event_store/private_event_store.ts +127 -108
  463. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  464. package/src/storage/tagging_store/index.ts +1 -1
  465. package/src/storage/tagging_store/recipient_tagging_store.ts +34 -24
  466. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  467. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  468. package/src/tagging/constants.ts +19 -9
  469. package/src/tagging/get_all_logs_by_tags.ts +90 -38
  470. package/src/tagging/index.ts +5 -4
  471. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  472. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +301 -0
  473. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +4 -4
  474. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  475. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +54 -19
  476. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -14
  477. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -30
  478. package/dest/contract_function_simulator/oracle/oracle.d.ts +0 -60
  479. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +0 -1
  480. package/dest/contract_function_simulator/oracle/oracle.js +0 -356
  481. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  482. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  483. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -80
  484. package/dest/contract_sync/index.d.ts +0 -23
  485. package/dest/contract_sync/index.d.ts.map +0 -1
  486. package/dest/contract_sync/index.js +0 -54
  487. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  488. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  489. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  490. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  491. package/dest/storage/tagging_store/sender_address_book_store.js +0 -30
  492. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -15
  493. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
  494. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
  495. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -15
  496. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
  497. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -32
  498. package/src/contract_function_simulator/oracle/oracle.ts +0 -620
  499. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -83
  500. package/src/contract_sync/index.ts +0 -98
  501. package/src/storage/tagging_store/sender_address_book_store.ts +0 -42
  502. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -143
  503. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -49
package/src/pxe.ts CHANGED
@@ -1,38 +1,45 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { Point } from '@aztec/foundation/curves/grumpkin';
5
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
6
  import { SerialQueue } from '@aztec/foundation/queue';
6
7
  import { Timer } from '@aztec/foundation/timer';
7
8
  import { KeyStore } from '@aztec/key-store';
9
+ import type { AccountPrivacyKeys, AccountPrivacySecretKeys } from '@aztec/key-store';
8
10
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
- import { L2TipsKVStore } from '@aztec/kv-store/stores';
10
11
  import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
11
12
  import type { CircuitSimulator } from '@aztec/simulator/client';
12
13
  import {
13
14
  type ContractArtifact,
14
15
  EventSelector,
15
16
  FunctionCall,
17
+ type FunctionSelector,
16
18
  FunctionType,
17
19
  decodeFunctionSignature,
18
20
  } from '@aztec/stdlib/abi';
19
21
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
22
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
23
+ import { GENESIS_BLOCK_HEADER_HASH, type L2TipsProvider } from '@aztec/stdlib/block';
21
24
  import {
22
25
  CompleteAddress,
26
+ type ContractInstancePreimage,
27
+ type ContractInstancePreimageWithAddress,
23
28
  type ContractInstanceWithAddress,
24
29
  type PartialAddress,
25
30
  computeContractAddressFromInstance,
26
- getContractClassFromArtifact,
27
31
  } from '@aztec/stdlib/contract';
28
32
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
33
+ import type { AztecNode, AztecNodeDebug, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
30
34
  import type {
31
35
  PrivateExecutionStep,
32
36
  PrivateKernelExecutionProofOutput,
33
37
  PrivateKernelTailCircuitPublicInputs,
34
38
  } from '@aztec/stdlib/kernel';
39
+ import { computeAddressSecret } from '@aztec/stdlib/keys';
40
+ import { deriveEcdhSharedSecretPoint } from '@aztec/stdlib/logs';
35
41
  import {
42
+ BlockHeader,
36
43
  type ContractOverrides,
37
44
  type InTx,
38
45
  PrivateExecutionResult,
@@ -46,24 +53,27 @@ import {
46
53
  TxProfileResult,
47
54
  TxProvingResult,
48
55
  TxSimulationResult,
49
- UtilitySimulationResult,
56
+ UtilityExecutionResult,
50
57
  } from '@aztec/stdlib/tx';
51
58
 
52
59
  import { inspect } from 'util';
53
60
 
54
61
  import { BlockSynchronizer } from './block_synchronizer/index.js';
55
62
  import type { PXEConfig } from './config/index.js';
63
+ import { ContractClassService } from './contract/contract_class_service.js';
64
+ import { ContractSyncService } from './contract/contract_sync_service.js';
56
65
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
66
  import {
58
67
  ContractFunctionSimulator,
59
68
  generateSimulatedProvingResult,
60
69
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
70
+ import { displayDebugLogs } from './contract_logging.js';
63
71
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
72
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
73
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
74
+ import type { ExecutionHooks } from './hooks/index.js';
66
75
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
76
+ import { TxResolverService } from './messages/tx_resolver_service.js';
67
77
  import {
68
78
  PrivateKernelExecutionProver,
69
79
  type PrivateKernelExecutionProverConfig,
@@ -73,17 +83,147 @@ import { AddressStore } from './storage/address_store/address_store.js';
73
83
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
74
84
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
75
85
  import { ContractStore } from './storage/contract_store/contract_store.js';
86
+ import { FactStore } from './storage/fact_store/index.js';
76
87
  import { NoteStore } from './storage/note_store/note_store.js';
88
+ import { openPxeStores } from './storage/open_pxe_stores.js';
77
89
  import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
78
90
  import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
79
- import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
80
91
  import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
92
+ import {
93
+ type SharedSecretKind,
94
+ TaggingSecretSourcesStore,
95
+ } from './storage/tagging_store/tagging_secret_sources_store.js';
96
+ import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
81
97
 
82
98
  export type PackedPrivateEvent = InTx & {
83
99
  packedEvent: Fr[];
84
100
  eventSelector: EventSelector;
85
101
  };
86
102
 
103
+ /** Options for PXE.proveTx. */
104
+ export type ProveTxOpts = {
105
+ /** Addresses whose private state and keys are accessible during private execution. */
106
+ scopes: AztecAddress[];
107
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
108
+ senderForTags?: AztecAddress;
109
+ };
110
+
111
+ /** Options for PXE.profileTx. */
112
+ export type ProfileTxOpts = {
113
+ /** The profiling mode to use. */
114
+ profileMode: 'full' | 'execution-steps' | 'gates';
115
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
116
+ skipProofGeneration?: boolean;
117
+ /** Addresses whose private state and keys are accessible during private execution. */
118
+ scopes: AztecAddress[];
119
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
120
+ senderForTags?: AztecAddress;
121
+ };
122
+
123
+ /** Options for PXE.simulateTx. */
124
+ export type SimulateTxOpts = {
125
+ /** Whether to simulate the public part of the transaction. */
126
+ simulatePublic: boolean;
127
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
128
+ skipTxValidation?: boolean;
129
+ /** If false, fees are enforced. */
130
+ skipFeeEnforcement?: boolean;
131
+ /** If true, kernel logic is emulated in TS for simulation */
132
+ skipKernels?: boolean;
133
+ /**
134
+ * Pre-simulation overrides applied to the ephemeral fork and contract DB. Bundles publicStorage
135
+ * writes (no skipKernels required) and per-address (instance, artifact?) overrides used by both
136
+ * AVM-side public dispatch and PXE-side ACIR private dispatch (requires skipKernels: true).
137
+ */
138
+ overrides?: SimulationOverrides;
139
+ /** Addresses whose private state and keys are accessible during private execution */
140
+ scopes: AztecAddress[];
141
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
142
+ senderForTags?: AztecAddress;
143
+ };
144
+
145
+ /** Options for PXE.executeUtility. */
146
+ export type ExecuteUtilityOpts = {
147
+ /** The authentication witnesses required for the function call. */
148
+ authwits?: AuthWitness[];
149
+ /** The accounts whose notes we can access in this call */
150
+ scopes: AztecAddress[];
151
+ };
152
+
153
+ /**
154
+ * Supplies the set of "nice to have" contracts that every PXE preloads regardless of which wallet
155
+ * drives it. Today this is just the standard multi-call entrypoint: the SDK's self-paid account
156
+ * deploy flow ({@link DeployAccountMethod} with `from = NO_FROM`) routes its payload through it, so a
157
+ * PXE that did not register it would fail contract sync with an opaque "no contract instance" error.
158
+ *
159
+ * Returning a list keeps this extensible: a wallet may supply its own provider that preloads
160
+ * additional contracts. Injected the same way as {@link ProtocolContractsProvider} so the PXE never
161
+ * statically imports the bundled artifacts, keeping the bundle/lazy split intact.
162
+ */
163
+ export type PreloadedContractsProvider = {
164
+ /** Returns the contract instances and artifacts the PXE should preload on startup. */
165
+ getPreloadedContracts: () => Promise<Array<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>>;
166
+ };
167
+
168
+ /** Args for PXE.create. */
169
+ export type PXECreateArgs = {
170
+ /** The Aztec node to connect to. */
171
+ node: AztecNode;
172
+ /**
173
+ * Optional debug API client. When provided, public function signatures are registered with the node so that
174
+ * node-side public-execution stack traces can be named. Skipped when the node does not expose the debug API.
175
+ */
176
+ nodeDebug?: AztecNodeDebug;
177
+ /** The key-value store for persisting PXE state. */
178
+ store: AztecAsyncKVStore;
179
+ /** The prover for generating private kernel proofs. */
180
+ proofCreator: PrivateKernelProver;
181
+ /** The circuit simulator for executing ACIR circuits. */
182
+ simulator: CircuitSimulator;
183
+ /** Provider for protocol contract artifacts and instances. */
184
+ protocolContractsProvider: ProtocolContractsProvider;
185
+ /**
186
+ * Contracts to preload on startup. Injected by the entrypoint with the bundle-or-lazy flavor that
187
+ * matches the runtime (bundle for node/eager browser, lazy for code-split browser), so the PXE
188
+ * never statically imports a standard-contract artifact and the bundle/lazy split stays intact.
189
+ */
190
+ preloadedContractsProvider: PreloadedContractsProvider;
191
+ /** PXE configuration options. */
192
+ config: PXEConfig;
193
+ /** Optional logger instance or string suffix for the logger name. */
194
+ loggerOrSuffix?: string | Logger;
195
+ /** Optional hooks to observe and influence contract execution. */
196
+ hooks?: ExecutionHooks;
197
+ };
198
+
199
+ /** A source from which PXE derives the tagging secrets it scans for to discover incoming private logs. */
200
+ export type TaggingSecretSource =
201
+ /**
202
+ * Derives a shared secret via ECDH from an external `sender` address against every account registered in this PXE
203
+ * (present and future), so registering one sender applies it to all of them. The address is not secret, so unlike
204
+ * `arbitrary-secret` it can be reused freely across recipients.
205
+ */
206
+ | { kind: 'address-derived'; sender: AztecAddress }
207
+ /**
208
+ * A shared secret point provided directly, scoped to a single recipient. It bypasses ECDH, so it must not be
209
+ * reused across recipients (each would then be able to find the others' tags).
210
+ */
211
+ | { kind: 'arbitrary-secret'; recipient: AztecAddress; secret: Point }
212
+ /**
213
+ * A handshake known by the x-coordinate of its ephemeral public key (the value a recipient learns while authorizing
214
+ * an interactive handshake, which emits no discoverable announcement). The ephemeral key's y-coordinate is always
215
+ * positive by protocol construction, so the x-coordinate alone identifies it.
216
+ */
217
+ | { kind: 'handshake'; recipient: AztecAddress; ephPk: Fr };
218
+
219
+ /**
220
+ * The registered form of a {@link TaggingSecretSource}.
221
+ */
222
+ export type RegisteredTaggingSecretSource =
223
+ | Exclude<TaggingSecretSource, { kind: 'handshake' }>
224
+ /** A handshake's resolved shared secret, derived at registration from the handshake's ephemeral key. */
225
+ | { kind: 'handshake'; recipient: AztecAddress; secret: Point };
226
+
87
227
  /**
88
228
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
229
  * manage private state of users.
@@ -91,25 +231,35 @@ export type PackedPrivateEvent = InTx & {
91
231
  export class PXE {
92
232
  private constructor(
93
233
  private node: AztecNode,
234
+ private nodeDebug: AztecNodeDebug | undefined,
235
+ private db: AztecAsyncKVStore,
94
236
  private blockStateSynchronizer: BlockSynchronizer,
95
237
  private keyStore: KeyStore,
96
238
  private contractStore: ContractStore,
97
239
  private noteStore: NoteStore,
98
240
  private capsuleStore: CapsuleStore,
241
+ private factStore: FactStore,
99
242
  private anchorBlockStore: AnchorBlockStore,
100
243
  private senderTaggingStore: SenderTaggingStore,
101
- private senderAddressBookStore: SenderAddressBookStore,
244
+ private taggingSecretSourcesStore: TaggingSecretSourcesStore,
102
245
  private recipientTaggingStore: RecipientTaggingStore,
103
246
  private addressStore: AddressStore,
104
247
  private privateEventStore: PrivateEventStore,
248
+ private contractSyncService: ContractSyncService,
249
+ private contractClassService: ContractClassService,
250
+ private txResolver: TxResolverService,
251
+ private l2TipsStore: L2TipsProvider,
105
252
  private simulator: CircuitSimulator,
106
253
  private proverEnabled: boolean,
254
+ private autoSync: boolean,
107
255
  private proofCreator: PrivateKernelProver,
108
256
  private protocolContractsProvider: ProtocolContractsProvider,
257
+ private preloadedContractsProvider: PreloadedContractsProvider,
109
258
  private log: Logger,
110
259
  private jobQueue: SerialQueue,
111
260
  private jobCoordinator: JobCoordinator,
112
261
  public debug: PXEDebugUtils,
262
+ private hooks: ExecutionHooks | undefined,
113
263
  ) {}
114
264
 
115
265
  /**
@@ -119,85 +269,133 @@ export class PXE {
119
269
  *
120
270
  * @returns A promise that resolves PXE is ready to be used.
121
271
  */
122
- public static async create(
123
- node: AztecNode,
124
- store: AztecAsyncKVStore,
125
- proofCreator: PrivateKernelProver,
126
- simulator: CircuitSimulator,
127
- protocolContractsProvider: ProtocolContractsProvider,
128
- config: PXEConfig,
129
- loggerOrSuffix?: string | Logger,
130
- ) {
272
+ public static async create({
273
+ node,
274
+ nodeDebug,
275
+ store,
276
+ proofCreator,
277
+ simulator,
278
+ protocolContractsProvider,
279
+ preloadedContractsProvider,
280
+ config,
281
+ loggerOrSuffix,
282
+ hooks,
283
+ }: PXECreateArgs) {
284
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
285
+ const bindings: LoggerBindings | undefined =
286
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
287
+
131
288
  const log =
132
289
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
133
290
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
134
291
  : loggerOrSuffix;
135
292
 
136
- const proverEnabled = !!config.proverEnabled;
137
- const addressStore = new AddressStore(store);
138
- const privateEventStore = new PrivateEventStore(store);
139
- const contractStore = new ContractStore(store);
140
- const noteStore = new NoteStore(store);
141
- const anchorBlockStore = new AnchorBlockStore(store);
142
- const senderTaggingStore = new SenderTaggingStore(store);
143
- const senderAddressBookStore = new SenderAddressBookStore(store);
144
- const recipientTaggingStore = new RecipientTaggingStore(store);
145
- const capsuleStore = new CapsuleStore(store);
146
- const keyStore = new KeyStore(store);
147
- const tipsStore = new L2TipsKVStore(store, 'pxe');
293
+ const info = await node.getNodeInfo();
294
+
295
+ // Source the genesis block hash from the node so PXE's L2BlockStream agrees with the node's
296
+ // archiver on the dynamic initial header hash. Without this the tip store would fall back to
297
+ // the static `GENESIS_BLOCK_HEADER_HASH` constant, which only matches deployments with the
298
+ // default empty genesis (timestamp 0, no prefilled public data) and diverges otherwise — the
299
+ // sync at block 0 would then get stuck in `areBlockHashesEqualAt` and abort. If the node does
300
+ // not return a genesis block (older node or test fixture) we fall back to the static constant.
301
+ const initialBlockHash = (await node.getBlock(BlockNumber.ZERO))?.hash ?? GENESIS_BLOCK_HEADER_HASH;
302
+
303
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
304
+ const {
305
+ addressStore,
306
+ privateEventStore,
307
+ contractStore,
308
+ noteStore,
309
+ anchorBlockStore,
310
+ senderTaggingStore,
311
+ taggingSecretSourcesStore,
312
+ recipientTaggingStore,
313
+ capsuleStore,
314
+ keyStore,
315
+ l2TipsStore,
316
+ factStore,
317
+ } = openPxeStores(store, initialBlockHash);
318
+ const contractClassService = new ContractClassService(node, contractStore);
319
+ const contractSyncService = new ContractSyncService(
320
+ node,
321
+ contractStore,
322
+ contractClassService,
323
+ noteStore,
324
+ createLogger('pxe:contract_sync', bindings),
325
+ );
326
+ const txResolver = new TxResolverService(node);
327
+
148
328
  const synchronizer = new BlockSynchronizer(
149
329
  node,
150
330
  store,
151
331
  anchorBlockStore,
152
332
  noteStore,
153
333
  privateEventStore,
154
- tipsStore,
334
+ factStore,
335
+ l2TipsStore,
336
+ contractSyncService,
337
+ contractClassService,
155
338
  config,
156
- loggerOrSuffix,
339
+ bindings,
157
340
  );
158
341
 
159
- const jobCoordinator = new JobCoordinator(store);
342
+ const jobCoordinator = new JobCoordinator(store, bindings);
160
343
  jobCoordinator.registerStores([
161
344
  capsuleStore,
162
345
  senderTaggingStore,
163
346
  recipientTaggingStore,
164
347
  privateEventStore,
165
348
  noteStore,
349
+ factStore,
350
+ contractSyncService,
166
351
  ]);
167
352
 
168
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
353
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
169
354
 
170
355
  const jobQueue = new SerialQueue();
171
356
 
172
357
  const pxe = new PXE(
173
358
  node,
359
+ nodeDebug,
360
+ store,
174
361
  synchronizer,
175
362
  keyStore,
176
363
  contractStore,
177
364
  noteStore,
178
365
  capsuleStore,
366
+ factStore,
179
367
  anchorBlockStore,
180
368
  senderTaggingStore,
181
- senderAddressBookStore,
369
+ taggingSecretSourcesStore,
182
370
  recipientTaggingStore,
183
371
  addressStore,
184
372
  privateEventStore,
373
+ contractSyncService,
374
+ contractClassService,
375
+ txResolver,
376
+ l2TipsStore,
185
377
  simulator,
186
378
  proverEnabled,
379
+ config.autoSync,
187
380
  proofCreator,
188
381
  protocolContractsProvider,
382
+ preloadedContractsProvider,
189
383
  log,
190
384
  jobQueue,
191
385
  jobCoordinator,
192
386
  debugUtils,
387
+ hooks,
193
388
  );
194
389
 
195
- debugUtils.setPXE(pxe);
390
+ debugUtils.setPXEHelpers(
391
+ pxe.#putInJobQueue.bind(pxe),
392
+ pxe.#getSimulatorForTx.bind(pxe),
393
+ pxe.#executeUtility.bind(pxe),
394
+ );
196
395
 
197
396
  pxe.jobQueue.start();
198
397
 
199
- await pxe.#registerProtocolContracts();
200
- const info = await node.getNodeInfo();
398
+ await Promise.all([pxe.#registerProtocolContracts(), pxe.#registerPreloadedContracts()]);
201
399
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
202
400
  return pxe;
203
401
  }
@@ -205,22 +403,50 @@ export class PXE {
205
403
  // Internal methods
206
404
 
207
405
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
208
- const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
406
+ return new ContractFunctionSimulator({
407
+ contractStore: this.contractStore,
408
+ contractClassService: this.contractClassService,
409
+ overrides: overrides?.contracts,
410
+ noteStore: this.noteStore,
411
+ keyStore: this.keyStore,
412
+ addressStore: this.addressStore,
413
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
414
+ l2TipsStore: this.l2TipsStore,
415
+ senderTaggingStore: this.senderTaggingStore,
416
+ recipientTaggingStore: this.recipientTaggingStore,
417
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
418
+ capsuleStore: this.capsuleStore,
419
+ factStore: this.factStore,
420
+ privateEventStore: this.privateEventStore,
421
+ simulator: this.simulator,
422
+ contractSyncService: this.contractSyncService,
423
+ txResolver: this.txResolver,
424
+ hooks: this.hooks,
425
+ });
426
+ }
209
427
 
210
- return new ContractFunctionSimulator(
211
- proxyContractStore,
212
- this.noteStore,
213
- this.keyStore,
214
- this.addressStore,
215
- BenchmarkedNodeFactory.create(this.node),
216
- this.anchorBlockStore,
217
- this.senderTaggingStore,
218
- this.recipientTaggingStore,
219
- this.senderAddressBookStore,
220
- this.capsuleStore,
221
- this.privateEventStore,
222
- this.simulator,
223
- );
428
+ /** Best-effort debug function name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
429
+ async #getDebugFunctionName(
430
+ address: AztecAddress,
431
+ selector: FunctionSelector,
432
+ anchorBlockHeader: BlockHeader,
433
+ ): Promise<string> {
434
+ try {
435
+ const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
436
+ return classId ? await this.contractStore.getDebugFunctionName(classId, selector) : `${address}:${selector}`;
437
+ } catch {
438
+ return `${address}:${selector}`;
439
+ }
440
+ }
441
+
442
+ /** Best-effort debug contract name for the class `address` runs at `anchorBlockHeader`. Used for log display only. */
443
+ async #getDebugContractName(address: AztecAddress, anchorBlockHeader: BlockHeader): Promise<string | undefined> {
444
+ try {
445
+ const classId = await this.contractClassService.getCurrentClassId(address, anchorBlockHeader);
446
+ return classId ? await this.contractStore.getDebugContractName(classId) : undefined;
447
+ } catch {
448
+ return undefined;
449
+ }
224
450
  }
225
451
 
226
452
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -270,84 +496,112 @@ export class PXE {
270
496
  }
271
497
 
272
498
  async #registerProtocolContracts() {
273
- const registered: Record<string, string> = {};
274
- for (const name of protocolContractNames) {
275
- const { address, contractClass, instance, artifact } =
276
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
277
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
278
- await this.contractStore.addContractInstance(instance);
279
- registered[name] = address.toString();
280
- }
499
+ const registered = Object.fromEntries(
500
+ await Promise.all(
501
+ protocolContractNames.map(async name => {
502
+ const { address, instance, artifact } =
503
+ await this.protocolContractsProvider.getProtocolContractArtifact(name);
504
+ await this.contractStore.addContractArtifact(artifact);
505
+ await this.contractStore.addContractInstance(instance);
506
+ return [name, address.toString()] as const;
507
+ }),
508
+ ),
509
+ );
281
510
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
282
511
  }
283
512
 
513
+ async #registerPreloadedContracts() {
514
+ const contracts = await this.preloadedContractsProvider.getPreloadedContracts();
515
+ await Promise.all(
516
+ contracts.map(async ({ instance, artifact }) => {
517
+ if (artifact) {
518
+ await this.registerContractClass(artifact);
519
+ }
520
+ await this.registerContract(instance);
521
+ }),
522
+ );
523
+ this.log.verbose(`Registered preloaded contracts in pxe`, {
524
+ contracts: contracts.map(({ instance }) => instance.address.toString()),
525
+ });
526
+ }
527
+
284
528
  // Executes the entrypoint private function, as well as all nested private
285
529
  // functions that might arise.
286
- async #executePrivate(
287
- contractFunctionSimulator: ContractFunctionSimulator,
288
- txRequest: TxExecutionRequest,
289
- scopes: AztecAddress[] | undefined,
290
- jobId: string,
291
- ): Promise<PrivateExecutionResult> {
530
+ async #executePrivate({
531
+ contractFunctionSimulator,
532
+ txRequest,
533
+ anchorBlockHeader,
534
+ scopes,
535
+ jobId,
536
+ senderForTags,
537
+ }: {
538
+ contractFunctionSimulator: ContractFunctionSimulator;
539
+ txRequest: TxExecutionRequest;
540
+ anchorBlockHeader: BlockHeader;
541
+ scopes: AztecAddress[];
542
+ jobId: string;
543
+ senderForTags?: AztecAddress;
544
+ }): Promise<PrivateExecutionResult> {
292
545
  const { origin: contractAddress, functionSelector } = txRequest;
293
546
 
294
547
  try {
295
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
296
-
297
- await ensureContractSynced(
548
+ await this.contractSyncService.ensureContractSynced(
298
549
  contractAddress,
299
550
  functionSelector,
300
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
301
- this.node,
302
- this.contractStore,
551
+ (privateSyncCall, execScopes) =>
552
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
303
553
  anchorBlockHeader,
554
+ jobId,
555
+ scopes,
304
556
  );
305
557
 
306
- const result = await contractFunctionSimulator.run(
307
- txRequest,
308
- contractAddress,
309
- functionSelector,
310
- undefined,
558
+ const result = await contractFunctionSimulator.run(txRequest, {
311
559
  anchorBlockHeader,
312
- // The sender for tags is set by contracts, typically by an account
313
- // contract entrypoint
314
- undefined, // senderForTags
315
560
  scopes,
316
561
  jobId,
317
- );
562
+ senderForTags,
563
+ });
318
564
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
319
565
  return result;
320
566
  } catch (err) {
321
567
  if (err instanceof SimulationError) {
322
- await enrichSimulationError(err, this.contractStore, this.log);
568
+ await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
323
569
  }
324
570
  throw err;
325
571
  }
326
572
  }
327
573
 
328
574
  /**
329
- * Simulate a utility function call on the given contract.
575
+ * Execute a utility function call on the given contract.
330
576
  * @param contractFunctionSimulator - The simulator to use for the function call.
331
577
  * @param call - The function call to execute.
332
578
  * @param authWitnesses - Authentication witnesses required for the function call.
333
579
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
334
580
  * accounts if not specified.
335
581
  * @param jobId - The job ID for staged writes.
336
- * @returns The simulation result containing the outputs of the utility function.
582
+ * @returns The execution result containing the outputs of the utility function.
337
583
  */
338
- async #simulateUtility(
584
+ async #executeUtility(
339
585
  contractFunctionSimulator: ContractFunctionSimulator,
340
586
  call: FunctionCall,
341
587
  authWitnesses: AuthWitness[] | undefined,
342
- scopes: AztecAddress[] | undefined,
588
+ scopes: AztecAddress[],
343
589
  jobId: string,
344
590
  ) {
345
591
  try {
346
592
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
347
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
593
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
594
+ call,
595
+ authWitnesses ?? [],
596
+ anchorBlockHeader,
597
+ scopes,
598
+ jobId,
599
+ );
600
+ return { result, offchainEffects };
348
601
  } catch (err) {
349
602
  if (err instanceof SimulationError) {
350
- await enrichSimulationError(err, this.contractStore, this.log);
603
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
604
+ await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
351
605
  }
352
606
  throw err;
353
607
  }
@@ -359,11 +613,11 @@ export class PXE {
359
613
  * It can also be used for estimating gas in the future.
360
614
  * @param tx - The transaction to be simulated.
361
615
  */
362
- async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
616
+ async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean, overrides?: SimulationOverrides) {
363
617
  // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
364
618
  // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
365
619
  try {
366
- const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
620
+ const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
367
621
  if (result.revertReason) {
368
622
  throw result.revertReason;
369
623
  }
@@ -371,7 +625,14 @@ export class PXE {
371
625
  } catch (err) {
372
626
  if (err instanceof SimulationError) {
373
627
  try {
374
- await enrichPublicSimulationError(err, this.contractStore, this.log);
628
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
629
+ await enrichPublicSimulationError(
630
+ err,
631
+ this.contractStore,
632
+ this.contractClassService,
633
+ anchorBlockHeader,
634
+ this.log,
635
+ );
375
636
  } catch (enrichErr) {
376
637
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
377
638
  }
@@ -395,19 +656,64 @@ export class PXE {
395
656
  txExecutionRequest: TxExecutionRequest,
396
657
  proofCreator: PrivateKernelProver,
397
658
  privateExecutionResult: PrivateExecutionResult,
659
+ anchorBlockHeader: BlockHeader,
398
660
  config: PrivateKernelExecutionProverConfig,
399
661
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
400
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
401
- const anchorBlockHash = await anchorBlockHeader.hash();
402
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
403
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
662
+ const kernelOracle = new PrivateKernelOracle(
663
+ this.contractStore,
664
+ this.contractClassService,
665
+ this.keyStore,
666
+ this.node,
667
+ anchorBlockHeader,
668
+ );
669
+ const kernelTraceProver = new PrivateKernelExecutionProver(
670
+ kernelOracle,
671
+ proofCreator,
672
+ !this.proverEnabled,
673
+ this.log.getBindings(),
674
+ );
404
675
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
405
676
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
406
677
  }
407
678
 
679
+ /**
680
+ * Syncs with the node only when `autoSync` is enabled.
681
+ * When `autoSync` is disabled, callers (typically a wallet) are
682
+ * responsible for invoking `pxe.sync()` at the right granularity.
683
+ */
684
+ async #maybeSync(): Promise<void> {
685
+ if (this.autoSync) {
686
+ await this.blockStateSynchronizer.sync();
687
+ }
688
+ }
689
+
408
690
  // Public API
409
691
 
410
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
692
+ /**
693
+ * Triggers a sync of PXE state with the node, regardless of the `autoSync` config flag. Use this to
694
+ * batch syncs across composite flows when `autoSync` is disabled (e.g. one sync per simulate+send
695
+ * instead of one per inner PXE call). Serialized through the job queue.
696
+ */
697
+ public sync(): Promise<void> {
698
+ return this.#putInJobQueue(() => this.blockStateSynchronizer.sync());
699
+ }
700
+
701
+ /**
702
+ * Returns the block header up to which the PXE has synced.
703
+ * @returns The synced block header
704
+ */
705
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
706
+ return this.#putInJobQueue(() => {
707
+ return this.anchorBlockStore.getBlockHeader();
708
+ });
709
+ }
710
+
711
+ /**
712
+ * Returns the address preimage of the contract instance at a given address, if it's registered in the PXE.
713
+ * @param address - The contract address.
714
+ * @returns The contract instance address preimage if found, undefined otherwise.
715
+ */
716
+ public getContractInstance(address: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
411
717
  return this.contractStore.getContractInstance(address);
412
718
  }
413
719
 
@@ -421,19 +727,23 @@ export class PXE {
421
727
  }
422
728
 
423
729
  /**
424
- * Registers a user account in PXE given its master encryption private key.
425
- * Once a new account is registered, the PXE will trial-decrypt all published notes on
426
- * the chain and store those that correspond to the registered account. Will do nothing if the
427
- * account is already registered.
730
+ * Registers a user account in PXE.
731
+ *
732
+ * PXE holds the account's four privacy secret keys but only the *public* message-signing and fallback keys: their
733
+ * secret keys are withheld, since PXE is not trusted to hold them.
428
734
  *
429
- * @param secretKey - Secret key of the corresponding user master public key.
735
+ * Does nothing if the account is already registered.
736
+ *
737
+ * The four privacy secret keys can be retrieved later with {@link getAccountSecretKeys}.
738
+ *
739
+ * @param keys - The account's privacy keys: four secret keys plus the message-signing and fallback public keys.
430
740
  * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
431
741
  * @returns The complete address of the account.
432
742
  */
433
- public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
743
+ public async registerAccount(keys: AccountPrivacyKeys, partialAddress: PartialAddress): Promise<CompleteAddress> {
434
744
  const accounts = await this.keyStore.getAccounts();
435
- const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
436
- if (accounts.includes(accountCompleteAddress.address)) {
745
+ const accountCompleteAddress = await this.keyStore.addAccount(keys, partialAddress);
746
+ if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
437
747
  this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
438
748
  return accountCompleteAddress;
439
749
  } else {
@@ -446,53 +756,186 @@ export class PXE {
446
756
  }
447
757
 
448
758
  /**
449
- * Registers a sender in this PXE.
759
+ * Retrieves the four privacy secret keys PXE holds for a registered account (nullifier-hiding, incoming-viewing,
760
+ * outgoing-viewing, tagging).
761
+ *
762
+ * These do NOT grant control over an account's assets, e.g. they are insufficient to impersonate the account or to
763
+ * spend notes, but they _do_ guard the account's privacy. Parties that have knowledge of these keys can decrypt all
764
+ * messages sent to the account, discover all of their on-chain activity, including notes, events, etc.
450
765
  *
451
- * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
452
- * Will do nothing if the address is already registered.
766
+ * Security is paramount when handling these keys, which should itself be a very rare occurrence. Other than exporting
767
+ * and then importing an account into a separate PXE/wallet, there is typically no need for a wallet to ever access
768
+ * these keys. Applications should NEVER be given access to them.
453
769
  *
454
- * @param sender - Address of the sender to register.
455
- * @returns The address of the sender.
456
- * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
770
+ * @throws If the account is not registered.
457
771
  */
458
- public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
459
- const accounts = await this.keyStore.getAccounts();
460
- if (accounts.includes(sender)) {
461
- this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
462
- return sender;
463
- }
772
+ public getAccountSecretKeys(account: AztecAddress): Promise<AccountPrivacySecretKeys> {
773
+ return this.keyStore.getAccountSecretKeys(account);
774
+ }
464
775
 
465
- const wasAdded = await this.senderAddressBookStore.addSender(sender);
776
+ /**
777
+ * Registers a source from which this PXE derives the tagging secrets it scans for to discover incoming private logs.
778
+ * See {@link TaggingSecretSource} for the meaning of each variant. Does nothing if the source is already registered.
779
+ *
780
+ * After a new source is added we clear the cache tracking which contracts have finished syncing, so every contract
781
+ * re-syncs against the new source's logs (whose notes/events could belong to any contract). Already-discovered
782
+ * notes/events are not discarded.
783
+ */
784
+ public async registerTaggingSecretSource(source: TaggingSecretSource): Promise<void> {
785
+ let wasAdded: boolean;
786
+
787
+ switch (source.kind) {
788
+ case 'address-derived':
789
+ wasAdded = await this.#registerSender(source.sender);
790
+ break;
791
+ case 'arbitrary-secret':
792
+ wasAdded = await this.#registerSharedSecret(source.recipient, 'arbitrary-secret', source.secret);
793
+ break;
794
+ case 'handshake':
795
+ wasAdded = await this.#registerSharedSecret(
796
+ source.recipient,
797
+ 'handshake',
798
+ await this.#deriveHandshakeSecret(source.recipient, source.ephPk),
799
+ );
800
+ break;
801
+ default: {
802
+ const _: never = source;
803
+ throw new Error('Unhandled tagging secret source kind');
804
+ }
805
+ }
466
806
 
467
807
  if (wasAdded) {
468
- this.log.info(`Added sender:\n ${sender.toString()}`);
469
- } else {
470
- this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
808
+ // Queued to avoid wiping while a job is in flight.
809
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
471
810
  }
811
+ }
472
812
 
473
- return sender;
813
+ /**
814
+ * Removes a previously registered tagging secret source, identified by its registered form (see
815
+ * {@link getTaggingSecretSources}). Does nothing if it was not registered.
816
+ */
817
+ public async removeTaggingSecretSource(source: RegisteredTaggingSecretSource): Promise<void> {
818
+ switch (source.kind) {
819
+ case 'address-derived': {
820
+ const { sender } = source;
821
+ const wasRemoved = await this.taggingSecretSourcesStore.removeSender(sender);
822
+ this.log.info(
823
+ wasRemoved
824
+ ? `Removed sender:\n ${sender.toString()}`
825
+ : `Sender:\n "${sender.toString()}"\n not registered in PXE.`,
826
+ );
827
+ break;
828
+ }
829
+ case 'arbitrary-secret':
830
+ case 'handshake': {
831
+ const { kind, recipient, secret } = source;
832
+ const wasRemoved = await this.taggingSecretSourcesStore.removeSharedSecret(recipient, kind, secret);
833
+ this.log.info(
834
+ wasRemoved
835
+ ? `Removed ${kind} shared secret for recipient:\n ${recipient.toString()}`
836
+ : `No ${kind} shared secret registered for recipient:\n ${recipient.toString()}`,
837
+ );
838
+ break;
839
+ }
840
+ default: {
841
+ const _: never = source;
842
+ throw new Error('Unhandled tagging secret source kind');
843
+ }
844
+ }
474
845
  }
475
846
 
476
847
  /**
477
- * Retrieves senders registered in this PXE.
478
- * @returns Senders registered in this PXE.
848
+ * Retrieves the tagging secret sources registered in this PXE, in their registered form. Without a filter it
849
+ * returns every source; pass `{ kind }` to narrow to a single variant. See {@link RegisteredTaggingSecretSource}.
479
850
  */
480
- public getSenders(): Promise<AztecAddress[]> {
481
- return this.senderAddressBookStore.getSenders();
851
+ public getTaggingSecretSources<K extends RegisteredTaggingSecretSource['kind']>(filter: {
852
+ kind: K;
853
+ }): Promise<Extract<RegisteredTaggingSecretSource, { kind: K }>[]>;
854
+ public getTaggingSecretSources(): Promise<RegisteredTaggingSecretSource[]>;
855
+ public async getTaggingSecretSources(filter?: {
856
+ kind?: RegisteredTaggingSecretSource['kind'];
857
+ }): Promise<RegisteredTaggingSecretSource[]> {
858
+ const [senders, secrets] = await Promise.all([
859
+ this.taggingSecretSourcesStore.getSenders(),
860
+ this.taggingSecretSourcesStore.getAllSharedSecrets(),
861
+ ]);
862
+
863
+ const sources: RegisteredTaggingSecretSource[] = [
864
+ ...senders.map((sender): RegisteredTaggingSecretSource => ({ kind: 'address-derived', sender })),
865
+ ...secrets.map(({ recipient, kind, secret }): RegisteredTaggingSecretSource => ({ kind, recipient, secret })),
866
+ ];
867
+
868
+ return filter?.kind ? sources.filter(source => source.kind === filter.kind) : sources;
869
+ }
870
+
871
+ /** Registers a sender, skipping addresses that belong to a local account. Returns whether it was newly added. */
872
+ async #registerSender(address: AztecAddress): Promise<boolean> {
873
+ if (!(await address.isValid())) {
874
+ throw new Error(
875
+ `Address ${address} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
876
+ );
877
+ }
878
+
879
+ const accounts = await this.keyStore.getAccounts();
880
+ if (accounts.some(a => a.equals(address))) {
881
+ this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
882
+ return false;
883
+ }
884
+
885
+ const wasAdded = await this.taggingSecretSourcesStore.addSender(address);
886
+ this.log.info(
887
+ wasAdded ? `Added sender:\n ${address.toString()}` : `Sender:\n "${address.toString()}"\n already registered.`,
888
+ );
889
+ return wasAdded;
482
890
  }
483
891
 
484
892
  /**
485
- * Removes a sender registered in this PXE.
486
- * @param sender - The address of the sender to remove.
893
+ * Derives the shared secret of a handshake from its ephemeral public key: `S = addressSecret(recipient) * ephPk`,
894
+ * the same derivation the recipient-side scan uses for handshakes discovered onchain. The ephemeral key is
895
+ * reconstructed from its x-coordinate with a positive y, matching how the protocol generates it.
896
+ *
897
+ * @throws If `ephPk` is not the x-coordinate of a Grumpkin curve point, or if `recipient` is not an account of
898
+ * this PXE, since the derivation needs its keys.
487
899
  */
488
- public async removeSender(sender: AztecAddress): Promise<void> {
489
- const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
900
+ async #deriveHandshakeSecret(recipient: AztecAddress, ephPk: Fr): Promise<Point> {
901
+ let ephPkPoint: Point;
902
+ try {
903
+ ephPkPoint = await Point.fromXAndSign(ephPk, true);
904
+ } catch {
905
+ throw new Error(`Ephemeral public key x-coordinate ${ephPk} does not correspond to a Grumpkin curve point.`);
906
+ }
490
907
 
491
- if (wasRemoved) {
492
- this.log.info(`Removed sender:\n ${sender.toString()}`);
493
- } else {
494
- this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
908
+ const completeAddress = await this.addressStore.getCompleteAddress(recipient);
909
+ if (!completeAddress || !(await this.keyStore.hasAccount(recipient))) {
910
+ throw new Error(
911
+ `Recipient ${recipient} is not an account of this PXE. A handshake's shared secret can only be derived for an account whose keys are held.`,
912
+ );
913
+ }
914
+
915
+ const ivskM = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
916
+ const addressSecret = await computeAddressSecret(await completeAddress.getPreaddress(), ivskM);
917
+ return deriveEcdhSharedSecretPoint(addressSecret, ephPkPoint);
918
+ }
919
+
920
+ /** Registers a resolved shared secret scoped to a recipient. Returns whether it was newly added. */
921
+ async #registerSharedSecret(recipient: AztecAddress, kind: SharedSecretKind, secret: Point): Promise<boolean> {
922
+ if (!(await recipient.isValid())) {
923
+ throw new Error(
924
+ `Recipient ${recipient} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register a shared secret for it.`,
925
+ );
926
+ }
927
+
928
+ if (secret.isZero() || !secret.isOnCurve()) {
929
+ throw new Error(`Shared secret ${secret} is not a valid non-zero point on the Grumpkin curve.`);
495
930
  }
931
+
932
+ const wasAdded = await this.taggingSecretSourcesStore.addSharedSecret(recipient, kind, secret);
933
+ this.log.info(
934
+ wasAdded
935
+ ? `Added ${kind} shared secret for recipient:\n ${recipient.toString()}`
936
+ : `${kind} shared secret already registered for recipient:\n ${recipient.toString()}`,
937
+ );
938
+ return wasAdded;
496
939
  }
497
940
 
498
941
  /**
@@ -515,95 +958,34 @@ export class PXE {
515
958
  * @param artifact - The build artifact for the contract class.
516
959
  */
517
960
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
518
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
519
- await this.contractStore.addContractArtifact(contractClassId, artifact);
961
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
962
+ // Publishing the artifact's public function signatures to the node is part of "registering a class", so that
963
+ // node-side debugging works regardless of which entrypoint (registerContractClass or registerContract) was used.
964
+ const publicFunctionSignatures = artifact.functions
965
+ .filter(fn => fn.functionType === FunctionType.PUBLIC)
966
+ .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
967
+ if (publicFunctionSignatures.length > 0) {
968
+ await this.nodeDebug?.registerContractFunctionSignatures(publicFunctionSignatures);
969
+ }
520
970
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
521
971
  }
522
972
 
523
973
  /**
524
- * Adds deployed contracts to the PXE. Deployed contract information is used to access the
525
- * contract code when simulating local transactions. This is automatically called by aztec.js when
526
- * deploying a contract. Dapps that wish to interact with contracts already deployed should register
527
- * these contracts in their users' PXE through this method.
974
+ * Registers a deployed contract instance so its private state can be synced and its functions simulated. The
975
+ * artifact for the class the instance runs must be registered separately via {@link registerContractClass}, before
976
+ * or after this call; registration performs no validation, so a missing or mismatched artifact only surfaces when
977
+ * the contract is later simulated. This is automatically called by aztec.js when deploying a contract.
528
978
  *
529
- * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
530
- */
531
- public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
532
- const { instance } = contract;
533
- let { artifact } = contract;
534
-
535
- if (artifact) {
536
- // If the user provides an artifact, validate it against the expected class id and register it
537
- const contractClass = await getContractClassFromArtifact(artifact);
538
- const contractClassId = contractClass.id;
539
- if (!contractClassId.equals(instance.currentContractClassId)) {
540
- throw new Error(
541
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
542
- );
543
- }
544
- const computedAddress = await computeContractAddressFromInstance(instance);
545
- if (!computedAddress.equals(instance.address)) {
546
- throw new Error('Added a contract in which the address does not match the contract instance.');
547
- }
548
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
549
-
550
- const publicFunctionSignatures = artifact.functions
551
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
552
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
553
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
554
- } else {
555
- // Otherwise, make sure there is an artifact already registered for that class id
556
- artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
557
- if (!artifact) {
558
- throw new Error(
559
- `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
560
- );
561
- }
562
- }
563
-
564
- await this.contractStore.addContractInstance(instance);
565
- this.log.info(
566
- `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
567
- );
568
- }
569
-
570
- /**
571
- * Updates a deployed contract in the PXE. This is used to update the contract artifact when
572
- * an update has happened, so the new code can be used in the simulation of local transactions.
573
- * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
574
- * @param contractAddress - The address of the contract to update.
575
- * @param artifact - The updated artifact for the contract.
576
- * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
577
- * the current one (current one from the point of view of the node to which the PXE is connected).
979
+ * @param instance - The address preimage of the contract instance to register. The address is derived from it.
980
+ * @returns The address of the registered instance.
578
981
  */
579
- public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
580
- // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
581
- // class while we're simulating it.
982
+ public registerContract(instance: ContractInstancePreimage): Promise<AztecAddress> {
983
+ // Run inside the job queue so we can't race a concurrent simulation while writing the instance to the store.
582
984
  return this.#putInJobQueue(async () => {
583
- const currentInstance = await this.contractStore.getContractInstance(contractAddress);
584
- if (!currentInstance) {
585
- throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
586
- }
587
- const contractClass = await getContractClassFromArtifact(artifact);
588
- await this.blockStateSynchronizer.sync();
589
-
590
- const header = await this.anchorBlockStore.getBlockHeader();
591
-
592
- const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
593
- if (!contractClass.id.equals(currentClassId)) {
594
- throw new Error('Could not update contract to a class different from the current one.');
595
- }
596
-
597
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
598
-
599
- const publicFunctionSignatures = artifact.functions
600
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
601
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
602
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
603
-
604
- currentInstance.currentContractClassId = contractClass.id;
605
- await this.contractStore.addContractInstance(currentInstance);
606
- this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
985
+ const address = await computeContractAddressFromInstance(instance);
986
+ await this.contractStore.addContractInstance({ ...instance, address });
987
+ this.log.info(`Added contract at ${address}`, { address });
988
+ return address;
607
989
  });
608
990
  }
609
991
 
@@ -620,11 +1002,12 @@ export class PXE {
620
1002
  * (where validators prove the public portion).
621
1003
  *
622
1004
  * @param txRequest - An authenticated tx request ready for proving
1005
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
623
1006
  * @returns A result containing the proof and public inputs of the tail circuit.
624
1007
  * @throws If contract code not found, or public simulation reverts.
625
1008
  * Also throws if simulatePublic is true and public simulation reverts.
626
1009
  */
627
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
1010
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
628
1011
  let privateExecutionResult: PrivateExecutionResult;
629
1012
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
630
1013
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -632,17 +1015,25 @@ export class PXE {
632
1015
  const totalTimer = new Timer();
633
1016
  try {
634
1017
  const syncTimer = new Timer();
635
- await this.blockStateSynchronizer.sync();
1018
+ await this.#maybeSync();
1019
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
636
1020
  const syncTime = syncTimer.ms();
637
1021
  const contractFunctionSimulator = this.#getSimulatorForTx();
638
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
1022
+ privateExecutionResult = await this.#executePrivate({
1023
+ contractFunctionSimulator,
1024
+ txRequest,
1025
+ anchorBlockHeader,
1026
+ scopes,
1027
+ jobId,
1028
+ senderForTags,
1029
+ });
639
1030
 
640
1031
  const {
641
1032
  publicInputs,
642
1033
  chonkProof,
643
1034
  executionSteps,
644
1035
  timings: { proving } = {},
645
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
1036
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
646
1037
  simulate: false,
647
1038
  skipFeeEnforcement: false,
648
1039
  profileMode: 'none',
@@ -672,23 +1063,20 @@ export class PXE {
672
1063
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
673
1064
  });
674
1065
 
675
- // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
676
- // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
677
- // transaction before this one is included in a block from this PXE, and that transaction contains a log with
678
- // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
679
- // storing the tags here prevents linkage of txs sent from the same PXE.
680
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
681
- if (preTagsUsedInTheTx.length > 0) {
682
- // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
683
- const txHash = (await txProvingResult.toTx()).txHash;
684
-
685
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
686
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
687
- preTagsUsedInTheTx,
688
- });
689
- } else {
690
- this.log.debug(`No pre-tags used in the tx`);
691
- }
1066
+ // We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
1067
+ // (which would link them) without having to rely on this tx being mined (and us seeing the indices being used
1068
+ // onchain).
1069
+ // Note that this must happen _after_ proving as it requires the proof's public inputs, from which the kernels
1070
+ // may have removed some logs due to note-nullifier squashing - this may lead to range of tagging indices we've
1071
+ // actually used to being reduced.
1072
+ await persistSenderTaggingIndexRangesForTx(
1073
+ this.senderTaggingStore,
1074
+ privateExecutionResult.entrypoint.taggingIndexRanges,
1075
+ publicInputs,
1076
+ () => txProvingResult.getTxHash(),
1077
+ jobId,
1078
+ this.log,
1079
+ );
692
1080
 
693
1081
  return txProvingResult;
694
1082
  } catch (err: any) {
@@ -699,17 +1087,13 @@ export class PXE {
699
1087
 
700
1088
  /**
701
1089
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
702
- *
703
- * @param txRequest - An authenticated tx request ready for simulation
704
- * @param msgSender - (Optional) The message sender to use for the simulation.
705
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
1090
+ * @param txRequest - An authenticated tx request ready for simulation.
706
1091
  * @returns A trace of the program execution with gate counts.
707
1092
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
708
1093
  */
709
1094
  public profileTx(
710
1095
  txRequest: TxExecutionRequest,
711
- profileMode: 'full' | 'execution-steps' | 'gates',
712
- skipProofGeneration: boolean = true,
1096
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
713
1097
  ): Promise<TxProfileResult> {
714
1098
  // We disable concurrent profiles for consistency with simulateTx.
715
1099
  return this.#putInJobQueue(async jobId => {
@@ -728,21 +1112,25 @@ export class PXE {
728
1112
  txInfo,
729
1113
  );
730
1114
  const syncTimer = new Timer();
731
- await this.blockStateSynchronizer.sync();
1115
+ await this.#maybeSync();
1116
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
732
1117
  const syncTime = syncTimer.ms();
733
1118
 
734
1119
  const contractFunctionSimulator = this.#getSimulatorForTx();
735
- const privateExecutionResult = await this.#executePrivate(
1120
+ const privateExecutionResult = await this.#executePrivate({
736
1121
  contractFunctionSimulator,
737
1122
  txRequest,
738
- undefined,
1123
+ anchorBlockHeader,
1124
+ scopes,
739
1125
  jobId,
740
- );
1126
+ senderForTags,
1127
+ });
741
1128
 
742
1129
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
743
1130
  txRequest,
744
1131
  this.proofCreator,
745
1132
  privateExecutionResult,
1133
+ anchorBlockHeader,
746
1134
  {
747
1135
  simulate: skipProofGeneration,
748
1136
  skipFeeEnforcement: false,
@@ -794,12 +1182,7 @@ export class PXE {
794
1182
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
795
1183
  *
796
1184
  *
797
- * @param txRequest - An authenticated tx request ready for simulation
798
- * @param simulatePublic - Whether to simulate the public part of the transaction.
799
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
800
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
801
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
802
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
1185
+ * @param txRequest - An authenticated tx request ready for simulation.
803
1186
  * @returns A simulated transaction result object that includes public and private return values.
804
1187
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
805
1188
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -808,11 +1191,15 @@ export class PXE {
808
1191
  */
809
1192
  public simulateTx(
810
1193
  txRequest: TxExecutionRequest,
811
- simulatePublic: boolean,
812
- skipTxValidation: boolean = false,
813
- skipFeeEnforcement: boolean = false,
814
- overrides?: SimulationOverrides,
815
- scopes?: AztecAddress[],
1194
+ {
1195
+ simulatePublic,
1196
+ skipTxValidation = false,
1197
+ skipFeeEnforcement = false,
1198
+ skipKernels = true,
1199
+ overrides,
1200
+ scopes,
1201
+ senderForTags,
1202
+ }: SimulateTxOpts,
816
1203
  ): Promise<TxSimulationResult> {
817
1204
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
818
1205
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -833,17 +1220,26 @@ export class PXE {
833
1220
  txInfo,
834
1221
  );
835
1222
  const syncTimer = new Timer();
836
- await this.blockStateSynchronizer.sync();
1223
+ await this.#maybeSync();
1224
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
837
1225
  const syncTime = syncTimer.ms();
838
1226
 
1227
+ if (overrides?.contracts && Object.keys(overrides.contracts).length > 0 && !skipKernels) {
1228
+ throw new Error(
1229
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
1230
+ );
1231
+ }
839
1232
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
840
- // Temporary: in case there are overrides, we have to skip the kernels or validations
841
- // will fail. Consider handing control to the user/wallet on whether they want to run them
842
- // or not.
843
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
844
1233
 
845
1234
  // Execution of private functions only; no proving, and no kernel logic.
846
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
1235
+ const privateExecutionResult = await this.#executePrivate({
1236
+ contractFunctionSimulator,
1237
+ txRequest,
1238
+ anchorBlockHeader,
1239
+ scopes,
1240
+ jobId,
1241
+ senderForTags,
1242
+ });
847
1243
 
848
1244
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
849
1245
  let executionSteps: PrivateExecutionStep[] = [];
@@ -851,15 +1247,22 @@ export class PXE {
851
1247
  if (skipKernels) {
852
1248
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
853
1249
  privateExecutionResult,
854
- this.contractStore,
1250
+ (addr, sel) => this.#getDebugFunctionName(addr, sel, anchorBlockHeader),
1251
+ this.node,
855
1252
  ));
856
1253
  } else {
857
1254
  // Kernel logic, plus proving of all private functions and kernels.
858
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
859
- simulate: true,
860
- skipFeeEnforcement,
861
- profileMode: 'none',
862
- }));
1255
+ ({ publicInputs, executionSteps } = await this.#prove(
1256
+ txRequest,
1257
+ this.proofCreator,
1258
+ privateExecutionResult,
1259
+ anchorBlockHeader,
1260
+ {
1261
+ simulate: true,
1262
+ skipFeeEnforcement,
1263
+ profileMode: 'none',
1264
+ },
1265
+ ));
863
1266
  }
864
1267
 
865
1268
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -868,8 +1271,11 @@ export class PXE {
868
1271
  let publicOutput: PublicSimulationOutput | undefined;
869
1272
  if (simulatePublic && publicInputs.forPublic) {
870
1273
  const publicSimulationTimer = new Timer();
871
- publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
1274
+ publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
872
1275
  publicSimulationTime = publicSimulationTimer.ms();
1276
+ if (publicOutput?.debugLogs?.length) {
1277
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.#getDebugContractName(addr, anchorBlockHeader));
1278
+ }
873
1279
  }
874
1280
 
875
1281
  let validationTime: number | undefined;
@@ -878,7 +1284,8 @@ export class PXE {
878
1284
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
879
1285
  validationTime = validationTimer.ms();
880
1286
  if (validationResult.result === 'invalid') {
881
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1287
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1288
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
882
1289
  }
883
1290
  }
884
1291
 
@@ -929,49 +1336,44 @@ export class PXE {
929
1336
  inspect(txRequest),
930
1337
  `simulatePublic=${simulatePublic}`,
931
1338
  `skipTxValidation=${skipTxValidation}`,
932
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1339
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
933
1340
  );
934
1341
  }
935
1342
  });
936
1343
  }
937
1344
 
938
1345
  /**
939
- * Simulate the execution of a contract utility function.
940
- *
1346
+ * Executes a contract utility function.
941
1347
  * @param call - The function call containing the function details, arguments, and target contract address.
942
- * @param authwits - (Optional) The authentication witnesses required for the function call.
943
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
944
- * default to all.
945
- * @returns The result of the utility function call, structured based on the function ABI.
946
1348
  */
947
- public simulateUtility(
1349
+ public executeUtility(
948
1350
  call: FunctionCall,
949
- authwits?: AuthWitness[],
950
- scopes?: AztecAddress[],
951
- ): Promise<UtilitySimulationResult> {
952
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1351
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1352
+ ): Promise<UtilityExecutionResult> {
1353
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
953
1354
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
954
- // delete the same read value, or reading values that another simulation is currently modifying).
1355
+ // delete the same read value, or reading values that another execution is currently modifying).
955
1356
  return this.#putInJobQueue(async jobId => {
956
1357
  try {
957
1358
  const totalTimer = new Timer();
958
1359
  const syncTimer = new Timer();
959
- await this.blockStateSynchronizer.sync();
1360
+ await this.#maybeSync();
960
1361
  const syncTime = syncTimer.ms();
961
1362
  const functionTimer = new Timer();
962
1363
  const contractFunctionSimulator = this.#getSimulatorForTx();
963
1364
 
964
1365
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
965
- await ensureContractSynced(
1366
+ await this.contractSyncService.ensureContractSynced(
966
1367
  call.to,
967
1368
  call.selector,
968
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
969
- this.node,
970
- this.contractStore,
1369
+ (privateSyncCall, execScopes) =>
1370
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
971
1371
  anchorBlockHeader,
1372
+ jobId,
1373
+ scopes,
972
1374
  );
973
1375
 
974
- const executionResult = await this.#simulateUtility(
1376
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
975
1377
  contractFunctionSimulator,
976
1378
  call,
977
1379
  authwits ?? [],
@@ -992,14 +1394,19 @@ export class PXE {
992
1394
  };
993
1395
 
994
1396
  const simulationStats = contractFunctionSimulator.getStats();
995
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1397
+ return {
1398
+ result: executionResult,
1399
+ offchainEffects,
1400
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1401
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1402
+ };
996
1403
  } catch (err: any) {
997
1404
  const { to, name, args } = call;
998
1405
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
999
1406
  throw this.#contextualizeError(
1000
1407
  err,
1001
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1002
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1408
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1409
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1003
1410
  );
1004
1411
  }
1005
1412
  });
@@ -1025,21 +1432,21 @@ export class PXE {
1025
1432
  let anchorBlockNumber: BlockNumber;
1026
1433
 
1027
1434
  await this.#putInJobQueue(async jobId => {
1028
- await this.blockStateSynchronizer.sync();
1435
+ await this.#maybeSync();
1029
1436
 
1030
1437
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1031
1438
  anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1032
1439
 
1033
1440
  const contractFunctionSimulator = this.#getSimulatorForTx();
1034
1441
 
1035
- await ensureContractSynced(
1442
+ await this.contractSyncService.ensureContractSynced(
1036
1443
  filter.contractAddress,
1037
1444
  null,
1038
- async privateSyncCall =>
1039
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1040
- this.node,
1041
- this.contractStore,
1445
+ async (privateSyncCall, execScopes) =>
1446
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1042
1447
  anchorBlockHeader,
1448
+ jobId,
1449
+ filter.scopes,
1043
1450
  );
1044
1451
  });
1045
1452
 
@@ -1054,9 +1461,11 @@ export class PXE {
1054
1461
  }
1055
1462
 
1056
1463
  /**
1057
- * Stops the PXE's job queue.
1464
+ * Stops the PXE's job queue and closes the backing store.
1058
1465
  */
1059
- public stop(): Promise<void> {
1060
- return this.jobQueue.end();
1466
+ public async stop(): Promise<void> {
1467
+ await this.jobQueue.end();
1468
+ await this.blockStateSynchronizer.stop();
1469
+ await this.db.close();
1061
1470
  }
1062
1471
  }