@aztec/simulator 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9

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