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