@aztec/pxe 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6

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 (286) hide show
  1. package/dest/access_scopes.d.ts +9 -0
  2. package/dest/access_scopes.d.ts.map +1 -0
  3. package/dest/access_scopes.js +6 -0
  4. package/dest/bin/check_oracle_version.js +1 -1
  5. package/dest/block_synchronizer/block_synchronizer.d.ts +11 -5
  6. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  7. package/dest/block_synchronizer/block_synchronizer.js +72 -21
  8. package/dest/config/index.d.ts +4 -2
  9. package/dest/config/index.d.ts.map +1 -1
  10. package/dest/config/index.js +18 -1
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
  13. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/benchmarked_node.js +77 -0
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts +64 -36
  16. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/contract_function_simulator.js +224 -88
  18. package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
  19. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/execution_note_cache.js +45 -28
  21. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  22. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  24. package/dest/contract_function_simulator/index.d.ts +3 -2
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +2 -1
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -4
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +6 -5
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
  33. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
  34. package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
  35. package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
  36. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -5
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +4 -6
  39. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
  42. package/dest/contract_function_simulator/oracle/interfaces.d.ts +56 -47
  43. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  45. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  46. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +42 -0
  47. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
  48. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +6 -6
  50. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  51. package/dest/contract_function_simulator/oracle/note_packing_utils.js +8 -8
  52. package/dest/contract_function_simulator/oracle/oracle.d.ts +45 -42
  53. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  54. package/dest/contract_function_simulator/oracle/oracle.js +209 -117
  55. package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
  56. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  57. package/dest/contract_function_simulator/oracle/private_execution.js +5 -38
  58. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +60 -76
  59. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  60. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +113 -88
  61. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +107 -56
  62. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  63. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +214 -137
  64. package/dest/contract_logging.d.ts +22 -0
  65. package/dest/contract_logging.d.ts.map +1 -0
  66. package/dest/contract_logging.js +23 -0
  67. package/dest/contract_sync/contract_sync_service.d.ts +45 -0
  68. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  69. package/dest/contract_sync/contract_sync_service.js +114 -0
  70. package/dest/contract_sync/helpers.d.ts +29 -0
  71. package/dest/contract_sync/helpers.d.ts.map +1 -0
  72. package/dest/contract_sync/helpers.js +55 -0
  73. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  74. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  75. package/dest/debug/pxe_debug_utils.js +28 -17
  76. package/dest/entrypoints/client/bundle/index.d.ts +4 -1
  77. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  78. package/dest/entrypoints/client/bundle/index.js +3 -0
  79. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  80. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  81. package/dest/entrypoints/client/bundle/utils.js +21 -7
  82. package/dest/entrypoints/client/lazy/index.d.ts +4 -1
  83. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  84. package/dest/entrypoints/client/lazy/index.js +3 -0
  85. package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
  86. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  87. package/dest/entrypoints/client/lazy/utils.js +22 -8
  88. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  89. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  90. package/dest/entrypoints/server/index.d.ts +5 -1
  91. package/dest/entrypoints/server/index.d.ts.map +1 -1
  92. package/dest/entrypoints/server/index.js +4 -0
  93. package/dest/entrypoints/server/utils.d.ts +1 -1
  94. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  95. package/dest/entrypoints/server/utils.js +28 -9
  96. package/dest/events/event_service.d.ts +6 -6
  97. package/dest/events/event_service.d.ts.map +1 -1
  98. package/dest/events/event_service.js +19 -22
  99. package/dest/events/private_event_filter_validator.d.ts +5 -5
  100. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  101. package/dest/events/private_event_filter_validator.js +5 -6
  102. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  103. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  104. package/dest/job_coordinator/job_coordinator.js +3 -2
  105. package/dest/logs/log_service.d.ts +8 -5
  106. package/dest/logs/log_service.d.ts.map +1 -1
  107. package/dest/logs/log_service.js +31 -33
  108. package/dest/messages/message_context_service.d.ts +17 -0
  109. package/dest/messages/message_context_service.d.ts.map +1 -0
  110. package/dest/messages/message_context_service.js +36 -0
  111. package/dest/notes/note_service.d.ts +10 -9
  112. package/dest/notes/note_service.d.ts.map +1 -1
  113. package/dest/notes/note_service.js +34 -38
  114. package/dest/notes_filter.d.ts +25 -0
  115. package/dest/notes_filter.d.ts.map +1 -0
  116. package/dest/notes_filter.js +4 -0
  117. package/dest/oracle_version.d.ts +3 -3
  118. package/dest/oracle_version.d.ts.map +1 -1
  119. package/dest/oracle_version.js +5 -4
  120. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  121. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  122. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  123. package/dest/private_kernel/hints/index.d.ts +3 -3
  124. package/dest/private_kernel/hints/index.d.ts.map +1 -1
  125. package/dest/private_kernel/hints/index.js +2 -2
  126. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
  127. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
  128. package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +140 -73
  129. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  130. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  131. package/dest/private_kernel/hints/test_utils.js +203 -0
  132. package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
  133. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  134. package/dest/private_kernel/private_kernel_execution_prover.js +22 -14
  135. package/dest/private_kernel/private_kernel_oracle.d.ts +23 -24
  136. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  137. package/dest/private_kernel/private_kernel_oracle.js +94 -2
  138. package/dest/pxe.d.ts +80 -59
  139. package/dest/pxe.d.ts.map +1 -1
  140. package/dest/pxe.js +155 -145
  141. package/dest/storage/address_store/address_store.d.ts +1 -1
  142. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  143. package/dest/storage/address_store/address_store.js +12 -11
  144. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  145. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  146. package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
  147. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  148. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  149. package/dest/storage/capsule_store/capsule_store.js +130 -23
  150. package/dest/storage/contract_store/contract_store.d.ts +42 -16
  151. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  152. package/dest/storage/contract_store/contract_store.js +157 -84
  153. package/dest/storage/metadata.d.ts +1 -1
  154. package/dest/storage/metadata.js +1 -1
  155. package/dest/storage/note_store/note_store.d.ts +50 -51
  156. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  157. package/dest/storage/note_store/note_store.js +284 -263
  158. package/dest/storage/note_store/stored_note.d.ts +16 -0
  159. package/dest/storage/note_store/stored_note.d.ts.map +1 -0
  160. package/dest/storage/note_store/stored_note.js +43 -0
  161. package/dest/storage/private_event_store/private_event_store.d.ts +43 -8
  162. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  163. package/dest/storage/private_event_store/private_event_store.js +226 -111
  164. package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
  165. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
  166. package/dest/storage/private_event_store/stored_private_event.js +56 -0
  167. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +16 -9
  168. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  169. package/dest/storage/tagging_store/recipient_tagging_store.js +88 -19
  170. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  171. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  172. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  173. package/dest/storage/tagging_store/sender_tagging_store.d.ts +43 -32
  174. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  175. package/dest/storage/tagging_store/sender_tagging_store.js +300 -122
  176. package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
  177. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
  178. package/dest/tagging/get_all_logs_by_tags.js +60 -0
  179. package/dest/tagging/index.d.ts +4 -3
  180. package/dest/tagging/index.d.ts.map +1 -1
  181. package/dest/tagging/index.js +2 -1
  182. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
  183. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  184. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +11 -11
  185. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  186. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
  187. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
  188. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +16 -12
  189. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
  190. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  191. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +18 -12
  192. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
  193. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  194. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +23 -16
  195. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +8 -7
  196. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  197. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +44 -27
  198. package/package.json +27 -18
  199. package/src/access_scopes.ts +9 -0
  200. package/src/bin/check_oracle_version.ts +1 -0
  201. package/src/block_synchronizer/block_synchronizer.ts +91 -33
  202. package/src/config/index.ts +15 -1
  203. package/src/config/package_info.ts +1 -1
  204. package/src/contract_function_simulator/benchmarked_node.ts +103 -0
  205. package/src/contract_function_simulator/contract_function_simulator.ts +386 -153
  206. package/src/contract_function_simulator/execution_note_cache.ts +44 -25
  207. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  208. package/src/contract_function_simulator/index.ts +2 -1
  209. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -6
  210. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
  211. package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
  212. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -7
  213. package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
  214. package/src/contract_function_simulator/oracle/interfaces.ts +69 -59
  215. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
  216. package/src/contract_function_simulator/oracle/note_packing_utils.ts +10 -10
  217. package/src/contract_function_simulator/oracle/oracle.ts +235 -165
  218. package/src/contract_function_simulator/oracle/private_execution.ts +5 -71
  219. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +153 -184
  220. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +318 -154
  221. package/src/contract_logging.ts +39 -0
  222. package/src/contract_sync/contract_sync_service.ts +181 -0
  223. package/src/contract_sync/helpers.ts +98 -0
  224. package/src/debug/pxe_debug_utils.ts +63 -18
  225. package/src/entrypoints/client/bundle/index.ts +3 -0
  226. package/src/entrypoints/client/bundle/utils.ts +16 -15
  227. package/src/entrypoints/client/lazy/index.ts +3 -0
  228. package/src/entrypoints/client/lazy/utils.ts +17 -15
  229. package/src/entrypoints/pxe_creation_options.ts +2 -1
  230. package/src/entrypoints/server/index.ts +4 -0
  231. package/src/entrypoints/server/utils.ts +22 -26
  232. package/src/events/event_service.ts +17 -25
  233. package/src/events/private_event_filter_validator.ts +3 -5
  234. package/src/job_coordinator/job_coordinator.ts +4 -3
  235. package/src/logs/log_service.ts +51 -40
  236. package/src/messages/message_context_service.ts +45 -0
  237. package/src/notes/note_service.ts +41 -45
  238. package/src/notes_filter.ts +26 -0
  239. package/src/oracle_version.ts +5 -4
  240. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  241. package/src/private_kernel/hints/index.ts +2 -2
  242. package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +195 -136
  243. package/src/private_kernel/hints/test_utils.ts +325 -0
  244. package/src/private_kernel/private_kernel_execution_prover.ts +26 -16
  245. package/src/private_kernel/private_kernel_oracle.ts +116 -37
  246. package/src/pxe.ts +286 -223
  247. package/src/storage/address_store/address_store.ts +15 -15
  248. package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
  249. package/src/storage/capsule_store/capsule_store.ts +159 -23
  250. package/src/storage/contract_store/contract_store.ts +186 -96
  251. package/src/storage/metadata.ts +1 -1
  252. package/src/storage/note_store/note_store.ts +326 -320
  253. package/src/storage/note_store/stored_note.ts +48 -0
  254. package/src/storage/private_event_store/private_event_store.ts +292 -124
  255. package/src/storage/private_event_store/stored_private_event.ts +73 -0
  256. package/src/storage/tagging_store/recipient_tagging_store.ts +111 -21
  257. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  258. package/src/storage/tagging_store/sender_tagging_store.ts +366 -134
  259. package/src/tagging/get_all_logs_by_tags.ts +92 -0
  260. package/src/tagging/index.ts +3 -2
  261. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +22 -14
  262. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  263. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
  264. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +31 -15
  265. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +29 -26
  266. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +42 -29
  267. package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
  268. package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
  269. package/dest/contract_function_simulator/proxied_node.js +0 -27
  270. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
  271. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  272. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  273. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  274. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  275. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  276. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -85
  277. package/dest/public_storage/public_storage_service.d.ts +0 -24
  278. package/dest/public_storage/public_storage_service.d.ts.map +0 -1
  279. package/dest/public_storage/public_storage_service.js +0 -26
  280. package/dest/tree_membership/tree_membership_service.d.ts +0 -52
  281. package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
  282. package/dest/tree_membership/tree_membership_service.js +0 -84
  283. package/src/contract_function_simulator/proxied_node.ts +0 -33
  284. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -127
  285. package/src/public_storage/public_storage_service.ts +0 -33
  286. package/src/tree_membership/tree_membership_service.ts +0 -112
package/src/pxe.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
5
  import { SerialQueue } from '@aztec/foundation/queue';
5
6
  import { Timer } from '@aztec/foundation/timer';
6
7
  import { KeyStore } from '@aztec/key-store';
@@ -19,14 +20,12 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
19
20
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
20
21
  import {
21
22
  CompleteAddress,
22
- type ContractClassWithId,
23
23
  type ContractInstanceWithAddress,
24
24
  type PartialAddress,
25
25
  computeContractAddressFromInstance,
26
26
  getContractClassFromArtifact,
27
27
  } from '@aztec/stdlib/contract';
28
28
  import { SimulationError } from '@aztec/stdlib/errors';
29
- import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
30
29
  import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
31
30
  import type {
32
31
  PrivateExecutionStep,
@@ -34,6 +33,7 @@ import type {
34
33
  PrivateKernelTailCircuitPublicInputs,
35
34
  } from '@aztec/stdlib/kernel';
36
35
  import {
36
+ BlockHeader,
37
37
  type ContractOverrides,
38
38
  type InTx,
39
39
  PrivateExecutionResult,
@@ -47,29 +47,33 @@ import {
47
47
  TxProfileResult,
48
48
  TxProvingResult,
49
49
  TxSimulationResult,
50
- UtilitySimulationResult,
50
+ UtilityExecutionResult,
51
51
  } from '@aztec/stdlib/tx';
52
52
 
53
53
  import { inspect } from 'util';
54
54
 
55
+ import type { AccessScopes } from './access_scopes.js';
55
56
  import { BlockSynchronizer } from './block_synchronizer/index.js';
56
57
  import type { PXEConfig } from './config/index.js';
58
+ import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
57
59
  import {
58
60
  ContractFunctionSimulator,
59
61
  generateSimulatedProvingResult,
60
62
  } from './contract_function_simulator/contract_function_simulator.js';
61
- import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
62
63
  import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
63
- import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
64
+ import { displayDebugLogs } from './contract_logging.js';
65
+ import { ContractSyncService } from './contract_sync/contract_sync_service.js';
66
+ import { readCurrentClassId } from './contract_sync/helpers.js';
64
67
  import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
65
68
  import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
66
69
  import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
67
70
  import { JobCoordinator } from './job_coordinator/job_coordinator.js';
71
+ import { MessageContextService } from './messages/message_context_service.js';
68
72
  import {
69
73
  PrivateKernelExecutionProver,
70
74
  type PrivateKernelExecutionProverConfig,
71
75
  } from './private_kernel/private_kernel_execution_prover.js';
72
- import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
76
+ import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
73
77
  import { AddressStore } from './storage/address_store/address_store.js';
74
78
  import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
75
79
  import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
@@ -85,6 +89,58 @@ export type PackedPrivateEvent = InTx & {
85
89
  eventSelector: EventSelector;
86
90
  };
87
91
 
92
+ /** Options for PXE.profileTx. */
93
+ export type ProfileTxOpts = {
94
+ /** The profiling mode to use. */
95
+ profileMode: 'full' | 'execution-steps' | 'gates';
96
+ /** If true, proof generation is skipped during profiling. Defaults to true. */
97
+ skipProofGeneration?: boolean;
98
+ /** Addresses whose private state and keys are accessible during private execution. */
99
+ scopes: AccessScopes;
100
+ };
101
+
102
+ /** Options for PXE.simulateTx. */
103
+ export type SimulateTxOpts = {
104
+ /** Whether to simulate the public part of the transaction. */
105
+ simulatePublic: boolean;
106
+ /** If false, this function throws if the transaction is unable to be included in a block at the current state. */
107
+ skipTxValidation?: boolean;
108
+ /** If false, fees are enforced. */
109
+ skipFeeEnforcement?: boolean;
110
+ /** If true, kernel logic is emulated in TS for simulation */
111
+ skipKernels?: boolean;
112
+ /** State overrides for the simulation, such as contract instances and artifacts. Requires skipKernels: true */
113
+ overrides?: SimulationOverrides;
114
+ /** Addresses whose private state and keys are accessible during private execution */
115
+ scopes: AccessScopes;
116
+ };
117
+
118
+ /** Options for PXE.executeUtility. */
119
+ export type ExecuteUtilityOpts = {
120
+ /** The authentication witnesses required for the function call. */
121
+ authwits?: AuthWitness[];
122
+ /** The accounts whose notes we can access in this call */
123
+ scopes: AccessScopes;
124
+ };
125
+
126
+ /** Args for PXE.create. */
127
+ export type PXECreateArgs = {
128
+ /** The Aztec node to connect to. */
129
+ node: AztecNode;
130
+ /** The key-value store for persisting PXE state. */
131
+ store: AztecAsyncKVStore;
132
+ /** The prover for generating private kernel proofs. */
133
+ proofCreator: PrivateKernelProver;
134
+ /** The circuit simulator for executing ACIR circuits. */
135
+ simulator: CircuitSimulator;
136
+ /** Provider for protocol contract artifacts and instances. */
137
+ protocolContractsProvider: ProtocolContractsProvider;
138
+ /** PXE configuration options. */
139
+ config: PXEConfig;
140
+ /** Optional logger instance or string suffix for the logger name. */
141
+ loggerOrSuffix?: string | Logger;
142
+ };
143
+
88
144
  /**
89
145
  * Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
90
146
  * manage private state of users.
@@ -92,6 +148,7 @@ export type PackedPrivateEvent = InTx & {
92
148
  export class PXE {
93
149
  private constructor(
94
150
  private node: AztecNode,
151
+ private db: AztecAsyncKVStore,
95
152
  private blockStateSynchronizer: BlockSynchronizer,
96
153
  private keyStore: KeyStore,
97
154
  private contractStore: ContractStore,
@@ -103,6 +160,8 @@ export class PXE {
103
160
  private recipientTaggingStore: RecipientTaggingStore,
104
161
  private addressStore: AddressStore,
105
162
  private privateEventStore: PrivateEventStore,
163
+ private contractSyncService: ContractSyncService,
164
+ private messageContextService: MessageContextService,
106
165
  private simulator: CircuitSimulator,
107
166
  private proverEnabled: boolean,
108
167
  private proofCreator: PrivateKernelProver,
@@ -120,25 +179,31 @@ export class PXE {
120
179
  *
121
180
  * @returns A promise that resolves PXE is ready to be used.
122
181
  */
123
- public static async create(
124
- node: AztecNode,
125
- store: AztecAsyncKVStore,
126
- proofCreator: PrivateKernelProver,
127
- simulator: CircuitSimulator,
128
- protocolContractsProvider: ProtocolContractsProvider,
129
- config: PXEConfig,
130
- loggerOrSuffix?: string | Logger,
131
- ) {
182
+ public static async create({
183
+ node,
184
+ store,
185
+ proofCreator,
186
+ simulator,
187
+ protocolContractsProvider,
188
+ config,
189
+ loggerOrSuffix,
190
+ }: PXECreateArgs) {
191
+ // Extract bindings from the logger, or use empty bindings if a string suffix is provided.
192
+ const bindings: LoggerBindings | undefined =
193
+ loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
194
+
132
195
  const log =
133
196
  !loggerOrSuffix || typeof loggerOrSuffix === 'string'
134
197
  ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
135
198
  : loggerOrSuffix;
136
199
 
137
- const proverEnabled = !!config.proverEnabled;
200
+ const info = await node.getNodeInfo();
201
+
202
+ const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
138
203
  const addressStore = new AddressStore(store);
139
204
  const privateEventStore = new PrivateEventStore(store);
140
205
  const contractStore = new ContractStore(store);
141
- const noteStore = await NoteStore.create(store);
206
+ const noteStore = new NoteStore(store);
142
207
  const anchorBlockStore = new AnchorBlockStore(store);
143
208
  const senderTaggingStore = new SenderTaggingStore(store);
144
209
  const senderAddressBookStore = new SenderAddressBookStore(store);
@@ -146,24 +211,43 @@ export class PXE {
146
211
  const capsuleStore = new CapsuleStore(store);
147
212
  const keyStore = new KeyStore(store);
148
213
  const tipsStore = new L2TipsKVStore(store, 'pxe');
214
+ const contractSyncService = new ContractSyncService(
215
+ node,
216
+ contractStore,
217
+ noteStore,
218
+ createLogger('pxe:contract_sync', bindings),
219
+ );
220
+ const messageContextService = new MessageContextService(node);
221
+
149
222
  const synchronizer = new BlockSynchronizer(
150
223
  node,
224
+ store,
151
225
  anchorBlockStore,
152
226
  noteStore,
153
227
  privateEventStore,
154
228
  tipsStore,
229
+ contractSyncService,
155
230
  config,
156
- loggerOrSuffix,
231
+ bindings,
157
232
  );
158
233
 
159
- const jobCoordinator = new JobCoordinator(store);
234
+ const jobCoordinator = new JobCoordinator(store, bindings);
235
+ jobCoordinator.registerStores([
236
+ capsuleStore,
237
+ senderTaggingStore,
238
+ recipientTaggingStore,
239
+ privateEventStore,
240
+ noteStore,
241
+ contractSyncService,
242
+ ]);
160
243
 
161
- const debugUtils = new PXEDebugUtils(contractStore, noteStore);
244
+ const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
162
245
 
163
246
  const jobQueue = new SerialQueue();
164
247
 
165
248
  const pxe = new PXE(
166
249
  node,
250
+ store,
167
251
  synchronizer,
168
252
  keyStore,
169
253
  contractStore,
@@ -175,6 +259,8 @@ export class PXE {
175
259
  recipientTaggingStore,
176
260
  addressStore,
177
261
  privateEventStore,
262
+ contractSyncService,
263
+ messageContextService,
178
264
  simulator,
179
265
  proverEnabled,
180
266
  proofCreator,
@@ -185,12 +271,15 @@ export class PXE {
185
271
  debugUtils,
186
272
  );
187
273
 
188
- debugUtils.setPXE(pxe);
274
+ debugUtils.setPXEHelpers(
275
+ pxe.#putInJobQueue.bind(pxe),
276
+ pxe.#getSimulatorForTx.bind(pxe),
277
+ pxe.#executeUtility.bind(pxe),
278
+ );
189
279
 
190
280
  pxe.jobQueue.start();
191
281
 
192
282
  await pxe.#registerProtocolContracts();
193
- const info = await node.getNodeInfo();
194
283
  log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
195
284
  return pxe;
196
285
  }
@@ -200,20 +289,21 @@ export class PXE {
200
289
  #getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
201
290
  const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
202
291
 
203
- return new ContractFunctionSimulator(
204
- proxyContractStore,
205
- this.noteStore,
206
- this.keyStore,
207
- this.addressStore,
208
- ProxiedNodeFactory.create(this.node),
209
- this.anchorBlockStore,
210
- this.senderTaggingStore,
211
- this.recipientTaggingStore,
212
- this.senderAddressBookStore,
213
- this.capsuleStore,
214
- this.privateEventStore,
215
- this.simulator,
216
- );
292
+ return new ContractFunctionSimulator({
293
+ contractStore: proxyContractStore,
294
+ noteStore: this.noteStore,
295
+ keyStore: this.keyStore,
296
+ addressStore: this.addressStore,
297
+ aztecNode: BenchmarkedNodeFactory.create(this.node),
298
+ senderTaggingStore: this.senderTaggingStore,
299
+ recipientTaggingStore: this.recipientTaggingStore,
300
+ senderAddressBookStore: this.senderAddressBookStore,
301
+ capsuleStore: this.capsuleStore,
302
+ privateEventStore: this.privateEventStore,
303
+ simulator: this.simulator,
304
+ contractSyncService: this.contractSyncService,
305
+ messageContextService: this.messageContextService,
306
+ });
217
307
  }
218
308
 
219
309
  #contextualizeError(err: Error, ...context: string[]): Error {
@@ -265,34 +355,20 @@ export class PXE {
265
355
  async #registerProtocolContracts() {
266
356
  const registered: Record<string, string> = {};
267
357
  for (const name of protocolContractNames) {
268
- const { address, contractClass, instance, artifact } =
269
- await this.protocolContractsProvider.getProtocolContractArtifact(name);
270
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
358
+ const { address, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
359
+ await this.contractStore.addContractArtifact(artifact);
271
360
  await this.contractStore.addContractInstance(instance);
272
361
  registered[name] = address.toString();
273
362
  }
274
363
  this.log.verbose(`Registered protocol contracts in pxe`, registered);
275
364
  }
276
365
 
277
- async #isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
278
- return !!(await this.node.getContractClass(id));
279
- }
280
-
281
- async #isContractPublished(address: AztecAddress): Promise<boolean> {
282
- return !!(await this.node.getContract(address));
283
- }
284
-
285
- async #isContractInitialized(address: AztecAddress): Promise<boolean> {
286
- const initNullifier = await siloNullifier(address, address.toField());
287
- return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
288
- }
289
-
290
366
  // Executes the entrypoint private function, as well as all nested private
291
367
  // functions that might arise.
292
368
  async #executePrivate(
293
369
  contractFunctionSimulator: ContractFunctionSimulator,
294
370
  txRequest: TxExecutionRequest,
295
- scopes: AztecAddress[] | undefined,
371
+ scopes: AccessScopes,
296
372
  jobId: string,
297
373
  ): Promise<PrivateExecutionResult> {
298
374
  const { origin: contractAddress, functionSelector } = txRequest;
@@ -300,18 +376,23 @@ export class PXE {
300
376
  try {
301
377
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
302
378
 
303
- const result = await contractFunctionSimulator.run(
304
- txRequest,
379
+ await this.contractSyncService.ensureContractSynced(
305
380
  contractAddress,
306
381
  functionSelector,
307
- undefined,
382
+ (privateSyncCall, execScopes) =>
383
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
308
384
  anchorBlockHeader,
309
- // The sender for tags is set by contracts, typically by an account
310
- // contract entrypoint
311
- undefined, // senderForTags
312
- scopes,
313
385
  jobId,
386
+ scopes,
314
387
  );
388
+
389
+ const result = await contractFunctionSimulator.run(txRequest, {
390
+ contractAddress,
391
+ selector: functionSelector,
392
+ anchorBlockHeader,
393
+ scopes,
394
+ jobId,
395
+ });
315
396
  this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
316
397
  return result;
317
398
  } catch (err) {
@@ -323,25 +404,32 @@ export class PXE {
323
404
  }
324
405
 
325
406
  /**
326
- * Simulate a utility function call on the given contract.
407
+ * Execute a utility function call on the given contract.
327
408
  * @param contractFunctionSimulator - The simulator to use for the function call.
328
409
  * @param call - The function call to execute.
329
410
  * @param authWitnesses - Authentication witnesses required for the function call.
330
411
  * @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
331
412
  * accounts if not specified.
332
413
  * @param jobId - The job ID for staged writes.
333
- * @returns The simulation result containing the outputs of the utility function.
414
+ * @returns The execution result containing the outputs of the utility function.
334
415
  */
335
- async #simulateUtility(
416
+ async #executeUtility(
336
417
  contractFunctionSimulator: ContractFunctionSimulator,
337
418
  call: FunctionCall,
338
419
  authWitnesses: AuthWitness[] | undefined,
339
- scopes: AztecAddress[] | undefined,
420
+ scopes: AccessScopes,
340
421
  jobId: string,
341
422
  ) {
342
423
  try {
343
424
  const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
344
- return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
425
+ const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
426
+ call,
427
+ authWitnesses ?? [],
428
+ anchorBlockHeader,
429
+ scopes,
430
+ jobId,
431
+ );
432
+ return { result, offchainEffects };
345
433
  } catch (err) {
346
434
  if (err instanceof SimulationError) {
347
435
  await enrichSimulationError(err, this.contractStore, this.log);
@@ -394,85 +482,45 @@ export class PXE {
394
482
  privateExecutionResult: PrivateExecutionResult,
395
483
  config: PrivateKernelExecutionProverConfig,
396
484
  ): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
397
- const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
398
- const kernelOracle = new PrivateKernelOracleImpl(
399
- this.contractStore,
400
- this.keyStore,
401
- this.node,
402
- simulationAnchorBlock,
485
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
486
+ const anchorBlockHash = await anchorBlockHeader.hash();
487
+ const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
488
+ const kernelTraceProver = new PrivateKernelExecutionProver(
489
+ kernelOracle,
490
+ proofCreator,
491
+ !this.proverEnabled,
492
+ this.log.getBindings(),
403
493
  );
404
- const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
405
494
  this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
406
495
  return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
407
496
  }
408
497
 
409
498
  // Public API
410
499
 
411
- public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
412
- return this.contractStore.getContractInstance(address);
500
+ /**
501
+ * Returns the block header up to which the PXE has synced.
502
+ * @returns The synced block header
503
+ */
504
+ public getSyncedBlockHeader(): Promise<BlockHeader> {
505
+ return this.anchorBlockStore.getBlockHeader();
413
506
  }
414
507
 
415
508
  /**
416
- * Returns the contract class metadata given a contract class id.
417
- * The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
418
- * @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
419
- * @param id - Identifier of the class.
420
- * @param includeArtifact - Identifier of the class.
421
- * @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
422
- * for `includeArtifact`
423
- * TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
424
- * should the pxe query the node for contract public info, and merge it with its own definitions?
425
- * TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
426
- * during a public deployment. We probably want a nicer and more general API for this, but it'll have to
427
- * do for the time being.
509
+ * Returns the contract instance for a given address, if it's registered in the PXE.
510
+ * @param address - The contract address.
511
+ * @returns The contract instance if found, undefined otherwise.
428
512
  */
429
- public async getContractClassMetadata(
430
- id: Fr,
431
- includeArtifact: boolean = false,
432
- ): Promise<{
433
- contractClass: ContractClassWithId | undefined;
434
- isContractClassPubliclyRegistered: boolean;
435
- artifact: ContractArtifact | undefined;
436
- }> {
437
- const artifact = await this.contractStore.getContractArtifact(id);
438
- if (!artifact) {
439
- this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
440
- }
441
-
442
- return {
443
- contractClass: artifact && (await getContractClassFromArtifact(artifact)),
444
- isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
445
- artifact: includeArtifact ? artifact : undefined,
446
- };
513
+ public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
514
+ return this.contractStore.getContractInstance(address);
447
515
  }
448
516
 
449
517
  /**
450
- * Returns the contract metadata given an address.
451
- * The metadata consists of its contract instance, which includes the contract class identifier,
452
- * initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
453
- * and whether the contract instance with the given address has been publicly deployed.
454
- * @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
455
- * This query is not dependent on the PXE.
456
- * @param address - The address that the contract instance resides at.
457
- * @returns - It returns the contract metadata
458
- * TODO(@spalladino): Should we return the public keys in plain as well here?
518
+ * Returns the contract artifact for a given contract class id, if it's registered in the PXE.
519
+ * @param id - Identifier of the contract class.
520
+ * @returns The contract artifact if found, undefined otherwise.
459
521
  */
460
- public async getContractMetadata(address: AztecAddress): Promise<{
461
- contractInstance: ContractInstanceWithAddress | undefined;
462
- isContractInitialized: boolean;
463
- isContractPublished: boolean;
464
- }> {
465
- let instance;
466
- try {
467
- instance = await this.contractStore.getContractInstance(address);
468
- } catch {
469
- this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
470
- }
471
- return {
472
- contractInstance: instance,
473
- isContractInitialized: await this.#isContractInitialized(address),
474
- isContractPublished: await this.#isContractPublished(address),
475
- };
522
+ public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
523
+ return await this.contractStore.getContractArtifact(id);
476
524
  }
477
525
 
478
526
  /**
@@ -497,7 +545,6 @@ export class PXE {
497
545
  }
498
546
 
499
547
  await this.addressStore.addCompleteAddress(accountCompleteAddress);
500
- await this.noteStore.addScope(accountCompleteAddress.address);
501
548
  return accountCompleteAddress;
502
549
  }
503
550
 
@@ -522,6 +569,9 @@ export class PXE {
522
569
 
523
570
  if (wasAdded) {
524
571
  this.log.info(`Added sender:\n ${sender.toString()}`);
572
+ // Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
573
+ // all contracts must re-sync to discover them.
574
+ this.contractSyncService.wipe();
525
575
  } else {
526
576
  this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
527
577
  }
@@ -571,8 +621,7 @@ export class PXE {
571
621
  * @param artifact - The build artifact for the contract class.
572
622
  */
573
623
  public async registerContractClass(artifact: ContractArtifact): Promise<void> {
574
- const { id: contractClassId } = await getContractClassFromArtifact(artifact);
575
- await this.contractStore.addContractArtifact(contractClassId, artifact);
624
+ const contractClassId = await this.contractStore.addContractArtifact(artifact);
576
625
  this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
577
626
  }
578
627
 
@@ -591,17 +640,17 @@ export class PXE {
591
640
  if (artifact) {
592
641
  // If the user provides an artifact, validate it against the expected class id and register it
593
642
  const contractClass = await getContractClassFromArtifact(artifact);
594
- const contractClassId = contractClass.id;
595
- if (!contractClassId.equals(instance.currentContractClassId)) {
643
+ if (!contractClass.id.equals(instance.currentContractClassId)) {
596
644
  throw new Error(
597
- `Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`,
645
+ `Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
598
646
  );
599
647
  }
600
648
  const computedAddress = await computeContractAddressFromInstance(instance);
601
649
  if (!computedAddress.equals(instance.address)) {
602
650
  throw new Error('Added a contract in which the address does not match the contract instance.');
603
651
  }
604
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
652
+
653
+ await this.contractStore.addContractArtifact(artifact, contractClass);
605
654
 
606
655
  const publicFunctionSignatures = artifact.functions
607
656
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
@@ -645,26 +694,21 @@ export class PXE {
645
694
 
646
695
  const header = await this.anchorBlockStore.getBlockHeader();
647
696
 
648
- const currentClassId = await readCurrentClassId(
649
- contractAddress,
650
- currentInstance,
651
- this.node,
652
- header.globalVariables.blockNumber,
653
- header.globalVariables.timestamp,
654
- );
697
+ const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
655
698
  if (!contractClass.id.equals(currentClassId)) {
656
699
  throw new Error('Could not update contract to a class different from the current one.');
657
700
  }
658
701
 
659
- await this.contractStore.addContractArtifact(contractClass.id, artifact);
660
-
661
702
  const publicFunctionSignatures = artifact.functions
662
703
  .filter(fn => fn.functionType === FunctionType.PUBLIC)
663
704
  .map(fn => decodeFunctionSignature(fn.name, fn.parameters));
664
705
  await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
665
706
 
666
707
  currentInstance.currentContractClassId = contractClass.id;
667
- await this.contractStore.addContractInstance(currentInstance);
708
+ await Promise.all([
709
+ this.contractStore.addContractArtifact(artifact, contractClass),
710
+ this.contractStore.addContractInstance(currentInstance),
711
+ ]);
668
712
  this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
669
713
  });
670
714
  }
@@ -682,11 +726,12 @@ export class PXE {
682
726
  * (where validators prove the public portion).
683
727
  *
684
728
  * @param txRequest - An authenticated tx request ready for proving
729
+ * @param scopes - Addresses whose private state and keys are accessible during private execution.
685
730
  * @returns A result containing the proof and public inputs of the tail circuit.
686
731
  * @throws If contract code not found, or public simulation reverts.
687
732
  * Also throws if simulatePublic is true and public simulation reverts.
688
733
  */
689
- public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
734
+ public proveTx(txRequest: TxExecutionRequest, scopes: AztecAddress[]): Promise<TxProvingResult> {
690
735
  let privateExecutionResult: PrivateExecutionResult;
691
736
  // We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
692
737
  // computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
@@ -697,7 +742,7 @@ export class PXE {
697
742
  await this.blockStateSynchronizer.sync();
698
743
  const syncTime = syncTimer.ms();
699
744
  const contractFunctionSimulator = this.#getSimulatorForTx();
700
- privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
745
+ privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
701
746
 
702
747
  const {
703
748
  publicInputs,
@@ -739,17 +784,17 @@ export class PXE {
739
784
  // transaction before this one is included in a block from this PXE, and that transaction contains a log with
740
785
  // a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
741
786
  // storing the tags here prevents linkage of txs sent from the same PXE.
742
- const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
743
- if (preTagsUsedInTheTx.length > 0) {
787
+ const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
788
+ if (taggingIndexRangesUsedInTheTx.length > 0) {
744
789
  // TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
745
790
  const txHash = (await txProvingResult.toTx()).txHash;
746
791
 
747
- await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
748
- this.log.debug(`Stored used pre-tags as sender for the tx`, {
749
- preTagsUsedInTheTx,
792
+ await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
793
+ this.log.debug(`Stored used tagging index ranges as sender for the tx`, {
794
+ taggingIndexRangesUsedInTheTx,
750
795
  });
751
796
  } else {
752
- this.log.debug(`No pre-tags used in the tx`);
797
+ this.log.debug(`No tagging index ranges used in the tx`);
753
798
  }
754
799
 
755
800
  return txProvingResult;
@@ -761,17 +806,13 @@ export class PXE {
761
806
 
762
807
  /**
763
808
  * Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
764
- *
765
- * @param txRequest - An authenticated tx request ready for simulation
766
- * @param msgSender - (Optional) The message sender to use for the simulation.
767
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
809
+ * @param txRequest - An authenticated tx request ready for simulation.
768
810
  * @returns A trace of the program execution with gate counts.
769
811
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
770
812
  */
771
813
  public profileTx(
772
814
  txRequest: TxExecutionRequest,
773
- profileMode: 'full' | 'execution-steps' | 'gates',
774
- skipProofGeneration: boolean = true,
815
+ { profileMode, skipProofGeneration = true, scopes }: ProfileTxOpts,
775
816
  ): Promise<TxProfileResult> {
776
817
  // We disable concurrent profiles for consistency with simulateTx.
777
818
  return this.#putInJobQueue(async jobId => {
@@ -794,12 +835,7 @@ export class PXE {
794
835
  const syncTime = syncTimer.ms();
795
836
 
796
837
  const contractFunctionSimulator = this.#getSimulatorForTx();
797
- const privateExecutionResult = await this.#executePrivate(
798
- contractFunctionSimulator,
799
- txRequest,
800
- undefined,
801
- jobId,
802
- );
838
+ const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
803
839
 
804
840
  const { executionSteps, timings: { proving } = {} } = await this.#prove(
805
841
  txRequest,
@@ -856,12 +892,7 @@ export class PXE {
856
892
  * In that case, the transaction returned is only potentially ready to be sent to the network for execution.
857
893
  *
858
894
  *
859
- * @param txRequest - An authenticated tx request ready for simulation
860
- * @param simulatePublic - Whether to simulate the public part of the transaction.
861
- * @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
862
- * @param skipFeeEnforcement - (Optional) If false, fees are enforced.
863
- * @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
864
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
895
+ * @param txRequest - An authenticated tx request ready for simulation.
865
896
  * @returns A simulated transaction result object that includes public and private return values.
866
897
  * @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
867
898
  * Also throws if simulatePublic is true and public simulation reverts.
@@ -870,11 +901,14 @@ export class PXE {
870
901
  */
871
902
  public simulateTx(
872
903
  txRequest: TxExecutionRequest,
873
- simulatePublic: boolean,
874
- skipTxValidation: boolean = false,
875
- skipFeeEnforcement: boolean = false,
876
- overrides?: SimulationOverrides,
877
- scopes?: AztecAddress[],
904
+ {
905
+ simulatePublic,
906
+ skipTxValidation = false,
907
+ skipFeeEnforcement = false,
908
+ skipKernels = true,
909
+ overrides,
910
+ scopes,
911
+ }: SimulateTxOpts,
878
912
  ): Promise<TxSimulationResult> {
879
913
  // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
880
914
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
@@ -898,11 +932,21 @@ export class PXE {
898
932
  await this.blockStateSynchronizer.sync();
899
933
  const syncTime = syncTimer.ms();
900
934
 
935
+ const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
936
+ const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
937
+
938
+ if (hasOverriddenContracts && !skipKernels) {
939
+ throw new Error(
940
+ 'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
941
+ );
942
+ }
901
943
  const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
902
- // Temporary: in case there are overrides, we have to skip the kernels or validations
903
- // will fail. Consider handing control to the user/wallet on whether they want to run them
904
- // or not.
905
- const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
944
+
945
+ if (hasOverriddenContracts) {
946
+ // Overridden contracts don't have a sync function, so calling sync on them would fail.
947
+ // We exclude them so the sync service skips them entirely.
948
+ this.contractSyncService.setExcludedFromSync(jobId, overriddenContracts);
949
+ }
906
950
 
907
951
  // Execution of private functions only; no proving, and no kernel logic.
908
952
  const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
@@ -911,15 +955,10 @@ export class PXE {
911
955
  let executionSteps: PrivateExecutionStep[] = [];
912
956
 
913
957
  if (skipKernels) {
914
- // According to the protocol rules, the nonce generator for the note hashes
915
- // can either be the first nullifier in the tx or the protocol nullifier if there are none.
916
- const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
917
- ? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
918
- : privateExecutionResult.firstNullifier;
919
958
  ({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
920
959
  privateExecutionResult,
921
- nonceGenerator,
922
- this.contractStore,
960
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
961
+ this.node,
923
962
  ));
924
963
  } else {
925
964
  // Kernel logic, plus proving of all private functions and kernels.
@@ -938,6 +977,9 @@ export class PXE {
938
977
  const publicSimulationTimer = new Timer();
939
978
  publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
940
979
  publicSimulationTime = publicSimulationTimer.ms();
980
+ if (publicOutput?.debugLogs?.length) {
981
+ await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
982
+ }
941
983
  }
942
984
 
943
985
  let validationTime: number | undefined;
@@ -946,7 +988,8 @@ export class PXE {
946
988
  const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
947
989
  validationTime = validationTimer.ms();
948
990
  if (validationResult.result === 'invalid') {
949
- throw new Error('The simulated transaction is unable to be added to state and is invalid.');
991
+ const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
992
+ throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
950
993
  }
951
994
  }
952
995
 
@@ -997,29 +1040,23 @@ export class PXE {
997
1040
  inspect(txRequest),
998
1041
  `simulatePublic=${simulatePublic}`,
999
1042
  `skipTxValidation=${skipTxValidation}`,
1000
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1043
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1001
1044
  );
1002
1045
  }
1003
1046
  });
1004
1047
  }
1005
1048
 
1006
1049
  /**
1007
- * Simulate the execution of a contract utility function.
1008
- *
1050
+ * Executes a contract utility function.
1009
1051
  * @param call - The function call containing the function details, arguments, and target contract address.
1010
- * @param authwits - (Optional) The authentication witnesses required for the function call.
1011
- * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
1012
- * default to all.
1013
- * @returns The result of the utility function call, structured based on the function ABI.
1014
1052
  */
1015
- public simulateUtility(
1053
+ public executeUtility(
1016
1054
  call: FunctionCall,
1017
- authwits?: AuthWitness[],
1018
- scopes?: AztecAddress[],
1019
- ): Promise<UtilitySimulationResult> {
1020
- // We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
1055
+ { authwits, scopes }: ExecuteUtilityOpts = { scopes: 'ALL_SCOPES' },
1056
+ ): Promise<UtilityExecutionResult> {
1057
+ // We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
1021
1058
  // to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
1022
- // delete the same read value, or reading values that another simulation is currently modifying).
1059
+ // delete the same read value, or reading values that another execution is currently modifying).
1023
1060
  return this.#putInJobQueue(async jobId => {
1024
1061
  try {
1025
1062
  const totalTimer = new Timer();
@@ -1029,11 +1066,18 @@ export class PXE {
1029
1066
  const functionTimer = new Timer();
1030
1067
  const contractFunctionSimulator = this.#getSimulatorForTx();
1031
1068
 
1032
- await this.contractStore.syncPrivateState(call.to, call.selector, privateSyncCall =>
1033
- this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1069
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1070
+ await this.contractSyncService.ensureContractSynced(
1071
+ call.to,
1072
+ call.selector,
1073
+ (privateSyncCall, execScopes) =>
1074
+ this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1075
+ anchorBlockHeader,
1076
+ jobId,
1077
+ scopes,
1034
1078
  );
1035
1079
 
1036
- const executionResult = await this.#simulateUtility(
1080
+ const { result: executionResult, offchainEffects } = await this.#executeUtility(
1037
1081
  contractFunctionSimulator,
1038
1082
  call,
1039
1083
  authwits ?? [],
@@ -1054,14 +1098,19 @@ export class PXE {
1054
1098
  };
1055
1099
 
1056
1100
  const simulationStats = contractFunctionSimulator.getStats();
1057
- return { result: executionResult, stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls } };
1101
+ return {
1102
+ result: executionResult,
1103
+ offchainEffects,
1104
+ anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
1105
+ stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
1106
+ };
1058
1107
  } catch (err: any) {
1059
1108
  const { to, name, args } = call;
1060
1109
  const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
1061
1110
  throw this.#contextualizeError(
1062
1111
  err,
1063
- `simulateUtility ${to}:${name}(${stringifiedArgs})`,
1064
- `scopes=${scopes?.map(s => s.toString()).join(', ') ?? 'undefined'}`,
1112
+ `executeUtility ${to}:${name}(${stringifiedArgs})`,
1113
+ `scopes=${scopes === 'ALL_SCOPES' ? scopes : scopes.map(s => s.toString()).join(', ')}`,
1065
1114
  );
1066
1115
  }
1067
1116
  });
@@ -1080,32 +1129,46 @@ export class PXE {
1080
1129
  * Defaults to the latest known block to PXE + 1.
1081
1130
  * @returns - The packed events with block and tx metadata.
1082
1131
  */
1083
- public getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventFilter): Promise<PackedPrivateEvent[]> {
1084
- return this.#putInJobQueue(async jobId => {
1132
+ public async getPrivateEvents(
1133
+ eventSelector: EventSelector,
1134
+ filter: PrivateEventFilter,
1135
+ ): Promise<PackedPrivateEvent[]> {
1136
+ let anchorBlockNumber: BlockNumber;
1137
+
1138
+ await this.#putInJobQueue(async jobId => {
1085
1139
  await this.blockStateSynchronizer.sync();
1140
+
1141
+ const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
1142
+ anchorBlockNumber = anchorBlockHeader.getBlockNumber();
1143
+
1086
1144
  const contractFunctionSimulator = this.#getSimulatorForTx();
1087
1145
 
1088
- await this.contractStore.syncPrivateState(
1146
+ await this.contractSyncService.ensureContractSynced(
1089
1147
  filter.contractAddress,
1090
1148
  null,
1091
- async privateSyncCall =>
1092
- await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
1149
+ async (privateSyncCall, execScopes) =>
1150
+ await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
1151
+ anchorBlockHeader,
1152
+ jobId,
1153
+ filter.scopes,
1093
1154
  );
1155
+ });
1094
1156
 
1095
- const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
1157
+ // anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
1158
+ const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
1096
1159
 
1097
- this.log.debug(
1098
- `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1099
- );
1160
+ this.log.debug(
1161
+ `Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
1162
+ );
1100
1163
 
1101
- return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1102
- });
1164
+ return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
1103
1165
  }
1104
1166
 
1105
1167
  /**
1106
- * Stops the PXE's job queue.
1168
+ * Stops the PXE's job queue and closes the backing store.
1107
1169
  */
1108
- public stop(): Promise<void> {
1109
- return this.jobQueue.end();
1170
+ public async stop(): Promise<void> {
1171
+ await this.jobQueue.end();
1172
+ await this.db.close();
1110
1173
  }
1111
1174
  }