@aztec/pxe 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e

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 (302) hide show
  1. package/dest/bin/check_oracle_version.js +5 -5
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +16 -6
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +91 -22
  5. package/dest/config/index.d.ts +4 -2
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +12 -2
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  10. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  12. package/dest/contract_function_simulator/contract_function_simulator.d.ts +66 -36
  13. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/contract_function_simulator.js +230 -89
  15. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  16. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  17. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  24. package/dest/contract_function_simulator/index.d.ts +3 -2
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +2 -1
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -7
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +9 -11
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  35. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -8
  36. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +7 -12
  38. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  39. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  41. package/dest/contract_function_simulator/oracle/interfaces.d.ts +67 -47
  42. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  44. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  46. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  47. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  48. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  49. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  50. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  51. package/dest/contract_function_simulator/oracle/oracle.d.ts +75 -42
  52. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  53. package/dest/contract_function_simulator/oracle/oracle.js +327 -119
  54. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  55. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  56. package/dest/contract_function_simulator/oracle/private_execution.js +5 -38
  57. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +59 -76
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +125 -90
  60. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +140 -73
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  62. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +347 -162
  63. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  64. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  65. package/dest/contract_function_simulator/pick_notes.js +20 -3
  66. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  67. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  69. package/dest/contract_logging.d.ts +27 -0
  70. package/dest/contract_logging.d.ts.map +1 -0
  71. package/dest/contract_logging.js +38 -0
  72. package/dest/contract_sync/contract_sync_service.d.ts +44 -0
  73. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  74. package/dest/contract_sync/contract_sync_service.js +116 -0
  75. package/dest/contract_sync/helpers.d.ts +28 -0
  76. package/dest/contract_sync/helpers.d.ts.map +1 -0
  77. package/dest/contract_sync/helpers.js +60 -0
  78. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  79. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  80. package/dest/debug/pxe_debug_utils.js +28 -17
  81. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  82. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/index.js +2 -0
  84. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  85. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  86. package/dest/entrypoints/client/bundle/utils.js +23 -9
  87. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  88. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/index.js +2 -0
  90. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  91. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  92. package/dest/entrypoints/client/lazy/utils.js +24 -10
  93. package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
  94. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  95. package/dest/entrypoints/pxe_creation_options.js +3 -1
  96. package/dest/entrypoints/server/index.d.ts +5 -2
  97. package/dest/entrypoints/server/index.d.ts.map +1 -1
  98. package/dest/entrypoints/server/index.js +4 -1
  99. package/dest/entrypoints/server/utils.d.ts +2 -2
  100. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  101. package/dest/entrypoints/server/utils.js +30 -11
  102. package/dest/events/event_service.d.ts +7 -6
  103. package/dest/events/event_service.d.ts.map +1 -1
  104. package/dest/events/event_service.js +33 -24
  105. package/dest/events/private_event_filter_validator.d.ts +6 -5
  106. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  107. package/dest/events/private_event_filter_validator.js +20 -6
  108. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  109. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  110. package/dest/job_coordinator/job_coordinator.js +3 -2
  111. package/dest/logs/log_service.d.ts +11 -9
  112. package/dest/logs/log_service.d.ts.map +1 -1
  113. package/dest/logs/log_service.js +52 -64
  114. package/dest/messages/message_context_service.d.ts +17 -0
  115. package/dest/messages/message_context_service.d.ts.map +1 -0
  116. package/dest/messages/message_context_service.js +36 -0
  117. package/dest/notes/note_service.d.ts +9 -9
  118. package/dest/notes/note_service.d.ts.map +1 -1
  119. package/dest/notes/note_service.js +45 -40
  120. package/dest/notes_filter.d.ts +24 -0
  121. package/dest/notes_filter.d.ts.map +1 -0
  122. package/dest/notes_filter.js +4 -0
  123. package/dest/oracle_version.d.ts +4 -3
  124. package/dest/oracle_version.d.ts.map +1 -1
  125. package/dest/oracle_version.js +20 -9
  126. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  127. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  128. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  129. package/dest/private_kernel/hints/index.d.ts +3 -3
  130. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  131. package/dest/private_kernel/hints/index.js +2 -2
  132. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  133. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  134. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +140 -73
  135. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  136. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  137. package/dest/private_kernel/hints/test_utils.js +203 -0
  138. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  139. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  140. package/dest/private_kernel/private_kernel_execution_prover.js +21 -16
  141. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -25
  142. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  143. package/dest/private_kernel/private_kernel_oracle.js +91 -2
  144. package/dest/pxe.d.ts +80 -59
  145. package/dest/pxe.d.ts.map +1 -1
  146. package/dest/pxe.js +163 -145
  147. package/dest/storage/address_store/address_store.d.ts +1 -1
  148. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  149. package/dest/storage/address_store/address_store.js +12 -11
  150. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  151. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  152. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
  153. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  154. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  155. package/dest/storage/capsule_store/capsule_service.js +50 -0
  156. package/dest/storage/capsule_store/capsule_store.d.ts +25 -10
  157. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  158. package/dest/storage/capsule_store/capsule_store.js +143 -28
  159. package/dest/storage/capsule_store/index.d.ts +2 -1
  160. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  161. package/dest/storage/capsule_store/index.js +1 -0
  162. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  163. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  164. package/dest/storage/contract_store/contract_store.js +160 -85
  165. package/dest/storage/metadata.d.ts +1 -1
  166. package/dest/storage/metadata.js +1 -1
  167. package/dest/storage/note_store/note_store.d.ts +50 -51
  168. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  169. package/dest/storage/note_store/note_store.js +284 -263
  170. package/dest/storage/note_store/stored_note.d.ts +16 -0
  171. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  172. package/dest/storage/note_store/stored_note.js +43 -0
  173. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  174. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  175. package/dest/storage/private_event_store/private_event_store.js +229 -111
  176. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  177. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  178. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  179. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +16 -9
  180. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  181. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  182. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  183. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  184. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  185. package/dest/storage/tagging_store/sender_tagging_store.d.ts +43 -32
  186. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  187. package/dest/storage/tagging_store/sender_tagging_store.js +300 -122
  188. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  189. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  190. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  191. package/dest/tagging/index.d.ts +4 -3
  192. package/dest/tagging/index.d.ts.map +1 -1
  193. package/dest/tagging/index.js +2 -1
  194. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
  195. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  196. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +12 -26
  197. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  198. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  199. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  200. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  201. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
  202. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  203. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +18 -12
  204. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  205. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  206. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +23 -16
  207. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +8 -7
  208. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  209. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +44 -27
  210. package/package.json +27 -18
  211. package/src/bin/check_oracle_version.ts +5 -4
  212. package/src/block_synchronizer/block_synchronizer.ts +113 -35
  213. package/src/config/index.ts +9 -1
  214. package/src/config/package_info.ts +1 -1
  215. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  216. package/src/contract_function_simulator/contract_function_simulator.ts +392 -154
  217. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  218. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  219. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  220. package/src/contract_function_simulator/index.ts +2 -1
  221. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +10 -10
  222. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  223. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  224. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +5 -11
  225. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  226. package/src/contract_function_simulator/oracle/interfaces.ts +97 -59
  227. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  228. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  229. package/src/contract_function_simulator/oracle/oracle.ts +422 -166
  230. package/src/contract_function_simulator/oracle/private_execution.ts +5 -71
  231. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +169 -185
  232. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +578 -193
  233. package/src/contract_function_simulator/pick_notes.ts +22 -3
  234. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  235. package/src/contract_logging.ts +52 -0
  236. package/src/contract_sync/contract_sync_service.ts +176 -0
  237. package/src/contract_sync/helpers.ts +98 -0
  238. package/src/debug/pxe_debug_utils.ts +63 -18
  239. package/src/entrypoints/client/bundle/index.ts +2 -0
  240. package/src/entrypoints/client/bundle/utils.ts +18 -18
  241. package/src/entrypoints/client/lazy/index.ts +2 -0
  242. package/src/entrypoints/client/lazy/utils.ts +19 -18
  243. package/src/entrypoints/pxe_creation_options.ts +9 -1
  244. package/src/entrypoints/server/index.ts +4 -1
  245. package/src/entrypoints/server/utils.ts +24 -29
  246. package/src/events/event_service.ts +31 -26
  247. package/src/events/private_event_filter_validator.ts +23 -5
  248. package/src/job_coordinator/job_coordinator.ts +4 -3
  249. package/src/logs/log_service.ts +94 -104
  250. package/src/messages/message_context_service.ts +44 -0
  251. package/src/notes/note_service.ts +54 -48
  252. package/src/notes_filter.ts +24 -0
  253. package/src/oracle_version.ts +20 -9
  254. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  255. package/src/private_kernel/hints/index.ts +2 -2
  256. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +195 -136
  257. package/src/private_kernel/hints/test_utils.ts +325 -0
  258. package/src/private_kernel/private_kernel_execution_prover.ts +25 -20
  259. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  260. package/src/pxe.ts +297 -223
  261. package/src/storage/address_store/address_store.ts +15 -15
  262. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
  263. package/src/storage/capsule_store/capsule_service.ts +90 -0
  264. package/src/storage/capsule_store/capsule_store.ts +183 -29
  265. package/src/storage/capsule_store/index.ts +1 -0
  266. package/src/storage/contract_store/contract_store.ts +193 -101
  267. package/src/storage/metadata.ts +1 -1
  268. package/src/storage/note_store/note_store.ts +323 -320
  269. package/src/storage/note_store/stored_note.ts +48 -0
  270. package/src/storage/private_event_store/private_event_store.ts +296 -124
  271. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  272. package/src/storage/tagging_store/recipient_tagging_store.ts +111 -21
  273. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  274. package/src/storage/tagging_store/sender_tagging_store.ts +366 -134
  275. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  276. package/src/tagging/index.ts +3 -2
  277. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +27 -29
  278. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  279. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  280. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +31 -15
  281. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +29 -26
  282. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +42 -29
  283. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  284. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  285. package/dest/contract_function_simulator/proxied_node.js +0 -27
  286. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  287. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  288. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  289. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  290. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  291. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  292. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  293. package/dest/public_storage/public_storage_service.d.ts +0 -24
  294. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  295. package/dest/public_storage/public_storage_service.js +0 -26
  296. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  297. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  298. package/dest/tree_membership/tree_membership_service.js +0 -84
  299. package/src/contract_function_simulator/proxied_node.ts +0 -33
  300. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  301. package/src/public_storage/public_storage_service.ts +0 -33
  302. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -17,16 +18,15 @@ import {
17
18
  } from '@aztec/stdlib/abi';
18
19
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
20
22
  import {
21
23
  CompleteAddress,
22
- type ContractClassWithId,
23
24
  type ContractInstanceWithAddress,
24
25
  type PartialAddress,
25
26
  computeContractAddressFromInstance,
26
27
  getContractClassFromArtifact,
27
28
  } from '@aztec/stdlib/contract';
28
29
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
30
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
31
  import type {
32
32
  PrivateExecutionStep,
@@ -34,6 +34,7 @@ import type {
34
34
  PrivateKernelTailCircuitPublicInputs,
35
35
  } from '@aztec/stdlib/kernel';
36
36
  import {
37
+ BlockHeader,
37
38
  type ContractOverrides,
38
39
  type InTx,
39
40
  PrivateExecutionResult,
@@ -47,29 +48,32 @@ import {
47
48
  TxProfileResult,
48
49
  TxProvingResult,
49
50
  TxSimulationResult,
50
- UtilitySimulationResult,
51
+ UtilityExecutionResult,
51
52
  } from '@aztec/stdlib/tx';
52
53
 
53
54
  import { inspect } from 'util';
54
55
 
55
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
57
  import type { PXEConfig } from './config/index.js';
58
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
59
  import {
58
60
  ContractFunctionSimulator,
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
65
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
66
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
68
72
  import {
69
73
  PrivateKernelExecutionProver,
70
74
  type PrivateKernelExecutionProverConfig,
71
75
  } from './private_kernel/private_kernel_execution_prover.js';
72
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
76
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
73
77
  import { AddressStore } from './storage/address_store/address_store.js';
74
78
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
75
79
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -85,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
85
89
  eventSelector: EventSelector;
86
90
  };
87
91
 
92
+ /** Options for PXE.profileTx. */
93
+ export type ProfileTxOpts = {
94
+ /** The profiling mode to use. */
95
+ profileMode: 'full' | 'execution-steps' | 'gates';
96
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
97
+ skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AztecAddress[];
100
+ };
101
+
102
+ /** Options for PXE.simulateTx. */
103
+ export type SimulateTxOpts = {
104
+ /** Whether to simulate the public part of the transaction. */
105
+ simulatePublic: boolean;
106
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
107
+ skipTxValidation?: boolean;
108
+ /** If false, fees are enforced. */
109
+ skipFeeEnforcement?: boolean;
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
113
+ overrides?: SimulationOverrides;
114
+ /** Addresses whose private state and keys are accessible during private execution */
115
+ scopes: AztecAddress[];
116
+ };
117
+
118
+ /** Options for PXE.executeUtility. */
119
+ export type ExecuteUtilityOpts = {
120
+ /** The authentication witnesses required for the function call. */
121
+ authwits?: AuthWitness[];
122
+ /** The accounts whose notes we can access in this call */
123
+ scopes: AztecAddress[];
124
+ };
125
+
126
+ /** Args for PXE.create. */
127
+ export type PXECreateArgs = {
128
+ /** The Aztec node to connect to. */
129
+ node: AztecNode;
130
+ /** The key-value store for persisting PXE state. */
131
+ store: AztecAsyncKVStore;
132
+ /** The prover for generating private kernel proofs. */
133
+ proofCreator: PrivateKernelProver;
134
+ /** The circuit simulator for executing ACIR circuits. */
135
+ simulator: CircuitSimulator;
136
+ /** Provider for protocol contract artifacts and instances. */
137
+ protocolContractsProvider: ProtocolContractsProvider;
138
+ /** PXE configuration options. */
139
+ config: PXEConfig;
140
+ /** Optional logger instance or string suffix for the logger name. */
141
+ loggerOrSuffix?: string | Logger;
142
+ };
143
+
88
144
  /**
89
145
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
146
  * manage private state of users.
@@ -92,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
92
148
  export class PXE {
93
149
  private constructor(
94
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
95
152
  private blockStateSynchronizer: BlockSynchronizer,
96
153
  private keyStore: KeyStore,
97
154
  private contractStore: ContractStore,
@@ -103,6 +160,9 @@ export class PXE {
103
160
  private recipientTaggingStore: RecipientTaggingStore,
104
161
  private addressStore: AddressStore,
105
162
  private privateEventStore: PrivateEventStore,
163
+ private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
165
+ private l2TipsStore: L2TipsProvider,
106
166
  private simulator: CircuitSimulator,
107
167
  private proverEnabled: boolean,
108
168
  private proofCreator: PrivateKernelProver,
@@ -120,25 +180,31 @@ export class PXE {
120
180
  *
121
181
  * @returns A promise that resolves PXE is ready to be used.
122
182
  */
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
- ) {
183
+ public static async create({
184
+ node,
185
+ store,
186
+ proofCreator,
187
+ simulator,
188
+ protocolContractsProvider,
189
+ config,
190
+ loggerOrSuffix,
191
+ }: PXECreateArgs) {
192
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
193
+ const bindings: LoggerBindings | undefined =
194
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
195
+
132
196
  const log =
133
197
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
198
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
199
  : loggerOrSuffix;
136
200
 
137
- const proverEnabled = !!config.proverEnabled;
201
+ const info = await node.getNodeInfo();
202
+
203
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
204
  const addressStore = new AddressStore(store);
139
205
  const privateEventStore = new PrivateEventStore(store);
140
206
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
207
+ const noteStore = new NoteStore(store);
142
208
  const anchorBlockStore = new AnchorBlockStore(store);
143
209
  const senderTaggingStore = new SenderTaggingStore(store);
144
210
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,24 +212,43 @@ export class PXE {
146
212
  const capsuleStore = new CapsuleStore(store);
147
213
  const keyStore = new KeyStore(store);
148
214
  const tipsStore = new L2TipsKVStore(store, 'pxe');
215
+ const contractSyncService = new ContractSyncService(
216
+ node,
217
+ contractStore,
218
+ noteStore,
219
+ createLogger('pxe:contract_sync', bindings),
220
+ );
221
+ const messageContextService = new MessageContextService(node);
222
+
149
223
  const synchronizer = new BlockSynchronizer(
150
224
  node,
225
+ store,
151
226
  anchorBlockStore,
152
227
  noteStore,
153
228
  privateEventStore,
154
229
  tipsStore,
230
+ contractSyncService,
155
231
  config,
156
- loggerOrSuffix,
232
+ bindings,
157
233
  );
158
234
 
159
- const jobCoordinator = new JobCoordinator(store);
235
+ const jobCoordinator = new JobCoordinator(store, bindings);
236
+ jobCoordinator.registerStores([
237
+ capsuleStore,
238
+ senderTaggingStore,
239
+ recipientTaggingStore,
240
+ privateEventStore,
241
+ noteStore,
242
+ contractSyncService,
243
+ ]);
160
244
 
161
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
245
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
162
246
 
163
247
  const jobQueue = new SerialQueue();
164
248
 
165
249
  const pxe = new PXE(
166
250
  node,
251
+ store,
167
252
  synchronizer,
168
253
  keyStore,
169
254
  contractStore,
@@ -175,6 +260,9 @@ export class PXE {
175
260
  recipientTaggingStore,
176
261
  addressStore,
177
262
  privateEventStore,
263
+ contractSyncService,
264
+ messageContextService,
265
+ tipsStore,
178
266
  simulator,
179
267
  proverEnabled,
180
268
  proofCreator,
@@ -185,12 +273,15 @@ export class PXE {
185
273
  debugUtils,
186
274
  );
187
275
 
188
- debugUtils.setPXE(pxe);
276
+ debugUtils.setPXEHelpers(
277
+ pxe.#putInJobQueue.bind(pxe),
278
+ pxe.#getSimulatorForTx.bind(pxe),
279
+ pxe.#executeUtility.bind(pxe),
280
+ );
189
281
 
190
282
  pxe.jobQueue.start();
191
283
 
192
284
  await pxe.#registerProtocolContracts();
193
- const info = await node.getNodeInfo();
194
285
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
195
286
  return pxe;
196
287
  }
@@ -200,20 +291,22 @@ export class PXE {
200
291
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
201
292
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
202
293
 
203
- return new ContractFunctionSimulator(
204
- proxyContractStore,
205
- this.noteStore,
206
- this.keyStore,
207
- this.addressStore,
208
- ProxiedNodeFactory.create(this.node),
209
- this.anchorBlockStore,
210
- this.senderTaggingStore,
211
- this.recipientTaggingStore,
212
- this.senderAddressBookStore,
213
- this.capsuleStore,
214
- this.privateEventStore,
215
- this.simulator,
216
- );
294
+ return new ContractFunctionSimulator({
295
+ contractStore: proxyContractStore,
296
+ noteStore: this.noteStore,
297
+ keyStore: this.keyStore,
298
+ addressStore: this.addressStore,
299
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
300
+ l2TipsStore: this.l2TipsStore,
301
+ senderTaggingStore: this.senderTaggingStore,
302
+ recipientTaggingStore: this.recipientTaggingStore,
303
+ senderAddressBookStore: this.senderAddressBookStore,
304
+ capsuleStore: this.capsuleStore,
305
+ privateEventStore: this.privateEventStore,
306
+ simulator: this.simulator,
307
+ contractSyncService: this.contractSyncService,
308
+ messageContextService: this.messageContextService,
309
+ });
217
310
  }
218
311
 
219
312
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -265,34 +358,20 @@ export class PXE {
265
358
  async #registerProtocolContracts() {
266
359
  const registered: Record<string, string> = {};
267
360
  for (const name of protocolContractNames) {
268
- const { address, contractClass, instance, artifact } =
269
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
270
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
361
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
362
+ await this.contractStore.addContractArtifact(artifact);
271
363
  await this.contractStore.addContractInstance(instance);
272
364
  registered[name] = address.toString();
273
365
  }
274
366
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
275
367
  }
276
368
 
277
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
278
- return !!(await this.node.getContractClass(id));
279
- }
280
-
281
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
282
- return !!(await this.node.getContract(address));
283
- }
284
-
285
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
286
- const initNullifier = await siloNullifier(address, address.toField());
287
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
288
- }
289
-
290
369
  // Executes the entrypoint private function, as well as all nested private
291
370
  // functions that might arise.
292
371
  async #executePrivate(
293
372
  contractFunctionSimulator: ContractFunctionSimulator,
294
373
  txRequest: TxExecutionRequest,
295
- scopes: AztecAddress[] | undefined,
374
+ scopes: AztecAddress[],
296
375
  jobId: string,
297
376
  ): Promise<PrivateExecutionResult> {
298
377
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -300,18 +379,23 @@ export class PXE {
300
379
  try {
301
380
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
302
381
 
303
- const result = await contractFunctionSimulator.run(
304
- txRequest,
382
+ await this.contractSyncService.ensureContractSynced(
305
383
  contractAddress,
306
384
  functionSelector,
307
- undefined,
385
+ (privateSyncCall, execScopes) =>
386
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
308
387
  anchorBlockHeader,
309
- // The sender for tags is set by contracts, typically by an account
310
- // contract entrypoint
311
- undefined, // senderForTags
312
- scopes,
313
388
  jobId,
389
+ scopes,
314
390
  );
391
+
392
+ const result = await contractFunctionSimulator.run(txRequest, {
393
+ contractAddress,
394
+ selector: functionSelector,
395
+ anchorBlockHeader,
396
+ scopes,
397
+ jobId,
398
+ });
315
399
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
316
400
  return result;
317
401
  } catch (err) {
@@ -323,25 +407,32 @@ export class PXE {
323
407
  }
324
408
 
325
409
  /**
326
- * Simulate a utility function call on the given contract.
410
+ * Execute a utility function call on the given contract.
327
411
  * @param contractFunctionSimulator - The simulator to use for the function call.
328
412
  * @param call - The function call to execute.
329
413
  * @param authWitnesses - Authentication witnesses required for the function call.
330
414
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
331
415
  * accounts if not specified.
332
416
  * @param jobId - The job ID for staged writes.
333
- * @returns The simulation result containing the outputs of the utility function.
417
+ * @returns The execution result containing the outputs of the utility function.
334
418
  */
335
- async #simulateUtility(
419
+ async #executeUtility(
336
420
  contractFunctionSimulator: ContractFunctionSimulator,
337
421
  call: FunctionCall,
338
422
  authWitnesses: AuthWitness[] | undefined,
339
- scopes: AztecAddress[] | undefined,
423
+ scopes: AztecAddress[],
340
424
  jobId: string,
341
425
  ) {
342
426
  try {
343
427
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
344
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
428
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
429
+ call,
430
+ authWitnesses ?? [],
431
+ anchorBlockHeader,
432
+ scopes,
433
+ jobId,
434
+ );
435
+ return { result, offchainEffects };
345
436
  } catch (err) {
346
437
  if (err instanceof SimulationError) {
347
438
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -394,85 +485,46 @@ export class PXE {
394
485
  privateExecutionResult: PrivateExecutionResult,
395
486
  config: PrivateKernelExecutionProverConfig,
396
487
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
397
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
398
- const kernelOracle = new PrivateKernelOracleImpl(
399
- this.contractStore,
400
- this.keyStore,
401
- this.node,
402
- simulationAnchorBlock,
488
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
489
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
490
+ const kernelTraceProver = new PrivateKernelExecutionProver(
491
+ kernelOracle,
492
+ proofCreator,
493
+ !this.proverEnabled,
494
+ this.log.getBindings(),
403
495
  );
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
405
496
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
497
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
498
  }
408
499
 
409
500
  // Public API
410
501
 
411
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
- return this.contractStore.getContractInstance(address);
502
+ /**
503
+ * Returns the block header up to which the PXE has synced.
504
+ * @returns The synced block header
505
+ */
506
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
507
+ return this.#putInJobQueue(() => {
508
+ return this.anchorBlockStore.getBlockHeader();
509
+ });
413
510
  }
414
511
 
415
512
  /**
416
- * Returns the contract class metadata given a contract class id.
417
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
418
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
419
- * @param id - Identifier of the class.
420
- * @param includeArtifact - Identifier of the class.
421
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
422
- * for `includeArtifact`
423
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
424
- * should the pxe query the node for contract public info, and merge it with its own definitions?
425
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
426
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
427
- * do for the time being.
513
+ * Returns the contract instance for a given address, if it's registered in the PXE.
514
+ * @param address - The contract address.
515
+ * @returns The contract instance if found, undefined otherwise.
428
516
  */
429
- public async getContractClassMetadata(
430
- id: Fr,
431
- includeArtifact: boolean = false,
432
- ): Promise<{
433
- contractClass: ContractClassWithId | undefined;
434
- isContractClassPubliclyRegistered: boolean;
435
- artifact: ContractArtifact | undefined;
436
- }> {
437
- const artifact = await this.contractStore.getContractArtifact(id);
438
- if (!artifact) {
439
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
440
- }
441
-
442
- return {
443
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
444
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
445
- artifact: includeArtifact ? artifact : undefined,
446
- };
517
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
518
+ return this.contractStore.getContractInstance(address);
447
519
  }
448
520
 
449
521
  /**
450
- * Returns the contract metadata given an address.
451
- * The metadata consists of its contract instance, which includes the contract class identifier,
452
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
453
- * and whether the contract instance with the given address has been publicly deployed.
454
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
455
- * This query is not dependent on the PXE.
456
- * @param address - The address that the contract instance resides at.
457
- * @returns - It returns the contract metadata
458
- * TODO(@spalladino): Should we return the public keys in plain as well here?
522
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
523
+ * @param id - Identifier of the contract class.
524
+ * @returns The contract artifact if found, undefined otherwise.
459
525
  */
460
- public async getContractMetadata(address: AztecAddress): Promise<{
461
- contractInstance: ContractInstanceWithAddress | undefined;
462
- isContractInitialized: boolean;
463
- isContractPublished: boolean;
464
- }> {
465
- let instance;
466
- try {
467
- instance = await this.contractStore.getContractInstance(address);
468
- } catch {
469
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
470
- }
471
- return {
472
- contractInstance: instance,
473
- isContractInitialized: await this.#isContractInitialized(address),
474
- isContractPublished: await this.#isContractPublished(address),
475
- };
526
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
527
+ return await this.contractStore.getContractArtifact(id);
476
528
  }
477
529
 
478
530
  /**
@@ -497,7 +549,6 @@ export class PXE {
497
549
  }
498
550
 
499
551
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
500
- await this.noteStore.addScope(accountCompleteAddress.address);
501
552
  return accountCompleteAddress;
502
553
  }
503
554
 
@@ -512,6 +563,12 @@ export class PXE {
512
563
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
513
564
  */
514
565
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
566
+ if (!(await sender.isValid())) {
567
+ throw new Error(
568
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
569
+ );
570
+ }
571
+
515
572
  const accounts = await this.keyStore.getAccounts();
516
573
  if (accounts.includes(sender)) {
517
574
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -522,6 +579,9 @@ export class PXE {
522
579
 
523
580
  if (wasAdded) {
524
581
  this.log.info(`Added sender:\n ${sender.toString()}`);
582
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
583
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
584
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
525
585
  } else {
526
586
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
527
587
  }
@@ -571,8 +631,7 @@ export class PXE {
571
631
  * @param artifact - The build artifact for the contract class.
572
632
  */
573
633
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
574
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
575
- await this.contractStore.addContractArtifact(contractClassId, artifact);
634
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
576
635
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
577
636
  }
578
637
 
@@ -591,17 +650,17 @@ export class PXE {
591
650
  if (artifact) {
592
651
  // If the user provides an artifact, validate it against the expected class id and register it
593
652
  const contractClass = await getContractClassFromArtifact(artifact);
594
- const contractClassId = contractClass.id;
595
- if (!contractClassId.equals(instance.currentContractClassId)) {
653
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
596
654
  throw new Error(
597
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
655
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
598
656
  );
599
657
  }
600
658
  const computedAddress = await computeContractAddressFromInstance(instance);
601
659
  if (!computedAddress.equals(instance.address)) {
602
660
  throw new Error('Added a contract in which the address does not match the contract instance.');
603
661
  }
604
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
662
+
663
+ await this.contractStore.addContractArtifact(artifact, contractClass);
605
664
 
606
665
  const publicFunctionSignatures = artifact.functions
607
666
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -645,26 +704,21 @@ export class PXE {
645
704
 
646
705
  const header = await this.anchorBlockStore.getBlockHeader();
647
706
 
648
- const currentClassId = await readCurrentClassId(
649
- contractAddress,
650
- currentInstance,
651
- this.node,
652
- header.globalVariables.blockNumber,
653
- header.globalVariables.timestamp,
654
- );
707
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
655
708
  if (!contractClass.id.equals(currentClassId)) {
656
709
  throw new Error('Could not update contract to a class different from the current one.');
657
710
  }
658
711
 
659
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
660
-
661
712
  const publicFunctionSignatures = artifact.functions
662
713
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
663
714
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
664
715
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
665
716
 
666
717
  currentInstance.currentContractClassId = contractClass.id;
667
- await this.contractStore.addContractInstance(currentInstance);
718
+ await Promise.all([
719
+ this.contractStore.addContractArtifact(artifact, contractClass),
720
+ this.contractStore.addContractInstance(currentInstance),
721
+ ]);
668
722
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
669
723
  });
670
724
  }
@@ -682,11 +736,12 @@ export class PXE {
682
736
  * (where validators prove the public portion).
683
737
  *
684
738
  * @param txRequest - An authenticated tx request ready for proving
739
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
685
740
  * @returns A result containing the proof and public inputs of the tail circuit.
686
741
  * @throws If contract code not found, or public simulation reverts.
687
742
  * Also throws if simulatePublic is true and public simulation reverts.
688
743
  */
689
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
744
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
690
745
  let privateExecutionResult: PrivateExecutionResult;
691
746
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
692
747
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -697,7 +752,7 @@ export class PXE {
697
752
  await this.blockStateSynchronizer.sync();
698
753
  const syncTime = syncTimer.ms();
699
754
  const contractFunctionSimulator = this.#getSimulatorForTx();
700
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
755
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
701
756
 
702
757
  const {
703
758
  publicInputs,
@@ -739,17 +794,17 @@ export class PXE {
739
794
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
740
795
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
741
796
  // storing the tags here prevents linkage of txs sent from the same PXE.
742
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
743
- if (preTagsUsedInTheTx.length > 0) {
797
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
798
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
744
799
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
745
800
  const txHash = (await txProvingResult.toTx()).txHash;
746
801
 
747
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
748
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
749
- preTagsUsedInTheTx,
802
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
803
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
804
+ taggingIndexRangesUsedInTheTx,
750
805
  });
751
806
  } else {
752
- this.log.debug(`No pre-tags used in the tx`);
807
+ this.log.debug(`No tagging index ranges used in the tx`);
753
808
  }
754
809
 
755
810
  return txProvingResult;
@@ -761,17 +816,13 @@ export class PXE {
761
816
 
762
817
  /**
763
818
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
764
- *
765
- * @param txRequest - An authenticated tx request ready for simulation
766
- * @param msgSender - (Optional) The message sender to use for the simulation.
767
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
819
+ * @param txRequest - An authenticated tx request ready for simulation.
768
820
  * @returns A trace of the program execution with gate counts.
769
821
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
770
822
  */
771
823
  public profileTx(
772
824
  txRequest: TxExecutionRequest,
773
- profileMode: 'full' | 'execution-steps' | 'gates',
774
- skipProofGeneration: boolean = true,
825
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
775
826
  ): Promise<TxProfileResult> {
776
827
  // We disable concurrent profiles for consistency with simulateTx.
777
828
  return this.#putInJobQueue(async jobId => {
@@ -794,12 +845,7 @@ export class PXE {
794
845
  const syncTime = syncTimer.ms();
795
846
 
796
847
  const contractFunctionSimulator = this.#getSimulatorForTx();
797
- const privateExecutionResult = await this.#executePrivate(
798
- contractFunctionSimulator,
799
- txRequest,
800
- undefined,
801
- jobId,
802
- );
848
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
803
849
 
804
850
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
805
851
  txRequest,
@@ -856,12 +902,7 @@ export class PXE {
856
902
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
857
903
  *
858
904
  *
859
- * @param txRequest - An authenticated tx request ready for simulation
860
- * @param simulatePublic - Whether to simulate the public part of the transaction.
861
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
862
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
863
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
864
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
905
+ * @param txRequest - An authenticated tx request ready for simulation.
865
906
  * @returns A simulated transaction result object that includes public and private return values.
866
907
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
867
908
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -870,11 +911,14 @@ export class PXE {
870
911
  */
871
912
  public simulateTx(
872
913
  txRequest: TxExecutionRequest,
873
- simulatePublic: boolean,
874
- skipTxValidation: boolean = false,
875
- skipFeeEnforcement: boolean = false,
876
- overrides?: SimulationOverrides,
877
- scopes?: AztecAddress[],
914
+ {
915
+ simulatePublic,
916
+ skipTxValidation = false,
917
+ skipFeeEnforcement = false,
918
+ skipKernels = true,
919
+ overrides,
920
+ scopes,
921
+ }: SimulateTxOpts,
878
922
  ): Promise<TxSimulationResult> {
879
923
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
880
924
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -898,11 +942,21 @@ export class PXE {
898
942
  await this.blockStateSynchronizer.sync();
899
943
  const syncTime = syncTimer.ms();
900
944
 
945
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
946
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
947
+
948
+ if (hasOverriddenContracts && !skipKernels) {
949
+ throw new Error(
950
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
951
+ );
952
+ }
901
953
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
902
- // Temporary: in case there are overrides, we have to skip the kernels or validations
903
- // will fail. Consider handing control to the user/wallet on whether they want to run them
904
- // or not.
905
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
954
+
955
+ if (hasOverriddenContracts) {
956
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
957
+ // We exclude them so the sync service skips them entirely.
958
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
959
+ }
906
960
 
907
961
  // Execution of private functions only; no proving, and no kernel logic.
908
962
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -911,15 +965,10 @@ export class PXE {
911
965
  let executionSteps: PrivateExecutionStep[] = [];
912
966
 
913
967
  if (skipKernels) {
914
- // According to the protocol rules, the nonce generator for the note hashes
915
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
916
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
917
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
918
- : privateExecutionResult.firstNullifier;
919
968
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
920
969
  privateExecutionResult,
921
- nonceGenerator,
922
- this.contractStore,
970
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
971
+ this.node,
923
972
  ));
924
973
  } else {
925
974
  // Kernel logic, plus proving of all private functions and kernels.
@@ -938,6 +987,9 @@ export class PXE {
938
987
  const publicSimulationTimer = new Timer();
939
988
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
940
989
  publicSimulationTime = publicSimulationTimer.ms();
990
+ if (publicOutput?.debugLogs?.length) {
991
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
992
+ }
941
993
  }
942
994
 
943
995
  let validationTime: number | undefined;
@@ -946,7 +998,8 @@ export class PXE {
946
998
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
947
999
  validationTime = validationTimer.ms();
948
1000
  if (validationResult.result === 'invalid') {
949
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1001
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1002
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
950
1003
  }
951
1004
  }
952
1005
 
@@ -997,29 +1050,23 @@ export class PXE {
997
1050
  inspect(txRequest),
998
1051
  `simulatePublic=${simulatePublic}`,
999
1052
  `skipTxValidation=${skipTxValidation}`,
1000
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1053
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1001
1054
  );
1002
1055
  }
1003
1056
  });
1004
1057
  }
1005
1058
 
1006
1059
  /**
1007
- * Simulate the execution of a contract utility function.
1008
- *
1060
+ * Executes a contract utility function.
1009
1061
  * @param call - The function call containing the function details, arguments, and target contract address.
1010
- * @param authwits - (Optional) The authentication witnesses required for the function call.
1011
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
- * default to all.
1013
- * @returns The result of the utility function call, structured based on the function ABI.
1014
1062
  */
1015
- public simulateUtility(
1063
+ public executeUtility(
1016
1064
  call: FunctionCall,
1017
- authwits?: AuthWitness[],
1018
- scopes?: AztecAddress[],
1019
- ): Promise<UtilitySimulationResult> {
1020
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1065
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1066
+ ): Promise<UtilityExecutionResult> {
1067
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1021
1068
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1022
- // delete the same read value, or reading values that another simulation is currently modifying).
1069
+ // delete the same read value, or reading values that another execution is currently modifying).
1023
1070
  return this.#putInJobQueue(async jobId => {
1024
1071
  try {
1025
1072
  const totalTimer = new Timer();
@@ -1029,11 +1076,18 @@ export class PXE {
1029
1076
  const functionTimer = new Timer();
1030
1077
  const contractFunctionSimulator = this.#getSimulatorForTx();
1031
1078
 
1032
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1033
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1079
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1080
+ await this.contractSyncService.ensureContractSynced(
1081
+ call.to,
1082
+ call.selector,
1083
+ (privateSyncCall, execScopes) =>
1084
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1085
+ anchorBlockHeader,
1086
+ jobId,
1087
+ scopes,
1034
1088
  );
1035
1089
 
1036
- const executionResult = await this.#simulateUtility(
1090
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1037
1091
  contractFunctionSimulator,
1038
1092
  call,
1039
1093
  authwits ?? [],
@@ -1054,14 +1108,19 @@ export class PXE {
1054
1108
  };
1055
1109
 
1056
1110
  const simulationStats = contractFunctionSimulator.getStats();
1057
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1111
+ return {
1112
+ result: executionResult,
1113
+ offchainEffects,
1114
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1115
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1116
+ };
1058
1117
  } catch (err: any) {
1059
1118
  const { to, name, args } = call;
1060
1119
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1061
1120
  throw this.#contextualizeError(
1062
1121
  err,
1063
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1064
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1122
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1123
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1065
1124
  );
1066
1125
  }
1067
1126
  });
@@ -1080,32 +1139,47 @@ export class PXE {
1080
1139
  * Defaults to the latest known block to PXE + 1.
1081
1140
  * @returns - The packed events with block and tx metadata.
1082
1141
  */
1083
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1084
- return this.#putInJobQueue(async jobId => {
1142
+ public async getPrivateEvents(
1143
+ eventSelector: EventSelector,
1144
+ filter: PrivateEventFilter,
1145
+ ): Promise<PackedPrivateEvent[]> {
1146
+ let anchorBlockNumber: BlockNumber;
1147
+
1148
+ await this.#putInJobQueue(async jobId => {
1085
1149
  await this.blockStateSynchronizer.sync();
1150
+
1151
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1152
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1153
+
1086
1154
  const contractFunctionSimulator = this.#getSimulatorForTx();
1087
1155
 
1088
- await this.contractStore.syncPrivateState(
1156
+ await this.contractSyncService.ensureContractSynced(
1089
1157
  filter.contractAddress,
1090
1158
  null,
1091
- async privateSyncCall =>
1092
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1159
+ async (privateSyncCall, execScopes) =>
1160
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1161
+ anchorBlockHeader,
1162
+ jobId,
1163
+ filter.scopes,
1093
1164
  );
1165
+ });
1094
1166
 
1095
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1167
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1168
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1096
1169
 
1097
- this.log.debug(
1098
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1099
- );
1170
+ this.log.debug(
1171
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1172
+ );
1100
1173
 
1101
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1102
- });
1174
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1175
  }
1104
1176
 
1105
1177
  /**
1106
- * Stops the PXE's job queue.
1178
+ * Stops the PXE's job queue and closes the backing store.
1107
1179
  */
1108
- public stop(): Promise<void> {
1109
- return this.jobQueue.end();
1180
+ public async stop(): Promise<void> {
1181
+ await this.jobQueue.end();
1182
+ await this.blockStateSynchronizer.stop();
1183
+ await this.db.close();
1110
1184
  }
1111
1185
  }