@aztec/simulator 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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 (405) hide show
  1. package/README.md +6 -4
  2. package/dest/client.d.ts +1 -3
  3. package/dest/client.d.ts.map +1 -1
  4. package/dest/client.js +0 -2
  5. package/dest/common/errors.d.ts +2 -2
  6. package/dest/common/errors.d.ts.map +1 -1
  7. package/dest/common/index.d.ts +1 -1
  8. package/dest/common/stats/index.d.ts +1 -1
  9. package/dest/common/stats/stats.d.ts +1 -1
  10. package/dest/private/acvm/acvm.d.ts +4 -2
  11. package/dest/private/acvm/acvm.d.ts.map +1 -1
  12. package/dest/private/acvm/acvm.js +4 -3
  13. package/dest/private/acvm/acvm_types.d.ts +1 -1
  14. package/dest/private/acvm/deserialize.d.ts +2 -2
  15. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  16. package/dest/private/acvm/deserialize.js +1 -1
  17. package/dest/private/acvm/index.d.ts +1 -1
  18. package/dest/private/acvm/serialize.d.ts +2 -2
  19. package/dest/private/acvm/serialize.d.ts.map +1 -1
  20. package/dest/private/acvm/serialize.js +1 -1
  21. package/dest/private/acvm_native.d.ts +5 -3
  22. package/dest/private/acvm_native.d.ts.map +1 -1
  23. package/dest/private/acvm_native.js +8 -6
  24. package/dest/private/acvm_wasm.d.ts +4 -3
  25. package/dest/private/acvm_wasm.d.ts.map +1 -1
  26. package/dest/private/acvm_wasm.js +7 -5
  27. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  28. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  29. package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
  30. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  31. package/dest/private/circuit_recording/circuit_recorder.js +71 -72
  32. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
  33. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  34. package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
  35. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  36. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  37. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  38. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  39. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  40. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  41. package/dest/private/circuit_simulator.d.ts +1 -1
  42. package/dest/private/factory.d.ts +3 -3
  43. package/dest/private/factory.d.ts.map +1 -1
  44. package/dest/private/factory.js +7 -4
  45. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  46. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  47. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  48. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
  49. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  50. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +19 -4
  51. package/dest/public/avm/{fixtures → testing}/utils.d.ts +4 -10
  52. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  53. package/dest/public/avm/{fixtures → testing}/utils.js +7 -36
  54. package/dest/public/avm_simulator.d.ts +28 -0
  55. package/dest/public/avm_simulator.d.ts.map +1 -0
  56. package/dest/public/avm_simulator.js +4 -0
  57. package/dest/public/avm_simulator_pool.d.ts +45 -0
  58. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  59. package/dest/public/avm_simulator_pool.js +197 -0
  60. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  61. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  62. package/dest/public/cdb/generated/api_types.js +314 -0
  63. package/dest/public/cdb/generated/server.d.ts +26 -0
  64. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  65. package/dest/public/cdb/generated/server.js +135 -0
  66. package/dest/public/cdb_ipc_server.d.ts +33 -0
  67. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  68. package/dest/public/cdb_ipc_server.js +153 -0
  69. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  70. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  71. package/dest/public/contracts_db_checkpoint.js +30 -0
  72. package/dest/public/db_interfaces.d.ts +14 -2
  73. package/dest/public/db_interfaces.d.ts.map +1 -1
  74. package/dest/public/executor_metrics.d.ts +3 -2
  75. package/dest/public/executor_metrics.d.ts.map +1 -1
  76. package/dest/public/executor_metrics.js +13 -34
  77. package/dest/public/executor_metrics_interface.d.ts +3 -2
  78. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  79. package/dest/public/fixtures/amm_test.d.ts +1 -1
  80. package/dest/public/fixtures/amm_test.js +6 -6
  81. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  82. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  83. package/dest/public/fixtures/bulk_test.js +38 -75
  84. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  85. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  86. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  87. package/dest/public/fixtures/index.d.ts +3 -3
  88. package/dest/public/fixtures/index.d.ts.map +1 -1
  89. package/dest/public/fixtures/index.js +2 -2
  90. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  91. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  92. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  93. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +32 -9
  94. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  95. package/dest/public/fixtures/public_tx_simulation_tester.js +84 -26
  96. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  97. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  98. package/dest/public/fixtures/simple_contract_data_source.js +5 -5
  99. package/dest/public/fixtures/token_test.d.ts +6 -2
  100. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  101. package/dest/public/fixtures/token_test.js +16 -15
  102. package/dest/public/fixtures/utils.d.ts +3 -3
  103. package/dest/public/fixtures/utils.d.ts.map +1 -1
  104. package/dest/public/fixtures/utils.js +25 -23
  105. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +67 -0
  106. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  107. package/dest/public/fuzzing/avm_fuzzer_simulator.js +185 -0
  108. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  109. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  110. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  111. package/dest/public/index.d.ts +6 -2
  112. package/dest/public/index.d.ts.map +1 -1
  113. package/dest/public/index.js +2 -1
  114. package/dest/public/public_db_sources.d.ts +29 -66
  115. package/dest/public/public_db_sources.d.ts.map +1 -1
  116. package/dest/public/public_db_sources.js +83 -134
  117. package/dest/public/public_errors.d.ts +1 -1
  118. package/dest/public/public_errors.d.ts.map +1 -1
  119. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -5
  120. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  121. package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
  122. package/dest/public/public_processor/public_processor.d.ts +24 -22
  123. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  124. package/dest/public/public_processor/public_processor.js +559 -125
  125. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  126. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  127. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  128. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  129. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  130. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +39 -0
  131. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  132. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  133. package/dest/public/public_tx_simulator/factories.js +28 -0
  134. package/dest/public/public_tx_simulator/index.d.ts +6 -4
  135. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  136. package/dest/public/public_tx_simulator/index.js +3 -2
  137. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +43 -90
  138. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  139. package/dest/public/public_tx_simulator/public_tx_simulator.js +99 -331
  140. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  141. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  142. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  143. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  144. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  145. package/dest/public/side_effect_errors.d.ts +1 -1
  146. package/dest/public/side_effect_errors.d.ts.map +1 -1
  147. package/dest/public/test_executor_metrics.d.ts +6 -4
  148. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  149. package/dest/public/test_executor_metrics.js +7 -6
  150. package/dest/public/unique_class_ids.d.ts +1 -1
  151. package/dest/public/unique_class_ids.d.ts.map +1 -1
  152. package/dest/public/utils.d.ts +1 -1
  153. package/dest/server.d.ts +1 -1
  154. package/dest/testing.d.ts +1 -1
  155. package/package.json +26 -22
  156. package/src/client.ts +0 -2
  157. package/src/common/errors.ts +1 -1
  158. package/src/private/acvm/acvm.ts +4 -3
  159. package/src/private/acvm/deserialize.ts +1 -1
  160. package/src/private/acvm/serialize.ts +1 -1
  161. package/src/private/acvm_native.ts +11 -5
  162. package/src/private/acvm_wasm.ts +11 -4
  163. package/src/private/circuit_recording/circuit_recorder.ts +90 -81
  164. package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
  165. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  166. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  167. package/src/private/factory.ts +7 -4
  168. package/src/public/avm/testing/account_proof.json +553 -0
  169. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  170. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +24 -4
  171. package/src/public/avm/{fixtures → testing}/utils.ts +7 -42
  172. package/src/public/avm_simulator.ts +29 -0
  173. package/src/public/avm_simulator_pool.ts +226 -0
  174. package/src/public/cdb/generated/api_types.ts +457 -0
  175. package/src/public/cdb/generated/server.ts +109 -0
  176. package/src/public/cdb_ipc_server.ts +197 -0
  177. package/src/public/contracts_db_checkpoint.ts +41 -0
  178. package/src/public/db_interfaces.ts +16 -1
  179. package/src/public/executor_metrics.ts +11 -34
  180. package/src/public/executor_metrics_interface.ts +2 -1
  181. package/src/public/fixtures/amm_test.ts +6 -6
  182. package/src/public/fixtures/bulk_test.ts +40 -15
  183. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  184. package/src/public/fixtures/index.ts +6 -2
  185. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  186. package/src/public/fixtures/public_tx_simulation_tester.ts +117 -26
  187. package/src/public/fixtures/simple_contract_data_source.ts +9 -10
  188. package/src/public/fixtures/token_test.ts +21 -13
  189. package/src/public/fixtures/utils.ts +25 -27
  190. package/src/public/fuzzing/avm_fuzzer_simulator.ts +303 -0
  191. package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
  192. package/src/public/index.ts +8 -2
  193. package/src/public/public_db_sources.ts +112 -174
  194. package/src/public/public_processor/guarded_merkle_tree.ts +14 -6
  195. package/src/public/public_processor/public_processor.ts +234 -138
  196. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  197. package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +67 -0
  198. package/src/public/public_tx_simulator/factories.ts +61 -0
  199. package/src/public/public_tx_simulator/index.ts +8 -3
  200. package/src/public/public_tx_simulator/public_tx_simulator.ts +142 -500
  201. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  202. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  203. package/src/public/test_executor_metrics.ts +10 -8
  204. package/dest/public/avm/avm_context.d.ts +0 -41
  205. package/dest/public/avm/avm_context.d.ts.map +0 -1
  206. package/dest/public/avm/avm_context.js +0 -44
  207. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  208. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  209. package/dest/public/avm/avm_contract_call_result.js +0 -54
  210. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  211. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  212. package/dest/public/avm/avm_execution_environment.js +0 -36
  213. package/dest/public/avm/avm_gas.d.ts +0 -44
  214. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  215. package/dest/public/avm/avm_gas.js +0 -195
  216. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  217. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  218. package/dest/public/avm/avm_machine_state.js +0 -109
  219. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  220. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  221. package/dest/public/avm/avm_memory_types.js +0 -351
  222. package/dest/public/avm/avm_simulator.d.ts +0 -39
  223. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  224. package/dest/public/avm/avm_simulator.js +0 -190
  225. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  226. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  227. package/dest/public/avm/avm_simulator_interface.js +0 -3
  228. package/dest/public/avm/errors.d.ts +0 -98
  229. package/dest/public/avm/errors.d.ts.map +0 -1
  230. package/dest/public/avm/errors.js +0 -129
  231. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  232. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  233. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -74
  234. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  235. package/dest/public/avm/fixtures/initializers.d.ts +0 -43
  236. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  237. package/dest/public/avm/fixtures/initializers.js +0 -42
  238. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  239. package/dest/public/avm/index.d.ts +0 -2
  240. package/dest/public/avm/index.d.ts.map +0 -1
  241. package/dest/public/avm/index.js +0 -1
  242. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  243. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  244. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  245. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  246. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  247. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  248. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
  249. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  250. package/dest/public/avm/opcodes/arithmetic.js +0 -87
  251. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  252. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  253. package/dest/public/avm/opcodes/bitwise.js +0 -99
  254. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  255. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  256. package/dest/public/avm/opcodes/comparators.js +0 -43
  257. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  258. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  259. package/dest/public/avm/opcodes/contract.js +0 -65
  260. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  261. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  262. package/dest/public/avm/opcodes/control_flow.js +0 -107
  263. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  264. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  265. package/dest/public/avm/opcodes/conversion.js +0 -333
  266. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  267. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  268. package/dest/public/avm/opcodes/ec_add.js +0 -84
  269. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  270. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  271. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  272. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  273. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  274. package/dest/public/avm/opcodes/external_calls.js +0 -209
  275. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  276. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  277. package/dest/public/avm/opcodes/hashing.js +0 -114
  278. package/dest/public/avm/opcodes/index.d.ts +0 -16
  279. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  280. package/dest/public/avm/opcodes/index.js +0 -15
  281. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  282. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  283. package/dest/public/avm/opcodes/instruction.js +0 -95
  284. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  285. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  286. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  287. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  288. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  289. package/dest/public/avm/opcodes/memory.js +0 -257
  290. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  291. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  292. package/dest/public/avm/opcodes/misc.js +0 -73
  293. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  294. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  295. package/dest/public/avm/opcodes/storage.js +0 -68
  296. package/dest/public/avm/revert_reason.d.ts +0 -18
  297. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  298. package/dest/public/avm/revert_reason.js +0 -38
  299. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  300. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  301. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  302. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  303. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  304. package/dest/public/avm/serialization/bytecode_serialization.js +0 -333
  305. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  306. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  307. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  308. package/dest/public/avm/test_utils.d.ts +0 -15
  309. package/dest/public/avm/test_utils.d.ts.map +0 -1
  310. package/dest/public/avm/test_utils.js +0 -44
  311. package/dest/public/debug_fn_name.d.ts +0 -5
  312. package/dest/public/debug_fn_name.d.ts.map +0 -1
  313. package/dest/public/debug_fn_name.js +0 -9
  314. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
  315. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  316. package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
  317. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -10
  318. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  319. package/dest/public/fixtures/minimal_public_tx.js +0 -29
  320. package/dest/public/hinting_db_sources.d.ts +0 -70
  321. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  322. package/dest/public/hinting_db_sources.js +0 -297
  323. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -41
  324. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  325. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -89
  326. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -24
  327. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  328. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  329. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -127
  330. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  331. package/dest/public/public_tx_simulator/public_tx_context.js +0 -292
  332. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  333. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  334. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
  335. package/dest/public/side_effect_trace.d.ts +0 -87
  336. package/dest/public/side_effect_trace.d.ts.map +0 -1
  337. package/dest/public/side_effect_trace.js +0 -199
  338. package/dest/public/side_effect_trace_interface.d.ts +0 -23
  339. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  340. package/dest/public/side_effect_trace_interface.js +0 -1
  341. package/dest/public/state_manager/index.d.ts +0 -2
  342. package/dest/public/state_manager/index.d.ts.map +0 -1
  343. package/dest/public/state_manager/index.js +0 -1
  344. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  345. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  346. package/dest/public/state_manager/nullifiers.js +0 -92
  347. package/dest/public/state_manager/public_storage.d.ts +0 -66
  348. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  349. package/dest/public/state_manager/public_storage.js +0 -145
  350. package/dest/public/state_manager/state_manager.d.ts +0 -166
  351. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  352. package/dest/public/state_manager/state_manager.js +0 -391
  353. package/dest/public/tx_contract_cache.d.ts +0 -41
  354. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  355. package/dest/public/tx_contract_cache.js +0 -49
  356. package/src/public/avm/avm_context.ts +0 -61
  357. package/src/public/avm/avm_contract_call_result.ts +0 -67
  358. package/src/public/avm/avm_execution_environment.ts +0 -48
  359. package/src/public/avm/avm_gas.ts +0 -183
  360. package/src/public/avm/avm_machine_state.ts +0 -169
  361. package/src/public/avm/avm_memory_types.ts +0 -436
  362. package/src/public/avm/avm_simulator.ts +0 -274
  363. package/src/public/avm/avm_simulator_interface.ts +0 -8
  364. package/src/public/avm/errors.ts +0 -163
  365. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -108
  366. package/src/public/avm/fixtures/initializers.ts +0 -104
  367. package/src/public/avm/index.ts +0 -1
  368. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  369. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  370. package/src/public/avm/opcodes/arithmetic.ts +0 -117
  371. package/src/public/avm/opcodes/bitwise.ts +0 -113
  372. package/src/public/avm/opcodes/comparators.ts +0 -55
  373. package/src/public/avm/opcodes/contract.ts +0 -75
  374. package/src/public/avm/opcodes/control_flow.ts +0 -123
  375. package/src/public/avm/opcodes/conversion.ts +0 -104
  376. package/src/public/avm/opcodes/ec_add.ts +0 -96
  377. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  378. package/src/public/avm/opcodes/external_calls.ts +0 -260
  379. package/src/public/avm/opcodes/hashing.ts +0 -145
  380. package/src/public/avm/opcodes/index.ts +0 -15
  381. package/src/public/avm/opcodes/instruction.ts +0 -136
  382. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  383. package/src/public/avm/opcodes/memory.ts +0 -293
  384. package/src/public/avm/opcodes/misc.ts +0 -102
  385. package/src/public/avm/opcodes/storage.ts +0 -87
  386. package/src/public/avm/revert_reason.ts +0 -55
  387. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  388. package/src/public/avm/serialization/bytecode_serialization.ts +0 -204
  389. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  390. package/src/public/avm/test_utils.ts +0 -64
  391. package/src/public/debug_fn_name.ts +0 -18
  392. package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
  393. package/src/public/fixtures/minimal_public_tx.ts +0 -36
  394. package/src/public/hinting_db_sources.ts +0 -505
  395. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -128
  396. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -109
  397. package/src/public/public_tx_simulator/public_tx_context.ts +0 -471
  398. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  399. package/src/public/side_effect_trace.ts +0 -290
  400. package/src/public/side_effect_trace_interface.ts +0 -28
  401. package/src/public/state_manager/index.ts +0 -1
  402. package/src/public/state_manager/nullifiers.ts +0 -103
  403. package/src/public/state_manager/public_storage.ts +0 -174
  404. package/src/public/state_manager/state_manager.ts +0 -560
  405. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,18 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import { FunctionSelector } from '@aztec/stdlib/abi';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
-
5
- import type { PublicContractsDBInterface } from './db_interfaces.js';
6
-
7
- export async function getPublicFunctionDebugName(
8
- db: PublicContractsDBInterface,
9
- contractAddress: AztecAddress,
10
- calldata: Fr[],
11
- ): Promise<string> {
12
- // Public function is dispatched and therefore the target function is passed in the first argument.
13
- if (!calldata[0]) {
14
- return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
- }
16
- const selector = FunctionSelector.fromField(calldata[0]);
17
- return (await db.getDebugFunctionName(contractAddress, selector)) ?? selector.toString();
18
- }
@@ -1,135 +0,0 @@
1
- import { strict as assert } from 'assert';
2
-
3
- import { TypeTag } from '../avm/avm_memory_types.js';
4
- import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
5
- import { CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
6
- import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
7
- import {
8
- MAX_OPCODE_VALUE,
9
- Opcode,
10
- OperandType,
11
- getOperandSize,
12
- } from '../avm/serialization/instruction_serialization.js';
13
- import { testCustomBytecode } from './custom_bytecode_tester.js';
14
- import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
15
-
16
- // First instruction resolved a base address (offset 0) which is uninitialized and therefore
17
- // of invalid tag (FF). This will trigger an exceptional halt.
18
- export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester: PublicTxSimulationTester) {
19
- const addressingMode = Addressing.fromModes([
20
- isIndirect ? AddressingMode.INDIRECT_RELATIVE : AddressingMode.RELATIVE,
21
- AddressingMode.DIRECT,
22
- AddressingMode.DIRECT,
23
- ]);
24
-
25
- const bytecode = encodeToBytecode([
26
- new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 0),
27
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
28
- ]);
29
-
30
- const txLabel = isIndirect ? 'AddressingWithBaseTagInvalidIndirect' : 'AddressingWithBaseTagInvalidDirect';
31
- return await testCustomBytecode(bytecode, tester, txLabel);
32
- }
33
-
34
- export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
35
- const bytecode = encodeToBytecode([
36
- new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
37
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
38
- ]);
39
-
40
- const txLabel = 'PcOutOfRange';
41
- return await testCustomBytecode(bytecode, tester, txLabel);
42
- }
43
-
44
- export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
45
- let bytecode = encodeToBytecode([
46
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
47
- ]);
48
-
49
- const offsetReturnOpcodeByte = bytecode.length;
50
-
51
- bytecode = Buffer.concat([
52
- bytecode,
53
- encodeToBytecode([new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
54
- ]);
55
-
56
- // Manipulate the Return opcode to make the opcode invalid (out of range).
57
- bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
58
-
59
- const txLabel = 'InvalidOpcode';
60
- return await testCustomBytecode(bytecode, tester, txLabel);
61
- }
62
-
63
- // Single invalid byte in the bytecode.
64
- export async function invalidByteTest(tester: PublicTxSimulationTester) {
65
- const invalidOpcode = MAX_OPCODE_VALUE + 7;
66
- assert(invalidOpcode < 256, 'Invalid opcode must fit in a single byte');
67
- const bytecode = Buffer.from([invalidOpcode]);
68
-
69
- const txLabel = 'InvalidByte';
70
- return await testCustomBytecode(bytecode, tester, txLabel);
71
- }
72
-
73
- // Truncate the last instruction in the bytecode.
74
- export async function instructionTruncatedTest(tester: PublicTxSimulationTester) {
75
- let bytecode = encodeToBytecode([
76
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
77
- ]);
78
-
79
- // Truncate the bytecode.
80
- bytecode = bytecode.subarray(0, -1);
81
-
82
- const txLabel = 'InstructionTruncated';
83
- return await testCustomBytecode(bytecode, tester, txLabel);
84
- }
85
-
86
- // Invalid tag value byte in an instruction.
87
- export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
88
- const bytecode = encodeToBytecode([
89
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
90
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
91
- ]);
92
-
93
- const tagOffset = getTagOffsetInInstruction(Set.wireFormat8);
94
- assert(bytecode[tagOffset].valueOf() == TypeTag.UINT32.valueOf(), 'Set instruction tag should be UINT32 in test');
95
- bytecode[tagOffset] = TypeTag.INVALID;
96
-
97
- const txLabel = 'InvalidTagValue';
98
- return await testCustomBytecode(bytecode, tester, txLabel);
99
- }
100
-
101
- // Combine an invalid tag in the last instruction that is truncated.
102
- export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicTxSimulationTester) {
103
- let bytecode = encodeToBytecode([
104
- // Important: value argument must be a bigint otherwise a type error will be thrown.
105
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT128, /*value=*/ 0n).as(Opcode.SET_128, Set.wireFormat128),
106
- ]);
107
-
108
- // Truncate the bytecode.
109
- bytecode = bytecode.subarray(0, -5);
110
- const tagOffset = getTagOffsetInInstruction(Set.wireFormat128);
111
- assert(bytecode[tagOffset].valueOf() == TypeTag.UINT128.valueOf(), 'Set instruction tag should be UINT128 in test');
112
- bytecode[tagOffset] = 0x6f; // Invalid tag value.
113
-
114
- const txLabel = 'InvalidTagValueAndInstructionTruncated';
115
- return await testCustomBytecode(bytecode, tester, txLabel);
116
- }
117
-
118
- /**
119
- * Returns the offset of the tag in an instruction.
120
- * @details Loops over the wire format operand type entries until it finds the tag.
121
- * Returns the byte offset of the tag based on each operand size that is passed.
122
- *
123
- * @param wireFormat array of operand types
124
- * @returns byte offset of the tag
125
- */
126
- function getTagOffsetInInstruction(wireFormat: OperandType[]): number {
127
- let offset = 0;
128
- for (const operand of wireFormat) {
129
- if (operand === OperandType.TAG) {
130
- break;
131
- }
132
- offset += getOperandSize(operand);
133
- }
134
- return offset;
135
- }
@@ -1,36 +0,0 @@
1
- import { AvmCircuitInputs } from '@aztec/stdlib/avm';
2
- import { ProtocolContracts } from '@aztec/stdlib/tx';
3
-
4
- import avmMinimalCircuitInputsJson from '../../../artifacts/avm_minimal_inputs.json' with { type: 'json' };
5
- import { TypeTag } from '../avm/avm_memory_types.js';
6
- import { Add, Return, Set } from '../avm/opcodes/index.js';
7
- import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
8
- import { Opcode } from '../avm/serialization/instruction_serialization.js';
9
- import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
10
- import { testCustomBytecode } from './custom_bytecode_tester.js';
11
- import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
12
-
13
- export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester): Promise<PublicTxResult> {
14
- const minimalBytecode = encodeToBytecode([
15
- new Set(/*indirect*/ 0, /*dstOffset*/ 0, TypeTag.UINT32, /*value*/ 1).as(Opcode.SET_8, Set.wireFormat8),
16
- new Set(/*indirect*/ 0, /*dstOffset*/ 1, TypeTag.UINT32, /*value*/ 2).as(Opcode.SET_8, Set.wireFormat8),
17
- new Add(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
18
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
19
- ]);
20
-
21
- const result = await testCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');
22
-
23
- // Modify the protocol contracts to be all zeros
24
- result.avmProvingRequest.inputs.hints.protocolContracts = ProtocolContracts.empty();
25
- result.avmProvingRequest.inputs.publicInputs.protocolContracts = ProtocolContracts.empty();
26
-
27
- return result;
28
- }
29
-
30
- /**
31
- * Reads the AVM circuit inputs for the minimal public tx from a pre-generated JSON file.
32
- * @returns The AvmCircuitInputs for the minimal public tx.
33
- */
34
- export function readAvmMinimalPublicTxInputsFromFile(): AvmCircuitInputs {
35
- return AvmCircuitInputs.schema.parse(avmMinimalCircuitInputsJson);
36
- }
@@ -1,505 +0,0 @@
1
- import { sha256Trunc } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
4
- import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
5
- import type { FunctionSelector } from '@aztec/stdlib/abi';
6
- import {
7
- AvmAppendLeavesHint,
8
- AvmBytecodeCommitmentHint,
9
- AvmCommitCheckpointHint,
10
- AvmContractClassHint,
11
- AvmContractInstanceHint,
12
- AvmCreateCheckpointHint,
13
- type AvmExecutionHints,
14
- AvmGetLeafPreimageHintNullifierTree,
15
- AvmGetLeafPreimageHintPublicDataTree,
16
- AvmGetLeafValueHint,
17
- AvmGetPreviousValueIndexHint,
18
- AvmGetSiblingPathHint,
19
- AvmRevertCheckpointHint,
20
- AvmSequentialInsertHintNullifierTree,
21
- AvmSequentialInsertHintPublicDataTree,
22
- } from '@aztec/stdlib/avm';
23
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
24
- import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
25
- import {
26
- AppendOnlyTreeSnapshot,
27
- type BatchInsertionResult,
28
- type IndexedTreeId,
29
- MerkleTreeId,
30
- type MerkleTreeLeafType,
31
- type MerkleTreeWriteOperations,
32
- NullifierLeaf,
33
- NullifierLeafPreimage,
34
- PublicDataTreeLeaf,
35
- PublicDataTreeLeafPreimage,
36
- type SequentialInsertionResult,
37
- type TreeHeights,
38
- getTreeName,
39
- merkleTreeIds,
40
- } from '@aztec/stdlib/trees';
41
- import { TreeSnapshots } from '@aztec/stdlib/tx';
42
- import type { UInt64 } from '@aztec/stdlib/types';
43
- import type { WorldStateRevision } from '@aztec/stdlib/world-state';
44
-
45
- import { strict as assert } from 'assert';
46
-
47
- import type { PublicContractsDBInterface } from './db_interfaces.js';
48
-
49
- /**
50
- * A public contracts database that forwards requests and collects AVM hints.
51
- */
52
- export class HintingPublicContractsDB implements PublicContractsDBInterface {
53
- // We deduplicate contract classes because they include the whole bytecode.
54
- private contractClassIds: Set<bigint> = new Set();
55
-
56
- constructor(
57
- private readonly db: PublicContractsDBInterface,
58
- private hints: AvmExecutionHints,
59
- ) {}
60
-
61
- public async getContractInstance(
62
- address: AztecAddress,
63
- timestamp: UInt64,
64
- ): Promise<ContractInstanceWithAddress | undefined> {
65
- const instance = await this.db.getContractInstance(address, timestamp);
66
- if (instance) {
67
- // We don't need to hint the block number because it doesn't change.
68
- this.hints.contractInstances.push(
69
- new AvmContractInstanceHint(
70
- instance.address,
71
- instance.salt,
72
- instance.deployer,
73
- instance.currentContractClassId,
74
- instance.originalContractClassId,
75
- instance.initializationHash,
76
- instance.publicKeys,
77
- ),
78
- );
79
- }
80
- return instance;
81
- }
82
-
83
- public async getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined> {
84
- const contractClass = await this.db.getContractClass(contractClassId);
85
- if (contractClass && !this.contractClassIds.has(contractClassId.toBigInt())) {
86
- this.contractClassIds.add(contractClassId.toBigInt());
87
- this.hints.contractClasses.push(
88
- new AvmContractClassHint(
89
- contractClass.id,
90
- contractClass.artifactHash,
91
- contractClass.privateFunctionsRoot,
92
- contractClass.packedBytecode,
93
- ),
94
- );
95
- }
96
- return contractClass;
97
- }
98
-
99
- public async getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined> {
100
- const commitment = await this.db.getBytecodeCommitment(contractClassId);
101
- if (commitment) {
102
- this.hints.bytecodeCommitments.push(new AvmBytecodeCommitmentHint(contractClassId, commitment));
103
- }
104
- return commitment;
105
- }
106
-
107
- public async getDebugFunctionName(
108
- contractAddress: AztecAddress,
109
- selector: FunctionSelector,
110
- ): Promise<string | undefined> {
111
- return await this.db.getDebugFunctionName(contractAddress, selector);
112
- }
113
- }
114
-
115
- /**
116
- * A low-level merkle DB that collects hints.
117
- */
118
- export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
119
- private static readonly log: Logger = createLogger('simulator:hinting-merkle-db');
120
- // This stack is only for debugging purposes.
121
- // The top of the stack is the current checkpoint id.
122
- // We need the stack to be non-empty and use 0 as an arbitrary initial checkpoint id.
123
- // This is not necessarily a checkpoint that happened, but whatever tree state we start with.
124
- private checkpointStack: number[] = [0];
125
- private nextCheckpointId: number = 1;
126
- private checkpointActionCounter: number = 0; // yes, a side-effect counter.
127
-
128
- public static async create(db: MerkleTreeWriteOperations, hints: AvmExecutionHints) {
129
- const hintingTreesDB = new HintingMerkleWriteOperations(db, hints);
130
- const startStateReference = await db.getStateReference();
131
- hints.startingTreeRoots = new TreeSnapshots(
132
- startStateReference.l1ToL2MessageTree,
133
- startStateReference.partial.noteHashTree,
134
- startStateReference.partial.nullifierTree,
135
- startStateReference.partial.publicDataTree,
136
- );
137
-
138
- return hintingTreesDB;
139
- }
140
-
141
- // Use create() to instantiate.
142
- private constructor(
143
- private db: MerkleTreeWriteOperations,
144
- private hints: AvmExecutionHints,
145
- ) {}
146
-
147
- // Getters.
148
- public async getSiblingPath<ID extends MerkleTreeId>(
149
- treeId: ID,
150
- index: bigint,
151
- ): Promise<SiblingPath<TreeHeights[ID]>> {
152
- const path = await this.db.getSiblingPath(treeId, index);
153
- const key = await this.getHintKey(treeId);
154
- this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
155
- return Promise.resolve(path);
156
- }
157
-
158
- public async getPreviousValueIndex<ID extends IndexedTreeId>(
159
- treeId: ID,
160
- value: bigint,
161
- ): Promise<
162
- | {
163
- index: bigint;
164
- alreadyPresent: boolean;
165
- }
166
- | undefined
167
- > {
168
- const result = await this.db.getPreviousValueIndex(treeId, value);
169
- if (result === undefined) {
170
- throw new Error(
171
- `getPreviousValueIndex(${getTreeName(
172
- treeId,
173
- )}, ${value}}) returned undefined. Possible wrong tree setup or corrupted state.`,
174
- );
175
- }
176
- const key = await this.getHintKey(treeId);
177
- this.hints.getPreviousValueIndexHints.push(
178
- new AvmGetPreviousValueIndexHint(key, treeId, new Fr(value), result.index, result.alreadyPresent),
179
- );
180
- return result;
181
- }
182
-
183
- public async getLeafPreimage<ID extends IndexedTreeId>(
184
- treeId: ID,
185
- index: bigint,
186
- ): Promise<IndexedTreeLeafPreimage | undefined> {
187
- const preimage = await this.db.getLeafPreimage<ID>(treeId, index);
188
- if (preimage) {
189
- const key = await this.getHintKey(treeId);
190
-
191
- switch (treeId) {
192
- case MerkleTreeId.PUBLIC_DATA_TREE:
193
- this.hints.getLeafPreimageHintsPublicDataTree.push(
194
- new AvmGetLeafPreimageHintPublicDataTree(key, index, preimage as PublicDataTreeLeafPreimage),
195
- );
196
- break;
197
- case MerkleTreeId.NULLIFIER_TREE:
198
- this.hints.getLeafPreimageHintsNullifierTree.push(
199
- new AvmGetLeafPreimageHintNullifierTree(key, index, preimage as NullifierLeafPreimage),
200
- );
201
- break;
202
- default:
203
- // Use getLeafValue for the other trees.
204
- throw new Error('getLeafPreimage only supported for PublicDataTree and NullifierTree!');
205
- break;
206
- }
207
- }
208
-
209
- return preimage;
210
- }
211
-
212
- public async getLeafValue<ID extends MerkleTreeId>(
213
- treeId: ID,
214
- index: bigint,
215
- ): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
216
- // Use getLeafPreimage for PublicDataTree and NullifierTree.
217
- assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
218
-
219
- const value = await this.db.getLeafValue<ID>(treeId, index);
220
- if (value) {
221
- const key = await this.getHintKey(treeId);
222
- // We can cast to Fr because we know the type of the tree.
223
- this.hints.getLeafValueHints.push(new AvmGetLeafValueHint(key, treeId, index, value as Fr));
224
- }
225
-
226
- return value;
227
- }
228
-
229
- // State modification.
230
- // FIXME(fcarreiro): This is a horrible interface (in the merkle ops). It's receiving the leaves as buffers,
231
- // from a leaf class that is NOT the one that will be used to write. Make this type safe.
232
- public async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
233
- treeId: ID,
234
- leaves: Buffer[],
235
- ): Promise<SequentialInsertionResult<TreeHeight>> {
236
- // Use appendLeaf for NoteHashTree and L1ToL2MessageTree.
237
- assert(treeId == MerkleTreeId.PUBLIC_DATA_TREE || treeId == MerkleTreeId.NULLIFIER_TREE);
238
- // We only support 1 leaf at a time for now. Can easily be extended.
239
- assert(leaves.length === 1, 'sequentialInsert supports only one leaf at a time!');
240
-
241
- const beforeState = await this.getHintKey(treeId);
242
-
243
- const result = await this.db.sequentialInsert<TreeHeight, ID>(treeId, leaves);
244
-
245
- const afterState = await this.getHintKey(treeId);
246
- HintingMerkleWriteOperations.logTreeChange('sequentialInsert', beforeState, afterState, treeId);
247
-
248
- switch (treeId) {
249
- case MerkleTreeId.PUBLIC_DATA_TREE:
250
- this.hints.sequentialInsertHintsPublicDataTree.push(
251
- new AvmSequentialInsertHintPublicDataTree(
252
- beforeState,
253
- afterState,
254
- treeId,
255
- PublicDataTreeLeaf.fromBuffer(leaves[0]),
256
- {
257
- leaf: result.lowLeavesWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
258
- index: result.lowLeavesWitnessData[0].index,
259
- path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
260
- },
261
- {
262
- leaf: result.insertionWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
263
- index: result.insertionWitnessData[0].index,
264
- path: result.insertionWitnessData[0].siblingPath.toFields(),
265
- },
266
- ),
267
- );
268
- break;
269
- case MerkleTreeId.NULLIFIER_TREE:
270
- this.hints.sequentialInsertHintsNullifierTree.push(
271
- new AvmSequentialInsertHintNullifierTree(
272
- beforeState,
273
- afterState,
274
- treeId,
275
- NullifierLeaf.fromBuffer(leaves[0]),
276
- {
277
- leaf: result.lowLeavesWitnessData[0].leafPreimage as NullifierLeafPreimage,
278
- index: result.lowLeavesWitnessData[0].index,
279
- path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
280
- },
281
- {
282
- leaf: result.insertionWitnessData[0].leafPreimage as NullifierLeafPreimage,
283
- index: result.insertionWitnessData[0].index,
284
- path: result.insertionWitnessData[0].siblingPath.toFields(),
285
- },
286
- ),
287
- );
288
- break;
289
- default:
290
- throw new Error('sequentialInsert only supported for PublicDataTree and NullifierTree!');
291
- break;
292
- }
293
-
294
- return result;
295
- }
296
-
297
- public async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
298
- // Use sequentialInsert for PublicDataTree and NullifierTree.
299
- assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
300
-
301
- // We need to process each leaf individually because we need the sibling path after insertion, to be able to constraint the insertion.
302
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/13380): This can be changed if the world state appendLeaves returns the sibling paths.
303
- if (leaves.length === 1) {
304
- await this.appendLeafInternal(treeId, leaves[0]);
305
- return;
306
- } else {
307
- // TODO(dbanks12): NON-HINTING! We skip hinting here for now because:
308
- // 1. We only ever append multiple leaves (for now) when padding (all empty leaves).
309
- // 2. We don't need hints per-item when padding.
310
- // 3. In order to get per-item hints today, you need to append one-at-a-time (mentioned above), which is VERY slow.
311
- await this.db.appendLeaves<ID>(treeId, leaves);
312
- }
313
- }
314
-
315
- public async createCheckpoint(): Promise<void> {
316
- const actionCounter = this.checkpointActionCounter++;
317
- const oldCheckpointId = this.getCurrentCheckpointId();
318
- const treesStateHash = await this.getTreesStateHash();
319
-
320
- await this.db.createCheckpoint();
321
- this.checkpointStack.push(this.nextCheckpointId++);
322
- const newCheckpointId = this.getCurrentCheckpointId();
323
-
324
- this.hints.createCheckpointHints.push(new AvmCreateCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
325
-
326
- HintingMerkleWriteOperations.log.trace(
327
- `[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
328
- );
329
- }
330
-
331
- public commitAllCheckpoints(): Promise<void> {
332
- throw new Error('commitAllCheckpoints is not supported in HintingMerkleWriteOperations.');
333
- }
334
-
335
- public revertAllCheckpoints(): Promise<void> {
336
- throw new Error('revertAllCheckpoints is not supported in HintingMerkleWriteOperations.');
337
- }
338
-
339
- public async commitCheckpoint(): Promise<void> {
340
- const actionCounter = this.checkpointActionCounter++;
341
- const oldCheckpointId = this.getCurrentCheckpointId();
342
- const treesStateHash = await this.getTreesStateHash();
343
-
344
- await this.db.commitCheckpoint();
345
- this.checkpointStack.pop();
346
- const newCheckpointId = this.getCurrentCheckpointId();
347
-
348
- this.hints.commitCheckpointHints.push(new AvmCommitCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
349
-
350
- HintingMerkleWriteOperations.log.trace(
351
- `[commitCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
352
- );
353
- }
354
-
355
- public async revertCheckpoint(): Promise<void> {
356
- const actionCounter = this.checkpointActionCounter++;
357
- const oldCheckpointId = this.getCurrentCheckpointId();
358
- const treesStateHash = await this.getTreesStateHash();
359
-
360
- const beforeState: Record<MerkleTreeId, AppendOnlyTreeSnapshot> = {
361
- [MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
362
- [MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
363
- [MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
364
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
365
- [MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
366
- };
367
-
368
- await this.db.revertCheckpoint();
369
- this.checkpointStack.pop();
370
- const newCheckpointId = this.getCurrentCheckpointId();
371
-
372
- const afterState: Record<MerkleTreeId, AppendOnlyTreeSnapshot> = {
373
- [MerkleTreeId.PUBLIC_DATA_TREE]: await this.getHintKey(MerkleTreeId.PUBLIC_DATA_TREE),
374
- [MerkleTreeId.NULLIFIER_TREE]: await this.getHintKey(MerkleTreeId.NULLIFIER_TREE),
375
- [MerkleTreeId.NOTE_HASH_TREE]: await this.getHintKey(MerkleTreeId.NOTE_HASH_TREE),
376
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: await this.getHintKey(MerkleTreeId.L1_TO_L2_MESSAGE_TREE),
377
- [MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
378
- };
379
-
380
- this.hints.revertCheckpointHints.push(
381
- AvmRevertCheckpointHint.create(actionCounter, oldCheckpointId, newCheckpointId, beforeState, afterState),
382
- );
383
-
384
- HintingMerkleWriteOperations.log.trace(
385
- `[revertCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
386
- );
387
- for (const treeId of merkleTreeIds()) {
388
- HintingMerkleWriteOperations.logTreeChange('revertCheckpoint', beforeState[treeId], afterState[treeId], treeId);
389
- }
390
- }
391
-
392
- // Private methods.
393
- private async getHintKey(treeId: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
394
- const treeInfo = await this.db.getTreeInfo(treeId);
395
- return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
396
- }
397
-
398
- private getCurrentCheckpointId(): number {
399
- return this.checkpointStack[this.checkpointStack.length - 1];
400
- }
401
-
402
- // For logging/debugging purposes.
403
- private async getTreesStateHash(): Promise<Fr> {
404
- const stateReferenceFields = (await this.db.getStateReference()).toFields();
405
- return Fr.fromBuffer(sha256Trunc(Buffer.concat(stateReferenceFields.map(field => field.toBuffer()))));
406
- }
407
-
408
- private static logTreeChange(
409
- action: string,
410
- beforeState: AppendOnlyTreeSnapshot,
411
- afterState: AppendOnlyTreeSnapshot,
412
- treeId: MerkleTreeId,
413
- ) {
414
- const treeName = getTreeName(treeId);
415
- HintingMerkleWriteOperations.log.trace(
416
- `[${action}] ${treeName} tree state: ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`,
417
- );
418
- }
419
-
420
- private async appendLeafInternal<ID extends MerkleTreeId>(
421
- treeId: ID,
422
- leaf: MerkleTreeLeafType<ID>,
423
- ): Promise<SiblingPath<TreeHeights[ID]>> {
424
- // Use sequentialInsert for PublicDataTree and NullifierTree.
425
- assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
426
-
427
- const beforeState = await this.getHintKey(treeId);
428
-
429
- await this.db.appendLeaves<ID>(treeId, [leaf]);
430
-
431
- const afterState = await this.getHintKey(treeId);
432
-
433
- HintingMerkleWriteOperations.logTreeChange('appendLeaves', beforeState, afterState, treeId);
434
-
435
- this.hints.appendLeavesHints.push(new AvmAppendLeavesHint(beforeState, afterState, treeId, [leaf as Fr]));
436
-
437
- return await this.getSiblingPath(treeId, BigInt(beforeState.nextAvailableLeafIndex));
438
- }
439
-
440
- // Non-hinted required methods from MerkleTreeWriteOperations interface
441
- public async getTreeInfo(treeId: MerkleTreeId) {
442
- return await this.db.getTreeInfo(treeId);
443
- }
444
-
445
- public async getStateReference() {
446
- return await this.db.getStateReference();
447
- }
448
-
449
- public getInitialHeader() {
450
- return this.db.getInitialHeader();
451
- }
452
-
453
- public getRevision(): WorldStateRevision {
454
- return this.db.getRevision();
455
- }
456
-
457
- public async updateArchive(header: any): Promise<void> {
458
- return await this.db.updateArchive(header);
459
- }
460
-
461
- public async batchInsert<
462
- TreeHeight extends number,
463
- SubtreeSiblingPathHeight extends number,
464
- ID extends IndexedTreeId,
465
- >(
466
- treeId: ID,
467
- leaves: Buffer[],
468
- subtreeHeight: number,
469
- ): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
470
- return await this.db.batchInsert<TreeHeight, SubtreeSiblingPathHeight, ID>(treeId, leaves, subtreeHeight);
471
- }
472
-
473
- public async close(): Promise<void> {
474
- return await this.db.close();
475
- }
476
-
477
- public async findLeafIndices<ID extends MerkleTreeId>(
478
- treeId: ID,
479
- values: MerkleTreeLeafType<ID>[],
480
- ): Promise<(bigint | undefined)[]> {
481
- return await this.db.findLeafIndices(treeId, values);
482
- }
483
-
484
- public findSiblingPaths<ID extends MerkleTreeId>(
485
- treeId: ID,
486
- values: MerkleTreeLeafType<ID>[],
487
- ): Promise<({ path: SiblingPath<TreeHeights[ID]>; index: bigint } | undefined)[]> {
488
- return this.db.findSiblingPaths(treeId, values);
489
- }
490
-
491
- public async findLeafIndicesAfter<ID extends MerkleTreeId>(
492
- treeId: ID,
493
- values: MerkleTreeLeafType<ID>[],
494
- startIndex: bigint,
495
- ): Promise<(bigint | undefined)[]> {
496
- return await this.db.findLeafIndicesAfter(treeId, values, startIndex);
497
- }
498
-
499
- public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
500
- treeId: ID,
501
- leafIndices: bigint[],
502
- ): Promise<(bigint | undefined)[]> {
503
- return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
504
- }
505
- }