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

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