@aztec/pxe 0.0.0-test.1 → 0.0.1-commit.5476d83

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 (328) 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 +39 -0
  5. package/dest/config/index.d.ts +11 -24
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +18 -33
  8. package/dest/config/package_info.d.ts +1 -1
  9. package/dest/config/package_info.js +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts +56 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  12. package/dest/contract_function_simulator/contract_function_simulator.js +300 -0
  13. package/dest/contract_function_simulator/execution_data_provider.d.ts +265 -0
  14. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
  15. package/dest/contract_function_simulator/execution_data_provider.js +14 -0
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts +94 -0
  17. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  18. package/dest/contract_function_simulator/execution_note_cache.js +190 -0
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  20. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  22. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  23. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  25. package/dest/contract_function_simulator/index.d.ts +14 -0
  26. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  27. package/dest/contract_function_simulator/index.js +12 -0
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  30. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +15 -0
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +25 -0
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  36. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +23 -0
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +48 -0
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  41. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  43. package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
  44. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  45. package/dest/contract_function_simulator/oracle/index.js +2 -0
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts +100 -0
  47. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  48. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +17 -0
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  51. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +24 -0
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  54. package/dest/contract_function_simulator/oracle/note_packing_utils.js +50 -0
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts +58 -0
  56. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  57. package/dest/contract_function_simulator/oracle/oracle.js +333 -0
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts +48 -0
  59. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  60. package/dest/contract_function_simulator/oracle/private_execution.js +123 -0
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +231 -0
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  63. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +428 -0
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +153 -0
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  66. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +265 -0
  67. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  68. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  69. package/dest/contract_function_simulator/pick_notes.js +51 -0
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
  71. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
  72. package/dest/contract_function_simulator/proxied_contract_data_source.js +62 -0
  73. package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
  74. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
  75. package/dest/contract_function_simulator/proxied_node.js +27 -0
  76. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +122 -0
  77. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
  78. package/dest/contract_function_simulator/pxe_oracle_interface.js +694 -0
  79. package/dest/entrypoints/client/bundle/index.d.ts +5 -3
  80. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  81. package/dest/entrypoints/client/bundle/index.js +3 -2
  82. package/dest/entrypoints/client/bundle/utils.d.ts +10 -10
  83. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  84. package/dest/entrypoints/client/bundle/utils.js +18 -12
  85. package/dest/entrypoints/client/lazy/index.d.ts +5 -3
  86. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  87. package/dest/entrypoints/client/lazy/index.js +3 -2
  88. package/dest/entrypoints/client/lazy/utils.d.ts +9 -9
  89. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  90. package/dest/entrypoints/client/lazy/utils.js +17 -11
  91. package/dest/entrypoints/pxe_creation_options.d.ts +14 -0
  92. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  93. package/dest/entrypoints/server/index.d.ts +6 -4
  94. package/dest/entrypoints/server/index.d.ts.map +1 -1
  95. package/dest/entrypoints/server/index.js +4 -3
  96. package/dest/entrypoints/server/utils.d.ts +8 -16
  97. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  98. package/dest/entrypoints/server/utils.js +30 -35
  99. package/dest/error_enriching.d.ts +11 -0
  100. package/dest/error_enriching.d.ts.map +1 -0
  101. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +26 -18
  102. package/dest/oracle_version.d.ts +3 -0
  103. package/dest/oracle_version.d.ts.map +1 -0
  104. package/dest/oracle_version.js +10 -0
  105. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +28 -0
  106. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
  107. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
  108. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.d.ts +3 -0
  109. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.d.ts.map +1 -0
  110. package/dest/private_kernel/hints/compute_side_effect_uniqueness_hints.js +48 -0
  111. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  112. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  113. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  114. package/dest/private_kernel/hints/index.d.ts +3 -0
  115. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  116. package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
  117. package/dest/private_kernel/index.d.ts +3 -0
  118. package/dest/private_kernel/index.d.ts.map +1 -0
  119. package/dest/private_kernel/index.js +2 -0
  120. package/dest/private_kernel/private_kernel_execution_prover.d.ts +44 -0
  121. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  122. package/dest/private_kernel/private_kernel_execution_prover.js +289 -0
  123. package/dest/private_kernel/private_kernel_oracle.d.ts +62 -0
  124. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  125. package/dest/private_kernel/private_kernel_oracle.js +4 -0
  126. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +45 -0
  127. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
  128. package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
  129. package/dest/pxe.d.ts +240 -0
  130. package/dest/pxe.d.ts.map +1 -0
  131. package/dest/pxe.js +771 -0
  132. package/dest/storage/address_data_provider/address_data_provider.d.ts +2 -4
  133. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  134. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  135. package/dest/storage/address_data_provider/index.d.ts +1 -1
  136. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +15 -6
  137. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  138. package/dest/storage/capsule_data_provider/capsule_data_provider.js +85 -24
  139. package/dest/storage/capsule_data_provider/index.d.ts +1 -1
  140. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +13 -58
  141. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  142. package/dest/storage/contract_data_provider/contract_data_provider.js +89 -79
  143. package/dest/storage/contract_data_provider/index.d.ts +1 -2
  144. package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
  145. package/dest/storage/contract_data_provider/index.js +0 -1
  146. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +3 -42
  147. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  148. package/dest/storage/contract_data_provider/private_functions_tree.js +9 -61
  149. package/dest/storage/index.d.ts +3 -4
  150. package/dest/storage/index.d.ts.map +1 -1
  151. package/dest/storage/index.js +2 -3
  152. package/dest/storage/metadata.d.ts +2 -0
  153. package/dest/storage/metadata.d.ts.map +1 -0
  154. package/dest/storage/metadata.js +1 -0
  155. package/dest/storage/note_data_provider/index.d.ts +2 -2
  156. package/dest/storage/note_data_provider/index.d.ts.map +1 -1
  157. package/dest/storage/note_data_provider/index.js +1 -1
  158. package/dest/storage/note_data_provider/note_data_provider.d.ts +73 -10
  159. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  160. package/dest/storage/note_data_provider/note_data_provider.js +145 -83
  161. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +37 -0
  162. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
  163. package/dest/storage/private_event_data_provider/private_event_data_provider.js +105 -0
  164. package/dest/storage/sync_data_provider/index.d.ts +1 -1
  165. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +3 -5
  166. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  167. package/dest/storage/sync_data_provider/sync_data_provider.js +2 -5
  168. package/dest/storage/tagging_data_provider/index.d.ts +1 -1
  169. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +29 -7
  170. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  171. package/dest/storage/tagging_data_provider/tagging_data_provider.js +48 -24
  172. package/dest/synchronizer/index.d.ts +1 -1
  173. package/dest/synchronizer/synchronizer.d.ts +8 -10
  174. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  175. package/dest/synchronizer/synchronizer.js +17 -19
  176. package/dest/tagging/constants.d.ts +2 -0
  177. package/dest/tagging/constants.d.ts.map +1 -0
  178. package/dest/tagging/constants.js +2 -0
  179. package/dest/tagging/index.d.ts +7 -0
  180. package/dest/tagging/index.d.ts.map +1 -0
  181. package/dest/tagging/index.js +5 -0
  182. package/dest/tagging/siloed_tag.d.ts +14 -0
  183. package/dest/tagging/siloed_tag.d.ts.map +1 -0
  184. package/dest/tagging/siloed_tag.js +20 -0
  185. package/dest/tagging/tag.d.ts +12 -0
  186. package/dest/tagging/tag.d.ts.map +1 -0
  187. package/dest/tagging/tag.js +17 -0
  188. package/dest/tagging/utils.d.ts +18 -0
  189. package/dest/tagging/utils.d.ts.map +1 -0
  190. package/dest/tagging/utils.js +24 -0
  191. package/package.json +37 -34
  192. package/src/bin/check_oracle_version.ts +50 -0
  193. package/src/config/index.ts +27 -55
  194. package/src/config/package_info.ts +1 -1
  195. package/src/contract_function_simulator/contract_function_simulator.ts +553 -0
  196. package/src/contract_function_simulator/execution_data_provider.ts +333 -0
  197. package/src/contract_function_simulator/execution_note_cache.ts +229 -0
  198. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  199. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  200. package/src/contract_function_simulator/index.ts +13 -0
  201. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
  202. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -0
  203. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
  204. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +61 -0
  205. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  206. package/src/contract_function_simulator/oracle/index.ts +16 -0
  207. package/src/contract_function_simulator/oracle/interfaces.ts +170 -0
  208. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  209. package/src/contract_function_simulator/oracle/note_packing_utils.ts +54 -0
  210. package/src/contract_function_simulator/oracle/oracle.ts +583 -0
  211. package/src/contract_function_simulator/oracle/private_execution.ts +207 -0
  212. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +633 -0
  213. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +358 -0
  214. package/src/contract_function_simulator/pick_notes.ts +141 -0
  215. package/src/contract_function_simulator/proxied_contract_data_source.ts +66 -0
  216. package/src/contract_function_simulator/proxied_node.ts +33 -0
  217. package/src/contract_function_simulator/pxe_oracle_interface.ts +1008 -0
  218. package/src/entrypoints/client/bundle/index.ts +4 -2
  219. package/src/entrypoints/client/bundle/utils.ts +36 -36
  220. package/src/entrypoints/client/lazy/index.ts +4 -2
  221. package/src/entrypoints/client/lazy/utils.ts +36 -31
  222. package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
  223. package/src/entrypoints/server/index.ts +5 -3
  224. package/src/entrypoints/server/utils.ts +58 -50
  225. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +36 -27
  226. package/src/oracle_version.ts +11 -0
  227. package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +158 -146
  228. package/src/private_kernel/hints/compute_side_effect_uniqueness_hints.ts +173 -0
  229. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  230. package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
  231. package/src/private_kernel/index.ts +2 -0
  232. package/src/private_kernel/private_kernel_execution_prover.ts +436 -0
  233. package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +17 -29
  234. package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +30 -15
  235. package/src/pxe.ts +1085 -0
  236. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  237. package/src/storage/capsule_data_provider/capsule_data_provider.ts +97 -30
  238. package/src/storage/contract_data_provider/contract_data_provider.ts +109 -93
  239. package/src/storage/contract_data_provider/index.ts +0 -1
  240. package/src/storage/contract_data_provider/private_functions_tree.ts +11 -75
  241. package/src/storage/index.ts +2 -4
  242. package/src/storage/metadata.ts +1 -0
  243. package/src/storage/note_data_provider/index.ts +1 -1
  244. package/src/storage/note_data_provider/note_data_provider.ts +176 -122
  245. package/src/storage/private_event_data_provider/private_event_data_provider.ts +143 -0
  246. package/src/storage/sync_data_provider/sync_data_provider.ts +4 -10
  247. package/src/storage/tagging_data_provider/tagging_data_provider.ts +58 -30
  248. package/src/synchronizer/synchronizer.ts +21 -22
  249. package/src/tagging/constants.ts +2 -0
  250. package/src/tagging/index.ts +6 -0
  251. package/src/tagging/siloed_tag.ts +22 -0
  252. package/src/tagging/tag.ts +16 -0
  253. package/src/tagging/utils.ts +31 -0
  254. package/dest/bin/index.d.ts +0 -3
  255. package/dest/bin/index.d.ts.map +0 -1
  256. package/dest/bin/index.js +0 -28
  257. package/dest/entrypoints/client/pxe_creation_options.d.ts +0 -11
  258. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  259. package/dest/kernel_oracle/index.d.ts +0 -45
  260. package/dest/kernel_oracle/index.d.ts.map +0 -1
  261. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  262. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  263. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
  264. package/dest/kernel_prover/hints/index.d.ts +0 -2
  265. package/dest/kernel_prover/hints/index.d.ts.map +0 -1
  266. package/dest/kernel_prover/index.d.ts +0 -3
  267. package/dest/kernel_prover/index.d.ts.map +0 -1
  268. package/dest/kernel_prover/index.js +0 -2
  269. package/dest/kernel_prover/kernel_prover.d.ts +0 -38
  270. package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
  271. package/dest/kernel_prover/kernel_prover.js +0 -217
  272. package/dest/kernel_prover/proving_data_oracle.d.ts +0 -73
  273. package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
  274. package/dest/kernel_prover/proving_data_oracle.js +0 -4
  275. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
  276. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
  277. package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
  278. package/dest/pxe_http/index.d.ts +0 -2
  279. package/dest/pxe_http/index.d.ts.map +0 -1
  280. package/dest/pxe_http/index.js +0 -1
  281. package/dest/pxe_http/pxe_http_server.d.ts +0 -16
  282. package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
  283. package/dest/pxe_http/pxe_http_server.js +0 -27
  284. package/dest/pxe_oracle_interface/index.d.ts +0 -159
  285. package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
  286. package/dest/pxe_oracle_interface/index.js +0 -692
  287. package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
  288. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  289. package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
  290. package/dest/pxe_service/error_enriching.d.ts +0 -11
  291. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  292. package/dest/pxe_service/index.d.ts +0 -3
  293. package/dest/pxe_service/index.d.ts.map +0 -1
  294. package/dest/pxe_service/index.js +0 -2
  295. package/dest/pxe_service/pxe_service.d.ts +0 -111
  296. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  297. package/dest/pxe_service/pxe_service.js +0 -664
  298. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
  299. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
  300. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
  301. package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
  302. package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
  303. package/dest/storage/auth_witness_data_provider/index.js +0 -1
  304. package/dest/storage/data_provider.d.ts +0 -4
  305. package/dest/storage/data_provider.d.ts.map +0 -1
  306. package/dest/storage/data_provider.js +0 -1
  307. package/dest/storage/note_data_provider/note_dao.d.ts +0 -106
  308. package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
  309. package/dest/storage/note_data_provider/note_dao.js +0 -106
  310. package/dest/test/pxe_test_suite.d.ts +0 -3
  311. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  312. package/dest/test/pxe_test_suite.js +0 -97
  313. package/src/bin/index.ts +0 -38
  314. package/src/kernel_prover/index.ts +0 -2
  315. package/src/kernel_prover/kernel_prover.ts +0 -351
  316. package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
  317. package/src/pxe_http/index.ts +0 -1
  318. package/src/pxe_http/pxe_http_server.ts +0 -29
  319. package/src/pxe_oracle_interface/index.ts +0 -925
  320. package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
  321. package/src/pxe_service/index.ts +0 -2
  322. package/src/pxe_service/pxe_service.ts +0 -949
  323. package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
  324. package/src/storage/auth_witness_data_provider/index.ts +0 -1
  325. package/src/storage/data_provider.ts +0 -3
  326. package/src/storage/note_data_provider/note_dao.ts +0 -162
  327. package/src/test/pxe_test_suite.ts +0 -111
  328. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
package/dest/pxe.js ADDED
@@ -0,0 +1,771 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { SerialQueue } from '@aztec/foundation/queue';
4
+ import { Timer } from '@aztec/foundation/timer';
5
+ import { KeyStore } from '@aztec/key-store';
6
+ import { L2TipsKVStore } from '@aztec/kv-store/stores';
7
+ import { protocolContractNames } from '@aztec/protocol-contracts';
8
+ import { FunctionSelector, FunctionType, decodeFunctionSignature, encodeArguments } from '@aztec/stdlib/abi';
9
+ import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
10
+ import { SimulationError } from '@aztec/stdlib/errors';
11
+ import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
12
+ import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
13
+ import { inspect } from 'util';
14
+ import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
15
+ import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
16
+ import { ProxiedContractDataProviderFactory } from './contract_function_simulator/proxied_contract_data_source.js';
17
+ import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
18
+ import { PXEOracleInterface } from './contract_function_simulator/pxe_oracle_interface.js';
19
+ import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
20
+ import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
21
+ import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
22
+ import { AddressDataProvider } from './storage/address_data_provider/address_data_provider.js';
23
+ import { CapsuleDataProvider } from './storage/capsule_data_provider/capsule_data_provider.js';
24
+ import { ContractDataProvider } from './storage/contract_data_provider/contract_data_provider.js';
25
+ import { NoteDataProvider } from './storage/note_data_provider/note_data_provider.js';
26
+ import { PrivateEventDataProvider } from './storage/private_event_data_provider/private_event_data_provider.js';
27
+ import { SyncDataProvider } from './storage/sync_data_provider/sync_data_provider.js';
28
+ import { TaggingDataProvider } from './storage/tagging_data_provider/tagging_data_provider.js';
29
+ import { Synchronizer } from './synchronizer/index.js';
30
+ /**
31
+ * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
32
+ * manage private state of users.
33
+ */ export class PXE {
34
+ node;
35
+ synchronizer;
36
+ keyStore;
37
+ contractDataProvider;
38
+ noteDataProvider;
39
+ capsuleDataProvider;
40
+ syncDataProvider;
41
+ taggingDataProvider;
42
+ addressDataProvider;
43
+ privateEventDataProvider;
44
+ simulator;
45
+ proverEnabled;
46
+ proofCreator;
47
+ protocolContractsProvider;
48
+ log;
49
+ jobQueue;
50
+ constructor(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue){
51
+ this.node = node;
52
+ this.synchronizer = synchronizer;
53
+ this.keyStore = keyStore;
54
+ this.contractDataProvider = contractDataProvider;
55
+ this.noteDataProvider = noteDataProvider;
56
+ this.capsuleDataProvider = capsuleDataProvider;
57
+ this.syncDataProvider = syncDataProvider;
58
+ this.taggingDataProvider = taggingDataProvider;
59
+ this.addressDataProvider = addressDataProvider;
60
+ this.privateEventDataProvider = privateEventDataProvider;
61
+ this.simulator = simulator;
62
+ this.proverEnabled = proverEnabled;
63
+ this.proofCreator = proofCreator;
64
+ this.protocolContractsProvider = protocolContractsProvider;
65
+ this.log = log;
66
+ this.jobQueue = jobQueue;
67
+ }
68
+ /**
69
+ * Creates an instance of a PXE by instantiating all the necessary data providers and services.
70
+ * Also triggers the registration of the protocol contracts and makes sure the provided node
71
+ * can be contacted.
72
+ *
73
+ * @returns A promise that resolves PXE is ready to be used.
74
+ */ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
75
+ const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
76
+ const proverEnabled = !!config.proverEnabled;
77
+ const addressDataProvider = new AddressDataProvider(store);
78
+ const privateEventDataProvider = new PrivateEventDataProvider(store);
79
+ const contractDataProvider = new ContractDataProvider(store);
80
+ const noteDataProvider = await NoteDataProvider.create(store);
81
+ const syncDataProvider = new SyncDataProvider(store);
82
+ const taggingDataProvider = new TaggingDataProvider(store);
83
+ const capsuleDataProvider = new CapsuleDataProvider(store);
84
+ const keyStore = new KeyStore(store);
85
+ const tipsStore = new L2TipsKVStore(store, 'pxe');
86
+ const synchronizer = new Synchronizer(node, syncDataProvider, noteDataProvider, taggingDataProvider, tipsStore, config, loggerOrSuffix);
87
+ const jobQueue = new SerialQueue();
88
+ const pxe = new PXE(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue);
89
+ pxe.jobQueue.start();
90
+ await pxe.#registerProtocolContracts();
91
+ const info = await node.getNodeInfo();
92
+ log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
93
+ return pxe;
94
+ }
95
+ // Internal methods
96
+ #getSimulatorForTx(overrides) {
97
+ const pxeOracleInterface = new PXEOracleInterface(ProxiedNodeFactory.create(this.node), this.keyStore, ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts), this.noteDataProvider, this.capsuleDataProvider, this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, this.privateEventDataProvider, this.log);
98
+ return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
99
+ }
100
+ #contextualizeError(err, ...context) {
101
+ let contextStr = '';
102
+ if (context.length > 0) {
103
+ contextStr = `\nContext:\n${context.join('\n')}`;
104
+ }
105
+ if (err instanceof SimulationError) {
106
+ err.setAztecContext(contextStr);
107
+ } else {
108
+ this.log.error(err.name, err);
109
+ this.log.debug(contextStr);
110
+ }
111
+ return err;
112
+ }
113
+ /**
114
+ * Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is
115
+ * complete.
116
+ *
117
+ * Useful for tasks that cannot run concurrently, such as contract function simulation.
118
+ */ #putInJobQueue(fn) {
119
+ // TODO(#12636): relax the conditions under which we forbid concurrency.
120
+ if (this.jobQueue.length() != 0) {
121
+ this.log.warn(`PXE is already processing ${this.jobQueue.length()} jobs, concurrent execution is not supported. Will run once those are complete.`);
122
+ }
123
+ return this.jobQueue.put(fn);
124
+ }
125
+ async #registerProtocolContracts() {
126
+ const registered = {};
127
+ for (const name of protocolContractNames){
128
+ const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
129
+ await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
130
+ await this.contractDataProvider.addContractInstance(instance);
131
+ registered[name] = address.toString();
132
+ }
133
+ this.log.verbose(`Registered protocol contracts in pxe`, registered);
134
+ }
135
+ async #isContractClassPubliclyRegistered(id) {
136
+ return !!await this.node.getContractClass(id);
137
+ }
138
+ async #isContractPublished(address) {
139
+ return !!await this.node.getContract(address);
140
+ }
141
+ async #isContractInitialized(address) {
142
+ const initNullifier = await siloNullifier(address, address.toField());
143
+ return !!await this.node.getNullifierMembershipWitness('latest', initNullifier);
144
+ }
145
+ async #getFunctionCall(functionName, args, to) {
146
+ const contract = await this.contractDataProvider.getContract(to);
147
+ if (!contract) {
148
+ throw new Error(`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`);
149
+ }
150
+ const functionDao = contract.functions.find((f)=>f.name === functionName);
151
+ if (!functionDao) {
152
+ throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
153
+ }
154
+ return {
155
+ name: functionDao.name,
156
+ args: encodeArguments(functionDao, args),
157
+ selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
158
+ type: functionDao.functionType,
159
+ to,
160
+ hideMsgSender: false,
161
+ isStatic: functionDao.isStatic,
162
+ returnTypes: functionDao.returnTypes
163
+ };
164
+ }
165
+ // Executes the entrypoint private function, as well as all nested private
166
+ // functions that might arise.
167
+ async #executePrivate(contractFunctionSimulator, txRequest, scopes) {
168
+ const { origin: contractAddress, functionSelector } = txRequest;
169
+ try {
170
+ const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, // The sender for tags is set by contracts, typically by an account
171
+ // contract entrypoint
172
+ undefined, scopes);
173
+ this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
174
+ return result;
175
+ } catch (err) {
176
+ if (err instanceof SimulationError) {
177
+ await enrichSimulationError(err, this.contractDataProvider, this.log);
178
+ }
179
+ throw err;
180
+ }
181
+ }
182
+ /**
183
+ * Simulate a utility function call on the given contract.
184
+ * @param contractFunctionSimulator - The simulator to use for the function call.
185
+ * @param call - The function call to execute.
186
+ * @param authWitnesses - Authentication witnesses required for the function call.
187
+ * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
188
+ * accounts if not specified.
189
+ * @returns The simulation result containing the outputs of the utility function.
190
+ */ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes) {
191
+ try {
192
+ return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
193
+ } catch (err) {
194
+ if (err instanceof SimulationError) {
195
+ await enrichSimulationError(err, this.contractDataProvider, this.log);
196
+ }
197
+ throw err;
198
+ }
199
+ }
200
+ /**
201
+ * Simulate the public part of a transaction.
202
+ * This allows to catch public execution errors before submitting the transaction.
203
+ * It can also be used for estimating gas in the future.
204
+ * @param tx - The transaction to be simulated.
205
+ */ async #simulatePublicCalls(tx, skipFeeEnforcement) {
206
+ // Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
207
+ // Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
208
+ try {
209
+ const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
210
+ if (result.revertReason) {
211
+ throw result.revertReason;
212
+ }
213
+ return result;
214
+ } catch (err) {
215
+ if (err instanceof SimulationError) {
216
+ try {
217
+ await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
218
+ } catch (enrichErr) {
219
+ this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
220
+ }
221
+ }
222
+ throw err;
223
+ }
224
+ }
225
+ /**
226
+ * Generate a kernel proof, and create a private kernel output.
227
+ * The function takes in a transaction execution request, and the result of private execution
228
+ * and then generates a kernel proof.
229
+ *
230
+ * @param txExecutionRequest - The transaction request to be simulated and proved.
231
+ * @param proofCreator - The proof creator to use for proving the execution.
232
+ * @param privateExecutionResult - The result of the private execution
233
+ * @param config - The configuration for the kernel execution prover.
234
+ * @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
235
+ */ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
236
+ const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
237
+ const kernelOracle = new PrivateKernelOracleImpl(this.contractDataProvider, this.keyStore, this.node, simulationAnchorBlock);
238
+ const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
239
+ this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
240
+ return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
241
+ }
242
+ // Public API
243
+ getContractInstance(address) {
244
+ return this.contractDataProvider.getContractInstance(address);
245
+ }
246
+ /**
247
+ * Returns the contract class metadata given a contract class id.
248
+ * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
249
+ * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
250
+ * @param id - Identifier of the class.
251
+ * @param includeArtifact - Identifier of the class.
252
+ * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
253
+ * for `includeArtifact`
254
+ * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
255
+ * should the pxe query the node for contract public info, and merge it with its own definitions?
256
+ * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
257
+ * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
258
+ * do for the time being.
259
+ */ async getContractClassMetadata(id, includeArtifact = false) {
260
+ const artifact = await this.contractDataProvider.getContractArtifact(id);
261
+ if (!artifact) {
262
+ this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
263
+ }
264
+ return {
265
+ contractClass: artifact && await getContractClassFromArtifact(artifact),
266
+ isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
267
+ artifact: includeArtifact ? artifact : undefined
268
+ };
269
+ }
270
+ /**
271
+ * Returns the contract metadata given an address.
272
+ * The metadata consists of its contract instance, which includes the contract class identifier,
273
+ * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
274
+ * and whether the contract instance with the given address has been publicly deployed.
275
+ * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
276
+ * This query is not dependent on the PXE.
277
+ * @param address - The address that the contract instance resides at.
278
+ * @returns - It returns the contract metadata
279
+ * TODO(@spalladino): Should we return the public keys in plain as well here?
280
+ */ async getContractMetadata(address) {
281
+ let instance;
282
+ try {
283
+ instance = await this.contractDataProvider.getContractInstance(address);
284
+ } catch {
285
+ this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
286
+ }
287
+ return {
288
+ contractInstance: instance,
289
+ isContractInitialized: await this.#isContractInitialized(address),
290
+ isContractPublished: await this.#isContractPublished(address)
291
+ };
292
+ }
293
+ /**
294
+ * Registers a user account in PXE given its master encryption private key.
295
+ * Once a new account is registered, the PXE will trial-decrypt all published notes on
296
+ * the chain and store those that correspond to the registered account. Will do nothing if the
297
+ * account is already registered.
298
+ *
299
+ * @param secretKey - Secret key of the corresponding user master public key.
300
+ * @param partialAddress - The partial address of the account contract corresponding to the account being registered.
301
+ * @returns The complete address of the account.
302
+ */ async registerAccount(secretKey, partialAddress) {
303
+ const accounts = await this.keyStore.getAccounts();
304
+ const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
305
+ if (accounts.includes(accountCompleteAddress.address)) {
306
+ this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
307
+ return accountCompleteAddress;
308
+ } else {
309
+ this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
310
+ this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
311
+ }
312
+ await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
313
+ await this.noteDataProvider.addScope(accountCompleteAddress.address);
314
+ return accountCompleteAddress;
315
+ }
316
+ /**
317
+ * Registers a user contact in PXE.
318
+ *
319
+ * Once a new contact is registered, the PXE will be able to receive notes tagged from this contact.
320
+ * Will do nothing if the account is already registered.
321
+ *
322
+ * @param address - Address of the user to add to the address book
323
+ * @returns The address address of the account.
324
+ */ async registerSender(address) {
325
+ const accounts = await this.keyStore.getAccounts();
326
+ if (accounts.includes(address)) {
327
+ this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
328
+ return address;
329
+ }
330
+ const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
331
+ if (wasAdded) {
332
+ this.log.info(`Added sender:\n ${address.toString()}`);
333
+ } else {
334
+ this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
335
+ }
336
+ return address;
337
+ }
338
+ /**
339
+ * Retrieves the addresses stored as senders on this PXE.
340
+ * @returns An array of the senders on this PXE.
341
+ */ getSenders() {
342
+ return this.taggingDataProvider.getSenderAddresses();
343
+ }
344
+ /**
345
+ * Removes a sender in the address book.
346
+ */ async removeSender(address) {
347
+ const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
348
+ if (wasRemoved) {
349
+ this.log.info(`Removed sender:\n ${address.toString()}`);
350
+ } else {
351
+ this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
352
+ }
353
+ }
354
+ /**
355
+ * Retrieves the user accounts registered on this PXE.
356
+ * @returns An array of the accounts registered on this PXE.
357
+ */ async getRegisteredAccounts() {
358
+ // Get complete addresses of both the recipients and the accounts
359
+ const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
360
+ // Filter out the addresses not corresponding to accounts
361
+ const accounts = await this.keyStore.getAccounts();
362
+ return completeAddresses.filter((completeAddress)=>accounts.find((address)=>address.equals(completeAddress.address)));
363
+ }
364
+ /**
365
+ * Registers a contract class in the PXE without registering any associated contract instance with it.
366
+ *
367
+ * @param artifact - The build artifact for the contract class.
368
+ */ async registerContractClass(artifact) {
369
+ const { id: contractClassId } = await getContractClassFromArtifact(artifact);
370
+ await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
371
+ this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
372
+ }
373
+ /**
374
+ * Adds deployed contracts to the PXE. Deployed contract information is used to access the
375
+ * contract code when simulating local transactions. This is automatically called by aztec.js when
376
+ * deploying a contract. Dapps that wish to interact with contracts already deployed should register
377
+ * these contracts in their users' PXE through this method.
378
+ *
379
+ * @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
380
+ */ async registerContract(contract) {
381
+ const { instance } = contract;
382
+ let { artifact } = contract;
383
+ if (artifact) {
384
+ // If the user provides an artifact, validate it against the expected class id and register it
385
+ const contractClass = await getContractClassFromArtifact(artifact);
386
+ const contractClassId = contractClass.id;
387
+ if (!contractClassId.equals(instance.currentContractClassId)) {
388
+ throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
389
+ }
390
+ const computedAddress = await computeContractAddressFromInstance(instance);
391
+ if (!computedAddress.equals(instance.address)) {
392
+ throw new Error('Added a contract in which the address does not match the contract instance.');
393
+ }
394
+ await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
395
+ const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
396
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
397
+ } else {
398
+ // Otherwise, make sure there is an artifact already registered for that class id
399
+ artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
400
+ if (!artifact) {
401
+ throw new Error(`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`);
402
+ }
403
+ }
404
+ await this.contractDataProvider.addContractInstance(instance);
405
+ this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`);
406
+ }
407
+ /**
408
+ * Updates a deployed contract in the PXE. This is used to update the contract artifact when
409
+ * an update has happened, so the new code can be used in the simulation of local transactions.
410
+ * This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
411
+ * @param contractAddress - The address of the contract to update.
412
+ * @param artifact - The updated artifact for the contract.
413
+ * @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
414
+ * the current one (current one from the point of view of the node to which the PXE is connected).
415
+ */ updateContract(contractAddress, artifact) {
416
+ // We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
417
+ // class while we're simulating it.
418
+ return this.#putInJobQueue(async ()=>{
419
+ const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
420
+ if (!currentInstance) {
421
+ throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
422
+ }
423
+ const contractClass = await getContractClassFromArtifact(artifact);
424
+ await this.synchronizer.sync();
425
+ const header = await this.syncDataProvider.getBlockHeader();
426
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header.globalVariables.blockNumber, header.globalVariables.timestamp);
427
+ if (!contractClass.id.equals(currentClassId)) {
428
+ throw new Error('Could not update contract to a class different from the current one.');
429
+ }
430
+ await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
431
+ const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
432
+ await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
433
+ currentInstance.currentContractClassId = contractClass.id;
434
+ await this.contractDataProvider.addContractInstance(currentInstance);
435
+ this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
436
+ });
437
+ }
438
+ /**
439
+ * Retrieves the addresses of contracts added to this PXE.
440
+ * @returns An array of contracts addresses registered on this PXE.
441
+ */ getContracts() {
442
+ return this.contractDataProvider.getContractsAddresses();
443
+ }
444
+ /**
445
+ * A debugging utility to get notes based on the provided filter.
446
+ *
447
+ * Note that this should not be used in production code because the structure of notes is considered to be
448
+ * an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
449
+ * note-related information in production code, please implement a custom utility function on your contract and call
450
+ * that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
451
+ *
452
+ * @param filter - The filter to apply to the notes.
453
+ * @returns The requested notes.
454
+ */ async getNotes(filter) {
455
+ // We need to manually trigger private state sync to have a guarantee that all the notes are available.
456
+ const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
457
+ await this.simulateUtility(call);
458
+ return this.noteDataProvider.getNotes(filter);
459
+ }
460
+ /**
461
+ * Proves the private portion of a simulated transaction, ready to send to the network
462
+ * (where validators prove the public portion).
463
+ *
464
+ * @param txRequest - An authenticated tx request ready for proving
465
+ * @returns A result containing the proof and public inputs of the tail circuit.
466
+ * @throws If contract code not found, or public simulation reverts.
467
+ * Also throws if simulatePublic is true and public simulation reverts.
468
+ */ proveTx(txRequest) {
469
+ let privateExecutionResult;
470
+ // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
471
+ // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
472
+ return this.#putInJobQueue(async ()=>{
473
+ const totalTimer = new Timer();
474
+ try {
475
+ const syncTimer = new Timer();
476
+ await this.synchronizer.sync();
477
+ const syncTime = syncTimer.ms();
478
+ const contractFunctionSimulator = this.#getSimulatorForTx();
479
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
480
+ const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
481
+ simulate: false,
482
+ skipFeeEnforcement: false,
483
+ profileMode: 'none'
484
+ });
485
+ const totalTime = totalTimer.ms();
486
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
487
+ functionName,
488
+ time: witgen,
489
+ oracles
490
+ }));
491
+ const timings = {
492
+ total: totalTime,
493
+ sync: syncTime,
494
+ proving,
495
+ perFunction,
496
+ unaccounted: totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
497
+ };
498
+ this.log.debug(`Proving completed in ${totalTime}ms`, {
499
+ timings
500
+ });
501
+ const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof, {
502
+ timings,
503
+ nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
504
+ });
505
+ const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
506
+ if (preTagsUsedInTheTx.length > 0) {
507
+ await this.taggingDataProvider.setLastUsedIndexesAsSender(preTagsUsedInTheTx);
508
+ this.log.debug(`Stored used pre tags as sender for the tx`, {
509
+ preTagsUsedInTheTx
510
+ });
511
+ } else {
512
+ this.log.debug(`No pre tags used in the tx`);
513
+ }
514
+ return txProvingResult;
515
+ } catch (err) {
516
+ throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
517
+ }
518
+ });
519
+ }
520
+ /**
521
+ * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
522
+ *
523
+ * @param txRequest - An authenticated tx request ready for simulation
524
+ * @param msgSender - (Optional) The message sender to use for the simulation.
525
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
526
+ * @returns A trace of the program execution with gate counts.
527
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
528
+ */ profileTx(txRequest, profileMode, skipProofGeneration = true) {
529
+ // We disable concurrent profiles for consistency with simulateTx.
530
+ return this.#putInJobQueue(async ()=>{
531
+ const totalTimer = new Timer();
532
+ try {
533
+ const txInfo = {
534
+ origin: txRequest.origin,
535
+ functionSelector: txRequest.functionSelector,
536
+ simulatePublic: false,
537
+ chainId: txRequest.txContext.chainId,
538
+ version: txRequest.txContext.version,
539
+ authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
540
+ };
541
+ this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
542
+ const syncTimer = new Timer();
543
+ await this.synchronizer.sync();
544
+ const syncTime = syncTimer.ms();
545
+ const contractFunctionSimulator = this.#getSimulatorForTx();
546
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
547
+ const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
548
+ simulate: skipProofGeneration,
549
+ skipFeeEnforcement: false,
550
+ profileMode
551
+ });
552
+ const totalTime = totalTimer.ms();
553
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>{
554
+ return {
555
+ functionName,
556
+ time: witgen,
557
+ oracles
558
+ };
559
+ });
560
+ // Gate computation is time is not relevant for profiling, so we subtract it from the total time.
561
+ const gateCountComputationTime = executionSteps.reduce((acc, { timings })=>acc + (timings.gateCount ?? 0), 0) ?? 0;
562
+ const total = totalTime - gateCountComputationTime;
563
+ const timings = {
564
+ total,
565
+ sync: syncTime,
566
+ proving,
567
+ perFunction,
568
+ unaccounted: total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
569
+ };
570
+ const simulatorStats = contractFunctionSimulator.getStats();
571
+ return new TxProfileResult(executionSteps, {
572
+ timings,
573
+ nodeRPCCalls: simulatorStats.nodeRPCCalls
574
+ });
575
+ } catch (err) {
576
+ throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
577
+ }
578
+ });
579
+ }
580
+ /**
581
+ * Simulates a transaction based on the provided preauthenticated execution request.
582
+ * This will run a local simulation of private execution (and optionally of public as well), run the
583
+ * kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
584
+ * simulation results .
585
+ *
586
+ *
587
+ * Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
588
+ * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
589
+ *
590
+ *
591
+ * @param txRequest - An authenticated tx request ready for simulation
592
+ * @param simulatePublic - Whether to simulate the public part of the transaction.
593
+ * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
594
+ * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
595
+ * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
596
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
597
+ * @returns A simulated transaction result object that includes public and private return values.
598
+ * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
599
+ * Also throws if simulatePublic is true and public simulation reverts.
600
+ *
601
+ * TODO(#7456) Prevent msgSender being defined here for the first call
602
+ */ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
603
+ // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
604
+ // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
605
+ // delete the same read value, or reading values that another simulation is currently modifying).
606
+ return this.#putInJobQueue(async ()=>{
607
+ try {
608
+ const totalTimer = new Timer();
609
+ const txInfo = {
610
+ origin: txRequest.origin,
611
+ functionSelector: txRequest.functionSelector,
612
+ simulatePublic,
613
+ chainId: txRequest.txContext.chainId,
614
+ version: txRequest.txContext.version,
615
+ authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
616
+ };
617
+ this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
618
+ const syncTimer = new Timer();
619
+ await this.synchronizer.sync();
620
+ const syncTime = syncTimer.ms();
621
+ const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
622
+ // Temporary: in case there are overrides, we have to skip the kernels or validations
623
+ // will fail. Consider handing control to the user/wallet on whether they want to run them
624
+ // or not.
625
+ const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
626
+ // Execution of private functions only; no proving, and no kernel logic.
627
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
628
+ let publicInputs;
629
+ let executionSteps = [];
630
+ if (skipKernels) {
631
+ // According to the protocol rules, the nonce generator for the note hashes
632
+ // can either be the first nullifier in the tx or the protocol nullifier if there are none.
633
+ const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO) ? await computeProtocolNullifier(await txRequest.toTxRequest().hash()) : privateExecutionResult.firstNullifier;
634
+ ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractDataProvider));
635
+ } else {
636
+ // Kernel logic, plus proving of all private functions and kernels.
637
+ ({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
638
+ simulate: true,
639
+ skipFeeEnforcement,
640
+ profileMode: 'none'
641
+ }));
642
+ }
643
+ const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
644
+ const simulatedTx = await privateSimulationResult.toSimulatedTx();
645
+ let publicSimulationTime;
646
+ let publicOutput;
647
+ if (simulatePublic && publicInputs.forPublic) {
648
+ const publicSimulationTimer = new Timer();
649
+ publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
650
+ publicSimulationTime = publicSimulationTimer.ms();
651
+ }
652
+ let validationTime;
653
+ if (!skipTxValidation) {
654
+ const validationTimer = new Timer();
655
+ const validationResult = await this.node.isValidTx(simulatedTx, {
656
+ isSimulation: true,
657
+ skipFeeEnforcement
658
+ });
659
+ validationTime = validationTimer.ms();
660
+ if (validationResult.result === 'invalid') {
661
+ throw new Error('The simulated transaction is unable to be added to state and is invalid.');
662
+ }
663
+ }
664
+ const txHash = simulatedTx.getTxHash();
665
+ const totalTime = totalTimer.ms();
666
+ const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
667
+ functionName,
668
+ time: witgen,
669
+ oracles
670
+ }));
671
+ const timings = {
672
+ total: totalTime,
673
+ sync: syncTime,
674
+ publicSimulation: publicSimulationTime,
675
+ validation: validationTime,
676
+ perFunction,
677
+ unaccounted: totalTime - (syncTime + (publicSimulationTime ?? 0) + (validationTime ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
678
+ };
679
+ this.log.info(`Simulation completed for ${txHash.toString()} in ${totalTime}ms`, {
680
+ txHash,
681
+ ...txInfo,
682
+ ...publicOutput ? {
683
+ gasUsed: publicOutput.gasUsed,
684
+ revertCode: publicOutput.txEffect.revertCode.getCode(),
685
+ revertReason: publicOutput.revertReason
686
+ } : {}
687
+ });
688
+ const simulatorStats = contractFunctionSimulator.getStats();
689
+ return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
690
+ timings,
691
+ nodeRPCCalls: simulatorStats.nodeRPCCalls
692
+ });
693
+ } catch (err) {
694
+ throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
695
+ }
696
+ });
697
+ }
698
+ /**
699
+ * Simulate the execution of a contract utility function.
700
+ *
701
+ * @param call - The function call containing the function details, arguments, and target contract address.
702
+ * @param authwits - (Optional) The authentication witnesses required for the function call.
703
+ * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
704
+ * default to all.
705
+ * @returns The result of the utility function call, structured based on the function ABI.
706
+ */ simulateUtility(call, authwits, scopes) {
707
+ // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
708
+ // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
709
+ // delete the same read value, or reading values that another simulation is currently modifying).
710
+ return this.#putInJobQueue(async ()=>{
711
+ try {
712
+ const totalTimer = new Timer();
713
+ const syncTimer = new Timer();
714
+ await this.synchronizer.sync();
715
+ const syncTime = syncTimer.ms();
716
+ const functionTimer = new Timer();
717
+ const contractFunctionSimulator = this.#getSimulatorForTx();
718
+ const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
719
+ const functionTime = functionTimer.ms();
720
+ const totalTime = totalTimer.ms();
721
+ const perFunction = [
722
+ {
723
+ functionName: call.name,
724
+ time: functionTime
725
+ }
726
+ ];
727
+ const timings = {
728
+ total: totalTime,
729
+ sync: syncTime,
730
+ perFunction,
731
+ unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time })=>acc + time, 0))
732
+ };
733
+ const simulationStats = contractFunctionSimulator.getStats();
734
+ return {
735
+ result: executionResult,
736
+ stats: {
737
+ timings,
738
+ nodeRPCCalls: simulationStats.nodeRPCCalls
739
+ }
740
+ };
741
+ } catch (err) {
742
+ const { to, name, args } = call;
743
+ const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
744
+ throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
745
+ }
746
+ });
747
+ }
748
+ /**
749
+ * Returns the private events given search parameters.
750
+ * @param contractAddress - The address of the contract to get events from.
751
+ * @param eventSelector - Event selector to search for.
752
+ * @param from - The block number to search from.
753
+ * @param numBlocks - The amount of blocks to search.
754
+ * @param recipients - The addresses that decrypted the logs.
755
+ * @returns - The packed events with block and tx metadata.
756
+ */ async getPrivateEvents(contractAddress, eventSelector, from, numBlocks, recipients) {
757
+ if (recipients.length === 0) {
758
+ throw new Error('Recipients are required to get private events');
759
+ }
760
+ this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
761
+ // We need to manually trigger private state sync to have a guarantee that all the events are available.
762
+ const call = await this.#getFunctionCall('sync_private_state', [], contractAddress);
763
+ await this.simulateUtility(call);
764
+ return this.privateEventDataProvider.getPrivateEvents(contractAddress, from, numBlocks, recipients, eventSelector);
765
+ }
766
+ /**
767
+ * Stops the PXE's job queue.
768
+ */ stop() {
769
+ return this.jobQueue.end();
770
+ }
771
+ }