@aztec/pxe 3.0.0-rc.5 → 4.0.0-nightly.20260107

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 (281) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
  3. package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +22 -22
  4. package/dest/block_synchronizer/index.d.ts +2 -0
  5. package/dest/block_synchronizer/index.d.ts.map +1 -0
  6. package/dest/block_synchronizer/index.js +1 -0
  7. package/dest/config/index.d.ts +4 -4
  8. package/dest/config/index.d.ts.map +1 -1
  9. package/dest/config/package_info.js +1 -1
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts +40 -11
  11. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/contract_function_simulator.js +47 -17
  13. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +1 -1
  14. package/dest/contract_function_simulator/execution_tagging_index_cache.js +1 -1
  15. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +4 -3
  16. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
  17. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
  18. package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -4
  19. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  20. package/dest/contract_function_simulator/oracle/oracle.d.ts +1 -1
  21. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/oracle.js +3 -3
  23. package/dest/contract_function_simulator/oracle/private_execution.d.ts +7 -9
  24. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/private_execution.js +11 -11
  26. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -8
  27. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  28. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +24 -12
  29. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +47 -8
  30. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  31. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +143 -37
  32. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
  33. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
  34. package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
  35. package/dest/debug/pxe_debug_utils.d.ts +31 -0
  36. package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
  37. package/dest/debug/pxe_debug_utils.js +37 -0
  38. package/dest/entrypoints/client/bundle/index.d.ts +1 -2
  39. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  40. package/dest/entrypoints/client/bundle/index.js +0 -1
  41. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  42. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  43. package/dest/entrypoints/client/bundle/utils.js +10 -1
  44. package/dest/entrypoints/client/lazy/index.d.ts +1 -2
  45. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  46. package/dest/entrypoints/client/lazy/index.js +0 -1
  47. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  48. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  49. package/dest/entrypoints/client/lazy/utils.js +10 -1
  50. package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
  51. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
  52. package/dest/entrypoints/server/index.d.ts +2 -2
  53. package/dest/entrypoints/server/index.d.ts.map +1 -1
  54. package/dest/entrypoints/server/index.js +1 -1
  55. package/dest/entrypoints/server/utils.d.ts +1 -1
  56. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  57. package/dest/entrypoints/server/utils.js +11 -7
  58. package/dest/error_enriching.d.ts +4 -4
  59. package/dest/error_enriching.d.ts.map +1 -1
  60. package/dest/error_enriching.js +6 -6
  61. package/dest/events/event_service.d.ts +15 -0
  62. package/dest/events/event_service.d.ts.map +1 -0
  63. package/dest/events/event_service.js +47 -0
  64. package/dest/events/private_event_filter_validator.d.ts +6 -5
  65. package/dest/events/private_event_filter_validator.d.ts.map +1 -1
  66. package/dest/events/private_event_filter_validator.js +4 -4
  67. package/dest/logs/log_service.d.ts +26 -0
  68. package/dest/logs/log_service.d.ts.map +1 -0
  69. package/dest/logs/log_service.js +120 -0
  70. package/dest/notes/index.d.ts +2 -0
  71. package/dest/notes/index.d.ts.map +1 -0
  72. package/dest/notes/index.js +1 -0
  73. package/dest/notes/note_service.d.ts +48 -0
  74. package/dest/notes/note_service.d.ts.map +1 -0
  75. package/dest/notes/note_service.js +152 -0
  76. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +4 -4
  77. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
  78. package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
  79. package/dest/public_storage/public_storage_service.d.ts +24 -0
  80. package/dest/public_storage/public_storage_service.d.ts.map +1 -0
  81. package/dest/public_storage/public_storage_service.js +26 -0
  82. package/dest/pxe.d.ts +25 -33
  83. package/dest/pxe.d.ts.map +1 -1
  84. package/dest/pxe.js +125 -136
  85. package/dest/storage/address_store/address_store.d.ts +11 -0
  86. package/dest/storage/address_store/address_store.d.ts.map +1 -0
  87. package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -1
  88. package/dest/storage/address_store/index.d.ts +2 -0
  89. package/dest/storage/address_store/index.d.ts.map +1 -0
  90. package/dest/storage/address_store/index.js +1 -0
  91. package/dest/storage/{sync_data_provider/sync_data_provider.d.ts → anchor_block_store/anchor_block_store.d.ts} +2 -4
  92. package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
  93. package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -9
  94. package/dest/storage/{sync_data_provider → anchor_block_store}/index.d.ts +2 -2
  95. package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
  96. package/dest/storage/anchor_block_store/index.js +1 -0
  97. package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
  98. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
  99. package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +33 -5
  100. package/dest/storage/capsule_store/index.d.ts +2 -0
  101. package/dest/storage/capsule_store/index.d.ts.map +1 -0
  102. package/dest/storage/capsule_store/index.js +1 -0
  103. package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +7 -4
  104. package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
  105. package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -3
  106. package/dest/storage/contract_store/index.d.ts +2 -0
  107. package/dest/storage/contract_store/index.d.ts.map +1 -0
  108. package/dest/storage/contract_store/index.js +1 -0
  109. package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
  110. package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
  111. package/dest/storage/index.d.ts +8 -8
  112. package/dest/storage/index.d.ts.map +1 -1
  113. package/dest/storage/index.js +7 -7
  114. package/dest/storage/note_store/index.d.ts +3 -0
  115. package/dest/storage/note_store/index.d.ts.map +1 -0
  116. package/dest/storage/note_store/index.js +2 -0
  117. package/dest/storage/{note_data_provider/note_data_provider.d.ts → note_store/note_store.d.ts} +7 -7
  118. package/dest/storage/note_store/note_store.d.ts.map +1 -0
  119. package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +6 -6
  120. package/dest/storage/{private_event_data_provider/private_event_data_provider.d.ts → private_event_store/private_event_store.d.ts} +9 -4
  121. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
  122. package/dest/storage/{private_event_data_provider/private_event_data_provider.js → private_event_store/private_event_store.js} +57 -15
  123. package/dest/storage/tagging_store/index.d.ts +4 -0
  124. package/dest/storage/tagging_store/index.d.ts.map +1 -0
  125. package/dest/storage/tagging_store/index.js +3 -0
  126. package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
  127. package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
  128. package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
  129. package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
  130. package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
  131. package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
  132. package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
  133. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
  134. package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
  135. package/dest/tagging/index.d.ts +15 -6
  136. package/dest/tagging/index.d.ts.map +1 -1
  137. package/dest/tagging/index.js +23 -5
  138. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
  139. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
  140. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
  141. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
  142. package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
  143. package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
  144. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
  145. package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
  146. package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
  147. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
  148. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
  149. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
  150. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
  151. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
  152. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
  153. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
  154. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
  155. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
  156. package/dest/tree_membership/tree_membership_service.d.ts +52 -0
  157. package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
  158. package/dest/tree_membership/tree_membership_service.js +84 -0
  159. package/package.json +16 -16
  160. package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +21 -22
  161. package/src/block_synchronizer/index.ts +1 -0
  162. package/src/config/index.ts +3 -3
  163. package/src/config/package_info.ts +1 -1
  164. package/src/contract_function_simulator/contract_function_simulator.ts +84 -15
  165. package/src/contract_function_simulator/execution_tagging_index_cache.ts +1 -1
  166. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +5 -4
  167. package/src/contract_function_simulator/oracle/interfaces.ts +2 -3
  168. package/src/contract_function_simulator/oracle/oracle.ts +3 -3
  169. package/src/contract_function_simulator/oracle/private_execution.ts +14 -13
  170. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +89 -19
  171. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +208 -45
  172. package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
  173. package/src/debug/pxe_debug_utils.ts +48 -0
  174. package/src/entrypoints/client/bundle/index.ts +0 -1
  175. package/src/entrypoints/client/bundle/utils.ts +7 -1
  176. package/src/entrypoints/client/lazy/index.ts +0 -1
  177. package/src/entrypoints/client/lazy/utils.ts +7 -2
  178. package/src/entrypoints/pxe_creation_options.ts +2 -1
  179. package/src/entrypoints/server/index.ts +1 -1
  180. package/src/entrypoints/server/utils.ts +11 -15
  181. package/src/error_enriching.ts +7 -15
  182. package/src/events/event_service.ts +77 -0
  183. package/src/events/private_event_filter_validator.ts +5 -4
  184. package/src/logs/log_service.ts +202 -0
  185. package/src/notes/index.ts +1 -0
  186. package/src/notes/note_service.ts +200 -0
  187. package/src/private_kernel/private_kernel_oracle_impl.ts +6 -6
  188. package/src/public_storage/public_storage_service.ts +33 -0
  189. package/src/pxe.ts +153 -162
  190. package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -1
  191. package/src/storage/address_store/index.ts +1 -0
  192. package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -12
  193. package/src/storage/anchor_block_store/index.ts +1 -0
  194. package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +33 -1
  195. package/src/storage/capsule_store/index.ts +1 -0
  196. package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +64 -2
  197. package/src/storage/contract_store/index.ts +1 -0
  198. package/src/storage/index.ts +7 -7
  199. package/src/storage/note_store/index.ts +2 -0
  200. package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +7 -7
  201. package/src/storage/{private_event_data_provider/private_event_data_provider.ts → private_event_store/private_event_store.ts} +69 -18
  202. package/src/storage/tagging_store/index.ts +3 -0
  203. package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
  204. package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
  205. package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
  206. package/src/tagging/index.ts +27 -5
  207. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
  208. package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
  209. package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
  210. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
  211. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
  212. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
  213. package/src/tree_membership/tree_membership_service.ts +112 -0
  214. package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -268
  215. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
  216. package/dest/contract_function_simulator/execution_data_provider.js +0 -14
  217. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -124
  218. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
  219. package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -713
  220. package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
  221. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
  222. package/dest/storage/address_data_provider/index.d.ts +0 -2
  223. package/dest/storage/address_data_provider/index.d.ts.map +0 -1
  224. package/dest/storage/address_data_provider/index.js +0 -1
  225. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -25
  226. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
  227. package/dest/storage/capsule_data_provider/index.d.ts +0 -2
  228. package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
  229. package/dest/storage/capsule_data_provider/index.js +0 -1
  230. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
  231. package/dest/storage/contract_data_provider/index.d.ts +0 -2
  232. package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
  233. package/dest/storage/contract_data_provider/index.js +0 -1
  234. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
  235. package/dest/storage/note_data_provider/index.d.ts +0 -3
  236. package/dest/storage/note_data_provider/index.d.ts.map +0 -1
  237. package/dest/storage/note_data_provider/index.js +0 -2
  238. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
  239. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
  240. package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
  241. package/dest/storage/sync_data_provider/index.js +0 -1
  242. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
  243. package/dest/storage/tagging_data_provider/index.d.ts +0 -2
  244. package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
  245. package/dest/storage/tagging_data_provider/index.js +0 -1
  246. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -40
  247. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
  248. package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -89
  249. package/dest/synchronizer/index.d.ts +0 -2
  250. package/dest/synchronizer/index.d.ts.map +0 -1
  251. package/dest/synchronizer/index.js +0 -1
  252. package/dest/synchronizer/synchronizer.d.ts +0 -36
  253. package/dest/synchronizer/synchronizer.d.ts.map +0 -1
  254. package/dest/tagging/constants.d.ts +0 -2
  255. package/dest/tagging/constants.d.ts.map +0 -1
  256. package/dest/tagging/constants.js +0 -2
  257. package/dest/tagging/siloed_tag.d.ts +0 -14
  258. package/dest/tagging/siloed_tag.d.ts.map +0 -1
  259. package/dest/tagging/siloed_tag.js +0 -20
  260. package/dest/tagging/tag.d.ts +0 -12
  261. package/dest/tagging/tag.d.ts.map +0 -1
  262. package/dest/tagging/tag.js +0 -17
  263. package/dest/tagging/utils.d.ts +0 -18
  264. package/dest/tagging/utils.d.ts.map +0 -1
  265. package/dest/tagging/utils.js +0 -24
  266. package/src/contract_function_simulator/execution_data_provider.ts +0 -343
  267. package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1040
  268. package/src/storage/address_data_provider/index.ts +0 -1
  269. package/src/storage/capsule_data_provider/index.ts +0 -1
  270. package/src/storage/contract_data_provider/index.ts +0 -1
  271. package/src/storage/note_data_provider/index.ts +0 -2
  272. package/src/storage/sync_data_provider/index.ts +0 -1
  273. package/src/storage/tagging_data_provider/index.ts +0 -1
  274. package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -120
  275. package/src/synchronizer/index.ts +0 -1
  276. package/src/tagging/constants.ts +0 -2
  277. package/src/tagging/siloed_tag.ts +0 -22
  278. package/src/tagging/tag.ts +0 -16
  279. package/src/tagging/utils.ts +0 -31
  280. /package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +0 -0
  281. /package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +0 -0
@@ -1,1040 +0,0 @@
1
- import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
- import { timesParallel } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { Point } from '@aztec/foundation/curves/grumpkin';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import type { KeyStore } from '@aztec/key-store';
7
- import { EventSelector, type FunctionArtifactWithContractName, FunctionSelector } from '@aztec/stdlib/abi';
8
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
9
- import type { BlockParameter, DataInBlock, L2Block } from '@aztec/stdlib/block';
10
- import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
11
- import { computeUniqueNoteHash, siloNoteHash, siloNullifier, siloPrivateLog } from '@aztec/stdlib/hash';
12
- import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
13
- import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
14
- import { computeAddressSecret } from '@aztec/stdlib/keys';
15
- import {
16
- PendingTaggedLog,
17
- PrivateLogWithTxData,
18
- PublicLog,
19
- PublicLogWithTxData,
20
- TxScopedL2Log,
21
- deriveEcdhSharedSecret,
22
- } from '@aztec/stdlib/logs';
23
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
24
- import { Note, type NoteStatus } from '@aztec/stdlib/note';
25
- import { NoteDao } from '@aztec/stdlib/note';
26
- import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
27
- import type { BlockHeader } from '@aztec/stdlib/tx';
28
- import { TxHash } from '@aztec/stdlib/tx';
29
-
30
- import type { ExecutionDataProvider, ExecutionStats } from '../contract_function_simulator/execution_data_provider.js';
31
- import { MessageLoadOracleInputs } from '../contract_function_simulator/oracle/message_load_oracle_inputs.js';
32
- import { ORACLE_VERSION } from '../oracle_version.js';
33
- import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
34
- import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
35
- import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
36
- import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
37
- import type { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
38
- import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
39
- import type { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
40
- import {
41
- DirectionalAppTaggingSecret,
42
- SiloedTag,
43
- Tag,
44
- WINDOW_HALF_SIZE,
45
- getInitialIndexesMap,
46
- getPreTagsForTheWindow,
47
- } from '../tagging/index.js';
48
- import { EventValidationRequest } from './noir-structs/event_validation_request.js';
49
- import { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
50
- import { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
51
- import { NoteValidationRequest } from './noir-structs/note_validation_request.js';
52
- import type { ProxiedNode } from './proxied_node.js';
53
-
54
- /**
55
- * A data layer that provides and stores information needed for simulating/proving a transaction.
56
- */
57
- export class PXEOracleInterface implements ExecutionDataProvider {
58
- constructor(
59
- private aztecNode: AztecNode | ProxiedNode,
60
- private keyStore: KeyStore,
61
- private contractDataProvider: ContractDataProvider,
62
- private noteDataProvider: NoteDataProvider,
63
- private capsuleDataProvider: CapsuleDataProvider,
64
- private syncDataProvider: SyncDataProvider,
65
- private taggingDataProvider: TaggingDataProvider,
66
- private addressDataProvider: AddressDataProvider,
67
- private privateEventDataProvider: PrivateEventDataProvider,
68
- private log = createLogger('pxe:pxe_oracle_interface'),
69
- ) {}
70
-
71
- getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise<KeyValidationRequest> {
72
- return this.keyStore.getKeyValidationRequest(pkMHash, contractAddress);
73
- }
74
-
75
- async getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
76
- const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
77
- if (!completeAddress) {
78
- throw new Error(
79
- `No public key registered for address ${account}.
80
- Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
81
- );
82
- }
83
- return completeAddress;
84
- }
85
-
86
- async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
87
- const instance = await this.contractDataProvider.getContractInstance(address);
88
- if (!instance) {
89
- throw new Error(`No contract instance found for address ${address.toString()}`);
90
- }
91
- return instance;
92
- }
93
-
94
- async getNotes(
95
- contractAddress: AztecAddress,
96
- owner: AztecAddress | undefined,
97
- storageSlot: Fr,
98
- status: NoteStatus,
99
- scopes?: AztecAddress[],
100
- ) {
101
- const noteDaos = await this.noteDataProvider.getNotes({
102
- contractAddress,
103
- owner,
104
- storageSlot,
105
- status,
106
- scopes,
107
- });
108
- return noteDaos.map(
109
- ({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier, index }) => ({
110
- contractAddress,
111
- owner,
112
- storageSlot,
113
- randomness,
114
- noteNonce,
115
- note,
116
- noteHash,
117
- siloedNullifier,
118
- // PXE can use this index to get full MembershipWitness
119
- index,
120
- }),
121
- );
122
- }
123
-
124
- async getFunctionArtifact(
125
- contractAddress: AztecAddress,
126
- selector: FunctionSelector,
127
- ): Promise<FunctionArtifactWithContractName> {
128
- const artifact = await this.contractDataProvider.getFunctionArtifact(contractAddress, selector);
129
- if (!artifact) {
130
- throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
131
- }
132
- const debug = await this.contractDataProvider.getFunctionDebugMetadata(contractAddress, selector);
133
- return {
134
- ...artifact,
135
- debug,
136
- };
137
- }
138
-
139
- /**
140
- * Fetches a message from the db, given its key.
141
- * @param contractAddress - Address of a contract by which the message was emitted.
142
- * @param messageHash - Hash of the message.
143
- * @param secret - Secret used to compute a nullifier.
144
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
145
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
146
- */
147
- async getL1ToL2MembershipWitness(
148
- contractAddress: AztecAddress,
149
- messageHash: Fr,
150
- secret: Fr,
151
- ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
152
- const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
153
- this.aztecNode,
154
- contractAddress,
155
- messageHash,
156
- secret,
157
- );
158
-
159
- // Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
160
- return new MessageLoadOracleInputs(messageIndex, siblingPath);
161
- }
162
-
163
- async getNullifierIndex(nullifier: Fr) {
164
- return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
165
- }
166
-
167
- async #findLeafIndex(blockNumber: BlockParameter, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
168
- const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]);
169
- return leafIndex?.data;
170
- }
171
-
172
- public async getMembershipWitness(blockNumber: BlockParameter, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
173
- const witness = await this.#tryGetMembershipWitness(blockNumber, treeId, leafValue);
174
- if (!witness) {
175
- throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block ${blockNumber}`);
176
- }
177
- return witness;
178
- }
179
-
180
- async #tryGetMembershipWitness(
181
- blockNumber: BlockParameter,
182
- treeId: MerkleTreeId,
183
- value: Fr,
184
- ): Promise<Fr[] | undefined> {
185
- switch (treeId) {
186
- case MerkleTreeId.NULLIFIER_TREE:
187
- return (await this.aztecNode.getNullifierMembershipWitness(blockNumber, value))?.withoutPreimage().toFields();
188
- case MerkleTreeId.NOTE_HASH_TREE:
189
- return (await this.aztecNode.getNoteHashMembershipWitness(blockNumber, value))?.toFields();
190
- case MerkleTreeId.PUBLIC_DATA_TREE:
191
- return (await this.aztecNode.getPublicDataWitness(blockNumber, value))?.withoutPreimage().toFields();
192
- case MerkleTreeId.ARCHIVE:
193
- return (await this.aztecNode.getArchiveMembershipWitness(blockNumber, value))?.toFields();
194
- default:
195
- throw new Error('Not implemented');
196
- }
197
- }
198
-
199
- public async getNullifierMembershipWitnessAtLatestBlock(nullifier: Fr) {
200
- const blockNumber = (await this.getAnchorBlockHeader()).globalVariables.blockNumber;
201
- return this.getNullifierMembershipWitness(blockNumber, nullifier);
202
- }
203
-
204
- public getNullifierMembershipWitness(
205
- blockNumber: BlockParameter,
206
- nullifier: Fr,
207
- ): Promise<NullifierMembershipWitness | undefined> {
208
- return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
209
- }
210
-
211
- public async getLowNullifierMembershipWitness(
212
- blockNumber: BlockParameter,
213
- nullifier: Fr,
214
- ): Promise<NullifierMembershipWitness | undefined> {
215
- const header = await this.getAnchorBlockHeader();
216
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
217
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
218
- }
219
- return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
220
- }
221
-
222
- public async getBlock(blockNumber: BlockParameter): Promise<L2Block | undefined> {
223
- const header = await this.getAnchorBlockHeader();
224
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
225
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
226
- }
227
- return await this.aztecNode.getBlock(blockNumber);
228
- }
229
-
230
- public async getPublicDataWitness(blockNumber: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
231
- const header = await this.getAnchorBlockHeader();
232
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
233
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
234
- }
235
- return await this.aztecNode.getPublicDataWitness(blockNumber, leafSlot);
236
- }
237
-
238
- public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
239
- const header = await this.getAnchorBlockHeader();
240
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
241
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
242
- }
243
- return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
244
- }
245
-
246
- getAnchorBlockHeader(): Promise<BlockHeader> {
247
- return this.syncDataProvider.getBlockHeader();
248
- }
249
-
250
- public assertCompatibleOracleVersion(version: number): void {
251
- if (version !== ORACLE_VERSION) {
252
- throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
253
- }
254
- }
255
-
256
- public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
257
- return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
258
- }
259
-
260
- /**
261
- * Returns the full contents of your address book.
262
- * This is used when calculating tags for incoming notes by deriving the shared secret, the contract-siloed tagging secret, and
263
- * finally the index specified tag. We will then query the node with this tag for each address in the address book.
264
- * @returns The full list of the users contact addresses.
265
- */
266
- public getSenders(): Promise<AztecAddress[]> {
267
- return this.taggingDataProvider.getSenderAddresses();
268
- }
269
-
270
- public getLastUsedIndexAsSender(secret: DirectionalAppTaggingSecret): Promise<number | undefined> {
271
- return this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
272
- }
273
-
274
- public async calculateDirectionalAppTaggingSecret(
275
- contractAddress: AztecAddress,
276
- sender: AztecAddress,
277
- recipient: AztecAddress,
278
- ) {
279
- const senderCompleteAddress = await this.getCompleteAddress(sender);
280
- const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
281
- return DirectionalAppTaggingSecret.compute(
282
- senderCompleteAddress,
283
- senderIvsk,
284
- recipient,
285
- contractAddress,
286
- recipient,
287
- );
288
- }
289
-
290
- /**
291
- * Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
292
- * the senders in the address book.
293
- * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
294
- * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
295
- * so we're keeping it private for now.
296
- * @param contractAddress - The contract address to silo the secret for
297
- * @param recipient - The address receiving the notes
298
- * @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
299
- * secret was never used, the index is undefined.
300
- * TODO(benesjan): The naming here is broken as the function name does not reflect the return type. Fix when associating
301
- * indexes with tx hash.
302
- */
303
- async #getLastUsedTaggingIndexesForSenders(
304
- contractAddress: AztecAddress,
305
- recipient: AztecAddress,
306
- ): Promise<{ secret: DirectionalAppTaggingSecret; index: number | undefined }[]> {
307
- const recipientCompleteAddress = await this.getCompleteAddress(recipient);
308
- const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
309
-
310
- // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
311
- // (recipient = us, sender = us)
312
- const senders = [
313
- ...(await this.taggingDataProvider.getSenderAddresses()),
314
- ...(await this.keyStore.getAccounts()),
315
- ].filter((address, index, self) => index === self.findIndex(otherAddress => otherAddress.equals(address)));
316
- const secrets = await Promise.all(
317
- senders.map(contact => {
318
- return DirectionalAppTaggingSecret.compute(
319
- recipientCompleteAddress,
320
- recipientIvsk,
321
- contact,
322
- contractAddress,
323
- recipient,
324
- );
325
- }),
326
- );
327
- const indexes = await this.taggingDataProvider.getLastUsedIndexesAsRecipient(secrets);
328
- if (indexes.length !== secrets.length) {
329
- throw new Error('Indexes and directional app tagging secrets have different lengths');
330
- }
331
-
332
- return secrets.map((secret, i) => ({
333
- secret,
334
- index: indexes[i],
335
- }));
336
- }
337
-
338
- public async syncTaggedLogsAsSender(
339
- secret: DirectionalAppTaggingSecret,
340
- contractAddress: AztecAddress,
341
- ): Promise<void> {
342
- const lastUsedIndex = await this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
343
- // If lastUsedIndex is undefined, we've never used this secret, so start from 0
344
- // Otherwise, start from one past the last used index
345
- const startIndex = lastUsedIndex === undefined ? 0 : lastUsedIndex + 1;
346
-
347
- // This algorithm works such that:
348
- // 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
349
- // we found and quit.
350
- // 2. If we don't find minimum consecutive empty logs in a window of logs we slide the window to latest log index
351
- // and repeat the process.
352
- const MIN_CONSECUTIVE_EMPTY_LOGS = 10;
353
- const WINDOW_SIZE = MIN_CONSECUTIVE_EMPTY_LOGS * 2;
354
-
355
- let [numConsecutiveEmptyLogs, currentIndex] = [0, startIndex];
356
- let lastFoundLogIndex: number | undefined = undefined;
357
- do {
358
- // We compute the tags for the current window of indexes
359
- const currentTags = await timesParallel(WINDOW_SIZE, async i => {
360
- return SiloedTag.compute(await Tag.compute({ secret, index: currentIndex + i }), contractAddress);
361
- });
362
-
363
- // We fetch the logs for the tags
364
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
365
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
366
- const tagsAsFr = currentTags.map(tag => tag.value);
367
- const possibleLogs = await this.#getPrivateLogsByTags(tagsAsFr);
368
-
369
- // We find the index of the last log in the window that is not empty
370
- const indexOfLastLogWithinArray = possibleLogs.findLastIndex(possibleLog => possibleLog.length !== 0);
371
-
372
- if (indexOfLastLogWithinArray === -1) {
373
- // We haven't found any logs in the current window so we stop looking
374
- break;
375
- }
376
-
377
- // We've found logs so we update the last found log index
378
- lastFoundLogIndex = (lastFoundLogIndex ?? 0) + indexOfLastLogWithinArray;
379
- // We move the current index to that of the log right after the last found log
380
- currentIndex = lastFoundLogIndex + 1;
381
-
382
- // We compute the number of consecutive empty logs we found and repeat the process if we haven't found enough.
383
- numConsecutiveEmptyLogs = WINDOW_SIZE - indexOfLastLogWithinArray - 1;
384
- } while (numConsecutiveEmptyLogs < MIN_CONSECUTIVE_EMPTY_LOGS);
385
-
386
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
387
- if (lastFoundLogIndex !== undefined) {
388
- // Last found index is defined meaning we have actually found logs so we update the last used index
389
- await this.taggingDataProvider.setLastUsedIndexesAsSender([{ secret, index: lastFoundLogIndex }]);
390
-
391
- this.log.debug(`Syncing logs for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`, {
392
- index: currentIndex,
393
- contractName,
394
- contractAddress,
395
- });
396
- } else {
397
- this.log.debug(
398
- `No new logs found for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`,
399
- );
400
- }
401
- }
402
-
403
- /**
404
- * Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
405
- * logs in CapsuleArray ready for a later retrieval in Aztec.nr.
406
- * @param contractAddress - The address of the contract that the logs are tagged for.
407
- * @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged logs capsule array in which
408
- * found logs will be stored.
409
- * @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
410
- * synced.
411
- */
412
- public async syncTaggedLogs(
413
- contractAddress: AztecAddress,
414
- pendingTaggedLogArrayBaseSlot: Fr,
415
- scopes?: AztecAddress[],
416
- ) {
417
- this.log.verbose('Searching for tagged logs', { contract: contractAddress });
418
-
419
- const maxBlockNumber = await this.syncDataProvider.getBlockNumber();
420
-
421
- // Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
422
- // However it is impossible at the moment due to the language not supporting nested slices.
423
- // This nesting is necessary because for a given set of tags we don't
424
- // know how many logs we will get back. Furthermore, these logs are of undetermined
425
- // length, since we don't really know the note they correspond to until we decrypt them.
426
-
427
- const recipients = scopes ? scopes : await this.keyStore.getAccounts();
428
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
429
- for (const recipient of recipients) {
430
- // Get all the secrets for the recipient and sender pairs (#9365)
431
- const indexedSecrets = await this.#getLastUsedTaggingIndexesForSenders(contractAddress, recipient);
432
-
433
- // We fetch logs for a window of indexes in a range:
434
- // <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
435
- //
436
- // We use this window approach because it could happen that a sender might have messed up and inadvertently
437
- // incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
438
- // for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
439
- // Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
440
- // some logs. For these reasons, we have to look both back and ahead of the stored index.
441
- let secretsAndWindows = indexedSecrets.map(indexedSecret => {
442
- if (indexedSecret.index === undefined) {
443
- return {
444
- secret: indexedSecret.secret,
445
- leftMostIndex: 0,
446
- rightMostIndex: WINDOW_HALF_SIZE,
447
- };
448
- } else {
449
- return {
450
- secret: indexedSecret.secret,
451
- leftMostIndex: Math.max(0, indexedSecret.index - WINDOW_HALF_SIZE),
452
- rightMostIndex: indexedSecret.index + WINDOW_HALF_SIZE,
453
- };
454
- }
455
- });
456
-
457
- // As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
458
- const newLargestIndexMapToStore: { [k: string]: number } = {};
459
-
460
- // The initial/unmodified indexes of the secrets stored in a key-value map where key is the directional app
461
- // tagging secret.
462
- const initialIndexesMap = getInitialIndexesMap(indexedSecrets);
463
-
464
- while (secretsAndWindows.length > 0) {
465
- const preTagsForTheWholeWindow = getPreTagsForTheWindow(secretsAndWindows);
466
- const tagsForTheWholeWindow = await Promise.all(
467
- preTagsForTheWholeWindow.map(async preTag => {
468
- return SiloedTag.compute(await Tag.compute(preTag), contractAddress);
469
- }),
470
- );
471
-
472
- // We store the new largest indexes we find in the iteration in the following map to later on construct
473
- // a new set of secrets and windows to fetch logs for.
474
- const newLargestIndexMapForIteration: { [k: string]: number } = {};
475
-
476
- // Fetch the private logs for the tags and iterate over them
477
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
478
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
479
- const tagsForTheWholeWindowAsFr = tagsForTheWholeWindow.map(tag => tag.value);
480
- const logsByTags = await this.#getPrivateLogsByTags(tagsForTheWholeWindowAsFr);
481
- this.log.debug(`Found ${logsByTags.filter(logs => logs.length > 0).length} logs as recipient ${recipient}`, {
482
- recipient,
483
- contractName,
484
- contractAddress,
485
- });
486
-
487
- for (let logIndex = 0; logIndex < logsByTags.length; logIndex++) {
488
- const logsByTag = logsByTags[logIndex];
489
- if (logsByTag.length > 0) {
490
- // We filter out the logs that are newer than the anchor block number of the tx currently being constructed
491
- const filteredLogsByBlockNumber = logsByTag.filter(l => l.blockNumber <= maxBlockNumber);
492
-
493
- // We store the logs in capsules (to later be obtained in Noir)
494
- await this.#storePendingTaggedLogs(
495
- contractAddress,
496
- pendingTaggedLogArrayBaseSlot,
497
- recipient,
498
- filteredLogsByBlockNumber,
499
- );
500
-
501
- // We retrieve the pre tag corresponding to the log as I need that to evaluate whether
502
- // a new largest index have been found.
503
- const preTagCorrespondingToLog = preTagsForTheWholeWindow[logIndex];
504
- const initialIndex = initialIndexesMap[preTagCorrespondingToLog.secret.toString()];
505
-
506
- if (
507
- preTagCorrespondingToLog.index >= initialIndex &&
508
- (newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] === undefined ||
509
- preTagCorrespondingToLog.index >=
510
- newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()])
511
- ) {
512
- // We have found a new largest index so we store it for later processing (storing it in the db + fetching
513
- // the difference of the window sets of current and the next iteration)
514
- newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] =
515
- preTagCorrespondingToLog.index + 1;
516
-
517
- this.log.debug(
518
- `Incrementing index to ${
519
- preTagCorrespondingToLog.index + 1
520
- } at contract ${contractName}(${contractAddress})`,
521
- );
522
- }
523
- }
524
- }
525
-
526
- // Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
527
- // for. Note that it's very unlikely that a new log from the current window would appear between the iterations
528
- // so we fetch the logs only for the difference of the window sets.
529
- const newSecretsAndWindows = [];
530
- for (const [directionalAppTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)) {
531
- const maybeIndexedSecret = indexedSecrets.find(
532
- indexedSecret => indexedSecret.secret.toString() === directionalAppTaggingSecret,
533
- );
534
- if (maybeIndexedSecret) {
535
- newSecretsAndWindows.push({
536
- secret: maybeIndexedSecret.secret,
537
- // We set the left most index to the new index to avoid fetching the same logs again
538
- leftMostIndex: newIndex,
539
- rightMostIndex: newIndex + WINDOW_HALF_SIZE,
540
- });
541
-
542
- // We store the new largest index in the map to later store it in the db.
543
- newLargestIndexMapToStore[directionalAppTaggingSecret] = newIndex;
544
- } else {
545
- throw new Error(
546
- `Secret not found for directionalAppTaggingSecret ${directionalAppTaggingSecret}. This is a bug as it should never happen!`,
547
- );
548
- }
549
- }
550
-
551
- // Now we set the new secrets and windows and proceed to the next iteration.
552
- secretsAndWindows = newSecretsAndWindows;
553
- }
554
-
555
- // At this point we have processed all the logs for the recipient so we store the last used indexes in the db.
556
- // newLargestIndexMapToStore contains "next" indexes to look for (one past the last found), so subtract 1 to get
557
- // last used.
558
- await this.taggingDataProvider.setLastUsedIndexesAsRecipient(
559
- Object.entries(newLargestIndexMapToStore).map(([directionalAppTaggingSecret, index]) => ({
560
- secret: DirectionalAppTaggingSecret.fromString(directionalAppTaggingSecret),
561
- index: index - 1,
562
- })),
563
- );
564
- }
565
- }
566
-
567
- async #storePendingTaggedLogs(
568
- contractAddress: AztecAddress,
569
- capsuleArrayBaseSlot: Fr,
570
- recipient: AztecAddress,
571
- privateLogs: TxScopedL2Log[],
572
- ) {
573
- // Build all pending tagged logs upfront with their tx effects
574
- const pendingTaggedLogs = await Promise.all(
575
- privateLogs.map(async scopedLog => {
576
- // TODO(#9789): get these effects along with the log
577
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
578
- if (!txEffect) {
579
- throw new Error(`Could not find tx effect for tx hash ${scopedLog.txHash}`);
580
- }
581
-
582
- const pendingTaggedLog = new PendingTaggedLog(
583
- scopedLog.log.fields,
584
- scopedLog.txHash,
585
- txEffect.data.noteHashes,
586
- txEffect.data.nullifiers[0],
587
- recipient,
588
- );
589
-
590
- return pendingTaggedLog.toFields();
591
- }),
592
- );
593
-
594
- return this.capsuleDataProvider.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
595
- }
596
-
597
- public async validateEnqueuedNotesAndEvents(
598
- contractAddress: AztecAddress,
599
- noteValidationRequestsArrayBaseSlot: Fr,
600
- eventValidationRequestsArrayBaseSlot: Fr,
601
- ): Promise<void> {
602
- // We read all note and event validation requests and process them all concurrently. This makes the process much
603
- // faster as we don't need to wait for the network round-trip.
604
- const noteValidationRequests = (
605
- await this.capsuleDataProvider.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)
606
- ).map(NoteValidationRequest.fromFields);
607
-
608
- const eventValidationRequests = (
609
- await this.capsuleDataProvider.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)
610
- ).map(EventValidationRequest.fromFields);
611
-
612
- const noteDeliveries = noteValidationRequests.map(request =>
613
- this.deliverNote(
614
- request.contractAddress,
615
- request.owner,
616
- request.storageSlot,
617
- request.randomness,
618
- request.noteNonce,
619
- request.content,
620
- request.noteHash,
621
- request.nullifier,
622
- request.txHash,
623
- request.recipient,
624
- ),
625
- );
626
-
627
- const eventDeliveries = eventValidationRequests.map(request =>
628
- this.deliverEvent(
629
- request.contractAddress,
630
- request.eventTypeId,
631
- request.serializedEvent,
632
- request.eventCommitment,
633
- request.txHash,
634
- request.recipient,
635
- ),
636
- );
637
-
638
- await Promise.all([...noteDeliveries, ...eventDeliveries]);
639
-
640
- // Requests are cleared once we're done.
641
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
642
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
643
- }
644
-
645
- async deliverNote(
646
- contractAddress: AztecAddress,
647
- owner: AztecAddress,
648
- storageSlot: Fr,
649
- randomness: Fr,
650
- noteNonce: Fr,
651
- content: Fr[],
652
- noteHash: Fr,
653
- nullifier: Fr,
654
- txHash: TxHash,
655
- recipient: AztecAddress,
656
- ): Promise<void> {
657
- // We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
658
- // There's two things we need to check before we do this however:
659
- // - we must make sure the note does actually exist in the note hash tree
660
- // - we need to check if the note has already been nullified
661
- //
662
- // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
663
- // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
664
- // are catastrophic failure modes.
665
- //
666
- // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
667
- // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
668
- // so we must store both the note hash and nullifier block information.
669
-
670
- // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
671
- // in time of the locally synced state.
672
- // Note that while this technically results in historical queries, we perform it at the latest locally synced block
673
- // number which *should* be recent enough to be available, even for non-archive nodes.
674
- // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
675
- // logs up to the synced block making this only an additional safety check.
676
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
677
-
678
- // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
679
- // of other contracts, which would constitute a security breach.
680
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
681
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
682
-
683
- const txEffect = await this.aztecNode.getTxEffect(txHash);
684
- if (!txEffect) {
685
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
686
- }
687
-
688
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
689
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
690
- }
691
-
692
- const noteInTx = txEffect.data.noteHashes.some(nh => nh.equals(uniqueNoteHash));
693
- if (!noteInTx) {
694
- throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
695
- }
696
-
697
- // We store notes by their index in the global note hash tree, which has the convenient side effect of validating
698
- // note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
699
- // queries in a single round-trip.
700
- const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
701
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]),
702
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
703
- ]);
704
-
705
- if (uniqueNoteHashTreeIndexInBlock === undefined) {
706
- throw new Error(
707
- `Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`,
708
- );
709
- }
710
-
711
- const noteDao = new NoteDao(
712
- new Note(content),
713
- contractAddress,
714
- owner,
715
- storageSlot,
716
- randomness,
717
- noteNonce,
718
- noteHash,
719
- siloedNullifier,
720
- txHash,
721
- uniqueNoteHashTreeIndexInBlock.l2BlockNumber,
722
- uniqueNoteHashTreeIndexInBlock.l2BlockHash.toString(),
723
- uniqueNoteHashTreeIndexInBlock.data,
724
- );
725
-
726
- // The note was found by `recipient`, so we use that as the scope when storing the note.
727
- await this.noteDataProvider.addNotes([noteDao], recipient);
728
- this.log.verbose('Added note', {
729
- index: noteDao.index,
730
- contract: noteDao.contractAddress.toString(),
731
- slot: noteDao.storageSlot.toString(),
732
- noteHash: noteDao.noteHash.toString(),
733
- nullifier: noteDao.siloedNullifier.toString(),
734
- });
735
-
736
- if (nullifierIndex !== undefined) {
737
- const { data: _, ...blockHashAndNum } = nullifierIndex;
738
- await this.noteDataProvider.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }]);
739
-
740
- this.log.verbose(`Removed just-added note`, {
741
- contract: contractAddress,
742
- slot: storageSlot,
743
- noteHash: noteHash,
744
- nullifier: siloedNullifier.toString(),
745
- });
746
- }
747
- }
748
-
749
- public async bulkRetrieveLogs(
750
- contractAddress: AztecAddress,
751
- logRetrievalRequestsArrayBaseSlot: Fr,
752
- logRetrievalResponsesArrayBaseSlot: Fr,
753
- ) {
754
- // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
755
- // don't need to wait for the network round-trip.
756
- const logRetrievalRequests = (
757
- await this.capsuleDataProvider.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)
758
- ).map(LogRetrievalRequest.fromFields);
759
-
760
- const maybeLogRetrievalResponses = await Promise.all(
761
- logRetrievalRequests.map(async request => {
762
- // TODO(#14555): remove these internal functions and have node endpoints that do this instead
763
- const [publicLog, privateLog] = await Promise.all([
764
- this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
765
- this.getPrivateLogByTag(await siloPrivateLog(request.contractAddress, request.unsiloedTag)),
766
- ]);
767
-
768
- if (publicLog !== null) {
769
- if (privateLog !== null) {
770
- throw new Error(
771
- `Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`,
772
- );
773
- }
774
-
775
- return new LogRetrievalResponse(
776
- publicLog.logPayload,
777
- publicLog.txHash,
778
- publicLog.uniqueNoteHashesInTx,
779
- publicLog.firstNullifierInTx,
780
- );
781
- } else if (privateLog !== null) {
782
- return new LogRetrievalResponse(
783
- privateLog.logPayload,
784
- privateLog.txHash,
785
- privateLog.uniqueNoteHashesInTx,
786
- privateLog.firstNullifierInTx,
787
- );
788
- } else {
789
- return null;
790
- }
791
- }),
792
- );
793
-
794
- // Requests are cleared once we're done.
795
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
796
-
797
- // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
798
- await this.capsuleDataProvider.setCapsuleArray(
799
- contractAddress,
800
- logRetrievalResponsesArrayBaseSlot,
801
- maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
802
- );
803
- }
804
-
805
- async deliverEvent(
806
- contractAddress: AztecAddress,
807
- selector: EventSelector,
808
- content: Fr[],
809
- eventCommitment: Fr,
810
- txHash: TxHash,
811
- scope: AztecAddress,
812
- ): Promise<void> {
813
- // While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
814
- // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
815
- // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
816
- // since `fetchTaggedLogs` only processes logs up to the synced block.
817
- const [syncedBlockNumber, siloedEventCommitment, txEffect] = await Promise.all([
818
- this.syncDataProvider.getBlockNumber(),
819
- siloNullifier(contractAddress, eventCommitment),
820
- this.aztecNode.getTxEffect(txHash),
821
- ]);
822
-
823
- if (!txEffect) {
824
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
825
- }
826
-
827
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
828
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
829
- }
830
-
831
- const eventInTx = txEffect.data.nullifiers.some(n => n.equals(siloedEventCommitment));
832
- if (!eventInTx) {
833
- throw new Error(
834
- `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`,
835
- );
836
- }
837
-
838
- const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
839
- siloedEventCommitment,
840
- ]);
841
-
842
- if (nullifierIndex === undefined) {
843
- throw new Error(
844
- `Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`,
845
- );
846
- }
847
-
848
- return this.privateEventDataProvider.storePrivateEventLog(
849
- selector,
850
- content,
851
- Number(nullifierIndex.data), // Index of the event commitment in the nullifier tree
852
- {
853
- contractAddress,
854
- scope,
855
- txHash,
856
- l2BlockNumber: nullifierIndex.l2BlockNumber, // Block number in which the event was emitted
857
- l2BlockHash: nullifierIndex.l2BlockHash, // Block hash in which the event was emitted
858
- },
859
- );
860
- }
861
-
862
- // TODO(#14555): delete this function and implement this behavior in the node instead
863
- async getPublicLogByTag(tag: Fr, contractAddress: AztecAddress): Promise<PublicLogWithTxData | null> {
864
- const logs = await this.#getPublicLogsByTagsFromContract([tag], contractAddress);
865
- const logsForTag = logs[0];
866
-
867
- this.log.debug(`Got ${logsForTag.length} public logs for tag ${tag}`);
868
-
869
- if (logsForTag.length == 0) {
870
- return null;
871
- } else if (logsForTag.length > 1) {
872
- // TODO(#11627): handle this case
873
- throw new Error(
874
- `Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`,
875
- );
876
- }
877
-
878
- const scopedLog = logsForTag[0];
879
-
880
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
881
- // we need to make a second call to the node for `getTxEffect`.
882
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
883
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
884
- if (txEffect == undefined) {
885
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
886
- }
887
-
888
- return new PublicLogWithTxData(
889
- scopedLog.log.getEmittedFieldsWithoutTag(),
890
- scopedLog.txHash,
891
- txEffect.data.noteHashes,
892
- txEffect.data.nullifiers[0],
893
- );
894
- }
895
-
896
- // TODO(#14555): delete this function and implement this behavior in the node instead
897
- async getPrivateLogByTag(siloedTag: Fr): Promise<PrivateLogWithTxData | null> {
898
- const logs = await this.#getPrivateLogsByTags([siloedTag]);
899
- const logsForTag = logs[0];
900
-
901
- this.log.debug(`Got ${logsForTag.length} private logs for tag ${siloedTag}`);
902
-
903
- if (logsForTag.length == 0) {
904
- return null;
905
- } else if (logsForTag.length > 1) {
906
- // TODO(#11627): handle this case
907
- throw new Error(
908
- `Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`,
909
- );
910
- }
911
-
912
- const scopedLog = logsForTag[0];
913
-
914
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
915
- // we need to make a second call to the node for `getTxEffect`.
916
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
917
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
918
- if (txEffect == undefined) {
919
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
920
- }
921
-
922
- return new PrivateLogWithTxData(
923
- scopedLog.log.getEmittedFieldsWithoutTag(),
924
- scopedLog.txHash,
925
- txEffect.data.noteHashes,
926
- txEffect.data.nullifiers[0],
927
- );
928
- }
929
-
930
- /**
931
- * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
932
- *
933
- * Fetches notes from the NoteDataProvider and checks which nullifiers are present in the
934
- * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
935
- * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
936
- * notes are only marked nullified once their corresponding nullifier has been included in a
937
- * block up to which the PXE has synced.
938
- * This allows recent nullifications to be processed even if the node is not an archive node.
939
- *
940
- * @param contractAddress - The contract whose notes should be checked and nullified.
941
- */
942
- public async syncNoteNullifiers(contractAddress: AztecAddress) {
943
- this.log.verbose('Searching for nullifiers of known notes', { contract: contractAddress });
944
-
945
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
946
-
947
- const contractNotes = await this.noteDataProvider.getNotes({ contractAddress });
948
-
949
- if (contractNotes.length === 0) {
950
- return;
951
- }
952
-
953
- const nullifiersToCheck = contractNotes.map(note => note.siloedNullifier);
954
- const nullifierBatches = nullifiersToCheck.reduce(
955
- (acc, nullifier) => {
956
- if (acc[acc.length - 1].length < MAX_RPC_LEN) {
957
- acc[acc.length - 1].push(nullifier);
958
- } else {
959
- acc.push([nullifier]);
960
- }
961
- return acc;
962
- },
963
- [[]] as Fr[][],
964
- );
965
- const nullifierIndexes = (
966
- await Promise.all(
967
- nullifierBatches.map(batch =>
968
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, batch),
969
- ),
970
- )
971
- ).flat();
972
-
973
- const foundNullifiers = nullifiersToCheck
974
- .map((nullifier, i) => {
975
- if (nullifierIndexes[i] !== undefined) {
976
- return { ...nullifierIndexes[i], ...{ data: nullifier } } as DataInBlock<Fr>;
977
- }
978
- })
979
- .filter(nullifier => nullifier !== undefined) as DataInBlock<Fr>[];
980
-
981
- const nullifiedNotes = await this.noteDataProvider.applyNullifiers(foundNullifiers);
982
- nullifiedNotes.forEach(noteDao => {
983
- this.log.verbose(`Removed note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, {
984
- contract: noteDao.contractAddress,
985
- slot: noteDao.storageSlot,
986
- nullifier: noteDao.siloedNullifier.toString(),
987
- });
988
- });
989
- }
990
-
991
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
992
- return this.capsuleDataProvider.storeCapsule(contractAddress, slot, capsule);
993
- }
994
-
995
- loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
996
- return this.capsuleDataProvider.loadCapsule(contractAddress, slot);
997
- }
998
-
999
- deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
1000
- return this.capsuleDataProvider.deleteCapsule(contractAddress, slot);
1001
- }
1002
-
1003
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
1004
- return this.capsuleDataProvider.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
1005
- }
1006
-
1007
- async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
1008
- // TODO(#12656): return an app-siloed secret
1009
- const recipientCompleteAddress = await this.getCompleteAddress(address);
1010
- const ivskM = await this.keyStore.getMasterSecretKey(
1011
- recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
1012
- );
1013
- const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
1014
- return deriveEcdhSharedSecret(addressSecret, ephPk);
1015
- }
1016
-
1017
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
1018
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
1019
- async #getPrivateLogsByTags(tags: Fr[]): Promise<TxScopedL2Log[][]> {
1020
- const allLogs = await this.aztecNode.getLogsByTags(tags);
1021
- return allLogs.map(logs => logs.filter(log => !log.isFromPublic));
1022
- }
1023
-
1024
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
1025
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
1026
- async #getPublicLogsByTagsFromContract(tags: Fr[], contractAddress: AztecAddress): Promise<TxScopedL2Log[][]> {
1027
- const allLogs = await this.aztecNode.getLogsByTags(tags);
1028
- const allPublicLogs = allLogs.map(logs => logs.filter(log => log.isFromPublic));
1029
- return allPublicLogs.map(logs =>
1030
- logs.filter(log => (log.log as PublicLog).contractAddress.equals(contractAddress)),
1031
- );
1032
- }
1033
-
1034
- getStats(): ExecutionStats {
1035
- const nodeRPCCalls =
1036
- typeof (this.aztecNode as ProxiedNode).getStats === 'function' ? (this.aztecNode as ProxiedNode).getStats() : {};
1037
-
1038
- return { nodeRPCCalls };
1039
- }
1040
- }