@aztec/simulator 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107

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 (346) 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 +16 -15
  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 +8 -8
  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 +1 -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 +9 -4
  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 +28 -2
  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 +59 -161
  147. package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
  148. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
  149. package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
  150. package/dest/public/fixtures/custom_bytecode_tests.d.ts +12 -0
  151. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
  152. package/dest/public/fixtures/custom_bytecode_tests.js +174 -0
  153. package/dest/public/fixtures/index.d.ts +5 -2
  154. package/dest/public/fixtures/index.d.ts.map +1 -1
  155. package/dest/public/fixtures/index.js +4 -1
  156. package/dest/public/fixtures/minimal_public_tx.d.ts +4 -9
  157. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  158. package/dest/public/fixtures/minimal_public_tx.js +8 -32
  159. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  160. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  161. package/dest/public/fixtures/opcode_spammer.js +1681 -0
  162. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +25 -5
  163. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  164. package/dest/public/fixtures/public_tx_simulation_tester.js +63 -17
  165. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  166. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  167. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  168. package/dest/public/fixtures/token_test.d.ts +6 -2
  169. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  170. package/dest/public/fixtures/token_test.js +13 -12
  171. package/dest/public/fixtures/utils.d.ts +2 -2
  172. package/dest/public/fixtures/utils.d.ts.map +1 -1
  173. package/dest/public/fixtures/utils.js +7 -6
  174. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
  175. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  176. package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -0
  177. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  178. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  179. package/dest/public/fuzzing/avm_simulator_bin.js +100 -0
  180. package/dest/public/hinting_db_sources.d.ts +16 -4
  181. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  182. package/dest/public/hinting_db_sources.js +74 -13
  183. package/dest/public/index.d.ts +3 -2
  184. package/dest/public/index.d.ts.map +1 -1
  185. package/dest/public/index.js +1 -1
  186. package/dest/public/public_db_sources.d.ts +24 -65
  187. package/dest/public/public_db_sources.d.ts.map +1 -1
  188. package/dest/public/public_db_sources.js +85 -132
  189. package/dest/public/public_errors.d.ts +12 -0
  190. package/dest/public/public_errors.d.ts.map +1 -0
  191. package/dest/public/public_errors.js +13 -0
  192. package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -2
  193. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  194. package/dest/public/public_processor/guarded_merkle_tree.js +8 -0
  195. package/dest/public/public_processor/public_processor.d.ts +11 -13
  196. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  197. package/dest/public/public_processor/public_processor.js +477 -70
  198. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  199. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  200. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
  201. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  202. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
  203. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +53 -0
  204. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
  205. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +131 -0
  206. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  207. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  208. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  209. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  210. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  211. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  212. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  213. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  214. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  215. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  216. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  217. package/dest/public/public_tx_simulator/factories.js +28 -0
  218. package/dest/public/public_tx_simulator/index.d.ts +6 -1
  219. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  220. package/dest/public/public_tx_simulator/index.js +3 -0
  221. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +16 -8
  222. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  223. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +7 -8
  224. package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -4
  225. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  226. package/dest/public/public_tx_simulator/public_tx_context.js +22 -10
  227. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +22 -29
  228. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  229. package/dest/public/public_tx_simulator/public_tx_simulator.js +178 -127
  230. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
  231. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
  232. package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
  233. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -3
  234. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  235. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +396 -20
  236. package/dest/public/side_effect_errors.d.ts +42 -2
  237. package/dest/public/side_effect_errors.d.ts.map +1 -1
  238. package/dest/public/side_effect_errors.js +70 -1
  239. package/dest/public/side_effect_trace.d.ts +13 -7
  240. package/dest/public/side_effect_trace.d.ts.map +1 -1
  241. package/dest/public/side_effect_trace.js +36 -21
  242. package/dest/public/side_effect_trace_interface.d.ts +9 -4
  243. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  244. package/dest/public/state_manager/index.d.ts +1 -1
  245. package/dest/public/state_manager/nullifiers.d.ts +2 -5
  246. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  247. package/dest/public/state_manager/nullifiers.js +1 -6
  248. package/dest/public/state_manager/public_storage.d.ts +2 -2
  249. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  250. package/dest/public/state_manager/public_storage.js +1 -1
  251. package/dest/public/state_manager/state_manager.d.ts +16 -13
  252. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  253. package/dest/public/state_manager/state_manager.js +64 -21
  254. package/dest/public/test_executor_metrics.d.ts +4 -3
  255. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  256. package/dest/public/test_executor_metrics.js +5 -4
  257. package/dest/public/unique_class_ids.d.ts +1 -1
  258. package/dest/public/unique_class_ids.d.ts.map +1 -1
  259. package/dest/public/utils.d.ts +1 -1
  260. package/dest/server.d.ts +1 -1
  261. package/dest/testing.d.ts +1 -1
  262. package/package.json +24 -19
  263. package/src/common/errors.ts +1 -1
  264. package/src/private/acvm/deserialize.ts +1 -1
  265. package/src/private/acvm/serialize.ts +1 -1
  266. package/src/private/acvm_native.ts +18 -11
  267. package/src/private/circuit_recording/circuit_recorder.ts +17 -16
  268. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +1 -1
  269. package/src/public/avm/avm_context.ts +1 -1
  270. package/src/public/avm/avm_contract_call_result.ts +1 -1
  271. package/src/public/avm/avm_execution_environment.ts +4 -3
  272. package/src/public/avm/avm_gas.ts +5 -5
  273. package/src/public/avm/avm_machine_state.ts +1 -1
  274. package/src/public/avm/avm_memory_types.ts +12 -3
  275. package/src/public/avm/avm_simulator.ts +24 -33
  276. package/src/public/avm/errors.ts +24 -27
  277. package/src/public/avm/fixtures/avm_simulation_tester.ts +14 -4
  278. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +33 -1
  279. package/src/public/avm/fixtures/initializers.ts +7 -8
  280. package/src/public/avm/fixtures/utils.ts +3 -2
  281. package/src/public/avm/opcodes/accrued_substate.ts +5 -5
  282. package/src/public/avm/opcodes/addressing_mode.ts +5 -5
  283. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  284. package/src/public/avm/opcodes/conversion.ts +4 -0
  285. package/src/public/avm/opcodes/ec_add.ts +6 -6
  286. package/src/public/avm/opcodes/environment_getters.ts +6 -8
  287. package/src/public/avm/opcodes/external_calls.ts +1 -1
  288. package/src/public/avm/opcodes/hashing.ts +10 -4
  289. package/src/public/avm/opcodes/instruction.ts +8 -6
  290. package/src/public/avm/opcodes/memory.ts +1 -1
  291. package/src/public/avm/opcodes/misc.ts +41 -7
  292. package/src/public/avm/revert_reason.ts +6 -3
  293. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  294. package/src/public/avm/serialization/instruction_serialization.ts +13 -1
  295. package/src/public/avm/test_utils.ts +7 -15
  296. package/src/public/contracts_db_checkpoint.ts +41 -0
  297. package/src/public/db_interfaces.ts +16 -1
  298. package/src/public/debug_fn_name.ts +35 -3
  299. package/src/public/executor_metrics.ts +2 -1
  300. package/src/public/executor_metrics_interface.ts +2 -1
  301. package/src/public/fixtures/amm_test.ts +2 -2
  302. package/src/public/fixtures/bulk_test.ts +38 -25
  303. package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
  304. package/src/public/fixtures/custom_bytecode_tests.ts +219 -0
  305. package/src/public/fixtures/index.ts +8 -1
  306. package/src/public/fixtures/minimal_public_tx.ts +9 -42
  307. package/src/public/fixtures/opcode_spammer.ts +1638 -0
  308. package/src/public/fixtures/public_tx_simulation_tester.ts +90 -22
  309. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  310. package/src/public/fixtures/token_test.ts +18 -10
  311. package/src/public/fixtures/utils.ts +5 -6
  312. package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
  313. package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
  314. package/src/public/hinting_db_sources.ts +117 -10
  315. package/src/public/index.ts +8 -1
  316. package/src/public/public_db_sources.ts +112 -175
  317. package/src/public/public_errors.ts +14 -0
  318. package/src/public/public_processor/guarded_merkle_tree.ts +10 -1
  319. package/src/public/public_processor/public_processor.ts +112 -79
  320. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +121 -0
  321. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +200 -0
  322. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  323. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
  324. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  325. package/src/public/public_tx_simulator/factories.ts +41 -0
  326. package/src/public/public_tx_simulator/index.ts +5 -0
  327. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +13 -14
  328. package/src/public/public_tx_simulator/public_tx_context.ts +20 -7
  329. package/src/public/public_tx_simulator/public_tx_simulator.ts +265 -179
  330. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
  331. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -13
  332. package/src/public/side_effect_errors.ts +91 -1
  333. package/src/public/side_effect_trace.ts +49 -24
  334. package/src/public/side_effect_trace_interface.ts +7 -1
  335. package/src/public/state_manager/nullifiers.ts +2 -8
  336. package/src/public/state_manager/public_storage.ts +1 -1
  337. package/src/public/state_manager/state_manager.ts +87 -39
  338. package/src/public/test_executor_metrics.ts +7 -5
  339. package/dest/public/bytecode_errors.d.ts +0 -4
  340. package/dest/public/bytecode_errors.d.ts.map +0 -1
  341. package/dest/public/bytecode_errors.js +0 -6
  342. package/dest/public/tx_contract_cache.d.ts +0 -41
  343. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  344. package/dest/public/tx_contract_cache.js +0 -49
  345. package/src/public/bytecode_errors.ts +0 -6
  346. package/src/public/tx_contract_cache.ts +0 -69
@@ -34,4 +34,4 @@ export declare class UniqueClassIds {
34
34
  */
35
35
  acceptAndMerge(incoming: UniqueClassIds): void;
36
36
  }
37
- //# sourceMappingURL=unique_class_ids.d.ts.map
37
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pcXVlX2NsYXNzX2lkcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3B1YmxpYy91bmlxdWVfY2xhc3NfaWRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBOzs7R0FHRztBQUNILHFCQUFhLGNBQWM7SUFHYixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQztJQUZwQyxPQUFPLENBQUMsUUFBUSxDQUFDLFFBQVEsQ0FBMEI7SUFFbkQsWUFBNkIsTUFBTSxDQUFDLDRCQUFnQixFQUFJO0lBRXhEOztPQUVHO0lBQ0ksSUFBSSxtQkFFVjtJQUVEOzs7OztPQUtHO0lBQ0ksR0FBRyxDQUFDLE9BQU8sRUFBRSxNQUFNLEdBQUcsT0FBTyxDQVNuQztJQUVEOztPQUVHO0lBQ0ksSUFBSSxJQUFJLE1BQU0sQ0FFcEI7SUFFRDs7OztPQUlHO0lBQ0ksR0FBRyxDQUFDLE9BQU8sRUFBRSxNQUFNLFFBU3pCO0lBRUQ7Ozs7T0FJRztJQUNJLGNBQWMsQ0FBQyxRQUFRLEVBQUUsY0FBYyxRQWE3QztDQUNGIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"unique_class_ids.d.ts","sourceRoot":"","sources":["../../src/public/unique_class_ids.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAFpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;gBAEtB,MAAM,CAAC,EAAE,cAAc,YAAA;IAEpD;;OAEG;IACI,IAAI;IAIX;;;;;OAKG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAWpC;;OAEG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM;IAW1B;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,cAAc;CAc/C"}
1
+ {"version":3,"file":"unique_class_ids.d.ts","sourceRoot":"","sources":["../../src/public/unique_class_ids.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAFpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;IAEnD,YAA6B,MAAM,CAAC,4BAAgB,EAAI;IAExD;;OAEG;IACI,IAAI,mBAEV;IAED;;;;;OAKG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CASnC;IAED;;OAEG;IACI,IAAI,IAAI,MAAM,CAEpB;IAED;;;;OAIG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,QASzB;IAED;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,cAAc,QAa7C;CACF"}
@@ -1,3 +1,3 @@
1
1
  import { PublicCallRequestWithCalldata, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
2
2
  export declare function getCallRequestsWithCalldataByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequestWithCalldata[];
3
- //# sourceMappingURL=utils.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wdWJsaWMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLDZCQUE2QixFQUFFLEtBQUssRUFBRSxFQUFFLGdCQUFnQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFNUYsd0JBQWdCLGtDQUFrQyxDQUFDLEVBQUUsRUFBRSxFQUFFLEVBQUUsS0FBSyxFQUFFLGdCQUFnQixHQUFHLDZCQUE2QixFQUFFLENBYW5IIn0=
package/dest/server.d.ts CHANGED
@@ -6,4 +6,4 @@ export { SimulatorRecorderWrapper } from './private/circuit_recording/simulator_
6
6
  export { MemoryCircuitRecorder } from './private/circuit_recording/memory_circuit_recorder.js';
7
7
  export { type CircuitSimulator, type DecodedError } from './private/circuit_simulator.js';
8
8
  export * from './common/index.js';
9
- //# sourceMappingURL=server.d.ts.map
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2VydmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxPQUFPLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSxtQ0FBbUMsQ0FBQztBQUMzRSxPQUFPLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUMvRCxPQUFPLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSwyREFBMkQsQ0FBQztBQUNyRyxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSx3REFBd0QsQ0FBQztBQUMvRixPQUFPLEVBQUUsS0FBSyxnQkFBZ0IsRUFBRSxLQUFLLFlBQVksRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQzFGLGNBQWMsbUJBQW1CLENBQUMifQ==
package/dest/testing.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { FileCircuitRecorder } from './private/circuit_recording/file_circuit_recorder.js';
2
- //# sourceMappingURL=testing.d.ts.map
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sc0RBQXNELENBQUMifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "4.0.0-nightly.20250907",
3
+ "version": "4.0.0-nightly.20260107",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -17,10 +17,11 @@
17
17
  "tsconfig": "./tsconfig.json"
18
18
  },
19
19
  "scripts": {
20
- "build": "yarn clean && tsc -b",
21
- "build:dev": "tsc -b --watch",
20
+ "build": "yarn clean && ../scripts/tsc.sh",
21
+ "build:dev": "../scripts/tsc.sh --watch",
22
22
  "clean": "rm -rf ./dest .tsbuildinfo",
23
- "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
23
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
24
+ "build:fuzzer": "yarn clean && ../scripts/tsc.sh"
24
25
  },
25
26
  "inherits": [
26
27
  "../package.common.json"
@@ -63,35 +64,39 @@
63
64
  ]
64
65
  },
65
66
  "dependencies": {
66
- "@aztec/constants": "4.0.0-nightly.20250907",
67
- "@aztec/foundation": "4.0.0-nightly.20250907",
68
- "@aztec/noir-acvm_js": "4.0.0-nightly.20250907",
69
- "@aztec/noir-noirc_abi": "4.0.0-nightly.20250907",
70
- "@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20250907",
71
- "@aztec/noir-types": "4.0.0-nightly.20250907",
72
- "@aztec/protocol-contracts": "4.0.0-nightly.20250907",
73
- "@aztec/stdlib": "4.0.0-nightly.20250907",
74
- "@aztec/telemetry-client": "4.0.0-nightly.20250907",
75
- "@aztec/world-state": "4.0.0-nightly.20250907",
67
+ "@aztec/constants": "4.0.0-nightly.20260107",
68
+ "@aztec/foundation": "4.0.0-nightly.20260107",
69
+ "@aztec/native": "4.0.0-nightly.20260107",
70
+ "@aztec/noir-acvm_js": "4.0.0-nightly.20260107",
71
+ "@aztec/noir-noirc_abi": "4.0.0-nightly.20260107",
72
+ "@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20260107",
73
+ "@aztec/noir-types": "4.0.0-nightly.20260107",
74
+ "@aztec/protocol-contracts": "4.0.0-nightly.20260107",
75
+ "@aztec/stdlib": "4.0.0-nightly.20260107",
76
+ "@aztec/telemetry-client": "4.0.0-nightly.20260107",
77
+ "@aztec/world-state": "4.0.0-nightly.20260107",
76
78
  "lodash.clonedeep": "^4.5.0",
77
79
  "lodash.merge": "^4.6.2",
78
80
  "tslib": "^2.4.0"
79
81
  },
80
82
  "devDependencies": {
81
- "@aztec/kv-store": "4.0.0-nightly.20250907",
82
- "@aztec/merkle-tree": "4.0.0-nightly.20250907",
83
- "@aztec/noir-contracts.js": "4.0.0-nightly.20250907",
84
- "@aztec/noir-test-contracts.js": "4.0.0-nightly.20250907",
83
+ "@aztec/kv-store": "4.0.0-nightly.20260107",
84
+ "@aztec/merkle-tree": "4.0.0-nightly.20260107",
85
+ "@aztec/noir-contracts.js": "4.0.0-nightly.20260107",
86
+ "@aztec/noir-test-contracts.js": "4.0.0-nightly.20260107",
85
87
  "@jest/globals": "^30.0.0",
86
88
  "@types/jest": "^30.0.0",
87
89
  "@types/lodash.clonedeep": "^4.5.7",
88
90
  "@types/lodash.merge": "^4.6.9",
89
91
  "@types/node": "^22.15.17",
92
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
93
+ "istanbul-lib-hook": "^3.0.0",
94
+ "istanbul-lib-instrument": "^6.0.3",
90
95
  "jest": "^30.0.0",
91
96
  "jest-mock-extended": "^4.0.0",
92
97
  "ts-node": "^10.9.1",
93
98
  "typescript": "^5.3.3",
94
- "viem": "2.23.7"
99
+ "viem": "npm:@aztec/viem@2.38.2"
95
100
  },
96
101
  "files": [
97
102
  "dest",
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { jsonStringify } from '@aztec/foundation/json-rpc';
3
3
  import type { RawAssertionPayload } from '@aztec/noir-acvm_js';
4
4
  import { abiDecodeError } from '@aztec/noir-noirc_abi';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { hexToBuffer } from '@aztec/foundation/string';
3
3
 
4
4
  import type { ACVMField, ACVMWitness } from './acvm_types.js';
@@ -1,5 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
 
5
5
  import type { ACVMField } from './acvm_types.js';
@@ -1,8 +1,7 @@
1
1
  import { runInDirectory } from '@aztec/foundation/fs';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
- import type { WitnessMap } from '@aztec/noir-acvm_js';
5
- import type { ForeignCallHandler } from '@aztec/noir-protocol-circuits-types/types';
4
+ import type { ForeignCallHandler, WitnessMap } from '@aztec/noir-acvm_js';
6
5
  import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
7
6
  import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
8
7
 
@@ -104,21 +103,26 @@ export async function executeNativeCircuit(
104
103
  logger.debug(`Calling ACVM with ${args.join(' ')}`);
105
104
 
106
105
  const processPromise = new Promise<string>((resolve, reject) => {
107
- let outputWitness = Buffer.alloc(0);
108
- let errorBuffer = Buffer.alloc(0);
106
+ const outChunks: Buffer[] = [];
107
+ const errChunks: Buffer[] = [];
108
+ let outLen = 0;
109
+ let errLen = 0;
109
110
  const acvm = proc.spawn(pathToAcvm, args);
110
- acvm.stdout.on('data', data => {
111
- outputWitness = Buffer.concat([outputWitness, data]);
111
+ acvm.stdout.on('data', (data: Buffer) => {
112
+ outChunks.push(data);
113
+ outLen += data.length;
112
114
  });
113
- acvm.stderr.on('data', data => {
114
- errorBuffer = Buffer.concat([errorBuffer, data]);
115
+ acvm.stderr.on('data', (data: Buffer) => {
116
+ errChunks.push(data);
117
+ errLen += data.length;
115
118
  });
116
119
  acvm.on('close', code => {
117
120
  if (code === 0) {
118
- resolve(outputWitness.toString('utf-8'));
121
+ resolve(Buffer.concat(outChunks, outLen).toString('utf-8'));
119
122
  } else {
120
- logger.error(`From ACVM: ${errorBuffer.toString('utf-8')}`);
121
- reject(errorBuffer.toString('utf-8'));
123
+ const stderr = Buffer.concat(errChunks, errLen);
124
+ logger.error(`From ACVM: ${stderr.toString('utf-8')}`);
125
+ reject(stderr.toString('utf-8'));
122
126
  }
123
127
  });
124
128
  });
@@ -130,6 +134,9 @@ export async function executeNativeCircuit(
130
134
  const outputWitnessFileName = `${workingDirectory}/output-witness.gz`;
131
135
  await fs.copyFile(outputWitnessFileName, outputFilename);
132
136
  }
137
+ // TODO: We shouldn't be parsing the witness from stdout, it's not very performant, and we end up with two ways of fetching the witness.
138
+ // We probably should implement the WitnessStack type, run the ACVM with msgpack serialization mode (env variable), and ungzip and parse the witness from
139
+ // the outputted gz witness file.
133
140
  const witness = parseIntoWitnessMap(output);
134
141
  return { status: ACVM_RESULT.SUCCESS, witness, duration };
135
142
  } catch (error) {
@@ -1,4 +1,4 @@
1
- import { sha512 } from '@aztec/foundation/crypto';
1
+ import { sha512 } from '@aztec/foundation/crypto/sha512';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@aztec/noir-acvm_js';
@@ -108,16 +108,16 @@ export class CircuitRecorder {
108
108
  * contracts as protocol circuits artifacts always contain a single entrypoint function called 'main'.
109
109
  */
110
110
  start(input: ACVMWitness, circuitBytecode: Buffer, circuitName: string, functionName: string): Promise<void> {
111
- const parentRef = this.recording;
112
111
  if (this.newCircuit) {
112
+ const parentRef = this.recording;
113
113
  this.recording = new CircuitRecording(
114
114
  circuitName,
115
115
  functionName,
116
116
  sha512(circuitBytecode).toString('hex'),
117
117
  Object.fromEntries(input),
118
118
  );
119
+ this.recording.setParent(parentRef);
119
120
  }
120
- this.recording!.setParent(parentRef);
121
121
 
122
122
  return Promise.resolve();
123
123
  }
@@ -173,22 +173,22 @@ export class CircuitRecorder {
173
173
  if (result instanceof Promise) {
174
174
  return result.then(async r => {
175
175
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
176
- // since we are going back to the "parent" circuit which can never be new
176
+ // so that the parent circuit continues with its existing recording
177
+ // Note: recording restoration is handled by finish()
177
178
  if (isExternalCall) {
178
179
  this.stackDepth--;
179
180
  this.newCircuit = false;
180
- this.recording = this.recording!.parent;
181
181
  }
182
182
  await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
183
183
  return r;
184
184
  }) as ReturnType<typeof fn>;
185
185
  }
186
186
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
187
- // since we are going back to the "parent" circuit which can never be new
187
+ // so that the parent circuit continues with its existing recording
188
+ // Note: recording restoration is handled by finish()
188
189
  if (isExternalCall) {
189
190
  this.stackDepth--;
190
191
  this.newCircuit = false;
191
- this.recording = this.recording!.parent;
192
192
  }
193
193
  void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
194
194
  return result;
@@ -239,6 +239,12 @@ export class CircuitRecorder {
239
239
  if (!result!.parent) {
240
240
  this.newCircuit = true;
241
241
  this.recording = undefined;
242
+ } else {
243
+ // For nested circuits (utility calls, nested contract calls), restore to parent recording
244
+ // Note: we don't set newCircuit=false here because:
245
+ // - For privateCallPrivateFunction, the callback wrapper will set it to false
246
+ // - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
247
+ this.recording = result!.parent;
242
248
  }
243
249
  return Promise.resolve(result!);
244
250
  }
@@ -247,14 +253,9 @@ export class CircuitRecorder {
247
253
  * Finalizes the recording by resetting the state and returning the recording object with an attached error.
248
254
  * @param error - The error that occurred during circuit execution
249
255
  */
250
- finishWithError(error: unknown): Promise<CircuitRecording> {
251
- const result = this.recording;
252
- // If this is the top-level circuit recording, we reset the state for the next simulator call
253
- if (!result!.parent) {
254
- this.newCircuit = true;
255
- this.recording = undefined;
256
- }
257
- result!.error = JSON.stringify(error);
258
- return Promise.resolve(result!);
256
+ async finishWithError(error: unknown): Promise<CircuitRecording> {
257
+ const result = await this.finish();
258
+ result.error = JSON.stringify(error);
259
+ return result;
259
260
  }
260
261
  }
@@ -1,4 +1,4 @@
1
- import type { ForeignCallHandler } from '@aztec/noir-protocol-circuits-types/types';
1
+ import type { ForeignCallHandler } from '@aztec/noir-acvm_js';
2
2
  import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
3
3
  import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
4
4
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
4
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { SimulationError } from '@aztec/stdlib/errors';
3
3
  import { Gas } from '@aztec/stdlib/gas';
4
4
 
@@ -1,4 +1,5 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
2
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
4
  import type { GlobalVariables } from '@aztec/stdlib/tx';
4
5
 
@@ -15,7 +16,7 @@ export class AvmExecutionEnvironment {
15
16
  public readonly globals: GlobalVariables,
16
17
  public readonly isStaticCall: boolean,
17
18
  public readonly calldata: Fr[],
18
- public readonly clientInitiatedSimulation: boolean = false,
19
+ public readonly config: PublicSimulatorConfig,
19
20
  ) {}
20
21
 
21
22
  private deriveEnvironmentForNestedCallInternal(
@@ -31,7 +32,7 @@ export class AvmExecutionEnvironment {
31
32
  this.globals,
32
33
  isStaticCall,
33
34
  calldata,
34
- /*clientInitiatedSimulation=*/ this.clientInitiatedSimulation,
35
+ this.config,
35
36
  );
36
37
  }
37
38
 
@@ -26,9 +26,9 @@ export function makeGas(gasCost: Partial<Gas>) {
26
26
  }
27
27
 
28
28
  /** Sums together multiple instances of Gas. */
29
- export function sumGas(...gases: Partial<Gas>[]) {
30
- return gases.reduce(
31
- (acc: Gas, gas) => ({
29
+ export function sumGas(...gases: Partial<Gas>[]): Gas {
30
+ return gases.reduce<Gas>(
31
+ (acc, gas) => ({
32
32
  l2Gas: acc.l2Gas + (gas.l2Gas ?? 0),
33
33
  daGas: acc.daGas + (gas.daGas ?? 0),
34
34
  }),
@@ -110,7 +110,7 @@ const BASE_GAS_COSTS: Record<Opcode, Gas> = {
110
110
  [Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_BASE_L2_GAS, 0),
111
111
  [Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_BASE_L2_GAS, c.AVM_EMITNULLIFIER_BASE_DA_GAS),
112
112
  [Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_BASE_L2_GAS, 0),
113
- [Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS, 0),
113
+ [Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS, c.AVM_EMITUNENCRYPTEDLOG_BASE_DA_GAS),
114
114
  [Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_BASE_L2_GAS, c.AVM_SENDL2TOL1MSG_BASE_DA_GAS),
115
115
  [Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, 0),
116
116
  [Opcode.CALL]: makeCost(c.AVM_CALL_BASE_L2_GAS, 0),
@@ -130,7 +130,7 @@ const DYNAMIC_GAS_COSTS = new Map<Opcode, Gas>([
130
130
  [Opcode.CALLDATACOPY, makeCost(c.AVM_CALLDATACOPY_DYN_L2_GAS, 0)],
131
131
  [Opcode.RETURNDATACOPY, makeCost(c.AVM_RETURNDATACOPY_DYN_L2_GAS, 0)],
132
132
  // TODO: Call and static call based on bytecode length
133
- [Opcode.EMITUNENCRYPTEDLOG, makeCost(0, c.AVM_EMITUNENCRYPTEDLOG_DYN_DA_GAS)],
133
+ [Opcode.EMITUNENCRYPTEDLOG, makeCost(c.AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS, c.AVM_EMITUNENCRYPTEDLOG_DYN_DA_GAS)],
134
134
  [Opcode.TORADIXBE, makeCost(c.AVM_TORADIXBE_DYN_L2_GAS, 0)],
135
135
  [Opcode.AND_8, makeCost(c.AVM_BITWISE_DYN_L2_GAS, 0)],
136
136
  [Opcode.AND_16, makeCost(c.AVM_BITWISE_DYN_L2_GAS, 0)],
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { Gas } from './avm_gas.js';
4
4
  import { TaggedMemory } from './avm_memory_types.js';
@@ -8,7 +8,7 @@ import {
8
8
  MEM_TAG_U128,
9
9
  } from '@aztec/constants';
10
10
  import { toBufferBE } from '@aztec/foundation/bigint-buffer';
11
- import { Fr } from '@aztec/foundation/fields';
11
+ import { Fr } from '@aztec/foundation/curves/bn254';
12
12
  import { type Logger, createLogger } from '@aztec/foundation/log';
13
13
  import type { FunctionsOf } from '@aztec/foundation/types';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -74,6 +74,7 @@ export abstract class IntegralValue extends MemoryValue {
74
74
  **/
75
75
  function UnsignedIntegerClassFactory(bits: number) {
76
76
  return class NewUintClass extends IntegralValue {
77
+ static readonly bits: number = bits;
77
78
  static readonly mod: bigint = 1n << BigInt(bits);
78
79
  static readonly bitmask: bigint = this.mod - 1n;
79
80
  public readonly n: bigint; // Cannot be private due to TS limitations.
@@ -108,12 +109,20 @@ function UnsignedIntegerClassFactory(bits: number) {
108
109
 
109
110
  // No sign extension.
110
111
  public shr(rhs: NewUintClass): NewUintClass {
111
- // Note that this.n is > 0 by class invariant.
112
+ // Note that this.n is >= 0 by class invariant.
112
113
  return this.build(this.n >> rhs.n);
113
114
  }
114
115
 
115
116
  public shl(rhs: NewUintClass): NewUintClass {
116
- return this.build((this.n << rhs.n) & NewUintClass.bitmask);
117
+ const shiftAmount = rhs.n;
118
+ const bitSize = BigInt(NewUintClass.bits);
119
+
120
+ // Shifting by more than the bit size always results in 0
121
+ if (shiftAmount >= bitSize) {
122
+ return this.build(0n);
123
+ }
124
+
125
+ return this.build((this.n << shiftAmount) & NewUintClass.bitmask);
117
126
  }
118
127
 
119
128
  public and(rhs: NewUintClass): NewUintClass {
@@ -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
+ }