@aztec/pxe 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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