@aztec/simulator 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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 (378) hide show
  1. package/README.md +4 -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/private/acvm/acvm.d.ts +4 -2
  6. package/dest/private/acvm/acvm.d.ts.map +1 -1
  7. package/dest/private/acvm/acvm.js +4 -3
  8. package/dest/private/acvm_native.d.ts +5 -3
  9. package/dest/private/acvm_native.d.ts.map +1 -1
  10. package/dest/private/acvm_native.js +8 -6
  11. package/dest/private/acvm_wasm.d.ts +4 -3
  12. package/dest/private/acvm_wasm.d.ts.map +1 -1
  13. package/dest/private/acvm_wasm.js +7 -5
  14. package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
  15. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/circuit_recorder.js +70 -72
  17. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
  18. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  19. package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
  20. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  21. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  22. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  23. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  24. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  25. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  26. package/dest/private/factory.d.ts +3 -3
  27. package/dest/private/factory.d.ts.map +1 -1
  28. package/dest/private/factory.js +7 -4
  29. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  30. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  31. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  32. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +2 -1
  33. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  34. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
  35. package/dest/public/avm/testing/utils.d.ts +32 -0
  36. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  37. package/dest/public/avm/{fixtures → testing}/utils.js +4 -34
  38. package/dest/public/avm_simulator.d.ts +28 -0
  39. package/dest/public/avm_simulator.d.ts.map +1 -0
  40. package/dest/public/avm_simulator.js +4 -0
  41. package/dest/public/avm_simulator_pool.d.ts +45 -0
  42. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  43. package/dest/public/avm_simulator_pool.js +197 -0
  44. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  45. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  46. package/dest/public/cdb/generated/api_types.js +314 -0
  47. package/dest/public/cdb/generated/server.d.ts +26 -0
  48. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  49. package/dest/public/cdb/generated/server.js +135 -0
  50. package/dest/public/cdb_ipc_server.d.ts +33 -0
  51. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  52. package/dest/public/cdb_ipc_server.js +153 -0
  53. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  54. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  55. package/dest/public/contracts_db_checkpoint.js +1 -1
  56. package/dest/public/executor_metrics.d.ts +1 -1
  57. package/dest/public/executor_metrics.d.ts.map +1 -1
  58. package/dest/public/executor_metrics.js +7 -2
  59. package/dest/public/fixtures/amm_test.js +4 -4
  60. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  61. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  62. package/dest/public/fixtures/bulk_test.js +33 -6
  63. package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
  64. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  65. package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
  66. package/dest/public/fixtures/index.d.ts +2 -4
  67. package/dest/public/fixtures/index.d.ts.map +1 -1
  68. package/dest/public/fixtures/index.js +1 -3
  69. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  70. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  71. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  72. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -7
  73. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  74. package/dest/public/fixtures/public_tx_simulation_tester.js +32 -15
  75. package/dest/public/fixtures/simple_contract_data_source.js +1 -1
  76. package/dest/public/fixtures/token_test.js +3 -3
  77. package/dest/public/fixtures/utils.d.ts +2 -2
  78. package/dest/public/fixtures/utils.d.ts.map +1 -1
  79. package/dest/public/fixtures/utils.js +21 -20
  80. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +11 -4
  81. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  82. package/dest/public/fuzzing/avm_fuzzer_simulator.js +24 -10
  83. package/dest/public/fuzzing/avm_simulator_bin.js +11 -8
  84. package/dest/public/index.d.ts +5 -2
  85. package/dest/public/index.d.ts.map +1 -1
  86. package/dest/public/index.js +2 -1
  87. package/dest/public/public_db_sources.d.ts +9 -5
  88. package/dest/public/public_db_sources.d.ts.map +1 -1
  89. package/dest/public/public_db_sources.js +20 -14
  90. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -7
  91. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  92. package/dest/public/public_processor/guarded_merkle_tree.js +8 -5
  93. package/dest/public/public_processor/public_processor.d.ts +17 -8
  94. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  95. package/dest/public/public_processor/public_processor.js +119 -77
  96. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  97. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  98. package/dest/public/public_processor/public_processor_metrics.js +28 -4
  99. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  100. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  101. package/dest/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.js → dumping_public_tx_simulator.js} +10 -23
  102. package/dest/public/public_tx_simulator/factories.d.ts +9 -8
  103. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  104. package/dest/public/public_tx_simulator/factories.js +9 -9
  105. package/dest/public/public_tx_simulator/index.d.ts +4 -6
  106. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  107. package/dest/public/public_tx_simulator/index.js +2 -4
  108. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +43 -71
  109. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  110. package/dest/public/public_tx_simulator/public_tx_simulator.js +99 -316
  111. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  112. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  113. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  114. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +5 -5
  115. package/dest/public/test_executor_metrics.d.ts +3 -2
  116. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  117. package/dest/public/test_executor_metrics.js +2 -2
  118. package/package.json +22 -19
  119. package/src/client.ts +0 -2
  120. package/src/private/acvm/acvm.ts +4 -3
  121. package/src/private/acvm_native.ts +11 -5
  122. package/src/private/acvm_wasm.ts +11 -4
  123. package/src/private/circuit_recording/circuit_recorder.ts +89 -81
  124. package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
  125. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  126. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  127. package/src/private/factory.ts +7 -4
  128. package/src/public/avm/testing/account_proof.json +553 -0
  129. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  130. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
  131. package/src/public/avm/{fixtures → testing}/utils.ts +4 -40
  132. package/src/public/avm_simulator.ts +29 -0
  133. package/src/public/avm_simulator_pool.ts +226 -0
  134. package/src/public/cdb/generated/api_types.ts +457 -0
  135. package/src/public/cdb/generated/server.ts +109 -0
  136. package/src/public/cdb_ipc_server.ts +197 -0
  137. package/src/public/contracts_db_checkpoint.ts +1 -1
  138. package/src/public/executor_metrics.ts +4 -1
  139. package/src/public/fixtures/amm_test.ts +4 -4
  140. package/src/public/fixtures/bulk_test.ts +31 -6
  141. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  142. package/src/public/fixtures/index.ts +1 -3
  143. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  144. package/src/public/fixtures/public_tx_simulation_tester.ts +45 -18
  145. package/src/public/fixtures/simple_contract_data_source.ts +1 -1
  146. package/src/public/fixtures/token_test.ts +3 -3
  147. package/src/public/fixtures/utils.ts +23 -24
  148. package/src/public/fuzzing/avm_fuzzer_simulator.ts +26 -11
  149. package/src/public/fuzzing/avm_simulator_bin.ts +14 -6
  150. package/src/public/index.ts +7 -3
  151. package/src/public/public_db_sources.ts +36 -19
  152. package/src/public/public_processor/guarded_merkle_tree.ts +11 -8
  153. package/src/public/public_processor/public_processor.ts +166 -97
  154. package/src/public/public_processor/public_processor_metrics.ts +22 -4
  155. package/src/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.ts → dumping_public_tx_simulator.ts} +17 -31
  156. package/src/public/public_tx_simulator/factories.ts +31 -11
  157. package/src/public/public_tx_simulator/index.ts +6 -5
  158. package/src/public/public_tx_simulator/public_tx_simulator.ts +142 -470
  159. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  160. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +5 -5
  161. package/src/public/test_executor_metrics.ts +3 -3
  162. package/dest/public/avm/avm_context.d.ts +0 -41
  163. package/dest/public/avm/avm_context.d.ts.map +0 -1
  164. package/dest/public/avm/avm_context.js +0 -44
  165. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  166. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  167. package/dest/public/avm/avm_contract_call_result.js +0 -54
  168. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  169. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  170. package/dest/public/avm/avm_execution_environment.js +0 -33
  171. package/dest/public/avm/avm_gas.d.ts +0 -44
  172. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  173. package/dest/public/avm/avm_gas.js +0 -195
  174. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  175. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  176. package/dest/public/avm/avm_machine_state.js +0 -109
  177. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  178. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  179. package/dest/public/avm/avm_memory_types.js +0 -351
  180. package/dest/public/avm/avm_simulator.d.ts +0 -40
  181. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  182. package/dest/public/avm/avm_simulator.js +0 -191
  183. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  184. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  185. package/dest/public/avm/avm_simulator_interface.js +0 -3
  186. package/dest/public/avm/errors.d.ts +0 -104
  187. package/dest/public/avm/errors.d.ts.map +0 -1
  188. package/dest/public/avm/errors.js +0 -141
  189. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  190. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  191. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -83
  192. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  193. package/dest/public/avm/fixtures/initializers.d.ts +0 -42
  194. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  195. package/dest/public/avm/fixtures/initializers.js +0 -44
  196. package/dest/public/avm/fixtures/utils.d.ts +0 -39
  197. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  198. package/dest/public/avm/index.d.ts +0 -2
  199. package/dest/public/avm/index.d.ts.map +0 -1
  200. package/dest/public/avm/index.js +0 -1
  201. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  202. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  203. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  204. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  205. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  206. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  207. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -49
  208. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  209. package/dest/public/avm/opcodes/arithmetic.js +0 -97
  210. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  211. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  212. package/dest/public/avm/opcodes/bitwise.js +0 -99
  213. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  214. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  215. package/dest/public/avm/opcodes/comparators.js +0 -43
  216. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  217. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  218. package/dest/public/avm/opcodes/contract.js +0 -65
  219. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  220. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  221. package/dest/public/avm/opcodes/control_flow.js +0 -107
  222. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  223. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  224. package/dest/public/avm/opcodes/conversion.js +0 -333
  225. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  226. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  227. package/dest/public/avm/opcodes/ec_add.js +0 -93
  228. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  229. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  230. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  231. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  232. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  233. package/dest/public/avm/opcodes/external_calls.js +0 -210
  234. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  235. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  236. package/dest/public/avm/opcodes/hashing.js +0 -119
  237. package/dest/public/avm/opcodes/index.d.ts +0 -16
  238. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  239. package/dest/public/avm/opcodes/index.js +0 -15
  240. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  241. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  242. package/dest/public/avm/opcodes/instruction.js +0 -95
  243. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  244. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  245. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  246. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  247. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  248. package/dest/public/avm/opcodes/memory.js +0 -257
  249. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  250. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  251. package/dest/public/avm/opcodes/misc.js +0 -73
  252. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  253. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  254. package/dest/public/avm/opcodes/storage.js +0 -68
  255. package/dest/public/avm/revert_reason.d.ts +0 -18
  256. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  257. package/dest/public/avm/revert_reason.js +0 -39
  258. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  259. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  260. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  261. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  262. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  263. package/dest/public/avm/serialization/bytecode_serialization.js +0 -336
  264. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  265. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  266. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  267. package/dest/public/avm/test_utils.d.ts +0 -15
  268. package/dest/public/avm/test_utils.d.ts.map +0 -1
  269. package/dest/public/avm/test_utils.js +0 -44
  270. package/dest/public/debug_fn_name.d.ts +0 -18
  271. package/dest/public/debug_fn_name.d.ts.map +0 -1
  272. package/dest/public/debug_fn_name.js +0 -35
  273. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -12
  274. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  275. package/dest/public/fixtures/custom_bytecode_tests.js +0 -174
  276. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -4
  277. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  278. package/dest/public/fixtures/minimal_public_tx.js +0 -19
  279. package/dest/public/fixtures/opcode_spammer.d.ts +0 -123
  280. package/dest/public/fixtures/opcode_spammer.d.ts.map +0 -1
  281. package/dest/public/fixtures/opcode_spammer.js +0 -1681
  282. package/dest/public/hinting_db_sources.d.ts +0 -80
  283. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  284. package/dest/public/hinting_db_sources.js +0 -355
  285. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -18
  286. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
  287. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -98
  288. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -53
  289. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  290. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -132
  291. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +0 -42
  292. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +0 -1
  293. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +0 -86
  294. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +0 -30
  295. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +0 -1
  296. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +0 -171
  297. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +0 -22
  298. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +0 -1
  299. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -31
  300. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  301. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  302. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -130
  303. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  304. package/dest/public/public_tx_simulator/public_tx_context.js +0 -300
  305. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  306. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  307. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -415
  308. package/dest/public/side_effect_trace.d.ts +0 -87
  309. package/dest/public/side_effect_trace.d.ts.map +0 -1
  310. package/dest/public/side_effect_trace.js +0 -199
  311. package/dest/public/side_effect_trace_interface.d.ts +0 -22
  312. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  313. package/dest/public/side_effect_trace_interface.js +0 -1
  314. package/dest/public/state_manager/index.d.ts +0 -2
  315. package/dest/public/state_manager/index.d.ts.map +0 -1
  316. package/dest/public/state_manager/index.js +0 -1
  317. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  318. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  319. package/dest/public/state_manager/nullifiers.js +0 -92
  320. package/dest/public/state_manager/public_storage.d.ts +0 -66
  321. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  322. package/dest/public/state_manager/public_storage.js +0 -145
  323. package/dest/public/state_manager/state_manager.d.ts +0 -164
  324. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  325. package/dest/public/state_manager/state_manager.js +0 -395
  326. package/src/public/avm/avm_context.ts +0 -61
  327. package/src/public/avm/avm_contract_call_result.ts +0 -67
  328. package/src/public/avm/avm_execution_environment.ts +0 -46
  329. package/src/public/avm/avm_gas.ts +0 -183
  330. package/src/public/avm/avm_machine_state.ts +0 -169
  331. package/src/public/avm/avm_memory_types.ts +0 -436
  332. package/src/public/avm/avm_simulator.ts +0 -276
  333. package/src/public/avm/avm_simulator_interface.ts +0 -8
  334. package/src/public/avm/errors.ts +0 -177
  335. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -116
  336. package/src/public/avm/fixtures/initializers.ts +0 -102
  337. package/src/public/avm/index.ts +0 -1
  338. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  339. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  340. package/src/public/avm/opcodes/arithmetic.ts +0 -129
  341. package/src/public/avm/opcodes/bitwise.ts +0 -113
  342. package/src/public/avm/opcodes/comparators.ts +0 -55
  343. package/src/public/avm/opcodes/contract.ts +0 -75
  344. package/src/public/avm/opcodes/control_flow.ts +0 -123
  345. package/src/public/avm/opcodes/conversion.ts +0 -104
  346. package/src/public/avm/opcodes/ec_add.ts +0 -105
  347. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  348. package/src/public/avm/opcodes/external_calls.ts +0 -261
  349. package/src/public/avm/opcodes/hashing.ts +0 -151
  350. package/src/public/avm/opcodes/index.ts +0 -15
  351. package/src/public/avm/opcodes/instruction.ts +0 -136
  352. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  353. package/src/public/avm/opcodes/memory.ts +0 -293
  354. package/src/public/avm/opcodes/misc.ts +0 -102
  355. package/src/public/avm/opcodes/storage.ts +0 -87
  356. package/src/public/avm/revert_reason.ts +0 -58
  357. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  358. package/src/public/avm/serialization/bytecode_serialization.ts +0 -215
  359. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  360. package/src/public/avm/test_utils.ts +0 -64
  361. package/src/public/debug_fn_name.ts +0 -50
  362. package/src/public/fixtures/custom_bytecode_tests.ts +0 -228
  363. package/src/public/fixtures/minimal_public_tx.ts +0 -26
  364. package/src/public/fixtures/opcode_spammer.ts +0 -1725
  365. package/src/public/hinting_db_sources.ts +0 -607
  366. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -121
  367. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -208
  368. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +0 -132
  369. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +0 -237
  370. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -105
  371. package/src/public/public_tx_simulator/public_tx_context.ts +0 -477
  372. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  373. package/src/public/side_effect_trace.ts +0 -290
  374. package/src/public/side_effect_trace_interface.ts +0 -28
  375. package/src/public/state_manager/index.ts +0 -1
  376. package/src/public/state_manager/nullifiers.ts +0 -103
  377. package/src/public/state_manager/public_storage.ts +0 -174
  378. package/src/public/state_manager/state_manager.ts +0 -546
@@ -1,436 +0,0 @@
1
- import {
2
- MEM_TAG_FF,
3
- MEM_TAG_U1,
4
- MEM_TAG_U8,
5
- MEM_TAG_U16,
6
- MEM_TAG_U32,
7
- MEM_TAG_U64,
8
- MEM_TAG_U128,
9
- } from '@aztec/constants';
10
- import { toBufferBE } from '@aztec/foundation/bigint-buffer';
11
- import { Fr } from '@aztec/foundation/curves/bn254';
12
- import { type Logger, createLogger } from '@aztec/foundation/log';
13
- import type { FunctionsOf } from '@aztec/foundation/types';
14
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
-
16
- import { strict as assert } from 'assert';
17
-
18
- import { InvalidTagValueError, MemorySliceOutOfRangeError, TagCheckError } from './errors.js';
19
-
20
- /** MemoryValue gathers the common operations for all memory types. */
21
- export abstract class MemoryValue {
22
- public abstract add(rhs: MemoryValue): MemoryValue;
23
- public abstract sub(rhs: MemoryValue): MemoryValue;
24
- public abstract mul(rhs: MemoryValue): MemoryValue;
25
- public abstract div(rhs: MemoryValue): MemoryValue;
26
-
27
- public abstract equals(rhs: MemoryValue): boolean;
28
- public abstract lt(rhs: MemoryValue): boolean;
29
-
30
- // We need this to be able to build an instance of the subclasses.
31
- public abstract build(n: bigint): MemoryValue;
32
-
33
- // Use sparingly.
34
- public abstract toBigInt(): bigint;
35
- public getTag(): TypeTag {
36
- return TaggedMemory.getTag(this);
37
- }
38
-
39
- // To Buffer
40
- public abstract toBuffer(): Buffer;
41
-
42
- // To field
43
- public toFr(): Fr {
44
- return new Fr(this.toBigInt());
45
- }
46
-
47
- public toAztecAddress(): AztecAddress {
48
- return new AztecAddress(this.toFr());
49
- }
50
-
51
- // To number. Throws if exceeds max safe int.
52
- public toNumber(): number {
53
- return this.toFr().toNumber();
54
- }
55
-
56
- public toString(): string {
57
- return `${this.constructor.name}(0x${this.toBigInt().toString(16)})`;
58
- }
59
- }
60
-
61
- /** IntegralValue gathers the common operations for all integral memory types. */
62
- export abstract class IntegralValue extends MemoryValue {
63
- public abstract shl(rhs: IntegralValue): IntegralValue;
64
- public abstract shr(rhs: IntegralValue): IntegralValue;
65
- public abstract and(rhs: IntegralValue): IntegralValue;
66
- public abstract or(rhs: IntegralValue): IntegralValue;
67
- public abstract xor(rhs: IntegralValue): IntegralValue;
68
- public abstract not(): IntegralValue;
69
- }
70
-
71
- /**
72
- * This function creates a class for unsigned integers of a given number of bits.
73
- * In TypeScript terms, it's a class mixin.
74
- **/
75
- function UnsignedIntegerClassFactory(bits: number) {
76
- return class NewUintClass extends IntegralValue {
77
- static readonly bits: number = bits;
78
- static readonly mod: bigint = 1n << BigInt(bits);
79
- static readonly bitmask: bigint = this.mod - 1n;
80
- public readonly n: bigint; // Cannot be private due to TS limitations.
81
-
82
- public constructor(n: bigint | number) {
83
- super();
84
- this.n = BigInt(n);
85
- assert(n >= 0n, `${this.constructor.name} cannot handle negative values: ${n}.`);
86
- assert(n < NewUintClass.mod, `Value ${n} is too large for ${this.constructor.name}.`);
87
- }
88
-
89
- public build(n: bigint): NewUintClass {
90
- return new this.constructor.prototype.constructor(n);
91
- }
92
-
93
- public add(rhs: NewUintClass): NewUintClass {
94
- return this.build((this.n + rhs.n) & NewUintClass.bitmask);
95
- }
96
-
97
- public sub(rhs: NewUintClass): NewUintClass {
98
- const res: bigint = this.n - rhs.n;
99
- return this.build(res >= 0 ? res : res + NewUintClass.mod);
100
- }
101
-
102
- public mul(rhs: NewUintClass): NewUintClass {
103
- return this.build((this.n * rhs.n) & NewUintClass.bitmask);
104
- }
105
-
106
- public div(rhs: NewUintClass): NewUintClass {
107
- return this.build(this.n / rhs.n);
108
- }
109
-
110
- // No sign extension.
111
- public shr(rhs: NewUintClass): NewUintClass {
112
- // Note that this.n is >= 0 by class invariant.
113
- return this.build(this.n >> rhs.n);
114
- }
115
-
116
- public shl(rhs: NewUintClass): NewUintClass {
117
- const shiftAmount = rhs.n;
118
- const bitSize = BigInt(NewUintClass.bits);
119
-
120
- // Shifting by more than the bit size always results in 0
121
- if (shiftAmount >= bitSize) {
122
- return this.build(0n);
123
- }
124
-
125
- return this.build((this.n << shiftAmount) & NewUintClass.bitmask);
126
- }
127
-
128
- public and(rhs: NewUintClass): NewUintClass {
129
- return this.build(this.n & rhs.n);
130
- }
131
-
132
- public or(rhs: NewUintClass): NewUintClass {
133
- return this.build(this.n | rhs.n);
134
- }
135
-
136
- public xor(rhs: NewUintClass): NewUintClass {
137
- return this.build(this.n ^ rhs.n);
138
- }
139
-
140
- public not(): NewUintClass {
141
- return this.build(~this.n & NewUintClass.bitmask);
142
- }
143
-
144
- public equals(rhs: NewUintClass): boolean {
145
- return this.n === rhs.n;
146
- }
147
-
148
- public lt(rhs: NewUintClass): boolean {
149
- return this.n < rhs.n;
150
- }
151
-
152
- public toBigInt(): bigint {
153
- return this.n;
154
- }
155
-
156
- public toBuffer(): Buffer {
157
- if (bits < 8) {
158
- return toBufferBE(this.n, 1);
159
- }
160
- return toBufferBE(this.n, bits / 8);
161
- }
162
- };
163
- }
164
-
165
- // Now we can create the classes for each unsigned integer type.
166
- // We extend instead of just assigning so that the class has the right name.
167
- // Otherwise they are all called "NewUintClass".
168
- export class Uint1 extends UnsignedIntegerClassFactory(1) {}
169
- export class Uint8 extends UnsignedIntegerClassFactory(8) {}
170
- export class Uint16 extends UnsignedIntegerClassFactory(16) {}
171
- export class Uint32 extends UnsignedIntegerClassFactory(32) {}
172
- export class Uint64 extends UnsignedIntegerClassFactory(64) {}
173
- export class Uint128 extends UnsignedIntegerClassFactory(128) {}
174
-
175
- export class Field extends MemoryValue {
176
- public static readonly MODULUS: bigint = Fr.MODULUS;
177
- private readonly rep: Fr;
178
-
179
- constructor(v: number | bigint | Fr | Buffer) {
180
- super();
181
- this.rep = new Fr(v);
182
- }
183
-
184
- public build(n: bigint): Field {
185
- return new Field(n);
186
- }
187
-
188
- public add(rhs: Field): Field {
189
- return new Field(this.rep.add(rhs.rep));
190
- }
191
-
192
- public sub(rhs: Field): Field {
193
- return new Field(this.rep.sub(rhs.rep));
194
- }
195
-
196
- public mul(rhs: Field): Field {
197
- return new Field(this.rep.mul(rhs.rep));
198
- }
199
-
200
- // Euclidean division.
201
- public div(rhs: Field): Field {
202
- return new Field(this.rep.ediv(rhs.rep));
203
- }
204
-
205
- // Field division.
206
- public fdiv(rhs: Field): Field {
207
- return new Field(this.rep.div(rhs.rep));
208
- }
209
-
210
- public equals(rhs: Field): boolean {
211
- return this.rep.equals(rhs.rep);
212
- }
213
-
214
- public lt(rhs: Field): boolean {
215
- return this.rep.lt(rhs.rep);
216
- }
217
-
218
- public toBigInt(): bigint {
219
- return this.rep.toBigInt();
220
- }
221
-
222
- public toBuffer(): Buffer {
223
- return this.rep.toBuffer();
224
- }
225
- }
226
-
227
- export enum TypeTag {
228
- FIELD = MEM_TAG_FF,
229
- UINT1 = MEM_TAG_U1,
230
- UINT8 = MEM_TAG_U8,
231
- UINT16 = MEM_TAG_U16,
232
- UINT32 = MEM_TAG_U32,
233
- UINT64 = MEM_TAG_U64,
234
- UINT128 = MEM_TAG_U128,
235
- INVALID = MEM_TAG_U128 + 1,
236
- }
237
-
238
- // Lazy interface definition for tagged memory
239
- export type TaggedMemoryInterface = FunctionsOf<TaggedMemory>;
240
-
241
- export class TaggedMemory implements TaggedMemoryInterface {
242
- static readonly log: Logger = createLogger('simulator:avm:memory');
243
-
244
- // Whether to track and validate memory accesses for each instruction.
245
- static readonly TRACK_MEMORY_ACCESSES = process.env.NODE_ENV === 'test';
246
-
247
- // Memory is modelled by a map with key type being number.
248
- // We however restrict the keys to be non-negative integers smaller than
249
- // MAX_MEMORY_SIZE.
250
- static readonly MAX_MEMORY_SIZE = Number(1n << 32n);
251
- private _mem: Map<number, MemoryValue>;
252
-
253
- constructor() {
254
- this._mem = new Map<number, MemoryValue>();
255
- }
256
-
257
- public getMaxMemorySize(): number {
258
- return TaggedMemory.MAX_MEMORY_SIZE;
259
- }
260
-
261
- public get(offset: number): MemoryValue {
262
- return this.getAs<MemoryValue>(offset);
263
- }
264
-
265
- public getAs<T>(offset: number): T {
266
- assert(Number.isInteger(offset) && offset < TaggedMemory.MAX_MEMORY_SIZE);
267
- const word = this._mem.get(offset);
268
- //TaggedMemory.log.trace(`Memory read: ${offset} -> ${word}`);
269
- if (word === undefined) {
270
- TaggedMemory.log.debug(`WARNING: Memory at offset ${offset} is undefined!`);
271
- return new Field(0) as T;
272
- }
273
- return word as T;
274
- }
275
-
276
- public getSlice(offset: number, size: number): MemoryValue[] {
277
- assert(Number.isInteger(offset) && Number.isInteger(size));
278
-
279
- if (offset + size > TaggedMemory.MAX_MEMORY_SIZE) {
280
- throw new MemorySliceOutOfRangeError(offset, size);
281
- }
282
-
283
- const slice = new Array<MemoryValue>(size);
284
-
285
- for (let i = 0; i < size; i++) {
286
- slice[i] = this._mem.get(offset + i) ?? new Field(0);
287
- }
288
-
289
- TaggedMemory.log.trace(`getSlice(${offset}, ${size}) = ${slice}`);
290
- return slice;
291
- }
292
-
293
- public getSliceAs<T>(offset: number, size: number): T[] {
294
- return this.getSlice(offset, size) as T[];
295
- }
296
-
297
- public getSliceTags(offset: number, size: number): TypeTag[] {
298
- return this.getSlice(offset, size).map(TaggedMemory.getTag);
299
- }
300
-
301
- public set(offset: number, v: MemoryValue) {
302
- assert(Number.isInteger(offset) && offset < TaggedMemory.MAX_MEMORY_SIZE);
303
- this._mem.set(offset, v);
304
- //TaggedMemory.log.trace(`Memory write: ${offset} <- ${v}`);
305
- }
306
-
307
- public setSlice(offset: number, slice: MemoryValue[]) {
308
- assert(Number.isInteger(offset));
309
-
310
- if (offset + slice.length > TaggedMemory.MAX_MEMORY_SIZE) {
311
- throw new MemorySliceOutOfRangeError(offset, slice.length);
312
- }
313
-
314
- slice.forEach((element, idx) => {
315
- this._mem.set(offset + idx, element);
316
- });
317
- TaggedMemory.log.trace(`setSlice(${offset}, ${slice})`);
318
- }
319
-
320
- public getTag(offset: number): TypeTag {
321
- assert(Number.isInteger(offset) && offset < TaggedMemory.MAX_MEMORY_SIZE);
322
- return TaggedMemory.getTag(this._mem.get(offset));
323
- }
324
-
325
- /**
326
- * Check that the memory at the given offset matches the specified tag.
327
- */
328
- public checkTag(tag: TypeTag, offset: number) {
329
- const gotTag = this.getTag(offset);
330
- if (gotTag !== tag) {
331
- throw TagCheckError.forOffset(offset, TypeTag[gotTag], TypeTag[tag]);
332
- }
333
- }
334
-
335
- public static isValidMemoryAddressTag(tag: TypeTag) {
336
- return tag === TypeTag.UINT32;
337
- }
338
-
339
- public static checkIsIntegralTag(tag: TypeTag) {
340
- if (!INTEGRAL_TAGS.has(tag)) {
341
- throw TagCheckError.forTag(TypeTag[tag], 'integral');
342
- }
343
- }
344
-
345
- public static checkIsValidTag(tagNumber: number) {
346
- if (!VALID_TAGS.has(tagNumber)) {
347
- throw new InvalidTagValueError(tagNumber);
348
- }
349
- }
350
-
351
- /**
352
- * Check tags for memory at all of the specified offsets.
353
- */
354
- public checkTags(tag: TypeTag, ...offsets: number[]) {
355
- for (const offset of offsets) {
356
- this.checkTag(tag, offset);
357
- }
358
- }
359
-
360
- /**
361
- * Check that all tags at the given offsets are the same.
362
- */
363
- public checkTagsAreSame(offset0: number, offset1: number) {
364
- const tag0 = this.getTag(offset0);
365
- this.checkTag(tag0, offset1);
366
- }
367
-
368
- /**
369
- * Check tags for all memory in the specified range.
370
- */
371
- public checkTagsRange(tag: TypeTag, startOffset: number, size: number) {
372
- for (let offset = startOffset; offset < startOffset + size; offset++) {
373
- this.checkTag(tag, offset);
374
- }
375
- }
376
-
377
- public static getTag(v: MemoryValue | undefined): TypeTag {
378
- if (v === undefined) {
379
- return TypeTag.FIELD; // uninitialized memory is Field(0)
380
- } else {
381
- return TAG_FOR_MEM_VAL.get(v.constructor.name) ?? TypeTag.INVALID;
382
- }
383
- }
384
-
385
- // Truncates the value to fit the type.
386
- public static buildFromTagTruncating(v: bigint | number, tag: TypeTag): MemoryValue {
387
- v = BigInt(v);
388
- switch (tag) {
389
- case TypeTag.FIELD:
390
- return new Field(v);
391
- case TypeTag.UINT1:
392
- return new Uint1(v & 1n);
393
- case TypeTag.UINT8:
394
- return new Uint8(v & ((1n << 8n) - 1n));
395
- case TypeTag.UINT16:
396
- return new Uint16(v & ((1n << 16n) - 1n));
397
- case TypeTag.UINT32:
398
- return new Uint32(v & ((1n << 32n) - 1n));
399
- case TypeTag.UINT64:
400
- return new Uint64(v & ((1n << 64n) - 1n));
401
- case TypeTag.UINT128:
402
- return new Uint128(v & ((1n << 128n) - 1n));
403
- default:
404
- throw new InvalidTagValueError(tag);
405
- }
406
- }
407
- }
408
-
409
- const TAG_FOR_MEM_VAL = new Map<string, TypeTag>([
410
- ['Field', TypeTag.FIELD],
411
- ['Uint1', TypeTag.UINT1],
412
- ['Uint8', TypeTag.UINT8],
413
- ['Uint16', TypeTag.UINT16],
414
- ['Uint32', TypeTag.UINT32],
415
- ['Uint64', TypeTag.UINT64],
416
- ['Uint128', TypeTag.UINT128],
417
- ]);
418
-
419
- const VALID_TAGS = new Set([
420
- TypeTag.FIELD,
421
- TypeTag.UINT1,
422
- TypeTag.UINT8,
423
- TypeTag.UINT16,
424
- TypeTag.UINT32,
425
- TypeTag.UINT64,
426
- TypeTag.UINT128,
427
- ]);
428
-
429
- const INTEGRAL_TAGS = new Set([
430
- TypeTag.UINT1,
431
- TypeTag.UINT8,
432
- TypeTag.UINT16,
433
- TypeTag.UINT32,
434
- TypeTag.UINT64,
435
- TypeTag.UINT128,
436
- ]);
@@ -1,276 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
3
- import { Timer } from '@aztec/foundation/timer';
4
- import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
5
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import type { GlobalVariables } from '@aztec/stdlib/tx';
7
-
8
- import { strict as assert } from 'assert';
9
-
10
- import { CheckedPublicExecutionError } from '../public_errors.js';
11
- import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
12
- import { AvmContext } from './avm_context.js';
13
- import { AvmContractCallResult } from './avm_contract_call_result.js';
14
- import { AvmExecutionEnvironment } from './avm_execution_environment.js';
15
- import type { Gas } from './avm_gas.js';
16
- import { AvmMachineState } from './avm_machine_state.js';
17
- import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
18
- import { AvmRevertReason, InvalidProgramCounterError } from './errors.js';
19
- import type { Instruction } from './opcodes/instruction.js';
20
- import { revertReasonFromExceptionalHalt, revertReasonFromExplicitRevert } from './revert_reason.js';
21
- import {
22
- INSTRUCTION_SET,
23
- type InstructionSet,
24
- decodeInstructionFromBytecode,
25
- } from './serialization/bytecode_serialization.js';
26
-
27
- type OpcodeTally = {
28
- count: number;
29
- gas: Gas;
30
- };
31
-
32
- export class AvmSimulator implements AvmSimulatorInterface {
33
- private log: Logger;
34
- private bytecode: Buffer | undefined;
35
- private opcodeTallies: Map<string, OpcodeTally> = new Map();
36
- // maps pc to [instr, bytesRead]
37
- private deserializedInstructionsCache: Map<number, [Instruction, number]> = new Map();
38
-
39
- private tallyPrintFunction = () => {};
40
- private tallyInstructionFunction = (_b: string, _c: Gas) => {};
41
-
42
- // Test Purposes only: Logger will not have the proper function name. Use this constructor for testing purposes
43
- // only. Otherwise, use build() below.
44
- constructor(
45
- private context: AvmContext,
46
- private instructionSet: InstructionSet = INSTRUCTION_SET,
47
- enableTallying = false,
48
- ) {
49
- // This will be used by the CALL opcode to create a new simulator. It is required to
50
- // avoid a dependency cycle.
51
- context.provideSimulator = AvmSimulator.build;
52
- this.log = createLogger(`simulator:avm(calldata[0]: ${context.environment.calldata[0]})`);
53
- // Turn on tallying if explicitly enabled or if trace logging
54
- if (enableTallying || this.log.isLevelEnabled('trace')) {
55
- this.tallyPrintFunction = this.printOpcodeTallies;
56
- this.tallyInstructionFunction = this.tallyInstruction;
57
- }
58
- }
59
-
60
- // Factory to have a proper function name in the logger. Retrieving the name is asynchronous and
61
- // cannot be done as part of the constructor.
62
- public static async build(context: AvmContext): Promise<AvmSimulator> {
63
- const simulator = new AvmSimulator(context);
64
- const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
65
- simulator.log = createLogger(`simulator:avm(f:${fnName})`);
66
-
67
- return simulator;
68
- }
69
-
70
- public static async create(
71
- stateManager: PublicPersistableStateManager,
72
- address: AztecAddress,
73
- sender: AztecAddress,
74
- transactionFee: Fr,
75
- globals: GlobalVariables,
76
- isStaticCall: boolean,
77
- calldata: Fr[],
78
- allocatedGas: Gas,
79
- config: PublicSimulatorConfig,
80
- ) {
81
- const avmExecutionEnv = new AvmExecutionEnvironment(
82
- address,
83
- sender,
84
- /*contractCallDepth=*/ Fr.zero(),
85
- transactionFee,
86
- globals,
87
- isStaticCall,
88
- calldata,
89
- config,
90
- );
91
-
92
- const avmMachineState = new AvmMachineState(allocatedGas);
93
- const avmContext = new AvmContext(stateManager, avmExecutionEnv, avmMachineState);
94
- return await AvmSimulator.build(avmContext);
95
- }
96
-
97
- /**
98
- * Fetch the bytecode and execute it in the current context.
99
- */
100
- public async execute(): Promise<AvmContractCallResult> {
101
- const bytecode = await this.context.persistableState.getBytecode(this.context.environment.address);
102
- // getBytecode returns undefined if bytecode is not found or if the limit of contract calls to unique class IDs is reached.
103
- // If it throws an error that reaches this point, it is a bug.
104
-
105
- if (!bytecode) {
106
- return await this.handleFailureToRetrieveBytecode(
107
- `No bytecode found. Contract is not deployed, or limit encountered for max calls to unique contract class IDs. Contract address: ${this.context.environment.address}. Reverting...`,
108
- );
109
- }
110
-
111
- return await this.executeBytecode(bytecode);
112
- }
113
-
114
- /**
115
- * Return the bytecode used for execution, if any.
116
- */
117
- public getBytecode(): Buffer | undefined {
118
- return this.bytecode;
119
- }
120
-
121
- /**
122
- * Executes the provided bytecode in the current context.
123
- * This method is useful for testing and debugging.
124
- */
125
- public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
126
- const timer = new Timer();
127
- assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");
128
-
129
- this.bytecode = bytecode;
130
- let instructionName = 'NONE'; // This is used for logging purposes
131
-
132
- const { machineState } = this.context;
133
- const callStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
134
- try {
135
- // Execute instruction pointed to by the current program counter
136
- // continuing until the machine state signifies a halt
137
- while (!machineState.getHalted()) {
138
- // Get the instruction from cache, or deserialize for the first time
139
- let cachedInstruction = this.deserializedInstructionsCache.get(machineState.pc);
140
-
141
- if (cachedInstruction === undefined) {
142
- cachedInstruction = decodeInstructionFromBytecode(bytecode, machineState.pc, this.instructionSet);
143
- this.deserializedInstructionsCache.set(machineState.pc, cachedInstruction);
144
- }
145
- const [instruction, bytesRead] = cachedInstruction;
146
-
147
- const instrStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
148
-
149
- if (this.log.isLevelEnabled('trace')) {
150
- // Skip this entirely to avoid toStringing etc if trace is not enabled
151
- this.log.trace(
152
- `[PC:${machineState.pc}] [IC:${machineState.instrCounter}] ${instruction.toString()} (gasLeft l2=${
153
- machineState.l2GasLeft
154
- } da=${machineState.daGasLeft})`,
155
- );
156
- }
157
- machineState.nextPc = machineState.pc + bytesRead;
158
-
159
- instructionName = instruction.constructor.name;
160
- // Execute the instruction.
161
- // Normal returns and reverts will return normally here.
162
- // "Exceptional halts" will throw.
163
- await instruction.execute(this.context);
164
- if (!instruction.handlesPC()) {
165
- // Increment PC if the instruction doesn't handle it itself
166
- machineState.pc += bytesRead;
167
- }
168
-
169
- machineState.instrCounter++;
170
-
171
- // gas used by this instruction - used for profiling/tallying
172
- const gasUsed: Gas = {
173
- l2Gas: instrStartGas.l2Gas - machineState.l2GasLeft,
174
- daGas: instrStartGas.daGas - machineState.daGasLeft,
175
- };
176
- this.tallyInstructionFunction(instruction.constructor.name, gasUsed);
177
-
178
- if (machineState.pc >= bytecode.length) {
179
- this.log.warn('Passed end of program');
180
- throw new InvalidProgramCounterError(machineState.pc, /*max=*/ bytecode.length - 1);
181
- }
182
- }
183
-
184
- const output = machineState.getOutput();
185
- const reverted = machineState.getReverted();
186
- const revertReason = reverted ? await revertReasonFromExplicitRevert(output, this.context) : undefined;
187
- const results = new AvmContractCallResult(
188
- reverted,
189
- output,
190
- machineState.gasLeft,
191
- revertReason,
192
- machineState.instrCounter,
193
- );
194
- this.log.debug(`Context execution results: ${results.toString()}`);
195
- const totalGasUsed: Gas = {
196
- l2Gas: callStartGas.l2Gas - machineState.l2GasLeft,
197
- daGas: callStartGas.daGas - machineState.daGasLeft,
198
- };
199
- this.log.debug(`Executed ${machineState.instrCounter} instructions and consumed ${totalGasUsed.l2Gas} L2 Gas`);
200
-
201
- this.tallyPrintFunction();
202
-
203
- this.log.debug(`Core AVM simulation took ${timer.ms()}ms`);
204
-
205
- // Return results for processing by calling context
206
- return results;
207
- } catch (err: any) {
208
- this.log.info(
209
- `Exceptional halt (revert by something other than REVERT opcode) for instruction
210
- ${instructionName} at pc ${machineState.pc} and instruction counter ${machineState.instrCounter}`,
211
- );
212
- if (!(err instanceof CheckedPublicExecutionError)) {
213
- this.log.error(`Unchecked/unknown error thrown by AVM. This is a bug. Error: ${err}`);
214
- throw err;
215
- }
216
-
217
- const revertReason = await revertReasonFromExceptionalHalt(err, this.context);
218
- // Exceptional halts consume all allocated gas
219
- const noGasLeft = { l2Gas: 0, daGas: 0 };
220
- // Note: "exceptional halts" cannot return data, hence [].
221
- const results = new AvmContractCallResult(
222
- /*reverted=*/ true,
223
- /*output=*/ [],
224
- noGasLeft,
225
- revertReason,
226
- machineState.instrCounter,
227
- );
228
- this.log.debug(`Context execution results: ${results.toString()}`);
229
-
230
- this.tallyPrintFunction();
231
- // Return results for processing by calling context
232
- return results;
233
- }
234
- }
235
-
236
- private async handleFailureToRetrieveBytecode(message: string): Promise<AvmContractCallResult> {
237
- // revert, consuming all gas
238
- const { functionSelector, functionName } = await this.context.persistableState.getPublicFunctionSelectorAndName(
239
- this.context.environment,
240
- );
241
- const revertReason = new AvmRevertReason(
242
- message,
243
- /*failingFunction=*/ {
244
- contractAddress: this.context.environment.address,
245
- functionSelector,
246
- functionName,
247
- },
248
- /*noirCallStack=*/ [],
249
- );
250
- this.log.warn(message);
251
- return new AvmContractCallResult(
252
- /*reverted=*/ true,
253
- /*output=*/ [],
254
- /*gasLeft=*/ { l2Gas: 0, daGas: 0 }, // consumes all allocated gas
255
- revertReason,
256
- );
257
- }
258
-
259
- private tallyInstruction(opcode: string, gasUsed: Gas) {
260
- const opcodeTally = this.opcodeTallies.get(opcode) || ({ count: 0, gas: { l2Gas: 0, daGas: 0 } } as OpcodeTally);
261
- opcodeTally.count++;
262
- opcodeTally.gas.l2Gas += gasUsed.l2Gas;
263
- opcodeTally.gas.daGas += gasUsed.daGas;
264
- this.opcodeTallies.set(opcode, opcodeTally);
265
- }
266
-
267
- private printOpcodeTallies() {
268
- this.log.debug(`Printing tallies per opcode sorted by gas...`);
269
- // sort descending by L2 gas consumed
270
- const sortedOpcodes = Array.from(this.opcodeTallies.entries()).sort((a, b) => b[1].gas.l2Gas - a[1].gas.l2Gas);
271
- for (const [opcode, tally] of sortedOpcodes) {
272
- // NOTE: don't care to clutter the logs with DA gas for now
273
- this.log.debug(`${opcode} executed ${tally.count} times consuming a total of ${tally.gas.l2Gas} L2 gas`);
274
- }
275
- }
276
- }