@aztec/pxe 0.0.1-commit.fffb133c → 0.0.1-dev

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 (309) hide show
  1. package/dest/bin/check_oracle_version.js +5 -5
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +10 -4
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +30 -6
  5. package/dest/config/package_info.js +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.d.ts +66 -31
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.js +214 -75
  9. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  10. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  12. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  15. package/dest/contract_function_simulator/index.d.ts +2 -1
  16. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/index.js +1 -0
  18. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  19. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  22. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +66 -47
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +78 -44
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +363 -114
  37. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  38. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +56 -86
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +123 -98
  41. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +145 -70
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +435 -145
  44. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  45. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/pick_notes.js +20 -3
  47. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  48. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  50. package/dest/contract_logging.d.ts +27 -0
  51. package/dest/contract_logging.d.ts.map +1 -0
  52. package/dest/contract_logging.js +38 -0
  53. package/dest/contract_sync/contract_sync_service.d.ts +45 -0
  54. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  55. package/dest/contract_sync/contract_sync_service.js +150 -0
  56. package/dest/contract_sync/helpers.d.ts +27 -0
  57. package/dest/contract_sync/helpers.d.ts.map +1 -0
  58. package/dest/contract_sync/{index.js → helpers.js} +16 -17
  59. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  60. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  61. package/dest/debug/pxe_debug_utils.js +28 -18
  62. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  63. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/bundle/index.js +2 -0
  65. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  66. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/utils.js +24 -9
  68. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  69. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  70. package/dest/entrypoints/client/lazy/index.js +2 -0
  71. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  72. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/utils.js +25 -10
  74. package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
  75. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  76. package/dest/entrypoints/pxe_creation_options.js +3 -1
  77. package/dest/entrypoints/server/index.d.ts +5 -3
  78. package/dest/entrypoints/server/index.d.ts.map +1 -1
  79. package/dest/entrypoints/server/index.js +4 -2
  80. package/dest/entrypoints/server/utils.d.ts +2 -2
  81. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  82. package/dest/entrypoints/server/utils.js +31 -11
  83. package/dest/events/event_service.d.ts +16 -8
  84. package/dest/events/event_service.d.ts.map +1 -1
  85. package/dest/events/event_service.js +46 -14
  86. package/dest/events/private_event_filter_validator.d.ts +3 -2
  87. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  88. package/dest/events/private_event_filter_validator.js +15 -0
  89. package/dest/hooks/authorize_utility_call.d.ts +37 -0
  90. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  91. package/dest/hooks/authorize_utility_call.js +4 -0
  92. package/dest/hooks/execution_hooks.d.ts +42 -0
  93. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  94. package/dest/hooks/execution_hooks.js +9 -0
  95. package/dest/hooks/index.d.ts +4 -0
  96. package/dest/hooks/index.d.ts.map +1 -0
  97. package/dest/hooks/index.js +1 -0
  98. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  99. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  100. package/dest/job_coordinator/job_coordinator.js +3 -2
  101. package/dest/logs/log_service.d.ts +10 -9
  102. package/dest/logs/log_service.d.ts.map +1 -1
  103. package/dest/logs/log_service.js +50 -85
  104. package/dest/messages/message_context_service.d.ts +17 -0
  105. package/dest/messages/message_context_service.d.ts.map +1 -0
  106. package/dest/messages/message_context_service.js +38 -0
  107. package/dest/notes/note_service.d.ts +29 -8
  108. package/dest/notes/note_service.d.ts.map +1 -1
  109. package/dest/notes/note_service.js +89 -65
  110. package/dest/notes_filter.d.ts +24 -0
  111. package/dest/notes_filter.d.ts.map +1 -0
  112. package/dest/notes_filter.js +4 -0
  113. package/dest/oracle_version.d.ts +4 -3
  114. package/dest/oracle_version.d.ts.map +1 -1
  115. package/dest/oracle_version.js +20 -10
  116. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  117. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  118. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  119. package/dest/private_kernel/hints/index.d.ts +1 -1
  120. package/dest/private_kernel/hints/index.js +1 -1
  121. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  122. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  123. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  124. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  125. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  126. package/dest/private_kernel/hints/test_utils.js +203 -0
  127. package/dest/private_kernel/private_kernel_execution_prover.d.ts +4 -2
  128. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  129. package/dest/private_kernel/private_kernel_execution_prover.js +38 -19
  130. package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
  131. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  132. package/dest/private_kernel/private_kernel_oracle.js +26 -20
  133. package/dest/pxe.d.ts +87 -23
  134. package/dest/pxe.d.ts.map +1 -1
  135. package/dest/pxe.js +178 -119
  136. package/dest/storage/address_store/address_store.d.ts +1 -1
  137. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  138. package/dest/storage/address_store/address_store.js +12 -11
  139. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  140. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  141. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
  142. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  143. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  144. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  145. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  146. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  147. package/dest/storage/backwards_compatibility_tests/schema_tests.js +588 -0
  148. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  149. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  150. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  151. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  152. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  153. package/dest/storage/capsule_store/capsule_service.js +50 -0
  154. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  155. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  156. package/dest/storage/capsule_store/capsule_store.js +42 -36
  157. package/dest/storage/capsule_store/index.d.ts +2 -1
  158. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  159. package/dest/storage/capsule_store/index.js +1 -0
  160. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  161. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  162. package/dest/storage/contract_store/contract_store.js +160 -73
  163. package/dest/storage/metadata.d.ts +1 -1
  164. package/dest/storage/metadata.js +1 -1
  165. package/dest/storage/note_store/note_store.d.ts +13 -3
  166. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  167. package/dest/storage/note_store/note_store.js +147 -107
  168. package/dest/storage/open_pxe_stores.d.ts +31 -0
  169. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  170. package/dest/storage/open_pxe_stores.js +26 -0
  171. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  172. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  173. package/dest/storage/private_event_store/private_event_store.js +87 -61
  174. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  175. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  176. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  177. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  178. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  179. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  180. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  181. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  182. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  183. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  184. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  185. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  186. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  187. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  188. package/dest/tagging/get_all_logs_by_tags.js +20 -3
  189. package/dest/tagging/index.d.ts +6 -5
  190. package/dest/tagging/index.d.ts.map +1 -1
  191. package/dest/tagging/index.js +4 -3
  192. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  193. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  194. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  195. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +56 -0
  196. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  197. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +158 -0
  198. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  199. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  200. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  201. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  202. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
  203. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  204. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +30 -13
  205. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +13 -7
  206. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  207. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +41 -10
  208. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  209. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  210. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  211. package/package.json +26 -16
  212. package/src/bin/check_oracle_version.ts +5 -5
  213. package/src/block_synchronizer/block_synchronizer.ts +45 -21
  214. package/src/config/package_info.ts +1 -1
  215. package/src/contract_function_simulator/contract_function_simulator.ts +389 -134
  216. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  217. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  218. package/src/contract_function_simulator/index.ts +1 -0
  219. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  220. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  221. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  222. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  223. package/src/contract_function_simulator/oracle/interfaces.ts +101 -62
  224. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  225. package/src/contract_function_simulator/oracle/oracle.ts +464 -151
  226. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  227. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +152 -191
  228. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +709 -200
  229. package/src/contract_function_simulator/pick_notes.ts +22 -3
  230. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  231. package/src/contract_logging.ts +52 -0
  232. package/src/contract_sync/contract_sync_service.ts +208 -0
  233. package/src/contract_sync/{index.ts → helpers.ts} +17 -29
  234. package/src/debug/pxe_debug_utils.ts +63 -19
  235. package/src/entrypoints/client/bundle/index.ts +2 -0
  236. package/src/entrypoints/client/bundle/utils.ts +19 -18
  237. package/src/entrypoints/client/lazy/index.ts +2 -0
  238. package/src/entrypoints/client/lazy/utils.ts +20 -18
  239. package/src/entrypoints/pxe_creation_options.ts +13 -1
  240. package/src/entrypoints/server/index.ts +4 -2
  241. package/src/entrypoints/server/utils.ts +25 -29
  242. package/src/events/event_service.ts +70 -24
  243. package/src/events/private_event_filter_validator.ts +21 -1
  244. package/src/hooks/authorize_utility_call.ts +40 -0
  245. package/src/hooks/execution_hooks.ts +48 -0
  246. package/src/hooks/index.ts +7 -0
  247. package/src/job_coordinator/job_coordinator.ts +4 -3
  248. package/src/logs/log_service.ts +88 -141
  249. package/src/messages/message_context_service.ts +45 -0
  250. package/src/notes/note_service.ts +124 -91
  251. package/src/notes_filter.ts +24 -0
  252. package/src/oracle_version.ts +20 -10
  253. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  254. package/src/private_kernel/hints/index.ts +1 -1
  255. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  256. package/src/private_kernel/hints/test_utils.ts +325 -0
  257. package/src/private_kernel/private_kernel_execution_prover.ts +53 -22
  258. package/src/private_kernel/private_kernel_oracle.ts +36 -26
  259. package/src/pxe.ts +351 -168
  260. package/src/storage/address_store/address_store.ts +15 -15
  261. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
  262. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  263. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  264. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  265. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  266. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  267. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +42 -0
  268. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +36 -0
  269. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  270. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
  271. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +16 -0
  272. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
  273. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +97 -0
  274. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  275. package/src/storage/backwards_compatibility_tests/schema_tests.ts +707 -0
  276. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  277. package/src/storage/capsule_store/capsule_service.ts +90 -0
  278. package/src/storage/capsule_store/capsule_store.ts +52 -34
  279. package/src/storage/capsule_store/index.ts +1 -0
  280. package/src/storage/contract_store/contract_store.ts +193 -81
  281. package/src/storage/metadata.ts +1 -1
  282. package/src/storage/note_store/note_store.ts +166 -132
  283. package/src/storage/open_pxe_stores.ts +47 -0
  284. package/src/storage/private_event_store/private_event_store.ts +106 -81
  285. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  286. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  287. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  288. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  289. package/src/tagging/get_all_logs_by_tags.ts +35 -7
  290. package/src/tagging/index.ts +5 -4
  291. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  292. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +236 -0
  293. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  294. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  295. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +54 -18
  296. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -14
  297. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
  298. package/dest/contract_sync/index.d.ts +0 -23
  299. package/dest/contract_sync/index.d.ts.map +0 -1
  300. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  301. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  302. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -15
  303. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
  304. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
  305. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -15
  306. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
  307. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -32
  308. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -143
  309. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -49
package/src/pxe.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { SerialQueue } from '@aztec/foundation/queue';
6
6
  import { Timer } from '@aztec/foundation/timer';
7
7
  import { KeyStore } from '@aztec/key-store';
8
8
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
- import { L2TipsKVStore } from '@aztec/kv-store/stores';
10
9
  import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
11
10
  import type { CircuitSimulator } from '@aztec/simulator/client';
12
11
  import {
@@ -18,6 +17,7 @@ import {
18
17
  } from '@aztec/stdlib/abi';
19
18
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
19
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
21
21
  import {
22
22
  CompleteAddress,
23
23
  type ContractInstanceWithAddress,
@@ -33,6 +33,7 @@ import type {
33
33
  PrivateKernelTailCircuitPublicInputs,
34
34
  } from '@aztec/stdlib/kernel';
35
35
  import {
36
+ BlockHeader,
36
37
  type ContractOverrides,
37
38
  type InTx,
38
39
  PrivateExecutionResult,
@@ -46,7 +47,7 @@ import {
46
47
  TxProfileResult,
47
48
  TxProvingResult,
48
49
  TxSimulationResult,
49
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
50
51
  } from '@aztec/stdlib/tx';
51
52
 
52
53
  import { inspect } from 'util';
@@ -59,11 +60,15 @@ import {
59
60
  generateSimulatedProvingResult,
60
61
  } from './contract_function_simulator/contract_function_simulator.js';
61
62
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
+ import { displayDebugLogs } from './contract_logging.js';
64
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
65
+ import { readCurrentClassId } from './contract_sync/helpers.js';
63
66
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
67
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
68
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
69
+ import type { ExecutionHooks } from './hooks/index.js';
66
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
67
72
  import {
68
73
  PrivateKernelExecutionProver,
69
74
  type PrivateKernelExecutionProverConfig,
@@ -74,16 +79,84 @@ import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_stor
74
79
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
75
80
  import { ContractStore } from './storage/contract_store/contract_store.js';
76
81
  import { NoteStore } from './storage/note_store/note_store.js';
82
+ import { openPxeStores } from './storage/open_pxe_stores.js';
77
83
  import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
78
84
  import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
79
85
  import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
80
86
  import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
87
+ import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
81
88
 
82
89
  export type PackedPrivateEvent = InTx & {
83
90
  packedEvent: Fr[];
84
91
  eventSelector: EventSelector;
85
92
  };
86
93
 
94
+ /** Options for PXE.proveTx. */
95
+ export type ProveTxOpts = {
96
+ /** Addresses whose private state and keys are accessible during private execution. */
97
+ scopes: AztecAddress[];
98
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
99
+ senderForTags?: AztecAddress;
100
+ };
101
+
102
+ /** Options for PXE.profileTx. */
103
+ export type ProfileTxOpts = {
104
+ /** The profiling mode to use. */
105
+ profileMode: 'full' | 'execution-steps' | 'gates';
106
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
107
+ skipProofGeneration?: boolean;
108
+ /** Addresses whose private state and keys are accessible during private execution. */
109
+ scopes: AztecAddress[];
110
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
111
+ senderForTags?: AztecAddress;
112
+ };
113
+
114
+ /** Options for PXE.simulateTx. */
115
+ export type SimulateTxOpts = {
116
+ /** Whether to simulate the public part of the transaction. */
117
+ simulatePublic: boolean;
118
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
119
+ skipTxValidation?: boolean;
120
+ /** If false, fees are enforced. */
121
+ skipFeeEnforcement?: boolean;
122
+ /** If true, kernel logic is emulated in TS for simulation */
123
+ skipKernels?: boolean;
124
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
125
+ overrides?: SimulationOverrides;
126
+ /** Addresses whose private state and keys are accessible during private execution */
127
+ scopes: AztecAddress[];
128
+ /** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
129
+ senderForTags?: AztecAddress;
130
+ };
131
+
132
+ /** Options for PXE.executeUtility. */
133
+ export type ExecuteUtilityOpts = {
134
+ /** The authentication witnesses required for the function call. */
135
+ authwits?: AuthWitness[];
136
+ /** The accounts whose notes we can access in this call */
137
+ scopes: AztecAddress[];
138
+ };
139
+
140
+ /** Args for PXE.create. */
141
+ export type PXECreateArgs = {
142
+ /** The Aztec node to connect to. */
143
+ node: AztecNode;
144
+ /** The key-value store for persisting PXE state. */
145
+ store: AztecAsyncKVStore;
146
+ /** The prover for generating private kernel proofs. */
147
+ proofCreator: PrivateKernelProver;
148
+ /** The circuit simulator for executing ACIR circuits. */
149
+ simulator: CircuitSimulator;
150
+ /** Provider for protocol contract artifacts and instances. */
151
+ protocolContractsProvider: ProtocolContractsProvider;
152
+ /** PXE configuration options. */
153
+ config: PXEConfig;
154
+ /** Optional logger instance or string suffix for the logger name. */
155
+ loggerOrSuffix?: string | Logger;
156
+ /** Optional hooks to observe and influence contract execution. */
157
+ hooks?: ExecutionHooks;
158
+ };
159
+
87
160
  /**
88
161
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
162
  * manage private state of users.
@@ -102,6 +175,9 @@ export class PXE {
102
175
  private recipientTaggingStore: RecipientTaggingStore,
103
176
  private addressStore: AddressStore,
104
177
  private privateEventStore: PrivateEventStore,
178
+ private contractSyncService: ContractSyncService,
179
+ private messageContextService: MessageContextService,
180
+ private l2TipsStore: L2TipsProvider,
105
181
  private simulator: CircuitSimulator,
106
182
  private proverEnabled: boolean,
107
183
  private proofCreator: PrivateKernelProver,
@@ -110,6 +186,7 @@ export class PXE {
110
186
  private jobQueue: SerialQueue,
111
187
  private jobCoordinator: JobCoordinator,
112
188
  public debug: PXEDebugUtils,
189
+ private hooks: ExecutionHooks | undefined,
113
190
  ) {}
114
191
 
115
192
  /**
@@ -119,53 +196,72 @@ export class PXE {
119
196
  *
120
197
  * @returns A promise that resolves PXE is ready to be used.
121
198
  */
122
- public static async create(
123
- node: AztecNode,
124
- store: AztecAsyncKVStore,
125
- proofCreator: PrivateKernelProver,
126
- simulator: CircuitSimulator,
127
- protocolContractsProvider: ProtocolContractsProvider,
128
- config: PXEConfig,
129
- loggerOrSuffix?: string | Logger,
130
- ) {
199
+ public static async create({
200
+ node,
201
+ store,
202
+ proofCreator,
203
+ simulator,
204
+ protocolContractsProvider,
205
+ config,
206
+ loggerOrSuffix,
207
+ hooks,
208
+ }: PXECreateArgs) {
209
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
210
+ const bindings: LoggerBindings | undefined =
211
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
212
+
131
213
  const log =
132
214
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
133
215
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
134
216
  : loggerOrSuffix;
135
217
 
136
- const proverEnabled = !!config.proverEnabled;
137
- const addressStore = new AddressStore(store);
138
- const privateEventStore = new PrivateEventStore(store);
139
- const contractStore = new ContractStore(store);
140
- const noteStore = new NoteStore(store);
141
- const anchorBlockStore = new AnchorBlockStore(store);
142
- const senderTaggingStore = new SenderTaggingStore(store);
143
- const senderAddressBookStore = new SenderAddressBookStore(store);
144
- const recipientTaggingStore = new RecipientTaggingStore(store);
145
- const capsuleStore = new CapsuleStore(store);
146
- const keyStore = new KeyStore(store);
147
- const tipsStore = new L2TipsKVStore(store, 'pxe');
218
+ const info = await node.getNodeInfo();
219
+
220
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
221
+ const {
222
+ addressStore,
223
+ privateEventStore,
224
+ contractStore,
225
+ noteStore,
226
+ anchorBlockStore,
227
+ senderTaggingStore,
228
+ senderAddressBookStore,
229
+ recipientTaggingStore,
230
+ capsuleStore,
231
+ keyStore,
232
+ l2TipsStore,
233
+ } = openPxeStores(store);
234
+ const contractSyncService = new ContractSyncService(
235
+ node,
236
+ contractStore,
237
+ noteStore,
238
+ createLogger('pxe:contract_sync', bindings),
239
+ );
240
+ const messageContextService = new MessageContextService(node);
241
+
148
242
  const synchronizer = new BlockSynchronizer(
149
243
  node,
150
244
  store,
151
245
  anchorBlockStore,
152
246
  noteStore,
153
247
  privateEventStore,
154
- tipsStore,
248
+ l2TipsStore,
249
+ contractSyncService,
155
250
  config,
156
- loggerOrSuffix,
251
+ bindings,
157
252
  );
158
253
 
159
- const jobCoordinator = new JobCoordinator(store);
254
+ const jobCoordinator = new JobCoordinator(store, bindings);
160
255
  jobCoordinator.registerStores([
161
256
  capsuleStore,
162
257
  senderTaggingStore,
163
258
  recipientTaggingStore,
164
259
  privateEventStore,
165
260
  noteStore,
261
+ contractSyncService,
166
262
  ]);
167
263
 
168
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
264
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
169
265
 
170
266
  const jobQueue = new SerialQueue();
171
267
 
@@ -182,6 +278,9 @@ export class PXE {
182
278
  recipientTaggingStore,
183
279
  addressStore,
184
280
  privateEventStore,
281
+ contractSyncService,
282
+ messageContextService,
283
+ l2TipsStore,
185
284
  simulator,
186
285
  proverEnabled,
187
286
  proofCreator,
@@ -190,14 +289,18 @@ export class PXE {
190
289
  jobQueue,
191
290
  jobCoordinator,
192
291
  debugUtils,
292
+ hooks,
193
293
  );
194
294
 
195
- debugUtils.setPXE(pxe);
295
+ debugUtils.setPXEHelpers(
296
+ pxe.#putInJobQueue.bind(pxe),
297
+ pxe.#getSimulatorForTx.bind(pxe),
298
+ pxe.#executeUtility.bind(pxe),
299
+ );
196
300
 
197
301
  pxe.jobQueue.start();
198
302
 
199
303
  await pxe.#registerProtocolContracts();
200
- const info = await node.getNodeInfo();
201
304
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
202
305
  return pxe;
203
306
  }
@@ -207,20 +310,23 @@ export class PXE {
207
310
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
208
311
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
209
312
 
210
- return new ContractFunctionSimulator(
211
- proxyContractStore,
212
- this.noteStore,
213
- this.keyStore,
214
- this.addressStore,
215
- BenchmarkedNodeFactory.create(this.node),
216
- this.anchorBlockStore,
217
- this.senderTaggingStore,
218
- this.recipientTaggingStore,
219
- this.senderAddressBookStore,
220
- this.capsuleStore,
221
- this.privateEventStore,
222
- this.simulator,
223
- );
313
+ return new ContractFunctionSimulator({
314
+ contractStore: proxyContractStore,
315
+ noteStore: this.noteStore,
316
+ keyStore: this.keyStore,
317
+ addressStore: this.addressStore,
318
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
319
+ l2TipsStore: this.l2TipsStore,
320
+ senderTaggingStore: this.senderTaggingStore,
321
+ recipientTaggingStore: this.recipientTaggingStore,
322
+ senderAddressBookStore: this.senderAddressBookStore,
323
+ capsuleStore: this.capsuleStore,
324
+ privateEventStore: this.privateEventStore,
325
+ simulator: this.simulator,
326
+ contractSyncService: this.contractSyncService,
327
+ messageContextService: this.messageContextService,
328
+ hooks: this.hooks,
329
+ });
224
330
  }
225
331
 
226
332
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -272,9 +378,8 @@ export class PXE {
272
378
  async #registerProtocolContracts() {
273
379
  const registered: Record<string, string> = {};
274
380
  for (const name of protocolContractNames) {
275
- const { address, contractClass, instance, artifact } =
276
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
277
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
381
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
382
+ await this.contractStore.addContractArtifact(artifact);
278
383
  await this.contractStore.addContractInstance(instance);
279
384
  registered[name] = address.toString();
280
385
  }
@@ -283,38 +388,42 @@ export class PXE {
283
388
 
284
389
  // Executes the entrypoint private function, as well as all nested private
285
390
  // functions that might arise.
286
- async #executePrivate(
287
- contractFunctionSimulator: ContractFunctionSimulator,
288
- txRequest: TxExecutionRequest,
289
- scopes: AztecAddress[] | undefined,
290
- jobId: string,
291
- ): Promise<PrivateExecutionResult> {
391
+ async #executePrivate({
392
+ contractFunctionSimulator,
393
+ txRequest,
394
+ anchorBlockHeader,
395
+ scopes,
396
+ jobId,
397
+ senderForTags,
398
+ }: {
399
+ contractFunctionSimulator: ContractFunctionSimulator;
400
+ txRequest: TxExecutionRequest;
401
+ anchorBlockHeader: BlockHeader;
402
+ scopes: AztecAddress[];
403
+ jobId: string;
404
+ senderForTags?: AztecAddress;
405
+ }): Promise<PrivateExecutionResult> {
292
406
  const { origin: contractAddress, functionSelector } = txRequest;
293
407
 
294
408
  try {
295
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
296
-
297
- await ensureContractSynced(
409
+ await this.contractSyncService.ensureContractSynced(
298
410
  contractAddress,
299
411
  functionSelector,
300
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
301
- this.node,
302
- this.contractStore,
412
+ (privateSyncCall, execScopes) =>
413
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
303
414
  anchorBlockHeader,
415
+ jobId,
416
+ scopes,
304
417
  );
305
418
 
306
- const result = await contractFunctionSimulator.run(
307
- txRequest,
419
+ const result = await contractFunctionSimulator.run(txRequest, {
308
420
  contractAddress,
309
- functionSelector,
310
- undefined,
421
+ selector: functionSelector,
311
422
  anchorBlockHeader,
312
- // The sender for tags is set by contracts, typically by an account
313
- // contract entrypoint
314
- undefined, // senderForTags
315
423
  scopes,
316
424
  jobId,
317
- );
425
+ senderForTags,
426
+ });
318
427
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
319
428
  return result;
320
429
  } catch (err) {
@@ -326,25 +435,32 @@ export class PXE {
326
435
  }
327
436
 
328
437
  /**
329
- * Simulate a utility function call on the given contract.
438
+ * Execute a utility function call on the given contract.
330
439
  * @param contractFunctionSimulator - The simulator to use for the function call.
331
440
  * @param call - The function call to execute.
332
441
  * @param authWitnesses - Authentication witnesses required for the function call.
333
442
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
334
443
  * accounts if not specified.
335
444
  * @param jobId - The job ID for staged writes.
336
- * @returns The simulation result containing the outputs of the utility function.
445
+ * @returns The execution result containing the outputs of the utility function.
337
446
  */
338
- async #simulateUtility(
447
+ async #executeUtility(
339
448
  contractFunctionSimulator: ContractFunctionSimulator,
340
449
  call: FunctionCall,
341
450
  authWitnesses: AuthWitness[] | undefined,
342
- scopes: AztecAddress[] | undefined,
451
+ scopes: AztecAddress[],
343
452
  jobId: string,
344
453
  ) {
345
454
  try {
346
455
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
347
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
456
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
457
+ call,
458
+ authWitnesses ?? [],
459
+ anchorBlockHeader,
460
+ scopes,
461
+ jobId,
462
+ );
463
+ return { result, offchainEffects };
348
464
  } catch (err) {
349
465
  if (err instanceof SimulationError) {
350
466
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -395,18 +511,37 @@ export class PXE {
395
511
  txExecutionRequest: TxExecutionRequest,
396
512
  proofCreator: PrivateKernelProver,
397
513
  privateExecutionResult: PrivateExecutionResult,
514
+ anchorBlockHeader: BlockHeader,
398
515
  config: PrivateKernelExecutionProverConfig,
399
516
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
400
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
401
- const anchorBlockHash = await anchorBlockHeader.hash();
402
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
403
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
517
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
518
+ const kernelTraceProver = new PrivateKernelExecutionProver(
519
+ kernelOracle,
520
+ proofCreator,
521
+ !this.proverEnabled,
522
+ this.log.getBindings(),
523
+ );
404
524
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
405
525
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
406
526
  }
407
527
 
408
528
  // Public API
409
529
 
530
+ /**
531
+ * Returns the block header up to which the PXE has synced.
532
+ * @returns The synced block header
533
+ */
534
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
535
+ return this.#putInJobQueue(() => {
536
+ return this.anchorBlockStore.getBlockHeader();
537
+ });
538
+ }
539
+
540
+ /**
541
+ * Returns the contract instance for a given address, if it's registered in the PXE.
542
+ * @param address - The contract address.
543
+ * @returns The contract instance if found, undefined otherwise.
544
+ */
410
545
  public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
411
546
  return this.contractStore.getContractInstance(address);
412
547
  }
@@ -456,6 +591,12 @@ export class PXE {
456
591
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
457
592
  */
458
593
  public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
594
+ if (!(await sender.isValid())) {
595
+ throw new Error(
596
+ `Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
597
+ );
598
+ }
599
+
459
600
  const accounts = await this.keyStore.getAccounts();
460
601
  if (accounts.includes(sender)) {
461
602
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -466,6 +607,9 @@ export class PXE {
466
607
 
467
608
  if (wasAdded) {
468
609
  this.log.info(`Added sender:\n ${sender.toString()}`);
610
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
611
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
612
+ await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
469
613
  } else {
470
614
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
471
615
  }
@@ -515,8 +659,7 @@ export class PXE {
515
659
  * @param artifact - The build artifact for the contract class.
516
660
  */
517
661
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
518
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
519
- await this.contractStore.addContractArtifact(contractClassId, artifact);
662
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
520
663
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
521
664
  }
522
665
 
@@ -535,22 +678,24 @@ export class PXE {
535
678
  if (artifact) {
536
679
  // If the user provides an artifact, validate it against the expected class id and register it
537
680
  const contractClass = await getContractClassFromArtifact(artifact);
538
- const contractClassId = contractClass.id;
539
- if (!contractClassId.equals(instance.currentContractClassId)) {
681
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
540
682
  throw new Error(
541
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
683
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
542
684
  );
543
685
  }
544
686
  const computedAddress = await computeContractAddressFromInstance(instance);
545
687
  if (!computedAddress.equals(instance.address)) {
546
688
  throw new Error('Added a contract in which the address does not match the contract instance.');
547
689
  }
548
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
690
+
691
+ await this.contractStore.addContractArtifact(artifact, contractClass);
549
692
 
550
693
  const publicFunctionSignatures = artifact.functions
551
694
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
552
695
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
553
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
696
+ if (publicFunctionSignatures.length > 0) {
697
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
698
+ }
554
699
  } else {
555
700
  // Otherwise, make sure there is an artifact already registered for that class id
556
701
  artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
@@ -594,15 +739,18 @@ export class PXE {
594
739
  throw new Error('Could not update contract to a class different from the current one.');
595
740
  }
596
741
 
597
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
598
-
599
742
  const publicFunctionSignatures = artifact.functions
600
743
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
601
744
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
602
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
745
+ if (publicFunctionSignatures.length > 0) {
746
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
747
+ }
603
748
 
604
749
  currentInstance.currentContractClassId = contractClass.id;
605
- await this.contractStore.addContractInstance(currentInstance);
750
+ await Promise.all([
751
+ this.contractStore.addContractArtifact(artifact, contractClass),
752
+ this.contractStore.addContractInstance(currentInstance),
753
+ ]);
606
754
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
607
755
  });
608
756
  }
@@ -620,11 +768,12 @@ export class PXE {
620
768
  * (where validators prove the public portion).
621
769
  *
622
770
  * @param txRequest - An authenticated tx request ready for proving
771
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
623
772
  * @returns A result containing the proof and public inputs of the tail circuit.
624
773
  * @throws If contract code not found, or public simulation reverts.
625
774
  * Also throws if simulatePublic is true and public simulation reverts.
626
775
  */
627
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
776
+ public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
628
777
  let privateExecutionResult: PrivateExecutionResult;
629
778
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
630
779
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -633,16 +782,24 @@ export class PXE {
633
782
  try {
634
783
  const syncTimer = new Timer();
635
784
  await this.blockStateSynchronizer.sync();
785
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
636
786
  const syncTime = syncTimer.ms();
637
787
  const contractFunctionSimulator = this.#getSimulatorForTx();
638
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
788
+ privateExecutionResult = await this.#executePrivate({
789
+ contractFunctionSimulator,
790
+ txRequest,
791
+ anchorBlockHeader,
792
+ scopes,
793
+ jobId,
794
+ senderForTags,
795
+ });
639
796
 
640
797
  const {
641
798
  publicInputs,
642
799
  chonkProof,
643
800
  executionSteps,
644
801
  timings: { proving } = {},
645
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
802
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
646
803
  simulate: false,
647
804
  skipFeeEnforcement: false,
648
805
  profileMode: 'none',
@@ -672,23 +829,20 @@ export class PXE {
672
829
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
673
830
  });
674
831
 
675
- // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
676
- // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
677
- // transaction before this one is included in a block from this PXE, and that transaction contains a log with
678
- // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
679
- // storing the tags here prevents linkage of txs sent from the same PXE.
680
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
681
- if (preTagsUsedInTheTx.length > 0) {
682
- // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
683
- const txHash = (await txProvingResult.toTx()).txHash;
684
-
685
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
686
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
687
- preTagsUsedInTheTx,
688
- });
689
- } else {
690
- this.log.debug(`No pre-tags used in the tx`);
691
- }
832
+ // We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
833
+ // (which would link them) without having to rely on this tx being mined (and us seeing the indices being used
834
+ // onchain).
835
+ // Note that this must happen _after_ proving as it requires the proof's public inputs, from which the kernels
836
+ // may have removed some logs due to note-nullifier squashing - this may lead to range of tagging indices we've
837
+ // actually used to being reduced.
838
+ await persistSenderTaggingIndexRangesForTx(
839
+ this.senderTaggingStore,
840
+ privateExecutionResult.entrypoint.taggingIndexRanges,
841
+ publicInputs,
842
+ () => txProvingResult.getTxHash(),
843
+ jobId,
844
+ this.log,
845
+ );
692
846
 
693
847
  return txProvingResult;
694
848
  } catch (err: any) {
@@ -699,17 +853,13 @@ export class PXE {
699
853
 
700
854
  /**
701
855
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
702
- *
703
- * @param txRequest - An authenticated tx request ready for simulation
704
- * @param msgSender - (Optional) The message sender to use for the simulation.
705
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
856
+ * @param txRequest - An authenticated tx request ready for simulation.
706
857
  * @returns A trace of the program execution with gate counts.
707
858
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
708
859
  */
709
860
  public profileTx(
710
861
  txRequest: TxExecutionRequest,
711
- profileMode: 'full' | 'execution-steps' | 'gates',
712
- skipProofGeneration: boolean = true,
862
+ { profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
713
863
  ): Promise<TxProfileResult> {
714
864
  // We disable concurrent profiles for consistency with simulateTx.
715
865
  return this.#putInJobQueue(async jobId => {
@@ -729,20 +879,24 @@ export class PXE {
729
879
  );
730
880
  const syncTimer = new Timer();
731
881
  await this.blockStateSynchronizer.sync();
882
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
732
883
  const syncTime = syncTimer.ms();
733
884
 
734
885
  const contractFunctionSimulator = this.#getSimulatorForTx();
735
- const privateExecutionResult = await this.#executePrivate(
886
+ const privateExecutionResult = await this.#executePrivate({
736
887
  contractFunctionSimulator,
737
888
  txRequest,
738
- undefined,
889
+ anchorBlockHeader,
890
+ scopes,
739
891
  jobId,
740
- );
892
+ senderForTags,
893
+ });
741
894
 
742
895
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
743
896
  txRequest,
744
897
  this.proofCreator,
745
898
  privateExecutionResult,
899
+ anchorBlockHeader,
746
900
  {
747
901
  simulate: skipProofGeneration,
748
902
  skipFeeEnforcement: false,
@@ -794,12 +948,7 @@ export class PXE {
794
948
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
795
949
  *
796
950
  *
797
- * @param txRequest - An authenticated tx request ready for simulation
798
- * @param simulatePublic - Whether to simulate the public part of the transaction.
799
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
800
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
801
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
802
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
951
+ * @param txRequest - An authenticated tx request ready for simulation.
803
952
  * @returns A simulated transaction result object that includes public and private return values.
804
953
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
805
954
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -808,11 +957,15 @@ export class PXE {
808
957
  */
809
958
  public simulateTx(
810
959
  txRequest: TxExecutionRequest,
811
- simulatePublic: boolean,
812
- skipTxValidation: boolean = false,
813
- skipFeeEnforcement: boolean = false,
814
- overrides?: SimulationOverrides,
815
- scopes?: AztecAddress[],
960
+ {
961
+ simulatePublic,
962
+ skipTxValidation = false,
963
+ skipFeeEnforcement = false,
964
+ skipKernels = true,
965
+ overrides,
966
+ scopes,
967
+ senderForTags,
968
+ }: SimulateTxOpts,
816
969
  ): Promise<TxSimulationResult> {
817
970
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
818
971
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -834,16 +987,34 @@ export class PXE {
834
987
  );
835
988
  const syncTimer = new Timer();
836
989
  await this.blockStateSynchronizer.sync();
990
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
837
991
  const syncTime = syncTimer.ms();
838
992
 
993
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
994
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
995
+
996
+ if (hasOverriddenContracts && !skipKernels) {
997
+ throw new Error(
998
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
999
+ );
1000
+ }
839
1001
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
840
- // Temporary: in case there are overrides, we have to skip the kernels or validations
841
- // will fail. Consider handing control to the user/wallet on whether they want to run them
842
- // or not.
843
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
1002
+
1003
+ if (hasOverriddenContracts) {
1004
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
1005
+ // We exclude them so the sync service skips them entirely.
1006
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
1007
+ }
844
1008
 
845
1009
  // Execution of private functions only; no proving, and no kernel logic.
846
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
1010
+ const privateExecutionResult = await this.#executePrivate({
1011
+ contractFunctionSimulator,
1012
+ txRequest,
1013
+ anchorBlockHeader,
1014
+ scopes,
1015
+ jobId,
1016
+ senderForTags,
1017
+ });
847
1018
 
848
1019
  let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
849
1020
  let executionSteps: PrivateExecutionStep[] = [];
@@ -851,15 +1022,22 @@ export class PXE {
851
1022
  if (skipKernels) {
852
1023
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
853
1024
  privateExecutionResult,
854
- this.contractStore,
1025
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
1026
+ this.node,
855
1027
  ));
856
1028
  } else {
857
1029
  // Kernel logic, plus proving of all private functions and kernels.
858
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
859
- simulate: true,
860
- skipFeeEnforcement,
861
- profileMode: 'none',
862
- }));
1030
+ ({ publicInputs, executionSteps } = await this.#prove(
1031
+ txRequest,
1032
+ this.proofCreator,
1033
+ privateExecutionResult,
1034
+ anchorBlockHeader,
1035
+ {
1036
+ simulate: true,
1037
+ skipFeeEnforcement,
1038
+ profileMode: 'none',
1039
+ },
1040
+ ));
863
1041
  }
864
1042
 
865
1043
  const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
@@ -870,6 +1048,9 @@ export class PXE {
870
1048
  const publicSimulationTimer = new Timer();
871
1049
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
872
1050
  publicSimulationTime = publicSimulationTimer.ms();
1051
+ if (publicOutput?.debugLogs?.length) {
1052
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
1053
+ }
873
1054
  }
874
1055
 
875
1056
  let validationTime: number | undefined;
@@ -878,7 +1059,8 @@ export class PXE {
878
1059
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
879
1060
  validationTime = validationTimer.ms();
880
1061
  if (validationResult.result === 'invalid') {
881
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
1062
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
1063
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
882
1064
  }
883
1065
  }
884
1066
 
@@ -929,29 +1111,23 @@ export class PXE {
929
1111
  inspect(txRequest),
930
1112
  `simulatePublic=${simulatePublic}`,
931
1113
  `skipTxValidation=${skipTxValidation}`,
932
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1114
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
933
1115
  );
934
1116
  }
935
1117
  });
936
1118
  }
937
1119
 
938
1120
  /**
939
- * Simulate the execution of a contract utility function.
940
- *
1121
+ * Executes a contract utility function.
941
1122
  * @param call - The function call containing the function details, arguments, and target contract address.
942
- * @param authwits - (Optional) The authentication witnesses required for the function call.
943
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
944
- * default to all.
945
- * @returns The result of the utility function call, structured based on the function ABI.
946
1123
  */
947
- public simulateUtility(
1124
+ public executeUtility(
948
1125
  call: FunctionCall,
949
- authwits?: AuthWitness[],
950
- scopes?: AztecAddress[],
951
- ): Promise<UtilitySimulationResult> {
952
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1126
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
1127
+ ): Promise<UtilityExecutionResult> {
1128
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
953
1129
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
954
- // delete the same read value, or reading values that another simulation is currently modifying).
1130
+ // delete the same read value, or reading values that another execution is currently modifying).
955
1131
  return this.#putInJobQueue(async jobId => {
956
1132
  try {
957
1133
  const totalTimer = new Timer();
@@ -962,16 +1138,17 @@ export class PXE {
962
1138
  const contractFunctionSimulator = this.#getSimulatorForTx();
963
1139
 
964
1140
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
965
- await ensureContractSynced(
1141
+ await this.contractSyncService.ensureContractSynced(
966
1142
  call.to,
967
1143
  call.selector,
968
- privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
969
- this.node,
970
- this.contractStore,
1144
+ (privateSyncCall, execScopes) =>
1145
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
971
1146
  anchorBlockHeader,
1147
+ jobId,
1148
+ scopes,
972
1149
  );
973
1150
 
974
- const executionResult = await this.#simulateUtility(
1151
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
975
1152
  contractFunctionSimulator,
976
1153
  call,
977
1154
  authwits ?? [],
@@ -992,14 +1169,19 @@ export class PXE {
992
1169
  };
993
1170
 
994
1171
  const simulationStats = contractFunctionSimulator.getStats();
995
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1172
+ return {
1173
+ result: executionResult,
1174
+ offchainEffects,
1175
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1176
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1177
+ };
996
1178
  } catch (err: any) {
997
1179
  const { to, name, args } = call;
998
1180
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
999
1181
  throw this.#contextualizeError(
1000
1182
  err,
1001
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1002
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1183
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1184
+ `scopes=${scopes.map(s => s.toString()).join(', ')}`,
1003
1185
  );
1004
1186
  }
1005
1187
  });
@@ -1032,14 +1214,14 @@ export class PXE {
1032
1214
 
1033
1215
  const contractFunctionSimulator = this.#getSimulatorForTx();
1034
1216
 
1035
- await ensureContractSynced(
1217
+ await this.contractSyncService.ensureContractSynced(
1036
1218
  filter.contractAddress,
1037
1219
  null,
1038
- async privateSyncCall =>
1039
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1040
- this.node,
1041
- this.contractStore,
1220
+ async (privateSyncCall, execScopes) =>
1221
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1042
1222
  anchorBlockHeader,
1223
+ jobId,
1224
+ filter.scopes,
1043
1225
  );
1044
1226
  });
1045
1227
 
@@ -1056,7 +1238,8 @@ export class PXE {
1056
1238
  /**
1057
1239
  * Stops the PXE's job queue.
1058
1240
  */
1059
- public stop(): Promise<void> {
1060
- return this.jobQueue.end();
1241
+ public async stop(): Promise<void> {
1242
+ await this.jobQueue.end();
1243
+ await this.blockStateSynchronizer.stop();
1061
1244
  }
1062
1245
  }