@aztec/simulator 0.0.1-commit.9b94fc1 → 0.0.1-commit.9d2bcf6d

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 (323) hide show
  1. package/README.md +2 -0
  2. package/dest/common/errors.d.ts +8 -2
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.d.ts +4 -2
  5. package/dest/private/acvm/acvm.d.ts.map +1 -1
  6. package/dest/private/acvm/acvm.js +4 -3
  7. package/dest/private/acvm/deserialize.d.ts +2 -2
  8. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  9. package/dest/private/acvm/deserialize.js +1 -1
  10. package/dest/private/acvm/serialize.d.ts +2 -2
  11. package/dest/private/acvm/serialize.d.ts.map +1 -1
  12. package/dest/private/acvm/serialize.js +1 -1
  13. package/dest/private/acvm_native.d.ts +5 -3
  14. package/dest/private/acvm_native.d.ts.map +1 -1
  15. package/dest/private/acvm_native.js +8 -6
  16. package/dest/private/acvm_wasm.d.ts +4 -3
  17. package/dest/private/acvm_wasm.d.ts.map +1 -1
  18. package/dest/private/acvm_wasm.js +4 -4
  19. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  20. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  21. package/dest/private/circuit_recording/circuit_recorder.js +21 -18
  22. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  23. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  24. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  25. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  26. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  27. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  28. package/dest/private/factory.d.ts +3 -3
  29. package/dest/private/factory.d.ts.map +1 -1
  30. package/dest/private/factory.js +7 -4
  31. package/dest/public/avm/avm_context.d.ts +3 -3
  32. package/dest/public/avm/avm_context.d.ts.map +1 -1
  33. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  34. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  35. package/dest/public/avm/avm_contract_call_result.js +3 -3
  36. package/dest/public/avm/avm_execution_environment.d.ts +7 -6
  37. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  38. package/dest/public/avm/avm_execution_environment.js +1 -1
  39. package/dest/public/avm/avm_gas.d.ts +1 -1
  40. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  41. package/dest/public/avm/avm_machine_state.d.ts +7 -6
  42. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  43. package/dest/public/avm/avm_machine_state.js +3 -2
  44. package/dest/public/avm/avm_memory_types.d.ts +2 -2
  45. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  46. package/dest/public/avm/avm_memory_types.js +4 -1
  47. package/dest/public/avm/avm_simulator.d.ts +4 -3
  48. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  49. package/dest/public/avm/avm_simulator.js +11 -9
  50. package/dest/public/avm/calldata.d.ts +51 -0
  51. package/dest/public/avm/calldata.d.ts.map +1 -0
  52. package/dest/public/avm/calldata.js +63 -0
  53. package/dest/public/avm/errors.d.ts +8 -2
  54. package/dest/public/avm/errors.d.ts.map +1 -1
  55. package/dest/public/avm/errors.js +14 -2
  56. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  57. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  58. package/dest/public/avm/fixtures/avm_simulation_tester.js +4 -3
  59. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -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 +1 -1
  62. package/dest/public/avm/fixtures/initializers.d.ts +2 -2
  63. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  64. package/dest/public/avm/fixtures/initializers.js +5 -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/opcodes/accrued_substate.d.ts +16 -17
  69. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  70. package/dest/public/avm/opcodes/accrued_substate.js +39 -39
  71. package/dest/public/avm/opcodes/addressing_mode.js +2 -2
  72. package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
  73. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/arithmetic.js +12 -2
  75. package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
  76. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/bitwise.js +5 -5
  78. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  79. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/comparators.js +1 -1
  81. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  82. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/contract.js +8 -8
  84. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  85. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/control_flow.js +4 -4
  87. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  88. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  89. package/dest/public/avm/opcodes/conversion.js +4 -4
  90. package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
  91. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  92. package/dest/public/avm/opcodes/ec_add.js +17 -8
  93. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  94. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  95. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  96. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  97. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  98. package/dest/public/avm/opcodes/external_calls.js +23 -22
  99. package/dest/public/avm/opcodes/hashing.d.ts +8 -8
  100. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  101. package/dest/public/avm/opcodes/hashing.js +21 -16
  102. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  103. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  104. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  105. package/dest/public/avm/opcodes/memory.d.ts +14 -14
  106. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  107. package/dest/public/avm/opcodes/memory.js +26 -26
  108. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  109. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  110. package/dest/public/avm/opcodes/misc.js +6 -6
  111. package/dest/public/avm/opcodes/storage.d.ts +16 -15
  112. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  113. package/dest/public/avm/opcodes/storage.js +34 -24
  114. package/dest/public/avm/revert_reason.d.ts +2 -2
  115. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  116. package/dest/public/avm/revert_reason.js +3 -2
  117. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  118. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  119. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  120. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  121. package/dest/public/avm/test_utils.d.ts +2 -2
  122. package/dest/public/avm/test_utils.d.ts.map +1 -1
  123. package/dest/public/avm/test_utils.js +1 -1
  124. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  125. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  126. package/dest/public/db_interfaces.d.ts +2 -2
  127. package/dest/public/db_interfaces.d.ts.map +1 -1
  128. package/dest/public/debug_fn_name.d.ts +16 -3
  129. package/dest/public/debug_fn_name.d.ts.map +1 -1
  130. package/dest/public/debug_fn_name.js +31 -3
  131. package/dest/public/executor_metrics.d.ts +1 -1
  132. package/dest/public/executor_metrics.d.ts.map +1 -1
  133. package/dest/public/executor_metrics.js +12 -33
  134. package/dest/public/fixtures/amm_test.js +2 -2
  135. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  136. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  137. package/dest/public/fixtures/bulk_test.js +5 -69
  138. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  139. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  140. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  141. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
  142. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  143. package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
  144. package/dest/public/fixtures/index.d.ts +4 -2
  145. package/dest/public/fixtures/index.d.ts.map +1 -1
  146. package/dest/public/fixtures/index.js +3 -1
  147. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
  148. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  149. package/dest/public/fixtures/minimal_public_tx.js +4 -14
  150. package/dest/public/fixtures/opcode_spammer.d.ts +122 -0
  151. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  152. package/dest/public/fixtures/opcode_spammer.js +1653 -0
  153. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +22 -3
  154. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  155. package/dest/public/fixtures/public_tx_simulation_tester.js +50 -13
  156. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  157. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  158. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  159. package/dest/public/fixtures/token_test.d.ts +6 -2
  160. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  161. package/dest/public/fixtures/token_test.js +13 -11
  162. package/dest/public/fixtures/utils.d.ts +2 -2
  163. package/dest/public/fixtures/utils.d.ts.map +1 -1
  164. package/dest/public/fixtures/utils.js +4 -3
  165. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
  166. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  167. package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
  168. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  169. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  170. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  171. package/dest/public/hinting_db_sources.d.ts +5 -3
  172. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  173. package/dest/public/hinting_db_sources.js +7 -2
  174. package/dest/public/index.d.ts +2 -2
  175. package/dest/public/index.d.ts.map +1 -1
  176. package/dest/public/index.js +1 -1
  177. package/dest/public/public_db_sources.d.ts +5 -4
  178. package/dest/public/public_db_sources.d.ts.map +1 -1
  179. package/dest/public/public_db_sources.js +5 -5
  180. package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -2
  181. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  182. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  183. package/dest/public/public_processor/public_processor.d.ts +9 -7
  184. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  185. package/dest/public/public_processor/public_processor.js +444 -47
  186. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  187. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  188. package/dest/public/public_processor/public_processor_metrics.js +28 -45
  189. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -14
  190. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  191. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +20 -55
  192. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +24 -37
  193. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  194. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +67 -145
  195. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  196. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  197. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  198. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  199. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  200. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  201. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +23 -0
  202. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  203. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  204. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  205. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  206. package/dest/public/public_tx_simulator/factories.js +28 -0
  207. package/dest/public/public_tx_simulator/index.d.ts +4 -1
  208. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  209. package/dest/public/public_tx_simulator/index.js +3 -0
  210. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -3
  211. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  212. package/dest/public/public_tx_simulator/public_tx_context.d.ts +5 -4
  213. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  214. package/dest/public/public_tx_simulator/public_tx_context.js +9 -9
  215. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +8 -6
  216. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  217. package/dest/public/public_tx_simulator/public_tx_simulator.js +23 -12
  218. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  219. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  220. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  221. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  222. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  223. package/dest/public/side_effect_trace.d.ts +6 -5
  224. package/dest/public/side_effect_trace.d.ts.map +1 -1
  225. package/dest/public/side_effect_trace.js +4 -4
  226. package/dest/public/side_effect_trace_interface.d.ts +2 -2
  227. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  228. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  229. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  230. package/dest/public/state_manager/public_storage.d.ts +2 -2
  231. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  232. package/dest/public/state_manager/public_storage.js +1 -1
  233. package/dest/public/state_manager/state_manager.d.ts +16 -5
  234. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  235. package/dest/public/state_manager/state_manager.js +19 -9
  236. package/dest/public/test_executor_metrics.d.ts +3 -2
  237. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  238. package/dest/public/test_executor_metrics.js +2 -2
  239. package/package.json +20 -20
  240. package/src/common/errors.ts +1 -1
  241. package/src/private/acvm/acvm.ts +4 -3
  242. package/src/private/acvm/deserialize.ts +1 -1
  243. package/src/private/acvm/serialize.ts +1 -1
  244. package/src/private/acvm_native.ts +11 -5
  245. package/src/private/acvm_wasm.ts +7 -3
  246. package/src/private/circuit_recording/circuit_recorder.ts +22 -19
  247. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  248. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  249. package/src/private/factory.ts +7 -4
  250. package/src/public/avm/avm_context.ts +2 -2
  251. package/src/public/avm/avm_contract_call_result.ts +8 -6
  252. package/src/public/avm/avm_execution_environment.ts +10 -5
  253. package/src/public/avm/avm_gas.ts +3 -3
  254. package/src/public/avm/avm_machine_state.ts +7 -6
  255. package/src/public/avm/avm_memory_types.ts +5 -1
  256. package/src/public/avm/avm_simulator.ts +16 -10
  257. package/src/public/avm/calldata.ts +100 -0
  258. package/src/public/avm/errors.ts +17 -3
  259. package/src/public/avm/fixtures/avm_simulation_tester.ts +9 -3
  260. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  261. package/src/public/avm/fixtures/initializers.ts +5 -4
  262. package/src/public/avm/fixtures/utils.ts +3 -2
  263. package/src/public/avm/opcodes/accrued_substate.ts +28 -30
  264. package/src/public/avm/opcodes/addressing_mode.ts +2 -2
  265. package/src/public/avm/opcodes/arithmetic.ts +14 -2
  266. package/src/public/avm/opcodes/bitwise.ts +3 -3
  267. package/src/public/avm/opcodes/comparators.ts +1 -1
  268. package/src/public/avm/opcodes/contract.ts +4 -7
  269. package/src/public/avm/opcodes/control_flow.ts +2 -2
  270. package/src/public/avm/opcodes/conversion.ts +3 -3
  271. package/src/public/avm/opcodes/ec_add.ts +15 -6
  272. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  273. package/src/public/avm/opcodes/external_calls.ts +17 -15
  274. package/src/public/avm/opcodes/hashing.ts +16 -10
  275. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  276. package/src/public/avm/opcodes/memory.ts +20 -20
  277. package/src/public/avm/opcodes/misc.ts +4 -4
  278. package/src/public/avm/opcodes/storage.ts +30 -22
  279. package/src/public/avm/revert_reason.ts +6 -3
  280. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  281. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  282. package/src/public/avm/test_utils.ts +1 -1
  283. package/src/public/contracts_db_checkpoint.ts +1 -1
  284. package/src/public/db_interfaces.ts +1 -1
  285. package/src/public/debug_fn_name.ts +39 -5
  286. package/src/public/executor_metrics.ts +9 -33
  287. package/src/public/fixtures/amm_test.ts +2 -2
  288. package/src/public/fixtures/bulk_test.ts +9 -9
  289. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  290. package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
  291. package/src/public/fixtures/index.ts +7 -1
  292. package/src/public/fixtures/minimal_public_tx.ts +6 -15
  293. package/src/public/fixtures/opcode_spammer.ts +1721 -0
  294. package/src/public/fixtures/public_tx_simulation_tester.ts +69 -13
  295. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  296. package/src/public/fixtures/token_test.ts +18 -9
  297. package/src/public/fixtures/utils.ts +2 -3
  298. package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
  299. package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
  300. package/src/public/hinting_db_sources.ts +8 -3
  301. package/src/public/index.ts +7 -1
  302. package/src/public/public_db_sources.ts +16 -6
  303. package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
  304. package/src/public/public_processor/public_processor.ts +63 -33
  305. package/src/public/public_processor/public_processor_metrics.ts +16 -44
  306. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +25 -63
  307. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +83 -178
  308. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +134 -0
  309. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +239 -0
  310. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +83 -0
  311. package/src/public/public_tx_simulator/factories.ts +43 -0
  312. package/src/public/public_tx_simulator/index.ts +3 -0
  313. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
  314. package/src/public/public_tx_simulator/public_tx_context.ts +14 -7
  315. package/src/public/public_tx_simulator/public_tx_simulator.ts +42 -16
  316. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
  317. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
  318. package/src/public/side_effect_trace.ts +6 -3
  319. package/src/public/side_effect_trace_interface.ts +1 -1
  320. package/src/public/state_manager/nullifiers.ts +1 -1
  321. package/src/public/state_manager/public_storage.ts +1 -1
  322. package/src/public/state_manager/state_manager.ts +39 -23
  323. package/src/public/test_executor_metrics.ts +3 -3
@@ -0,0 +1,175 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import {
4
+ AvmCircuitPublicInputs,
5
+ type AvmTxHint,
6
+ PublicTxEffect,
7
+ deserializeFromMessagePack,
8
+ serializeWithMessagePack,
9
+ } from '@aztec/stdlib/avm';
10
+ import { GlobalVariables, ProtocolContracts, TreeSnapshots } from '@aztec/stdlib/tx';
11
+ import { NativeWorldStateService } from '@aztec/world-state';
12
+
13
+ import { createInterface } from 'readline';
14
+
15
+ import { AvmFuzzerSimulator, FuzzerSimulationRequest } from './avm_fuzzer_simulator.js';
16
+
17
+ /** Write data to stdout, letting Node handle buffering. */
18
+ function writeOutput(data: string): Promise<void> {
19
+ return new Promise<void>((resolve, reject) => {
20
+ process.stdout.write(data, err => {
21
+ if (err) {
22
+ reject(err);
23
+ } else {
24
+ resolve();
25
+ }
26
+ });
27
+ });
28
+ }
29
+
30
+ // This cache holds opened world states to avoid reopening them for each invocation.
31
+ // It's a map so that in the future we could support multiple world states (if we had multiple fuzzers).
32
+ const worldStateCache = new Map<string, NativeWorldStateService>();
33
+
34
+ async function openExistingWorldState(dataDir: string, mapSizeKb: number): Promise<NativeWorldStateService> {
35
+ const cached = worldStateCache.get(dataDir);
36
+ if (cached) {
37
+ return cached;
38
+ }
39
+
40
+ const ws = await NativeWorldStateService.new(EthAddress.ZERO, dataDir, {
41
+ archiveTreeMapSizeKb: mapSizeKb,
42
+ nullifierTreeMapSizeKb: mapSizeKb,
43
+ noteHashTreeMapSizeKb: mapSizeKb,
44
+ messageTreeMapSizeKb: mapSizeKb,
45
+ publicDataTreeMapSizeKb: mapSizeKb,
46
+ });
47
+
48
+ worldStateCache.set(dataDir, ws);
49
+ return ws;
50
+ }
51
+
52
+ async function simulateWithFuzzer(
53
+ dataDir: string,
54
+ mapSizeKb: number,
55
+ txHint: AvmTxHint,
56
+ globals: GlobalVariables,
57
+ rawContractClasses: any[], // Replace these when we are moving contract classes to TS
58
+ rawContractInstances: [any, any][], // Replace these when we are moving contract instances to TS
59
+ rawPublicDataWrites: any[], // Public data tree writes to apply before simulation
60
+ rawNoteHashes: any[], // Note hashes to apply before simulation
61
+ protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
62
+ ): Promise<{
63
+ reverted: boolean;
64
+ output: Fr[];
65
+ revertReason?: string;
66
+ publicInputs: AvmCircuitPublicInputs;
67
+ publicTxEffect: PublicTxEffect;
68
+ }> {
69
+ const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
70
+
71
+ const simulator = await AvmFuzzerSimulator.create(worldStateService, globals, protocolContracts);
72
+
73
+ await simulator.applyNoteHashes(rawNoteHashes);
74
+
75
+ // Register contract classes from C++ (must happen before public data writes to match C++ order)
76
+ for (const rawClass of rawContractClasses) {
77
+ await simulator.addContractClassFromCpp(rawClass);
78
+ }
79
+
80
+ // Register contract instances from C++
81
+ for (const [rawAddress, rawInstance] of rawContractInstances) {
82
+ await simulator.addContractInstanceFromCpp(rawAddress, rawInstance);
83
+ }
84
+
85
+ // Apply public data writes after contract registration (e.g., for bytecode upgrades)
86
+ // This must happen last to match C++ setup_fuzzer_state ordering
87
+ await simulator.applyPublicDataWrites(rawPublicDataWrites);
88
+
89
+ const result = await simulator.simulate(txHint);
90
+
91
+ const output = result
92
+ .getAppLogicReturnValues()
93
+ .flatMap((rv: { values?: Fr[] } | undefined) => rv?.values?.filter((v: Fr | null | undefined) => v != null) ?? []);
94
+
95
+ return {
96
+ reverted: !result.revertCode.isOK(),
97
+ output,
98
+ revertReason: result.findRevertReason()?.message,
99
+ publicInputs: result.publicInputs!,
100
+ publicTxEffect: result.publicTxEffect,
101
+ };
102
+ }
103
+
104
+ async function execute(base64Line: string): Promise<void> {
105
+ try {
106
+ // Decode base64 and deserialize the entire request from msgpack
107
+ const buffer = Buffer.from(base64Line.trim(), 'base64');
108
+ const rawRequest = deserializeFromMessagePack(buffer);
109
+ const request = FuzzerSimulationRequest.fromPlainObject(rawRequest);
110
+
111
+ // Run the TS simulation
112
+ const result = await simulateWithFuzzer(
113
+ request.wsDataDir,
114
+ request.wsMapSizeKb,
115
+ request.tx,
116
+ request.globals,
117
+ request.contractClasses,
118
+ request.contractInstances,
119
+ request.publicDataWrites,
120
+ request.noteHashes,
121
+ request.protocolContracts,
122
+ );
123
+
124
+ // Serialize the result to msgpack and encode it in base64 for output
125
+ const resultBuffer = serializeWithMessagePack({
126
+ reverted: result.reverted,
127
+ output: result.output,
128
+ revertReason: result.revertReason ?? '',
129
+ endTreeSnapshots: result.publicInputs.endTreeSnapshots,
130
+ publicTxEffect: result.publicTxEffect,
131
+ });
132
+ const base64Response = resultBuffer.toString('base64') + '\n';
133
+ await writeOutput(base64Response);
134
+ } catch (error: any) {
135
+ // If we error, treat as reverted
136
+ const errorResult = serializeWithMessagePack({
137
+ reverted: true,
138
+ output: [] as Fr[],
139
+ revertReason: `Unexpected Error ${error.message}`,
140
+ endTreeSnapshots: TreeSnapshots.empty(),
141
+ publicTxEffect: PublicTxEffect.empty(),
142
+ });
143
+ await writeOutput(errorResult.toString('base64') + '\n');
144
+ }
145
+ }
146
+
147
+ function mainLoop() {
148
+ const rl = createInterface({ input: process.stdin, terminal: false });
149
+
150
+ // Process lines sequentially to avoid race conditions in responses
151
+ const lineQueue: string[] = [];
152
+ let processing = false;
153
+
154
+ async function processQueue() {
155
+ if (processing || lineQueue.length === 0) {
156
+ return;
157
+ }
158
+ processing = true;
159
+ while (lineQueue.length > 0) {
160
+ const line = lineQueue.shift()!;
161
+ await execute(line);
162
+ }
163
+ processing = false;
164
+ }
165
+
166
+ rl.on('line', (line: string) => {
167
+ if (line.trim()) {
168
+ lineQueue.push(line);
169
+ void processQueue();
170
+ }
171
+ });
172
+ rl.on('close', () => process.exit(0));
173
+ }
174
+
175
+ void mainLoop();
@@ -1,5 +1,6 @@
1
- import { sha256Trunc } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
5
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
@@ -571,6 +572,10 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
571
572
  return await this.db.close();
572
573
  }
573
574
 
575
+ async [Symbol.dispose](): Promise<void> {
576
+ await this.close();
577
+ }
578
+
574
579
  public async findLeafIndices<ID extends MerkleTreeId>(
575
580
  treeId: ID,
576
581
  values: MerkleTreeLeafType<ID>[],
@@ -596,7 +601,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
596
601
  public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
597
602
  treeId: ID,
598
603
  leafIndices: bigint[],
599
- ): Promise<(bigint | undefined)[]> {
604
+ ): Promise<(BlockNumber | undefined)[]> {
600
605
  return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
601
606
  }
602
607
  }
@@ -1,6 +1,12 @@
1
1
  export { PublicContractsDB } from './public_db_sources.js';
2
2
  export { GuardedMerkleTreeOperations } from './public_processor/guarded_merkle_tree.js';
3
3
  export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
4
- export { PublicTxSimulator, TelemetryPublicTxSimulator } from './public_tx_simulator/index.js';
4
+ export {
5
+ CppPublicTxSimulator,
6
+ createPublicTxSimulatorForBlockBuilding,
7
+ DumpingCppPublicTxSimulator,
8
+ type PublicTxSimulatorInterface,
9
+ TelemetryCppPublicTxSimulator,
10
+ } from './public_tx_simulator/index.js';
5
11
  export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
6
12
  export { getCallRequestsWithCalldataByPhase } from './utils.js';
@@ -4,8 +4,8 @@ import {
4
4
  NULLIFIER_SUBTREE_HEIGHT,
5
5
  PUBLIC_DATA_SUBTREE_HEIGHT,
6
6
  } from '@aztec/constants';
7
- import { Fr } from '@aztec/foundation/fields';
8
- import { createLogger } from '@aztec/foundation/log';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
8
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
9
9
  import { Timer } from '@aztec/foundation/timer';
10
10
  import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
11
11
  import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
@@ -46,9 +46,14 @@ import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from
46
46
  export class PublicContractsDB implements PublicContractsDBInterface {
47
47
  private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
48
48
 
49
- private log = createLogger('simulator:contracts-data-source');
49
+ private log: Logger;
50
50
 
51
- constructor(private dataSource: ContractDataSource) {}
51
+ constructor(
52
+ private dataSource: ContractDataSource,
53
+ bindings?: LoggerBindings,
54
+ ) {
55
+ this.log = createLogger('simulator:contracts-data-source', bindings);
56
+ }
52
57
 
53
58
  public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
54
59
  const currentState = this.getCurrentState();
@@ -208,9 +213,14 @@ export class PublicContractsDB implements PublicContractsDBInterface {
208
213
  * to decide whether to use hints or not (same with tracing, etc).
209
214
  */
210
215
  export class PublicTreesDB implements PublicStateDBInterface {
211
- private logger = createLogger('simulator:public-trees-db');
216
+ private logger: Logger;
212
217
 
213
- constructor(private readonly db: MerkleTreeWriteOperations) {}
218
+ constructor(
219
+ private readonly db: MerkleTreeWriteOperations,
220
+ bindings?: LoggerBindings,
221
+ ) {
222
+ this.logger = createLogger('simulator:public-trees-db', bindings);
223
+ }
214
224
 
215
225
  public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
216
226
  const timer = new Timer();
@@ -1,3 +1,4 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { SerialQueue } from '@aztec/foundation/queue';
2
3
  import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
3
4
  import type {
@@ -80,6 +81,10 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
80
81
  close(): Promise<void> {
81
82
  return this.guardAndPush(() => this.target.close());
82
83
  }
84
+
85
+ async [Symbol.dispose](): Promise<void> {
86
+ await this.close();
87
+ }
83
88
  getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
84
89
  return this.guardAndPush(() => this.target.getTreeInfo(treeId));
85
90
  }
@@ -126,7 +131,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
126
131
  getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
127
132
  treeId: ID,
128
133
  leafIndices: bigint[],
129
- ): Promise<(bigint | undefined)[]> {
134
+ ): Promise<(BlockNumber | undefined)[]> {
130
135
  return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
131
136
  }
132
137
  createCheckpoint(): Promise<void> {
@@ -1,7 +1,7 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { createLogger } from '@aztec/foundation/log';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { sleep } from '@aztec/foundation/sleep';
6
6
  import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
7
7
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
@@ -51,9 +51,9 @@ import { AssertionError } from 'assert';
51
51
 
52
52
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
53
53
  import {
54
- type PublicTxSimulator,
55
54
  type PublicTxSimulatorConfig,
56
- TelemetryPublicTxSimulator,
55
+ type PublicTxSimulatorInterface,
56
+ TelemetryCppPublicTxSimulator,
57
57
  } from '../public_tx_simulator/index.js';
58
58
  import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
59
59
  import { PublicProcessorMetrics } from './public_processor_metrics.js';
@@ -62,11 +62,15 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
62
62
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
63
63
  */
64
64
  export class PublicProcessorFactory {
65
+ private log: Logger;
65
66
  constructor(
66
67
  private contractDataSource: ContractDataSource,
67
68
  private dateProvider: DateProvider = new DateProvider(),
68
69
  protected telemetryClient: TelemetryClient = getTelemetryClient(),
69
- ) {}
70
+ bindings?: LoggerBindings,
71
+ ) {
72
+ this.log = createLogger('simulator:public-processor-factory', bindings);
73
+ }
70
74
 
71
75
  /**
72
76
  * Creates a new instance of a PublicProcessor.
@@ -79,7 +83,8 @@ export class PublicProcessorFactory {
79
83
  globalVariables: GlobalVariables,
80
84
  config: PublicSimulatorConfig,
81
85
  ): PublicProcessor {
82
- const contractsDB = new PublicContractsDB(this.contractDataSource);
86
+ const bindings = this.log.getBindings();
87
+ const contractsDB = new PublicContractsDB(this.contractDataSource, bindings);
83
88
 
84
89
  const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
85
90
  const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
@@ -91,6 +96,7 @@ export class PublicProcessorFactory {
91
96
  publicTxSimulator,
92
97
  this.dateProvider,
93
98
  this.telemetryClient,
99
+ createLogger('simulator:public-processor', bindings),
94
100
  );
95
101
  }
96
102
 
@@ -99,8 +105,15 @@ export class PublicProcessorFactory {
99
105
  contractsDB: PublicContractsDB,
100
106
  globalVariables: GlobalVariables,
101
107
  config?: Partial<PublicTxSimulatorConfig>,
102
- ): PublicTxSimulator {
103
- return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
108
+ ): PublicTxSimulatorInterface {
109
+ return new TelemetryCppPublicTxSimulator(
110
+ merkleTree,
111
+ contractsDB,
112
+ globalVariables,
113
+ this.telemetryClient,
114
+ config,
115
+ this.log.getBindings(),
116
+ );
104
117
  }
105
118
  }
106
119
 
@@ -122,11 +135,11 @@ export class PublicProcessor implements Traceable {
122
135
  protected globalVariables: GlobalVariables,
123
136
  private guardedMerkleTree: GuardedMerkleTreeOperations,
124
137
  protected contractsDB: PublicContractsDB,
125
- protected publicTxSimulator: PublicTxSimulator,
138
+ protected publicTxSimulator: PublicTxSimulatorInterface,
126
139
  private dateProvider: DateProvider,
127
140
  telemetryClient: TelemetryClient = getTelemetryClient(),
128
- private log = createLogger('simulator:public-processor'),
129
- private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
141
+ private log: Logger,
142
+ private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
130
143
  ) {
131
144
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
132
145
  }
@@ -146,7 +159,7 @@ export class PublicProcessor implements Traceable {
146
159
  txs: Iterable<Tx> | AsyncIterable<Tx>,
147
160
  limits: PublicProcessorLimits = {},
148
161
  validator: PublicProcessorValidator = {},
149
- ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
162
+ ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
150
163
  const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
151
164
  const { preprocessValidator, nullifierCache } = validator;
152
165
  const result: ProcessedTx[] = [];
@@ -160,7 +173,7 @@ export class PublicProcessor implements Traceable {
160
173
  let totalBlockGas = new Gas(0, 0);
161
174
  let totalBlobFields = 0;
162
175
 
163
- for await (const origTx of txs) {
176
+ for await (const tx of txs) {
164
177
  // Only process up to the max tx limit
165
178
  if (maxTransactions !== undefined && result.length >= maxTransactions) {
166
179
  this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
@@ -174,8 +187,8 @@ export class PublicProcessor implements Traceable {
174
187
  }
175
188
 
176
189
  // Skip this tx if it'd exceed max block size
177
- const txHash = origTx.getTxHash().toString();
178
- const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
190
+ const txHash = tx.getTxHash().toString();
191
+ const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
179
192
  if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
180
193
  this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
181
194
  txHash,
@@ -187,7 +200,7 @@ export class PublicProcessor implements Traceable {
187
200
  }
188
201
 
189
202
  // Skip this tx if its gas limit would exceed the block gas limit
190
- const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
203
+ const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
191
204
  if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
192
205
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
193
206
  txHash,
@@ -198,9 +211,6 @@ export class PublicProcessor implements Traceable {
198
211
  continue;
199
212
  }
200
213
 
201
- // The processor modifies the tx objects in place, so we need to clone them.
202
- const tx = Tx.clone(origTx);
203
-
204
214
  // We validate the tx before processing it, to avoid unnecessary work.
205
215
  if (preprocessValidator) {
206
216
  const result = await preprocessValidator.validateTx(tx);
@@ -233,6 +243,12 @@ export class PublicProcessor implements Traceable {
233
243
  try {
234
244
  const [processedTx, returnValues] = await this.processTx(tx, deadline);
235
245
 
246
+ // Inject a fake processing failure after N txs if requested
247
+ const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
248
+ if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
249
+ throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
250
+ }
251
+
236
252
  const txBlobFields = processedTx.txEffect.getNumBlobFields();
237
253
 
238
254
  // If the actual size of this tx would exceed block size, skip it
@@ -251,6 +267,7 @@ export class PublicProcessor implements Traceable {
251
267
  }
252
268
 
253
269
  // If the actual blob fields of this tx would exceed the limit, skip it
270
+ // Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
254
271
  if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
255
272
  this.log.debug(
256
273
  `Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
@@ -282,7 +299,15 @@ export class PublicProcessor implements Traceable {
282
299
  if (err?.name === 'PublicProcessorTimeoutError') {
283
300
  this.log.warn(`Stopping tx processing due to timeout.`);
284
301
  // We hit the transaction execution deadline.
285
- // There may still be a transaction executing. We stop the guarded fork to prevent any further access to the world state.
302
+ // There may still be a transaction executing on a worker thread (C++ via NAPI).
303
+ // Signal cancellation AND WAIT for the simulation to actually stop.
304
+ // This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
305
+ // and won't check the cancellation flag until that operation completes.
306
+ // Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
307
+ // Wait for C++ to stop gracefully.
308
+ await this.publicTxSimulator.cancel?.();
309
+
310
+ // Now stop the guarded fork to prevent any further TS-side access to the world state.
286
311
  await this.guardedMerkleTree.stop();
287
312
 
288
313
  // We now know there can't be any further access to world state. The fork is in a state where there is:
@@ -338,7 +363,7 @@ export class PublicProcessor implements Traceable {
338
363
  totalSizeInBytes,
339
364
  });
340
365
 
341
- return [result, failed, usedTxs, returns];
366
+ return [result, failed, usedTxs, returns, totalBlobFields];
342
367
  }
343
368
 
344
369
  private async checkWorldStateUnchanged(
@@ -521,13 +546,9 @@ export class PublicProcessor implements Traceable {
521
546
  private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
522
547
  const timer = new Timer();
523
548
 
524
- const { hints, publicInputs, gasUsed, revertCode, revertReason, appLogicReturnValues } =
525
- await this.publicTxSimulator.simulate(tx);
526
-
527
- if (!hints) {
528
- this.metrics.recordFailedTx();
529
- throw new Error('Avm proving result was not generated.');
530
- }
549
+ const result = await this.publicTxSimulator.simulate(tx);
550
+ // TODO: use the callStackMetadata here to extract more data about public execution
551
+ const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
531
552
 
532
553
  const contractClassLogs = revertCode.isOK()
533
554
  ? tx.getContractClassLogs()
@@ -539,19 +560,28 @@ export class PublicProcessor implements Traceable {
539
560
  );
540
561
 
541
562
  // TODO(fcarreiro): remove phase count metric.
542
- const phaseCount = 1;
543
563
  const durationMs = timer.ms();
544
- this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
564
+ this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
565
+
566
+ // Extract the return values from the call stack metadata.
567
+ const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
568
+ // Extract the revert reason from the call stack metadata.
569
+ const revertReason = result.findRevertReason();
570
+ // Create proving request if we have hints and public inputs.
571
+ const avmProvingRequest =
572
+ hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
545
573
 
546
574
  const processedTx = makeProcessedTxFromTxWithPublicCalls(
547
575
  tx,
548
- PublicProcessor.generateProvingRequest(publicInputs, hints),
576
+ this.globalVariables,
577
+ avmProvingRequest,
578
+ publicTxEffect,
549
579
  gasUsed,
550
580
  revertCode,
551
581
  revertReason,
552
582
  );
553
583
 
554
- return [processedTx, appLogicReturnValues ?? []];
584
+ return [processedTx, appLogicReturnValues];
555
585
  }
556
586
 
557
587
  /**
@@ -559,7 +589,7 @@ export class PublicProcessor implements Traceable {
559
589
  */
560
590
  private static generateProvingRequest(
561
591
  publicInputs: AvmCircuitPublicInputs,
562
- hints: AvmExecutionHints,
592
+ hints: AvmExecutionHints = AvmExecutionHints.empty(),
563
593
  ): AvmProvingRequest {
564
594
  return {
565
595
  type: ProvingRequestType.PUBLIC_VM,
@@ -1,6 +1,6 @@
1
1
  import type { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
2
2
  import type { Gas } from '@aztec/stdlib/gas';
3
- import type { TxExecutionPhase } from '@aztec/stdlib/tx';
3
+ import { TxExecutionPhase } from '@aztec/stdlib/tx';
4
4
  import {
5
5
  Attributes,
6
6
  type Gauge,
@@ -9,7 +9,7 @@ import {
9
9
  type TelemetryClient,
10
10
  type Tracer,
11
11
  type UpDownCounter,
12
- ValueType,
12
+ createUpDownCounterWithDefault,
13
13
  } from '@aztec/telemetry-client';
14
14
 
15
15
  export class PublicProcessorMetrics {
@@ -34,60 +34,32 @@ export class PublicProcessorMetrics {
34
34
  this.tracer = client.getTracer(name);
35
35
  const meter = client.getMeter(name);
36
36
 
37
- this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION, {
38
- description: 'How long it takes to process a transaction',
39
- unit: 'ms',
40
- valueType: ValueType.INT,
41
- });
37
+ this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
42
38
 
43
- this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
44
- description: 'Number of transactions processed',
39
+ this.txCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
40
+ [Attributes.OK]: [true, false],
45
41
  });
46
42
 
47
- this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT, {
48
- description: 'Number of phases processed',
49
- });
43
+ this.txPhaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
50
44
 
51
- this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION, {
52
- description: 'How long it takes to process a phase',
53
- unit: 'ms',
54
- valueType: ValueType.INT,
55
- });
45
+ this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
56
46
 
57
- this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
58
- description: 'Number of failed phases',
47
+ this.phaseCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
48
+ [Attributes.TX_PHASE_NAME]: [TxExecutionPhase.SETUP, TxExecutionPhase.APP_LOGIC, TxExecutionPhase.TEARDOWN],
49
+ [Attributes.OK]: [true, false],
59
50
  });
60
51
 
61
- this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE, {
62
- description: 'Size of deployed bytecode',
63
- unit: 'By',
64
- });
52
+ this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
65
53
 
66
- this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS, {
67
- description: 'Total gas used in block',
68
- unit: 'gas',
69
- });
54
+ this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
70
55
 
71
- this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM, {
72
- description: 'Total gas used in block as histogram',
73
- unit: 'gas/block',
74
- });
56
+ this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
75
57
 
76
- this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS, {
77
- description: 'Gas used in transaction',
78
- unit: 'gas/tx',
79
- });
58
+ this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
80
59
 
81
- this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE, {
82
- description: 'L2 gas per second for complete block',
83
- unit: 'gas/s',
84
- });
60
+ this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
85
61
 
86
- this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION, {
87
- description: 'How long it takes for tree insertion',
88
- unit: 'us',
89
- valueType: ValueType.INT,
90
- });
62
+ this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
91
63
  }
92
64
 
93
65
  recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {