@aztec/simulator 0.0.0-test.0

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 (367) hide show
  1. package/README.md +49 -0
  2. package/dest/client.d.ts +5 -0
  3. package/dest/client.d.ts.map +1 -0
  4. package/dest/client.js +3 -0
  5. package/dest/common/db_interfaces.d.ts +80 -0
  6. package/dest/common/db_interfaces.d.ts.map +1 -0
  7. package/dest/common/db_interfaces.js +1 -0
  8. package/dest/common/debug_fn_name.d.ts +5 -0
  9. package/dest/common/debug_fn_name.d.ts.map +1 -0
  10. package/dest/common/debug_fn_name.js +6 -0
  11. package/dest/common/errors.d.ts +54 -0
  12. package/dest/common/errors.d.ts.map +1 -0
  13. package/dest/common/errors.js +135 -0
  14. package/dest/common/index.d.ts +4 -0
  15. package/dest/common/index.d.ts.map +1 -0
  16. package/dest/common/index.js +3 -0
  17. package/dest/common/message_load_oracle_inputs.d.ts +15 -0
  18. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -0
  19. package/dest/common/message_load_oracle_inputs.js +15 -0
  20. package/dest/common/stats/index.d.ts +2 -0
  21. package/dest/common/stats/index.d.ts.map +1 -0
  22. package/dest/common/stats/index.js +1 -0
  23. package/dest/common/stats/stats.d.ts +4 -0
  24. package/dest/common/stats/stats.d.ts.map +1 -0
  25. package/dest/common/stats/stats.js +10 -0
  26. package/dest/private/acvm/acvm.d.ts +35 -0
  27. package/dest/private/acvm/acvm.d.ts.map +1 -0
  28. package/dest/private/acvm/acvm.js +70 -0
  29. package/dest/private/acvm/acvm_types.d.ts +10 -0
  30. package/dest/private/acvm/acvm_types.d.ts.map +1 -0
  31. package/dest/private/acvm/acvm_types.js +3 -0
  32. package/dest/private/acvm/deserialize.d.ts +36 -0
  33. package/dest/private/acvm/deserialize.d.ts.map +1 -0
  34. package/dest/private/acvm/deserialize.js +42 -0
  35. package/dest/private/acvm/index.d.ts +6 -0
  36. package/dest/private/acvm/index.d.ts.map +1 -0
  37. package/dest/private/acvm/index.js +5 -0
  38. package/dest/private/acvm/oracle/index.d.ts +14 -0
  39. package/dest/private/acvm/oracle/index.d.ts.map +1 -0
  40. package/dest/private/acvm/oracle/index.js +2 -0
  41. package/dest/private/acvm/oracle/oracle.d.ts +49 -0
  42. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -0
  43. package/dest/private/acvm/oracle/oracle.js +263 -0
  44. package/dest/private/acvm/oracle/typed_oracle.d.ts +83 -0
  45. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -0
  46. package/dest/private/acvm/oracle/typed_oracle.js +132 -0
  47. package/dest/private/acvm/serialize.d.ts +24 -0
  48. package/dest/private/acvm/serialize.d.ts.map +1 -0
  49. package/dest/private/acvm/serialize.js +46 -0
  50. package/dest/private/execution_data_provider.d.ts +261 -0
  51. package/dest/private/execution_data_provider.d.ts.map +1 -0
  52. package/dest/private/execution_data_provider.js +14 -0
  53. package/dest/private/execution_note_cache.d.ts +93 -0
  54. package/dest/private/execution_note_cache.d.ts.map +1 -0
  55. package/dest/private/execution_note_cache.js +180 -0
  56. package/dest/private/hashed_values_cache.d.ts +28 -0
  57. package/dest/private/hashed_values_cache.d.ts.map +1 -0
  58. package/dest/private/hashed_values_cache.js +46 -0
  59. package/dest/private/index.d.ts +13 -0
  60. package/dest/private/index.d.ts.map +1 -0
  61. package/dest/private/index.js +12 -0
  62. package/dest/private/pick_notes.d.ts +85 -0
  63. package/dest/private/pick_notes.d.ts.map +1 -0
  64. package/dest/private/pick_notes.js +51 -0
  65. package/dest/private/private_execution.d.ts +25 -0
  66. package/dest/private/private_execution.d.ts.map +1 -0
  67. package/dest/private/private_execution.js +92 -0
  68. package/dest/private/private_execution_oracle.d.ts +215 -0
  69. package/dest/private/private_execution_oracle.d.ts.map +1 -0
  70. package/dest/private/private_execution_oracle.js +382 -0
  71. package/dest/private/providers/acvm_native.d.ts +40 -0
  72. package/dest/private/providers/acvm_native.d.ts.map +1 -0
  73. package/dest/private/providers/acvm_native.js +139 -0
  74. package/dest/private/providers/acvm_wasm.d.ts +15 -0
  75. package/dest/private/providers/acvm_wasm.d.ts.map +1 -0
  76. package/dest/private/providers/acvm_wasm.js +62 -0
  77. package/dest/private/providers/acvm_wasm_with_blobs.d.ts +19 -0
  78. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -0
  79. package/dest/private/providers/acvm_wasm_with_blobs.js +32 -0
  80. package/dest/private/providers/factory.d.ts +12 -0
  81. package/dest/private/providers/factory.d.ts.map +1 -0
  82. package/dest/private/providers/factory.js +27 -0
  83. package/dest/private/providers/simulation_provider.d.ts +19 -0
  84. package/dest/private/providers/simulation_provider.d.ts.map +1 -0
  85. package/dest/private/providers/simulation_provider.js +24 -0
  86. package/dest/private/simulator.d.ts +34 -0
  87. package/dest/private/simulator.d.ts.map +1 -0
  88. package/dest/private/simulator.js +76 -0
  89. package/dest/private/unconstrained_execution.d.ts +10 -0
  90. package/dest/private/unconstrained_execution.d.ts.map +1 -0
  91. package/dest/private/unconstrained_execution.js +27 -0
  92. package/dest/private/unconstrained_execution_oracle.d.ts +161 -0
  93. package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -0
  94. package/dest/private/unconstrained_execution_oracle.js +258 -0
  95. package/dest/public/avm/avm_context.d.ts +41 -0
  96. package/dest/public/avm/avm_context.d.ts.map +1 -0
  97. package/dest/public/avm/avm_context.js +44 -0
  98. package/dest/public/avm/avm_contract_call_result.d.ts +30 -0
  99. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -0
  100. package/dest/public/avm/avm_contract_call_result.js +50 -0
  101. package/dest/public/avm/avm_execution_environment.d.ts +21 -0
  102. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -0
  103. package/dest/public/avm/avm_execution_environment.js +31 -0
  104. package/dest/public/avm/avm_gas.d.ts +60 -0
  105. package/dest/public/avm/avm_gas.d.ts.map +1 -0
  106. package/dest/public/avm/avm_gas.js +203 -0
  107. package/dest/public/avm/avm_machine_state.d.ts +95 -0
  108. package/dest/public/avm/avm_machine_state.d.ts.map +1 -0
  109. package/dest/public/avm/avm_machine_state.js +107 -0
  110. package/dest/public/avm/avm_memory_types.d.ts +264 -0
  111. package/dest/public/avm/avm_memory_types.d.ts.map +1 -0
  112. package/dest/public/avm/avm_memory_types.js +340 -0
  113. package/dest/public/avm/avm_simulator.d.ts +40 -0
  114. package/dest/public/avm/avm_simulator.d.ts.map +1 -0
  115. package/dest/public/avm/avm_simulator.js +202 -0
  116. package/dest/public/avm/bytecode_utils.d.ts +5 -0
  117. package/dest/public/avm/bytecode_utils.d.ts.map +1 -0
  118. package/dest/public/avm/bytecode_utils.js +17 -0
  119. package/dest/public/avm/errors.d.ts +122 -0
  120. package/dest/public/avm/errors.d.ts.map +1 -0
  121. package/dest/public/avm/errors.js +179 -0
  122. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +21 -0
  123. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
  124. package/dest/public/avm/fixtures/avm_simulation_tester.js +76 -0
  125. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +36 -0
  126. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
  127. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +83 -0
  128. package/dest/public/avm/fixtures/index.d.ts +84 -0
  129. package/dest/public/avm/fixtures/index.d.ts.map +1 -0
  130. package/dest/public/avm/fixtures/index.js +175 -0
  131. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +35 -0
  132. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
  133. package/dest/public/avm/fixtures/simple_contract_data_source.js +74 -0
  134. package/dest/public/avm/index.d.ts +4 -0
  135. package/dest/public/avm/index.d.ts.map +1 -0
  136. package/dest/public/avm/index.js +3 -0
  137. package/dest/public/avm/journal/index.d.ts +2 -0
  138. package/dest/public/avm/journal/index.d.ts.map +1 -0
  139. package/dest/public/avm/journal/index.js +1 -0
  140. package/dest/public/avm/journal/journal.d.ts +209 -0
  141. package/dest/public/avm/journal/journal.d.ts.map +1 -0
  142. package/dest/public/avm/journal/journal.js +486 -0
  143. package/dest/public/avm/journal/nullifiers.d.ts +64 -0
  144. package/dest/public/avm/journal/nullifiers.d.ts.map +1 -0
  145. package/dest/public/avm/journal/nullifiers.js +97 -0
  146. package/dest/public/avm/journal/public_storage.d.ts +66 -0
  147. package/dest/public/avm/journal/public_storage.d.ts.map +1 -0
  148. package/dest/public/avm/journal/public_storage.js +145 -0
  149. package/dest/public/avm/opcodes/accrued_substate.d.ts +75 -0
  150. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -0
  151. package/dest/public/avm/opcodes/accrued_substate.js +252 -0
  152. package/dest/public/avm/opcodes/addressing_mode.d.ts +27 -0
  153. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -0
  154. package/dest/public/avm/opcodes/addressing_mode.js +74 -0
  155. package/dest/public/avm/opcodes/arithmetic.d.ts +37 -0
  156. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -0
  157. package/dest/public/avm/opcodes/arithmetic.js +73 -0
  158. package/dest/public/avm/opcodes/bitwise.d.ts +50 -0
  159. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -0
  160. package/dest/public/avm/opcodes/bitwise.js +106 -0
  161. package/dest/public/avm/opcodes/comparators.d.ts +25 -0
  162. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -0
  163. package/dest/public/avm/opcodes/comparators.js +43 -0
  164. package/dest/public/avm/opcodes/contract.d.ts +21 -0
  165. package/dest/public/avm/opcodes/contract.d.ts.map +1 -0
  166. package/dest/public/avm/opcodes/contract.js +66 -0
  167. package/dest/public/avm/opcodes/control_flow.d.ts +41 -0
  168. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -0
  169. package/dest/public/avm/opcodes/control_flow.js +105 -0
  170. package/dest/public/avm/opcodes/conversion.d.ts +17 -0
  171. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -0
  172. package/dest/public/avm/opcodes/conversion.js +69 -0
  173. package/dest/public/avm/opcodes/ec_add.d.ts +19 -0
  174. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -0
  175. package/dest/public/avm/opcodes/ec_add.js +84 -0
  176. package/dest/public/avm/opcodes/environment_getters.d.ts +28 -0
  177. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -0
  178. package/dest/public/avm/opcodes/environment_getters.js +79 -0
  179. package/dest/public/avm/opcodes/external_calls.d.ts +58 -0
  180. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -0
  181. package/dest/public/avm/opcodes/external_calls.js +204 -0
  182. package/dest/public/avm/opcodes/hashing.d.ts +36 -0
  183. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -0
  184. package/dest/public/avm/opcodes/hashing.js +114 -0
  185. package/dest/public/avm/opcodes/index.d.ts +16 -0
  186. package/dest/public/avm/opcodes/index.d.ts.map +1 -0
  187. package/dest/public/avm/opcodes/index.js +15 -0
  188. package/dest/public/avm/opcodes/instruction.d.ts +70 -0
  189. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -0
  190. package/dest/public/avm/opcodes/instruction.js +91 -0
  191. package/dest/public/avm/opcodes/instruction_impl.d.ts +19 -0
  192. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -0
  193. package/dest/public/avm/opcodes/instruction_impl.js +30 -0
  194. package/dest/public/avm/opcodes/memory.d.ts +74 -0
  195. package/dest/public/avm/opcodes/memory.d.ts.map +1 -0
  196. package/dest/public/avm/opcodes/memory.js +253 -0
  197. package/dest/public/avm/opcodes/misc.d.ts +17 -0
  198. package/dest/public/avm/opcodes/misc.d.ts.map +1 -0
  199. package/dest/public/avm/opcodes/misc.js +48 -0
  200. package/dest/public/avm/opcodes/storage.d.ts +24 -0
  201. package/dest/public/avm/opcodes/storage.d.ts.map +1 -0
  202. package/dest/public/avm/opcodes/storage.js +66 -0
  203. package/dest/public/avm/serialization/buffer_cursor.d.ts +28 -0
  204. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -0
  205. package/dest/public/avm/serialization/buffer_cursor.js +99 -0
  206. package/dest/public/avm/serialization/bytecode_serialization.d.ts +21 -0
  207. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -0
  208. package/dest/public/avm/serialization/bytecode_serialization.js +332 -0
  209. package/dest/public/avm/serialization/instruction_serialization.d.ts +105 -0
  210. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -0
  211. package/dest/public/avm/serialization/instruction_serialization.js +226 -0
  212. package/dest/public/avm/test_utils.d.ts +18 -0
  213. package/dest/public/avm/test_utils.d.ts.map +1 -0
  214. package/dest/public/avm/test_utils.js +52 -0
  215. package/dest/public/bytecode_errors.d.ts +4 -0
  216. package/dest/public/bytecode_errors.d.ts.map +1 -0
  217. package/dest/public/bytecode_errors.js +6 -0
  218. package/dest/public/execution.d.ts +108 -0
  219. package/dest/public/execution.d.ts.map +1 -0
  220. package/dest/public/execution.js +9 -0
  221. package/dest/public/executor_metrics.d.ts +13 -0
  222. package/dest/public/executor_metrics.d.ts.map +1 -0
  223. package/dest/public/executor_metrics.js +54 -0
  224. package/dest/public/fixtures/index.d.ts +3 -0
  225. package/dest/public/fixtures/index.d.ts.map +1 -0
  226. package/dest/public/fixtures/index.js +2 -0
  227. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +32 -0
  228. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
  229. package/dest/public/fixtures/public_tx_simulation_tester.js +93 -0
  230. package/dest/public/fixtures/utils.d.ts +13 -0
  231. package/dest/public/fixtures/utils.d.ts.map +1 -0
  232. package/dest/public/fixtures/utils.js +126 -0
  233. package/dest/public/index.d.ts +10 -0
  234. package/dest/public/index.d.ts.map +1 -0
  235. package/dest/public/index.js +8 -0
  236. package/dest/public/public_db_sources.d.ts +129 -0
  237. package/dest/public/public_db_sources.d.ts.map +1 -0
  238. package/dest/public/public_db_sources.js +264 -0
  239. package/dest/public/public_processor/public_processor.d.ts +74 -0
  240. package/dest/public/public_processor/public_processor.d.ts.map +1 -0
  241. package/dest/public/public_processor/public_processor.js +379 -0
  242. package/dest/public/public_processor/public_processor_metrics.d.ts +27 -0
  243. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -0
  244. package/dest/public/public_processor/public_processor_metrics.js +125 -0
  245. package/dest/public/public_tx_simulator/public_tx_context.d.ts +137 -0
  246. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -0
  247. package/dest/public/public_tx_simulator/public_tx_context.js +320 -0
  248. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +102 -0
  249. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -0
  250. package/dest/public/public_tx_simulator/public_tx_simulator.js +334 -0
  251. package/dest/public/side_effect_errors.d.ts +4 -0
  252. package/dest/public/side_effect_errors.d.ts.map +1 -0
  253. package/dest/public/side_effect_errors.js +6 -0
  254. package/dest/public/side_effect_trace.d.ts +132 -0
  255. package/dest/public/side_effect_trace.d.ts.map +1 -0
  256. package/dest/public/side_effect_trace.js +249 -0
  257. package/dest/public/side_effect_trace_interface.d.ts +34 -0
  258. package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
  259. package/dest/public/side_effect_trace_interface.js +1 -0
  260. package/dest/public/tx_contract_cache.d.ts +41 -0
  261. package/dest/public/tx_contract_cache.d.ts.map +1 -0
  262. package/dest/public/tx_contract_cache.js +49 -0
  263. package/dest/public/unique_class_ids.d.ts +37 -0
  264. package/dest/public/unique_class_ids.d.ts.map +1 -0
  265. package/dest/public/unique_class_ids.js +61 -0
  266. package/dest/public/utils.d.ts +5 -0
  267. package/dest/public/utils.d.ts.map +1 -0
  268. package/dest/public/utils.js +35 -0
  269. package/dest/server.d.ts +6 -0
  270. package/dest/server.d.ts.map +1 -0
  271. package/dest/server.js +4 -0
  272. package/dest/test/utils.d.ts +13 -0
  273. package/dest/test/utils.d.ts.map +1 -0
  274. package/dest/test/utils.js +22 -0
  275. package/package.json +104 -0
  276. package/src/client.ts +4 -0
  277. package/src/common/db_interfaces.ts +94 -0
  278. package/src/common/debug_fn_name.ts +18 -0
  279. package/src/common/errors.ts +183 -0
  280. package/src/common/index.ts +3 -0
  281. package/src/common/message_load_oracle_inputs.ts +15 -0
  282. package/src/common/stats/index.ts +1 -0
  283. package/src/common/stats/stats.ts +20 -0
  284. package/src/private/acvm/acvm.ts +127 -0
  285. package/src/private/acvm/acvm_types.ts +11 -0
  286. package/src/private/acvm/deserialize.ts +52 -0
  287. package/src/private/acvm/index.ts +5 -0
  288. package/src/private/acvm/oracle/index.ts +16 -0
  289. package/src/private/acvm/oracle/oracle.ts +455 -0
  290. package/src/private/acvm/oracle/typed_oracle.ts +259 -0
  291. package/src/private/acvm/serialize.ts +60 -0
  292. package/src/private/execution_data_provider.ts +323 -0
  293. package/src/private/execution_note_cache.ts +217 -0
  294. package/src/private/hashed_values_cache.ts +55 -0
  295. package/src/private/index.ts +16 -0
  296. package/src/private/pick_notes.ts +141 -0
  297. package/src/private/private_execution.ts +151 -0
  298. package/src/private/private_execution_oracle.ts +614 -0
  299. package/src/private/providers/acvm_native.ts +171 -0
  300. package/src/private/providers/acvm_wasm.ts +63 -0
  301. package/src/private/providers/acvm_wasm_with_blobs.ts +50 -0
  302. package/src/private/providers/factory.ts +38 -0
  303. package/src/private/providers/simulation_provider.ts +45 -0
  304. package/src/private/simulator.ts +147 -0
  305. package/src/private/unconstrained_execution.ts +50 -0
  306. package/src/private/unconstrained_execution_oracle.ts +373 -0
  307. package/src/public/avm/avm_context.ts +61 -0
  308. package/src/public/avm/avm_contract_call_result.ts +55 -0
  309. package/src/public/avm/avm_execution_environment.ts +39 -0
  310. package/src/public/avm/avm_gas.ts +195 -0
  311. package/src/public/avm/avm_machine_state.ts +164 -0
  312. package/src/public/avm/avm_memory_types.ts +423 -0
  313. package/src/public/avm/avm_simulator.ts +284 -0
  314. package/src/public/avm/bytecode_utils.ts +17 -0
  315. package/src/public/avm/errors.ts +232 -0
  316. package/src/public/avm/fixtures/avm_simulation_tester.ts +105 -0
  317. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +109 -0
  318. package/src/public/avm/fixtures/index.ts +296 -0
  319. package/src/public/avm/fixtures/simple_contract_data_source.ts +105 -0
  320. package/src/public/avm/index.ts +3 -0
  321. package/src/public/avm/journal/index.ts +1 -0
  322. package/src/public/avm/journal/journal.ts +742 -0
  323. package/src/public/avm/journal/nullifiers.ts +109 -0
  324. package/src/public/avm/journal/public_storage.ts +174 -0
  325. package/src/public/avm/opcodes/.eslintrc.cjs +8 -0
  326. package/src/public/avm/opcodes/accrued_substate.ts +253 -0
  327. package/src/public/avm/opcodes/addressing_mode.ts +87 -0
  328. package/src/public/avm/opcodes/arithmetic.ts +95 -0
  329. package/src/public/avm/opcodes/bitwise.ts +109 -0
  330. package/src/public/avm/opcodes/comparators.ts +52 -0
  331. package/src/public/avm/opcodes/contract.ts +72 -0
  332. package/src/public/avm/opcodes/control_flow.ts +114 -0
  333. package/src/public/avm/opcodes/conversion.ts +80 -0
  334. package/src/public/avm/opcodes/ec_add.ts +93 -0
  335. package/src/public/avm/opcodes/environment_getters.ts +82 -0
  336. package/src/public/avm/opcodes/external_calls.ts +228 -0
  337. package/src/public/avm/opcodes/hashing.ts +125 -0
  338. package/src/public/avm/opcodes/index.ts +15 -0
  339. package/src/public/avm/opcodes/instruction.ts +126 -0
  340. package/src/public/avm/opcodes/instruction_impl.ts +36 -0
  341. package/src/public/avm/opcodes/memory.ts +254 -0
  342. package/src/public/avm/opcodes/misc.ts +60 -0
  343. package/src/public/avm/opcodes/storage.ts +71 -0
  344. package/src/public/avm/serialization/buffer_cursor.ts +115 -0
  345. package/src/public/avm/serialization/bytecode_serialization.ts +206 -0
  346. package/src/public/avm/serialization/instruction_serialization.ts +208 -0
  347. package/src/public/avm/test_utils.ts +81 -0
  348. package/src/public/bytecode_errors.ts +6 -0
  349. package/src/public/execution.ts +140 -0
  350. package/src/public/executor_metrics.ts +71 -0
  351. package/src/public/fixtures/index.ts +2 -0
  352. package/src/public/fixtures/public_tx_simulation_tester.ts +179 -0
  353. package/src/public/fixtures/utils.ts +199 -0
  354. package/src/public/index.ts +9 -0
  355. package/src/public/public_db_sources.ts +369 -0
  356. package/src/public/public_processor/public_processor.ts +521 -0
  357. package/src/public/public_processor/public_processor_metrics.ts +154 -0
  358. package/src/public/public_tx_simulator/public_tx_context.ts +504 -0
  359. package/src/public/public_tx_simulator/public_tx_simulator.ts +474 -0
  360. package/src/public/side_effect_errors.ts +6 -0
  361. package/src/public/side_effect_trace.ts +516 -0
  362. package/src/public/side_effect_trace_interface.ts +76 -0
  363. package/src/public/tx_contract_cache.ts +69 -0
  364. package/src/public/unique_class_ids.ts +80 -0
  365. package/src/public/utils.ts +32 -0
  366. package/src/server.ts +5 -0
  367. package/src/test/utils.ts +36 -0
@@ -0,0 +1,379 @@
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
8
+ import { padArrayEnd } from '@aztec/foundation/collection';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import { createLogger } from '@aztec/foundation/log';
11
+ import { Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
12
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
13
+ import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
14
+ import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
15
+ import { PublicDataWrite } from '@aztec/stdlib/avm';
16
+ import { Gas } from '@aztec/stdlib/gas';
17
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
18
+ import { NestedProcessReturnValues, Tx, TxExecutionPhase, makeProcessedTxFromPrivateOnlyTx, makeProcessedTxFromTxWithPublicCalls } from '@aztec/stdlib/tx';
19
+ import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
20
+ import { ForkCheckpoint } from '@aztec/world-state/native';
21
+ import { WorldStateDB } from '../public_db_sources.js';
22
+ import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
23
+ import { PublicProcessorMetrics } from './public_processor_metrics.js';
24
+ /**
25
+ * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
26
+ */ export class PublicProcessorFactory {
27
+ contractDataSource;
28
+ dateProvider;
29
+ telemetryClient;
30
+ constructor(contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
31
+ this.contractDataSource = contractDataSource;
32
+ this.dateProvider = dateProvider;
33
+ this.telemetryClient = telemetryClient;
34
+ }
35
+ /**
36
+ * Creates a new instance of a PublicProcessor.
37
+ * @param historicalHeader - The header of a block previous to the one in which the tx is included.
38
+ * @param globalVariables - The global variables for the block being processed.
39
+ * @param skipFeeEnforcement - Allows disabling balance checks for fee estimations.
40
+ * @returns A new instance of a PublicProcessor.
41
+ */ create(merkleTree, globalVariables, skipFeeEnforcement) {
42
+ const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
43
+ const publicTxSimulator = this.createPublicTxSimulator(merkleTree, worldStateDB, globalVariables, /*doMerkleOperations=*/ true, skipFeeEnforcement, this.telemetryClient);
44
+ return new PublicProcessor(merkleTree, globalVariables, worldStateDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
45
+ }
46
+ createPublicTxSimulator(db, worldStateDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
47
+ return new PublicTxSimulator(db, worldStateDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
48
+ }
49
+ }
50
+ class PublicProcessorTimeoutError extends Error {
51
+ constructor(message = 'Timed out while processing tx'){
52
+ super(message);
53
+ this.name = 'PublicProcessorTimeoutError';
54
+ }
55
+ }
56
+ /**
57
+ * Converts Txs lifted from the P2P module into ProcessedTx objects by executing
58
+ * any public function calls in them. Txs with private calls only are unaffected.
59
+ */ export class PublicProcessor {
60
+ db;
61
+ globalVariables;
62
+ worldStateDB;
63
+ publicTxSimulator;
64
+ dateProvider;
65
+ log;
66
+ metrics;
67
+ constructor(db, globalVariables, worldStateDB, publicTxSimulator, dateProvider, telemetryClient = getTelemetryClient(), log = createLogger('simulator:public-processor')){
68
+ this.db = db;
69
+ this.globalVariables = globalVariables;
70
+ this.worldStateDB = worldStateDB;
71
+ this.publicTxSimulator = publicTxSimulator;
72
+ this.dateProvider = dateProvider;
73
+ this.log = log;
74
+ this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
75
+ }
76
+ get tracer() {
77
+ return this.metrics.tracer;
78
+ }
79
+ /**
80
+ * Run each tx through the public circuit and the public kernel circuit if needed.
81
+ * @param txs - Txs to process.
82
+ * @param processedTxHandler - Handler for processed txs in the context of block building or proving.
83
+ * @returns The list of processed txs with their circuit simulation outputs.
84
+ */ async process(txs, limits = {}, validators = {}) {
85
+ const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
86
+ const { preprocessValidator, postprocessValidator, nullifierCache } = validators;
87
+ const result = [];
88
+ const failed = [];
89
+ const timer = new Timer();
90
+ let totalSizeInBytes = 0;
91
+ let returns = [];
92
+ let totalPublicGas = new Gas(0, 0);
93
+ let totalBlockGas = new Gas(0, 0);
94
+ for await (const origTx of txs){
95
+ // Only process up to the max tx limit
96
+ if (maxTransactions !== undefined && result.length >= maxTransactions) {
97
+ this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
98
+ break;
99
+ }
100
+ // Bail if we've hit the deadline
101
+ if (deadline && this.dateProvider.now() > +deadline) {
102
+ this.log.warn(`Stopping tx processing due to timeout.`);
103
+ break;
104
+ }
105
+ // Skip this tx if it'd exceed max block size
106
+ const txHash = (await origTx.getTxHash()).toString();
107
+ const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
108
+ if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
109
+ this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
110
+ txHash,
111
+ sizeInBytes: preTxSizeInBytes,
112
+ totalSizeInBytes,
113
+ maxBlockSize
114
+ });
115
+ continue;
116
+ }
117
+ // Skip this tx if its gas limit would exceed the block gas limit
118
+ const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
119
+ if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
120
+ this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
121
+ txHash,
122
+ txGasLimit,
123
+ totalBlockGas,
124
+ maxBlockGas
125
+ });
126
+ continue;
127
+ }
128
+ // The processor modifies the tx objects in place, so we need to clone them.
129
+ const tx = Tx.clone(origTx);
130
+ // We validate the tx before processing it, to avoid unnecessary work.
131
+ if (preprocessValidator) {
132
+ const result = await preprocessValidator.validateTx(tx);
133
+ const txHash = await tx.getTxHash();
134
+ if (result.result === 'invalid') {
135
+ const reason = result.reason.join(', ');
136
+ this.log.warn(`Rejecting tx ${txHash.toString()} due to pre-process validation fail: ${reason}`);
137
+ failed.push({
138
+ tx,
139
+ error: new Error(`Tx failed preprocess validation: ${reason}`)
140
+ });
141
+ returns.push(new NestedProcessReturnValues([]));
142
+ continue;
143
+ } else if (result.result === 'skipped') {
144
+ const reason = result.reason.join(', ');
145
+ this.log.warn(`Skipping tx ${txHash.toString()} due to pre-process validation: ${reason}`);
146
+ returns.push(new NestedProcessReturnValues([]));
147
+ continue;
148
+ } else {
149
+ this.log.trace(`Tx ${txHash.toString()} is valid before processing.`);
150
+ }
151
+ }
152
+ // We checkpoint the transaction here, then within the try/catch we
153
+ // 1. Revert the checkpoint if the tx fails or needs to be discarded for any reason
154
+ // 2. Commit the transaction in the finally block. Note that by using the ForkCheckpoint lifecycle only the first commit/revert takes effect
155
+ const checkpoint = await ForkCheckpoint.new(this.worldStateDB);
156
+ try {
157
+ const [processedTx, returnValues] = await this.processTx(tx, deadline);
158
+ // If the actual size of this tx would exceed block size, skip it
159
+ const txSize = processedTx.txEffect.getDASize();
160
+ if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
161
+ this.log.warn(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
162
+ txHash,
163
+ sizeInBytes: txSize,
164
+ totalSizeInBytes,
165
+ maxBlockSize
166
+ });
167
+ // Need to revert the checkpoint here and don't go any further
168
+ await checkpoint.revert();
169
+ continue;
170
+ }
171
+ // Re-validate the transaction
172
+ if (postprocessValidator) {
173
+ // Only accept processed transactions that are not double-spends,
174
+ // public functions emitting nullifiers would pass earlier check but fail here.
175
+ // Note that we're checking all nullifiers generated in the private execution twice,
176
+ // we could store the ones already checked and skip them here as an optimization.
177
+ // TODO(palla/txs): Can we get into this case? AVM validates this. We should be able to remove it.
178
+ const result = await postprocessValidator.validateTx(processedTx);
179
+ if (result.result !== 'valid') {
180
+ const reason = result.reason.join(', ');
181
+ this.log.error(`Rejecting tx ${processedTx.hash} after processing: ${reason}.`);
182
+ failed.push({
183
+ tx,
184
+ error: new Error(`Tx failed post-process validation: ${reason}`)
185
+ });
186
+ // Need to revert the checkpoint here and don't go any further
187
+ await checkpoint.revert();
188
+ continue;
189
+ } else {
190
+ this.log.trace(`Tx ${txHash.toString()} is valid post processing.`);
191
+ }
192
+ }
193
+ if (!tx.hasPublicCalls()) {
194
+ // If there are no public calls, perform all tree insertions for side effects from private
195
+ // When there are public calls, the PublicTxSimulator & AVM handle tree insertions.
196
+ await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
197
+ // Add any contracts registered/deployed in this private-only tx to the block-level cache
198
+ // (add to tx-level cache and then commit to block-level cache)
199
+ await this.worldStateDB.addNewContracts(tx);
200
+ this.worldStateDB.commitContractsForTx();
201
+ }
202
+ nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map((n)=>n.toBuffer()));
203
+ result.push(processedTx);
204
+ returns = returns.concat(returnValues);
205
+ totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
206
+ totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
207
+ totalSizeInBytes += txSize;
208
+ } catch (err) {
209
+ // Roll back state to start of TX before proceeding to next TX
210
+ await checkpoint.revert();
211
+ if (err?.name === 'PublicProcessorTimeoutError') {
212
+ this.log.warn(`Stopping tx processing due to timeout.`);
213
+ break;
214
+ }
215
+ const errorMessage = err instanceof Error ? err.message : 'Unknown error';
216
+ this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
217
+ failed.push({
218
+ tx,
219
+ error: err instanceof Error ? err : new Error(errorMessage)
220
+ });
221
+ returns.push(new NestedProcessReturnValues([]));
222
+ } finally{
223
+ // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was reverted
224
+ await checkpoint.commit();
225
+ // The tx-level contracts cache should not live on to the next tx
226
+ this.worldStateDB.clearContractsForTx();
227
+ }
228
+ }
229
+ const duration = timer.s();
230
+ const rate = duration > 0 ? totalPublicGas.l2Gas / duration : 0;
231
+ this.metrics.recordAllTxs(totalPublicGas, rate);
232
+ this.log.info(`Processed ${result.length} successful txs and ${failed.length} failed txs in ${duration}s`, {
233
+ duration,
234
+ rate,
235
+ totalPublicGas,
236
+ totalBlockGas,
237
+ totalSizeInBytes
238
+ });
239
+ return [
240
+ result,
241
+ failed,
242
+ returns
243
+ ];
244
+ }
245
+ async processTx(tx, deadline) {
246
+ const [time, [processedTx, returnValues]] = await elapsed(()=>this.processTxWithinDeadline(tx, deadline));
247
+ this.log.verbose(!tx.hasPublicCalls() ? `Processed tx ${processedTx.hash} with no public calls in ${time}ms` : `Processed tx ${processedTx.hash} with ${tx.enqueuedPublicFunctionCalls.length} public calls in ${time}ms`, {
248
+ txHash: processedTx.hash,
249
+ txFee: processedTx.txEffect.transactionFee.toBigInt(),
250
+ revertCode: processedTx.txEffect.revertCode.getCode(),
251
+ revertReason: processedTx.revertReason,
252
+ gasUsed: processedTx.gasUsed,
253
+ publicDataWriteCount: processedTx.txEffect.publicDataWrites.length,
254
+ nullifierCount: processedTx.txEffect.nullifiers.length,
255
+ noteHashCount: processedTx.txEffect.noteHashes.length,
256
+ contractClassLogCount: processedTx.txEffect.contractClassLogs.length,
257
+ publicLogCount: processedTx.txEffect.publicLogs.length,
258
+ privateLogCount: processedTx.txEffect.privateLogs.length,
259
+ l2ToL1MessageCount: processedTx.txEffect.l2ToL1Msgs.length,
260
+ durationMs: time
261
+ });
262
+ return [
263
+ processedTx,
264
+ returnValues ?? []
265
+ ];
266
+ }
267
+ async doTreeInsertionsForPrivateOnlyTx(processedTx, txValidator) {
268
+ const treeInsertionStart = process.hrtime.bigint();
269
+ // Update the state so that the next tx in the loop has the correct .startState
270
+ // NB: before this change, all .startStates were actually incorrect, but the issue was never caught because we either:
271
+ // a) had only 1 tx with public calls per block, so this loop had len 1
272
+ // b) always had a txHandler with the same db passed to it as this.db, which updated the db in buildBaseRollupHints in this loop
273
+ // To see how this ^ happens, move back to one shared db in test_context and run orchestrator_multi_public_functions.test.ts
274
+ // The below is taken from buildBaseRollupHints:
275
+ await this.db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(processedTx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
276
+ try {
277
+ await this.db.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((n)=>n.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
278
+ } catch (error) {
279
+ if (txValidator) {
280
+ // Ideally the validator has already caught this above, but just in case:
281
+ throw new Error(`Transaction ${processedTx.hash} invalid after processing public functions`);
282
+ } else {
283
+ // We have no validator and assume this call should blindly process txs with duplicates being caught later
284
+ this.log.warn(`Detected duplicate nullifier after public processing for: ${processedTx.hash}.`);
285
+ }
286
+ }
287
+ // The only public data write should be for fee payment
288
+ await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, processedTx.txEffect.publicDataWrites.map((x)=>x.toBuffer()));
289
+ const treeInsertionEnd = process.hrtime.bigint();
290
+ this.metrics.recordTreeInsertions(Number(treeInsertionEnd - treeInsertionStart) / 1_000);
291
+ }
292
+ /** Processes the given tx within deadline. Returns timeout if deadline is hit. */ async processTxWithinDeadline(tx, deadline) {
293
+ const processFn = tx.hasPublicCalls() ? ()=>this.processTxWithPublicCalls(tx) : ()=>this.processPrivateOnlyTx(tx);
294
+ if (!deadline) {
295
+ return await processFn();
296
+ }
297
+ const txHash = await tx.getTxHash();
298
+ const timeout = +deadline - this.dateProvider.now();
299
+ if (timeout <= 0) {
300
+ throw new PublicProcessorTimeoutError();
301
+ }
302
+ this.log.debug(`Processing tx ${txHash.toString()} within ${timeout}ms`, {
303
+ deadline: deadline.toISOString(),
304
+ now: new Date(this.dateProvider.now()).toISOString(),
305
+ txHash
306
+ });
307
+ return await executeTimeout(()=>processFn(), timeout, ()=>new PublicProcessorTimeoutError());
308
+ }
309
+ /**
310
+ * Creates the public data write for paying the tx fee.
311
+ * This is used in private only txs, since for txs with public calls
312
+ * the avm handles the fee payment itself.
313
+ */ async getFeePaymentPublicDataWrite(txFee, feePayer) {
314
+ const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
315
+ const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
316
+ const leafSlot = await computeFeePayerBalanceLeafSlot(feePayer);
317
+ this.log.debug(`Deducting ${txFee.toBigInt()} balance in Fee Juice for ${feePayer}`);
318
+ const balance = await this.worldStateDB.storageRead(feeJuiceAddress, balanceSlot);
319
+ if (balance.lt(txFee)) {
320
+ throw new Error(`Not enough balance for fee payer to pay for transaction (got ${balance.toBigInt()} needs ${txFee.toBigInt()})`);
321
+ }
322
+ const updatedBalance = balance.sub(txFee);
323
+ await this.worldStateDB.storageWrite(feeJuiceAddress, balanceSlot, updatedBalance);
324
+ return new PublicDataWrite(leafSlot, updatedBalance);
325
+ }
326
+ async processPrivateOnlyTx(tx) {
327
+ const gasFees = this.globalVariables.gasFees;
328
+ const transactionFee = tx.data.gasUsed.computeFee(gasFees);
329
+ const feePaymentPublicDataWrite = await this.getFeePaymentPublicDataWrite(transactionFee, tx.data.feePayer);
330
+ const processedTx = await makeProcessedTxFromPrivateOnlyTx(tx, transactionFee, feePaymentPublicDataWrite, this.globalVariables);
331
+ const siloedContractClassLogs = await tx.filterContractClassLogs(tx.data.getNonEmptyContractClassLogsHashes(), true);
332
+ this.metrics.recordClassRegistration(...siloedContractClassLogs.filter((log)=>ContractClassRegisteredEvent.isContractClassRegisteredEvent(log)).map((log)=>ContractClassRegisteredEvent.fromLog(log)));
333
+ return [
334
+ processedTx,
335
+ undefined
336
+ ];
337
+ }
338
+ async processTxWithPublicCalls(tx) {
339
+ const timer = new Timer();
340
+ const { avmProvingRequest, gasUsed, revertCode, revertReason, processedPhases } = await this.publicTxSimulator.simulate(tx);
341
+ if (!avmProvingRequest) {
342
+ this.metrics.recordFailedTx();
343
+ throw new Error('Avm proving result was not generated.');
344
+ }
345
+ processedPhases.forEach((phase)=>{
346
+ if (phase.reverted) {
347
+ this.metrics.recordRevertedPhase(phase.phase);
348
+ } else {
349
+ this.metrics.recordPhaseDuration(phase.phase, phase.durationMs);
350
+ }
351
+ });
352
+ const siloedContractClassLogs = await tx.filterContractClassLogs(tx.data.getNonEmptyContractClassLogsHashes(), true);
353
+ this.metrics.recordClassRegistration(...siloedContractClassLogs.filter((log)=>ContractClassRegisteredEvent.isContractClassRegisteredEvent(log)).map((log)=>ContractClassRegisteredEvent.fromLog(log)));
354
+ const phaseCount = processedPhases.length;
355
+ const durationMs = timer.ms();
356
+ this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
357
+ const processedTx = await makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
358
+ const returnValues = processedPhases.find(({ phase })=>phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
359
+ return [
360
+ processedTx,
361
+ returnValues
362
+ ];
363
+ }
364
+ }
365
+ _ts_decorate([
366
+ trackSpan('PublicProcessor.processTx', async (tx)=>({
367
+ [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
368
+ }))
369
+ ], PublicProcessor.prototype, "processTx", null);
370
+ _ts_decorate([
371
+ trackSpan('PublicProcessor.processPrivateOnlyTx', async (tx)=>({
372
+ [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
373
+ }))
374
+ ], PublicProcessor.prototype, "processPrivateOnlyTx", null);
375
+ _ts_decorate([
376
+ trackSpan('PublicProcessor.processTxWithPublicCalls', async (tx)=>({
377
+ [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
378
+ }))
379
+ ], PublicProcessor.prototype, "processTxWithPublicCalls", null);
@@ -0,0 +1,27 @@
1
+ import type { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
2
+ import type { Gas } from '@aztec/stdlib/gas';
3
+ import type { TxExecutionPhase } from '@aztec/stdlib/tx';
4
+ import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
5
+ export declare class PublicProcessorMetrics {
6
+ readonly tracer: Tracer;
7
+ private txDuration;
8
+ private txCount;
9
+ private txPhaseCount;
10
+ private phaseDuration;
11
+ private phaseCount;
12
+ private bytecodeDeployed;
13
+ private totalGas;
14
+ private totalGasHistogram;
15
+ private gasRate;
16
+ private txGas;
17
+ private treeInsertionDuration;
18
+ constructor(client: TelemetryClient, name?: string);
19
+ recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number): void;
20
+ recordTx(phaseCount: number, durationMs: number, gasUsed: Gas): void;
21
+ recordAllTxs(totalGas: Gas, gasRate: number): void;
22
+ recordFailedTx(): void;
23
+ recordRevertedPhase(phaseName: TxExecutionPhase): void;
24
+ recordClassRegistration(...events: ContractClassRegisteredEvent[]): void;
25
+ recordTreeInsertions(durationUs: number): void;
26
+ }
27
+ //# sourceMappingURL=public_processor_metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public_processor_metrics.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,sBAAsB;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAgB;IAEpC,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,KAAK,CAAY;IAEzB,OAAO,CAAC,qBAAqB,CAAY;gBAE7B,MAAM,EAAE,eAAe,EAAE,IAAI,SAAoB;IA4D7D,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM;IAKnE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAc7D,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAkB3C,cAAc;IAMd,mBAAmB,CAAC,SAAS,EAAE,gBAAgB;IAI/C,uBAAuB,CAAC,GAAG,MAAM,EAAE,4BAA4B,EAAE;IAWjE,oBAAoB,CAAC,UAAU,EAAE,MAAM;CAGxC"}
@@ -0,0 +1,125 @@
1
+ import { Attributes, Metrics, ValueType } from '@aztec/telemetry-client';
2
+ export class PublicProcessorMetrics {
3
+ tracer;
4
+ txDuration;
5
+ txCount;
6
+ txPhaseCount;
7
+ phaseDuration;
8
+ phaseCount;
9
+ bytecodeDeployed;
10
+ totalGas;
11
+ totalGasHistogram;
12
+ gasRate;
13
+ txGas;
14
+ treeInsertionDuration;
15
+ constructor(client, name = 'PublicProcessor'){
16
+ this.tracer = client.getTracer(name);
17
+ const meter = client.getMeter(name);
18
+ this.txDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_DURATION, {
19
+ description: 'How long it takes to process a transaction',
20
+ unit: 'ms',
21
+ valueType: ValueType.INT
22
+ });
23
+ this.txCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_COUNT, {
24
+ description: 'Number of transactions processed'
25
+ });
26
+ this.txPhaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_TX_PHASE_COUNT, {
27
+ description: 'Number of phases processed'
28
+ });
29
+ this.phaseDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_PHASE_DURATION, {
30
+ description: 'How long it takes to process a phase',
31
+ unit: 'ms',
32
+ valueType: ValueType.INT
33
+ });
34
+ this.phaseCount = meter.createUpDownCounter(Metrics.PUBLIC_PROCESSOR_PHASE_COUNT, {
35
+ description: 'Number of failed phases'
36
+ });
37
+ this.bytecodeDeployed = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_DEPLOY_BYTECODE_SIZE, {
38
+ description: 'Size of deployed bytecode',
39
+ unit: 'By'
40
+ });
41
+ this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS, {
42
+ description: 'Total gas used in block',
43
+ unit: 'gas'
44
+ });
45
+ this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM, {
46
+ description: 'Total gas used in block as histogram',
47
+ unit: 'gas/block'
48
+ });
49
+ this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS, {
50
+ description: 'Gas used in transaction',
51
+ unit: 'gas/tx'
52
+ });
53
+ this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE, {
54
+ description: 'L2 gas per second for complete block',
55
+ unit: 'gas/s'
56
+ });
57
+ this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION, {
58
+ description: 'How long it takes for tree insertion',
59
+ unit: 'us',
60
+ valueType: ValueType.INT
61
+ });
62
+ }
63
+ recordPhaseDuration(phaseName, durationMs) {
64
+ this.phaseCount.add(1, {
65
+ [Attributes.TX_PHASE_NAME]: phaseName,
66
+ [Attributes.OK]: true
67
+ });
68
+ this.phaseDuration.record(Math.ceil(durationMs), {
69
+ [Attributes.TX_PHASE_NAME]: phaseName
70
+ });
71
+ }
72
+ recordTx(phaseCount, durationMs, gasUsed) {
73
+ this.txPhaseCount.add(phaseCount);
74
+ this.txDuration.record(Math.ceil(durationMs));
75
+ this.txCount.add(1, {
76
+ [Attributes.OK]: true
77
+ });
78
+ this.txGas.record(gasUsed.daGas, {
79
+ [Attributes.GAS_DIMENSION]: 'DA'
80
+ });
81
+ this.txGas.record(gasUsed.l2Gas, {
82
+ [Attributes.GAS_DIMENSION]: 'L2'
83
+ });
84
+ }
85
+ recordAllTxs(totalGas, gasRate) {
86
+ this.totalGas.record(totalGas.daGas, {
87
+ [Attributes.GAS_DIMENSION]: 'DA'
88
+ });
89
+ this.totalGas.record(totalGas.l2Gas, {
90
+ [Attributes.GAS_DIMENSION]: 'L2'
91
+ });
92
+ this.gasRate.record(gasRate, {
93
+ [Attributes.GAS_DIMENSION]: 'L2'
94
+ });
95
+ this.totalGasHistogram.record(totalGas.daGas, {
96
+ [Attributes.GAS_DIMENSION]: 'DA'
97
+ });
98
+ this.totalGasHistogram.record(totalGas.l2Gas, {
99
+ [Attributes.GAS_DIMENSION]: 'L2'
100
+ });
101
+ }
102
+ recordFailedTx() {
103
+ this.txCount.add(1, {
104
+ [Attributes.OK]: false
105
+ });
106
+ }
107
+ recordRevertedPhase(phaseName) {
108
+ this.phaseCount.add(1, {
109
+ [Attributes.TX_PHASE_NAME]: phaseName,
110
+ [Attributes.OK]: false
111
+ });
112
+ }
113
+ recordClassRegistration(...events) {
114
+ let totalBytecode = 0;
115
+ for (const event of events){
116
+ totalBytecode += event.packedPublicBytecode.length;
117
+ }
118
+ if (totalBytecode > 0) {
119
+ this.bytecodeDeployed.record(totalBytecode);
120
+ }
121
+ }
122
+ recordTreeInsertions(durationUs) {
123
+ this.treeInsertionDuration.record(Math.ceil(durationUs));
124
+ }
125
+ }
@@ -0,0 +1,137 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { type AvmProvingRequest, RevertCode } from '@aztec/stdlib/avm';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { SimulationError } from '@aztec/stdlib/errors';
5
+ import { Gas, GasSettings } from '@aztec/stdlib/gas';
6
+ import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
7
+ import { type PrivateToPublicAccumulatedData, PublicCallRequest } from '@aztec/stdlib/kernel';
8
+ import { type GlobalVariables, type PublicExecutionRequest, type StateReference, type Tx, TxExecutionPhase, type TxHash } from '@aztec/stdlib/tx';
9
+ import { AvmPersistableStateManager } from '../avm/index.js';
10
+ import type { WorldStateDB } from '../public_db_sources.js';
11
+ import { SideEffectTrace } from '../side_effect_trace.js';
12
+ /**
13
+ * The transaction-level context for public execution.
14
+ */
15
+ export declare class PublicTxContext {
16
+ readonly txHash: TxHash;
17
+ readonly state: PhaseStateManager;
18
+ private readonly globalVariables;
19
+ private readonly startStateReference;
20
+ private readonly gasSettings;
21
+ private readonly gasUsedByPrivate;
22
+ private readonly gasAllocatedToPublic;
23
+ private readonly setupCallRequests;
24
+ private readonly appLogicCallRequests;
25
+ private readonly teardownCallRequests;
26
+ private readonly setupExecutionRequests;
27
+ private readonly appLogicExecutionRequests;
28
+ private readonly teardownExecutionRequests;
29
+ readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData;
30
+ readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData;
31
+ readonly feePayer: AztecAddress;
32
+ trace: SideEffectTrace;
33
+ private log;
34
+ private gasUsedByPublic;
35
+ teardownGasUsed: Gas;
36
+ private halted;
37
+ private revertCode;
38
+ revertReason: SimulationError | undefined;
39
+ avmProvingRequest: AvmProvingRequest | undefined;
40
+ constructor(txHash: TxHash, state: PhaseStateManager, globalVariables: GlobalVariables, startStateReference: StateReference, gasSettings: GasSettings, gasUsedByPrivate: Gas, gasAllocatedToPublic: Gas, setupCallRequests: PublicCallRequest[], appLogicCallRequests: PublicCallRequest[], teardownCallRequests: PublicCallRequest[], setupExecutionRequests: PublicExecutionRequest[], appLogicExecutionRequests: PublicExecutionRequest[], teardownExecutionRequests: PublicExecutionRequest[], nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData, revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData, feePayer: AztecAddress, trace: SideEffectTrace);
41
+ static create(db: MerkleTreeReadOperations, worldStateDB: WorldStateDB, tx: Tx, globalVariables: GlobalVariables, doMerkleOperations: boolean): Promise<PublicTxContext>;
42
+ /**
43
+ * Signal that the entire transaction execution is done.
44
+ * All phases have been processed.
45
+ * Actual transaction fee and actual total consumed gas can now be queried.
46
+ */
47
+ halt(): Promise<void>;
48
+ /**
49
+ * Revert execution a phase. Populate revertReason & revertCode.
50
+ * If in setup, throw an error (transaction will be thrown out).
51
+ * NOTE: this does not "halt" the entire transaction execution.
52
+ */
53
+ revert(phase: TxExecutionPhase, revertReason?: SimulationError | undefined, culprit?: string): void;
54
+ /**
55
+ * Get the revert code.
56
+ * @returns The revert code.
57
+ */
58
+ getFinalRevertCode(): RevertCode;
59
+ /**
60
+ * Are there any call requests for the speciiied phase?
61
+ */
62
+ hasPhase(phase: TxExecutionPhase): boolean;
63
+ /**
64
+ * Get the call requests for the specified phase (including args hashes).
65
+ */
66
+ getCallRequestsForPhase(phase: TxExecutionPhase): PublicCallRequest[];
67
+ /**
68
+ * Get the call requests for the specified phase (including actual args).
69
+ */
70
+ getExecutionRequestsForPhase(phase: TxExecutionPhase): PublicExecutionRequest[];
71
+ /**
72
+ * How much gas is left as of the specified phase?
73
+ */
74
+ getGasLeftAtPhase(phase: TxExecutionPhase): Gas;
75
+ /**
76
+ * Consume gas. Track gas for teardown phase separately.
77
+ */
78
+ consumeGas(phase: TxExecutionPhase, gas: Gas): void;
79
+ /**
80
+ * The gasUsed by public and private,
81
+ * as if the entire teardown gas limit was consumed.
82
+ */
83
+ getTotalGasUsed(): Gas;
84
+ /**
85
+ * Compute the gas used using the actual gas used during teardown instead
86
+ * of the teardown gas limit.
87
+ * Note that this.gasUsed is initialized from private's gasUsed which includes
88
+ * teardown gas limit.
89
+ */
90
+ getActualGasUsed(): Gas;
91
+ /**
92
+ * Compute the public gas used using the actual gas used during teardown instead
93
+ * of the teardown gas limit.
94
+ */
95
+ getActualPublicGasUsed(): Gas;
96
+ /**
97
+ * Get the transaction fee as is available to the specified phase.
98
+ * Only teardown should have access to the actual transaction fee.
99
+ */
100
+ getTransactionFee(phase: TxExecutionPhase): Fr;
101
+ /**
102
+ * Compute the transaction fee.
103
+ * Should only be called during or after teardown.
104
+ */
105
+ private getTransactionFeeUnsafe;
106
+ /**
107
+ * Generate the public inputs for the AVM circuit.
108
+ */
109
+ private generateAvmCircuitPublicInputs;
110
+ /**
111
+ * Generate the proving request for the AVM circuit.
112
+ */
113
+ generateProvingRequest(endStateReference: StateReference): Promise<AvmProvingRequest>;
114
+ }
115
+ /**
116
+ * Thin wrapper around the state manager to handle forking and merging for phases.
117
+ *
118
+ * This lets us keep track of whether the state has already been forked
119
+ * so that we can conditionally fork at the start of a phase.
120
+ *
121
+ * There is a state manager that lives at the level of the entire transaction,
122
+ * but for app logic and teardown the active state manager will be a fork of the
123
+ * transaction level one.
124
+ */
125
+ declare class PhaseStateManager {
126
+ private readonly txStateManager;
127
+ private log;
128
+ private currentlyActiveStateManager;
129
+ constructor(txStateManager: AvmPersistableStateManager);
130
+ fork(): Promise<void>;
131
+ getActiveStateManager(): AvmPersistableStateManager;
132
+ isForked(): boolean;
133
+ mergeForkedState(): Promise<void>;
134
+ discardForkedState(): Promise<void>;
135
+ }
136
+ export {};
137
+ //# sourceMappingURL=public_tx_context.d.ts.map