@aztec/simulator 0.76.4 → 0.77.0-testnet-ignition.21

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 (517) hide show
  1. package/README.md +3 -3
  2. package/dest/client.d.ts +5 -0
  3. package/dest/client.d.ts.map +1 -0
  4. package/dest/client.js +3 -0
  5. package/dest/{public → common}/db_interfaces.d.ts +8 -33
  6. package/dest/common/db_interfaces.d.ts.map +1 -0
  7. package/dest/common/db_interfaces.js +1 -0
  8. package/dest/common/debug_fn_name.d.ts +3 -2
  9. package/dest/common/debug_fn_name.d.ts.map +1 -1
  10. package/dest/common/debug_fn_name.js +2 -5
  11. package/dest/common/errors.d.ts +4 -4
  12. package/dest/common/errors.d.ts.map +1 -1
  13. package/dest/common/errors.js +30 -39
  14. package/dest/common/index.d.ts +2 -1
  15. package/dest/common/index.d.ts.map +1 -1
  16. package/dest/common/index.js +2 -2
  17. package/dest/common/message_load_oracle_inputs.d.ts +2 -2
  18. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -1
  19. package/dest/common/message_load_oracle_inputs.js +8 -8
  20. package/dest/common/stats/index.d.ts.map +1 -0
  21. package/dest/{stats → common/stats}/stats.d.ts +2 -2
  22. package/dest/common/stats/stats.d.ts.map +1 -0
  23. package/dest/common/stats/stats.js +10 -0
  24. package/dest/{acvm → private/acvm}/acvm.d.ts +4 -4
  25. package/dest/private/acvm/acvm.d.ts.map +1 -0
  26. package/dest/private/acvm/acvm.js +70 -0
  27. package/dest/{acvm → private/acvm}/acvm_types.d.ts +1 -1
  28. package/dest/private/acvm/acvm_types.d.ts.map +1 -0
  29. package/dest/private/acvm/acvm_types.js +3 -0
  30. package/dest/{acvm → private/acvm}/deserialize.d.ts +2 -2
  31. package/dest/private/acvm/deserialize.d.ts.map +1 -0
  32. package/dest/private/acvm/deserialize.js +42 -0
  33. package/dest/private/acvm/index.d.ts.map +1 -0
  34. package/dest/private/acvm/index.js +5 -0
  35. package/dest/{acvm → private/acvm}/oracle/index.d.ts +1 -1
  36. package/dest/private/acvm/oracle/index.d.ts.map +1 -0
  37. package/dest/private/acvm/oracle/index.js +2 -0
  38. package/dest/{acvm → private/acvm}/oracle/oracle.d.ts +4 -3
  39. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -0
  40. package/dest/private/acvm/oracle/oracle.js +263 -0
  41. package/dest/{acvm → private/acvm}/oracle/typed_oracle.d.ts +12 -6
  42. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -0
  43. package/dest/private/acvm/oracle/typed_oracle.js +132 -0
  44. package/dest/{acvm → private/acvm}/serialize.d.ts +7 -3
  45. package/dest/private/acvm/serialize.d.ts.map +1 -0
  46. package/dest/private/acvm/serialize.js +46 -0
  47. package/dest/{client → private}/client_execution_context.d.ts +20 -17
  48. package/dest/private/client_execution_context.d.ts.map +1 -0
  49. package/dest/private/client_execution_context.js +378 -0
  50. package/dest/{client → private}/db_oracle.d.ts +19 -7
  51. package/dest/private/db_oracle.d.ts.map +1 -0
  52. package/dest/private/db_oracle.js +14 -0
  53. package/dest/{client → private}/execution_note_cache.d.ts +2 -2
  54. package/dest/private/execution_note_cache.d.ts.map +1 -0
  55. package/dest/private/execution_note_cache.js +180 -0
  56. package/dest/{common → private}/hashed_values_cache.d.ts +2 -2
  57. package/dest/private/hashed_values_cache.d.ts.map +1 -0
  58. package/dest/private/hashed_values_cache.js +46 -0
  59. package/dest/private/index.d.ts +13 -0
  60. package/dest/private/index.d.ts.map +1 -0
  61. package/dest/private/index.js +12 -0
  62. package/dest/{client → private}/pick_notes.d.ts +1 -1
  63. package/dest/private/pick_notes.d.ts.map +1 -0
  64. package/dest/private/pick_notes.js +51 -0
  65. package/dest/private/private_execution.d.ts +24 -0
  66. package/dest/private/private_execution.d.ts.map +1 -0
  67. package/dest/private/private_execution.js +90 -0
  68. package/dest/{providers → private/providers}/acvm_native.d.ts +5 -5
  69. package/dest/private/providers/acvm_native.d.ts.map +1 -0
  70. package/dest/private/providers/acvm_native.js +139 -0
  71. package/dest/{providers → private/providers}/acvm_wasm.d.ts +4 -4
  72. package/dest/private/providers/acvm_wasm.d.ts.map +1 -0
  73. package/dest/private/providers/acvm_wasm.js +62 -0
  74. package/dest/{providers → private/providers}/acvm_wasm_with_blobs.d.ts +5 -5
  75. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -0
  76. package/dest/{providers → private/providers}/acvm_wasm_with_blobs.js +3 -6
  77. package/dest/{providers → private/providers}/factory.d.ts +1 -1
  78. package/dest/private/providers/factory.d.ts.map +1 -0
  79. package/dest/private/providers/factory.js +27 -0
  80. package/dest/{common → private/providers}/simulation_provider.d.ts +5 -5
  81. package/dest/private/providers/simulation_provider.d.ts.map +1 -0
  82. package/dest/private/providers/simulation_provider.js +24 -0
  83. package/dest/private/simulator.d.ts +36 -0
  84. package/dest/private/simulator.d.ts.map +1 -0
  85. package/dest/private/simulator.js +78 -0
  86. package/dest/{client → private}/unconstrained_execution.d.ts +5 -5
  87. package/dest/private/unconstrained_execution.d.ts.map +1 -0
  88. package/dest/private/unconstrained_execution.js +27 -0
  89. package/dest/{client → private}/view_data_oracle.d.ts +15 -7
  90. package/dest/private/view_data_oracle.d.ts.map +1 -0
  91. package/dest/private/view_data_oracle.js +260 -0
  92. package/dest/{avm → public/avm}/avm_context.d.ts +7 -5
  93. package/dest/public/avm/avm_context.d.ts.map +1 -0
  94. package/dest/public/avm/avm_context.js +44 -0
  95. package/dest/{avm → public/avm}/avm_contract_call_result.d.ts +5 -5
  96. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -0
  97. package/dest/public/avm/avm_contract_call_result.js +50 -0
  98. package/dest/{avm → public/avm}/avm_execution_environment.d.ts +2 -2
  99. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -0
  100. package/dest/public/avm/avm_execution_environment.js +31 -0
  101. package/dest/public/avm/avm_gas.d.ts.map +1 -0
  102. package/dest/public/avm/avm_gas.js +202 -0
  103. package/dest/{avm → public/avm}/avm_machine_state.d.ts +2 -2
  104. package/dest/public/avm/avm_machine_state.d.ts.map +1 -0
  105. package/dest/public/avm/avm_machine_state.js +106 -0
  106. package/dest/{avm → public/avm}/avm_memory_types.d.ts +2 -2
  107. package/dest/public/avm/avm_memory_types.d.ts.map +1 -0
  108. package/dest/public/avm/avm_memory_types.js +340 -0
  109. package/dest/{avm → public/avm}/avm_simulator.d.ts +5 -3
  110. package/dest/public/avm/avm_simulator.d.ts.map +1 -0
  111. package/dest/public/avm/avm_simulator.js +202 -0
  112. package/dest/public/avm/bytecode_utils.d.ts.map +1 -0
  113. package/dest/public/avm/bytecode_utils.js +17 -0
  114. package/dest/{avm → public/avm}/errors.d.ts +5 -4
  115. package/dest/public/avm/errors.d.ts.map +1 -0
  116. package/dest/public/avm/errors.js +179 -0
  117. package/dest/{avm → public/avm}/fixtures/avm_simulation_tester.d.ts +6 -6
  118. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
  119. package/dest/public/avm/fixtures/avm_simulation_tester.js +76 -0
  120. package/dest/{avm → public/avm}/fixtures/base_avm_simulation_tester.d.ts +13 -12
  121. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
  122. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +83 -0
  123. package/dest/{avm → public/avm}/fixtures/index.d.ts +24 -7
  124. package/dest/public/avm/fixtures/index.d.ts.map +1 -0
  125. package/dest/public/avm/fixtures/index.js +175 -0
  126. package/dest/{avm → public/avm}/fixtures/simple_contract_data_source.d.ts +10 -6
  127. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
  128. package/dest/public/avm/fixtures/simple_contract_data_source.js +74 -0
  129. package/dest/public/avm/index.d.ts +4 -0
  130. package/dest/public/avm/index.d.ts.map +1 -0
  131. package/dest/{avm/index.d.ts → public/avm/index.js} +1 -2
  132. package/dest/public/avm/journal/index.d.ts.map +1 -0
  133. package/dest/{avm → public/avm}/journal/journal.d.ts +51 -18
  134. package/dest/public/avm/journal/journal.d.ts.map +1 -0
  135. package/dest/public/avm/journal/journal.js +486 -0
  136. package/dest/{avm → public/avm}/journal/nullifiers.d.ts +8 -6
  137. package/dest/public/avm/journal/nullifiers.d.ts.map +1 -0
  138. package/dest/public/avm/journal/nullifiers.js +97 -0
  139. package/dest/{avm → public/avm}/journal/public_storage.d.ts +2 -2
  140. package/dest/public/avm/journal/public_storage.d.ts.map +1 -0
  141. package/dest/public/avm/journal/public_storage.js +145 -0
  142. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -0
  143. package/dest/public/avm/opcodes/accrued_substate.js +252 -0
  144. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -0
  145. package/dest/public/avm/opcodes/addressing_mode.js +74 -0
  146. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -0
  147. package/dest/public/avm/opcodes/arithmetic.js +73 -0
  148. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -0
  149. package/dest/public/avm/opcodes/bitwise.js +106 -0
  150. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -0
  151. package/dest/public/avm/opcodes/comparators.js +43 -0
  152. package/dest/public/avm/opcodes/contract.d.ts.map +1 -0
  153. package/dest/public/avm/opcodes/contract.js +66 -0
  154. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -0
  155. package/dest/public/avm/opcodes/control_flow.js +105 -0
  156. package/dest/{avm → public/avm}/opcodes/conversion.d.ts +1 -1
  157. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -0
  158. package/dest/public/avm/opcodes/conversion.js +69 -0
  159. package/dest/{avm → public/avm}/opcodes/ec_add.d.ts +1 -1
  160. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -0
  161. package/dest/public/avm/opcodes/ec_add.js +84 -0
  162. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -0
  163. package/dest/public/avm/opcodes/environment_getters.js +79 -0
  164. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -0
  165. package/dest/public/avm/opcodes/external_calls.js +180 -0
  166. package/dest/{avm → public/avm}/opcodes/hashing.d.ts +1 -1
  167. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -0
  168. package/dest/public/avm/opcodes/hashing.js +114 -0
  169. package/dest/public/avm/opcodes/index.d.ts.map +1 -0
  170. package/dest/{avm → public/avm}/opcodes/instruction.d.ts +2 -2
  171. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -0
  172. package/dest/public/avm/opcodes/instruction.js +91 -0
  173. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -0
  174. package/dest/public/avm/opcodes/instruction_impl.js +30 -0
  175. package/dest/public/avm/opcodes/memory.d.ts.map +1 -0
  176. package/dest/public/avm/opcodes/memory.js +253 -0
  177. package/dest/{avm → public/avm}/opcodes/misc.d.ts +1 -1
  178. package/dest/public/avm/opcodes/misc.d.ts.map +1 -0
  179. package/dest/public/avm/opcodes/misc.js +48 -0
  180. package/dest/public/avm/opcodes/storage.d.ts.map +1 -0
  181. package/dest/public/avm/opcodes/storage.js +66 -0
  182. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -0
  183. package/dest/public/avm/serialization/buffer_cursor.js +99 -0
  184. package/dest/{avm → public/avm}/serialization/bytecode_serialization.d.ts +1 -1
  185. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -0
  186. package/dest/public/avm/serialization/bytecode_serialization.js +328 -0
  187. package/dest/{avm → public/avm}/serialization/instruction_serialization.d.ts +1 -2
  188. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -0
  189. package/dest/public/avm/serialization/instruction_serialization.js +225 -0
  190. package/dest/{avm → public/avm}/test_utils.d.ts +6 -4
  191. package/dest/public/avm/test_utils.d.ts.map +1 -0
  192. package/dest/public/avm/test_utils.js +52 -0
  193. package/dest/public/bytecode_errors.js +1 -2
  194. package/dest/public/execution.d.ts +8 -2
  195. package/dest/public/execution.d.ts.map +1 -1
  196. package/dest/public/execution.js +4 -5
  197. package/dest/public/executor_metrics.js +16 -12
  198. package/dest/public/fixtures/index.js +0 -1
  199. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +15 -9
  200. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  201. package/dest/public/fixtures/public_tx_simulation_tester.js +54 -53
  202. package/dest/public/fixtures/utils.d.ts +7 -11
  203. package/dest/public/fixtures/utils.d.ts.map +1 -1
  204. package/dest/public/fixtures/utils.js +92 -32
  205. package/dest/public/index.d.ts +5 -4
  206. package/dest/public/index.d.ts.map +1 -1
  207. package/dest/public/index.js +5 -5
  208. package/dest/public/public_db_sources.d.ts +82 -34
  209. package/dest/public/public_db_sources.d.ts.map +1 -1
  210. package/dest/public/public_db_sources.js +171 -196
  211. package/dest/public/{public_processor.d.ts → public_processor/public_processor.d.ts} +10 -8
  212. package/dest/public/public_processor/public_processor.d.ts.map +1 -0
  213. package/dest/public/public_processor/public_processor.js +379 -0
  214. package/dest/public/{public_processor_metrics.d.ts → public_processor/public_processor_metrics.d.ts} +3 -3
  215. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -0
  216. package/dest/public/public_processor/public_processor_metrics.js +125 -0
  217. package/dest/public/{public_tx_context.d.ts → public_tx_simulator/public_tx_context.d.ts} +14 -8
  218. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -0
  219. package/dest/public/public_tx_simulator/public_tx_context.js +320 -0
  220. package/dest/public/{public_tx_simulator.d.ts → public_tx_simulator/public_tx_simulator.d.ts} +10 -7
  221. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -0
  222. package/dest/public/public_tx_simulator/public_tx_simulator.js +325 -0
  223. package/dest/public/side_effect_errors.js +1 -2
  224. package/dest/public/side_effect_trace.d.ts +16 -10
  225. package/dest/public/side_effect_trace.d.ts.map +1 -1
  226. package/dest/public/side_effect_trace.js +82 -149
  227. package/dest/public/side_effect_trace_interface.d.ts +9 -7
  228. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  229. package/dest/public/side_effect_trace_interface.js +1 -2
  230. package/dest/public/tx_contract_cache.d.ts +41 -0
  231. package/dest/public/tx_contract_cache.d.ts.map +1 -0
  232. package/dest/public/tx_contract_cache.js +49 -0
  233. package/dest/public/unique_class_ids.js +23 -28
  234. package/dest/public/utils.d.ts +2 -2
  235. package/dest/public/utils.d.ts.map +1 -1
  236. package/dest/public/utils.js +17 -12
  237. package/dest/server.d.ts +4 -4
  238. package/dest/server.d.ts.map +1 -1
  239. package/dest/server.js +3 -5
  240. package/dest/test/utils.d.ts +3 -2
  241. package/dest/test/utils.d.ts.map +1 -1
  242. package/dest/test/utils.js +9 -7
  243. package/package.json +19 -21
  244. package/src/client.ts +4 -0
  245. package/src/{public → common}/db_interfaces.ts +8 -40
  246. package/src/common/debug_fn_name.ts +4 -2
  247. package/src/common/errors.ts +5 -5
  248. package/src/common/index.ts +2 -1
  249. package/src/common/message_load_oracle_inputs.ts +2 -2
  250. package/src/common/stats/index.ts +1 -0
  251. package/src/{stats → common/stats}/stats.ts +2 -2
  252. package/src/{acvm → private/acvm}/acvm.ts +5 -5
  253. package/src/{acvm → private/acvm}/acvm_types.ts +1 -1
  254. package/src/{acvm → private/acvm}/deserialize.ts +2 -2
  255. package/src/{acvm → private/acvm}/oracle/index.ts +1 -1
  256. package/src/{acvm → private/acvm}/oracle/oracle.ts +22 -12
  257. package/src/{acvm → private/acvm}/oracle/typed_oracle.ts +50 -55
  258. package/src/{acvm → private/acvm}/serialize.ts +10 -3
  259. package/src/{client → private}/client_execution_context.ts +54 -37
  260. package/src/{client → private}/db_oracle.ts +20 -20
  261. package/src/{client → private}/execution_note_cache.ts +3 -3
  262. package/src/{common → private}/hashed_values_cache.ts +2 -2
  263. package/src/private/index.ts +12 -0
  264. package/src/{client → private}/pick_notes.ts +1 -1
  265. package/src/{client → private}/private_execution.ts +46 -14
  266. package/src/{providers → private/providers}/acvm_native.ts +6 -6
  267. package/src/{providers → private/providers}/acvm_wasm.ts +4 -4
  268. package/src/{providers → private/providers}/acvm_wasm_with_blobs.ts +5 -5
  269. package/src/{providers → private/providers}/factory.ts +1 -1
  270. package/src/{common → private/providers}/simulation_provider.ts +5 -5
  271. package/src/{client → private}/simulator.ts +31 -123
  272. package/src/{client → private}/unconstrained_execution.ts +7 -7
  273. package/src/{client → private}/view_data_oracle.ts +25 -28
  274. package/src/{avm → public/avm}/avm_context.ts +12 -7
  275. package/src/{avm → public/avm}/avm_contract_call_result.ts +6 -6
  276. package/src/{avm → public/avm}/avm_execution_environment.ts +2 -2
  277. package/src/{avm → public/avm}/avm_gas.ts +1 -3
  278. package/src/{avm → public/avm}/avm_machine_state.ts +2 -2
  279. package/src/{avm → public/avm}/avm_memory_types.ts +4 -4
  280. package/src/{avm → public/avm}/avm_simulator.ts +12 -6
  281. package/src/{avm → public/avm}/errors.ts +5 -4
  282. package/src/{avm → public/avm}/fixtures/avm_simulation_tester.ts +16 -15
  283. package/src/{avm → public/avm}/fixtures/base_avm_simulation_tester.ts +45 -40
  284. package/src/{avm → public/avm}/fixtures/index.ts +77 -12
  285. package/src/{avm → public/avm}/fixtures/simple_contract_data_source.ts +26 -19
  286. package/src/{avm → public/avm}/index.ts +1 -1
  287. package/src/public/avm/journal/index.ts +1 -0
  288. package/src/{avm → public/avm}/journal/journal.ts +330 -305
  289. package/src/{avm → public/avm}/journal/nullifiers.ts +20 -19
  290. package/src/{avm → public/avm}/journal/public_storage.ts +2 -2
  291. package/src/{avm → public/avm}/opcodes/contract.ts +1 -1
  292. package/src/{avm → public/avm}/opcodes/control_flow.ts +1 -1
  293. package/src/{avm → public/avm}/opcodes/conversion.ts +1 -1
  294. package/src/{avm → public/avm}/opcodes/ec_add.ts +2 -2
  295. package/src/{avm → public/avm}/opcodes/external_calls.ts +5 -6
  296. package/src/{avm → public/avm}/opcodes/hashing.ts +1 -1
  297. package/src/public/avm/opcodes/index.ts +15 -0
  298. package/src/{avm → public/avm}/opcodes/instruction.ts +2 -2
  299. package/src/{avm → public/avm}/opcodes/misc.ts +1 -1
  300. package/src/public/avm/serialization/bytecode_serialization.ts +204 -0
  301. package/src/{avm → public/avm}/serialization/instruction_serialization.ts +0 -1
  302. package/src/{avm → public/avm}/test_utils.ts +10 -7
  303. package/src/public/execution.ts +9 -12
  304. package/src/public/fixtures/public_tx_simulation_tester.ts +66 -72
  305. package/src/public/fixtures/utils.ts +122 -33
  306. package/src/public/index.ts +5 -4
  307. package/src/public/public_db_sources.ts +216 -222
  308. package/src/public/{public_processor.ts → public_processor/public_processor.ts} +78 -53
  309. package/src/public/{public_processor_metrics.ts → public_processor/public_processor_metrics.ts} +3 -3
  310. package/src/public/{public_tx_context.ts → public_tx_simulator/public_tx_context.ts} +70 -75
  311. package/src/public/{public_tx_simulator.ts → public_tx_simulator/public_tx_simulator.ts} +104 -91
  312. package/src/public/side_effect_trace.ts +85 -160
  313. package/src/public/side_effect_trace_interface.ts +10 -23
  314. package/src/public/tx_contract_cache.ts +69 -0
  315. package/src/public/unique_class_ids.ts +1 -1
  316. package/src/public/utils.ts +2 -2
  317. package/src/server.ts +4 -4
  318. package/src/test/utils.ts +5 -3
  319. package/dest/acvm/acvm.d.ts.map +0 -1
  320. package/dest/acvm/acvm.js +0 -73
  321. package/dest/acvm/acvm_types.d.ts.map +0 -1
  322. package/dest/acvm/acvm_types.js +0 -2
  323. package/dest/acvm/deserialize.d.ts.map +0 -1
  324. package/dest/acvm/deserialize.js +0 -46
  325. package/dest/acvm/index.d.ts.map +0 -1
  326. package/dest/acvm/index.js +0 -6
  327. package/dest/acvm/oracle/index.d.ts.map +0 -1
  328. package/dest/acvm/oracle/index.js +0 -3
  329. package/dest/acvm/oracle/oracle.d.ts.map +0 -1
  330. package/dest/acvm/oracle/oracle.js +0 -230
  331. package/dest/acvm/oracle/typed_oracle.d.ts.map +0 -1
  332. package/dest/acvm/oracle/typed_oracle.js +0 -131
  333. package/dest/acvm/serialize.d.ts.map +0 -1
  334. package/dest/acvm/serialize.js +0 -48
  335. package/dest/avm/avm_context.d.ts.map +0 -1
  336. package/dest/avm/avm_context.js +0 -44
  337. package/dest/avm/avm_contract_call_result.d.ts.map +0 -1
  338. package/dest/avm/avm_contract_call_result.js +0 -45
  339. package/dest/avm/avm_execution_environment.d.ts.map +0 -1
  340. package/dest/avm/avm_execution_environment.js +0 -28
  341. package/dest/avm/avm_gas.d.ts.map +0 -1
  342. package/dest/avm/avm_gas.js +0 -170
  343. package/dest/avm/avm_machine_state.d.ts.map +0 -1
  344. package/dest/avm/avm_machine_state.js +0 -112
  345. package/dest/avm/avm_memory_types.d.ts.map +0 -1
  346. package/dest/avm/avm_memory_types.js +0 -327
  347. package/dest/avm/avm_simulator.d.ts.map +0 -1
  348. package/dest/avm/avm_simulator.js +0 -193
  349. package/dest/avm/avm_tree.d.ts +0 -282
  350. package/dest/avm/avm_tree.d.ts.map +0 -1
  351. package/dest/avm/avm_tree.js +0 -684
  352. package/dest/avm/bytecode_utils.d.ts.map +0 -1
  353. package/dest/avm/bytecode_utils.js +0 -15
  354. package/dest/avm/errors.d.ts.map +0 -1
  355. package/dest/avm/errors.js +0 -196
  356. package/dest/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  357. package/dest/avm/fixtures/avm_simulation_tester.js +0 -73
  358. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  359. package/dest/avm/fixtures/base_avm_simulation_tester.js +0 -76
  360. package/dest/avm/fixtures/index.d.ts.map +0 -1
  361. package/dest/avm/fixtures/index.js +0 -134
  362. package/dest/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
  363. package/dest/avm/fixtures/simple_contract_data_source.js +0 -75
  364. package/dest/avm/index.d.ts.map +0 -1
  365. package/dest/avm/index.js +0 -4
  366. package/dest/avm/journal/index.d.ts.map +0 -1
  367. package/dest/avm/journal/index.js +0 -2
  368. package/dest/avm/journal/journal.d.ts.map +0 -1
  369. package/dest/avm/journal/journal.js +0 -499
  370. package/dest/avm/journal/nullifiers.d.ts.map +0 -1
  371. package/dest/avm/journal/nullifiers.js +0 -99
  372. package/dest/avm/journal/public_storage.d.ts.map +0 -1
  373. package/dest/avm/journal/public_storage.js +0 -159
  374. package/dest/avm/opcodes/accrued_substate.d.ts.map +0 -1
  375. package/dest/avm/opcodes/accrued_substate.js +0 -215
  376. package/dest/avm/opcodes/addressing_mode.d.ts.map +0 -1
  377. package/dest/avm/opcodes/addressing_mode.js +0 -81
  378. package/dest/avm/opcodes/arithmetic.d.ts.map +0 -1
  379. package/dest/avm/opcodes/arithmetic.js +0 -70
  380. package/dest/avm/opcodes/bitwise.d.ts.map +0 -1
  381. package/dest/avm/opcodes/bitwise.js +0 -90
  382. package/dest/avm/opcodes/comparators.d.ts.map +0 -1
  383. package/dest/avm/opcodes/comparators.js +0 -40
  384. package/dest/avm/opcodes/contract.d.ts.map +0 -1
  385. package/dest/avm/opcodes/contract.js +0 -63
  386. package/dest/avm/opcodes/control_flow.d.ts.map +0 -1
  387. package/dest/avm/opcodes/control_flow.js +0 -97
  388. package/dest/avm/opcodes/conversion.d.ts.map +0 -1
  389. package/dest/avm/opcodes/conversion.js +0 -64
  390. package/dest/avm/opcodes/ec_add.d.ts.map +0 -1
  391. package/dest/avm/opcodes/ec_add.js +0 -82
  392. package/dest/avm/opcodes/environment_getters.d.ts.map +0 -1
  393. package/dest/avm/opcodes/environment_getters.js +0 -78
  394. package/dest/avm/opcodes/external_calls.d.ts.map +0 -1
  395. package/dest/avm/opcodes/external_calls.js +0 -169
  396. package/dest/avm/opcodes/hashing.d.ts.map +0 -1
  397. package/dest/avm/opcodes/hashing.js +0 -103
  398. package/dest/avm/opcodes/index.d.ts.map +0 -1
  399. package/dest/avm/opcodes/index.js +0 -16
  400. package/dest/avm/opcodes/instruction.d.ts.map +0 -1
  401. package/dest/avm/opcodes/instruction.js +0 -100
  402. package/dest/avm/opcodes/instruction_impl.d.ts.map +0 -1
  403. package/dest/avm/opcodes/instruction_impl.js +0 -33
  404. package/dest/avm/opcodes/memory.d.ts.map +0 -1
  405. package/dest/avm/opcodes/memory.js +0 -226
  406. package/dest/avm/opcodes/misc.d.ts.map +0 -1
  407. package/dest/avm/opcodes/misc.js +0 -45
  408. package/dest/avm/opcodes/multi_scalar_mul.d.ts +0 -16
  409. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +0 -1
  410. package/dest/avm/opcodes/multi_scalar_mul.js +0 -112
  411. package/dest/avm/opcodes/storage.d.ts.map +0 -1
  412. package/dest/avm/opcodes/storage.js +0 -61
  413. package/dest/avm/serialization/buffer_cursor.d.ts.map +0 -1
  414. package/dest/avm/serialization/buffer_cursor.js +0 -99
  415. package/dest/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  416. package/dest/avm/serialization/bytecode_serialization.js +0 -132
  417. package/dest/avm/serialization/instruction_serialization.d.ts.map +0 -1
  418. package/dest/avm/serialization/instruction_serialization.js +0 -187
  419. package/dest/avm/test_utils.d.ts.map +0 -1
  420. package/dest/avm/test_utils.js +0 -52
  421. package/dest/client/client_execution_context.d.ts.map +0 -1
  422. package/dest/client/client_execution_context.js +0 -392
  423. package/dest/client/db_oracle.d.ts.map +0 -1
  424. package/dest/client/db_oracle.js +0 -17
  425. package/dest/client/execution_note_cache.d.ts.map +0 -1
  426. package/dest/client/execution_note_cache.js +0 -181
  427. package/dest/client/index.d.ts +0 -16
  428. package/dest/client/index.d.ts.map +0 -1
  429. package/dest/client/index.js +0 -15
  430. package/dest/client/pick_notes.d.ts.map +0 -1
  431. package/dest/client/pick_notes.js +0 -54
  432. package/dest/client/private_execution.d.ts +0 -19
  433. package/dest/client/private_execution.d.ts.map +0 -1
  434. package/dest/client/private_execution.js +0 -72
  435. package/dest/client/simulator.d.ts +0 -60
  436. package/dest/client/simulator.d.ts.map +0 -1
  437. package/dest/client/simulator.js +0 -136
  438. package/dest/client/unconstrained_execution.d.ts.map +0 -1
  439. package/dest/client/unconstrained_execution.js +0 -30
  440. package/dest/client/view_data_oracle.d.ts.map +0 -1
  441. package/dest/client/view_data_oracle.js +0 -268
  442. package/dest/common/hashed_values_cache.d.ts.map +0 -1
  443. package/dest/common/hashed_values_cache.js +0 -50
  444. package/dest/common/simulation_provider.d.ts.map +0 -1
  445. package/dest/common/simulation_provider.js +0 -27
  446. package/dest/common.d.ts +0 -2
  447. package/dest/common.d.ts.map +0 -1
  448. package/dest/common.js +0 -2
  449. package/dest/providers/acvm_native.d.ts.map +0 -1
  450. package/dest/providers/acvm_native.js +0 -125
  451. package/dest/providers/acvm_wasm.d.ts.map +0 -1
  452. package/dest/providers/acvm_wasm.js +0 -54
  453. package/dest/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
  454. package/dest/providers/factory.d.ts.map +0 -1
  455. package/dest/providers/factory.js +0 -27
  456. package/dest/providers/index.d.ts +0 -5
  457. package/dest/providers/index.d.ts.map +0 -1
  458. package/dest/providers/index.js +0 -5
  459. package/dest/public/db_interfaces.d.ts.map +0 -1
  460. package/dest/public/db_interfaces.js +0 -2
  461. package/dest/public/fee_payment.d.ts +0 -11
  462. package/dest/public/fee_payment.d.ts.map +0 -1
  463. package/dest/public/fee_payment.js +0 -21
  464. package/dest/public/public_processor.d.ts.map +0 -1
  465. package/dest/public/public_processor.js +0 -352
  466. package/dest/public/public_processor_metrics.d.ts.map +0 -1
  467. package/dest/public/public_processor_metrics.js +0 -106
  468. package/dest/public/public_tx_context.d.ts.map +0 -1
  469. package/dest/public/public_tx_context.js +0 -341
  470. package/dest/public/public_tx_simulator.d.ts.map +0 -1
  471. package/dest/public/public_tx_simulator.js +0 -333
  472. package/dest/stats/index.d.ts.map +0 -1
  473. package/dest/stats/index.js +0 -2
  474. package/dest/stats/stats.d.ts.map +0 -1
  475. package/dest/stats/stats.js +0 -11
  476. package/src/avm/avm_tree.ts +0 -887
  477. package/src/avm/opcodes/multi_scalar_mul.ts +0 -121
  478. package/src/avm/serialization/bytecode_serialization.ts +0 -212
  479. package/src/client/index.ts +0 -15
  480. package/src/common.ts +0 -1
  481. package/src/providers/index.ts +0 -4
  482. package/src/public/fee_payment.ts +0 -23
  483. /package/dest/{stats → common/stats}/index.d.ts +0 -0
  484. /package/{src/stats/index.ts → dest/common/stats/index.js} +0 -0
  485. /package/dest/{acvm → private/acvm}/index.d.ts +0 -0
  486. /package/dest/{avm → public/avm}/avm_gas.d.ts +0 -0
  487. /package/dest/{avm → public/avm}/bytecode_utils.d.ts +0 -0
  488. /package/dest/{avm → public/avm}/journal/index.d.ts +0 -0
  489. /package/{src/avm/journal/index.ts → dest/public/avm/journal/index.js} +0 -0
  490. /package/dest/{avm → public/avm}/opcodes/accrued_substate.d.ts +0 -0
  491. /package/dest/{avm → public/avm}/opcodes/addressing_mode.d.ts +0 -0
  492. /package/dest/{avm → public/avm}/opcodes/arithmetic.d.ts +0 -0
  493. /package/dest/{avm → public/avm}/opcodes/bitwise.d.ts +0 -0
  494. /package/dest/{avm → public/avm}/opcodes/comparators.d.ts +0 -0
  495. /package/dest/{avm → public/avm}/opcodes/contract.d.ts +0 -0
  496. /package/dest/{avm → public/avm}/opcodes/control_flow.d.ts +0 -0
  497. /package/dest/{avm → public/avm}/opcodes/environment_getters.d.ts +0 -0
  498. /package/dest/{avm → public/avm}/opcodes/external_calls.d.ts +0 -0
  499. /package/dest/{avm → public/avm}/opcodes/index.d.ts +0 -0
  500. /package/{src/avm/opcodes/index.ts → dest/public/avm/opcodes/index.js} +0 -0
  501. /package/dest/{avm → public/avm}/opcodes/instruction_impl.d.ts +0 -0
  502. /package/dest/{avm → public/avm}/opcodes/memory.d.ts +0 -0
  503. /package/dest/{avm → public/avm}/opcodes/storage.d.ts +0 -0
  504. /package/dest/{avm → public/avm}/serialization/buffer_cursor.d.ts +0 -0
  505. /package/src/{acvm → private/acvm}/index.ts +0 -0
  506. /package/src/{avm → public/avm}/bytecode_utils.ts +0 -0
  507. /package/src/{avm → public/avm}/opcodes/.eslintrc.cjs +0 -0
  508. /package/src/{avm → public/avm}/opcodes/accrued_substate.ts +0 -0
  509. /package/src/{avm → public/avm}/opcodes/addressing_mode.ts +0 -0
  510. /package/src/{avm → public/avm}/opcodes/arithmetic.ts +0 -0
  511. /package/src/{avm → public/avm}/opcodes/bitwise.ts +0 -0
  512. /package/src/{avm → public/avm}/opcodes/comparators.ts +0 -0
  513. /package/src/{avm → public/avm}/opcodes/environment_getters.ts +0 -0
  514. /package/src/{avm → public/avm}/opcodes/instruction_impl.ts +0 -0
  515. /package/src/{avm → public/avm}/opcodes/memory.ts +0 -0
  516. /package/src/{avm → public/avm}/opcodes/storage.ts +0 -0
  517. /package/src/{avm → public/avm}/serialization/buffer_cursor.ts +0 -0
@@ -0,0 +1,378 @@
1
+ import { PRIVATE_CONTEXT_INPUTS_LENGTH, PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { FunctionSelector, countArgumentsSize } from '@aztec/stdlib/abi';
5
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import { computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
7
+ import { PrivateContextInputs } from '@aztec/stdlib/kernel';
8
+ import { Note } from '@aztec/stdlib/note';
9
+ import { CallContext, CountedContractClassLog, CountedPublicExecutionRequest, NoteAndSlot, PublicExecutionRequest } from '@aztec/stdlib/tx';
10
+ import { toACVMWitness } from './acvm/index.js';
11
+ import { pickNotes } from './pick_notes.js';
12
+ import { executePrivateFunction, verifyCurrentClassId } from './private_execution.js';
13
+ import { ViewDataOracle } from './view_data_oracle.js';
14
+ /**
15
+ * The execution context for a client tx simulation.
16
+ */ export class ClientExecutionContext extends ViewDataOracle {
17
+ argsHash;
18
+ txContext;
19
+ callContext;
20
+ historicalHeader;
21
+ executionCache;
22
+ noteCache;
23
+ node;
24
+ provider;
25
+ sideEffectCounter;
26
+ /**
27
+ * New notes created during this execution.
28
+ * It's possible that a note in this list has been nullified (in the same or other executions) and doesn't exist in the ExecutionNoteCache and the final proof data.
29
+ * But we still include those notes in the execution result because their commitments are still in the public inputs of this execution.
30
+ * This information is only for references (currently used for tests), and is not used for any sort of constrains.
31
+ * Users can also use this to get a clearer idea of what's happened during a simulation.
32
+ */ newNotes;
33
+ /**
34
+ * Notes from previous transactions that are returned to the oracle call `getNotes` during this execution.
35
+ * The mapping maps from the unique siloed note hash to the index for notes created in private executions.
36
+ * It maps from siloed note hash to the index for notes created by public functions.
37
+ *
38
+ * They are not part of the ExecutionNoteCache and being forwarded to nested contexts via `extend()`
39
+ * because these notes are meant to be maintained on a per-call basis
40
+ * They should act as references for the read requests output by an app circuit via public inputs.
41
+ */ noteHashLeafIndexMap;
42
+ noteHashNullifierCounterMap;
43
+ contractClassLogs;
44
+ nestedExecutions;
45
+ enqueuedPublicFunctionCalls;
46
+ publicTeardownFunctionCall;
47
+ constructor(argsHash, txContext, callContext, /** Header of a block whose state is used during private execution (not the block the transaction is included in). */ historicalHeader, /** List of transient auth witnesses to be used during this simulation */ authWitnesses, capsules, executionCache, noteCache, db, node, provider, sideEffectCounter = 0, log = createLogger('simulator:client_execution_context'), scopes){
48
+ super(callContext.contractAddress, authWitnesses, capsules, db, node, log, scopes), this.argsHash = argsHash, this.txContext = txContext, this.callContext = callContext, this.historicalHeader = historicalHeader, this.executionCache = executionCache, this.noteCache = noteCache, this.node = node, this.provider = provider, this.sideEffectCounter = sideEffectCounter, this.newNotes = [], this.noteHashLeafIndexMap = new Map(), this.noteHashNullifierCounterMap = new Map(), this.contractClassLogs = [], this.nestedExecutions = [], this.enqueuedPublicFunctionCalls = [], this.publicTeardownFunctionCall = PublicExecutionRequest.empty();
49
+ }
50
+ // We still need this function until we can get user-defined ordering of structs for fn arguments
51
+ // TODO When that is sorted out on noir side, we can use instead the utilities in serialize.ts
52
+ /**
53
+ * Writes the function inputs to the initial witness.
54
+ * @param abi - The function ABI.
55
+ * @returns The initial witness.
56
+ */ getInitialWitness(abi) {
57
+ const argumentsSize = countArgumentsSize(abi);
58
+ const args = this.executionCache.getPreimage(this.argsHash);
59
+ if (args.length !== argumentsSize) {
60
+ throw new Error(`Invalid arguments size: expected ${argumentsSize}, got ${args.length}`);
61
+ }
62
+ const privateContextInputs = new PrivateContextInputs(this.callContext, this.historicalHeader, this.txContext, this.sideEffectCounter);
63
+ const privateContextInputsAsFields = privateContextInputs.toFields();
64
+ if (privateContextInputsAsFields.length !== PRIVATE_CONTEXT_INPUTS_LENGTH) {
65
+ throw new Error('Invalid private context inputs size');
66
+ }
67
+ const fields = [
68
+ ...privateContextInputsAsFields,
69
+ ...args
70
+ ];
71
+ return toACVMWitness(0, fields);
72
+ }
73
+ /**
74
+ * The KernelProver will use this to fully populate witnesses and provide hints to the kernel circuit
75
+ * regarding which note hash each settled read request corresponds to.
76
+ */ getNoteHashLeafIndexMap() {
77
+ return this.noteHashLeafIndexMap;
78
+ }
79
+ /**
80
+ * Get the data for the newly created notes.
81
+ */ getNewNotes() {
82
+ return this.newNotes;
83
+ }
84
+ getNoteHashNullifierCounterMap() {
85
+ return this.noteHashNullifierCounterMap;
86
+ }
87
+ /**
88
+ * Return the contract class logs emitted during this execution.
89
+ */ getContractClassLogs() {
90
+ return this.contractClassLogs;
91
+ }
92
+ /**
93
+ * Return the nested execution results during this execution.
94
+ */ getNestedExecutions() {
95
+ return this.nestedExecutions;
96
+ }
97
+ /**
98
+ * Return the enqueued public function calls during this execution.
99
+ */ getEnqueuedPublicFunctionCalls() {
100
+ return this.enqueuedPublicFunctionCalls;
101
+ }
102
+ /**
103
+ * Return the public teardown function call set during this execution.
104
+ */ getPublicTeardownFunctionCall() {
105
+ return this.publicTeardownFunctionCall;
106
+ }
107
+ /**
108
+ * Store values in the execution cache.
109
+ * @param values - Values to store.
110
+ * @returns The hash of the values.
111
+ */ storeInExecutionCache(values) {
112
+ return this.executionCache.store(values);
113
+ }
114
+ /**
115
+ * Gets values from the execution cache.
116
+ * @param hash - Hash of the values.
117
+ * @returns The values.
118
+ */ loadFromExecutionCache(hash) {
119
+ return Promise.resolve(this.executionCache.getPreimage(hash));
120
+ }
121
+ /**
122
+ * Gets some notes for a storage slot.
123
+ *
124
+ * @remarks
125
+ * Check for pending notes with matching slot.
126
+ * Real notes coming from DB will have a leafIndex which
127
+ * represents their index in the note hash tree.
128
+ *
129
+ * @param storageSlot - The storage slot.
130
+ * @param numSelects - The number of valid selects in selectBy and selectValues.
131
+ * @param selectBy - An array of indices of the fields to selects.
132
+ * @param selectValues - The values to match.
133
+ * @param selectComparators - The comparators to match by.
134
+ * @param sortBy - An array of indices of the fields to sort.
135
+ * @param sortOrder - The order of the corresponding index in sortBy. (1: DESC, 2: ASC, 0: Do nothing)
136
+ * @param limit - The number of notes to retrieve per query.
137
+ * @param offset - The starting index for pagination.
138
+ * @param status - The status of notes to fetch.
139
+ * @returns Array of note data.
140
+ */ async getNotes(storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
141
+ // Nullified pending notes are already removed from the list.
142
+ const pendingNotes = this.noteCache.getNotes(this.callContext.contractAddress, storageSlot);
143
+ const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.contractAddress);
144
+ const dbNotes = await this.db.getNotes(this.callContext.contractAddress, storageSlot, status, this.scopes);
145
+ const dbNotesFiltered = dbNotes.filter((n)=>!pendingNullifiers.has(n.siloedNullifier.value));
146
+ const notes = pickNotes([
147
+ ...dbNotesFiltered,
148
+ ...pendingNotes
149
+ ], {
150
+ selects: selectByIndexes.slice(0, numSelects).map((index, i)=>({
151
+ selector: {
152
+ index,
153
+ offset: selectByOffsets[i],
154
+ length: selectByLengths[i]
155
+ },
156
+ value: selectValues[i],
157
+ comparator: selectComparators[i]
158
+ })),
159
+ sorts: sortByIndexes.map((index, i)=>({
160
+ selector: {
161
+ index,
162
+ offset: sortByOffsets[i],
163
+ length: sortByLengths[i]
164
+ },
165
+ order: sortOrder[i]
166
+ })),
167
+ limit,
168
+ offset
169
+ });
170
+ this.log.debug(`Returning ${notes.length} notes for ${this.callContext.contractAddress} at ${storageSlot}: ${notes.map((n)=>`${n.nonce.toString()}:[${n.note.items.map((i)=>i.toString()).join(',')}]`).join(', ')}`);
171
+ const noteHashesAndIndexes = await Promise.all(notes.map(async (n)=>{
172
+ if (n.index !== undefined) {
173
+ const siloedNoteHash = await siloNoteHash(n.contractAddress, n.noteHash);
174
+ const uniqueNoteHash = await computeUniqueNoteHash(n.nonce, siloedNoteHash);
175
+ return {
176
+ hash: uniqueNoteHash,
177
+ index: n.index
178
+ };
179
+ }
180
+ }));
181
+ noteHashesAndIndexes.filter((n)=>n !== undefined).forEach((n)=>{
182
+ this.noteHashLeafIndexMap.set(n.hash.toBigInt(), n.index);
183
+ });
184
+ return notes;
185
+ }
186
+ /**
187
+ * Keep track of the new note created during execution.
188
+ * It can be used in subsequent calls (or transactions when chaining txs is possible).
189
+ * @param contractAddress - The contract address.
190
+ * @param storageSlot - The storage slot.
191
+ * @param noteTypeId - The type ID of the note.
192
+ * @param noteItems - The items to be included in a Note.
193
+ * @param noteHash - A hash of the new note.
194
+ * @returns
195
+ */ notifyCreatedNote(storageSlot, noteTypeId, noteItems, noteHash, counter) {
196
+ this.log.debug(`Notified of new note with inner hash ${noteHash}`, {
197
+ contractAddress: this.callContext.contractAddress,
198
+ storageSlot,
199
+ noteTypeId,
200
+ counter
201
+ });
202
+ const note = new Note(noteItems);
203
+ this.noteCache.addNewNote({
204
+ contractAddress: this.callContext.contractAddress,
205
+ storageSlot,
206
+ nonce: Fr.ZERO,
207
+ note,
208
+ siloedNullifier: undefined,
209
+ noteHash
210
+ }, counter);
211
+ this.newNotes.push(new NoteAndSlot(note, storageSlot, noteTypeId));
212
+ }
213
+ /**
214
+ * Adding a siloed nullifier into the current set of all pending nullifiers created
215
+ * within the current transaction/execution.
216
+ * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
217
+ * @param noteHash - A hash of the new note.
218
+ */ async notifyNullifiedNote(innerNullifier, noteHash, counter) {
219
+ const nullifiedNoteHashCounter = await this.noteCache.nullifyNote(this.callContext.contractAddress, innerNullifier, noteHash);
220
+ if (nullifiedNoteHashCounter !== undefined) {
221
+ this.noteHashNullifierCounterMap.set(nullifiedNoteHashCounter, counter);
222
+ }
223
+ }
224
+ /**
225
+ * Adding a siloed nullifier into the current set of all pending nullifiers created
226
+ * within the current transaction/execution.
227
+ * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
228
+ * @param noteHash - A hash of the new note.
229
+ */ notifyCreatedNullifier(innerNullifier) {
230
+ return this.noteCache.nullifierCreated(this.callContext.contractAddress, innerNullifier);
231
+ }
232
+ /**
233
+ * Emit a contract class log.
234
+ * This fn exists because we only carry a poseidon hash through the kernels, and need to
235
+ * keep the preimage in ts for later.
236
+ * We could also return the hash here if we must save extra gates.
237
+ * @param log - The contract class log to be emitted.
238
+ * @param counter - The contract class log's counter.
239
+ */ emitContractClassLog(log, counter) {
240
+ this.contractClassLogs.push(new CountedContractClassLog(log, counter));
241
+ const text = log.toBuffer().toString('hex');
242
+ this.log.verbose(`Emitted log from ContractClassRegisterer: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
243
+ }
244
+ #checkValidStaticCall(childExecutionResult) {
245
+ if (childExecutionResult.publicInputs.noteHashes.some((item)=>!item.isEmpty()) || childExecutionResult.publicInputs.nullifiers.some((item)=>!item.isEmpty()) || childExecutionResult.publicInputs.l2ToL1Msgs.some((item)=>!item.isEmpty()) || childExecutionResult.publicInputs.privateLogs.some((item)=>!item.isEmpty()) || childExecutionResult.publicInputs.contractClassLogsHashes.some((item)=>!item.isEmpty())) {
246
+ throw new Error(`Static call cannot update the state, emit L2->L1 messages or generate logs`);
247
+ }
248
+ }
249
+ /**
250
+ * Calls a private function as a nested execution.
251
+ * @param targetContractAddress - The address of the contract to call.
252
+ * @param functionSelector - The function selector of the function to call.
253
+ * @param argsHash - The arguments hash to pass to the function.
254
+ * @param sideEffectCounter - The side effect counter at the start of the call.
255
+ * @param isStaticCall - Whether the call is a static call.
256
+ * @returns The execution result.
257
+ */ async callPrivateFunction(targetContractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall) {
258
+ this.log.debug(`Calling private function ${targetContractAddress}:${functionSelector} from ${this.callContext.contractAddress}`);
259
+ isStaticCall = isStaticCall || this.callContext.isStaticCall;
260
+ await verifyCurrentClassId(targetContractAddress, await this.db.getContractInstance(targetContractAddress), this.node, this.historicalHeader.globalVariables.blockNumber.toNumber());
261
+ const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
262
+ const derivedTxContext = this.txContext.clone();
263
+ const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
264
+ const context = new ClientExecutionContext(argsHash, derivedTxContext, derivedCallContext, this.historicalHeader, this.authWitnesses, this.capsules, this.executionCache, this.noteCache, this.db, this.node, this.provider, sideEffectCounter, this.log, this.scopes);
265
+ const childExecutionResult = await executePrivateFunction(this.provider, context, targetArtifact, targetContractAddress, functionSelector);
266
+ if (isStaticCall) {
267
+ this.#checkValidStaticCall(childExecutionResult);
268
+ }
269
+ this.nestedExecutions.push(childExecutionResult);
270
+ const publicInputs = childExecutionResult.publicInputs;
271
+ return {
272
+ endSideEffectCounter: publicInputs.endSideEffectCounter,
273
+ returnsHash: publicInputs.returnsHash
274
+ };
275
+ }
276
+ /**
277
+ * Creates a PublicExecutionRequest object representing the request to call a public function.
278
+ * @param targetContractAddress - The address of the contract to call.
279
+ * @param functionSelector - The function selector of the function to call.
280
+ * @param argsHash - The arguments hash to pass to the function.
281
+ * @param sideEffectCounter - The side effect counter at the start of the call.
282
+ * @param isStaticCall - Whether the call is a static call.
283
+ * @returns The public call stack item with the request information.
284
+ */ async createPublicExecutionRequest(callType, targetContractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall) {
285
+ const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
286
+ const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
287
+ const args = this.executionCache.getPreimage(argsHash);
288
+ this.log.verbose(`Created ${callType} public execution request to ${targetArtifact.name}@${targetContractAddress}`, {
289
+ sideEffectCounter,
290
+ isStaticCall,
291
+ functionSelector,
292
+ targetContractAddress,
293
+ callType
294
+ });
295
+ const request = PublicExecutionRequest.from({
296
+ args,
297
+ callContext: derivedCallContext
298
+ });
299
+ if (callType === 'enqueued') {
300
+ this.enqueuedPublicFunctionCalls.push(new CountedPublicExecutionRequest(request, sideEffectCounter));
301
+ } else {
302
+ this.publicTeardownFunctionCall = request;
303
+ }
304
+ }
305
+ /**
306
+ * Creates and enqueues a PublicExecutionRequest object representing the request to call a public function. No function
307
+ * is actually called, since that must happen on the sequencer side. All the fields related to the result
308
+ * of the execution are empty.
309
+ * @param targetContractAddress - The address of the contract to call.
310
+ * @param functionSelector - The function selector of the function to call.
311
+ * @param argsHash - The arguments hash to pass to the function.
312
+ * @param sideEffectCounter - The side effect counter at the start of the call.
313
+ * @param isStaticCall - Whether the call is a static call.
314
+ * @returns The public call stack item with the request information.
315
+ */ async enqueuePublicFunctionCall(targetContractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall) {
316
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
317
+ // WARNING: This is insecure and should be temporary!
318
+ // The oracle re-hashes the arguments and returns a new args_hash.
319
+ // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
320
+ // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
321
+ // b) this is only temporary.
322
+ const newArgsHash = await this.executionCache.store([
323
+ functionSelector.toField(),
324
+ ...this.executionCache.getPreimage(argsHash)
325
+ ]);
326
+ await this.createPublicExecutionRequest('enqueued', targetContractAddress, FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)), newArgsHash, sideEffectCounter, isStaticCall);
327
+ return newArgsHash;
328
+ }
329
+ /**
330
+ * Creates a PublicExecutionRequest and sets it as the public teardown function. No function
331
+ * is actually called, since that must happen on the sequencer side. All the fields related to the result
332
+ * of the execution are empty.
333
+ * @param targetContractAddress - The address of the contract to call.
334
+ * @param functionSelector - The function selector of the function to call.
335
+ * @param argsHash - The arguments hash to pass to the function.
336
+ * @param sideEffectCounter - The side effect counter at the start of the call.
337
+ * @param isStaticCall - Whether the call is a static call.
338
+ * @returns The public call stack item with the request information.
339
+ */ async setPublicTeardownFunctionCall(targetContractAddress, functionSelector, argsHash, sideEffectCounter, isStaticCall) {
340
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
341
+ // WARNING: This is insecure and should be temporary!
342
+ // The oracle rehashes the arguments and returns a new args_hash.
343
+ // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
344
+ // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
345
+ // b) this is only temporary.
346
+ const newArgsHash = await this.executionCache.store([
347
+ functionSelector.toField(),
348
+ ...this.executionCache.getPreimage(argsHash)
349
+ ]);
350
+ await this.createPublicExecutionRequest('teardown', targetContractAddress, FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)), newArgsHash, sideEffectCounter, isStaticCall);
351
+ return newArgsHash;
352
+ }
353
+ notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter) {
354
+ return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
355
+ }
356
+ /**
357
+ * Derives the call context for a nested execution.
358
+ * @param targetContractAddress - The address of the contract being called.
359
+ * @param targetArtifact - The artifact of the function being called.
360
+ * @param isStaticCall - Whether the call is a static call.
361
+ * @returns The derived call context.
362
+ */ async deriveCallContext(targetContractAddress, targetArtifact, isStaticCall = false) {
363
+ return new CallContext(this.contractAddress, targetContractAddress, await FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters), isStaticCall);
364
+ }
365
+ getDebugFunctionName() {
366
+ return this.db.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
367
+ }
368
+ async incrementAppTaggingSecretIndexAsSender(sender, recipient) {
369
+ await this.db.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
370
+ }
371
+ async syncNotes() {
372
+ const taggedLogsByRecipient = await this.db.syncTaggedLogs(this.contractAddress, this.historicalHeader.globalVariables.blockNumber.toNumber(), this.scopes);
373
+ for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()){
374
+ await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
375
+ }
376
+ await this.db.removeNullifiedNotes(this.contractAddress);
377
+ }
378
+ }
@@ -1,10 +1,15 @@
1
- import { type L2Block, type MerkleTreeId, type NoteStatus, type NullifierMembershipWitness, type PublicDataWitness, type TxScopedL2Log } from '@aztec/circuit-types';
2
- import { type BlockHeader, type CompleteAddress, type ContractInstance, type IndexedTaggingSecret, type KeyValidationRequest } from '@aztec/circuits.js';
3
- import { type FunctionArtifact, type FunctionSelector } from '@aztec/foundation/abi';
4
- import { type AztecAddress } from '@aztec/foundation/aztec-address';
5
- import { type Fr } from '@aztec/foundation/fields';
6
- import { type NoteData } from '../acvm/index.js';
7
- import { type CommitmentsDB } from '../public/db_interfaces.js';
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { FunctionArtifact, FunctionSelector } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { L2Block } from '@aztec/stdlib/block';
5
+ import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
6
+ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
7
+ import { IndexedTaggingSecret, LogWithTxData, TxScopedL2Log } from '@aztec/stdlib/logs';
8
+ import type { NoteStatus } from '@aztec/stdlib/note';
9
+ import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
10
+ import type { BlockHeader } from '@aztec/stdlib/tx';
11
+ import type { CommitmentsDB } from '../common/db_interfaces.js';
12
+ import type { NoteData } from './acvm/index.js';
8
13
  /**
9
14
  * Error thrown when a contract is not found in the database.
10
15
  */
@@ -182,6 +187,13 @@ export interface DBOracle extends CommitmentsDB {
182
187
  * @param recipient - The account that discovered the note
183
188
  */
184
189
  deliverNote(contractAddress: AztecAddress, storageSlot: Fr, nonce: Fr, content: Fr[], noteHash: Fr, nullifier: Fr, txHash: Fr, recipient: AztecAddress): Promise<void>;
190
+ /**
191
+ * Searches for a log with the corresponding `tag` and returns it along with contextual transaction information.
192
+ * Returns null if no such log exists, and throws if more than one exists.
193
+ *
194
+ * @param tag - The log tag to search for.
195
+ */
196
+ getLogByTag(tag: Fr): Promise<LogWithTxData | null>;
185
197
  /**
186
198
  * Removes all of a contract's notes that have been nullified from the note database.
187
199
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db_oracle.d.ts","sourceRoot":"","sources":["../../src/private/db_oracle.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Error thrown when a contract is not found in the database.
3
+ */ export class ContractNotFoundError extends Error {
4
+ constructor(contractAddress){
5
+ super(`DB has no contract with address ${contractAddress}`);
6
+ }
7
+ }
8
+ /**
9
+ * Error thrown when a contract class is not found in the database.
10
+ */ export class ContractClassNotFoundError extends Error {
11
+ constructor(contractClassId){
12
+ super(`DB has no contract class with id ${contractClassId}`);
13
+ }
14
+ }
@@ -1,6 +1,6 @@
1
- import { type AztecAddress } from '@aztec/foundation/aztec-address';
2
1
  import { Fr } from '@aztec/foundation/fields';
3
- import { type NoteData } from '../acvm/index.js';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { NoteData } from './acvm/index.js';
4
4
  interface PendingNote {
5
5
  note: NoteData;
6
6
  counter: number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution_note_cache.d.ts","sourceRoot":"","sources":["../../src/private/execution_note_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,UAAU,WAAW;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,EAAE,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,kBAAkB;;IAiCjB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAhC1C;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAqB;IAClC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAyC;IAExD;;;;OAIG;IACH,OAAO,CAAC,YAAY,CAAuC;IAE3D;;OAEG;IACH,OAAO,CAAC,aAAa,CAA0B;IAE/C,OAAO,CAAC,8BAA8B,CAAK;IAE3C,OAAO,CAAC,iBAAiB,CAAS;IAElC;;;OAGG;IACH,OAAO,CAAC,0BAA0B,CAAQ;gBAEb,aAAa,EAAE,EAAE;IAE9C;;;OAGG;IACU,iCAAiC,CAAC,8BAA8B,EAAE,MAAM;IAwC9E,MAAM;;;IAWb;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM;IAWjD;;;;;;OAMG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;IA2BxF;;;;OAIG;IACU,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE;IAK/E;;;;;QAKI;IACG,QAAQ,CAAC,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE;IAK9D;;;;;QAKI;IACG,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE;IAKlE;;;OAGG;IACI,aAAa,CAAC,eAAe,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC;IAYhE,WAAW,IAAI,WAAW,EAAE;IAI5B,gBAAgB,IAAI,EAAE,EAAE;IAIxB,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE;CAMnE"}
@@ -0,0 +1,180 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
3
+ /**
4
+ * Data that's accessible by all the function calls in an execution.
5
+ */ export class ExecutionNoteCache {
6
+ txRequestHash;
7
+ /**
8
+ * New notes created in this transaction.
9
+ * They are pushed to this array in the same order as they are emitted.
10
+ */ notes;
11
+ /**
12
+ * This mapping maps from a contract address to the notes in the contract.
13
+ */ noteMap;
14
+ /**
15
+ * This maps from a contract address to the nullifiers emitted from the contract.
16
+ * The note which is nullified might be new or not (i.e., was generated in a previous transaction).
17
+ * Note that their value (bigint representation) is used because Frs cannot be looked up in Sets.
18
+ */ nullifierMap;
19
+ /**
20
+ * All nullifiers emitted in this transaction.
21
+ */ allNullifiers;
22
+ minRevertibleSideEffectCounter;
23
+ inRevertiblePhase;
24
+ /**
25
+ * We don't need to use the tx request hash for nonces if another non revertible nullifier is emitted.
26
+ * In that case we disable injecting the tx request hash as a nullifier.
27
+ */ usedTxRequestHashForNonces;
28
+ constructor(txRequestHash){
29
+ this.txRequestHash = txRequestHash;
30
+ this.notes = [];
31
+ this.noteMap = new Map();
32
+ this.nullifierMap = new Map();
33
+ this.allNullifiers = new Set();
34
+ this.minRevertibleSideEffectCounter = 0;
35
+ this.inRevertiblePhase = false;
36
+ this.usedTxRequestHashForNonces = true;
37
+ }
38
+ /**
39
+ * Enters the revertible phase of the transaction.
40
+ * @param minRevertibleSideEffectCounter - The counter at which the transaction enters the revertible phase.
41
+ */ async setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter) {
42
+ if (this.inRevertiblePhase) {
43
+ throw new Error(`Cannot enter the revertible phase twice. Current counter: ${minRevertibleSideEffectCounter}. Previous enter counter: ${this.minRevertibleSideEffectCounter}`);
44
+ }
45
+ this.inRevertiblePhase = true;
46
+ this.minRevertibleSideEffectCounter = minRevertibleSideEffectCounter;
47
+ let nonceGenerator = this.txRequestHash;
48
+ const nullifiers = this.getAllNullifiers();
49
+ if (nullifiers.length > 0) {
50
+ nonceGenerator = new Fr(nullifiers[0]);
51
+ this.usedTxRequestHashForNonces = false;
52
+ }
53
+ // The existing pending notes are all non-revertible.
54
+ // They cannot be squashed by nullifiers emitted after minRevertibleSideEffectCounter is set.
55
+ // Their indexes in the tx are known at this point and won't change. So we can assign a nonce to each one of them.
56
+ // The nonces will be used to create the "complete" nullifier.
57
+ const updatedNotes = await Promise.all(this.notes.map(async ({ note, counter }, i)=>{
58
+ const nonce = await computeNoteHashNonce(nonceGenerator, i);
59
+ const uniqueNoteHash = await computeUniqueNoteHash(nonce, await siloNoteHash(note.contractAddress, note.noteHash));
60
+ return {
61
+ counter,
62
+ note: {
63
+ ...note,
64
+ nonce
65
+ },
66
+ noteHashForConsumption: uniqueNoteHash
67
+ };
68
+ }));
69
+ // Rebuild the data.
70
+ this.notes = [];
71
+ this.noteMap = new Map();
72
+ updatedNotes.forEach((n)=>this.#addNote(n));
73
+ }
74
+ finish() {
75
+ // If we never entered the revertible phase, we need to use the tx request hash as a nonce for the notes if no nullifiers have been emitted.
76
+ if (!this.inRevertiblePhase) {
77
+ this.usedTxRequestHashForNonces = this.getAllNullifiers().length === 0;
78
+ }
79
+ // If we entered the revertible phase, the nonce generator was decided based on wether or not a nullifier was emitted before entering.
80
+ return {
81
+ usedTxRequestHashForNonces: this.usedTxRequestHashForNonces
82
+ };
83
+ }
84
+ /**
85
+ * Add a new note to cache.
86
+ * @param note - New note created during execution.
87
+ */ addNewNote(note, counter) {
88
+ const previousNote = this.notes[this.notes.length - 1];
89
+ if (previousNote && previousNote.counter >= counter) {
90
+ throw new Error(`Note hash counters must be strictly increasing. Current counter: ${counter}. Previous counter: ${previousNote.counter}.`);
91
+ }
92
+ this.#addNote({
93
+ note,
94
+ counter,
95
+ noteHashForConsumption: note.noteHash
96
+ });
97
+ }
98
+ /**
99
+ * Add a nullifier to cache. It could be for a db note or a new note created during execution.
100
+ * @param contractAddress - Contract address of the note.
101
+ * @param innerNullifier - Inner nullifier of the note.
102
+ * @param noteHash - A hash of the note. If this value equals 0, it means the note being nullified is from a previous
103
+ * transaction (and thus not a new note).
104
+ */ async nullifyNote(contractAddress, innerNullifier, noteHash) {
105
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
106
+ let nullifiedNoteHashCounter = undefined;
107
+ // Find and remove the matching new note and log(s) if the emitted noteHash is not empty.
108
+ if (!noteHash.isEmpty()) {
109
+ const notesInContract = this.noteMap.get(contractAddress.toBigInt()) ?? [];
110
+ const noteIndexToRemove = notesInContract.findIndex((n)=>n.noteHashForConsumption.equals(noteHash));
111
+ if (noteIndexToRemove === -1) {
112
+ throw new Error('Attempt to remove a pending note that does not exist.');
113
+ }
114
+ const note = notesInContract.splice(noteIndexToRemove, 1)[0];
115
+ nullifiedNoteHashCounter = note.counter;
116
+ this.noteMap.set(contractAddress.toBigInt(), notesInContract);
117
+ this.notes = this.notes.filter((n)=>n.counter !== note.counter);
118
+ // If the note is non revertible and the nullifier was emitted in the revertible phase, both the note hash and the nullifier will be emitted
119
+ if (this.inRevertiblePhase && note.counter < this.minRevertibleSideEffectCounter) {
120
+ this.recordNullifier(contractAddress, siloedNullifier);
121
+ }
122
+ } else {
123
+ // If the note being nullified comes from a previous tx the nullifier will be emitted.
124
+ this.recordNullifier(contractAddress, siloedNullifier);
125
+ }
126
+ return nullifiedNoteHashCounter;
127
+ }
128
+ /**
129
+ * Adds a nullifier to the cache. Note cache needs to track all nullifiers to decide which nullifier to use for note siloing.
130
+ * @param contractAddress - Contract address that emitted the nullifier.
131
+ * @param innerNullifier
132
+ */ async nullifierCreated(contractAddress, innerNullifier) {
133
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
134
+ this.recordNullifier(contractAddress, siloedNullifier);
135
+ }
136
+ /**
137
+ * Return notes created up to current point in execution.
138
+ * If a nullifier for a note in this list is emitted, the note will be deleted.
139
+ * @param contractAddress - Contract address of the notes.
140
+ * @param storageSlot - Storage slot of the notes.
141
+ **/ getNotes(contractAddress, storageSlot) {
142
+ const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
143
+ return notes.filter((n)=>n.note.storageSlot.equals(storageSlot)).map((n)=>n.note);
144
+ }
145
+ /**
146
+ * Check if a note exists in the newNotes array.
147
+ * @param contractAddress - Contract address of the note.
148
+ * @param storageSlot - Storage slot of the note.
149
+ * @param noteHash - A hash of the note.
150
+ **/ checkNoteExists(contractAddress, noteHash) {
151
+ const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
152
+ return notes.some((n)=>n.note.noteHash.equals(noteHash));
153
+ }
154
+ /**
155
+ * Return all nullifiers emitted from a contract.
156
+ * @param contractAddress - Address of the contract.
157
+ */ getNullifiers(contractAddress) {
158
+ return this.nullifierMap.get(contractAddress.toBigInt()) ?? new Set();
159
+ }
160
+ #addNote(note) {
161
+ this.notes.push(note);
162
+ const notes = this.noteMap.get(note.note.contractAddress.toBigInt()) ?? [];
163
+ notes.push(note);
164
+ this.noteMap.set(note.note.contractAddress.toBigInt(), notes);
165
+ }
166
+ getAllNotes() {
167
+ return this.notes;
168
+ }
169
+ getAllNullifiers() {
170
+ return [
171
+ ...this.allNullifiers
172
+ ].map((n)=>new Fr(n));
173
+ }
174
+ recordNullifier(contractAddress, siloedNullifier) {
175
+ const nullifiers = this.getNullifiers(contractAddress);
176
+ nullifiers.add(siloedNullifier.toBigInt());
177
+ this.nullifierMap.set(contractAddress.toBigInt(), nullifiers);
178
+ this.allNullifiers.add(siloedNullifier.toBigInt());
179
+ }
180
+ }
@@ -1,5 +1,5 @@
1
- import { HashedValues } from '@aztec/circuit-types';
2
- import { Fr } from '@aztec/circuits.js';
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { HashedValues } from '@aztec/stdlib/tx';
3
3
  /**
4
4
  * A cache for hashed values (arguments, returns) during transaction execution.
5
5
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashed_values_cache.d.ts","sourceRoot":"","sources":["../../src/private/hashed_values_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAoB;gBAErB,gBAAgB,GAAE,YAAY,EAAO;IAOjD;;;;OAIG;WACW,MAAM,CAAC,gBAAgB,GAAE,YAAY,EAAO;IAI1D;;;;OAIG;IACI,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;IAWlC;;;;OAIG;IACU,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE;CAQhC"}