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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (405) hide show
  1. package/README.md +6 -4
  2. package/dest/client.d.ts +1 -3
  3. package/dest/client.d.ts.map +1 -1
  4. package/dest/client.js +0 -2
  5. package/dest/common/errors.d.ts +2 -2
  6. package/dest/common/errors.d.ts.map +1 -1
  7. package/dest/common/index.d.ts +1 -1
  8. package/dest/common/stats/index.d.ts +1 -1
  9. package/dest/common/stats/stats.d.ts +1 -1
  10. package/dest/private/acvm/acvm.d.ts +4 -2
  11. package/dest/private/acvm/acvm.d.ts.map +1 -1
  12. package/dest/private/acvm/acvm.js +4 -3
  13. package/dest/private/acvm/acvm_types.d.ts +1 -1
  14. package/dest/private/acvm/deserialize.d.ts +2 -2
  15. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  16. package/dest/private/acvm/deserialize.js +1 -1
  17. package/dest/private/acvm/index.d.ts +1 -1
  18. package/dest/private/acvm/serialize.d.ts +2 -2
  19. package/dest/private/acvm/serialize.d.ts.map +1 -1
  20. package/dest/private/acvm/serialize.js +1 -1
  21. package/dest/private/acvm_native.d.ts +5 -3
  22. package/dest/private/acvm_native.d.ts.map +1 -1
  23. package/dest/private/acvm_native.js +8 -6
  24. package/dest/private/acvm_wasm.d.ts +4 -3
  25. package/dest/private/acvm_wasm.d.ts.map +1 -1
  26. package/dest/private/acvm_wasm.js +7 -5
  27. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  28. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  29. package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
  30. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  31. package/dest/private/circuit_recording/circuit_recorder.js +71 -72
  32. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
  33. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  34. package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
  35. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  36. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  37. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  38. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  39. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  40. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  41. package/dest/private/circuit_simulator.d.ts +1 -1
  42. package/dest/private/factory.d.ts +3 -3
  43. package/dest/private/factory.d.ts.map +1 -1
  44. package/dest/private/factory.js +7 -4
  45. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  46. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  47. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  48. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
  49. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  50. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +19 -4
  51. package/dest/public/avm/{fixtures → testing}/utils.d.ts +4 -10
  52. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  53. package/dest/public/avm/{fixtures → testing}/utils.js +7 -36
  54. package/dest/public/avm_simulator.d.ts +28 -0
  55. package/dest/public/avm_simulator.d.ts.map +1 -0
  56. package/dest/public/avm_simulator.js +4 -0
  57. package/dest/public/avm_simulator_pool.d.ts +45 -0
  58. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  59. package/dest/public/avm_simulator_pool.js +197 -0
  60. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  61. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  62. package/dest/public/cdb/generated/api_types.js +314 -0
  63. package/dest/public/cdb/generated/server.d.ts +26 -0
  64. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  65. package/dest/public/cdb/generated/server.js +135 -0
  66. package/dest/public/cdb_ipc_server.d.ts +33 -0
  67. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  68. package/dest/public/cdb_ipc_server.js +153 -0
  69. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  70. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  71. package/dest/public/contracts_db_checkpoint.js +30 -0
  72. package/dest/public/db_interfaces.d.ts +14 -2
  73. package/dest/public/db_interfaces.d.ts.map +1 -1
  74. package/dest/public/executor_metrics.d.ts +3 -2
  75. package/dest/public/executor_metrics.d.ts.map +1 -1
  76. package/dest/public/executor_metrics.js +13 -34
  77. package/dest/public/executor_metrics_interface.d.ts +3 -2
  78. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  79. package/dest/public/fixtures/amm_test.d.ts +1 -1
  80. package/dest/public/fixtures/amm_test.js +6 -6
  81. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  82. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  83. package/dest/public/fixtures/bulk_test.js +38 -75
  84. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  85. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  86. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  87. package/dest/public/fixtures/index.d.ts +3 -3
  88. package/dest/public/fixtures/index.d.ts.map +1 -1
  89. package/dest/public/fixtures/index.js +2 -2
  90. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  91. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  92. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  93. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +32 -9
  94. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  95. package/dest/public/fixtures/public_tx_simulation_tester.js +84 -26
  96. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  97. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  98. package/dest/public/fixtures/simple_contract_data_source.js +5 -5
  99. package/dest/public/fixtures/token_test.d.ts +6 -2
  100. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  101. package/dest/public/fixtures/token_test.js +16 -15
  102. package/dest/public/fixtures/utils.d.ts +3 -3
  103. package/dest/public/fixtures/utils.d.ts.map +1 -1
  104. package/dest/public/fixtures/utils.js +25 -23
  105. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +67 -0
  106. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  107. package/dest/public/fuzzing/avm_fuzzer_simulator.js +185 -0
  108. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  109. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  110. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  111. package/dest/public/index.d.ts +6 -2
  112. package/dest/public/index.d.ts.map +1 -1
  113. package/dest/public/index.js +2 -1
  114. package/dest/public/public_db_sources.d.ts +29 -66
  115. package/dest/public/public_db_sources.d.ts.map +1 -1
  116. package/dest/public/public_db_sources.js +83 -134
  117. package/dest/public/public_errors.d.ts +1 -1
  118. package/dest/public/public_errors.d.ts.map +1 -1
  119. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -5
  120. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  121. package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
  122. package/dest/public/public_processor/public_processor.d.ts +24 -22
  123. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  124. package/dest/public/public_processor/public_processor.js +559 -125
  125. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  126. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  127. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  128. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  129. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  130. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +39 -0
  131. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  132. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  133. package/dest/public/public_tx_simulator/factories.js +28 -0
  134. package/dest/public/public_tx_simulator/index.d.ts +6 -4
  135. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  136. package/dest/public/public_tx_simulator/index.js +3 -2
  137. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +43 -90
  138. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  139. package/dest/public/public_tx_simulator/public_tx_simulator.js +99 -331
  140. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  141. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  142. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  143. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  144. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  145. package/dest/public/side_effect_errors.d.ts +1 -1
  146. package/dest/public/side_effect_errors.d.ts.map +1 -1
  147. package/dest/public/test_executor_metrics.d.ts +6 -4
  148. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  149. package/dest/public/test_executor_metrics.js +7 -6
  150. package/dest/public/unique_class_ids.d.ts +1 -1
  151. package/dest/public/unique_class_ids.d.ts.map +1 -1
  152. package/dest/public/utils.d.ts +1 -1
  153. package/dest/server.d.ts +1 -1
  154. package/dest/testing.d.ts +1 -1
  155. package/package.json +26 -22
  156. package/src/client.ts +0 -2
  157. package/src/common/errors.ts +1 -1
  158. package/src/private/acvm/acvm.ts +4 -3
  159. package/src/private/acvm/deserialize.ts +1 -1
  160. package/src/private/acvm/serialize.ts +1 -1
  161. package/src/private/acvm_native.ts +11 -5
  162. package/src/private/acvm_wasm.ts +11 -4
  163. package/src/private/circuit_recording/circuit_recorder.ts +90 -81
  164. package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
  165. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  166. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  167. package/src/private/factory.ts +7 -4
  168. package/src/public/avm/testing/account_proof.json +553 -0
  169. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  170. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +24 -4
  171. package/src/public/avm/{fixtures → testing}/utils.ts +7 -42
  172. package/src/public/avm_simulator.ts +29 -0
  173. package/src/public/avm_simulator_pool.ts +226 -0
  174. package/src/public/cdb/generated/api_types.ts +457 -0
  175. package/src/public/cdb/generated/server.ts +109 -0
  176. package/src/public/cdb_ipc_server.ts +197 -0
  177. package/src/public/contracts_db_checkpoint.ts +41 -0
  178. package/src/public/db_interfaces.ts +16 -1
  179. package/src/public/executor_metrics.ts +11 -34
  180. package/src/public/executor_metrics_interface.ts +2 -1
  181. package/src/public/fixtures/amm_test.ts +6 -6
  182. package/src/public/fixtures/bulk_test.ts +40 -15
  183. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  184. package/src/public/fixtures/index.ts +6 -2
  185. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  186. package/src/public/fixtures/public_tx_simulation_tester.ts +117 -26
  187. package/src/public/fixtures/simple_contract_data_source.ts +9 -10
  188. package/src/public/fixtures/token_test.ts +21 -13
  189. package/src/public/fixtures/utils.ts +25 -27
  190. package/src/public/fuzzing/avm_fuzzer_simulator.ts +303 -0
  191. package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
  192. package/src/public/index.ts +8 -2
  193. package/src/public/public_db_sources.ts +112 -174
  194. package/src/public/public_processor/guarded_merkle_tree.ts +14 -6
  195. package/src/public/public_processor/public_processor.ts +234 -138
  196. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  197. package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +67 -0
  198. package/src/public/public_tx_simulator/factories.ts +61 -0
  199. package/src/public/public_tx_simulator/index.ts +8 -3
  200. package/src/public/public_tx_simulator/public_tx_simulator.ts +142 -500
  201. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  202. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  203. package/src/public/test_executor_metrics.ts +10 -8
  204. package/dest/public/avm/avm_context.d.ts +0 -41
  205. package/dest/public/avm/avm_context.d.ts.map +0 -1
  206. package/dest/public/avm/avm_context.js +0 -44
  207. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  208. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  209. package/dest/public/avm/avm_contract_call_result.js +0 -54
  210. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  211. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  212. package/dest/public/avm/avm_execution_environment.js +0 -36
  213. package/dest/public/avm/avm_gas.d.ts +0 -44
  214. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  215. package/dest/public/avm/avm_gas.js +0 -195
  216. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  217. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  218. package/dest/public/avm/avm_machine_state.js +0 -109
  219. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  220. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  221. package/dest/public/avm/avm_memory_types.js +0 -351
  222. package/dest/public/avm/avm_simulator.d.ts +0 -39
  223. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  224. package/dest/public/avm/avm_simulator.js +0 -190
  225. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  226. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  227. package/dest/public/avm/avm_simulator_interface.js +0 -3
  228. package/dest/public/avm/errors.d.ts +0 -98
  229. package/dest/public/avm/errors.d.ts.map +0 -1
  230. package/dest/public/avm/errors.js +0 -129
  231. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  232. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  233. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -74
  234. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  235. package/dest/public/avm/fixtures/initializers.d.ts +0 -43
  236. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  237. package/dest/public/avm/fixtures/initializers.js +0 -42
  238. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  239. package/dest/public/avm/index.d.ts +0 -2
  240. package/dest/public/avm/index.d.ts.map +0 -1
  241. package/dest/public/avm/index.js +0 -1
  242. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  243. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  244. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  245. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  246. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  247. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  248. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
  249. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  250. package/dest/public/avm/opcodes/arithmetic.js +0 -87
  251. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  252. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  253. package/dest/public/avm/opcodes/bitwise.js +0 -99
  254. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  255. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  256. package/dest/public/avm/opcodes/comparators.js +0 -43
  257. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  258. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  259. package/dest/public/avm/opcodes/contract.js +0 -65
  260. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  261. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  262. package/dest/public/avm/opcodes/control_flow.js +0 -107
  263. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  264. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  265. package/dest/public/avm/opcodes/conversion.js +0 -333
  266. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  267. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  268. package/dest/public/avm/opcodes/ec_add.js +0 -84
  269. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  270. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  271. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  272. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  273. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  274. package/dest/public/avm/opcodes/external_calls.js +0 -209
  275. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  276. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  277. package/dest/public/avm/opcodes/hashing.js +0 -114
  278. package/dest/public/avm/opcodes/index.d.ts +0 -16
  279. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  280. package/dest/public/avm/opcodes/index.js +0 -15
  281. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  282. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  283. package/dest/public/avm/opcodes/instruction.js +0 -95
  284. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  285. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  286. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  287. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  288. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  289. package/dest/public/avm/opcodes/memory.js +0 -257
  290. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  291. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  292. package/dest/public/avm/opcodes/misc.js +0 -73
  293. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  294. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  295. package/dest/public/avm/opcodes/storage.js +0 -68
  296. package/dest/public/avm/revert_reason.d.ts +0 -18
  297. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  298. package/dest/public/avm/revert_reason.js +0 -38
  299. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  300. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  301. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  302. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  303. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  304. package/dest/public/avm/serialization/bytecode_serialization.js +0 -333
  305. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  306. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  307. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  308. package/dest/public/avm/test_utils.d.ts +0 -15
  309. package/dest/public/avm/test_utils.d.ts.map +0 -1
  310. package/dest/public/avm/test_utils.js +0 -44
  311. package/dest/public/debug_fn_name.d.ts +0 -5
  312. package/dest/public/debug_fn_name.d.ts.map +0 -1
  313. package/dest/public/debug_fn_name.js +0 -9
  314. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
  315. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  316. package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
  317. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -10
  318. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  319. package/dest/public/fixtures/minimal_public_tx.js +0 -29
  320. package/dest/public/hinting_db_sources.d.ts +0 -70
  321. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  322. package/dest/public/hinting_db_sources.js +0 -297
  323. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -41
  324. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  325. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -89
  326. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -24
  327. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  328. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  329. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -127
  330. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  331. package/dest/public/public_tx_simulator/public_tx_context.js +0 -292
  332. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  333. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  334. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
  335. package/dest/public/side_effect_trace.d.ts +0 -87
  336. package/dest/public/side_effect_trace.d.ts.map +0 -1
  337. package/dest/public/side_effect_trace.js +0 -199
  338. package/dest/public/side_effect_trace_interface.d.ts +0 -23
  339. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  340. package/dest/public/side_effect_trace_interface.js +0 -1
  341. package/dest/public/state_manager/index.d.ts +0 -2
  342. package/dest/public/state_manager/index.d.ts.map +0 -1
  343. package/dest/public/state_manager/index.js +0 -1
  344. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  345. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  346. package/dest/public/state_manager/nullifiers.js +0 -92
  347. package/dest/public/state_manager/public_storage.d.ts +0 -66
  348. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  349. package/dest/public/state_manager/public_storage.js +0 -145
  350. package/dest/public/state_manager/state_manager.d.ts +0 -166
  351. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  352. package/dest/public/state_manager/state_manager.js +0 -391
  353. package/dest/public/tx_contract_cache.d.ts +0 -41
  354. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  355. package/dest/public/tx_contract_cache.js +0 -49
  356. package/src/public/avm/avm_context.ts +0 -61
  357. package/src/public/avm/avm_contract_call_result.ts +0 -67
  358. package/src/public/avm/avm_execution_environment.ts +0 -48
  359. package/src/public/avm/avm_gas.ts +0 -183
  360. package/src/public/avm/avm_machine_state.ts +0 -169
  361. package/src/public/avm/avm_memory_types.ts +0 -436
  362. package/src/public/avm/avm_simulator.ts +0 -274
  363. package/src/public/avm/avm_simulator_interface.ts +0 -8
  364. package/src/public/avm/errors.ts +0 -163
  365. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -108
  366. package/src/public/avm/fixtures/initializers.ts +0 -104
  367. package/src/public/avm/index.ts +0 -1
  368. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  369. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  370. package/src/public/avm/opcodes/arithmetic.ts +0 -117
  371. package/src/public/avm/opcodes/bitwise.ts +0 -113
  372. package/src/public/avm/opcodes/comparators.ts +0 -55
  373. package/src/public/avm/opcodes/contract.ts +0 -75
  374. package/src/public/avm/opcodes/control_flow.ts +0 -123
  375. package/src/public/avm/opcodes/conversion.ts +0 -104
  376. package/src/public/avm/opcodes/ec_add.ts +0 -96
  377. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  378. package/src/public/avm/opcodes/external_calls.ts +0 -260
  379. package/src/public/avm/opcodes/hashing.ts +0 -145
  380. package/src/public/avm/opcodes/index.ts +0 -15
  381. package/src/public/avm/opcodes/instruction.ts +0 -136
  382. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  383. package/src/public/avm/opcodes/memory.ts +0 -293
  384. package/src/public/avm/opcodes/misc.ts +0 -102
  385. package/src/public/avm/opcodes/storage.ts +0 -87
  386. package/src/public/avm/revert_reason.ts +0 -55
  387. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  388. package/src/public/avm/serialization/bytecode_serialization.ts +0 -204
  389. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  390. package/src/public/avm/test_utils.ts +0 -64
  391. package/src/public/debug_fn_name.ts +0 -18
  392. package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
  393. package/src/public/fixtures/minimal_public_tx.ts +0 -36
  394. package/src/public/hinting_db_sources.ts +0 -505
  395. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -128
  396. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -109
  397. package/src/public/public_tx_simulator/public_tx_context.ts +0 -471
  398. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  399. package/src/public/side_effect_trace.ts +0 -290
  400. package/src/public/side_effect_trace_interface.ts +0 -28
  401. package/src/public/state_manager/index.ts +0 -1
  402. package/src/public/state_manager/nullifiers.ts +0 -103
  403. package/src/public/state_manager/public_storage.ts +0 -174
  404. package/src/public/state_manager/state_manager.ts +0 -560
  405. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,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,274 +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 { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { GlobalVariables } from '@aztec/stdlib/tx';
6
-
7
- import { strict as assert } from 'assert';
8
-
9
- import { CheckedPublicExecutionError } from '../public_errors.js';
10
- import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
11
- import { AvmContext } from './avm_context.js';
12
- import { AvmContractCallResult } from './avm_contract_call_result.js';
13
- import { AvmExecutionEnvironment } from './avm_execution_environment.js';
14
- import type { Gas } from './avm_gas.js';
15
- import { AvmMachineState } from './avm_machine_state.js';
16
- import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
17
- import { AvmRevertReason, InvalidProgramCounterError } from './errors.js';
18
- import type { Instruction } from './opcodes/instruction.js';
19
- import { revertReasonFromExceptionalHalt, revertReasonFromExplicitRevert } from './revert_reason.js';
20
- import {
21
- INSTRUCTION_SET,
22
- type InstructionSet,
23
- decodeInstructionFromBytecode,
24
- } from './serialization/bytecode_serialization.js';
25
-
26
- type OpcodeTally = {
27
- count: number;
28
- gas: Gas;
29
- };
30
-
31
- export class AvmSimulator implements AvmSimulatorInterface {
32
- private log: Logger;
33
- private bytecode: Buffer | undefined;
34
- private opcodeTallies: Map<string, OpcodeTally> = new Map();
35
- // maps pc to [instr, bytesRead]
36
- private deserializedInstructionsCache: Map<number, [Instruction, number]> = new Map();
37
-
38
- private tallyPrintFunction = () => {};
39
- private tallyInstructionFunction = (_b: string, _c: Gas) => {};
40
-
41
- // Test Purposes only: Logger will not have the proper function name. Use this constructor for testing purposes
42
- // only. Otherwise, use build() below.
43
- constructor(
44
- private context: AvmContext,
45
- private instructionSet: InstructionSet = INSTRUCTION_SET,
46
- enableTallying = false,
47
- ) {
48
- // This will be used by the CALL opcode to create a new simulator. It is required to
49
- // avoid a dependency cycle.
50
- context.provideSimulator = AvmSimulator.build;
51
- this.log = createLogger(`simulator:avm(calldata[0]: ${context.environment.calldata[0]})`);
52
- // Turn on tallying if explicitly enabled or if trace logging
53
- if (enableTallying || this.log.isLevelEnabled('trace')) {
54
- this.tallyPrintFunction = this.printOpcodeTallies;
55
- this.tallyInstructionFunction = this.tallyInstruction;
56
- }
57
- }
58
-
59
- // Factory to have a proper function name in the logger. Retrieving the name is asynchronous and
60
- // cannot be done as part of the constructor.
61
- public static async build(context: AvmContext): Promise<AvmSimulator> {
62
- const simulator = new AvmSimulator(context);
63
- const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
64
- simulator.log = createLogger(`simulator:avm(f:${fnName})`);
65
-
66
- return simulator;
67
- }
68
-
69
- public static async create(
70
- stateManager: PublicPersistableStateManager,
71
- address: AztecAddress,
72
- sender: AztecAddress,
73
- transactionFee: Fr,
74
- globals: GlobalVariables,
75
- isStaticCall: boolean,
76
- calldata: Fr[],
77
- allocatedGas: Gas,
78
- clientInitiatedSimulation: boolean = false,
79
- maxDebugLogMemoryReads?: number,
80
- ) {
81
- const avmExecutionEnv = new AvmExecutionEnvironment(
82
- address,
83
- sender,
84
- /*contractCallDepth=*/ Fr.zero(),
85
- transactionFee,
86
- globals,
87
- isStaticCall,
88
- calldata,
89
- clientInitiatedSimulation,
90
- maxDebugLogMemoryReads,
91
- );
92
-
93
- const avmMachineState = new AvmMachineState(allocatedGas);
94
- const avmContext = new AvmContext(stateManager, avmExecutionEnv, avmMachineState);
95
- return await AvmSimulator.build(avmContext);
96
- }
97
-
98
- /**
99
- * Fetch the bytecode and execute it in the current context.
100
- */
101
- public async execute(): Promise<AvmContractCallResult> {
102
- const bytecode = await this.context.persistableState.getBytecode(this.context.environment.address);
103
- // getBytecode returns undefined if bytecode is not found or if the limit of contract calls to unique class IDs is reached.
104
- // If it throws an error that reaches this point, it is a bug.
105
-
106
- if (!bytecode) {
107
- return await this.handleFailureToRetrieveBytecode(
108
- `No bytecode found, or limit encountered for max calls to unique contract class IDs. Contract address: ${this.context.environment.address}. Reverting...`,
109
- );
110
- }
111
-
112
- return await this.executeBytecode(bytecode);
113
- }
114
-
115
- /**
116
- * Return the bytecode used for execution, if any.
117
- */
118
- public getBytecode(): Buffer | undefined {
119
- return this.bytecode;
120
- }
121
-
122
- /**
123
- * Executes the provided bytecode in the current context.
124
- * This method is useful for testing and debugging.
125
- */
126
- public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
127
- const timer = new Timer();
128
- assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");
129
-
130
- this.bytecode = bytecode;
131
- let instructionName = 'NONE'; // This is used for logging purposes
132
-
133
- const { machineState } = this.context;
134
- const callStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
135
- try {
136
- // Execute instruction pointed to by the current program counter
137
- // continuing until the machine state signifies a halt
138
- while (!machineState.getHalted()) {
139
- // Get the instruction from cache, or deserialize for the first time
140
- let cachedInstruction = this.deserializedInstructionsCache.get(machineState.pc);
141
-
142
- if (cachedInstruction === undefined) {
143
- cachedInstruction = decodeInstructionFromBytecode(bytecode, machineState.pc, this.instructionSet);
144
- this.deserializedInstructionsCache.set(machineState.pc, cachedInstruction);
145
- }
146
- const [instruction, bytesRead] = cachedInstruction;
147
-
148
- const instrStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
149
-
150
- if (this.log.isLevelEnabled('trace')) {
151
- // Skip this entirely to avoid toStringing etc if trace is not enabled
152
- this.log.trace(
153
- `[PC:${machineState.pc}] [IC:${machineState.instrCounter}] ${instruction.toString()} (gasLeft l2=${
154
- machineState.l2GasLeft
155
- } da=${machineState.daGasLeft})`,
156
- );
157
- }
158
- machineState.nextPc = machineState.pc + bytesRead;
159
-
160
- instructionName = instruction.constructor.name;
161
- // Execute the instruction.
162
- // Normal returns and reverts will return normally here.
163
- // "Exceptional halts" will throw.
164
- await instruction.execute(this.context);
165
- if (!instruction.handlesPC()) {
166
- // Increment PC if the instruction doesn't handle it itself
167
- machineState.pc += bytesRead;
168
- }
169
-
170
- machineState.instrCounter++;
171
-
172
- // gas used by this instruction - used for profiling/tallying
173
- const gasUsed: Gas = {
174
- l2Gas: instrStartGas.l2Gas - machineState.l2GasLeft,
175
- daGas: instrStartGas.daGas - machineState.daGasLeft,
176
- };
177
- this.tallyInstructionFunction(instruction.constructor.name, gasUsed);
178
-
179
- if (machineState.pc >= bytecode.length) {
180
- this.log.warn('Passed end of program');
181
- throw new InvalidProgramCounterError(machineState.pc, /*max=*/ bytecode.length);
182
- }
183
- }
184
-
185
- const output = machineState.getOutput();
186
- const reverted = machineState.getReverted();
187
- const revertReason = reverted ? await revertReasonFromExplicitRevert(output, this.context) : undefined;
188
- const results = new AvmContractCallResult(
189
- reverted,
190
- output,
191
- machineState.gasLeft,
192
- revertReason,
193
- machineState.instrCounter,
194
- );
195
- this.log.debug(`Context execution results: ${results.toString()}`);
196
- const totalGasUsed: Gas = {
197
- l2Gas: callStartGas.l2Gas - machineState.l2GasLeft,
198
- daGas: callStartGas.daGas - machineState.daGasLeft,
199
- };
200
- this.log.debug(`Executed ${machineState.instrCounter} instructions and consumed ${totalGasUsed.l2Gas} L2 Gas`);
201
-
202
- this.tallyPrintFunction();
203
-
204
- this.log.debug(`Core AVM simulation took ${timer.ms()}ms`);
205
-
206
- // Return results for processing by calling context
207
- return results;
208
- } catch (err: any) {
209
- this.log.info(
210
- `Exceptional halt (revert by something other than REVERT opcode) for instruction
211
- ${instructionName} at pc ${machineState.pc} and instruction counter ${machineState.instrCounter}`,
212
- );
213
- if (!(err instanceof CheckedPublicExecutionError)) {
214
- this.log.error(`Unchecked/unknown error thrown by AVM. This is a bug. Error: ${err}`);
215
- throw err;
216
- }
217
-
218
- const revertReason = await revertReasonFromExceptionalHalt(err, this.context);
219
- // Exceptional halts consume all allocated gas
220
- const noGasLeft = { l2Gas: 0, daGas: 0 };
221
- // Note: "exceptional halts" cannot return data, hence [].
222
- const results = new AvmContractCallResult(
223
- /*reverted=*/ true,
224
- /*output=*/ [],
225
- noGasLeft,
226
- revertReason,
227
- machineState.instrCounter,
228
- );
229
- this.log.debug(`Context execution results: ${results.toString()}`);
230
-
231
- this.tallyPrintFunction();
232
- // Return results for processing by calling context
233
- return results;
234
- }
235
- }
236
-
237
- private async handleFailureToRetrieveBytecode(message: string): Promise<AvmContractCallResult> {
238
- // revert, consuming all gas
239
- const fnName = await this.context.persistableState.getPublicFunctionDebugName(this.context.environment);
240
- const revertReason = new AvmRevertReason(
241
- message,
242
- /*failingFunction=*/ {
243
- contractAddress: this.context.environment.address,
244
- functionName: fnName,
245
- },
246
- /*noirCallStack=*/ [],
247
- );
248
- this.log.warn(message);
249
- return new AvmContractCallResult(
250
- /*reverted=*/ true,
251
- /*output=*/ [],
252
- /*gasLeft=*/ { l2Gas: 0, daGas: 0 }, // consumes all allocated gas
253
- revertReason,
254
- );
255
- }
256
-
257
- private tallyInstruction(opcode: string, gasUsed: Gas) {
258
- const opcodeTally = this.opcodeTallies.get(opcode) || ({ count: 0, gas: { l2Gas: 0, daGas: 0 } } as OpcodeTally);
259
- opcodeTally.count++;
260
- opcodeTally.gas.l2Gas += gasUsed.l2Gas;
261
- opcodeTally.gas.daGas += gasUsed.daGas;
262
- this.opcodeTallies.set(opcode, opcodeTally);
263
- }
264
-
265
- private printOpcodeTallies() {
266
- this.log.debug(`Printing tallies per opcode sorted by gas...`);
267
- // sort descending by L2 gas consumed
268
- const sortedOpcodes = Array.from(this.opcodeTallies.entries()).sort((a, b) => b[1].gas.l2Gas - a[1].gas.l2Gas);
269
- for (const [opcode, tally] of sortedOpcodes) {
270
- // NOTE: don't care to clutter the logs with DA gas for now
271
- this.log.debug(`${opcode} executed ${tally.count} times consuming a total of ${tally.gas.l2Gas} L2 gas`);
272
- }
273
- }
274
- }