@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,6 +1,96 @@
1
- export class SideEffectLimitReachedError extends Error {
1
+ import {
2
+ L1_TO_L2_MSG_TREE_LEAF_COUNT,
3
+ MAX_L2_TO_L1_MSGS_PER_TX,
4
+ MAX_NOTE_HASHES_PER_TX,
5
+ MAX_NULLIFIERS_PER_TX,
6
+ MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS,
7
+ NOTE_HASH_TREE_LEAF_COUNT,
8
+ } from '@aztec/constants';
9
+
10
+ import { CheckedPublicExecutionError } from './public_errors.js';
11
+
12
+ /**
13
+ * Any error that can be thrown during side effect insertion in public.
14
+ * Includes SideEffectLimitReachedError and NullifierCollisionError.
15
+ */
16
+ export abstract class SideEffectError extends CheckedPublicExecutionError {
17
+ constructor(message: string) {
18
+ super(message);
19
+ this.name = 'SideEffectInsertionError';
20
+ }
21
+ }
22
+
23
+ export class SideEffectLimitReachedError extends SideEffectError {
2
24
  constructor(sideEffectType: string, limit: number) {
3
25
  super(`Reached the limit (${limit}) on number of '${sideEffectType}' per tx`);
4
26
  this.name = 'SideEffectLimitReachedError';
5
27
  }
6
28
  }
29
+
30
+ export class MaxCallsToUniqueContractClassIdsError extends SideEffectLimitReachedError {
31
+ constructor() {
32
+ super('contract calls to unique class IDs', MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS);
33
+ this.name = 'MaxCallsToUniqueContractClassIdsError';
34
+ }
35
+ }
36
+
37
+ export class NullifierLimitReachedError extends SideEffectLimitReachedError {
38
+ constructor() {
39
+ super('nullifier', MAX_NULLIFIERS_PER_TX);
40
+ this.name = 'NullifierLimitReachedError';
41
+ }
42
+ }
43
+
44
+ export class NoteHashLimitReachedError extends SideEffectLimitReachedError {
45
+ constructor() {
46
+ super('note hash', MAX_NOTE_HASHES_PER_TX);
47
+ this.name = 'NoteHashLimitReachedError';
48
+ }
49
+ }
50
+
51
+ export class L2ToL1MessageLimitReachedError extends SideEffectLimitReachedError {
52
+ constructor() {
53
+ super('l2 to l1 message', MAX_L2_TO_L1_MSGS_PER_TX);
54
+ this.name = 'L2ToL1MessageLimitReachedError';
55
+ }
56
+ }
57
+
58
+ export class NullifierCollisionError extends SideEffectError {
59
+ constructor(message: string) {
60
+ super(`Nullifier collision: ${message}`);
61
+ this.name = 'NullifierCollisionError';
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Any error that can be thrown during side effect reads in public.
67
+ * Note: Thrown at state manager level and unknown by simulation, hence NOT considered
68
+ * CheckedPublicExecutionErrors. Currently only includes append-only tree reads.
69
+ */
70
+ export abstract class SideEffectReadError extends Error {
71
+ constructor(message: string) {
72
+ super(message);
73
+ this.name = 'SideEffectReadError';
74
+ }
75
+ }
76
+
77
+ export class IndexOutOfRangeError extends SideEffectReadError {
78
+ constructor(tree: string, index: number, limit: number) {
79
+ super(`Attempting to read index ${index} of ${tree} tree with maximum ${limit} leaves`);
80
+ this.name = 'IndexOutOfRangeError';
81
+ }
82
+ }
83
+
84
+ export class NoteHashIndexOutOfRangeError extends IndexOutOfRangeError {
85
+ constructor(index: number) {
86
+ super('note hash', index, NOTE_HASH_TREE_LEAF_COUNT);
87
+ this.name = 'NoteHashIndexOutOfRangeError';
88
+ }
89
+ }
90
+
91
+ export class L1ToL2MessageIndexOutOfRangeError extends IndexOutOfRangeError {
92
+ constructor(index: number) {
93
+ super('l1 to l2 message', index, L1_TO_L2_MSG_TREE_LEAF_COUNT);
94
+ this.name = 'L1ToL2MessageIndexOutOfRangeError';
95
+ }
96
+ }
@@ -1,27 +1,31 @@
1
1
  import {
2
+ FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH,
2
3
  MAX_L2_TO_L1_MSGS_PER_TX,
3
4
  MAX_NOTE_HASHES_PER_TX,
4
5
  MAX_NULLIFIERS_PER_TX,
5
6
  MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS,
6
7
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
7
- MAX_PUBLIC_LOGS_PER_TX,
8
8
  PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
9
- PUBLIC_LOG_SIZE_IN_FIELDS,
10
9
  } from '@aztec/constants';
11
- import { padArrayEnd } from '@aztec/foundation/collection';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
12
11
  import { EthAddress } from '@aztec/foundation/eth-address';
13
- import { Fr } from '@aztec/foundation/fields';
14
- import { createLogger } from '@aztec/foundation/log';
12
+ import { type LogLevel, createLogger } from '@aztec/foundation/log';
15
13
  import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
16
14
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
17
15
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
18
16
  import { NoteHash, Nullifier } from '@aztec/stdlib/kernel';
19
- import { PublicLog } from '@aztec/stdlib/logs';
17
+ import { DebugLog, PublicLog } from '@aztec/stdlib/logs';
20
18
  import { L2ToL1Message, ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
21
19
 
22
20
  import { strict as assert } from 'assert';
23
21
 
24
- import { SideEffectLimitReachedError } from './side_effect_errors.js';
22
+ import {
23
+ L2ToL1MessageLimitReachedError,
24
+ MaxCallsToUniqueContractClassIdsError,
25
+ NoteHashLimitReachedError,
26
+ NullifierLimitReachedError,
27
+ SideEffectLimitReachedError,
28
+ } from './side_effect_errors.js';
25
29
  import type { PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
26
30
  import { UniqueClassIds } from './unique_class_ids.js';
27
31
 
@@ -45,7 +49,7 @@ export class SideEffectArrayLengths {
45
49
  public readonly noteHashes: number,
46
50
  public readonly nullifiers: number,
47
51
  public readonly l2ToL1Msgs: number,
48
- public readonly publicLogs: number,
52
+ public readonly publicLogFields: number,
49
53
  ) {}
50
54
 
51
55
  static empty() {
@@ -69,7 +73,6 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
69
73
  private nullifiers: Nullifier[] = [];
70
74
  private l2ToL1Messages: ScopedL2ToL1Message[] = [];
71
75
  private publicLogs: PublicLog[] = [];
72
-
73
76
  /** Make sure a forked trace is never merged twice. */
74
77
  private alreadyMergedIntoParent = false;
75
78
 
@@ -83,6 +86,8 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
83
86
  /** We need to track the set of class IDs used, to enforce limits. */
84
87
  private uniqueClassIds: UniqueClassIds = new UniqueClassIds(),
85
88
  private writtenPublicDataSlots: Set<string> = new Set(),
89
+ private debugLogs: DebugLog[] = [],
90
+ private debugLogMemoryReads: number = 0,
86
91
  ) {
87
92
  this.sideEffectCounter = startSideEffectCounter;
88
93
  }
@@ -96,10 +101,13 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
96
101
  this.previousSideEffectArrayLengths.noteHashes + this.noteHashes.length,
97
102
  this.previousSideEffectArrayLengths.nullifiers + this.nullifiers.length,
98
103
  this.previousSideEffectArrayLengths.l2ToL1Msgs + this.l2ToL1Messages.length,
99
- this.previousSideEffectArrayLengths.publicLogs + this.publicLogs.length,
104
+ this.previousSideEffectArrayLengths.publicLogFields +
105
+ this.publicLogs.reduce((acc, log) => acc + log.sizeInFields(), 0),
100
106
  ),
101
107
  this.uniqueClassIds.fork(),
102
108
  new Set(this.writtenPublicDataSlots),
109
+ this.debugLogs.slice(),
110
+ this.debugLogMemoryReads,
103
111
  );
104
112
  }
105
113
 
@@ -113,6 +121,8 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
113
121
 
114
122
  this.sideEffectCounter = forkedTrace.sideEffectCounter;
115
123
  this.uniqueClassIds.acceptAndMerge(forkedTrace.uniqueClassIds);
124
+ this.debugLogs = forkedTrace.debugLogs;
125
+ this.debugLogMemoryReads = forkedTrace.debugLogMemoryReads;
116
126
 
117
127
  if (!reverted) {
118
128
  this.publicDataWrites.push(...forkedTrace.publicDataWrites);
@@ -193,7 +203,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
193
203
 
194
204
  public traceNewNoteHash(noteHash: Fr) {
195
205
  if (this.noteHashes.length + this.previousSideEffectArrayLengths.noteHashes >= MAX_NOTE_HASHES_PER_TX) {
196
- throw new SideEffectLimitReachedError('note hash', MAX_NOTE_HASHES_PER_TX);
206
+ throw new NoteHashLimitReachedError();
197
207
  }
198
208
 
199
209
  this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter));
@@ -203,10 +213,10 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
203
213
 
204
214
  public traceNewNullifier(siloedNullifier: Fr) {
205
215
  if (this.nullifiers.length + this.previousSideEffectArrayLengths.nullifiers >= MAX_NULLIFIERS_PER_TX) {
206
- throw new SideEffectLimitReachedError('nullifier', MAX_NULLIFIERS_PER_TX);
216
+ throw new NullifierLimitReachedError();
207
217
  }
208
218
 
209
- this.nullifiers.push(new Nullifier(siloedNullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
219
+ this.nullifiers.push(new Nullifier(siloedNullifier, /*noteHash=*/ Fr.ZERO, this.sideEffectCounter));
210
220
 
211
221
  this.log.trace(`Tracing new nullifier (counter=${this.sideEffectCounter})`);
212
222
  this.incrementSideEffectCounter();
@@ -214,7 +224,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
214
224
 
215
225
  public traceNewL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr) {
216
226
  if (this.l2ToL1Messages.length + this.previousSideEffectArrayLengths.l2ToL1Msgs >= MAX_L2_TO_L1_MSGS_PER_TX) {
217
- throw new SideEffectLimitReachedError('l2 to l1 message', MAX_L2_TO_L1_MSGS_PER_TX);
227
+ throw new L2ToL1MessageLimitReachedError();
218
228
  }
219
229
 
220
230
  const recipientAddress = EthAddress.fromField(recipient);
@@ -224,28 +234,43 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
224
234
  }
225
235
 
226
236
  public tracePublicLog(contractAddress: AztecAddress, log: Fr[]) {
227
- if (this.publicLogs.length + this.previousSideEffectArrayLengths.publicLogs >= MAX_PUBLIC_LOGS_PER_TX) {
228
- throw new SideEffectLimitReachedError('public log', MAX_PUBLIC_LOGS_PER_TX);
229
- }
237
+ const previouslyEmittedPublicLogFieldsCount =
238
+ this.previousSideEffectArrayLengths.publicLogFields +
239
+ this.publicLogs.reduce((acc, log) => acc + log.sizeInFields(), 0);
240
+
241
+ const publicLog = new PublicLog(contractAddress, log);
230
242
 
231
- if (log.length > PUBLIC_LOG_SIZE_IN_FIELDS) {
232
- throw new Error(`Emitted public log is too large, max: ${PUBLIC_LOG_SIZE_IN_FIELDS}, passed: ${log.length}`);
243
+ if (previouslyEmittedPublicLogFieldsCount + publicLog.sizeInFields() > FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH) {
244
+ throw new SideEffectLimitReachedError('public log fields', FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH);
233
245
  }
234
- const publicLog = new PublicLog(contractAddress, padArrayEnd(log, Fr.ZERO, PUBLIC_LOG_SIZE_IN_FIELDS), log.length);
246
+
235
247
  this.publicLogs.push(publicLog);
236
248
  this.log.trace(`Tracing new public log (counter=${this.sideEffectCounter})`);
237
249
  this.incrementSideEffectCounter();
238
250
  }
239
251
 
252
+ public traceDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]) {
253
+ this.debugLogs.push(new DebugLog(contractAddress, level, message, fields));
254
+ }
255
+
256
+ public getDebugLogs() {
257
+ return this.debugLogs;
258
+ }
259
+
260
+ public getDebugLogMemoryReads() {
261
+ return this.debugLogMemoryReads;
262
+ }
263
+
264
+ public traceDebugLogMemoryReads(memoryReads: number) {
265
+ this.debugLogMemoryReads += memoryReads;
266
+ }
267
+
240
268
  public traceGetContractClass(contractClassId: Fr, exists: boolean) {
241
269
  // We limit the number of unique contract class IDs due to hashing and the trace length limit.
242
270
  if (exists && !this.uniqueClassIds.has(contractClassId.toString())) {
243
271
  if (this.uniqueClassIds.size() >= MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS) {
244
272
  this.log.debug(`Bytecode retrieval failure for contract class ID ${contractClassId} (limit reached)`);
245
- throw new SideEffectLimitReachedError(
246
- 'contract calls to unique class IDs',
247
- MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS,
248
- );
273
+ throw new MaxCallsToUniqueContractClassIdsError();
249
274
  }
250
275
  this.log.trace(`Adding contract class ID ${contractClassId} (counter=${this.sideEffectCounter})`);
251
276
  this.uniqueClassIds.add(contractClassId.toString());
@@ -1,5 +1,7 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { LogLevel } from '@aztec/foundation/log';
2
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { DebugLog } from '@aztec/stdlib/logs';
3
5
 
4
6
  export interface PublicSideEffectTraceInterface {
5
7
  fork(): PublicSideEffectTraceInterface;
@@ -18,5 +20,9 @@ export interface PublicSideEffectTraceInterface {
18
20
  traceNewNullifier(siloedNullifier: Fr): void;
19
21
  traceNewL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr): void;
20
22
  tracePublicLog(contractAddress: AztecAddress, log: Fr[]): void;
23
+ traceDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]): void;
24
+ getDebugLogs(): DebugLog[];
25
+ getDebugLogMemoryReads(): number;
26
+ traceDebugLogMemoryReads(memoryReads: number): void;
21
27
  traceGetContractClass(contractClassId: Fr, exists: boolean): void;
22
28
  }
@@ -1,6 +1,7 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { PublicTreesDB } from '../public_db_sources.js';
4
+ import { NullifierCollisionError } from '../side_effect_errors.js';
4
5
 
5
6
  /**
6
7
  * A class to manage new nullifier staging and existence checks during a contract call's AVM simulation.
@@ -100,10 +101,3 @@ export class NullifierManager {
100
101
  this.cache = new Set([...this.cache, ...incomingNullifiers.cache]);
101
102
  }
102
103
  }
103
-
104
- export class NullifierCollisionError extends Error {
105
- constructor(message: string, ...rest: any[]) {
106
- super(message, ...rest);
107
- this.name = 'NullifierCollisionError';
108
- }
109
- }
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
4
  import type { PublicStateDBInterface } from '../db_interfaces.js';
@@ -6,16 +6,18 @@ import {
6
6
  MULTI_CALL_ENTRYPOINT_ADDRESS,
7
7
  ROUTER_ADDRESS,
8
8
  } from '@aztec/constants';
9
- import { poseidon2Hash } from '@aztec/foundation/crypto';
10
- import { Fr } from '@aztec/foundation/fields';
9
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
11
  import { jsonStringify } from '@aztec/foundation/json-rpc';
12
- import { createLogger } from '@aztec/foundation/log';
12
+ import { type LogLevel, createLogger } from '@aztec/foundation/log';
13
13
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
14
+ import { FunctionSelector } from '@aztec/stdlib/abi';
14
15
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
16
  import type { ContractClassPublicWithCommitment, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
16
17
  import { SerializableContractInstance } from '@aztec/stdlib/contract';
17
18
  import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
18
19
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
20
+ import type { DebugLog } from '@aztec/stdlib/logs';
19
21
  import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
20
22
  import { MerkleTreeId } from '@aztec/stdlib/trees';
21
23
  import type { TreeSnapshots } from '@aztec/stdlib/tx';
@@ -25,10 +27,16 @@ import { strict as assert } from 'assert';
25
27
 
26
28
  import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
27
29
  import type { PublicContractsDBInterface } from '../db_interfaces.js';
28
- import { getPublicFunctionDebugName } from '../debug_fn_name.js';
30
+ import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
29
31
  import type { PublicTreesDB } from '../public_db_sources.js';
32
+ import {
33
+ L1ToL2MessageIndexOutOfRangeError,
34
+ MaxCallsToUniqueContractClassIdsError,
35
+ NoteHashIndexOutOfRangeError,
36
+ NullifierCollisionError,
37
+ } from '../side_effect_errors.js';
30
38
  import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
31
- import { NullifierCollisionError, NullifierManager } from './nullifiers.js';
39
+ import { NullifierManager } from './nullifiers.js';
32
40
  import { PublicStorage } from './public_storage.js';
33
41
 
34
42
  /**
@@ -52,7 +60,7 @@ export class PublicPersistableStateManager {
52
60
  private readonly trace: PublicSideEffectTraceInterface,
53
61
  private readonly firstNullifier: Fr, // Needed for note hashes.
54
62
  private readonly timestamp: UInt64, // Needed for contract updates.
55
- private readonly doMerkleOperations: boolean = false,
63
+ private readonly doMerkleOperations: boolean = true,
56
64
  private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
57
65
  private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
58
66
  ) {}
@@ -64,18 +72,10 @@ export class PublicPersistableStateManager {
64
72
  treesDB: PublicTreesDB,
65
73
  contractsDB: PublicContractsDBInterface,
66
74
  trace: PublicSideEffectTraceInterface,
67
- doMerkleOperations: boolean = false,
68
75
  firstNullifier: Fr,
69
76
  timestamp: UInt64,
70
77
  ): PublicPersistableStateManager {
71
- return new PublicPersistableStateManager(
72
- treesDB,
73
- contractsDB,
74
- trace,
75
- firstNullifier,
76
- timestamp,
77
- doMerkleOperations,
78
- );
78
+ return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp);
79
79
  }
80
80
 
81
81
  /**
@@ -164,7 +164,6 @@ export class PublicPersistableStateManager {
164
164
  if (this.doMerkleOperations) {
165
165
  return await this.treesDB.storageRead(contractAddress, slot);
166
166
  } else {
167
- // TODO(fcarreiro): I don't get this. PublicStorage CAN end up reading the tree. Why is it in the "dont do merkle operations" branch?
168
167
  const read = await this.publicStorage.read(contractAddress, slot);
169
168
  this.log.trace(
170
169
  `Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`,
@@ -183,12 +182,21 @@ export class PublicPersistableStateManager {
183
182
  * @returns true if the note hash exists at the given leaf index, false otherwise
184
183
  */
185
184
  public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: bigint): Promise<boolean> {
186
- const gotLeafValue = await this.treesDB.getNoteHash(leafIndex);
187
- const exists = gotLeafValue !== undefined && gotLeafValue.equals(noteHash);
188
- this.log.trace(
189
- `noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`,
190
- );
191
- return Promise.resolve(exists);
185
+ try {
186
+ const gotLeafValue = await this.treesDB.getNoteHash(leafIndex);
187
+ const exists = gotLeafValue.equals(noteHash);
188
+ this.log.trace(
189
+ `noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`,
190
+ );
191
+ return Promise.resolve(exists);
192
+ } catch (error) {
193
+ // If the index is out of range, note_hash_leaf_in_range = 0 and the circuit returns false:
194
+ if (error instanceof NoteHashIndexOutOfRangeError) {
195
+ return Promise.resolve(false);
196
+ }
197
+ // Otherwise, unknown error. This is a bug.
198
+ throw error;
199
+ }
192
200
  }
193
201
 
194
202
  /**
@@ -288,12 +296,21 @@ export class PublicPersistableStateManager {
288
296
  * @returns exists - whether the message exists in the L1 to L2 Messages tree
289
297
  */
290
298
  public async checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean> {
291
- const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
292
- const exists = valueAtIndex !== undefined && valueAtIndex.equals(msgHash);
293
- this.log.trace(
294
- `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`,
295
- );
296
- return Promise.resolve(exists);
299
+ try {
300
+ const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
301
+ const exists = valueAtIndex.equals(msgHash);
302
+ this.log.trace(
303
+ `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`,
304
+ );
305
+ return Promise.resolve(exists);
306
+ } catch (error) {
307
+ // If the index is out of range, l1_to_l2_msg_leaf_in_range = 0 and the circuit returns false:
308
+ if (error instanceof L1ToL2MessageIndexOutOfRangeError) {
309
+ return Promise.resolve(false);
310
+ }
311
+ // Otherwise, unknown error. This is a bug.
312
+ throw error;
313
+ }
297
314
  }
298
315
 
299
316
  /**
@@ -319,6 +336,22 @@ export class PublicPersistableStateManager {
319
336
  );
320
337
  }
321
338
 
339
+ public writeDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]) {
340
+ this.trace.traceDebugLog(contractAddress, level, message, fields);
341
+ }
342
+
343
+ public writeDebugLogMemoryReads(memoryReads: number) {
344
+ this.trace.traceDebugLogMemoryReads(memoryReads);
345
+ }
346
+
347
+ public getDebugLogMemoryReads() {
348
+ return this.trace.getDebugLogMemoryReads();
349
+ }
350
+
351
+ public getLogs(): DebugLog[] {
352
+ return this.trace.getDebugLogs();
353
+ }
354
+
322
355
  /**
323
356
  * Write a public log
324
357
  * @param contractAddress - address of the contract that emitted the log
@@ -368,7 +401,7 @@ export class PublicPersistableStateManager {
368
401
 
369
402
  this.log.trace(`Got contract instance (address=${contractAddress}): instance=${jsonStringify(instance!)}`);
370
403
 
371
- // All that is left is tocheck that the contract updatability information is correct.
404
+ // All that is left is to check that the contract updatability information is correct.
372
405
  // That is, that the current and original contract class ids are correct.
373
406
  await this.checkContractUpdateInformation(instanceWithAddress);
374
407
 
@@ -389,13 +422,15 @@ export class PublicPersistableStateManager {
389
422
  //
390
423
  // However, we will also be checking the hash of the delayed public mutable values.
391
424
  // This is a bit of a leak of information, since the circuit will use it to prove
392
- // one public read insted of N of the delayed public mutable values.
425
+ // one public read instead of N of the delayed public mutable values.
393
426
  const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } =
394
427
  await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(instance.address);
395
428
  const readDeployerStorage = async (storageSlot: Fr) =>
396
429
  await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
397
430
 
398
431
  const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
432
+ // NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
433
+ // See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
399
434
  const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
400
435
  delayedPublicMutableSlot,
401
436
  readDeployerStorage,
@@ -438,7 +473,7 @@ export class PublicPersistableStateManager {
438
473
  * @param classId - class id to retrieve.
439
474
  * @returns the contract class or undefined if it does not exist.
440
475
  */
441
- public async getContractClass(classId: Fr): Promise<ContractClassPublicWithCommitment | undefined> {
476
+ private async getContractClass(classId: Fr): Promise<ContractClassPublicWithCommitment | undefined> {
442
477
  this.log.trace(`Getting contract class for id ${classId}`);
443
478
  const contractClass = await this.contractsDB.getContractClass(classId);
444
479
  const exists = contractClass !== undefined;
@@ -459,7 +494,7 @@ export class PublicPersistableStateManager {
459
494
  publicBytecodeCommitment: bytecodeCommitment,
460
495
  };
461
496
  } else {
462
- this.log.debug(`Contract instance NOT FOUND (id=${classId})`);
497
+ this.log.debug(`Contract class NOT FOUND (id=${classId})`);
463
498
  }
464
499
 
465
500
  // TODO(dbanks12): does this need to be moved to before the DB accesses as was done with writeNullifier?
@@ -478,19 +513,32 @@ export class PublicPersistableStateManager {
478
513
  return undefined;
479
514
  }
480
515
 
481
- const contractClass = await this.getContractClass(contractInstance.currentContractClassId);
482
- assert(
483
- contractClass,
484
- `Contract class not found in DB, but a contract instance was found with this class ID (${contractInstance.currentContractClassId}). This should not happen!`,
485
- );
486
-
487
- return contractClass.packedBytecode;
516
+ try {
517
+ const contractClass = await this.getContractClass(contractInstance.currentContractClassId);
518
+ assert(
519
+ contractClass,
520
+ `Contract class not found in DB, but a contract instance was found with this class ID (${contractInstance.currentContractClassId}). This should not happen!`,
521
+ );
522
+ return contractClass.packedBytecode;
523
+ } catch (error) {
524
+ if (error instanceof MaxCallsToUniqueContractClassIdsError) {
525
+ return undefined;
526
+ }
527
+ // Otherwise, unknown error. This is a bug.
528
+ throw error;
529
+ }
488
530
  }
489
531
 
490
532
  public async getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string> {
491
533
  return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
492
534
  }
493
535
 
536
+ public async getPublicFunctionSelectorAndName(
537
+ avmEnvironment: AvmExecutionEnvironment,
538
+ ): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
539
+ return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
540
+ }
541
+
494
542
  public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
495
543
  await this.treesDB.padTree(treeId, leavesToInsert);
496
544
  }
@@ -2,6 +2,7 @@ import { sum } from '@aztec/foundation/collection';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { RevertCode } from '@aztec/stdlib/avm';
5
+ import type { GasUsed } from '@aztec/stdlib/gas';
5
6
 
6
7
  import { strict as assert } from 'assert';
7
8
 
@@ -18,7 +19,7 @@ export interface PublicEnqueuedCallMetrics {
18
19
  export interface PublicTxMetrics {
19
20
  // TS simulation
20
21
  totalDurationMs: number;
21
- manaUsed: number;
22
+ manaUsed: number | undefined;
22
23
  totalInstructionsExecuted: number;
23
24
  nonRevertiblePrivateInsertionsUs: number | undefined;
24
25
  revertiblePrivateInsertionsUs: number | undefined;
@@ -99,7 +100,7 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
99
100
  this.txTimer = new Timer();
100
101
  }
101
102
 
102
- stopRecordingTxSimulation(txLabel: string, revertedCode?: RevertCode) {
103
+ stopRecordingTxSimulation(txLabel: string, gasUsed?: GasUsed, revertedCode?: RevertCode) {
103
104
  assert(this.currentTxLabel === txLabel, 'Cannot stop recording metrics for tx when another is live');
104
105
 
105
106
  const txMetrics = this.txMetrics.get(txLabel)!;
@@ -109,7 +110,7 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
109
110
  this.logger.debug(`Public TX simulation of ${txLabel} took ${txMetrics.totalDurationMs}ms`);
110
111
 
111
112
  // add manaUsed across all enqueued calls
112
- txMetrics.manaUsed = sum(txMetrics.enqueuedCalls.map(call => call.manaUsed));
113
+ txMetrics.manaUsed = gasUsed?.publicGas.l2Gas;
113
114
  // add totalInstructionsExecuted across all enqueued calls
114
115
  txMetrics.totalInstructionsExecuted = sum(txMetrics.enqueuedCalls.map(call => call.totalInstructionsExecuted));
115
116
  txMetrics.revertedCode = revertedCode;
@@ -202,8 +203,9 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
202
203
  pretty += `${INDENT0}Total duration: ${fmtNum(txMetrics.totalDurationMs, 'ms')}\n`;
203
204
  }
204
205
  if (filter === PublicTxMetricsFilter.TOTALS || filter === PublicTxMetricsFilter.ALL) {
205
- pretty += `${INDENT0}Total mana used: ${fmtNum(txMetrics.manaUsed)}\n`;
206
- const manaPerSecond = Math.round((txMetrics.manaUsed * 1000) / txMetrics.totalDurationMs);
206
+ const manaUsed = txMetrics.manaUsed || 0;
207
+ pretty += `${INDENT0}Total mana used: ${fmtNum(manaUsed)}\n`;
208
+ const manaPerSecond = Math.round((manaUsed * 1000) / txMetrics.totalDurationMs);
207
209
  pretty += `${INDENT0}Mana per second: ${fmtNum(manaPerSecond)}\n`;
208
210
  }
209
211
 
@@ -1,4 +0,0 @@
1
- export declare class ContractClassBytecodeError extends Error {
2
- constructor(contractAddress: string);
3
- }
4
- //# sourceMappingURL=bytecode_errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bytecode_errors.d.ts","sourceRoot":"","sources":["../../src/public/bytecode_errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,eAAe,EAAE,MAAM;CAIpC"}
@@ -1,6 +0,0 @@
1
- export class ContractClassBytecodeError extends Error {
2
- constructor(contractAddress){
3
- super(`Failed to get bytecode for contract at address ${contractAddress}`);
4
- this.name = 'ContractClassBytecodeError';
5
- }
6
- }
@@ -1,41 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
- /**
5
- * A cache for contract classes and instances for a single transaction.
6
- * Useful for tracking/retrieving contracts for a tx while leaving
7
- * the option to clear them if the tx is reverted.
8
- */
9
- export declare class TxContractCache {
10
- private instanceCache;
11
- private classCache;
12
- /**
13
- * Add a contract instance to the cache
14
- */
15
- addInstance(address: AztecAddress, instance: ContractInstanceWithAddress): void;
16
- /**
17
- * Add a contract class to the cache
18
- */
19
- addClass(classId: Fr, contractClass: ContractClassPublic): void;
20
- /**
21
- * Get a contract instance from the cache
22
- */
23
- getInstance(address: AztecAddress): ContractInstanceWithAddress | undefined;
24
- /**
25
- * Get a contract class from the cache
26
- */
27
- getClass(classId: Fr): ContractClassPublic | undefined;
28
- /**
29
- * Check if the cache has a contract class
30
- */
31
- hasClass(classId: Fr): boolean;
32
- /**
33
- * Clear all entries from the cache
34
- */
35
- clear(): void;
36
- /**
37
- * Merge another cache into this one
38
- */
39
- mergeFrom(other: TxContractCache): void;
40
- }
41
- //# sourceMappingURL=tx_contract_cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tx_contract_cache.d.ts","sourceRoot":"","sources":["../../src/public/tx_contract_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE/F;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAkD;IACvE,OAAO,CAAC,UAAU,CAA0C;IAE5D;;OAEG;IACI,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAItF;;OAEG;IACI,QAAQ,CAAC,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,mBAAmB,GAAG,IAAI;IAItE;;OAEG;IACI,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,2BAA2B,GAAG,SAAS;IAIlF;;OAEG;IACI,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,mBAAmB,GAAG,SAAS;IAI7D;;OAEG;IACI,QAAQ,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO;IAIrC;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;OAEG;IACI,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;CAS/C"}