@aztec/simulator 0.0.1-commit.d3ec352c → 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 (391) hide show
  1. package/README.md +6 -4
  2. package/dest/client.d.ts +1 -3
  3. package/dest/client.d.ts.map +1 -1
  4. package/dest/client.js +0 -2
  5. package/dest/common/errors.d.ts +8 -2
  6. package/dest/common/errors.d.ts.map +1 -1
  7. package/dest/private/acvm/acvm.d.ts +4 -2
  8. package/dest/private/acvm/acvm.d.ts.map +1 -1
  9. package/dest/private/acvm/acvm.js +4 -3
  10. package/dest/private/acvm/deserialize.d.ts +2 -2
  11. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  12. package/dest/private/acvm/deserialize.js +1 -1
  13. package/dest/private/acvm/serialize.d.ts +2 -2
  14. package/dest/private/acvm/serialize.d.ts.map +1 -1
  15. package/dest/private/acvm/serialize.js +1 -1
  16. package/dest/private/acvm_native.d.ts +5 -3
  17. package/dest/private/acvm_native.d.ts.map +1 -1
  18. package/dest/private/acvm_native.js +8 -6
  19. package/dest/private/acvm_wasm.d.ts +4 -3
  20. package/dest/private/acvm_wasm.d.ts.map +1 -1
  21. package/dest/private/acvm_wasm.js +7 -5
  22. package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
  23. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  24. package/dest/private/circuit_recording/circuit_recorder.js +71 -72
  25. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
  26. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  27. package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
  28. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  29. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  30. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  31. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  32. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  33. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  34. package/dest/private/factory.d.ts +3 -3
  35. package/dest/private/factory.d.ts.map +1 -1
  36. package/dest/private/factory.js +7 -4
  37. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  38. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  39. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  40. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
  41. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  42. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +19 -4
  43. package/dest/public/avm/testing/utils.d.ts +32 -0
  44. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  45. package/dest/public/avm/{fixtures → testing}/utils.js +5 -35
  46. package/dest/public/avm_simulator.d.ts +28 -0
  47. package/dest/public/avm_simulator.d.ts.map +1 -0
  48. package/dest/public/avm_simulator.js +4 -0
  49. package/dest/public/avm_simulator_pool.d.ts +45 -0
  50. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  51. package/dest/public/avm_simulator_pool.js +197 -0
  52. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  53. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  54. package/dest/public/cdb/generated/api_types.js +314 -0
  55. package/dest/public/cdb/generated/server.d.ts +26 -0
  56. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  57. package/dest/public/cdb/generated/server.js +135 -0
  58. package/dest/public/cdb_ipc_server.d.ts +33 -0
  59. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  60. package/dest/public/cdb_ipc_server.js +153 -0
  61. package/dest/public/contracts_db_checkpoint.d.ts +3 -3
  62. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  63. package/dest/public/contracts_db_checkpoint.js +1 -1
  64. package/dest/public/db_interfaces.d.ts +2 -2
  65. package/dest/public/db_interfaces.d.ts.map +1 -1
  66. package/dest/public/executor_metrics.d.ts +1 -1
  67. package/dest/public/executor_metrics.d.ts.map +1 -1
  68. package/dest/public/executor_metrics.js +12 -33
  69. package/dest/public/fixtures/amm_test.js +6 -6
  70. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  71. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  72. package/dest/public/fixtures/bulk_test.js +38 -75
  73. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  74. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  75. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  76. package/dest/public/fixtures/index.d.ts +3 -3
  77. package/dest/public/fixtures/index.d.ts.map +1 -1
  78. package/dest/public/fixtures/index.js +2 -2
  79. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  80. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  81. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  82. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +24 -6
  83. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  84. package/dest/public/fixtures/public_tx_simulation_tester.js +66 -21
  85. package/dest/public/fixtures/simple_contract_data_source.d.ts +2 -2
  86. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  87. package/dest/public/fixtures/simple_contract_data_source.js +1 -1
  88. package/dest/public/fixtures/token_test.js +4 -4
  89. package/dest/public/fixtures/utils.d.ts +3 -3
  90. package/dest/public/fixtures/utils.d.ts.map +1 -1
  91. package/dest/public/fixtures/utils.js +25 -23
  92. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +67 -0
  93. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  94. package/dest/public/fuzzing/avm_fuzzer_simulator.js +185 -0
  95. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  96. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  97. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  98. package/dest/public/index.d.ts +5 -2
  99. package/dest/public/index.d.ts.map +1 -1
  100. package/dest/public/index.js +2 -1
  101. package/dest/public/public_db_sources.d.ts +10 -6
  102. package/dest/public/public_db_sources.d.ts.map +1 -1
  103. package/dest/public/public_db_sources.js +21 -15
  104. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -6
  105. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  106. package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
  107. package/dest/public/public_processor/public_processor.d.ts +17 -8
  108. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  109. package/dest/public/public_processor/public_processor.js +535 -100
  110. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  111. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  112. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  113. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  114. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  115. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +39 -0
  116. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  117. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  118. package/dest/public/public_tx_simulator/factories.js +28 -0
  119. package/dest/public/public_tx_simulator/index.d.ts +5 -5
  120. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  121. package/dest/public/public_tx_simulator/index.js +3 -3
  122. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +43 -70
  123. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  124. package/dest/public/public_tx_simulator/public_tx_simulator.js +99 -312
  125. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  126. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  127. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  128. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  129. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  130. package/dest/public/test_executor_metrics.d.ts +3 -2
  131. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  132. package/dest/public/test_executor_metrics.js +2 -2
  133. package/package.json +23 -20
  134. package/src/client.ts +0 -2
  135. package/src/common/errors.ts +1 -1
  136. package/src/private/acvm/acvm.ts +4 -3
  137. package/src/private/acvm/deserialize.ts +1 -1
  138. package/src/private/acvm/serialize.ts +1 -1
  139. package/src/private/acvm_native.ts +11 -5
  140. package/src/private/acvm_wasm.ts +11 -4
  141. package/src/private/circuit_recording/circuit_recorder.ts +90 -81
  142. package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
  143. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  144. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  145. package/src/private/factory.ts +7 -4
  146. package/src/public/avm/testing/account_proof.json +553 -0
  147. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  148. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +24 -4
  149. package/src/public/avm/{fixtures → testing}/utils.ts +5 -41
  150. package/src/public/avm_simulator.ts +29 -0
  151. package/src/public/avm_simulator_pool.ts +226 -0
  152. package/src/public/cdb/generated/api_types.ts +457 -0
  153. package/src/public/cdb/generated/server.ts +109 -0
  154. package/src/public/cdb_ipc_server.ts +197 -0
  155. package/src/public/contracts_db_checkpoint.ts +2 -2
  156. package/src/public/db_interfaces.ts +1 -1
  157. package/src/public/executor_metrics.ts +9 -33
  158. package/src/public/fixtures/amm_test.ts +6 -6
  159. package/src/public/fixtures/bulk_test.ts +40 -15
  160. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  161. package/src/public/fixtures/index.ts +6 -2
  162. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  163. package/src/public/fixtures/public_tx_simulation_tester.ts +82 -21
  164. package/src/public/fixtures/simple_contract_data_source.ts +2 -2
  165. package/src/public/fixtures/token_test.ts +4 -4
  166. package/src/public/fixtures/utils.ts +25 -27
  167. package/src/public/fuzzing/avm_fuzzer_simulator.ts +303 -0
  168. package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
  169. package/src/public/index.ts +8 -2
  170. package/src/public/public_db_sources.ts +37 -20
  171. package/src/public/public_processor/guarded_merkle_tree.ts +14 -7
  172. package/src/public/public_processor/public_processor.ts +188 -102
  173. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  174. package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +67 -0
  175. package/src/public/public_tx_simulator/factories.ts +61 -0
  176. package/src/public/public_tx_simulator/index.ts +7 -4
  177. package/src/public/public_tx_simulator/public_tx_simulator.ts +143 -458
  178. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  179. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
  180. package/src/public/test_executor_metrics.ts +3 -3
  181. package/dest/public/avm/avm_context.d.ts +0 -41
  182. package/dest/public/avm/avm_context.d.ts.map +0 -1
  183. package/dest/public/avm/avm_context.js +0 -44
  184. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  185. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  186. package/dest/public/avm/avm_contract_call_result.js +0 -54
  187. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  188. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  189. package/dest/public/avm/avm_execution_environment.js +0 -33
  190. package/dest/public/avm/avm_gas.d.ts +0 -44
  191. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  192. package/dest/public/avm/avm_gas.js +0 -195
  193. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  194. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  195. package/dest/public/avm/avm_machine_state.js +0 -109
  196. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  197. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  198. package/dest/public/avm/avm_memory_types.js +0 -351
  199. package/dest/public/avm/avm_simulator.d.ts +0 -40
  200. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  201. package/dest/public/avm/avm_simulator.js +0 -191
  202. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  203. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  204. package/dest/public/avm/avm_simulator_interface.js +0 -3
  205. package/dest/public/avm/errors.d.ts +0 -104
  206. package/dest/public/avm/errors.d.ts.map +0 -1
  207. package/dest/public/avm/errors.js +0 -141
  208. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  209. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  210. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -83
  211. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  212. package/dest/public/avm/fixtures/initializers.d.ts +0 -42
  213. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  214. package/dest/public/avm/fixtures/initializers.js +0 -44
  215. package/dest/public/avm/fixtures/utils.d.ts +0 -39
  216. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  217. package/dest/public/avm/index.d.ts +0 -2
  218. package/dest/public/avm/index.d.ts.map +0 -1
  219. package/dest/public/avm/index.js +0 -1
  220. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  221. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  222. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  223. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  224. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  225. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  226. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
  227. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  228. package/dest/public/avm/opcodes/arithmetic.js +0 -87
  229. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  230. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  231. package/dest/public/avm/opcodes/bitwise.js +0 -99
  232. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  233. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  234. package/dest/public/avm/opcodes/comparators.js +0 -43
  235. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  236. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  237. package/dest/public/avm/opcodes/contract.js +0 -65
  238. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  239. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  240. package/dest/public/avm/opcodes/control_flow.js +0 -107
  241. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  242. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  243. package/dest/public/avm/opcodes/conversion.js +0 -333
  244. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  245. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  246. package/dest/public/avm/opcodes/ec_add.js +0 -84
  247. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  248. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  249. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  250. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  251. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  252. package/dest/public/avm/opcodes/external_calls.js +0 -209
  253. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  254. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  255. package/dest/public/avm/opcodes/hashing.js +0 -114
  256. package/dest/public/avm/opcodes/index.d.ts +0 -16
  257. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  258. package/dest/public/avm/opcodes/index.js +0 -15
  259. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  260. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  261. package/dest/public/avm/opcodes/instruction.js +0 -95
  262. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  263. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  264. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  265. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  266. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  267. package/dest/public/avm/opcodes/memory.js +0 -257
  268. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  269. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  270. package/dest/public/avm/opcodes/misc.js +0 -73
  271. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  272. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  273. package/dest/public/avm/opcodes/storage.js +0 -68
  274. package/dest/public/avm/revert_reason.d.ts +0 -18
  275. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  276. package/dest/public/avm/revert_reason.js +0 -39
  277. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  278. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  279. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  280. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  281. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  282. package/dest/public/avm/serialization/bytecode_serialization.js +0 -336
  283. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  284. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  285. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  286. package/dest/public/avm/test_utils.d.ts +0 -15
  287. package/dest/public/avm/test_utils.d.ts.map +0 -1
  288. package/dest/public/avm/test_utils.js +0 -44
  289. package/dest/public/debug_fn_name.d.ts +0 -18
  290. package/dest/public/debug_fn_name.d.ts.map +0 -1
  291. package/dest/public/debug_fn_name.js +0 -28
  292. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
  293. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  294. package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
  295. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -9
  296. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  297. package/dest/public/fixtures/minimal_public_tx.js +0 -29
  298. package/dest/public/hinting_db_sources.d.ts +0 -79
  299. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  300. package/dest/public/hinting_db_sources.js +0 -350
  301. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -30
  302. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
  303. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -133
  304. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -38
  305. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  306. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -93
  307. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +0 -42
  308. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +0 -1
  309. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +0 -86
  310. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +0 -30
  311. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +0 -1
  312. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +0 -170
  313. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -31
  314. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  315. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  316. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -130
  317. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  318. package/dest/public/public_tx_simulator/public_tx_context.js +0 -300
  319. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  320. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  321. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
  322. package/dest/public/side_effect_trace.d.ts +0 -86
  323. package/dest/public/side_effect_trace.d.ts.map +0 -1
  324. package/dest/public/side_effect_trace.js +0 -199
  325. package/dest/public/side_effect_trace_interface.d.ts +0 -22
  326. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  327. package/dest/public/side_effect_trace_interface.js +0 -1
  328. package/dest/public/state_manager/index.d.ts +0 -2
  329. package/dest/public/state_manager/index.d.ts.map +0 -1
  330. package/dest/public/state_manager/index.js +0 -1
  331. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  332. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  333. package/dest/public/state_manager/nullifiers.js +0 -92
  334. package/dest/public/state_manager/public_storage.d.ts +0 -66
  335. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  336. package/dest/public/state_manager/public_storage.js +0 -145
  337. package/dest/public/state_manager/state_manager.d.ts +0 -164
  338. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  339. package/dest/public/state_manager/state_manager.js +0 -395
  340. package/src/public/avm/avm_context.ts +0 -61
  341. package/src/public/avm/avm_contract_call_result.ts +0 -67
  342. package/src/public/avm/avm_execution_environment.ts +0 -46
  343. package/src/public/avm/avm_gas.ts +0 -183
  344. package/src/public/avm/avm_machine_state.ts +0 -169
  345. package/src/public/avm/avm_memory_types.ts +0 -436
  346. package/src/public/avm/avm_simulator.ts +0 -276
  347. package/src/public/avm/avm_simulator_interface.ts +0 -8
  348. package/src/public/avm/errors.ts +0 -177
  349. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -116
  350. package/src/public/avm/fixtures/initializers.ts +0 -102
  351. package/src/public/avm/index.ts +0 -1
  352. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  353. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  354. package/src/public/avm/opcodes/arithmetic.ts +0 -117
  355. package/src/public/avm/opcodes/bitwise.ts +0 -113
  356. package/src/public/avm/opcodes/comparators.ts +0 -55
  357. package/src/public/avm/opcodes/contract.ts +0 -75
  358. package/src/public/avm/opcodes/control_flow.ts +0 -123
  359. package/src/public/avm/opcodes/conversion.ts +0 -104
  360. package/src/public/avm/opcodes/ec_add.ts +0 -96
  361. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  362. package/src/public/avm/opcodes/external_calls.ts +0 -260
  363. package/src/public/avm/opcodes/hashing.ts +0 -145
  364. package/src/public/avm/opcodes/index.ts +0 -15
  365. package/src/public/avm/opcodes/instruction.ts +0 -136
  366. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  367. package/src/public/avm/opcodes/memory.ts +0 -293
  368. package/src/public/avm/opcodes/misc.ts +0 -102
  369. package/src/public/avm/opcodes/storage.ts +0 -87
  370. package/src/public/avm/revert_reason.ts +0 -58
  371. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  372. package/src/public/avm/serialization/bytecode_serialization.ts +0 -215
  373. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  374. package/src/public/avm/test_utils.ts +0 -64
  375. package/src/public/debug_fn_name.ts +0 -43
  376. package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
  377. package/src/public/fixtures/minimal_public_tx.ts +0 -35
  378. package/src/public/hinting_db_sources.ts +0 -603
  379. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -162
  380. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -155
  381. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +0 -132
  382. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +0 -240
  383. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -105
  384. package/src/public/public_tx_simulator/public_tx_context.ts +0 -477
  385. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  386. package/src/public/side_effect_trace.ts +0 -290
  387. package/src/public/side_effect_trace_interface.ts +0 -28
  388. package/src/public/state_manager/index.ts +0 -1
  389. package/src/public/state_manager/nullifiers.ts +0 -103
  390. package/src/public/state_manager/public_storage.ts +0 -174
  391. package/src/public/state_manager/state_manager.ts +0 -560
@@ -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/fields';
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/fields';
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
- }