@aztec/pxe 0.0.0-test.0 → 0.0.1-commit.0208eb9

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 (458) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +2 -0
  3. package/dest/bin/check_oracle_version.d.ts.map +1 -0
  4. package/dest/bin/check_oracle_version.js +129 -0
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +43 -0
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  7. package/dest/block_synchronizer/block_synchronizer.js +147 -0
  8. package/dest/block_synchronizer/index.d.ts +2 -0
  9. package/dest/block_synchronizer/index.d.ts.map +1 -0
  10. package/dest/block_synchronizer/index.js +1 -0
  11. package/dest/config/index.d.ts +13 -24
  12. package/dest/config/index.d.ts.map +1 -1
  13. package/dest/config/index.js +35 -33
  14. package/dest/config/package_info.d.ts +1 -1
  15. package/dest/config/package_info.js +1 -1
  16. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  17. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  19. package/dest/contract_function_simulator/contract_function_simulator.d.ts +82 -0
  20. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/contract_function_simulator.js +339 -0
  22. package/dest/contract_function_simulator/execution_note_cache.d.ts +104 -0
  23. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/execution_note_cache.js +208 -0
  25. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  26. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  27. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  28. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  29. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  31. package/dest/contract_function_simulator/index.d.ts +14 -0
  32. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/index.js +12 -0
  34. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +21 -0
  35. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +40 -0
  37. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +16 -0
  38. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +26 -0
  40. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
  41. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
  43. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +24 -0
  44. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +51 -0
  46. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +16 -0
  47. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/noir-structs/utility_context.js +22 -0
  49. package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
  50. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  51. package/dest/contract_function_simulator/oracle/index.js +2 -0
  52. package/dest/contract_function_simulator/oracle/interfaces.d.ts +107 -0
  53. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  54. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  55. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
  56. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  57. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  58. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +28 -0
  59. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  60. package/dest/contract_function_simulator/oracle/note_packing_utils.js +54 -0
  61. package/dest/contract_function_simulator/oracle/oracle.d.ts +60 -0
  62. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  63. package/dest/contract_function_simulator/oracle/oracle.js +368 -0
  64. package/dest/contract_function_simulator/oracle/private_execution.d.ts +23 -0
  65. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  66. package/dest/contract_function_simulator/oracle/private_execution.js +87 -0
  67. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +239 -0
  68. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  69. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +426 -0
  70. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +208 -0
  71. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  72. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +367 -0
  73. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  74. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  75. package/dest/contract_function_simulator/pick_notes.js +51 -0
  76. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
  77. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
  78. package/dest/contract_function_simulator/proxied_contract_data_source.js +80 -0
  79. package/dest/contract_sync/index.d.ts +24 -0
  80. package/dest/contract_sync/index.d.ts.map +1 -0
  81. package/dest/contract_sync/index.js +61 -0
  82. package/dest/debug/pxe_debug_utils.d.ts +41 -0
  83. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  84. package/dest/debug/pxe_debug_utils.js +47 -0
  85. package/dest/entrypoints/client/bundle/index.d.ts +4 -3
  86. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  87. package/dest/entrypoints/client/bundle/index.js +2 -2
  88. package/dest/entrypoints/client/bundle/utils.d.ts +10 -10
  89. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  90. package/dest/entrypoints/client/bundle/utils.js +33 -12
  91. package/dest/entrypoints/client/lazy/index.d.ts +4 -3
  92. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  93. package/dest/entrypoints/client/lazy/index.js +2 -2
  94. package/dest/entrypoints/client/lazy/utils.d.ts +10 -10
  95. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  96. package/dest/entrypoints/client/lazy/utils.js +33 -12
  97. package/dest/entrypoints/pxe_creation_options.d.ts +18 -0
  98. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  99. package/dest/entrypoints/server/index.d.ts +8 -4
  100. package/dest/entrypoints/server/index.d.ts.map +1 -1
  101. package/dest/entrypoints/server/index.js +6 -3
  102. package/dest/entrypoints/server/utils.d.ts +8 -16
  103. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  104. package/dest/entrypoints/server/utils.js +46 -36
  105. package/dest/error_enriching.d.ts +11 -0
  106. package/dest/error_enriching.d.ts.map +1 -0
  107. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +30 -22
  108. package/dest/events/event_service.d.ts +15 -0
  109. package/dest/events/event_service.d.ts.map +1 -0
  110. package/dest/events/event_service.js +44 -0
  111. package/dest/events/index.d.ts +2 -0
  112. package/dest/events/index.d.ts.map +1 -0
  113. package/dest/events/index.js +1 -0
  114. package/dest/events/private_event_filter_validator.d.ts +9 -0
  115. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  116. package/dest/events/private_event_filter_validator.js +38 -0
  117. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  118. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  119. package/dest/job_coordinator/job_coordinator.js +94 -0
  120. package/dest/logs/log_service.d.ts +28 -0
  121. package/dest/logs/log_service.d.ts.map +1 -0
  122. package/dest/logs/log_service.js +123 -0
  123. package/dest/notes/index.d.ts +2 -0
  124. package/dest/notes/index.d.ts.map +1 -0
  125. package/dest/notes/index.js +1 -0
  126. package/dest/notes/note_service.d.ts +48 -0
  127. package/dest/notes/note_service.d.ts.map +1 -0
  128. package/dest/notes/note_service.js +147 -0
  129. package/dest/oracle_version.d.ts +3 -0
  130. package/dest/oracle_version.d.ts.map +1 -0
  131. package/dest/oracle_version.js +11 -0
  132. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  133. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  134. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  135. package/dest/private_kernel/hints/index.d.ts +3 -0
  136. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  137. package/dest/private_kernel/hints/index.js +2 -0
  138. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  139. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  140. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +277 -0
  141. package/dest/private_kernel/index.d.ts +3 -0
  142. package/dest/private_kernel/index.d.ts.map +1 -0
  143. package/dest/private_kernel/index.js +2 -0
  144. package/dest/private_kernel/private_kernel_execution_prover.d.ts +45 -0
  145. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  146. package/dest/private_kernel/private_kernel_execution_prover.js +285 -0
  147. package/dest/private_kernel/private_kernel_oracle.d.ts +59 -0
  148. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  149. package/dest/private_kernel/private_kernel_oracle.js +92 -0
  150. package/dest/pxe.d.ts +204 -0
  151. package/dest/pxe.d.ts.map +1 -0
  152. package/dest/pxe.js +742 -0
  153. package/dest/storage/address_store/address_store.d.ts +11 -0
  154. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  155. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -15
  156. package/dest/storage/address_store/index.d.ts +2 -0
  157. package/dest/storage/address_store/index.d.ts.map +1 -0
  158. package/dest/storage/address_store/index.js +1 -0
  159. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  160. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  161. package/dest/storage/anchor_block_store/anchor_block_store.js +26 -0
  162. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  163. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  164. package/dest/storage/anchor_block_store/index.js +1 -0
  165. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  166. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  167. package/dest/storage/capsule_store/capsule_store.js +253 -0
  168. package/dest/storage/capsule_store/index.d.ts +2 -0
  169. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  170. package/dest/storage/capsule_store/index.js +1 -0
  171. package/dest/storage/contract_store/contract_store.d.ts +66 -0
  172. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  173. package/dest/storage/contract_store/contract_store.js +233 -0
  174. package/dest/storage/contract_store/index.d.ts +2 -0
  175. package/dest/storage/contract_store/index.d.ts.map +1 -0
  176. package/dest/storage/contract_store/index.js +1 -0
  177. package/dest/storage/contract_store/private_functions_tree.d.ts +27 -0
  178. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  179. package/dest/storage/contract_store/private_functions_tree.js +47 -0
  180. package/dest/storage/index.d.ts +9 -10
  181. package/dest/storage/index.d.ts.map +1 -1
  182. package/dest/storage/index.js +8 -9
  183. package/dest/storage/metadata.d.ts +2 -0
  184. package/dest/storage/metadata.d.ts.map +1 -0
  185. package/dest/storage/metadata.js +1 -0
  186. package/dest/storage/note_store/index.d.ts +3 -0
  187. package/dest/storage/note_store/index.d.ts.map +1 -0
  188. package/dest/storage/note_store/index.js +2 -0
  189. package/dest/storage/note_store/note_store.d.ts +83 -0
  190. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  191. package/dest/storage/note_store/note_store.js +341 -0
  192. package/dest/storage/note_store/stored_note.d.ts +16 -0
  193. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  194. package/dest/storage/note_store/stored_note.js +43 -0
  195. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  196. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  197. package/dest/storage/private_event_store/private_event_store.js +273 -0
  198. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  199. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  200. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  201. package/dest/storage/tagging_store/index.d.ts +4 -0
  202. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  203. package/dest/storage/tagging_store/index.js +3 -0
  204. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  205. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  206. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  207. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  208. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  209. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  210. package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
  211. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  212. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  213. package/dest/tagging/constants.d.ts +2 -0
  214. package/dest/tagging/constants.d.ts.map +1 -0
  215. package/dest/tagging/constants.js +10 -0
  216. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  217. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  218. package/dest/tagging/get_all_logs_by_tags.js +46 -0
  219. package/dest/tagging/index.d.ts +17 -0
  220. package/dest/tagging/index.d.ts.map +1 -0
  221. package/dest/tagging/index.js +15 -0
  222. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
  223. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  224. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  225. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  226. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  227. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  228. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
  229. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  230. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  231. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
  232. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  233. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  234. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  235. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  236. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
  237. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
  238. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  239. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
  240. package/package.json +37 -34
  241. package/src/bin/check_oracle_version.ts +161 -0
  242. package/src/block_synchronizer/block_synchronizer.ts +172 -0
  243. package/src/block_synchronizer/index.ts +1 -0
  244. package/src/config/index.ts +41 -55
  245. package/src/config/package_info.ts +1 -1
  246. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  247. package/src/contract_function_simulator/contract_function_simulator.ts +633 -0
  248. package/src/contract_function_simulator/execution_note_cache.ts +252 -0
  249. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  250. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  251. package/src/contract_function_simulator/index.ts +13 -0
  252. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +51 -0
  253. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +28 -0
  254. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
  255. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +64 -0
  256. package/src/contract_function_simulator/noir-structs/utility_context.ts +23 -0
  257. package/src/contract_function_simulator/oracle/index.ts +16 -0
  258. package/src/contract_function_simulator/oracle/interfaces.ts +185 -0
  259. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  260. package/src/contract_function_simulator/oracle/note_packing_utils.ts +68 -0
  261. package/src/contract_function_simulator/oracle/oracle.ts +637 -0
  262. package/src/contract_function_simulator/oracle/private_execution.ts +141 -0
  263. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +701 -0
  264. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +544 -0
  265. package/src/contract_function_simulator/pick_notes.ts +141 -0
  266. package/src/contract_function_simulator/proxied_contract_data_source.ts +83 -0
  267. package/src/contract_sync/index.ts +119 -0
  268. package/src/debug/pxe_debug_utils.ts +63 -0
  269. package/src/entrypoints/client/bundle/index.ts +3 -2
  270. package/src/entrypoints/client/bundle/utils.ts +35 -36
  271. package/src/entrypoints/client/lazy/index.ts +3 -2
  272. package/src/entrypoints/client/lazy/utils.ts +36 -32
  273. package/src/entrypoints/pxe_creation_options.ts +14 -0
  274. package/src/entrypoints/server/index.ts +7 -3
  275. package/src/entrypoints/server/utils.ts +52 -52
  276. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +40 -39
  277. package/src/events/event_service.ts +71 -0
  278. package/src/events/index.ts +1 -0
  279. package/src/events/private_event_filter_validator.ts +46 -0
  280. package/src/job_coordinator/job_coordinator.ts +150 -0
  281. package/src/logs/log_service.ts +220 -0
  282. package/src/notes/index.ts +1 -0
  283. package/src/notes/note_service.ts +195 -0
  284. package/src/oracle_version.ts +12 -0
  285. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  286. package/src/private_kernel/hints/index.ts +2 -0
  287. package/src/{kernel_prover/hints/build_private_kernel_reset_private_inputs.ts → private_kernel/hints/private_kernel_reset_private_inputs_builder.ts} +179 -156
  288. package/src/private_kernel/index.ts +2 -0
  289. package/src/private_kernel/private_kernel_execution_prover.ts +433 -0
  290. package/src/private_kernel/private_kernel_oracle.ts +152 -0
  291. package/src/pxe.ts +1076 -0
  292. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +15 -21
  293. package/src/storage/address_store/index.ts +1 -0
  294. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -17
  295. package/src/storage/anchor_block_store/index.ts +1 -0
  296. package/src/storage/capsule_store/capsule_store.ts +315 -0
  297. package/src/storage/capsule_store/index.ts +1 -0
  298. package/src/storage/contract_store/contract_store.ts +330 -0
  299. package/src/storage/contract_store/index.ts +1 -0
  300. package/src/storage/contract_store/private_functions_tree.ts +67 -0
  301. package/src/storage/index.ts +8 -10
  302. package/src/storage/metadata.ts +1 -0
  303. package/src/storage/note_store/index.ts +2 -0
  304. package/src/storage/note_store/note_store.ts +411 -0
  305. package/src/storage/note_store/stored_note.ts +48 -0
  306. package/src/storage/private_event_store/private_event_store.ts +384 -0
  307. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  308. package/src/storage/tagging_store/index.ts +3 -0
  309. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  310. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  311. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  312. package/src/tagging/constants.ts +10 -0
  313. package/src/tagging/get_all_logs_by_tags.ts +68 -0
  314. package/src/tagging/index.ts +19 -0
  315. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
  316. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  317. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
  318. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
  319. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
  320. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  321. package/dest/bin/index.d.ts +0 -3
  322. package/dest/bin/index.d.ts.map +0 -1
  323. package/dest/bin/index.js +0 -28
  324. package/dest/entrypoints/client/pxe_creation_options.d.ts +0 -11
  325. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  326. package/dest/kernel_oracle/index.d.ts +0 -45
  327. package/dest/kernel_oracle/index.d.ts.map +0 -1
  328. package/dest/kernel_oracle/index.js +0 -76
  329. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  330. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  331. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
  332. package/dest/kernel_prover/hints/index.d.ts +0 -2
  333. package/dest/kernel_prover/hints/index.d.ts.map +0 -1
  334. package/dest/kernel_prover/hints/index.js +0 -1
  335. package/dest/kernel_prover/index.d.ts +0 -3
  336. package/dest/kernel_prover/index.d.ts.map +0 -1
  337. package/dest/kernel_prover/index.js +0 -2
  338. package/dest/kernel_prover/kernel_prover.d.ts +0 -38
  339. package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
  340. package/dest/kernel_prover/kernel_prover.js +0 -217
  341. package/dest/kernel_prover/proving_data_oracle.d.ts +0 -73
  342. package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
  343. package/dest/kernel_prover/proving_data_oracle.js +0 -4
  344. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
  345. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
  346. package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
  347. package/dest/pxe_http/index.d.ts +0 -2
  348. package/dest/pxe_http/index.d.ts.map +0 -1
  349. package/dest/pxe_http/index.js +0 -1
  350. package/dest/pxe_http/pxe_http_server.d.ts +0 -16
  351. package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
  352. package/dest/pxe_http/pxe_http_server.js +0 -27
  353. package/dest/pxe_oracle_interface/index.d.ts +0 -159
  354. package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
  355. package/dest/pxe_oracle_interface/index.js +0 -692
  356. package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
  357. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  358. package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
  359. package/dest/pxe_service/error_enriching.d.ts +0 -11
  360. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  361. package/dest/pxe_service/index.d.ts +0 -3
  362. package/dest/pxe_service/index.d.ts.map +0 -1
  363. package/dest/pxe_service/index.js +0 -2
  364. package/dest/pxe_service/pxe_service.d.ts +0 -111
  365. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  366. package/dest/pxe_service/pxe_service.js +0 -664
  367. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
  368. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  369. package/dest/storage/address_data_provider/index.d.ts +0 -2
  370. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  371. package/dest/storage/address_data_provider/index.js +0 -1
  372. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
  373. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
  374. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
  375. package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
  376. package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
  377. package/dest/storage/auth_witness_data_provider/index.js +0 -1
  378. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -16
  379. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  380. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -57
  381. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  382. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  383. package/dest/storage/capsule_data_provider/index.js +0 -1
  384. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -109
  385. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  386. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -183
  387. package/dest/storage/contract_data_provider/index.d.ts +0 -3
  388. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  389. package/dest/storage/contract_data_provider/index.js +0 -2
  390. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +0 -66
  391. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  392. package/dest/storage/contract_data_provider/private_functions_tree.js +0 -99
  393. package/dest/storage/data_provider.d.ts +0 -4
  394. package/dest/storage/data_provider.d.ts.map +0 -1
  395. package/dest/storage/data_provider.js +0 -1
  396. package/dest/storage/note_data_provider/index.d.ts +0 -3
  397. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  398. package/dest/storage/note_data_provider/index.js +0 -2
  399. package/dest/storage/note_data_provider/note_dao.d.ts +0 -106
  400. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  401. package/dest/storage/note_data_provider/note_dao.js +0 -106
  402. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
  403. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  404. package/dest/storage/note_data_provider/note_data_provider.js +0 -249
  405. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  406. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  407. package/dest/storage/sync_data_provider/index.js +0 -1
  408. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  409. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  410. package/dest/storage/sync_data_provider/sync_data_provider.js +0 -29
  411. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  412. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  413. package/dest/storage/tagging_data_provider/index.js +0 -1
  414. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  415. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  416. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -65
  417. package/dest/synchronizer/index.d.ts +0 -2
  418. package/dest/synchronizer/index.d.ts.map +0 -1
  419. package/dest/synchronizer/index.js +0 -1
  420. package/dest/synchronizer/synchronizer.d.ts +0 -37
  421. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  422. package/dest/synchronizer/synchronizer.js +0 -103
  423. package/dest/test/pxe_test_suite.d.ts +0 -3
  424. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  425. package/dest/test/pxe_test_suite.js +0 -97
  426. package/src/bin/index.ts +0 -38
  427. package/src/entrypoints/client/pxe_creation_options.ts +0 -7
  428. package/src/kernel_oracle/index.ts +0 -117
  429. package/src/kernel_prover/hints/index.ts +0 -1
  430. package/src/kernel_prover/index.ts +0 -2
  431. package/src/kernel_prover/kernel_prover.ts +0 -351
  432. package/src/kernel_prover/proving_data_oracle.ts +0 -83
  433. package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
  434. package/src/pxe_http/index.ts +0 -1
  435. package/src/pxe_http/pxe_http_server.ts +0 -29
  436. package/src/pxe_oracle_interface/index.ts +0 -925
  437. package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
  438. package/src/pxe_service/index.ts +0 -2
  439. package/src/pxe_service/pxe_service.ts +0 -949
  440. package/src/storage/address_data_provider/index.ts +0 -1
  441. package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
  442. package/src/storage/auth_witness_data_provider/index.ts +0 -1
  443. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -80
  444. package/src/storage/capsule_data_provider/index.ts +0 -1
  445. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -261
  446. package/src/storage/contract_data_provider/index.ts +0 -2
  447. package/src/storage/contract_data_provider/private_functions_tree.ts +0 -131
  448. package/src/storage/data_provider.ts +0 -3
  449. package/src/storage/note_data_provider/index.ts +0 -2
  450. package/src/storage/note_data_provider/note_dao.ts +0 -162
  451. package/src/storage/note_data_provider/note_data_provider.ts +0 -345
  452. package/src/storage/sync_data_provider/index.ts +0 -1
  453. package/src/storage/tagging_data_provider/index.ts +0 -1
  454. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -92
  455. package/src/synchronizer/index.ts +0 -1
  456. package/src/synchronizer/synchronizer.ts +0 -121
  457. package/src/test/pxe_test_suite.ts +0 -111
  458. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
package/src/pxe.ts ADDED
@@ -0,0 +1,1076 @@
1
+ import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
+ import { SerialQueue } from '@aztec/foundation/queue';
6
+ import { Timer } from '@aztec/foundation/timer';
7
+ import { KeyStore } from '@aztec/key-store';
8
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
9
+ import { L2TipsKVStore } from '@aztec/kv-store/stores';
10
+ import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
11
+ import type { CircuitSimulator } from '@aztec/simulator/client';
12
+ import {
13
+ type ContractArtifact,
14
+ EventSelector,
15
+ FunctionCall,
16
+ FunctionType,
17
+ decodeFunctionSignature,
18
+ } from '@aztec/stdlib/abi';
19
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
20
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
21
+ import {
22
+ CompleteAddress,
23
+ type ContractInstanceWithAddress,
24
+ type PartialAddress,
25
+ computeContractAddressFromInstance,
26
+ getContractClassFromArtifact,
27
+ } from '@aztec/stdlib/contract';
28
+ import { SimulationError } from '@aztec/stdlib/errors';
29
+ import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
30
+ import type {
31
+ PrivateExecutionStep,
32
+ PrivateKernelExecutionProofOutput,
33
+ PrivateKernelTailCircuitPublicInputs,
34
+ } from '@aztec/stdlib/kernel';
35
+ import {
36
+ type ContractOverrides,
37
+ type InTx,
38
+ PrivateExecutionResult,
39
+ PrivateSimulationResult,
40
+ type ProvingTimings,
41
+ PublicSimulationOutput,
42
+ SimulationOverrides,
43
+ type SimulationTimings,
44
+ Tx,
45
+ TxExecutionRequest,
46
+ TxProfileResult,
47
+ TxProvingResult,
48
+ TxSimulationResult,
49
+ UtilitySimulationResult,
50
+ } from '@aztec/stdlib/tx';
51
+
52
+ import { inspect } from 'util';
53
+
54
+ import { BlockSynchronizer } from './block_synchronizer/index.js';
55
+ import type { PXEConfig } from './config/index.js';
56
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
+ import {
58
+ ContractFunctionSimulator,
59
+ generateSimulatedProvingResult,
60
+ } from './contract_function_simulator/contract_function_simulator.js';
61
+ import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
62
+ import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
63
+ import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
64
+ import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
65
+ import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
66
+ import { JobCoordinator } from './job_coordinator/job_coordinator.js';
67
+ import {
68
+ PrivateKernelExecutionProver,
69
+ type PrivateKernelExecutionProverConfig,
70
+ } from './private_kernel/private_kernel_execution_prover.js';
71
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
72
+ import { AddressStore } from './storage/address_store/address_store.js';
73
+ import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
74
+ import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
75
+ import { ContractStore } from './storage/contract_store/contract_store.js';
76
+ import { NoteStore } from './storage/note_store/note_store.js';
77
+ import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
78
+ import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
79
+ import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
80
+ import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
81
+
82
+ export type PackedPrivateEvent = InTx & {
83
+ packedEvent: Fr[];
84
+ eventSelector: EventSelector;
85
+ };
86
+
87
+ /**
88
+ * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
89
+ * manage private state of users.
90
+ */
91
+ export class PXE {
92
+ private constructor(
93
+ private node: AztecNode,
94
+ private blockStateSynchronizer: BlockSynchronizer,
95
+ private keyStore: KeyStore,
96
+ private contractStore: ContractStore,
97
+ private noteStore: NoteStore,
98
+ private capsuleStore: CapsuleStore,
99
+ private anchorBlockStore: AnchorBlockStore,
100
+ private senderTaggingStore: SenderTaggingStore,
101
+ private senderAddressBookStore: SenderAddressBookStore,
102
+ private recipientTaggingStore: RecipientTaggingStore,
103
+ private addressStore: AddressStore,
104
+ private privateEventStore: PrivateEventStore,
105
+ private simulator: CircuitSimulator,
106
+ private proverEnabled: boolean,
107
+ private proofCreator: PrivateKernelProver,
108
+ private protocolContractsProvider: ProtocolContractsProvider,
109
+ private log: Logger,
110
+ private jobQueue: SerialQueue,
111
+ private jobCoordinator: JobCoordinator,
112
+ public debug: PXEDebugUtils,
113
+ ) {}
114
+
115
+ /**
116
+ * Creates an instance of a PXE by instantiating all the necessary data providers and services.
117
+ * Also triggers the registration of the protocol contracts and makes sure the provided node
118
+ * can be contacted.
119
+ *
120
+ * @returns A promise that resolves PXE is ready to be used.
121
+ */
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
+ ) {
131
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
132
+ const bindings: LoggerBindings | undefined =
133
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
134
+
135
+ const log =
136
+ !loggerOrSuffix || typeof loggerOrSuffix === 'string'
137
+ ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
138
+ : loggerOrSuffix;
139
+
140
+ const proverEnabled = !!config.proverEnabled;
141
+ const addressStore = new AddressStore(store);
142
+ const privateEventStore = new PrivateEventStore(store);
143
+ const contractStore = new ContractStore(store);
144
+ const noteStore = new NoteStore(store);
145
+ const anchorBlockStore = new AnchorBlockStore(store);
146
+ const senderTaggingStore = new SenderTaggingStore(store);
147
+ const senderAddressBookStore = new SenderAddressBookStore(store);
148
+ const recipientTaggingStore = new RecipientTaggingStore(store);
149
+ const capsuleStore = new CapsuleStore(store);
150
+ const keyStore = new KeyStore(store);
151
+ const tipsStore = new L2TipsKVStore(store, 'pxe');
152
+ const synchronizer = new BlockSynchronizer(
153
+ node,
154
+ store,
155
+ anchorBlockStore,
156
+ noteStore,
157
+ privateEventStore,
158
+ tipsStore,
159
+ config,
160
+ bindings,
161
+ );
162
+
163
+ const jobCoordinator = new JobCoordinator(store, bindings);
164
+ jobCoordinator.registerStores([
165
+ capsuleStore,
166
+ senderTaggingStore,
167
+ recipientTaggingStore,
168
+ privateEventStore,
169
+ noteStore,
170
+ ]);
171
+
172
+ const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
173
+
174
+ const jobQueue = new SerialQueue();
175
+
176
+ const pxe = new PXE(
177
+ node,
178
+ synchronizer,
179
+ keyStore,
180
+ contractStore,
181
+ noteStore,
182
+ capsuleStore,
183
+ anchorBlockStore,
184
+ senderTaggingStore,
185
+ senderAddressBookStore,
186
+ recipientTaggingStore,
187
+ addressStore,
188
+ privateEventStore,
189
+ simulator,
190
+ proverEnabled,
191
+ proofCreator,
192
+ protocolContractsProvider,
193
+ log,
194
+ jobQueue,
195
+ jobCoordinator,
196
+ debugUtils,
197
+ );
198
+
199
+ debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
200
+
201
+ pxe.jobQueue.start();
202
+
203
+ await pxe.#registerProtocolContracts();
204
+ const info = await node.getNodeInfo();
205
+ log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
206
+ return pxe;
207
+ }
208
+
209
+ // Internal methods
210
+
211
+ #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
212
+ const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
213
+
214
+ return new ContractFunctionSimulator(
215
+ proxyContractStore,
216
+ this.noteStore,
217
+ this.keyStore,
218
+ this.addressStore,
219
+ BenchmarkedNodeFactory.create(this.node),
220
+ this.senderTaggingStore,
221
+ this.recipientTaggingStore,
222
+ this.senderAddressBookStore,
223
+ this.capsuleStore,
224
+ this.privateEventStore,
225
+ this.simulator,
226
+ );
227
+ }
228
+
229
+ #contextualizeError(err: Error, ...context: string[]): Error {
230
+ let contextStr = '';
231
+ if (context.length > 0) {
232
+ contextStr = `\nContext:\n${context.join('\n')}`;
233
+ }
234
+ if (err instanceof SimulationError) {
235
+ err.setAztecContext(contextStr);
236
+ } else {
237
+ this.log.error(err.name, err);
238
+ this.log.debug(contextStr);
239
+ }
240
+ return err;
241
+ }
242
+
243
+ /**
244
+ * Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is
245
+ * complete.
246
+ *
247
+ * Useful for tasks that cannot run concurrently, such as contract function simulation.
248
+ */
249
+ #putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
250
+ // TODO(#12636): relax the conditions under which we forbid concurrency.
251
+ if (this.jobQueue.length() != 0) {
252
+ this.log.warn(
253
+ `PXE is already processing ${this.jobQueue.length()} jobs, concurrent execution is not supported. Will run once those are complete.`,
254
+ );
255
+ }
256
+
257
+ return this.jobQueue.put(async () => {
258
+ const jobId = this.jobCoordinator.beginJob();
259
+ this.log.verbose(`Beginning job ${jobId}`);
260
+
261
+ try {
262
+ const result = await fn(jobId);
263
+ this.log.verbose(`Committing job ${jobId}`);
264
+
265
+ await this.jobCoordinator.commitJob(jobId);
266
+ return result;
267
+ } catch (err) {
268
+ this.log.verbose(`Aborting job ${jobId}`);
269
+ await this.jobCoordinator.abortJob(jobId);
270
+ throw err;
271
+ }
272
+ });
273
+ }
274
+
275
+ async #registerProtocolContracts() {
276
+ const registered: Record<string, string> = {};
277
+ for (const name of protocolContractNames) {
278
+ const { address, contractClass, instance, artifact } =
279
+ await this.protocolContractsProvider.getProtocolContractArtifact(name);
280
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
281
+ await this.contractStore.addContractInstance(instance);
282
+ registered[name] = address.toString();
283
+ }
284
+ this.log.verbose(`Registered protocol contracts in pxe`, registered);
285
+ }
286
+
287
+ // Executes the entrypoint private function, as well as all nested private
288
+ // functions that might arise.
289
+ async #executePrivate(
290
+ contractFunctionSimulator: ContractFunctionSimulator,
291
+ txRequest: TxExecutionRequest,
292
+ scopes: AztecAddress[] | undefined,
293
+ jobId: string,
294
+ ): Promise<PrivateExecutionResult> {
295
+ const { origin: contractAddress, functionSelector } = txRequest;
296
+
297
+ try {
298
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
299
+
300
+ await ensureContractSynced(
301
+ contractAddress,
302
+ functionSelector,
303
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
304
+ this.node,
305
+ this.contractStore,
306
+ this.noteStore,
307
+ anchorBlockHeader,
308
+ jobId,
309
+ );
310
+
311
+ const result = await contractFunctionSimulator.run(
312
+ txRequest,
313
+ contractAddress,
314
+ functionSelector,
315
+ undefined,
316
+ anchorBlockHeader,
317
+ // The sender for tags is set by contracts, typically by an account
318
+ // contract entrypoint
319
+ undefined, // senderForTags
320
+ scopes,
321
+ jobId,
322
+ );
323
+ this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
324
+ return result;
325
+ } catch (err) {
326
+ if (err instanceof SimulationError) {
327
+ await enrichSimulationError(err, this.contractStore, this.log);
328
+ }
329
+ throw err;
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Simulate a utility function call on the given contract.
335
+ * @param contractFunctionSimulator - The simulator to use for the function call.
336
+ * @param call - The function call to execute.
337
+ * @param authWitnesses - Authentication witnesses required for the function call.
338
+ * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
339
+ * accounts if not specified.
340
+ * @param jobId - The job ID for staged writes.
341
+ * @returns The simulation result containing the outputs of the utility function.
342
+ */
343
+ async #simulateUtility(
344
+ contractFunctionSimulator: ContractFunctionSimulator,
345
+ call: FunctionCall,
346
+ authWitnesses: AuthWitness[] | undefined,
347
+ scopes: AztecAddress[] | undefined,
348
+ jobId: string,
349
+ ) {
350
+ try {
351
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
352
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
353
+ } catch (err) {
354
+ if (err instanceof SimulationError) {
355
+ await enrichSimulationError(err, this.contractStore, this.log);
356
+ }
357
+ throw err;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Simulate the public part of a transaction.
363
+ * This allows to catch public execution errors before submitting the transaction.
364
+ * It can also be used for estimating gas in the future.
365
+ * @param tx - The transaction to be simulated.
366
+ */
367
+ async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
368
+ // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
369
+ // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
370
+ try {
371
+ const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
372
+ if (result.revertReason) {
373
+ throw result.revertReason;
374
+ }
375
+ return result;
376
+ } catch (err) {
377
+ if (err instanceof SimulationError) {
378
+ try {
379
+ await enrichPublicSimulationError(err, this.contractStore, this.log);
380
+ } catch (enrichErr) {
381
+ this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
382
+ }
383
+ }
384
+ throw err;
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Generate a kernel proof, and create a private kernel output.
390
+ * The function takes in a transaction execution request, and the result of private execution
391
+ * and then generates a kernel proof.
392
+ *
393
+ * @param txExecutionRequest - The transaction request to be simulated and proved.
394
+ * @param proofCreator - The proof creator to use for proving the execution.
395
+ * @param privateExecutionResult - The result of the private execution
396
+ * @param config - The configuration for the kernel execution prover.
397
+ * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
398
+ */
399
+ async #prove(
400
+ txExecutionRequest: TxExecutionRequest,
401
+ proofCreator: PrivateKernelProver,
402
+ privateExecutionResult: PrivateExecutionResult,
403
+ config: PrivateKernelExecutionProverConfig,
404
+ ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
405
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
406
+ const anchorBlockHash = await anchorBlockHeader.hash();
407
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
408
+ const kernelTraceProver = new PrivateKernelExecutionProver(
409
+ kernelOracle,
410
+ proofCreator,
411
+ !this.proverEnabled,
412
+ this.log.getBindings(),
413
+ );
414
+ this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
415
+ return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
416
+ }
417
+
418
+ // Public API
419
+
420
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
421
+ return this.contractStore.getContractInstance(address);
422
+ }
423
+
424
+ /**
425
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
426
+ * @param id - Identifier of the contract class.
427
+ * @returns The contract artifact if found, undefined otherwise.
428
+ */
429
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
430
+ return await this.contractStore.getContractArtifact(id);
431
+ }
432
+
433
+ /**
434
+ * Registers a user account in PXE given its master encryption private key.
435
+ * Once a new account is registered, the PXE will trial-decrypt all published notes on
436
+ * the chain and store those that correspond to the registered account. Will do nothing if the
437
+ * account is already registered.
438
+ *
439
+ * @param secretKey - Secret key of the corresponding user master public key.
440
+ * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
441
+ * @returns The complete address of the account.
442
+ */
443
+ public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
444
+ const accounts = await this.keyStore.getAccounts();
445
+ const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
446
+ if (accounts.includes(accountCompleteAddress.address)) {
447
+ this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
448
+ return accountCompleteAddress;
449
+ } else {
450
+ this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
451
+ this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
452
+ }
453
+
454
+ await this.addressStore.addCompleteAddress(accountCompleteAddress);
455
+ return accountCompleteAddress;
456
+ }
457
+
458
+ /**
459
+ * Registers a sender in this PXE.
460
+ *
461
+ * After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
462
+ * Will do nothing if the address is already registered.
463
+ *
464
+ * @param sender - Address of the sender to register.
465
+ * @returns The address of the sender.
466
+ * TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
467
+ */
468
+ public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
469
+ const accounts = await this.keyStore.getAccounts();
470
+ if (accounts.includes(sender)) {
471
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
472
+ return sender;
473
+ }
474
+
475
+ const wasAdded = await this.senderAddressBookStore.addSender(sender);
476
+
477
+ if (wasAdded) {
478
+ this.log.info(`Added sender:\n ${sender.toString()}`);
479
+ } else {
480
+ this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
481
+ }
482
+
483
+ return sender;
484
+ }
485
+
486
+ /**
487
+ * Retrieves senders registered in this PXE.
488
+ * @returns Senders registered in this PXE.
489
+ */
490
+ public getSenders(): Promise<AztecAddress[]> {
491
+ return this.senderAddressBookStore.getSenders();
492
+ }
493
+
494
+ /**
495
+ * Removes a sender registered in this PXE.
496
+ * @param sender - The address of the sender to remove.
497
+ */
498
+ public async removeSender(sender: AztecAddress): Promise<void> {
499
+ const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
500
+
501
+ if (wasRemoved) {
502
+ this.log.info(`Removed sender:\n ${sender.toString()}`);
503
+ } else {
504
+ this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
505
+ }
506
+ }
507
+
508
+ /**
509
+ * Retrieves the user accounts registered on this PXE.
510
+ * @returns An array of the accounts registered on this PXE.
511
+ */
512
+ public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
513
+ // Get complete addresses of both the recipients and the accounts
514
+ const completeAddresses = await this.addressStore.getCompleteAddresses();
515
+ // Filter out the addresses not corresponding to accounts
516
+ const accounts = await this.keyStore.getAccounts();
517
+ return completeAddresses.filter(completeAddress =>
518
+ accounts.find(address => address.equals(completeAddress.address)),
519
+ );
520
+ }
521
+
522
+ /**
523
+ * Registers a contract class in the PXE without registering any associated contract instance with it.
524
+ *
525
+ * @param artifact - The build artifact for the contract class.
526
+ */
527
+ public async registerContractClass(artifact: ContractArtifact): Promise<void> {
528
+ const { id: contractClassId } = await getContractClassFromArtifact(artifact);
529
+ await this.contractStore.addContractArtifact(contractClassId, artifact);
530
+ this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
531
+ }
532
+
533
+ /**
534
+ * Adds deployed contracts to the PXE. Deployed contract information is used to access the
535
+ * contract code when simulating local transactions. This is automatically called by aztec.js when
536
+ * deploying a contract. Dapps that wish to interact with contracts already deployed should register
537
+ * these contracts in their users' PXE through this method.
538
+ *
539
+ * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
540
+ */
541
+ public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
542
+ const { instance } = contract;
543
+ let { artifact } = contract;
544
+
545
+ if (artifact) {
546
+ // If the user provides an artifact, validate it against the expected class id and register it
547
+ const contractClass = await getContractClassFromArtifact(artifact);
548
+ const contractClassId = contractClass.id;
549
+ if (!contractClassId.equals(instance.currentContractClassId)) {
550
+ throw new Error(
551
+ `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
552
+ );
553
+ }
554
+ const computedAddress = await computeContractAddressFromInstance(instance);
555
+ if (!computedAddress.equals(instance.address)) {
556
+ throw new Error('Added a contract in which the address does not match the contract instance.');
557
+ }
558
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
559
+
560
+ const publicFunctionSignatures = artifact.functions
561
+ .filter(fn => fn.functionType === FunctionType.PUBLIC)
562
+ .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
563
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
564
+ } else {
565
+ // Otherwise, make sure there is an artifact already registered for that class id
566
+ artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
567
+ if (!artifact) {
568
+ throw new Error(
569
+ `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
570
+ );
571
+ }
572
+ }
573
+
574
+ await this.contractStore.addContractInstance(instance);
575
+ this.log.info(
576
+ `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
577
+ );
578
+ }
579
+
580
+ /**
581
+ * Updates a deployed contract in the PXE. This is used to update the contract artifact when
582
+ * an update has happened, so the new code can be used in the simulation of local transactions.
583
+ * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
584
+ * @param contractAddress - The address of the contract to update.
585
+ * @param artifact - The updated artifact for the contract.
586
+ * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
587
+ * the current one (current one from the point of view of the node to which the PXE is connected).
588
+ */
589
+ public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
590
+ // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
591
+ // class while we're simulating it.
592
+ return this.#putInJobQueue(async () => {
593
+ const currentInstance = await this.contractStore.getContractInstance(contractAddress);
594
+ if (!currentInstance) {
595
+ throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
596
+ }
597
+ const contractClass = await getContractClassFromArtifact(artifact);
598
+ await this.blockStateSynchronizer.sync();
599
+
600
+ const header = await this.anchorBlockStore.getBlockHeader();
601
+
602
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
603
+ if (!contractClass.id.equals(currentClassId)) {
604
+ throw new Error('Could not update contract to a class different from the current one.');
605
+ }
606
+
607
+ await this.contractStore.addContractArtifact(contractClass.id, artifact);
608
+
609
+ const publicFunctionSignatures = artifact.functions
610
+ .filter(fn => fn.functionType === FunctionType.PUBLIC)
611
+ .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
612
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
613
+
614
+ currentInstance.currentContractClassId = contractClass.id;
615
+ await this.contractStore.addContractInstance(currentInstance);
616
+ this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
617
+ });
618
+ }
619
+
620
+ /**
621
+ * Retrieves the addresses of contracts added to this PXE.
622
+ * @returns An array of contracts addresses registered on this PXE.
623
+ */
624
+ public getContracts(): Promise<AztecAddress[]> {
625
+ return this.contractStore.getContractsAddresses();
626
+ }
627
+
628
+ /**
629
+ * Proves the private portion of a simulated transaction, ready to send to the network
630
+ * (where validators prove the public portion).
631
+ *
632
+ * @param txRequest - An authenticated tx request ready for proving
633
+ * @returns A result containing the proof and public inputs of the tail circuit.
634
+ * @throws If contract code not found, or public simulation reverts.
635
+ * Also throws if simulatePublic is true and public simulation reverts.
636
+ */
637
+ public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
638
+ let privateExecutionResult: PrivateExecutionResult;
639
+ // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
640
+ // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
641
+ return this.#putInJobQueue(async jobId => {
642
+ const totalTimer = new Timer();
643
+ try {
644
+ const syncTimer = new Timer();
645
+ await this.blockStateSynchronizer.sync();
646
+ const syncTime = syncTimer.ms();
647
+ const contractFunctionSimulator = this.#getSimulatorForTx();
648
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
649
+
650
+ const {
651
+ publicInputs,
652
+ chonkProof,
653
+ executionSteps,
654
+ timings: { proving } = {},
655
+ } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
656
+ simulate: false,
657
+ skipFeeEnforcement: false,
658
+ profileMode: 'none',
659
+ });
660
+
661
+ const totalTime = totalTimer.ms();
662
+
663
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => ({
664
+ functionName,
665
+ time: witgen,
666
+ oracles,
667
+ }));
668
+
669
+ const timings: ProvingTimings = {
670
+ total: totalTime,
671
+ sync: syncTime,
672
+ proving,
673
+ perFunction,
674
+ unaccounted:
675
+ totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
676
+ };
677
+
678
+ this.log.debug(`Proving completed in ${totalTime}ms`, { timings });
679
+
680
+ const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof!, {
681
+ timings,
682
+ nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
683
+ });
684
+
685
+ // While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
686
+ // chain before sending new logs, the sync can only see logs already included in blocks. If we send another
687
+ // transaction before this one is included in a block from this PXE, and that transaction contains a log with
688
+ // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
689
+ // storing the tags here prevents linkage of txs sent from the same PXE.
690
+ const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
691
+ if (preTagsUsedInTheTx.length > 0) {
692
+ // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
693
+ const txHash = (await txProvingResult.toTx()).txHash;
694
+
695
+ await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
696
+ this.log.debug(`Stored used pre-tags as sender for the tx`, {
697
+ preTagsUsedInTheTx,
698
+ });
699
+ } else {
700
+ this.log.debug(`No pre-tags used in the tx`);
701
+ }
702
+
703
+ return txProvingResult;
704
+ } catch (err: any) {
705
+ throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
706
+ }
707
+ });
708
+ }
709
+
710
+ /**
711
+ * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
712
+ *
713
+ * @param txRequest - An authenticated tx request ready for simulation
714
+ * @param msgSender - (Optional) The message sender to use for the simulation.
715
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
716
+ * @returns A trace of the program execution with gate counts.
717
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
718
+ */
719
+ public profileTx(
720
+ txRequest: TxExecutionRequest,
721
+ profileMode: 'full' | 'execution-steps' | 'gates',
722
+ skipProofGeneration: boolean = true,
723
+ ): Promise<TxProfileResult> {
724
+ // We disable concurrent profiles for consistency with simulateTx.
725
+ return this.#putInJobQueue(async jobId => {
726
+ const totalTimer = new Timer();
727
+ try {
728
+ const txInfo = {
729
+ origin: txRequest.origin,
730
+ functionSelector: txRequest.functionSelector,
731
+ simulatePublic: false,
732
+ chainId: txRequest.txContext.chainId,
733
+ version: txRequest.txContext.version,
734
+ authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
735
+ };
736
+ this.log.info(
737
+ `Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`,
738
+ txInfo,
739
+ );
740
+ const syncTimer = new Timer();
741
+ await this.blockStateSynchronizer.sync();
742
+ const syncTime = syncTimer.ms();
743
+
744
+ const contractFunctionSimulator = this.#getSimulatorForTx();
745
+ const privateExecutionResult = await this.#executePrivate(
746
+ contractFunctionSimulator,
747
+ txRequest,
748
+ undefined,
749
+ jobId,
750
+ );
751
+
752
+ const { executionSteps, timings: { proving } = {} } = await this.#prove(
753
+ txRequest,
754
+ this.proofCreator,
755
+ privateExecutionResult,
756
+ {
757
+ simulate: skipProofGeneration,
758
+ skipFeeEnforcement: false,
759
+ profileMode,
760
+ },
761
+ );
762
+
763
+ const totalTime = totalTimer.ms();
764
+
765
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => {
766
+ return {
767
+ functionName,
768
+ time: witgen,
769
+ oracles,
770
+ };
771
+ });
772
+
773
+ // Gate computation is time is not relevant for profiling, so we subtract it from the total time.
774
+ const gateCountComputationTime =
775
+ executionSteps.reduce((acc, { timings }) => acc + (timings.gateCount ?? 0), 0) ?? 0;
776
+
777
+ const total = totalTime - gateCountComputationTime;
778
+
779
+ const timings: ProvingTimings = {
780
+ total,
781
+ sync: syncTime,
782
+ proving,
783
+ perFunction,
784
+ unaccounted:
785
+ total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
786
+ };
787
+
788
+ const simulatorStats = contractFunctionSimulator.getStats();
789
+ return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: simulatorStats.nodeRPCCalls });
790
+ } catch (err: any) {
791
+ throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
792
+ }
793
+ });
794
+ }
795
+
796
+ /**
797
+ * Simulates a transaction based on the provided preauthenticated execution request.
798
+ * This will run a local simulation of private execution (and optionally of public as well), run the
799
+ * kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
800
+ * simulation results .
801
+ *
802
+ *
803
+ * Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
804
+ * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
805
+ *
806
+ *
807
+ * @param txRequest - An authenticated tx request ready for simulation
808
+ * @param simulatePublic - Whether to simulate the public part of the transaction.
809
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
810
+ * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
811
+ * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
812
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
813
+ * @returns A simulated transaction result object that includes public and private return values.
814
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
815
+ * Also throws if simulatePublic is true and public simulation reverts.
816
+ *
817
+ * TODO(#7456) Prevent msgSender being defined here for the first call
818
+ */
819
+ public simulateTx(
820
+ txRequest: TxExecutionRequest,
821
+ simulatePublic: boolean,
822
+ skipTxValidation: boolean = false,
823
+ skipFeeEnforcement: boolean = false,
824
+ overrides?: SimulationOverrides,
825
+ scopes?: AztecAddress[],
826
+ ): Promise<TxSimulationResult> {
827
+ // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
828
+ // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
829
+ // delete the same read value, or reading values that another simulation is currently modifying).
830
+ return this.#putInJobQueue(async jobId => {
831
+ try {
832
+ const totalTimer = new Timer();
833
+ const txInfo = {
834
+ origin: txRequest.origin,
835
+ functionSelector: txRequest.functionSelector,
836
+ simulatePublic,
837
+ chainId: txRequest.txContext.chainId,
838
+ version: txRequest.txContext.version,
839
+ authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
840
+ };
841
+ this.log.info(
842
+ `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`,
843
+ txInfo,
844
+ );
845
+ const syncTimer = new Timer();
846
+ await this.blockStateSynchronizer.sync();
847
+ const syncTime = syncTimer.ms();
848
+
849
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
850
+ // Temporary: in case there are overrides, we have to skip the kernels or validations
851
+ // will fail. Consider handing control to the user/wallet on whether they want to run them
852
+ // or not.
853
+ const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
854
+
855
+ // Execution of private functions only; no proving, and no kernel logic.
856
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
857
+
858
+ let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
859
+ let executionSteps: PrivateExecutionStep[] = [];
860
+
861
+ if (skipKernels) {
862
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
863
+ privateExecutionResult,
864
+ this.contractStore,
865
+ ));
866
+ } else {
867
+ // Kernel logic, plus proving of all private functions and kernels.
868
+ ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
869
+ simulate: true,
870
+ skipFeeEnforcement,
871
+ profileMode: 'none',
872
+ }));
873
+ }
874
+
875
+ const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
876
+ const simulatedTx = await privateSimulationResult.toSimulatedTx();
877
+ let publicSimulationTime: number | undefined;
878
+ let publicOutput: PublicSimulationOutput | undefined;
879
+ if (simulatePublic && publicInputs.forPublic) {
880
+ const publicSimulationTimer = new Timer();
881
+ publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
882
+ publicSimulationTime = publicSimulationTimer.ms();
883
+ }
884
+
885
+ let validationTime: number | undefined;
886
+ if (!skipTxValidation) {
887
+ const validationTimer = new Timer();
888
+ const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
889
+ validationTime = validationTimer.ms();
890
+ if (validationResult.result === 'invalid') {
891
+ throw new Error('The simulated transaction is unable to be added to state and is invalid.');
892
+ }
893
+ }
894
+
895
+ const txHash = simulatedTx.getTxHash();
896
+
897
+ const totalTime = totalTimer.ms();
898
+
899
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => ({
900
+ functionName,
901
+ time: witgen,
902
+ oracles,
903
+ }));
904
+
905
+ const timings: SimulationTimings = {
906
+ total: totalTime,
907
+ sync: syncTime,
908
+ publicSimulation: publicSimulationTime,
909
+ validation: validationTime,
910
+ perFunction,
911
+ unaccounted:
912
+ totalTime -
913
+ (syncTime +
914
+ (publicSimulationTime ?? 0) +
915
+ (validationTime ?? 0) +
916
+ perFunction.reduce((acc, { time }) => acc + time, 0)),
917
+ };
918
+
919
+ this.log.info(`Simulation completed for ${txHash.toString()} in ${totalTime}ms`, {
920
+ txHash,
921
+ ...txInfo,
922
+ ...(publicOutput
923
+ ? {
924
+ gasUsed: publicOutput.gasUsed,
925
+ revertCode: publicOutput.txEffect.revertCode.getCode(),
926
+ revertReason: publicOutput.revertReason,
927
+ }
928
+ : {}),
929
+ });
930
+
931
+ const simulatorStats = contractFunctionSimulator.getStats();
932
+ return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
933
+ timings,
934
+ nodeRPCCalls: simulatorStats.nodeRPCCalls,
935
+ });
936
+ } catch (err: any) {
937
+ throw this.#contextualizeError(
938
+ err,
939
+ inspect(txRequest),
940
+ `simulatePublic=${simulatePublic}`,
941
+ `skipTxValidation=${skipTxValidation}`,
942
+ `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
943
+ );
944
+ }
945
+ });
946
+ }
947
+
948
+ /**
949
+ * Simulate the execution of a contract utility function.
950
+ *
951
+ * @param call - The function call containing the function details, arguments, and target contract address.
952
+ * @param authwits - (Optional) The authentication witnesses required for the function call.
953
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
954
+ * default to all.
955
+ * @returns The result of the utility function call, structured based on the function ABI.
956
+ */
957
+ public simulateUtility(
958
+ call: FunctionCall,
959
+ authwits?: AuthWitness[],
960
+ scopes?: AztecAddress[],
961
+ ): Promise<UtilitySimulationResult> {
962
+ // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
963
+ // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
964
+ // delete the same read value, or reading values that another simulation is currently modifying).
965
+ return this.#putInJobQueue(async jobId => {
966
+ try {
967
+ const totalTimer = new Timer();
968
+ const syncTimer = new Timer();
969
+ await this.blockStateSynchronizer.sync();
970
+ const syncTime = syncTimer.ms();
971
+ const functionTimer = new Timer();
972
+ const contractFunctionSimulator = this.#getSimulatorForTx();
973
+
974
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
975
+ await ensureContractSynced(
976
+ call.to,
977
+ call.selector,
978
+ privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
979
+ this.node,
980
+ this.contractStore,
981
+ this.noteStore,
982
+ anchorBlockHeader,
983
+ jobId,
984
+ );
985
+
986
+ const executionResult = await this.#simulateUtility(
987
+ contractFunctionSimulator,
988
+ call,
989
+ authwits ?? [],
990
+ scopes,
991
+ jobId,
992
+ );
993
+ const functionTime = functionTimer.ms();
994
+
995
+ const totalTime = totalTimer.ms();
996
+
997
+ const perFunction = [{ functionName: call.name, time: functionTime }];
998
+
999
+ const timings: SimulationTimings = {
1000
+ total: totalTime,
1001
+ sync: syncTime,
1002
+ perFunction,
1003
+ unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time }) => acc + time, 0)),
1004
+ };
1005
+
1006
+ const simulationStats = contractFunctionSimulator.getStats();
1007
+ return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1008
+ } catch (err: any) {
1009
+ const { to, name, args } = call;
1010
+ const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1011
+ throw this.#contextualizeError(
1012
+ err,
1013
+ `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1014
+ `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1015
+ );
1016
+ }
1017
+ });
1018
+ }
1019
+
1020
+ /**
1021
+ * Returns the private events given search parameters.
1022
+ * @param eventSelector - Event selector to search for.
1023
+ * @param filter
1024
+ * contractAddress - The address of the contract to get events from. Required.
1025
+ * scopes - One or more event scope addresses to filter by. Required.
1026
+ * fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
1027
+ * Defaults to 0.
1028
+ * If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
1029
+ * toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
1030
+ * Defaults to the latest known block to PXE + 1.
1031
+ * @returns - The packed events with block and tx metadata.
1032
+ */
1033
+ public async getPrivateEvents(
1034
+ eventSelector: EventSelector,
1035
+ filter: PrivateEventFilter,
1036
+ ): Promise<PackedPrivateEvent[]> {
1037
+ let anchorBlockNumber: BlockNumber;
1038
+
1039
+ await this.#putInJobQueue(async jobId => {
1040
+ await this.blockStateSynchronizer.sync();
1041
+
1042
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1043
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1044
+
1045
+ const contractFunctionSimulator = this.#getSimulatorForTx();
1046
+
1047
+ await ensureContractSynced(
1048
+ filter.contractAddress,
1049
+ null,
1050
+ async privateSyncCall =>
1051
+ await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1052
+ this.node,
1053
+ this.contractStore,
1054
+ this.noteStore,
1055
+ anchorBlockHeader,
1056
+ jobId,
1057
+ );
1058
+ });
1059
+
1060
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1061
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1062
+
1063
+ this.log.debug(
1064
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1065
+ );
1066
+
1067
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1068
+ }
1069
+
1070
+ /**
1071
+ * Stops the PXE's job queue.
1072
+ */
1073
+ public stop(): Promise<void> {
1074
+ return this.jobQueue.end();
1075
+ }
1076
+ }