@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,713 +0,0 @@
1
- import { timesParallel } from '@aztec/foundation/collection';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { computeUniqueNoteHash, siloNoteHash, siloNullifier, siloPrivateLog } from '@aztec/stdlib/hash';
4
- import { MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
5
- import { computeAddressSecret } from '@aztec/stdlib/keys';
6
- import { PendingTaggedLog, PrivateLogWithTxData, PublicLogWithTxData, deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
7
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
8
- import { Note } from '@aztec/stdlib/note';
9
- import { NoteDao } from '@aztec/stdlib/note';
10
- import { MerkleTreeId } from '@aztec/stdlib/trees';
11
- import { MessageLoadOracleInputs } from '../contract_function_simulator/oracle/message_load_oracle_inputs.js';
12
- import { ORACLE_VERSION } from '../oracle_version.js';
13
- import { DirectionalAppTaggingSecret, SiloedTag, Tag, WINDOW_HALF_SIZE, getInitialIndexesMap, getPreTagsForTheWindow } from '../tagging/index.js';
14
- import { EventValidationRequest } from './noir-structs/event_validation_request.js';
15
- import { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
16
- import { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
17
- import { NoteValidationRequest } from './noir-structs/note_validation_request.js';
18
- /**
19
- * A data layer that provides and stores information needed for simulating/proving a transaction.
20
- */ export class PXEOracleInterface {
21
- aztecNode;
22
- keyStore;
23
- contractDataProvider;
24
- noteDataProvider;
25
- capsuleDataProvider;
26
- syncDataProvider;
27
- taggingDataProvider;
28
- addressDataProvider;
29
- privateEventDataProvider;
30
- log;
31
- constructor(aztecNode, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, log = createLogger('pxe:pxe_oracle_interface')){
32
- this.aztecNode = aztecNode;
33
- this.keyStore = keyStore;
34
- this.contractDataProvider = contractDataProvider;
35
- this.noteDataProvider = noteDataProvider;
36
- this.capsuleDataProvider = capsuleDataProvider;
37
- this.syncDataProvider = syncDataProvider;
38
- this.taggingDataProvider = taggingDataProvider;
39
- this.addressDataProvider = addressDataProvider;
40
- this.privateEventDataProvider = privateEventDataProvider;
41
- this.log = log;
42
- }
43
- getKeyValidationRequest(pkMHash, contractAddress) {
44
- return this.keyStore.getKeyValidationRequest(pkMHash, contractAddress);
45
- }
46
- async getCompleteAddress(account) {
47
- const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
48
- if (!completeAddress) {
49
- throw new Error(`No public key registered for address ${account}.
50
- 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`);
51
- }
52
- return completeAddress;
53
- }
54
- async getContractInstance(address) {
55
- const instance = await this.contractDataProvider.getContractInstance(address);
56
- if (!instance) {
57
- throw new Error(`No contract instance found for address ${address.toString()}`);
58
- }
59
- return instance;
60
- }
61
- async getNotes(contractAddress, owner, storageSlot, status, scopes) {
62
- const noteDaos = await this.noteDataProvider.getNotes({
63
- contractAddress,
64
- owner,
65
- storageSlot,
66
- status,
67
- scopes
68
- });
69
- return noteDaos.map(({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier, index })=>({
70
- contractAddress,
71
- owner,
72
- storageSlot,
73
- randomness,
74
- noteNonce,
75
- note,
76
- noteHash,
77
- siloedNullifier,
78
- // PXE can use this index to get full MembershipWitness
79
- index
80
- }));
81
- }
82
- async getFunctionArtifact(contractAddress, selector) {
83
- const artifact = await this.contractDataProvider.getFunctionArtifact(contractAddress, selector);
84
- if (!artifact) {
85
- throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
86
- }
87
- const debug = await this.contractDataProvider.getFunctionDebugMetadata(contractAddress, selector);
88
- return {
89
- ...artifact,
90
- debug
91
- };
92
- }
93
- /**
94
- * Fetches a message from the db, given its key.
95
- * @param contractAddress - Address of a contract by which the message was emitted.
96
- * @param messageHash - Hash of the message.
97
- * @param secret - Secret used to compute a nullifier.
98
- * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
99
- * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
100
- */ async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
101
- const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
102
- // Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
103
- return new MessageLoadOracleInputs(messageIndex, siblingPath);
104
- }
105
- async getNullifierIndex(nullifier) {
106
- return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
107
- }
108
- async #findLeafIndex(blockNumber, treeId, leafValue) {
109
- const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [
110
- leafValue
111
- ]);
112
- return leafIndex?.data;
113
- }
114
- async getMembershipWitness(blockNumber, treeId, leafValue) {
115
- const witness = await this.#tryGetMembershipWitness(blockNumber, treeId, leafValue);
116
- if (!witness) {
117
- throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block ${blockNumber}`);
118
- }
119
- return witness;
120
- }
121
- async #tryGetMembershipWitness(blockNumber, treeId, value) {
122
- switch(treeId){
123
- case MerkleTreeId.NULLIFIER_TREE:
124
- return (await this.aztecNode.getNullifierMembershipWitness(blockNumber, value))?.withoutPreimage().toFields();
125
- case MerkleTreeId.NOTE_HASH_TREE:
126
- return (await this.aztecNode.getNoteHashMembershipWitness(blockNumber, value))?.toFields();
127
- case MerkleTreeId.PUBLIC_DATA_TREE:
128
- return (await this.aztecNode.getPublicDataWitness(blockNumber, value))?.withoutPreimage().toFields();
129
- case MerkleTreeId.ARCHIVE:
130
- return (await this.aztecNode.getArchiveMembershipWitness(blockNumber, value))?.toFields();
131
- default:
132
- throw new Error('Not implemented');
133
- }
134
- }
135
- async getNullifierMembershipWitnessAtLatestBlock(nullifier) {
136
- const blockNumber = (await this.getAnchorBlockHeader()).globalVariables.blockNumber;
137
- return this.getNullifierMembershipWitness(blockNumber, nullifier);
138
- }
139
- getNullifierMembershipWitness(blockNumber, nullifier) {
140
- return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
141
- }
142
- async getLowNullifierMembershipWitness(blockNumber, nullifier) {
143
- const header = await this.getAnchorBlockHeader();
144
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
145
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
146
- }
147
- return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
148
- }
149
- async getBlock(blockNumber) {
150
- const header = await this.getAnchorBlockHeader();
151
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
152
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
153
- }
154
- return await this.aztecNode.getBlock(blockNumber);
155
- }
156
- async getPublicDataWitness(blockNumber, leafSlot) {
157
- const header = await this.getAnchorBlockHeader();
158
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
159
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
160
- }
161
- return await this.aztecNode.getPublicDataWitness(blockNumber, leafSlot);
162
- }
163
- async getPublicStorageAt(blockNumber, contract, slot) {
164
- const header = await this.getAnchorBlockHeader();
165
- if (blockNumber !== 'latest' && blockNumber > header.globalVariables.blockNumber) {
166
- throw new Error(`Block number ${blockNumber} is higher than current block ${header.globalVariables.blockNumber}`);
167
- }
168
- return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
169
- }
170
- getAnchorBlockHeader() {
171
- return this.syncDataProvider.getBlockHeader();
172
- }
173
- assertCompatibleOracleVersion(version) {
174
- if (version !== ORACLE_VERSION) {
175
- throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
176
- }
177
- }
178
- getDebugFunctionName(contractAddress, selector) {
179
- return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
180
- }
181
- /**
182
- * Returns the full contents of your address book.
183
- * This is used when calculating tags for incoming notes by deriving the shared secret, the contract-siloed tagging secret, and
184
- * finally the index specified tag. We will then query the node with this tag for each address in the address book.
185
- * @returns The full list of the users contact addresses.
186
- */ getSenders() {
187
- return this.taggingDataProvider.getSenderAddresses();
188
- }
189
- getLastUsedIndexAsSender(secret) {
190
- return this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
191
- }
192
- async calculateDirectionalAppTaggingSecret(contractAddress, sender, recipient) {
193
- const senderCompleteAddress = await this.getCompleteAddress(sender);
194
- const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
195
- return DirectionalAppTaggingSecret.compute(senderCompleteAddress, senderIvsk, recipient, contractAddress, recipient);
196
- }
197
- /**
198
- * Returns the last used tagging indexes along with the directional app tagging secrets for a given recipient and all
199
- * the senders in the address book.
200
- * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
201
- * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
202
- * so we're keeping it private for now.
203
- * @param contractAddress - The contract address to silo the secret for
204
- * @param recipient - The address receiving the notes
205
- * @returns A list of directional app tagging secrets along with the last used tagging indexes. If the corresponding
206
- * secret was never used, the index is undefined.
207
- * TODO(benesjan): The naming here is broken as the function name does not reflect the return type. Fix when associating
208
- * indexes with tx hash.
209
- */ async #getLastUsedTaggingIndexesForSenders(contractAddress, recipient) {
210
- const recipientCompleteAddress = await this.getCompleteAddress(recipient);
211
- const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
212
- // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
213
- // (recipient = us, sender = us)
214
- const senders = [
215
- ...await this.taggingDataProvider.getSenderAddresses(),
216
- ...await this.keyStore.getAccounts()
217
- ].filter((address, index, self)=>index === self.findIndex((otherAddress)=>otherAddress.equals(address)));
218
- const secrets = await Promise.all(senders.map((contact)=>{
219
- return DirectionalAppTaggingSecret.compute(recipientCompleteAddress, recipientIvsk, contact, contractAddress, recipient);
220
- }));
221
- const indexes = await this.taggingDataProvider.getLastUsedIndexesAsRecipient(secrets);
222
- if (indexes.length !== secrets.length) {
223
- throw new Error('Indexes and directional app tagging secrets have different lengths');
224
- }
225
- return secrets.map((secret, i)=>({
226
- secret,
227
- index: indexes[i]
228
- }));
229
- }
230
- async syncTaggedLogsAsSender(secret, contractAddress) {
231
- const lastUsedIndex = await this.taggingDataProvider.getLastUsedIndexesAsSender(secret);
232
- // If lastUsedIndex is undefined, we've never used this secret, so start from 0
233
- // Otherwise, start from one past the last used index
234
- const startIndex = lastUsedIndex === undefined ? 0 : lastUsedIndex + 1;
235
- // This algorithm works such that:
236
- // 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
237
- // we found and quit.
238
- // 2. If we don't find minimum consecutive empty logs in a window of logs we slide the window to latest log index
239
- // and repeat the process.
240
- const MIN_CONSECUTIVE_EMPTY_LOGS = 10;
241
- const WINDOW_SIZE = MIN_CONSECUTIVE_EMPTY_LOGS * 2;
242
- let [numConsecutiveEmptyLogs, currentIndex] = [
243
- 0,
244
- startIndex
245
- ];
246
- let lastFoundLogIndex = undefined;
247
- do {
248
- // We compute the tags for the current window of indexes
249
- const currentTags = await timesParallel(WINDOW_SIZE, async (i)=>{
250
- return SiloedTag.compute(await Tag.compute({
251
- secret,
252
- index: currentIndex + i
253
- }), contractAddress);
254
- });
255
- // We fetch the logs for the tags
256
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
257
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
258
- const tagsAsFr = currentTags.map((tag)=>tag.value);
259
- const possibleLogs = await this.#getPrivateLogsByTags(tagsAsFr);
260
- // We find the index of the last log in the window that is not empty
261
- const indexOfLastLogWithinArray = possibleLogs.findLastIndex((possibleLog)=>possibleLog.length !== 0);
262
- if (indexOfLastLogWithinArray === -1) {
263
- break;
264
- }
265
- // We've found logs so we update the last found log index
266
- lastFoundLogIndex = (lastFoundLogIndex ?? 0) + indexOfLastLogWithinArray;
267
- // We move the current index to that of the log right after the last found log
268
- currentIndex = lastFoundLogIndex + 1;
269
- // We compute the number of consecutive empty logs we found and repeat the process if we haven't found enough.
270
- numConsecutiveEmptyLogs = WINDOW_SIZE - indexOfLastLogWithinArray - 1;
271
- }while (numConsecutiveEmptyLogs < MIN_CONSECUTIVE_EMPTY_LOGS)
272
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
273
- if (lastFoundLogIndex !== undefined) {
274
- // Last found index is defined meaning we have actually found logs so we update the last used index
275
- await this.taggingDataProvider.setLastUsedIndexesAsSender([
276
- {
277
- secret,
278
- index: lastFoundLogIndex
279
- }
280
- ]);
281
- this.log.debug(`Syncing logs for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`, {
282
- index: currentIndex,
283
- contractName,
284
- contractAddress
285
- });
286
- } else {
287
- this.log.debug(`No new logs found for secret ${secret.toString()} at contract ${contractName}(${contractAddress})`);
288
- }
289
- }
290
- /**
291
- * Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
292
- * logs in CapsuleArray ready for a later retrieval in Aztec.nr.
293
- * @param contractAddress - The address of the contract that the logs are tagged for.
294
- * @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged logs capsule array in which
295
- * found logs will be stored.
296
- * @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
297
- * synced.
298
- */ async syncTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, scopes) {
299
- this.log.verbose('Searching for tagged logs', {
300
- contract: contractAddress
301
- });
302
- const maxBlockNumber = await this.syncDataProvider.getBlockNumber();
303
- // Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
304
- // However it is impossible at the moment due to the language not supporting nested slices.
305
- // This nesting is necessary because for a given set of tags we don't
306
- // know how many logs we will get back. Furthermore, these logs are of undetermined
307
- // length, since we don't really know the note they correspond to until we decrypt them.
308
- const recipients = scopes ? scopes : await this.keyStore.getAccounts();
309
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
310
- for (const recipient of recipients){
311
- // Get all the secrets for the recipient and sender pairs (#9365)
312
- const indexedSecrets = await this.#getLastUsedTaggingIndexesForSenders(contractAddress, recipient);
313
- // We fetch logs for a window of indexes in a range:
314
- // <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
315
- //
316
- // We use this window approach because it could happen that a sender might have messed up and inadvertently
317
- // incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
318
- // for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
319
- // Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
320
- // some logs. For these reasons, we have to look both back and ahead of the stored index.
321
- let secretsAndWindows = indexedSecrets.map((indexedSecret)=>{
322
- if (indexedSecret.index === undefined) {
323
- return {
324
- secret: indexedSecret.secret,
325
- leftMostIndex: 0,
326
- rightMostIndex: WINDOW_HALF_SIZE
327
- };
328
- } else {
329
- return {
330
- secret: indexedSecret.secret,
331
- leftMostIndex: Math.max(0, indexedSecret.index - WINDOW_HALF_SIZE),
332
- rightMostIndex: indexedSecret.index + WINDOW_HALF_SIZE
333
- };
334
- }
335
- });
336
- // As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
337
- const newLargestIndexMapToStore = {};
338
- // The initial/unmodified indexes of the secrets stored in a key-value map where key is the directional app
339
- // tagging secret.
340
- const initialIndexesMap = getInitialIndexesMap(indexedSecrets);
341
- while(secretsAndWindows.length > 0){
342
- const preTagsForTheWholeWindow = getPreTagsForTheWindow(secretsAndWindows);
343
- const tagsForTheWholeWindow = await Promise.all(preTagsForTheWholeWindow.map(async (preTag)=>{
344
- return SiloedTag.compute(await Tag.compute(preTag), contractAddress);
345
- }));
346
- // We store the new largest indexes we find in the iteration in the following map to later on construct
347
- // a new set of secrets and windows to fetch logs for.
348
- const newLargestIndexMapForIteration = {};
349
- // Fetch the private logs for the tags and iterate over them
350
- // TODO: The following conversion is unfortunate and we should most likely just type the #getPrivateLogsByTags
351
- // to accept SiloedTag[] instead of Fr[]. That would result in a large change so I didn't do it yet.
352
- const tagsForTheWholeWindowAsFr = tagsForTheWholeWindow.map((tag)=>tag.value);
353
- const logsByTags = await this.#getPrivateLogsByTags(tagsForTheWholeWindowAsFr);
354
- this.log.debug(`Found ${logsByTags.filter((logs)=>logs.length > 0).length} logs as recipient ${recipient}`, {
355
- recipient,
356
- contractName,
357
- contractAddress
358
- });
359
- for(let logIndex = 0; logIndex < logsByTags.length; logIndex++){
360
- const logsByTag = logsByTags[logIndex];
361
- if (logsByTag.length > 0) {
362
- // We filter out the logs that are newer than the anchor block number of the tx currently being constructed
363
- const filteredLogsByBlockNumber = logsByTag.filter((l)=>l.blockNumber <= maxBlockNumber);
364
- // We store the logs in capsules (to later be obtained in Noir)
365
- await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, filteredLogsByBlockNumber);
366
- // We retrieve the pre tag corresponding to the log as I need that to evaluate whether
367
- // a new largest index have been found.
368
- const preTagCorrespondingToLog = preTagsForTheWholeWindow[logIndex];
369
- const initialIndex = initialIndexesMap[preTagCorrespondingToLog.secret.toString()];
370
- if (preTagCorrespondingToLog.index >= initialIndex && (newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] === undefined || preTagCorrespondingToLog.index >= newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()])) {
371
- // We have found a new largest index so we store it for later processing (storing it in the db + fetching
372
- // the difference of the window sets of current and the next iteration)
373
- newLargestIndexMapForIteration[preTagCorrespondingToLog.secret.toString()] = preTagCorrespondingToLog.index + 1;
374
- this.log.debug(`Incrementing index to ${preTagCorrespondingToLog.index + 1} at contract ${contractName}(${contractAddress})`);
375
- }
376
- }
377
- }
378
- // Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
379
- // for. Note that it's very unlikely that a new log from the current window would appear between the iterations
380
- // so we fetch the logs only for the difference of the window sets.
381
- const newSecretsAndWindows = [];
382
- for (const [directionalAppTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)){
383
- const maybeIndexedSecret = indexedSecrets.find((indexedSecret)=>indexedSecret.secret.toString() === directionalAppTaggingSecret);
384
- if (maybeIndexedSecret) {
385
- newSecretsAndWindows.push({
386
- secret: maybeIndexedSecret.secret,
387
- // We set the left most index to the new index to avoid fetching the same logs again
388
- leftMostIndex: newIndex,
389
- rightMostIndex: newIndex + WINDOW_HALF_SIZE
390
- });
391
- // We store the new largest index in the map to later store it in the db.
392
- newLargestIndexMapToStore[directionalAppTaggingSecret] = newIndex;
393
- } else {
394
- throw new Error(`Secret not found for directionalAppTaggingSecret ${directionalAppTaggingSecret}. This is a bug as it should never happen!`);
395
- }
396
- }
397
- // Now we set the new secrets and windows and proceed to the next iteration.
398
- secretsAndWindows = newSecretsAndWindows;
399
- }
400
- // At this point we have processed all the logs for the recipient so we store the last used indexes in the db.
401
- // newLargestIndexMapToStore contains "next" indexes to look for (one past the last found), so subtract 1 to get
402
- // last used.
403
- await this.taggingDataProvider.setLastUsedIndexesAsRecipient(Object.entries(newLargestIndexMapToStore).map(([directionalAppTaggingSecret, index])=>({
404
- secret: DirectionalAppTaggingSecret.fromString(directionalAppTaggingSecret),
405
- index: index - 1
406
- })));
407
- }
408
- }
409
- async #storePendingTaggedLogs(contractAddress, capsuleArrayBaseSlot, recipient, privateLogs) {
410
- // Build all pending tagged logs upfront with their tx effects
411
- const pendingTaggedLogs = await Promise.all(privateLogs.map(async (scopedLog)=>{
412
- // TODO(#9789): get these effects along with the log
413
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
414
- if (!txEffect) {
415
- throw new Error(`Could not find tx effect for tx hash ${scopedLog.txHash}`);
416
- }
417
- const pendingTaggedLog = new PendingTaggedLog(scopedLog.log.fields, scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0], recipient);
418
- return pendingTaggedLog.toFields();
419
- }));
420
- return this.capsuleDataProvider.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
421
- }
422
- async validateEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot) {
423
- // We read all note and event validation requests and process them all concurrently. This makes the process much
424
- // faster as we don't need to wait for the network round-trip.
425
- const noteValidationRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)).map(NoteValidationRequest.fromFields);
426
- const eventValidationRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)).map(EventValidationRequest.fromFields);
427
- const noteDeliveries = noteValidationRequests.map((request)=>this.deliverNote(request.contractAddress, request.owner, request.storageSlot, request.randomness, request.noteNonce, request.content, request.noteHash, request.nullifier, request.txHash, request.recipient));
428
- const eventDeliveries = eventValidationRequests.map((request)=>this.deliverEvent(request.contractAddress, request.eventTypeId, request.serializedEvent, request.eventCommitment, request.txHash, request.recipient));
429
- await Promise.all([
430
- ...noteDeliveries,
431
- ...eventDeliveries
432
- ]);
433
- // Requests are cleared once we're done.
434
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
435
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
436
- }
437
- async deliverNote(contractAddress, owner, storageSlot, randomness, noteNonce, content, noteHash, nullifier, txHash, recipient) {
438
- // We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
439
- // There's two things we need to check before we do this however:
440
- // - we must make sure the note does actually exist in the note hash tree
441
- // - we need to check if the note has already been nullified
442
- //
443
- // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
444
- // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
445
- // are catastrophic failure modes.
446
- //
447
- // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
448
- // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
449
- // so we must store both the note hash and nullifier block information.
450
- // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
451
- // in time of the locally synced state.
452
- // Note that while this technically results in historical queries, we perform it at the latest locally synced block
453
- // number which *should* be recent enough to be available, even for non-archive nodes.
454
- // Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
455
- // logs up to the synced block making this only an additional safety check.
456
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
457
- // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
458
- // of other contracts, which would constitute a security breach.
459
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
460
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
461
- const txEffect = await this.aztecNode.getTxEffect(txHash);
462
- if (!txEffect) {
463
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
464
- }
465
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
466
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
467
- }
468
- const noteInTx = txEffect.data.noteHashes.some((nh)=>nh.equals(uniqueNoteHash));
469
- if (!noteInTx) {
470
- throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
471
- }
472
- // We store notes by their index in the global note hash tree, which has the convenient side effect of validating
473
- // note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
474
- // queries in a single round-trip.
475
- const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
476
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [
477
- uniqueNoteHash
478
- ]),
479
- this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
480
- siloedNullifier
481
- ])
482
- ]);
483
- if (uniqueNoteHashTreeIndexInBlock === undefined) {
484
- throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`);
485
- }
486
- const noteDao = new NoteDao(new Note(content), contractAddress, owner, storageSlot, randomness, noteNonce, noteHash, siloedNullifier, txHash, uniqueNoteHashTreeIndexInBlock.l2BlockNumber, uniqueNoteHashTreeIndexInBlock.l2BlockHash.toString(), uniqueNoteHashTreeIndexInBlock.data);
487
- // The note was found by `recipient`, so we use that as the scope when storing the note.
488
- await this.noteDataProvider.addNotes([
489
- noteDao
490
- ], recipient);
491
- this.log.verbose('Added note', {
492
- index: noteDao.index,
493
- contract: noteDao.contractAddress.toString(),
494
- slot: noteDao.storageSlot.toString(),
495
- noteHash: noteDao.noteHash.toString(),
496
- nullifier: noteDao.siloedNullifier.toString()
497
- });
498
- if (nullifierIndex !== undefined) {
499
- const { data: _, ...blockHashAndNum } = nullifierIndex;
500
- await this.noteDataProvider.applyNullifiers([
501
- {
502
- data: siloedNullifier,
503
- ...blockHashAndNum
504
- }
505
- ]);
506
- this.log.verbose(`Removed just-added note`, {
507
- contract: contractAddress,
508
- slot: storageSlot,
509
- noteHash: noteHash,
510
- nullifier: siloedNullifier.toString()
511
- });
512
- }
513
- }
514
- async bulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot) {
515
- // We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
516
- // don't need to wait for the network round-trip.
517
- const logRetrievalRequests = (await this.capsuleDataProvider.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)).map(LogRetrievalRequest.fromFields);
518
- const maybeLogRetrievalResponses = await Promise.all(logRetrievalRequests.map(async (request)=>{
519
- // TODO(#14555): remove these internal functions and have node endpoints that do this instead
520
- const [publicLog, privateLog] = await Promise.all([
521
- this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
522
- this.getPrivateLogByTag(await siloPrivateLog(request.contractAddress, request.unsiloedTag))
523
- ]);
524
- if (publicLog !== null) {
525
- if (privateLog !== null) {
526
- throw new Error(`Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`);
527
- }
528
- return new LogRetrievalResponse(publicLog.logPayload, publicLog.txHash, publicLog.uniqueNoteHashesInTx, publicLog.firstNullifierInTx);
529
- } else if (privateLog !== null) {
530
- return new LogRetrievalResponse(privateLog.logPayload, privateLog.txHash, privateLog.uniqueNoteHashesInTx, privateLog.firstNullifierInTx);
531
- } else {
532
- return null;
533
- }
534
- }));
535
- // Requests are cleared once we're done.
536
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
537
- // The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
538
- await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalResponsesArrayBaseSlot, maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption));
539
- }
540
- async deliverEvent(contractAddress, selector, content, eventCommitment, txHash, scope) {
541
- // While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
542
- // (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
543
- // maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
544
- // since `fetchTaggedLogs` only processes logs up to the synced block.
545
- const [syncedBlockNumber, siloedEventCommitment, txEffect] = await Promise.all([
546
- this.syncDataProvider.getBlockNumber(),
547
- siloNullifier(contractAddress, eventCommitment),
548
- this.aztecNode.getTxEffect(txHash)
549
- ]);
550
- if (!txEffect) {
551
- throw new Error(`Could not find tx effect for tx hash ${txHash}`);
552
- }
553
- if (txEffect.l2BlockNumber > syncedBlockNumber) {
554
- throw new Error(`Could not find tx effect for tx hash ${txHash} as of block number ${syncedBlockNumber}`);
555
- }
556
- const eventInTx = txEffect.data.nullifiers.some((n)=>n.equals(siloedEventCommitment));
557
- if (!eventInTx) {
558
- throw new Error(`Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present in tx ${txHash}`);
559
- }
560
- const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
561
- siloedEventCommitment
562
- ]);
563
- if (nullifierIndex === undefined) {
564
- throw new Error(`Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`);
565
- }
566
- return this.privateEventDataProvider.storePrivateEventLog(selector, content, Number(nullifierIndex.data), {
567
- contractAddress,
568
- scope,
569
- txHash,
570
- l2BlockNumber: nullifierIndex.l2BlockNumber,
571
- l2BlockHash: nullifierIndex.l2BlockHash
572
- });
573
- }
574
- // TODO(#14555): delete this function and implement this behavior in the node instead
575
- async getPublicLogByTag(tag, contractAddress) {
576
- const logs = await this.#getPublicLogsByTagsFromContract([
577
- tag
578
- ], contractAddress);
579
- const logsForTag = logs[0];
580
- this.log.debug(`Got ${logsForTag.length} public logs for tag ${tag}`);
581
- if (logsForTag.length == 0) {
582
- return null;
583
- } else if (logsForTag.length > 1) {
584
- // TODO(#11627): handle this case
585
- throw new Error(`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`);
586
- }
587
- const scopedLog = logsForTag[0];
588
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
589
- // we need to make a second call to the node for `getTxEffect`.
590
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
591
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
592
- if (txEffect == undefined) {
593
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
594
- }
595
- return new PublicLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
596
- }
597
- // TODO(#14555): delete this function and implement this behavior in the node instead
598
- async getPrivateLogByTag(siloedTag) {
599
- const logs = await this.#getPrivateLogsByTags([
600
- siloedTag
601
- ]);
602
- const logsForTag = logs[0];
603
- this.log.debug(`Got ${logsForTag.length} private logs for tag ${siloedTag}`);
604
- if (logsForTag.length == 0) {
605
- return null;
606
- } else if (logsForTag.length > 1) {
607
- // TODO(#11627): handle this case
608
- throw new Error(`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`);
609
- }
610
- const scopedLog = logsForTag[0];
611
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
612
- // we need to make a second call to the node for `getTxEffect`.
613
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
614
- const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
615
- if (txEffect == undefined) {
616
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
617
- }
618
- return new PrivateLogWithTxData(scopedLog.log.getEmittedFieldsWithoutTag(), scopedLog.txHash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
619
- }
620
- /**
621
- * Looks for nullifiers of active contract notes and marks them as nullified if a nullifier is found.
622
- *
623
- * Fetches notes from the NoteDataProvider and checks which nullifiers are present in the
624
- * onchain nullifier Merkle tree - up to the latest locally synced block. We use the
625
- * locally synced block instead of querying the chain's 'latest' block to ensure correctness:
626
- * notes are only marked nullified once their corresponding nullifier has been included in a
627
- * block up to which the PXE has synced.
628
- * This allows recent nullifications to be processed even if the node is not an archive node.
629
- *
630
- * @param contractAddress - The contract whose notes should be checked and nullified.
631
- */ async syncNoteNullifiers(contractAddress) {
632
- this.log.verbose('Searching for nullifiers of known notes', {
633
- contract: contractAddress
634
- });
635
- const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
636
- const contractNotes = await this.noteDataProvider.getNotes({
637
- contractAddress
638
- });
639
- if (contractNotes.length === 0) {
640
- return;
641
- }
642
- const nullifiersToCheck = contractNotes.map((note)=>note.siloedNullifier);
643
- const nullifierBatches = nullifiersToCheck.reduce((acc, nullifier)=>{
644
- if (acc[acc.length - 1].length < MAX_RPC_LEN) {
645
- acc[acc.length - 1].push(nullifier);
646
- } else {
647
- acc.push([
648
- nullifier
649
- ]);
650
- }
651
- return acc;
652
- }, [
653
- []
654
- ]);
655
- const nullifierIndexes = (await Promise.all(nullifierBatches.map((batch)=>this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, batch)))).flat();
656
- const foundNullifiers = nullifiersToCheck.map((nullifier, i)=>{
657
- if (nullifierIndexes[i] !== undefined) {
658
- return {
659
- ...nullifierIndexes[i],
660
- ...{
661
- data: nullifier
662
- }
663
- };
664
- }
665
- }).filter((nullifier)=>nullifier !== undefined);
666
- const nullifiedNotes = await this.noteDataProvider.applyNullifiers(foundNullifiers);
667
- nullifiedNotes.forEach((noteDao)=>{
668
- this.log.verbose(`Removed note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, {
669
- contract: noteDao.contractAddress,
670
- slot: noteDao.storageSlot,
671
- nullifier: noteDao.siloedNullifier.toString()
672
- });
673
- });
674
- }
675
- storeCapsule(contractAddress, slot, capsule) {
676
- return this.capsuleDataProvider.storeCapsule(contractAddress, slot, capsule);
677
- }
678
- loadCapsule(contractAddress, slot) {
679
- return this.capsuleDataProvider.loadCapsule(contractAddress, slot);
680
- }
681
- deleteCapsule(contractAddress, slot) {
682
- return this.capsuleDataProvider.deleteCapsule(contractAddress, slot);
683
- }
684
- copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
685
- return this.capsuleDataProvider.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
686
- }
687
- async getSharedSecret(address, ephPk) {
688
- // TODO(#12656): return an app-siloed secret
689
- const recipientCompleteAddress = await this.getCompleteAddress(address);
690
- const ivskM = await this.keyStore.getMasterSecretKey(recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey);
691
- const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
692
- return deriveEcdhSharedSecret(addressSecret, ephPk);
693
- }
694
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
695
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
696
- async #getPrivateLogsByTags(tags) {
697
- const allLogs = await this.aztecNode.getLogsByTags(tags);
698
- return allLogs.map((logs)=>logs.filter((log)=>!log.isFromPublic));
699
- }
700
- // TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
701
- // was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
702
- async #getPublicLogsByTagsFromContract(tags, contractAddress) {
703
- const allLogs = await this.aztecNode.getLogsByTags(tags);
704
- const allPublicLogs = allLogs.map((logs)=>logs.filter((log)=>log.isFromPublic));
705
- return allPublicLogs.map((logs)=>logs.filter((log)=>log.log.contractAddress.equals(contractAddress)));
706
- }
707
- getStats() {
708
- const nodeRPCCalls = typeof this.aztecNode.getStats === 'function' ? this.aztecNode.getStats() : {};
709
- return {
710
- nodeRPCCalls
711
- };
712
- }
713
- }