@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,131 +1,160 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
4
4
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
5
- import { AvmCircuitInputs, AvmExecutionHints, AvmTxHint } from '@aztec/stdlib/avm';
5
+ import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
6
6
  import { SimulationError } from '@aztec/stdlib/errors';
7
- import { ProvingRequestType } from '@aztec/stdlib/proofs';
8
7
  import { NestedProcessReturnValues, TxExecutionPhase } from '@aztec/stdlib/tx';
8
+ import { strict as assert } from 'assert';
9
+ import { CallDataArray } from '../avm/calldata.js';
9
10
  import { AvmSimulator } from '../avm/index.js';
10
11
  import { getPublicFunctionDebugName } from '../debug_fn_name.js';
11
12
  import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
12
13
  import { PublicTreesDB } from '../public_db_sources.js';
14
+ import { L2ToL1MessageLimitReachedError, NoteHashLimitReachedError, NullifierCollisionError, NullifierLimitReachedError } from '../side_effect_errors.js';
13
15
  import { PublicTxContext } from './public_tx_context.js';
16
+ // The errors below are only thrown here in the public tx simulator,
17
+ // and only during revertible phases (revertible insertions, app logic and teardown).
18
+ // These are strictly "checked" errors (not exported and never propagated).
19
+ // They are used internally for control flow to trigger rollbacks to the post-setup state.
20
+ /**
21
+ * Error thrown when public tx simulation reverts in a known/checked way during revertible insertions.
22
+ */ class TxSimRevertibleInsertionsRevert extends Error {
23
+ constructor(){
24
+ super('Public Tx Simulation reverted during Revertible Insertions');
25
+ this.name = 'TxSimRevertibleInsertionsRevert';
26
+ }
27
+ }
28
+ /**
29
+ * Error thrown when public tx simulation reverts during app logic.
30
+ */ class TxSimAppLogicRevert extends Error {
31
+ constructor(){
32
+ super('Public Tx Simulation reverted during App Logic');
33
+ this.name = 'TxSimAppLogicRevert';
34
+ }
35
+ }
36
+ /**
37
+ * Error thrown when public tx simulation reverts during teardown.
38
+ */ class TxSimTeardownRevert extends Error {
39
+ constructor(){
40
+ super('Public Tx Simulation reverted during Teardown');
41
+ this.name = 'TxSimTeardownRevert';
42
+ }
43
+ }
14
44
  export class PublicTxSimulator {
15
45
  merkleTree;
16
46
  contractsDB;
17
47
  globalVariables;
18
- doMerkleOperations;
19
- skipFeeEnforcement;
20
- clientInitiatedSimulation;
48
+ protocolContracts;
21
49
  log;
22
- constructor(merkleTree, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, clientInitiatedSimulation = false){
50
+ config;
51
+ bindings;
52
+ constructor(merkleTree, contractsDB, globalVariables, config, protocolContracts = ProtocolContractsList, bindings){
23
53
  this.merkleTree = merkleTree;
24
54
  this.contractsDB = contractsDB;
25
55
  this.globalVariables = globalVariables;
26
- this.doMerkleOperations = doMerkleOperations;
27
- this.skipFeeEnforcement = skipFeeEnforcement;
28
- this.clientInitiatedSimulation = clientInitiatedSimulation;
29
- this.log = createLogger(`simulator:public_tx_simulator`);
56
+ this.protocolContracts = protocolContracts;
57
+ this.config = PublicSimulatorConfig.from(config ?? {});
58
+ this.bindings = bindings;
59
+ this.log = createLogger(`simulator:public_tx_simulator`, bindings);
30
60
  }
31
61
  /**
32
62
  * Simulate a transaction's public portion including all of its phases.
33
63
  * @param tx - The transaction to simulate.
34
64
  * @returns The result of the transaction's public execution.
35
65
  */ async simulate(tx) {
36
- try {
37
- const txHash = this.computeTxHash(tx);
38
- this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
39
- txHash
40
- });
41
- // Create hinting DBs.
42
- const hints = new AvmExecutionHints(this.globalVariables, AvmTxHint.fromTx(tx, this.globalVariables.gasFees));
43
- const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
44
- const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
45
- const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
46
- const context = await PublicTxContext.create(hintingTreesDB, hintingContractsDB, tx, this.globalVariables, this.doMerkleOperations);
47
- // This will throw if there is a nullifier collision.
66
+ const txHash = this.computeTxHash(tx);
67
+ this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
68
+ txHash
69
+ });
70
+ // Create hinting DBs.
71
+ const hints = new AvmExecutionHints(this.globalVariables, AvmTxHint.fromTx(tx, this.globalVariables.gasFees), this.protocolContracts);
72
+ const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
73
+ const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
74
+ const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
75
+ const context = await PublicTxContext.create(hintingTreesDB, hintingContractsDB, tx, this.globalVariables, this.protocolContracts, this.config.proverId, this.bindings);
76
+ // This will throw if there is a nullifier collision.
77
+ // In that case the transaction will be thrown out.
78
+ await this.insertNonRevertiblesFromPrivate(context);
79
+ const processedPhases = [];
80
+ if (context.hasPhase(TxExecutionPhase.SETUP)) {
81
+ // This will throw if the setup phase reverts.
48
82
  // In that case the transaction will be thrown out.
49
- await this.insertNonRevertiblesFromPrivate(context, tx);
50
- const processedPhases = [];
51
- if (context.hasPhase(TxExecutionPhase.SETUP)) {
52
- // This will throw if the setup phase reverts.
53
- // In that case the transaction will be thrown out.
54
- const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
55
- if (setupResult.reverted) {
56
- throw new Error(`Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`);
57
- }
58
- processedPhases.push(setupResult);
83
+ const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
84
+ if (setupResult.reverted) {
85
+ throw new Error(`[SETUP] UNRECOVERABLE ERROR! The transaction will be thrown out. ${setupResult.revertReason?.message}`);
59
86
  }
60
- // The checkpoint we should go back to if anything from now on reverts.
61
- await context.state.fork();
62
- try {
63
- // This will throw if there is a nullifier collision.
64
- await this.insertRevertiblesFromPrivate(context, tx);
65
- // Only proceed with app logic if there was no revert during revertible insertion.
66
- if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
67
- const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
68
- processedPhases.push(appLogicResult);
69
- if (appLogicResult.reverted) {
70
- throw new Error(`App logic phase reverted! ${appLogicResult.revertReason?.message}`);
71
- }
87
+ processedPhases.push(setupResult);
88
+ }
89
+ // The checkpoint we should go back to if anything from now on reverts.
90
+ await context.state.fork();
91
+ hintingContractsDB.createCheckpoint();
92
+ try {
93
+ // This will throw if there is a nullifier collision or other insertion error (limit reached).
94
+ await this.insertRevertiblesFromPrivate(context);
95
+ // Only proceed with app logic if there was no revert during revertible insertion.
96
+ if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
97
+ const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
98
+ processedPhases.push(appLogicResult);
99
+ if (appLogicResult.reverted) {
100
+ throw new TxSimAppLogicRevert();
72
101
  }
73
- } catch (e) {
74
- this.log.debug(String(e));
102
+ }
103
+ } catch (e) {
104
+ if (e instanceof TxSimRevertibleInsertionsRevert || e instanceof TxSimAppLogicRevert) {
75
105
  // We revert to the post-setup state.
76
106
  await context.state.discardForkedState();
107
+ hintingContractsDB.revertCheckpoint();
77
108
  // But we also create a new fork so that the teardown phase can transparently
78
109
  // commit or rollback at the end of teardown.
79
110
  await context.state.fork();
111
+ hintingContractsDB.createCheckpoint();
112
+ } else {
113
+ // Unchecked/unknown error - re-throw as-is
114
+ throw e;
80
115
  }
81
- try {
82
- if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
83
- const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
84
- processedPhases.push(teardownResult);
85
- if (teardownResult.reverted) {
86
- throw new Error(`Teardown phase reverted! ${teardownResult.revertReason?.message}`);
87
- }
116
+ }
117
+ try {
118
+ if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
119
+ const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
120
+ processedPhases.push(teardownResult);
121
+ if (teardownResult.reverted) {
122
+ throw new TxSimTeardownRevert();
88
123
  }
89
- // We commit the forked state and we are done.
90
- await context.state.mergeForkedState();
91
- } catch (e) {
92
- this.log.debug(String(e));
93
- // We rollback to the post-setup state.
94
- await context.state.discardForkedState();
95
124
  }
96
- context.halt();
97
- if (context.getActualGasUsed().l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
98
- throw new Error(`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`);
125
+ // We commit the forked state and we are done.
126
+ await context.state.mergeForkedState();
127
+ hintingContractsDB.commitCheckpoint();
128
+ } catch (e) {
129
+ if (e instanceof TxSimTeardownRevert) {
130
+ // We revert to the post-setup state and we are done.
131
+ await context.state.discardForkedState();
132
+ hintingContractsDB.revertCheckpoint();
133
+ } else {
134
+ // Unchecked/unknown error - re-throw as-is
135
+ throw e;
99
136
  }
100
- await this.payFee(context);
101
- const publicInputs = await context.generateAvmCircuitPublicInputs();
102
- const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, hints);
103
- const revertCode = context.getFinalRevertCode();
104
- // Commit contracts from this TX to the block-level cache and clear tx cache
105
- // If the tx reverted, only commit non-revertible contracts
106
- // NOTE: You can't create contracts in public, so this is only relevant for private-created contracts
107
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
108
- // However things should work as they are now because the hinted db would still pick up the new contracts.
109
- this.contractsDB.commitContractsForTx(/*onlyNonRevertibles=*/ !revertCode.isOK());
110
- return {
111
- avmProvingRequest,
112
- gasUsed: {
113
- totalGas: context.getActualGasUsed(),
114
- teardownGas: context.teardownGasUsed,
115
- publicGas: context.getActualPublicGasUsed(),
116
- billedGas: context.getTotalGasUsed()
117
- },
118
- revertCode,
119
- revertReason: context.revertReason,
120
- processedPhases: processedPhases
121
- };
122
- } finally{
123
- // Make sure there are no new contracts in the tx-level cache.
124
- // They should either be committed to block-level cache or cleared.
125
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
126
- // However things should work as they are now because the hinted db would still pick up the new contracts.
127
- this.contractsDB.clearContractsForTx();
128
137
  }
138
+ context.halt();
139
+ // Such transactions should be filtered by GasTxValidator.
140
+ assert(context.getActualGasUsed().l2Gas <= AVM_MAX_PROCESSABLE_L2_GAS, `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`);
141
+ await this.payFee(context);
142
+ const publicInputs = await context.generateAvmCircuitPublicInputs();
143
+ const revertCode = context.getFinalRevertCode();
144
+ // We only return the app logic phase information, and only 1 per phase.
145
+ const appLogicReturnValues = processedPhases.find(({ phase })=>phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
146
+ // TODO(fcarreiro): This is a temporary backwards compatibility layer until we migrate to the C++ simulator.
147
+ if (context.revertReason !== undefined) {
148
+ appLogicReturnValues.revertReason = context.revertReason;
149
+ }
150
+ // Create PublicTxEffect from PublicInputs.
151
+ const publicTxEffect = new PublicTxEffect(publicInputs.transactionFee, publicInputs.accumulatedData.noteHashes.filter((h)=>!h.isEmpty()), publicInputs.accumulatedData.nullifiers.filter((n)=>!n.isEmpty()), publicInputs.accumulatedData.l2ToL1Msgs.filter((m)=>!m.isEmpty()), publicInputs.accumulatedData.publicLogs.toLogs(), publicInputs.accumulatedData.publicDataWrites.filter((w)=>!w.isEmpty()));
152
+ return new PublicTxResult(/*gasUsed=*/ {
153
+ totalGas: context.getActualGasUsed(),
154
+ teardownGas: context.teardownGasUsed,
155
+ publicGas: context.getActualPublicGasUsed(),
156
+ billedGas: context.getTotalGasUsed()
157
+ }, /*revertCode=*/ revertCode, /*publicTxEffect=*/ publicTxEffect, /*callStackMetadata=*/ appLogicReturnValues, /*logs=*/ context.state.getActiveStateManager().getLogs(), /*hints=*/ hints, /*publicInputs=*/ publicInputs);
129
158
  }
130
159
  computeTxHash(tx) {
131
160
  return tx.getTxHash();
@@ -150,7 +179,7 @@ export class PublicTxSimulator {
150
179
  }
151
180
  const callRequest = callRequests[i];
152
181
  const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
153
- returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
182
+ returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
154
183
  if (enqueuedCallResult.reverted) {
155
184
  reverted = true;
156
185
  revertReason = enqueuedCallResult.revertReason;
@@ -172,14 +201,14 @@ export class PublicTxSimulator {
172
201
  */ async simulateEnqueuedCall(phase, context, callRequest) {
173
202
  const stateManager = context.state.getActiveStateManager();
174
203
  const contractAddress = callRequest.request.contractAddress;
175
- const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
204
+ const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, new CallDataArray(callRequest.calldata));
176
205
  const allocatedGas = context.getGasLeftAtPhase(phase);
177
206
  const result = await this.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, /*transactionFee=*/ context.getTransactionFee(phase), fnName);
178
207
  const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
179
208
  context.consumeGas(phase, gasUsed);
180
209
  this.log.debug(`Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`);
181
210
  if (result.reverted) {
182
- const culprit = `${contractAddress}:${callRequest.functionSelector}`;
211
+ const culprit = `${contractAddress}:${fnName}`;
183
212
  context.revert(phase, result.revertReason, culprit);
184
213
  }
185
214
  return result;
@@ -200,13 +229,13 @@ export class PublicTxSimulator {
200
229
  const address = request.contractAddress;
201
230
  const sender = request.msgSender;
202
231
  this.log.debug(`Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`);
203
- const simulator = await AvmSimulator.create(stateManager, address, sender, transactionFee, this.globalVariables, request.isStaticCall, calldata, allocatedGas, this.clientInitiatedSimulation);
232
+ const simulator = await AvmSimulator.create(stateManager, address, sender, transactionFee, this.globalVariables, request.isStaticCall, new CallDataArray(calldata), allocatedGas, this.config);
204
233
  const avmCallResult = await simulator.execute();
205
234
  return avmCallResult.finalize();
206
235
  }
207
236
  /**
208
237
  * Insert the non-revertible accumulated data from private into the public state.
209
- */ async insertNonRevertiblesFromPrivate(context, tx) {
238
+ */ async insertNonRevertiblesFromPrivate(context) {
210
239
  const stateManager = context.state.getActiveStateManager();
211
240
  for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
212
241
  await stateManager.writeSiloedNullifier(siloedNullifier);
@@ -221,46 +250,81 @@ export class PublicTxSimulator {
221
250
  stateManager.writeScopedL2ToL1Message(l2ToL1Message);
222
251
  }
223
252
  }
224
- // add new contracts to the contracts db so that their functions may be found and called
225
- // TODO(#6464): Should we allow emitting contracts in the private setup phase?
226
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
227
- // However things should work as they are now because the hinted db would still pick up the new contracts.
228
- await this.contractsDB.addNewNonRevertibleContracts(tx);
253
+ // add new contracts to the contracts db so that their code may be found and called
254
+ // FIXME(fcarreiro): this should conceptually use the hinting contracts db.
255
+ // However, things work as expected because later calls to getters on the hintingContractsDB
256
+ // will pick up the new contracts and will generate the necessary hints.
257
+ // So, a consumer of the hints will always see the new contracts.
258
+ await this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
229
259
  }
230
260
  /**
231
261
  * Insert the revertible accumulated data from private into the public state.
232
- * Start by forking state so we can rollback to the end of setup if app logic or teardown reverts.
233
- */ async insertRevertiblesFromPrivate(context, tx) {
262
+ * Throws TxSimRevertibleInsertionsRevert if there is some checked error during revertible insertions.
263
+ * This function checks for the following errors:
264
+ * - NullifierLimitReachedError
265
+ * - NullifierCollisionError
266
+ * - NoteHashLimitReachedError
267
+ * - L2ToL1MessageLimitReachedError
268
+ */ async insertRevertiblesFromPrivate(context) {
234
269
  const stateManager = context.state.getActiveStateManager();
235
270
  try {
236
271
  for (const siloedNullifier of context.revertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
237
272
  await stateManager.writeSiloedNullifier(siloedNullifier);
238
273
  }
239
274
  } catch (e) {
240
- context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Nullifier collision encountered when inserting revertible nullifiers from private.\nDetails: ${String(e)}`, []));
241
- throw e;
275
+ if (e instanceof NullifierLimitReachedError || e instanceof NullifierCollisionError) {
276
+ context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Error encountered when inserting revertible nullifiers from private.\nDetails: ${e.message}`, []));
277
+ throw new TxSimRevertibleInsertionsRevert();
278
+ } else {
279
+ // Unchecked/unknown error - re-throw as-is
280
+ throw e;
281
+ }
242
282
  }
243
- for (const noteHash of context.revertibleAccumulatedDataFromPrivate.noteHashes){
244
- if (!noteHash.isEmpty()) {
245
- // Revertible note hashes from private are not hashed with nonce, since private can't know their final position, only we can.
246
- await stateManager.writeSiloedNoteHash(noteHash);
283
+ try {
284
+ for (const noteHash of context.revertibleAccumulatedDataFromPrivate.noteHashes){
285
+ if (!noteHash.isEmpty()) {
286
+ // Revertible note hashes from private are not hashed with nonce, since private can't know their final position, only we can.
287
+ await stateManager.writeSiloedNoteHash(noteHash);
288
+ }
289
+ }
290
+ } catch (e) {
291
+ if (e instanceof NoteHashLimitReachedError) {
292
+ context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Error encountered when inserting revertible note hashes from private.\nDetails: ${e.message}`, []));
293
+ throw new TxSimRevertibleInsertionsRevert();
294
+ } else {
295
+ // Unchecked/unknown error - re-throw as-is
296
+ throw e;
247
297
  }
248
298
  }
249
- for (const l2ToL1Message of context.revertibleAccumulatedDataFromPrivate.l2ToL1Msgs){
250
- if (!l2ToL1Message.isEmpty()) {
251
- stateManager.writeScopedL2ToL1Message(l2ToL1Message);
299
+ try {
300
+ for (const l2ToL1Message of context.revertibleAccumulatedDataFromPrivate.l2ToL1Msgs){
301
+ if (!l2ToL1Message.isEmpty()) {
302
+ stateManager.writeScopedL2ToL1Message(l2ToL1Message);
303
+ }
304
+ }
305
+ } catch (e) {
306
+ if (e instanceof L2ToL1MessageLimitReachedError) {
307
+ context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Error encountered when inserting revertible L2-to-L1 messages from private.\nDetails: ${e.message}`, []));
308
+ throw new TxSimRevertibleInsertionsRevert();
309
+ } else {
310
+ // Unchecked/unknown error - re-throw as-is
311
+ throw e;
252
312
  }
253
313
  }
254
314
  // add new contracts to the contracts db so that their functions may be found and called
255
- // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
256
- // However things should work as they are now because the hinted db would still pick up the new contracts.
257
- await this.contractsDB.addNewRevertibleContracts(tx);
258
- return /*success=*/ true;
315
+ // FIXME(fcarreiro): this should conceptually use the hinting contracts db.
316
+ // However, things work as expected because later calls to getters on the hintingContractsDB
317
+ // will pick up the new contracts and will generate the necessary hints.
318
+ // So, a consumer of the hints will always see the new contracts.
319
+ await this.contractsDB.addContracts(context.revertibleContractDeploymentData);
259
320
  }
260
321
  async payFee(context) {
261
322
  const txFee = context.getTransactionFee(TxExecutionPhase.TEARDOWN);
262
323
  if (context.feePayer.isZero()) {
263
- this.log.debug(`No one is paying the fee of ${txFee.toBigInt()}`);
324
+ // Real transactions are enforced by private kernel to have nonzero fee payer.
325
+ // Real transactions cannot skip fee enforcement (skipping fee enforcement makes them unprovable).
326
+ assert(this.config.skipFeeEnforcement, 'Fee payer cannot be 0 unless skipping fee enforcement for simulation');
327
+ this.log.debug(`Fee payer is 0. Skipping fee enforcement. No one is paying the fee of ${txFee.toBigInt()}`);
264
328
  return;
265
329
  }
266
330
  const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
@@ -271,21 +335,13 @@ export class PublicTxSimulator {
271
335
  // We allow to fake the balance of the fee payer to allow fee estimation
272
336
  // When mocking the balance of the fee payer, the circuit should not be able to prove the simulation
273
337
  if (currentBalance.lt(txFee)) {
274
- if (!this.skipFeeEnforcement) {
275
- throw new Error(`Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`);
276
- } else {
277
- currentBalance = txFee;
278
- }
338
+ // Without "skipFeeEnforcement", such transactions should be filtered by GasTxValidator.
339
+ assert(this.config.skipFeeEnforcement, `Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`);
340
+ this.log.debug(`Fee payer balance insufficient, but we're skipping fee enforcement`);
341
+ // We still proceed and perform the storage write to minimize deviation from normal execution.
342
+ currentBalance = txFee;
279
343
  }
280
344
  const updatedBalance = currentBalance.sub(txFee);
281
345
  await stateManager.writeStorage(feeJuiceAddress, balanceSlot, updatedBalance, true);
282
346
  }
283
- /**
284
- * Generate the proving request for the AVM circuit.
285
- */ static generateProvingRequest(publicInputs, hints) {
286
- return {
287
- type: ProvingRequestType.PUBLIC_VM,
288
- inputs: new AvmCircuitInputs(hints, publicInputs)
289
- };
290
- }
291
347
  }
@@ -0,0 +1,32 @@
1
+ import type { PublicTxResult } from '@aztec/stdlib/avm';
2
+ import type { Tx } from '@aztec/stdlib/tx';
3
+ export interface PublicTxSimulatorInterface {
4
+ simulate(tx: Tx): Promise<PublicTxResult>;
5
+ /**
6
+ * Cancel the current simulation if one is in progress.
7
+ * This signals the underlying simulator (e.g., C++) to stop at the next safe point.
8
+ * Safe to call even if no simulation is in progress.
9
+ * Optional - not all implementations support cancellation.
10
+ *
11
+ * @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
12
+ * This is important because signaling cancellation doesn't immediately stop C++ -
13
+ * it only sets a flag that C++ checks at certain points. If C++ is in the middle
14
+ * of a slow operation (e.g., pad_trees), it won't stop until that completes.
15
+ * @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
16
+ */
17
+ cancel?(waitTimeoutMs?: number): Promise<void>;
18
+ }
19
+ export interface MeasuredPublicTxSimulatorInterface {
20
+ simulate(tx: Tx, txLabel: string): Promise<PublicTxResult>;
21
+ /**
22
+ * Cancel the current simulation if one is in progress.
23
+ * This signals the underlying simulator (e.g., C++) to stop at the next safe point.
24
+ * Safe to call even if no simulation is in progress.
25
+ * Optional - not all implementations support cancellation.
26
+ *
27
+ * @param waitTimeoutMs - If provided, wait up to this many ms for the simulation to actually stop.
28
+ * @returns Promise that resolves when cancellation is signaled (and optionally when simulation stops)
29
+ */
30
+ cancel?(waitTimeoutMs?: number): Promise<void>;
31
+ }
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX3R4X3NpbXVsYXRvcl9pbnRlcmZhY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaWMvcHVibGljX3R4X3NpbXVsYXRvci9wdWJsaWNfdHhfc2ltdWxhdG9yX2ludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RCxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUUzQyxNQUFNLFdBQVcsMEJBQTBCO0lBQ3pDLFFBQVEsQ0FBQyxFQUFFLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUMsQ0FBQztJQUMxQzs7Ozs7Ozs7Ozs7T0FXRztJQUNILE1BQU0sQ0FBQyxDQUFDLGFBQWEsQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDaEQ7QUFFRCxNQUFNLFdBQVcsa0NBQWtDO0lBQ2pELFFBQVEsQ0FBQyxFQUFFLEVBQUUsRUFBRSxFQUFFLE9BQU8sRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLGNBQWMsQ0FBQyxDQUFDO0lBQzNEOzs7Ozs7OztPQVFHO0lBQ0gsTUFBTSxDQUFDLENBQUMsYUFBYSxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztDQUNoRCJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public_tx_simulator_interface.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1C;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3D;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
@@ -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';
@@ -13,8 +14,8 @@ import { PublicTxContext } from './public_tx_context.js';
13
14
  */
14
15
  export declare class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
15
16
  readonly tracer: Tracer;
16
- constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, clientInitiatedSimulation?: boolean, telemetryClient?: TelemetryClient);
17
+ constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, telemetryClient?: TelemetryClient, config?: Partial<PublicSimulatorConfig>);
17
18
  protected simulateEnqueuedCall(phase: TxExecutionPhase, context: PublicTxContext, callRequest: PublicCallRequestWithCalldata): Promise<AvmFinalizedCallResult>;
18
19
  protected simulateEnqueuedCallInternal(stateManager: PublicPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
19
20
  }
20
- //# sourceMappingURL=telemetry_public_tx_simulator.d.ts.map
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVsZW1ldHJ5X3B1YmxpY190eF9zaW11bGF0b3IuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaWMvcHVibGljX3R4X3NpbXVsYXRvci90ZWxlbWV0cnlfcHVibGljX3R4X3NpbXVsYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxxQkFBcUIsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQy9ELE9BQU8sS0FBSyxFQUFFLEdBQUcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQzdDLE9BQU8sS0FBSyxFQUFFLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDckUsT0FBTyxFQUFFLEtBQUssZUFBZSxFQUFFLDZCQUE2QixFQUFFLGdCQUFnQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDekcsT0FBTyxFQUFjLEtBQUssZUFBZSxFQUFFLEtBQUssTUFBTSxFQUFpQyxNQUFNLHlCQUF5QixDQUFDO0FBRXZILE9BQU8sS0FBSyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sb0NBQW9DLENBQUM7QUFFakYsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSw2QkFBNkIsRUFBRSxNQUFNLG1DQUFtQyxDQUFDO0FBQ3ZGLE9BQU8sRUFBRSx5QkFBeUIsRUFBRSxNQUFNLG1DQUFtQyxDQUFDO0FBQzlFLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUV6RDs7R0FFRztBQUNILHFCQUFhLDBCQUEyQixTQUFRLHlCQUF5QjtJQUV2RSxTQUFnQixNQUFNLEVBQUUsTUFBTSxDQUFDO0lBRS9CLFlBQ0UsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxXQUFXLEVBQUUsaUJBQWlCLEVBQzlCLGVBQWUsRUFBRSxlQUFlLEVBQ2hDLGVBQWUsR0FBRSxlQUFzQyxFQUN2RCxNQUFNLENBQUMsRUFBRSxPQUFPLENBQUMscUJBQXFCLENBQUMsRUFLeEM7SUFFRCxVQU15QixvQkFBb0IsQ0FDM0MsS0FBSyxFQUFFLGdCQUFnQixFQUN2QixPQUFPLEVBQUUsZUFBZSxFQUN4QixXQUFXLEVBQUUsNkJBQTZCLEdBQ3pDLE9BQU8sQ0FBQyxzQkFBc0IsQ0FBQyxDQUVqQztJQUVELFVBTXlCLDRCQUE0QixDQUNuRCxZQUFZLEVBQUUsNkJBQTZCLEVBQzNDLFdBQVcsRUFBRSw2QkFBNkIsRUFDMUMsWUFBWSxFQUFFLEdBQUcsRUFDakIsY0FBYyxFQUFFLEVBQUUsRUFDbEIsTUFBTSxFQUFFLE1BQU0sR0FDYixPQUFPLENBQUMsc0JBQXNCLENBQUMsQ0FFakM7Q0FDRiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/telemetry_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,yBAAyB;IAEvE,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAG7B,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,OAAe,EACnC,kBAAkB,GAAE,OAAe,EACnC,yBAAyB,GAAE,OAAe,EAC1C,eAAe,GAAE,eAAsC;cAqBhC,oBAAoB,CAC3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;cAUT,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAGnC"}
1
+ {"version":3,"file":"telemetry_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/telemetry_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,yBAAyB;IAEvE,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,YACE,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,eAAe,GAAE,eAAsC,EACvD,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,EAKxC;IAED,UAMyB,oBAAoB,CAC3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC,CAEjC;IAED,UAMyB,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC,CAEjC;CACF"}