@aztec/simulator 0.0.1-commit.b655e406 → 0.0.1-commit.d1f2d6c

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 (344) 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 +1 -1
  9. package/dest/private/acvm/acvm_types.d.ts +1 -1
  10. package/dest/private/acvm/deserialize.d.ts +2 -2
  11. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  12. package/dest/private/acvm/deserialize.js +1 -1
  13. package/dest/private/acvm/index.d.ts +1 -1
  14. package/dest/private/acvm/serialize.d.ts +2 -2
  15. package/dest/private/acvm/serialize.d.ts.map +1 -1
  16. package/dest/private/acvm/serialize.js +1 -1
  17. package/dest/private/acvm_native.d.ts +1 -1
  18. package/dest/private/acvm_native.d.ts.map +1 -1
  19. package/dest/private/acvm_wasm.d.ts +1 -1
  20. package/dest/private/acvm_wasm.d.ts.map +1 -1
  21. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  22. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  23. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  24. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  25. package/dest/private/circuit_recording/circuit_recorder.js +16 -15
  26. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
  27. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  28. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
  29. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  30. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  31. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  32. package/dest/private/circuit_simulator.d.ts +1 -1
  33. package/dest/private/factory.d.ts +1 -1
  34. package/dest/public/avm/avm_context.d.ts +2 -2
  35. package/dest/public/avm/avm_context.d.ts.map +1 -1
  36. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  37. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  38. package/dest/public/avm/avm_execution_environment.d.ts +5 -5
  39. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  40. package/dest/public/avm/avm_execution_environment.js +5 -8
  41. package/dest/public/avm/avm_gas.d.ts +2 -2
  42. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  43. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  44. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  45. package/dest/public/avm/avm_memory_types.d.ts +14 -14
  46. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  47. package/dest/public/avm/avm_memory_types.js +4 -1
  48. package/dest/public/avm/avm_simulator.d.ts +4 -3
  49. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  50. package/dest/public/avm/avm_simulator.js +8 -7
  51. package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
  52. package/dest/public/avm/errors.d.ts +8 -2
  53. package/dest/public/avm/errors.d.ts.map +1 -1
  54. package/dest/public/avm/errors.js +14 -2
  55. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  56. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  57. package/dest/public/avm/fixtures/avm_simulation_tester.js +12 -3
  58. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  59. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  60. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  61. package/dest/public/avm/fixtures/initializers.d.ts +2 -3
  62. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  63. package/dest/public/avm/fixtures/initializers.js +7 -5
  64. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  65. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  66. package/dest/public/avm/fixtures/utils.js +3 -2
  67. package/dest/public/avm/index.d.ts +1 -1
  68. package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
  69. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  70. package/dest/public/avm/opcodes/accrued_substate.js +29 -29
  71. package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
  72. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
  73. package/dest/public/avm/opcodes/addressing_mode.js +2 -2
  74. package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
  75. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  76. package/dest/public/avm/opcodes/arithmetic.js +12 -2
  77. package/dest/public/avm/opcodes/bitwise.d.ts +3 -3
  78. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  79. package/dest/public/avm/opcodes/bitwise.js +5 -5
  80. package/dest/public/avm/opcodes/comparators.d.ts +1 -1
  81. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  82. package/dest/public/avm/opcodes/comparators.js +1 -1
  83. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  84. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  85. package/dest/public/avm/opcodes/contract.js +8 -8
  86. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  87. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  88. package/dest/public/avm/opcodes/control_flow.js +4 -4
  89. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  90. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  91. package/dest/public/avm/opcodes/conversion.js +4 -4
  92. package/dest/public/avm/opcodes/ec_add.d.ts +3 -3
  93. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  94. package/dest/public/avm/opcodes/ec_add.js +17 -8
  95. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  96. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  97. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  98. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  99. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  100. package/dest/public/avm/opcodes/external_calls.js +17 -16
  101. package/dest/public/avm/opcodes/hashing.d.ts +7 -7
  102. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  103. package/dest/public/avm/opcodes/hashing.js +21 -16
  104. package/dest/public/avm/opcodes/index.d.ts +1 -1
  105. package/dest/public/avm/opcodes/instruction.d.ts +2 -2
  106. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  107. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  108. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  109. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  110. package/dest/public/avm/opcodes/memory.d.ts +13 -13
  111. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  112. package/dest/public/avm/opcodes/memory.js +25 -25
  113. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  114. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  115. package/dest/public/avm/opcodes/misc.js +8 -8
  116. package/dest/public/avm/opcodes/storage.d.ts +14 -13
  117. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  118. package/dest/public/avm/opcodes/storage.js +34 -24
  119. package/dest/public/avm/revert_reason.d.ts +2 -2
  120. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  121. package/dest/public/avm/revert_reason.js +3 -2
  122. package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
  123. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
  124. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  125. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  126. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  127. package/dest/public/avm/serialization/instruction_serialization.d.ts +1 -1
  128. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  129. package/dest/public/avm/test_utils.d.ts +2 -2
  130. package/dest/public/avm/test_utils.d.ts.map +1 -1
  131. package/dest/public/avm/test_utils.js +1 -1
  132. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  133. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  134. package/dest/public/contracts_db_checkpoint.js +30 -0
  135. package/dest/public/db_interfaces.d.ts +14 -2
  136. package/dest/public/db_interfaces.d.ts.map +1 -1
  137. package/dest/public/debug_fn_name.d.ts +15 -2
  138. package/dest/public/debug_fn_name.d.ts.map +1 -1
  139. package/dest/public/debug_fn_name.js +28 -2
  140. package/dest/public/executor_metrics.d.ts +3 -2
  141. package/dest/public/executor_metrics.d.ts.map +1 -1
  142. package/dest/public/executor_metrics.js +9 -35
  143. package/dest/public/executor_metrics_interface.d.ts +3 -2
  144. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  145. package/dest/public/fixtures/amm_test.d.ts +1 -1
  146. package/dest/public/fixtures/amm_test.js +2 -2
  147. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  148. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  149. package/dest/public/fixtures/bulk_test.js +5 -69
  150. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  151. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  152. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  153. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
  154. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  155. package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
  156. package/dest/public/fixtures/index.d.ts +4 -2
  157. package/dest/public/fixtures/index.d.ts.map +1 -1
  158. package/dest/public/fixtures/index.js +3 -1
  159. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -8
  160. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  161. package/dest/public/fixtures/minimal_public_tx.js +6 -16
  162. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  163. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  164. package/dest/public/fixtures/opcode_spammer.js +1693 -0
  165. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +24 -6
  166. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  167. package/dest/public/fixtures/public_tx_simulation_tester.js +62 -21
  168. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  169. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  170. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  171. package/dest/public/fixtures/token_test.d.ts +6 -2
  172. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  173. package/dest/public/fixtures/token_test.js +13 -12
  174. package/dest/public/fixtures/utils.d.ts +2 -2
  175. package/dest/public/fixtures/utils.d.ts.map +1 -1
  176. package/dest/public/fixtures/utils.js +4 -3
  177. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
  178. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  179. package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
  180. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  181. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  182. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  183. package/dest/public/hinting_db_sources.d.ts +14 -4
  184. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  185. package/dest/public/hinting_db_sources.js +71 -13
  186. package/dest/public/index.d.ts +3 -2
  187. package/dest/public/index.d.ts.map +1 -1
  188. package/dest/public/index.js +1 -1
  189. package/dest/public/public_db_sources.d.ts +22 -63
  190. package/dest/public/public_db_sources.d.ts.map +1 -1
  191. package/dest/public/public_db_sources.js +74 -131
  192. package/dest/public/public_errors.d.ts +1 -1
  193. package/dest/public/public_errors.d.ts.map +1 -1
  194. package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -4
  195. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  196. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  197. package/dest/public/public_processor/public_processor.d.ts +12 -19
  198. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  199. package/dest/public/public_processor/public_processor.js +456 -64
  200. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  201. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  202. package/dest/public/public_processor/public_processor_metrics.js +12 -45
  203. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
  204. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  205. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
  206. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +34 -22
  207. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  208. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +93 -50
  209. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  210. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  211. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  212. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  213. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  214. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  215. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  216. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  217. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  218. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  219. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  220. package/dest/public/public_tx_simulator/factories.js +28 -0
  221. package/dest/public/public_tx_simulator/index.d.ts +5 -1
  222. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  223. package/dest/public/public_tx_simulator/index.js +3 -0
  224. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +14 -7
  225. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  226. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +5 -5
  227. package/dest/public/public_tx_simulator/public_tx_context.d.ts +6 -3
  228. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  229. package/dest/public/public_tx_simulator/public_tx_context.js +13 -5
  230. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +13 -32
  231. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  232. package/dest/public/public_tx_simulator/public_tx_simulator.js +112 -127
  233. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  234. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  235. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -4
  236. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  237. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  238. package/dest/public/side_effect_errors.d.ts +1 -1
  239. package/dest/public/side_effect_errors.d.ts.map +1 -1
  240. package/dest/public/side_effect_trace.d.ts +2 -2
  241. package/dest/public/side_effect_trace.d.ts.map +1 -1
  242. package/dest/public/side_effect_trace.js +1 -1
  243. package/dest/public/side_effect_trace_interface.d.ts +3 -4
  244. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  245. package/dest/public/state_manager/index.d.ts +1 -1
  246. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  247. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  248. package/dest/public/state_manager/public_storage.d.ts +2 -2
  249. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  250. package/dest/public/state_manager/public_storage.js +1 -1
  251. package/dest/public/state_manager/state_manager.d.ts +9 -11
  252. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  253. package/dest/public/state_manager/state_manager.js +12 -8
  254. package/dest/public/test_executor_metrics.d.ts +4 -3
  255. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  256. package/dest/public/test_executor_metrics.js +5 -4
  257. package/dest/public/unique_class_ids.d.ts +1 -1
  258. package/dest/public/unique_class_ids.d.ts.map +1 -1
  259. package/dest/public/utils.d.ts +1 -1
  260. package/dest/server.d.ts +1 -1
  261. package/dest/testing.d.ts +1 -1
  262. package/package.json +21 -20
  263. package/src/common/errors.ts +1 -1
  264. package/src/private/acvm/deserialize.ts +1 -1
  265. package/src/private/acvm/serialize.ts +1 -1
  266. package/src/private/circuit_recording/circuit_recorder.ts +17 -16
  267. package/src/public/avm/avm_context.ts +1 -1
  268. package/src/public/avm/avm_contract_call_result.ts +1 -1
  269. package/src/public/avm/avm_execution_environment.ts +4 -6
  270. package/src/public/avm/avm_gas.ts +3 -3
  271. package/src/public/avm/avm_machine_state.ts +1 -1
  272. package/src/public/avm/avm_memory_types.ts +5 -1
  273. package/src/public/avm/avm_simulator.ts +11 -9
  274. package/src/public/avm/errors.ts +17 -3
  275. package/src/public/avm/fixtures/avm_simulation_tester.ts +10 -2
  276. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  277. package/src/public/avm/fixtures/initializers.ts +8 -10
  278. package/src/public/avm/fixtures/utils.ts +3 -2
  279. package/src/public/avm/opcodes/accrued_substate.ts +15 -15
  280. package/src/public/avm/opcodes/addressing_mode.ts +2 -2
  281. package/src/public/avm/opcodes/arithmetic.ts +14 -2
  282. package/src/public/avm/opcodes/bitwise.ts +3 -3
  283. package/src/public/avm/opcodes/comparators.ts +1 -1
  284. package/src/public/avm/opcodes/contract.ts +4 -7
  285. package/src/public/avm/opcodes/control_flow.ts +2 -2
  286. package/src/public/avm/opcodes/conversion.ts +3 -3
  287. package/src/public/avm/opcodes/ec_add.ts +15 -6
  288. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  289. package/src/public/avm/opcodes/external_calls.ts +10 -9
  290. package/src/public/avm/opcodes/hashing.ts +16 -10
  291. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  292. package/src/public/avm/opcodes/memory.ts +19 -19
  293. package/src/public/avm/opcodes/misc.ts +6 -6
  294. package/src/public/avm/opcodes/storage.ts +30 -22
  295. package/src/public/avm/revert_reason.ts +6 -3
  296. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  297. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  298. package/src/public/avm/test_utils.ts +1 -1
  299. package/src/public/contracts_db_checkpoint.ts +41 -0
  300. package/src/public/db_interfaces.ts +16 -1
  301. package/src/public/debug_fn_name.ts +35 -3
  302. package/src/public/executor_metrics.ts +9 -35
  303. package/src/public/executor_metrics_interface.ts +2 -1
  304. package/src/public/fixtures/amm_test.ts +2 -2
  305. package/src/public/fixtures/bulk_test.ts +9 -9
  306. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  307. package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
  308. package/src/public/fixtures/index.ts +7 -1
  309. package/src/public/fixtures/minimal_public_tx.ts +7 -17
  310. package/src/public/fixtures/opcode_spammer.ts +1754 -0
  311. package/src/public/fixtures/public_tx_simulation_tester.ts +85 -21
  312. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  313. package/src/public/fixtures/token_test.ts +18 -10
  314. package/src/public/fixtures/utils.ts +2 -3
  315. package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
  316. package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
  317. package/src/public/hinting_db_sources.ts +112 -10
  318. package/src/public/index.ts +6 -4
  319. package/src/public/public_db_sources.ts +93 -172
  320. package/src/public/public_processor/guarded_merkle_tree.ts +8 -3
  321. package/src/public/public_processor/public_processor.ts +86 -59
  322. package/src/public/public_processor/public_processor_metrics.ts +11 -45
  323. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +121 -0
  324. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +137 -57
  325. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  326. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
  327. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  328. package/src/public/public_tx_simulator/factories.ts +41 -0
  329. package/src/public/public_tx_simulator/index.ts +4 -0
  330. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +10 -14
  331. package/src/public/public_tx_simulator/public_tx_context.ts +9 -3
  332. package/src/public/public_tx_simulator/public_tx_simulator.ts +163 -193
  333. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  334. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +3 -3
  335. package/src/public/side_effect_trace.ts +1 -1
  336. package/src/public/side_effect_trace_interface.ts +1 -1
  337. package/src/public/state_manager/nullifiers.ts +1 -1
  338. package/src/public/state_manager/public_storage.ts +1 -1
  339. package/src/public/state_manager/state_manager.ts +16 -30
  340. package/src/public/test_executor_metrics.ts +7 -5
  341. package/dest/public/tx_contract_cache.d.ts +0 -41
  342. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  343. package/dest/public/tx_contract_cache.js +0 -49
  344. 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';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { 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';
@@ -70,23 +77,12 @@ export class PublicProcessorFactory {
70
77
  public create(
71
78
  merkleTree: MerkleTreeWriteOperations,
72
79
  globalVariables: GlobalVariables,
73
- config: {
74
- skipFeeEnforcement: boolean;
75
- clientInitiatedSimulation: boolean;
76
- proverId?: Fr;
77
- maxDebugLogMemoryReads?: number;
78
- },
80
+ config: PublicSimulatorConfig,
79
81
  ): PublicProcessor {
80
82
  const contractsDB = new PublicContractsDB(this.contractDataSource);
81
83
 
82
84
  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
- });
85
+ const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
90
86
 
91
87
  return new PublicProcessor(
92
88
  globalVariables,
@@ -103,8 +99,8 @@ export class PublicProcessorFactory {
103
99
  contractsDB: PublicContractsDB,
104
100
  globalVariables: GlobalVariables,
105
101
  config?: Partial<PublicTxSimulatorConfig>,
106
- ): PublicTxSimulator {
107
- return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
102
+ ): PublicTxSimulatorInterface {
103
+ return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
108
104
  }
109
105
  }
110
106
 
@@ -126,11 +122,11 @@ export class PublicProcessor implements Traceable {
126
122
  protected globalVariables: GlobalVariables,
127
123
  private guardedMerkleTree: GuardedMerkleTreeOperations,
128
124
  protected contractsDB: PublicContractsDB,
129
- protected publicTxSimulator: PublicTxSimulator,
125
+ protected publicTxSimulator: PublicTxSimulatorInterface,
130
126
  private dateProvider: DateProvider,
131
127
  telemetryClient: TelemetryClient = getTelemetryClient(),
132
128
  private log = createLogger('simulator:public-processor'),
133
- private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
129
+ private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
134
130
  ) {
135
131
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
136
132
  }
@@ -150,7 +146,7 @@ export class PublicProcessor implements Traceable {
150
146
  txs: Iterable<Tx> | AsyncIterable<Tx>,
151
147
  limits: PublicProcessorLimits = {},
152
148
  validator: PublicProcessorValidator = {},
153
- ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
149
+ ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
154
150
  const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
155
151
  const { preprocessValidator, nullifierCache } = validator;
156
152
  const result: ProcessedTx[] = [];
@@ -164,7 +160,7 @@ export class PublicProcessor implements Traceable {
164
160
  let totalBlockGas = new Gas(0, 0);
165
161
  let totalBlobFields = 0;
166
162
 
167
- for await (const origTx of txs) {
163
+ for await (const tx of txs) {
168
164
  // Only process up to the max tx limit
169
165
  if (maxTransactions !== undefined && result.length >= maxTransactions) {
170
166
  this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
@@ -178,8 +174,8 @@ export class PublicProcessor implements Traceable {
178
174
  }
179
175
 
180
176
  // Skip this tx if it'd exceed max block size
181
- const txHash = origTx.getTxHash().toString();
182
- const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
177
+ const txHash = tx.getTxHash().toString();
178
+ const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
183
179
  if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
184
180
  this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
185
181
  txHash,
@@ -191,7 +187,7 @@ export class PublicProcessor implements Traceable {
191
187
  }
192
188
 
193
189
  // Skip this tx if its gas limit would exceed the block gas limit
194
- const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
190
+ const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
195
191
  if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
196
192
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
197
193
  txHash,
@@ -202,9 +198,6 @@ export class PublicProcessor implements Traceable {
202
198
  continue;
203
199
  }
204
200
 
205
- // The processor modifies the tx objects in place, so we need to clone them.
206
- const tx = Tx.clone(origTx);
207
-
208
201
  // We validate the tx before processing it, to avoid unnecessary work.
209
202
  if (preprocessValidator) {
210
203
  const result = await preprocessValidator.validateTx(tx);
@@ -232,12 +225,21 @@ export class PublicProcessor implements Traceable {
232
225
  // Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
233
226
  const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
234
227
  const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
228
+ this.contractsDB.createCheckpoint();
235
229
 
236
230
  try {
237
231
  const [processedTx, returnValues] = await this.processTx(tx, deadline);
238
232
 
233
+ // Inject a fake processing failure after N txs if requested
234
+ const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
235
+ if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
236
+ throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
237
+ }
238
+
239
+ const txBlobFields = processedTx.txEffect.getNumBlobFields();
240
+
239
241
  // If the actual size of this tx would exceed block size, skip it
240
- const txSize = processedTx.txEffect.getDASize();
242
+ const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
241
243
  if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
242
244
  this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
243
245
  txHash,
@@ -247,11 +249,12 @@ export class PublicProcessor implements Traceable {
247
249
  });
248
250
  // Need to revert the checkpoint here and don't go any further
249
251
  await checkpoint.revert();
252
+ this.contractsDB.revertCheckpoint();
250
253
  continue;
251
254
  }
252
255
 
253
256
  // If the actual blob fields of this tx would exceed the limit, skip it
254
- const txBlobFields = processedTx.txEffect.toBlobFields().length;
257
+ // Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
255
258
  if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
256
259
  this.log.debug(
257
260
  `Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
@@ -264,6 +267,7 @@ export class PublicProcessor implements Traceable {
264
267
  );
265
268
  // Need to revert the checkpoint here and don't go any further
266
269
  await checkpoint.revert();
270
+ this.contractsDB.revertCheckpoint();
267
271
  continue;
268
272
  }
269
273
 
@@ -282,7 +286,15 @@ export class PublicProcessor implements Traceable {
282
286
  if (err?.name === 'PublicProcessorTimeoutError') {
283
287
  this.log.warn(`Stopping tx processing due to timeout.`);
284
288
  // 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.
289
+ // There may still be a transaction executing on a worker thread (C++ via NAPI).
290
+ // Signal cancellation AND WAIT for the simulation to actually stop.
291
+ // This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
292
+ // and won't check the cancellation flag until that operation completes.
293
+ // Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
294
+ // Wait for C++ to stop gracefully.
295
+ await this.publicTxSimulator.cancel?.();
296
+
297
+ // Now stop the guarded fork to prevent any further TS-side access to the world state.
286
298
  await this.guardedMerkleTree.stop();
287
299
 
288
300
  // We now know there can't be any further access to world state. The fork is in a state where there is:
@@ -298,6 +310,9 @@ export class PublicProcessor implements Traceable {
298
310
  // This needs to be done directly on the underlying fork as the guarded fork has been stopped.
299
311
  await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
300
312
 
313
+ // Revert any contracts added to the DB for the tx.
314
+ this.contractsDB.revertCheckpoint();
315
+
301
316
  // Ensure we're at the same state as when we started processing this tx.
302
317
  await this.checkWorldStateUnchanged(startStateReference, txHash, err);
303
318
 
@@ -308,6 +323,7 @@ export class PublicProcessor implements Traceable {
308
323
  // Roll back state to start of TX before proceeding to next TX
309
324
  await checkpoint.revert();
310
325
  await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
326
+ this.contractsDB.revertCheckpoint();
311
327
  const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
312
328
  this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
313
329
  failed.push({ tx, error: err instanceof Error ? err : new Error(errorMessage) });
@@ -318,8 +334,7 @@ export class PublicProcessor implements Traceable {
318
334
  } finally {
319
335
  // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
320
336
  await checkpoint.commit();
321
- // The tx-level contracts cache should not live on to the next tx
322
- this.contractsDB.clearContractsForTx();
337
+ this.contractsDB.commitCheckpointOkIfNone();
323
338
  }
324
339
  }
325
340
 
@@ -335,7 +350,7 @@ export class PublicProcessor implements Traceable {
335
350
  totalSizeInBytes,
336
351
  });
337
352
 
338
- return [result, failed, usedTxs, returns];
353
+ return [result, failed, usedTxs, returns, totalBlobFields];
339
354
  }
340
355
 
341
356
  private async checkWorldStateUnchanged(
@@ -507,10 +522,7 @@ export class PublicProcessor implements Traceable {
507
522
  // Fee payment insertion has already been done. Do the rest.
508
523
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
509
524
 
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
525
  await this.contractsDB.addNewContracts(tx);
513
- this.contractsDB.commitContractsForTx();
514
526
 
515
527
  return [processedTx, undefined];
516
528
  }
@@ -521,21 +533,9 @@ export class PublicProcessor implements Traceable {
521
533
  private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
522
534
  const timer = new Timer();
523
535
 
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
- });
536
+ const result = await this.publicTxSimulator.simulate(tx);
537
+ // TODO: use the callStackMetadata here to extract more data about public execution
538
+ const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
539
539
 
540
540
  const contractClassLogs = revertCode.isOK()
541
541
  ? tx.getContractClassLogs()
@@ -546,14 +546,41 @@ export class PublicProcessor implements Traceable {
546
546
  .map(log => ContractClassPublishedEvent.fromLog(log)),
547
547
  );
548
548
 
549
- const phaseCount = processedPhases.length;
549
+ // TODO(fcarreiro): remove phase count metric.
550
550
  const durationMs = timer.ms();
551
- this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
551
+ this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
552
552
 
553
- const processedTx = makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
553
+ // Extract the return values from the call stack metadata.
554
+ const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
555
+ // Extract the revert reason from the call stack metadata.
556
+ const revertReason = result.findRevertReason();
557
+ // Create proving request if we have hints and public inputs.
558
+ const avmProvingRequest =
559
+ hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
554
560
 
555
- const returnValues = processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
561
+ const processedTx = makeProcessedTxFromTxWithPublicCalls(
562
+ tx,
563
+ this.globalVariables,
564
+ avmProvingRequest,
565
+ publicTxEffect,
566
+ gasUsed,
567
+ revertCode,
568
+ revertReason,
569
+ );
556
570
 
557
- return [processedTx, returnValues];
571
+ return [processedTx, appLogicReturnValues];
572
+ }
573
+
574
+ /**
575
+ * Generate the proving request for the AVM circuit.
576
+ */
577
+ private static generateProvingRequest(
578
+ publicInputs: AvmCircuitPublicInputs,
579
+ hints: AvmExecutionHints = AvmExecutionHints.empty(),
580
+ ): AvmProvingRequest {
581
+ return {
582
+ type: ProvingRequestType.PUBLIC_VM,
583
+ inputs: new AvmCircuitInputs(hints, publicInputs),
584
+ };
558
585
  }
559
586
  }
@@ -9,7 +9,6 @@ import {
9
9
  type TelemetryClient,
10
10
  type Tracer,
11
11
  type UpDownCounter,
12
- ValueType,
13
12
  } from '@aztec/telemetry-client';
14
13
 
15
14
  export class PublicProcessorMetrics {
@@ -34,60 +33,27 @@ export class PublicProcessorMetrics {
34
33
  this.tracer = client.getTracer(name);
35
34
  const meter = client.getMeter(name);
36
35
 
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
- });
36
+ this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION);
42
37
 
43
- this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
44
- description: 'Number of transactions processed',
45
- });
38
+ this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT);
46
39
 
47
- this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT, {
48
- description: 'Number of phases processed',
49
- });
40
+ this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT);
50
41
 
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
- });
42
+ this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION);
56
43
 
57
- this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
58
- description: 'Number of failed phases',
59
- });
44
+ this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT);
60
45
 
61
- this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE, {
62
- description: 'Size of deployed bytecode',
63
- unit: 'By',
64
- });
46
+ this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE);
65
47
 
66
- this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS, {
67
- description: 'Total gas used in block',
68
- unit: 'gas',
69
- });
48
+ this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS);
70
49
 
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
- });
50
+ this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM);
75
51
 
76
- this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS, {
77
- description: 'Gas used in transaction',
78
- unit: 'gas/tx',
79
- });
52
+ this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS);
80
53
 
81
- this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE, {
82
- description: 'L2 gas per second for complete block',
83
- unit: 'gas/s',
84
- });
54
+ this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
85
55
 
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
- });
56
+ this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
91
57
  }
92
58
 
93
59
  recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
@@ -0,0 +1,121 @@
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { type Logger, 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 = createLogger('simulator:contract_provider_for_cpp');
14
+
15
+ constructor(
16
+ private contractsDB: PublicContractsDB,
17
+ private globalVariables: GlobalVariables,
18
+ ) {}
19
+
20
+ public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
21
+ this.log.trace(`Contract provider callback: getContractInstance(${address})`);
22
+
23
+ const aztecAddr = AztecAddress.fromString(address);
24
+
25
+ const instance = await this.contractsDB.getContractInstance(aztecAddr, this.globalVariables.timestamp);
26
+
27
+ if (!instance) {
28
+ this.log.debug(`Contract instance not found: ${address}`);
29
+ return undefined;
30
+ }
31
+
32
+ return serializeWithMessagePack(instance);
33
+ };
34
+
35
+ public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
36
+ this.log.trace(`Contract provider callback: getContractClass(${classId})`);
37
+
38
+ // Parse classId string to Fr
39
+ const classIdFr = Fr.fromString(classId);
40
+
41
+ // Fetch contract class from the contracts DB
42
+ const contractClass = await this.contractsDB.getContractClass(classIdFr);
43
+
44
+ if (!contractClass) {
45
+ this.log.debug(`Contract class not found: ${classId}`);
46
+ return undefined;
47
+ }
48
+
49
+ return serializeWithMessagePack(contractClass);
50
+ };
51
+
52
+ public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
53
+ this.log.trace(`Contract provider callback: addContracts`);
54
+
55
+ const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
56
+
57
+ // Construct ContractDeploymentData from plain object.
58
+ const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
59
+
60
+ // Add contracts to the contracts DB
61
+ this.log.trace(`Calling contractsDB.addContracts`);
62
+ await this.contractsDB.addContracts(contractDeploymentData);
63
+ };
64
+
65
+ public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
66
+ this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
67
+
68
+ // Parse classId string to Fr
69
+ const classIdFr = Fr.fromString(classId);
70
+
71
+ // Fetch bytecode commitment from the contracts DB
72
+ const commitment = await this.contractsDB.getBytecodeCommitment(classIdFr);
73
+
74
+ if (!commitment) {
75
+ this.log.debug(`Bytecode commitment not found: ${classId}`);
76
+ return undefined;
77
+ }
78
+
79
+ // Serialize the Fr to buffer
80
+ return serializeWithMessagePack(commitment);
81
+ };
82
+
83
+ public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
84
+ this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
85
+
86
+ // Parse address and selector strings
87
+ const aztecAddr = AztecAddress.fromString(address);
88
+ const selectorFr = Fr.fromString(selector);
89
+ const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
90
+
91
+ if (!functionSelector) {
92
+ this.log.trace(`calldata[0] is not a function selector: ${selector}`);
93
+ return undefined;
94
+ }
95
+
96
+ // Fetch debug function name from the contracts DB
97
+ const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
98
+
99
+ if (!name) {
100
+ this.log.trace(`Debug function name not found for ${address}:${selector}`);
101
+ return undefined;
102
+ }
103
+
104
+ return name;
105
+ };
106
+
107
+ public createCheckpoint = (): Promise<void> => {
108
+ this.log.trace(`Contract provider callback: createCheckpoint`);
109
+ return Promise.resolve(this.contractsDB.createCheckpoint());
110
+ };
111
+
112
+ public commitCheckpoint = (): Promise<void> => {
113
+ this.log.trace(`Contract provider callback: commitCheckpoint`);
114
+ return Promise.resolve(this.contractsDB.commitCheckpoint());
115
+ };
116
+
117
+ public revertCheckpoint = (): Promise<void> => {
118
+ this.log.trace(`Contract provider callback: revertCheckpoint`);
119
+ return Promise.resolve(this.contractsDB.revertCheckpoint());
120
+ };
121
+ }