@aztec/pxe 0.0.1-commit.f2ce05ee → 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 (544) 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 +72 -43
  34. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/contract_function_simulator.js +266 -114
  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 +82 -98
  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 +263 -117
  135. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +206 -83
  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 +688 -188
  138. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  139. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  140. package/dest/contract_function_simulator/pick_notes.js +20 -3
  141. package/dest/contract_function_simulator/transient_array_service.d.ts +31 -0
  142. package/dest/contract_function_simulator/transient_array_service.d.ts.map +1 -0
  143. package/dest/contract_function_simulator/transient_array_service.js +62 -0
  144. package/dest/contract_logging.d.ts +27 -0
  145. package/dest/contract_logging.d.ts.map +1 -0
  146. package/dest/contract_logging.js +38 -0
  147. package/dest/debug/pxe_debug_utils.d.ts +5 -9
  148. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  149. package/dest/debug/pxe_debug_utils.js +4 -10
  150. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  151. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  152. package/dest/entrypoints/client/bundle/index.js +3 -0
  153. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  154. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  155. package/dest/entrypoints/client/bundle/utils.js +29 -8
  156. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  157. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  158. package/dest/entrypoints/client/lazy/index.js +3 -0
  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 +29 -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 +8 -3
  169. package/dest/entrypoints/server/index.d.ts.map +1 -1
  170. package/dest/entrypoints/server/index.js +6 -2
  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 +30 -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 -10
  202. package/dest/logs/log_service.d.ts.map +1 -1
  203. package/dest/logs/log_service.js +184 -90
  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 -6
  214. package/dest/notes/note_service.d.ts.map +1 -1
  215. package/dest/notes/note_service.js +85 -59
  216. package/dest/notes_filter.d.ts +24 -0
  217. package/dest/notes_filter.d.ts.map +1 -0
  218. package/dest/notes_filter.js +4 -0
  219. package/dest/oracle_version.d.ts +4 -3
  220. package/dest/oracle_version.d.ts.map +1 -1
  221. package/dest/oracle_version.js +20 -10
  222. package/dest/private_kernel/batch_planner.d.ts +47 -0
  223. package/dest/private_kernel/batch_planner.d.ts.map +1 -0
  224. package/dest/private_kernel/batch_planner.js +104 -0
  225. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  226. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  227. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  228. package/dest/private_kernel/hints/index.d.ts +1 -1
  229. package/dest/private_kernel/hints/index.js +1 -1
  230. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  231. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  232. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +138 -72
  233. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  234. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  235. package/dest/private_kernel/hints/test_utils.js +202 -0
  236. package/dest/private_kernel/private_kernel_execution_prover.d.ts +6 -2
  237. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  238. package/dest/private_kernel/private_kernel_execution_prover.js +165 -82
  239. package/dest/private_kernel/private_kernel_oracle.d.ts +17 -11
  240. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  241. package/dest/private_kernel/private_kernel_oracle.js +47 -29
  242. package/dest/pxe.d.ts +219 -68
  243. package/dest/pxe.d.ts.map +1 -1
  244. package/dest/pxe.js +423 -243
  245. package/dest/storage/address_store/address_store.d.ts +1 -1
  246. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  247. package/dest/storage/address_store/address_store.js +2 -1
  248. package/dest/storage/allowed_scopes.d.ts +6 -0
  249. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  250. package/dest/storage/allowed_scopes.js +7 -0
  251. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -6
  252. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  253. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -7
  254. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  255. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  256. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  257. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  258. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  259. package/dest/storage/backwards_compatibility_tests/schema_tests.js +671 -0
  260. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  261. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  262. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  263. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  264. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  265. package/dest/storage/capsule_store/capsule_service.js +47 -0
  266. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  267. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  268. package/dest/storage/capsule_store/capsule_store.js +37 -29
  269. package/dest/storage/capsule_store/index.d.ts +2 -1
  270. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  271. package/dest/storage/capsule_store/index.js +1 -0
  272. package/dest/storage/contract_store/contract_store.d.ts +63 -33
  273. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  274. package/dest/storage/contract_store/contract_store.js +179 -130
  275. package/dest/storage/contract_store/private_functions_tree.d.ts +1 -1
  276. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -1
  277. package/dest/storage/contract_store/private_functions_tree.js +2 -1
  278. package/dest/storage/fact_store/fact_service.d.ts +22 -0
  279. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  280. package/dest/storage/fact_store/fact_service.js +45 -0
  281. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  282. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  283. package/dest/storage/fact_store/fact_store.js +411 -0
  284. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  285. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  286. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  287. package/dest/storage/fact_store/index.d.ts +6 -0
  288. package/dest/storage/fact_store/index.d.ts.map +1 -0
  289. package/dest/storage/fact_store/index.js +4 -0
  290. package/dest/storage/fact_store/origin_state.d.ts +59 -0
  291. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  292. package/dest/storage/fact_store/origin_state.js +60 -0
  293. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  294. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  295. package/dest/storage/fact_store/stored_fact.js +64 -0
  296. package/dest/storage/index.d.ts +3 -2
  297. package/dest/storage/index.d.ts.map +1 -1
  298. package/dest/storage/index.js +2 -1
  299. package/dest/storage/metadata.d.ts +2 -2
  300. package/dest/storage/metadata.d.ts.map +1 -1
  301. package/dest/storage/metadata.js +1 -1
  302. package/dest/storage/note_store/note_store.d.ts +44 -35
  303. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  304. package/dest/storage/note_store/note_store.js +203 -174
  305. package/dest/storage/note_store/stored_note.d.ts +3 -8
  306. package/dest/storage/note_store/stored_note.d.ts.map +1 -1
  307. package/dest/storage/note_store/stored_note.js +4 -20
  308. package/dest/storage/open_pxe_stores.d.ts +35 -0
  309. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  310. package/dest/storage/open_pxe_stores.js +29 -0
  311. package/dest/storage/private_event_store/private_event_store.d.ts +13 -16
  312. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  313. package/dest/storage/private_event_store/private_event_store.js +48 -45
  314. package/dest/storage/private_event_store/stored_private_event.js +1 -1
  315. package/dest/storage/store_identity.d.ts +35 -0
  316. package/dest/storage/store_identity.d.ts.map +1 -0
  317. package/dest/storage/store_identity.js +44 -0
  318. package/dest/storage/tagging_store/index.d.ts +2 -2
  319. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  320. package/dest/storage/tagging_store/index.js +1 -1
  321. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  322. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  323. package/dest/storage/tagging_store/sender_tagging_store.d.ts +63 -31
  324. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  325. package/dest/storage/tagging_store/sender_tagging_store.js +210 -129
  326. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  327. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  328. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
  329. package/dest/tagging/constants.d.ts +11 -2
  330. package/dest/tagging/constants.d.ts.map +1 -1
  331. package/dest/tagging/constants.js +38 -10
  332. package/dest/tagging/get_all_logs_by_tags.d.ts +55 -10
  333. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  334. package/dest/tagging/get_all_logs_by_tags.js +65 -32
  335. package/dest/tagging/index.d.ts +8 -7
  336. package/dest/tagging/index.d.ts.map +1 -1
  337. package/dest/tagging/index.js +6 -5
  338. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  339. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  340. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  341. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +74 -0
  342. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  343. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +235 -0
  344. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +3 -3
  345. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -1
  346. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  347. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  348. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  349. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  350. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +8 -10
  351. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  352. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +25 -22
  353. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  354. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  355. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +62 -0
  356. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +17 -9
  357. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  358. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +53 -39
  359. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  360. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  361. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +42 -0
  362. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  363. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  364. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  365. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  366. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  367. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  368. package/package.json +20 -17
  369. package/src/bin/check_oracle_version.ts +46 -135
  370. package/src/bin/index.ts +1 -0
  371. package/src/bin/oracle_version_helpers.ts +54 -0
  372. package/src/block_synchronizer/block_stream_source.ts +42 -0
  373. package/src/block_synchronizer/block_synchronizer.ts +86 -40
  374. package/src/config/index.ts +16 -9
  375. package/src/config/package_info.ts +1 -1
  376. package/src/contract/contract_class_service.ts +45 -0
  377. package/src/contract/contract_sync_service.ts +179 -0
  378. package/src/contract/helpers.ts +35 -0
  379. package/src/contract/skip_sync_contracts.ts +23 -0
  380. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  381. package/src/contract_function_simulator/contract_function_simulator.ts +468 -180
  382. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  383. package/src/contract_function_simulator/execution_note_cache.ts +10 -30
  384. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -18
  385. package/src/contract_function_simulator/index.ts +89 -4
  386. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +43 -0
  387. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  388. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  389. package/src/contract_function_simulator/noir-structs/ephemeral_array.ts +66 -0
  390. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -9
  391. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  392. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  393. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -20
  394. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +14 -64
  395. package/src/contract_function_simulator/noir-structs/note_data.ts +27 -0
  396. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -11
  397. package/src/contract_function_simulator/noir-structs/option.ts +75 -0
  398. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  399. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  400. package/src/contract_function_simulator/noir-structs/provided_secret.ts +5 -0
  401. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
  402. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +19 -0
  403. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +16 -0
  404. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  405. package/src/contract_function_simulator/oracle/acir_callback.ts +154 -0
  406. package/src/contract_function_simulator/oracle/index.ts +1 -15
  407. package/src/contract_function_simulator/oracle/interfaces.ts +11 -176
  408. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  409. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  410. package/src/contract_function_simulator/oracle/note_packing_utils.ts +3 -3
  411. package/src/contract_function_simulator/oracle/oracle_registry.ts +710 -0
  412. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +1052 -0
  413. package/src/contract_function_simulator/oracle/private_execution.ts +6 -7
  414. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +320 -210
  415. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +1028 -268
  416. package/src/contract_function_simulator/pick_notes.ts +22 -3
  417. package/src/contract_function_simulator/transient_array_service.ts +91 -0
  418. package/src/contract_logging.ts +52 -0
  419. package/src/debug/pxe_debug_utils.ts +11 -17
  420. package/src/entrypoints/client/bundle/index.ts +3 -0
  421. package/src/entrypoints/client/bundle/utils.ts +35 -9
  422. package/src/entrypoints/client/lazy/index.ts +3 -0
  423. package/src/entrypoints/client/lazy/utils.ts +35 -9
  424. package/src/entrypoints/client/store.ts +54 -0
  425. package/src/entrypoints/pxe_creation_options.ts +21 -1
  426. package/src/entrypoints/server/index.ts +8 -2
  427. package/src/entrypoints/server/store.ts +47 -0
  428. package/src/entrypoints/server/utils.ts +46 -21
  429. package/src/error_enriching.ts +30 -13
  430. package/src/events/event_service.ts +85 -26
  431. package/src/events/private_event_filter_validator.ts +21 -1
  432. package/src/hooks/authorize_utility_call.ts +44 -0
  433. package/src/hooks/execution_hooks.ts +68 -0
  434. package/src/hooks/index.ts +13 -0
  435. package/src/hooks/resolve_custom_request.ts +24 -0
  436. package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
  437. package/src/logs/log_service.ts +231 -157
  438. package/src/messages/tx_resolver_service.ts +81 -0
  439. package/src/node/benchmarked_node.ts +140 -0
  440. package/src/node/caching_aztec_node.ts +407 -0
  441. package/src/notes/note_service.ts +128 -86
  442. package/src/notes_filter.ts +24 -0
  443. package/src/oracle_version.ts +20 -10
  444. package/src/private_kernel/batch_planner.ts +169 -0
  445. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  446. package/src/private_kernel/hints/index.ts +1 -1
  447. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +179 -121
  448. package/src/private_kernel/hints/test_utils.ts +318 -0
  449. package/src/private_kernel/private_kernel_execution_prover.ts +252 -116
  450. package/src/private_kernel/private_kernel_oracle.ts +65 -36
  451. package/src/pxe.ts +698 -311
  452. package/src/storage/address_store/address_store.ts +2 -1
  453. package/src/storage/allowed_scopes.ts +14 -0
  454. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -7
  455. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  456. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  457. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  458. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  459. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  460. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  461. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +40 -0
  462. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +56 -0
  463. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  464. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +26 -0
  465. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +30 -0
  466. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  467. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +117 -0
  468. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  469. package/src/storage/backwards_compatibility_tests/schema_tests.ts +803 -0
  470. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  471. package/src/storage/capsule_store/capsule_service.ts +85 -0
  472. package/src/storage/capsule_store/capsule_store.ts +45 -27
  473. package/src/storage/capsule_store/index.ts +1 -0
  474. package/src/storage/contract_store/contract_store.ts +238 -166
  475. package/src/storage/contract_store/private_functions_tree.ts +2 -1
  476. package/src/storage/fact_store/fact_service.ts +69 -0
  477. package/src/storage/fact_store/fact_store.ts +488 -0
  478. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  479. package/src/storage/fact_store/index.ts +15 -0
  480. package/src/storage/fact_store/origin_state.ts +84 -0
  481. package/src/storage/fact_store/stored_fact.ts +80 -0
  482. package/src/storage/index.ts +2 -1
  483. package/src/storage/metadata.ts +1 -1
  484. package/src/storage/note_store/note_store.ts +236 -194
  485. package/src/storage/note_store/stored_note.ts +5 -27
  486. package/src/storage/open_pxe_stores.ts +52 -0
  487. package/src/storage/private_event_store/private_event_store.ts +55 -56
  488. package/src/storage/private_event_store/stored_private_event.ts +1 -1
  489. package/src/storage/store_identity.ts +72 -0
  490. package/src/storage/tagging_store/index.ts +1 -1
  491. package/src/storage/tagging_store/recipient_tagging_store.ts +5 -5
  492. package/src/storage/tagging_store/sender_tagging_store.ts +278 -158
  493. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  494. package/src/tagging/constants.ts +42 -10
  495. package/src/tagging/get_all_logs_by_tags.ts +125 -36
  496. package/src/tagging/index.ts +12 -6
  497. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  498. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +356 -0
  499. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +4 -4
  500. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  501. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +32 -27
  502. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +92 -0
  503. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +57 -50
  504. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +65 -0
  505. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  506. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
  507. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  508. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  509. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  510. package/dest/contract_function_simulator/oracle/oracle.d.ts +0 -60
  511. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +0 -1
  512. package/dest/contract_function_simulator/oracle/oracle.js +0 -368
  513. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  514. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  515. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -80
  516. package/dest/contract_sync/contract_sync_service.d.ts +0 -41
  517. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  518. package/dest/contract_sync/contract_sync_service.js +0 -82
  519. package/dest/contract_sync/helpers.d.ts +0 -28
  520. package/dest/contract_sync/helpers.d.ts.map +0 -1
  521. package/dest/contract_sync/helpers.js +0 -55
  522. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  523. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  524. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  525. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  526. package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
  527. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -15
  528. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
  529. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
  530. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -15
  531. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
  532. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -32
  533. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -11
  534. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  535. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -29
  536. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  537. package/src/contract_function_simulator/oracle/oracle.ts +0 -637
  538. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -83
  539. package/src/contract_sync/contract_sync_service.ts +0 -129
  540. package/src/contract_sync/helpers.ts +0 -93
  541. package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
  542. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -143
  543. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -49
  544. 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,
@@ -47,25 +54,27 @@ import {
47
54
  TxProfileResult,
48
55
  TxProvingResult,
49
56
  TxSimulationResult,
50
- UtilitySimulationResult,
57
+ UtilityExecutionResult,
51
58
  } from '@aztec/stdlib/tx';
52
59
 
53
60
  import { inspect } from 'util';
54
61
 
55
62
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
63
  import type { PXEConfig } from './config/index.js';
57
- 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';
58
66
  import {
59
67
  ContractFunctionSimulator,
60
68
  generateSimulatedProvingResult,
61
69
  } from './contract_function_simulator/contract_function_simulator.js';
62
- import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ContractSyncService } from './contract_sync/contract_sync_service.js';
64
- import { readCurrentClassId } from './contract_sync/helpers.js';
70
+ import { displayDebugLogs } from './contract_logging.js';
65
71
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
66
72
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
67
73
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
74
+ import type { ExecutionHooks } from './hooks/index.js';
68
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';
69
78
  import {
70
79
  PrivateKernelExecutionProver,
71
80
  type PrivateKernelExecutionProverConfig,
@@ -75,44 +84,183 @@ import { AddressStore } from './storage/address_store/address_store.js';
75
84
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
76
85
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
77
86
  import { ContractStore } from './storage/contract_store/contract_store.js';
87
+ import { FactStore } from './storage/fact_store/index.js';
78
88
  import { NoteStore } from './storage/note_store/note_store.js';
89
+ import { openPxeStores } from './storage/open_pxe_stores.js';
79
90
  import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
80
91
  import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
81
- import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
82
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';
83
98
 
84
99
  export type PackedPrivateEvent = InTx & {
85
100
  packedEvent: Fr[];
86
101
  eventSelector: EventSelector;
87
102
  };
88
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
+
112
+ /** Options for PXE.profileTx. */
113
+ export type ProfileTxOpts = {
114
+ /** The profiling mode to use. */
115
+ profileMode: 'full' | 'execution-steps' | 'gates';
116
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
117
+ skipProofGeneration?: boolean;
118
+ /** Addresses whose private state and keys are accessible during private execution. */
119
+ scopes: AztecAddress[];
120
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
121
+ senderForTags?: AztecAddress;
122
+ };
123
+
124
+ /** Options for PXE.simulateTx. */
125
+ export type SimulateTxOpts = {
126
+ /** Whether to simulate the public part of the transaction. */
127
+ simulatePublic: boolean;
128
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
129
+ skipTxValidation?: boolean;
130
+ /** If false, fees are enforced. */
131
+ skipFeeEnforcement?: boolean;
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
+ */
139
+ overrides?: SimulationOverrides;
140
+ /** Addresses whose private state and keys are accessible during private execution */
141
+ scopes: AztecAddress[];
142
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
143
+ senderForTags?: AztecAddress;
144
+ };
145
+
146
+ /** Options for PXE.executeUtility. */
147
+ export type ExecuteUtilityOpts = {
148
+ /** The authentication witnesses required for the function call. */
149
+ authwits?: AuthWitness[];
150
+ /** The accounts whose notes we can access in this call */
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 }>>;
167
+ };
168
+
169
+ /** Args for PXE.create. */
170
+ export type PXECreateArgs = {
171
+ /** The Aztec node to connect to. */
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;
178
+ /** The key-value store for persisting PXE state. */
179
+ store: AztecAsyncKVStore;
180
+ /** The prover for generating private kernel proofs. */
181
+ proofCreator: PrivateKernelProver;
182
+ /** The circuit simulator for executing ACIR circuits. */
183
+ simulator: CircuitSimulator;
184
+ /** Provider for protocol contract artifacts and instances. */
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;
192
+ /** PXE configuration options. */
193
+ config: PXEConfig;
194
+ /** Optional logger instance or string suffix for the logger name. */
195
+ loggerOrSuffix?: string | Logger;
196
+ /** Optional hooks to observe and influence contract execution. */
197
+ hooks?: ExecutionHooks;
198
+ };
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
+
89
228
  /**
90
229
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
91
230
  * manage private state of users.
92
231
  */
93
232
  export class PXE {
94
233
  private constructor(
95
- private node: AztecNode,
234
+ private node: CachingAztecNode,
235
+ private nodeDebug: AztecNodeDebug | undefined,
236
+ private db: AztecAsyncKVStore,
96
237
  private blockStateSynchronizer: BlockSynchronizer,
97
238
  private keyStore: KeyStore,
98
239
  private contractStore: ContractStore,
99
240
  private noteStore: NoteStore,
100
241
  private capsuleStore: CapsuleStore,
242
+ private factStore: FactStore,
101
243
  private anchorBlockStore: AnchorBlockStore,
102
244
  private senderTaggingStore: SenderTaggingStore,
103
- private senderAddressBookStore: SenderAddressBookStore,
245
+ private taggingSecretSourcesStore: TaggingSecretSourcesStore,
104
246
  private recipientTaggingStore: RecipientTaggingStore,
105
247
  private addressStore: AddressStore,
106
248
  private privateEventStore: PrivateEventStore,
107
249
  private contractSyncService: ContractSyncService,
250
+ private contractClassService: ContractClassService,
251
+ private txResolver: TxResolverService,
252
+ private l2TipsStore: L2TipsProvider,
108
253
  private simulator: CircuitSimulator,
109
254
  private proverEnabled: boolean,
255
+ private autoSync: boolean,
110
256
  private proofCreator: PrivateKernelProver,
111
257
  private protocolContractsProvider: ProtocolContractsProvider,
258
+ private preloadedContractsProvider: PreloadedContractsProvider,
112
259
  private log: Logger,
113
260
  private jobQueue: SerialQueue,
114
261
  private jobCoordinator: JobCoordinator,
115
262
  public debug: PXEDebugUtils,
263
+ private hooks: ExecutionHooks | undefined,
116
264
  ) {}
117
265
 
118
266
  /**
@@ -122,15 +270,18 @@ export class PXE {
122
270
  *
123
271
  * @returns A promise that resolves PXE is ready to be used.
124
272
  */
125
- public static async create(
126
- node: AztecNode,
127
- store: AztecAsyncKVStore,
128
- proofCreator: PrivateKernelProver,
129
- simulator: CircuitSimulator,
130
- protocolContractsProvider: ProtocolContractsProvider,
131
- config: PXEConfig,
132
- loggerOrSuffix?: string | Logger,
133
- ) {
273
+ public static async create({
274
+ node,
275
+ nodeDebug,
276
+ store,
277
+ proofCreator,
278
+ simulator,
279
+ protocolContractsProvider,
280
+ preloadedContractsProvider,
281
+ config,
282
+ loggerOrSuffix,
283
+ hooks,
284
+ }: PXECreateArgs) {
134
285
  // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
135
286
  const bindings: LoggerBindings | undefined =
136
287
  loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
@@ -140,31 +291,53 @@ export class PXE {
140
291
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
141
292
  : loggerOrSuffix;
142
293
 
143
- const proverEnabled = !!config.proverEnabled;
144
- const addressStore = new AddressStore(store);
145
- const privateEventStore = new PrivateEventStore(store);
146
- const contractStore = new ContractStore(store);
147
- const noteStore = new NoteStore(store);
148
- const anchorBlockStore = new AnchorBlockStore(store);
149
- const senderTaggingStore = new SenderTaggingStore(store);
150
- const senderAddressBookStore = new SenderAddressBookStore(store);
151
- const recipientTaggingStore = new RecipientTaggingStore(store);
152
- const capsuleStore = new CapsuleStore(store);
153
- const keyStore = new KeyStore(store);
154
- const tipsStore = new L2TipsKVStore(store, 'pxe');
294
+ const info = await node.getNodeInfo();
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
+
304
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
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);
155
324
  const contractSyncService = new ContractSyncService(
156
- node,
325
+ readCachedNode,
157
326
  contractStore,
327
+ contractClassService,
158
328
  noteStore,
159
329
  createLogger('pxe:contract_sync', bindings),
160
330
  );
331
+ const txResolver = new TxResolverService(readCachedNode);
332
+
161
333
  const synchronizer = new BlockSynchronizer(
162
- node,
334
+ readCachedNode,
163
335
  store,
164
336
  anchorBlockStore,
165
337
  noteStore,
166
338
  privateEventStore,
167
- tipsStore,
339
+ factStore,
340
+ l2TipsStore,
168
341
  contractSyncService,
169
342
  config,
170
343
  bindings,
@@ -177,6 +350,7 @@ export class PXE {
177
350
  recipientTaggingStore,
178
351
  privateEventStore,
179
352
  noteStore,
353
+ factStore,
180
354
  contractSyncService,
181
355
  ]);
182
356
 
@@ -185,39 +359,47 @@ export class PXE {
185
359
  const jobQueue = new SerialQueue();
186
360
 
187
361
  const pxe = new PXE(
188
- node,
362
+ readCachedNode,
363
+ nodeDebug,
364
+ store,
189
365
  synchronizer,
190
366
  keyStore,
191
367
  contractStore,
192
368
  noteStore,
193
369
  capsuleStore,
370
+ factStore,
194
371
  anchorBlockStore,
195
372
  senderTaggingStore,
196
- senderAddressBookStore,
373
+ taggingSecretSourcesStore,
197
374
  recipientTaggingStore,
198
375
  addressStore,
199
376
  privateEventStore,
200
377
  contractSyncService,
378
+ contractClassService,
379
+ txResolver,
380
+ l2TipsStore,
201
381
  simulator,
202
382
  proverEnabled,
383
+ config.autoSync,
203
384
  proofCreator,
204
385
  protocolContractsProvider,
386
+ preloadedContractsProvider,
205
387
  log,
206
388
  jobQueue,
207
389
  jobCoordinator,
208
390
  debugUtils,
391
+ hooks,
209
392
  );
210
393
 
211
394
  debugUtils.setPXEHelpers(
212
395
  pxe.#putInJobQueue.bind(pxe),
213
396
  pxe.#getSimulatorForTx.bind(pxe),
214
- pxe.#simulateUtility.bind(pxe),
397
+ pxe.#executeUtility.bind(pxe),
215
398
  );
216
399
 
217
400
  pxe.jobQueue.start();
218
401
 
219
- await pxe.#registerProtocolContracts();
220
- const info = await node.getNodeInfo();
402
+ await allToCompletion([pxe.#registerProtocolContracts(), pxe.#registerPreloadedContracts()]);
221
403
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
222
404
  return pxe;
223
405
  }
@@ -225,22 +407,50 @@ export class PXE {
225
407
  // Internal methods
226
408
 
227
409
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
228
- const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
410
+ return new ContractFunctionSimulator({
411
+ contractStore: this.contractStore,
412
+ contractClassService: this.contractClassService,
413
+ overrides: overrides?.contracts,
414
+ noteStore: this.noteStore,
415
+ keyStore: this.keyStore,
416
+ addressStore: this.addressStore,
417
+ aztecNode: this.node,
418
+ l2TipsStore: this.l2TipsStore,
419
+ senderTaggingStore: this.senderTaggingStore,
420
+ recipientTaggingStore: this.recipientTaggingStore,
421
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
422
+ capsuleStore: this.capsuleStore,
423
+ factStore: this.factStore,
424
+ privateEventStore: this.privateEventStore,
425
+ simulator: this.simulator,
426
+ contractSyncService: this.contractSyncService,
427
+ txResolver: this.txResolver,
428
+ hooks: this.hooks,
429
+ });
430
+ }
229
431
 
230
- return new ContractFunctionSimulator(
231
- proxyContractStore,
232
- this.noteStore,
233
- this.keyStore,
234
- this.addressStore,
235
- BenchmarkedNodeFactory.create(this.node),
236
- this.senderTaggingStore,
237
- this.recipientTaggingStore,
238
- this.senderAddressBookStore,
239
- this.capsuleStore,
240
- this.privateEventStore,
241
- this.simulator,
242
- this.contractSyncService,
243
- );
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
+ }
244
454
  }
245
455
 
246
456
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -290,83 +500,112 @@ export class PXE {
290
500
  }
291
501
 
292
502
  async #registerProtocolContracts() {
293
- const registered: Record<string, string> = {};
294
- for (const name of protocolContractNames) {
295
- const { address, contractClass, instance, artifact } =
296
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
297
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
298
- await this.contractStore.addContractInstance(instance);
299
- registered[name] = address.toString();
300
- }
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
+ );
301
514
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
302
515
  }
303
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
+
304
532
  // Executes the entrypoint private function, as well as all nested private
305
533
  // functions that might arise.
306
- async #executePrivate(
307
- contractFunctionSimulator: ContractFunctionSimulator,
308
- txRequest: TxExecutionRequest,
309
- scopes: AztecAddress[] | undefined,
310
- jobId: string,
311
- ): 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> {
312
549
  const { origin: contractAddress, functionSelector } = txRequest;
313
550
 
314
551
  try {
315
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
316
-
317
552
  await this.contractSyncService.ensureContractSynced(
318
553
  contractAddress,
319
554
  functionSelector,
320
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
555
+ (privateSyncCall, execScopes) =>
556
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
321
557
  anchorBlockHeader,
322
558
  jobId,
559
+ scopes,
323
560
  );
324
561
 
325
- const result = await contractFunctionSimulator.run(
326
- txRequest,
327
- contractAddress,
328
- functionSelector,
329
- undefined,
562
+ const result = await contractFunctionSimulator.run(txRequest, {
330
563
  anchorBlockHeader,
331
- // The sender for tags is set by contracts, typically by an account
332
- // contract entrypoint
333
- undefined, // senderForTags
334
564
  scopes,
335
565
  jobId,
336
- );
566
+ senderForTags,
567
+ });
337
568
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
338
569
  return result;
339
570
  } catch (err) {
340
571
  if (err instanceof SimulationError) {
341
- await enrichSimulationError(err, this.contractStore, this.log);
572
+ await enrichSimulationError(err, this.contractStore, this.contractClassService, anchorBlockHeader, this.log);
342
573
  }
343
574
  throw err;
344
575
  }
345
576
  }
346
577
 
347
578
  /**
348
- * Simulate a utility function call on the given contract.
579
+ * Execute a utility function call on the given contract.
349
580
  * @param contractFunctionSimulator - The simulator to use for the function call.
350
581
  * @param call - The function call to execute.
351
582
  * @param authWitnesses - Authentication witnesses required for the function call.
352
583
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
353
584
  * accounts if not specified.
354
585
  * @param jobId - The job ID for staged writes.
355
- * @returns The simulation result containing the outputs of the utility function.
586
+ * @returns The execution result containing the outputs of the utility function.
356
587
  */
357
- async #simulateUtility(
588
+ async #executeUtility(
358
589
  contractFunctionSimulator: ContractFunctionSimulator,
359
590
  call: FunctionCall,
360
591
  authWitnesses: AuthWitness[] | undefined,
361
- scopes: AztecAddress[] | undefined,
592
+ scopes: AztecAddress[],
362
593
  jobId: string,
363
594
  ) {
364
595
  try {
365
596
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
366
- 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 };
367
605
  } catch (err) {
368
606
  if (err instanceof SimulationError) {
369
- 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);
370
609
  }
371
610
  throw err;
372
611
  }
@@ -378,11 +617,11 @@ export class PXE {
378
617
  * It can also be used for estimating gas in the future.
379
618
  * @param tx - The transaction to be simulated.
380
619
  */
381
- async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
620
+ async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean, overrides?: SimulationOverrides) {
382
621
  // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
383
622
  // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
384
623
  try {
385
- const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
624
+ const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
386
625
  if (result.revertReason) {
387
626
  throw result.revertReason;
388
627
  }
@@ -390,7 +629,14 @@ export class PXE {
390
629
  } catch (err) {
391
630
  if (err instanceof SimulationError) {
392
631
  try {
393
- 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
+ );
394
640
  } catch (enrichErr) {
395
641
  this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
396
642
  }
@@ -414,11 +660,16 @@ export class PXE {
414
660
  txExecutionRequest: TxExecutionRequest,
415
661
  proofCreator: PrivateKernelProver,
416
662
  privateExecutionResult: PrivateExecutionResult,
663
+ anchorBlockHeader: BlockHeader,
417
664
  config: PrivateKernelExecutionProverConfig,
418
665
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
419
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
420
- const anchorBlockHash = await anchorBlockHeader.hash();
421
- 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
+ );
422
673
  const kernelTraceProver = new PrivateKernelExecutionProver(
423
674
  kernelOracle,
424
675
  proofCreator,
@@ -429,22 +680,44 @@ export class PXE {
429
680
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
430
681
  }
431
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
+
432
694
  // Public API
433
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
+
434
705
  /**
435
706
  * Returns the block header up to which the PXE has synced.
436
707
  * @returns The synced block header
437
708
  */
438
709
  public getSyncedBlockHeader(): Promise<BlockHeader> {
439
- return this.anchorBlockStore.getBlockHeader();
710
+ return this.#putInJobQueue(() => {
711
+ return this.anchorBlockStore.getBlockHeader();
712
+ });
440
713
  }
441
714
 
442
715
  /**
443
- * 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.
444
717
  * @param address - The contract address.
445
- * @returns The contract instance if found, undefined otherwise.
718
+ * @returns The contract instance address preimage if found, undefined otherwise.
446
719
  */
447
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
720
+ public getContractInstance(address: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
448
721
  return this.contractStore.getContractInstance(address);
449
722
  }
450
723
 
@@ -458,19 +731,23 @@ export class PXE {
458
731
  }
459
732
 
460
733
  /**
461
- * Registers a user account in PXE given its master encryption private key.
462
- * Once a new account is registered, the PXE will trial-decrypt all published notes on
463
- * the chain and store those that correspond to the registered account. Will do nothing if the
464
- * 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.
738
+ *
739
+ * Does nothing if the account is already registered.
465
740
  *
466
- * @param secretKey - Secret key of the corresponding user master public key.
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.
467
744
  * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
468
745
  * @returns The complete address of the account.
469
746
  */
470
- public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
747
+ public async registerAccount(keys: AccountPrivacyKeys, partialAddress: PartialAddress): Promise<CompleteAddress> {
471
748
  const accounts = await this.keyStore.getAccounts();
472
- const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
473
- if (accounts.includes(accountCompleteAddress.address)) {
749
+ const accountCompleteAddress = await this.keyStore.addAccount(keys, partialAddress);
750
+ if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
474
751
  this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
475
752
  return accountCompleteAddress;
476
753
  } else {
@@ -483,53 +760,189 @@ export class PXE {
483
760
  }
484
761
 
485
762
  /**
486
- * 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.
487
769
  *
488
- * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
489
- * 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.
490
773
  *
491
- * @param sender - Address of the sender to register.
492
- * @returns The address of the sender.
493
- * 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.
494
775
  */
495
- public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
496
- const accounts = await this.keyStore.getAccounts();
497
- if (accounts.includes(sender)) {
498
- this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
499
- return sender;
500
- }
776
+ public getAccountSecretKeys(account: AztecAddress): Promise<AccountPrivacySecretKeys> {
777
+ return this.keyStore.getAccountSecretKeys(account);
778
+ }
501
779
 
502
- 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
+ }
503
810
 
504
811
  if (wasAdded) {
505
- this.log.info(`Added sender:\n ${sender.toString()}`);
506
- } else {
507
- 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()));
508
814
  }
815
+ }
509
816
 
510
- 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
+ }
511
849
  }
512
850
 
513
851
  /**
514
- * Retrieves senders registered in this PXE.
515
- * @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}.
516
854
  */
517
- public getSenders(): Promise<AztecAddress[]> {
518
- 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;
519
894
  }
520
895
 
521
896
  /**
522
- * Removes a sender registered in this PXE.
523
- * @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.
524
905
  */
525
- public async removeSender(sender: AztecAddress): Promise<void> {
526
- 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
+ }
527
913
 
528
- if (wasRemoved) {
529
- this.log.info(`Removed sender:\n ${sender.toString()}`);
530
- } else {
531
- 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.`);
532
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;
533
946
  }
534
947
 
535
948
  /**
@@ -552,95 +965,34 @@ export class PXE {
552
965
  * @param artifact - The build artifact for the contract class.
553
966
  */
554
967
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
555
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
556
- await this.contractStore.addContractArtifact(contractClassId, artifact);
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
+ }
557
977
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
558
978
  }
559
979
 
560
980
  /**
561
- * Adds deployed contracts to the PXE. Deployed contract information is used to access the
562
- * contract code when simulating local transactions. This is automatically called by aztec.js when
563
- * deploying a contract. Dapps that wish to interact with contracts already deployed should register
564
- * 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.
565
985
  *
566
- * @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.
567
988
  */
568
- public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
569
- const { instance } = contract;
570
- let { artifact } = contract;
571
-
572
- if (artifact) {
573
- // If the user provides an artifact, validate it against the expected class id and register it
574
- const contractClass = await getContractClassFromArtifact(artifact);
575
- const contractClassId = contractClass.id;
576
- if (!contractClassId.equals(instance.currentContractClassId)) {
577
- throw new Error(
578
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
579
- );
580
- }
581
- const computedAddress = await computeContractAddressFromInstance(instance);
582
- if (!computedAddress.equals(instance.address)) {
583
- throw new Error('Added a contract in which the address does not match the contract instance.');
584
- }
585
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
586
-
587
- const publicFunctionSignatures = artifact.functions
588
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
589
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
590
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
591
- } else {
592
- // Otherwise, make sure there is an artifact already registered for that class id
593
- artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
594
- if (!artifact) {
595
- throw new Error(
596
- `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
597
- );
598
- }
599
- }
600
-
601
- await this.contractStore.addContractInstance(instance);
602
- this.log.info(
603
- `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
604
- );
605
- }
606
-
607
- /**
608
- * Updates a deployed contract in the PXE. This is used to update the contract artifact when
609
- * an update has happened, so the new code can be used in the simulation of local transactions.
610
- * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
611
- * @param contractAddress - The address of the contract to update.
612
- * @param artifact - The updated artifact for the contract.
613
- * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
614
- * the current one (current one from the point of view of the node to which the PXE is connected).
615
- */
616
- public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
617
- // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
618
- // 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.
619
991
  return this.#putInJobQueue(async () => {
620
- const currentInstance = await this.contractStore.getContractInstance(contractAddress);
621
- if (!currentInstance) {
622
- throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
623
- }
624
- const contractClass = await getContractClassFromArtifact(artifact);
625
- await this.blockStateSynchronizer.sync();
626
-
627
- const header = await this.anchorBlockStore.getBlockHeader();
628
-
629
- const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
630
- if (!contractClass.id.equals(currentClassId)) {
631
- throw new Error('Could not update contract to a class different from the current one.');
632
- }
633
-
634
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
635
-
636
- const publicFunctionSignatures = artifact.functions
637
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
638
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
639
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
640
-
641
- currentInstance.currentContractClassId = contractClass.id;
642
- await this.contractStore.addContractInstance(currentInstance);
643
- 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;
644
996
  });
645
997
  }
646
998
 
@@ -657,29 +1009,39 @@ export class PXE {
657
1009
  * (where validators prove the public portion).
658
1010
  *
659
1011
  * @param txRequest - An authenticated tx request ready for proving
1012
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
660
1013
  * @returns A result containing the proof and public inputs of the tail circuit.
661
1014
  * @throws If contract code not found, or public simulation reverts.
662
1015
  * Also throws if simulatePublic is true and public simulation reverts.
663
1016
  */
664
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
1017
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
665
1018
  let privateExecutionResult: PrivateExecutionResult;
666
1019
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
667
1020
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
668
1021
  return this.#putInJobQueue(async jobId => {
669
1022
  const totalTimer = new Timer();
1023
+ const recording = this.node.startRecording();
670
1024
  try {
671
1025
  const syncTimer = new Timer();
672
- await this.blockStateSynchronizer.sync();
1026
+ await this.#maybeSync();
1027
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
673
1028
  const syncTime = syncTimer.ms();
674
1029
  const contractFunctionSimulator = this.#getSimulatorForTx();
675
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
1030
+ privateExecutionResult = await this.#executePrivate({
1031
+ contractFunctionSimulator,
1032
+ txRequest,
1033
+ anchorBlockHeader,
1034
+ scopes,
1035
+ jobId,
1036
+ senderForTags,
1037
+ });
676
1038
 
677
1039
  const {
678
1040
  publicInputs,
679
1041
  chonkProof,
680
1042
  executionSteps,
681
1043
  timings: { proving } = {},
682
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
1044
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
683
1045
  simulate: false,
684
1046
  skipFeeEnforcement: false,
685
1047
  profileMode: 'none',
@@ -706,51 +1068,48 @@ export class PXE {
706
1068
 
707
1069
  const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof!, {
708
1070
  timings,
709
- nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
1071
+ nodeRPCCalls: recording.stop(),
710
1072
  });
711
1073
 
712
- // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
713
- // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
714
- // transaction before this one is included in a block from this PXE, and that transaction contains a log with
715
- // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
716
- // storing the tags here prevents linkage of txs sent from the same PXE.
717
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
718
- if (preTagsUsedInTheTx.length > 0) {
719
- // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
720
- const txHash = (await txProvingResult.toTx()).txHash;
721
-
722
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
723
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
724
- preTagsUsedInTheTx,
725
- });
726
- } else {
727
- this.log.debug(`No pre-tags used in the tx`);
728
- }
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
+ );
729
1088
 
730
1089
  return txProvingResult;
731
1090
  } catch (err: any) {
732
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();
733
1095
  }
734
1096
  });
735
1097
  }
736
1098
 
737
1099
  /**
738
1100
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
739
- *
740
- * @param txRequest - An authenticated tx request ready for simulation
741
- * @param msgSender - (Optional) The message sender to use for the simulation.
742
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
1101
+ * @param txRequest - An authenticated tx request ready for simulation.
743
1102
  * @returns A trace of the program execution with gate counts.
744
1103
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
745
1104
  */
746
1105
  public profileTx(
747
1106
  txRequest: TxExecutionRequest,
748
- profileMode: 'full' | 'execution-steps' | 'gates',
749
- skipProofGeneration: boolean = true,
1107
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
750
1108
  ): Promise<TxProfileResult> {
751
1109
  // We disable concurrent profiles for consistency with simulateTx.
752
1110
  return this.#putInJobQueue(async jobId => {
753
1111
  const totalTimer = new Timer();
1112
+ const recording = this.node.startRecording();
754
1113
  try {
755
1114
  const txInfo = {
756
1115
  origin: txRequest.origin,
@@ -765,21 +1124,25 @@ export class PXE {
765
1124
  txInfo,
766
1125
  );
767
1126
  const syncTimer = new Timer();
768
- await this.blockStateSynchronizer.sync();
1127
+ await this.#maybeSync();
1128
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
769
1129
  const syncTime = syncTimer.ms();
770
1130
 
771
1131
  const contractFunctionSimulator = this.#getSimulatorForTx();
772
- const privateExecutionResult = await this.#executePrivate(
1132
+ const privateExecutionResult = await this.#executePrivate({
773
1133
  contractFunctionSimulator,
774
1134
  txRequest,
775
- undefined,
1135
+ anchorBlockHeader,
1136
+ scopes,
776
1137
  jobId,
777
- );
1138
+ senderForTags,
1139
+ });
778
1140
 
779
1141
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
780
1142
  txRequest,
781
1143
  this.proofCreator,
782
1144
  privateExecutionResult,
1145
+ anchorBlockHeader,
783
1146
  {
784
1147
  simulate: skipProofGeneration,
785
1148
  skipFeeEnforcement: false,
@@ -812,10 +1175,12 @@ export class PXE {
812
1175
  total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
813
1176
  };
814
1177
 
815
- const simulatorStats = contractFunctionSimulator.getStats();
816
- return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: simulatorStats.nodeRPCCalls });
1178
+ return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: recording.stop() });
817
1179
  } catch (err: any) {
818
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();
819
1184
  }
820
1185
  });
821
1186
  }
@@ -831,12 +1196,7 @@ export class PXE {
831
1196
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
832
1197
  *
833
1198
  *
834
- * @param txRequest - An authenticated tx request ready for simulation
835
- * @param simulatePublic - Whether to simulate the public part of the transaction.
836
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
837
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
838
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
839
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
1199
+ * @param txRequest - An authenticated tx request ready for simulation.
840
1200
  * @returns A simulated transaction result object that includes public and private return values.
841
1201
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
842
1202
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -845,16 +1205,21 @@ export class PXE {
845
1205
  */
846
1206
  public simulateTx(
847
1207
  txRequest: TxExecutionRequest,
848
- simulatePublic: boolean,
849
- skipTxValidation: boolean = false,
850
- skipFeeEnforcement: boolean = false,
851
- overrides?: SimulationOverrides,
852
- scopes?: AztecAddress[],
1208
+ {
1209
+ simulatePublic,
1210
+ skipTxValidation = false,
1211
+ skipFeeEnforcement = false,
1212
+ skipKernels = true,
1213
+ overrides,
1214
+ scopes,
1215
+ senderForTags,
1216
+ }: SimulateTxOpts,
853
1217
  ): Promise<TxSimulationResult> {
854
1218
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
855
1219
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
856
1220
  // delete the same read value, or reading values that another simulation is currently modifying).
857
1221
  return this.#putInJobQueue(async jobId => {
1222
+ const recording = this.node.startRecording();
858
1223
  try {
859
1224
  const totalTimer = new Timer();
860
1225
  const txInfo = {
@@ -870,24 +1235,26 @@ export class PXE {
870
1235
  txInfo,
871
1236
  );
872
1237
  const syncTimer = new Timer();
873
- await this.blockStateSynchronizer.sync();
1238
+ await this.#maybeSync();
1239
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
874
1240
  const syncTime = syncTimer.ms();
875
1241
 
876
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
877
- // Temporary: in case there are overrides, we have to skip the kernels or validations
878
- // will fail. Consider handing control to the user/wallet on whether they want to run them
879
- // or not.
880
- const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
881
- const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
882
- const skipKernels = hasOverriddenContracts;
883
-
884
- // Set overridden contracts on the sync service so it knows to skip syncing them
885
- if (hasOverriddenContracts) {
886
- 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
+ );
887
1246
  }
1247
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
888
1248
 
889
1249
  // Execution of private functions only; no proving, and no kernel logic.
890
- 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
+ });
891
1258
 
892
1259
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
893
1260
  let executionSteps: PrivateExecutionStep[] = [];
@@ -895,15 +1262,22 @@ export class PXE {
895
1262
  if (skipKernels) {
896
1263
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
897
1264
  privateExecutionResult,
898
- (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
1265
+ (addr, sel) => this.#getDebugFunctionName(addr, sel, anchorBlockHeader),
1266
+ this.node,
899
1267
  ));
900
1268
  } else {
901
1269
  // Kernel logic, plus proving of all private functions and kernels.
902
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
903
- simulate: true,
904
- skipFeeEnforcement,
905
- profileMode: 'none',
906
- }));
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
+ ));
907
1281
  }
908
1282
 
909
1283
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -912,8 +1286,11 @@ export class PXE {
912
1286
  let publicOutput: PublicSimulationOutput | undefined;
913
1287
  if (simulatePublic && publicInputs.forPublic) {
914
1288
  const publicSimulationTimer = new Timer();
915
- publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
1289
+ publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
916
1290
  publicSimulationTime = publicSimulationTimer.ms();
1291
+ if (publicOutput?.debugLogs?.length) {
1292
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.#getDebugContractName(addr, anchorBlockHeader));
1293
+ }
917
1294
  }
918
1295
 
919
1296
  let validationTime: number | undefined;
@@ -922,7 +1299,8 @@ export class PXE {
922
1299
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
923
1300
  validationTime = validationTimer.ms();
924
1301
  if (validationResult.result === 'invalid') {
925
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1302
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1303
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
926
1304
  }
927
1305
  }
928
1306
 
@@ -962,10 +1340,9 @@ export class PXE {
962
1340
  : {}),
963
1341
  });
964
1342
 
965
- const simulatorStats = contractFunctionSimulator.getStats();
966
1343
  return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
967
1344
  timings,
968
- nodeRPCCalls: simulatorStats.nodeRPCCalls,
1345
+ nodeRPCCalls: recording.stop(),
969
1346
  });
970
1347
  } catch (err: any) {
971
1348
  throw this.#contextualizeError(
@@ -973,34 +1350,32 @@ export class PXE {
973
1350
  inspect(txRequest),
974
1351
  `simulatePublic=${simulatePublic}`,
975
1352
  `skipTxValidation=${skipTxValidation}`,
976
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1353
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
977
1354
  );
1355
+ } finally {
1356
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1357
+ recording.stop();
978
1358
  }
979
1359
  });
980
1360
  }
981
1361
 
982
1362
  /**
983
- * Simulate the execution of a contract utility function.
984
- *
1363
+ * Executes a contract utility function.
985
1364
  * @param call - The function call containing the function details, arguments, and target contract address.
986
- * @param authwits - (Optional) The authentication witnesses required for the function call.
987
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
988
- * default to all.
989
- * @returns The result of the utility function call, structured based on the function ABI.
990
1365
  */
991
- public simulateUtility(
1366
+ public executeUtility(
992
1367
  call: FunctionCall,
993
- authwits?: AuthWitness[],
994
- scopes?: AztecAddress[],
995
- ): Promise<UtilitySimulationResult> {
996
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1368
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1369
+ ): Promise<UtilityExecutionResult> {
1370
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
997
1371
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
998
- // delete the same read value, or reading values that another simulation is currently modifying).
1372
+ // delete the same read value, or reading values that another execution is currently modifying).
999
1373
  return this.#putInJobQueue(async jobId => {
1374
+ const recording = this.node.startRecording();
1000
1375
  try {
1001
1376
  const totalTimer = new Timer();
1002
1377
  const syncTimer = new Timer();
1003
- await this.blockStateSynchronizer.sync();
1378
+ await this.#maybeSync();
1004
1379
  const syncTime = syncTimer.ms();
1005
1380
  const functionTimer = new Timer();
1006
1381
  const contractFunctionSimulator = this.#getSimulatorForTx();
@@ -1009,12 +1384,14 @@ export class PXE {
1009
1384
  await this.contractSyncService.ensureContractSynced(
1010
1385
  call.to,
1011
1386
  call.selector,
1012
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1387
+ (privateSyncCall, execScopes) =>
1388
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1013
1389
  anchorBlockHeader,
1014
1390
  jobId,
1391
+ scopes,
1015
1392
  );
1016
1393
 
1017
- const executionResult = await this.#simulateUtility(
1394
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1018
1395
  contractFunctionSimulator,
1019
1396
  call,
1020
1397
  authwits ?? [],
@@ -1034,16 +1411,23 @@ export class PXE {
1034
1411
  unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time }) => acc + time, 0)),
1035
1412
  };
1036
1413
 
1037
- const simulationStats = contractFunctionSimulator.getStats();
1038
- 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
+ };
1039
1420
  } catch (err: any) {
1040
1421
  const { to, name, args } = call;
1041
1422
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1042
1423
  throw this.#contextualizeError(
1043
1424
  err,
1044
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1045
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1425
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1426
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1046
1427
  );
1428
+ } finally {
1429
+ // Idempotent cleanup for the error and early-exit paths. The success path already stopped the recording.
1430
+ recording.stop();
1047
1431
  }
1048
1432
  });
1049
1433
  }
@@ -1068,7 +1452,7 @@ export class PXE {
1068
1452
  let anchorBlockNumber: BlockNumber;
1069
1453
 
1070
1454
  await this.#putInJobQueue(async jobId => {
1071
- await this.blockStateSynchronizer.sync();
1455
+ await this.#maybeSync();
1072
1456
 
1073
1457
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1074
1458
  anchorBlockNumber = anchorBlockHeader.getBlockNumber();
@@ -1078,10 +1462,11 @@ export class PXE {
1078
1462
  await this.contractSyncService.ensureContractSynced(
1079
1463
  filter.contractAddress,
1080
1464
  null,
1081
- async privateSyncCall =>
1082
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1465
+ async (privateSyncCall, execScopes) =>
1466
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1083
1467
  anchorBlockHeader,
1084
1468
  jobId,
1469
+ filter.scopes,
1085
1470
  );
1086
1471
  });
1087
1472
 
@@ -1096,9 +1481,11 @@ export class PXE {
1096
1481
  }
1097
1482
 
1098
1483
  /**
1099
- * Stops the PXE's job queue.
1484
+ * Stops the PXE's job queue and closes the backing store.
1100
1485
  */
1101
- public stop(): Promise<void> {
1102
- return this.jobQueue.end();
1486
+ public async stop(): Promise<void> {
1487
+ await this.jobQueue.end();
1488
+ await this.blockStateSynchronizer.stop();
1489
+ await this.db.close();
1103
1490
  }
1104
1491
  }