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

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 (380) hide show
  1. package/README.md +6 -4
  2. package/dest/client.d.ts +1 -1
  3. package/dest/common/errors.d.ts +2 -2
  4. package/dest/common/errors.d.ts.map +1 -1
  5. package/dest/common/index.d.ts +1 -1
  6. package/dest/common/stats/index.d.ts +1 -1
  7. package/dest/common/stats/stats.d.ts +1 -1
  8. package/dest/private/acvm/acvm.d.ts +4 -2
  9. package/dest/private/acvm/acvm.d.ts.map +1 -1
  10. package/dest/private/acvm/acvm.js +4 -3
  11. package/dest/private/acvm/acvm_types.d.ts +1 -1
  12. package/dest/private/acvm/deserialize.d.ts +2 -2
  13. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  14. package/dest/private/acvm/deserialize.js +1 -1
  15. package/dest/private/acvm/index.d.ts +1 -1
  16. package/dest/private/acvm/serialize.d.ts +2 -2
  17. package/dest/private/acvm/serialize.d.ts.map +1 -1
  18. package/dest/private/acvm/serialize.js +1 -1
  19. package/dest/private/acvm_native.d.ts +5 -3
  20. package/dest/private/acvm_native.d.ts.map +1 -1
  21. package/dest/private/acvm_native.js +8 -6
  22. package/dest/private/acvm_wasm.d.ts +4 -3
  23. package/dest/private/acvm_wasm.d.ts.map +1 -1
  24. package/dest/private/acvm_wasm.js +7 -5
  25. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  26. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  27. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  28. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  29. package/dest/private/circuit_recording/circuit_recorder.js +23 -20
  30. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  31. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  32. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  33. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  34. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  35. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  36. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  37. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  38. package/dest/private/circuit_simulator.d.ts +1 -1
  39. package/dest/private/factory.d.ts +3 -3
  40. package/dest/private/factory.d.ts.map +1 -1
  41. package/dest/private/factory.js +7 -4
  42. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  43. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  44. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  45. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
  46. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  47. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
  48. package/dest/public/avm/{fixtures → testing}/utils.d.ts +4 -10
  49. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  50. package/dest/public/avm/{fixtures → testing}/utils.js +6 -35
  51. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  52. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  53. package/dest/public/contracts_db_checkpoint.js +30 -0
  54. package/dest/public/db_interfaces.d.ts +14 -2
  55. package/dest/public/db_interfaces.d.ts.map +1 -1
  56. package/dest/public/executor_metrics.d.ts +3 -2
  57. package/dest/public/executor_metrics.d.ts.map +1 -1
  58. package/dest/public/executor_metrics.js +13 -34
  59. package/dest/public/executor_metrics_interface.d.ts +3 -2
  60. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  61. package/dest/public/fixtures/amm_test.d.ts +1 -1
  62. package/dest/public/fixtures/amm_test.js +4 -4
  63. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  64. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  65. package/dest/public/fixtures/bulk_test.js +36 -73
  66. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  67. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  68. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  69. package/dest/public/fixtures/index.d.ts +2 -3
  70. package/dest/public/fixtures/index.d.ts.map +1 -1
  71. package/dest/public/fixtures/index.js +1 -2
  72. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +30 -11
  73. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  74. package/dest/public/fixtures/public_tx_simulation_tester.js +98 -31
  75. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  76. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  77. package/dest/public/fixtures/simple_contract_data_source.js +5 -5
  78. package/dest/public/fixtures/token_test.d.ts +6 -2
  79. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  80. package/dest/public/fixtures/token_test.js +13 -12
  81. package/dest/public/fixtures/utils.d.ts +3 -3
  82. package/dest/public/fixtures/utils.d.ts.map +1 -1
  83. package/dest/public/fixtures/utils.js +23 -23
  84. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +62 -0
  85. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  86. package/dest/public/fuzzing/avm_fuzzer_simulator.js +176 -0
  87. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  88. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  89. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  90. package/dest/public/index.d.ts +3 -2
  91. package/dest/public/index.d.ts.map +1 -1
  92. package/dest/public/index.js +1 -1
  93. package/dest/public/public_db_sources.d.ts +29 -66
  94. package/dest/public/public_db_sources.d.ts.map +1 -1
  95. package/dest/public/public_db_sources.js +83 -134
  96. package/dest/public/public_errors.d.ts +1 -1
  97. package/dest/public/public_errors.d.ts.map +1 -1
  98. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -5
  99. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  100. package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
  101. package/dest/public/public_processor/public_processor.d.ts +19 -21
  102. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  103. package/dest/public/public_processor/public_processor.js +553 -123
  104. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  105. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  106. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  107. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +19 -0
  108. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  109. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +99 -0
  110. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +23 -0
  111. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  112. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +52 -0
  113. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  114. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  115. package/dest/public/public_tx_simulator/factories.js +28 -0
  116. package/dest/public/public_tx_simulator/index.d.ts +5 -3
  117. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  118. package/dest/public/public_tx_simulator/index.js +3 -2
  119. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +42 -89
  120. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  121. package/dest/public/public_tx_simulator/public_tx_simulator.js +101 -334
  122. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +22 -0
  123. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  124. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +28 -0
  125. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  126. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  127. package/dest/public/side_effect_errors.d.ts +1 -1
  128. package/dest/public/side_effect_errors.d.ts.map +1 -1
  129. package/dest/public/test_executor_metrics.d.ts +11 -4
  130. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  131. package/dest/public/test_executor_metrics.js +29 -6
  132. package/dest/public/unique_class_ids.d.ts +1 -1
  133. package/dest/public/unique_class_ids.d.ts.map +1 -1
  134. package/dest/public/utils.d.ts +1 -1
  135. package/dest/server.d.ts +1 -1
  136. package/dest/testing.d.ts +1 -1
  137. package/package.json +22 -22
  138. package/src/common/errors.ts +1 -1
  139. package/src/private/acvm/acvm.ts +4 -3
  140. package/src/private/acvm/deserialize.ts +1 -1
  141. package/src/private/acvm/serialize.ts +1 -1
  142. package/src/private/acvm_native.ts +11 -5
  143. package/src/private/acvm_wasm.ts +11 -4
  144. package/src/private/circuit_recording/circuit_recorder.ts +24 -21
  145. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  146. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  147. package/src/private/factory.ts +7 -4
  148. package/src/public/avm/testing/account_proof.json +553 -0
  149. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  150. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
  151. package/src/public/avm/{fixtures → testing}/utils.ts +6 -41
  152. package/src/public/contracts_db_checkpoint.ts +41 -0
  153. package/src/public/db_interfaces.ts +16 -1
  154. package/src/public/executor_metrics.ts +11 -34
  155. package/src/public/executor_metrics_interface.ts +2 -1
  156. package/src/public/fixtures/amm_test.ts +4 -4
  157. package/src/public/fixtures/bulk_test.ts +38 -13
  158. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  159. package/src/public/fixtures/index.ts +5 -2
  160. package/src/public/fixtures/public_tx_simulation_tester.ts +129 -27
  161. package/src/public/fixtures/simple_contract_data_source.ts +9 -10
  162. package/src/public/fixtures/token_test.ts +18 -10
  163. package/src/public/fixtures/utils.ts +28 -25
  164. package/src/public/fuzzing/avm_fuzzer_simulator.ts +285 -0
  165. package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
  166. package/src/public/index.ts +4 -2
  167. package/src/public/public_db_sources.ts +112 -174
  168. package/src/public/public_processor/guarded_merkle_tree.ts +14 -6
  169. package/src/public/public_processor/public_processor.ts +225 -136
  170. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  171. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +125 -0
  172. package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +83 -0
  173. package/src/public/public_tx_simulator/factories.ts +44 -0
  174. package/src/public/public_tx_simulator/index.ts +4 -2
  175. package/src/public/public_tx_simulator/public_tx_simulator.ts +153 -500
  176. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +35 -0
  177. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  178. package/src/public/test_executor_metrics.ts +34 -8
  179. package/dest/public/avm/avm_context.d.ts +0 -41
  180. package/dest/public/avm/avm_context.d.ts.map +0 -1
  181. package/dest/public/avm/avm_context.js +0 -44
  182. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  183. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  184. package/dest/public/avm/avm_contract_call_result.js +0 -54
  185. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  186. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  187. package/dest/public/avm/avm_execution_environment.js +0 -36
  188. package/dest/public/avm/avm_gas.d.ts +0 -44
  189. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  190. package/dest/public/avm/avm_gas.js +0 -195
  191. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  192. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  193. package/dest/public/avm/avm_machine_state.js +0 -109
  194. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  195. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  196. package/dest/public/avm/avm_memory_types.js +0 -351
  197. package/dest/public/avm/avm_simulator.d.ts +0 -39
  198. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  199. package/dest/public/avm/avm_simulator.js +0 -190
  200. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  201. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  202. package/dest/public/avm/avm_simulator_interface.js +0 -3
  203. package/dest/public/avm/errors.d.ts +0 -98
  204. package/dest/public/avm/errors.d.ts.map +0 -1
  205. package/dest/public/avm/errors.js +0 -129
  206. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  207. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  208. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -74
  209. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  210. package/dest/public/avm/fixtures/initializers.d.ts +0 -43
  211. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  212. package/dest/public/avm/fixtures/initializers.js +0 -42
  213. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  214. package/dest/public/avm/index.d.ts +0 -2
  215. package/dest/public/avm/index.d.ts.map +0 -1
  216. package/dest/public/avm/index.js +0 -1
  217. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  218. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  219. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  220. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  221. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  222. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  223. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
  224. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  225. package/dest/public/avm/opcodes/arithmetic.js +0 -87
  226. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  227. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  228. package/dest/public/avm/opcodes/bitwise.js +0 -99
  229. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  230. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  231. package/dest/public/avm/opcodes/comparators.js +0 -43
  232. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  233. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  234. package/dest/public/avm/opcodes/contract.js +0 -65
  235. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  236. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  237. package/dest/public/avm/opcodes/control_flow.js +0 -107
  238. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  239. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  240. package/dest/public/avm/opcodes/conversion.js +0 -333
  241. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  242. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  243. package/dest/public/avm/opcodes/ec_add.js +0 -84
  244. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  245. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  246. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  247. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  248. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  249. package/dest/public/avm/opcodes/external_calls.js +0 -209
  250. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  251. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  252. package/dest/public/avm/opcodes/hashing.js +0 -114
  253. package/dest/public/avm/opcodes/index.d.ts +0 -16
  254. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  255. package/dest/public/avm/opcodes/index.js +0 -15
  256. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  257. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  258. package/dest/public/avm/opcodes/instruction.js +0 -95
  259. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  260. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  261. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  262. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  263. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  264. package/dest/public/avm/opcodes/memory.js +0 -257
  265. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  266. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  267. package/dest/public/avm/opcodes/misc.js +0 -73
  268. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  269. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  270. package/dest/public/avm/opcodes/storage.js +0 -68
  271. package/dest/public/avm/revert_reason.d.ts +0 -18
  272. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  273. package/dest/public/avm/revert_reason.js +0 -38
  274. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  275. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  276. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  277. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  278. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  279. package/dest/public/avm/serialization/bytecode_serialization.js +0 -333
  280. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  281. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  282. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  283. package/dest/public/avm/test_utils.d.ts +0 -15
  284. package/dest/public/avm/test_utils.d.ts.map +0 -1
  285. package/dest/public/avm/test_utils.js +0 -44
  286. package/dest/public/debug_fn_name.d.ts +0 -5
  287. package/dest/public/debug_fn_name.d.ts.map +0 -1
  288. package/dest/public/debug_fn_name.js +0 -9
  289. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
  290. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  291. package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
  292. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -10
  293. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  294. package/dest/public/fixtures/minimal_public_tx.js +0 -29
  295. package/dest/public/hinting_db_sources.d.ts +0 -70
  296. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  297. package/dest/public/hinting_db_sources.js +0 -297
  298. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -41
  299. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  300. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -89
  301. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -24
  302. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  303. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  304. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -127
  305. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  306. package/dest/public/public_tx_simulator/public_tx_context.js +0 -292
  307. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  308. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  309. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
  310. package/dest/public/side_effect_trace.d.ts +0 -87
  311. package/dest/public/side_effect_trace.d.ts.map +0 -1
  312. package/dest/public/side_effect_trace.js +0 -199
  313. package/dest/public/side_effect_trace_interface.d.ts +0 -23
  314. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  315. package/dest/public/side_effect_trace_interface.js +0 -1
  316. package/dest/public/state_manager/index.d.ts +0 -2
  317. package/dest/public/state_manager/index.d.ts.map +0 -1
  318. package/dest/public/state_manager/index.js +0 -1
  319. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  320. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  321. package/dest/public/state_manager/nullifiers.js +0 -92
  322. package/dest/public/state_manager/public_storage.d.ts +0 -66
  323. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  324. package/dest/public/state_manager/public_storage.js +0 -145
  325. package/dest/public/state_manager/state_manager.d.ts +0 -166
  326. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  327. package/dest/public/state_manager/state_manager.js +0 -391
  328. package/dest/public/tx_contract_cache.d.ts +0 -41
  329. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  330. package/dest/public/tx_contract_cache.js +0 -49
  331. package/src/public/avm/avm_context.ts +0 -61
  332. package/src/public/avm/avm_contract_call_result.ts +0 -67
  333. package/src/public/avm/avm_execution_environment.ts +0 -48
  334. package/src/public/avm/avm_gas.ts +0 -183
  335. package/src/public/avm/avm_machine_state.ts +0 -169
  336. package/src/public/avm/avm_memory_types.ts +0 -436
  337. package/src/public/avm/avm_simulator.ts +0 -274
  338. package/src/public/avm/avm_simulator_interface.ts +0 -8
  339. package/src/public/avm/errors.ts +0 -163
  340. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -108
  341. package/src/public/avm/fixtures/initializers.ts +0 -104
  342. package/src/public/avm/index.ts +0 -1
  343. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  344. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  345. package/src/public/avm/opcodes/arithmetic.ts +0 -117
  346. package/src/public/avm/opcodes/bitwise.ts +0 -113
  347. package/src/public/avm/opcodes/comparators.ts +0 -55
  348. package/src/public/avm/opcodes/contract.ts +0 -75
  349. package/src/public/avm/opcodes/control_flow.ts +0 -123
  350. package/src/public/avm/opcodes/conversion.ts +0 -104
  351. package/src/public/avm/opcodes/ec_add.ts +0 -96
  352. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  353. package/src/public/avm/opcodes/external_calls.ts +0 -260
  354. package/src/public/avm/opcodes/hashing.ts +0 -145
  355. package/src/public/avm/opcodes/index.ts +0 -15
  356. package/src/public/avm/opcodes/instruction.ts +0 -136
  357. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  358. package/src/public/avm/opcodes/memory.ts +0 -293
  359. package/src/public/avm/opcodes/misc.ts +0 -102
  360. package/src/public/avm/opcodes/storage.ts +0 -87
  361. package/src/public/avm/revert_reason.ts +0 -55
  362. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  363. package/src/public/avm/serialization/bytecode_serialization.ts +0 -204
  364. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  365. package/src/public/avm/test_utils.ts +0 -64
  366. package/src/public/debug_fn_name.ts +0 -18
  367. package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
  368. package/src/public/fixtures/minimal_public_tx.ts +0 -36
  369. package/src/public/hinting_db_sources.ts +0 -505
  370. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -128
  371. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -109
  372. package/src/public/public_tx_simulator/public_tx_context.ts +0 -471
  373. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  374. package/src/public/side_effect_trace.ts +0 -290
  375. package/src/public/side_effect_trace_interface.ts +0 -28
  376. package/src/public/state_manager/index.ts +0 -1
  377. package/src/public/state_manager/nullifiers.ts +0 -103
  378. package/src/public/state_manager/public_storage.ts +0 -174
  379. package/src/public/state_manager/state_manager.ts +0 -560
  380. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,104 +0,0 @@
1
- import type { AvmContext } from '../avm_context.js';
2
- import { TypeTag, Uint1, Uint8 } from '../avm_memory_types.js';
3
- import { InvalidToRadixInputsError } from '../errors.js';
4
- import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
- import { Addressing } from './addressing_mode.js';
6
- import { Instruction } from './instruction.js';
7
-
8
- export class ToRadixBE extends Instruction {
9
- static type: string = 'TORADIXBE';
10
- static readonly opcode: Opcode = Opcode.TORADIXBE;
11
-
12
- // Informs (de)serialization. See Instruction.deserialize.
13
- static readonly wireFormat: OperandType[] = [
14
- OperandType.UINT8, // Opcode
15
- OperandType.UINT16, // Indirect
16
- OperandType.UINT16, // src memory address
17
- OperandType.UINT16, // radix memory address
18
- OperandType.UINT16, // number of limbs address
19
- OperandType.UINT16, // output is in "bits" mode memory address (boolean/Uint1 is stored)
20
- OperandType.UINT16, // dst memory address
21
- ];
22
-
23
- constructor(
24
- private indirect: number,
25
- private srcOffset: number,
26
- private radixOffset: number,
27
- private numLimbsOffset: number,
28
- private outputBitsOffset: number,
29
- private dstOffset: number,
30
- ) {
31
- super();
32
- }
33
-
34
- public async execute(context: AvmContext): Promise<void> {
35
- const memory = context.machineState.memory;
36
- const addressing = Addressing.fromWire(this.indirect);
37
-
38
- context.machineState.consumeGas(
39
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
40
- );
41
-
42
- const operands = [this.srcOffset, this.radixOffset, this.numLimbsOffset, this.outputBitsOffset, this.dstOffset];
43
- const [srcOffset, radixOffset, numLimbsOffset, outputBitsOffset, dstOffset] = addressing.resolve(operands, memory);
44
-
45
- // The radix gadget only takes in a Field
46
- memory.checkTag(TypeTag.FIELD, srcOffset);
47
- memory.checkTag(TypeTag.UINT32, radixOffset);
48
- memory.checkTag(TypeTag.UINT32, numLimbsOffset);
49
- memory.checkTag(TypeTag.UINT1, outputBitsOffset);
50
-
51
- const numLimbs = memory.get(numLimbsOffset).toNumber();
52
- const radix: bigint = memory.get(radixOffset).toBigInt();
53
- context.machineState.consumeGas(
54
- this.dynamicGasCost(Math.max(numLimbs, radix > 256n ? 32 : MODULUS_LIMBS_PER_RADIX[Number(radix)])),
55
- );
56
- const outputBits = memory.get(outputBitsOffset).toNumber();
57
-
58
- let value: bigint = memory.get(srcOffset).toBigInt();
59
-
60
- if (radix < 2 || radix > 256) {
61
- throw new InvalidToRadixInputsError(`ToRadixBE instruction's radix should be in range [2,256] (was ${radix}).`);
62
- }
63
-
64
- if (numLimbs < 1 && value != BigInt(0n)) {
65
- throw new InvalidToRadixInputsError(
66
- `ToRadixBE instruction's input value is not zero (was ${value}) but numLimbs zero.`,
67
- );
68
- }
69
-
70
- if (outputBits != 0 && radix != BigInt(2n)) {
71
- throw new InvalidToRadixInputsError(`Radix ${radix} is not equal to 2 and bit mode is activated.`);
72
- }
73
-
74
- const radixBN: bigint = BigInt(radix);
75
- const limbArray = new Array(numLimbs);
76
-
77
- for (let i = numLimbs - 1; i >= 0; i--) {
78
- const limb = value % radixBN;
79
- limbArray[i] = limb;
80
- value /= radixBN;
81
- }
82
-
83
- if (value !== 0n) {
84
- throw new InvalidToRadixInputsError(`Field failed to decompose in ${numLimbs} limbs.`);
85
- }
86
-
87
- const outputType = outputBits != 0 ? Uint1 : Uint8;
88
- const res = limbArray.map(byte => new outputType(byte));
89
- memory.setSlice(dstOffset, res);
90
- }
91
- }
92
-
93
- // First two are for radix = 0 and 1, which are invalid, so we have 0 limbs for those cases.
94
- export const MODULUS_LIMBS_PER_RADIX: number[] = [
95
- 0, 0, 254, 161, 127, 110, 99, 91, 85, 81, 77, 74, 71, 69, 67, 65, 64, 63, 61, 60, 59, 58, 57, 57, 56, 55, 54, 54, 53,
96
- 53, 52, 52, 51, 51, 50, 50, 50, 49, 49, 48, 48, 48, 48, 47, 47, 47, 46, 46, 46, 46, 45, 45, 45, 45, 45, 44, 44, 44,
97
- 44, 44, 43, 43, 43, 43, 43, 43, 42, 42, 42, 42, 42, 42, 42, 41, 41, 41, 41, 41, 41, 41, 41, 41, 40, 40, 40, 40, 40,
98
- 40, 40, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
99
- 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
100
- 36, 36, 36, 36, 36, 36, 36, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
101
- 35, 35, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
102
- 34, 34, 34, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
103
- 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
104
- ];
@@ -1,96 +0,0 @@
1
- import { Grumpkin } from '@aztec/foundation/crypto';
2
- import { Point } from '@aztec/foundation/fields';
3
-
4
- import type { AvmContext } from '../avm_context.js';
5
- import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
6
- import { EcAddPointNotOnCurveError } from '../errors.js';
7
- import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
8
- import { Addressing } from './addressing_mode.js';
9
- import { Instruction } from './instruction.js';
10
-
11
- export class EcAdd extends Instruction {
12
- static type: string = 'ECADD';
13
- static readonly opcode = Opcode.ECADD;
14
-
15
- // Informs (de)serialization. See Instruction.deserialize.
16
- static readonly wireFormat: OperandType[] = [
17
- OperandType.UINT8, // reserved
18
- OperandType.UINT16, // indirect
19
- OperandType.UINT16, // p1X
20
- OperandType.UINT16, // p1Y
21
- OperandType.UINT16, // p1IsInfinite
22
- OperandType.UINT16, // p2X
23
- OperandType.UINT16, // p2Y
24
- OperandType.UINT16, // p2IsInfinite
25
- OperandType.UINT16, // dst
26
- ];
27
-
28
- constructor(
29
- private indirect: number,
30
- private p1XOffset: number,
31
- private p1YOffset: number,
32
- private p1IsInfiniteOffset: number,
33
- private p2XOffset: number,
34
- private p2YOffset: number,
35
- private p2IsInfiniteOffset: number,
36
- private dstOffset: number,
37
- ) {
38
- super();
39
- }
40
-
41
- public async execute(context: AvmContext): Promise<void> {
42
- const memory = context.machineState.memory;
43
- const addressing = Addressing.fromWire(this.indirect);
44
-
45
- context.machineState.consumeGas(
46
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
47
- );
48
-
49
- const operands = [
50
- this.p1XOffset,
51
- this.p1YOffset,
52
- this.p1IsInfiniteOffset,
53
- this.p2XOffset,
54
- this.p2YOffset,
55
- this.p2IsInfiniteOffset,
56
- this.dstOffset,
57
- ];
58
- const [p1XOffset, p1YOffset, p1IsInfiniteOffset, p2XOffset, p2YOffset, p2IsInfiniteOffset, dstOffset] =
59
- addressing.resolve(operands, memory);
60
-
61
- memory.checkTags(TypeTag.FIELD, p1XOffset, p1YOffset, p2XOffset, p2YOffset);
62
- memory.checkTags(TypeTag.UINT1, p1IsInfiniteOffset, p2IsInfiniteOffset);
63
-
64
- const p1X = memory.get(p1XOffset);
65
- const p1Y = memory.get(p1YOffset);
66
- const p1IsInfinite = memory.get(p1IsInfiniteOffset).toNumber() === 1;
67
- const p1 = new Point(p1X.toFr(), p1Y.toFr(), p1IsInfinite);
68
- if (!p1.isOnGrumpkin()) {
69
- throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 1, p1);
70
- }
71
-
72
- const p2X = memory.get(p2XOffset);
73
- const p2Y = memory.get(p2YOffset);
74
- // unused. Point doesn't store this information
75
- const p2IsInfinite = memory.get(p2IsInfiniteOffset).toNumber() === 1;
76
- const p2 = new Point(p2X.toFr(), p2Y.toFr(), p2IsInfinite);
77
- if (!p2.isOnGrumpkin()) {
78
- throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 2, p2);
79
- }
80
-
81
- let dest;
82
- if (p1IsInfinite) {
83
- dest = p2;
84
- } else if (p2IsInfinite) {
85
- dest = p1;
86
- } else {
87
- dest = await Grumpkin.add(p1, p2);
88
- }
89
-
90
- // Important to use setSlice() and not set() in the two following statements as
91
- // this checks that the offsets lie within memory range.
92
- memory.setSlice(dstOffset, [new Field(dest.x), new Field(dest.y)]);
93
- // Check representation of infinity for grumpkin
94
- memory.setSlice(dstOffset + 2, [new Uint1(dest.equals(Point.ZERO) ? 1 : 0)]);
95
- }
96
- }
@@ -1,87 +0,0 @@
1
- import type { AvmContext } from '../avm_context.js';
2
- import { Field, Uint1, Uint32, Uint64, Uint128 } from '../avm_memory_types.js';
3
- import { InstructionExecutionError } from '../errors.js';
4
- import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
- import { Addressing } from './addressing_mode.js';
6
- import { Instruction } from './instruction.js';
7
-
8
- export enum EnvironmentVariable {
9
- ADDRESS,
10
- SENDER,
11
- TRANSACTIONFEE,
12
- CHAINID,
13
- VERSION,
14
- BLOCKNUMBER,
15
- TIMESTAMP,
16
- BASEFEEPERL2GAS,
17
- BASEFEEPERDAGAS,
18
- ISSTATICCALL,
19
- L2GASLEFT,
20
- DAGASLEFT,
21
- }
22
-
23
- function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
24
- switch (varEnum) {
25
- case EnvironmentVariable.ADDRESS:
26
- return new Field(ctx.environment.address.toField());
27
- case EnvironmentVariable.SENDER:
28
- return new Field(ctx.environment.sender.toField());
29
- case EnvironmentVariable.TRANSACTIONFEE:
30
- return new Field(ctx.environment.transactionFee);
31
- case EnvironmentVariable.CHAINID:
32
- return new Field(ctx.environment.globals.chainId);
33
- case EnvironmentVariable.VERSION:
34
- return new Field(ctx.environment.globals.version);
35
- case EnvironmentVariable.BLOCKNUMBER:
36
- return new Uint32(ctx.environment.globals.blockNumber);
37
- case EnvironmentVariable.TIMESTAMP:
38
- return new Uint64(ctx.environment.globals.timestamp);
39
- case EnvironmentVariable.BASEFEEPERL2GAS:
40
- return new Uint128(ctx.environment.globals.gasFees.feePerL2Gas);
41
- case EnvironmentVariable.BASEFEEPERDAGAS:
42
- return new Uint128(ctx.environment.globals.gasFees.feePerDaGas);
43
- case EnvironmentVariable.ISSTATICCALL:
44
- return new Uint1(ctx.environment.isStaticCall ? 1 : 0);
45
- case EnvironmentVariable.L2GASLEFT:
46
- return new Uint32(ctx.machineState.l2GasLeft);
47
- case EnvironmentVariable.DAGASLEFT:
48
- return new Uint32(ctx.machineState.daGasLeft);
49
- default:
50
- throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${varEnum}`);
51
- }
52
- }
53
-
54
- export class GetEnvVar extends Instruction {
55
- public static readonly type: string = 'GETENVVAR';
56
- public static readonly opcode: Opcode = Opcode.GETENVVAR_16;
57
- static readonly wireFormat16: OperandType[] = [
58
- OperandType.UINT8, // opcode
59
- OperandType.UINT8, // indirect
60
- OperandType.UINT16, // dstOffset
61
- OperandType.UINT8, // variable enum (immediate)
62
- ];
63
-
64
- constructor(
65
- private indirect: number,
66
- private dstOffset: number,
67
- private varEnum: number,
68
- ) {
69
- super();
70
- }
71
-
72
- public async execute(context: AvmContext): Promise<void> {
73
- const memory = context.machineState.memory;
74
- const addressing = Addressing.fromWire(this.indirect);
75
-
76
- context.machineState.consumeGas(
77
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
78
- );
79
-
80
- const operands = [this.dstOffset];
81
- const [dstOffset] = addressing.resolve(operands, memory);
82
-
83
- const value = getValue(this.varEnum as EnvironmentVariable, context);
84
-
85
- memory.set(dstOffset, value);
86
- }
87
- }
@@ -1,260 +0,0 @@
1
- import type { AvmContext } from '../avm_context.js';
2
- import type { AvmContractCallResult } from '../avm_contract_call_result.js';
3
- import { type Field, TypeTag, Uint1 } from '../avm_memory_types.js';
4
- import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
- import { Addressing } from './addressing_mode.js';
6
- import { Instruction } from './instruction.js';
7
-
8
- abstract class ExternalCall extends Instruction {
9
- // Informs (de)serialization. See Instruction.deserialize.
10
- static readonly wireFormat: OperandType[] = [
11
- OperandType.UINT8,
12
- OperandType.UINT16, // Indirect
13
- OperandType.UINT16, // L2 gas offset
14
- OperandType.UINT16, // DA gas offset
15
- OperandType.UINT16, // Address offset
16
- OperandType.UINT16, // Args offset
17
- OperandType.UINT16, // Args size offset
18
- ];
19
-
20
- constructor(
21
- private indirect: number,
22
- private l2GasOffset: number,
23
- private daGasOffset: number,
24
- private addrOffset: number,
25
- private argsSizeOffset: number,
26
- private argsOffset: number,
27
- ) {
28
- super();
29
- }
30
-
31
- public async execute(context: AvmContext) {
32
- const memory = context.machineState.memory;
33
- const addressing = Addressing.fromWire(this.indirect);
34
-
35
- context.machineState.consumeGas(
36
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
37
- );
38
-
39
- const operands = [this.l2GasOffset, this.daGasOffset, this.addrOffset, this.argsSizeOffset, this.argsOffset];
40
- const [l2GasOffset, daGasOffset, addrOffset, argsSizeOffset, argsOffset] = addressing.resolve(operands, memory);
41
-
42
- memory.checkTags(TypeTag.UINT32, l2GasOffset);
43
- memory.checkTags(TypeTag.UINT32, daGasOffset);
44
- memory.checkTag(TypeTag.FIELD, addrOffset);
45
- memory.checkTag(TypeTag.UINT32, argsSizeOffset);
46
-
47
- const calldataSize = memory.get(argsSizeOffset).toNumber();
48
- const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
-
50
- const callAddress = memory.getAs<Field>(addrOffset);
51
- // If we are already in a static call, we propagate the environment.
52
- const callType = context.environment.isStaticCall ? 'STATICCALL' : this.type;
53
-
54
- // We consume the gas allocated for the nested call. The excess will be refunded later.
55
- // Gas allocation is capped by the amount of gas left in the current context.
56
- // We have to do some dancing here because the gas allocation is a field,
57
- // but in the machine state we track gas as a number.
58
- const allocatedL2Gas = Number(
59
- BigIntMin(memory.get(l2GasOffset).toBigInt(), BigInt(context.machineState.l2GasLeft)),
60
- );
61
- const allocatedDaGas = Number(
62
- BigIntMin(memory.get(daGasOffset).toBigInt(), BigInt(context.machineState.daGasLeft)),
63
- );
64
- const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas };
65
- context.machineState.consumeGas(allocatedGas);
66
-
67
- const aztecAddress = callAddress.toAztecAddress();
68
- const nestedContext = await context.createNestedContractCallContext(aztecAddress, calldata, allocatedGas, callType);
69
-
70
- const simulator = await context.provideSimulator!(nestedContext);
71
- const nestedCallResults: AvmContractCallResult = await simulator.execute();
72
- const success = !nestedCallResults.reverted;
73
-
74
- // Save return/revert data for later.
75
- const fullReturnData = nestedCallResults.output;
76
- context.machineState.nestedReturndata = fullReturnData;
77
-
78
- // Track the success status directly
79
- context.machineState.nestedCallSuccess = success;
80
-
81
- // Account for all instructions executed in the nested call
82
- context.machineState.instrCounter += nestedCallResults.totalInstructions;
83
-
84
- // If the nested call reverted, we try to save the reason and the revert data.
85
- // This will be used by the caller to try to reconstruct the call stack.
86
- // This is only a heuristic and may not always work. It is intended to work
87
- // for the case where a nested call reverts and the caller always rethrows
88
- // (in Noir code).
89
- if (!success) {
90
- context.machineState.collectedRevertInfo = {
91
- revertDataRepresentative: fullReturnData,
92
- recursiveRevertReason: nestedCallResults.revertReason!,
93
- };
94
- }
95
-
96
- // Refund unused gas
97
- context.machineState.refundGas(nestedCallResults.gasLeft);
98
-
99
- // Merge nested call's state and trace based on whether it succeeded.
100
- if (success) {
101
- await context.persistableState.merge(nestedContext.persistableState);
102
- } else {
103
- await context.persistableState.reject(nestedContext.persistableState);
104
- }
105
- }
106
-
107
- public abstract override get type(): 'CALL' | 'STATICCALL';
108
- }
109
-
110
- export class Call extends ExternalCall {
111
- static type = 'CALL' as const;
112
- static readonly opcode: Opcode = Opcode.CALL;
113
-
114
- public get type() {
115
- return Call.type;
116
- }
117
- }
118
-
119
- export class StaticCall extends ExternalCall {
120
- static type = 'STATICCALL' as const;
121
- static readonly opcode: Opcode = Opcode.STATICCALL;
122
-
123
- public get type() {
124
- return StaticCall.type;
125
- }
126
- }
127
-
128
- export class SuccessCopy extends Instruction {
129
- static type: string = 'SUCCESSCOPY';
130
- static readonly opcode: Opcode = Opcode.SUCCESSCOPY;
131
- // Informs (de)serialization. See Instruction.deserialize.
132
- static readonly wireFormat: OperandType[] = [
133
- OperandType.UINT8,
134
- OperandType.UINT8, // Indirect (8-bit)
135
- OperandType.UINT16, // dstOffset (16-bit)
136
- ];
137
-
138
- constructor(
139
- private indirect: number,
140
- private dstOffset: number,
141
- ) {
142
- super();
143
- }
144
-
145
- public async execute(context: AvmContext): Promise<void> {
146
- const memory = context.machineState.memory;
147
- const addressing = Addressing.fromWire(this.indirect);
148
-
149
- context.machineState.consumeGas(
150
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
151
- );
152
-
153
- const operands = [this.dstOffset];
154
- const [dstOffset] = addressing.resolve(operands, memory);
155
-
156
- // Use the direct success tracking property
157
- const success = context.machineState.nestedCallSuccess;
158
-
159
- // Write the success flag to the provided memory location
160
- memory.set(dstOffset, new Uint1(success ? 1 : 0));
161
- }
162
- }
163
-
164
- export class Return extends Instruction {
165
- static type: string = 'RETURN';
166
- static readonly opcode: Opcode = Opcode.RETURN;
167
- // Informs (de)serialization. See Instruction.deserialize.
168
- static readonly wireFormat: OperandType[] = [
169
- OperandType.UINT8,
170
- OperandType.UINT8,
171
- OperandType.UINT16,
172
- OperandType.UINT16,
173
- ];
174
-
175
- constructor(
176
- private indirect: number,
177
- private returnSizeOffset: number,
178
- private returnOffset: number,
179
- ) {
180
- super();
181
- }
182
-
183
- public async execute(context: AvmContext): Promise<void> {
184
- const memory = context.machineState.memory;
185
- const addressing = Addressing.fromWire(this.indirect);
186
-
187
- context.machineState.consumeGas(
188
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
189
- );
190
-
191
- const operands = [this.returnSizeOffset, this.returnOffset];
192
- const [returnSizeOffset, returnOffset] = addressing.resolve(operands, memory);
193
-
194
- memory.checkTag(TypeTag.UINT32, returnSizeOffset);
195
- const returnSize = memory.get(returnSizeOffset).toNumber();
196
-
197
- const output = memory.getSlice(returnOffset, returnSize).map(word => word.toFr());
198
-
199
- context.machineState.return(output);
200
- }
201
-
202
- public override handlesPC(): boolean {
203
- return true;
204
- }
205
- }
206
-
207
- export class Revert extends Instruction {
208
- static type: string = 'REVERT';
209
- static readonly opcode: Opcode = Opcode.REVERT_8;
210
-
211
- static readonly wireFormat8: OperandType[] = [
212
- OperandType.UINT8,
213
- OperandType.UINT8,
214
- OperandType.UINT8,
215
- OperandType.UINT8,
216
- ];
217
- static readonly wireFormat16: OperandType[] = [
218
- OperandType.UINT8,
219
- OperandType.UINT8,
220
- OperandType.UINT16,
221
- OperandType.UINT16,
222
- ];
223
-
224
- constructor(
225
- private indirect: number,
226
- private retSizeOffset: number,
227
- private returnOffset: number,
228
- ) {
229
- super();
230
- }
231
-
232
- public async execute(context: AvmContext): Promise<void> {
233
- const memory = context.machineState.memory;
234
- const addressing = Addressing.fromWire(this.indirect);
235
-
236
- context.machineState.consumeGas(
237
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
238
- );
239
-
240
- const operands = [this.retSizeOffset, this.returnOffset];
241
- const [retSizeOffset, returnOffset] = addressing.resolve(operands, memory);
242
-
243
- memory.checkTag(TypeTag.UINT32, retSizeOffset);
244
- const retSize = memory.get(retSizeOffset).toNumber();
245
- const output = memory.getSlice(returnOffset, retSize).map(word => word.toFr());
246
-
247
- context.machineState.revert(output);
248
- }
249
-
250
- // We don't want to increase the PC after reverting because it breaks messages.
251
- // Maybe we can remove this once messages don't depend on PCs.
252
- public override handlesPC(): boolean {
253
- return true;
254
- }
255
- }
256
-
257
- /** Returns the smaller of two bigints. */
258
- function BigIntMin(a: bigint, b: bigint): bigint {
259
- return a < b ? a : b;
260
- }
@@ -1,145 +0,0 @@
1
- import { keccakf1600, poseidon2Permutation, sha256Compression } from '@aztec/foundation/crypto';
2
-
3
- import type { AvmContext } from '../avm_context.js';
4
- import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
5
- import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
- import { Addressing } from './addressing_mode.js';
7
- import { Instruction } from './instruction.js';
8
-
9
- export class Poseidon2 extends Instruction {
10
- static type: string = 'POSEIDON2';
11
- static readonly opcode: Opcode = Opcode.POSEIDON2;
12
- static readonly stateSize = 4;
13
-
14
- // Informs (de)serialization. See Instruction.deserialize.
15
- static readonly wireFormat: OperandType[] = [
16
- OperandType.UINT8,
17
- OperandType.UINT8,
18
- OperandType.UINT16,
19
- OperandType.UINT16,
20
- ];
21
-
22
- constructor(
23
- private indirect: number,
24
- private inputStateOffset: number,
25
- private outputStateOffset: number,
26
- ) {
27
- super();
28
- }
29
-
30
- public async execute(context: AvmContext): Promise<void> {
31
- const memory = context.machineState.memory;
32
- const addressing = Addressing.fromWire(this.indirect);
33
-
34
- context.machineState.consumeGas(
35
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
36
- );
37
-
38
- const operands = [this.inputStateOffset, this.outputStateOffset];
39
-
40
- const [inputOffset, outputOffset] = addressing.resolve(operands, memory);
41
-
42
- const inputState = memory.getSlice(inputOffset, Poseidon2.stateSize);
43
- memory.checkTagsRange(TypeTag.FIELD, inputOffset, Poseidon2.stateSize);
44
-
45
- const outputState = await poseidon2Permutation(inputState);
46
- memory.setSlice(
47
- outputOffset,
48
- outputState.map(word => new Field(word)),
49
- );
50
- }
51
- }
52
-
53
- export class KeccakF1600 extends Instruction {
54
- static type: string = 'KECCAKF1600';
55
- static readonly opcode: Opcode = Opcode.KECCAKF1600;
56
-
57
- // Informs (de)serialization. See Instruction.deserialize.
58
- static readonly wireFormat: OperandType[] = [
59
- OperandType.UINT8,
60
- OperandType.UINT8,
61
- OperandType.UINT16,
62
- OperandType.UINT16,
63
- ];
64
-
65
- constructor(
66
- private indirect: number,
67
- private dstOffset: number,
68
- private inputOffset: number,
69
- ) {
70
- super();
71
- }
72
-
73
- // pub fn keccakf1600(input: [u64; 25]) -> [u64; 25]
74
- public async execute(context: AvmContext): Promise<void> {
75
- const inputSize = 25;
76
- const memory = context.machineState.memory;
77
- const addressing = Addressing.fromWire(this.indirect);
78
-
79
- context.machineState.consumeGas(
80
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
81
- );
82
-
83
- const operands = [this.dstOffset, this.inputOffset];
84
- const [dstOffset, inputOffset] = addressing.resolve(operands, memory);
85
-
86
- const stateData = memory.getSlice(inputOffset, inputSize).map(word => word.toBigInt());
87
- memory.checkTagsRange(TypeTag.UINT64, inputOffset, inputSize);
88
-
89
- const updatedState = keccakf1600(stateData);
90
-
91
- const res = updatedState.map(word => new Uint64(word));
92
- memory.setSlice(dstOffset, res);
93
- }
94
- }
95
-
96
- export class Sha256Compression extends Instruction {
97
- static type: string = 'SHA256COMPRESSION';
98
- static readonly opcode: Opcode = Opcode.SHA256COMPRESSION;
99
-
100
- // Informs (de)serialization. See Instruction.deserialize.
101
- static readonly wireFormat: OperandType[] = [
102
- OperandType.UINT8,
103
- OperandType.UINT8,
104
- OperandType.UINT16,
105
- OperandType.UINT16,
106
- OperandType.UINT16,
107
- ];
108
-
109
- constructor(
110
- private indirect: number,
111
- private outputOffset: number,
112
- private stateOffset: number,
113
- private inputsOffset: number,
114
- ) {
115
- super();
116
- }
117
-
118
- public async execute(context: AvmContext): Promise<void> {
119
- const STATE_SIZE = 8;
120
- const INPUTS_SIZE = 16;
121
-
122
- const memory = context.machineState.memory;
123
- const addressing = Addressing.fromWire(this.indirect);
124
-
125
- context.machineState.consumeGas(
126
- this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
127
- );
128
-
129
- const operands = [this.outputOffset, this.stateOffset, this.inputsOffset];
130
- const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
131
-
132
- // Note: size of output is same as size of state
133
- const inputs = Uint32Array.from(memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toNumber()));
134
- const state = Uint32Array.from(memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toNumber()));
135
-
136
- memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
137
- memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
138
-
139
- const output = sha256Compression(state, inputs);
140
-
141
- // Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
142
- const res = [...output].map(word => new Uint32(word));
143
- memory.setSlice(outputOffset, res);
144
- }
145
- }