@aztec/simulator 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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 (378) hide show
  1. package/README.md +4 -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/private/acvm/acvm.d.ts +4 -2
  6. package/dest/private/acvm/acvm.d.ts.map +1 -1
  7. package/dest/private/acvm/acvm.js +4 -3
  8. package/dest/private/acvm_native.d.ts +5 -3
  9. package/dest/private/acvm_native.d.ts.map +1 -1
  10. package/dest/private/acvm_native.js +8 -6
  11. package/dest/private/acvm_wasm.d.ts +4 -3
  12. package/dest/private/acvm_wasm.d.ts.map +1 -1
  13. package/dest/private/acvm_wasm.js +7 -5
  14. package/dest/private/circuit_recording/circuit_recorder.d.ts +39 -25
  15. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/circuit_recorder.js +70 -72
  17. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +9 -20
  18. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  19. package/dest/private/circuit_recording/file_circuit_recorder.js +39 -43
  20. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  21. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  22. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  23. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  24. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  25. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  26. package/dest/private/factory.d.ts +3 -3
  27. package/dest/private/factory.d.ts.map +1 -1
  28. package/dest/private/factory.js +7 -4
  29. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  30. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  31. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  32. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +2 -1
  33. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  34. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
  35. package/dest/public/avm/testing/utils.d.ts +32 -0
  36. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  37. package/dest/public/avm/{fixtures → testing}/utils.js +4 -34
  38. package/dest/public/avm_simulator.d.ts +28 -0
  39. package/dest/public/avm_simulator.d.ts.map +1 -0
  40. package/dest/public/avm_simulator.js +4 -0
  41. package/dest/public/avm_simulator_pool.d.ts +45 -0
  42. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  43. package/dest/public/avm_simulator_pool.js +197 -0
  44. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  45. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  46. package/dest/public/cdb/generated/api_types.js +314 -0
  47. package/dest/public/cdb/generated/server.d.ts +26 -0
  48. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  49. package/dest/public/cdb/generated/server.js +135 -0
  50. package/dest/public/cdb_ipc_server.d.ts +33 -0
  51. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  52. package/dest/public/cdb_ipc_server.js +153 -0
  53. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  54. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  55. package/dest/public/contracts_db_checkpoint.js +1 -1
  56. package/dest/public/executor_metrics.d.ts +1 -1
  57. package/dest/public/executor_metrics.d.ts.map +1 -1
  58. package/dest/public/executor_metrics.js +7 -2
  59. package/dest/public/fixtures/amm_test.js +4 -4
  60. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  61. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  62. package/dest/public/fixtures/bulk_test.js +33 -6
  63. package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
  64. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  65. package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
  66. package/dest/public/fixtures/index.d.ts +2 -4
  67. package/dest/public/fixtures/index.d.ts.map +1 -1
  68. package/dest/public/fixtures/index.js +1 -3
  69. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  70. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  71. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  72. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -7
  73. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  74. package/dest/public/fixtures/public_tx_simulation_tester.js +32 -15
  75. package/dest/public/fixtures/simple_contract_data_source.js +1 -1
  76. package/dest/public/fixtures/token_test.js +3 -3
  77. package/dest/public/fixtures/utils.d.ts +2 -2
  78. package/dest/public/fixtures/utils.d.ts.map +1 -1
  79. package/dest/public/fixtures/utils.js +21 -20
  80. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +11 -4
  81. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  82. package/dest/public/fuzzing/avm_fuzzer_simulator.js +24 -10
  83. package/dest/public/fuzzing/avm_simulator_bin.js +11 -8
  84. package/dest/public/index.d.ts +5 -2
  85. package/dest/public/index.d.ts.map +1 -1
  86. package/dest/public/index.js +2 -1
  87. package/dest/public/public_db_sources.d.ts +9 -5
  88. package/dest/public/public_db_sources.d.ts.map +1 -1
  89. package/dest/public/public_db_sources.js +20 -14
  90. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -7
  91. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  92. package/dest/public/public_processor/guarded_merkle_tree.js +8 -5
  93. package/dest/public/public_processor/public_processor.d.ts +17 -8
  94. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  95. package/dest/public/public_processor/public_processor.js +119 -77
  96. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  97. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  98. package/dest/public/public_processor/public_processor_metrics.js +28 -4
  99. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  100. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  101. package/dest/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.js → dumping_public_tx_simulator.js} +10 -23
  102. package/dest/public/public_tx_simulator/factories.d.ts +9 -8
  103. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  104. package/dest/public/public_tx_simulator/factories.js +9 -9
  105. package/dest/public/public_tx_simulator/index.d.ts +4 -6
  106. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  107. package/dest/public/public_tx_simulator/index.js +2 -4
  108. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +43 -71
  109. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  110. package/dest/public/public_tx_simulator/public_tx_simulator.js +99 -316
  111. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  112. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  113. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  114. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +5 -5
  115. package/dest/public/test_executor_metrics.d.ts +3 -2
  116. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  117. package/dest/public/test_executor_metrics.js +2 -2
  118. package/package.json +22 -19
  119. package/src/client.ts +0 -2
  120. package/src/private/acvm/acvm.ts +4 -3
  121. package/src/private/acvm_native.ts +11 -5
  122. package/src/private/acvm_wasm.ts +11 -4
  123. package/src/private/circuit_recording/circuit_recorder.ts +89 -81
  124. package/src/private/circuit_recording/file_circuit_recorder.ts +45 -50
  125. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  126. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  127. package/src/private/factory.ts +7 -4
  128. package/src/public/avm/testing/account_proof.json +553 -0
  129. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  130. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
  131. package/src/public/avm/{fixtures → testing}/utils.ts +4 -40
  132. package/src/public/avm_simulator.ts +29 -0
  133. package/src/public/avm_simulator_pool.ts +226 -0
  134. package/src/public/cdb/generated/api_types.ts +457 -0
  135. package/src/public/cdb/generated/server.ts +109 -0
  136. package/src/public/cdb_ipc_server.ts +197 -0
  137. package/src/public/contracts_db_checkpoint.ts +1 -1
  138. package/src/public/executor_metrics.ts +4 -1
  139. package/src/public/fixtures/amm_test.ts +4 -4
  140. package/src/public/fixtures/bulk_test.ts +31 -6
  141. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  142. package/src/public/fixtures/index.ts +1 -3
  143. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  144. package/src/public/fixtures/public_tx_simulation_tester.ts +45 -18
  145. package/src/public/fixtures/simple_contract_data_source.ts +1 -1
  146. package/src/public/fixtures/token_test.ts +3 -3
  147. package/src/public/fixtures/utils.ts +23 -24
  148. package/src/public/fuzzing/avm_fuzzer_simulator.ts +26 -11
  149. package/src/public/fuzzing/avm_simulator_bin.ts +14 -6
  150. package/src/public/index.ts +7 -3
  151. package/src/public/public_db_sources.ts +36 -19
  152. package/src/public/public_processor/guarded_merkle_tree.ts +11 -8
  153. package/src/public/public_processor/public_processor.ts +166 -97
  154. package/src/public/public_processor/public_processor_metrics.ts +22 -4
  155. package/src/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.ts → dumping_public_tx_simulator.ts} +17 -31
  156. package/src/public/public_tx_simulator/factories.ts +31 -11
  157. package/src/public/public_tx_simulator/index.ts +6 -5
  158. package/src/public/public_tx_simulator/public_tx_simulator.ts +142 -470
  159. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  160. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +5 -5
  161. package/src/public/test_executor_metrics.ts +3 -3
  162. package/dest/public/avm/avm_context.d.ts +0 -41
  163. package/dest/public/avm/avm_context.d.ts.map +0 -1
  164. package/dest/public/avm/avm_context.js +0 -44
  165. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  166. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  167. package/dest/public/avm/avm_contract_call_result.js +0 -54
  168. package/dest/public/avm/avm_execution_environment.d.ts +0 -23
  169. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  170. package/dest/public/avm/avm_execution_environment.js +0 -33
  171. package/dest/public/avm/avm_gas.d.ts +0 -44
  172. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  173. package/dest/public/avm/avm_gas.js +0 -195
  174. package/dest/public/avm/avm_machine_state.d.ts +0 -97
  175. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  176. package/dest/public/avm/avm_machine_state.js +0 -109
  177. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  178. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  179. package/dest/public/avm/avm_memory_types.js +0 -351
  180. package/dest/public/avm/avm_simulator.d.ts +0 -40
  181. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  182. package/dest/public/avm/avm_simulator.js +0 -191
  183. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  184. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  185. package/dest/public/avm/avm_simulator_interface.js +0 -3
  186. package/dest/public/avm/errors.d.ts +0 -104
  187. package/dest/public/avm/errors.d.ts.map +0 -1
  188. package/dest/public/avm/errors.js +0 -141
  189. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  190. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  191. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -83
  192. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  193. package/dest/public/avm/fixtures/initializers.d.ts +0 -42
  194. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  195. package/dest/public/avm/fixtures/initializers.js +0 -44
  196. package/dest/public/avm/fixtures/utils.d.ts +0 -39
  197. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  198. package/dest/public/avm/index.d.ts +0 -2
  199. package/dest/public/avm/index.d.ts.map +0 -1
  200. package/dest/public/avm/index.js +0 -1
  201. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -75
  202. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  203. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  204. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  205. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  206. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  207. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -49
  208. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  209. package/dest/public/avm/opcodes/arithmetic.js +0 -97
  210. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  211. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  212. package/dest/public/avm/opcodes/bitwise.js +0 -99
  213. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  214. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  215. package/dest/public/avm/opcodes/comparators.js +0 -43
  216. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  217. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  218. package/dest/public/avm/opcodes/contract.js +0 -65
  219. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  220. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  221. package/dest/public/avm/opcodes/control_flow.js +0 -107
  222. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  223. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  224. package/dest/public/avm/opcodes/conversion.js +0 -333
  225. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  226. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  227. package/dest/public/avm/opcodes/ec_add.js +0 -93
  228. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  229. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  230. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  231. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  232. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  233. package/dest/public/avm/opcodes/external_calls.js +0 -210
  234. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  235. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  236. package/dest/public/avm/opcodes/hashing.js +0 -119
  237. package/dest/public/avm/opcodes/index.d.ts +0 -16
  238. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  239. package/dest/public/avm/opcodes/index.js +0 -15
  240. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  241. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  242. package/dest/public/avm/opcodes/instruction.js +0 -95
  243. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  244. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  245. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  246. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  247. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  248. package/dest/public/avm/opcodes/memory.js +0 -257
  249. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  250. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  251. package/dest/public/avm/opcodes/misc.js +0 -73
  252. package/dest/public/avm/opcodes/storage.d.ts +0 -24
  253. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  254. package/dest/public/avm/opcodes/storage.js +0 -68
  255. package/dest/public/avm/revert_reason.d.ts +0 -18
  256. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  257. package/dest/public/avm/revert_reason.js +0 -39
  258. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  259. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  260. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  261. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  262. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  263. package/dest/public/avm/serialization/bytecode_serialization.js +0 -336
  264. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  265. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  266. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  267. package/dest/public/avm/test_utils.d.ts +0 -15
  268. package/dest/public/avm/test_utils.d.ts.map +0 -1
  269. package/dest/public/avm/test_utils.js +0 -44
  270. package/dest/public/debug_fn_name.d.ts +0 -18
  271. package/dest/public/debug_fn_name.d.ts.map +0 -1
  272. package/dest/public/debug_fn_name.js +0 -35
  273. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -12
  274. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  275. package/dest/public/fixtures/custom_bytecode_tests.js +0 -174
  276. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -4
  277. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  278. package/dest/public/fixtures/minimal_public_tx.js +0 -19
  279. package/dest/public/fixtures/opcode_spammer.d.ts +0 -123
  280. package/dest/public/fixtures/opcode_spammer.d.ts.map +0 -1
  281. package/dest/public/fixtures/opcode_spammer.js +0 -1681
  282. package/dest/public/hinting_db_sources.d.ts +0 -80
  283. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  284. package/dest/public/hinting_db_sources.js +0 -355
  285. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -18
  286. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
  287. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -98
  288. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -53
  289. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  290. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -132
  291. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +0 -42
  292. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +0 -1
  293. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +0 -86
  294. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +0 -30
  295. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +0 -1
  296. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +0 -171
  297. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +0 -22
  298. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +0 -1
  299. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -31
  300. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  301. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  302. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -130
  303. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  304. package/dest/public/public_tx_simulator/public_tx_context.js +0 -300
  305. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  306. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  307. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -415
  308. package/dest/public/side_effect_trace.d.ts +0 -87
  309. package/dest/public/side_effect_trace.d.ts.map +0 -1
  310. package/dest/public/side_effect_trace.js +0 -199
  311. package/dest/public/side_effect_trace_interface.d.ts +0 -22
  312. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  313. package/dest/public/side_effect_trace_interface.js +0 -1
  314. package/dest/public/state_manager/index.d.ts +0 -2
  315. package/dest/public/state_manager/index.d.ts.map +0 -1
  316. package/dest/public/state_manager/index.js +0 -1
  317. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  318. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  319. package/dest/public/state_manager/nullifiers.js +0 -92
  320. package/dest/public/state_manager/public_storage.d.ts +0 -66
  321. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  322. package/dest/public/state_manager/public_storage.js +0 -145
  323. package/dest/public/state_manager/state_manager.d.ts +0 -164
  324. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  325. package/dest/public/state_manager/state_manager.js +0 -395
  326. package/src/public/avm/avm_context.ts +0 -61
  327. package/src/public/avm/avm_contract_call_result.ts +0 -67
  328. package/src/public/avm/avm_execution_environment.ts +0 -46
  329. package/src/public/avm/avm_gas.ts +0 -183
  330. package/src/public/avm/avm_machine_state.ts +0 -169
  331. package/src/public/avm/avm_memory_types.ts +0 -436
  332. package/src/public/avm/avm_simulator.ts +0 -276
  333. package/src/public/avm/avm_simulator_interface.ts +0 -8
  334. package/src/public/avm/errors.ts +0 -177
  335. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -116
  336. package/src/public/avm/fixtures/initializers.ts +0 -102
  337. package/src/public/avm/index.ts +0 -1
  338. package/src/public/avm/opcodes/accrued_substate.ts +0 -288
  339. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  340. package/src/public/avm/opcodes/arithmetic.ts +0 -129
  341. package/src/public/avm/opcodes/bitwise.ts +0 -113
  342. package/src/public/avm/opcodes/comparators.ts +0 -55
  343. package/src/public/avm/opcodes/contract.ts +0 -75
  344. package/src/public/avm/opcodes/control_flow.ts +0 -123
  345. package/src/public/avm/opcodes/conversion.ts +0 -104
  346. package/src/public/avm/opcodes/ec_add.ts +0 -105
  347. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  348. package/src/public/avm/opcodes/external_calls.ts +0 -261
  349. package/src/public/avm/opcodes/hashing.ts +0 -151
  350. package/src/public/avm/opcodes/index.ts +0 -15
  351. package/src/public/avm/opcodes/instruction.ts +0 -136
  352. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  353. package/src/public/avm/opcodes/memory.ts +0 -293
  354. package/src/public/avm/opcodes/misc.ts +0 -102
  355. package/src/public/avm/opcodes/storage.ts +0 -87
  356. package/src/public/avm/revert_reason.ts +0 -58
  357. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  358. package/src/public/avm/serialization/bytecode_serialization.ts +0 -215
  359. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  360. package/src/public/avm/test_utils.ts +0 -64
  361. package/src/public/debug_fn_name.ts +0 -50
  362. package/src/public/fixtures/custom_bytecode_tests.ts +0 -228
  363. package/src/public/fixtures/minimal_public_tx.ts +0 -26
  364. package/src/public/fixtures/opcode_spammer.ts +0 -1725
  365. package/src/public/hinting_db_sources.ts +0 -607
  366. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -121
  367. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -208
  368. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +0 -132
  369. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +0 -237
  370. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -105
  371. package/src/public/public_tx_simulator/public_tx_context.ts +0 -477
  372. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  373. package/src/public/side_effect_trace.ts +0 -290
  374. package/src/public/side_effect_trace_interface.ts +0 -28
  375. package/src/public/state_manager/index.ts +0 -1
  376. package/src/public/state_manager/nullifiers.ts +0 -103
  377. package/src/public/state_manager/public_storage.ts +0 -174
  378. package/src/public/state_manager/state_manager.ts +0 -546
@@ -1,164 +0,0 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type LogLevel } from '@aztec/foundation/log';
3
- import { FunctionSelector } from '@aztec/stdlib/abi';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { SerializableContractInstance } from '@aztec/stdlib/contract';
6
- import type { DebugLog } from '@aztec/stdlib/logs';
7
- import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
8
- import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import type { TreeSnapshots } from '@aztec/stdlib/tx';
10
- import type { UInt64 } from '@aztec/stdlib/types';
11
- import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
12
- import type { PublicContractsDBInterface } from '../db_interfaces.js';
13
- import type { PublicTreesDB } from '../public_db_sources.js';
14
- import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
15
- import { NullifierManager } from './nullifiers.js';
16
- import { PublicStorage } from './public_storage.js';
17
- /**
18
- * A class to manage persistable AVM state for contract calls.
19
- * Maintains a cache of the current world state,
20
- * a trace of all side effects.
21
- *
22
- * The simulator should make any world state / tree queries through this object.
23
- *
24
- * Manages merging of successful/reverted child state into current state.
25
- */
26
- export declare class PublicPersistableStateManager {
27
- private readonly treesDB;
28
- private readonly contractsDB;
29
- private readonly trace;
30
- private readonly firstNullifier;
31
- private readonly timestamp;
32
- private readonly doMerkleOperations;
33
- private readonly publicStorage;
34
- private readonly nullifiers;
35
- private readonly log;
36
- /** Make sure a forked state is never merged twice. */
37
- private alreadyMergedIntoParent;
38
- constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, trace: PublicSideEffectTraceInterface, firstNullifier: Fr, timestamp: UInt64, doMerkleOperations?: boolean, publicStorage?: PublicStorage, nullifiers?: NullifierManager);
39
- /**
40
- * Create a new state manager
41
- */
42
- static create(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, trace: PublicSideEffectTraceInterface, firstNullifier: Fr, timestamp: UInt64): PublicPersistableStateManager;
43
- /**
44
- * Create a new state manager forked from this one
45
- */
46
- fork(): Promise<PublicPersistableStateManager>;
47
- /**
48
- * Accept forked world state modifications & traced side effects / hints
49
- */
50
- merge(forkedState: PublicPersistableStateManager): Promise<void>;
51
- /**
52
- * Reject forked world state modifications & traced side effects, keep traced hints
53
- */
54
- reject(forkedState: PublicPersistableStateManager): Promise<void>;
55
- private _merge;
56
- /**
57
- * Write to public storage, journal/trace the write.
58
- *
59
- * @param contractAddress - the address of the contract whose storage is being written to
60
- * @param slot - the slot in the contract's storage being written to
61
- * @param value - the value being written to the slot
62
- */
63
- writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr, protocolWrite?: boolean): Promise<void>;
64
- isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean;
65
- /**
66
- * Read from public storage.
67
- *
68
- * @param contractAddress - the address of the contract whose storage is being read from
69
- * @param slot - the slot in the contract's storage being read from
70
- * @returns the latest value written to slot, or 0 if never written to before
71
- */
72
- readStorage(contractAddress: AztecAddress, slot: Fr): Promise<Fr>;
73
- /**
74
- * Check if a note hash exists at the given leaf index, trace the check.
75
- *
76
- * @param contractAddress - the address of the contract whose storage is being read from
77
- * @param noteHash - the unsiloed note hash being checked
78
- * @param leafIndex - the leaf index being checked
79
- * @returns true if the note hash exists at the given leaf index, false otherwise
80
- */
81
- checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: bigint): Promise<boolean>;
82
- /**
83
- * Write a raw note hash, silo it and make it unique, then trace the write.
84
- * @param noteHash - the unsiloed note hash to write
85
- */
86
- writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): Promise<void>;
87
- /**
88
- * Write a note hash, make it unique, trace the write.
89
- * @param siloedNoteHash - the non unique note hash to write
90
- */
91
- writeSiloedNoteHash(siloedNoteHash: Fr): Promise<void>;
92
- /**
93
- * Write a note hash, trace the write.
94
- * @param uniqueNoteHash - the siloed unique hash to write
95
- */
96
- writeUniqueNoteHash(uniqueNoteHash: Fr): Promise<void>;
97
- /**
98
- * Check if a nullifier exists, trace the check.
99
- * @param contractAddress - address of the contract that the nullifier is associated with
100
- * @param nullifier - the unsiloed nullifier to check
101
- * @returns exists - whether the nullifier exists in the nullifier set
102
- */
103
- checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise<boolean>;
104
- /**
105
- * Write a nullifier to the nullifier set, trace the write.
106
- * @param contractAddress - address of the contract that the nullifier is associated with
107
- * @param nullifier - the unsiloed nullifier to write
108
- */
109
- writeNullifier(contractAddress: AztecAddress, nullifier: Fr): Promise<void>;
110
- /**
111
- * Write a nullifier to the nullifier set, trace the write.
112
- * @param siloedNullifier - the siloed nullifier to write
113
- */
114
- writeSiloedNullifier(siloedNullifier: Fr): Promise<void>;
115
- /**
116
- * Check if an L1 to L2 message exists, trace the check.
117
- * @param msgHash - the message hash to check existence of
118
- * @param msgLeafIndex - the message leaf index to use in the check
119
- * @returns exists - whether the message exists in the L1 to L2 Messages tree
120
- */
121
- checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean>;
122
- /**
123
- * Write an L2 to L1 message.
124
- * @param contractAddress - L2 contract address that created this message
125
- * @param recipient - L1 contract address to send the message to.
126
- * @param content - Message content.
127
- */
128
- writeL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr): void;
129
- /**
130
- * Write a scoped L2 to L1 message.
131
- * @param l2ToL1Message - The L2 to L1 message to write.
132
- */
133
- writeScopedL2ToL1Message(l2ToL1Message: ScopedL2ToL1Message): void;
134
- writeDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]): void;
135
- writeDebugLogMemoryReads(memoryReads: number): void;
136
- getDebugLogMemoryReads(): number;
137
- getLogs(): DebugLog[];
138
- /**
139
- * Write a public log
140
- * @param contractAddress - address of the contract that emitted the log
141
- * @param log - log contents
142
- */
143
- writePublicLog(contractAddress: AztecAddress, log: Fr[]): void;
144
- /**
145
- * Get a contract instance.
146
- * @param contractAddress - address of the contract instance to retrieve.
147
- * @returns the contract instance or undefined if it does not exist.
148
- */
149
- getContractInstance(contractAddress: AztecAddress): Promise<SerializableContractInstance | undefined>;
150
- private checkContractUpdateInformation;
151
- private getContractClass;
152
- /**
153
- * Get a contract's bytecode from the contracts DB, also trace the contract class and instance indirectly.
154
- */
155
- getBytecode(contractAddress: AztecAddress): Promise<Buffer | undefined>;
156
- getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string>;
157
- getPublicFunctionSelectorAndName(avmEnvironment: AvmExecutionEnvironment): Promise<{
158
- functionSelector?: FunctionSelector;
159
- functionName?: string;
160
- }>;
161
- padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void>;
162
- getTreeSnapshots(): Promise<TreeSnapshots>;
163
- }
164
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGVfbWFuYWdlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3B1YmxpYy9zdGF0ZV9tYW5hZ2VyL3N0YXRlX21hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sRUFBRSxLQUFLLFFBQVEsRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUVwRSxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNyRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFFM0QsT0FBTyxFQUFFLDRCQUE0QixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFHdEUsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDbkQsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDOUQsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ25ELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQ3RELE9BQU8sS0FBSyxFQUFFLE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E9B,gBAAgB;IA6B9B;;OAEG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAsBnF;IAEY,0BAA0B,CAAC,cAAc,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhG;IAEY,gCAAgC,CAC3C,cAAc,EAAE,uBAAuB,GACtC,OAAO,CAAC;QAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAEzE;IAEY,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhF;IAEY,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,CAEtD;CACF"}
@@ -1,395 +0,0 @@
1
- import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec/constants';
2
- import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
3
- import { jsonStringify } from '@aztec/foundation/json-rpc';
4
- import { createLogger } from '@aztec/foundation/log';
5
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
6
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import { SerializableContractInstance } from '@aztec/stdlib/contract';
8
- import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
9
- import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
10
- import { strict as assert } from 'assert';
11
- import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
12
- import { L1ToL2MessageIndexOutOfRangeError, MaxCallsToUniqueContractClassIdsError, NoteHashIndexOutOfRangeError, NullifierCollisionError } from '../side_effect_errors.js';
13
- import { NullifierManager } from './nullifiers.js';
14
- import { PublicStorage } from './public_storage.js';
15
- /**
16
- * A class to manage persistable AVM state for contract calls.
17
- * Maintains a cache of the current world state,
18
- * a trace of all side effects.
19
- *
20
- * The simulator should make any world state / tree queries through this object.
21
- *
22
- * Manages merging of successful/reverted child state into current state.
23
- */ export class PublicPersistableStateManager {
24
- treesDB;
25
- contractsDB;
26
- trace;
27
- firstNullifier;
28
- timestamp;
29
- doMerkleOperations;
30
- publicStorage;
31
- nullifiers;
32
- log;
33
- /** Make sure a forked state is never merged twice. */ alreadyMergedIntoParent;
34
- constructor(treesDB, contractsDB, trace, firstNullifier, timestamp, doMerkleOperations = true, publicStorage = new PublicStorage(treesDB), nullifiers = new NullifierManager(treesDB)){
35
- this.treesDB = treesDB;
36
- this.contractsDB = contractsDB;
37
- this.trace = trace;
38
- this.firstNullifier = firstNullifier;
39
- this.timestamp = timestamp;
40
- this.doMerkleOperations = doMerkleOperations;
41
- this.publicStorage = publicStorage;
42
- this.nullifiers = nullifiers;
43
- this.log = createLogger('simulator:state_manager');
44
- this.alreadyMergedIntoParent = false;
45
- }
46
- /**
47
- * Create a new state manager
48
- */ static create(treesDB, contractsDB, trace, firstNullifier, timestamp) {
49
- return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp);
50
- }
51
- /**
52
- * Create a new state manager forked from this one
53
- */ async fork() {
54
- await this.treesDB.createCheckpoint();
55
- return new PublicPersistableStateManager(this.treesDB, this.contractsDB, this.trace.fork(), this.firstNullifier, this.timestamp, this.doMerkleOperations, this.publicStorage.fork(), this.nullifiers.fork());
56
- }
57
- /**
58
- * Accept forked world state modifications & traced side effects / hints
59
- */ async merge(forkedState) {
60
- await this._merge(forkedState, /*reverted=*/ false);
61
- }
62
- /**
63
- * Reject forked world state modifications & traced side effects, keep traced hints
64
- */ async reject(forkedState) {
65
- await this._merge(forkedState, /*reverted=*/ true);
66
- }
67
- async _merge(forkedState, reverted) {
68
- // sanity check to avoid merging the same forked trace twice
69
- assert(!forkedState.alreadyMergedIntoParent, 'Cannot merge forked state that has already been merged into its parent!');
70
- forkedState.alreadyMergedIntoParent = true;
71
- this.publicStorage.acceptAndMerge(forkedState.publicStorage);
72
- this.nullifiers.acceptAndMerge(forkedState.nullifiers);
73
- this.trace.merge(forkedState.trace, reverted);
74
- if (reverted) {
75
- this.log.trace('Reverting forked state...');
76
- await this.treesDB.revertCheckpoint();
77
- } else {
78
- this.log.trace('Merging forked state into parent...');
79
- await this.treesDB.commitCheckpoint();
80
- }
81
- }
82
- /**
83
- * Write to public storage, journal/trace the write.
84
- *
85
- * @param contractAddress - the address of the contract whose storage is being written to
86
- * @param slot - the slot in the contract's storage being written to
87
- * @param value - the value being written to the slot
88
- */ async writeStorage(contractAddress, slot, value, protocolWrite = false) {
89
- this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`);
90
- await this.trace.tracePublicStorageWrite(contractAddress, slot, value, protocolWrite);
91
- if (this.doMerkleOperations) {
92
- // write to native merkle trees
93
- await this.treesDB.storageWrite(contractAddress, slot, value);
94
- } else {
95
- // Cache storage writes for later reference/reads
96
- this.publicStorage.write(contractAddress, slot, value);
97
- }
98
- }
99
- isStorageCold(contractAddress, slot) {
100
- return this.trace.isStorageCold(contractAddress, slot);
101
- }
102
- /**
103
- * Read from public storage.
104
- *
105
- * @param contractAddress - the address of the contract whose storage is being read from
106
- * @param slot - the slot in the contract's storage being read from
107
- * @returns the latest value written to slot, or 0 if never written to before
108
- */ async readStorage(contractAddress, slot) {
109
- if (this.doMerkleOperations) {
110
- return await this.treesDB.storageRead(contractAddress, slot);
111
- } else {
112
- const read = await this.publicStorage.read(contractAddress, slot);
113
- this.log.trace(`Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`);
114
- return read.value;
115
- }
116
- }
117
- // TODO(4886): We currently don't silo note hashes.
118
- /**
119
- * Check if a note hash exists at the given leaf index, trace the check.
120
- *
121
- * @param contractAddress - the address of the contract whose storage is being read from
122
- * @param noteHash - the unsiloed note hash being checked
123
- * @param leafIndex - the leaf index being checked
124
- * @returns true if the note hash exists at the given leaf index, false otherwise
125
- */ async checkNoteHashExists(contractAddress, noteHash, leafIndex) {
126
- try {
127
- const gotLeafValue = await this.treesDB.getNoteHash(leafIndex);
128
- const exists = gotLeafValue.equals(noteHash);
129
- this.log.trace(`noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`);
130
- return Promise.resolve(exists);
131
- } catch (error) {
132
- // If the index is out of range, note_hash_leaf_in_range = 0 and the circuit returns false:
133
- if (error instanceof NoteHashIndexOutOfRangeError) {
134
- return Promise.resolve(false);
135
- }
136
- // Otherwise, unknown error. This is a bug.
137
- throw error;
138
- }
139
- }
140
- /**
141
- * Write a raw note hash, silo it and make it unique, then trace the write.
142
- * @param noteHash - the unsiloed note hash to write
143
- */ async writeNoteHash(contractAddress, noteHash) {
144
- this.log.trace(`noteHashes(${contractAddress}) += ${noteHash}.`);
145
- const siloedNoteHash = await siloNoteHash(contractAddress, noteHash);
146
- await this.writeSiloedNoteHash(siloedNoteHash);
147
- }
148
- /**
149
- * Write a note hash, make it unique, trace the write.
150
- * @param siloedNoteHash - the non unique note hash to write
151
- */ async writeSiloedNoteHash(siloedNoteHash) {
152
- const noteNonce = await computeNoteHashNonce(this.firstNullifier, this.trace.getNoteHashCount());
153
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, siloedNoteHash);
154
- await this.writeUniqueNoteHash(uniqueNoteHash);
155
- }
156
- /**
157
- * Write a note hash, trace the write.
158
- * @param uniqueNoteHash - the siloed unique hash to write
159
- */ async writeUniqueNoteHash(uniqueNoteHash) {
160
- this.log.trace(`noteHashes += @${uniqueNoteHash}.`);
161
- this.trace.traceNewNoteHash(uniqueNoteHash);
162
- if (this.doMerkleOperations) {
163
- await this.treesDB.writeNoteHash(uniqueNoteHash);
164
- }
165
- }
166
- /**
167
- * Check if a nullifier exists, trace the check.
168
- * @param contractAddress - address of the contract that the nullifier is associated with
169
- * @param nullifier - the unsiloed nullifier to check
170
- * @returns exists - whether the nullifier exists in the nullifier set
171
- */ async checkNullifierExists(contractAddress, nullifier) {
172
- this.log.trace(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`);
173
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
174
- if (this.doMerkleOperations) {
175
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
176
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
177
- return Promise.resolve(exists);
178
- } else {
179
- const { exists, cacheHit } = await this.nullifiers.checkExists(siloedNullifier);
180
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), cacheHit=${cacheHit}`);
181
- return Promise.resolve(exists);
182
- }
183
- }
184
- /**
185
- * Write a nullifier to the nullifier set, trace the write.
186
- * @param contractAddress - address of the contract that the nullifier is associated with
187
- * @param nullifier - the unsiloed nullifier to write
188
- */ async writeNullifier(contractAddress, nullifier) {
189
- this.log.trace(`Inserting new nullifier (address=${nullifier}, nullifier=${contractAddress})`);
190
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
191
- await this.writeSiloedNullifier(siloedNullifier);
192
- }
193
- /**
194
- * Write a nullifier to the nullifier set, trace the write.
195
- * @param siloedNullifier - the siloed nullifier to write
196
- */ async writeSiloedNullifier(siloedNullifier) {
197
- this.log.trace(`Inserting siloed nullifier=${siloedNullifier}`);
198
- this.trace.traceNewNullifier(siloedNullifier);
199
- if (this.doMerkleOperations) {
200
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
201
- if (exists) {
202
- this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree!`);
203
- throw new NullifierCollisionError(`Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`);
204
- } else {
205
- await this.treesDB.writeNullifier(siloedNullifier);
206
- }
207
- } else {
208
- // Cache pending nullifiers for later access
209
- await this.nullifiers.append(siloedNullifier);
210
- }
211
- }
212
- /**
213
- * Check if an L1 to L2 message exists, trace the check.
214
- * @param msgHash - the message hash to check existence of
215
- * @param msgLeafIndex - the message leaf index to use in the check
216
- * @returns exists - whether the message exists in the L1 to L2 Messages tree
217
- */ async checkL1ToL2MessageExists(msgHash, msgLeafIndex) {
218
- try {
219
- const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
220
- const exists = valueAtIndex.equals(msgHash);
221
- this.log.trace(`l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`);
222
- return Promise.resolve(exists);
223
- } catch (error) {
224
- // If the index is out of range, l1_to_l2_msg_leaf_in_range = 0 and the circuit returns false:
225
- if (error instanceof L1ToL2MessageIndexOutOfRangeError) {
226
- return Promise.resolve(false);
227
- }
228
- // Otherwise, unknown error. This is a bug.
229
- throw error;
230
- }
231
- }
232
- /**
233
- * Write an L2 to L1 message.
234
- * @param contractAddress - L2 contract address that created this message
235
- * @param recipient - L1 contract address to send the message to.
236
- * @param content - Message content.
237
- */ writeL2ToL1Message(contractAddress, recipient, content) {
238
- this.log.trace(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`);
239
- this.trace.traceNewL2ToL1Message(contractAddress, recipient, content);
240
- }
241
- /**
242
- * Write a scoped L2 to L1 message.
243
- * @param l2ToL1Message - The L2 to L1 message to write.
244
- */ writeScopedL2ToL1Message(l2ToL1Message) {
245
- this.writeL2ToL1Message(l2ToL1Message.contractAddress, l2ToL1Message.message.recipient.toField(), l2ToL1Message.message.content);
246
- }
247
- writeDebugLog(contractAddress, level, message, fields) {
248
- this.trace.traceDebugLog(contractAddress, level, message, fields);
249
- }
250
- writeDebugLogMemoryReads(memoryReads) {
251
- this.trace.traceDebugLogMemoryReads(memoryReads);
252
- }
253
- getDebugLogMemoryReads() {
254
- return this.trace.getDebugLogMemoryReads();
255
- }
256
- getLogs() {
257
- return this.trace.getDebugLogs();
258
- }
259
- /**
260
- * Write a public log
261
- * @param contractAddress - address of the contract that emitted the log
262
- * @param log - log contents
263
- */ writePublicLog(contractAddress, log) {
264
- this.log.trace(`PublicLog(${contractAddress}) += event with ${log.length} fields.`);
265
- this.trace.tracePublicLog(contractAddress, log);
266
- }
267
- /**
268
- * Get a contract instance.
269
- * @param contractAddress - address of the contract instance to retrieve.
270
- * @returns the contract instance or undefined if it does not exist.
271
- */ async getContractInstance(contractAddress) {
272
- this.log.trace(`Getting contract instance for address ${contractAddress}`);
273
- const instanceWithAddress = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
274
- const exists = instanceWithAddress !== undefined;
275
- const instance = exists ? new SerializableContractInstance(instanceWithAddress) : undefined;
276
- if (contractAddressIsCanonical(contractAddress)) {
277
- this.log.trace(`Got canonical contract instance (address=${contractAddress}): instance=${jsonStringify(instance)}`);
278
- return instance;
279
- }
280
- // Nullifier check! We do this regardless of whether or not the instance exists,
281
- // as even for non-existence, we need to generate nullifier check hints.
282
- // This will internally decide whether to check the nullifier tree or not depending on doMerkleOperations.
283
- const nullifierExistsInTree = await this.checkNullifierExists(AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS), contractAddress.toField());
284
- assert(exists == nullifierExistsInTree, `Contract instance for address ${contractAddress} in DB: ${exists} != nullifier tree: ${nullifierExistsInTree}. This is a bug!`);
285
- if (!exists) {
286
- this.log.debug(`Contract instance NOT FOUND (address=${contractAddress})`);
287
- return undefined;
288
- }
289
- this.log.trace(`Got contract instance (address=${contractAddress}): instance=${jsonStringify(instance)}`);
290
- // All that is left is to check that the contract updatability information is correct.
291
- // That is, that the current and original contract class ids are correct.
292
- await this.checkContractUpdateInformation(instanceWithAddress);
293
- return instance;
294
- }
295
- async checkContractUpdateInformation(instance) {
296
- // If "merkle operations" are not requested, we trust the DB.
297
- // Otherwise we check that the contract updatability information is correct.
298
- // That is, that the current and original contract class ids are correct.
299
- // All failures are fatal and the simulation is not expected to be provable.
300
- if (this.doMerkleOperations) {
301
- // Conceptually, we want to do the following:
302
- // * Read a DelayedPublicMutable at the contract update slot.
303
- // * Obtain the expected current class id from the DelayedPublicMutable, at the current block.
304
- // * if expectedId == 0 then currentClassId should be original contract class id
305
- // * if expectedId != 0 then currentClassId should be expectedId
306
- //
307
- // However, we will also be checking the hash of the delayed public mutable values.
308
- // This is a bit of a leak of information, since the circuit will use it to prove
309
- // one public read instead of N of the delayed public mutable values.
310
- const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(instance.address);
311
- const readDeployerStorage = async (storageSlot)=>await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
312
- const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
313
- // NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
314
- // See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
315
- const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, readDeployerStorage);
316
- const preImage = delayedPublicMutableValues.toFields();
317
- // 1) update never scheduled: hash == 0 and preimage should be empty (but poseidon2hash(preimage) will not be 0s)
318
- if (hash.isZero()) {
319
- assert(preImage.every((f)=>f.isZero()), `Found updatability hash 0 but preimage is not empty for contract instance ${instance.address}.`);
320
- assert(instance.currentContractClassId.equals(instance.originalContractClassId), `Found updatability hash 0 for contract instance ${instance.address} but original class id ${instance.originalContractClassId} != current class id ${instance.currentContractClassId}.`);
321
- return;
322
- }
323
- // 2) At this point we know that the hash is not zero and this means that an update has at some point been scheduled.
324
- const computedHash = await poseidon2Hash(preImage);
325
- assert(hash.equals(computedHash), `Delayed public mutable values hash mismatch for contract instance ${instance.address}. Expected: ${hash}, computed: ${computedHash}`);
326
- // We now check that, depending on the current block, the current class id is correct.
327
- const expectedClassIdRaw = delayedPublicMutableValues.svc.getCurrentAt(this.timestamp).at(0);
328
- const expectedClassId = expectedClassIdRaw.isZero() ? instance.originalContractClassId : expectedClassIdRaw;
329
- assert(instance.currentContractClassId.equals(expectedClassId), `Current class id mismatch
330
- for contract instance ${instance.address}. Expected: ${expectedClassId}, current: ${instance.currentContractClassId}`);
331
- }
332
- }
333
- /**
334
- * Get a contract class.
335
- * @param classId - class id to retrieve.
336
- * @returns the contract class or undefined if it does not exist.
337
- */ async getContractClass(classId) {
338
- this.log.trace(`Getting contract class for id ${classId}`);
339
- const contractClass = await this.contractsDB.getContractClass(classId);
340
- const exists = contractClass !== undefined;
341
- let extendedClass = undefined;
342
- // Note: We currently do not generate info to check the nullifier tree, because
343
- // this is not needed for our use cases.
344
- if (exists) {
345
- this.log.trace(`Got contract class (id=${classId})`);
346
- // Extend class information with public bytecode commitment.
347
- const bytecodeCommitment = await this.contractsDB.getBytecodeCommitment(classId);
348
- assert(bytecodeCommitment, `Bytecode commitment was not found in DB for contract class (${classId}). This should not happen!`);
349
- extendedClass = {
350
- ...contractClass,
351
- publicBytecodeCommitment: bytecodeCommitment
352
- };
353
- } else {
354
- this.log.debug(`Contract class NOT FOUND (id=${classId})`);
355
- }
356
- // TODO(dbanks12): does this need to be moved to before the DB accesses as was done with writeNullifier?
357
- this.trace.traceGetContractClass(classId, exists);
358
- return extendedClass;
359
- }
360
- /**
361
- * Get a contract's bytecode from the contracts DB, also trace the contract class and instance indirectly.
362
- */ async getBytecode(contractAddress) {
363
- this.log.debug(`Getting bytecode for contract address ${contractAddress}`);
364
- const contractInstance = await this.getContractInstance(contractAddress);
365
- if (!contractInstance) {
366
- return undefined;
367
- }
368
- try {
369
- const contractClass = await this.getContractClass(contractInstance.currentContractClassId);
370
- assert(contractClass, `Contract class not found in DB, but a contract instance was found with this class ID (${contractInstance.currentContractClassId}). This should not happen!`);
371
- return contractClass.packedBytecode;
372
- } catch (error) {
373
- if (error instanceof MaxCallsToUniqueContractClassIdsError) {
374
- return undefined;
375
- }
376
- // Otherwise, unknown error. This is a bug.
377
- throw error;
378
- }
379
- }
380
- async getPublicFunctionDebugName(avmEnvironment) {
381
- return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
382
- }
383
- async getPublicFunctionSelectorAndName(avmEnvironment) {
384
- return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
385
- }
386
- async padTree(treeId, leavesToInsert) {
387
- await this.treesDB.padTree(treeId, leavesToInsert);
388
- }
389
- async getTreeSnapshots() {
390
- return await this.treesDB.getTreeSnapshots();
391
- }
392
- }
393
- function contractAddressIsCanonical(contractAddress) {
394
- return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
395
- }
@@ -1,61 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
2
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
-
4
- import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
5
- import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
6
- import { type Gas, gasToGasLeft } from './avm_gas.js';
7
- import { AvmMachineState } from './avm_machine_state.js';
8
- import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
9
-
10
- /**
11
- * An execution context includes the information necessary to initiate AVM
12
- * execution along with all state maintained by the AVM throughout execution.
13
- */
14
- export class AvmContext {
15
- /**
16
- * Create a new AVM context
17
- * @param persistableState - Manages world state and accrued substate during execution - (caching, fetching, tracing)
18
- * @param environment - Contains constant variables provided by the kernel
19
- * @param machineState - VM state that is modified on an instruction-by-instruction basis
20
- * @returns new AvmContext instance
21
- */
22
- constructor(
23
- public persistableState: PublicPersistableStateManager,
24
- public environment: AvmExecutionEnvironment,
25
- public machineState: AvmMachineState,
26
- ) {}
27
-
28
- // This is needed to break a dependency cycle created by the CALL opcode,
29
- // which needs to create a new simulator but cannot depend directly on AvmSimulator.
30
- public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;
31
-
32
- /**
33
- * Prepare a new AVM context that will be ready for an external/nested call
34
- * - Fork the world state journal
35
- * - Derive a machine state from the current state
36
- * - E.g., gas metering is preserved but pc is reset
37
- * - Derive an execution environment from the caller/parent
38
- * - Alter address
39
- *
40
- * @param address - The contract instance to initialize a context for
41
- * @param calldata - Data/arguments for nested call
42
- * @param allocatedGas - Gas allocated for the nested call
43
- * @param callType - Type of call (CALL or STATICCALL)
44
- * @returns new AvmContext instance
45
- */
46
- public async createNestedContractCallContext(
47
- address: AztecAddress,
48
- calldata: Fr[],
49
- allocatedGas: Gas,
50
- callType: 'CALL' | 'STATICCALL',
51
- ): Promise<AvmContext> {
52
- const deriveFn =
53
- callType === 'CALL'
54
- ? this.environment.deriveEnvironmentForNestedCall
55
- : this.environment.deriveEnvironmentForNestedStaticCall;
56
- const newExecutionEnvironment = deriveFn.call(this.environment, address, calldata);
57
- const forkedWorldState = await this.persistableState.fork();
58
- const machineState = AvmMachineState.fromState(gasToGasLeft(allocatedGas));
59
- return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
60
- }
61
- }