@aztec/simulator 0.0.1-commit.a072138 → 0.0.1-commit.a4600f49

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 (358) 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_wasm.d.ts +1 -1
  6. package/dest/private/acvm_wasm.d.ts.map +1 -1
  7. package/dest/private/acvm_wasm.js +3 -1
  8. package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
  9. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  10. package/dest/private/circuit_recording/circuit_recorder.js +65 -69
  11. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
  12. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  13. package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
  14. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  15. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  17. package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
  18. package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
  19. package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
  20. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.d.ts +2 -1
  21. package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
  22. package/dest/public/avm/{fixtures → testing}/base_avm_simulation_tester.js +18 -3
  23. package/dest/public/avm/testing/utils.d.ts +32 -0
  24. package/dest/public/avm/testing/utils.d.ts.map +1 -0
  25. package/dest/public/avm/{fixtures → testing}/utils.js +4 -34
  26. package/dest/public/avm_simulator.d.ts +28 -0
  27. package/dest/public/avm_simulator.d.ts.map +1 -0
  28. package/dest/public/avm_simulator.js +4 -0
  29. package/dest/public/avm_simulator_pool.d.ts +45 -0
  30. package/dest/public/avm_simulator_pool.d.ts.map +1 -0
  31. package/dest/public/avm_simulator_pool.js +197 -0
  32. package/dest/public/cdb/generated/api_types.d.ts +171 -0
  33. package/dest/public/cdb/generated/api_types.d.ts.map +1 -0
  34. package/dest/public/cdb/generated/api_types.js +314 -0
  35. package/dest/public/cdb/generated/server.d.ts +26 -0
  36. package/dest/public/cdb/generated/server.d.ts.map +1 -0
  37. package/dest/public/cdb/generated/server.js +135 -0
  38. package/dest/public/cdb_ipc_server.d.ts +33 -0
  39. package/dest/public/cdb_ipc_server.d.ts.map +1 -0
  40. package/dest/public/cdb_ipc_server.js +153 -0
  41. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  42. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  43. package/dest/public/contracts_db_checkpoint.js +1 -1
  44. package/dest/public/fixtures/amm_test.js +4 -4
  45. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  46. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  47. package/dest/public/fixtures/bulk_test.js +33 -6
  48. package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
  49. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  50. package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
  51. package/dest/public/fixtures/index.d.ts +2 -4
  52. package/dest/public/fixtures/index.d.ts.map +1 -1
  53. package/dest/public/fixtures/index.js +1 -3
  54. package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
  55. package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
  56. package/dest/public/fixtures/public_processor_test_env.js +73 -0
  57. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -7
  58. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  59. package/dest/public/fixtures/public_tx_simulation_tester.js +32 -15
  60. package/dest/public/fixtures/simple_contract_data_source.js +1 -1
  61. package/dest/public/fixtures/token_test.js +3 -3
  62. package/dest/public/fixtures/utils.d.ts +2 -2
  63. package/dest/public/fixtures/utils.d.ts.map +1 -1
  64. package/dest/public/fixtures/utils.js +21 -20
  65. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +11 -4
  66. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  67. package/dest/public/fuzzing/avm_fuzzer_simulator.js +24 -10
  68. package/dest/public/fuzzing/avm_simulator_bin.js +4 -4
  69. package/dest/public/index.d.ts +5 -2
  70. package/dest/public/index.d.ts.map +1 -1
  71. package/dest/public/index.js +2 -1
  72. package/dest/public/public_db_sources.d.ts +6 -3
  73. package/dest/public/public_db_sources.d.ts.map +1 -1
  74. package/dest/public/public_db_sources.js +16 -10
  75. package/dest/public/public_processor/guarded_merkle_tree.d.ts +8 -7
  76. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  77. package/dest/public/public_processor/guarded_merkle_tree.js +8 -5
  78. package/dest/public/public_processor/public_processor.d.ts +15 -8
  79. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  80. package/dest/public/public_processor/public_processor.js +117 -78
  81. package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
  82. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  83. package/dest/public/public_processor/public_processor_metrics.js +8 -0
  84. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
  85. package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
  86. package/dest/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.js → dumping_public_tx_simulator.js} +10 -23
  87. package/dest/public/public_tx_simulator/factories.d.ts +8 -8
  88. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  89. package/dest/public/public_tx_simulator/factories.js +9 -9
  90. package/dest/public/public_tx_simulator/index.d.ts +4 -6
  91. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  92. package/dest/public/public_tx_simulator/index.js +2 -4
  93. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +42 -71
  94. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  95. package/dest/public/public_tx_simulator/public_tx_simulator.js +98 -318
  96. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
  97. package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
  98. package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
  99. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +5 -5
  100. package/package.json +22 -19
  101. package/src/client.ts +0 -2
  102. package/src/private/acvm_wasm.ts +4 -1
  103. package/src/private/circuit_recording/circuit_recorder.ts +84 -78
  104. package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
  105. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  106. package/src/public/avm/testing/account_proof.json +553 -0
  107. package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
  108. package/src/public/avm/{fixtures → testing}/base_avm_simulation_tester.ts +23 -3
  109. package/src/public/avm/{fixtures → testing}/utils.ts +4 -40
  110. package/src/public/avm_simulator.ts +29 -0
  111. package/src/public/avm_simulator_pool.ts +226 -0
  112. package/src/public/cdb/generated/api_types.ts +457 -0
  113. package/src/public/cdb/generated/server.ts +109 -0
  114. package/src/public/cdb_ipc_server.ts +197 -0
  115. package/src/public/contracts_db_checkpoint.ts +1 -1
  116. package/src/public/fixtures/amm_test.ts +4 -4
  117. package/src/public/fixtures/bulk_test.ts +31 -6
  118. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  119. package/src/public/fixtures/index.ts +1 -3
  120. package/src/public/fixtures/public_processor_test_env.ts +88 -0
  121. package/src/public/fixtures/public_tx_simulation_tester.ts +45 -18
  122. package/src/public/fixtures/simple_contract_data_source.ts +1 -1
  123. package/src/public/fixtures/token_test.ts +3 -3
  124. package/src/public/fixtures/utils.ts +23 -24
  125. package/src/public/fuzzing/avm_fuzzer_simulator.ts +26 -11
  126. package/src/public/fuzzing/avm_simulator_bin.ts +3 -5
  127. package/src/public/index.ts +7 -3
  128. package/src/public/public_db_sources.ts +21 -14
  129. package/src/public/public_processor/guarded_merkle_tree.ts +11 -8
  130. package/src/public/public_processor/public_processor.ts +154 -98
  131. package/src/public/public_processor/public_processor_metrics.ts +12 -0
  132. package/src/public/public_tx_simulator/{dumping_cpp_public_tx_simulator.ts → dumping_public_tx_simulator.ts} +15 -31
  133. package/src/public/public_tx_simulator/factories.ts +29 -11
  134. package/src/public/public_tx_simulator/index.ts +6 -5
  135. package/src/public/public_tx_simulator/public_tx_simulator.ts +139 -476
  136. package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
  137. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +5 -5
  138. package/dest/public/avm/avm_context.d.ts +0 -41
  139. package/dest/public/avm/avm_context.d.ts.map +0 -1
  140. package/dest/public/avm/avm_context.js +0 -44
  141. package/dest/public/avm/avm_contract_call_result.d.ts +0 -32
  142. package/dest/public/avm/avm_contract_call_result.d.ts.map +0 -1
  143. package/dest/public/avm/avm_contract_call_result.js +0 -54
  144. package/dest/public/avm/avm_execution_environment.d.ts +0 -24
  145. package/dest/public/avm/avm_execution_environment.d.ts.map +0 -1
  146. package/dest/public/avm/avm_execution_environment.js +0 -33
  147. package/dest/public/avm/avm_gas.d.ts +0 -44
  148. package/dest/public/avm/avm_gas.d.ts.map +0 -1
  149. package/dest/public/avm/avm_gas.js +0 -195
  150. package/dest/public/avm/avm_machine_state.d.ts +0 -98
  151. package/dest/public/avm/avm_machine_state.d.ts.map +0 -1
  152. package/dest/public/avm/avm_machine_state.js +0 -110
  153. package/dest/public/avm/avm_memory_types.d.ts +0 -275
  154. package/dest/public/avm/avm_memory_types.d.ts.map +0 -1
  155. package/dest/public/avm/avm_memory_types.js +0 -354
  156. package/dest/public/avm/avm_simulator.d.ts +0 -41
  157. package/dest/public/avm/avm_simulator.d.ts.map +0 -1
  158. package/dest/public/avm/avm_simulator.js +0 -192
  159. package/dest/public/avm/avm_simulator_interface.d.ts +0 -9
  160. package/dest/public/avm/avm_simulator_interface.d.ts.map +0 -1
  161. package/dest/public/avm/avm_simulator_interface.js +0 -3
  162. package/dest/public/avm/calldata.d.ts +0 -51
  163. package/dest/public/avm/calldata.d.ts.map +0 -1
  164. package/dest/public/avm/calldata.js +0 -63
  165. package/dest/public/avm/errors.d.ts +0 -104
  166. package/dest/public/avm/errors.d.ts.map +0 -1
  167. package/dest/public/avm/errors.js +0 -141
  168. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +0 -22
  169. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  170. package/dest/public/avm/fixtures/avm_simulation_tester.js +0 -84
  171. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  172. package/dest/public/avm/fixtures/initializers.d.ts +0 -42
  173. package/dest/public/avm/fixtures/initializers.d.ts.map +0 -1
  174. package/dest/public/avm/fixtures/initializers.js +0 -45
  175. package/dest/public/avm/fixtures/utils.d.ts +0 -39
  176. package/dest/public/avm/fixtures/utils.d.ts.map +0 -1
  177. package/dest/public/avm/index.d.ts +0 -2
  178. package/dest/public/avm/index.d.ts.map +0 -1
  179. package/dest/public/avm/index.js +0 -1
  180. package/dest/public/avm/opcodes/accrued_substate.d.ts +0 -74
  181. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +0 -1
  182. package/dest/public/avm/opcodes/accrued_substate.js +0 -255
  183. package/dest/public/avm/opcodes/addressing_mode.d.ts +0 -31
  184. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +0 -1
  185. package/dest/public/avm/opcodes/addressing_mode.js +0 -94
  186. package/dest/public/avm/opcodes/arithmetic.d.ts +0 -49
  187. package/dest/public/avm/opcodes/arithmetic.d.ts.map +0 -1
  188. package/dest/public/avm/opcodes/arithmetic.js +0 -97
  189. package/dest/public/avm/opcodes/bitwise.d.ts +0 -42
  190. package/dest/public/avm/opcodes/bitwise.d.ts.map +0 -1
  191. package/dest/public/avm/opcodes/bitwise.js +0 -99
  192. package/dest/public/avm/opcodes/comparators.d.ts +0 -25
  193. package/dest/public/avm/opcodes/comparators.d.ts.map +0 -1
  194. package/dest/public/avm/opcodes/comparators.js +0 -43
  195. package/dest/public/avm/opcodes/contract.d.ts +0 -20
  196. package/dest/public/avm/opcodes/contract.d.ts.map +0 -1
  197. package/dest/public/avm/opcodes/contract.js +0 -65
  198. package/dest/public/avm/opcodes/control_flow.d.ts +0 -41
  199. package/dest/public/avm/opcodes/control_flow.d.ts.map +0 -1
  200. package/dest/public/avm/opcodes/control_flow.js +0 -107
  201. package/dest/public/avm/opcodes/conversion.d.ts +0 -18
  202. package/dest/public/avm/opcodes/conversion.d.ts.map +0 -1
  203. package/dest/public/avm/opcodes/conversion.js +0 -333
  204. package/dest/public/avm/opcodes/ec_add.d.ts +0 -19
  205. package/dest/public/avm/opcodes/ec_add.d.ts.map +0 -1
  206. package/dest/public/avm/opcodes/ec_add.js +0 -93
  207. package/dest/public/avm/opcodes/environment_getters.d.ts +0 -28
  208. package/dest/public/avm/opcodes/environment_getters.d.ts.map +0 -1
  209. package/dest/public/avm/opcodes/environment_getters.js +0 -77
  210. package/dest/public/avm/opcodes/external_calls.d.ts +0 -59
  211. package/dest/public/avm/opcodes/external_calls.d.ts.map +0 -1
  212. package/dest/public/avm/opcodes/external_calls.js +0 -210
  213. package/dest/public/avm/opcodes/hashing.d.ts +0 -36
  214. package/dest/public/avm/opcodes/hashing.d.ts.map +0 -1
  215. package/dest/public/avm/opcodes/hashing.js +0 -119
  216. package/dest/public/avm/opcodes/index.d.ts +0 -16
  217. package/dest/public/avm/opcodes/index.d.ts.map +0 -1
  218. package/dest/public/avm/opcodes/index.js +0 -15
  219. package/dest/public/avm/opcodes/instruction.d.ts +0 -74
  220. package/dest/public/avm/opcodes/instruction.d.ts.map +0 -1
  221. package/dest/public/avm/opcodes/instruction.js +0 -95
  222. package/dest/public/avm/opcodes/instruction_impl.d.ts +0 -19
  223. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +0 -1
  224. package/dest/public/avm/opcodes/instruction_impl.js +0 -30
  225. package/dest/public/avm/opcodes/memory.d.ts +0 -74
  226. package/dest/public/avm/opcodes/memory.d.ts.map +0 -1
  227. package/dest/public/avm/opcodes/memory.js +0 -257
  228. package/dest/public/avm/opcodes/misc.d.ts +0 -18
  229. package/dest/public/avm/opcodes/misc.d.ts.map +0 -1
  230. package/dest/public/avm/opcodes/misc.js +0 -73
  231. package/dest/public/avm/opcodes/storage.d.ts +0 -25
  232. package/dest/public/avm/opcodes/storage.d.ts.map +0 -1
  233. package/dest/public/avm/opcodes/storage.js +0 -78
  234. package/dest/public/avm/revert_reason.d.ts +0 -18
  235. package/dest/public/avm/revert_reason.d.ts.map +0 -1
  236. package/dest/public/avm/revert_reason.js +0 -39
  237. package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -26
  238. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +0 -1
  239. package/dest/public/avm/serialization/buffer_cursor.js +0 -99
  240. package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -17
  241. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  242. package/dest/public/avm/serialization/bytecode_serialization.js +0 -336
  243. package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -114
  244. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +0 -1
  245. package/dest/public/avm/serialization/instruction_serialization.js +0 -261
  246. package/dest/public/avm/test_utils.d.ts +0 -15
  247. package/dest/public/avm/test_utils.d.ts.map +0 -1
  248. package/dest/public/avm/test_utils.js +0 -44
  249. package/dest/public/debug_fn_name.d.ts +0 -18
  250. package/dest/public/debug_fn_name.d.ts.map +0 -1
  251. package/dest/public/debug_fn_name.js +0 -37
  252. package/dest/public/fixtures/custom_bytecode_tests.d.ts +0 -12
  253. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +0 -1
  254. package/dest/public/fixtures/custom_bytecode_tests.js +0 -174
  255. package/dest/public/fixtures/minimal_public_tx.d.ts +0 -4
  256. package/dest/public/fixtures/minimal_public_tx.d.ts.map +0 -1
  257. package/dest/public/fixtures/minimal_public_tx.js +0 -19
  258. package/dest/public/fixtures/opcode_spammer.d.ts +0 -122
  259. package/dest/public/fixtures/opcode_spammer.d.ts.map +0 -1
  260. package/dest/public/fixtures/opcode_spammer.js +0 -1653
  261. package/dest/public/hinting_db_sources.d.ts +0 -80
  262. package/dest/public/hinting_db_sources.d.ts.map +0 -1
  263. package/dest/public/hinting_db_sources.js +0 -355
  264. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +0 -19
  265. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +0 -1
  266. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +0 -98
  267. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +0 -53
  268. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +0 -1
  269. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +0 -132
  270. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +0 -42
  271. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +0 -1
  272. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +0 -86
  273. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +0 -30
  274. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +0 -1
  275. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +0 -171
  276. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +0 -23
  277. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +0 -1
  278. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -31
  279. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +0 -1
  280. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -51
  281. package/dest/public/public_tx_simulator/public_tx_context.d.ts +0 -131
  282. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +0 -1
  283. package/dest/public/public_tx_simulator/public_tx_context.js +0 -300
  284. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +0 -21
  285. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +0 -1
  286. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +0 -415
  287. package/dest/public/side_effect_trace.d.ts +0 -87
  288. package/dest/public/side_effect_trace.d.ts.map +0 -1
  289. package/dest/public/side_effect_trace.js +0 -199
  290. package/dest/public/side_effect_trace_interface.d.ts +0 -22
  291. package/dest/public/side_effect_trace_interface.d.ts.map +0 -1
  292. package/dest/public/side_effect_trace_interface.js +0 -1
  293. package/dest/public/state_manager/index.d.ts +0 -2
  294. package/dest/public/state_manager/index.d.ts.map +0 -1
  295. package/dest/public/state_manager/index.js +0 -1
  296. package/dest/public/state_manager/nullifiers.d.ts +0 -61
  297. package/dest/public/state_manager/nullifiers.d.ts.map +0 -1
  298. package/dest/public/state_manager/nullifiers.js +0 -92
  299. package/dest/public/state_manager/public_storage.d.ts +0 -66
  300. package/dest/public/state_manager/public_storage.d.ts.map +0 -1
  301. package/dest/public/state_manager/public_storage.js +0 -145
  302. package/dest/public/state_manager/state_manager.d.ts +0 -170
  303. package/dest/public/state_manager/state_manager.d.ts.map +0 -1
  304. package/dest/public/state_manager/state_manager.js +0 -402
  305. package/src/public/avm/avm_context.ts +0 -61
  306. package/src/public/avm/avm_contract_call_result.ts +0 -69
  307. package/src/public/avm/avm_execution_environment.ts +0 -51
  308. package/src/public/avm/avm_gas.ts +0 -183
  309. package/src/public/avm/avm_machine_state.ts +0 -170
  310. package/src/public/avm/avm_memory_types.ts +0 -440
  311. package/src/public/avm/avm_simulator.ts +0 -279
  312. package/src/public/avm/avm_simulator_interface.ts +0 -8
  313. package/src/public/avm/calldata.ts +0 -100
  314. package/src/public/avm/errors.ts +0 -177
  315. package/src/public/avm/fixtures/avm_simulation_tester.ts +0 -122
  316. package/src/public/avm/fixtures/initializers.ts +0 -103
  317. package/src/public/avm/index.ts +0 -1
  318. package/src/public/avm/opcodes/accrued_substate.ts +0 -286
  319. package/src/public/avm/opcodes/addressing_mode.ts +0 -111
  320. package/src/public/avm/opcodes/arithmetic.ts +0 -129
  321. package/src/public/avm/opcodes/bitwise.ts +0 -113
  322. package/src/public/avm/opcodes/comparators.ts +0 -55
  323. package/src/public/avm/opcodes/contract.ts +0 -72
  324. package/src/public/avm/opcodes/control_flow.ts +0 -123
  325. package/src/public/avm/opcodes/conversion.ts +0 -104
  326. package/src/public/avm/opcodes/ec_add.ts +0 -105
  327. package/src/public/avm/opcodes/environment_getters.ts +0 -87
  328. package/src/public/avm/opcodes/external_calls.ts +0 -262
  329. package/src/public/avm/opcodes/hashing.ts +0 -151
  330. package/src/public/avm/opcodes/index.ts +0 -15
  331. package/src/public/avm/opcodes/instruction.ts +0 -136
  332. package/src/public/avm/opcodes/instruction_impl.ts +0 -36
  333. package/src/public/avm/opcodes/memory.ts +0 -293
  334. package/src/public/avm/opcodes/misc.ts +0 -102
  335. package/src/public/avm/opcodes/storage.ts +0 -95
  336. package/src/public/avm/revert_reason.ts +0 -58
  337. package/src/public/avm/serialization/buffer_cursor.ts +0 -118
  338. package/src/public/avm/serialization/bytecode_serialization.ts +0 -215
  339. package/src/public/avm/serialization/instruction_serialization.ts +0 -249
  340. package/src/public/avm/test_utils.ts +0 -64
  341. package/src/public/debug_fn_name.ts +0 -52
  342. package/src/public/fixtures/custom_bytecode_tests.ts +0 -228
  343. package/src/public/fixtures/minimal_public_tx.ts +0 -26
  344. package/src/public/fixtures/opcode_spammer.ts +0 -1721
  345. package/src/public/hinting_db_sources.ts +0 -607
  346. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +0 -124
  347. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +0 -211
  348. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +0 -134
  349. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +0 -239
  350. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -105
  351. package/src/public/public_tx_simulator/public_tx_context.ts +0 -484
  352. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +0 -63
  353. package/src/public/side_effect_trace.ts +0 -293
  354. package/src/public/side_effect_trace_interface.ts +0 -28
  355. package/src/public/state_manager/index.ts +0 -1
  356. package/src/public/state_manager/nullifiers.ts +0 -103
  357. package/src/public/state_manager/public_storage.ts +0 -174
  358. package/src/public/state_manager/state_manager.ts +0 -569
@@ -1,569 +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 { Fr } from '@aztec/foundation/curves/bn254';
4
- import { jsonStringify } from '@aztec/foundation/json-rpc';
5
- import { type LogLevel, type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
6
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
7
- import { FunctionSelector } from '@aztec/stdlib/abi';
8
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
9
- import type { ContractClassPublicWithCommitment, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
10
- import { SerializableContractInstance } from '@aztec/stdlib/contract';
11
- import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
12
- import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
13
- import type { DebugLog } from '@aztec/stdlib/logs';
14
- import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
15
- import { MerkleTreeId } from '@aztec/stdlib/trees';
16
- import type { TreeSnapshots } from '@aztec/stdlib/tx';
17
- import type { UInt64 } from '@aztec/stdlib/types';
18
-
19
- import { strict as assert } from 'assert';
20
-
21
- import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
22
- import type { PublicContractsDBInterface } from '../db_interfaces.js';
23
- import { getPublicFunctionDebugName, getPublicFunctionSelectorAndName } from '../debug_fn_name.js';
24
- import type { PublicTreesDB } from '../public_db_sources.js';
25
- import {
26
- L1ToL2MessageIndexOutOfRangeError,
27
- MaxCallsToUniqueContractClassIdsError,
28
- NoteHashIndexOutOfRangeError,
29
- NullifierCollisionError,
30
- } from '../side_effect_errors.js';
31
- import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
32
- import { NullifierManager } from './nullifiers.js';
33
- import { PublicStorage } from './public_storage.js';
34
-
35
- /**
36
- * A class to manage persistable AVM state for contract calls.
37
- * Maintains a cache of the current world state,
38
- * a trace of all side effects.
39
- *
40
- * The simulator should make any world state / tree queries through this object.
41
- *
42
- * Manages merging of successful/reverted child state into current state.
43
- */
44
- export class PublicPersistableStateManager {
45
- private readonly log: Logger;
46
-
47
- /** Make sure a forked state is never merged twice. */
48
- private alreadyMergedIntoParent = false;
49
-
50
- constructor(
51
- private readonly treesDB: PublicTreesDB,
52
- private readonly contractsDB: PublicContractsDBInterface,
53
- private readonly trace: PublicSideEffectTraceInterface,
54
- private readonly firstNullifier: Fr, // Needed for note hashes.
55
- private readonly timestamp: UInt64, // Needed for contract updates.
56
- private readonly doMerkleOperations: boolean = true,
57
- private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
58
- private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
59
- bindings?: LoggerBindings,
60
- ) {
61
- this.log = createLogger('simulator:state_manager', bindings);
62
- }
63
-
64
- /**
65
- * Create a new state manager
66
- */
67
- public static create(
68
- treesDB: PublicTreesDB,
69
- contractsDB: PublicContractsDBInterface,
70
- trace: PublicSideEffectTraceInterface,
71
- firstNullifier: Fr,
72
- timestamp: UInt64,
73
- bindings?: LoggerBindings,
74
- ): PublicPersistableStateManager {
75
- return new PublicPersistableStateManager(
76
- treesDB,
77
- contractsDB,
78
- trace,
79
- firstNullifier,
80
- timestamp,
81
- undefined,
82
- undefined,
83
- undefined,
84
- bindings,
85
- );
86
- }
87
-
88
- /**
89
- * Create a new state manager forked from this one
90
- */
91
- public async fork() {
92
- await this.treesDB.createCheckpoint();
93
- return new PublicPersistableStateManager(
94
- this.treesDB,
95
- this.contractsDB,
96
- this.trace.fork(),
97
- this.firstNullifier,
98
- this.timestamp,
99
- this.doMerkleOperations,
100
- this.publicStorage.fork(),
101
- this.nullifiers.fork(),
102
- this.log.getBindings(),
103
- );
104
- }
105
-
106
- /**
107
- * Accept forked world state modifications & traced side effects / hints
108
- */
109
- public async merge(forkedState: PublicPersistableStateManager) {
110
- await this._merge(forkedState, /*reverted=*/ false);
111
- }
112
-
113
- /**
114
- * Reject forked world state modifications & traced side effects, keep traced hints
115
- */
116
- public async reject(forkedState: PublicPersistableStateManager) {
117
- await this._merge(forkedState, /*reverted=*/ true);
118
- }
119
-
120
- private async _merge(forkedState: PublicPersistableStateManager, reverted: boolean) {
121
- // sanity check to avoid merging the same forked trace twice
122
- assert(
123
- !forkedState.alreadyMergedIntoParent,
124
- 'Cannot merge forked state that has already been merged into its parent!',
125
- );
126
- forkedState.alreadyMergedIntoParent = true;
127
- this.publicStorage.acceptAndMerge(forkedState.publicStorage);
128
- this.nullifiers.acceptAndMerge(forkedState.nullifiers);
129
- this.trace.merge(forkedState.trace, reverted);
130
- if (reverted) {
131
- this.log.trace('Reverting forked state...');
132
- await this.treesDB.revertCheckpoint();
133
- } else {
134
- this.log.trace('Merging forked state into parent...');
135
- await this.treesDB.commitCheckpoint();
136
- }
137
- }
138
-
139
- /**
140
- * Write to public storage, journal/trace the write.
141
- *
142
- * @param contractAddress - the address of the contract whose storage is being written to
143
- * @param slot - the slot in the contract's storage being written to
144
- * @param value - the value being written to the slot
145
- */
146
- public async writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr, protocolWrite = false): Promise<void> {
147
- this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`);
148
-
149
- await this.trace.tracePublicStorageWrite(contractAddress, slot, value, protocolWrite);
150
-
151
- if (this.doMerkleOperations) {
152
- // write to native merkle trees
153
- await this.treesDB.storageWrite(contractAddress, slot, value);
154
- } else {
155
- // Cache storage writes for later reference/reads
156
- this.publicStorage.write(contractAddress, slot, value);
157
- }
158
- }
159
-
160
- public isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean {
161
- return this.trace.isStorageCold(contractAddress, slot);
162
- }
163
-
164
- /**
165
- * Read from public storage.
166
- *
167
- * @param contractAddress - the address of the contract whose storage is being read from
168
- * @param slot - the slot in the contract's storage being read from
169
- * @returns the latest value written to slot, or 0 if never written to before
170
- */
171
- public async readStorage(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
172
- if (this.doMerkleOperations) {
173
- return await this.treesDB.storageRead(contractAddress, slot);
174
- } else {
175
- const read = await this.publicStorage.read(contractAddress, slot);
176
- this.log.trace(
177
- `Storage read results (address=${contractAddress}, slot=${slot}): value=${read.value}, cached=${read.cached}`,
178
- );
179
- return read.value;
180
- }
181
- }
182
-
183
- // TODO(4886): We currently don't silo note hashes.
184
- /**
185
- * Check if a note hash exists at the given leaf index, trace the check.
186
- *
187
- * @param contractAddress - the address of the contract whose storage is being read from
188
- * @param noteHash - the unsiloed note hash being checked
189
- * @param leafIndex - the leaf index being checked
190
- * @returns true if the note hash exists at the given leaf index, false otherwise
191
- */
192
- public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: bigint): Promise<boolean> {
193
- try {
194
- const gotLeafValue = await this.treesDB.getNoteHash(leafIndex);
195
- const exists = gotLeafValue.equals(noteHash);
196
- this.log.trace(
197
- `noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`,
198
- );
199
- return Promise.resolve(exists);
200
- } catch (error) {
201
- // If the index is out of range, note_hash_leaf_in_range = 0 and the circuit returns false:
202
- if (error instanceof NoteHashIndexOutOfRangeError) {
203
- return Promise.resolve(false);
204
- }
205
- // Otherwise, unknown error. This is a bug.
206
- throw error;
207
- }
208
- }
209
-
210
- /**
211
- * Write a raw note hash, silo it and make it unique, then trace the write.
212
- * @param noteHash - the unsiloed note hash to write
213
- */
214
- public async writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): Promise<void> {
215
- this.log.trace(`noteHashes(${contractAddress}) += ${noteHash}.`);
216
- const siloedNoteHash = await siloNoteHash(contractAddress, noteHash);
217
- await this.writeSiloedNoteHash(siloedNoteHash);
218
- }
219
-
220
- /**
221
- * Write a note hash, make it unique, trace the write.
222
- * @param siloedNoteHash - the non unique note hash to write
223
- */
224
- public async writeSiloedNoteHash(siloedNoteHash: Fr): Promise<void> {
225
- const noteNonce = await computeNoteHashNonce(this.firstNullifier, this.trace.getNoteHashCount());
226
- const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, siloedNoteHash);
227
- await this.writeUniqueNoteHash(uniqueNoteHash);
228
- }
229
-
230
- /**
231
- * Write a note hash, trace the write.
232
- * @param uniqueNoteHash - the siloed unique hash to write
233
- */
234
- public async writeUniqueNoteHash(uniqueNoteHash: Fr): Promise<void> {
235
- this.log.trace(`noteHashes += @${uniqueNoteHash}.`);
236
- this.trace.traceNewNoteHash(uniqueNoteHash);
237
- if (this.doMerkleOperations) {
238
- await this.treesDB.writeNoteHash(uniqueNoteHash);
239
- }
240
- }
241
-
242
- /**
243
- * Check if a nullifier exists, trace the check.
244
- * @param contractAddress - address of the contract that the nullifier is associated with
245
- * @param nullifier - the unsiloed nullifier to check
246
- * @returns exists - whether the nullifier exists in the nullifier set
247
- */
248
- public async checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise<boolean> {
249
- this.log.trace(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`);
250
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
251
- return this.checkSiloedNullifierExists(siloedNullifier);
252
- }
253
-
254
- /**
255
- * Check if a siloed nullifier exists.
256
- * @param siloedNullifier - the siloed nullifier to check
257
- * @returns exists - whether the nullifier exists in the nullifier set
258
- */
259
- public async checkSiloedNullifierExists(siloedNullifier: Fr): Promise<boolean> {
260
- if (this.doMerkleOperations) {
261
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
262
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
263
- return Promise.resolve(exists);
264
- } else {
265
- const { exists, cacheHit } = await this.nullifiers.checkExists(siloedNullifier);
266
- this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), cacheHit=${cacheHit}`);
267
- return Promise.resolve(exists);
268
- }
269
- }
270
-
271
- /**
272
- * Write a nullifier to the nullifier set, trace the write.
273
- * @param contractAddress - address of the contract that the nullifier is associated with
274
- * @param nullifier - the unsiloed nullifier to write
275
- */
276
- public async writeNullifier(contractAddress: AztecAddress, nullifier: Fr) {
277
- this.log.trace(`Inserting new nullifier (address=${nullifier}, nullifier=${contractAddress})`);
278
- const siloedNullifier = await siloNullifier(contractAddress, nullifier);
279
- await this.writeSiloedNullifier(siloedNullifier);
280
- }
281
-
282
- /**
283
- * Write a nullifier to the nullifier set, trace the write.
284
- * @param siloedNullifier - the siloed nullifier to write
285
- */
286
- public async writeSiloedNullifier(siloedNullifier: Fr) {
287
- this.log.trace(`Inserting siloed nullifier=${siloedNullifier}`);
288
-
289
- this.trace.traceNewNullifier(siloedNullifier);
290
-
291
- if (this.doMerkleOperations) {
292
- const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
293
-
294
- if (exists) {
295
- this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree!`);
296
- throw new NullifierCollisionError(
297
- `Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`,
298
- );
299
- } else {
300
- await this.treesDB.writeNullifier(siloedNullifier);
301
- }
302
- } else {
303
- // Cache pending nullifiers for later access
304
- await this.nullifiers.append(siloedNullifier);
305
- }
306
- }
307
-
308
- /**
309
- * Check if an L1 to L2 message exists, trace the check.
310
- * @param msgHash - the message hash to check existence of
311
- * @param msgLeafIndex - the message leaf index to use in the check
312
- * @returns exists - whether the message exists in the L1 to L2 Messages tree
313
- */
314
- public async checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean> {
315
- try {
316
- const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
317
- const exists = valueAtIndex.equals(msgHash);
318
- this.log.trace(
319
- `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`,
320
- );
321
- return Promise.resolve(exists);
322
- } catch (error) {
323
- // If the index is out of range, l1_to_l2_msg_leaf_in_range = 0 and the circuit returns false:
324
- if (error instanceof L1ToL2MessageIndexOutOfRangeError) {
325
- return Promise.resolve(false);
326
- }
327
- // Otherwise, unknown error. This is a bug.
328
- throw error;
329
- }
330
- }
331
-
332
- /**
333
- * Write an L2 to L1 message.
334
- * @param contractAddress - L2 contract address that created this message
335
- * @param recipient - L1 contract address to send the message to.
336
- * @param content - Message content.
337
- */
338
- public writeL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr) {
339
- this.log.trace(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`);
340
- this.trace.traceNewL2ToL1Message(contractAddress, recipient, content);
341
- }
342
-
343
- /**
344
- * Write a scoped L2 to L1 message.
345
- * @param l2ToL1Message - The L2 to L1 message to write.
346
- */
347
- public writeScopedL2ToL1Message(l2ToL1Message: ScopedL2ToL1Message) {
348
- this.writeL2ToL1Message(
349
- l2ToL1Message.contractAddress,
350
- l2ToL1Message.message.recipient.toField(),
351
- l2ToL1Message.message.content,
352
- );
353
- }
354
-
355
- public writeDebugLog(contractAddress: AztecAddress, level: LogLevel, message: string, fields: Fr[]) {
356
- this.trace.traceDebugLog(contractAddress, level, message, fields);
357
- }
358
-
359
- public writeDebugLogMemoryReads(memoryReads: number) {
360
- this.trace.traceDebugLogMemoryReads(memoryReads);
361
- }
362
-
363
- public getDebugLogMemoryReads() {
364
- return this.trace.getDebugLogMemoryReads();
365
- }
366
-
367
- public getLogs(): DebugLog[] {
368
- return this.trace.getDebugLogs();
369
- }
370
-
371
- /**
372
- * Write a public log
373
- * @param contractAddress - address of the contract that emitted the log
374
- * @param log - log contents
375
- */
376
- public writePublicLog(contractAddress: AztecAddress, log: Fr[]) {
377
- this.log.trace(`PublicLog(${contractAddress}) += event with ${log.length} fields.`);
378
- this.trace.tracePublicLog(contractAddress, log);
379
- }
380
-
381
- /**
382
- * Get a contract instance.
383
- * @param contractAddress - address of the contract instance to retrieve.
384
- * @returns the contract instance or undefined if it does not exist.
385
- */
386
- public async getContractInstance(contractAddress: AztecAddress): Promise<SerializableContractInstance | undefined> {
387
- this.log.trace(`Getting contract instance for address ${contractAddress}`);
388
- const instanceWithAddress = await this.contractsDB.getContractInstance(contractAddress, this.timestamp);
389
- const exists = instanceWithAddress !== undefined;
390
-
391
- const instance = exists ? new SerializableContractInstance(instanceWithAddress) : undefined;
392
-
393
- if (contractAddressIsCanonical(contractAddress)) {
394
- this.log.trace(
395
- `Got canonical contract instance (address=${contractAddress}): instance=${jsonStringify(instance!)}`,
396
- );
397
- return instance;
398
- }
399
-
400
- // Nullifier check! We do this regardless of whether or not the instance exists,
401
- // as even for non-existence, we need to generate nullifier check hints.
402
-
403
- // This will internally decide whether to check the nullifier tree or not depending on doMerkleOperations.
404
- const nullifierExistsInTree = await this.checkNullifierExists(
405
- AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
406
- contractAddress.toField(),
407
- );
408
- assert(
409
- exists == nullifierExistsInTree,
410
- `Contract instance for address ${contractAddress} in DB: ${exists} != nullifier tree: ${nullifierExistsInTree}. This is a bug!`,
411
- );
412
-
413
- if (!exists) {
414
- this.log.debug(`Contract instance NOT FOUND (address=${contractAddress})`);
415
- return undefined;
416
- }
417
-
418
- this.log.trace(`Got contract instance (address=${contractAddress}): instance=${jsonStringify(instance!)}`);
419
-
420
- // All that is left is to check that the contract updatability information is correct.
421
- // That is, that the current and original contract class ids are correct.
422
- await this.checkContractUpdateInformation(instanceWithAddress);
423
-
424
- return instance;
425
- }
426
-
427
- private async checkContractUpdateInformation(instance: ContractInstanceWithAddress): Promise<void> {
428
- // If "merkle operations" are not requested, we trust the DB.
429
- // Otherwise we check that the contract updatability information is correct.
430
- // That is, that the current and original contract class ids are correct.
431
- // All failures are fatal and the simulation is not expected to be provable.
432
- if (this.doMerkleOperations) {
433
- // Conceptually, we want to do the following:
434
- // * Read a DelayedPublicMutable at the contract update slot.
435
- // * Obtain the expected current class id from the DelayedPublicMutable, at the current block.
436
- // * if expectedId == 0 then currentClassId should be original contract class id
437
- // * if expectedId != 0 then currentClassId should be expectedId
438
- //
439
- // However, we will also be checking the hash of the delayed public mutable values.
440
- // This is a bit of a leak of information, since the circuit will use it to prove
441
- // one public read instead of N of the delayed public mutable values.
442
- const { delayedPublicMutableSlot, delayedPublicMutableHashSlot } =
443
- await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(instance.address);
444
- const readDeployerStorage = async (storageSlot: Fr) =>
445
- await this.readStorage(ProtocolContractAddress.ContractInstanceRegistry, storageSlot);
446
-
447
- const hash = await readDeployerStorage(delayedPublicMutableHashSlot);
448
- // NOTE: The below reads are either not performed (if hash.isZero()) or only performed in unconstrained in c++ simulation.
449
- // See UpdateCheck::check_current_class_id documentation - this means if we generate hints from the merkle db, they are unused:
450
- const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(
451
- delayedPublicMutableSlot,
452
- readDeployerStorage,
453
- );
454
- const preImage = delayedPublicMutableValues.toFields();
455
-
456
- // 1) update never scheduled: hash == 0 and preimage should be empty (but poseidon2hash(preimage) will not be 0s)
457
- if (hash.isZero()) {
458
- assert(
459
- preImage.every(f => f.isZero()),
460
- `Found updatability hash 0 but preimage is not empty for contract instance ${instance.address}.`,
461
- );
462
- assert(
463
- instance.currentContractClassId.equals(instance.originalContractClassId),
464
- `Found updatability hash 0 for contract instance ${instance.address} but original class id ${instance.originalContractClassId} != current class id ${instance.currentContractClassId}.`,
465
- );
466
- return;
467
- }
468
-
469
- // 2) At this point we know that the hash is not zero and this means that an update has at some point been scheduled.
470
- const computedHash = await poseidon2Hash(preImage);
471
- assert(
472
- hash.equals(computedHash),
473
- `Delayed public mutable values hash mismatch for contract instance ${instance.address}. Expected: ${hash}, computed: ${computedHash}`,
474
- );
475
-
476
- // We now check that, depending on the current block, the current class id is correct.
477
- const expectedClassIdRaw = delayedPublicMutableValues.svc.getCurrentAt(this.timestamp).at(0)!;
478
- const expectedClassId = expectedClassIdRaw.isZero() ? instance.originalContractClassId : expectedClassIdRaw;
479
- assert(
480
- instance.currentContractClassId.equals(expectedClassId),
481
- `Current class id mismatch
482
- for contract instance ${instance.address}. Expected: ${expectedClassId}, current: ${instance.currentContractClassId}`,
483
- );
484
- }
485
- }
486
-
487
- /**
488
- * Get a contract class.
489
- * @param classId - class id to retrieve.
490
- * @returns the contract class or undefined if it does not exist.
491
- */
492
- private async getContractClass(classId: Fr): Promise<ContractClassPublicWithCommitment | undefined> {
493
- this.log.trace(`Getting contract class for id ${classId}`);
494
- const contractClass = await this.contractsDB.getContractClass(classId);
495
- const exists = contractClass !== undefined;
496
- let extendedClass: ContractClassPublicWithCommitment | undefined = undefined;
497
-
498
- // Note: We currently do not generate info to check the nullifier tree, because
499
- // this is not needed for our use cases.
500
- if (exists) {
501
- this.log.trace(`Got contract class (id=${classId})`);
502
- // Extend class information with public bytecode commitment.
503
- const bytecodeCommitment = await this.contractsDB.getBytecodeCommitment(classId);
504
- assert(
505
- bytecodeCommitment,
506
- `Bytecode commitment was not found in DB for contract class (${classId}). This should not happen!`,
507
- );
508
- extendedClass = {
509
- ...contractClass,
510
- publicBytecodeCommitment: bytecodeCommitment,
511
- };
512
- } else {
513
- this.log.debug(`Contract class NOT FOUND (id=${classId})`);
514
- }
515
-
516
- // TODO(dbanks12): does this need to be moved to before the DB accesses as was done with writeNullifier?
517
- this.trace.traceGetContractClass(classId, exists);
518
- return extendedClass;
519
- }
520
-
521
- /**
522
- * Get a contract's bytecode from the contracts DB, also trace the contract class and instance indirectly.
523
- */
524
- public async getBytecode(contractAddress: AztecAddress): Promise<Buffer | undefined> {
525
- this.log.debug(`Getting bytecode for contract address ${contractAddress}`);
526
- const contractInstance = await this.getContractInstance(contractAddress);
527
-
528
- if (!contractInstance) {
529
- return undefined;
530
- }
531
-
532
- try {
533
- const contractClass = await this.getContractClass(contractInstance.currentContractClassId);
534
- assert(
535
- contractClass,
536
- `Contract class not found in DB, but a contract instance was found with this class ID (${contractInstance.currentContractClassId}). This should not happen!`,
537
- );
538
- return contractClass.packedBytecode;
539
- } catch (error) {
540
- if (error instanceof MaxCallsToUniqueContractClassIdsError) {
541
- return undefined;
542
- }
543
- // Otherwise, unknown error. This is a bug.
544
- throw error;
545
- }
546
- }
547
-
548
- public async getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string> {
549
- return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
550
- }
551
-
552
- public async getPublicFunctionSelectorAndName(
553
- avmEnvironment: AvmExecutionEnvironment,
554
- ): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
555
- return await getPublicFunctionSelectorAndName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
556
- }
557
-
558
- public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
559
- await this.treesDB.padTree(treeId, leavesToInsert);
560
- }
561
-
562
- public async getTreeSnapshots(): Promise<TreeSnapshots> {
563
- return await this.treesDB.getTreeSnapshots();
564
- }
565
- }
566
-
567
- function contractAddressIsCanonical(contractAddress: AztecAddress): boolean {
568
- return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
569
- }