@aztec/pxe 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d

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