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

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 +3 -3
  93. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  94. package/dest/public/avm/opcodes/environment_getters.js +7 -9
  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 -177
  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 +10 -12
  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 +39 -26
  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
@@ -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,15 +237,15 @@ 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
- memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
245
244
 
246
245
  const contractAddress = context.environment.address;
247
246
 
248
247
  context.machineState.consumeGas(this.dynamicGasCost(logSize));
248
+ memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
249
249
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
250
250
  context.persistableState.writePublicLog(contractAddress, log);
251
251
  }
@@ -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
@@ -13,15 +13,15 @@ export enum EnvironmentVariable {
13
13
  VERSION,
14
14
  BLOCKNUMBER,
15
15
  TIMESTAMP,
16
- BASEFEEPERL2GAS,
17
- BASEFEEPERDAGAS,
16
+ MINFEEPERL2GAS,
17
+ MINFEEPERDAGAS,
18
18
  ISSTATICCALL,
19
19
  L2GASLEFT,
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:
@@ -36,9 +36,9 @@ function getValue(e: EnvironmentVariable, ctx: AvmContext) {
36
36
  return new Uint32(ctx.environment.globals.blockNumber);
37
37
  case EnvironmentVariable.TIMESTAMP:
38
38
  return new Uint64(ctx.environment.globals.timestamp);
39
- case EnvironmentVariable.BASEFEEPERL2GAS:
39
+ case EnvironmentVariable.MINFEEPERL2GAS:
40
40
  return new Uint128(ctx.environment.globals.gasFees.feePerL2Gas);
41
- case EnvironmentVariable.BASEFEEPERDAGAS:
41
+ case EnvironmentVariable.MINFEEPERDAGAS:
42
42
  return new Uint128(ctx.environment.globals.gasFees.feePerDaGas);
43
43
  case EnvironmentVariable.ISSTATICCALL:
44
44
  return new Uint1(ctx.environment.isStaticCall ? 1 : 0);
@@ -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
  }
@@ -45,8 +45,8 @@ abstract class ExternalCall extends Instruction {
45
45
  memory.checkTag(TypeTag.UINT32, argsSizeOffset);
46
46
 
47
47
  const calldataSize = memory.get(argsSizeOffset).toNumber();
48
+ // This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
48
49
  const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
- memory.checkTagsRange(TypeTag.FIELD, argsOffset, calldataSize);
50
50
 
51
51
  const callAddress = memory.getAs<Field>(addrOffset);
52
52
  // 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';
@@ -130,13 +132,17 @@ export class Sha256Compression extends Instruction {
130
132
  const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
131
133
 
132
134
  // Note: size of output is same as size of state
133
- const inputs = Uint32Array.from(memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toNumber()));
134
- const state = Uint32Array.from(memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toNumber()));
135
+ const inputs = memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toBigInt());
136
+ const state = memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toBigInt());
135
137
 
136
138
  memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
137
139
  memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
138
140
 
139
- const output = sha256Compression(state, inputs);
141
+ // At this point both state and inputs are Uint32Array-compatible
142
+ const inputsArray = new Uint32Array(inputs.map(i => Number(i)));
143
+ const stateArray = new Uint32Array(state.map(i => Number(i)));
144
+
145
+ const output = sha256Compression(stateArray, inputsArray);
140
146
 
141
147
  // Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
142
148
  const res = [...output].map(word => new Uint32(word));
@@ -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
 
@@ -1,4 +1,4 @@
1
- import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
1
+ import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import type { AvmContext } from '../avm_context.js';
4
4
  import { TypeTag } from '../avm_memory_types.js';
@@ -15,6 +15,7 @@ export class DebugLog extends Instruction {
15
15
  static readonly wireFormat: OperandType[] = [
16
16
  OperandType.UINT8, // Opcode
17
17
  OperandType.UINT8, // Indirect
18
+ OperandType.UINT16, // level memory address
18
19
  OperandType.UINT16, // message memory address
19
20
  OperandType.UINT16, // fields memory address
20
21
  OperandType.UINT16, // fields size address
@@ -23,6 +24,7 @@ export class DebugLog extends Instruction {
23
24
 
24
25
  constructor(
25
26
  private indirect: number,
27
+ private levelOffset: number,
26
28
  private messageOffset: number,
27
29
  private fieldsOffset: number,
28
30
  private fieldsSizeOffset: number,
@@ -39,16 +41,30 @@ export class DebugLog extends Instruction {
39
41
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
40
42
  );
41
43
 
42
- const operands = [this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
43
- const [messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
44
+ const operands = [this.levelOffset, this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
45
+ const [levelOffset, messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
44
46
 
45
- // DebugLog is a no-op except when doing client-initiated simulation with debug logging enabled.
47
+ // DebugLog is a no-op except unless the config is set to collect debug logs.
46
48
  // Note that we still do address resolution and basic tag-checking (above)
47
49
  // To avoid a special-case in the witness generator and circuit.
48
- if (context.environment.clientInitiatedSimulation && DebugLog.logger.isLevelEnabled('verbose')) {
50
+ if (context.environment.config.collectDebugLogs) {
51
+ memory.checkTag(TypeTag.UINT8, levelOffset);
52
+ const levelNumber = memory.get(levelOffset).toNumber();
49
53
  memory.checkTag(TypeTag.UINT32, fieldsSizeOffset);
50
54
  const fieldsSize = memory.get(fieldsSizeOffset).toNumber();
51
55
 
56
+ const memoryReads = 1 /* level */ + 1 /* fieldsSize */ + this.messageSize /* message */ + fieldsSize; /* fields */
57
+ if (
58
+ context.persistableState.getDebugLogMemoryReads() + memoryReads >
59
+ context.environment.config.collectionLimits.maxDebugLogMemoryReads
60
+ ) {
61
+ // Regular error on purpose: this is not a recoverable error.
62
+ throw new Error(
63
+ `Max debug log memory reads exceeded: ${context.persistableState.getDebugLogMemoryReads() + memoryReads} > ${context.environment.config.collectionLimits.maxDebugLogMemoryReads}`,
64
+ );
65
+ }
66
+ context.persistableState.writeDebugLogMemoryReads(memoryReads);
67
+
52
68
  const rawMessage = memory.getSlice(messageOffset, this.messageSize);
53
69
  const fields = memory.getSlice(fieldsOffset, fieldsSize);
54
70
 
@@ -57,12 +73,30 @@ export class DebugLog extends Instruction {
57
73
 
58
74
  // Interpret str<N> = [u8; N] to string.
59
75
  const messageAsStr = rawMessage.map(field => String.fromCharCode(field.toNumber())).join('');
60
- const formattedStr = applyStringFormatting(
76
+
77
+ if (!LogLevels[levelNumber]) {
78
+ // Regular error on purpose: this is not a recoverable error.
79
+ throw new Error(`Invalid debug log level: ${levelNumber}`);
80
+ }
81
+
82
+ const level = LogLevels[levelNumber];
83
+
84
+ context.persistableState.writeDebugLog(
85
+ context.environment.address,
86
+ level,
61
87
  messageAsStr,
62
88
  fields.map(field => field.toFr()),
63
89
  );
64
90
 
65
- DebugLog.logger.verbose(formattedStr);
91
+ // Skips string formatting if the level is disabled.
92
+ if (DebugLog.logger.isLevelEnabled(level)) {
93
+ const formattedStr = applyStringFormatting(
94
+ messageAsStr,
95
+ fields.map(field => field.toFr()),
96
+ );
97
+
98
+ DebugLog.logger[level](formattedStr);
99
+ }
66
100
  }
67
101
  }
68
102
  }
@@ -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 { AvmContext } from './avm_context.js';
4
4
  import { type AvmExecutionError, AvmRevertReason } from './errors.js';
@@ -18,13 +18,16 @@ async function createRevertReason(message: string, revertData: Fr[], context: Av
18
18
  message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
19
19
  }
20
20
 
21
- const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
21
+ const { functionSelector, functionName } = await context.persistableState.getPublicFunctionSelectorAndName(
22
+ context.environment,
23
+ );
22
24
 
23
25
  return new AvmRevertReason(
24
26
  message,
25
27
  /*failingFunction=*/ {
26
28
  contractAddress: context.environment.address,
27
- functionName: fnName,
29
+ functionSelector,
30
+ functionName,
28
31
  },
29
32
  /*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
30
33
  /*options=*/ { cause: nestedError },
@@ -1,6 +1,13 @@
1
1
  import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
2
2
 
3
- import { AvmExecutionError, AvmParsingError, InvalidOpcodeError, InvalidProgramCounterError } from '../errors.js';
3
+ import {
4
+ AvmExecutionError,
5
+ AvmParsingError,
6
+ InvalidOpcodeError,
7
+ InvalidProgramCounterError,
8
+ InvalidTagValueError,
9
+ duringInstrFetch,
10
+ } from '../errors.js';
4
11
  import {
5
12
  Add,
6
13
  And,
@@ -172,7 +179,7 @@ export function decodeInstructionFromBytecode(
172
179
  instructionSet: InstructionSet = INSTRUCTION_SET,
173
180
  ): [Instruction, number] {
174
181
  if (pc >= bytecode.length) {
175
- throw new InvalidProgramCounterError(pc, bytecode.length);
182
+ throw new InvalidProgramCounterError(pc, bytecode.length - 1);
176
183
  }
177
184
 
178
185
  try {
@@ -182,7 +189,7 @@ export function decodeInstructionFromBytecode(
182
189
 
183
190
  if (opcode > MAX_OPCODE_VALUE) {
184
191
  throw new InvalidOpcodeError(
185
- `Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes.`,
192
+ `Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes (at PC ${pc}).`,
186
193
  );
187
194
  }
188
195
 
@@ -192,13 +199,17 @@ export function decodeInstructionFromBytecode(
192
199
  }
193
200
 
194
201
  const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
202
+
195
203
  const instruction = instructionDeserializer(cursor);
196
204
  return [instruction, cursor.position() - startingPosition];
197
205
  } catch (error) {
198
- if (error instanceof InvalidOpcodeError || error instanceof AvmExecutionError) {
199
- throw error;
206
+ if (error instanceof InvalidTagValueError || error instanceof InvalidOpcodeError) {
207
+ throw duringInstrFetch(error, pc);
208
+ } else if (error instanceof AvmExecutionError) {
209
+ throw new AvmParsingError(`Instruction parsing error at pc ${pc}: ${error.message}`);
200
210
  } else {
201
- throw new AvmParsingError(`${error}`);
211
+ const msg = error instanceof Error ? `: ${error.message}` : '';
212
+ throw new AvmParsingError(`Instruction fetching error at pc ${pc}${msg}`);
202
213
  }
203
214
  }
204
215
  }
@@ -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
 
@@ -124,6 +124,18 @@ const OPERAND_SPEC = new Map<OperandType, [number, (offset: number) => OperandNa
124
124
  [OperandType.TAG, [1, Buffer.prototype.readUint8, Buffer.prototype.writeUint8]],
125
125
  ]);
126
126
 
127
+ /**
128
+ * Returns the size of an operand in bytes.
129
+ * Should not be called with unknown operand types.
130
+ * @param operandType
131
+ * @returns number size in bytes
132
+ * @throws AssertionError if the operand type is unknown
133
+ */
134
+ export function getOperandSize(operandType: OperandType): number {
135
+ assert(OPERAND_SPEC.has(operandType), `Unknown operand type: ${operandType}`);
136
+ return OPERAND_SPEC.get(operandType)![0];
137
+ }
138
+
127
139
  function readUintBE(buf: Buffer, offset: number, totalBytes: number): bigint {
128
140
  let value: bigint = 0n;
129
141
  for (let i = 0; i < totalBytes; ++i) {