@aztec/pxe 0.0.1-commit.fffb133c → 0.0.1-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/dest/bin/check_oracle_version.js +5 -5
  2. package/dest/block_synchronizer/block_synchronizer.d.ts +10 -4
  3. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  4. package/dest/block_synchronizer/block_synchronizer.js +30 -6
  5. package/dest/config/package_info.js +1 -1
  6. package/dest/contract_function_simulator/contract_function_simulator.d.ts +66 -31
  7. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/contract_function_simulator.js +214 -75
  9. package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
  10. package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
  12. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -7
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
  15. package/dest/contract_function_simulator/index.d.ts +2 -1
  16. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/index.js +1 -0
  18. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +4 -6
  19. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +8 -10
  21. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
  22. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
  23. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
  24. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
  26. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
  27. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +6 -11
  29. package/dest/contract_function_simulator/oracle/interfaces.d.ts +66 -47
  30. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
  32. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
  33. package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
  34. package/dest/contract_function_simulator/oracle/oracle.d.ts +78 -44
  35. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/oracle/oracle.js +363 -114
  37. package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
  38. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +56 -86
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +123 -98
  41. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +145 -70
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +435 -145
  44. package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
  45. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
  46. package/dest/contract_function_simulator/pick_notes.js +20 -3
  47. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
  48. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  49. package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
  50. package/dest/contract_logging.d.ts +27 -0
  51. package/dest/contract_logging.d.ts.map +1 -0
  52. package/dest/contract_logging.js +38 -0
  53. package/dest/contract_sync/contract_sync_service.d.ts +45 -0
  54. package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
  55. package/dest/contract_sync/contract_sync_service.js +150 -0
  56. package/dest/contract_sync/helpers.d.ts +27 -0
  57. package/dest/contract_sync/helpers.d.ts.map +1 -0
  58. package/dest/contract_sync/{index.js → helpers.js} +16 -17
  59. package/dest/debug/pxe_debug_utils.d.ts +24 -10
  60. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  61. package/dest/debug/pxe_debug_utils.js +28 -18
  62. package/dest/entrypoints/client/bundle/index.d.ts +3 -1
  63. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  64. package/dest/entrypoints/client/bundle/index.js +2 -0
  65. package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
  66. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/client/bundle/utils.js +24 -9
  68. package/dest/entrypoints/client/lazy/index.d.ts +3 -1
  69. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  70. package/dest/entrypoints/client/lazy/index.js +2 -0
  71. package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
  72. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  73. package/dest/entrypoints/client/lazy/utils.js +25 -10
  74. package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
  75. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  76. package/dest/entrypoints/pxe_creation_options.js +3 -1
  77. package/dest/entrypoints/server/index.d.ts +5 -3
  78. package/dest/entrypoints/server/index.d.ts.map +1 -1
  79. package/dest/entrypoints/server/index.js +4 -2
  80. package/dest/entrypoints/server/utils.d.ts +2 -2
  81. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  82. package/dest/entrypoints/server/utils.js +31 -11
  83. package/dest/events/event_service.d.ts +16 -8
  84. package/dest/events/event_service.d.ts.map +1 -1
  85. package/dest/events/event_service.js +46 -14
  86. package/dest/events/private_event_filter_validator.d.ts +3 -2
  87. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  88. package/dest/events/private_event_filter_validator.js +15 -0
  89. package/dest/hooks/authorize_utility_call.d.ts +37 -0
  90. package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
  91. package/dest/hooks/authorize_utility_call.js +4 -0
  92. package/dest/hooks/execution_hooks.d.ts +42 -0
  93. package/dest/hooks/execution_hooks.d.ts.map +1 -0
  94. package/dest/hooks/execution_hooks.js +9 -0
  95. package/dest/hooks/index.d.ts +4 -0
  96. package/dest/hooks/index.d.ts.map +1 -0
  97. package/dest/hooks/index.js +1 -0
  98. package/dest/job_coordinator/job_coordinator.d.ts +3 -2
  99. package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
  100. package/dest/job_coordinator/job_coordinator.js +3 -2
  101. package/dest/logs/log_service.d.ts +10 -9
  102. package/dest/logs/log_service.d.ts.map +1 -1
  103. package/dest/logs/log_service.js +50 -85
  104. package/dest/messages/message_context_service.d.ts +17 -0
  105. package/dest/messages/message_context_service.d.ts.map +1 -0
  106. package/dest/messages/message_context_service.js +38 -0
  107. package/dest/notes/note_service.d.ts +29 -8
  108. package/dest/notes/note_service.d.ts.map +1 -1
  109. package/dest/notes/note_service.js +89 -65
  110. package/dest/notes_filter.d.ts +24 -0
  111. package/dest/notes_filter.d.ts.map +1 -0
  112. package/dest/notes_filter.js +4 -0
  113. package/dest/oracle_version.d.ts +4 -3
  114. package/dest/oracle_version.d.ts.map +1 -1
  115. package/dest/oracle_version.js +20 -10
  116. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
  117. package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
  118. package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
  119. package/dest/private_kernel/hints/index.d.ts +1 -1
  120. package/dest/private_kernel/hints/index.js +1 -1
  121. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
  122. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  123. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
  124. package/dest/private_kernel/hints/test_utils.d.ts +122 -0
  125. package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
  126. package/dest/private_kernel/hints/test_utils.js +203 -0
  127. package/dest/private_kernel/private_kernel_execution_prover.d.ts +4 -2
  128. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  129. package/dest/private_kernel/private_kernel_execution_prover.js +38 -19
  130. package/dest/private_kernel/private_kernel_oracle.d.ts +10 -6
  131. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  132. package/dest/private_kernel/private_kernel_oracle.js +26 -20
  133. package/dest/pxe.d.ts +87 -23
  134. package/dest/pxe.d.ts.map +1 -1
  135. package/dest/pxe.js +178 -119
  136. package/dest/storage/address_store/address_store.d.ts +1 -1
  137. package/dest/storage/address_store/address_store.d.ts.map +1 -1
  138. package/dest/storage/address_store/address_store.js +12 -11
  139. package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
  140. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
  141. package/dest/storage/anchor_block_store/anchor_block_store.js +9 -2
  142. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
  143. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
  144. package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
  145. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
  146. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
  147. package/dest/storage/backwards_compatibility_tests/schema_tests.js +588 -0
  148. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
  149. package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
  150. package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
  151. package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
  152. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
  153. package/dest/storage/capsule_store/capsule_service.js +50 -0
  154. package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
  155. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  156. package/dest/storage/capsule_store/capsule_store.js +42 -36
  157. package/dest/storage/capsule_store/index.d.ts +2 -1
  158. package/dest/storage/capsule_store/index.d.ts.map +1 -1
  159. package/dest/storage/capsule_store/index.js +1 -0
  160. package/dest/storage/contract_store/contract_store.d.ts +42 -15
  161. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  162. package/dest/storage/contract_store/contract_store.js +160 -73
  163. package/dest/storage/metadata.d.ts +1 -1
  164. package/dest/storage/metadata.js +1 -1
  165. package/dest/storage/note_store/note_store.d.ts +13 -3
  166. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  167. package/dest/storage/note_store/note_store.js +147 -107
  168. package/dest/storage/open_pxe_stores.d.ts +31 -0
  169. package/dest/storage/open_pxe_stores.d.ts.map +1 -0
  170. package/dest/storage/open_pxe_stores.js +26 -0
  171. package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
  172. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  173. package/dest/storage/private_event_store/private_event_store.js +87 -61
  174. package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
  175. package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
  176. package/dest/storage/private_event_store/stored_private_event.js +2 -2
  177. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
  178. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
  179. package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
  180. package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
  181. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
  182. package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
  183. package/dest/storage/tagging_store/sender_tagging_store.d.ts +29 -28
  184. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  185. package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
  186. package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
  187. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  188. package/dest/tagging/get_all_logs_by_tags.js +20 -3
  189. package/dest/tagging/index.d.ts +6 -5
  190. package/dest/tagging/index.d.ts.map +1 -1
  191. package/dest/tagging/index.js +4 -3
  192. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
  193. package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
  194. package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
  195. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +56 -0
  196. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
  197. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +158 -0
  198. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
  199. package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
  200. package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
  201. package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
  202. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
  203. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  204. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +30 -13
  205. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +13 -7
  206. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  207. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +41 -10
  208. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +6 -8
  209. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  210. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -24
  211. package/package.json +26 -16
  212. package/src/bin/check_oracle_version.ts +5 -5
  213. package/src/block_synchronizer/block_synchronizer.ts +45 -21
  214. package/src/config/package_info.ts +1 -1
  215. package/src/contract_function_simulator/contract_function_simulator.ts +389 -134
  216. package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
  217. package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
  218. package/src/contract_function_simulator/index.ts +1 -0
  219. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
  220. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
  221. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
  222. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
  223. package/src/contract_function_simulator/oracle/interfaces.ts +101 -62
  224. package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
  225. package/src/contract_function_simulator/oracle/oracle.ts +464 -151
  226. package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
  227. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +152 -191
  228. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +709 -200
  229. package/src/contract_function_simulator/pick_notes.ts +22 -3
  230. package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
  231. package/src/contract_logging.ts +52 -0
  232. package/src/contract_sync/contract_sync_service.ts +208 -0
  233. package/src/contract_sync/{index.ts → helpers.ts} +17 -29
  234. package/src/debug/pxe_debug_utils.ts +63 -19
  235. package/src/entrypoints/client/bundle/index.ts +2 -0
  236. package/src/entrypoints/client/bundle/utils.ts +19 -18
  237. package/src/entrypoints/client/lazy/index.ts +2 -0
  238. package/src/entrypoints/client/lazy/utils.ts +20 -18
  239. package/src/entrypoints/pxe_creation_options.ts +13 -1
  240. package/src/entrypoints/server/index.ts +4 -2
  241. package/src/entrypoints/server/utils.ts +25 -29
  242. package/src/events/event_service.ts +70 -24
  243. package/src/events/private_event_filter_validator.ts +21 -1
  244. package/src/hooks/authorize_utility_call.ts +40 -0
  245. package/src/hooks/execution_hooks.ts +48 -0
  246. package/src/hooks/index.ts +7 -0
  247. package/src/job_coordinator/job_coordinator.ts +4 -3
  248. package/src/logs/log_service.ts +88 -141
  249. package/src/messages/message_context_service.ts +45 -0
  250. package/src/notes/note_service.ts +124 -91
  251. package/src/notes_filter.ts +24 -0
  252. package/src/oracle_version.ts +20 -10
  253. package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
  254. package/src/private_kernel/hints/index.ts +1 -1
  255. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
  256. package/src/private_kernel/hints/test_utils.ts +325 -0
  257. package/src/private_kernel/private_kernel_execution_prover.ts +53 -22
  258. package/src/private_kernel/private_kernel_oracle.ts +36 -26
  259. package/src/pxe.ts +351 -168
  260. package/src/storage/address_store/address_store.ts +15 -15
  261. package/src/storage/anchor_block_store/anchor_block_store.ts +9 -1
  262. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
  263. package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
  264. package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
  265. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
  266. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
  267. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +42 -0
  268. package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +36 -0
  269. package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
  270. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
  271. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +16 -0
  272. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
  273. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +97 -0
  274. package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
  275. package/src/storage/backwards_compatibility_tests/schema_tests.ts +707 -0
  276. package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
  277. package/src/storage/capsule_store/capsule_service.ts +90 -0
  278. package/src/storage/capsule_store/capsule_store.ts +52 -34
  279. package/src/storage/capsule_store/index.ts +1 -0
  280. package/src/storage/contract_store/contract_store.ts +193 -81
  281. package/src/storage/metadata.ts +1 -1
  282. package/src/storage/note_store/note_store.ts +166 -132
  283. package/src/storage/open_pxe_stores.ts +47 -0
  284. package/src/storage/private_event_store/private_event_store.ts +106 -81
  285. package/src/storage/private_event_store/stored_private_event.ts +3 -3
  286. package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
  287. package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
  288. package/src/storage/tagging_store/sender_tagging_store.ts +287 -156
  289. package/src/tagging/get_all_logs_by_tags.ts +35 -7
  290. package/src/tagging/index.ts +5 -4
  291. package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
  292. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +236 -0
  293. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
  294. package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
  295. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +54 -18
  296. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -14
  297. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +30 -29
  298. package/dest/contract_sync/index.d.ts +0 -23
  299. package/dest/contract_sync/index.d.ts.map +0 -1
  300. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
  301. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
  302. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -15
  303. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
  304. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
  305. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -15
  306. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
  307. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -32
  308. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -143
  309. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -49
@@ -1,15 +1,20 @@
1
+ import { uniqueBy } from '@aztec/foundation/collection';
1
2
  import { Aes128 } from '@aztec/foundation/crypto/aes128';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
4
+ import { LogLevels, createLogger } from '@aztec/foundation/log';
5
+ import { isProtocolContract } from '@aztec/protocol-contracts';
6
+ import { ExecutionError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
4
7
  import { siloNullifier } from '@aztec/stdlib/hash';
5
8
  import { computeAddressSecret } from '@aztec/stdlib/keys';
6
- import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
9
+ import { MessageContext, deriveAppSiloedSharedSecret } from '@aztec/stdlib/logs';
7
10
  import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
8
11
  import { MerkleTreeId } from '@aztec/stdlib/trees';
12
+ import { createContractLogger, logContractMessage, stripAztecnrLogPrefix } from '../../contract_logging.js';
9
13
  import { EventService } from '../../events/event_service.js';
10
14
  import { LogService } from '../../logs/log_service.js';
11
15
  import { NoteService } from '../../notes/note_service.js';
12
- import { ORACLE_VERSION } from '../../oracle_version.js';
16
+ import { ORACLE_VERSION_MAJOR } from '../../oracle_version.js';
17
+ import { EphemeralArrayService } from '../ephemeral_array_service.js';
13
18
  import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
14
19
  import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
15
20
  import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
@@ -17,9 +22,18 @@ import { NoteValidationRequest } from '../noir-structs/note_validation_request.j
17
22
  import { UtilityContext } from '../noir-structs/utility_context.js';
18
23
  import { pickNotes } from '../pick_notes.js';
19
24
  import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
25
+ import { Oracle } from './oracle.js';
20
26
  /**
21
27
  * The oracle for an execution of utility contract functions.
22
28
  */ export class UtilityExecutionOracle {
29
+ isMisc = true;
30
+ isUtility = true;
31
+ contractLogger;
32
+ aztecnrLogger;
33
+ offchainEffects = [];
34
+ ephemeralArrayService = new EphemeralArrayService();
35
+ // We store oracle version to be able to show a nice error message when an oracle handler is missing.
36
+ contractOracleVersion;
23
37
  contractAddress;
24
38
  authWitnesses;
25
39
  capsules;
@@ -29,48 +43,79 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
29
43
  keyStore;
30
44
  addressStore;
31
45
  aztecNode;
32
- anchorBlockStore;
33
46
  recipientTaggingStore;
34
47
  senderAddressBookStore;
35
- capsuleStore;
48
+ capsuleService;
36
49
  privateEventStore;
50
+ messageContextService;
51
+ contractSyncService;
52
+ l2TipsStore;
37
53
  jobId;
38
- log;
54
+ logger;
39
55
  scopes;
40
- isMisc;
41
- isUtility;
42
- aztecNrDebugLog;
43
- constructor(contractAddress, /** List of transient auth witnesses to be used during this simulation */ authWitnesses, capsules, anchorBlockHeader, contractStore, noteStore, keyStore, addressStore, aztecNode, anchorBlockStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobId, log = createLogger('simulator:client_view_context'), scopes){
44
- this.contractAddress = contractAddress;
45
- this.authWitnesses = authWitnesses;
46
- this.capsules = capsules;
47
- this.anchorBlockHeader = anchorBlockHeader;
48
- this.contractStore = contractStore;
49
- this.noteStore = noteStore;
50
- this.keyStore = keyStore;
51
- this.addressStore = addressStore;
52
- this.aztecNode = aztecNode;
53
- this.anchorBlockStore = anchorBlockStore;
54
- this.recipientTaggingStore = recipientTaggingStore;
55
- this.senderAddressBookStore = senderAddressBookStore;
56
- this.capsuleStore = capsuleStore;
57
- this.privateEventStore = privateEventStore;
58
- this.jobId = jobId;
59
- this.log = log;
60
- this.scopes = scopes;
61
- this.isMisc = true;
62
- this.isUtility = true;
63
- this.aztecNrDebugLog = createLogger('aztec-nr:debug_log');
64
- }
65
- utilityAssertCompatibleOracleVersion(version) {
66
- if (version !== ORACLE_VERSION) {
67
- throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
56
+ simulator;
57
+ hooks;
58
+ utilityExecutor;
59
+ constructor(args){
60
+ this.contractAddress = args.contractAddress;
61
+ this.authWitnesses = args.authWitnesses;
62
+ this.capsules = args.capsules;
63
+ this.anchorBlockHeader = args.anchorBlockHeader;
64
+ this.contractStore = args.contractStore;
65
+ this.noteStore = args.noteStore;
66
+ this.keyStore = args.keyStore;
67
+ this.addressStore = args.addressStore;
68
+ this.aztecNode = args.aztecNode;
69
+ this.recipientTaggingStore = args.recipientTaggingStore;
70
+ this.senderAddressBookStore = args.senderAddressBookStore;
71
+ this.capsuleService = args.capsuleService;
72
+ this.privateEventStore = args.privateEventStore;
73
+ this.messageContextService = args.messageContextService;
74
+ this.contractSyncService = args.contractSyncService;
75
+ this.l2TipsStore = args.l2TipsStore;
76
+ this.jobId = args.jobId;
77
+ this.logger = args.log ?? createLogger('simulator:client_view_context');
78
+ this.scopes = args.scopes;
79
+ this.simulator = args.simulator;
80
+ this.hooks = args.hooks;
81
+ this.utilityExecutor = args.utilityExecutor;
82
+ }
83
+ assertCompatibleOracleVersion(major, minor) {
84
+ // TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
85
+ // Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
86
+ // the expected pinned version or the current one. We want to allow for both the pinned and the current versions
87
+ // because we want this code to work with both the pinned and unpinned version since some branches do not have the
88
+ // pinned contracts (like e.g. next)
89
+ const LEGACY_ORACLE_VERSION = 12;
90
+ if (isProtocolContract(this.contractAddress)) {
91
+ if (major !== LEGACY_ORACLE_VERSION && major !== ORACLE_VERSION_MAJOR) {
92
+ const hint = major > ORACLE_VERSION_MAJOR ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.' : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
93
+ throw new Error(`Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${LEGACY_ORACLE_VERSION} or ${ORACLE_VERSION_MAJOR}, got ${major})`);
94
+ }
95
+ this.contractOracleVersion = {
96
+ major,
97
+ minor
98
+ };
99
+ return;
100
+ }
101
+ if (major !== ORACLE_VERSION_MAJOR) {
102
+ const hint = major > ORACLE_VERSION_MAJOR ? 'The contract was compiled with a newer version of Aztec.nr than your private environment supports. Upgrade your private environment to a compatible version.' : 'The contract was compiled with an older version of Aztec.nr than your private environment supports. Recompile the contract with a compatible version of Aztec.nr.';
103
+ throw new Error(`Incompatible private environment version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`);
68
104
  }
105
+ // Major matches - store both major and minor for later diagnostics (e.g. when an oracle is not found)
106
+ this.contractOracleVersion = {
107
+ major,
108
+ minor
109
+ };
110
+ }
111
+ // Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
112
+ nonOracleFunctionGetContractOracleVersion() {
113
+ return this.contractOracleVersion;
69
114
  }
70
- utilityGetRandomField() {
115
+ getRandomField() {
71
116
  return Fr.random();
72
117
  }
73
- utilityGetUtilityContext() {
118
+ getUtilityContext() {
74
119
  return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
75
120
  }
76
121
  /**
@@ -78,32 +123,51 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
78
123
  * @param pkMHash - The master public key hash.
79
124
  * @returns A Promise that resolves to nullifier keys.
80
125
  * @throws If the keys are not registered in the key store.
81
- */ utilityGetKeyValidationRequest(pkMHash) {
126
+ * @throws If scopes are defined and the account is not in the scopes.
127
+ */ async getKeyValidationRequest(pkMHash) {
128
+ let hasAccess = false;
129
+ for(let i = 0; i < this.scopes.length && !hasAccess; i++){
130
+ if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
131
+ hasAccess = true;
132
+ }
133
+ }
134
+ if (!hasAccess) {
135
+ throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
136
+ }
82
137
  return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
83
138
  }
84
139
  /**
85
140
  * Fetches the index and sibling path of a leaf at a given block from the note hash tree.
86
- * @param blockHash - The block hash at which to get the membership witness.
87
- * @param leafValue - The leaf value
141
+ * @param blockHash - The hash of a block that contains the note hash tree root in which to find the
142
+ * membership witness.
143
+ * @param noteHash - The note hash to find in the note hash tree.
88
144
  * @returns The membership witness containing the leaf index and sibling path
89
- */ utilityGetNoteHashMembershipWitness(blockHash, leafValue) {
90
- return this.aztecNode.getNoteHashMembershipWitness(blockHash, leafValue);
145
+ */ getNoteHashMembershipWitness(blockHash, noteHash) {
146
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, ()=>this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash));
91
147
  }
92
148
  /**
93
- * Fetches the index and sibling path of a leaf at a given block from the archive tree.
94
- * @param blockHash - The block hash at which to get the membership witness.
95
- * @param leafValue - The leaf value
149
+ * Fetches the index and sibling path of a block hash in the archive tree.
150
+ *
151
+ * Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
152
+ * its block hash is appended as a new leaf to the archive tree.
153
+ *
154
+ * @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
155
+ * witness.
156
+ * @param blockHash - The block hash to find in the archive tree.
96
157
  * @returns The membership witness containing the leaf index and sibling path
97
- */ utilityGetArchiveMembershipWitness(blockHash, leafValue) {
98
- return this.aztecNode.getArchiveMembershipWitness(blockHash, leafValue);
158
+ */ getBlockHashMembershipWitness(referenceBlockHash, blockHash) {
159
+ // Note that we validate that the reference block hash is at or before the anchor block - we don't test the block
160
+ // hash at all. If the block hash did not exist by the reference block hash, then the node will not return the
161
+ // membership witness as there is none.
162
+ return this.#queryWithBlockHashNotAfterAnchor(referenceBlockHash, ()=>this.aztecNode.getBlockHashMembershipWitness(referenceBlockHash, blockHash));
99
163
  }
100
164
  /**
101
165
  * Returns a nullifier membership witness for a given nullifier at a given block.
102
166
  * @param blockHash - The block hash at which to get the index.
103
167
  * @param nullifier - Nullifier we try to find witness for.
104
168
  * @returns The nullifier membership witness (if found).
105
- */ utilityGetNullifierMembershipWitness(blockHash, nullifier) {
106
- return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
169
+ */ getNullifierMembershipWitness(blockHash, nullifier) {
170
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, ()=>this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier));
107
171
  }
108
172
  /**
109
173
  * Returns a low nullifier membership witness for a given nullifier at a given block.
@@ -113,38 +177,48 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
113
177
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
114
178
  * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
115
179
  * we are trying to prove non-inclusion for.
116
- */ utilityGetLowNullifierMembershipWitness(blockHash, nullifier) {
117
- return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
180
+ */ getLowNullifierMembershipWitness(blockHash, nullifier) {
181
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, ()=>this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier));
118
182
  }
119
183
  /**
120
184
  * Returns a public data tree witness for a given leaf slot at a given block.
121
185
  * @param blockHash - The block hash at which to get the index.
122
186
  * @param leafSlot - The slot of the public data tree to get the witness for.
123
187
  * @returns - The witness
124
- */ utilityGetPublicDataWitness(blockHash, leafSlot) {
125
- return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
188
+ */ getPublicDataWitness(blockHash, leafSlot) {
189
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, ()=>this.aztecNode.getPublicDataWitness(blockHash, leafSlot));
126
190
  }
127
191
  /**
128
192
  * Fetches a block header of a given block.
129
193
  * @param blockNumber - The number of a block of which to get the block header.
130
194
  * @returns Block extracted from a block with block number `blockNumber`.
131
- */ async utilityGetBlockHeader(blockNumber) {
132
- const anchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
195
+ */ async getBlockHeader(blockNumber) {
196
+ const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
133
197
  if (blockNumber > anchorBlockNumber) {
134
198
  throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
135
199
  }
200
+ // Most contracts query state at the "current" block, which is the anchor. Skip the RPC when we can.
201
+ if (blockNumber === anchorBlockNumber) {
202
+ return this.anchorBlockHeader;
203
+ }
136
204
  const block = await this.aztecNode.getBlock(blockNumber);
137
205
  return block?.header;
138
206
  }
139
207
  /**
140
- * Retrieve the complete address associated to a given address.
208
+ * Retrieve the public keys and partial address associated to a given address.
141
209
  * @param account - The account address.
142
- * @returns A complete address associated with the input address.
143
- * @throws An error if the account is not registered in the database.
144
- */ utilityGetPublicKeysAndPartialAddress(account) {
145
- return this.getCompleteAddress(account);
210
+ * @returns The public keys and partial address, or `undefined` if the account is not registered.
211
+ */ async getPublicKeysAndPartialAddress(account) {
212
+ const completeAddress = await this.addressStore.getCompleteAddress(account);
213
+ if (!completeAddress) {
214
+ return undefined;
215
+ }
216
+ return {
217
+ publicKeys: completeAddress.publicKeys,
218
+ partialAddress: completeAddress.partialAddress
219
+ };
146
220
  }
147
- async getCompleteAddress(account) {
221
+ async getCompleteAddressOrFail(account) {
148
222
  const completeAddress = await this.addressStore.getCompleteAddress(account);
149
223
  if (!completeAddress) {
150
224
  throw new Error(`No public key registered for address ${account}.
@@ -156,10 +230,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
156
230
  * Returns a contract instance associated with an address or throws if not found.
157
231
  * @param address - Address.
158
232
  * @returns A contract instance.
159
- */ utilityGetContractInstance(address) {
160
- return this.getContractInstance(address);
161
- }
162
- async getContractInstance(address) {
233
+ */ async getContractInstance(address) {
163
234
  const instance = await this.contractStore.getContractInstance(address);
164
235
  if (!instance) {
165
236
  throw new Error(`No contract instance found for address ${address.toString()}`);
@@ -167,11 +238,10 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
167
238
  return instance;
168
239
  }
169
240
  /**
170
- * Returns an auth witness for the given message hash. Checks on the list of transient witnesses
171
- * for this transaction first, and falls back to the local database if not found.
241
+ * Returns an auth witness for the given message hash from the list of transient witnesses for this transaction.
172
242
  * @param messageHash - Hash of the message to authenticate.
173
- * @returns Authentication witness for the requested message hash.
174
- */ utilityGetAuthWitness(messageHash) {
243
+ * @returns Authentication witness for the requested message hash, or undefined if not found.
244
+ */ getAuthWitness(messageHash) {
175
245
  return Promise.resolve(this.authWitnesses.find((w)=>w.requestHash.equals(messageHash))?.witness);
176
246
  }
177
247
  /**
@@ -195,8 +265,8 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
195
265
  * @param offset - The starting index for pagination.
196
266
  * @param status - The status of notes to fetch.
197
267
  * @returns Array of note data.
198
- */ async utilityGetNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
199
- const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
268
+ */ async getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
269
+ const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
200
270
  const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
201
271
  return pickNotes(dbNotes, {
202
272
  selects: selectByIndexes.slice(0, numSelects).map((index, i)=>({
@@ -224,22 +294,25 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
224
294
  * Check if a nullifier exists in the nullifier tree.
225
295
  * @param innerNullifier - The inner nullifier.
226
296
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
227
- */ async utilityCheckNullifierExists(innerNullifier) {
228
- const nullifier = await siloNullifier(this.contractAddress, innerNullifier);
229
- const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
297
+ */ async doesNullifierExist(innerNullifier) {
298
+ const [nullifier, anchorBlockHash] = await Promise.all([
299
+ siloNullifier(this.contractAddress, innerNullifier),
300
+ this.anchorBlockHeader.hash()
301
+ ]);
302
+ const [leafIndex] = await this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [
230
303
  nullifier
231
304
  ]);
232
305
  return leafIndex?.data !== undefined;
233
306
  }
234
307
  /**
235
- * Fetches a message from the executionStore, given its key.
308
+ * Returns the membership witness of an un-nullified L1 to L2 message.
236
309
  * @param contractAddress - Address of a contract by which the message was emitted.
237
310
  * @param messageHash - Hash of the message.
238
311
  * @param secret - Secret used to compute a nullifier.
239
312
  * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
240
313
  * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
241
- */ async utilityGetL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
242
- const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
314
+ */ async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
315
+ const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret, await this.anchorBlockHeader.hash());
243
316
  return new MessageLoadOracleInputs(messageIndex, siblingPath);
244
317
  }
245
318
  /**
@@ -248,125 +321,342 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
248
321
  * @param contractAddress - The address to read storage from.
249
322
  * @param startStorageSlot - The starting storage slot.
250
323
  * @param numberOfElements - Number of elements to read from the starting storage slot.
251
- */ async utilityStorageRead(blockHash, contractAddress, startStorageSlot, numberOfElements) {
252
- const slots = Array(numberOfElements).fill(0).map((_, i)=>new Fr(startStorageSlot.value + BigInt(i)));
253
- const values = await Promise.all(slots.map((storageSlot)=>this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)));
254
- this.log.debug(`Oracle storage read: slots=[${slots.map((slot)=>slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`);
255
- return values;
324
+ */ getFromPublicStorage(blockHash, contractAddress, startStorageSlot, numberOfElements) {
325
+ return this.#queryWithBlockHashNotAfterAnchor(blockHash, async ()=>{
326
+ const slots = Array(numberOfElements).fill(0).map((_, i)=>new Fr(startStorageSlot.value + BigInt(i)));
327
+ const values = await Promise.all(slots.map((storageSlot)=>this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)));
328
+ this.logger.debug(`Oracle storage read: slots=[${slots.map((slot)=>slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`);
329
+ return values;
330
+ });
256
331
  }
257
- utilityDebugLog(level, message, fields) {
332
+ /**
333
+ * Returns a per-contract logger whose output is prefixed with `contract:<name>(<addrAbbrev>)`.
334
+ */ async #getContractLogger() {
335
+ if (!this.contractLogger) {
336
+ // Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
337
+ // to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
338
+ this.contractLogger = await createContractLogger(this.contractAddress, (addr)=>this.contractStore.getDebugContractName(addr), 'user', {
339
+ instanceId: this.jobId
340
+ });
341
+ }
342
+ return this.contractLogger;
343
+ }
344
+ /**
345
+ * Returns a per-contract logger whose output is prefixed with `aztecnr:<name>(<addrAbbrev>)`.
346
+ */ async #getAztecnrLogger() {
347
+ if (!this.aztecnrLogger) {
348
+ // Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
349
+ // to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
350
+ this.aztecnrLogger = await createContractLogger(this.contractAddress, (addr)=>this.contractStore.getDebugContractName(addr), 'aztecnr', {
351
+ instanceId: this.jobId
352
+ });
353
+ }
354
+ return this.aztecnrLogger;
355
+ }
356
+ async log(level, message, fields) {
258
357
  if (!LogLevels[level]) {
259
- throw new Error(`Invalid debug log level: ${level}`);
358
+ throw new Error(`Invalid log level: ${level}`);
260
359
  }
261
- const levelName = LogLevels[level];
262
- this.aztecNrDebugLog[levelName](`${applyStringFormatting(message, fields)}`);
263
- }
264
- async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot) {
265
- const logService = new LogService(this.aztecNode, this.anchorBlockStore, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId);
266
- const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
267
- // It is acceptable to run the following operations in parallel for several reasons:
268
- // 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
269
- // which is then processed in Noir after this handler returns.
270
- // 2. Even if syncTaggedLogs did write to the note store, it would not cause inconsistent state.
271
- await Promise.all([
272
- logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes),
273
- noteService.syncNoteNullifiers(this.contractAddress)
274
- ]);
360
+ const { kind, message: strippedMessage } = stripAztecnrLogPrefix(message);
361
+ const logger = kind == 'aztecnr' ? await this.#getAztecnrLogger() : await this.#getContractLogger();
362
+ logContractMessage(logger, LogLevels[level], strippedMessage, fields);
363
+ }
364
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
365
+ async getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope) {
366
+ const logService = this.#createLogService();
367
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
368
+ await this.capsuleService.appendToCapsuleArray(this.contractAddress, pendingTaggedLogArrayBaseSlot, logs.map((log)=>log.toFields()), this.jobId, scope);
369
+ }
370
+ /** Fetches pending tagged logs into a freshly allocated ephemeral array and returns its base slot. */ async getPendingTaggedLogsV2(scope) {
371
+ const logService = this.#createLogService();
372
+ const logs = await logService.fetchTaggedLogs(this.contractAddress, scope);
373
+ return this.ephemeralArrayService.newArray(logs.map((log)=>log.toFields()));
374
+ }
375
+ #createLogService() {
376
+ return new LogService(this.aztecNode, this.anchorBlockHeader, this.l2TipsStore, this.keyStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId, this.logger.getBindings());
275
377
  }
276
378
  /**
277
- * Validates all note and event validation requests enqueued via `enqueue_note_for_validation` and
278
- * `enqueue_event_for_validation`, inserting them into the note database and event store respectively, making them
279
- * queryable via `get_notes` and `getPrivateEvents`.
379
+ * Legacy: validates note/event requests stored in capsule arrays.
280
380
  *
281
- * This automatically clears both validation request queues, so no further work needs to be done by the caller.
282
- * @param contractAddress - The address of the contract that the logs are tagged for.
283
- * @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
284
- * @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
285
- */ async utilityValidateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot) {
381
+ * Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
382
+ */ async validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope) {
286
383
  // TODO(#10727): allow other contracts to store notes
287
384
  if (!this.contractAddress.equals(contractAddress)) {
288
385
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
289
386
  }
290
- // We read all note and event validation requests and process them all concurrently. This makes the process much
291
- // faster as we don't need to wait for the network round-trip.
292
- const noteValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)).map(NoteValidationRequest.fromFields);
293
- const eventValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)).map(EventValidationRequest.fromFields);
294
- const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
295
- const noteStorePromises = noteValidationRequests.map((request)=>noteService.validateAndStoreNote(request.contractAddress, request.owner, request.storageSlot, request.randomness, request.noteNonce, request.content, request.noteHash, request.nullifier, request.txHash, request.recipient));
296
- const eventService = new EventService(this.anchorBlockStore, this.aztecNode, this.privateEventStore, this.jobId);
297
- const eventStorePromises = eventValidationRequests.map((request)=>eventService.validateAndStoreEvent(request.contractAddress, request.eventTypeId, request.randomness, request.serializedEvent, request.eventCommitment, request.txHash, request.recipient));
387
+ const noteValidationRequests = (await this.capsuleService.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId, scope)).map((fields)=>NoteValidationRequest.fromFields(fields, maxNotePackedLen));
388
+ const eventValidationRequests = (await this.capsuleService.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId, scope)).map((fields)=>EventValidationRequest.fromFields(fields, maxEventSerializedLen));
389
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
390
+ await this.capsuleService.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, [], this.jobId, scope);
391
+ await this.capsuleService.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId, scope);
392
+ }
393
+ async validateAndStoreEnqueuedNotesAndEventsV2(noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope) {
394
+ const noteValidationRequests = this.ephemeralArrayService.readArrayAt(noteValidationRequestsArrayBaseSlot).map((fields)=>NoteValidationRequest.fromFields(fields, maxNotePackedLen));
395
+ const eventValidationRequests = this.ephemeralArrayService.readArrayAt(eventValidationRequestsArrayBaseSlot).map((fields)=>EventValidationRequest.fromFields(fields, maxEventSerializedLen));
396
+ await this.#processValidationRequests(noteValidationRequests, eventValidationRequests, scope);
397
+ }
398
+ /**
399
+ * Dispatches note and event validation requests to the service layer.
400
+ *
401
+ * This function is an auxiliary to support legacy (capsule backed) and new (ephemeral array backed) versions of the
402
+ * `validateAndStoreEnqueuedNotesAndEvents` oracle.
403
+ */ async #processValidationRequests(noteValidationRequests, eventValidationRequests, scope) {
404
+ const txEffects = await this.#fetchTxEffects([
405
+ ...noteValidationRequests.map((r)=>r.txHash),
406
+ ...eventValidationRequests.map((r)=>r.txHash)
407
+ ]);
408
+ const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
409
+ const eventService = new EventService(this.anchorBlockHeader, this.aztecNode, this.privateEventStore, this.jobId);
298
410
  await Promise.all([
299
- ...noteStorePromises,
300
- ...eventStorePromises
411
+ noteService.validateAndStoreNotes(noteValidationRequests, scope, txEffects),
412
+ eventService.validateAndStoreEvents(eventValidationRequests, scope, txEffects)
301
413
  ]);
302
- // Requests are cleared once we're done.
303
- await this.capsuleStore.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, [], this.jobId);
304
- await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
305
414
  }
306
- async utilityBulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot) {
415
+ async getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope) {
307
416
  // TODO(#10727): allow other contracts to process partial notes
308
417
  if (!this.contractAddress.equals(contractAddress)) {
309
418
  throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
310
419
  }
311
420
  // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
312
421
  // don't need to wait for the network round-trip.
313
- const logRetrievalRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId)).map(LogRetrievalRequest.fromFields);
314
- const logService = new LogService(this.aztecNode, this.anchorBlockStore, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId);
315
- const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
422
+ const logRetrievalRequests = (await this.capsuleService.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId, scope)).map(LogRetrievalRequest.fromFields);
423
+ const logService = this.#createLogService();
424
+ const maybeLogRetrievalResponses = await logService.fetchLogsByTag(contractAddress, logRetrievalRequests);
316
425
  // Requests are cleared once we're done.
317
- await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, [], this.jobId);
426
+ await this.capsuleService.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, [], this.jobId, scope);
318
427
  // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
319
- await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalResponsesArrayBaseSlot, maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption), this.jobId);
428
+ await this.capsuleService.setCapsuleArray(contractAddress, logRetrievalResponsesArrayBaseSlot, maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption), this.jobId, scope);
320
429
  }
321
- utilityStoreCapsule(contractAddress, slot, capsule) {
430
+ async getLogsByTagV2(requestArrayBaseSlot) {
431
+ const logRetrievalRequests = this.ephemeralArrayService.readArrayAt(requestArrayBaseSlot).map(LogRetrievalRequest.fromFields);
432
+ const logService = this.#createLogService();
433
+ const maybeLogRetrievalResponses = await logService.fetchLogsByTag(this.contractAddress, logRetrievalRequests);
434
+ return this.ephemeralArrayService.newArray(maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption));
435
+ }
436
+ // Deprecated, only kept for backwards compatibility until Alpha v5 rolls out.
437
+ async getMessageContextsByTxHash(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot, scope) {
438
+ try {
439
+ if (!this.contractAddress.equals(contractAddress)) {
440
+ throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
441
+ }
442
+ // TODO(@mverzilli): this is a prime example of where using an ephemeral array would make much more sense, we don't
443
+ // need scopes here, we just need a bit of shared memory to cross boundaries between Noir and TS.
444
+ // At the same time, we don't want to allow any global scope access other than where backwards compatibility
445
+ // forces us to. Hence we need the scope here to be artificial.
446
+ const requestCapsules = await this.capsuleService.readCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, this.jobId, scope);
447
+ const txHashes = requestCapsules.map((fields, i)=>{
448
+ if (fields.length !== 1) {
449
+ throw new Error(`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`);
450
+ }
451
+ return fields[0];
452
+ });
453
+ const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(txHashes, this.anchorBlockHeader.getBlockNumber());
454
+ // Leave response in response capsule array.
455
+ await this.capsuleService.setCapsuleArray(contractAddress, messageContextResponsesArrayBaseSlot, maybeMessageContexts.map(MessageContext.toSerializedOption), this.jobId, scope);
456
+ } finally{
457
+ await this.capsuleService.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId, scope);
458
+ }
459
+ }
460
+ /** Reads tx hash requests from an ephemeral array, resolves their contexts, and returns the response slot. */ async getMessageContextsByTxHashV2(requestArrayBaseSlot) {
461
+ const requestFields = this.ephemeralArrayService.readArrayAt(requestArrayBaseSlot);
462
+ const txHashes = requestFields.map((fields, i)=>{
463
+ if (fields.length !== 1) {
464
+ throw new Error(`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`);
465
+ }
466
+ return fields[0];
467
+ });
468
+ const maybeMessageContexts = await this.messageContextService.getMessageContextsByTxHash(txHashes, this.anchorBlockHeader.getBlockNumber());
469
+ return this.ephemeralArrayService.newArray(maybeMessageContexts.map(MessageContext.toSerializedOption));
470
+ }
471
+ /**
472
+ * Fetches the effects of a transaction by its hash. Returns null if the tx is not found or is beyond the anchor
473
+ * block.
474
+ */ async getTxEffect(txHash) {
475
+ if (txHash.hash.isZero()) {
476
+ throw new Error('Invalid tx hash passed into aztec_utl_getTxEffect oracle handler');
477
+ }
478
+ const txEffect = await this.aztecNode.getTxEffect(txHash);
479
+ if (!txEffect || txEffect.l2BlockNumber > this.anchorBlockHeader.getBlockNumber()) {
480
+ return null;
481
+ }
482
+ return txEffect.data;
483
+ }
484
+ setCapsule(contractAddress, slot, capsule, scope) {
322
485
  if (!contractAddress.equals(this.contractAddress)) {
323
486
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
324
487
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
325
488
  }
326
- this.capsuleStore.storeCapsule(this.contractAddress, slot, capsule, this.jobId);
327
- return Promise.resolve();
489
+ this.capsuleService.setCapsule(contractAddress, slot, capsule, this.jobId, scope);
328
490
  }
329
- async utilityLoadCapsule(contractAddress, slot) {
491
+ getCapsule(contractAddress, slot, scope) {
330
492
  if (!contractAddress.equals(this.contractAddress)) {
331
493
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
332
494
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
333
495
  }
334
- return(// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
335
- this.capsules.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ?? await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId));
496
+ return this.capsuleService.getCapsule(contractAddress, slot, this.jobId, scope, this.capsules);
336
497
  }
337
- utilityDeleteCapsule(contractAddress, slot) {
498
+ deleteCapsule(contractAddress, slot, scope) {
338
499
  if (!contractAddress.equals(this.contractAddress)) {
339
500
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
340
501
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
341
502
  }
342
- this.capsuleStore.deleteCapsule(this.contractAddress, slot, this.jobId);
343
- return Promise.resolve();
503
+ this.capsuleService.deleteCapsule(contractAddress, slot, this.jobId, scope);
344
504
  }
345
- utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
505
+ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope) {
346
506
  if (!contractAddress.equals(this.contractAddress)) {
347
507
  // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
348
508
  throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
349
509
  }
350
- return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
510
+ return this.capsuleService.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, this.jobId, scope);
511
+ }
512
+ /**
513
+ * Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
514
+ * stored notes or events are discovered.
515
+ */ setContractSyncCacheInvalid(contractAddress, scopes) {
516
+ if (!contractAddress.equals(this.contractAddress)) {
517
+ throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
518
+ }
519
+ this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
351
520
  }
352
521
  // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
353
- utilityAes128Decrypt(ciphertext, iv, symKey) {
522
+ decryptAes128(ciphertext, iv, symKey) {
354
523
  const aes128 = new Aes128();
355
524
  return aes128.decryptBufferCBC(ciphertext, iv, symKey);
356
525
  }
357
526
  /**
358
- * Retrieves the shared secret for a given address and ephemeral public key.
527
+ * Retrieves the app-siloed shared secret for a given address and ephemeral public key.
359
528
  * @param address - The address to get the secret for.
360
529
  * @param ephPk - The ephemeral public key to get the secret for.
361
- * @returns The secret for the given address.
362
- */ utilityGetSharedSecret(address, ephPk) {
363
- return this.getSharedSecret(address, ephPk);
364
- }
365
- async getSharedSecret(address, ephPk) {
366
- // TODO(#12656): return an app-siloed secret
367
- const recipientCompleteAddress = await this.getCompleteAddress(address);
530
+ * @param contractAddress - The contract address for app-siloing (validated against execution context).
531
+ * @returns The app-siloed shared secret as a Field.
532
+ */ async getSharedSecret(address, ephPk, contractAddress) {
533
+ if (!contractAddress.equals(this.contractAddress)) {
534
+ throw new Error(`getSharedSecret called with contract address ${contractAddress}, expected ${this.contractAddress}`);
535
+ }
536
+ const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
368
537
  const ivskM = await this.keyStore.getMasterSecretKey(recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey);
369
538
  const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
370
- return deriveEcdhSharedSecret(addressSecret, ephPk);
539
+ return deriveAppSiloedSharedSecret(addressSecret, ephPk, this.contractAddress);
540
+ }
541
+ pushEphemeral(slot, elements) {
542
+ return this.ephemeralArrayService.push(slot, elements);
543
+ }
544
+ popEphemeral(slot) {
545
+ return this.ephemeralArrayService.pop(slot);
546
+ }
547
+ getEphemeral(slot, index) {
548
+ return this.ephemeralArrayService.get(slot, index);
549
+ }
550
+ setEphemeral(slot, index, elements) {
551
+ this.ephemeralArrayService.set(slot, index, elements);
552
+ }
553
+ getEphemeralLen(slot) {
554
+ return this.ephemeralArrayService.len(slot);
555
+ }
556
+ removeEphemeral(slot, index) {
557
+ this.ephemeralArrayService.remove(slot, index);
558
+ }
559
+ clearEphemeral(slot) {
560
+ this.ephemeralArrayService.clear(slot);
561
+ }
562
+ emitOffchainEffect(data) {
563
+ this.offchainEffects.push({
564
+ data,
565
+ contractAddress: this.contractAddress
566
+ });
567
+ return Promise.resolve();
568
+ }
569
+ /** Executes another utility function from within this one and returns its serialized return values. */ async callUtilityFunction(targetContractAddress, functionSelector, args) {
570
+ const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(targetContractAddress, functionSelector);
571
+ if (!targetContractAddress.equals(this.contractAddress)) {
572
+ const request = {
573
+ caller: this.contractAddress,
574
+ target: targetContractAddress,
575
+ functionSelector,
576
+ functionName: targetArtifact.name,
577
+ args,
578
+ callerContext: 'isPrivate' in this ? 'private' : 'utility'
579
+ };
580
+ const response = this.hooks ? await this.hooks.authorizeUtilityCall(request) : {
581
+ authorized: false,
582
+ reason: 'No execution hooks configured'
583
+ };
584
+ if (!response.authorized) {
585
+ const reason = response.reason ? `: ${response.reason}` : '';
586
+ throw new Error(`Cross-contract utility call denied${reason}. ${this.contractAddress} attempted to call ` + `${targetContractAddress}:${functionSelector} (${targetArtifact.name}). ` + `See https://docs.aztec.network/errors/11`);
587
+ }
588
+ await this.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, this.utilityExecutor, this.anchorBlockHeader, this.jobId, this.scopes);
589
+ }
590
+ this.logger.debug(`Calling nested utility function ${targetContractAddress}:${functionSelector} from ${this.contractAddress}`);
591
+ const nestedOracle = new UtilityExecutionOracle({
592
+ contractAddress: targetContractAddress,
593
+ authWitnesses: this.authWitnesses,
594
+ capsules: this.capsules,
595
+ anchorBlockHeader: this.anchorBlockHeader,
596
+ contractStore: this.contractStore,
597
+ noteStore: this.noteStore,
598
+ keyStore: this.keyStore,
599
+ addressStore: this.addressStore,
600
+ aztecNode: this.aztecNode,
601
+ recipientTaggingStore: this.recipientTaggingStore,
602
+ senderAddressBookStore: this.senderAddressBookStore,
603
+ capsuleService: this.capsuleService,
604
+ privateEventStore: this.privateEventStore,
605
+ messageContextService: this.messageContextService,
606
+ contractSyncService: this.contractSyncService,
607
+ l2TipsStore: this.l2TipsStore,
608
+ jobId: this.jobId,
609
+ scopes: this.scopes,
610
+ simulator: this.simulator,
611
+ hooks: this.hooks,
612
+ utilityExecutor: this.utilityExecutor,
613
+ log: this.logger
614
+ });
615
+ const initialWitness = toACVMWitness(0, args);
616
+ const acvmCallback = new Oracle(nestedOracle);
617
+ const acirExecutionResult = await this.simulator.executeUserCircuit(initialWitness, targetArtifact, acvmCallback.toACIRCallback()).catch((err)=>{
618
+ err.message = resolveAssertionMessageFromError(err, targetArtifact);
619
+ throw new ExecutionError(err.message, {
620
+ contractAddress: targetContractAddress,
621
+ functionSelector
622
+ }, extractCallStack(err, targetArtifact.debug), {
623
+ cause: err
624
+ });
625
+ });
626
+ return witnessMapToFields(acirExecutionResult.returnWitness);
627
+ }
628
+ /** Returns offchain effects collected during execution. */ getOffchainEffects() {
629
+ return this.offchainEffects;
630
+ }
631
+ /**
632
+ * Fetches tx effects for the given hashes in parallel, deduplicating repeated hashes so each tx is only requested
633
+ * once. Returns a map keyed by `TxHash.toString()`; hashes for which the node has no tx effect are omitted.
634
+ */ async #fetchTxEffects(txHashes) {
635
+ const uniqueTxHashes = uniqueBy(txHashes, (h)=>h.toString());
636
+ const fetched = await Promise.all(uniqueTxHashes.map((h)=>this.aztecNode.getTxEffect(h)));
637
+ return new Map(uniqueTxHashes.map((h, i)=>[
638
+ h.toString(),
639
+ fetched[i]
640
+ ]).filter((entry)=>entry[1] !== undefined));
641
+ }
642
+ /** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */ async #queryWithBlockHashNotAfterAnchor(blockHash, query) {
643
+ // Most contracts query state at the "current" block, which is the anchor. Skip the validation when we can.
644
+ const anchorHash = await this.anchorBlockHeader.hash();
645
+ if (blockHash.equals(anchorHash)) {
646
+ return query();
647
+ }
648
+ const [response] = await Promise.all([
649
+ query(),
650
+ (async ()=>{
651
+ const header = await this.aztecNode.getBlockHeader(blockHash);
652
+ if (!header) {
653
+ throw new Error(`Could not find block header for block hash ${blockHash}`);
654
+ }
655
+ if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
656
+ throw new Error(`Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${anchorHash}).`);
657
+ }
658
+ })()
659
+ ]);
660
+ return response;
371
661
  }
372
662
  }