@aztec/pxe 5.0.0-rc.1 → 5.0.0

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 (297) hide show
  1. package/dest/block_synchronizer/block_stream_source.d.ts +5 -5
  2. package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_stream_source.js +4 -29
  4. package/dest/block_synchronizer/block_synchronizer.d.ts +16 -12
  5. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  6. package/dest/block_synchronizer/block_synchronizer.js +49 -15
  7. package/dest/config/index.d.ts +2 -1
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/index.js +1 -0
  10. package/dest/contract/contract_class_service.d.ts +31 -0
  11. package/dest/contract/contract_class_service.d.ts.map +1 -0
  12. package/dest/contract/contract_class_service.js +68 -0
  13. package/dest/{contract_sync → contract}/contract_sync_service.d.ts +7 -6
  14. package/dest/contract/contract_sync_service.d.ts.map +1 -0
  15. package/dest/{contract_sync → contract}/contract_sync_service.js +10 -30
  16. package/dest/contract/helpers.d.ts +7 -0
  17. package/dest/contract/helpers.d.ts.map +1 -0
  18. package/dest/contract/helpers.js +20 -0
  19. package/dest/contract_function_simulator/anchored_contract_data.d.ts +36 -0
  20. package/dest/contract_function_simulator/anchored_contract_data.d.ts.map +1 -0
  21. package/dest/contract_function_simulator/anchored_contract_data.js +54 -0
  22. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +39 -0
  23. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +1 -0
  24. package/dest/contract_function_simulator/aztec_node_read_cache.js +60 -0
  25. package/dest/contract_function_simulator/contract_function_simulator.d.ts +19 -18
  26. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  27. package/dest/contract_function_simulator/contract_function_simulator.js +52 -31
  28. package/dest/contract_function_simulator/execution_note_cache.d.ts +3 -9
  29. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
  30. package/dest/contract_function_simulator/execution_note_cache.js +8 -28
  31. package/dest/contract_function_simulator/index.d.ts +17 -9
  32. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  33. package/dest/contract_function_simulator/index.js +4 -7
  34. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +8 -27
  35. package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -1
  36. package/dest/contract_function_simulator/noir-structs/bounded_vec.js +8 -23
  37. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts +9 -0
  38. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.d.ts.map +1 -0
  39. package/dest/contract_function_simulator/noir-structs/contract_class_log_data.js +1 -0
  40. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts +7 -0
  41. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.d.ts.map +1 -0
  42. package/dest/contract_function_simulator/noir-structs/embedded_curve_point.js +1 -0
  43. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
  44. package/dest/contract_function_simulator/noir-structs/fact.d.ts +16 -0
  45. package/dest/contract_function_simulator/noir-structs/fact.d.ts.map +1 -0
  46. package/dest/contract_function_simulator/noir-structs/fact.js +6 -0
  47. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts +27 -0
  48. package/dest/contract_function_simulator/noir-structs/fact_collection.d.ts.map +1 -0
  49. package/dest/contract_function_simulator/noir-structs/fact_collection.js +31 -0
  50. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +11 -12
  51. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  52. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +6 -49
  53. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +10 -8
  54. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
  55. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -60
  56. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +2 -2
  57. package/dest/contract_function_simulator/noir-structs/option.d.ts +9 -11
  58. package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -1
  59. package/dest/contract_function_simulator/noir-structs/option.js +18 -13
  60. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts +11 -0
  61. package/dest/contract_function_simulator/noir-structs/origin_block.d.ts.map +1 -0
  62. package/dest/contract_function_simulator/noir-structs/origin_block.js +5 -0
  63. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts +11 -0
  64. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.d.ts.map +1 -0
  65. package/dest/contract_function_simulator/noir-structs/pending_tagged_log.js +4 -0
  66. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts +6 -9
  67. package/dest/contract_function_simulator/noir-structs/provided_secret.d.ts.map +1 -1
  68. package/dest/contract_function_simulator/noir-structs/provided_secret.js +1 -14
  69. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts +28 -0
  70. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.d.ts.map +1 -0
  71. package/dest/contract_function_simulator/noir-structs/resolved_tagging_strategy.js +50 -0
  72. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +21 -0
  73. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -0
  74. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +50 -0
  75. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +14 -0
  76. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -0
  77. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +5 -0
  78. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +6 -11
  79. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
  80. package/dest/contract_function_simulator/noir-structs/utility_context.js +1 -20
  81. package/dest/contract_function_simulator/oracle/acir_callback.d.ts +7 -2
  82. package/dest/contract_function_simulator/oracle/acir_callback.d.ts.map +1 -1
  83. package/dest/contract_function_simulator/oracle/acir_callback.js +55 -11
  84. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts +39 -0
  85. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.d.ts.map +1 -0
  86. package/dest/contract_function_simulator/oracle/legacy_oracle_registry.js +107 -0
  87. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -14
  88. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
  89. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -24
  90. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +86 -8
  91. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  92. package/dest/contract_function_simulator/oracle/oracle_registry.js +168 -18
  93. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +123 -40
  94. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  95. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +947 -264
  96. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +21 -8
  97. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  98. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +126 -16
  99. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +63 -33
  100. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  101. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +175 -90
  102. package/dest/debug/pxe_debug_utils.d.ts +2 -2
  103. package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
  104. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  105. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  106. package/dest/entrypoints/client/bundle/utils.js +3 -2
  107. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  108. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  109. package/dest/entrypoints/client/lazy/utils.js +3 -2
  110. package/dest/entrypoints/pxe_creation_options.d.ts +8 -2
  111. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  112. package/dest/entrypoints/server/index.d.ts +5 -3
  113. package/dest/entrypoints/server/index.d.ts.map +1 -1
  114. package/dest/entrypoints/server/index.js +3 -2
  115. package/dest/entrypoints/server/utils.d.ts +1 -1
  116. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  117. package/dest/entrypoints/server/utils.js +3 -1
  118. package/dest/error_enriching.d.ts +5 -3
  119. package/dest/error_enriching.d.ts.map +1 -1
  120. package/dest/error_enriching.js +13 -11
  121. package/dest/hooks/execution_hooks.d.ts +27 -7
  122. package/dest/hooks/execution_hooks.d.ts.map +1 -1
  123. package/dest/hooks/execution_hooks.js +3 -3
  124. package/dest/hooks/index.d.ts +4 -3
  125. package/dest/hooks/index.d.ts.map +1 -1
  126. package/dest/hooks/index.js +1 -0
  127. package/dest/hooks/resolve_custom_request.d.ts +23 -0
  128. package/dest/hooks/resolve_custom_request.d.ts.map +1 -0
  129. package/dest/hooks/resolve_custom_request.js +3 -0
  130. package/dest/hooks/resolve_tagging_secret_strategy.d.ts +50 -0
  131. package/dest/hooks/resolve_tagging_secret_strategy.d.ts.map +1 -0
  132. package/dest/hooks/resolve_tagging_secret_strategy.js +3 -0
  133. package/dest/logs/log_service.d.ts +7 -6
  134. package/dest/logs/log_service.d.ts.map +1 -1
  135. package/dest/logs/log_service.js +79 -28
  136. package/dest/messages/tx_resolver_service.d.ts +17 -0
  137. package/dest/messages/tx_resolver_service.d.ts.map +1 -0
  138. package/dest/messages/{message_context_service.js → tx_resolver_service.js} +8 -8
  139. package/dest/oracle_version.d.ts +3 -3
  140. package/dest/oracle_version.js +3 -3
  141. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +1 -1
  142. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
  143. package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +6 -2
  144. package/dest/private_kernel/hints/test_utils.js +1 -1
  145. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  146. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  147. package/dest/private_kernel/private_kernel_execution_prover.js +17 -36
  148. package/dest/private_kernel/private_kernel_oracle.d.ts +4 -2
  149. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  150. package/dest/private_kernel/private_kernel_oracle.js +17 -5
  151. package/dest/pxe.d.ts +109 -47
  152. package/dest/pxe.d.ts.map +1 -1
  153. package/dest/pxe.js +222 -139
  154. package/dest/storage/allowed_scopes.d.ts +6 -0
  155. package/dest/storage/allowed_scopes.d.ts.map +1 -0
  156. package/dest/storage/allowed_scopes.js +7 -0
  157. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +1 -1
  158. package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -1
  159. package/dest/storage/backwards_compatibility_tests/schema_tests.js +114 -37
  160. package/dest/storage/capsule_store/capsule_service.d.ts +1 -1
  161. package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -1
  162. package/dest/storage/capsule_store/capsule_service.js +6 -9
  163. package/dest/storage/contract_store/contract_store.d.ts +27 -24
  164. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  165. package/dest/storage/contract_store/contract_store.js +64 -75
  166. package/dest/storage/fact_store/fact_service.d.ts +22 -0
  167. package/dest/storage/fact_store/fact_service.d.ts.map +1 -0
  168. package/dest/storage/fact_store/fact_service.js +45 -0
  169. package/dest/storage/fact_store/fact_store.d.ts +95 -0
  170. package/dest/storage/fact_store/fact_store.d.ts.map +1 -0
  171. package/dest/storage/fact_store/fact_store.js +408 -0
  172. package/dest/storage/fact_store/fact_store_keys.d.ts +34 -0
  173. package/dest/storage/fact_store/fact_store_keys.d.ts.map +1 -0
  174. package/dest/storage/fact_store/fact_store_keys.js +50 -0
  175. package/dest/storage/fact_store/index.d.ts +6 -0
  176. package/dest/storage/fact_store/index.d.ts.map +1 -0
  177. package/dest/storage/fact_store/index.js +4 -0
  178. package/dest/storage/fact_store/origin_state.d.ts +57 -0
  179. package/dest/storage/fact_store/origin_state.d.ts.map +1 -0
  180. package/dest/storage/fact_store/origin_state.js +53 -0
  181. package/dest/storage/fact_store/stored_fact.d.ts +32 -0
  182. package/dest/storage/fact_store/stored_fact.d.ts.map +1 -0
  183. package/dest/storage/fact_store/stored_fact.js +64 -0
  184. package/dest/storage/index.d.ts +2 -1
  185. package/dest/storage/index.d.ts.map +1 -1
  186. package/dest/storage/index.js +1 -0
  187. package/dest/storage/metadata.d.ts +2 -2
  188. package/dest/storage/metadata.d.ts.map +1 -1
  189. package/dest/storage/metadata.js +1 -1
  190. package/dest/storage/open_pxe_stores.d.ts +5 -3
  191. package/dest/storage/open_pxe_stores.d.ts.map +1 -1
  192. package/dest/storage/open_pxe_stores.js +5 -3
  193. package/dest/storage/tagging_store/index.d.ts +2 -2
  194. package/dest/storage/tagging_store/index.d.ts.map +1 -1
  195. package/dest/storage/tagging_store/index.js +1 -1
  196. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts +51 -0
  197. package/dest/storage/tagging_store/tagging_secret_sources_store.d.ts.map +1 -0
  198. package/dest/storage/tagging_store/tagging_secret_sources_store.js +105 -0
  199. package/dest/tagging/constants.d.ts +2 -2
  200. package/dest/tagging/constants.d.ts.map +1 -1
  201. package/dest/tagging/constants.js +18 -9
  202. package/package.json +17 -17
  203. package/src/block_synchronizer/block_stream_source.ts +6 -45
  204. package/src/block_synchronizer/block_synchronizer.ts +65 -24
  205. package/src/config/index.ts +1 -0
  206. package/src/contract/contract_class_service.ts +83 -0
  207. package/src/{contract_sync → contract}/contract_sync_service.ts +18 -37
  208. package/src/contract/helpers.ts +35 -0
  209. package/src/contract_function_simulator/anchored_contract_data.ts +74 -0
  210. package/src/contract_function_simulator/aztec_node_read_cache.ts +89 -0
  211. package/src/contract_function_simulator/contract_function_simulator.ts +86 -43
  212. package/src/contract_function_simulator/execution_note_cache.ts +7 -28
  213. package/src/contract_function_simulator/index.ts +24 -9
  214. package/src/contract_function_simulator/noir-structs/bounded_vec.ts +12 -24
  215. package/src/contract_function_simulator/noir-structs/contract_class_log_data.ts +9 -0
  216. package/src/contract_function_simulator/noir-structs/embedded_curve_point.ts +4 -0
  217. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
  218. package/src/contract_function_simulator/noir-structs/fact.ts +13 -0
  219. package/src/contract_function_simulator/noir-structs/fact_collection.ts +64 -0
  220. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +20 -46
  221. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +13 -60
  222. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
  223. package/src/contract_function_simulator/noir-structs/option.ts +17 -11
  224. package/src/contract_function_simulator/noir-structs/origin_block.ts +8 -0
  225. package/src/contract_function_simulator/noir-structs/pending_tagged_log.ts +12 -0
  226. package/src/contract_function_simulator/noir-structs/provided_secret.ts +4 -15
  227. package/src/contract_function_simulator/noir-structs/resolved_tagging_strategy.ts +66 -0
  228. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +53 -0
  229. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +15 -0
  230. package/src/contract_function_simulator/noir-structs/utility_context.ts +5 -17
  231. package/src/contract_function_simulator/oracle/acir_callback.ts +58 -12
  232. package/src/contract_function_simulator/oracle/legacy_oracle_registry.ts +147 -0
  233. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +6 -21
  234. package/src/contract_function_simulator/oracle/oracle_registry.ts +119 -86
  235. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +659 -248
  236. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +155 -24
  237. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +300 -115
  238. package/src/debug/pxe_debug_utils.ts +1 -1
  239. package/src/entrypoints/client/bundle/utils.ts +3 -2
  240. package/src/entrypoints/client/lazy/utils.ts +3 -2
  241. package/src/entrypoints/pxe_creation_options.ts +7 -1
  242. package/src/entrypoints/server/index.ts +5 -2
  243. package/src/entrypoints/server/utils.ts +3 -1
  244. package/src/error_enriching.ts +27 -11
  245. package/src/hooks/execution_hooks.ts +28 -8
  246. package/src/hooks/index.ts +8 -2
  247. package/src/hooks/resolve_custom_request.ts +24 -0
  248. package/src/hooks/resolve_tagging_secret_strategy.ts +60 -0
  249. package/src/logs/log_service.ts +91 -37
  250. package/src/messages/{message_context_service.ts → tx_resolver_service.ts} +16 -9
  251. package/src/oracle_version.ts +3 -3
  252. package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +11 -1
  253. package/src/private_kernel/hints/test_utils.ts +1 -1
  254. package/src/private_kernel/private_kernel_execution_prover.ts +22 -52
  255. package/src/private_kernel/private_kernel_oracle.ts +23 -4
  256. package/src/pxe.ts +320 -158
  257. package/src/storage/allowed_scopes.ts +14 -0
  258. package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +6 -6
  259. package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +1 -1
  260. package/src/storage/backwards_compatibility_tests/__snapshots__/FactStore.json +40 -0
  261. package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +12 -12
  262. package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +1 -1
  263. package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +11 -3
  264. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +12 -4
  265. package/src/storage/backwards_compatibility_tests/__snapshots__/TaggingSecretSourcesStore.json +30 -0
  266. package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +21 -5
  267. package/src/storage/backwards_compatibility_tests/schema_tests.ts +125 -36
  268. package/src/storage/capsule_store/capsule_service.ts +8 -13
  269. package/src/storage/contract_store/contract_store.ts +86 -93
  270. package/src/storage/fact_store/fact_service.ts +69 -0
  271. package/src/storage/fact_store/fact_store.ts +487 -0
  272. package/src/storage/fact_store/fact_store_keys.ts +75 -0
  273. package/src/storage/fact_store/index.ts +14 -0
  274. package/src/storage/fact_store/origin_state.ts +75 -0
  275. package/src/storage/fact_store/stored_fact.ts +80 -0
  276. package/src/storage/index.ts +1 -0
  277. package/src/storage/metadata.ts +1 -1
  278. package/src/storage/open_pxe_stores.ts +6 -3
  279. package/src/storage/tagging_store/index.ts +1 -1
  280. package/src/storage/tagging_store/tagging_secret_sources_store.ts +138 -0
  281. package/src/tagging/constants.ts +19 -9
  282. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +0 -6
  283. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +0 -1
  284. package/dest/contract_function_simulator/proxied_contract_data_source.js +0 -51
  285. package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
  286. package/dest/contract_sync/helpers.d.ts +0 -27
  287. package/dest/contract_sync/helpers.d.ts.map +0 -1
  288. package/dest/contract_sync/helpers.js +0 -53
  289. package/dest/messages/message_context_service.d.ts +0 -17
  290. package/dest/messages/message_context_service.d.ts.map +0 -1
  291. package/dest/storage/tagging_store/sender_address_book_store.d.ts +0 -14
  292. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +0 -1
  293. package/dest/storage/tagging_store/sender_address_book_store.js +0 -36
  294. package/src/contract_function_simulator/proxied_contract_data_source.ts +0 -60
  295. package/src/contract_sync/helpers.ts +0 -86
  296. package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +0 -16
  297. package/src/storage/tagging_store/sender_address_book_store.ts +0 -48
@@ -2,6 +2,7 @@
2
2
  import { CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
3
3
  import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { Point } from '@aztec/foundation/curves/grumpkin';
5
6
  import { EthAddress } from '@aztec/foundation/eth-address';
6
7
  import type { Tuple } from '@aztec/foundation/serialize';
7
8
  import { KeyStore } from '@aztec/key-store';
@@ -14,9 +15,10 @@ import { BlockHash, Body, GENESIS_BLOCK_HEADER_HASH, L2Block } from '@aztec/stdl
14
15
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
15
16
  import { CompleteAddress, SerializableContractInstance } from '@aztec/stdlib/contract';
16
17
  import { GasFees } from '@aztec/stdlib/gas';
17
- import { PublicKey, PublicKeys } from '@aztec/stdlib/keys';
18
+ import { PublicKey, PublicKeys, deriveKeys } from '@aztec/stdlib/keys';
18
19
  import {
19
20
  AppTaggingSecret,
21
+ AppTaggingSecretKind,
20
22
  ContractClassLog,
21
23
  ContractClassLogFields,
22
24
  PrivateLog,
@@ -39,9 +41,11 @@ import { AddressStore } from '../address_store/address_store.js';
39
41
  import { AnchorBlockStore } from '../anchor_block_store/index.js';
40
42
  import { CapsuleStore } from '../capsule_store/capsule_store.js';
41
43
  import { ContractStore } from '../contract_store/contract_store.js';
44
+ import { FactStore } from '../fact_store/fact_store.js';
45
+ import { FactCollectionKey } from '../fact_store/fact_store_keys.js';
42
46
  import { NoteStore } from '../note_store/note_store.js';
43
47
  import { PrivateEventStore } from '../private_event_store/private_event_store.js';
44
- import { RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '../tagging_store/index.js';
48
+ import { RecipientTaggingStore, SenderTaggingStore, TaggingSecretSourcesStore } from '../tagging_store/index.js';
45
49
  import { snapshotArray, snapshotMap, snapshotSingleton } from './kv_store_snapshot.js';
46
50
 
47
51
  /**
@@ -106,7 +110,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
106
110
  SlotNumber(47),
107
111
  53n,
108
112
  EthAddress.fromField(new Fr(59n)),
109
- AztecAddress.fromBigInt(61n),
113
+ AztecAddress.fromBigIntUnsafe(61n),
110
114
  new GasFees(67n, 71n),
111
115
  ),
112
116
  new Fr(73n),
@@ -125,8 +129,8 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
125
129
  const capsuleStore = new CapsuleStore(kvStore);
126
130
 
127
131
  const jobId = 'fixture-job';
128
- const contractAddress = AztecAddress.fromBigInt(2n);
129
- const scope = AztecAddress.fromBigInt(3n);
132
+ const contractAddress = AztecAddress.fromBigIntUnsafe(2n);
133
+ const scope = AztecAddress.fromBigIntUnsafe(3n);
130
134
 
131
135
  // Three setCapsule calls (2-element, 1-element, 0-element value vector) pin every value-encoding length case.
132
136
  capsuleStore.setCapsule(contractAddress, new Fr(5n), [new Fr(7n), new Fr(11n)], jobId, scope);
@@ -188,7 +192,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
188
192
  new SerializableContractInstance({
189
193
  version: 2,
190
194
  salt: new Fr(73n),
191
- deployer: AztecAddress.fromBigInt(79n),
195
+ deployer: AztecAddress.fromBigIntUnsafe(79n),
192
196
  currentContractClassId: new Fr(83n),
193
197
  originalContractClassId: new Fr(89n),
194
198
  initializationHash: new Fr(97n),
@@ -204,7 +208,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
204
208
  new Fr(71n),
205
209
  new Fr(73n),
206
210
  ),
207
- }).withAddress(AztecAddress.fromBigInt(101n)),
211
+ }).withAddress(AztecAddress.fromBigIntUnsafe(101n)),
208
212
  );
209
213
  },
210
214
  snapshotStore: async kvStore => ({
@@ -214,11 +218,45 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
214
218
  }),
215
219
  },
216
220
 
221
+ {
222
+ name: 'FactStore',
223
+ writeToStore: async kvStore => {
224
+ const factStore = new FactStore(kvStore);
225
+ const jobId = 'fixture-job';
226
+ const contract = AztecAddress.fromBigIntUnsafe(100n);
227
+ const scope = AztecAddress.fromBigIntUnsafe(1n);
228
+ const factCollectionTypeId = new Fr(7n);
229
+ const keyA = FactCollectionKey.from({
230
+ contractAddress: contract,
231
+ scope,
232
+ factCollectionTypeId,
233
+ factCollectionId: new Fr(0xaan),
234
+ });
235
+ const keyB = FactCollectionKey.from({
236
+ contractAddress: contract,
237
+ scope,
238
+ factCollectionTypeId,
239
+ factCollectionId: new Fr(0xbbn),
240
+ });
241
+ // A collection whose only fact is retractable (origin block 6): pruned on a reorg above block 6.
242
+ await factStore.recordFact(keyA, new Fr(3n), [new Fr(5n)], { blockNumber: 6, blockHash: new Fr(2n) }, jobId);
243
+ // A collection with a non-retractable and a retractable fact.
244
+ await factStore.recordFact(keyB, new Fr(1n), [new Fr(9n)], undefined, jobId);
245
+ await factStore.recordFact(keyB, new Fr(2n), [], { blockNumber: 5, blockHash: new Fr(1n) }, jobId);
246
+ await kvStore.transactionAsync(() => factStore.commit(jobId));
247
+ },
248
+ snapshotStore: async kvStore => ({
249
+ facts: await snapshotMap(kvStore.openMap<string, Buffer>('facts')),
250
+ facts_by_collection: await snapshotMap(kvStore.openMultiMap<string, string>('facts_by_collection')),
251
+ facts_by_block: await snapshotMap(kvStore.openMultiMap<number, string>('facts_by_block')),
252
+ }),
253
+ },
254
+
217
255
  {
218
256
  name: 'KeyStore',
219
257
  writeToStore: async kvStore => {
220
258
  const keyStore = new KeyStore(kvStore);
221
- await keyStore.addAccount(new Fr(2n), new Fr(3n));
259
+ await keyStore.addAccount(await deriveKeys(new Fr(2n)), new Fr(3n));
222
260
  },
223
261
  snapshotStore: async kvStore => ({
224
262
  key_store: await snapshotMap(kvStore.openMap<string, Buffer>('key_store')),
@@ -243,9 +281,10 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
243
281
  SlotNumber(19),
244
282
  23n,
245
283
  EthAddress.fromField(new Fr(29n)),
246
- AztecAddress.fromBigInt(31n),
284
+ AztecAddress.fromBigIntUnsafe(31n),
247
285
  new GasFees(37n, 41n),
248
286
  new Fr(43n),
287
+ new Fr(47n),
249
288
  ),
250
289
  [block],
251
290
  CheckpointNumber(47),
@@ -261,7 +300,10 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
261
300
  await l2TipsStore.handleBlockStreamEvent({
262
301
  type: 'chain-checkpointed',
263
302
  block: { number: BlockNumber(71), hash: new Fr(73n).toString() },
264
- checkpoint: publishedCheckpoint,
303
+ checkpoint: {
304
+ number: publishedCheckpoint.checkpoint.number,
305
+ hash: publishedCheckpoint.checkpoint.hash().toString(),
306
+ },
265
307
  });
266
308
  // `'chain-proven'` writes the 'proven' tag. `'finalized'` is omitted because its handler runs delete-before
267
309
  // logic that would depend on the order of preceding events.
@@ -289,17 +331,17 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
289
331
 
290
332
  // Two contracts so `note_nullifiers_by_contract` exhibits both a multi-value row (contractA → {n1, n2}) and a
291
333
  // single-value row (contractB → {n3}).
292
- const contractA = AztecAddress.fromBigInt(2n);
293
- const contractB = AztecAddress.fromBigInt(3n);
294
- const scopeX = AztecAddress.fromBigInt(5n);
295
- const scopeY = AztecAddress.fromBigInt(7n);
334
+ const contractA = AztecAddress.fromBigIntUnsafe(2n);
335
+ const contractB = AztecAddress.fromBigIntUnsafe(3n);
336
+ const scopeX = AztecAddress.fromBigIntUnsafe(5n);
337
+ const scopeY = AztecAddress.fromBigIntUnsafe(7n);
296
338
 
297
339
  // note1: active, will be added under two scopes to exercise the multi-element scopes vector encoding in
298
340
  // `StoredNote.toBuffer`.
299
341
  const note1 = new NoteDao(
300
342
  new Note([new Fr(13n), new Fr(17n), new Fr(19n)]),
301
343
  contractA,
302
- AztecAddress.fromBigInt(23n),
344
+ AztecAddress.fromBigIntUnsafe(23n),
303
345
  new Fr(29n),
304
346
  new Fr(31n),
305
347
  new Fr(37n),
@@ -316,7 +358,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
316
358
  const note2 = new NoteDao(
317
359
  new Note([new Fr(71n), new Fr(73n), new Fr(79n)]),
318
360
  contractA,
319
- AztecAddress.fromBigInt(83n),
361
+ AztecAddress.fromBigIntUnsafe(83n),
320
362
  new Fr(89n),
321
363
  new Fr(97n),
322
364
  new Fr(101n),
@@ -334,7 +376,7 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
334
376
  const note3 = new NoteDao(
335
377
  new Note([new Fr(139n), new Fr(149n), new Fr(151n)]),
336
378
  contractB,
337
- AztecAddress.fromBigInt(157n),
379
+ AztecAddress.fromBigIntUnsafe(157n),
338
380
  new Fr(163n),
339
381
  new Fr(167n),
340
382
  new Fr(173n),
@@ -387,12 +429,12 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
387
429
 
388
430
  // Two (contract, selector) pairs and two block numbers so each multimap exhibits both a multi-value row
389
431
  // (contractA/selectorA → {e1, e2} and blockN1 → {e1, e2}) and a contrasting single-value row.
390
- const contractA = AztecAddress.fromBigInt(2n);
391
- const contractB = AztecAddress.fromBigInt(3n);
432
+ const contractA = AztecAddress.fromBigIntUnsafe(2n);
433
+ const contractB = AztecAddress.fromBigIntUnsafe(3n);
392
434
  const selectorA = EventSelector.fromField(new Fr(5n));
393
435
  const selectorB = EventSelector.fromField(new Fr(7n));
394
- const scopeX = AztecAddress.fromBigInt(11n);
395
- const scopeY = AztecAddress.fromBigInt(13n);
436
+ const scopeX = AztecAddress.fromBigIntUnsafe(11n);
437
+ const scopeY = AztecAddress.fromBigIntUnsafe(13n);
396
438
  const blockN1 = BlockNumber(17);
397
439
  const blockN2 = BlockNumber(19);
398
440
 
@@ -487,12 +529,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
487
529
  const recipientTaggingStore = new RecipientTaggingStore(kvStore);
488
530
 
489
531
  const jobId = 'fixture-job';
490
- const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigInt(3n));
491
- const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigInt(7n));
532
+ const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigIntUnsafe(3n));
533
+ const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigIntUnsafe(7n));
534
+ // A constrained secret keys under the `constrained:` prefix, so the snapshot pins both kinds side by side.
535
+ const secretConstrained = new AppTaggingSecret(
536
+ new Fr(19n),
537
+ AztecAddress.fromBigIntUnsafe(23n),
538
+ AppTaggingSecretKind.CONSTRAINED,
539
+ );
492
540
 
493
541
  await recipientTaggingStore.updateHighestFinalizedIndex(secretA, 11, jobId);
494
542
  await recipientTaggingStore.updateHighestAgedIndex(secretA, 13, jobId);
495
543
  await recipientTaggingStore.updateHighestFinalizedIndex(secretB, 17, jobId);
544
+ await recipientTaggingStore.updateHighestFinalizedIndex(secretConstrained, 11, jobId);
545
+ await recipientTaggingStore.updateHighestAgedIndex(secretConstrained, 13, jobId);
496
546
  await kvStore.transactionAsync(() => recipientTaggingStore.commit(jobId));
497
547
  },
498
548
  snapshotStore: async kvStore => ({
@@ -502,16 +552,35 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
502
552
  },
503
553
 
504
554
  {
505
- name: 'SenderAddressBookStore',
555
+ name: 'TaggingSecretSourcesStore',
506
556
  writeToStore: async kvStore => {
507
- const senderAddressBookStore = new SenderAddressBookStore(kvStore);
557
+ const taggingSecretSourcesStore = new TaggingSecretSourcesStore(kvStore);
558
+
559
+ await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(2n));
560
+ await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(3n));
561
+ await taggingSecretSourcesStore.addSender(AztecAddress.fromBigIntUnsafe(5n));
508
562
 
509
- await senderAddressBookStore.addSender(AztecAddress.fromBigInt(2n));
510
- await senderAddressBookStore.addSender(AztecAddress.fromBigInt(3n));
511
- await senderAddressBookStore.addSender(AztecAddress.fromBigInt(5n));
563
+ await taggingSecretSourcesStore.addSharedSecret(
564
+ AztecAddress.fromBigIntUnsafe(7n),
565
+ 'arbitrary-secret',
566
+ new Point(new Fr(2n), new Fr(3n)),
567
+ );
568
+ await taggingSecretSourcesStore.addSharedSecret(
569
+ AztecAddress.fromBigIntUnsafe(7n),
570
+ 'handshake',
571
+ new Point(new Fr(5n), new Fr(7n)),
572
+ );
573
+ await taggingSecretSourcesStore.addSharedSecret(
574
+ AztecAddress.fromBigIntUnsafe(11n),
575
+ 'arbitrary-secret',
576
+ new Point(new Fr(13n), new Fr(17n)),
577
+ );
512
578
  },
513
579
  snapshotStore: async kvStore => ({
514
- address_book: await snapshotMap(kvStore.openMap<string, true>('address_book')),
580
+ senders: await snapshotMap(kvStore.openMap<string, true>('senders')),
581
+ recipient_shared_secrets: await snapshotMap(
582
+ kvStore.openMultiMap<string, { kind: string; secret: string }>('recipient_shared_secrets'),
583
+ ),
515
584
  }),
516
585
  },
517
586
 
@@ -521,13 +590,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
521
590
  const senderTaggingStore = new SenderTaggingStore(kvStore);
522
591
 
523
592
  const jobId = 'fixture-job';
524
- const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigInt(3n));
525
- const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigInt(7n));
526
- const secretC = new AppTaggingSecret(new Fr(11n), AztecAddress.fromBigInt(13n));
593
+ const secretA = new AppTaggingSecret(new Fr(2n), AztecAddress.fromBigIntUnsafe(3n));
594
+ const secretB = new AppTaggingSecret(new Fr(5n), AztecAddress.fromBigIntUnsafe(7n));
595
+ const secretC = new AppTaggingSecret(new Fr(11n), AztecAddress.fromBigIntUnsafe(13n));
596
+ const secretConstrained = new AppTaggingSecret(
597
+ new Fr(19n),
598
+ AztecAddress.fromBigIntUnsafe(23n),
599
+ AppTaggingSecretKind.CONSTRAINED,
600
+ );
527
601
  const txHashA = TxHash.fromBigInt(17n);
528
602
  const txHashB = TxHash.fromBigInt(19n);
529
603
  const txHashC = TxHash.fromBigInt(23n);
530
604
  const txHashD = TxHash.fromBigInt(29n);
605
+ const txHashE = TxHash.fromBigInt(31n);
606
+ const txHashF = TxHash.fromBigInt(37n);
531
607
 
532
608
  // secretA receives three pending ranges (one per tx); secretB receives one. After finalizing txHashA below,
533
609
  // secretA's array shrinks to two elements (the txHashB and txHashC ranges, both with highestIndex > 3) which
@@ -566,7 +642,20 @@ export const SCHEMA_TESTS: readonly SchemaTest[] = [
566
642
  jobId,
567
643
  );
568
644
 
569
- await senderTaggingStore.finalizePendingIndexes([txHashA], jobId);
645
+ // secretConstrained gets a finalized range (txHashE) plus a surviving higher pending range (txHashF), so the
646
+ // `constrained:` key lands in both pending_indexes and last_finalized_indexes.
647
+ await senderTaggingStore.storePendingIndexes(
648
+ [{ extendedSecret: secretConstrained, lowestIndex: 1, highestIndex: 3 }],
649
+ txHashE,
650
+ jobId,
651
+ );
652
+ await senderTaggingStore.storePendingIndexes(
653
+ [{ extendedSecret: secretConstrained, lowestIndex: 4, highestIndex: 7 }],
654
+ txHashF,
655
+ jobId,
656
+ );
657
+
658
+ await senderTaggingStore.finalizePendingIndexes([txHashA, txHashE], jobId);
570
659
 
571
660
  await kvStore.transactionAsync(() => senderTaggingStore.commit(jobId));
572
661
  },
@@ -617,7 +706,7 @@ function buildL2Block(): L2Block {
617
706
  SlotNumber(181),
618
707
  191n,
619
708
  EthAddress.fromField(new Fr(193n)),
620
- AztecAddress.fromBigInt(197n),
709
+ AztecAddress.fromBigIntUnsafe(197n),
621
710
  new GasFees(199n, 211n),
622
711
  ),
623
712
  new Fr(223n),
@@ -638,10 +727,10 @@ function buildL2Block(): L2Block {
638
727
  3,
639
728
  ),
640
729
  ],
641
- [new PublicLog(AztecAddress.fromBigInt(281n), [new Fr(283n), new Fr(293n)])],
730
+ [new PublicLog(AztecAddress.fromBigIntUnsafe(281n), [new Fr(283n), new Fr(293n)])],
642
731
  [
643
732
  new ContractClassLog(
644
- AztecAddress.fromBigInt(307n),
733
+ AztecAddress.fromBigIntUnsafe(307n),
645
734
  new ContractClassLogFields(paddedFrs([311n, 313n, 317n], CONTRACT_CLASS_LOG_SIZE_IN_FIELDS)),
646
735
  3,
647
736
  ),
@@ -2,6 +2,7 @@ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { Capsule } from '@aztec/stdlib/tx';
4
4
 
5
+ import { assertAllowedScope } from '../allowed_scopes.js';
5
6
  import type { CapsuleStore } from './capsule_store.js';
6
7
 
7
8
  /**
@@ -9,10 +10,15 @@ import type { CapsuleStore } from './capsule_store.js';
9
10
  * allowed scopes list before delegating to the underlying store.
10
11
  */
11
12
  export class CapsuleService {
13
+ private readonly allowedScopes: AztecAddress[];
14
+
12
15
  constructor(
13
16
  private readonly capsuleStore: CapsuleStore,
14
- private readonly allowedScopes: AztecAddress[],
15
- ) {}
17
+ allowedScopes: AztecAddress[],
18
+ ) {
19
+ // The zero address denotes the global capsule scope, which is always permitted.
20
+ this.allowedScopes = [...allowedScopes, AztecAddress.ZERO];
21
+ }
16
22
 
17
23
  setCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[], jobId: string, scope: AztecAddress) {
18
24
  assertAllowedScope(scope, this.allowedScopes);
@@ -77,14 +83,3 @@ export class CapsuleService {
77
83
  return this.capsuleStore.setCapsuleArray(contractAddress, baseSlot, content, jobId, scope);
78
84
  }
79
85
  }
80
-
81
- function assertAllowedScope(scope: AztecAddress, allowedScopes: AztecAddress[]) {
82
- if (scope.equals(AztecAddress.ZERO)) {
83
- return;
84
- }
85
- if (!allowedScopes.some((allowed: AztecAddress) => allowed.equals(scope))) {
86
- throw new Error(
87
- `Scope ${scope.toString()} is not in the allowed scopes list: [${allowedScopes.map((s: AztecAddress) => s.toString()).join(', ')}]. See https://docs.aztec.network/errors/10`,
88
- );
89
- }
90
- }
@@ -6,7 +6,6 @@ import type { MembershipWitness } from '@aztec/foundation/trees';
6
6
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
7
7
  import {
8
8
  type ContractArtifact,
9
- type FunctionAbi,
10
9
  type FunctionArtifactWithContractName,
11
10
  FunctionCall,
12
11
  type FunctionDebugMetadata,
@@ -23,8 +22,8 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
23
22
  import {
24
23
  type ContractClassIdPreimage,
25
24
  type ContractClassWithId,
26
- type ContractInstanceWithAddress,
27
- SerializableContractInstance,
25
+ type ContractInstancePreimageWithAddress,
26
+ SerializableContractInstancePreimage,
28
27
  getContractClassFromArtifact,
29
28
  } from '@aztec/stdlib/contract';
30
29
 
@@ -112,9 +111,6 @@ export class ContractStore {
112
111
  // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
113
112
  #contractArtifactCache: Map<string, ContractArtifact> = new Map();
114
113
 
115
- /** Map from contract address to contract class id (avoids KV round-trip on hot path). */
116
- #contractClassIdMap: Map<string, Fr> = new Map();
117
-
118
114
  #store: AztecAsyncKVStore;
119
115
  #contractArtifacts: AztecAsyncMap<string, Buffer>;
120
116
  #contractClassData: AztecAsyncMap<string, Buffer>;
@@ -131,9 +127,10 @@ export class ContractStore {
131
127
 
132
128
  /**
133
129
  * Registers a new contract artifact and its corresponding class data.
134
- * IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
135
- * It is the caller's responsibility to ensure the consistency and correctness of the provided data.
136
- * This is done to avoid redundant, expensive contract class computations
130
+ *
131
+ * IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id
132
+ * matches the artifact. It is the caller's responsibility to ensure the consistency and correctness of the provided
133
+ * data. This is done to avoid redundant, expensive contract class computations.
137
134
  */
138
135
  public async addContractArtifact(
139
136
  contract: ContractArtifact,
@@ -168,31 +165,17 @@ export class ContractStore {
168
165
  return contractClass.id;
169
166
  }
170
167
 
171
- async addContractInstance(contract: ContractInstanceWithAddress): Promise<void> {
168
+ async addContractInstance(contract: ContractInstancePreimageWithAddress): Promise<void> {
172
169
  await this.#store.transactionAsync(async () => {
173
170
  await this.#contractInstances.set(
174
171
  contract.address.toString(),
175
- new SerializableContractInstance(contract).toBuffer(),
172
+ new SerializableContractInstancePreimage(contract).toBuffer(),
176
173
  );
177
174
  });
178
-
179
- this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
180
175
  }
181
176
 
182
177
  // Private getters
183
178
 
184
- async #getContractClassId(contractAddress: AztecAddress): Promise<Fr | undefined> {
185
- const key = contractAddress.toString();
186
- if (!this.#contractClassIdMap.has(key)) {
187
- const instance = await this.getContractInstance(contractAddress);
188
- if (!instance) {
189
- return;
190
- }
191
- this.#contractClassIdMap.set(key, instance.currentContractClassId);
192
- }
193
- return this.#contractClassIdMap.get(key);
194
- }
195
-
196
179
  async #getPrivateFunctionTreeForClassId(classId: Fr): Promise<PrivateFunctionsTree | undefined> {
197
180
  if (!this.#privateFunctionTrees.has(classId.toString())) {
198
181
  const artifact = await this.getContractArtifact(classId);
@@ -205,25 +188,20 @@ export class ContractStore {
205
188
  return this.#privateFunctionTrees.get(classId.toString())!;
206
189
  }
207
190
 
208
- async #getArtifactByAddress(contractAddress: AztecAddress): Promise<ContractArtifact | undefined> {
209
- const classId = await this.#getContractClassId(contractAddress);
210
- return classId && this.getContractArtifact(classId);
211
- }
212
-
213
191
  // Public getters
214
192
 
215
193
  getContractsAddresses(): Promise<AztecAddress[]> {
216
194
  return this.#store.transactionAsync(async () => {
217
195
  const keys = await toArray(this.#contractInstances.keysAsync());
218
- return keys.map(AztecAddress.fromString);
196
+ return keys.map(AztecAddress.fromStringUnsafe);
219
197
  });
220
198
  }
221
199
 
222
- /** Returns a contract instance for a given address. */
223
- public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
200
+ /** Returns the address preimage of a given address. */
201
+ public getContractInstance(contractAddress: AztecAddress): Promise<ContractInstancePreimageWithAddress | undefined> {
224
202
  return this.#store.transactionAsync(async () => {
225
203
  const contract = await this.#contractInstances.getAsync(contractAddress.toString());
226
- return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
204
+ return contract && SerializableContractInstancePreimage.fromBuffer(contract).withAddress(contractAddress);
227
205
  });
228
206
  }
229
207
 
@@ -262,82 +240,69 @@ export class ContractStore {
262
240
  return { ...classData, packedBytecode };
263
241
  }
264
242
 
265
- public async getContract(
266
- address: AztecAddress,
267
- ): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined> {
268
- const instance = await this.getContractInstance(address);
269
- if (!instance) {
270
- return;
271
- }
272
- const artifact = await this.getContractArtifact(instance.currentContractClassId);
273
- if (!artifact) {
274
- return;
275
- }
276
- return { ...instance, ...artifact };
277
- }
278
-
279
243
  /**
280
- * Retrieves the artifact of a specified function within a given contract.
244
+ * Retrieves the artifact of a specified function within a given contract class.
281
245
  *
282
- * @param contractAddress - The AztecAddress representing the contract containing the function.
246
+ * @param contractClassId - The id of the contract class containing the function.
283
247
  * @param selector - The function selector.
284
- * @returns The corresponding function's artifact as an object.
248
+ * @returns The corresponding function's artifact as an object, or `undefined` if the class is not registered.
285
249
  */
286
250
  public async getFunctionArtifact(
287
- contractAddress: AztecAddress,
251
+ contractClassId: Fr,
288
252
  selector: FunctionSelector,
289
253
  ): Promise<FunctionArtifactWithContractName | undefined> {
290
- const artifact = await this.#getArtifactByAddress(contractAddress);
254
+ const artifact = await this.getContractArtifact(contractClassId);
291
255
  if (!artifact) {
292
256
  return undefined;
293
257
  }
294
- const fn = await findFunctionArtifactBySelector(artifact, selector);
295
- return fn && { ...fn, contractName: artifact.name };
258
+ const fn = assertSelectorInArtifact(artifact, await findFunctionArtifactBySelector(artifact, selector), {
259
+ contractClassId,
260
+ selector,
261
+ });
262
+ return { ...fn, contractName: artifact.name };
296
263
  }
297
264
 
265
+ /**
266
+ * Same as {@link getFunctionArtifact} but with debug metadata attached. Returns `undefined` when the class artifact
267
+ * is not registered.
268
+ */
298
269
  public async getFunctionArtifactWithDebugMetadata(
299
- contractAddress: AztecAddress,
270
+ contractClassId: Fr,
300
271
  selector: FunctionSelector,
301
- ): Promise<FunctionArtifactWithContractName> {
302
- const artifact = await this.getFunctionArtifact(contractAddress, selector);
272
+ ): Promise<FunctionArtifactWithContractName | undefined> {
273
+ const artifact = await this.getContractArtifact(contractClassId);
303
274
  if (!artifact) {
304
- throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
275
+ return undefined;
305
276
  }
306
- const debug = await this.getFunctionDebugMetadata(contractAddress, selector);
277
+ const fn = assertSelectorInArtifact(artifact, await findFunctionArtifactBySelector(artifact, selector), {
278
+ contractClassId,
279
+ selector,
280
+ });
307
281
  return {
308
- ...artifact,
309
- debug,
282
+ ...fn,
283
+ contractName: artifact.name,
284
+ debug: getFunctionDebugMetadata(artifact, fn),
310
285
  };
311
286
  }
312
287
 
313
- public async getPublicFunctionArtifact(
314
- contractAddress: AztecAddress,
315
- ): Promise<FunctionArtifactWithContractName | undefined> {
316
- const artifact = await this.#getArtifactByAddress(contractAddress);
288
+ public async getPublicFunctionArtifact(contractClassId: Fr): Promise<FunctionArtifactWithContractName | undefined> {
289
+ const artifact = await this.getContractArtifact(contractClassId);
317
290
  const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
318
291
  return fn && { ...fn, contractName: artifact.name };
319
292
  }
320
293
 
321
- public async getFunctionAbi(
322
- contractAddress: AztecAddress,
323
- selector: FunctionSelector,
324
- ): Promise<FunctionAbi | undefined> {
325
- const artifact = await this.#getArtifactByAddress(contractAddress);
326
- return artifact && (await findFunctionAbiBySelector(artifact, selector));
327
- }
328
-
329
294
  /**
330
- * Retrieves the debug metadata of a specified function within a given contract.
295
+ * Retrieves the debug metadata of a specified function within a given contract class.
331
296
  *
332
- * @param contractAddress - The AztecAddress representing the contract containing the function.
297
+ * @param contractClassId - The id of the contract class containing the function.
333
298
  * @param selector - The function selector.
334
299
  * @returns The corresponding function's debug metadata, or undefined.
335
300
  */
336
301
  public async getFunctionDebugMetadata(
337
- contractAddress: AztecAddress,
302
+ contractClassId: Fr,
338
303
  selector: FunctionSelector,
339
304
  ): Promise<FunctionDebugMetadata | undefined> {
340
- const artifact = await this.#getArtifactByAddress(contractAddress);
305
+ const artifact = await this.getContractArtifact(contractClassId);
341
306
  if (!artifact) {
342
307
  return undefined;
343
308
  }
@@ -345,10 +310,8 @@ export class ContractStore {
345
310
  return fn && getFunctionDebugMetadata(artifact, fn);
346
311
  }
347
312
 
348
- public async getPublicFunctionDebugMetadata(
349
- contractAddress: AztecAddress,
350
- ): Promise<FunctionDebugMetadata | undefined> {
351
- const artifact = await this.#getArtifactByAddress(contractAddress);
313
+ public async getPublicFunctionDebugMetadata(contractClassId: Fr): Promise<FunctionDebugMetadata | undefined> {
314
+ const artifact = await this.getContractArtifact(contractClassId);
352
315
  const fn = artifact && artifact.functions.find(f => f.functionType === FunctionType.PUBLIC);
353
316
  return fn && getFunctionDebugMetadata(artifact, fn);
354
317
  }
@@ -368,28 +331,34 @@ export class ContractStore {
368
331
  return tree?.getFunctionMembershipWitness(selector);
369
332
  }
370
333
 
371
- public async getDebugContractName(contractAddress: AztecAddress) {
372
- const artifact = await this.#getArtifactByAddress(contractAddress);
334
+ public async getDebugContractName(contractClassId: Fr) {
335
+ const artifact = await this.getContractArtifact(contractClassId);
373
336
  return artifact?.name;
374
337
  }
375
338
 
376
- public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) {
377
- const artifact = await this.#getArtifactByAddress(contractAddress);
339
+ public async getDebugFunctionName(contractClassId: Fr, selector: FunctionSelector) {
340
+ const artifact = await this.getContractArtifact(contractClassId);
378
341
  const fn = artifact && (await findFunctionAbiBySelector(artifact, selector));
379
- return `${artifact?.name ?? contractAddress}:${fn?.name ?? selector}`;
342
+ return `${artifact?.name ?? contractClassId}:${fn?.name ?? selector}`;
380
343
  }
381
344
 
382
- public async getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
383
- const contract = await this.getContract(to);
384
- if (!contract) {
345
+ public async getFunctionCall(
346
+ functionName: string,
347
+ args: any[],
348
+ to: AztecAddress,
349
+ contractClassId: Fr,
350
+ ): Promise<FunctionCall> {
351
+ const artifact = await this.getContractArtifact(contractClassId);
352
+ if (!artifact) {
385
353
  throw new Error(
386
- `Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
354
+ `No artifact registered for contract class ${contractClassId} (contract ${to}): register it by calling ` +
355
+ `wallet.registerContract(...).\nSee docs for context: https://docs.aztec.network/errors/14`,
387
356
  );
388
357
  }
389
358
 
390
- const functionDao = contract.functions.find(f => f.name === functionName);
359
+ const functionDao = artifact.functions.find(f => f.name === functionName);
391
360
  if (!functionDao) {
392
- throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
361
+ throw new Error(`Unknown function ${functionName} in contract ${artifact.name}.`);
393
362
  }
394
363
 
395
364
  const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
@@ -406,3 +375,27 @@ export class ContractStore {
406
375
  });
407
376
  }
408
377
  }
378
+
379
+ /**
380
+ * Narrows the result of a selector lookup against a registered artifact. A missing class artifact is reported as
381
+ * `undefined` by the callers (an absence they can handle), but a selector that is absent from an artifact we *do* have
382
+ * is exceptional and throws rather than returning undefined. We cannot tell from here why the selector is missing: it
383
+ * may be that no such function exists in the contract (a wrong selector), or that the registered artifact does not
384
+ * correspond to the resolved class id (registration performs no validation, so a mismatched artifact is possible). The
385
+ * error names both possibilities.
386
+ */
387
+ function assertSelectorInArtifact<T>(
388
+ artifact: ContractArtifact,
389
+ fn: T | undefined,
390
+ context: { contractClassId: Fr; selector: FunctionSelector },
391
+ ): T {
392
+ if (!fn) {
393
+ throw new Error(
394
+ `Function with selector ${context.selector} not found in the registered artifact for contract class ` +
395
+ `${context.contractClassId} (${artifact.name}). Either no function with this selector exists in the ` +
396
+ `contract, or the registered artifact does not match the class id (re-register it via ` +
397
+ `wallet.registerContract(...)).`,
398
+ );
399
+ }
400
+ return fn;
401
+ }