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

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 (380) 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 +5 -3
  20. package/dest/private/acvm_native.d.ts.map +1 -1
  21. package/dest/private/acvm_native.js +8 -6
  22. package/dest/private/acvm_wasm.d.ts +4 -3
  23. package/dest/private/acvm_wasm.d.ts.map +1 -1
  24. package/dest/private/acvm_wasm.js +7 -5
  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 +23 -20
  30. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  31. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  32. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  33. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  34. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  35. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  36. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  37. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  38. package/dest/private/circuit_simulator.d.ts +1 -1
  39. package/dest/private/factory.d.ts +3 -3
  40. package/dest/private/factory.d.ts.map +1 -1
  41. package/dest/private/factory.js +7 -4
  42. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  43. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  44. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  45. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +3 -2
  46. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  47. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
  48. package/dest/public/avm/{fixtures → testing}/utils.d.ts +4 -10
  49. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  50. package/dest/public/avm/{fixtures → testing}/utils.js +6 -35
  51. package/dest/public/contracts_db_checkpoint.d.ts +16 -0
  52. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
  53. package/dest/public/contracts_db_checkpoint.js +30 -0
  54. package/dest/public/db_interfaces.d.ts +14 -2
  55. package/dest/public/db_interfaces.d.ts.map +1 -1
  56. package/dest/public/executor_metrics.d.ts +3 -2
  57. package/dest/public/executor_metrics.d.ts.map +1 -1
  58. package/dest/public/executor_metrics.js +13 -34
  59. package/dest/public/executor_metrics_interface.d.ts +3 -2
  60. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  61. package/dest/public/fixtures/amm_test.d.ts +1 -1
  62. package/dest/public/fixtures/amm_test.js +4 -4
  63. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  64. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  65. package/dest/public/fixtures/bulk_test.js +36 -73
  66. package/dest/public/fixtures/custom_bytecode_tester.d.ts +29 -7
  67. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  68. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  69. package/dest/public/fixtures/index.d.ts +2 -3
  70. package/dest/public/fixtures/index.d.ts.map +1 -1
  71. package/dest/public/fixtures/index.js +1 -2
  72. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +30 -11
  73. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  74. package/dest/public/fixtures/public_tx_simulation_tester.js +98 -31
  75. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  76. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  77. package/dest/public/fixtures/simple_contract_data_source.js +5 -5
  78. package/dest/public/fixtures/token_test.d.ts +6 -2
  79. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  80. package/dest/public/fixtures/token_test.js +13 -12
  81. package/dest/public/fixtures/utils.d.ts +3 -3
  82. package/dest/public/fixtures/utils.d.ts.map +1 -1
  83. package/dest/public/fixtures/utils.js +23 -23
  84. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +62 -0
  85. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  86. package/dest/public/fuzzing/avm_fuzzer_simulator.js +176 -0
  87. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  88. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  89. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  90. package/dest/public/index.d.ts +3 -2
  91. package/dest/public/index.d.ts.map +1 -1
  92. package/dest/public/index.js +1 -1
  93. package/dest/public/public_db_sources.d.ts +29 -66
  94. package/dest/public/public_db_sources.d.ts.map +1 -1
  95. package/dest/public/public_db_sources.js +83 -134
  96. package/dest/public/public_errors.d.ts +1 -1
  97. package/dest/public/public_errors.d.ts.map +1 -1
  98. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -5
  99. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  100. package/dest/public/public_processor/guarded_merkle_tree.js +12 -4
  101. package/dest/public/public_processor/public_processor.d.ts +19 -21
  102. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  103. package/dest/public/public_processor/public_processor.js +553 -123
  104. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  105. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  106. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  107. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +19 -0
  108. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -0
  109. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +99 -0
  110. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +23 -0
  111. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  112. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +52 -0
  113. package/dest/public/public_tx_simulator/factories.d.ts +14 -0
  114. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  115. package/dest/public/public_tx_simulator/factories.js +28 -0
  116. package/dest/public/public_tx_simulator/index.d.ts +5 -3
  117. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  118. package/dest/public/public_tx_simulator/index.js +3 -2
  119. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +42 -89
  120. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  121. package/dest/public/public_tx_simulator/public_tx_simulator.js +101 -334
  122. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +22 -0
  123. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  124. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +28 -0
  125. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +25 -2
  126. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  127. package/dest/public/side_effect_errors.d.ts +1 -1
  128. package/dest/public/side_effect_errors.d.ts.map +1 -1
  129. package/dest/public/test_executor_metrics.d.ts +11 -4
  130. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  131. package/dest/public/test_executor_metrics.js +29 -6
  132. package/dest/public/unique_class_ids.d.ts +1 -1
  133. package/dest/public/unique_class_ids.d.ts.map +1 -1
  134. package/dest/public/utils.d.ts +1 -1
  135. package/dest/server.d.ts +1 -1
  136. package/dest/testing.d.ts +1 -1
  137. package/package.json +22 -22
  138. package/src/common/errors.ts +1 -1
  139. package/src/private/acvm/acvm.ts +4 -3
  140. package/src/private/acvm/deserialize.ts +1 -1
  141. package/src/private/acvm/serialize.ts +1 -1
  142. package/src/private/acvm_native.ts +11 -5
  143. package/src/private/acvm_wasm.ts +11 -4
  144. package/src/private/circuit_recording/circuit_recorder.ts +24 -21
  145. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  146. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  147. package/src/private/factory.ts +7 -4
  148. package/src/public/avm/testing/account_proof.json +553 -0
  149. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  150. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
  151. package/src/public/avm/{fixtures → testing}/utils.ts +6 -41
  152. package/src/public/contracts_db_checkpoint.ts +41 -0
  153. package/src/public/db_interfaces.ts +16 -1
  154. package/src/public/executor_metrics.ts +11 -34
  155. package/src/public/executor_metrics_interface.ts +2 -1
  156. package/src/public/fixtures/amm_test.ts +4 -4
  157. package/src/public/fixtures/bulk_test.ts +38 -13
  158. package/src/public/fixtures/custom_bytecode_tester.ts +54 -20
  159. package/src/public/fixtures/index.ts +5 -2
  160. package/src/public/fixtures/public_tx_simulation_tester.ts +129 -27
  161. package/src/public/fixtures/simple_contract_data_source.ts +9 -10
  162. package/src/public/fixtures/token_test.ts +18 -10
  163. package/src/public/fixtures/utils.ts +28 -25
  164. package/src/public/fuzzing/avm_fuzzer_simulator.ts +285 -0
  165. package/src/public/fuzzing/avm_simulator_bin.ts +173 -0
  166. package/src/public/index.ts +4 -2
  167. package/src/public/public_db_sources.ts +112 -174
  168. package/src/public/public_processor/guarded_merkle_tree.ts +14 -6
  169. package/src/public/public_processor/public_processor.ts +225 -136
  170. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  171. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +125 -0
  172. package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +83 -0
  173. package/src/public/public_tx_simulator/factories.ts +44 -0
  174. package/src/public/public_tx_simulator/index.ts +4 -2
  175. package/src/public/public_tx_simulator/public_tx_simulator.ts +153 -500
  176. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +35 -0
  177. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +24 -2
  178. package/src/public/test_executor_metrics.ts +34 -8
  179. package/dest/public/avm/avm_context.d.ts +0 -41
  180. package/dest/public/avm/avm_context.d.ts.map +0 -1
  181. package/dest/public/avm/avm_context.js +0 -44
  182. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  183. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  184. package/dest/public/avm/avm_contract_call_result.js +0 -54
  185. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  186. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  187. package/dest/public/avm/avm_execution_environment.js +0 -36
  188. package/dest/public/avm/avm_gas.d.ts +0 -44
  189. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  190. package/dest/public/avm/avm_gas.js +0 -195
  191. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  192. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  193. package/dest/public/avm/avm_machine_state.js +0 -109
  194. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  195. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  196. package/dest/public/avm/avm_memory_types.js +0 -351
  197. package/dest/public/avm/avm_simulator.d.ts +0 -39
  198. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  199. package/dest/public/avm/avm_simulator.js +0 -190
  200. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  201. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  202. package/dest/public/avm/avm_simulator_interface.js +0 -3
  203. package/dest/public/avm/errors.d.ts +0 -98
  204. package/dest/public/avm/errors.d.ts.map +0 -1
  205. package/dest/public/avm/errors.js +0 -129
  206. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  207. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  208. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -74
  209. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  210. package/dest/public/avm/fixtures/initializers.d.ts +0 -43
  211. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  212. package/dest/public/avm/fixtures/initializers.js +0 -42
  213. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  214. package/dest/public/avm/index.d.ts +0 -2
  215. package/dest/public/avm/index.d.ts.map +0 -1
  216. package/dest/public/avm/index.js +0 -1
  217. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  218. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  219. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  220. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  221. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  222. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  223. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -47
  224. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  225. package/dest/public/avm/opcodes/arithmetic.js +0 -87
  226. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  227. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  228. package/dest/public/avm/opcodes/bitwise.js +0 -99
  229. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  230. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  231. package/dest/public/avm/opcodes/comparators.js +0 -43
  232. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  233. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  234. package/dest/public/avm/opcodes/contract.js +0 -65
  235. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  236. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  237. package/dest/public/avm/opcodes/control_flow.js +0 -107
  238. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  239. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  240. package/dest/public/avm/opcodes/conversion.js +0 -333
  241. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  242. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  243. package/dest/public/avm/opcodes/ec_add.js +0 -84
  244. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  245. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  246. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  247. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  248. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  249. package/dest/public/avm/opcodes/external_calls.js +0 -209
  250. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  251. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  252. package/dest/public/avm/opcodes/hashing.js +0 -114
  253. package/dest/public/avm/opcodes/index.d.ts +0 -16
  254. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  255. package/dest/public/avm/opcodes/index.js +0 -15
  256. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  257. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  258. package/dest/public/avm/opcodes/instruction.js +0 -95
  259. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  260. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  261. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  262. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  263. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  264. package/dest/public/avm/opcodes/memory.js +0 -257
  265. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  266. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  267. package/dest/public/avm/opcodes/misc.js +0 -73
  268. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  269. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  270. package/dest/public/avm/opcodes/storage.js +0 -68
  271. package/dest/public/avm/revert_reason.d.ts +0 -18
  272. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  273. package/dest/public/avm/revert_reason.js +0 -38
  274. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  275. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  276. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  277. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  278. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  279. package/dest/public/avm/serialization/bytecode_serialization.js +0 -333
  280. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  281. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  282. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  283. package/dest/public/avm/test_utils.d.ts +0 -15
  284. package/dest/public/avm/test_utils.d.ts.map +0 -1
  285. package/dest/public/avm/test_utils.js +0 -44
  286. package/dest/public/debug_fn_name.d.ts +0 -5
  287. package/dest/public/debug_fn_name.d.ts.map +0 -1
  288. package/dest/public/debug_fn_name.js +0 -9
  289. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -9
  290. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  291. package/dest/public/fixtures/custom_bytecode_tests.js +0 -109
  292. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -10
  293. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  294. package/dest/public/fixtures/minimal_public_tx.js +0 -29
  295. package/dest/public/hinting_db_sources.d.ts +0 -70
  296. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  297. package/dest/public/hinting_db_sources.js +0 -297
  298. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -41
  299. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  300. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -89
  301. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -24
  302. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  303. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  304. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -127
  305. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  306. package/dest/public/public_tx_simulator/public_tx_context.js +0 -292
  307. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  308. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  309. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -39
  310. package/dest/public/side_effect_trace.d.ts +0 -87
  311. package/dest/public/side_effect_trace.d.ts.map +0 -1
  312. package/dest/public/side_effect_trace.js +0 -199
  313. package/dest/public/side_effect_trace_interface.d.ts +0 -23
  314. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  315. package/dest/public/side_effect_trace_interface.js +0 -1
  316. package/dest/public/state_manager/index.d.ts +0 -2
  317. package/dest/public/state_manager/index.d.ts.map +0 -1
  318. package/dest/public/state_manager/index.js +0 -1
  319. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  320. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  321. package/dest/public/state_manager/nullifiers.js +0 -92
  322. package/dest/public/state_manager/public_storage.d.ts +0 -66
  323. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  324. package/dest/public/state_manager/public_storage.js +0 -145
  325. package/dest/public/state_manager/state_manager.d.ts +0 -166
  326. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  327. package/dest/public/state_manager/state_manager.js +0 -391
  328. package/dest/public/tx_contract_cache.d.ts +0 -41
  329. package/dest/public/tx_contract_cache.d.ts.map +0 -1
  330. package/dest/public/tx_contract_cache.js +0 -49
  331. package/src/public/avm/avm_context.ts +0 -61
  332. package/src/public/avm/avm_contract_call_result.ts +0 -67
  333. package/src/public/avm/avm_execution_environment.ts +0 -48
  334. package/src/public/avm/avm_gas.ts +0 -183
  335. package/src/public/avm/avm_machine_state.ts +0 -169
  336. package/src/public/avm/avm_memory_types.ts +0 -436
  337. package/src/public/avm/avm_simulator.ts +0 -274
  338. package/src/public/avm/avm_simulator_interface.ts +0 -8
  339. package/src/public/avm/errors.ts +0 -163
  340. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -108
  341. package/src/public/avm/fixtures/initializers.ts +0 -104
  342. package/src/public/avm/index.ts +0 -1
  343. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  344. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  345. package/src/public/avm/opcodes/arithmetic.ts +0 -117
  346. package/src/public/avm/opcodes/bitwise.ts +0 -113
  347. package/src/public/avm/opcodes/comparators.ts +0 -55
  348. package/src/public/avm/opcodes/contract.ts +0 -75
  349. package/src/public/avm/opcodes/control_flow.ts +0 -123
  350. package/src/public/avm/opcodes/conversion.ts +0 -104
  351. package/src/public/avm/opcodes/ec_add.ts +0 -96
  352. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  353. package/src/public/avm/opcodes/external_calls.ts +0 -260
  354. package/src/public/avm/opcodes/hashing.ts +0 -145
  355. package/src/public/avm/opcodes/index.ts +0 -15
  356. package/src/public/avm/opcodes/instruction.ts +0 -136
  357. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  358. package/src/public/avm/opcodes/memory.ts +0 -293
  359. package/src/public/avm/opcodes/misc.ts +0 -102
  360. package/src/public/avm/opcodes/storage.ts +0 -87
  361. package/src/public/avm/revert_reason.ts +0 -55
  362. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  363. package/src/public/avm/serialization/bytecode_serialization.ts +0 -204
  364. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  365. package/src/public/avm/test_utils.ts +0 -64
  366. package/src/public/debug_fn_name.ts +0 -18
  367. package/src/public/fixtures/custom_bytecode_tests.ts +0 -135
  368. package/src/public/fixtures/minimal_public_tx.ts +0 -36
  369. package/src/public/hinting_db_sources.ts +0 -505
  370. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -128
  371. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -109
  372. package/src/public/public_tx_simulator/public_tx_context.ts +0 -471
  373. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  374. package/src/public/side_effect_trace.ts +0 -290
  375. package/src/public/side_effect_trace_interface.ts +0 -28
  376. package/src/public/state_manager/index.ts +0 -1
  377. package/src/public/state_manager/nullifiers.ts +0 -103
  378. package/src/public/state_manager/public_storage.ts +0 -174
  379. package/src/public/state_manager/state_manager.ts +0 -560
  380. package/src/public/tx_contract_cache.ts +0 -69
@@ -1,13 +1,20 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/fields';
4
- import { createLogger } from '@aztec/foundation/log';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import { sleep } from '@aztec/foundation/sleep';
6
- import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
6
+ import { DateProvider, Timer, elapsed, execWithSignal } from '@aztec/foundation/timer';
7
7
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
8
8
  import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
9
9
  import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
10
- import { PublicDataWrite } from '@aztec/stdlib/avm';
10
+ import {
11
+ AvmCircuitInputs,
12
+ AvmCircuitPublicInputs,
13
+ AvmExecutionHints,
14
+ type AvmProvingRequest,
15
+ PublicDataWrite,
16
+ PublicSimulatorConfig,
17
+ } from '@aztec/stdlib/avm';
11
18
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
12
19
  import type { ContractDataSource } from '@aztec/stdlib/contract';
13
20
  import { computeTransactionFee } from '@aztec/stdlib/fees';
@@ -18,6 +25,8 @@ import type {
18
25
  PublicProcessorValidator,
19
26
  SequencerConfig,
20
27
  } from '@aztec/stdlib/interfaces/server';
28
+ import { type DebugLog, type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
29
+ import { ProvingRequestType } from '@aztec/stdlib/proofs';
21
30
  import { MerkleTreeId } from '@aztec/stdlib/trees';
22
31
  import {
23
32
  type FailedTx,
@@ -26,7 +35,6 @@ import {
26
35
  type ProcessedTx,
27
36
  StateReference,
28
37
  Tx,
29
- TxExecutionPhase,
30
38
  makeProcessedTxFromPrivateOnlyTx,
31
39
  makeProcessedTxFromTxWithPublicCalls,
32
40
  } from '@aztec/stdlib/tx';
@@ -44,8 +52,8 @@ import { AssertionError } from 'assert';
44
52
 
45
53
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
46
54
  import {
47
- type PublicTxSimulator,
48
55
  type PublicTxSimulatorConfig,
56
+ type PublicTxSimulatorInterface,
49
57
  TelemetryPublicTxSimulator,
50
58
  } from '../public_tx_simulator/index.js';
51
59
  import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
@@ -55,38 +63,30 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
55
63
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
56
64
  */
57
65
  export class PublicProcessorFactory {
66
+ private log: Logger;
58
67
  constructor(
59
68
  private contractDataSource: ContractDataSource,
60
69
  private dateProvider: DateProvider = new DateProvider(),
61
70
  protected telemetryClient: TelemetryClient = getTelemetryClient(),
62
- ) {}
71
+ bindings?: LoggerBindings,
72
+ ) {
73
+ this.log = createLogger('simulator:public-processor-factory', bindings);
74
+ }
63
75
 
64
76
  /**
65
77
  * Creates a new instance of a PublicProcessor.
66
78
  * @param globalVariables - The global variables for the block being processed.
67
- * @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
79
+ * @param contractsDB - Optional pre-populated contracts DB; a fresh one is constructed if omitted.
68
80
  * @returns A new instance of a PublicProcessor.
69
81
  */
70
82
  public create(
71
83
  merkleTree: MerkleTreeWriteOperations,
72
84
  globalVariables: GlobalVariables,
73
- config: {
74
- skipFeeEnforcement: boolean;
75
- clientInitiatedSimulation: boolean;
76
- proverId?: Fr;
77
- maxDebugLogMemoryReads?: number;
78
- },
85
+ config: PublicSimulatorConfig,
86
+ contractsDB: PublicContractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings()),
79
87
  ): PublicProcessor {
80
- const contractsDB = new PublicContractsDB(this.contractDataSource);
81
-
82
88
  const guardedFork = new GuardedMerkleTreeOperations(merkleTree);
83
- const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, {
84
- proverId: config.proverId,
85
- doMerkleOperations: true,
86
- skipFeeEnforcement: config.skipFeeEnforcement,
87
- clientInitiatedSimulation: config.clientInitiatedSimulation,
88
- maxDebugLogMemoryReads: config.maxDebugLogMemoryReads,
89
- });
89
+ const publicTxSimulator = this.createPublicTxSimulator(guardedFork, contractsDB, globalVariables, config);
90
90
 
91
91
  return new PublicProcessor(
92
92
  globalVariables,
@@ -95,6 +95,7 @@ export class PublicProcessorFactory {
95
95
  publicTxSimulator,
96
96
  this.dateProvider,
97
97
  this.telemetryClient,
98
+ createLogger('simulator:public-processor', this.log.getBindings()),
98
99
  );
99
100
  }
100
101
 
@@ -103,8 +104,15 @@ export class PublicProcessorFactory {
103
104
  contractsDB: PublicContractsDB,
104
105
  globalVariables: GlobalVariables,
105
106
  config?: Partial<PublicTxSimulatorConfig>,
106
- ): PublicTxSimulator {
107
- return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
107
+ ): PublicTxSimulatorInterface {
108
+ return new TelemetryPublicTxSimulator(
109
+ merkleTree,
110
+ contractsDB,
111
+ globalVariables,
112
+ this.telemetryClient,
113
+ config,
114
+ this.log.getBindings(),
115
+ );
108
116
  }
109
117
  }
110
118
 
@@ -115,22 +123,33 @@ class PublicProcessorTimeoutError extends Error {
115
123
  }
116
124
  }
117
125
 
126
+ class PublicProcessorAbortError extends Error {
127
+ constructor(message: string = 'Aborted while processing tx') {
128
+ super(message);
129
+ this.name = 'PublicProcessorAbortError';
130
+ }
131
+ }
132
+
133
+ function isPublicProcessorInterruptError(err: any) {
134
+ return err?.name === 'PublicProcessorTimeoutError' || err?.name === 'PublicProcessorAbortError';
135
+ }
136
+
118
137
  /**
119
138
  * Converts Txs lifted from the P2P module into ProcessedTx objects by executing
120
139
  * any public function calls in them. Txs with private calls only are unaffected.
121
140
  */
122
141
  export class PublicProcessor implements Traceable {
123
142
  private metrics: PublicProcessorMetrics;
124
-
125
143
  constructor(
126
144
  protected globalVariables: GlobalVariables,
127
145
  private guardedMerkleTree: GuardedMerkleTreeOperations,
128
146
  protected contractsDB: PublicContractsDB,
129
- protected publicTxSimulator: PublicTxSimulator,
147
+ protected publicTxSimulator: PublicTxSimulatorInterface,
130
148
  private dateProvider: DateProvider,
131
149
  telemetryClient: TelemetryClient = getTelemetryClient(),
132
- private log = createLogger('simulator:public-processor'),
133
- private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
150
+ private log: Logger,
151
+ private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
152
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
134
153
  ) {
135
154
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
136
155
  }
@@ -150,12 +169,13 @@ export class PublicProcessor implements Traceable {
150
169
  txs: Iterable<Tx> | AsyncIterable<Tx>,
151
170
  limits: PublicProcessorLimits = {},
152
171
  validator: PublicProcessorValidator = {},
153
- ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[]]> {
154
- const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
172
+ ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], DebugLog[]]> {
173
+ const { maxTransactions, deadline, maxBlockGas, maxBlobFields, isBuildingProposal, signal } = limits;
155
174
  const { preprocessValidator, nullifierCache } = validator;
156
175
  const result: ProcessedTx[] = [];
157
176
  const usedTxs: Tx[] = [];
158
177
  const failed: FailedTx[] = [];
178
+ const debugLogs: DebugLog[] = [];
159
179
  const timer = new Timer();
160
180
 
161
181
  let totalSizeInBytes = 0;
@@ -163,36 +183,43 @@ export class PublicProcessor implements Traceable {
163
183
  let totalPublicGas = new Gas(0, 0);
164
184
  let totalBlockGas = new Gas(0, 0);
165
185
  let totalBlobFields = 0;
186
+ let silentlySkippedCount = 0;
187
+ let totalSilentlySkippedDurationMs = 0;
166
188
 
167
- for await (const origTx of txs) {
189
+ for await (const tx of txs) {
168
190
  // Only process up to the max tx limit
169
191
  if (maxTransactions !== undefined && result.length >= maxTransactions) {
170
192
  this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
171
193
  break;
172
194
  }
173
195
 
174
- // Bail if we've hit the deadline
196
+ // Bail if we've hit the deadline or have been interrupted.
175
197
  if (deadline && this.dateProvider.now() > +deadline) {
176
198
  this.log.warn(`Stopping tx processing due to timeout.`);
177
199
  break;
178
200
  }
201
+ if (signal?.aborted) {
202
+ this.log.warn(`Stopping tx processing due to abort signal.`);
203
+ break;
204
+ }
179
205
 
180
- // Skip this tx if it'd exceed max block size
181
- const txHash = origTx.getTxHash().toString();
182
- const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
183
- if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
184
- this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
185
- txHash,
186
- sizeInBytes: preTxSizeInBytes,
187
- totalSizeInBytes,
188
- maxBlockSize,
189
- });
206
+ const txHash = tx.getTxHash().toString();
207
+
208
+ // Skip this tx if its estimated blob fields would exceed the limit.
209
+ // Only done during proposal building: during re-execution we must process the exact txs from the proposal.
210
+ const txBlobFields = tx.getPrivateTxEffectsSizeInFields();
211
+ if (isBuildingProposal && maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
212
+ this.log.warn(
213
+ `Skipping tx ${txHash} with ${txBlobFields} fields from private side effects due to blob fields limit`,
214
+ { txHash, txBlobFields, totalBlobFields, maxBlobFields },
215
+ );
190
216
  continue;
191
217
  }
192
218
 
193
- // Skip this tx if its gas limit would exceed the block gas limit
194
- const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
195
- if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
219
+ // Skip this tx if its gas limit would exceed the block gas limit (either da or l2).
220
+ // Only done during proposal building: during re-execution we must process the exact txs from the proposal.
221
+ const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
222
+ if (isBuildingProposal && maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
196
223
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
197
224
  txHash,
198
225
  txGasLimit,
@@ -202,9 +229,6 @@ export class PublicProcessor implements Traceable {
202
229
  continue;
203
230
  }
204
231
 
205
- // The processor modifies the tx objects in place, so we need to clone them.
206
- const tx = Tx.clone(origTx);
207
-
208
232
  // We validate the tx before processing it, to avoid unnecessary work.
209
233
  if (preprocessValidator) {
210
234
  const result = await preprocessValidator.validateTx(tx);
@@ -215,11 +239,6 @@ export class PublicProcessor implements Traceable {
215
239
  failed.push({ tx, error: new Error(`Tx failed preprocess validation: ${reason}`) });
216
240
  returns.push(new NestedProcessReturnValues([]));
217
241
  continue;
218
- } else if (result.result === 'skipped') {
219
- const reason = result.reason.join(', ');
220
- this.log.debug(`Skipping tx ${txHash.toString()} due to pre-process validation: ${reason}`);
221
- returns.push(new NestedProcessReturnValues([]));
222
- continue;
223
242
  } else {
224
243
  this.log.trace(`Tx ${txHash.toString()} is valid before processing.`);
225
244
  }
@@ -232,26 +251,24 @@ export class PublicProcessor implements Traceable {
232
251
  // Note: We use the underlying fork here not the guarded one, this ensures that it's not impacted by stopping the guarded version
233
252
  const checkpoint = await ForkCheckpoint.new(this.guardedMerkleTree.getUnderlyingFork());
234
253
  const startStateReference = await this.guardedMerkleTree.getUnderlyingFork().getStateReference();
254
+ this.contractsDB.createCheckpoint();
235
255
 
236
256
  try {
237
- const [processedTx, returnValues] = await this.processTx(tx, deadline);
238
-
239
- // If the actual size of this tx would exceed block size, skip it
240
- const txSize = processedTx.txEffect.getDASize();
241
- if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
242
- this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
243
- txHash,
244
- sizeInBytes: txSize,
245
- totalSizeInBytes,
246
- maxBlockSize,
247
- });
248
- // Need to revert the checkpoint here and don't go any further
249
- await checkpoint.revert();
250
- continue;
257
+ const [txProcessingTimeMs, [processedTx, returnValues, txDebugLogs]] = await elapsed(() =>
258
+ this.processTx(tx, deadline, signal),
259
+ );
260
+
261
+ // Inject a fake processing failure after N txs if requested
262
+ const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
263
+ if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
264
+ throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
251
265
  }
252
266
 
253
- // If the actual blob fields of this tx would exceed the limit, skip it
254
- const txBlobFields = processedTx.txEffect.toBlobFields().length;
267
+ const txBlobFields = processedTx.txEffect.getNumBlobFields();
268
+ const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
269
+
270
+ // If the actual blob fields of this tx would exceed the limit, skip it.
271
+ // Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
255
272
  if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
256
273
  this.log.debug(
257
274
  `Skipping processed tx ${txHash} with ${txBlobFields} blob fields due to max blob fields limit.`,
@@ -260,43 +277,76 @@ export class PublicProcessor implements Traceable {
260
277
  txBlobFields,
261
278
  totalBlobFields,
262
279
  maxBlobFields,
280
+ txProcessingTimeMs,
263
281
  },
264
282
  );
283
+ silentlySkippedCount += 1;
284
+ totalSilentlySkippedDurationMs += txProcessingTimeMs;
285
+ this.metrics.recordSilentlySkipped(txProcessingTimeMs);
265
286
  // Need to revert the checkpoint here and don't go any further
266
287
  await checkpoint.revert();
288
+ this.contractsDB.revertCheckpoint();
267
289
  continue;
268
290
  }
269
291
 
292
+ // During re-execution, check if the actual gas used by this tx would push the block over the gas limit.
293
+ // Unlike the proposal-building check (which uses declared gas limits pessimistically before processing),
294
+ // this uses actual gas and stops processing when the limit is exceeded.
295
+ if (
296
+ !isBuildingProposal &&
297
+ maxBlockGas !== undefined &&
298
+ totalBlockGas.add(processedTx.gasUsed.totalGas).gtAny(maxBlockGas)
299
+ ) {
300
+ this.log.warn(`Stopping re-execution since tx ${txHash} would push block gas over limit`, {
301
+ txHash,
302
+ txGas: processedTx.gasUsed.totalGas,
303
+ totalBlockGas,
304
+ maxBlockGas,
305
+ });
306
+ await checkpoint.revert();
307
+ this.contractsDB.revertCheckpoint();
308
+ break;
309
+ }
310
+
270
311
  // FIXME(fcarreiro): it's ugly to have to notify the validator of nullifiers.
271
312
  // I'd rather pass the validators the processedTx as well and let them deal with it.
272
313
  nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map(n => n.toBuffer()));
273
314
  result.push(processedTx);
274
315
  usedTxs.push(tx);
275
316
  returns = returns.concat(returnValues);
317
+ debugLogs.push(...txDebugLogs);
318
+
319
+ this.debugLogStore.storeLogs(processedTx.hash.toString(), txDebugLogs);
276
320
 
277
321
  totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
278
322
  totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
279
323
  totalSizeInBytes += txSize;
280
324
  totalBlobFields += txBlobFields;
325
+
326
+ // Commit the tx-level contracts checkpoint on success
327
+ this.contractsDB.commitCheckpoint();
281
328
  } catch (err: any) {
282
- if (err?.name === 'PublicProcessorTimeoutError') {
283
- this.log.warn(`Stopping tx processing due to timeout.`);
284
- // We hit the transaction execution deadline.
285
- // There may still be a transaction executing. We stop the guarded fork to prevent any further access to the world state.
329
+ if (isPublicProcessorInterruptError(err)) {
330
+ const interruptReason = err.name === 'PublicProcessorTimeoutError' ? 'timeout' : 'abort signal';
331
+ this.log.warn(`Stopping tx processing due to ${interruptReason}.`);
332
+ // The tx may still be executing on a worker thread (C++ via NAPI).
333
+ // Signal cancellation AND WAIT for the simulation to actually stop before touching fork checkpoints.
334
+ await this.publicTxSimulator.cancel?.();
335
+
336
+ // Now stop the guarded fork to prevent any further TS-side access to the world state.
286
337
  await this.guardedMerkleTree.stop();
287
338
 
288
339
  // We now know there can't be any further access to world state. The fork is in a state where there is:
289
340
  // 1. At least one outstanding checkpoint that has not been committed (the one created before we processed the tx).
290
341
  // 2. Possible state updates on that checkpoint or any others created during execution.
291
342
 
292
- // First we revert a checkpoint as managed by the ForkCheckpoint. This will revert whatever is the current checkpoint
293
- // which may not be the one originally created by this object. But that is ok, we do this to fulfil the ForkCheckpoint
294
- // lifecycle expectations and ensure it doesn't attempt to commit later on.
295
- await checkpoint.revert();
343
+ // Revert all checkpoints at or above this checkpoint's depth (inclusive), destroying any outstanding state
344
+ // updates from this tx and any nested checkpoints created during execution. This preserves any checkpoints
345
+ // created by callers below our depth.
346
+ await checkpoint.revertToCheckpoint();
296
347
 
297
- // Now we want to revert any/all remaining checkpoints, destroying any outstanding state updates.
298
- // This needs to be done directly on the underlying fork as the guarded fork has been stopped.
299
- await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
348
+ // Revert any contracts added to the DB for the tx.
349
+ this.contractsDB.revertCheckpoint();
300
350
 
301
351
  // Ensure we're at the same state as when we started processing this tx.
302
352
  await this.checkWorldStateUnchanged(startStateReference, txHash, err);
@@ -305,9 +355,10 @@ export class PublicProcessor implements Traceable {
305
355
  break;
306
356
  }
307
357
 
308
- // Roll back state to start of TX before proceeding to next TX
309
- await checkpoint.revert();
310
- await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
358
+ // Roll back state to start of TX before proceeding to next TX.
359
+ // Reverts all checkpoints at or above this checkpoint's depth, preserving any caller checkpoints below.
360
+ await checkpoint.revertToCheckpoint();
361
+ this.contractsDB.revertCheckpoint();
311
362
  const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
312
363
  this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
313
364
  failed.push({ tx, error: err instanceof Error ? err : new Error(errorMessage) });
@@ -318,8 +369,6 @@ export class PublicProcessor implements Traceable {
318
369
  } finally {
319
370
  // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
320
371
  await checkpoint.commit();
321
- // The tx-level contracts cache should not live on to the next tx
322
- this.contractsDB.clearContractsForTx();
323
372
  }
324
373
  }
325
374
 
@@ -327,15 +376,26 @@ export class PublicProcessor implements Traceable {
327
376
  const rate = duration > 0 ? totalPublicGas.l2Gas / duration : 0;
328
377
  this.metrics.recordAllTxs(totalPublicGas, rate);
329
378
 
330
- this.log.info(`Processed ${result.length} successful txs and ${failed.length} failed txs in ${duration}s`, {
331
- duration,
332
- rate,
333
- totalPublicGas,
334
- totalBlockGas,
335
- totalSizeInBytes,
336
- });
379
+ const silentlySkippedDurationMs = Math.round(totalSilentlySkippedDurationMs);
380
+ this.log.info(
381
+ `Processed ${result.length} successful txs and ${failed.length} failed txs ` +
382
+ `(${silentlySkippedCount} silently skipped, ${silentlySkippedDurationMs}ms wasted) ` +
383
+ `in ${duration}s`,
384
+ {
385
+ blockNumber: this.globalVariables.blockNumber,
386
+ successfulCount: result.length,
387
+ failedCount: failed.length,
388
+ duration,
389
+ rate,
390
+ totalPublicGas,
391
+ totalBlockGas,
392
+ totalSizeInBytes,
393
+ silentlySkippedCount,
394
+ silentlySkippedDurationMs,
395
+ },
396
+ );
337
397
 
338
- return [result, failed, usedTxs, returns];
398
+ return [result, failed, usedTxs, returns, debugLogs];
339
399
  }
340
400
 
341
401
  private async checkWorldStateUnchanged(
@@ -355,8 +415,14 @@ export class PublicProcessor implements Traceable {
355
415
  }
356
416
 
357
417
  @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
358
- private async processTx(tx: Tx, deadline: Date | undefined): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
359
- const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline));
418
+ private async processTx(
419
+ tx: Tx,
420
+ deadline: Date | undefined,
421
+ signal: AbortSignal | undefined,
422
+ ): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
423
+ const [time, [processedTx, returnValues, debugLogs]] = await elapsed(() =>
424
+ this.processTxWithinDeadline(tx, deadline, signal),
425
+ );
360
426
 
361
427
  this.log.verbose(
362
428
  !tx.hasPublicCalls()
@@ -379,7 +445,7 @@ export class PublicProcessor implements Traceable {
379
445
  },
380
446
  );
381
447
 
382
- return [processedTx, returnValues ?? []];
448
+ return [processedTx, returnValues ?? [], debugLogs];
383
449
  }
384
450
 
385
451
  private async doTreeInsertionsForPrivateOnlyTx(processedTx: ProcessedTx): Promise<void> {
@@ -409,14 +475,14 @@ export class PublicProcessor implements Traceable {
409
475
  this.metrics.recordTreeInsertions(Number(treeInsertionEnd - treeInsertionStart) / 1_000);
410
476
  }
411
477
 
412
- /** Processes the given tx within deadline. Returns timeout if deadline is hit. */
478
+ /** Processes the given tx within deadline or until the signal is aborted. */
413
479
  private async processTxWithinDeadline(
414
480
  tx: Tx,
415
481
  deadline: Date | undefined,
416
- ): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> {
417
- const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> = tx.hasPublicCalls()
418
- ? () => this.processTxWithPublicCalls(tx)
419
- : () => this.processPrivateOnlyTx(tx);
482
+ signal: AbortSignal | undefined,
483
+ ): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> {
484
+ const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> =
485
+ tx.hasPublicCalls() ? () => this.processTxWithPublicCalls(tx) : () => this.processPrivateOnlyTx(tx);
420
486
 
421
487
  // Fake a delay per tx if instructed (used for tests)
422
488
  const fakeDelayPerTxMs = this.opts.fakeProcessingDelayPerTxMs;
@@ -430,27 +496,38 @@ export class PublicProcessor implements Traceable {
430
496
  }
431
497
  : innerProcessFn;
432
498
 
433
- if (!deadline) {
499
+ const processingSignal = this.getProcessingSignal(tx, deadline, signal);
500
+ if (!processingSignal) {
434
501
  return await processFn();
435
502
  }
436
503
 
437
- const txHash = tx.getTxHash();
504
+ return await execWithSignal(
505
+ () => processFn(),
506
+ processingSignal,
507
+ signal =>
508
+ signal.reason?.name === 'TimeoutError' ? new PublicProcessorTimeoutError() : new PublicProcessorAbortError(),
509
+ );
510
+ }
511
+
512
+ private getProcessingSignal(tx: Tx, deadline: Date | undefined, signal: AbortSignal | undefined) {
513
+ if (!deadline) {
514
+ return signal;
515
+ }
516
+
438
517
  const timeout = +deadline - this.dateProvider.now();
439
518
  if (timeout <= 0) {
440
519
  throw new PublicProcessorTimeoutError();
441
520
  }
442
521
 
522
+ const txHash = tx.getTxHash();
443
523
  this.log.debug(`Processing tx ${txHash.toString()} within ${timeout}ms`, {
444
524
  deadline: deadline.toISOString(),
445
525
  now: new Date(this.dateProvider.now()).toISOString(),
446
526
  txHash,
447
527
  });
448
528
 
449
- return await executeTimeout(
450
- () => processFn(),
451
- timeout,
452
- () => new PublicProcessorTimeoutError(),
453
- );
529
+ const timeoutSignal = AbortSignal.timeout(timeout);
530
+ return signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
454
531
  }
455
532
 
456
533
  /**
@@ -484,7 +561,7 @@ export class PublicProcessor implements Traceable {
484
561
  @trackSpan('PublicProcessor.processPrivateOnlyTx', (tx: Tx) => ({
485
562
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
486
563
  }))
487
- private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined]> {
564
+ private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined, DebugLog[]]> {
488
565
  const gasFees = this.globalVariables.gasFees;
489
566
  const transactionFee = computeTransactionFee(gasFees, tx.data.constants.txContext.gasSettings, tx.data.gasUsed);
490
567
 
@@ -507,35 +584,20 @@ export class PublicProcessor implements Traceable {
507
584
  // Fee payment insertion has already been done. Do the rest.
508
585
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
509
586
 
510
- // Add any contracts registered/deployed in this private-only tx to the block-level cache
511
- // (add to tx-level cache and then commit to block-level cache)
512
- await this.contractsDB.addNewContracts(tx);
513
- this.contractsDB.commitContractsForTx();
587
+ this.contractsDB.addNewContracts(tx);
514
588
 
515
- return [processedTx, undefined];
589
+ return [processedTx, undefined, []];
516
590
  }
517
591
 
518
592
  @trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
519
593
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
520
594
  }))
521
- private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
595
+ private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
522
596
  const timer = new Timer();
523
597
 
524
- const { avmProvingRequest, gasUsed, revertCode, revertReason, processedPhases } =
525
- await this.publicTxSimulator.simulate(tx);
526
-
527
- if (!avmProvingRequest) {
528
- this.metrics.recordFailedTx();
529
- throw new Error('Avm proving result was not generated.');
530
- }
531
-
532
- processedPhases.forEach(phase => {
533
- if (phase.reverted) {
534
- this.metrics.recordRevertedPhase(phase.phase);
535
- } else {
536
- this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
537
- }
538
- });
598
+ const result = await this.publicTxSimulator.simulate(tx);
599
+ // TODO: use the callStackMetadata here to extract more data about public execution
600
+ const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
539
601
 
540
602
  const contractClassLogs = revertCode.isOK()
541
603
  ? tx.getContractClassLogs()
@@ -546,14 +608,41 @@ export class PublicProcessor implements Traceable {
546
608
  .map(log => ContractClassPublishedEvent.fromLog(log)),
547
609
  );
548
610
 
549
- const phaseCount = processedPhases.length;
611
+ // TODO(fcarreiro): remove phase count metric.
550
612
  const durationMs = timer.ms();
551
- this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
613
+ this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
552
614
 
553
- const processedTx = makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
615
+ // Extract the return values from the call stack metadata.
616
+ const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
617
+ // Extract the revert reason from the call stack metadata.
618
+ const revertReason = result.findRevertReason();
619
+ // Create proving request if we have hints and public inputs.
620
+ const avmProvingRequest =
621
+ hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
554
622
 
555
- const returnValues = processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
623
+ const processedTx = makeProcessedTxFromTxWithPublicCalls(
624
+ tx,
625
+ this.globalVariables,
626
+ avmProvingRequest,
627
+ publicTxEffect,
628
+ gasUsed,
629
+ revertCode,
630
+ revertReason,
631
+ );
556
632
 
557
- return [processedTx, returnValues];
633
+ return [processedTx, appLogicReturnValues, result.logs ?? []];
634
+ }
635
+
636
+ /**
637
+ * Generate the proving request for the AVM circuit.
638
+ */
639
+ private static generateProvingRequest(
640
+ publicInputs: AvmCircuitPublicInputs,
641
+ hints: AvmExecutionHints = AvmExecutionHints.empty(),
642
+ ): AvmProvingRequest {
643
+ return {
644
+ type: ProvingRequestType.PUBLIC_VM,
645
+ inputs: new AvmCircuitInputs(hints, publicInputs),
646
+ };
558
647
  }
559
648
  }