@aztec/simulator 0.0.1-commit.24de95ac → 0.0.1-commit.2e2504e2

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 (364) hide show
  1. package/README.md +2 -0
  2. package/dest/client.d.ts +1 -1
  3. package/dest/common/errors.d.ts +2 -2
  4. package/dest/common/errors.d.ts.map +1 -1
  5. package/dest/common/index.d.ts +1 -1
  6. package/dest/common/stats/index.d.ts +1 -1
  7. package/dest/common/stats/stats.d.ts +1 -1
  8. package/dest/private/acvm/acvm.d.ts +4 -2
  9. package/dest/private/acvm/acvm.d.ts.map +1 -1
  10. package/dest/private/acvm/acvm.js +4 -3
  11. package/dest/private/acvm/acvm_types.d.ts +1 -1
  12. package/dest/private/acvm/deserialize.d.ts +2 -2
  13. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  14. package/dest/private/acvm/deserialize.js +1 -1
  15. package/dest/private/acvm/index.d.ts +1 -1
  16. package/dest/private/acvm/serialize.d.ts +2 -2
  17. package/dest/private/acvm/serialize.d.ts.map +1 -1
  18. package/dest/private/acvm/serialize.js +1 -1
  19. package/dest/private/acvm_native.d.ts +5 -3
  20. package/dest/private/acvm_native.d.ts.map +1 -1
  21. package/dest/private/acvm_native.js +8 -6
  22. package/dest/private/acvm_wasm.d.ts +4 -3
  23. package/dest/private/acvm_wasm.d.ts.map +1 -1
  24. package/dest/private/acvm_wasm.js +4 -4
  25. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  26. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  27. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  28. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  29. package/dest/private/circuit_recording/circuit_recorder.js +21 -18
  30. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  31. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  32. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  33. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  34. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  35. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  36. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  37. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  38. package/dest/private/circuit_simulator.d.ts +1 -1
  39. package/dest/private/factory.d.ts +3 -3
  40. package/dest/private/factory.d.ts.map +1 -1
  41. package/dest/private/factory.js +7 -4
  42. package/dest/public/avm/avm_context.d.ts +3 -3
  43. package/dest/public/avm/avm_context.d.ts.map +1 -1
  44. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  45. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  46. package/dest/public/avm/avm_contract_call_result.js +3 -3
  47. package/dest/public/avm/avm_execution_environment.d.ts +9 -8
  48. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  49. package/dest/public/avm/avm_execution_environment.js +5 -8
  50. package/dest/public/avm/avm_gas.d.ts +2 -2
  51. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  52. package/dest/public/avm/avm_machine_state.d.ts +7 -6
  53. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  54. package/dest/public/avm/avm_machine_state.js +3 -2
  55. package/dest/public/avm/avm_memory_types.d.ts +14 -14
  56. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  57. package/dest/public/avm/avm_memory_types.js +4 -1
  58. package/dest/public/avm/avm_simulator.d.ts +5 -3
  59. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  60. package/dest/public/avm/avm_simulator.js +13 -11
  61. package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
  62. package/dest/public/avm/calldata.d.ts +51 -0
  63. package/dest/public/avm/calldata.d.ts.map +1 -0
  64. package/dest/public/avm/calldata.js +63 -0
  65. package/dest/public/avm/errors.d.ts +8 -2
  66. package/dest/public/avm/errors.d.ts.map +1 -1
  67. package/dest/public/avm/errors.js +14 -2
  68. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  69. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  70. package/dest/public/avm/fixtures/avm_simulation_tester.js +15 -5
  71. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  72. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  73. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  74. package/dest/public/avm/fixtures/initializers.d.ts +2 -3
  75. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  76. package/dest/public/avm/fixtures/initializers.js +8 -5
  77. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  78. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  79. package/dest/public/avm/fixtures/utils.js +3 -2
  80. package/dest/public/avm/index.d.ts +1 -1
  81. package/dest/public/avm/opcodes/accrued_substate.d.ts +16 -17
  82. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/accrued_substate.js +39 -39
  84. package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
  85. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/addressing_mode.js +2 -2
  87. package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
  88. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  89. package/dest/public/avm/opcodes/arithmetic.js +12 -2
  90. package/dest/public/avm/opcodes/bitwise.d.ts +3 -3
  91. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  92. package/dest/public/avm/opcodes/bitwise.js +5 -5
  93. package/dest/public/avm/opcodes/comparators.d.ts +1 -1
  94. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  95. package/dest/public/avm/opcodes/comparators.js +1 -1
  96. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  97. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  98. package/dest/public/avm/opcodes/contract.js +8 -8
  99. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  100. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  101. package/dest/public/avm/opcodes/control_flow.js +4 -4
  102. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  103. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  104. package/dest/public/avm/opcodes/conversion.js +4 -4
  105. package/dest/public/avm/opcodes/ec_add.d.ts +3 -3
  106. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  107. package/dest/public/avm/opcodes/ec_add.js +17 -8
  108. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  109. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  110. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  111. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  112. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  113. package/dest/public/avm/opcodes/external_calls.js +23 -22
  114. package/dest/public/avm/opcodes/hashing.d.ts +7 -7
  115. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  116. package/dest/public/avm/opcodes/hashing.js +21 -16
  117. package/dest/public/avm/opcodes/index.d.ts +1 -1
  118. package/dest/public/avm/opcodes/instruction.d.ts +2 -2
  119. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  120. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  121. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  122. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  123. package/dest/public/avm/opcodes/memory.d.ts +13 -13
  124. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  125. package/dest/public/avm/opcodes/memory.js +26 -26
  126. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  127. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  128. package/dest/public/avm/opcodes/misc.js +8 -8
  129. package/dest/public/avm/opcodes/storage.d.ts +14 -13
  130. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  131. package/dest/public/avm/opcodes/storage.js +34 -24
  132. package/dest/public/avm/revert_reason.d.ts +2 -2
  133. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  134. package/dest/public/avm/revert_reason.js +3 -2
  135. package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
  136. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
  137. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  138. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  139. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  140. package/dest/public/avm/serialization/instruction_serialization.d.ts +1 -1
  141. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  142. package/dest/public/avm/test_utils.d.ts +2 -2
  143. package/dest/public/avm/test_utils.d.ts.map +1 -1
  144. package/dest/public/avm/test_utils.js +1 -1
  145. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  146. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  147. package/dest/public/contracts_db_checkpoint.js +30 -0
  148. package/dest/public/db_interfaces.d.ts +14 -2
  149. package/dest/public/db_interfaces.d.ts.map +1 -1
  150. package/dest/public/debug_fn_name.d.ts +16 -3
  151. package/dest/public/debug_fn_name.d.ts.map +1 -1
  152. package/dest/public/debug_fn_name.js +31 -3
  153. package/dest/public/executor_metrics.d.ts +3 -2
  154. package/dest/public/executor_metrics.d.ts.map +1 -1
  155. package/dest/public/executor_metrics.js +13 -34
  156. package/dest/public/executor_metrics_interface.d.ts +3 -2
  157. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  158. package/dest/public/fixtures/amm_test.d.ts +1 -1
  159. package/dest/public/fixtures/amm_test.js +2 -2
  160. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  161. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  162. package/dest/public/fixtures/bulk_test.js +5 -69
  163. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  164. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  165. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  166. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
  167. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  168. package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
  169. package/dest/public/fixtures/index.d.ts +4 -2
  170. package/dest/public/fixtures/index.d.ts.map +1 -1
  171. package/dest/public/fixtures/index.js +3 -1
  172. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -8
  173. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  174. package/dest/public/fixtures/minimal_public_tx.js +6 -16
  175. package/dest/public/fixtures/opcode_spammer.d.ts +122 -0
  176. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  177. package/dest/public/fixtures/opcode_spammer.js +1653 -0
  178. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +24 -6
  179. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  180. package/dest/public/fixtures/public_tx_simulation_tester.js +62 -21
  181. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  182. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  183. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  184. package/dest/public/fixtures/token_test.d.ts +6 -2
  185. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  186. package/dest/public/fixtures/token_test.js +13 -12
  187. package/dest/public/fixtures/utils.d.ts +2 -2
  188. package/dest/public/fixtures/utils.d.ts.map +1 -1
  189. package/dest/public/fixtures/utils.js +4 -3
  190. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
  191. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  192. package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
  193. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  194. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  195. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  196. package/dest/public/hinting_db_sources.d.ts +14 -4
  197. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  198. package/dest/public/hinting_db_sources.js +71 -13
  199. package/dest/public/index.d.ts +3 -2
  200. package/dest/public/index.d.ts.map +1 -1
  201. package/dest/public/index.js +1 -1
  202. package/dest/public/public_db_sources.d.ts +25 -65
  203. package/dest/public/public_db_sources.d.ts.map +1 -1
  204. package/dest/public/public_db_sources.js +78 -135
  205. package/dest/public/public_errors.d.ts +1 -1
  206. package/dest/public/public_errors.d.ts.map +1 -1
  207. package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -4
  208. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  209. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  210. package/dest/public/public_processor/public_processor.d.ts +15 -20
  211. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  212. package/dest/public/public_processor/public_processor.js +463 -68
  213. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  214. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  215. package/dest/public/public_processor/public_processor_metrics.js +28 -45
  216. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +19 -0
  217. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  218. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
  219. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +35 -23
  220. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  221. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +97 -54
  222. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  223. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  224. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  225. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  226. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  227. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  228. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +23 -0
  229. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  230. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  231. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  232. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  233. package/dest/public/public_tx_simulator/factories.js +28 -0
  234. package/dest/public/public_tx_simulator/index.d.ts +5 -1
  235. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  236. package/dest/public/public_tx_simulator/index.js +3 -0
  237. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +14 -7
  238. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  239. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +5 -5
  240. package/dest/public/public_tx_simulator/public_tx_context.d.ts +8 -4
  241. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  242. package/dest/public/public_tx_simulator/public_tx_context.js +17 -9
  243. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +15 -33
  244. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  245. package/dest/public/public_tx_simulator/public_tx_simulator.js +118 -130
  246. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  247. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  248. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -4
  249. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  250. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  251. package/dest/public/side_effect_errors.d.ts +1 -1
  252. package/dest/public/side_effect_errors.d.ts.map +1 -1
  253. package/dest/public/side_effect_trace.d.ts +5 -5
  254. package/dest/public/side_effect_trace.d.ts.map +1 -1
  255. package/dest/public/side_effect_trace.js +4 -4
  256. package/dest/public/side_effect_trace_interface.d.ts +3 -4
  257. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  258. package/dest/public/state_manager/index.d.ts +1 -1
  259. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  260. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  261. package/dest/public/state_manager/public_storage.d.ts +2 -2
  262. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  263. package/dest/public/state_manager/public_storage.js +1 -1
  264. package/dest/public/state_manager/state_manager.d.ts +16 -12
  265. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  266. package/dest/public/state_manager/state_manager.js +21 -10
  267. package/dest/public/test_executor_metrics.d.ts +6 -4
  268. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  269. package/dest/public/test_executor_metrics.js +7 -6
  270. package/dest/public/unique_class_ids.d.ts +1 -1
  271. package/dest/public/unique_class_ids.d.ts.map +1 -1
  272. package/dest/public/utils.d.ts +1 -1
  273. package/dest/server.d.ts +1 -1
  274. package/dest/testing.d.ts +1 -1
  275. package/package.json +21 -20
  276. package/src/common/errors.ts +1 -1
  277. package/src/private/acvm/acvm.ts +4 -3
  278. package/src/private/acvm/deserialize.ts +1 -1
  279. package/src/private/acvm/serialize.ts +1 -1
  280. package/src/private/acvm_native.ts +11 -5
  281. package/src/private/acvm_wasm.ts +7 -3
  282. package/src/private/circuit_recording/circuit_recorder.ts +22 -19
  283. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  284. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  285. package/src/private/factory.ts +7 -4
  286. package/src/public/avm/avm_context.ts +2 -2
  287. package/src/public/avm/avm_contract_call_result.ts +8 -6
  288. package/src/public/avm/avm_execution_environment.ts +13 -10
  289. package/src/public/avm/avm_gas.ts +3 -3
  290. package/src/public/avm/avm_machine_state.ts +7 -6
  291. package/src/public/avm/avm_memory_types.ts +5 -1
  292. package/src/public/avm/avm_simulator.ts +19 -14
  293. package/src/public/avm/calldata.ts +100 -0
  294. package/src/public/avm/errors.ts +17 -3
  295. package/src/public/avm/fixtures/avm_simulation_tester.ts +18 -4
  296. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  297. package/src/public/avm/fixtures/initializers.ts +10 -11
  298. package/src/public/avm/fixtures/utils.ts +3 -2
  299. package/src/public/avm/opcodes/accrued_substate.ts +28 -30
  300. package/src/public/avm/opcodes/addressing_mode.ts +2 -2
  301. package/src/public/avm/opcodes/arithmetic.ts +14 -2
  302. package/src/public/avm/opcodes/bitwise.ts +3 -3
  303. package/src/public/avm/opcodes/comparators.ts +1 -1
  304. package/src/public/avm/opcodes/contract.ts +4 -7
  305. package/src/public/avm/opcodes/control_flow.ts +2 -2
  306. package/src/public/avm/opcodes/conversion.ts +3 -3
  307. package/src/public/avm/opcodes/ec_add.ts +15 -6
  308. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  309. package/src/public/avm/opcodes/external_calls.ts +17 -15
  310. package/src/public/avm/opcodes/hashing.ts +16 -10
  311. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  312. package/src/public/avm/opcodes/memory.ts +20 -20
  313. package/src/public/avm/opcodes/misc.ts +6 -6
  314. package/src/public/avm/opcodes/storage.ts +30 -22
  315. package/src/public/avm/revert_reason.ts +6 -3
  316. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  317. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  318. package/src/public/avm/test_utils.ts +1 -1
  319. package/src/public/contracts_db_checkpoint.ts +41 -0
  320. package/src/public/db_interfaces.ts +16 -1
  321. package/src/public/debug_fn_name.ts +39 -5
  322. package/src/public/executor_metrics.ts +11 -34
  323. package/src/public/executor_metrics_interface.ts +2 -1
  324. package/src/public/fixtures/amm_test.ts +2 -2
  325. package/src/public/fixtures/bulk_test.ts +9 -9
  326. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  327. package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
  328. package/src/public/fixtures/index.ts +7 -1
  329. package/src/public/fixtures/minimal_public_tx.ts +7 -17
  330. package/src/public/fixtures/opcode_spammer.ts +1721 -0
  331. package/src/public/fixtures/public_tx_simulation_tester.ts +85 -21
  332. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  333. package/src/public/fixtures/token_test.ts +18 -10
  334. package/src/public/fixtures/utils.ts +2 -3
  335. package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
  336. package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
  337. package/src/public/hinting_db_sources.ts +112 -10
  338. package/src/public/index.ts +6 -4
  339. package/src/public/public_db_sources.ts +107 -176
  340. package/src/public/public_processor/guarded_merkle_tree.ts +8 -3
  341. package/src/public/public_processor/public_processor.ts +103 -63
  342. package/src/public/public_processor/public_processor_metrics.ts +16 -44
  343. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +124 -0
  344. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +142 -59
  345. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +134 -0
  346. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +239 -0
  347. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +83 -0
  348. package/src/public/public_tx_simulator/factories.ts +43 -0
  349. package/src/public/public_tx_simulator/index.ts +4 -0
  350. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +10 -14
  351. package/src/public/public_tx_simulator/public_tx_context.ts +22 -9
  352. package/src/public/public_tx_simulator/public_tx_simulator.ts +177 -198
  353. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  354. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +3 -3
  355. package/src/public/side_effect_trace.ts +6 -3
  356. package/src/public/side_effect_trace_interface.ts +1 -1
  357. package/src/public/state_manager/nullifiers.ts +1 -1
  358. package/src/public/state_manager/public_storage.ts +1 -1
  359. package/src/public/state_manager/state_manager.ts +35 -26
  360. package/src/public/test_executor_metrics.ts +10 -8
  361. package/dest/public/tx_contract_cache.d.ts +0 -41
  362. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  363. package/dest/public/tx_contract_cache.js +0 -49
  364. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,13 +1,20 @@
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';
8
8
  import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
9
9
  import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
10
- import { PublicDataWrite } from '@aztec/stdlib/avm';
10
+ import {
11
+ AvmCircuitInputs,
12
+ AvmCircuitPublicInputs,
13
+ AvmExecutionHints,
14
+ type AvmProvingRequest,
15
+ PublicDataWrite,
16
+ PublicSimulatorConfig,
17
+ } from '@aztec/stdlib/avm';
11
18
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
12
19
  import type { ContractDataSource } from '@aztec/stdlib/contract';
13
20
  import { computeTransactionFee } from '@aztec/stdlib/fees';
@@ -18,6 +25,7 @@ import type {
18
25
  PublicProcessorValidator,
19
26
  SequencerConfig,
20
27
  } from '@aztec/stdlib/interfaces/server';
28
+ import { ProvingRequestType } from '@aztec/stdlib/proofs';
21
29
  import { MerkleTreeId } from '@aztec/stdlib/trees';
22
30
  import {
23
31
  type FailedTx,
@@ -26,7 +34,6 @@ import {
26
34
  type ProcessedTx,
27
35
  StateReference,
28
36
  Tx,
29
- TxExecutionPhase,
30
37
  makeProcessedTxFromPrivateOnlyTx,
31
38
  makeProcessedTxFromTxWithPublicCalls,
32
39
  } from '@aztec/stdlib/tx';
@@ -44,9 +51,9 @@ import { AssertionError } from 'assert';
44
51
 
45
52
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
46
53
  import {
47
- type PublicTxSimulator,
48
54
  type PublicTxSimulatorConfig,
49
- TelemetryPublicTxSimulator,
55
+ type PublicTxSimulatorInterface,
56
+ TelemetryCppPublicTxSimulator,
50
57
  } from '../public_tx_simulator/index.js';
51
58
  import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
52
59
  import { PublicProcessorMetrics } from './public_processor_metrics.js';
@@ -55,11 +62,15 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
55
62
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
56
63
  */
57
64
  export class PublicProcessorFactory {
65
+ private log: Logger;
58
66
  constructor(
59
67
  private contractDataSource: ContractDataSource,
60
68
  private dateProvider: DateProvider = new DateProvider(),
61
69
  protected telemetryClient: TelemetryClient = getTelemetryClient(),
62
- ) {}
70
+ bindings?: LoggerBindings,
71
+ ) {
72
+ this.log = createLogger('simulator:public-processor-factory', bindings);
73
+ }
63
74
 
64
75
  /**
65
76
  * Creates a new instance of a PublicProcessor.
@@ -70,23 +81,13 @@ export class PublicProcessorFactory {
70
81
  public create(
71
82
  merkleTree: MerkleTreeWriteOperations,
72
83
  globalVariables: GlobalVariables,
73
- config: {
74
- skipFeeEnforcement: boolean;
75
- clientInitiatedSimulation: boolean;
76
- proverId?: Fr;
77
- maxDebugLogMemoryReads?: number;
78
- },
84
+ config: PublicSimulatorConfig,
79
85
  ): PublicProcessor {
80
- const contractsDB = new PublicContractsDB(this.contractDataSource);
86
+ const bindings = this.log.getBindings();
87
+ const contractsDB = new PublicContractsDB(this.contractDataSource, bindings);
81
88
 
82
89
  const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
83
- const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, {
84
- proverId: config.proverId,
85
- doMerkleOperations: true,
86
- skipFeeEnforcement: config.skipFeeEnforcement,
87
- clientInitiatedSimulation: config.clientInitiatedSimulation,
88
- maxDebugLogMemoryReads: config.maxDebugLogMemoryReads,
89
- });
90
+ const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
90
91
 
91
92
  return new PublicProcessor(
92
93
  globalVariables,
@@ -95,6 +96,7 @@ export class PublicProcessorFactory {
95
96
  publicTxSimulator,
96
97
  this.dateProvider,
97
98
  this.telemetryClient,
99
+ createLogger('simulator:public-processor', bindings),
98
100
  );
99
101
  }
100
102
 
@@ -103,8 +105,15 @@ export class PublicProcessorFactory {
103
105
  contractsDB: PublicContractsDB,
104
106
  globalVariables: GlobalVariables,
105
107
  config?: Partial<PublicTxSimulatorConfig>,
106
- ): PublicTxSimulator {
107
- 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
+ );
108
117
  }
109
118
  }
110
119
 
@@ -126,11 +135,11 @@ export class PublicProcessor implements Traceable {
126
135
  protected globalVariables: GlobalVariables,
127
136
  private guardedMerkleTree: GuardedMerkleTreeOperations,
128
137
  protected contractsDB: PublicContractsDB,
129
- protected publicTxSimulator: PublicTxSimulator,
138
+ protected publicTxSimulator: PublicTxSimulatorInterface,
130
139
  private dateProvider: DateProvider,
131
140
  telemetryClient: TelemetryClient = getTelemetryClient(),
132
- private log = createLogger('simulator:public-processor'),
133
- private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
141
+ private log: Logger,
142
+ private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
134
143
  ) {
135
144
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
136
145
  }
@@ -150,7 +159,7 @@ export class PublicProcessor implements Traceable {
150
159
  txs: Iterable<Tx> | AsyncIterable<Tx>,
151
160
  limits: PublicProcessorLimits = {},
152
161
  validator: PublicProcessorValidator = {},
153
- ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
162
+ ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
154
163
  const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
155
164
  const { preprocessValidator, nullifierCache } = validator;
156
165
  const result: ProcessedTx[] = [];
@@ -164,7 +173,7 @@ export class PublicProcessor implements Traceable {
164
173
  let totalBlockGas = new Gas(0, 0);
165
174
  let totalBlobFields = 0;
166
175
 
167
- for await (const origTx of txs) {
176
+ for await (const tx of txs) {
168
177
  // Only process up to the max tx limit
169
178
  if (maxTransactions !== undefined && result.length >= maxTransactions) {
170
179
  this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
@@ -178,8 +187,8 @@ export class PublicProcessor implements Traceable {
178
187
  }
179
188
 
180
189
  // Skip this tx if it'd exceed max block size
181
- const txHash = origTx.getTxHash().toString();
182
- const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
190
+ const txHash = tx.getTxHash().toString();
191
+ const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
183
192
  if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
184
193
  this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
185
194
  txHash,
@@ -191,7 +200,7 @@ export class PublicProcessor implements Traceable {
191
200
  }
192
201
 
193
202
  // Skip this tx if its gas limit would exceed the block gas limit
194
- const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
203
+ const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
195
204
  if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
196
205
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
197
206
  txHash,
@@ -202,9 +211,6 @@ export class PublicProcessor implements Traceable {
202
211
  continue;
203
212
  }
204
213
 
205
- // The processor modifies the tx objects in place, so we need to clone them.
206
- const tx = Tx.clone(origTx);
207
-
208
214
  // We validate the tx before processing it, to avoid unnecessary work.
209
215
  if (preprocessValidator) {
210
216
  const result = await preprocessValidator.validateTx(tx);
@@ -232,12 +238,21 @@ export class PublicProcessor implements Traceable {
232
238
  // Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
233
239
  const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
234
240
  const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
241
+ this.contractsDB.createCheckpoint();
235
242
 
236
243
  try {
237
244
  const [processedTx, returnValues] = await this.processTx(tx, deadline);
238
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
+
252
+ const txBlobFields = processedTx.txEffect.getNumBlobFields();
253
+
239
254
  // If the actual size of this tx would exceed block size, skip it
240
- const txSize = processedTx.txEffect.getDASize();
255
+ const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
241
256
  if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
242
257
  this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
243
258
  txHash,
@@ -247,11 +262,12 @@ export class PublicProcessor implements Traceable {
247
262
  });
248
263
  // Need to revert the checkpoint here and don't go any further
249
264
  await checkpoint.revert();
265
+ this.contractsDB.revertCheckpoint();
250
266
  continue;
251
267
  }
252
268
 
253
269
  // If the actual blob fields of this tx would exceed the limit, skip it
254
- const txBlobFields = processedTx.txEffect.toBlobFields().length;
270
+ // Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
255
271
  if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
256
272
  this.log.debug(
257
273
  `Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
@@ -264,6 +280,7 @@ export class PublicProcessor implements Traceable {
264
280
  );
265
281
  // Need to revert the checkpoint here and don't go any further
266
282
  await checkpoint.revert();
283
+ this.contractsDB.revertCheckpoint();
267
284
  continue;
268
285
  }
269
286
 
@@ -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:
@@ -298,6 +323,9 @@ export class PublicProcessor implements Traceable {
298
323
  // This needs to be done directly on the underlying fork as the guarded fork has been stopped.
299
324
  await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
300
325
 
326
+ // Revert any contracts added to the DB for the tx.
327
+ this.contractsDB.revertCheckpoint();
328
+
301
329
  // Ensure we're at the same state as when we started processing this tx.
302
330
  await this.checkWorldStateUnchanged(startStateReference, txHash, err);
303
331
 
@@ -308,6 +336,7 @@ export class PublicProcessor implements Traceable {
308
336
  // Roll back state to start of TX before proceeding to next TX
309
337
  await checkpoint.revert();
310
338
  await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
339
+ this.contractsDB.revertCheckpoint();
311
340
  const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
312
341
  this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
313
342
  failed.push({ tx, error: err instanceof Error ? err : new Error(errorMessage) });
@@ -318,8 +347,7 @@ export class PublicProcessor implements Traceable {
318
347
  } finally {
319
348
  // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
320
349
  await checkpoint.commit();
321
- // The tx-level contracts cache should not live on to the next tx
322
- this.contractsDB.clearContractsForTx();
350
+ this.contractsDB.commitCheckpointOkIfNone();
323
351
  }
324
352
  }
325
353
 
@@ -335,7 +363,7 @@ export class PublicProcessor implements Traceable {
335
363
  totalSizeInBytes,
336
364
  });
337
365
 
338
- return [result, failed, usedTxs, returns];
366
+ return [result, failed, usedTxs, returns, totalBlobFields];
339
367
  }
340
368
 
341
369
  private async checkWorldStateUnchanged(
@@ -507,10 +535,7 @@ export class PublicProcessor implements Traceable {
507
535
  // Fee payment insertion has already been done. Do the rest.
508
536
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
509
537
 
510
- // Add any contracts registered/deployed in this private-only tx to the block-level cache
511
- // (add to tx-level cache and then commit to block-level cache)
512
538
  await this.contractsDB.addNewContracts(tx);
513
- this.contractsDB.commitContractsForTx();
514
539
 
515
540
  return [processedTx, undefined];
516
541
  }
@@ -521,21 +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 { avmProvingRequest, gasUsed, revertCode, revertReason, processedPhases } =
525
- await this.publicTxSimulator.simulate(tx);
526
-
527
- if (!avmProvingRequest) {
528
- this.metrics.recordFailedTx();
529
- throw new Error('Avm proving result was not generated.');
530
- }
531
-
532
- processedPhases.forEach(phase => {
533
- if (phase.reverted) {
534
- this.metrics.recordRevertedPhase(phase.phase);
535
- } else {
536
- this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
537
- }
538
- });
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;
539
552
 
540
553
  const contractClassLogs = revertCode.isOK()
541
554
  ? tx.getContractClassLogs()
@@ -546,14 +559,41 @@ export class PublicProcessor implements Traceable {
546
559
  .map(log => ContractClassPublishedEvent.fromLog(log)),
547
560
  );
548
561
 
549
- const phaseCount = processedPhases.length;
562
+ // TODO(fcarreiro): remove phase count metric.
550
563
  const durationMs = timer.ms();
551
- 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;
552
573
 
553
- const processedTx = makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
574
+ const processedTx = makeProcessedTxFromTxWithPublicCalls(
575
+ tx,
576
+ this.globalVariables,
577
+ avmProvingRequest,
578
+ publicTxEffect,
579
+ gasUsed,
580
+ revertCode,
581
+ revertReason,
582
+ );
554
583
 
555
- const returnValues = processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
584
+ return [processedTx, appLogicReturnValues];
585
+ }
556
586
 
557
- return [processedTx, returnValues];
587
+ /**
588
+ * Generate the proving request for the AVM circuit.
589
+ */
590
+ private static generateProvingRequest(
591
+ publicInputs: AvmCircuitPublicInputs,
592
+ hints: AvmExecutionHints = AvmExecutionHints.empty(),
593
+ ): AvmProvingRequest {
594
+ return {
595
+ type: ProvingRequestType.PUBLIC_VM,
596
+ inputs: new AvmCircuitInputs(hints, publicInputs),
597
+ };
558
598
  }
559
599
  }
@@ -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) {
@@ -0,0 +1,124 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import type { ContractProvider } from '@aztec/native';
4
+ import { FunctionSelector } from '@aztec/stdlib/abi';
5
+ import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
6
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import { ContractDeploymentData } from '@aztec/stdlib/contract';
8
+ import type { GlobalVariables } from '@aztec/stdlib/tx';
9
+
10
+ import type { PublicContractsDB } from '../public_db_sources.js';
11
+
12
+ export class ContractProviderForCpp implements ContractProvider {
13
+ private log: Logger;
14
+
15
+ constructor(
16
+ private contractsDB: PublicContractsDB,
17
+ private globalVariables: GlobalVariables,
18
+ bindings?: LoggerBindings,
19
+ ) {
20
+ this.log = createLogger('simulator:contract_provider_for_cpp', bindings);
21
+ }
22
+
23
+ public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
24
+ this.log.trace(`Contract provider callback: getContractInstance(${address})`);
25
+
26
+ const aztecAddr = AztecAddress.fromString(address);
27
+
28
+ const instance = await this.contractsDB.getContractInstance(aztecAddr, this.globalVariables.timestamp);
29
+
30
+ if (!instance) {
31
+ this.log.debug(`Contract instance not found: ${address}`);
32
+ return undefined;
33
+ }
34
+
35
+ return serializeWithMessagePack(instance);
36
+ };
37
+
38
+ public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
39
+ this.log.trace(`Contract provider callback: getContractClass(${classId})`);
40
+
41
+ // Parse classId string to Fr
42
+ const classIdFr = Fr.fromString(classId);
43
+
44
+ // Fetch contract class from the contracts DB
45
+ const contractClass = await this.contractsDB.getContractClass(classIdFr);
46
+
47
+ if (!contractClass) {
48
+ this.log.debug(`Contract class not found: ${classId}`);
49
+ return undefined;
50
+ }
51
+
52
+ return serializeWithMessagePack(contractClass);
53
+ };
54
+
55
+ public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
56
+ this.log.trace(`Contract provider callback: addContracts`);
57
+
58
+ const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
59
+
60
+ // Construct ContractDeploymentData from plain object.
61
+ const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
62
+
63
+ // Add contracts to the contracts DB
64
+ this.log.trace(`Calling contractsDB.addContracts`);
65
+ await this.contractsDB.addContracts(contractDeploymentData);
66
+ };
67
+
68
+ public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
69
+ this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
70
+
71
+ // Parse classId string to Fr
72
+ const classIdFr = Fr.fromString(classId);
73
+
74
+ // Fetch bytecode commitment from the contracts DB
75
+ const commitment = await this.contractsDB.getBytecodeCommitment(classIdFr);
76
+
77
+ if (!commitment) {
78
+ this.log.debug(`Bytecode commitment not found: ${classId}`);
79
+ return undefined;
80
+ }
81
+
82
+ // Serialize the Fr to buffer
83
+ return serializeWithMessagePack(commitment);
84
+ };
85
+
86
+ public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
87
+ this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
88
+
89
+ // Parse address and selector strings
90
+ const aztecAddr = AztecAddress.fromString(address);
91
+ const selectorFr = Fr.fromString(selector);
92
+ const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
93
+
94
+ if (!functionSelector) {
95
+ this.log.trace(`calldata[0] is not a function selector: ${selector}`);
96
+ return undefined;
97
+ }
98
+
99
+ // Fetch debug function name from the contracts DB
100
+ const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
101
+
102
+ if (!name) {
103
+ this.log.trace(`Debug function name not found for ${address}:${selector}`);
104
+ return undefined;
105
+ }
106
+
107
+ return name;
108
+ };
109
+
110
+ public createCheckpoint = (): Promise<void> => {
111
+ this.log.trace(`Contract provider callback: createCheckpoint`);
112
+ return Promise.resolve(this.contractsDB.createCheckpoint());
113
+ };
114
+
115
+ public commitCheckpoint = (): Promise<void> => {
116
+ this.log.trace(`Contract provider callback: commitCheckpoint`);
117
+ return Promise.resolve(this.contractsDB.commitCheckpoint());
118
+ };
119
+
120
+ public revertCheckpoint = (): Promise<void> => {
121
+ this.log.trace(`Contract provider callback: revertCheckpoint`);
122
+ return Promise.resolve(this.contractsDB.revertCheckpoint());
123
+ };
124
+ }