@aztec/pxe 0.0.0-test.1 → 0.0.1-commit.b655e406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/README.md +5 -5
  2. package/dest/bin/check_oracle_version.d.ts +2 -0
  3. package/dest/bin/check_oracle_version.d.ts.map +1 -0
  4. package/dest/bin/check_oracle_version.js +39 -0
  5. package/dest/config/index.d.ts +10 -15
  6. package/dest/config/index.d.ts.map +1 -1
  7. package/dest/config/index.js +11 -20
  8. package/dest/config/package_info.js +1 -1
  9. package/dest/contract_function_simulator/contract_function_simulator.d.ts +56 -0
  10. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  11. package/dest/contract_function_simulator/contract_function_simulator.js +301 -0
  12. package/dest/contract_function_simulator/execution_data_provider.d.ts +274 -0
  13. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
  14. package/dest/contract_function_simulator/execution_data_provider.js +14 -0
  15. package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
  16. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  17. package/dest/contract_function_simulator/execution_note_cache.js +183 -0
  18. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
  19. package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
  20. package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
  21. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  22. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  23. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  24. package/dest/contract_function_simulator/index.d.ts +14 -0
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  26. package/dest/contract_function_simulator/index.js +12 -0
  27. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +20 -0
  28. package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
  29. package/dest/contract_function_simulator/noir-structs/event_validation_request.js +37 -0
  30. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +15 -0
  31. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
  32. package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +25 -0
  33. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
  34. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
  35. package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
  36. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +22 -0
  37. package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
  38. package/dest/contract_function_simulator/noir-structs/note_validation_request.js +42 -0
  39. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
  40. package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
  41. package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
  42. package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
  43. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  44. package/dest/contract_function_simulator/oracle/index.js +2 -0
  45. package/dest/contract_function_simulator/oracle/interfaces.d.ts +97 -0
  46. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
  47. package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
  48. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
  49. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  50. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  51. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +22 -0
  52. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
  53. package/dest/contract_function_simulator/oracle/note_packing_utils.js +49 -0
  54. package/dest/contract_function_simulator/oracle/oracle.d.ts +57 -0
  55. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  56. package/dest/contract_function_simulator/oracle/oracle.js +328 -0
  57. package/dest/contract_function_simulator/oracle/private_execution.d.ts +48 -0
  58. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  59. package/dest/contract_function_simulator/oracle/private_execution.js +123 -0
  60. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +236 -0
  61. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  62. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +417 -0
  63. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +154 -0
  64. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  65. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +265 -0
  66. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  67. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  68. package/dest/contract_function_simulator/pick_notes.js +51 -0
  69. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
  70. package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
  71. package/dest/contract_function_simulator/proxied_contract_data_source.js +62 -0
  72. package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
  73. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
  74. package/dest/contract_function_simulator/proxied_node.js +27 -0
  75. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +122 -0
  76. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
  77. package/dest/contract_function_simulator/pxe_oracle_interface.js +701 -0
  78. package/dest/entrypoints/client/bundle/index.d.ts +4 -2
  79. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  80. package/dest/entrypoints/client/bundle/index.js +3 -2
  81. package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
  82. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  83. package/dest/entrypoints/client/bundle/utils.js +18 -12
  84. package/dest/entrypoints/client/lazy/index.d.ts +4 -2
  85. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  86. package/dest/entrypoints/client/lazy/index.js +3 -2
  87. package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
  88. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  89. package/dest/entrypoints/client/lazy/utils.js +17 -11
  90. package/dest/entrypoints/{client/pxe_creation_options.d.ts → pxe_creation_options.d.ts} +4 -1
  91. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  92. package/dest/entrypoints/server/index.d.ts +5 -3
  93. package/dest/entrypoints/server/index.d.ts.map +1 -1
  94. package/dest/entrypoints/server/index.js +4 -3
  95. package/dest/entrypoints/server/utils.d.ts +7 -15
  96. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  97. package/dest/entrypoints/server/utils.js +34 -28
  98. package/dest/{pxe_service/error_enriching.d.ts → error_enriching.d.ts} +1 -1
  99. package/dest/error_enriching.d.ts.map +1 -0
  100. package/dest/{pxe_service/error_enriching.js → error_enriching.js} +26 -18
  101. package/dest/oracle_version.d.ts +3 -0
  102. package/dest/oracle_version.d.ts.map +1 -0
  103. package/dest/oracle_version.js +10 -0
  104. package/dest/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.d.ts +6 -6
  105. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -0
  106. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +271 -0
  107. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
  108. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
  109. package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
  110. package/dest/private_kernel/hints/index.d.ts +3 -0
  111. package/dest/private_kernel/hints/index.d.ts.map +1 -0
  112. package/dest/{kernel_prover → private_kernel}/hints/index.js +1 -0
  113. package/dest/private_kernel/index.d.ts +3 -0
  114. package/dest/private_kernel/index.d.ts.map +1 -0
  115. package/dest/private_kernel/index.js +2 -0
  116. package/dest/private_kernel/private_kernel_execution_prover.d.ts +44 -0
  117. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
  118. package/dest/private_kernel/private_kernel_execution_prover.js +285 -0
  119. package/dest/{kernel_prover/proving_data_oracle.d.ts → private_kernel/private_kernel_oracle.d.ts} +17 -28
  120. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
  121. package/dest/private_kernel/private_kernel_oracle.js +4 -0
  122. package/dest/{kernel_oracle/index.d.ts → private_kernel/private_kernel_oracle_impl.d.ts} +8 -8
  123. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -0
  124. package/dest/{kernel_oracle/index.js → private_kernel/private_kernel_oracle_impl.js} +19 -9
  125. package/dest/pxe.d.ts +233 -0
  126. package/dest/pxe.d.ts.map +1 -0
  127. package/dest/pxe.js +789 -0
  128. package/dest/storage/address_data_provider/address_data_provider.d.ts +1 -3
  129. package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -1
  130. package/dest/storage/address_data_provider/address_data_provider.js +0 -3
  131. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +14 -5
  132. package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -1
  133. package/dest/storage/capsule_data_provider/capsule_data_provider.js +85 -24
  134. package/dest/storage/contract_data_provider/contract_data_provider.d.ts +12 -47
  135. package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -1
  136. package/dest/storage/contract_data_provider/contract_data_provider.js +92 -70
  137. package/dest/storage/contract_data_provider/index.d.ts +0 -1
  138. package/dest/storage/contract_data_provider/index.d.ts.map +1 -1
  139. package/dest/storage/contract_data_provider/index.js +0 -1
  140. package/dest/storage/contract_data_provider/private_functions_tree.d.ts +2 -41
  141. package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -1
  142. package/dest/storage/contract_data_provider/private_functions_tree.js +9 -61
  143. package/dest/storage/index.d.ts +2 -3
  144. package/dest/storage/index.d.ts.map +1 -1
  145. package/dest/storage/index.js +2 -3
  146. package/dest/storage/metadata.d.ts +2 -0
  147. package/dest/storage/metadata.d.ts.map +1 -0
  148. package/dest/storage/metadata.js +1 -0
  149. package/dest/storage/note_data_provider/note_dao.d.ts +16 -22
  150. package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
  151. package/dest/storage/note_data_provider/note_dao.js +16 -20
  152. package/dest/storage/note_data_provider/note_data_provider.d.ts +71 -8
  153. package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
  154. package/dest/storage/note_data_provider/note_data_provider.js +133 -74
  155. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +43 -0
  156. package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +1 -0
  157. package/dest/storage/private_event_data_provider/private_event_data_provider.js +104 -0
  158. package/dest/storage/sync_data_provider/sync_data_provider.d.ts +2 -4
  159. package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -1
  160. package/dest/storage/sync_data_provider/sync_data_provider.js +2 -5
  161. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +28 -6
  162. package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -1
  163. package/dest/storage/tagging_data_provider/tagging_data_provider.js +48 -24
  164. package/dest/synchronizer/synchronizer.d.ts +7 -9
  165. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  166. package/dest/synchronizer/synchronizer.js +17 -19
  167. package/dest/tagging/constants.d.ts +2 -0
  168. package/dest/tagging/constants.d.ts.map +1 -0
  169. package/dest/tagging/constants.js +2 -0
  170. package/dest/tagging/index.d.ts +7 -0
  171. package/dest/tagging/index.d.ts.map +1 -0
  172. package/dest/tagging/index.js +5 -0
  173. package/dest/tagging/siloed_tag.d.ts +14 -0
  174. package/dest/tagging/siloed_tag.d.ts.map +1 -0
  175. package/dest/tagging/siloed_tag.js +20 -0
  176. package/dest/tagging/tag.d.ts +12 -0
  177. package/dest/tagging/tag.d.ts.map +1 -0
  178. package/dest/tagging/tag.js +17 -0
  179. package/dest/tagging/utils.d.ts +18 -0
  180. package/dest/tagging/utils.d.ts.map +1 -0
  181. package/dest/tagging/utils.js +24 -0
  182. package/package.json +34 -32
  183. package/src/bin/check_oracle_version.ts +50 -0
  184. package/src/config/index.ts +20 -33
  185. package/src/config/package_info.ts +1 -1
  186. package/src/contract_function_simulator/contract_function_simulator.ts +548 -0
  187. package/src/contract_function_simulator/execution_data_provider.ts +343 -0
  188. package/src/contract_function_simulator/execution_note_cache.ts +222 -0
  189. package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
  190. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  191. package/src/contract_function_simulator/index.ts +13 -0
  192. package/src/contract_function_simulator/noir-structs/event_validation_request.ts +47 -0
  193. package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +27 -0
  194. package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
  195. package/src/contract_function_simulator/noir-structs/note_validation_request.ts +52 -0
  196. package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
  197. package/src/contract_function_simulator/oracle/index.ts +16 -0
  198. package/src/contract_function_simulator/oracle/interfaces.ts +160 -0
  199. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  200. package/src/contract_function_simulator/oracle/note_packing_utils.ts +52 -0
  201. package/src/contract_function_simulator/oracle/oracle.ts +575 -0
  202. package/src/contract_function_simulator/oracle/private_execution.ts +207 -0
  203. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +625 -0
  204. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +358 -0
  205. package/src/contract_function_simulator/pick_notes.ts +141 -0
  206. package/src/contract_function_simulator/proxied_contract_data_source.ts +66 -0
  207. package/src/contract_function_simulator/proxied_node.ts +33 -0
  208. package/src/contract_function_simulator/pxe_oracle_interface.ts +1019 -0
  209. package/src/entrypoints/client/bundle/index.ts +4 -2
  210. package/src/entrypoints/client/bundle/utils.ts +36 -36
  211. package/src/entrypoints/client/lazy/index.ts +4 -2
  212. package/src/entrypoints/client/lazy/utils.ts +36 -31
  213. package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
  214. package/src/entrypoints/server/index.ts +5 -3
  215. package/src/entrypoints/server/utils.ts +69 -47
  216. package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +36 -27
  217. package/src/oracle_version.ts +11 -0
  218. package/src/{kernel_prover → private_kernel}/hints/build_private_kernel_reset_private_inputs.ts +158 -142
  219. package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
  220. package/src/{kernel_prover → private_kernel}/hints/index.ts +1 -0
  221. package/src/private_kernel/index.ts +2 -0
  222. package/src/private_kernel/private_kernel_execution_prover.ts +436 -0
  223. package/src/{kernel_prover/proving_data_oracle.ts → private_kernel/private_kernel_oracle.ts} +17 -29
  224. package/src/{kernel_oracle/index.ts → private_kernel/private_kernel_oracle_impl.ts} +30 -15
  225. package/src/pxe.ts +1113 -0
  226. package/src/storage/address_data_provider/address_data_provider.ts +1 -7
  227. package/src/storage/capsule_data_provider/capsule_data_provider.ts +97 -30
  228. package/src/storage/contract_data_provider/contract_data_provider.ts +114 -81
  229. package/src/storage/contract_data_provider/index.ts +0 -1
  230. package/src/storage/contract_data_provider/private_functions_tree.ts +11 -75
  231. package/src/storage/index.ts +2 -4
  232. package/src/storage/metadata.ts +1 -0
  233. package/src/storage/note_data_provider/note_dao.ts +19 -27
  234. package/src/storage/note_data_provider/note_data_provider.ts +161 -113
  235. package/src/storage/private_event_data_provider/private_event_data_provider.ts +148 -0
  236. package/src/storage/sync_data_provider/sync_data_provider.ts +4 -10
  237. package/src/storage/tagging_data_provider/tagging_data_provider.ts +58 -30
  238. package/src/synchronizer/synchronizer.ts +21 -22
  239. package/src/tagging/constants.ts +2 -0
  240. package/src/tagging/index.ts +6 -0
  241. package/src/tagging/siloed_tag.ts +22 -0
  242. package/src/tagging/tag.ts +16 -0
  243. package/src/tagging/utils.ts +31 -0
  244. package/dest/bin/index.d.ts +0 -3
  245. package/dest/bin/index.d.ts.map +0 -1
  246. package/dest/bin/index.js +0 -28
  247. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  248. package/dest/kernel_oracle/index.d.ts.map +0 -1
  249. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
  250. package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
  251. package/dest/kernel_prover/hints/index.d.ts +0 -2
  252. package/dest/kernel_prover/hints/index.d.ts.map +0 -1
  253. package/dest/kernel_prover/index.d.ts +0 -3
  254. package/dest/kernel_prover/index.d.ts.map +0 -1
  255. package/dest/kernel_prover/index.js +0 -2
  256. package/dest/kernel_prover/kernel_prover.d.ts +0 -38
  257. package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
  258. package/dest/kernel_prover/kernel_prover.js +0 -217
  259. package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
  260. package/dest/kernel_prover/proving_data_oracle.js +0 -4
  261. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
  262. package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
  263. package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
  264. package/dest/pxe_http/index.d.ts +0 -2
  265. package/dest/pxe_http/index.d.ts.map +0 -1
  266. package/dest/pxe_http/index.js +0 -1
  267. package/dest/pxe_http/pxe_http_server.d.ts +0 -16
  268. package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
  269. package/dest/pxe_http/pxe_http_server.js +0 -27
  270. package/dest/pxe_oracle_interface/index.d.ts +0 -159
  271. package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
  272. package/dest/pxe_oracle_interface/index.js +0 -692
  273. package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
  274. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  275. package/dest/pxe_oracle_interface/tagging_utils.js +0 -23
  276. package/dest/pxe_service/error_enriching.d.ts.map +0 -1
  277. package/dest/pxe_service/index.d.ts +0 -3
  278. package/dest/pxe_service/index.d.ts.map +0 -1
  279. package/dest/pxe_service/index.js +0 -2
  280. package/dest/pxe_service/pxe_service.d.ts +0 -111
  281. package/dest/pxe_service/pxe_service.d.ts.map +0 -1
  282. package/dest/pxe_service/pxe_service.js +0 -664
  283. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
  284. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
  285. package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
  286. package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
  287. package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
  288. package/dest/storage/auth_witness_data_provider/index.js +0 -1
  289. package/dest/storage/data_provider.d.ts +0 -4
  290. package/dest/storage/data_provider.d.ts.map +0 -1
  291. package/dest/storage/data_provider.js +0 -1
  292. package/dest/test/pxe_test_suite.d.ts +0 -3
  293. package/dest/test/pxe_test_suite.d.ts.map +0 -1
  294. package/dest/test/pxe_test_suite.js +0 -97
  295. package/src/bin/index.ts +0 -38
  296. package/src/kernel_prover/index.ts +0 -2
  297. package/src/kernel_prover/kernel_prover.ts +0 -351
  298. package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
  299. package/src/pxe_http/index.ts +0 -1
  300. package/src/pxe_http/pxe_http_server.ts +0 -29
  301. package/src/pxe_oracle_interface/index.ts +0 -925
  302. package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
  303. package/src/pxe_service/index.ts +0 -2
  304. package/src/pxe_service/pxe_service.ts +0 -949
  305. package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
  306. package/src/storage/auth_witness_data_provider/index.ts +0 -1
  307. package/src/storage/data_provider.ts +0 -3
  308. package/src/test/pxe_test_suite.ts +0 -111
  309. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
@@ -1,925 +0,0 @@
1
- import {
2
- type L1_TO_L2_MSG_TREE_HEIGHT,
3
- MAX_NOTE_HASHES_PER_TX,
4
- PRIVATE_LOG_SIZE_IN_FIELDS,
5
- PUBLIC_LOG_DATA_SIZE_IN_FIELDS,
6
- } from '@aztec/constants';
7
- import { timesParallel } from '@aztec/foundation/collection';
8
- import { poseidon2Hash } from '@aztec/foundation/crypto';
9
- import { Fr } from '@aztec/foundation/fields';
10
- import { createLogger } from '@aztec/foundation/log';
11
- import { BufferReader } from '@aztec/foundation/serialize';
12
- import type { KeyStore } from '@aztec/key-store';
13
- import { AcirSimulator, type ExecutionDataProvider, type SimulationProvider } from '@aztec/simulator/client';
14
- import { MessageLoadOracleInputs } from '@aztec/simulator/client';
15
- import {
16
- type FunctionArtifact,
17
- FunctionCall,
18
- FunctionSelector,
19
- FunctionType,
20
- NoteSelector,
21
- encodeArguments,
22
- getFunctionArtifact,
23
- } from '@aztec/stdlib/abi';
24
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
25
- import type { InBlock, L2Block, L2BlockNumber } from '@aztec/stdlib/block';
26
- import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
27
- import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
28
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
29
- import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
30
- import { computeAddressSecret, computeTaggingSecretPoint } from '@aztec/stdlib/keys';
31
- import {
32
- IndexedTaggingSecret,
33
- L1NotePayload,
34
- LogWithTxData,
35
- PrivateLog,
36
- PublicLog,
37
- TxScopedL2Log,
38
- } from '@aztec/stdlib/logs';
39
- import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
40
- import { Note, type NoteStatus } from '@aztec/stdlib/note';
41
- import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
42
- import type { BlockHeader } from '@aztec/stdlib/tx';
43
- import { TxHash } from '@aztec/stdlib/tx';
44
-
45
- import { getOrderedNoteItems } from '../note_decryption_utils/add_public_values_to_payload.js';
46
- import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
47
- import type { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js';
48
- import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
49
- import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
50
- import { NoteDao } from '../storage/note_data_provider/note_dao.js';
51
- import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
52
- import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
53
- import type { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
54
- import { WINDOW_HALF_SIZE, getIndexedTaggingSecretsForTheWindow, getInitialIndexesMap } from './tagging_utils.js';
55
-
56
- /**
57
- * A data layer that provides and stores information needed for simulating/proving a transaction.
58
- */
59
- export class PXEOracleInterface implements ExecutionDataProvider {
60
- constructor(
61
- private aztecNode: AztecNode,
62
- private keyStore: KeyStore,
63
- private simulationProvider: SimulationProvider,
64
- private contractDataProvider: ContractDataProvider,
65
- private noteDataProvider: NoteDataProvider,
66
- private capsuleDataProvider: CapsuleDataProvider,
67
- private syncDataProvider: SyncDataProvider,
68
- private taggingDataProvider: TaggingDataProvider,
69
- private addressDataProvider: AddressDataProvider,
70
- private authWitnessDataProvider: AuthWitnessDataProvider,
71
- private log = createLogger('pxe:pxe_data_manager'),
72
- ) {}
73
-
74
- getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise<KeyValidationRequest> {
75
- return this.keyStore.getKeyValidationRequest(pkMHash, contractAddress);
76
- }
77
-
78
- async getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
79
- const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
80
- if (!completeAddress) {
81
- throw new Error(
82
- `No public key registered for address ${account}.
83
- Register it by calling pxe.registerAccount(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
84
- );
85
- }
86
- return completeAddress;
87
- }
88
-
89
- async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
90
- const instance = await this.contractDataProvider.getContractInstance(address);
91
- if (!instance) {
92
- throw new Error(`No contract instance found for address ${address.toString()}`);
93
- }
94
- return instance;
95
- }
96
-
97
- async getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
98
- const witness = await this.authWitnessDataProvider.getAuthWitness(messageHash);
99
- return witness;
100
- }
101
-
102
- async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]) {
103
- const noteDaos = await this.noteDataProvider.getNotes({
104
- contractAddress,
105
- storageSlot,
106
- status,
107
- scopes,
108
- });
109
- return noteDaos.map(({ contractAddress, storageSlot, nonce, note, noteHash, siloedNullifier, index }) => ({
110
- contractAddress,
111
- storageSlot,
112
- nonce,
113
- note,
114
- noteHash,
115
- siloedNullifier,
116
- // PXE can use this index to get full MembershipWitness
117
- index,
118
- }));
119
- }
120
-
121
- async getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionArtifact> {
122
- const artifact = await this.contractDataProvider.getFunctionArtifact(contractAddress, selector);
123
- const debug = await this.contractDataProvider.getFunctionDebugMetadata(contractAddress, selector);
124
- return {
125
- ...artifact,
126
- debug,
127
- };
128
- }
129
-
130
- async getFunctionArtifactByName(
131
- contractAddress: AztecAddress,
132
- functionName: string,
133
- ): Promise<FunctionArtifact | undefined> {
134
- const instance = await this.contractDataProvider.getContractInstance(contractAddress);
135
- const artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
136
- return artifact && getFunctionArtifact(artifact, functionName);
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
- // Only used in public.
164
- public getL1ToL2LeafValue(_leafIndex: bigint): Promise<Fr | undefined> {
165
- throw new Error('Unimplemented in private!');
166
- }
167
-
168
- /**
169
- * Gets the index of a commitment in the note hash tree.
170
- * @param commitment - The commitment.
171
- * @returns - The index of the commitment. Undefined if it does not exist in the tree.
172
- */
173
- async getCommitmentIndex(commitment: Fr) {
174
- return await this.#findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment);
175
- }
176
-
177
- // We need this in public as part of the EXISTS calls - but isn't used in private
178
- public getCommitmentValue(_leafIndex: bigint): Promise<Fr | undefined> {
179
- throw new Error('Unimplemented in private!');
180
- }
181
-
182
- async getNullifierIndex(nullifier: Fr) {
183
- return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
184
- }
185
-
186
- async #findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
187
- const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]);
188
- return leafIndex;
189
- }
190
-
191
- public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
192
- const leafIndex = await this.#findLeafIndex(blockNumber, treeId, leafValue);
193
- if (!leafIndex) {
194
- throw new Error(`Leaf value: ${leafValue} not found in ${MerkleTreeId[treeId]}`);
195
- }
196
-
197
- const siblingPath = await this.#getSiblingPath(blockNumber, treeId, leafIndex);
198
-
199
- return [new Fr(leafIndex), ...siblingPath];
200
- }
201
-
202
- async #getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: bigint): Promise<Fr[]> {
203
- switch (treeId) {
204
- case MerkleTreeId.NULLIFIER_TREE:
205
- return (await this.aztecNode.getNullifierSiblingPath(blockNumber, leafIndex)).toFields();
206
- case MerkleTreeId.NOTE_HASH_TREE:
207
- return (await this.aztecNode.getNoteHashSiblingPath(blockNumber, leafIndex)).toFields();
208
- case MerkleTreeId.PUBLIC_DATA_TREE:
209
- return (await this.aztecNode.getPublicDataSiblingPath(blockNumber, leafIndex)).toFields();
210
- case MerkleTreeId.ARCHIVE:
211
- return (await this.aztecNode.getArchiveSiblingPath(blockNumber, leafIndex)).toFields();
212
- default:
213
- throw new Error('Not implemented');
214
- }
215
- }
216
-
217
- public async getNullifierMembershipWitnessAtLatestBlock(nullifier: Fr) {
218
- return this.getNullifierMembershipWitness(await this.getBlockNumber(), nullifier);
219
- }
220
-
221
- public getNullifierMembershipWitness(
222
- blockNumber: number,
223
- nullifier: Fr,
224
- ): Promise<NullifierMembershipWitness | undefined> {
225
- return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
226
- }
227
-
228
- public getLowNullifierMembershipWitness(
229
- blockNumber: number,
230
- nullifier: Fr,
231
- ): Promise<NullifierMembershipWitness | undefined> {
232
- return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
233
- }
234
-
235
- public async getBlock(blockNumber: number): Promise<L2Block | undefined> {
236
- return await this.aztecNode.getBlock(blockNumber);
237
- }
238
-
239
- public async getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
240
- return await this.aztecNode.getPublicDataTreeWitness(blockNumber, leafSlot);
241
- }
242
-
243
- public async getPublicStorageAt(blockNumber: number, contract: AztecAddress, slot: Fr): Promise<Fr> {
244
- return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
245
- }
246
-
247
- /**
248
- * Retrieve the databases view of the Block Header object.
249
- * This structure is fed into the circuits simulator and is used to prove against certain historical roots.
250
- *
251
- * @returns A Promise that resolves to a BlockHeader object.
252
- */
253
- getBlockHeader(): Promise<BlockHeader> {
254
- return this.syncDataProvider.getBlockHeader();
255
- }
256
-
257
- /**
258
- * Fetches the current block number.
259
- * @returns The block number.
260
- */
261
- public async getBlockNumber(): Promise<number> {
262
- return await this.aztecNode.getBlockNumber();
263
- }
264
-
265
- /**
266
- * Fetches the current chain id.
267
- * @returns The chain id.
268
- */
269
- public async getChainId(): Promise<number> {
270
- return await this.aztecNode.getChainId();
271
- }
272
-
273
- /**
274
- * Fetches the current version.
275
- * @returns The version.
276
- */
277
- public async getVersion(): Promise<number> {
278
- return await this.aztecNode.getVersion();
279
- }
280
-
281
- public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
282
- return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
283
- }
284
-
285
- /**
286
- * Returns the full contents of your address book.
287
- * This is used when calculating tags for incoming notes by deriving the shared secret, the contract-siloed tagging secret, and
288
- * finally the index specified tag. We will then query the node with this tag for each address in the address book.
289
- * @returns The full list of the users contact addresses.
290
- */
291
- public getSenders(): Promise<AztecAddress[]> {
292
- return this.taggingDataProvider.getSenderAddresses();
293
- }
294
-
295
- /**
296
- * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
297
- * Includes the next index to be used used for tagging with this secret.
298
- * @param contractAddress - The contract address to silo the secret for
299
- * @param sender - The address sending the note
300
- * @param recipient - The address receiving the note
301
- * @returns An indexed tagging secret that can be used to tag notes.
302
- */
303
- public async getIndexedTaggingSecretAsSender(
304
- contractAddress: AztecAddress,
305
- sender: AztecAddress,
306
- recipient: AztecAddress,
307
- ): Promise<IndexedTaggingSecret> {
308
- await this.syncTaggedLogsAsSender(contractAddress, sender, recipient);
309
-
310
- const appTaggingSecret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
311
- const [index] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([appTaggingSecret]);
312
-
313
- return new IndexedTaggingSecret(appTaggingSecret, index);
314
- }
315
-
316
- /**
317
- * Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
318
- * @param contractAddress - The contract address to silo the secret for
319
- * @param sender - The address sending the note
320
- * @param recipient - The address receiving the note
321
- */
322
- public async incrementAppTaggingSecretIndexAsSender(
323
- contractAddress: AztecAddress,
324
- sender: AztecAddress,
325
- recipient: AztecAddress,
326
- ): Promise<void> {
327
- const secret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
328
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
329
- this.log.debug(`Incrementing app tagging secret at ${contractName}(${contractAddress})`, {
330
- secret,
331
- sender,
332
- recipient,
333
- contractName,
334
- contractAddress,
335
- });
336
-
337
- const [index] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([secret]);
338
- await this.taggingDataProvider.setTaggingSecretsIndexesAsSender([new IndexedTaggingSecret(secret, index + 1)]);
339
- }
340
-
341
- async #calculateAppTaggingSecret(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress) {
342
- const senderCompleteAddress = await this.getCompleteAddress(sender);
343
- const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
344
- const secretPoint = await computeTaggingSecretPoint(senderCompleteAddress, senderIvsk, recipient);
345
- // Silo the secret so it can't be used to track other app's notes
346
- const appSecret = poseidon2Hash([secretPoint.x, secretPoint.y, contractAddress]);
347
- return appSecret;
348
- }
349
-
350
- /**
351
- * Returns the indexed tagging secrets for a given recipient and all the senders in the address book
352
- * This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
353
- * of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
354
- * so we're keeping it private for now.
355
- * @param contractAddress - The contract address to silo the secret for
356
- * @param recipient - The address receiving the notes
357
- * @returns A list of indexed tagging secrets
358
- */
359
- async #getIndexedTaggingSecretsForSenders(
360
- contractAddress: AztecAddress,
361
- recipient: AztecAddress,
362
- ): Promise<IndexedTaggingSecret[]> {
363
- const recipientCompleteAddress = await this.getCompleteAddress(recipient);
364
- const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
365
-
366
- // We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
367
- // (recipient = us, sender = us)
368
- const senders = [
369
- ...(await this.taggingDataProvider.getSenderAddresses()),
370
- ...(await this.keyStore.getAccounts()),
371
- ].filter((address, index, self) => index === self.findIndex(otherAddress => otherAddress.equals(address)));
372
- const appTaggingSecrets = await Promise.all(
373
- senders.map(async contact => {
374
- const sharedSecret = await computeTaggingSecretPoint(recipientCompleteAddress, recipientIvsk, contact);
375
- return poseidon2Hash([sharedSecret.x, sharedSecret.y, contractAddress]);
376
- }),
377
- );
378
- const indexes = await this.taggingDataProvider.getTaggingSecretsIndexesAsRecipient(appTaggingSecrets);
379
- return appTaggingSecrets.map((secret, i) => new IndexedTaggingSecret(secret, indexes[i]));
380
- }
381
-
382
- /**
383
- * Updates the local index of the shared tagging secret of a sender / recipient pair
384
- * if a log with a larger index is found from the node.
385
- * @param contractAddress - The address of the contract that the logs are tagged for
386
- * @param sender - The address of the sender, we must know the sender's ivsk_m.
387
- * @param recipient - The address of the recipient.
388
- */
389
- public async syncTaggedLogsAsSender(
390
- contractAddress: AztecAddress,
391
- sender: AztecAddress,
392
- recipient: AztecAddress,
393
- ): Promise<void> {
394
- const appTaggingSecret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
395
- const [oldIndex] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([appTaggingSecret]);
396
-
397
- // This algorithm works such that:
398
- // 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
399
- // we found and quit.
400
- // 2. If we don't find minimum consecutive empty logs in a window of logs we slide the window to latest log index
401
- // and repeat the process.
402
- const MIN_CONSECUTIVE_EMPTY_LOGS = 10;
403
- const WINDOW_SIZE = MIN_CONSECUTIVE_EMPTY_LOGS * 2;
404
-
405
- let [numConsecutiveEmptyLogs, currentIndex] = [0, oldIndex];
406
- do {
407
- // We compute the tags for the current window of indexes
408
- const currentTags = await timesParallel(WINDOW_SIZE, i => {
409
- const indexedAppTaggingSecret = new IndexedTaggingSecret(appTaggingSecret, currentIndex + i);
410
- return indexedAppTaggingSecret.computeSiloedTag(recipient, contractAddress);
411
- });
412
-
413
- // We fetch the logs for the tags
414
- const possibleLogs = await this.aztecNode.getLogsByTags(currentTags);
415
-
416
- // We find the index of the last log in the window that is not empty
417
- const indexOfLastLog = possibleLogs.findLastIndex(possibleLog => possibleLog.length !== 0);
418
-
419
- if (indexOfLastLog === -1) {
420
- // We haven't found any logs in the current window so we stop looking
421
- break;
422
- }
423
-
424
- // We move the current index to that of the last log we found
425
- currentIndex += indexOfLastLog + 1;
426
-
427
- // We compute the number of consecutive empty logs we found and repeat the process if we haven't found enough.
428
- numConsecutiveEmptyLogs = WINDOW_SIZE - indexOfLastLog - 1;
429
- } while (numConsecutiveEmptyLogs < MIN_CONSECUTIVE_EMPTY_LOGS);
430
-
431
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
432
- if (currentIndex !== oldIndex) {
433
- await this.taggingDataProvider.setTaggingSecretsIndexesAsSender([
434
- new IndexedTaggingSecret(appTaggingSecret, currentIndex),
435
- ]);
436
-
437
- this.log.debug(`Syncing logs for sender ${sender} at contract ${contractName}(${contractAddress})`, {
438
- sender,
439
- secret: appTaggingSecret,
440
- index: currentIndex,
441
- contractName,
442
- contractAddress,
443
- });
444
- } else {
445
- this.log.debug(`No new logs found for sender ${sender} at contract ${contractName}(${contractAddress})`);
446
- }
447
- }
448
-
449
- /**
450
- * Synchronizes the logs tagged with scoped addresses and all the senders in the address book.
451
- * Returns the unsynched logs and updates the indexes of the secrets used to tag them until there are no more logs
452
- * to sync.
453
- * @param contractAddress - The address of the contract that the logs are tagged for
454
- * @param recipient - The address of the recipient
455
- * @returns A list of encrypted logs tagged with the recipient's address
456
- */
457
- public async syncTaggedLogs(
458
- contractAddress: AztecAddress,
459
- maxBlockNumber: number,
460
- scopes?: AztecAddress[],
461
- ): Promise<Map<string, TxScopedL2Log[]>> {
462
- this.log.verbose('Searching for tagged logs', { contract: contractAddress });
463
-
464
- // Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
465
- // However it is impossible at the moment due to the language not supporting nested slices.
466
- // This nesting is necessary because for a given set of tags we don't
467
- // know how many logs we will get back. Furthermore, these logs are of undetermined
468
- // length, since we don't really know the note they correspond to until we decrypt them.
469
-
470
- const recipients = scopes ? scopes : await this.keyStore.getAccounts();
471
- // A map of logs going from recipient address to logs. Note that the logs might have been processed before
472
- // due to us having a sliding window that "looks back" for logs as well. (We look back as there is no guarantee
473
- // that a logs will be received ordered by a given tax index and that the tags won't be reused).
474
- const logsMap = new Map<string, TxScopedL2Log[]>();
475
- const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
476
- for (const recipient of recipients) {
477
- const logsForRecipient: TxScopedL2Log[] = [];
478
-
479
- // Get all the secrets for the recipient and sender pairs (#9365)
480
- const secrets = await this.#getIndexedTaggingSecretsForSenders(contractAddress, recipient);
481
-
482
- // We fetch logs for a window of indexes in a range:
483
- // <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
484
- //
485
- // We use this window approach because it could happen that a sender might have messed up and inadvertently
486
- // incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
487
- // for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
488
- // Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
489
- // some logs. For these reasons, we have to look both back and ahead of the stored index.
490
- let secretsAndWindows = secrets.map(secret => {
491
- return {
492
- appTaggingSecret: secret.appTaggingSecret,
493
- leftMostIndex: Math.max(0, secret.index - WINDOW_HALF_SIZE),
494
- rightMostIndex: secret.index + WINDOW_HALF_SIZE,
495
- };
496
- });
497
-
498
- // As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
499
- const newLargestIndexMapToStore: { [k: string]: number } = {};
500
-
501
- // The initial/unmodified indexes of the secrets stored in a key-value map where key is the app tagging secret.
502
- const initialIndexesMap = getInitialIndexesMap(secrets);
503
-
504
- while (secretsAndWindows.length > 0) {
505
- const secretsForTheWholeWindow = getIndexedTaggingSecretsForTheWindow(secretsAndWindows);
506
- const tagsForTheWholeWindow = await Promise.all(
507
- secretsForTheWholeWindow.map(secret => secret.computeSiloedTag(recipient, contractAddress)),
508
- );
509
-
510
- // We store the new largest indexes we find in the iteration in the following map to later on construct
511
- // a new set of secrets and windows to fetch logs for.
512
- const newLargestIndexMapForIteration: { [k: string]: number } = {};
513
-
514
- // Fetch the logs for the tags and iterate over them
515
- const logsByTags = await this.aztecNode.getLogsByTags(tagsForTheWholeWindow);
516
-
517
- logsByTags.forEach((logsByTag, logIndex) => {
518
- if (logsByTag.length > 0) {
519
- // Check that public logs have the correct contract address
520
- const checkedLogsbyTag = logsByTag.filter(
521
- l => !l.isFromPublic || PublicLog.fromBuffer(l.logData).contractAddress.equals(contractAddress),
522
- );
523
- if (checkedLogsbyTag.length < logsByTag.length) {
524
- const discarded = logsByTag.filter(
525
- log => checkedLogsbyTag.find(filteredLog => filteredLog.equals(log)) === undefined,
526
- );
527
- this.log.warn(
528
- `Discarded ${
529
- logsByTag.length - checkedLogsbyTag.length
530
- } public logs with mismatched contract address ${contractAddress}:`,
531
- discarded.map(l => PublicLog.fromBuffer(l.logData)),
532
- );
533
- }
534
-
535
- // The logs for the given tag exist so we store them for later processing
536
- logsForRecipient.push(...checkedLogsbyTag);
537
-
538
- // We retrieve the indexed tagging secret corresponding to the log as I need that to evaluate whether
539
- // a new largest index have been found.
540
- const secretCorrespondingToLog = secretsForTheWholeWindow[logIndex];
541
- const initialIndex = initialIndexesMap[secretCorrespondingToLog.appTaggingSecret.toString()];
542
-
543
- this.log.debug(`Found ${checkedLogsbyTag.length} logs as recipient ${recipient}`, {
544
- recipient,
545
- secret: secretCorrespondingToLog.appTaggingSecret,
546
- contractName,
547
- contractAddress,
548
- });
549
-
550
- if (
551
- secretCorrespondingToLog.index >= initialIndex &&
552
- (newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()] === undefined ||
553
- secretCorrespondingToLog.index >=
554
- newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()])
555
- ) {
556
- // We have found a new largest index so we store it for later processing (storing it in the db + fetching
557
- // the difference of the window sets of current and the next iteration)
558
- newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()] =
559
- secretCorrespondingToLog.index + 1;
560
-
561
- this.log.debug(
562
- `Incrementing index to ${
563
- secretCorrespondingToLog.index + 1
564
- } at contract ${contractName}(${contractAddress})`,
565
- );
566
- }
567
- }
568
- });
569
-
570
- // Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
571
- // for. Note that it's very unlikely that a new log from the current window would appear between the iterations
572
- // so we fetch the logs only for the difference of the window sets.
573
- const newSecretsAndWindows = [];
574
- for (const [appTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)) {
575
- const secret = secrets.find(secret => secret.appTaggingSecret.toString() === appTaggingSecret);
576
- if (secret) {
577
- newSecretsAndWindows.push({
578
- appTaggingSecret: secret.appTaggingSecret,
579
- // We set the left most index to the new index to avoid fetching the same logs again
580
- leftMostIndex: newIndex,
581
- rightMostIndex: newIndex + WINDOW_HALF_SIZE,
582
- });
583
-
584
- // We store the new largest index in the map to later store it in the db.
585
- newLargestIndexMapToStore[appTaggingSecret] = newIndex;
586
- } else {
587
- throw new Error(
588
- `Secret not found for appTaggingSecret ${appTaggingSecret}. This is a bug as it should never happen!`,
589
- );
590
- }
591
- }
592
-
593
- // Now we set the new secrets and windows and proceed to the next iteration.
594
- secretsAndWindows = newSecretsAndWindows;
595
- }
596
-
597
- // We filter the logs by block number and store them in the map.
598
- logsMap.set(
599
- recipient.toString(),
600
- logsForRecipient.filter(log => log.blockNumber <= maxBlockNumber),
601
- );
602
-
603
- // At this point we have processed all the logs for the recipient so we store the new largest indexes in the db.
604
- await this.taggingDataProvider.setTaggingSecretsIndexesAsRecipient(
605
- Object.entries(newLargestIndexMapToStore).map(
606
- ([appTaggingSecret, index]) => new IndexedTaggingSecret(Fr.fromHexString(appTaggingSecret), index),
607
- ),
608
- );
609
- }
610
- return logsMap;
611
- }
612
-
613
- /**
614
- * Decrypts logs tagged for a recipient and returns them.
615
- * @param scopedLogs - The logs to decrypt.
616
- * @param recipient - The recipient of the logs.
617
- * @returns The decrypted notes.
618
- */
619
- async #decryptTaggedLogs(scopedLogs: TxScopedL2Log[], recipient: AztecAddress) {
620
- const recipientCompleteAddress = await this.getCompleteAddress(recipient);
621
- const ivskM = await this.keyStore.getMasterSecretKey(
622
- recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
623
- );
624
- const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
625
-
626
- // Since we could have notes with the same index for different txs, we need
627
- // to keep track of them scoping by txHash
628
- const excludedIndices: Map<string, Set<number>> = new Map();
629
- const decrypted = [];
630
-
631
- for (const scopedLog of scopedLogs) {
632
- const payload = scopedLog.isFromPublic
633
- ? await L1NotePayload.decryptAsIncomingFromPublic(PublicLog.fromBuffer(scopedLog.logData), addressSecret)
634
- : await L1NotePayload.decryptAsIncoming(PrivateLog.fromBuffer(scopedLog.logData), addressSecret);
635
-
636
- if (!payload) {
637
- this.log.verbose('Unable to decrypt log');
638
- continue;
639
- }
640
-
641
- if (!excludedIndices.has(scopedLog.txHash.toString())) {
642
- excludedIndices.set(scopedLog.txHash.toString(), new Set());
643
- }
644
-
645
- const note = await getOrderedNoteItems(this.contractDataProvider, payload);
646
- const plaintext = [payload.storageSlot, payload.noteTypeId.toField(), ...note.items];
647
-
648
- decrypted.push({ plaintext, txHash: scopedLog.txHash, contractAddress: payload.contractAddress });
649
- }
650
-
651
- return decrypted;
652
- }
653
-
654
- /**
655
- * Processes the tagged logs returned by syncTaggedLogs by decrypting them and storing them in the database.
656
- * @param logs - The logs to process.
657
- * @param recipient - The recipient of the logs.
658
- */
659
- public async processTaggedLogs(
660
- logs: TxScopedL2Log[],
661
- recipient: AztecAddress,
662
- simulator?: AcirSimulator,
663
- ): Promise<void> {
664
- const decryptedLogs = await this.#decryptTaggedLogs(logs, recipient);
665
-
666
- // We've produced the full NoteDao, which we'd be able to simply insert into the database. However, this is
667
- // only a temporary measure as we migrate from the PXE-driven discovery into the new contract-driven approach. We
668
- // discard most of the work done up to this point and reconstruct the note plaintext to then hand over to the
669
- // contract for further processing.
670
- for (const decryptedLog of decryptedLogs) {
671
- // Log processing requires the note hashes in the tx in which the note was created. We are now assuming that the
672
- // note was included in the same block in which the log was delivered - note that partial notes will not work this
673
- // way.
674
- const txEffect = await this.aztecNode.getTxEffect(decryptedLog.txHash);
675
- if (!txEffect) {
676
- throw new Error(`Could not find tx effect for tx hash ${decryptedLog.txHash}`);
677
- }
678
-
679
- // This will trigger calls to the deliverNote oracle
680
- await this.callProcessLog(
681
- decryptedLog.contractAddress,
682
- decryptedLog.plaintext,
683
- decryptedLog.txHash,
684
- txEffect.data.noteHashes,
685
- txEffect.data.nullifiers[0],
686
- recipient,
687
- simulator,
688
- );
689
- }
690
- return;
691
- }
692
-
693
- public async deliverNote(
694
- contractAddress: AztecAddress,
695
- storageSlot: Fr,
696
- nonce: Fr,
697
- content: Fr[],
698
- noteHash: Fr,
699
- nullifier: Fr,
700
- txHash: Fr,
701
- recipient: AztecAddress,
702
- ): Promise<void> {
703
- // We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
704
- // There's two things we need to check before we do this however:
705
- // - we must make sure the note does actually exist in the note hash tree
706
- // - we need to check if the note has already been nullified
707
- //
708
- // Failing to do either of the above would result in circuits getting either non-existent notes and failing to
709
- // produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
710
- // are catastrophic failure modes.
711
- //
712
- // Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
713
- // emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
714
- // so we must store both the note hash and nullifier block information.
715
-
716
- // We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
717
- // in time of the locally synced state.
718
- // Note that while this technically results in historical queries, we perform it at the latest locally synced block
719
- // number which *should* be recent enough to be available, even for non-archive nodes.
720
- const syncedBlockNumber = (await this.syncDataProvider.getBlockNumber())!;
721
- // TODO (#12559): handle undefined syncedBlockNumber
722
- // if (syncedBlockNumber === undefined) {
723
- // throw new Error(`Attempted to deliver a note with an unsynchronized PXE - this should never happen`);
724
- //}
725
-
726
- // By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
727
- // of other contracts, which would constitute a security breach.
728
- const uniqueNoteHash = await computeUniqueNoteHash(nonce, await siloNoteHash(contractAddress, noteHash));
729
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
730
-
731
- // We store notes by their index in the global note hash tree, which has the convenient side effect of validating
732
- // note existence in said tree.
733
- const [uniqueNoteHashTreeIndex] = await this.aztecNode.findLeavesIndexes(
734
- syncedBlockNumber,
735
- MerkleTreeId.NOTE_HASH_TREE,
736
- [uniqueNoteHash],
737
- );
738
- if (uniqueNoteHashTreeIndex === undefined) {
739
- throw new Error(
740
- `Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`,
741
- );
742
- }
743
-
744
- // TODO (#12550): findLeavesIndexes should probably return an InBlock, same as findNullifiersIndexesWithBlock. This
745
- // would save us from having to then query the tx receipt in order to get the block hash and number. Note regardless
746
- // that we're not validating that the note was indeed created in this tx (which would require inspecting the tx
747
- // effects), so maybe what we really want is an InTx.
748
- const txReceipt = await this.aztecNode.getTxReceipt(new TxHash(txHash));
749
- if (txReceipt === undefined) {
750
- throw new Error(`Failed to fetch tx receipt for tx hash ${txHash} when searching for note hashes`);
751
- }
752
-
753
- // TODO(#12549): does it make sense to store the recipient's address point instead of just its address?
754
- const recipientAddressPoint = await recipient.toAddressPoint();
755
- const noteDao = new NoteDao(
756
- new Note(content),
757
- contractAddress,
758
- storageSlot,
759
- nonce,
760
- noteHash,
761
- siloedNullifier,
762
- new TxHash(txHash),
763
- txReceipt.blockNumber!,
764
- txReceipt.blockHash!.toString(),
765
- uniqueNoteHashTreeIndex,
766
- recipientAddressPoint,
767
- NoteSelector.empty(), // TODO(#12013): remove
768
- );
769
-
770
- await this.noteDataProvider.addNotes([noteDao], recipient);
771
- this.log.verbose('Added note', {
772
- contract: noteDao.contractAddress,
773
- slot: noteDao.storageSlot,
774
- noteHash: noteDao.noteHash,
775
- nullifier: noteDao.siloedNullifier.toString(),
776
- });
777
-
778
- const [nullifierIndex] = await this.aztecNode.findNullifiersIndexesWithBlock(syncedBlockNumber, [siloedNullifier]);
779
- if (nullifierIndex !== undefined) {
780
- const { data: _, ...blockHashAndNum } = nullifierIndex;
781
- await this.noteDataProvider.removeNullifiedNotes(
782
- [{ data: siloedNullifier, ...blockHashAndNum }],
783
- recipientAddressPoint,
784
- );
785
-
786
- this.log.verbose(`Removed just-added note`, {
787
- contract: contractAddress,
788
- slot: storageSlot,
789
- noteHash: noteHash,
790
- nullifier: siloedNullifier.toString(),
791
- });
792
- }
793
- }
794
-
795
- public async getLogByTag(tag: Fr): Promise<LogWithTxData | null> {
796
- const logs = await this.aztecNode.getLogsByTags([tag]);
797
- const logsForTag = logs[0];
798
-
799
- this.log.debug(`Got ${logsForTag.length} logs for tag ${tag}`);
800
-
801
- if (logsForTag.length == 0) {
802
- return null;
803
- } else if (logsForTag.length > 1) {
804
- // TODO(#11627): handle this case
805
- throw new Error(
806
- `Got ${logsForTag.length} logs for tag ${tag}. getLogByTag currently only supports a single log per tag`,
807
- );
808
- }
809
-
810
- const log = logsForTag[0];
811
-
812
- // getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
813
- // we need to make a second call to the node for `getTxEffect`.
814
- // TODO(#9789): bundle this information in the `getLogsByTag` call.
815
- const txEffect = await this.aztecNode.getTxEffect(log.txHash);
816
- if (txEffect == undefined) {
817
- throw new Error(`Unexpected: failed to retrieve tx effects for tx ${log.txHash} which is known to exist`);
818
- }
819
-
820
- const reader = BufferReader.asReader(log.logData);
821
- const logArray = reader.readArray(PUBLIC_LOG_DATA_SIZE_IN_FIELDS, Fr);
822
-
823
- // Public logs always take up all available fields by padding with zeroes, and the length of the originally emitted
824
- // log is lost. Until this is improved, we simply remove all of the zero elements (which are expected to be at the
825
- // end).
826
- // TODO(#11636): use the actual log length.
827
- const trimmedLog = logArray.filter(x => !x.isZero());
828
-
829
- return new LogWithTxData(trimmedLog, log.txHash.hash, txEffect.data.noteHashes, txEffect.data.nullifiers[0]);
830
- }
831
-
832
- public async removeNullifiedNotes(contractAddress: AztecAddress) {
833
- this.log.verbose('Searching for nullifiers of known notes', { contract: contractAddress });
834
-
835
- for (const recipient of await this.keyStore.getAccounts()) {
836
- const currentNotesForRecipient = await this.noteDataProvider.getNotes({ contractAddress, owner: recipient });
837
- const nullifiersToCheck = currentNotesForRecipient.map(note => note.siloedNullifier);
838
- const nullifierIndexes = await this.aztecNode.findNullifiersIndexesWithBlock('latest', nullifiersToCheck);
839
-
840
- const foundNullifiers = nullifiersToCheck
841
- .map((nullifier, i) => {
842
- if (nullifierIndexes[i] !== undefined) {
843
- return { ...nullifierIndexes[i], ...{ data: nullifier } } as InBlock<Fr>;
844
- }
845
- })
846
- .filter(nullifier => nullifier !== undefined) as InBlock<Fr>[];
847
-
848
- const nullifiedNotes = await this.noteDataProvider.removeNullifiedNotes(
849
- foundNullifiers,
850
- await recipient.toAddressPoint(),
851
- );
852
- nullifiedNotes.forEach(noteDao => {
853
- this.log.verbose(`Removed note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, {
854
- contract: noteDao.contractAddress,
855
- slot: noteDao.storageSlot,
856
- nullifier: noteDao.siloedNullifier.toString(),
857
- });
858
- });
859
- }
860
- }
861
-
862
- async callProcessLog(
863
- contractAddress: AztecAddress,
864
- logPlaintext: Fr[],
865
- txHash: TxHash,
866
- noteHashes: Fr[],
867
- firstNullifier: Fr,
868
- recipient: AztecAddress,
869
- simulator?: AcirSimulator,
870
- ) {
871
- const artifact: FunctionArtifact | undefined = await this.contractDataProvider.getFunctionArtifactByName(
872
- contractAddress,
873
- 'process_log',
874
- );
875
- if (!artifact) {
876
- throw new Error(
877
- `Mandatory implementation of "process_log" missing in noir contract ${contractAddress.toString()}.`,
878
- );
879
- }
880
-
881
- const selector = await FunctionSelector.fromNameAndParameters(artifact);
882
- const execRequest: FunctionCall = {
883
- name: artifact.name,
884
- to: contractAddress,
885
- selector,
886
- type: FunctionType.UNCONSTRAINED,
887
- isStatic: artifact.isStatic,
888
- args: encodeArguments(artifact, [
889
- toBoundedVec(logPlaintext, PRIVATE_LOG_SIZE_IN_FIELDS),
890
- txHash.toString(),
891
- toBoundedVec(noteHashes, MAX_NOTE_HASHES_PER_TX),
892
- firstNullifier,
893
- recipient,
894
- ]),
895
- returnTypes: artifact.returnTypes,
896
- };
897
-
898
- await (simulator ?? new AcirSimulator(this, this.simulationProvider)).runUnconstrained(
899
- execRequest,
900
- contractAddress,
901
- selector,
902
- [], // empty scope as this call should not require access to private information
903
- );
904
- }
905
-
906
- storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
907
- return this.capsuleDataProvider.storeCapsule(contractAddress, slot, capsule);
908
- }
909
-
910
- loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
911
- return this.capsuleDataProvider.loadCapsule(contractAddress, slot);
912
- }
913
-
914
- deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
915
- return this.capsuleDataProvider.deleteCapsule(contractAddress, slot);
916
- }
917
-
918
- copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
919
- return this.capsuleDataProvider.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
920
- }
921
- }
922
-
923
- function toBoundedVec(array: Fr[], maxLength: number) {
924
- return { storage: array.concat(Array(maxLength - array.length).fill(new Fr(0))), len: array.length };
925
- }