@aztec/pxe 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928

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