@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/dest/pxe.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { SerialQueue } from '@aztec/foundation/queue';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
- import { KeyStore } from '@aztec/key-store';
5
- import { L2TipsKVStore } from '@aztec/kv-store/stores';
6
4
  import { protocolContractNames } from '@aztec/protocol-contracts';
7
5
  import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
8
6
  import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
@@ -13,22 +11,18 @@ import { BlockSynchronizer } from './block_synchronizer/index.js';
13
11
  import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
14
12
  import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
15
13
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
16
- import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
14
+ import { displayDebugLogs } from './contract_logging.js';
15
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
16
+ import { readCurrentClassId } from './contract_sync/helpers.js';
17
17
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
18
18
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
19
19
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
20
20
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
21
+ import { MessageContextService } from './messages/message_context_service.js';
21
22
  import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
22
23
  import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
23
- import { AddressStore } from './storage/address_store/address_store.js';
24
- import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
25
- import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
26
- import { ContractStore } from './storage/contract_store/contract_store.js';
27
- import { NoteStore } from './storage/note_store/note_store.js';
28
- import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
29
- import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
30
- import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
31
- import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
24
+ import { openPxeStores } from './storage/open_pxe_stores.js';
25
+ import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
32
26
  /**
33
27
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
34
28
  * manage private state of users.
@@ -45,6 +39,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
45
39
  recipientTaggingStore;
46
40
  addressStore;
47
41
  privateEventStore;
42
+ contractSyncService;
43
+ messageContextService;
44
+ l2TipsStore;
48
45
  simulator;
49
46
  proverEnabled;
50
47
  proofCreator;
@@ -53,7 +50,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
53
50
  jobQueue;
54
51
  jobCoordinator;
55
52
  debug;
56
- constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
53
+ hooks;
54
+ constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, l2TipsStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug, hooks){
57
55
  this.node = node;
58
56
  this.blockStateSynchronizer = blockStateSynchronizer;
59
57
  this.keyStore = keyStore;
@@ -66,6 +64,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
66
64
  this.recipientTaggingStore = recipientTaggingStore;
67
65
  this.addressStore = addressStore;
68
66
  this.privateEventStore = privateEventStore;
67
+ this.contractSyncService = contractSyncService;
68
+ this.messageContextService = messageContextService;
69
+ this.l2TipsStore = l2TipsStore;
69
70
  this.simulator = simulator;
70
71
  this.proverEnabled = proverEnabled;
71
72
  this.proofCreator = proofCreator;
@@ -74,6 +75,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
74
75
  this.jobQueue = jobQueue;
75
76
  this.jobCoordinator = jobCoordinator;
76
77
  this.debug = debug;
78
+ this.hooks = hooks;
77
79
  }
78
80
  /**
79
81
  * Creates an instance of a PXE by instantiating all the necessary data providers and services.
@@ -81,43 +83,54 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
81
83
  * can be contacted.
82
84
  *
83
85
  * @returns A promise that resolves PXE is ready to be used.
84
- */ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
86
+ */ static async create({ node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix, hooks }) {
87
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
88
+ const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
85
89
  const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
86
- const proverEnabled = !!config.proverEnabled;
87
- const addressStore = new AddressStore(store);
88
- const privateEventStore = new PrivateEventStore(store);
89
- const contractStore = new ContractStore(store);
90
- const noteStore = new NoteStore(store);
91
- const anchorBlockStore = new AnchorBlockStore(store);
92
- const senderTaggingStore = new SenderTaggingStore(store);
93
- const senderAddressBookStore = new SenderAddressBookStore(store);
94
- const recipientTaggingStore = new RecipientTaggingStore(store);
95
- const capsuleStore = new CapsuleStore(store);
96
- const keyStore = new KeyStore(store);
97
- const tipsStore = new L2TipsKVStore(store, 'pxe');
98
- const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, loggerOrSuffix);
99
- const jobCoordinator = new JobCoordinator(store);
90
+ const info = await node.getNodeInfo();
91
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
92
+ const { addressStore, privateEventStore, contractStore, noteStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, capsuleStore, keyStore, l2TipsStore } = openPxeStores(store);
93
+ const contractSyncService = new ContractSyncService(node, contractStore, noteStore, createLogger('pxe:contract_sync', bindings));
94
+ const messageContextService = new MessageContextService(node);
95
+ const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, l2TipsStore, contractSyncService, config, bindings);
96
+ const jobCoordinator = new JobCoordinator(store, bindings);
100
97
  jobCoordinator.registerStores([
101
98
  capsuleStore,
102
99
  senderTaggingStore,
103
100
  recipientTaggingStore,
104
101
  privateEventStore,
105
- noteStore
102
+ noteStore,
103
+ contractSyncService
106
104
  ]);
107
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
105
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
108
106
  const jobQueue = new SerialQueue();
109
- const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
110
- debugUtils.setPXE(pxe);
107
+ const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, contractSyncService, messageContextService, l2TipsStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils, hooks);
108
+ debugUtils.setPXEHelpers(pxe.#putInJobQueue.bind(pxe), pxe.#getSimulatorForTx.bind(pxe), pxe.#executeUtility.bind(pxe));
111
109
  pxe.jobQueue.start();
112
110
  await pxe.#registerProtocolContracts();
113
- const info = await node.getNodeInfo();
114
111
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
115
112
  return pxe;
116
113
  }
117
114
  // Internal methods
118
115
  #getSimulatorForTx(overrides) {
119
116
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
120
- return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, BenchmarkedNodeFactory.create(this.node), this.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
117
+ return new ContractFunctionSimulator({
118
+ contractStore: proxyContractStore,
119
+ noteStore: this.noteStore,
120
+ keyStore: this.keyStore,
121
+ addressStore: this.addressStore,
122
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
123
+ l2TipsStore: this.l2TipsStore,
124
+ senderTaggingStore: this.senderTaggingStore,
125
+ recipientTaggingStore: this.recipientTaggingStore,
126
+ senderAddressBookStore: this.senderAddressBookStore,
127
+ capsuleStore: this.capsuleStore,
128
+ privateEventStore: this.privateEventStore,
129
+ simulator: this.simulator,
130
+ contractSyncService: this.contractSyncService,
131
+ messageContextService: this.messageContextService,
132
+ hooks: this.hooks
133
+ });
121
134
  }
122
135
  #contextualizeError(err, ...context) {
123
136
  let contextStr = '';
@@ -160,8 +173,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
160
173
  async #registerProtocolContracts() {
161
174
  const registered = {};
162
175
  for (const name of protocolContractNames){
163
- const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
164
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
176
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
177
+ await this.contractStore.addContractArtifact(artifact);
165
178
  await this.contractStore.addContractInstance(instance);
166
179
  registered[name] = address.toString();
167
180
  }
@@ -169,14 +182,18 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
169
182
  }
170
183
  // Executes the entrypoint private function, as well as all nested private
171
184
  // functions that might arise.
172
- async #executePrivate(contractFunctionSimulator, txRequest, scopes, jobId) {
185
+ async #executePrivate({ contractFunctionSimulator, txRequest, anchorBlockHeader, scopes, jobId, senderForTags }) {
173
186
  const { origin: contractAddress, functionSelector } = txRequest;
174
187
  try {
175
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
176
- await ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
177
- const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
178
- // contract entrypoint
179
- undefined, scopes, jobId);
188
+ await this.contractSyncService.ensureContractSynced(contractAddress, functionSelector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
189
+ const result = await contractFunctionSimulator.run(txRequest, {
190
+ contractAddress,
191
+ selector: functionSelector,
192
+ anchorBlockHeader,
193
+ scopes,
194
+ jobId,
195
+ senderForTags
196
+ });
180
197
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
181
198
  return result;
182
199
  } catch (err) {
@@ -187,18 +204,22 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
187
204
  }
188
205
  }
189
206
  /**
190
- * Simulate a utility function call on the given contract.
207
+ * Execute a utility function call on the given contract.
191
208
  * @param contractFunctionSimulator - The simulator to use for the function call.
192
209
  * @param call - The function call to execute.
193
210
  * @param authWitnesses - Authentication witnesses required for the function call.
194
211
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
195
212
  * accounts if not specified.
196
213
  * @param jobId - The job ID for staged writes.
197
- * @returns The simulation result containing the outputs of the utility function.
198
- */ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
214
+ * @returns The execution result containing the outputs of the utility function.
215
+ */ async #executeUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
199
216
  try {
200
217
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
201
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
218
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
219
+ return {
220
+ result,
221
+ offchainEffects
222
+ };
202
223
  } catch (err) {
203
224
  if (err instanceof SimulationError) {
204
225
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -241,16 +262,26 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
241
262
  * @param privateExecutionResult - The result of the private execution
242
263
  * @param config - The configuration for the kernel execution prover.
243
264
  * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
244
- */ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
245
- const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
246
- const anchorBlockHash = await anchorBlockHeader.hash();
247
- const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
248
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
265
+ */ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, anchorBlockHeader, config) {
266
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
267
+ const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
249
268
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
250
269
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
251
270
  }
252
271
  // Public API
253
- getContractInstance(address) {
272
+ /**
273
+ * Returns the block header up to which the PXE has synced.
274
+ * @returns The synced block header
275
+ */ getSyncedBlockHeader() {
276
+ return this.#putInJobQueue(()=>{
277
+ return this.anchorBlockStore.getBlockHeader();
278
+ });
279
+ }
280
+ /**
281
+ * Returns the contract instance for a given address, if it's registered in the PXE.
282
+ * @param address - The contract address.
283
+ * @returns The contract instance if found, undefined otherwise.
284
+ */ getContractInstance(address) {
254
285
  return this.contractStore.getContractInstance(address);
255
286
  }
256
287
  /**
@@ -292,6 +323,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
292
323
  * @returns The address of the sender.
293
324
  * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
294
325
  */ async registerSender(sender) {
326
+ if (!await sender.isValid()) {
327
+ throw new Error(`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`);
328
+ }
295
329
  const accounts = await this.keyStore.getAccounts();
296
330
  if (accounts.includes(sender)) {
297
331
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
@@ -300,6 +334,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
300
334
  const wasAdded = await this.senderAddressBookStore.addSender(sender);
301
335
  if (wasAdded) {
302
336
  this.log.info(`Added sender:\n ${sender.toString()}`);
337
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
338
+ // all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
339
+ await this.#putInJobQueue(()=>Promise.resolve(this.contractSyncService.wipe()));
303
340
  } else {
304
341
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
305
342
  }
@@ -337,8 +374,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
337
374
  *
338
375
  * @param artifact - The build artifact for the contract class.
339
376
  */ async registerContractClass(artifact) {
340
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
341
- await this.contractStore.addContractArtifact(contractClassId, artifact);
377
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
342
378
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
343
379
  }
344
380
  /**
@@ -354,17 +390,18 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
354
390
  if (artifact) {
355
391
  // If the user provides an artifact, validate it against the expected class id and register it
356
392
  const contractClass = await getContractClassFromArtifact(artifact);
357
- const contractClassId = contractClass.id;
358
- if (!contractClassId.equals(instance.currentContractClassId)) {
359
- throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
393
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
394
+ throw new Error(`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`);
360
395
  }
361
396
  const computedAddress = await computeContractAddressFromInstance(instance);
362
397
  if (!computedAddress.equals(instance.address)) {
363
398
  throw new Error('Added a contract in which the address does not match the contract instance.');
364
399
  }
365
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
400
+ await this.contractStore.addContractArtifact(artifact, contractClass);
366
401
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
367
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
402
+ if (publicFunctionSignatures.length > 0) {
403
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
404
+ }
368
405
  } else {
369
406
  // Otherwise, make sure there is an artifact already registered for that class id
370
407
  artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
@@ -398,11 +435,15 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
398
435
  if (!contractClass.id.equals(currentClassId)) {
399
436
  throw new Error('Could not update contract to a class different from the current one.');
400
437
  }
401
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
402
438
  const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
403
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
439
+ if (publicFunctionSignatures.length > 0) {
440
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
441
+ }
404
442
  currentInstance.currentContractClassId = contractClass.id;
405
- await this.contractStore.addContractInstance(currentInstance);
443
+ await Promise.all([
444
+ this.contractStore.addContractArtifact(artifact, contractClass),
445
+ this.contractStore.addContractInstance(currentInstance)
446
+ ]);
406
447
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
407
448
  });
408
449
  }
@@ -417,10 +458,11 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
417
458
  * (where validators prove the public portion).
418
459
  *
419
460
  * @param txRequest - An authenticated tx request ready for proving
461
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
420
462
  * @returns A result containing the proof and public inputs of the tail circuit.
421
463
  * @throws If contract code not found, or public simulation reverts.
422
464
  * Also throws if simulatePublic is true and public simulation reverts.
423
- */ proveTx(txRequest) {
465
+ */ proveTx(txRequest, { scopes, senderForTags }) {
424
466
  let privateExecutionResult;
425
467
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
426
468
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -429,10 +471,18 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
429
471
  try {
430
472
  const syncTimer = new Timer();
431
473
  await this.blockStateSynchronizer.sync();
474
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
432
475
  const syncTime = syncTimer.ms();
433
476
  const contractFunctionSimulator = this.#getSimulatorForTx();
434
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
435
- const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
477
+ privateExecutionResult = await this.#executePrivate({
478
+ contractFunctionSimulator,
479
+ txRequest,
480
+ anchorBlockHeader,
481
+ scopes,
482
+ jobId,
483
+ senderForTags
484
+ });
485
+ const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
436
486
  simulate: false,
437
487
  skipFeeEnforcement: false,
438
488
  profileMode: 'none'
@@ -457,22 +507,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
457
507
  timings,
458
508
  nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
459
509
  });
460
- // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
461
- // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
462
- // transaction before this one is included in a block from this PXE, and that transaction contains a log with
463
- // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
464
- // storing the tags here prevents linkage of txs sent from the same PXE.
465
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
466
- if (preTagsUsedInTheTx.length > 0) {
467
- // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
468
- const txHash = (await txProvingResult.toTx()).txHash;
469
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
470
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
471
- preTagsUsedInTheTx
472
- });
473
- } else {
474
- this.log.debug(`No pre-tags used in the tx`);
475
- }
510
+ // We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
511
+ // (which would link them) without having to rely on this tx being mined (and us seeing the indices being used
512
+ // onchain).
513
+ // Note that this must happen _after_ proving as it requires the proof's public inputs, from which the kernels
514
+ // may have removed some logs due to note-nullifier squashing - this may lead to range of tagging indices we've
515
+ // actually used to being reduced.
516
+ await persistSenderTaggingIndexRangesForTx(this.senderTaggingStore, privateExecutionResult.entrypoint.taggingIndexRanges, publicInputs, ()=>txProvingResult.getTxHash(), jobId, this.log);
476
517
  return txProvingResult;
477
518
  } catch (err) {
478
519
  throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
@@ -481,13 +522,10 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
481
522
  }
482
523
  /**
483
524
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
484
- *
485
- * @param txRequest - An authenticated tx request ready for simulation
486
- * @param msgSender - (Optional) The message sender to use for the simulation.
487
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
525
+ * @param txRequest - An authenticated tx request ready for simulation.
488
526
  * @returns A trace of the program execution with gate counts.
489
527
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
490
- */ profileTx(txRequest, profileMode, skipProofGeneration = true) {
528
+ */ profileTx(txRequest, { profileMode, skipProofGeneration = true, scopes, senderForTags }) {
491
529
  // We disable concurrent profiles for consistency with simulateTx.
492
530
  return this.#putInJobQueue(async (jobId)=>{
493
531
  const totalTimer = new Timer();
@@ -503,10 +541,18 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
503
541
  this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
504
542
  const syncTimer = new Timer();
505
543
  await this.blockStateSynchronizer.sync();
544
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
506
545
  const syncTime = syncTimer.ms();
507
546
  const contractFunctionSimulator = this.#getSimulatorForTx();
508
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
509
- const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
547
+ const privateExecutionResult = await this.#executePrivate({
548
+ contractFunctionSimulator,
549
+ txRequest,
550
+ anchorBlockHeader,
551
+ scopes,
552
+ jobId,
553
+ senderForTags
554
+ });
555
+ const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
510
556
  simulate: skipProofGeneration,
511
557
  skipFeeEnforcement: false,
512
558
  profileMode
@@ -550,18 +596,13 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
550
596
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
551
597
  *
552
598
  *
553
- * @param txRequest - An authenticated tx request ready for simulation
554
- * @param simulatePublic - Whether to simulate the public part of the transaction.
555
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
556
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
557
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
558
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
599
+ * @param txRequest - An authenticated tx request ready for simulation.
559
600
  * @returns A simulated transaction result object that includes public and private return values.
560
601
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
561
602
  * Also throws if simulatePublic is true and public simulation reverts.
562
603
  *
563
604
  * TODO(#7456) Prevent msgSender being defined here for the first call
564
- */ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
605
+ */ simulateTx(txRequest, { simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, skipKernels = true, overrides, scopes, senderForTags }) {
565
606
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
566
607
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
567
608
  // delete the same read value, or reading values that another simulation is currently modifying).
@@ -579,21 +620,35 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
579
620
  this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
580
621
  const syncTimer = new Timer();
581
622
  await this.blockStateSynchronizer.sync();
623
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
582
624
  const syncTime = syncTimer.ms();
625
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
626
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
627
+ if (hasOverriddenContracts && !skipKernels) {
628
+ throw new Error('Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.');
629
+ }
583
630
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
584
- // Temporary: in case there are overrides, we have to skip the kernels or validations
585
- // will fail. Consider handing control to the user/wallet on whether they want to run them
586
- // or not.
587
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
631
+ if (hasOverriddenContracts) {
632
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
633
+ // We exclude them so the sync service skips them entirely.
634
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
635
+ }
588
636
  // Execution of private functions only; no proving, and no kernel logic.
589
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
637
+ const privateExecutionResult = await this.#executePrivate({
638
+ contractFunctionSimulator,
639
+ txRequest,
640
+ anchorBlockHeader,
641
+ scopes,
642
+ jobId,
643
+ senderForTags
644
+ });
590
645
  let publicInputs;
591
646
  let executionSteps = [];
592
647
  if (skipKernels) {
593
- ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
648
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.node));
594
649
  } else {
595
650
  // Kernel logic, plus proving of all private functions and kernels.
596
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
651
+ ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
597
652
  simulate: true,
598
653
  skipFeeEnforcement,
599
654
  profileMode: 'none'
@@ -607,6 +662,9 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
607
662
  const publicSimulationTimer = new Timer();
608
663
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
609
664
  publicSimulationTime = publicSimulationTimer.ms();
665
+ if (publicOutput?.debugLogs?.length) {
666
+ await displayDebugLogs(publicOutput.debugLogs, (addr)=>this.contractStore.getDebugContractName(addr));
667
+ }
610
668
  }
611
669
  let validationTime;
612
670
  if (!skipTxValidation) {
@@ -617,7 +675,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
617
675
  });
618
676
  validationTime = validationTimer.ms();
619
677
  if (validationResult.result === 'invalid') {
620
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
678
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
679
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
621
680
  }
622
681
  }
623
682
  const txHash = simulatedTx.getTxHash();
@@ -650,22 +709,19 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
650
709
  nodeRPCCalls: simulatorStats.nodeRPCCalls
651
710
  });
652
711
  } catch (err) {
653
- throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
712
+ throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
654
713
  }
655
714
  });
656
715
  }
657
716
  /**
658
- * Simulate the execution of a contract utility function.
659
- *
717
+ * Executes a contract utility function.
660
718
  * @param call - The function call containing the function details, arguments, and target contract address.
661
- * @param authwits - (Optional) The authentication witnesses required for the function call.
662
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
663
- * default to all.
664
- * @returns The result of the utility function call, structured based on the function ABI.
665
- */ simulateUtility(call, authwits, scopes) {
666
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
719
+ */ executeUtility(call, { authwits, scopes } = {
720
+ scopes: []
721
+ }) {
722
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
667
723
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
668
- // delete the same read value, or reading values that another simulation is currently modifying).
724
+ // delete the same read value, or reading values that another execution is currently modifying).
669
725
  return this.#putInJobQueue(async (jobId)=>{
670
726
  try {
671
727
  const totalTimer = new Timer();
@@ -675,8 +731,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
675
731
  const functionTimer = new Timer();
676
732
  const contractFunctionSimulator = this.#getSimulatorForTx();
677
733
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
678
- await ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
679
- const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
734
+ await this.contractSyncService.ensureContractSynced(call.to, call.selector, (privateSyncCall, execScopes)=>this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, scopes);
735
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
680
736
  const functionTime = functionTimer.ms();
681
737
  const totalTime = totalTimer.ms();
682
738
  const perFunction = [
@@ -694,6 +750,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
694
750
  const simulationStats = contractFunctionSimulator.getStats();
695
751
  return {
696
752
  result: executionResult,
753
+ offchainEffects,
754
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
697
755
  stats: {
698
756
  timings,
699
757
  nodeRPCCalls: simulationStats.nodeRPCCalls
@@ -702,7 +760,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
702
760
  } catch (err) {
703
761
  const { to, name, args } = call;
704
762
  const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
705
- throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
763
+ throw this.#contextualizeError(err, `executeUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes.map((s)=>s.toString()).join(', ')}`);
706
764
  }
707
765
  });
708
766
  }
@@ -725,7 +783,7 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
725
783
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
726
784
  anchorBlockNumber = anchorBlockHeader.getBlockNumber();
727
785
  const contractFunctionSimulator = this.#getSimulatorForTx();
728
- await ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, anchorBlockHeader);
786
+ await this.contractSyncService.ensureContractSynced(filter.contractAddress, null, async (privateSyncCall, execScopes)=>await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId), anchorBlockHeader, jobId, filter.scopes);
729
787
  });
730
788
  // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
731
789
  const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
@@ -734,7 +792,8 @@ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store
734
792
  }
735
793
  /**
736
794
  * Stops the PXE's job queue.
737
- */ stop() {
738
- return this.jobQueue.end();
795
+ */ async stop() {
796
+ await this.jobQueue.end();
797
+ await this.blockStateSynchronizer.stop();
739
798
  }
740
799
  }
@@ -8,4 +8,4 @@ export declare class AddressStore {
8
8
  getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined>;
9
9
  getCompleteAddresses(): Promise<CompleteAddress[]>;
10
10
  }
11
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQVlELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FFOUU7SUFFSyxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FJdkQ7Q0FDRiJ9
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc19zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvYWRkcmVzc19zdG9yZS9hZGRyZXNzX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFtQixpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN6RixPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsWUFBWTs7SUFLdkIsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBS25DO0lBRUQsa0JBQWtCLENBQUMsZUFBZSxFQUFFLGVBQWUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMEJyRTtJQUVELGtCQUFrQixDQUFDLE9BQU8sRUFBRSxZQUFZLEdBQUcsT0FBTyxDQUFDLGVBQWUsR0FBRyxTQUFTLENBQUMsQ0FVOUU7SUFFRCxvQkFBb0IsSUFBSSxPQUFPLENBQUMsZUFBZSxFQUFFLENBQUMsQ0FNakQ7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAYD,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAE9E;IAEK,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAIvD;CACF"}
1
+ {"version":3,"file":"address_store.d.ts","sourceRoot":"","sources":["../../../src/storage/address_store/address_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,YAAY;;IAKvB,YAAY,KAAK,EAAE,iBAAiB,EAKnC;IAED,kBAAkB,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CA0BrE;IAED,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAU9E;IAED,oBAAoB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAMjD;CACF"}