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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/dest/client.d.ts +1 -1
  2. package/dest/common/errors.d.ts +2 -8
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/common/index.d.ts +1 -1
  5. package/dest/common/stats/index.d.ts +1 -1
  6. package/dest/common/stats/stats.d.ts +1 -1
  7. package/dest/private/acvm/acvm.d.ts +1 -1
  8. package/dest/private/acvm/acvm_types.d.ts +1 -1
  9. package/dest/private/acvm/deserialize.d.ts +2 -2
  10. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  11. package/dest/private/acvm/deserialize.js +1 -1
  12. package/dest/private/acvm/index.d.ts +1 -1
  13. package/dest/private/acvm/serialize.d.ts +2 -2
  14. package/dest/private/acvm/serialize.d.ts.map +1 -1
  15. package/dest/private/acvm/serialize.js +1 -1
  16. package/dest/private/acvm_native.d.ts +2 -3
  17. package/dest/private/acvm_native.d.ts.map +1 -1
  18. package/dest/private/acvm_native.js +15 -13
  19. package/dest/private/acvm_wasm.d.ts +1 -1
  20. package/dest/private/acvm_wasm.d.ts.map +1 -1
  21. package/dest/private/acvm_wasm_with_blobs.d.ts +1 -1
  22. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -1
  23. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  24. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  25. package/dest/private/circuit_recording/circuit_recorder.js +16 -15
  26. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +1 -1
  27. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  28. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +1 -1
  29. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  30. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +2 -2
  31. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  32. package/dest/private/circuit_simulator.d.ts +1 -1
  33. package/dest/private/factory.d.ts +1 -1
  34. package/dest/public/avm/avm_context.d.ts +2 -2
  35. package/dest/public/avm/avm_context.d.ts.map +1 -1
  36. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  37. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  38. package/dest/public/avm/avm_execution_environment.d.ts +5 -4
  39. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  40. package/dest/public/avm/avm_execution_environment.js +5 -5
  41. package/dest/public/avm/avm_gas.d.ts +2 -2
  42. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  43. package/dest/public/avm/avm_gas.js +2 -2
  44. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  45. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  46. package/dest/public/avm/avm_memory_types.d.ts +20 -14
  47. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  48. package/dest/public/avm/avm_memory_types.js +10 -3
  49. package/dest/public/avm/avm_simulator.d.ts +4 -3
  50. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  51. package/dest/public/avm/avm_simulator.js +19 -25
  52. package/dest/public/avm/avm_simulator_interface.d.ts +1 -1
  53. package/dest/public/avm/errors.d.ts +13 -16
  54. package/dest/public/avm/errors.d.ts.map +1 -1
  55. package/dest/public/avm/errors.js +21 -22
  56. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +3 -2
  57. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  58. package/dest/public/avm/fixtures/avm_simulation_tester.js +14 -6
  59. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +4 -2
  60. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  61. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +23 -1
  62. package/dest/public/avm/fixtures/initializers.d.ts +2 -3
  63. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  64. package/dest/public/avm/fixtures/initializers.js +6 -4
  65. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  66. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  67. package/dest/public/avm/fixtures/utils.js +3 -2
  68. package/dest/public/avm/index.d.ts +1 -1
  69. package/dest/public/avm/opcodes/accrued_substate.d.ts +3 -3
  70. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/accrued_substate.js +8 -8
  72. package/dest/public/avm/opcodes/addressing_mode.d.ts +1 -1
  73. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/addressing_mode.js +4 -5
  75. package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
  76. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/arithmetic.js +11 -1
  78. package/dest/public/avm/opcodes/bitwise.d.ts +5 -5
  79. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  81. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  82. package/dest/public/avm/opcodes/contract.d.ts +1 -1
  83. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  84. package/dest/public/avm/opcodes/control_flow.d.ts +1 -1
  85. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/conversion.d.ts +1 -1
  87. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  88. package/dest/public/avm/opcodes/conversion.js +3 -0
  89. package/dest/public/avm/opcodes/ec_add.d.ts +2 -2
  90. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  91. package/dest/public/avm/opcodes/ec_add.js +6 -6
  92. package/dest/public/avm/opcodes/environment_getters.d.ts +1 -1
  93. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  94. package/dest/public/avm/opcodes/environment_getters.js +5 -7
  95. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  96. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  97. package/dest/public/avm/opcodes/external_calls.js +1 -1
  98. package/dest/public/avm/opcodes/hashing.d.ts +2 -2
  99. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  100. package/dest/public/avm/opcodes/hashing.js +9 -4
  101. package/dest/public/avm/opcodes/index.d.ts +1 -1
  102. package/dest/public/avm/opcodes/instruction.d.ts +2 -2
  103. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  104. package/dest/public/avm/opcodes/instruction.js +5 -6
  105. package/dest/public/avm/opcodes/instruction_impl.d.ts +1 -1
  106. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  107. package/dest/public/avm/opcodes/memory.d.ts +2 -2
  108. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  109. package/dest/public/avm/opcodes/memory.js +1 -1
  110. package/dest/public/avm/opcodes/misc.d.ts +3 -2
  111. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  112. package/dest/public/avm/opcodes/misc.js +28 -8
  113. package/dest/public/avm/opcodes/storage.d.ts +3 -3
  114. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  115. package/dest/public/avm/revert_reason.d.ts +2 -2
  116. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  117. package/dest/public/avm/revert_reason.js +3 -2
  118. package/dest/public/avm/serialization/buffer_cursor.d.ts +1 -1
  119. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
  120. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  121. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  122. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  123. package/dest/public/avm/serialization/instruction_serialization.d.ts +9 -1
  124. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  125. package/dest/public/avm/serialization/instruction_serialization.js +11 -1
  126. package/dest/public/avm/test_utils.d.ts +4 -4
  127. package/dest/public/avm/test_utils.d.ts.map +1 -1
  128. package/dest/public/avm/test_utils.js +7 -10
  129. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  130. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  131. package/dest/public/contracts_db_checkpoint.js +30 -0
  132. package/dest/public/db_interfaces.d.ts +14 -2
  133. package/dest/public/db_interfaces.d.ts.map +1 -1
  134. package/dest/public/debug_fn_name.d.ts +15 -2
  135. package/dest/public/debug_fn_name.d.ts.map +1 -1
  136. package/dest/public/debug_fn_name.js +28 -2
  137. package/dest/public/executor_metrics.d.ts +3 -2
  138. package/dest/public/executor_metrics.d.ts.map +1 -1
  139. package/dest/public/executor_metrics.js +1 -1
  140. package/dest/public/executor_metrics_interface.d.ts +3 -2
  141. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  142. package/dest/public/fixtures/amm_test.d.ts +1 -1
  143. package/dest/public/fixtures/amm_test.js +2 -2
  144. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  145. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  146. package/dest/public/fixtures/bulk_test.js +59 -161
  147. package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
  148. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
  149. package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
  150. package/dest/public/fixtures/custom_bytecode_tests.d.ts +12 -0
  151. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -0
  152. package/dest/public/fixtures/custom_bytecode_tests.js +174 -0
  153. package/dest/public/fixtures/index.d.ts +5 -2
  154. package/dest/public/fixtures/index.d.ts.map +1 -1
  155. package/dest/public/fixtures/index.js +4 -1
  156. package/dest/public/fixtures/minimal_public_tx.d.ts +4 -9
  157. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  158. package/dest/public/fixtures/minimal_public_tx.js +8 -32
  159. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  160. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  161. package/dest/public/fixtures/opcode_spammer.js +1681 -0
  162. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +25 -5
  163. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  164. package/dest/public/fixtures/public_tx_simulation_tester.js +63 -17
  165. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  166. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  167. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  168. package/dest/public/fixtures/token_test.d.ts +6 -2
  169. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  170. package/dest/public/fixtures/token_test.js +13 -12
  171. package/dest/public/fixtures/utils.d.ts +2 -2
  172. package/dest/public/fixtures/utils.d.ts.map +1 -1
  173. package/dest/public/fixtures/utils.js +7 -6
  174. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
  175. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  176. package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -0
  177. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  178. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  179. package/dest/public/fuzzing/avm_simulator_bin.js +100 -0
  180. package/dest/public/hinting_db_sources.d.ts +16 -4
  181. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  182. package/dest/public/hinting_db_sources.js +74 -13
  183. package/dest/public/index.d.ts +3 -2
  184. package/dest/public/index.d.ts.map +1 -1
  185. package/dest/public/index.js +1 -1
  186. package/dest/public/public_db_sources.d.ts +24 -65
  187. package/dest/public/public_db_sources.d.ts.map +1 -1
  188. package/dest/public/public_db_sources.js +85 -132
  189. package/dest/public/public_errors.d.ts +12 -0
  190. package/dest/public/public_errors.d.ts.map +1 -0
  191. package/dest/public/public_errors.js +13 -0
  192. package/dest/public/public_processor/guarded_merkle_tree.d.ts +6 -2
  193. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  194. package/dest/public/public_processor/guarded_merkle_tree.js +8 -0
  195. package/dest/public/public_processor/public_processor.d.ts +11 -13
  196. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  197. package/dest/public/public_processor/public_processor.js +477 -70
  198. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  199. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  200. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +18 -0
  201. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  202. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +98 -0
  203. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +53 -0
  204. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -0
  205. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +131 -0
  206. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  207. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  208. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  209. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  210. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  211. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  212. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  213. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  214. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  215. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  216. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  217. package/dest/public/public_tx_simulator/factories.js +28 -0
  218. package/dest/public/public_tx_simulator/index.d.ts +6 -1
  219. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  220. package/dest/public/public_tx_simulator/index.js +3 -0
  221. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +16 -8
  222. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  223. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +7 -8
  224. package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -4
  225. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  226. package/dest/public/public_tx_simulator/public_tx_context.js +22 -10
  227. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +22 -29
  228. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  229. package/dest/public/public_tx_simulator/public_tx_simulator.js +178 -127
  230. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
  231. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
  232. package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
  233. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +4 -3
  234. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  235. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +396 -20
  236. package/dest/public/side_effect_errors.d.ts +42 -2
  237. package/dest/public/side_effect_errors.d.ts.map +1 -1
  238. package/dest/public/side_effect_errors.js +70 -1
  239. package/dest/public/side_effect_trace.d.ts +13 -7
  240. package/dest/public/side_effect_trace.d.ts.map +1 -1
  241. package/dest/public/side_effect_trace.js +36 -21
  242. package/dest/public/side_effect_trace_interface.d.ts +9 -4
  243. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  244. package/dest/public/state_manager/index.d.ts +1 -1
  245. package/dest/public/state_manager/nullifiers.d.ts +2 -5
  246. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  247. package/dest/public/state_manager/nullifiers.js +1 -6
  248. package/dest/public/state_manager/public_storage.d.ts +2 -2
  249. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  250. package/dest/public/state_manager/public_storage.js +1 -1
  251. package/dest/public/state_manager/state_manager.d.ts +16 -13
  252. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  253. package/dest/public/state_manager/state_manager.js +64 -21
  254. package/dest/public/test_executor_metrics.d.ts +4 -3
  255. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  256. package/dest/public/test_executor_metrics.js +5 -4
  257. package/dest/public/unique_class_ids.d.ts +1 -1
  258. package/dest/public/unique_class_ids.d.ts.map +1 -1
  259. package/dest/public/utils.d.ts +1 -1
  260. package/dest/server.d.ts +1 -1
  261. package/dest/testing.d.ts +1 -1
  262. package/package.json +24 -19
  263. package/src/common/errors.ts +1 -1
  264. package/src/private/acvm/deserialize.ts +1 -1
  265. package/src/private/acvm/serialize.ts +1 -1
  266. package/src/private/acvm_native.ts +18 -11
  267. package/src/private/circuit_recording/circuit_recorder.ts +17 -16
  268. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +1 -1
  269. package/src/public/avm/avm_context.ts +1 -1
  270. package/src/public/avm/avm_contract_call_result.ts +1 -1
  271. package/src/public/avm/avm_execution_environment.ts +4 -3
  272. package/src/public/avm/avm_gas.ts +5 -5
  273. package/src/public/avm/avm_machine_state.ts +1 -1
  274. package/src/public/avm/avm_memory_types.ts +12 -3
  275. package/src/public/avm/avm_simulator.ts +24 -33
  276. package/src/public/avm/errors.ts +24 -27
  277. package/src/public/avm/fixtures/avm_simulation_tester.ts +14 -4
  278. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +33 -1
  279. package/src/public/avm/fixtures/initializers.ts +7 -8
  280. package/src/public/avm/fixtures/utils.ts +3 -2
  281. package/src/public/avm/opcodes/accrued_substate.ts +5 -5
  282. package/src/public/avm/opcodes/addressing_mode.ts +5 -5
  283. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  284. package/src/public/avm/opcodes/conversion.ts +4 -0
  285. package/src/public/avm/opcodes/ec_add.ts +6 -6
  286. package/src/public/avm/opcodes/environment_getters.ts +6 -8
  287. package/src/public/avm/opcodes/external_calls.ts +1 -1
  288. package/src/public/avm/opcodes/hashing.ts +10 -4
  289. package/src/public/avm/opcodes/instruction.ts +8 -6
  290. package/src/public/avm/opcodes/memory.ts +1 -1
  291. package/src/public/avm/opcodes/misc.ts +41 -7
  292. package/src/public/avm/revert_reason.ts +6 -3
  293. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  294. package/src/public/avm/serialization/instruction_serialization.ts +13 -1
  295. package/src/public/avm/test_utils.ts +7 -15
  296. package/src/public/contracts_db_checkpoint.ts +41 -0
  297. package/src/public/db_interfaces.ts +16 -1
  298. package/src/public/debug_fn_name.ts +35 -3
  299. package/src/public/executor_metrics.ts +2 -1
  300. package/src/public/executor_metrics_interface.ts +2 -1
  301. package/src/public/fixtures/amm_test.ts +2 -2
  302. package/src/public/fixtures/bulk_test.ts +38 -25
  303. package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
  304. package/src/public/fixtures/custom_bytecode_tests.ts +219 -0
  305. package/src/public/fixtures/index.ts +8 -1
  306. package/src/public/fixtures/minimal_public_tx.ts +9 -42
  307. package/src/public/fixtures/opcode_spammer.ts +1638 -0
  308. package/src/public/fixtures/public_tx_simulation_tester.ts +90 -22
  309. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  310. package/src/public/fixtures/token_test.ts +18 -10
  311. package/src/public/fixtures/utils.ts +5 -6
  312. package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
  313. package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
  314. package/src/public/hinting_db_sources.ts +117 -10
  315. package/src/public/index.ts +8 -1
  316. package/src/public/public_db_sources.ts +112 -175
  317. package/src/public/public_errors.ts +14 -0
  318. package/src/public/public_processor/guarded_merkle_tree.ts +10 -1
  319. package/src/public/public_processor/public_processor.ts +112 -79
  320. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +121 -0
  321. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +200 -0
  322. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  323. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
  324. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  325. package/src/public/public_tx_simulator/factories.ts +41 -0
  326. package/src/public/public_tx_simulator/index.ts +5 -0
  327. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +13 -14
  328. package/src/public/public_tx_simulator/public_tx_context.ts +20 -7
  329. package/src/public/public_tx_simulator/public_tx_simulator.ts +265 -179
  330. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
  331. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -13
  332. package/src/public/side_effect_errors.ts +91 -1
  333. package/src/public/side_effect_trace.ts +49 -24
  334. package/src/public/side_effect_trace_interface.ts +7 -1
  335. package/src/public/state_manager/nullifiers.ts +2 -8
  336. package/src/public/state_manager/public_storage.ts +1 -1
  337. package/src/public/state_manager/state_manager.ts +87 -39
  338. package/src/public/test_executor_metrics.ts +7 -5
  339. package/dest/public/bytecode_errors.d.ts +0 -4
  340. package/dest/public/bytecode_errors.d.ts.map +0 -1
  341. package/dest/public/bytecode_errors.js +0 -6
  342. package/dest/public/tx_contract_cache.d.ts +0 -41
  343. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  344. package/dest/public/tx_contract_cache.js +0 -49
  345. package/src/public/bytecode_errors.ts +0 -6
  346. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,19 +1,11 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
- import type { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
+ import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
5
5
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
6
- import {
7
- AvmCircuitInputs,
8
- AvmCircuitPublicInputs,
9
- AvmExecutionHints,
10
- type AvmProvingRequest,
11
- AvmTxHint,
12
- type RevertCode,
13
- } from '@aztec/stdlib/avm';
6
+ import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
14
7
  import { SimulationError } from '@aztec/stdlib/errors';
15
- import type { Gas, GasUsed } from '@aztec/stdlib/gas';
16
- import { ProvingRequestType } from '@aztec/stdlib/proofs';
8
+ import { Gas } from '@aztec/stdlib/gas';
17
9
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
18
10
  import {
19
11
  type GlobalVariables,
@@ -23,15 +15,60 @@ import {
23
15
  TxExecutionPhase,
24
16
  } from '@aztec/stdlib/tx';
25
17
 
18
+ import { strict as assert } from 'assert';
19
+
26
20
  import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
27
21
  import { AvmSimulator } from '../avm/index.js';
28
22
  import { getPublicFunctionDebugName } from '../debug_fn_name.js';
29
23
  import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
30
24
  import { type PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
25
+ import {
26
+ L2ToL1MessageLimitReachedError,
27
+ NoteHashLimitReachedError,
28
+ NullifierCollisionError,
29
+ NullifierLimitReachedError,
30
+ } from '../side_effect_errors.js';
31
31
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
32
32
  import { PublicTxContext } from './public_tx_context.js';
33
+ import type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
34
+
35
+ // The errors below are only thrown here in the public tx simulator,
36
+ // and only during revertible phases (revertible insertions, app logic and teardown).
37
+ // These are strictly "checked" errors (not exported and never propagated).
38
+ // They are used internally for control flow to trigger rollbacks to the post-setup state.
39
+
40
+ /**
41
+ * Error thrown when public tx simulation reverts in a known/checked way during revertible insertions.
42
+ */
43
+ class TxSimRevertibleInsertionsRevert extends Error {
44
+ constructor() {
45
+ super('Public Tx Simulation reverted during Revertible Insertions');
46
+ this.name = 'TxSimRevertibleInsertionsRevert';
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Error thrown when public tx simulation reverts during app logic.
52
+ */
53
+ class TxSimAppLogicRevert extends Error {
54
+ constructor() {
55
+ super('Public Tx Simulation reverted during App Logic');
56
+ this.name = 'TxSimAppLogicRevert';
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Error thrown when public tx simulation reverts during teardown.
62
+ */
63
+ class TxSimTeardownRevert extends Error {
64
+ constructor() {
65
+ super('Public Tx Simulation reverted during Teardown');
66
+ this.name = 'TxSimTeardownRevert';
67
+ }
68
+ }
33
69
 
34
- export type ProcessedPhase = {
70
+ /** Only used internally. */
71
+ type ProcessedPhase = {
35
72
  phase: TxExecutionPhase;
36
73
  durationMs?: number;
37
74
  returnValues: NestedProcessReturnValues[];
@@ -39,27 +76,17 @@ export type ProcessedPhase = {
39
76
  revertReason?: SimulationError;
40
77
  };
41
78
 
42
- export type PublicTxResult = {
43
- avmProvingRequest: AvmProvingRequest;
44
- /** Gas used during the execution of this tx */
45
- gasUsed: GasUsed;
46
- revertCode: RevertCode;
47
- /** Revert reason, if any */
48
- revertReason?: SimulationError;
49
- processedPhases: ProcessedPhase[];
50
- };
51
-
52
- export class PublicTxSimulator {
79
+ export class PublicTxSimulator implements PublicTxSimulatorInterface {
53
80
  protected log: Logger;
81
+ protected readonly config: PublicSimulatorConfig;
54
82
 
55
83
  constructor(
56
- private merkleTree: MerkleTreeWriteOperations,
57
- private contractsDB: PublicContractsDB,
58
- private globalVariables: GlobalVariables,
59
- private doMerkleOperations: boolean = false,
60
- private skipFeeEnforcement: boolean = false,
61
- private clientInitiatedSimulation: boolean = false,
84
+ protected merkleTree: MerkleTreeWriteOperations,
85
+ protected contractsDB: PublicContractsDB,
86
+ protected globalVariables: GlobalVariables,
87
+ config?: Partial<PublicSimulatorConfig>,
62
88
  ) {
89
+ this.config = PublicSimulatorConfig.from(config ?? {});
63
90
  this.log = createLogger(`simulator:public_tx_simulator`);
64
91
  }
65
92
 
@@ -69,121 +96,143 @@ export class PublicTxSimulator {
69
96
  * @returns The result of the transaction's public execution.
70
97
  */
71
98
  public async simulate(tx: Tx): Promise<PublicTxResult> {
72
- try {
73
- const txHash = this.computeTxHash(tx);
74
- this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
75
-
76
- // Create hinting DBs.
77
- const hints = new AvmExecutionHints(this.globalVariables, AvmTxHint.fromTx(tx, this.globalVariables.gasFees));
78
- const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
79
- const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
80
- const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
81
-
82
- const context = await PublicTxContext.create(
83
- hintingTreesDB,
84
- hintingContractsDB,
85
- tx,
86
- this.globalVariables,
87
- this.doMerkleOperations,
88
- );
99
+ const txHash = this.computeTxHash(tx);
100
+ this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
101
+
102
+ // Create hinting DBs.
103
+ const hints = new AvmExecutionHints(
104
+ this.globalVariables,
105
+ AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
106
+ ProtocolContractsList, // imported from file
107
+ );
108
+ const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
109
+ const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
110
+ const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
111
+
112
+ const context = await PublicTxContext.create(
113
+ hintingTreesDB,
114
+ hintingContractsDB,
115
+ tx,
116
+ this.globalVariables,
117
+ ProtocolContractsList, // imported from file
118
+ this.config.proverId,
119
+ );
120
+
121
+ // This will throw if there is a nullifier collision.
122
+ // In that case the transaction will be thrown out.
123
+ await this.insertNonRevertiblesFromPrivate(context);
89
124
 
90
- // This will throw if there is a nullifier collision.
125
+ const processedPhases: ProcessedPhase[] = [];
126
+ if (context.hasPhase(TxExecutionPhase.SETUP)) {
127
+ // This will throw if the setup phase reverts.
91
128
  // In that case the transaction will be thrown out.
92
- await this.insertNonRevertiblesFromPrivate(context, tx);
93
-
94
- const processedPhases: ProcessedPhase[] = [];
95
- if (context.hasPhase(TxExecutionPhase.SETUP)) {
96
- // This will throw if the setup phase reverts.
97
- // In that case the transaction will be thrown out.
98
- const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
99
- if (setupResult.reverted) {
100
- throw new Error(
101
- `Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
102
- );
103
- }
104
- processedPhases.push(setupResult);
129
+ const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
130
+ if (setupResult.reverted) {
131
+ throw new Error(
132
+ `[SETUP] UNRECOVERABLE ERROR! The transaction will be thrown out. ${setupResult.revertReason?.message}`,
133
+ );
105
134
  }
135
+ processedPhases.push(setupResult);
136
+ }
137
+
138
+ // The checkpoint we should go back to if anything from now on reverts.
139
+ await context.state.fork();
140
+ hintingContractsDB.createCheckpoint();
106
141
 
107
- // The checkpoint we should go back to if anything from now on reverts.
108
- await context.state.fork();
109
-
110
- try {
111
- // This will throw if there is a nullifier collision.
112
- await this.insertRevertiblesFromPrivate(context, tx);
113
- // Only proceed with app logic if there was no revert during revertible insertion.
114
- if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
115
- const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
116
- processedPhases.push(appLogicResult);
117
- if (appLogicResult.reverted) {
118
- throw new Error(`App logic phase reverted! ${appLogicResult.revertReason?.message}`);
119
- }
142
+ try {
143
+ // This will throw if there is a nullifier collision or other insertion error (limit reached).
144
+ await this.insertRevertiblesFromPrivate(context);
145
+
146
+ // Only proceed with app logic if there was no revert during revertible insertion.
147
+ if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
148
+ const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
149
+ processedPhases.push(appLogicResult);
150
+ if (appLogicResult.reverted) {
151
+ throw new TxSimAppLogicRevert();
120
152
  }
121
- } catch (e) {
122
- this.log.debug(String(e));
153
+ }
154
+ } catch (e: any) {
155
+ if (e instanceof TxSimRevertibleInsertionsRevert || e instanceof TxSimAppLogicRevert) {
123
156
  // We revert to the post-setup state.
124
157
  await context.state.discardForkedState();
158
+ hintingContractsDB.revertCheckpoint();
125
159
  // But we also create a new fork so that the teardown phase can transparently
126
160
  // commit or rollback at the end of teardown.
127
161
  await context.state.fork();
162
+ hintingContractsDB.createCheckpoint();
163
+ } else {
164
+ // Unchecked/unknown error - re-throw as-is
165
+ throw e;
128
166
  }
167
+ }
129
168
 
130
- try {
131
- if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
132
- const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
133
- processedPhases.push(teardownResult);
134
- if (teardownResult.reverted) {
135
- throw new Error(`Teardown phase reverted! ${teardownResult.revertReason?.message}`);
136
- }
169
+ try {
170
+ if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
171
+ const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
172
+ processedPhases.push(teardownResult);
173
+ if (teardownResult.reverted) {
174
+ throw new TxSimTeardownRevert();
137
175
  }
138
-
139
- // We commit the forked state and we are done.
140
- await context.state.mergeForkedState();
141
- } catch (e) {
142
- this.log.debug(String(e));
143
- // We rollback to the post-setup state.
176
+ }
177
+ // We commit the forked state and we are done.
178
+ await context.state.mergeForkedState();
179
+ hintingContractsDB.commitCheckpoint();
180
+ } catch (e: any) {
181
+ if (e instanceof TxSimTeardownRevert) {
182
+ // We revert to the post-setup state and we are done.
144
183
  await context.state.discardForkedState();
184
+ hintingContractsDB.revertCheckpoint();
185
+ } else {
186
+ // Unchecked/unknown error - re-throw as-is
187
+ throw e;
145
188
  }
189
+ }
146
190
 
147
- context.halt();
191
+ context.halt();
148
192
 
149
- if (context.getActualGasUsed().l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
150
- throw new Error(
151
- `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`,
152
- );
153
- }
154
- await this.payFee(context);
155
-
156
- const publicInputs = await context.generateAvmCircuitPublicInputs();
157
- const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, hints);
158
-
159
- const revertCode = context.getFinalRevertCode();
160
-
161
- // Commit contracts from this TX to the block-level cache and clear tx cache
162
- // If the tx reverted, only commit non-revertible contracts
163
- // NOTE: You can't create contracts in public, so this is only relevant for private-created contracts
164
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
165
- // However things should work as they are now because the hinted db would still pick up the new contracts.
166
- this.contractsDB.commitContractsForTx(/*onlyNonRevertibles=*/ !revertCode.isOK());
167
-
168
- return {
169
- avmProvingRequest,
170
- gasUsed: {
171
- totalGas: context.getActualGasUsed(),
172
- teardownGas: context.teardownGasUsed,
173
- publicGas: context.getActualPublicGasUsed(),
174
- billedGas: context.getTotalGasUsed(),
175
- },
176
- revertCode,
177
- revertReason: context.revertReason,
178
- processedPhases: processedPhases,
179
- };
180
- } finally {
181
- // Make sure there are no new contracts in the tx-level cache.
182
- // They should either be committed to block-level cache or cleared.
183
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
184
- // However things should work as they are now because the hinted db would still pick up the new contracts.
185
- this.contractsDB.clearContractsForTx();
193
+ // Such transactions should be filtered by GasTxValidator.
194
+ assert(
195
+ context.getActualGasUsed().l2Gas <= AVM_MAX_PROCESSABLE_L2_GAS,
196
+ `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`,
197
+ );
198
+ await this.payFee(context);
199
+
200
+ const publicInputs = await context.generateAvmCircuitPublicInputs();
201
+ const revertCode = context.getFinalRevertCode();
202
+
203
+ // We only return the app logic phase information, and only 1 per phase.
204
+ const appLogicReturnValues: NestedProcessReturnValues[] =
205
+ processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
206
+
207
+ // TODO(fcarreiro): This is a temporary backwards compatibility layer until we migrate to the C++ simulator.
208
+ if (context.revertReason !== undefined) {
209
+ (appLogicReturnValues as any).revertReason = context.revertReason;
186
210
  }
211
+
212
+ // Create PublicTxEffect from PublicInputs.
213
+ const publicTxEffect = new PublicTxEffect(
214
+ publicInputs.transactionFee,
215
+ publicInputs.accumulatedData.noteHashes.filter(h => !h.isEmpty()),
216
+ publicInputs.accumulatedData.nullifiers.filter(n => !n.isEmpty()),
217
+ publicInputs.accumulatedData.l2ToL1Msgs.filter(m => !m.isEmpty()),
218
+ publicInputs.accumulatedData.publicLogs.toLogs(),
219
+ publicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()),
220
+ );
221
+
222
+ return new PublicTxResult(
223
+ /*gasUsed=*/ {
224
+ totalGas: context.getActualGasUsed(),
225
+ teardownGas: context.teardownGasUsed,
226
+ publicGas: context.getActualPublicGasUsed(),
227
+ billedGas: context.getTotalGasUsed(),
228
+ },
229
+ /*revertCode=*/ revertCode,
230
+ /*publicTxEffect=*/ publicTxEffect,
231
+ /*callStackMetadata=*/ appLogicReturnValues,
232
+ /*logs=*/ context.state.getActiveStateManager().getLogs(),
233
+ /*hints=*/ hints,
234
+ /*publicInputs=*/ publicInputs,
235
+ );
187
236
  }
188
237
 
189
238
  protected computeTxHash(tx: Tx) {
@@ -265,7 +314,7 @@ export class PublicTxSimulator {
265
314
  );
266
315
 
267
316
  if (result.reverted) {
268
- const culprit = `${contractAddress}:${callRequest.functionSelector}`;
317
+ const culprit = `${contractAddress}:${fnName}`;
269
318
  context.revert(phase, result.revertReason, culprit);
270
319
  }
271
320
 
@@ -308,7 +357,7 @@ export class PublicTxSimulator {
308
357
  request.isStaticCall,
309
358
  calldata,
310
359
  allocatedGas,
311
- this.clientInitiatedSimulation,
360
+ this.config,
312
361
  );
313
362
  const avmCallResult = await simulator.execute();
314
363
  return avmCallResult.finalize();
@@ -317,7 +366,7 @@ export class PublicTxSimulator {
317
366
  /**
318
367
  * Insert the non-revertible accumulated data from private into the public state.
319
368
  */
320
- protected async insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx) {
369
+ protected async insertNonRevertiblesFromPrivate(context: PublicTxContext) {
321
370
  const stateManager = context.state.getActiveStateManager();
322
371
 
323
372
  for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter(
@@ -336,58 +385,107 @@ export class PublicTxSimulator {
336
385
  }
337
386
  }
338
387
 
339
- // add new contracts to the contracts db so that their functions may be found and called
340
- // TODO(#6464): Should we allow emitting contracts in the private setup phase?
341
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
342
- // However things should work as they are now because the hinted db would still pick up the new contracts.
343
- await this.contractsDB.addNewNonRevertibleContracts(tx);
388
+ // add new contracts to the contracts db so that their code may be found and called
389
+ // FIXME(fcarreiro): this should conceptually use the hinting contracts db.
390
+ // However, things work as expected because later calls to getters on the hintingContractsDB
391
+ // will pick up the new contracts and will generate the necessary hints.
392
+ // So, a consumer of the hints will always see the new contracts.
393
+ await this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
344
394
  }
345
395
 
346
396
  /**
347
397
  * Insert the revertible accumulated data from private into the public state.
348
- * Start by forking state so we can rollback to the end of setup if app logic or teardown reverts.
398
+ * Throws TxSimRevertibleInsertionsRevert if there is some checked error during revertible insertions.
399
+ * This function checks for the following errors:
400
+ * - NullifierLimitReachedError
401
+ * - NullifierCollisionError
402
+ * - NoteHashLimitReachedError
403
+ * - L2ToL1MessageLimitReachedError
349
404
  */
350
- protected async insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): /*success=*/ Promise<boolean> {
405
+ protected async insertRevertiblesFromPrivate(context: PublicTxContext) {
351
406
  const stateManager = context.state.getActiveStateManager();
352
407
 
353
408
  try {
354
409
  for (const siloedNullifier of context.revertibleAccumulatedDataFromPrivate.nullifiers.filter(n => !n.isEmpty())) {
355
410
  await stateManager.writeSiloedNullifier(siloedNullifier);
356
411
  }
357
- } catch (e) {
358
- context.revert(
359
- TxExecutionPhase.APP_LOGIC,
360
- new SimulationError(
361
- `Nullifier collision encountered when inserting revertible nullifiers from private.\nDetails: ${String(e)}`,
362
- [],
363
- ),
364
- );
365
- throw e;
412
+ } catch (e: any) {
413
+ if (e instanceof NullifierLimitReachedError || e instanceof NullifierCollisionError) {
414
+ context.revert(
415
+ TxExecutionPhase.APP_LOGIC,
416
+ new SimulationError(
417
+ `Error encountered when inserting revertible nullifiers from private.\nDetails: ${e.message}`,
418
+ [],
419
+ ),
420
+ );
421
+ throw new TxSimRevertibleInsertionsRevert();
422
+ } else {
423
+ // Unchecked/unknown error - re-throw as-is
424
+ throw e;
425
+ }
366
426
  }
367
- for (const noteHash of context.revertibleAccumulatedDataFromPrivate.noteHashes) {
368
- if (!noteHash.isEmpty()) {
369
- // Revertible note hashes from private are not hashed with nonce, since private can't know their final position, only we can.
370
- await stateManager.writeSiloedNoteHash(noteHash);
427
+
428
+ try {
429
+ for (const noteHash of context.revertibleAccumulatedDataFromPrivate.noteHashes) {
430
+ if (!noteHash.isEmpty()) {
431
+ // Revertible note hashes from private are not hashed with nonce, since private can't know their final position, only we can.
432
+ await stateManager.writeSiloedNoteHash(noteHash);
433
+ }
434
+ }
435
+ } catch (e: any) {
436
+ if (e instanceof NoteHashLimitReachedError) {
437
+ context.revert(
438
+ TxExecutionPhase.APP_LOGIC,
439
+ new SimulationError(
440
+ `Error encountered when inserting revertible note hashes from private.\nDetails: ${e.message}`,
441
+ [],
442
+ ),
443
+ );
444
+ throw new TxSimRevertibleInsertionsRevert();
445
+ } else {
446
+ // Unchecked/unknown error - re-throw as-is
447
+ throw e;
371
448
  }
372
449
  }
373
- for (const l2ToL1Message of context.revertibleAccumulatedDataFromPrivate.l2ToL1Msgs) {
374
- if (!l2ToL1Message.isEmpty()) {
375
- stateManager.writeScopedL2ToL1Message(l2ToL1Message);
450
+
451
+ try {
452
+ for (const l2ToL1Message of context.revertibleAccumulatedDataFromPrivate.l2ToL1Msgs) {
453
+ if (!l2ToL1Message.isEmpty()) {
454
+ stateManager.writeScopedL2ToL1Message(l2ToL1Message);
455
+ }
456
+ }
457
+ } catch (e: any) {
458
+ if (e instanceof L2ToL1MessageLimitReachedError) {
459
+ context.revert(
460
+ TxExecutionPhase.APP_LOGIC,
461
+ new SimulationError(
462
+ `Error encountered when inserting revertible L2-to-L1 messages from private.\nDetails: ${e.message}`,
463
+ [],
464
+ ),
465
+ );
466
+ throw new TxSimRevertibleInsertionsRevert();
467
+ } else {
468
+ // Unchecked/unknown error - re-throw as-is
469
+ throw e;
376
470
  }
377
471
  }
378
- // add new contracts to the contracts db so that their functions may be found and called
379
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
380
- // However things should work as they are now because the hinted db would still pick up the new contracts.
381
- await this.contractsDB.addNewRevertibleContracts(tx);
382
472
 
383
- return /*success=*/ true;
473
+ // add new contracts to the contracts db so that their functions may be found and called
474
+ // FIXME(fcarreiro): this should conceptually use the hinting contracts db.
475
+ // However, things work as expected because later calls to getters on the hintingContractsDB
476
+ // will pick up the new contracts and will generate the necessary hints.
477
+ // So, a consumer of the hints will always see the new contracts.
478
+ await this.contractsDB.addContracts(context.revertibleContractDeploymentData);
384
479
  }
385
480
 
386
481
  private async payFee(context: PublicTxContext) {
387
482
  const txFee = context.getTransactionFee(TxExecutionPhase.TEARDOWN);
388
483
 
389
484
  if (context.feePayer.isZero()) {
390
- this.log.debug(`No one is paying the fee of ${txFee.toBigInt()}`);
485
+ // Real transactions are enforced by private kernel to have nonzero fee payer.
486
+ // Real transactions cannot skip fee enforcement (skipping fee enforcement makes them unprovable).
487
+ assert(this.config.skipFeeEnforcement, 'Fee payer cannot be 0 unless skipping fee enforcement for simulation');
488
+ this.log.debug(`Fee payer is 0. Skipping fee enforcement. No one is paying the fee of ${txFee.toBigInt()}`);
391
489
  return;
392
490
  }
393
491
 
@@ -402,29 +500,17 @@ export class PublicTxSimulator {
402
500
  // When mocking the balance of the fee payer, the circuit should not be able to prove the simulation
403
501
 
404
502
  if (currentBalance.lt(txFee)) {
405
- if (!this.skipFeeEnforcement) {
406
- throw new Error(
407
- `Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
408
- );
409
- } else {
410
- currentBalance = txFee;
411
- }
503
+ // Without "skipFeeEnforcement", such transactions should be filtered by GasTxValidator.
504
+ assert(
505
+ this.config.skipFeeEnforcement,
506
+ `Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
507
+ );
508
+ this.log.debug(`Fee payer balance insufficient, but we're skipping fee enforcement`);
509
+ // We still proceed and perform the storage write to minimize deviation from normal execution.
510
+ currentBalance = txFee;
412
511
  }
413
512
 
414
513
  const updatedBalance = currentBalance.sub(txFee);
415
514
  await stateManager.writeStorage(feeJuiceAddress, balanceSlot, updatedBalance, true);
416
515
  }
417
-
418
- /**
419
- * Generate the proving request for the AVM circuit.
420
- */
421
- private static generateProvingRequest(
422
- publicInputs: AvmCircuitPublicInputs,
423
- hints: AvmExecutionHints,
424
- ): AvmProvingRequest {
425
- return {
426
- type: ProvingRequestType.PUBLIC_VM,
427
- inputs: new AvmCircuitInputs(hints, publicInputs),
428
- };
429
- }
430
516
  }
@@ -0,0 +1,33 @@
1
+ import type { PublicTxResult } from '@aztec/stdlib/avm';
2
+ import type { Tx } from '@aztec/stdlib/tx';
3
+
4
+ export interface PublicTxSimulatorInterface {
5
+ simulate(tx: Tx): Promise<PublicTxResult>;
6
+ /**
7
+ * Cancel the current simulation if one is in progress.
8
+ * This signals the underlying simulator (e.g., C++) to stop at the next safe point.
9
+ * Safe to call even if no simulation is in progress.
10
+ * Optional - not all implementations support cancellation.
11
+ *
12
+ * @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
13
+ * This is important because signaling cancellation doesn't immediately stop C++ -
14
+ * it only sets a flag that C++ checks at certain points. If C++ is in the middle
15
+ * of a slow operation (e.g., pad_trees), it won't stop until that completes.
16
+ * @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
17
+ */
18
+ cancel?(waitTimeoutMs?: number): Promise<void>;
19
+ }
20
+
21
+ export interface MeasuredPublicTxSimulatorInterface {
22
+ simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
23
+ /**
24
+ * Cancel the current simulation if one is in progress.
25
+ * This signals the underlying simulator (e.g., C++) to stop at the next safe point.
26
+ * Safe to call even if no simulation is in progress.
27
+ * Optional - not all implementations support cancellation.
28
+ *
29
+ * @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
30
+ * @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
31
+ */
32
+ cancel?(waitTimeoutMs?: number): Promise<void>;
33
+ }
@@ -1,4 +1,5 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
+ import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
2
3
  import type { Gas } from '@aztec/stdlib/gas';
3
4
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
4
5
  import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
@@ -22,21 +23,11 @@ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
22
23
  merkleTree: MerkleTreeWriteOperations,
23
24
  contractsDB: PublicContractsDB,
24
25
  globalVariables: GlobalVariables,
25
- doMerkleOperations: boolean = false,
26
- skipFeeEnforcement: boolean = false,
27
- clientInitiatedSimulation: boolean = false,
28
26
  telemetryClient: TelemetryClient = getTelemetryClient(),
27
+ config?: Partial<PublicSimulatorConfig>,
29
28
  ) {
30
29
  const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
31
- super(
32
- merkleTree,
33
- contractsDB,
34
- globalVariables,
35
- doMerkleOperations,
36
- skipFeeEnforcement,
37
- clientInitiatedSimulation,
38
- metrics,
39
- );
30
+ super(merkleTree, contractsDB, globalVariables, metrics, config);
40
31
  this.tracer = metrics.tracer;
41
32
  }
42
33