@aztec/simulator 6.0.0-nightly.20260604 → 6.0.0-nightly.20260721

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 (349) hide show
  1. package/dest/client.d.ts +1 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +0 -2
  4. package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
  5. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  6. package/dest/private/circuit_recording/circuit_recorder.js +65 -69
  7. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
  8. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  9. package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
  10. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  11. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  12. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  13. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  14. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  15. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +1 -1
  16. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  17. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +1 -1
  18. package/dest/public/avm/testing/utils.d.ts +32 -0
  19. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  20. package/dest/public/avm/{fixtures → testing}/utils.js +1 -34
  21. package/dest/public/avm_simulator.d.ts +28 -0
  22. package/dest/public/avm_simulator.d.ts.map +1 -0
  23. package/dest/public/avm_simulator.js +4 -0
  24. package/dest/public/avm_simulator_pool.d.ts +45 -0
  25. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  26. package/dest/public/avm_simulator_pool.js +197 -0
  27. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  28. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  29. package/dest/public/cdb/generated/api_types.js +314 -0
  30. package/dest/public/cdb/generated/server.d.ts +26 -0
  31. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  32. package/dest/public/cdb/generated/server.js +135 -0
  33. package/dest/public/cdb_ipc_server.d.ts +33 -0
  34. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  35. package/dest/public/cdb_ipc_server.js +153 -0
  36. package/dest/public/fixtures/amm_test.js +2 -2
  37. package/dest/public/fixtures/bulk_test.js +2 -2
  38. package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
  39. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  40. package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
  41. package/dest/public/fixtures/index.d.ts +2 -4
  42. package/dest/public/fixtures/index.d.ts.map +1 -1
  43. package/dest/public/fixtures/index.js +1 -3
  44. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  45. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  46. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  47. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +11 -7
  48. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  49. package/dest/public/fixtures/public_tx_simulation_tester.js +33 -43
  50. package/dest/public/fixtures/simple_contract_data_source.js +1 -1
  51. package/dest/public/fixtures/token_test.js +3 -3
  52. package/dest/public/fixtures/utils.d.ts +1 -1
  53. package/dest/public/fixtures/utils.d.ts.map +1 -1
  54. package/dest/public/fixtures/utils.js +5 -3
  55. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +11 -4
  56. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  57. package/dest/public/fuzzing/avm_fuzzer_simulator.js +24 -10
  58. package/dest/public/fuzzing/avm_simulator_bin.js +4 -4
  59. package/dest/public/index.d.ts +5 -2
  60. package/dest/public/index.d.ts.map +1 -1
  61. package/dest/public/index.js +2 -1
  62. package/dest/public/public_db_sources.d.ts +2 -2
  63. package/dest/public/public_db_sources.d.ts.map +1 -1
  64. package/dest/public/public_db_sources.js +1 -1
  65. package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -3
  66. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  67. package/dest/public/public_processor/guarded_merkle_tree.js +3 -0
  68. package/dest/public/public_processor/public_processor.d.ts +8 -4
  69. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  70. package/dest/public/public_processor/public_processor.js +18 -14
  71. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  72. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  73. package/dest/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.js → dumping_public_tx_simulator.js} +10 -23
  74. package/dest/public/public_tx_simulator/factories.d.ts +8 -8
  75. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  76. package/dest/public/public_tx_simulator/factories.js +8 -8
  77. package/dest/public/public_tx_simulator/index.d.ts +4 -6
  78. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  79. package/dest/public/public_tx_simulator/index.js +2 -4
  80. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +42 -75
  81. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  82. package/dest/public/public_tx_simulator/public_tx_simulator.js +98 -323
  83. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  84. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  85. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  86. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +5 -5
  87. package/dest/public/test_executor_metrics.d.ts +1 -6
  88. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  89. package/dest/public/test_executor_metrics.js +0 -22
  90. package/package.json +22 -19
  91. package/src/client.ts +0 -2
  92. package/src/private/circuit_recording/circuit_recorder.ts +84 -78
  93. package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
  94. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  95. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +1 -1
  96. package/src/public/avm/{fixtures → testing}/utils.ts +1 -40
  97. package/src/public/avm_simulator.ts +29 -0
  98. package/src/public/avm_simulator_pool.ts +226 -0
  99. package/src/public/cdb/generated/api_types.ts +457 -0
  100. package/src/public/cdb/generated/server.ts +109 -0
  101. package/src/public/cdb_ipc_server.ts +197 -0
  102. package/src/public/fixtures/amm_test.ts +2 -2
  103. package/src/public/fixtures/bulk_test.ts +2 -2
  104. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  105. package/src/public/fixtures/index.ts +1 -3
  106. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  107. package/src/public/fixtures/public_tx_simulation_tester.ts +41 -55
  108. package/src/public/fixtures/simple_contract_data_source.ts +1 -1
  109. package/src/public/fixtures/token_test.ts +3 -3
  110. package/src/public/fixtures/utils.ts +6 -11
  111. package/src/public/fuzzing/avm_fuzzer_simulator.ts +25 -10
  112. package/src/public/fuzzing/avm_simulator_bin.ts +3 -5
  113. package/src/public/index.ts +7 -3
  114. package/src/public/public_db_sources.ts +1 -1
  115. package/src/public/public_processor/guarded_merkle_tree.ts +5 -2
  116. package/src/public/public_processor/public_processor.ts +24 -17
  117. package/src/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.ts → dumping_public_tx_simulator.ts} +15 -31
  118. package/src/public/public_tx_simulator/factories.ts +27 -10
  119. package/src/public/public_tx_simulator/index.ts +6 -5
  120. package/src/public/public_tx_simulator/public_tx_simulator.ts +139 -480
  121. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  122. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +5 -5
  123. package/src/public/test_executor_metrics.ts +0 -24
  124. package/dest/public/avm/avm_context.d.ts +0 -41
  125. package/dest/public/avm/avm_context.d.ts.map +0 -1
  126. package/dest/public/avm/avm_context.js +0 -44
  127. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  128. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  129. package/dest/public/avm/avm_contract_call_result.js +0 -54
  130. package/dest/public/avm/avm_execution_environment.d.ts +0 -24
  131. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  132. package/dest/public/avm/avm_execution_environment.js +0 -33
  133. package/dest/public/avm/avm_gas.d.ts +0 -44
  134. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  135. package/dest/public/avm/avm_gas.js +0 -195
  136. package/dest/public/avm/avm_machine_state.d.ts +0 -98
  137. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  138. package/dest/public/avm/avm_machine_state.js +0 -110
  139. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  140. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  141. package/dest/public/avm/avm_memory_types.js +0 -354
  142. package/dest/public/avm/avm_simulator.d.ts +0 -41
  143. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  144. package/dest/public/avm/avm_simulator.js +0 -192
  145. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  146. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  147. package/dest/public/avm/avm_simulator_interface.js +0 -3
  148. package/dest/public/avm/calldata.d.ts +0 -51
  149. package/dest/public/avm/calldata.d.ts.map +0 -1
  150. package/dest/public/avm/calldata.js +0 -64
  151. package/dest/public/avm/errors.d.ts +0 -104
  152. package/dest/public/avm/errors.d.ts.map +0 -1
  153. package/dest/public/avm/errors.js +0 -141
  154. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +0 -2
  155. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +0 -1
  156. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  157. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  158. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -84
  159. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  160. package/dest/public/avm/fixtures/initializers.d.ts +0 -42
  161. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  162. package/dest/public/avm/fixtures/initializers.js +0 -45
  163. package/dest/public/avm/fixtures/utils.d.ts +0 -39
  164. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  165. package/dest/public/avm/index.d.ts +0 -2
  166. package/dest/public/avm/index.d.ts.map +0 -1
  167. package/dest/public/avm/index.js +0 -1
  168. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -74
  169. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  170. package/dest/public/avm/opcodes/accrued_substate.js +0 -254
  171. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  172. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  173. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  174. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -49
  175. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  176. package/dest/public/avm/opcodes/arithmetic.js +0 -97
  177. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  178. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  179. package/dest/public/avm/opcodes/bitwise.js +0 -99
  180. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  181. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  182. package/dest/public/avm/opcodes/comparators.js +0 -43
  183. package/dest/public/avm/opcodes/contract.d.ts +0 -21
  184. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  185. package/dest/public/avm/opcodes/contract.js +0 -69
  186. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  187. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  188. package/dest/public/avm/opcodes/control_flow.js +0 -107
  189. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  190. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  191. package/dest/public/avm/opcodes/conversion.js +0 -333
  192. package/dest/public/avm/opcodes/ec_add.d.ts +0 -17
  193. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  194. package/dest/public/avm/opcodes/ec_add.js +0 -79
  195. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  196. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  197. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  198. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  199. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  200. package/dest/public/avm/opcodes/external_calls.js +0 -210
  201. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  202. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  203. package/dest/public/avm/opcodes/hashing.js +0 -119
  204. package/dest/public/avm/opcodes/index.d.ts +0 -16
  205. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  206. package/dest/public/avm/opcodes/index.js +0 -15
  207. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  208. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  209. package/dest/public/avm/opcodes/instruction.js +0 -95
  210. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  211. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  212. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  213. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  214. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  215. package/dest/public/avm/opcodes/memory.js +0 -257
  216. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  217. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  218. package/dest/public/avm/opcodes/misc.js +0 -73
  219. package/dest/public/avm/opcodes/storage.d.ts +0 -25
  220. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  221. package/dest/public/avm/opcodes/storage.js +0 -78
  222. package/dest/public/avm/revert_reason.d.ts +0 -18
  223. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  224. package/dest/public/avm/revert_reason.js +0 -39
  225. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  226. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  227. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  228. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  229. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  230. package/dest/public/avm/serialization/bytecode_serialization.js +0 -336
  231. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  232. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  233. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  234. package/dest/public/avm/test_utils.d.ts +0 -15
  235. package/dest/public/avm/test_utils.d.ts.map +0 -1
  236. package/dest/public/avm/test_utils.js +0 -44
  237. package/dest/public/debug_fn_name.d.ts +0 -18
  238. package/dest/public/debug_fn_name.d.ts.map +0 -1
  239. package/dest/public/debug_fn_name.js +0 -37
  240. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -14
  241. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  242. package/dest/public/fixtures/custom_bytecode_tests.js +0 -234
  243. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -4
  244. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  245. package/dest/public/fixtures/minimal_public_tx.js +0 -19
  246. package/dest/public/fixtures/opcode_spammer.d.ts +0 -122
  247. package/dest/public/fixtures/opcode_spammer.d.ts.map +0 -1
  248. package/dest/public/fixtures/opcode_spammer.js +0 -1645
  249. package/dest/public/hinting_db_sources.d.ts +0 -80
  250. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  251. package/dest/public/hinting_db_sources.js +0 -356
  252. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -19
  253. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
  254. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -99
  255. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -53
  256. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  257. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -131
  258. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +0 -42
  259. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +0 -1
  260. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +0 -86
  261. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +0 -30
  262. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +0 -1
  263. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +0 -171
  264. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +0 -23
  265. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +0 -1
  266. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -31
  267. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  268. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  269. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -135
  270. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  271. package/dest/public/public_tx_simulator/public_tx_context.js +0 -298
  272. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  273. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  274. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -415
  275. package/dest/public/side_effect_trace.d.ts +0 -87
  276. package/dest/public/side_effect_trace.d.ts.map +0 -1
  277. package/dest/public/side_effect_trace.js +0 -199
  278. package/dest/public/side_effect_trace_interface.d.ts +0 -22
  279. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  280. package/dest/public/side_effect_trace_interface.js +0 -1
  281. package/dest/public/state_manager/index.d.ts +0 -2
  282. package/dest/public/state_manager/index.d.ts.map +0 -1
  283. package/dest/public/state_manager/index.js +0 -1
  284. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  285. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  286. package/dest/public/state_manager/nullifiers.js +0 -92
  287. package/dest/public/state_manager/public_storage.d.ts +0 -66
  288. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  289. package/dest/public/state_manager/public_storage.js +0 -145
  290. package/dest/public/state_manager/state_manager.d.ts +0 -170
  291. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  292. package/dest/public/state_manager/state_manager.js +0 -402
  293. package/src/public/avm/avm_context.ts +0 -61
  294. package/src/public/avm/avm_contract_call_result.ts +0 -69
  295. package/src/public/avm/avm_execution_environment.ts +0 -51
  296. package/src/public/avm/avm_gas.ts +0 -183
  297. package/src/public/avm/avm_machine_state.ts +0 -170
  298. package/src/public/avm/avm_memory_types.ts +0 -440
  299. package/src/public/avm/avm_simulator.ts +0 -279
  300. package/src/public/avm/avm_simulator_interface.ts +0 -8
  301. package/src/public/avm/calldata.ts +0 -101
  302. package/src/public/avm/errors.ts +0 -177
  303. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -122
  304. package/src/public/avm/fixtures/initializers.ts +0 -103
  305. package/src/public/avm/index.ts +0 -1
  306. package/src/public/avm/opcodes/accrued_substate.ts +0 -285
  307. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  308. package/src/public/avm/opcodes/arithmetic.ts +0 -129
  309. package/src/public/avm/opcodes/bitwise.ts +0 -113
  310. package/src/public/avm/opcodes/comparators.ts +0 -55
  311. package/src/public/avm/opcodes/contract.ts +0 -76
  312. package/src/public/avm/opcodes/control_flow.ts +0 -123
  313. package/src/public/avm/opcodes/conversion.ts +0 -104
  314. package/src/public/avm/opcodes/ec_add.ts +0 -86
  315. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  316. package/src/public/avm/opcodes/external_calls.ts +0 -262
  317. package/src/public/avm/opcodes/hashing.ts +0 -151
  318. package/src/public/avm/opcodes/index.ts +0 -15
  319. package/src/public/avm/opcodes/instruction.ts +0 -136
  320. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  321. package/src/public/avm/opcodes/memory.ts +0 -293
  322. package/src/public/avm/opcodes/misc.ts +0 -102
  323. package/src/public/avm/opcodes/storage.ts +0 -95
  324. package/src/public/avm/revert_reason.ts +0 -58
  325. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  326. package/src/public/avm/serialization/bytecode_serialization.ts +0 -215
  327. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  328. package/src/public/avm/test_utils.ts +0 -64
  329. package/src/public/debug_fn_name.ts +0 -52
  330. package/src/public/fixtures/custom_bytecode_tests.ts +0 -366
  331. package/src/public/fixtures/minimal_public_tx.ts +0 -26
  332. package/src/public/fixtures/opcode_spammer.ts +0 -1713
  333. package/src/public/hinting_db_sources.ts +0 -610
  334. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -125
  335. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -210
  336. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +0 -134
  337. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +0 -239
  338. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -105
  339. package/src/public/public_tx_simulator/public_tx_context.ts +0 -482
  340. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  341. package/src/public/side_effect_trace.ts +0 -293
  342. package/src/public/side_effect_trace_interface.ts +0 -28
  343. package/src/public/state_manager/index.ts +0 -1
  344. package/src/public/state_manager/nullifiers.ts +0 -103
  345. package/src/public/state_manager/public_storage.ts +0 -174
  346. package/src/public/state_manager/state_manager.ts +0 -569
  347. /package/dest/public/avm/{fixtures → testing}/account_proof_fetcher.js +0 -0
  348. /package/src/public/avm/{fixtures → testing}/account_proof.json +0 -0
  349. /package/src/public/avm/{fixtures → testing}/account_proof_fetcher.ts +0 -0
@@ -1,170 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type LogLevel, type LoggerBindings } from '@aztec/foundation/log';
3
- import { FunctionSelector } from '@aztec/stdlib/abi';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { SerializableContractInstance } from '@aztec/stdlib/contract';
6
- import type { DebugLog } from '@aztec/stdlib/logs';
7
- import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
8
- import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import type { TreeSnapshots } from '@aztec/stdlib/tx';
10
- import type { UInt64 } from '@aztec/stdlib/types';
11
- import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
12
- import type { PublicContractsDBInterface } from '../db_interfaces.js';
13
- import type { PublicTreesDB } from '../public_db_sources.js';
14
- import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
15
- import { NullifierManager } from './nullifiers.js';
16
- import { PublicStorage } from './public_storage.js';
17
- /**
18
- * A class to manage persistable AVM state for contract calls.
19
- * Maintains a cache of the current world state,
20
- * a trace of all side effects.
21
- *
22
- * The simulator should make any world state / tree queries through this object.
23
- *
24
- * Manages merging of successful/reverted child state into current state.
25
- */
26
- export declare class PublicPersistableStateManager {
27
- private readonly treesDB;
28
- private readonly contractsDB;
29
- private readonly trace;
30
- private readonly firstNullifier;
31
- private readonly timestamp;
32
- private readonly doMerkleOperations;
33
- private readonly publicStorage;
34
- private readonly nullifiers;
35
- private readonly log;
36
- /** Make sure a forked state is never merged twice. */
37
- private alreadyMergedIntoParent;
38
- constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, trace: PublicSideEffectTraceInterface, firstNullifier: Fr, timestamp: UInt64, doMerkleOperations?: boolean, publicStorage?: PublicStorage, nullifiers?: NullifierManager, bindings?: LoggerBindings);
39
- /**
40
- * Create a new state manager
41
- */
42
- static create(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, trace: PublicSideEffectTraceInterface, firstNullifier: Fr, timestamp: UInt64, bindings?: LoggerBindings): PublicPersistableStateManager;
43
- /**
44
- * Create a new state manager forked from this one
45
- */
46
- fork(): Promise<PublicPersistableStateManager>;
47
- /**
48
- * Accept forked world state modifications & traced side effects / hints
49
- */
50
- merge(forkedState: PublicPersistableStateManager): Promise<void>;
51
- /**
52
- * Reject forked world state modifications & traced side effects, keep traced hints
53
- */
54
- reject(forkedState: PublicPersistableStateManager): Promise<void>;
55
- private _merge;
56
- /**
57
- * Write to public storage, journal/trace the write.
58
- *
59
- * @param contractAddress - the address of the contract whose storage is being written to
60
- * @param slot - the slot in the contract's storage being written to
61
- * @param value - the value being written to the slot
62
- */
63
- writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr, protocolWrite?: boolean): Promise<void>;
64
- isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean;
65
- /**
66
- * Read from public storage.
67
- *
68
- * @param contractAddress - the address of the contract whose storage is being read from
69
- * @param slot - the slot in the contract's storage being read from
70
- * @returns the latest value written to slot, or 0 if never written to before
71
- */
72
- readStorage(contractAddress: AztecAddress, slot: Fr): Promise<Fr>;
73
- /**
74
- * Check if a note hash exists at the given leaf index, trace the check.
75
- *
76
- * @param contractAddress - the address of the contract whose storage is being read from
77
- * @param noteHash - the unsiloed note hash being checked
78
- * @param leafIndex - the leaf index being checked
79
- * @returns true if the note hash exists at the given leaf index, false otherwise
80
- */
81
- checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: bigint): Promise<boolean>;
82
- /**
83
- * Write a raw note hash, silo it and make it unique, then trace the write.
84
- * @param noteHash - the unsiloed note hash to write
85
- */
86
- writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): Promise<void>;
87
- /**
88
- * Write a note hash, make it unique, trace the write.
89
- * @param siloedNoteHash - the non unique note hash to write
90
- */
91
- writeSiloedNoteHash(siloedNoteHash: Fr): Promise<void>;
92
- /**
93
- * Write a note hash, trace the write.
94
- * @param uniqueNoteHash - the siloed unique hash to write
95
- */
96
- writeUniqueNoteHash(uniqueNoteHash: Fr): Promise<void>;
97
- /**
98
- * Check if a nullifier exists, trace the check.
99
- * @param contractAddress - address of the contract that the nullifier is associated with
100
- * @param nullifier - the unsiloed nullifier to check
101
- * @returns exists - whether the nullifier exists in the nullifier set
102
- */
103
- checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise<boolean>;
104
- /**
105
- * Check if a siloed nullifier exists.
106
- * @param siloedNullifier - the siloed nullifier to check
107
- * @returns exists - whether the nullifier exists in the nullifier set
108
- */
109
- checkSiloedNullifierExists(siloedNullifier: Fr): Promise<boolean>;
110
- /**
111
- * Write a nullifier to the nullifier set, trace the write.
112
- * @param contractAddress - address of the contract that the nullifier is associated with
113
- * @param nullifier - the unsiloed nullifier to write
114
- */
115
- writeNullifier(contractAddress: AztecAddress, nullifier: Fr): Promise<void>;
116
- /**
117
- * Write a nullifier to the nullifier set, trace the write.
118
- * @param siloedNullifier - the siloed nullifier to write
119
- */
120
- writeSiloedNullifier(siloedNullifier: Fr): Promise<void>;
121
- /**
122
- * Check if an L1 to L2 message exists, trace the check.
123
- * @param msgHash - the message hash to check existence of
124
- * @param msgLeafIndex - the message leaf index to use in the check
125
- * @returns exists - whether the message exists in the L1 to L2 Messages tree
126
- */
127
- checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean>;
128
- /**
129
- * Write an L2 to L1 message.
130
- * @param contractAddress - L2 contract address that created this message
131
- * @param recipient - L1 contract address to send the message to.
132
- * @param content - Message content.
133
- */
134
- writeL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr): void;
135
- /**
136
- * Write a scoped L2 to L1 message.
137
- * @param l2ToL1Message - The L2 to L1 message to write.
138
- */
139
- writeScopedL2ToL1Message(l2ToL1Message: ScopedL2ToL1Message): void;
140
- writeDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]): void;
141
- writeDebugLogMemoryReads(memoryReads: number): void;
142
- getDebugLogMemoryReads(): number;
143
- getLogs(): DebugLog[];
144
- /**
145
- * Write a public log
146
- * @param contractAddress - address of the contract that emitted the log
147
- * @param log - log contents
148
- */
149
- writePublicLog(contractAddress: AztecAddress, log: Fr[]): void;
150
- /**
151
- * Get a contract instance.
152
- * @param contractAddress - address of the contract instance to retrieve.
153
- * @returns the contract instance or undefined if it does not exist.
154
- */
155
- getContractInstance(contractAddress: AztecAddress): Promise<SerializableContractInstance | undefined>;
156
- private checkContractUpdateInformation;
157
- private getContractClass;
158
- /**
159
- * Get a contract's bytecode from the contracts DB, also trace the contract class and instance indirectly.
160
- */
161
- getBytecode(contractAddress: AztecAddress): Promise<Buffer | undefined>;
162
- getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string>;
163
- getPublicFunctionSelectorAndName(avmEnvironment: AvmExecutionEnvironment): Promise<{
164
- functionSelector?: FunctionSelector;
165
- functionName?: string;
166
- }>;
167
- padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void>;
168
- getTreeSnapshots(): Promise<TreeSnapshots>;
169
- }
170
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGVfbWFuYWdlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3B1YmxpYy9zdGF0ZV9tYW5hZ2VyL3N0YXRlX21hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxLQUFLLFFBQVEsRUFBZSxLQUFLLGNBQWMsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUV0RyxPQUFPLEVBQUUsZ0JBQWdC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Y,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhF;IAEY,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,CAEtD;CACF"}
@@ -1,402 +0,0 @@
1
- import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec/constants';
2
- import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
3
- import { jsonStringify } from '@aztec/foundation/json-rpc';
4
- import { createLogger } from '@aztec/foundation/log';
5
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
6
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { SerializableContractInstance } from '@aztec/stdlib/contract';
8
- import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
9
- import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
10
- import { strict as assert } from 'assert';
11
- import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
12
- import { L1ToL2MessageIndexOutOfRangeError, MaxCallsToUniqueContractClassIdsError, NoteHashIndexOutOfRangeError, NullifierCollisionError } from '../side_effect_errors.js';
13
- import { NullifierManager } from './nullifiers.js';
14
- import { PublicStorage } from './public_storage.js';
15
- /**
16
- * A class to manage persistable AVM state for contract calls.
17
- * Maintains a cache of the current world state,
18
- * a trace of all side effects.
19
- *
20
- * The simulator should make any world state / tree queries through this object.
21
- *
22
- * Manages merging of successful/reverted child state into current state.
23
- */ export class PublicPersistableStateManager {
24
- treesDB;
25
- contractsDB;
26
- trace;
27
- firstNullifier;
28
- timestamp;
29
- doMerkleOperations;
30
- publicStorage;
31
- nullifiers;
32
- log;
33
- /** Make sure a forked state is never merged twice. */ alreadyMergedIntoParent;
34
- constructor(treesDB, contractsDB, trace, firstNullifier, timestamp, doMerkleOperations = true, publicStorage = new PublicStorage(treesDB), nullifiers = new NullifierManager(treesDB), bindings){
35
- this.treesDB = treesDB;
36
- this.contractsDB = contractsDB;
37
- this.trace = trace;
38
- this.firstNullifier = firstNullifier;
39
- this.timestamp = timestamp;
40
- this.doMerkleOperations = doMerkleOperations;
41
- this.publicStorage = publicStorage;
42
- this.nullifiers = nullifiers;
43
- this.alreadyMergedIntoParent = false;
44
- this.log = createLogger('simulator:state_manager', bindings);
45
- }
46
- /**
47
- * Create a new state manager
48
- */ static create(treesDB, contractsDB, trace, firstNullifier, timestamp, bindings) {
49
- return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp, undefined, undefined, undefined, bindings);
50
- }
51
- /**
52
- * Create a new state manager forked from this one
53
- */ async fork() {
54
- await this.treesDB.createCheckpoint();
55
- return new PublicPersistableStateManager(this.treesDB, this.contractsDB, this.trace.fork(), this.firstNullifier, this.timestamp, this.doMerkleOperations, this.publicStorage.fork(), this.nullifiers.fork(), this.log.getBindings());
56
- }
57
- /**
58
- * Accept forked world state modifications & traced side effects / hints
59
- */ async merge(forkedState) {
60
- await this._merge(forkedState, /*reverted=*/ false);
61
- }
62
- /**
63
- * Reject forked world state modifications & traced side effects, keep traced hints
64
- */ async reject(forkedState) {
65
- await this._merge(forkedState, /*reverted=*/ true);
66
- }
67
- async _merge(forkedState, reverted) {
68
- // sanity check to avoid merging the same forked trace twice
69
- assert(!forkedState.alreadyMergedIntoParent, 'Cannot merge forked state that has already been merged into its parent!');
70
- forkedState.alreadyMergedIntoParent = true;
71
- this.publicStorage.acceptAndMerge(forkedState.publicStorage);
72
- this.nullifiers.acceptAndMerge(forkedState.nullifiers);
73
- this.trace.merge(forkedState.trace, reverted);
74
- if (reverted) {
75
- this.log.trace('Reverting forked state...');
76
- await this.treesDB.revertCheckpoint();
77
- } else {
78
- this.log.trace('Merging forked state into parent...');
79
- await this.treesDB.commitCheckpoint();
80
- }
81
- }
82
- /**
83
- * Write to public storage, journal/trace the write.
84
- *
85
- * @param contractAddress - the address of the contract whose storage is being written to
86
- * @param slot - the slot in the contract's storage being written to
87
- * @param value - the value being written to the slot
88
- */ async writeStorage(contractAddress, slot, value, protocolWrite = false) {
89
- this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`);
90
- await this.trace.tracePublicStorageWrite(contractAddress, slot, value, protocolWrite);
91
- if (this.doMerkleOperations) {
92
- // write to native merkle trees
93
- await this.treesDB.storageWrite(contractAddress, slot, value);
94
- } else {
95
- // Cache storage writes for later reference/reads
96
- this.publicStorage.write(contractAddress, slot, value);
97
- }
98
- }
99
- isStorageCold(contractAddress, slot) {
100
- return this.trace.isStorageCold(contractAddress, slot);
101
- }
102
- /**
103
- * Read from public storage.
104
- *
105
- * @param contractAddress - the address of the contract whose storage is being read from
106
- * @param slot - the slot in the contract's storage being read from
107
- * @returns the latest value written to slot, or 0 if never written to before
108
- */ async readStorage(contractAddress, slot) {
109
- if (this.doMerkleOperations) {
110
- return await this.treesDB.storageRead(contractAddress, slot);
111
- } else {
112
- const read = await this.publicStorage.read(contractAddress, slot);
113
- this.log.trace(`Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`);
114
- return read.value;
115
- }
116
- }
117
- // TODO(4886): We currently don't silo note hashes.
118
- /**
119
- * Check if a note hash exists at the given leaf index, trace the check.
120
- *
121
- * @param contractAddress - the address of the contract whose storage is being read from
122
- * @param noteHash - the unsiloed note hash being checked
123
- * @param leafIndex - the leaf index being checked
124
- * @returns true if the note hash exists at the given leaf index, false otherwise
125
- */ async checkNoteHashExists(contractAddress, noteHash, leafIndex) {
126
- try {
127
- const gotLeafValue = await this.treesDB.getNoteHash(leafIndex);
128
- const exists = gotLeafValue.equals(noteHash);
129
- this.log.trace(`noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`);
130
- return Promise.resolve(exists);
131
- } catch (error) {
132
- // If the index is out of range, note_hash_leaf_in_range = 0 and the circuit returns false:
133
- if (error instanceof NoteHashIndexOutOfRangeError) {
134
- return Promise.resolve(false);
135
- }
136
- // Otherwise, unknown error. This is a bug.
137
- throw error;
138
- }
139
- }
140
- /**
141
- * Write a raw note hash, silo it and make it unique, then trace the write.
142
- * @param noteHash - the unsiloed note hash to write
143
- */ async writeNoteHash(contractAddress, noteHash) {
144
- this.log.trace(`noteHashes(${contractAddress}) += ${noteHash}.`);
145
- const siloedNoteHash = await siloNoteHash(contractAddress, noteHash);
146
- await this.writeSiloedNoteHash(siloedNoteHash);
147
- }
148
- /**
149
- * Write a note hash, make it unique, trace the write.
150
- * @param siloedNoteHash - the non unique note hash to write
151
- */ async writeSiloedNoteHash(siloedNoteHash) {
152
- const noteNonce = await computeNoteHashNonce(this.firstNullifier, this.trace.getNoteHashCount());
153
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, siloedNoteHash);
154
- await this.writeUniqueNoteHash(uniqueNoteHash);
155
- }
156
- /**
157
- * Write a note hash, trace the write.
158
- * @param uniqueNoteHash - the siloed unique hash to write
159
- */ async writeUniqueNoteHash(uniqueNoteHash) {
160
- this.log.trace(`noteHashes += @${uniqueNoteHash}.`);
161
- this.trace.traceNewNoteHash(uniqueNoteHash);
162
- if (this.doMerkleOperations) {
163
- await this.treesDB.writeNoteHash(uniqueNoteHash);
164
- }
165
- }
166
- /**
167
- * Check if a nullifier exists, trace the check.
168
- * @param contractAddress - address of the contract that the nullifier is associated with
169
- * @param nullifier - the unsiloed nullifier to check
170
- * @returns exists - whether the nullifier exists in the nullifier set
171
- */ async checkNullifierExists(contractAddress, nullifier) {
172
- this.log.trace(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`);
173
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
174
- return this.checkSiloedNullifierExists(siloedNullifier);
175
- }
176
- /**
177
- * Check if a siloed nullifier exists.
178
- * @param siloedNullifier - the siloed nullifier to check
179
- * @returns exists - whether the nullifier exists in the nullifier set
180
- */ async checkSiloedNullifierExists(siloedNullifier) {
181
- if (this.doMerkleOperations) {
182
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
183
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
184
- return Promise.resolve(exists);
185
- } else {
186
- const { exists, cacheHit } = await this.nullifiers.checkExists(siloedNullifier);
187
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), cacheHit=${cacheHit}`);
188
- return Promise.resolve(exists);
189
- }
190
- }
191
- /**
192
- * Write a nullifier to the nullifier set, trace the write.
193
- * @param contractAddress - address of the contract that the nullifier is associated with
194
- * @param nullifier - the unsiloed nullifier to write
195
- */ async writeNullifier(contractAddress, nullifier) {
196
- this.log.trace(`Inserting new nullifier (address=${nullifier}, nullifier=${contractAddress})`);
197
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
198
- await this.writeSiloedNullifier(siloedNullifier);
199
- }
200
- /**
201
- * Write a nullifier to the nullifier set, trace the write.
202
- * @param siloedNullifier - the siloed nullifier to write
203
- */ async writeSiloedNullifier(siloedNullifier) {
204
- this.log.trace(`Inserting siloed nullifier=${siloedNullifier}`);
205
- this.trace.traceNewNullifier(siloedNullifier);
206
- if (this.doMerkleOperations) {
207
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
208
- if (exists) {
209
- this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree!`);
210
- throw new NullifierCollisionError(`Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`);
211
- } else {
212
- await this.treesDB.writeNullifier(siloedNullifier);
213
- }
214
- } else {
215
- // Cache pending nullifiers for later access
216
- await this.nullifiers.append(siloedNullifier);
217
- }
218
- }
219
- /**
220
- * Check if an L1 to L2 message exists, trace the check.
221
- * @param msgHash - the message hash to check existence of
222
- * @param msgLeafIndex - the message leaf index to use in the check
223
- * @returns exists - whether the message exists in the L1 to L2 Messages tree
224
- */ async checkL1ToL2MessageExists(msgHash, msgLeafIndex) {
225
- try {
226
- const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
227
- const exists = valueAtIndex.equals(msgHash);
228
- this.log.trace(`l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`);
229
- return Promise.resolve(exists);
230
- } catch (error) {
231
- // If the index is out of range, l1_to_l2_msg_leaf_in_range = 0 and the circuit returns false:
232
- if (error instanceof L1ToL2MessageIndexOutOfRangeError) {
233
- return Promise.resolve(false);
234
- }
235
- // Otherwise, unknown error. This is a bug.
236
- throw error;
237
- }
238
- }
239
- /**
240
- * Write an L2 to L1 message.
241
- * @param contractAddress - L2 contract address that created this message
242
- * @param recipient - L1 contract address to send the message to.
243
- * @param content - Message content.
244
- */ writeL2ToL1Message(contractAddress, recipient, content) {
245
- this.log.trace(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`);
246
- this.trace.traceNewL2ToL1Message(contractAddress, recipient, content);
247
- }
248
- /**
249
- * Write a scoped L2 to L1 message.
250
- * @param l2ToL1Message - The L2 to L1 message to write.
251
- */ writeScopedL2ToL1Message(l2ToL1Message) {
252
- this.writeL2ToL1Message(l2ToL1Message.contractAddress, l2ToL1Message.message.recipient.toField(), l2ToL1Message.message.content);
253
- }
254
- writeDebugLog(contractAddress, level, message, fields) {
255
- this.trace.traceDebugLog(contractAddress, level, message, fields);
256
- }
257
- writeDebugLogMemoryReads(memoryReads) {
258
- this.trace.traceDebugLogMemoryReads(memoryReads);
259
- }
260
- getDebugLogMemoryReads() {
261
- return this.trace.getDebugLogMemoryReads();
262
- }
263
- getLogs() {
264
- return this.trace.getDebugLogs();
265
- }
266
- /**
267
- * Write a public log
268
- * @param contractAddress - address of the contract that emitted the log
269
- * @param log - log contents
270
- */ writePublicLog(contractAddress, log) {
271
- this.log.trace(`PublicLog(${contractAddress}) += event with ${log.length} fields.`);
272
- this.trace.tracePublicLog(contractAddress, log);
273
- }
274
- /**
275
- * Get a contract instance.
276
- * @param contractAddress - address of the contract instance to retrieve.
277
- * @returns the contract instance or undefined if it does not exist.
278
- */ async getContractInstance(contractAddress) {
279
- this.log.trace(`Getting contract instance for address ${contractAddress}`);
280
- const instanceWithAddress = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
281
- const exists = instanceWithAddress !== undefined;
282
- const instance = exists ? new SerializableContractInstance(instanceWithAddress) : undefined;
283
- if (contractAddressIsCanonical(contractAddress)) {
284
- this.log.trace(`Got canonical contract instance (address=${contractAddress}): instance=${jsonStringify(instance)}`);
285
- return instance;
286
- }
287
- // Nullifier check! We do this regardless of whether or not the instance exists,
288
- // as even for non-existence, we need to generate nullifier check hints.
289
- // This will internally decide whether to check the nullifier tree or not depending on doMerkleOperations.
290
- const nullifierExistsInTree = await this.checkNullifierExists(AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS), contractAddress.toField());
291
- assert(exists == nullifierExistsInTree, `Contract instance for address ${contractAddress} in DB: ${exists} != nullifier tree: ${nullifierExistsInTree}. This is a bug!`);
292
- if (!exists) {
293
- this.log.debug(`Contract instance NOT FOUND (address=${contractAddress})`);
294
- return undefined;
295
- }
296
- this.log.trace(`Got contract instance (address=${contractAddress}): instance=${jsonStringify(instance)}`);
297
- // All that is left is to check that the contract updatability information is correct.
298
- // That is, that the current and original contract class ids are correct.
299
- await this.checkContractUpdateInformation(instanceWithAddress);
300
- return instance;
301
- }
302
- async checkContractUpdateInformation(instance) {
303
- // If "merkle operations" are not requested, we trust the DB.
304
- // Otherwise we check that the contract updatability information is correct.
305
- // That is, that the current and original contract class ids are correct.
306
- // All failures are fatal and the simulation is not expected to be provable.
307
- if (this.doMerkleOperations) {
308
- // Conceptually, we want to do the following:
309
- // * Read a DelayedPublicMutable at the contract update slot.
310
- // * Obtain the expected current class id from the DelayedPublicMutable, at the current block.
311
- // * if expectedId == 0 then currentClassId should be original contract class id
312
- // * if expectedId != 0 then currentClassId should be expectedId
313
- //
314
- // However, we will also be checking the hash of the delayed public mutable values.
315
- // This is a bit of a leak of information, since the circuit will use it to prove
316
- // one public read instead of N of the delayed public mutable values.
317
- const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(instance.address);
318
- const readDeployerStorage = async (storageSlot)=>await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
319
- const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
320
- // NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
321
- // See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
322
- const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, readDeployerStorage);
323
- const preImage = delayedPublicMutableValues.toFields();
324
- // 1) update never scheduled: hash == 0 and preimage should be empty (but poseidon2hash(preimage) will not be 0s)
325
- if (hash.isZero()) {
326
- assert(preImage.every((f)=>f.isZero()), `Found updatability hash 0 but preimage is not empty for contract instance ${instance.address}.`);
327
- assert(instance.currentContractClassId.equals(instance.originalContractClassId), `Found updatability hash 0 for contract instance ${instance.address} but original class id ${instance.originalContractClassId} != current class id ${instance.currentContractClassId}.`);
328
- return;
329
- }
330
- // 2) At this point we know that the hash is not zero and this means that an update has at some point been scheduled.
331
- const computedHash = await poseidon2Hash(preImage);
332
- assert(hash.equals(computedHash), `Delayed public mutable values hash mismatch for contract instance ${instance.address}. Expected: ${hash}, computed: ${computedHash}`);
333
- // We now check that, depending on the current block, the current class id is correct.
334
- const expectedClassIdRaw = delayedPublicMutableValues.svc.getCurrentAt(this.timestamp).at(0);
335
- const expectedClassId = expectedClassIdRaw.isZero() ? instance.originalContractClassId : expectedClassIdRaw;
336
- assert(instance.currentContractClassId.equals(expectedClassId), `Current class id mismatch
337
- for contract instance ${instance.address}. Expected: ${expectedClassId}, current: ${instance.currentContractClassId}`);
338
- }
339
- }
340
- /**
341
- * Get a contract class.
342
- * @param classId - class id to retrieve.
343
- * @returns the contract class or undefined if it does not exist.
344
- */ async getContractClass(classId) {
345
- this.log.trace(`Getting contract class for id ${classId}`);
346
- const contractClass = await this.contractsDB.getContractClass(classId);
347
- const exists = contractClass !== undefined;
348
- let extendedClass = undefined;
349
- // Note: We currently do not generate info to check the nullifier tree, because
350
- // this is not needed for our use cases.
351
- if (exists) {
352
- this.log.trace(`Got contract class (id=${classId})`);
353
- // Extend class information with public bytecode commitment.
354
- const bytecodeCommitment = await this.contractsDB.getBytecodeCommitment(classId);
355
- assert(bytecodeCommitment, `Bytecode commitment was not found in DB for contract class (${classId}). This should not happen!`);
356
- extendedClass = {
357
- ...contractClass,
358
- publicBytecodeCommitment: bytecodeCommitment
359
- };
360
- } else {
361
- this.log.debug(`Contract class NOT FOUND (id=${classId})`);
362
- }
363
- // TODO(dbanks12): does this need to be moved to before the DB accesses as was done with writeNullifier?
364
- this.trace.traceGetContractClass(classId, exists);
365
- return extendedClass;
366
- }
367
- /**
368
- * Get a contract's bytecode from the contracts DB, also trace the contract class and instance indirectly.
369
- */ async getBytecode(contractAddress) {
370
- this.log.debug(`Getting bytecode for contract address ${contractAddress}`);
371
- const contractInstance = await this.getContractInstance(contractAddress);
372
- if (!contractInstance) {
373
- return undefined;
374
- }
375
- try {
376
- const contractClass = await this.getContractClass(contractInstance.currentContractClassId);
377
- assert(contractClass, `Contract class not found in DB, but a contract instance was found with this class ID (${contractInstance.currentContractClassId}). This should not happen!`);
378
- return contractClass.packedBytecode;
379
- } catch (error) {
380
- if (error instanceof MaxCallsToUniqueContractClassIdsError) {
381
- return undefined;
382
- }
383
- // Otherwise, unknown error. This is a bug.
384
- throw error;
385
- }
386
- }
387
- async getPublicFunctionDebugName(avmEnvironment) {
388
- return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
389
- }
390
- async getPublicFunctionSelectorAndName(avmEnvironment) {
391
- return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
392
- }
393
- async padTree(treeId, leavesToInsert) {
394
- await this.treesDB.padTree(treeId, leavesToInsert);
395
- }
396
- async getTreeSnapshots() {
397
- return await this.treesDB.getTreeSnapshots();
398
- }
399
- }
400
- function contractAddressIsCanonical(contractAddress) {
401
- return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
402
- }
@@ -1,61 +0,0 @@
1
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
-
3
- import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
4
- import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
5
- import { type Gas, gasToGasLeft } from './avm_gas.js';
6
- import { AvmMachineState } from './avm_machine_state.js';
7
- import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
8
- import type { CallData } from './calldata.js';
9
-
10
- /**
11
- * An execution context includes the information necessary to initiate AVM
12
- * execution along with all state maintained by the AVM throughout execution.
13
- */
14
- export class AvmContext {
15
- /**
16
- * Create a new AVM context
17
- * @param persistableState - Manages world state and accrued substate during execution - (caching, fetching, tracing)
18
- * @param environment - Contains constant variables provided by the kernel
19
- * @param machineState - VM state that is modified on an instruction-by-instruction basis
20
- * @returns new AvmContext instance
21
- */
22
- constructor(
23
- public persistableState: PublicPersistableStateManager,
24
- public environment: AvmExecutionEnvironment,
25
- public machineState: AvmMachineState,
26
- ) {}
27
-
28
- // This is needed to break a dependency cycle created by the CALL opcode,
29
- // which needs to create a new simulator but cannot depend directly on AvmSimulator.
30
- public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;
31
-
32
- /**
33
- * Prepare a new AVM context that will be ready for an external/nested call
34
- * - Fork the world state journal
35
- * - Derive a machine state from the current state
36
- * - E.g., gas metering is preserved but pc is reset
37
- * - Derive an execution environment from the caller/parent
38
- * - Alter address
39
- *
40
- * @param address - The contract instance to initialize a context for
41
- * @param calldata - Data/arguments for nested call
42
- * @param allocatedGas - Gas allocated for the nested call
43
- * @param callType - Type of call (CALL or STATICCALL)
44
- * @returns new AvmContext instance
45
- */
46
- public async createNestedContractCallContext(
47
- address: AztecAddress,
48
- calldata: CallData,
49
- allocatedGas: Gas,
50
- callType: 'CALL' | 'STATICCALL',
51
- ): Promise<AvmContext> {
52
- const deriveFn =
53
- callType === 'CALL'
54
- ? this.environment.deriveEnvironmentForNestedCall
55
- : this.environment.deriveEnvironmentForNestedStaticCall;
56
- const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata);
57
- const forkedWorldState = await this.persistableState.fork();
58
- const machineState = AvmMachineState.fromState(gasToGasLeft(allocatedGas));
59
- return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
60
- }
61
- }