@aztec/simulator 3.0.0-canary.a9708bd → 3.0.0-devnet.2-patch.1

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 (342) hide show
  1. package/dest/client.d.ts +1 -1
  2. package/dest/common/errors.d.ts +2 -8
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/common/index.d.ts +1 -1
  5. package/dest/common/stats/index.d.ts +1 -1
  6. package/dest/common/stats/stats.d.ts +1 -1
  7. package/dest/private/acvm/acvm.d.ts +1 -1
  8. package/dest/private/acvm/acvm_types.d.ts +1 -1
  9. package/dest/private/acvm/deserialize.d.ts +2 -2
  10. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  11. package/dest/private/acvm/deserialize.js +1 -1
  12. package/dest/private/acvm/index.d.ts +1 -1
  13. package/dest/private/acvm/serialize.d.ts +2 -2
  14. package/dest/private/acvm/serialize.d.ts.map +1 -1
  15. package/dest/private/acvm/serialize.js +1 -1
  16. package/dest/private/acvm_native.d.ts +2 -3
  17. package/dest/private/acvm_native.d.ts.map +1 -1
  18. package/dest/private/acvm_native.js +15 -13
  19. package/dest/private/acvm_wasm.d.ts +1 -1
  20. package/dest/private/acvm_wasm.d.ts.map +1 -1
  21. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  22. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  23. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  24. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  25. package/dest/private/circuit_recording/circuit_recorder.js +1 -1
  26. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
  27. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  28. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
  29. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  30. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +2 -2
  31. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  32. package/dest/private/circuit_simulator.d.ts +1 -1
  33. package/dest/private/factory.d.ts +1 -1
  34. package/dest/public/avm/avm_context.d.ts +2 -2
  35. package/dest/public/avm/avm_context.d.ts.map +1 -1
  36. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  37. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  38. package/dest/public/avm/avm_execution_environment.d.ts +5 -4
  39. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  40. package/dest/public/avm/avm_execution_environment.js +5 -5
  41. package/dest/public/avm/avm_gas.d.ts +2 -2
  42. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  43. package/dest/public/avm/avm_gas.js +2 -2
  44. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  45. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  46. package/dest/public/avm/avm_memory_types.d.ts +20 -14
  47. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  48. package/dest/public/avm/avm_memory_types.js +10 -3
  49. package/dest/public/avm/avm_simulator.d.ts +4 -3
  50. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  51. package/dest/public/avm/avm_simulator.js +19 -25
  52. package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
  53. package/dest/public/avm/errors.d.ts +13 -16
  54. package/dest/public/avm/errors.d.ts.map +1 -1
  55. package/dest/public/avm/errors.js +21 -22
  56. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +3 -2
  57. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  58. package/dest/public/avm/fixtures/avm_simulation_tester.js +14 -6
  59. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +4 -2
  60. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  61. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +23 -1
  62. package/dest/public/avm/fixtures/initializers.d.ts +2 -3
  63. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  64. package/dest/public/avm/fixtures/initializers.js +6 -4
  65. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  66. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  67. package/dest/public/avm/fixtures/utils.js +3 -2
  68. package/dest/public/avm/index.d.ts +1 -1
  69. package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
  70. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/accrued_substate.js +7 -7
  72. package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
  73. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/addressing_mode.js +4 -5
  75. package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
  76. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/arithmetic.js +11 -1
  78. package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
  79. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  81. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  82. package/dest/public/avm/opcodes/contract.d.ts +1 -1
  83. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  84. package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
  85. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/conversion.d.ts +1 -1
  87. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  88. package/dest/public/avm/opcodes/conversion.js +3 -0
  89. package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
  90. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  91. package/dest/public/avm/opcodes/ec_add.js +6 -6
  92. package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
  93. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  94. package/dest/public/avm/opcodes/environment_getters.js +5 -7
  95. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  96. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  97. package/dest/public/avm/opcodes/external_calls.js +0 -1
  98. package/dest/public/avm/opcodes/hashing.d.ts +2 -2
  99. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  100. package/dest/public/avm/opcodes/hashing.js +3 -1
  101. package/dest/public/avm/opcodes/index.d.ts +1 -1
  102. package/dest/public/avm/opcodes/instruction.d.ts +2 -2
  103. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  104. package/dest/public/avm/opcodes/instruction.js +5 -6
  105. package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
  106. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  107. package/dest/public/avm/opcodes/memory.d.ts +2 -2
  108. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  109. package/dest/public/avm/opcodes/memory.js +1 -1
  110. package/dest/public/avm/opcodes/misc.d.ts +3 -2
  111. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  112. package/dest/public/avm/opcodes/misc.js +28 -8
  113. package/dest/public/avm/opcodes/storage.d.ts +3 -3
  114. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  115. package/dest/public/avm/revert_reason.d.ts +2 -2
  116. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  117. package/dest/public/avm/revert_reason.js +3 -2
  118. package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
  119. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
  120. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  121. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  122. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  123. package/dest/public/avm/serialization/instruction_serialization.d.ts +9 -1
  124. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  125. package/dest/public/avm/serialization/instruction_serialization.js +11 -1
  126. package/dest/public/avm/test_utils.d.ts +4 -4
  127. package/dest/public/avm/test_utils.d.ts.map +1 -1
  128. package/dest/public/avm/test_utils.js +7 -10
  129. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  130. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  131. package/dest/public/contracts_db_checkpoint.js +30 -0
  132. package/dest/public/db_interfaces.d.ts +14 -2
  133. package/dest/public/db_interfaces.d.ts.map +1 -1
  134. package/dest/public/debug_fn_name.d.ts +15 -2
  135. package/dest/public/debug_fn_name.d.ts.map +1 -1
  136. package/dest/public/debug_fn_name.js +19 -0
  137. package/dest/public/executor_metrics.d.ts +3 -2
  138. package/dest/public/executor_metrics.d.ts.map +1 -1
  139. package/dest/public/executor_metrics.js +1 -1
  140. package/dest/public/executor_metrics_interface.d.ts +3 -2
  141. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  142. package/dest/public/fixtures/amm_test.d.ts +1 -1
  143. package/dest/public/fixtures/amm_test.js +2 -2
  144. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  145. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  146. package/dest/public/fixtures/bulk_test.js +64 -131
  147. package/dest/public/fixtures/custom_bytecode_tester.d.ts +12 -0
  148. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
  149. package/dest/public/fixtures/custom_bytecode_tester.js +29 -0
  150. package/dest/public/fixtures/custom_bytecode_tests.d.ts +10 -0
  151. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
  152. package/dest/public/fixtures/custom_bytecode_tests.js +130 -0
  153. package/dest/public/fixtures/index.d.ts +3 -2
  154. package/dest/public/fixtures/index.d.ts.map +1 -1
  155. package/dest/public/fixtures/index.js +2 -1
  156. package/dest/public/fixtures/minimal_public_tx.d.ts +4 -4
  157. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  158. package/dest/public/fixtures/minimal_public_tx.js +8 -22
  159. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +11 -4
  160. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  161. package/dest/public/fixtures/public_tx_simulation_tester.js +29 -10
  162. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  163. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  164. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  165. package/dest/public/fixtures/token_test.d.ts +6 -2
  166. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  167. package/dest/public/fixtures/token_test.js +13 -12
  168. package/dest/public/fixtures/utils.d.ts +2 -2
  169. package/dest/public/fixtures/utils.d.ts.map +1 -1
  170. package/dest/public/fixtures/utils.js +4 -4
  171. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
  172. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  173. package/dest/public/fuzzing/avm_fuzzer_simulator.js +136 -0
  174. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  175. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  176. package/dest/public/fuzzing/avm_simulator_bin.js +84 -0
  177. package/dest/public/hinting_db_sources.d.ts +15 -4
  178. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  179. package/dest/public/hinting_db_sources.js +69 -13
  180. package/dest/public/index.d.ts +3 -2
  181. package/dest/public/index.d.ts.map +1 -1
  182. package/dest/public/index.js +1 -1
  183. package/dest/public/public_db_sources.d.ts +24 -65
  184. package/dest/public/public_db_sources.d.ts.map +1 -1
  185. package/dest/public/public_db_sources.js +85 -132
  186. package/dest/public/public_errors.d.ts +12 -0
  187. package/dest/public/public_errors.d.ts.map +1 -0
  188. package/dest/public/public_errors.js +13 -0
  189. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -2
  190. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  191. package/dest/public/public_processor/guarded_merkle_tree.js +3 -0
  192. package/dest/public/public_processor/public_processor.d.ts +11 -13
  193. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  194. package/dest/public/public_processor/public_processor.js +61 -43
  195. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  196. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  197. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
  198. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  199. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +94 -0
  200. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +38 -0
  201. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
  202. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +93 -0
  203. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  204. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  205. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  206. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  207. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  208. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +170 -0
  209. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  210. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  211. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  212. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  213. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  214. package/dest/public/public_tx_simulator/factories.js +28 -0
  215. package/dest/public/public_tx_simulator/index.d.ts +6 -1
  216. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  217. package/dest/public/public_tx_simulator/index.js +3 -0
  218. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +16 -8
  219. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  220. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +7 -8
  221. package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -4
  222. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  223. package/dest/public/public_tx_simulator/public_tx_context.js +22 -10
  224. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +22 -29
  225. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  226. package/dest/public/public_tx_simulator/public_tx_simulator.js +178 -127
  227. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +9 -0
  228. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
  229. package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
  230. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -3
  231. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  232. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
  233. package/dest/public/side_effect_errors.d.ts +42 -2
  234. package/dest/public/side_effect_errors.d.ts.map +1 -1
  235. package/dest/public/side_effect_errors.js +70 -1
  236. package/dest/public/side_effect_trace.d.ts +13 -7
  237. package/dest/public/side_effect_trace.d.ts.map +1 -1
  238. package/dest/public/side_effect_trace.js +36 -21
  239. package/dest/public/side_effect_trace_interface.d.ts +9 -4
  240. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  241. package/dest/public/state_manager/index.d.ts +1 -1
  242. package/dest/public/state_manager/nullifiers.d.ts +2 -5
  243. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  244. package/dest/public/state_manager/nullifiers.js +1 -6
  245. package/dest/public/state_manager/public_storage.d.ts +2 -2
  246. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  247. package/dest/public/state_manager/public_storage.js +1 -1
  248. package/dest/public/state_manager/state_manager.d.ts +16 -13
  249. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  250. package/dest/public/state_manager/state_manager.js +64 -21
  251. package/dest/public/test_executor_metrics.d.ts +4 -3
  252. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  253. package/dest/public/test_executor_metrics.js +5 -4
  254. package/dest/public/unique_class_ids.d.ts +1 -1
  255. package/dest/public/unique_class_ids.d.ts.map +1 -1
  256. package/dest/public/utils.d.ts +1 -1
  257. package/dest/server.d.ts +1 -1
  258. package/dest/testing.d.ts +1 -1
  259. package/package.json +24 -19
  260. package/src/common/errors.ts +1 -1
  261. package/src/private/acvm/deserialize.ts +1 -1
  262. package/src/private/acvm/serialize.ts +1 -1
  263. package/src/private/acvm_native.ts +18 -11
  264. package/src/private/circuit_recording/circuit_recorder.ts +1 -1
  265. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +1 -1
  266. package/src/public/avm/avm_context.ts +1 -1
  267. package/src/public/avm/avm_contract_call_result.ts +1 -1
  268. package/src/public/avm/avm_execution_environment.ts +4 -3
  269. package/src/public/avm/avm_gas.ts +5 -5
  270. package/src/public/avm/avm_machine_state.ts +1 -1
  271. package/src/public/avm/avm_memory_types.ts +12 -3
  272. package/src/public/avm/avm_simulator.ts +24 -33
  273. package/src/public/avm/errors.ts +24 -27
  274. package/src/public/avm/fixtures/avm_simulation_tester.ts +14 -4
  275. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +33 -1
  276. package/src/public/avm/fixtures/initializers.ts +7 -8
  277. package/src/public/avm/fixtures/utils.ts +3 -2
  278. package/src/public/avm/opcodes/accrued_substate.ts +4 -4
  279. package/src/public/avm/opcodes/addressing_mode.ts +5 -5
  280. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  281. package/src/public/avm/opcodes/conversion.ts +4 -0
  282. package/src/public/avm/opcodes/ec_add.ts +6 -6
  283. package/src/public/avm/opcodes/environment_getters.ts +6 -8
  284. package/src/public/avm/opcodes/external_calls.ts +0 -1
  285. package/src/public/avm/opcodes/hashing.ts +3 -1
  286. package/src/public/avm/opcodes/instruction.ts +8 -6
  287. package/src/public/avm/opcodes/memory.ts +1 -1
  288. package/src/public/avm/opcodes/misc.ts +41 -7
  289. package/src/public/avm/revert_reason.ts +6 -3
  290. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  291. package/src/public/avm/serialization/instruction_serialization.ts +13 -1
  292. package/src/public/avm/test_utils.ts +7 -15
  293. package/src/public/contracts_db_checkpoint.ts +41 -0
  294. package/src/public/db_interfaces.ts +16 -1
  295. package/src/public/debug_fn_name.ts +26 -1
  296. package/src/public/executor_metrics.ts +2 -1
  297. package/src/public/executor_metrics_interface.ts +2 -1
  298. package/src/public/fixtures/amm_test.ts +2 -2
  299. package/src/public/fixtures/bulk_test.ts +42 -24
  300. package/src/public/fixtures/custom_bytecode_tester.ts +49 -0
  301. package/src/public/fixtures/custom_bytecode_tests.ts +159 -0
  302. package/src/public/fixtures/index.ts +2 -1
  303. package/src/public/fixtures/minimal_public_tx.ts +9 -33
  304. package/src/public/fixtures/public_tx_simulation_tester.ts +52 -17
  305. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  306. package/src/public/fixtures/token_test.ts +18 -10
  307. package/src/public/fixtures/utils.ts +4 -4
  308. package/src/public/fuzzing/avm_fuzzer_simulator.ts +233 -0
  309. package/src/public/fuzzing/avm_simulator_bin.ts +121 -0
  310. package/src/public/hinting_db_sources.ts +113 -10
  311. package/src/public/index.ts +8 -1
  312. package/src/public/public_db_sources.ts +112 -175
  313. package/src/public/public_errors.ts +14 -0
  314. package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
  315. package/src/public/public_processor/public_processor.ts +92 -70
  316. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +116 -0
  317. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +155 -0
  318. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  319. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +236 -0
  320. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  321. package/src/public/public_tx_simulator/factories.ts +41 -0
  322. package/src/public/public_tx_simulator/index.ts +5 -0
  323. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +13 -14
  324. package/src/public/public_tx_simulator/public_tx_context.ts +20 -7
  325. package/src/public/public_tx_simulator/public_tx_simulator.ts +265 -179
  326. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +10 -0
  327. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -13
  328. package/src/public/side_effect_errors.ts +91 -1
  329. package/src/public/side_effect_trace.ts +49 -24
  330. package/src/public/side_effect_trace_interface.ts +7 -1
  331. package/src/public/state_manager/nullifiers.ts +2 -8
  332. package/src/public/state_manager/public_storage.ts +1 -1
  333. package/src/public/state_manager/state_manager.ts +87 -39
  334. package/src/public/test_executor_metrics.ts +7 -5
  335. package/dest/public/bytecode_errors.d.ts +0 -4
  336. package/dest/public/bytecode_errors.d.ts.map +0 -1
  337. package/dest/public/bytecode_errors.js +0 -6
  338. package/dest/public/tx_contract_cache.d.ts +0 -41
  339. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  340. package/dest/public/tx_contract_cache.js +0 -49
  341. package/src/public/bytecode_errors.ts +0 -6
  342. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,12 +1,13 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
+ import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
4
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
6
  import type { GlobalVariables } from '@aztec/stdlib/tx';
6
7
 
7
8
  import { strict as assert } from 'assert';
8
9
 
9
- import { SideEffectLimitReachedError } from '../side_effect_errors.js';
10
+ import { CheckedPublicExecutionError } from '../public_errors.js';
10
11
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
11
12
  import { AvmContext } from './avm_context.js';
12
13
  import { AvmContractCallResult } from './avm_contract_call_result.js';
@@ -14,7 +15,7 @@ import { AvmExecutionEnvironment } from './avm_execution_environment.js';
14
15
  import type { Gas } from './avm_gas.js';
15
16
  import { AvmMachineState } from './avm_machine_state.js';
16
17
  import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
17
- import { AvmExecutionError, AvmRevertReason, InvalidProgramCounterError } from './errors.js';
18
+ import { AvmRevertReason, InvalidProgramCounterError } from './errors.js';
18
19
  import type { Instruction } from './opcodes/instruction.js';
19
20
  import { revertReasonFromExceptionalHalt, revertReasonFromExplicitRevert } from './revert_reason.js';
20
21
  import {
@@ -75,7 +76,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
75
76
  isStaticCall: boolean,
76
77
  calldata: Fr[],
77
78
  allocatedGas: Gas,
78
- clientInitiatedSimulation: boolean = false,
79
+ config: PublicSimulatorConfig,
79
80
  ) {
80
81
  const avmExecutionEnv = new AvmExecutionEnvironment(
81
82
  address,
@@ -85,7 +86,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
85
86
  globals,
86
87
  isStaticCall,
87
88
  calldata,
88
- clientInitiatedSimulation,
89
+ config,
89
90
  );
90
91
 
91
92
  const avmMachineState = new AvmMachineState(allocatedGas);
@@ -97,22 +98,13 @@ export class AvmSimulator implements AvmSimulatorInterface {
97
98
  * Fetch the bytecode and execute it in the current context.
98
99
  */
99
100
  public async execute(): Promise<AvmContractCallResult> {
100
- let bytecode: Buffer | undefined;
101
- try {
102
- bytecode = await this.context.persistableState.getBytecode(this.context.environment.address);
103
- } catch (err: any) {
104
- if (!(err instanceof AvmExecutionError || err instanceof SideEffectLimitReachedError)) {
105
- this.log.error(`Unknown error thrown by AVM during bytecode retrieval: ${err}`);
106
- throw err;
107
- }
108
- return await this.handleFailureToRetrieveBytecode(
109
- `Bytecode retrieval for contract '${this.context.environment.address}' failed with ${err.message}. Reverting...`,
110
- );
111
- }
101
+ const bytecode = await this.context.persistableState.getBytecode(this.context.environment.address);
102
+ // getBytecode returns undefined if bytecode is not found or if the limit of contract calls to unique class IDs is reached.
103
+ // If it throws an error that reaches this point, it is a bug.
112
104
 
113
105
  if (!bytecode) {
114
106
  return await this.handleFailureToRetrieveBytecode(
115
- `No bytecode found at: ${this.context.environment.address}. Reverting...`,
107
+ `No bytecode found. Contract is not deployed, or limit encountered for max calls to unique contract class IDs. Contract address: ${this.context.environment.address}. Reverting...`,
116
108
  );
117
109
  }
118
110
 
@@ -135,6 +127,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
135
127
  assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");
136
128
 
137
129
  this.bytecode = bytecode;
130
+ let instructionName = 'NONE'; // This is used for logging purposes
138
131
 
139
132
  const { machineState } = this.context;
140
133
  const callStartGas = machineState.gasLeft; // Save gas before executing instruction (for profiling)
@@ -163,6 +156,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
163
156
  }
164
157
  machineState.nextPc = machineState.pc + bytesRead;
165
158
 
159
+ instructionName = instruction.constructor.name;
166
160
  // Execute the instruction.
167
161
  // Normal returns and reverts will return normally here.
168
162
  // "Exceptional halts" will throw.
@@ -183,7 +177,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
183
177
 
184
178
  if (machineState.pc >= bytecode.length) {
185
179
  this.log.warn('Passed end of program');
186
- throw new InvalidProgramCounterError(machineState.pc, /*max=*/ bytecode.length);
180
+ throw new InvalidProgramCounterError(machineState.pc, /*max=*/ bytecode.length - 1);
187
181
  }
188
182
  }
189
183
 
@@ -211,18 +205,12 @@ export class AvmSimulator implements AvmSimulatorInterface {
211
205
  // Return results for processing by calling context
212
206
  return results;
213
207
  } catch (err: any) {
214
- this.log.verbose('Exceptional halt (revert by something other than REVERT opcode)');
215
- // FIXME: weird that we have to do this OutOfGasError check because:
216
- // 1. OutOfGasError is an AvmExecutionError, so that check should cover both
217
- // 2. We should at least be able to do instanceof OutOfGasError instead of checking the constructor name
218
- if (
219
- !(
220
- err.constructor.name == 'OutOfGasError' ||
221
- err instanceof AvmExecutionError ||
222
- err instanceof SideEffectLimitReachedError
223
- )
224
- ) {
225
- this.log.error(`Unknown error thrown by AVM: ${err}`);
208
+ this.log.info(
209
+ `Exceptional halt (revert by something other than REVERT opcode) for instruction
210
+ ${instructionName} at pc ${machineState.pc} and instruction counter ${machineState.instrCounter}`,
211
+ );
212
+ if (!(err instanceof CheckedPublicExecutionError)) {
213
+ this.log.error(`Unchecked/unknown error thrown by AVM. This is a bug. Error: ${err}`);
226
214
  throw err;
227
215
  }
228
216
 
@@ -247,12 +235,15 @@ export class AvmSimulator implements AvmSimulatorInterface {
247
235
 
248
236
  private async handleFailureToRetrieveBytecode(message: string): Promise<AvmContractCallResult> {
249
237
  // revert, consuming all gas
250
- const fnName = await this.context.persistableState.getPublicFunctionDebugName(this.context.environment);
238
+ const { functionSelector, functionName } = await this.context.persistableState.getPublicFunctionSelectorAndName(
239
+ this.context.environment,
240
+ );
251
241
  const revertReason = new AvmRevertReason(
252
242
  message,
253
243
  /*failingFunction=*/ {
254
244
  contractAddress: this.context.environment.address,
255
- functionName: fnName,
245
+ functionSelector,
246
+ functionName,
256
247
  },
257
248
  /*noirCallStack=*/ [],
258
249
  );
@@ -1,26 +1,19 @@
1
- import type { Point } from '@aztec/foundation/fields';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
1
+ import type { Point } from '@aztec/foundation/curves/grumpkin';
3
2
  import type { FailingFunction, NoirCallStack } from '@aztec/stdlib/errors';
4
3
 
5
4
  import { ExecutionError } from '../../common/errors.js';
5
+ import { CheckedPublicExecutionError } from '../public_errors.js';
6
6
 
7
7
  /**
8
8
  * Avm-specific errors should derive from this
9
9
  */
10
- export abstract class AvmExecutionError extends Error {
10
+ export abstract class AvmExecutionError extends CheckedPublicExecutionError {
11
11
  constructor(message: string) {
12
12
  super(message);
13
13
  this.name = 'AvmExecutionError';
14
14
  }
15
15
  }
16
16
 
17
- export class NoBytecodeForContractError extends AvmExecutionError {
18
- constructor(contractAddress: AztecAddress) {
19
- super(`No bytecode found at: ${contractAddress}`);
20
- this.name = 'NoBytecodeFoundInterpreterError';
21
- }
22
- }
23
-
24
17
  export class ArithmeticError extends AvmExecutionError {
25
18
  constructor(message: string) {
26
19
  super(message);
@@ -65,7 +58,7 @@ export class AvmParsingError extends AvmExecutionError {
65
58
  */
66
59
  export class InvalidTagValueError extends AvmExecutionError {
67
60
  constructor(tagValue: number) {
68
- super(`Tag value ${tagValue} is invalid.`);
61
+ super(`Tag check failed: Tag value ${tagValue} is invalid.`);
69
62
  this.name = 'InvalidTagValueError';
70
63
  }
71
64
  }
@@ -84,6 +77,12 @@ export class InstructionExecutionError extends AvmExecutionError {
84
77
  * Error thrown on failed AVM memory tag check.
85
78
  */
86
79
  export class TagCheckError extends AvmExecutionError {
80
+ public static forBaseAddress(gotTag: string): TagCheckError {
81
+ return new TagCheckError(`Base address (mem[0]) is not a valid address (has tag ${gotTag})`);
82
+ }
83
+ public static forIndirectAddress(address: number, gotTag: string): TagCheckError {
84
+ return new TagCheckError(`Address after indirection is not a valid address (address ${address} has tag ${gotTag})`);
85
+ }
87
86
  public static forOffset(offset: number, gotTag: string, expectedTag: string): TagCheckError {
88
87
  return new TagCheckError(`Tag mismatch at offset ${offset}, got ${gotTag}, expected ${expectedTag}`);
89
88
  }
@@ -104,7 +103,7 @@ export class TagCheckError extends AvmExecutionError {
104
103
  */
105
104
  export class RelativeAddressOutOfRangeError extends AvmExecutionError {
106
105
  constructor(baseAddr: number, relOffset: number) {
107
- super(`Address out of range. Base address ${baseAddr}, relative offset ${relOffset}`);
106
+ super(`Relative address out of range. Base address ${baseAddr}, relative offset ${relOffset}`);
108
107
  this.name = 'RelativeAddressOutOfRangeError';
109
108
  }
110
109
  }
@@ -129,22 +128,12 @@ export class OutOfGasError extends AvmExecutionError {
129
128
  }
130
129
 
131
130
  /**
132
- * Error is thrown when the supplied points length is not a multiple of 3. Specific for MSM opcode.
133
- */
134
- export class MSMPointsLengthError extends AvmExecutionError {
135
- constructor(pointsReadLength: number) {
136
- super(`Points vector length should be a multiple of 3, was ${pointsReadLength}`);
137
- this.name = 'MSMPointsLengthError';
138
- }
139
- }
140
-
141
- /**
142
- * Error is thrown when one of the supplied points does not lie on the Grumpkin curve. Specific for MSM opcode.
131
+ * Error is thrown when one of the supplied points does not lie on the Grumpkin curve. Specific for ECADD opcode.
143
132
  */
144
- export class MSMPointNotOnCurveError extends AvmExecutionError {
145
- constructor(point: Point) {
146
- super(`Point ${point.toString()} is not on the curve.`);
147
- this.name = 'MSMPointNotOnCurveError';
133
+ export class EcAddPointNotOnCurveError extends AvmExecutionError {
134
+ constructor(pointIndex: number, point: Point) {
135
+ super(`EcAdd point${pointIndex} (${point.toString()}) is not on the curve.`);
136
+ this.name = 'EcAddPointNotOnCurveError';
148
137
  }
149
138
  }
150
139
 
@@ -178,3 +167,11 @@ export class AvmRevertReason extends ExecutionError {
178
167
  super(message, failingFunction, noirCallStack, options);
179
168
  }
180
169
  }
170
+
171
+ /**
172
+ * Helper to annotate errors occurring during instruction fetching.
173
+ */
174
+ export function duringInstrFetch(error: Error, pc: number) {
175
+ error.message = `Instruction fetching error at pc ${pc}: ${error.message}`;
176
+ return error;
177
+ }
@@ -1,5 +1,6 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { encodeArguments } from '@aztec/stdlib/abi';
3
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
3
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
5
  import { GasFees } from '@aztec/stdlib/gas';
5
6
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
@@ -37,9 +38,11 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
37
38
  super(contractDataSource, merkleTrees);
38
39
  }
39
40
 
40
- static async create(): Promise<AvmSimulationTester> {
41
+ static async create(
42
+ worldStateService: NativeWorldStateService, // make sure to close this later
43
+ ): Promise<AvmSimulationTester> {
41
44
  const contractDataSource = new SimpleContractDataSource();
42
- const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
45
+ const merkleTrees = await worldStateService.fork();
43
46
  const treesDB = new PublicTreesDB(merkleTrees);
44
47
  const contractsDB = new PublicContractsDB(contractDataSource);
45
48
  const trace = new SideEffectTrace();
@@ -49,7 +52,6 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
49
52
  treesDB,
50
53
  contractsDB,
51
54
  trace,
52
- /*doMerkleOperations=*/ false,
53
55
  firstNullifier,
54
56
  DEFAULT_TIMESTAMP,
55
57
  );
@@ -79,12 +81,20 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
79
81
  globals.timestamp = DEFAULT_TIMESTAMP;
80
82
  globals.gasFees = DEFAULT_GAS_FEES;
81
83
 
84
+ const config = PublicSimulatorConfig.from({
85
+ skipFeeEnforcement: false,
86
+ collectDebugLogs: true,
87
+ collectHints: false,
88
+ collectStatistics: false,
89
+ collectCallMetadata: true,
90
+ });
82
91
  const environment = initExecutionEnvironment({
83
92
  calldata,
84
93
  globals,
85
94
  address,
86
95
  sender,
87
96
  isStaticCall,
97
+ config,
88
98
  });
89
99
  const persistableState = await this.stateManager.fork();
90
100
  const context = initContext({ env: environment, persistableState });
@@ -1,8 +1,10 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
+ import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry';
5
6
  import { computeFeePayerBalanceStorageSlot, getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
7
+ import { getCanonicalInstanceRegistry } from '@aztec/protocol-contracts/instance-registry';
6
8
  import type { ContractArtifact } from '@aztec/stdlib/abi';
7
9
  import { PublicDataWrite } from '@aztec/stdlib/avm';
8
10
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -88,6 +90,36 @@ export abstract class BaseAvmSimulationTester {
88
90
  return feeJuice.instance;
89
91
  }
90
92
 
93
+ async registerAuthContract(): Promise<ContractInstanceWithAddress> {
94
+ const authRegistry = await getCanonicalAuthRegistry();
95
+ const authRegistryContractClassPublic = {
96
+ ...authRegistry.contractClass,
97
+ privateFunctions: [],
98
+ utilityFunctions: [],
99
+ };
100
+ await this.contractDataSource.addNewContract(
101
+ authRegistry.artifact,
102
+ authRegistryContractClassPublic,
103
+ authRegistry.instance,
104
+ );
105
+ return authRegistry.instance;
106
+ }
107
+
108
+ async registerInstanceRegistryContract(): Promise<ContractInstanceWithAddress> {
109
+ const instanceRegistry = await getCanonicalInstanceRegistry();
110
+ const instanceRegistryContractClassPublic = {
111
+ ...instanceRegistry.contractClass,
112
+ privateFunctions: [],
113
+ utilityFunctions: [],
114
+ };
115
+ await this.contractDataSource.addNewContract(
116
+ instanceRegistry.artifact,
117
+ instanceRegistryContractClassPublic,
118
+ instanceRegistry.instance,
119
+ );
120
+ return instanceRegistry.instance;
121
+ }
122
+
91
123
  async addContractInstance(contractInstance: ContractInstanceWithAddress, skipNullifierInsertion = false) {
92
124
  if (!skipNullifierInsertion) {
93
125
  await this.insertContractAddressNullifier(contractInstance.address);
@@ -1,6 +1,8 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
4
  import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { Fr } from '@aztec/foundation/fields';
5
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
4
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
7
  import { GasFees } from '@aztec/stdlib/gas';
6
8
  import { GlobalVariables } from '@aztec/stdlib/tx';
@@ -43,7 +45,6 @@ export function initPersistableStateManager(overrides?: {
43
45
  trace?: PublicSideEffectTraceInterface;
44
46
  publicStorage?: PublicStorage;
45
47
  nullifiers?: NullifierManager;
46
- doMerkleOperations?: boolean;
47
48
  firstNullifier?: Fr;
48
49
  timestamp?: UInt64;
49
50
  }): PublicPersistableStateManager {
@@ -54,9 +55,7 @@ export function initPersistableStateManager(overrides?: {
54
55
  overrides?.trace || mock<PublicSideEffectTraceInterface>(),
55
56
  overrides?.firstNullifier || new Fr(27),
56
57
  overrides?.timestamp || DEFAULT_TIMESTAMP,
57
- overrides?.doMerkleOperations || false,
58
- overrides?.publicStorage,
59
- overrides?.nullifiers,
58
+ /*doMerkleOperations=*/ false,
60
59
  );
61
60
  }
62
61
 
@@ -72,7 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
72
71
  overrides?.globals ?? GlobalVariables.empty(),
73
72
  overrides?.isStaticCall ?? false,
74
73
  overrides?.calldata ?? [],
75
- overrides?.clientInitiatedSimulation ?? true, // default to true for testing even though internal default is false
74
+ overrides?.config ?? PublicSimulatorConfig.empty(),
76
75
  );
77
76
  }
78
77
 
@@ -83,8 +82,8 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
83
82
  return new GlobalVariables(
84
83
  overrides?.chainId ?? Fr.zero(),
85
84
  overrides?.version ?? Fr.zero(),
86
- overrides?.blockNumber ?? 0,
87
- overrides?.slotNumber ?? Fr.zero(),
85
+ overrides?.blockNumber ?? BlockNumber.ZERO,
86
+ overrides?.slotNumber ?? SlotNumber.ZERO,
88
87
  overrides?.timestamp ?? 0n,
89
88
  overrides?.coinbase ?? EthAddress.ZERO,
90
89
  overrides?.feeRecipient ?? AztecAddress.zero(),
@@ -1,5 +1,6 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import {
4
5
  type ContractArtifact,
5
6
  type FunctionAbi,
@@ -28,7 +29,7 @@ import type { AvmRevertReason } from '../errors.js';
28
29
 
29
30
  export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
30
31
  export const DEFAULT_TIMESTAMP: UInt64 = 99833n;
31
- export const DEFAULT_BLOCK_NUMBER = 42;
32
+ export const DEFAULT_BLOCK_NUMBER = BlockNumber(42);
32
33
 
33
34
  /**
34
35
  * Create a new object with all the same properties as the original, except for the ones in the overrides object.
@@ -1,4 +1,4 @@
1
- import { NullifierCollisionError } from '../../state_manager/nullifiers.js';
1
+ import { NullifierCollisionError } from '../../side_effect_errors.js';
2
2
  import type { AvmContext } from '../avm_context.js';
3
3
  import { TypeTag, Uint1 } from '../avm_memory_types.js';
4
4
  import { InstructionExecutionError, StaticCallAlterationError } from '../errors.js';
@@ -219,8 +219,8 @@ export class EmitUnencryptedLog extends Instruction {
219
219
 
220
220
  constructor(
221
221
  private indirect: number,
222
- private logOffset: number,
223
222
  private logSizeOffset: number,
223
+ private logOffset: number,
224
224
  ) {
225
225
  super();
226
226
  }
@@ -237,8 +237,8 @@ export class EmitUnencryptedLog extends Instruction {
237
237
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
238
238
  );
239
239
 
240
- const operands = [this.logOffset, this.logSizeOffset];
241
- const [logOffset, logSizeOffset] = addressing.resolve(operands, memory);
240
+ const operands = [this.logSizeOffset, this.logOffset];
241
+ const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
242
242
  memory.checkTag(TypeTag.UINT32, logSizeOffset);
243
243
  const logSize = memory.get(logSizeOffset).toNumber();
244
244
  memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
@@ -2,6 +2,8 @@ import { AVM_MAX_OPERANDS } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import type { Tuple } from '@aztec/foundation/serialize';
4
4
 
5
+ import { strict as assert } from 'assert';
6
+
5
7
  import { MemoryValue, TaggedMemory, type TaggedMemoryInterface, TypeTag } from '../avm_memory_types.js';
6
8
  import { RelativeAddressOutOfRangeError, TagCheckError } from '../errors.js';
7
9
 
@@ -20,9 +22,7 @@ export class Addressing {
20
22
  ) {}
21
23
 
22
24
  public static fromModes(modes: AddressingMode[]): Addressing {
23
- if (modes.length > AVM_MAX_OPERANDS) {
24
- throw new Error('Too many operands for addressing mode');
25
- }
25
+ assert(modes.length <= AVM_MAX_OPERANDS, 'Too many operands for addressing mode');
26
26
  return new Addressing(padArrayEnd(modes, AddressingMode.DIRECT, AVM_MAX_OPERANDS));
27
27
  }
28
28
 
@@ -83,7 +83,7 @@ export class Addressing {
83
83
  baseAddr = mem.get(0);
84
84
  const baseAddrTag = baseAddr.getTag();
85
85
  if (!TaggedMemory.isValidMemoryAddressTag(baseAddrTag!)) {
86
- throw TagCheckError.forOffset(0, TypeTag[baseAddrTag!], TypeTag[TypeTag.UINT32]);
86
+ throw TagCheckError.forBaseAddress(TypeTag[baseAddrTag!]);
87
87
  }
88
88
  }
89
89
  // Here we know that resolved[i] is at most 32 bits and baseAddr is at most 32 bits.
@@ -100,7 +100,7 @@ export class Addressing {
100
100
 
101
101
  // Final check.
102
102
  if (!TaggedMemory.isValidMemoryAddressTag(resolvedTag)) {
103
- throw TagCheckError.forOffset(resolved[i], TypeTag[resolvedTag], TypeTag[TypeTag.UINT32]);
103
+ throw TagCheckError.forIndirectAddress(resolved[i], TypeTag[resolvedTag]);
104
104
  }
105
105
 
106
106
  resolved[i] = Number(resolvedValue.toBigInt());
@@ -88,7 +88,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
88
88
  static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
89
89
 
90
90
  protected compute(a: Field, b: Field): Field {
91
- // return (a as Field).fdiv(b as Field);
91
+ if (b.toBigInt() === 0n) {
92
+ throw new ArithmeticError('Division by zero');
93
+ }
92
94
  return a.fdiv(b);
93
95
  }
94
96
 
@@ -105,6 +107,11 @@ export class Shl extends ThreeOperandArithmeticInstruction {
105
107
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
106
108
  return a.shl(b);
107
109
  }
110
+
111
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
112
+ memory.checkTagsAreSame(aOffset, bOffset);
113
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
114
+ }
108
115
  }
109
116
 
110
117
  export class Shr extends ThreeOperandArithmeticInstruction {
@@ -114,4 +121,9 @@ export class Shr extends ThreeOperandArithmeticInstruction {
114
121
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
115
122
  return a.shr(b);
116
123
  }
124
+
125
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
126
+ memory.checkTagsAreSame(aOffset, bOffset);
127
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
128
+ }
117
129
  }
@@ -80,6 +80,10 @@ export class ToRadixBE extends Instruction {
80
80
  value /= radixBN;
81
81
  }
82
82
 
83
+ if (value !== 0n) {
84
+ throw new InvalidToRadixInputsError(`Field failed to decompose in ${numLimbs} limbs.`);
85
+ }
86
+
83
87
  const outputType = outputBits != 0 ? Uint1 : Uint8;
84
88
  const res = limbArray.map(byte => new outputType(byte));
85
89
  memory.setSlice(dstOffset, res);
@@ -1,8 +1,9 @@
1
- import { Grumpkin } from '@aztec/foundation/crypto';
2
- import { Point } from '@aztec/foundation/fields';
1
+ import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
2
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
3
 
4
4
  import type { AvmContext } from '../avm_context.js';
5
5
  import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
6
+ import { EcAddPointNotOnCurveError } from '../errors.js';
6
7
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
7
8
  import { Addressing } from './addressing_mode.js';
8
9
  import { Instruction } from './instruction.js';
@@ -65,7 +66,7 @@ export class EcAdd extends Instruction {
65
66
  const p1IsInfinite = memory.get(p1IsInfiniteOffset).toNumber() === 1;
66
67
  const p1 = new Point(p1X.toFr(), p1Y.toFr(), p1IsInfinite);
67
68
  if (!p1.isOnGrumpkin()) {
68
- throw new Error(`Point1 is not on the curve`);
69
+ throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 1, p1);
69
70
  }
70
71
 
71
72
  const p2X = memory.get(p2XOffset);
@@ -74,17 +75,16 @@ export class EcAdd extends Instruction {
74
75
  const p2IsInfinite = memory.get(p2IsInfiniteOffset).toNumber() === 1;
75
76
  const p2 = new Point(p2X.toFr(), p2Y.toFr(), p2IsInfinite);
76
77
  if (!p2.isOnGrumpkin()) {
77
- throw new Error(`Point1 is not on the curve`);
78
+ throw new EcAddPointNotOnCurveError(/*pointIndex=*/ 2, p2);
78
79
  }
79
80
 
80
- const grumpkin = new Grumpkin();
81
81
  let dest;
82
82
  if (p1IsInfinite) {
83
83
  dest = p2;
84
84
  } else if (p2IsInfinite) {
85
85
  dest = p1;
86
86
  } else {
87
- dest = await grumpkin.add(p1, p2);
87
+ dest = await Grumpkin.add(p1, p2);
88
88
  }
89
89
 
90
90
  // Important to use setSlice() and not set() in the two following statements as
@@ -20,8 +20,8 @@ export enum EnvironmentVariable {
20
20
  DAGASLEFT,
21
21
  }
22
22
 
23
- function getValue(e: EnvironmentVariable, ctx: AvmContext) {
24
- switch (e) {
23
+ function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
24
+ switch (varEnum) {
25
25
  case EnvironmentVariable.ADDRESS:
26
26
  return new Field(ctx.environment.address.toField());
27
27
  case EnvironmentVariable.SENDER:
@@ -47,7 +47,7 @@ function getValue(e: EnvironmentVariable, ctx: AvmContext) {
47
47
  case EnvironmentVariable.DAGASLEFT:
48
48
  return new Uint32(ctx.machineState.daGasLeft);
49
49
  default:
50
- throw new Error(`Unknown environment variable ${e}`);
50
+ throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${varEnum}`);
51
51
  }
52
52
  }
53
53
 
@@ -77,13 +77,11 @@ export class GetEnvVar extends Instruction {
77
77
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
78
78
  );
79
79
 
80
- if (!(this.varEnum in EnvironmentVariable)) {
81
- throw new InstructionExecutionError(`Invalid GETENVVAR var enum ${this.varEnum}`);
82
- }
83
-
84
80
  const operands = [this.dstOffset];
85
81
  const [dstOffset] = addressing.resolve(operands, memory);
86
82
 
87
- memory.set(dstOffset, getValue(this.varEnum as EnvironmentVariable, context));
83
+ const value = getValue(this.varEnum as EnvironmentVariable, context);
84
+
85
+ memory.set(dstOffset, value);
88
86
  }
89
87
  }
@@ -46,7 +46,6 @@ abstract class ExternalCall extends Instruction {
46
46
 
47
47
  const calldataSize = memory.get(argsSizeOffset).toNumber();
48
48
  const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
- memory.checkTagsRange(TypeTag.FIELD, argsOffset, calldataSize);
50
49
 
51
50
  const callAddress = memory.getAs<Field>(addrOffset);
52
51
  // If we are already in a static call, we propagate the environment.
@@ -1,4 +1,6 @@
1
- import { keccakf1600, poseidon2Permutation, sha256Compression } from '@aztec/foundation/crypto';
1
+ import { keccakf1600 } from '@aztec/foundation/crypto/keccak';
2
+ import { poseidon2Permutation } from '@aztec/foundation/crypto/poseidon';
3
+ import { sha256Compression } from '@aztec/foundation/crypto/sha256';
2
4
 
3
5
  import type { AvmContext } from '../avm_context.js';
4
6
  import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
@@ -36,6 +36,8 @@ export abstract class Instruction {
36
36
  * @returns Thee string representation.
37
37
  */
38
38
  public toString(): string {
39
+ // Note: we could have this be the actual wire opcode if `bytecode_serialization.ts` were to
40
+ // pass it into the class' static `Instruction.as(this, wireFormat)` method.
39
41
  let instructionStr = this.constructor.name + ': ';
40
42
  // assumes that all properties are flags or operands
41
43
  for (const prop of Object.getOwnPropertyNames(this) as (keyof Instruction)[]) {
@@ -114,9 +116,7 @@ export abstract class Instruction {
114
116
  */
115
117
  public get type(): string {
116
118
  const type = 'type' in this.constructor && (this.constructor.type as string);
117
- if (!type) {
118
- throw new Error(`Instruction class ${this.constructor.name} does not have a static 'type' property defined.`);
119
- }
119
+ assert(!!type, `Instruction class ${this.constructor.name} does not have a static 'type' property defined.`);
120
120
  return type;
121
121
  }
122
122
 
@@ -126,9 +126,11 @@ export abstract class Instruction {
126
126
  */
127
127
  public get opcode(): Opcode {
128
128
  const opcode = 'opcode' in this.constructor ? (this.constructor.opcode as Opcode) : undefined;
129
- if (opcode === undefined || Opcode[opcode] === undefined) {
130
- throw new Error(`Instruction class ${this.constructor.name} does not have a static 'opcode' property defined.`);
131
- }
129
+ assert(
130
+ opcode !== undefined,
131
+ `Instruction class ${this.constructor.name} does not have a static 'opcode' property defined.`,
132
+ );
133
+ assert(Opcode[opcode] !== undefined, `Invalid opcode ${opcode} for instruction class ${this.constructor.name}.`);
132
134
  return opcode;
133
135
  }
134
136
  }
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import { strict as assert } from 'assert';
4
4