@aztec/pxe 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9

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 (442) hide show
  1. package/README.md +5 -5
  2. package/dest/access_scopes.d.ts +9 -0
  3. package/dest/access_scopes.d.ts.map +1 -0
  4. package/dest/access_scopes.js +6 -0
  5. package/dest/bin/check_oracle_version.d.ts +1 -1
  6. package/dest/bin/check_oracle_version.js +110 -10
  7. package/dest/block_synchronizer/block_synchronizer.d.ts +45 -0
  8. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  9. package/dest/block_synchronizer/block_synchronizer.js +153 -0
  10. package/dest/block_synchronizer/index.d.ts +2 -0
  11. package/dest/block_synchronizer/index.d.ts.map +1 -0
  12. package/dest/block_synchronizer/index.js +1 -0
  13. package/dest/config/index.d.ts +11 -17
  14. package/dest/config/index.d.ts.map +1 -1
  15. package/dest/config/index.js +27 -16
  16. package/dest/config/package_info.d.ts +1 -1
  17. package/dest/config/package_info.js +1 -1
  18. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  19. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  20. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  21. package/dest/contract_function_simulator/contract_function_simulator.d.ts +79 -27
  22. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/contract_function_simulator.js +287 -87
  24. package/dest/contract_function_simulator/execution_note_cache.d.ts +26 -15
  25. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/execution_note_cache.js +65 -37
  27. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  28. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  29. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  30. package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
  31. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/index.d.ts +5 -3
  33. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/index.js +3 -2
  35. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -4
  36. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  37. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +7 -4
  38. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
  39. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  41. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
  42. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
  44. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +7 -4
  45. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +13 -4
  47. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +16 -0
  48. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  49. package/dest/contract_function_simulator/noir-structs/utility_context.js +22 -0
  50. package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
  51. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/oracle/index.js +1 -1
  53. package/dest/contract_function_simulator/oracle/interfaces.d.ts +107 -0
  54. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  55. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  56. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -2
  57. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  58. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
  59. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +14 -8
  60. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  61. package/dest/contract_function_simulator/oracle/note_packing_utils.js +16 -11
  62. package/dest/contract_function_simulator/oracle/oracle.d.ts +26 -22
  63. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  64. package/dest/contract_function_simulator/oracle/oracle.js +156 -113
  65. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -27
  66. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  67. package/dest/contract_function_simulator/oracle/private_execution.js +3 -48
  68. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +72 -52
  69. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  70. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +173 -68
  71. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +116 -53
  72. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  73. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +217 -94
  74. package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
  75. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  76. package/dest/contract_function_simulator/pick_notes.js +1 -1
  77. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  78. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  79. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  80. package/dest/contract_logging.d.ts +22 -0
  81. package/dest/contract_logging.d.ts.map +1 -0
  82. package/dest/contract_logging.js +23 -0
  83. package/dest/contract_sync/contract_sync_service.d.ts +43 -0
  84. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  85. package/dest/contract_sync/contract_sync_service.js +97 -0
  86. package/dest/contract_sync/helpers.d.ts +29 -0
  87. package/dest/contract_sync/helpers.d.ts.map +1 -0
  88. package/dest/contract_sync/helpers.js +55 -0
  89. package/dest/debug/pxe_debug_utils.d.ts +45 -0
  90. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  91. package/dest/debug/pxe_debug_utils.js +48 -0
  92. package/dest/entrypoints/client/bundle/index.d.ts +7 -3
  93. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  94. package/dest/entrypoints/client/bundle/index.js +5 -2
  95. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  96. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/client/bundle/utils.js +40 -17
  98. package/dest/entrypoints/client/lazy/index.d.ts +7 -3
  99. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  100. package/dest/entrypoints/client/lazy/index.js +5 -2
  101. package/dest/entrypoints/client/lazy/utils.d.ts +9 -9
  102. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  103. package/dest/entrypoints/client/lazy/utils.js +40 -17
  104. package/dest/entrypoints/pxe_creation_options.d.ts +7 -3
  105. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  106. package/dest/entrypoints/server/index.d.ts +9 -3
  107. package/dest/entrypoints/server/index.d.ts.map +1 -1
  108. package/dest/entrypoints/server/index.js +7 -2
  109. package/dest/entrypoints/server/utils.d.ts +5 -24
  110. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  111. package/dest/entrypoints/server/utils.js +42 -51
  112. package/dest/error_enriching.d.ts +11 -0
  113. package/dest/error_enriching.d.ts.map +1 -0
  114. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
  115. package/dest/events/event_service.d.ts +15 -0
  116. package/dest/events/event_service.d.ts.map +1 -0
  117. package/dest/events/event_service.js +44 -0
  118. package/dest/events/index.d.ts +2 -0
  119. package/dest/events/index.d.ts.map +1 -0
  120. package/dest/events/index.js +1 -0
  121. package/dest/events/private_event_filter_validator.d.ts +9 -0
  122. package/dest/events/private_event_filter_validator.d.ts.map +1 -0
  123. package/dest/events/private_event_filter_validator.js +38 -0
  124. package/dest/job_coordinator/job_coordinator.d.ts +75 -0
  125. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
  126. package/dest/job_coordinator/job_coordinator.js +94 -0
  127. package/dest/logs/log_service.d.ts +29 -0
  128. package/dest/logs/log_service.d.ts.map +1 -0
  129. package/dest/logs/log_service.js +118 -0
  130. package/dest/notes/index.d.ts +2 -0
  131. package/dest/notes/index.d.ts.map +1 -0
  132. package/dest/notes/index.js +1 -0
  133. package/dest/notes/note_service.d.ts +49 -0
  134. package/dest/notes/note_service.d.ts.map +1 -0
  135. package/dest/notes/note_service.js +148 -0
  136. package/dest/notes_filter.d.ts +25 -0
  137. package/dest/notes_filter.d.ts.map +1 -0
  138. package/dest/notes_filter.js +4 -0
  139. package/dest/oracle_version.d.ts +3 -3
  140. package/dest/oracle_version.d.ts.map +1 -1
  141. package/dest/oracle_version.js +4 -3
  142. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  143. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  144. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.js +41 -0
  145. package/dest/private_kernel/hints/index.d.ts +3 -3
  146. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  147. package/dest/private_kernel/hints/index.js +2 -2
  148. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
  149. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  150. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +22 -16
  151. package/dest/private_kernel/index.d.ts +1 -1
  152. package/dest/private_kernel/private_kernel_execution_prover.d.ts +11 -3
  153. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  154. package/dest/private_kernel/private_kernel_execution_prover.js +48 -43
  155. package/dest/private_kernel/private_kernel_oracle.d.ts +26 -25
  156. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  157. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  158. package/dest/pxe.d.ts +250 -0
  159. package/dest/pxe.d.ts.map +1 -0
  160. package/dest/pxe.js +774 -0
  161. package/dest/storage/address_store/address_store.d.ts +11 -0
  162. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  163. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -15
  164. package/dest/storage/address_store/index.d.ts +2 -0
  165. package/dest/storage/address_store/index.d.ts.map +1 -0
  166. package/dest/storage/address_store/index.js +1 -0
  167. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
  168. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  169. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +10 -13
  170. package/dest/storage/anchor_block_store/index.d.ts +2 -0
  171. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  172. package/dest/storage/anchor_block_store/index.js +1 -0
  173. package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
  174. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  175. package/dest/storage/capsule_store/capsule_store.js +253 -0
  176. package/dest/storage/capsule_store/index.d.ts +2 -0
  177. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  178. package/dest/storage/capsule_store/index.js +1 -0
  179. package/dest/storage/contract_store/contract_store.d.ts +93 -0
  180. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  181. package/dest/storage/contract_store/contract_store.js +309 -0
  182. package/dest/storage/contract_store/index.d.ts +2 -0
  183. package/dest/storage/contract_store/index.d.ts.map +1 -0
  184. package/dest/storage/contract_store/index.js +1 -0
  185. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  186. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  187. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
  188. package/dest/storage/index.d.ts +8 -9
  189. package/dest/storage/index.d.ts.map +1 -1
  190. package/dest/storage/index.js +7 -8
  191. package/dest/storage/metadata.d.ts +2 -2
  192. package/dest/storage/metadata.js +1 -1
  193. package/dest/storage/note_store/index.d.ts +3 -0
  194. package/dest/storage/note_store/index.d.ts.map +1 -0
  195. package/dest/storage/note_store/index.js +2 -0
  196. package/dest/storage/note_store/note_store.d.ts +83 -0
  197. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  198. package/dest/storage/note_store/note_store.js +343 -0
  199. package/dest/storage/note_store/stored_note.d.ts +16 -0
  200. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  201. package/dest/storage/note_store/stored_note.js +43 -0
  202. package/dest/storage/private_event_store/private_event_store.d.ts +91 -0
  203. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  204. package/dest/storage/private_event_store/private_event_store.js +273 -0
  205. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  206. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  207. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  208. package/dest/storage/tagging_store/index.d.ts +4 -0
  209. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  210. package/dest/storage/tagging_store/index.js +3 -0
  211. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
  212. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  213. package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
  214. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  215. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  216. package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
  217. package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
  218. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  219. package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
  220. package/dest/tagging/constants.d.ts +2 -0
  221. package/dest/tagging/constants.d.ts.map +1 -0
  222. package/dest/tagging/constants.js +10 -0
  223. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  224. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  225. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  226. package/dest/tagging/index.d.ts +17 -0
  227. package/dest/tagging/index.d.ts.map +1 -0
  228. package/dest/tagging/index.js +15 -0
  229. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
  230. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  231. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  232. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  233. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  234. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  235. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
  236. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  237. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
  238. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
  239. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  240. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  241. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  242. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  243. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
  244. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
  245. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  246. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
  247. package/package.json +30 -23
  248. package/src/access_scopes.ts +9 -0
  249. package/src/bin/check_oracle_version.ts +135 -10
  250. package/src/block_synchronizer/block_synchronizer.ts +178 -0
  251. package/src/block_synchronizer/index.ts +1 -0
  252. package/src/config/index.ts +32 -32
  253. package/src/config/package_info.ts +1 -1
  254. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  255. package/src/contract_function_simulator/contract_function_simulator.ts +505 -140
  256. package/src/contract_function_simulator/execution_note_cache.ts +67 -32
  257. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  258. package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
  259. package/src/contract_function_simulator/index.ts +4 -2
  260. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +7 -3
  261. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
  262. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
  263. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +15 -3
  264. package/src/contract_function_simulator/noir-structs/utility_context.ts +23 -0
  265. package/src/contract_function_simulator/oracle/index.ts +1 -1
  266. package/src/contract_function_simulator/oracle/interfaces.ts +185 -0
  267. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
  268. package/src/contract_function_simulator/oracle/note_packing_utils.ts +30 -14
  269. package/src/contract_function_simulator/oracle/oracle.ts +197 -110
  270. package/src/contract_function_simulator/oracle/private_execution.ts +4 -78
  271. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +248 -122
  272. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +372 -138
  273. package/src/contract_function_simulator/pick_notes.ts +1 -1
  274. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  275. package/src/contract_logging.ts +39 -0
  276. package/src/contract_sync/contract_sync_service.ts +152 -0
  277. package/src/contract_sync/helpers.ts +98 -0
  278. package/src/debug/pxe_debug_utils.ts +93 -0
  279. package/src/entrypoints/client/bundle/index.ts +6 -2
  280. package/src/entrypoints/client/bundle/utils.ts +31 -32
  281. package/src/entrypoints/client/lazy/index.ts +6 -2
  282. package/src/entrypoints/client/lazy/utils.ts +31 -32
  283. package/src/entrypoints/pxe_creation_options.ts +6 -2
  284. package/src/entrypoints/server/index.ts +8 -2
  285. package/src/entrypoints/server/utils.ts +39 -91
  286. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
  287. package/src/events/event_service.ts +71 -0
  288. package/src/events/index.ts +1 -0
  289. package/src/events/private_event_filter_validator.ts +46 -0
  290. package/src/job_coordinator/job_coordinator.ts +150 -0
  291. package/src/logs/log_service.ts +208 -0
  292. package/src/notes/index.ts +1 -0
  293. package/src/notes/note_service.ts +196 -0
  294. package/src/notes_filter.ts +26 -0
  295. package/src/oracle_version.ts +4 -3
  296. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +16 -16
  297. package/src/private_kernel/hints/index.ts +2 -2
  298. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +44 -37
  299. package/src/private_kernel/private_kernel_execution_prover.ts +64 -55
  300. package/src/private_kernel/private_kernel_oracle.ts +118 -37
  301. package/src/pxe.ts +1137 -0
  302. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +15 -21
  303. package/src/storage/address_store/index.ts +1 -0
  304. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -17
  305. package/src/storage/anchor_block_store/index.ts +1 -0
  306. package/src/storage/capsule_store/capsule_store.ts +315 -0
  307. package/src/storage/capsule_store/index.ts +1 -0
  308. package/src/storage/contract_store/contract_store.ts +429 -0
  309. package/src/storage/contract_store/index.ts +1 -0
  310. package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
  311. package/src/storage/index.ts +7 -8
  312. package/src/storage/metadata.ts +1 -1
  313. package/src/storage/note_store/index.ts +2 -0
  314. package/src/storage/note_store/note_store.ts +418 -0
  315. package/src/storage/note_store/stored_note.ts +48 -0
  316. package/src/storage/private_event_store/private_event_store.ts +384 -0
  317. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  318. package/src/storage/tagging_store/index.ts +3 -0
  319. package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
  320. package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
  321. package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
  322. package/src/tagging/constants.ts +10 -0
  323. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  324. package/src/tagging/index.ts +19 -0
  325. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
  326. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  327. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
  328. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
  329. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
  330. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
  331. package/dest/bin/index.d.ts +0 -3
  332. package/dest/bin/index.d.ts.map +0 -1
  333. package/dest/bin/index.js +0 -48
  334. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
  335. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  336. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  337. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
  338. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
  339. package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
  340. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  341. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  342. package/dest/contract_function_simulator/proxied_node.js +0 -27
  343. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
  344. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  345. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
  346. package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
  347. package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
  348. package/dest/contract_function_simulator/tagging_utils.js +0 -23
  349. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  350. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  351. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  352. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  353. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +0 -41
  354. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
  355. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  356. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  357. package/dest/pxe_service/error_enriching.d.ts +0 -11
  358. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  359. package/dest/pxe_service/index.d.ts +0 -3
  360. package/dest/pxe_service/index.d.ts.map +0 -1
  361. package/dest/pxe_service/index.js +0 -2
  362. package/dest/pxe_service/pxe_service.d.ts +0 -101
  363. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  364. package/dest/pxe_service/pxe_service.js +0 -791
  365. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
  366. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  367. package/dest/storage/address_data_provider/index.d.ts +0 -2
  368. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  369. package/dest/storage/address_data_provider/index.js +0 -1
  370. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
  371. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  372. package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -122
  373. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  374. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  375. package/dest/storage/capsule_data_provider/index.js +0 -1
  376. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +0 -75
  377. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  378. package/dest/storage/contract_data_provider/contract_data_provider.js +0 -208
  379. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  380. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  381. package/dest/storage/contract_data_provider/index.js +0 -1
  382. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  383. package/dest/storage/data_provider.d.ts +0 -4
  384. package/dest/storage/data_provider.d.ts.map +0 -1
  385. package/dest/storage/data_provider.js +0 -1
  386. package/dest/storage/note_data_provider/index.d.ts +0 -3
  387. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  388. package/dest/storage/note_data_provider/index.js +0 -2
  389. package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
  390. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  391. package/dest/storage/note_data_provider/note_dao.js +0 -102
  392. package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
  393. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  394. package/dest/storage/note_data_provider/note_data_provider.js +0 -260
  395. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
  396. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  397. package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
  398. package/dest/storage/sync_data_provider/index.d.ts +0 -2
  399. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  400. package/dest/storage/sync_data_provider/index.js +0 -1
  401. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
  402. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  403. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  404. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  405. package/dest/storage/tagging_data_provider/index.js +0 -1
  406. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
  407. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  408. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
  409. package/dest/synchronizer/index.d.ts +0 -2
  410. package/dest/synchronizer/index.d.ts.map +0 -1
  411. package/dest/synchronizer/index.js +0 -1
  412. package/dest/synchronizer/synchronizer.d.ts +0 -35
  413. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  414. package/dest/synchronizer/synchronizer.js +0 -102
  415. package/dest/test/pxe_test_suite.d.ts +0 -3
  416. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  417. package/dest/test/pxe_test_suite.js +0 -97
  418. package/src/bin/index.ts +0 -62
  419. package/src/contract_function_simulator/execution_data_provider.ts +0 -361
  420. package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
  421. package/src/contract_function_simulator/proxied_node.ts +0 -33
  422. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
  423. package/src/contract_function_simulator/tagging_utils.ts +0 -32
  424. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
  425. package/src/pxe_service/index.ts +0 -2
  426. package/src/pxe_service/pxe_service.ts +0 -1139
  427. package/src/storage/address_data_provider/index.ts +0 -1
  428. package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -157
  429. package/src/storage/capsule_data_provider/index.ts +0 -1
  430. package/src/storage/contract_data_provider/contract_data_provider.ts +0 -300
  431. package/src/storage/contract_data_provider/index.ts +0 -1
  432. package/src/storage/data_provider.ts +0 -3
  433. package/src/storage/note_data_provider/index.ts +0 -2
  434. package/src/storage/note_data_provider/note_dao.ts +0 -154
  435. package/src/storage/note_data_provider/note_data_provider.ts +0 -350
  436. package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
  437. package/src/storage/sync_data_provider/index.ts +0 -1
  438. package/src/storage/tagging_data_provider/index.ts +0 -1
  439. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
  440. package/src/synchronizer/index.ts +0 -1
  441. package/src/synchronizer/synchronizer.ts +0 -121
  442. package/src/test/pxe_test_suite.ts +0 -113
@@ -1,1139 +0,0 @@
1
- import { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
- import { SerialQueue } from '@aztec/foundation/queue';
5
- import { Timer } from '@aztec/foundation/timer';
6
- import type { SiblingPath } from '@aztec/foundation/trees';
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 {
11
- ProtocolContractAddress,
12
- type ProtocolContractsProvider,
13
- protocolContractNames,
14
- } from '@aztec/protocol-contracts';
15
- import type { CircuitSimulator } from '@aztec/simulator/client';
16
- import {
17
- type ContractArtifact,
18
- EventSelector,
19
- FunctionCall,
20
- FunctionSelector,
21
- FunctionType,
22
- decodeFromAbi,
23
- decodeFunctionSignature,
24
- encodeArguments,
25
- } from '@aztec/stdlib/abi';
26
- import type { AuthWitness } from '@aztec/stdlib/auth-witness';
27
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
28
- import type { L2Block } from '@aztec/stdlib/block';
29
- import {
30
- CompleteAddress,
31
- type ContractClassWithId,
32
- type ContractInstanceWithAddress,
33
- type NodeInfo,
34
- type PartialAddress,
35
- computeContractAddressFromInstance,
36
- getContractClassFromArtifact,
37
- } from '@aztec/stdlib/contract';
38
- import { SimulationError } from '@aztec/stdlib/errors';
39
- import type { GasFees } from '@aztec/stdlib/gas';
40
- import { siloNullifier } from '@aztec/stdlib/hash';
41
- import type {
42
- AztecNode,
43
- EventMetadataDefinition,
44
- GetContractClassLogsResponse,
45
- GetPublicLogsResponse,
46
- PXE,
47
- PXEInfo,
48
- PrivateKernelProver,
49
- } from '@aztec/stdlib/interfaces/client';
50
- import type {
51
- PrivateExecutionStep,
52
- PrivateKernelExecutionProofOutput,
53
- PrivateKernelTailCircuitPublicInputs,
54
- } from '@aztec/stdlib/kernel';
55
- import type { LogFilter } from '@aztec/stdlib/logs';
56
- import { computeL2ToL1MembershipWitness, getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
57
- import { type NotesFilter, UniqueNote } from '@aztec/stdlib/note';
58
- import { MerkleTreeId } from '@aztec/stdlib/trees';
59
- import {
60
- type ContractOverrides,
61
- type IndexedTxEffect,
62
- PrivateExecutionResult,
63
- PrivateSimulationResult,
64
- type ProvingTimings,
65
- PublicSimulationOutput,
66
- SimulationOverrides,
67
- type SimulationTimings,
68
- Tx,
69
- TxExecutionRequest,
70
- type TxHash,
71
- TxProfileResult,
72
- TxProvingResult,
73
- type TxReceipt,
74
- TxSimulationResult,
75
- UtilitySimulationResult,
76
- } from '@aztec/stdlib/tx';
77
-
78
- import { inspect } from 'util';
79
-
80
- import type { PXEServiceConfig } from '../config/index.js';
81
- import { getPackageInfo } from '../config/package_info.js';
82
- import {
83
- ContractFunctionSimulator,
84
- generateSimulatedProvingResult,
85
- } from '../contract_function_simulator/contract_function_simulator.js';
86
- import { readCurrentClassId } from '../contract_function_simulator/oracle/private_execution.js';
87
- import { ProxiedContractDataProviderFactory } from '../contract_function_simulator/proxied_contract_data_source.js';
88
- import { ProxiedNodeFactory } from '../contract_function_simulator/proxied_node.js';
89
- import { PXEOracleInterface } from '../contract_function_simulator/pxe_oracle_interface.js';
90
- import {
91
- PrivateKernelExecutionProver,
92
- type PrivateKernelExecutionProverConfig,
93
- } from '../private_kernel/private_kernel_execution_prover.js';
94
- import { PrivateKernelOracleImpl } from '../private_kernel/private_kernel_oracle_impl.js';
95
- import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
96
- import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
97
- import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
98
- import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
99
- import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
100
- import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
101
- import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
102
- import { Synchronizer } from '../synchronizer/index.js';
103
- import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
104
-
105
- /**
106
- * A Private eXecution Environment (PXE) implementation.
107
- */
108
- export class PXEService implements PXE {
109
- #nodeInfo?: NodeInfo;
110
-
111
- private constructor(
112
- private node: AztecNode,
113
- private synchronizer: Synchronizer,
114
- private keyStore: KeyStore,
115
- private contractDataProvider: ContractDataProvider,
116
- private noteDataProvider: NoteDataProvider,
117
- private capsuleDataProvider: CapsuleDataProvider,
118
- private syncDataProvider: SyncDataProvider,
119
- private taggingDataProvider: TaggingDataProvider,
120
- private addressDataProvider: AddressDataProvider,
121
- private privateEventDataProvider: PrivateEventDataProvider,
122
- private simulator: CircuitSimulator,
123
- private packageVersion: string,
124
- private proverEnabled: boolean,
125
- private proofCreator: PrivateKernelProver,
126
- private protocolContractsProvider: ProtocolContractsProvider,
127
- private log: Logger,
128
- private jobQueue: SerialQueue,
129
- ) {}
130
-
131
- /**
132
- * Creates an instance of a PXE Service by instantiating all the necessary data providers and services.
133
- * Also triggers the registration of the protocol contracts and makes sure the provided node
134
- * can be contacted.
135
- *
136
- * @returns A promise that resolves PXE service is ready to be used.
137
- */
138
- public static async create(
139
- node: AztecNode,
140
- store: AztecAsyncKVStore,
141
- proofCreator: PrivateKernelProver,
142
- simulator: CircuitSimulator,
143
- protocolContractsProvider: ProtocolContractsProvider,
144
- config: PXEServiceConfig,
145
- loggerOrSuffix?: string | Logger,
146
- ) {
147
- const log =
148
- !loggerOrSuffix || typeof loggerOrSuffix === 'string'
149
- ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
150
- : loggerOrSuffix;
151
-
152
- const packageVersion = getPackageInfo().version;
153
- const proverEnabled = !!config.proverEnabled;
154
- const addressDataProvider = new AddressDataProvider(store);
155
- const privateEventDataProvider = new PrivateEventDataProvider(store);
156
- const contractDataProvider = new ContractDataProvider(store);
157
- const noteDataProvider = await NoteDataProvider.create(store);
158
- const syncDataProvider = new SyncDataProvider(store);
159
- const taggingDataProvider = new TaggingDataProvider(store);
160
- const capsuleDataProvider = new CapsuleDataProvider(store);
161
- const keyStore = new KeyStore(store);
162
- const tipsStore = new L2TipsKVStore(store, 'pxe');
163
- const synchronizer = new Synchronizer(
164
- node,
165
- syncDataProvider,
166
- noteDataProvider,
167
- taggingDataProvider,
168
- tipsStore,
169
- config,
170
- loggerOrSuffix,
171
- );
172
-
173
- const jobQueue = new SerialQueue();
174
-
175
- const pxeService = new PXEService(
176
- node,
177
- synchronizer,
178
- keyStore,
179
- contractDataProvider,
180
- noteDataProvider,
181
- capsuleDataProvider,
182
- syncDataProvider,
183
- taggingDataProvider,
184
- addressDataProvider,
185
- privateEventDataProvider,
186
- simulator,
187
- packageVersion,
188
- proverEnabled,
189
- proofCreator,
190
- protocolContractsProvider,
191
- log,
192
- jobQueue,
193
- );
194
-
195
- pxeService.jobQueue.start();
196
-
197
- await pxeService.#registerProtocolContracts();
198
- const info = await pxeService.getNodeInfo();
199
- log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
200
- return pxeService;
201
- }
202
-
203
- public getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<number | undefined> {
204
- return this.node.getL1ToL2MessageBlock(l1ToL2Message);
205
- }
206
-
207
- // Aztec node proxy methods
208
-
209
- public isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
210
- return this.node.isL1ToL2MessageSynced(l1ToL2Message);
211
- }
212
-
213
- public async getL2ToL1MembershipWitness(
214
- blockNumber: number,
215
- l2Tol1Message: Fr,
216
- ): Promise<[bigint, SiblingPath<number>]> {
217
- const result = await computeL2ToL1MembershipWitness(this.node, blockNumber, l2Tol1Message);
218
- if (!result) {
219
- throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
220
- }
221
- return [result.leafIndex, result.siblingPath];
222
- }
223
-
224
- public getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
225
- return this.node.getTxReceipt(txHash);
226
- }
227
-
228
- public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
229
- return this.node.getTxEffect(txHash);
230
- }
231
-
232
- public getBlockNumber(): Promise<number> {
233
- return this.node.getBlockNumber();
234
- }
235
-
236
- public getProvenBlockNumber(): Promise<number> {
237
- return this.node.getProvenBlockNumber();
238
- }
239
-
240
- public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
241
- return this.node.getPublicLogs(filter);
242
- }
243
-
244
- public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
245
- return this.node.getContractClassLogs(filter);
246
- }
247
-
248
- public getPublicStorageAt(contract: AztecAddress, slot: Fr) {
249
- return this.node.getPublicStorageAt('latest', contract, slot);
250
- }
251
-
252
- public async getL1ToL2MembershipWitness(
253
- contractAddress: AztecAddress,
254
- messageHash: Fr,
255
- secret: Fr,
256
- ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]> {
257
- return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
258
- }
259
-
260
- // Internal methods
261
-
262
- #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
263
- const pxeOracleInterface = new PXEOracleInterface(
264
- ProxiedNodeFactory.create(this.node),
265
- this.keyStore,
266
- ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts),
267
- this.noteDataProvider,
268
- this.capsuleDataProvider,
269
- this.syncDataProvider,
270
- this.taggingDataProvider,
271
- this.addressDataProvider,
272
- this.privateEventDataProvider,
273
- this.log,
274
- );
275
- return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
276
- }
277
-
278
- #contextualizeError(err: Error, ...context: string[]): Error {
279
- let contextStr = '';
280
- if (context.length > 0) {
281
- contextStr = `\nContext:\n${context.join('\n')}`;
282
- }
283
- if (err instanceof SimulationError) {
284
- err.setAztecContext(contextStr);
285
- } else {
286
- this.log.error(err.name, err);
287
- this.log.debug(contextStr);
288
- }
289
- return err;
290
- }
291
-
292
- /**
293
- * Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is
294
- * complete.
295
- *
296
- * Useful for tasks that cannot run concurrently, such as contract function simulation.
297
- */
298
- #putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
299
- // TODO(#12636): relax the conditions under which we forbid concurrency.
300
- if (this.jobQueue.length() != 0) {
301
- this.log.warn(
302
- `PXE is already processing ${this.jobQueue.length()} jobs, concurrent execution is not supported. Will run once those are complete.`,
303
- );
304
- }
305
-
306
- return this.jobQueue.put(fn);
307
- }
308
-
309
- async #registerProtocolContracts() {
310
- const registered: Record<string, string> = {};
311
- for (const name of protocolContractNames) {
312
- const { address, contractClass, instance, artifact } =
313
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
314
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
315
- await this.contractDataProvider.addContractInstance(instance);
316
- registered[name] = address.toString();
317
- }
318
- this.log.verbose(`Registered protocol contracts in pxe`, registered);
319
- }
320
-
321
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
322
- return !!(await this.node.getContractClass(id));
323
- }
324
-
325
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
326
- return !!(await this.node.getContract(address));
327
- }
328
-
329
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
330
- const initNullifier = await siloNullifier(address, address.toField());
331
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
332
- }
333
-
334
- async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
335
- const contract = await this.contractDataProvider.getContract(to);
336
- if (!contract) {
337
- throw new Error(
338
- `Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
339
- );
340
- }
341
-
342
- const functionDao = contract.functions.find(f => f.name === functionName);
343
- if (!functionDao) {
344
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
345
- }
346
-
347
- return {
348
- name: functionDao.name,
349
- args: encodeArguments(functionDao, args),
350
- selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
351
- type: functionDao.functionType,
352
- to,
353
- isStatic: functionDao.isStatic,
354
- returnTypes: functionDao.returnTypes,
355
- };
356
- }
357
-
358
- // Executes the entrypoint private function, as well as all nested private
359
- // functions that might arise.
360
- async #executePrivate(
361
- contractFunctionSimulator: ContractFunctionSimulator,
362
- txRequest: TxExecutionRequest,
363
- scopes?: AztecAddress[],
364
- ): Promise<PrivateExecutionResult> {
365
- const { origin: contractAddress, functionSelector } = txRequest;
366
-
367
- try {
368
- const result = await contractFunctionSimulator.run(
369
- txRequest,
370
- contractAddress,
371
- functionSelector,
372
- undefined,
373
- // The sender for tags is set by contracts, typically by an account
374
- // contract entrypoint
375
- undefined, // senderForTags
376
- scopes,
377
- );
378
- this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
379
- return result;
380
- } catch (err) {
381
- if (err instanceof SimulationError) {
382
- await enrichSimulationError(err, this.contractDataProvider, this.log);
383
- }
384
- throw err;
385
- }
386
- }
387
-
388
- /**
389
- * Simulate a utility function call on the given contract.
390
- * @param contractFunctionSimulator - The simulator to use for the function call.
391
- * @param call - The function call to execute.
392
- * @param authWitnesses - Authentication witnesses required for the function call.
393
- * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
394
- * accounts if not specified.
395
- * @returns The simulation result containing the outputs of the utility function.
396
- */
397
- async #simulateUtility(
398
- contractFunctionSimulator: ContractFunctionSimulator,
399
- call: FunctionCall,
400
- authWitnesses?: AuthWitness[],
401
- scopes?: AztecAddress[],
402
- ) {
403
- try {
404
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
405
- } catch (err) {
406
- if (err instanceof SimulationError) {
407
- await enrichSimulationError(err, this.contractDataProvider, this.log);
408
- }
409
- throw err;
410
- }
411
- }
412
-
413
- /**
414
- * Simulate the public part of a transaction.
415
- * This allows to catch public execution errors before submitting the transaction.
416
- * It can also be used for estimating gas in the future.
417
- * @param tx - The transaction to be simulated.
418
- */
419
- async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
420
- // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
421
- // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
422
- try {
423
- const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
424
- if (result.revertReason) {
425
- throw result.revertReason;
426
- }
427
- return result;
428
- } catch (err) {
429
- if (err instanceof SimulationError) {
430
- try {
431
- await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
432
- } catch (enrichErr) {
433
- this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
434
- }
435
- }
436
- throw err;
437
- }
438
- }
439
-
440
- /**
441
- * Generate a kernel proof, and create a private kernel output.
442
- * The function takes in a transaction execution request, and the result of private execution
443
- * and then generates a kernel proof.
444
- *
445
- * @param txExecutionRequest - The transaction request to be simulated and proved.
446
- * @param proofCreator - The proof creator to use for proving the execution.
447
- * @param privateExecutionResult - The result of the private execution
448
- * @param config - The configuration for the kernel execution prover.
449
- * @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled.
450
- */
451
- async #prove(
452
- txExecutionRequest: TxExecutionRequest,
453
- proofCreator: PrivateKernelProver,
454
- privateExecutionResult: PrivateExecutionResult,
455
- config: PrivateKernelExecutionProverConfig,
456
- ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
457
- const block = privateExecutionResult.getSimulationBlockNumber();
458
- const kernelOracle = new PrivateKernelOracleImpl(this.contractDataProvider, this.keyStore, this.node, block);
459
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
460
- this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
461
- return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
462
- }
463
-
464
- // Public API
465
-
466
- /** Returns an estimate of the db size in bytes. */
467
- public async estimateDbSize() {
468
- const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
469
- const dbSizes = await Promise.all([
470
- this.addressDataProvider.getSize(),
471
- this.capsuleDataProvider.getSize(),
472
- this.contractDataProvider.getSize(),
473
- this.noteDataProvider.getSize(),
474
- this.syncDataProvider.getSize(),
475
- this.taggingDataProvider.getSize(),
476
- ]);
477
- return [...dbSizes, treeRootsSize].reduce((sum, size) => sum + size, 0);
478
- }
479
-
480
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
481
- return this.contractDataProvider.getContractInstance(address);
482
- }
483
-
484
- public async getContractClassMetadata(
485
- id: Fr,
486
- includeArtifact: boolean = false,
487
- ): Promise<{
488
- contractClass: ContractClassWithId | undefined;
489
- isContractClassPubliclyRegistered: boolean;
490
- artifact: ContractArtifact | undefined;
491
- }> {
492
- const artifact = await this.contractDataProvider.getContractArtifact(id);
493
- if (!artifact) {
494
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
495
- }
496
-
497
- return {
498
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
499
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
500
- artifact: includeArtifact ? artifact : undefined,
501
- };
502
- }
503
-
504
- public async getContractMetadata(address: AztecAddress): Promise<{
505
- contractInstance: ContractInstanceWithAddress | undefined;
506
- isContractInitialized: boolean;
507
- isContractPublished: boolean;
508
- }> {
509
- let instance;
510
- try {
511
- instance = await this.contractDataProvider.getContractInstance(address);
512
- } catch {
513
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
514
- }
515
- return {
516
- contractInstance: instance,
517
- isContractInitialized: await this.#isContractInitialized(address),
518
- isContractPublished: await this.#isContractPublished(address),
519
- };
520
- }
521
-
522
- public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
523
- const accounts = await this.keyStore.getAccounts();
524
- const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
525
- if (accounts.includes(accountCompleteAddress.address)) {
526
- this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
527
- return accountCompleteAddress;
528
- } else {
529
- this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
530
- this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
531
- }
532
-
533
- await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
534
- await this.noteDataProvider.addScope(accountCompleteAddress.address);
535
- return accountCompleteAddress;
536
- }
537
-
538
- public async registerSender(address: AztecAddress): Promise<AztecAddress> {
539
- const accounts = await this.keyStore.getAccounts();
540
- if (accounts.includes(address)) {
541
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
542
- return address;
543
- }
544
-
545
- const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
546
-
547
- if (wasAdded) {
548
- this.log.info(`Added sender:\n ${address.toString()}`);
549
- } else {
550
- this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
551
- }
552
-
553
- return address;
554
- }
555
-
556
- public getSenders(): Promise<AztecAddress[]> {
557
- return this.taggingDataProvider.getSenderAddresses();
558
- }
559
-
560
- public async removeSender(address: AztecAddress): Promise<void> {
561
- const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
562
-
563
- if (wasRemoved) {
564
- this.log.info(`Removed sender:\n ${address.toString()}`);
565
- } else {
566
- this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
567
- }
568
- }
569
-
570
- public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
571
- // Get complete addresses of both the recipients and the accounts
572
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
573
- // Filter out the addresses not corresponding to accounts
574
- const accounts = await this.keyStore.getAccounts();
575
- return completeAddresses.filter(completeAddress =>
576
- accounts.find(address => address.equals(completeAddress.address)),
577
- );
578
- }
579
-
580
- public async registerContractClass(artifact: ContractArtifact): Promise<void> {
581
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
582
- await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
583
- this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
584
- }
585
-
586
- public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
587
- const { instance } = contract;
588
- let { artifact } = contract;
589
-
590
- if (artifact) {
591
- // If the user provides an artifact, validate it against the expected class id and register it
592
- const contractClass = await getContractClassFromArtifact(artifact);
593
- const contractClassId = contractClass.id;
594
- if (!contractClassId.equals(instance.currentContractClassId)) {
595
- throw new Error(
596
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
597
- );
598
- }
599
- const computedAddress = await computeContractAddressFromInstance(instance);
600
- if (!computedAddress.equals(instance.address)) {
601
- throw new Error('Added a contract in which the address does not match the contract instance.');
602
- }
603
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
604
-
605
- const publicFunctionSignatures = artifact.functions
606
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
607
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
608
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
609
- } else {
610
- // Otherwise, make sure there is an artifact already registered for that class id
611
- artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
612
- if (!artifact) {
613
- throw new Error(
614
- `Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
615
- );
616
- }
617
- }
618
-
619
- await this.contractDataProvider.addContractInstance(instance);
620
- this.log.info(
621
- `Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
622
- );
623
- }
624
-
625
- public updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
626
- // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
627
- // class while we're simulating it.
628
- return this.#putInJobQueue(async () => {
629
- const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
630
- if (!currentInstance) {
631
- throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
632
- }
633
- const contractClass = await getContractClassFromArtifact(artifact);
634
- await this.synchronizer.sync();
635
-
636
- const header = await this.syncDataProvider.getBlockHeader();
637
-
638
- const currentClassId = await readCurrentClassId(
639
- contractAddress,
640
- currentInstance,
641
- this.node,
642
- header.globalVariables.blockNumber,
643
- header.globalVariables.timestamp,
644
- );
645
- if (!contractClass.id.equals(currentClassId)) {
646
- throw new Error('Could not update contract to a class different from the current one.');
647
- }
648
-
649
- await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
650
-
651
- const publicFunctionSignatures = artifact.functions
652
- .filter(fn => fn.functionType === FunctionType.PUBLIC)
653
- .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
654
- await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
655
-
656
- currentInstance.currentContractClassId = contractClass.id;
657
- await this.contractDataProvider.addContractInstance(currentInstance);
658
- this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
659
- });
660
- }
661
-
662
- public getContracts(): Promise<AztecAddress[]> {
663
- return this.contractDataProvider.getContractsAddresses();
664
- }
665
-
666
- public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
667
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
668
- await this.simulateUtility('sync_private_state', [], filter.contractAddress);
669
-
670
- const noteDaos = await this.noteDataProvider.getNotes(filter);
671
-
672
- const extendedNotes = noteDaos.map(async dao => {
673
- let recipient = filter.recipient;
674
- if (recipient === undefined) {
675
- const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
676
- const completeAddressIndex = completeAddresses.findIndex(completeAddress =>
677
- completeAddress.address.equals(dao.recipient),
678
- );
679
- const completeAddress = completeAddresses[completeAddressIndex];
680
- if (completeAddress === undefined) {
681
- throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
682
- }
683
- recipient = completeAddress.address;
684
- }
685
- return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
686
- });
687
- return Promise.all(extendedNotes);
688
- }
689
-
690
- public async getBlock(blockNumber: number): Promise<L2Block | undefined> {
691
- // If a negative block number is provided the current block number is fetched.
692
- if (blockNumber < 0) {
693
- blockNumber = await this.node.getBlockNumber();
694
- }
695
- return await this.node.getBlock(blockNumber);
696
- }
697
-
698
- public async getCurrentBaseFees(): Promise<GasFees> {
699
- return await this.node.getCurrentBaseFees();
700
- }
701
-
702
- public proveTx(
703
- txRequest: TxExecutionRequest,
704
- privateExecutionResult?: PrivateExecutionResult,
705
- ): Promise<TxProvingResult> {
706
- // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
707
- // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
708
- return this.#putInJobQueue(async () => {
709
- const totalTimer = new Timer();
710
- try {
711
- let syncTime: number | undefined;
712
- let contractFunctionSimulator: ContractFunctionSimulator | undefined;
713
- if (!privateExecutionResult) {
714
- const syncTimer = new Timer();
715
- await this.synchronizer.sync();
716
- syncTime = syncTimer.ms();
717
- contractFunctionSimulator = this.#getSimulatorForTx();
718
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
719
- }
720
- const {
721
- publicInputs,
722
- clientIvcProof,
723
- executionSteps,
724
- timings: { proving } = {},
725
- } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
726
- simulate: false,
727
- skipFeeEnforcement: false,
728
- profileMode: 'none',
729
- });
730
-
731
- const totalTime = totalTimer.ms();
732
-
733
- const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => ({
734
- functionName,
735
- time: witgen,
736
- oracles,
737
- }));
738
-
739
- const timings: ProvingTimings = {
740
- total: totalTime,
741
- sync: syncTime,
742
- proving,
743
- perFunction,
744
- unaccounted:
745
- totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
746
- };
747
-
748
- this.log.debug(`Proving completed in ${totalTime}ms`, { timings });
749
- return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof!, {
750
- timings,
751
- nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
752
- });
753
- } catch (err: any) {
754
- throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
755
- }
756
- });
757
- }
758
-
759
- public profileTx(
760
- txRequest: TxExecutionRequest,
761
- profileMode: 'full' | 'execution-steps' | 'gates',
762
- skipProofGeneration: boolean = true,
763
- ): Promise<TxProfileResult> {
764
- // We disable concurrent profiles for consistency with simulateTx.
765
- return this.#putInJobQueue(async () => {
766
- const totalTimer = new Timer();
767
- try {
768
- const txInfo = {
769
- origin: txRequest.origin,
770
- functionSelector: txRequest.functionSelector,
771
- simulatePublic: false,
772
- chainId: txRequest.txContext.chainId,
773
- version: txRequest.txContext.version,
774
- authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
775
- };
776
- this.log.info(
777
- `Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`,
778
- txInfo,
779
- );
780
- const syncTimer = new Timer();
781
- await this.synchronizer.sync();
782
- const syncTime = syncTimer.ms();
783
-
784
- const contractFunctionSimulator = this.#getSimulatorForTx();
785
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
786
-
787
- const { executionSteps, timings: { proving } = {} } = await this.#prove(
788
- txRequest,
789
- this.proofCreator,
790
- privateExecutionResult,
791
- {
792
- simulate: skipProofGeneration,
793
- skipFeeEnforcement: false,
794
- profileMode,
795
- },
796
- );
797
-
798
- const totalTime = totalTimer.ms();
799
-
800
- const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => {
801
- return {
802
- functionName,
803
- time: witgen,
804
- oracles,
805
- };
806
- });
807
-
808
- // Gate computation is time is not relevant for profiling, so we subtract it from the total time.
809
- const gateCountComputationTime =
810
- executionSteps.reduce((acc, { timings }) => acc + (timings.gateCount ?? 0), 0) ?? 0;
811
-
812
- const total = totalTime - gateCountComputationTime;
813
-
814
- const timings: ProvingTimings = {
815
- total,
816
- sync: syncTime,
817
- proving,
818
- perFunction,
819
- unaccounted:
820
- total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time }) => acc + time, 0)),
821
- };
822
-
823
- const simulatorStats = contractFunctionSimulator.getStats();
824
- return new TxProfileResult(executionSteps, { timings, nodeRPCCalls: simulatorStats.nodeRPCCalls });
825
- } catch (err: any) {
826
- throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
827
- }
828
- });
829
- }
830
-
831
- // TODO(#7456) Prevent msgSender being defined here for the first call
832
- public simulateTx(
833
- txRequest: TxExecutionRequest,
834
- simulatePublic: boolean,
835
- skipTxValidation: boolean = false,
836
- skipFeeEnforcement: boolean = false,
837
- overrides?: SimulationOverrides,
838
- scopes?: AztecAddress[],
839
- ): Promise<TxSimulationResult> {
840
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
841
- // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
842
- // delete the same read value, or reading values that another simulation is currently modifying).
843
- return this.#putInJobQueue(async () => {
844
- try {
845
- const totalTimer = new Timer();
846
- const txInfo = {
847
- origin: txRequest.origin,
848
- functionSelector: txRequest.functionSelector,
849
- simulatePublic,
850
- chainId: txRequest.txContext.chainId,
851
- version: txRequest.txContext.version,
852
- authWitnesses: txRequest.authWitnesses.map(w => w.requestHash),
853
- };
854
- this.log.info(
855
- `Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`,
856
- txInfo,
857
- );
858
- const syncTimer = new Timer();
859
- await this.synchronizer.sync();
860
- const syncTime = syncTimer.ms();
861
-
862
- const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
863
- // Temporary: in case there are overrides, we have to skip the kernels or validations
864
- // will fail. Consider handing control to the user/wallet on whether they want to run them
865
- // or not.
866
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
867
-
868
- // Execution of private functions only; no proving, and no kernel logic.
869
- const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
870
-
871
- let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
872
- let executionSteps: PrivateExecutionStep[] = [];
873
-
874
- if (skipKernels) {
875
- // According to the protocol rules, the nonce generator for the note hashes
876
- // can either be the first nullifier in the tx or the hash of the initial tx request
877
- // if there are none.
878
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
879
- ? await txRequest.toTxRequest().hash()
880
- : privateExecutionResult.firstNullifier;
881
- ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
882
- privateExecutionResult,
883
- nonceGenerator,
884
- this.contractDataProvider,
885
- ));
886
- } else {
887
- // Kernel logic, plus proving of all private functions and kernels.
888
- ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
889
- simulate: true,
890
- skipFeeEnforcement,
891
- profileMode: 'none',
892
- }));
893
- }
894
-
895
- const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
896
- const simulatedTx = await privateSimulationResult.toSimulatedTx();
897
- let publicSimulationTime: number | undefined;
898
- let publicOutput: PublicSimulationOutput | undefined;
899
- if (simulatePublic && publicInputs.forPublic) {
900
- const publicSimulationTimer = new Timer();
901
- publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
902
- publicSimulationTime = publicSimulationTimer.ms();
903
- }
904
-
905
- let validationTime: number | undefined;
906
- if (!skipTxValidation) {
907
- const validationTimer = new Timer();
908
- const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
909
- validationTime = validationTimer.ms();
910
- if (validationResult.result === 'invalid') {
911
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
912
- }
913
- }
914
-
915
- const txHash = simulatedTx.getTxHash();
916
-
917
- const totalTime = totalTimer.ms();
918
-
919
- const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } }) => ({
920
- functionName,
921
- time: witgen,
922
- oracles,
923
- }));
924
-
925
- const timings: SimulationTimings = {
926
- total: totalTime,
927
- sync: syncTime,
928
- publicSimulation: publicSimulationTime,
929
- validation: validationTime,
930
- perFunction,
931
- unaccounted:
932
- totalTime -
933
- (syncTime +
934
- (publicSimulationTime ?? 0) +
935
- (validationTime ?? 0) +
936
- perFunction.reduce((acc, { time }) => acc + time, 0)),
937
- };
938
-
939
- this.log.info(`Simulation completed for ${txHash.toString()} in ${totalTime}ms`, {
940
- txHash,
941
- ...txInfo,
942
- ...(publicOutput
943
- ? {
944
- gasUsed: publicOutput.gasUsed,
945
- revertCode: publicOutput.txEffect.revertCode.getCode(),
946
- revertReason: publicOutput.revertReason,
947
- }
948
- : {}),
949
- });
950
-
951
- const simulatorStats = contractFunctionSimulator.getStats();
952
- return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
953
- timings,
954
- nodeRPCCalls: simulatorStats.nodeRPCCalls,
955
- });
956
- } catch (err: any) {
957
- throw this.#contextualizeError(
958
- err,
959
- inspect(txRequest),
960
- `simulatePublic=${simulatePublic}`,
961
- `skipTxValidation=${skipTxValidation}`,
962
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
963
- );
964
- }
965
- });
966
- }
967
-
968
- public async sendTx(tx: Tx): Promise<TxHash> {
969
- const txHash = tx.getTxHash();
970
- if (await this.node.getTxEffect(txHash)) {
971
- throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
972
- }
973
- this.log.debug(`Sending transaction ${txHash}`);
974
- await this.node.sendTx(tx).catch(err => {
975
- throw this.#contextualizeError(err, inspect(tx));
976
- });
977
- this.log.info(`Sent transaction ${txHash}`);
978
- return txHash;
979
- }
980
-
981
- public simulateUtility(
982
- functionName: string,
983
- args: any[],
984
- to: AztecAddress,
985
- authwits?: AuthWitness[],
986
- _from?: AztecAddress,
987
- scopes?: AztecAddress[],
988
- ): Promise<UtilitySimulationResult> {
989
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
990
- // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
991
- // delete the same read value, or reading values that another simulation is currently modifying).
992
- return this.#putInJobQueue(async () => {
993
- try {
994
- const totalTimer = new Timer();
995
- const syncTimer = new Timer();
996
- await this.synchronizer.sync();
997
- const syncTime = syncTimer.ms();
998
- // TODO - Should check if `from` has the permission to call the view function.
999
- const functionCall = await this.#getFunctionCall(functionName, args, to);
1000
- const functionTimer = new Timer();
1001
- const contractFunctionSimulator = this.#getSimulatorForTx();
1002
- const executionResult = await this.#simulateUtility(
1003
- contractFunctionSimulator,
1004
- functionCall,
1005
- authwits ?? [],
1006
- scopes,
1007
- );
1008
- const functionTime = functionTimer.ms();
1009
-
1010
- const totalTime = totalTimer.ms();
1011
-
1012
- const perFunction = [{ functionName, time: functionTime }];
1013
-
1014
- const timings: SimulationTimings = {
1015
- total: totalTime,
1016
- sync: syncTime,
1017
- perFunction,
1018
- unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time }) => acc + time, 0)),
1019
- };
1020
-
1021
- const simulationStats = contractFunctionSimulator.getStats();
1022
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1023
- } catch (err: any) {
1024
- const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1025
- throw this.#contextualizeError(
1026
- err,
1027
- `simulateUtility ${to}:${functionName}(${stringifiedArgs})`,
1028
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1029
- );
1030
- }
1031
- });
1032
- }
1033
-
1034
- public async getNodeInfo(): Promise<NodeInfo> {
1035
- // This assumes we're connected to a single node, so we cache the info to avoid repeated calls.
1036
- // Load balancers and a myriad other configurations can break this assumption, so review this!
1037
- // Temporary measure to avoid hammering full nodes with requests on testnet.
1038
- if (!this.#nodeInfo) {
1039
- const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] =
1040
- await Promise.all([
1041
- this.node.getNodeVersion(),
1042
- this.node.getVersion(),
1043
- this.node.getChainId(),
1044
- this.node.getEncodedEnr(),
1045
- this.node.getL1ContractAddresses(),
1046
- this.node.getProtocolContractAddresses(),
1047
- ]);
1048
-
1049
- this.#nodeInfo = {
1050
- nodeVersion,
1051
- l1ChainId: chainId,
1052
- rollupVersion,
1053
- enr,
1054
- l1ContractAddresses: contractAddresses,
1055
- protocolContractAddresses: protocolContractAddresses,
1056
- };
1057
- }
1058
-
1059
- return this.#nodeInfo;
1060
- }
1061
-
1062
- public getPXEInfo(): Promise<PXEInfo> {
1063
- return Promise.resolve({
1064
- pxeVersion: this.packageVersion,
1065
- protocolContractAddresses: {
1066
- classRegistry: ProtocolContractAddress.ContractClassRegistry,
1067
- feeJuice: ProtocolContractAddress.FeeJuice,
1068
- instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
1069
- multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint,
1070
- },
1071
- });
1072
- }
1073
-
1074
- public async getPrivateEvents<T>(
1075
- contractAddress: AztecAddress,
1076
- eventMetadataDef: EventMetadataDefinition,
1077
- from: number,
1078
- numBlocks: number,
1079
- recipients: AztecAddress[],
1080
- ): Promise<T[]> {
1081
- if (recipients.length === 0) {
1082
- throw new Error('Recipients are required to get private events');
1083
- }
1084
-
1085
- this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
1086
-
1087
- // We need to manually trigger private state sync to have a guarantee that all the events are available.
1088
- await this.simulateUtility('sync_private_state', [], contractAddress);
1089
-
1090
- const events = await this.privateEventDataProvider.getPrivateEvents(
1091
- contractAddress,
1092
- from,
1093
- numBlocks,
1094
- recipients,
1095
- eventMetadataDef.eventSelector,
1096
- );
1097
-
1098
- const decodedEvents = events.map((event: Fr[]): T => decodeFromAbi([eventMetadataDef.abiType], event) as T);
1099
-
1100
- return decodedEvents;
1101
- }
1102
-
1103
- async getPublicEvents<T>(eventMetadataDef: EventMetadataDefinition, from: number, limit: number): Promise<T[]> {
1104
- const { logs } = await this.node.getPublicLogs({
1105
- fromBlock: from,
1106
- toBlock: from + limit,
1107
- });
1108
-
1109
- const decodedEvents = logs
1110
- .map(log => {
1111
- // +1 for the event selector
1112
- const expectedLength = eventMetadataDef.fieldNames.length + 1;
1113
- if (log.log.emittedLength !== expectedLength) {
1114
- throw new Error(
1115
- `Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.emittedLength}.`,
1116
- );
1117
- }
1118
-
1119
- const logFields = log.log.getEmittedFields();
1120
- // We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission.
1121
- if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) {
1122
- return undefined;
1123
- }
1124
-
1125
- return decodeFromAbi([eventMetadataDef.abiType], log.log.fields) as T;
1126
- })
1127
- .filter(log => log !== undefined) as T[];
1128
-
1129
- return decodedEvents;
1130
- }
1131
-
1132
- async resetNoteSyncData() {
1133
- return await this.taggingDataProvider.resetNoteSyncData();
1134
- }
1135
-
1136
- public stop(): Promise<void> {
1137
- return this.jobQueue.end();
1138
- }
1139
- }