@aztec/simulator 0.76.4 → 0.77.0-testnet-ignition.17

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 (505) hide show
  1. package/README.md +3 -3
  2. package/dest/client.d.ts +5 -0
  3. package/dest/client.d.ts.map +1 -0
  4. package/dest/client.js +3 -0
  5. package/dest/{public → common}/db_interfaces.d.ts +8 -33
  6. package/dest/common/db_interfaces.d.ts.map +1 -0
  7. package/dest/common/db_interfaces.js +1 -0
  8. package/dest/common/debug_fn_name.d.ts +3 -2
  9. package/dest/common/debug_fn_name.d.ts.map +1 -1
  10. package/dest/common/debug_fn_name.js +2 -5
  11. package/dest/common/errors.d.ts +4 -4
  12. package/dest/common/errors.d.ts.map +1 -1
  13. package/dest/common/errors.js +30 -39
  14. package/dest/common/index.d.ts +2 -1
  15. package/dest/common/index.d.ts.map +1 -1
  16. package/dest/common/index.js +2 -2
  17. package/dest/common/message_load_oracle_inputs.d.ts +2 -2
  18. package/dest/common/message_load_oracle_inputs.d.ts.map +1 -1
  19. package/dest/common/message_load_oracle_inputs.js +8 -8
  20. package/dest/common/stats/index.d.ts.map +1 -0
  21. package/dest/{stats → common/stats}/stats.d.ts +2 -2
  22. package/dest/common/stats/stats.d.ts.map +1 -0
  23. package/dest/common/stats/stats.js +10 -0
  24. package/dest/{acvm → private/acvm}/acvm.d.ts +4 -4
  25. package/dest/private/acvm/acvm.d.ts.map +1 -0
  26. package/dest/private/acvm/acvm.js +70 -0
  27. package/dest/{acvm → private/acvm}/acvm_types.d.ts +1 -1
  28. package/dest/private/acvm/acvm_types.d.ts.map +1 -0
  29. package/dest/private/acvm/acvm_types.js +3 -0
  30. package/dest/{acvm → private/acvm}/deserialize.d.ts +2 -2
  31. package/dest/private/acvm/deserialize.d.ts.map +1 -0
  32. package/dest/private/acvm/deserialize.js +42 -0
  33. package/dest/private/acvm/index.d.ts.map +1 -0
  34. package/dest/private/acvm/index.js +5 -0
  35. package/dest/{acvm → private/acvm}/oracle/index.d.ts +1 -1
  36. package/dest/private/acvm/oracle/index.d.ts.map +1 -0
  37. package/dest/private/acvm/oracle/index.js +2 -0
  38. package/dest/{acvm → private/acvm}/oracle/oracle.d.ts +4 -3
  39. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -0
  40. package/dest/private/acvm/oracle/oracle.js +263 -0
  41. package/dest/{acvm → private/acvm}/oracle/typed_oracle.d.ts +12 -6
  42. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -0
  43. package/dest/private/acvm/oracle/typed_oracle.js +132 -0
  44. package/dest/{acvm → private/acvm}/serialize.d.ts +7 -3
  45. package/dest/private/acvm/serialize.d.ts.map +1 -0
  46. package/dest/private/acvm/serialize.js +46 -0
  47. package/dest/{client → private}/client_execution_context.d.ts +20 -17
  48. package/dest/private/client_execution_context.d.ts.map +1 -0
  49. package/dest/private/client_execution_context.js +378 -0
  50. package/dest/{client → private}/db_oracle.d.ts +19 -7
  51. package/dest/private/db_oracle.d.ts.map +1 -0
  52. package/dest/private/db_oracle.js +14 -0
  53. package/dest/{client → private}/execution_note_cache.d.ts +2 -2
  54. package/dest/private/execution_note_cache.d.ts.map +1 -0
  55. package/dest/private/execution_note_cache.js +180 -0
  56. package/dest/{common → private}/hashed_values_cache.d.ts +2 -2
  57. package/dest/private/hashed_values_cache.d.ts.map +1 -0
  58. package/dest/private/hashed_values_cache.js +46 -0
  59. package/dest/private/index.d.ts +13 -0
  60. package/dest/private/index.d.ts.map +1 -0
  61. package/dest/private/index.js +12 -0
  62. package/dest/{client → private}/pick_notes.d.ts +1 -1
  63. package/dest/private/pick_notes.d.ts.map +1 -0
  64. package/dest/private/pick_notes.js +51 -0
  65. package/dest/private/private_execution.d.ts +24 -0
  66. package/dest/private/private_execution.d.ts.map +1 -0
  67. package/dest/private/private_execution.js +90 -0
  68. package/dest/{providers → private/providers}/acvm_native.d.ts +5 -5
  69. package/dest/private/providers/acvm_native.d.ts.map +1 -0
  70. package/dest/private/providers/acvm_native.js +139 -0
  71. package/dest/{providers → private/providers}/acvm_wasm.d.ts +4 -4
  72. package/dest/private/providers/acvm_wasm.d.ts.map +1 -0
  73. package/dest/private/providers/acvm_wasm.js +62 -0
  74. package/dest/{providers → private/providers}/acvm_wasm_with_blobs.d.ts +5 -5
  75. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -0
  76. package/dest/{providers → private/providers}/acvm_wasm_with_blobs.js +3 -6
  77. package/dest/{providers → private/providers}/factory.d.ts +1 -1
  78. package/dest/private/providers/factory.d.ts.map +1 -0
  79. package/dest/private/providers/factory.js +27 -0
  80. package/dest/{common → private/providers}/simulation_provider.d.ts +5 -5
  81. package/dest/private/providers/simulation_provider.d.ts.map +1 -0
  82. package/dest/private/providers/simulation_provider.js +24 -0
  83. package/dest/private/simulator.d.ts +36 -0
  84. package/dest/private/simulator.d.ts.map +1 -0
  85. package/dest/private/simulator.js +78 -0
  86. package/dest/{client → private}/unconstrained_execution.d.ts +5 -5
  87. package/dest/private/unconstrained_execution.d.ts.map +1 -0
  88. package/dest/private/unconstrained_execution.js +27 -0
  89. package/dest/{client → private}/view_data_oracle.d.ts +15 -7
  90. package/dest/private/view_data_oracle.d.ts.map +1 -0
  91. package/dest/private/view_data_oracle.js +260 -0
  92. package/dest/{avm → public/avm}/avm_context.d.ts +7 -5
  93. package/dest/public/avm/avm_context.d.ts.map +1 -0
  94. package/dest/public/avm/avm_context.js +44 -0
  95. package/dest/{avm → public/avm}/avm_contract_call_result.d.ts +5 -5
  96. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -0
  97. package/dest/public/avm/avm_contract_call_result.js +50 -0
  98. package/dest/{avm → public/avm}/avm_execution_environment.d.ts +2 -2
  99. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -0
  100. package/dest/public/avm/avm_execution_environment.js +31 -0
  101. package/dest/public/avm/avm_gas.d.ts.map +1 -0
  102. package/dest/public/avm/avm_gas.js +202 -0
  103. package/dest/{avm → public/avm}/avm_machine_state.d.ts +2 -2
  104. package/dest/public/avm/avm_machine_state.d.ts.map +1 -0
  105. package/dest/public/avm/avm_machine_state.js +106 -0
  106. package/dest/{avm → public/avm}/avm_memory_types.d.ts +2 -2
  107. package/dest/public/avm/avm_memory_types.d.ts.map +1 -0
  108. package/dest/public/avm/avm_memory_types.js +340 -0
  109. package/dest/{avm → public/avm}/avm_simulator.d.ts +5 -3
  110. package/dest/public/avm/avm_simulator.d.ts.map +1 -0
  111. package/dest/public/avm/avm_simulator.js +202 -0
  112. package/dest/public/avm/bytecode_utils.d.ts.map +1 -0
  113. package/dest/public/avm/bytecode_utils.js +17 -0
  114. package/dest/{avm → public/avm}/errors.d.ts +5 -4
  115. package/dest/public/avm/errors.d.ts.map +1 -0
  116. package/dest/public/avm/errors.js +179 -0
  117. package/dest/{avm → public/avm}/fixtures/avm_simulation_tester.d.ts +6 -6
  118. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
  119. package/dest/public/avm/fixtures/avm_simulation_tester.js +76 -0
  120. package/dest/{avm → public/avm}/fixtures/base_avm_simulation_tester.d.ts +13 -11
  121. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
  122. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +77 -0
  123. package/dest/{avm → public/avm}/fixtures/index.d.ts +7 -7
  124. package/dest/public/avm/fixtures/index.d.ts.map +1 -0
  125. package/dest/public/avm/fixtures/index.js +140 -0
  126. package/dest/{avm → public/avm}/fixtures/simple_contract_data_source.d.ts +10 -4
  127. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
  128. package/dest/public/avm/fixtures/simple_contract_data_source.js +112 -0
  129. package/dest/public/avm/index.d.ts +4 -0
  130. package/dest/public/avm/index.d.ts.map +1 -0
  131. package/dest/{avm/index.d.ts → public/avm/index.js} +1 -2
  132. package/dest/public/avm/journal/index.d.ts.map +1 -0
  133. package/dest/{avm → public/avm}/journal/journal.d.ts +51 -18
  134. package/dest/public/avm/journal/journal.d.ts.map +1 -0
  135. package/dest/public/avm/journal/journal.js +488 -0
  136. package/dest/{avm → public/avm}/journal/nullifiers.d.ts +8 -6
  137. package/dest/public/avm/journal/nullifiers.d.ts.map +1 -0
  138. package/dest/public/avm/journal/nullifiers.js +97 -0
  139. package/dest/{avm → public/avm}/journal/public_storage.d.ts +2 -2
  140. package/dest/public/avm/journal/public_storage.d.ts.map +1 -0
  141. package/dest/public/avm/journal/public_storage.js +145 -0
  142. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -0
  143. package/dest/public/avm/opcodes/accrued_substate.js +252 -0
  144. package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -0
  145. package/dest/public/avm/opcodes/addressing_mode.js +74 -0
  146. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -0
  147. package/dest/public/avm/opcodes/arithmetic.js +73 -0
  148. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -0
  149. package/dest/public/avm/opcodes/bitwise.js +106 -0
  150. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -0
  151. package/dest/public/avm/opcodes/comparators.js +43 -0
  152. package/dest/public/avm/opcodes/contract.d.ts.map +1 -0
  153. package/dest/public/avm/opcodes/contract.js +66 -0
  154. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -0
  155. package/dest/public/avm/opcodes/control_flow.js +105 -0
  156. package/dest/{avm → public/avm}/opcodes/conversion.d.ts +1 -1
  157. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -0
  158. package/dest/public/avm/opcodes/conversion.js +69 -0
  159. package/dest/{avm → public/avm}/opcodes/ec_add.d.ts +1 -1
  160. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -0
  161. package/dest/public/avm/opcodes/ec_add.js +84 -0
  162. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -0
  163. package/dest/public/avm/opcodes/environment_getters.js +79 -0
  164. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -0
  165. package/dest/public/avm/opcodes/external_calls.js +180 -0
  166. package/dest/{avm → public/avm}/opcodes/hashing.d.ts +1 -1
  167. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -0
  168. package/dest/public/avm/opcodes/hashing.js +114 -0
  169. package/dest/public/avm/opcodes/index.d.ts.map +1 -0
  170. package/dest/{avm → public/avm}/opcodes/instruction.d.ts +2 -2
  171. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -0
  172. package/dest/public/avm/opcodes/instruction.js +91 -0
  173. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -0
  174. package/dest/public/avm/opcodes/instruction_impl.js +30 -0
  175. package/dest/public/avm/opcodes/memory.d.ts.map +1 -0
  176. package/dest/public/avm/opcodes/memory.js +253 -0
  177. package/dest/{avm → public/avm}/opcodes/misc.d.ts +1 -1
  178. package/dest/public/avm/opcodes/misc.d.ts.map +1 -0
  179. package/dest/public/avm/opcodes/misc.js +48 -0
  180. package/dest/public/avm/opcodes/storage.d.ts.map +1 -0
  181. package/dest/public/avm/opcodes/storage.js +66 -0
  182. package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -0
  183. package/dest/public/avm/serialization/buffer_cursor.js +99 -0
  184. package/dest/{avm → public/avm}/serialization/bytecode_serialization.d.ts +1 -1
  185. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -0
  186. package/dest/public/avm/serialization/bytecode_serialization.js +328 -0
  187. package/dest/{avm → public/avm}/serialization/instruction_serialization.d.ts +1 -2
  188. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -0
  189. package/dest/public/avm/serialization/instruction_serialization.js +225 -0
  190. package/dest/{avm → public/avm}/test_utils.d.ts +6 -4
  191. package/dest/public/avm/test_utils.d.ts.map +1 -0
  192. package/dest/public/avm/test_utils.js +52 -0
  193. package/dest/public/bytecode_errors.js +1 -2
  194. package/dest/public/execution.d.ts +8 -2
  195. package/dest/public/execution.d.ts.map +1 -1
  196. package/dest/public/execution.js +4 -5
  197. package/dest/public/executor_metrics.js +16 -12
  198. package/dest/public/fixtures/index.js +0 -1
  199. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -8
  200. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  201. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -44
  202. package/dest/public/fixtures/utils.d.ts +3 -11
  203. package/dest/public/fixtures/utils.d.ts.map +1 -1
  204. package/dest/public/fixtures/utils.js +15 -35
  205. package/dest/public/index.d.ts +3 -2
  206. package/dest/public/index.d.ts.map +1 -1
  207. package/dest/public/index.js +3 -3
  208. package/dest/public/public_db_sources.d.ts +22 -28
  209. package/dest/public/public_db_sources.d.ts.map +1 -1
  210. package/dest/public/public_db_sources.js +75 -181
  211. package/dest/public/public_processor.d.ts +8 -6
  212. package/dest/public/public_processor.d.ts.map +1 -1
  213. package/dest/public/public_processor.js +329 -308
  214. package/dest/public/public_processor_metrics.d.ts +3 -3
  215. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  216. package/dest/public/public_processor_metrics.js +46 -27
  217. package/dest/public/public_tx_context.d.ts +14 -8
  218. package/dest/public/public_tx_context.d.ts.map +1 -1
  219. package/dest/public/public_tx_context.js +122 -143
  220. package/dest/public/public_tx_simulator.d.ts +8 -5
  221. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  222. package/dest/public/public_tx_simulator.js +306 -317
  223. package/dest/public/side_effect_errors.js +1 -2
  224. package/dest/public/side_effect_trace.d.ts +16 -10
  225. package/dest/public/side_effect_trace.d.ts.map +1 -1
  226. package/dest/public/side_effect_trace.js +65 -132
  227. package/dest/public/side_effect_trace_interface.d.ts +9 -7
  228. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  229. package/dest/public/side_effect_trace_interface.js +1 -2
  230. package/dest/public/unique_class_ids.js +23 -28
  231. package/dest/public/utils.d.ts +2 -2
  232. package/dest/public/utils.d.ts.map +1 -1
  233. package/dest/public/utils.js +17 -12
  234. package/dest/server.d.ts +4 -4
  235. package/dest/server.d.ts.map +1 -1
  236. package/dest/server.js +3 -5
  237. package/dest/test/utils.d.ts +3 -2
  238. package/dest/test/utils.d.ts.map +1 -1
  239. package/dest/test/utils.js +9 -7
  240. package/package.json +16 -18
  241. package/src/client.ts +4 -0
  242. package/src/{public → common}/db_interfaces.ts +8 -40
  243. package/src/common/debug_fn_name.ts +4 -2
  244. package/src/common/errors.ts +5 -5
  245. package/src/common/index.ts +2 -1
  246. package/src/common/message_load_oracle_inputs.ts +2 -2
  247. package/src/common/stats/index.ts +1 -0
  248. package/src/{stats → common/stats}/stats.ts +2 -2
  249. package/src/{acvm → private/acvm}/acvm.ts +5 -5
  250. package/src/{acvm → private/acvm}/acvm_types.ts +1 -1
  251. package/src/{acvm → private/acvm}/deserialize.ts +2 -2
  252. package/src/{acvm → private/acvm}/oracle/index.ts +1 -1
  253. package/src/{acvm → private/acvm}/oracle/oracle.ts +22 -12
  254. package/src/{acvm → private/acvm}/oracle/typed_oracle.ts +50 -55
  255. package/src/{acvm → private/acvm}/serialize.ts +10 -3
  256. package/src/{client → private}/client_execution_context.ts +54 -37
  257. package/src/{client → private}/db_oracle.ts +20 -20
  258. package/src/{client → private}/execution_note_cache.ts +3 -3
  259. package/src/{common → private}/hashed_values_cache.ts +2 -2
  260. package/src/private/index.ts +12 -0
  261. package/src/{client → private}/pick_notes.ts +1 -1
  262. package/src/{client → private}/private_execution.ts +46 -14
  263. package/src/{providers → private/providers}/acvm_native.ts +6 -6
  264. package/src/{providers → private/providers}/acvm_wasm.ts +4 -4
  265. package/src/{providers → private/providers}/acvm_wasm_with_blobs.ts +5 -5
  266. package/src/{providers → private/providers}/factory.ts +1 -1
  267. package/src/{common → private/providers}/simulation_provider.ts +5 -5
  268. package/src/{client → private}/simulator.ts +31 -123
  269. package/src/{client → private}/unconstrained_execution.ts +7 -7
  270. package/src/{client → private}/view_data_oracle.ts +25 -28
  271. package/src/{avm → public/avm}/avm_context.ts +12 -7
  272. package/src/{avm → public/avm}/avm_contract_call_result.ts +6 -6
  273. package/src/{avm → public/avm}/avm_execution_environment.ts +2 -2
  274. package/src/{avm → public/avm}/avm_gas.ts +1 -3
  275. package/src/{avm → public/avm}/avm_machine_state.ts +2 -2
  276. package/src/{avm → public/avm}/avm_memory_types.ts +4 -4
  277. package/src/{avm → public/avm}/avm_simulator.ts +12 -6
  278. package/src/{avm → public/avm}/errors.ts +5 -4
  279. package/src/{avm → public/avm}/fixtures/avm_simulation_tester.ts +16 -15
  280. package/src/{avm → public/avm}/fixtures/base_avm_simulation_tester.ts +38 -40
  281. package/src/{avm → public/avm}/fixtures/index.ts +17 -12
  282. package/src/{avm → public/avm}/fixtures/simple_contract_data_source.ts +64 -9
  283. package/src/{avm → public/avm}/index.ts +1 -1
  284. package/src/public/avm/journal/index.ts +1 -0
  285. package/src/{avm → public/avm}/journal/journal.ts +332 -305
  286. package/src/{avm → public/avm}/journal/nullifiers.ts +20 -19
  287. package/src/{avm → public/avm}/journal/public_storage.ts +2 -2
  288. package/src/{avm → public/avm}/opcodes/contract.ts +1 -1
  289. package/src/{avm → public/avm}/opcodes/control_flow.ts +1 -1
  290. package/src/{avm → public/avm}/opcodes/conversion.ts +1 -1
  291. package/src/{avm → public/avm}/opcodes/ec_add.ts +2 -2
  292. package/src/{avm → public/avm}/opcodes/external_calls.ts +5 -6
  293. package/src/{avm → public/avm}/opcodes/hashing.ts +1 -1
  294. package/src/public/avm/opcodes/index.ts +15 -0
  295. package/src/{avm → public/avm}/opcodes/instruction.ts +2 -2
  296. package/src/{avm → public/avm}/opcodes/misc.ts +1 -1
  297. package/src/public/avm/serialization/bytecode_serialization.ts +204 -0
  298. package/src/{avm → public/avm}/serialization/instruction_serialization.ts +0 -1
  299. package/src/{avm → public/avm}/test_utils.ts +10 -7
  300. package/src/public/execution.ts +9 -12
  301. package/src/public/fixtures/public_tx_simulation_tester.ts +45 -63
  302. package/src/public/fixtures/utils.ts +8 -43
  303. package/src/public/index.ts +3 -2
  304. package/src/public/public_db_sources.ts +55 -188
  305. package/src/public/public_processor.ts +66 -47
  306. package/src/public/public_processor_metrics.ts +3 -3
  307. package/src/public/public_tx_context.ts +69 -74
  308. package/src/public/public_tx_simulator.ts +35 -27
  309. package/src/public/side_effect_trace.ts +67 -140
  310. package/src/public/side_effect_trace_interface.ts +10 -23
  311. package/src/public/unique_class_ids.ts +1 -1
  312. package/src/public/utils.ts +2 -2
  313. package/src/server.ts +4 -4
  314. package/src/test/utils.ts +5 -3
  315. package/dest/acvm/acvm.d.ts.map +0 -1
  316. package/dest/acvm/acvm.js +0 -73
  317. package/dest/acvm/acvm_types.d.ts.map +0 -1
  318. package/dest/acvm/acvm_types.js +0 -2
  319. package/dest/acvm/deserialize.d.ts.map +0 -1
  320. package/dest/acvm/deserialize.js +0 -46
  321. package/dest/acvm/index.d.ts.map +0 -1
  322. package/dest/acvm/index.js +0 -6
  323. package/dest/acvm/oracle/index.d.ts.map +0 -1
  324. package/dest/acvm/oracle/index.js +0 -3
  325. package/dest/acvm/oracle/oracle.d.ts.map +0 -1
  326. package/dest/acvm/oracle/oracle.js +0 -230
  327. package/dest/acvm/oracle/typed_oracle.d.ts.map +0 -1
  328. package/dest/acvm/oracle/typed_oracle.js +0 -131
  329. package/dest/acvm/serialize.d.ts.map +0 -1
  330. package/dest/acvm/serialize.js +0 -48
  331. package/dest/avm/avm_context.d.ts.map +0 -1
  332. package/dest/avm/avm_context.js +0 -44
  333. package/dest/avm/avm_contract_call_result.d.ts.map +0 -1
  334. package/dest/avm/avm_contract_call_result.js +0 -45
  335. package/dest/avm/avm_execution_environment.d.ts.map +0 -1
  336. package/dest/avm/avm_execution_environment.js +0 -28
  337. package/dest/avm/avm_gas.d.ts.map +0 -1
  338. package/dest/avm/avm_gas.js +0 -170
  339. package/dest/avm/avm_machine_state.d.ts.map +0 -1
  340. package/dest/avm/avm_machine_state.js +0 -112
  341. package/dest/avm/avm_memory_types.d.ts.map +0 -1
  342. package/dest/avm/avm_memory_types.js +0 -327
  343. package/dest/avm/avm_simulator.d.ts.map +0 -1
  344. package/dest/avm/avm_simulator.js +0 -193
  345. package/dest/avm/avm_tree.d.ts +0 -282
  346. package/dest/avm/avm_tree.d.ts.map +0 -1
  347. package/dest/avm/avm_tree.js +0 -684
  348. package/dest/avm/bytecode_utils.d.ts.map +0 -1
  349. package/dest/avm/bytecode_utils.js +0 -15
  350. package/dest/avm/errors.d.ts.map +0 -1
  351. package/dest/avm/errors.js +0 -196
  352. package/dest/avm/fixtures/avm_simulation_tester.d.ts.map +0 -1
  353. package/dest/avm/fixtures/avm_simulation_tester.js +0 -73
  354. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts.map +0 -1
  355. package/dest/avm/fixtures/base_avm_simulation_tester.js +0 -76
  356. package/dest/avm/fixtures/index.d.ts.map +0 -1
  357. package/dest/avm/fixtures/index.js +0 -134
  358. package/dest/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
  359. package/dest/avm/fixtures/simple_contract_data_source.js +0 -75
  360. package/dest/avm/index.d.ts.map +0 -1
  361. package/dest/avm/index.js +0 -4
  362. package/dest/avm/journal/index.d.ts.map +0 -1
  363. package/dest/avm/journal/index.js +0 -2
  364. package/dest/avm/journal/journal.d.ts.map +0 -1
  365. package/dest/avm/journal/journal.js +0 -499
  366. package/dest/avm/journal/nullifiers.d.ts.map +0 -1
  367. package/dest/avm/journal/nullifiers.js +0 -99
  368. package/dest/avm/journal/public_storage.d.ts.map +0 -1
  369. package/dest/avm/journal/public_storage.js +0 -159
  370. package/dest/avm/opcodes/accrued_substate.d.ts.map +0 -1
  371. package/dest/avm/opcodes/accrued_substate.js +0 -215
  372. package/dest/avm/opcodes/addressing_mode.d.ts.map +0 -1
  373. package/dest/avm/opcodes/addressing_mode.js +0 -81
  374. package/dest/avm/opcodes/arithmetic.d.ts.map +0 -1
  375. package/dest/avm/opcodes/arithmetic.js +0 -70
  376. package/dest/avm/opcodes/bitwise.d.ts.map +0 -1
  377. package/dest/avm/opcodes/bitwise.js +0 -90
  378. package/dest/avm/opcodes/comparators.d.ts.map +0 -1
  379. package/dest/avm/opcodes/comparators.js +0 -40
  380. package/dest/avm/opcodes/contract.d.ts.map +0 -1
  381. package/dest/avm/opcodes/contract.js +0 -63
  382. package/dest/avm/opcodes/control_flow.d.ts.map +0 -1
  383. package/dest/avm/opcodes/control_flow.js +0 -97
  384. package/dest/avm/opcodes/conversion.d.ts.map +0 -1
  385. package/dest/avm/opcodes/conversion.js +0 -64
  386. package/dest/avm/opcodes/ec_add.d.ts.map +0 -1
  387. package/dest/avm/opcodes/ec_add.js +0 -82
  388. package/dest/avm/opcodes/environment_getters.d.ts.map +0 -1
  389. package/dest/avm/opcodes/environment_getters.js +0 -78
  390. package/dest/avm/opcodes/external_calls.d.ts.map +0 -1
  391. package/dest/avm/opcodes/external_calls.js +0 -169
  392. package/dest/avm/opcodes/hashing.d.ts.map +0 -1
  393. package/dest/avm/opcodes/hashing.js +0 -103
  394. package/dest/avm/opcodes/index.d.ts.map +0 -1
  395. package/dest/avm/opcodes/index.js +0 -16
  396. package/dest/avm/opcodes/instruction.d.ts.map +0 -1
  397. package/dest/avm/opcodes/instruction.js +0 -100
  398. package/dest/avm/opcodes/instruction_impl.d.ts.map +0 -1
  399. package/dest/avm/opcodes/instruction_impl.js +0 -33
  400. package/dest/avm/opcodes/memory.d.ts.map +0 -1
  401. package/dest/avm/opcodes/memory.js +0 -226
  402. package/dest/avm/opcodes/misc.d.ts.map +0 -1
  403. package/dest/avm/opcodes/misc.js +0 -45
  404. package/dest/avm/opcodes/multi_scalar_mul.d.ts +0 -16
  405. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +0 -1
  406. package/dest/avm/opcodes/multi_scalar_mul.js +0 -112
  407. package/dest/avm/opcodes/storage.d.ts.map +0 -1
  408. package/dest/avm/opcodes/storage.js +0 -61
  409. package/dest/avm/serialization/buffer_cursor.d.ts.map +0 -1
  410. package/dest/avm/serialization/buffer_cursor.js +0 -99
  411. package/dest/avm/serialization/bytecode_serialization.d.ts.map +0 -1
  412. package/dest/avm/serialization/bytecode_serialization.js +0 -132
  413. package/dest/avm/serialization/instruction_serialization.d.ts.map +0 -1
  414. package/dest/avm/serialization/instruction_serialization.js +0 -187
  415. package/dest/avm/test_utils.d.ts.map +0 -1
  416. package/dest/avm/test_utils.js +0 -52
  417. package/dest/client/client_execution_context.d.ts.map +0 -1
  418. package/dest/client/client_execution_context.js +0 -392
  419. package/dest/client/db_oracle.d.ts.map +0 -1
  420. package/dest/client/db_oracle.js +0 -17
  421. package/dest/client/execution_note_cache.d.ts.map +0 -1
  422. package/dest/client/execution_note_cache.js +0 -181
  423. package/dest/client/index.d.ts +0 -16
  424. package/dest/client/index.d.ts.map +0 -1
  425. package/dest/client/index.js +0 -15
  426. package/dest/client/pick_notes.d.ts.map +0 -1
  427. package/dest/client/pick_notes.js +0 -54
  428. package/dest/client/private_execution.d.ts +0 -19
  429. package/dest/client/private_execution.d.ts.map +0 -1
  430. package/dest/client/private_execution.js +0 -72
  431. package/dest/client/simulator.d.ts +0 -60
  432. package/dest/client/simulator.d.ts.map +0 -1
  433. package/dest/client/simulator.js +0 -136
  434. package/dest/client/unconstrained_execution.d.ts.map +0 -1
  435. package/dest/client/unconstrained_execution.js +0 -30
  436. package/dest/client/view_data_oracle.d.ts.map +0 -1
  437. package/dest/client/view_data_oracle.js +0 -268
  438. package/dest/common/hashed_values_cache.d.ts.map +0 -1
  439. package/dest/common/hashed_values_cache.js +0 -50
  440. package/dest/common/simulation_provider.d.ts.map +0 -1
  441. package/dest/common/simulation_provider.js +0 -27
  442. package/dest/common.d.ts +0 -2
  443. package/dest/common.d.ts.map +0 -1
  444. package/dest/common.js +0 -2
  445. package/dest/providers/acvm_native.d.ts.map +0 -1
  446. package/dest/providers/acvm_native.js +0 -125
  447. package/dest/providers/acvm_wasm.d.ts.map +0 -1
  448. package/dest/providers/acvm_wasm.js +0 -54
  449. package/dest/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
  450. package/dest/providers/factory.d.ts.map +0 -1
  451. package/dest/providers/factory.js +0 -27
  452. package/dest/providers/index.d.ts +0 -5
  453. package/dest/providers/index.d.ts.map +0 -1
  454. package/dest/providers/index.js +0 -5
  455. package/dest/public/db_interfaces.d.ts.map +0 -1
  456. package/dest/public/db_interfaces.js +0 -2
  457. package/dest/public/fee_payment.d.ts +0 -11
  458. package/dest/public/fee_payment.d.ts.map +0 -1
  459. package/dest/public/fee_payment.js +0 -21
  460. package/dest/stats/index.d.ts.map +0 -1
  461. package/dest/stats/index.js +0 -2
  462. package/dest/stats/stats.d.ts.map +0 -1
  463. package/dest/stats/stats.js +0 -11
  464. package/src/avm/avm_tree.ts +0 -887
  465. package/src/avm/opcodes/multi_scalar_mul.ts +0 -121
  466. package/src/avm/serialization/bytecode_serialization.ts +0 -212
  467. package/src/client/index.ts +0 -15
  468. package/src/common.ts +0 -1
  469. package/src/providers/index.ts +0 -4
  470. package/src/public/fee_payment.ts +0 -23
  471. /package/dest/{stats → common/stats}/index.d.ts +0 -0
  472. /package/{src/stats/index.ts → dest/common/stats/index.js} +0 -0
  473. /package/dest/{acvm → private/acvm}/index.d.ts +0 -0
  474. /package/dest/{avm → public/avm}/avm_gas.d.ts +0 -0
  475. /package/dest/{avm → public/avm}/bytecode_utils.d.ts +0 -0
  476. /package/dest/{avm → public/avm}/journal/index.d.ts +0 -0
  477. /package/{src/avm/journal/index.ts → dest/public/avm/journal/index.js} +0 -0
  478. /package/dest/{avm → public/avm}/opcodes/accrued_substate.d.ts +0 -0
  479. /package/dest/{avm → public/avm}/opcodes/addressing_mode.d.ts +0 -0
  480. /package/dest/{avm → public/avm}/opcodes/arithmetic.d.ts +0 -0
  481. /package/dest/{avm → public/avm}/opcodes/bitwise.d.ts +0 -0
  482. /package/dest/{avm → public/avm}/opcodes/comparators.d.ts +0 -0
  483. /package/dest/{avm → public/avm}/opcodes/contract.d.ts +0 -0
  484. /package/dest/{avm → public/avm}/opcodes/control_flow.d.ts +0 -0
  485. /package/dest/{avm → public/avm}/opcodes/environment_getters.d.ts +0 -0
  486. /package/dest/{avm → public/avm}/opcodes/external_calls.d.ts +0 -0
  487. /package/dest/{avm → public/avm}/opcodes/index.d.ts +0 -0
  488. /package/{src/avm/opcodes/index.ts → dest/public/avm/opcodes/index.js} +0 -0
  489. /package/dest/{avm → public/avm}/opcodes/instruction_impl.d.ts +0 -0
  490. /package/dest/{avm → public/avm}/opcodes/memory.d.ts +0 -0
  491. /package/dest/{avm → public/avm}/opcodes/storage.d.ts +0 -0
  492. /package/dest/{avm → public/avm}/serialization/buffer_cursor.d.ts +0 -0
  493. /package/src/{acvm → private/acvm}/index.ts +0 -0
  494. /package/src/{avm → public/avm}/bytecode_utils.ts +0 -0
  495. /package/src/{avm → public/avm}/opcodes/.eslintrc.cjs +0 -0
  496. /package/src/{avm → public/avm}/opcodes/accrued_substate.ts +0 -0
  497. /package/src/{avm → public/avm}/opcodes/addressing_mode.ts +0 -0
  498. /package/src/{avm → public/avm}/opcodes/arithmetic.ts +0 -0
  499. /package/src/{avm → public/avm}/opcodes/bitwise.ts +0 -0
  500. /package/src/{avm → public/avm}/opcodes/comparators.ts +0 -0
  501. /package/src/{avm → public/avm}/opcodes/environment_getters.ts +0 -0
  502. /package/src/{avm → public/avm}/opcodes/instruction_impl.ts +0 -0
  503. /package/src/{avm → public/avm}/opcodes/memory.ts +0 -0
  504. /package/src/{avm → public/avm}/opcodes/storage.ts +0 -0
  505. /package/src/{avm → public/avm}/serialization/buffer_cursor.ts +0 -0
@@ -1,6 +1,6 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/fields';
2
2
 
3
- import type { CommitmentsDB } from '../../server.js';
3
+ import type { WorldStateDB } from '../../public_db_sources.js';
4
4
 
5
5
  /**
6
6
  * A class to manage new nullifier staging and existence checks during a contract call's AVM simulation.
@@ -10,7 +10,7 @@ import type { CommitmentsDB } from '../../server.js';
10
10
  export class NullifierManager {
11
11
  constructor(
12
12
  /** Reference to node storage. Checked on parent cache-miss. */
13
- private readonly hostNullifiers: CommitmentsDB,
13
+ private readonly hostNullifiers: WorldStateDB,
14
14
  /** Cache of siloed nullifiers. */
15
15
  private cache: Set<bigint> = new Set(),
16
16
  /** Parent nullifier manager to fall back on */
@@ -50,24 +50,25 @@ export class NullifierManager {
50
50
  *
51
51
  * @param siloedNullifier - the nullifier to check for
52
52
  * @returns exists: whether the nullifier exists at all,
53
- * isPending: whether the nullifier was found in a cache,
54
- * leafIndex: the nullifier's leaf index if it exists and is not pending (comes from host state).
53
+ * cacheHit: whether the nullifier was found in a cache,
55
54
  */
56
- public async checkExists(
57
- siloedNullifier: Fr,
58
- ): Promise<[/*exists=*/ boolean, /*isPending=*/ boolean, /*leafIndex=*/ Fr]> {
55
+ public async checkExists(siloedNullifier: Fr): Promise<{ exists: boolean; cacheHit: boolean }> {
59
56
  // Check this cache and parent's (recursively)
60
- const existsAsPending = this.checkExistsHereOrParent(siloedNullifier);
61
- // Finally try the host's Aztec state (a trip to the database)
62
- // If the value is found in the database, it will be associated with a leaf index!
63
- let leafIndex: bigint | undefined = undefined;
64
- if (!existsAsPending) {
65
- // silo the nullifier before checking for its existence in the host
66
- leafIndex = await this.hostNullifiers.getNullifierIndex(siloedNullifier);
57
+ const cacheHit = this.checkExistsHereOrParent(siloedNullifier);
58
+ let existsInTree = false;
59
+ if (!cacheHit) {
60
+ // Finally try the host's Aztec state (a trip to the database)
61
+ //const leafOrLowLeafIndex = await this.hostNullifiers.db.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, siloedNullifier.toBigInt());
62
+ //assert(
63
+ // leafOrLowLeafIndex !== undefined,
64
+ // `${MerkleTreeId[MerkleTreeId.NULLIFIER_TREE]} low leaf index should always be found (even if target leaf does not exist)`,
65
+ //);
66
+ //existsInTree = leafOrLowLeafIndex.alreadyPresent;
67
+ const leafIndex = await this.hostNullifiers.getNullifierIndex(siloedNullifier);
68
+ existsInTree = leafIndex !== undefined;
67
69
  }
68
- const exists = existsAsPending || leafIndex !== undefined;
69
- leafIndex = leafIndex === undefined ? BigInt(0) : leafIndex;
70
- return Promise.resolve([exists, existsAsPending, new Fr(leafIndex)]);
70
+ const exists = cacheHit || existsInTree;
71
+ return Promise.resolve({ exists, cacheHit });
71
72
  }
72
73
 
73
74
  /**
@@ -76,7 +77,7 @@ export class NullifierManager {
76
77
  * @param siloedNullifier - the nullifier to stage
77
78
  */
78
79
  public async append(siloedNullifier: Fr) {
79
- const [exists, ,] = await this.checkExists(siloedNullifier);
80
+ const { exists } = await this.checkExists(siloedNullifier);
80
81
  if (exists) {
81
82
  throw new NullifierCollisionError(`Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`);
82
83
  }
@@ -1,7 +1,7 @@
1
- import { type AztecAddress } from '@aztec/circuits.js';
2
1
  import { Fr } from '@aztec/foundation/fields';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
- import type { PublicStateDB } from '../../server.js';
4
+ import type { PublicStateDB } from '../../../common/db_interfaces.js';
5
5
 
6
6
  type PublicStorageReadResult = {
7
7
  value: Fr;
@@ -58,7 +58,7 @@ export class GetContractInstance extends Instruction {
58
58
  memberValue = new Field(instance.deployer.toField());
59
59
  break;
60
60
  case ContractInstanceMember.CLASS_ID:
61
- memberValue = new Field(instance.contractClassId.toField());
61
+ memberValue = new Field(instance.currentContractClassId.toField());
62
62
  break;
63
63
  case ContractInstanceMember.INIT_HASH:
64
64
  memberValue = new Field(instance.initializationHash);
@@ -1,5 +1,5 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
- import { type IntegralValue } from '../avm_memory_types.js';
2
+ import type { IntegralValue } from '../avm_memory_types.js';
3
3
  import { InstructionExecutionError } from '../errors.js';
4
4
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
5
  import { Addressing } from './addressing_mode.js';
@@ -1,4 +1,4 @@
1
- import { type AvmContext } from '../avm_context.js';
1
+ import type { AvmContext } from '../avm_context.js';
2
2
  import { TypeTag, Uint1, Uint8 } from '../avm_memory_types.js';
3
3
  import { InvalidToRadixInputsError } from '../errors.js';
4
4
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
@@ -1,7 +1,7 @@
1
- import { Grumpkin } from '@aztec/circuits.js/barretenberg';
1
+ import { Grumpkin } from '@aztec/foundation/crypto';
2
2
  import { Point } from '@aztec/foundation/fields';
3
3
 
4
- import { type AvmContext } from '../avm_context.js';
4
+ import type { AvmContext } from '../avm_context.js';
5
5
  import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
6
6
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
7
7
  import { Addressing } from './addressing_mode.js';
@@ -1,7 +1,6 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
- import { type AvmContractCallResult } from '../avm_contract_call_result.js';
2
+ import type { AvmContractCallResult } from '../avm_contract_call_result.js';
3
3
  import { type Field, TypeTag, Uint1 } from '../avm_memory_types.js';
4
- import { AvmSimulator } from '../avm_simulator.js';
5
4
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
5
  import { Addressing } from './addressing_mode.js';
7
6
  import { Instruction } from './instruction.js';
@@ -60,9 +59,9 @@ abstract class ExternalCall extends Instruction {
60
59
  context.machineState.consumeGas(allocatedGas);
61
60
 
62
61
  const aztecAddress = callAddress.toAztecAddress();
63
- const nestedContext = context.createNestedContractCallContext(aztecAddress, calldata, allocatedGas, callType);
62
+ const nestedContext = await context.createNestedContractCallContext(aztecAddress, calldata, allocatedGas, callType);
64
63
 
65
- const simulator = await AvmSimulator.build(nestedContext);
64
+ const simulator = await context.provideSimulator!(nestedContext);
66
65
  const nestedCallResults: AvmContractCallResult = await simulator.execute();
67
66
  const success = !nestedCallResults.reverted;
68
67
 
@@ -90,9 +89,9 @@ abstract class ExternalCall extends Instruction {
90
89
 
91
90
  // Merge nested call's state and trace based on whether it succeeded.
92
91
  if (success) {
93
- context.persistableState.merge(nestedContext.persistableState);
92
+ await context.persistableState.merge(nestedContext.persistableState);
94
93
  } else {
95
- context.persistableState.reject(nestedContext.persistableState);
94
+ await context.persistableState.reject(nestedContext.persistableState);
96
95
  }
97
96
  }
98
97
 
@@ -1,6 +1,6 @@
1
1
  import { keccakf1600, poseidon2Permutation, sha256Compression } from '@aztec/foundation/crypto';
2
2
 
3
- import { type AvmContext } from '../avm_context.js';
3
+ import type { AvmContext } from '../avm_context.js';
4
4
  import { Field, TypeTag, Uint32, Uint64 } from '../avm_memory_types.js';
5
5
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
6
  import { Addressing } from './addressing_mode.js';
@@ -0,0 +1,15 @@
1
+ export * from './arithmetic.js';
2
+ export * from './bitwise.js';
3
+ export * from './control_flow.js';
4
+ export * from './contract.js';
5
+ export * from './conversion.js';
6
+ export * from './instruction.js';
7
+ export * from './comparators.js';
8
+ export * from './memory.js';
9
+ export * from './misc.js';
10
+ export * from './storage.js';
11
+ export * from './external_calls.js';
12
+ export * from './environment_getters.js';
13
+ export * from './accrued_substate.js';
14
+ export * from './hashing.js';
15
+ export * from './ec_add.js';
@@ -2,8 +2,8 @@ import { strict as assert } from 'assert';
2
2
 
3
3
  import type { AvmContext } from '../avm_context.js';
4
4
  import { type Gas, getBaseGasCost, getDynamicGasCost, mulGas, sumGas } from '../avm_gas.js';
5
- import { type BufferCursor } from '../serialization/buffer_cursor.js';
6
- import { type Serializable } from '../serialization/bytecode_serialization.js';
5
+ import type { BufferCursor } from '../serialization/buffer_cursor.js';
6
+ import type { Serializable } from '../serialization/bytecode_serialization.js';
7
7
  import { Opcode, type OperandType, deserialize, serializeAs } from '../serialization/instruction_serialization.js';
8
8
 
9
9
  type InstructionConstructor = {
@@ -1,6 +1,6 @@
1
1
  import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
2
2
 
3
- import { type AvmContext } from '../avm_context.js';
3
+ import type { AvmContext } from '../avm_context.js';
4
4
  import { TypeTag } from '../avm_memory_types.js';
5
5
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
6
  import { Addressing } from './addressing_mode.js';
@@ -0,0 +1,204 @@
1
+ import { AvmExecutionError, AvmParsingError, InvalidOpcodeError, InvalidProgramCounterError } from '../errors.js';
2
+ import {
3
+ Add,
4
+ And,
5
+ Call,
6
+ CalldataCopy,
7
+ Cast,
8
+ DebugLog,
9
+ Div,
10
+ EcAdd,
11
+ EmitNoteHash,
12
+ EmitNullifier,
13
+ EmitUnencryptedLog,
14
+ Eq,
15
+ FieldDiv,
16
+ GetContractInstance,
17
+ GetEnvVar,
18
+ Instruction,
19
+ InternalCall,
20
+ InternalReturn,
21
+ Jump,
22
+ JumpI,
23
+ KeccakF1600,
24
+ L1ToL2MessageExists,
25
+ Lt,
26
+ Lte,
27
+ Mov,
28
+ Mul,
29
+ Not,
30
+ NoteHashExists,
31
+ NullifierExists,
32
+ Or,
33
+ Poseidon2,
34
+ Return,
35
+ ReturndataCopy,
36
+ ReturndataSize,
37
+ Revert,
38
+ SLoad,
39
+ SStore,
40
+ SendL2ToL1Message,
41
+ Set,
42
+ Sha256Compression,
43
+ Shl,
44
+ Shr,
45
+ StaticCall,
46
+ Sub,
47
+ ToRadixBE,
48
+ Xor,
49
+ } from '../opcodes/index.js';
50
+ import { BufferCursor } from './buffer_cursor.js';
51
+ import { MAX_OPCODE_VALUE, Opcode } from './instruction_serialization.js';
52
+
53
+ export type InstructionDeserializer = (buf: BufferCursor | Buffer) => Instruction;
54
+
55
+ export interface Serializable {
56
+ serialize(): Buffer;
57
+ }
58
+
59
+ export interface Deserializable {
60
+ deserialize: InstructionDeserializer;
61
+ }
62
+
63
+ export type InstructionSet = Map<Opcode, InstructionDeserializer>;
64
+ export const INSTRUCTION_SET = new Map<Opcode, InstructionDeserializer>([
65
+ [Opcode.ADD_8, Add.as(Add.wireFormat8).deserialize],
66
+ [Opcode.ADD_16, Add.as(Add.wireFormat16).deserialize],
67
+ [Opcode.SUB_8, Sub.as(Sub.wireFormat8).deserialize],
68
+ [Opcode.SUB_16, Sub.as(Sub.wireFormat16).deserialize],
69
+ [Opcode.MUL_8, Mul.as(Mul.wireFormat8).deserialize],
70
+ [Opcode.MUL_16, Mul.as(Mul.wireFormat16).deserialize],
71
+ [Opcode.DIV_8, Div.as(Div.wireFormat8).deserialize],
72
+ [Opcode.DIV_16, Div.as(Div.wireFormat16).deserialize],
73
+ [Opcode.FDIV_8, FieldDiv.as(FieldDiv.wireFormat8).deserialize],
74
+ [Opcode.FDIV_16, FieldDiv.as(FieldDiv.wireFormat16).deserialize],
75
+ [Opcode.EQ_8, Eq.as(Eq.wireFormat8).deserialize],
76
+ [Opcode.EQ_16, Eq.as(Eq.wireFormat16).deserialize],
77
+ [Opcode.LT_8, Lt.as(Lt.wireFormat8).deserialize],
78
+ [Opcode.LT_16, Lt.as(Lt.wireFormat16).deserialize],
79
+ [Opcode.LTE_8, Lte.as(Lte.wireFormat8).deserialize],
80
+ [Opcode.LTE_16, Lte.as(Lte.wireFormat16).deserialize],
81
+ [Opcode.AND_8, And.as(And.wireFormat8).deserialize],
82
+ [Opcode.AND_16, And.as(And.wireFormat16).deserialize],
83
+ [Opcode.OR_8, Or.as(Or.wireFormat8).deserialize],
84
+ [Opcode.OR_16, Or.as(Or.wireFormat16).deserialize],
85
+ [Opcode.XOR_8, Xor.as(Xor.wireFormat8).deserialize],
86
+ [Opcode.XOR_16, Xor.as(Xor.wireFormat16).deserialize],
87
+ [Opcode.NOT_8, Not.as(Not.wireFormat8).deserialize],
88
+ [Opcode.NOT_16, Not.as(Not.wireFormat16).deserialize],
89
+ [Opcode.SHL_8, Shl.as(Shl.wireFormat8).deserialize],
90
+ [Opcode.SHL_16, Shl.as(Shl.wireFormat16).deserialize],
91
+ [Opcode.SHR_8, Shr.as(Shr.wireFormat8).deserialize],
92
+ [Opcode.SHR_16, Shr.as(Shr.wireFormat16).deserialize],
93
+ [Opcode.CAST_8, Cast.as(Cast.wireFormat8).deserialize],
94
+ [Opcode.CAST_16, Cast.as(Cast.wireFormat16).deserialize],
95
+ // Execution Environment
96
+ [Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).deserialize],
97
+ [CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)],
98
+ [Opcode.RETURNDATASIZE, Instruction.deserialize.bind(ReturndataSize)],
99
+ [Opcode.RETURNDATACOPY, Instruction.deserialize.bind(ReturndataCopy)],
100
+
101
+ // Machine State - Internal Control Flow
102
+ [Jump.opcode, Instruction.deserialize.bind(Jump)],
103
+ [JumpI.opcode, Instruction.deserialize.bind(JumpI)],
104
+ [InternalCall.opcode, Instruction.deserialize.bind(InternalCall)],
105
+ [InternalReturn.opcode, Instruction.deserialize.bind(InternalReturn)],
106
+ [Opcode.SET_8, Set.as(Set.wireFormat8).deserialize],
107
+ [Opcode.SET_16, Set.as(Set.wireFormat16).deserialize],
108
+ [Opcode.SET_32, Set.as(Set.wireFormat32).deserialize],
109
+ [Opcode.SET_64, Set.as(Set.wireFormat64).deserialize],
110
+ [Opcode.SET_128, Set.as(Set.wireFormat128).deserialize],
111
+ [Opcode.SET_FF, Set.as(Set.wireFormatFF).deserialize],
112
+ [Opcode.MOV_8, Mov.as(Mov.wireFormat8).deserialize],
113
+ [Opcode.MOV_16, Mov.as(Mov.wireFormat16).deserialize],
114
+
115
+ // World State
116
+ [SLoad.opcode, Instruction.deserialize.bind(SLoad)], // Public Storage
117
+ [SStore.opcode, Instruction.deserialize.bind(SStore)], // Public Storage
118
+ [NoteHashExists.opcode, Instruction.deserialize.bind(NoteHashExists)], // Notes & Nullifiers
119
+ [EmitNoteHash.opcode, Instruction.deserialize.bind(EmitNoteHash)], // Notes & Nullifiers
120
+ [NullifierExists.opcode, Instruction.deserialize.bind(NullifierExists)], // Notes & Nullifiers
121
+ [EmitNullifier.opcode, Instruction.deserialize.bind(EmitNullifier)], // Notes & Nullifiers
122
+ [L1ToL2MessageExists.opcode, Instruction.deserialize.bind(L1ToL2MessageExists)], // Messages
123
+
124
+ // Accrued Substate
125
+ [EmitUnencryptedLog.opcode, Instruction.deserialize.bind(EmitUnencryptedLog)],
126
+ [SendL2ToL1Message.opcode, Instruction.deserialize.bind(SendL2ToL1Message)],
127
+ [GetContractInstance.opcode, Instruction.deserialize.bind(GetContractInstance)],
128
+
129
+ // Control Flow - Contract Calls
130
+ [Call.opcode, Instruction.deserialize.bind(Call)],
131
+ [StaticCall.opcode, Instruction.deserialize.bind(StaticCall)],
132
+ [Return.opcode, Instruction.deserialize.bind(Return)],
133
+ [Opcode.REVERT_8, Revert.as(Revert.wireFormat8).deserialize],
134
+ [Opcode.REVERT_16, Revert.as(Revert.wireFormat16).deserialize],
135
+
136
+ // Misc
137
+ [DebugLog.opcode, Instruction.deserialize.bind(DebugLog)],
138
+
139
+ // Gadgets
140
+ [EcAdd.opcode, Instruction.deserialize.bind(EcAdd)],
141
+ [Poseidon2.opcode, Instruction.deserialize.bind(Poseidon2)],
142
+ [Sha256Compression.opcode, Instruction.deserialize.bind(Sha256Compression)],
143
+ [KeccakF1600.opcode, Instruction.deserialize.bind(KeccakF1600)],
144
+
145
+ // Conversions
146
+ [ToRadixBE.opcode, Instruction.deserialize.bind(ToRadixBE)],
147
+ ]);
148
+
149
+ /**
150
+ * Serializes an array of instructions to bytecode.
151
+ */
152
+ export function encodeToBytecode(instructions: Serializable[]): Buffer {
153
+ return Buffer.concat(instructions.map(i => i.serialize()));
154
+ }
155
+
156
+ // For testing only
157
+ export function decodeFromBytecode(bytecode: Buffer, instructionSet: InstructionSet = INSTRUCTION_SET): Instruction[] {
158
+ const instructions: Instruction[] = [];
159
+ let pc = 0;
160
+ while (pc < bytecode.length) {
161
+ const [instruction, bytesConsumed] = decodeInstructionFromBytecode(bytecode, pc, instructionSet);
162
+ instructions.push(instruction);
163
+ pc += bytesConsumed;
164
+ }
165
+ return instructions;
166
+ }
167
+
168
+ // Returns the instruction and the number of bytes consumed.
169
+ export function decodeInstructionFromBytecode(
170
+ bytecode: Buffer,
171
+ pc: number,
172
+ instructionSet: InstructionSet = INSTRUCTION_SET,
173
+ ): [Instruction, number] {
174
+ if (pc >= bytecode.length) {
175
+ throw new InvalidProgramCounterError(pc, bytecode.length);
176
+ }
177
+
178
+ try {
179
+ const cursor = new BufferCursor(bytecode, pc);
180
+ const startingPosition = cursor.position();
181
+ const opcode: number = cursor.bufferAtPosition().readUint8(); // peek.
182
+
183
+ if (opcode > MAX_OPCODE_VALUE) {
184
+ throw new InvalidOpcodeError(
185
+ `Opcode ${opcode} (0x${opcode.toString(16)}) value is not in the range of valid opcodes.`,
186
+ );
187
+ }
188
+
189
+ const instructionDeserializerOrUndef = instructionSet.get(opcode);
190
+ if (instructionDeserializerOrUndef === undefined) {
191
+ throw new InvalidOpcodeError(`Opcode ${Opcode[opcode]} (0x${opcode.toString(16)}) is not implemented`);
192
+ }
193
+
194
+ const instructionDeserializer: InstructionDeserializer = instructionDeserializerOrUndef;
195
+ const instruction = instructionDeserializer(cursor);
196
+ return [instruction, cursor.position() - startingPosition];
197
+ } catch (error) {
198
+ if (error instanceof InvalidOpcodeError || error instanceof AvmExecutionError) {
199
+ throw error;
200
+ } else {
201
+ throw new AvmParsingError(`${error}`);
202
+ }
203
+ }
204
+ }
@@ -81,7 +81,6 @@ export enum Opcode {
81
81
  SHA256COMPRESSION,
82
82
  KECCAKF1600,
83
83
  ECADD,
84
- MSM,
85
84
  // Conversion
86
85
  TORADIXBE,
87
86
  }
@@ -1,19 +1,18 @@
1
+ import { Fr } from '@aztec/foundation/fields';
1
2
  import {
2
3
  type ContractClassPublic,
3
4
  type ContractInstanceWithAddress,
4
- Fr,
5
5
  computePublicBytecodeCommitment,
6
- } from '@aztec/circuits.js';
6
+ } from '@aztec/stdlib/contract';
7
7
 
8
- import { type jest } from '@jest/globals';
8
+ import type { jest } from '@jest/globals';
9
9
  import { mock } from 'jest-mock-extended';
10
10
 
11
- import { type WorldStateDB } from '../public/public_db_sources.js';
12
- import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace_interface.js';
11
+ import type { WorldStateDB } from '../../public/public_db_sources.js';
12
+ import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
13
13
 
14
14
  export async function mockGetBytecode(worldStateDB: WorldStateDB, bytecode: Buffer) {
15
15
  const commitment = await computePublicBytecodeCommitment(bytecode);
16
- (worldStateDB as jest.Mocked<WorldStateDB>).getBytecode.mockResolvedValue(bytecode);
17
16
  (worldStateDB as jest.Mocked<WorldStateDB>).getBytecodeCommitment.mockResolvedValue(commitment);
18
17
  }
19
18
 
@@ -37,6 +36,10 @@ export function mockStorageReadWithMap(worldStateDB: WorldStateDB, mockedStorage
37
36
  );
38
37
  }
39
38
 
39
+ export function mockGetBytecodeCommitment(worldStateDB: WorldStateDB, commitment: Fr) {
40
+ (worldStateDB as jest.Mocked<WorldStateDB>).getBytecodeCommitment.mockResolvedValue(commitment);
41
+ }
42
+
40
43
  export function mockNoteHashExists(worldStateDB: WorldStateDB, _leafIndex: Fr, value?: Fr) {
41
44
  (worldStateDB as jest.Mocked<WorldStateDB>).getCommitmentValue.mockImplementation((index: bigint) => {
42
45
  if (index == _leafIndex.toBigInt()) {
@@ -48,7 +51,7 @@ export function mockNoteHashExists(worldStateDB: WorldStateDB, _leafIndex: Fr, v
48
51
  });
49
52
  }
50
53
 
51
- export function mockNullifierExists(worldStateDB: WorldStateDB, leafIndex: Fr, _value?: Fr) {
54
+ export function mockGetNullifierIndex(worldStateDB: WorldStateDB, leafIndex: Fr, _ignoredValue?: Fr) {
52
55
  (worldStateDB as jest.Mocked<WorldStateDB>).getNullifierIndex.mockResolvedValue(leafIndex.toBigInt());
53
56
  }
54
57
 
@@ -1,23 +1,20 @@
1
- import { type PublicExecutionRequest, type SimulationError } from '@aztec/circuit-types';
1
+ import type { Fr } from '@aztec/foundation/fields';
2
2
  import {
3
3
  type AvmExecutionHints,
4
4
  type ContractStorageRead,
5
5
  type ContractStorageUpdateRequest,
6
- type Fr,
7
- Gas,
8
- type L2ToL1Message,
9
- type NoteHash,
10
- type Nullifier,
11
6
  PublicCallStackItemCompressed,
12
7
  type PublicDataUpdateRequest,
13
8
  PublicInnerCallRequest,
14
- type PublicLog,
15
- type ReadRequest,
16
9
  RevertCode,
17
- type ScopedL2ToL1Message,
18
- type TreeLeafReadRequest,
19
- } from '@aztec/circuits.js';
20
- import { computeVarArgsHash } from '@aztec/circuits.js/hash';
10
+ } from '@aztec/stdlib/avm';
11
+ import type { SimulationError } from '@aztec/stdlib/errors';
12
+ import { Gas } from '@aztec/stdlib/gas';
13
+ import { computeVarArgsHash } from '@aztec/stdlib/hash';
14
+ import type { NoteHash, Nullifier, ReadRequest, TreeLeafReadRequest } from '@aztec/stdlib/kernel';
15
+ import type { PublicLog } from '@aztec/stdlib/logs';
16
+ import type { L2ToL1Message, ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
17
+ import type { PublicExecutionRequest } from '@aztec/stdlib/tx';
21
18
 
22
19
  export interface PublicSideEffects {
23
20
  /** The contract storage update requests performed. */
@@ -1,32 +1,24 @@
1
- import { MerkleTreeId, type MerkleTreeWriteOperations, PublicExecutionRequest, type Tx } from '@aztec/circuit-types';
2
- import {
3
- type AvmCircuitPublicInputs,
4
- CallContext,
5
- FunctionSelector,
6
- GasFees,
7
- GlobalVariables,
8
- MAX_NOTE_HASHES_PER_TX,
9
- MAX_NULLIFIERS_PER_TX,
10
- NULLIFIER_SUBTREE_HEIGHT,
11
- PUBLIC_DATA_TREE_HEIGHT,
12
- PUBLIC_DISPATCH_SELECTOR,
13
- } from '@aztec/circuits.js';
14
- import { type ContractArtifact, encodeArguments } from '@aztec/foundation/abi';
15
- import { AztecAddress } from '@aztec/foundation/aztec-address';
16
- import { padArrayEnd } from '@aztec/foundation/collection';
1
+ import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
17
2
  import { Fr } from '@aztec/foundation/fields';
18
3
  import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest';
4
+ import { type ContractArtifact, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
5
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import { GasFees } from '@aztec/stdlib/gas';
7
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
8
+ import { PublicExecutionRequest, type Tx } from '@aztec/stdlib/tx';
9
+ import { CallContext, GlobalVariables } from '@aztec/stdlib/tx';
19
10
  import { NativeWorldStateService } from '@aztec/world-state';
20
11
 
21
- import { BaseAvmSimulationTester } from '../../avm/fixtures/base_avm_simulation_tester.js';
22
- import { getContractFunctionArtifact, getFunctionSelector } from '../../avm/fixtures/index.js';
23
- import { SimpleContractDataSource } from '../../avm/fixtures/simple_contract_data_source.js';
12
+ import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
13
+ import { getContractFunctionArtifact, getFunctionSelector } from '../avm/fixtures/index.js';
14
+ import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
24
15
  import { WorldStateDB } from '../public_db_sources.js';
25
16
  import { type PublicTxResult, PublicTxSimulator } from '../public_tx_simulator.js';
26
17
  import { createTxForPublicCalls } from './index.js';
27
18
 
28
19
  const TIMESTAMP = new Fr(99833);
29
20
  const DEFAULT_GAS_FEES = new GasFees(2, 3);
21
+ export const DEFAULT_BLOCK_NUMBER = 42;
30
22
 
31
23
  export type TestEnqueuedCall = {
32
24
  address: AztecAddress;
@@ -47,31 +39,26 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
47
39
  private worldStateDB: WorldStateDB,
48
40
  contractDataSource: SimpleContractDataSource,
49
41
  merkleTrees: MerkleTreeWriteOperations,
50
- skipContractDeployments: boolean,
51
42
  ) {
52
- super(contractDataSource, merkleTrees, skipContractDeployments);
43
+ super(contractDataSource, merkleTrees);
53
44
  }
54
45
 
55
- public static async create(skipContractDeployments = false): Promise<PublicTxSimulationTester> {
46
+ public static async create(): Promise<PublicTxSimulationTester> {
56
47
  const contractDataSource = new SimpleContractDataSource();
57
48
  const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
58
49
  const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
59
- return new PublicTxSimulationTester(worldStateDB, contractDataSource, merkleTrees, skipContractDeployments);
50
+ return new PublicTxSimulationTester(worldStateDB, contractDataSource, merkleTrees);
60
51
  }
61
52
 
62
- public async simulateTx(
53
+ public async createTx(
63
54
  sender: AztecAddress,
64
55
  setupCalls: TestEnqueuedCall[] = [],
65
56
  appCalls: TestEnqueuedCall[] = [],
66
57
  teardownCall?: TestEnqueuedCall,
67
- feePayer: AztecAddress = AztecAddress.zero(),
68
- ): Promise<PublicTxResult> {
69
- const globals = GlobalVariables.empty();
70
- globals.timestamp = TIMESTAMP;
71
- globals.gasFees = DEFAULT_GAS_FEES;
72
-
73
- const simulator = new PublicTxSimulator(this.merkleTrees, this.worldStateDB, globals, /*doMerkleOperations=*/ true);
74
-
58
+ feePayer: AztecAddress = sender,
59
+ /* need some unique first nullifier for note-nonce computations */
60
+ firstNullifier = new Fr(420000 + this.txCount++),
61
+ ): Promise<Tx> {
75
62
  const setupExecutionRequests: PublicExecutionRequest[] = [];
76
63
  for (let i = 0; i < setupCalls.length; i++) {
77
64
  const address = setupCalls[i].address;
@@ -115,51 +102,38 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
115
102
  );
116
103
  }
117
104
 
118
- // Use a fake "first nullifier" to make sure note hash nonces are computed properly,
119
- // but make sure each tx has a unique first nullifier.
120
- const firstNullifier = new Fr(420000 + this.txCount++);
121
-
122
- const tx: Tx = await createTxForPublicCalls(
105
+ return await createTxForPublicCalls(
123
106
  firstNullifier,
124
107
  setupExecutionRequests,
125
108
  appExecutionRequests,
126
109
  teardownExecutionRequest,
127
110
  feePayer,
128
111
  );
112
+ }
113
+
114
+ public async simulateTx(
115
+ sender: AztecAddress,
116
+ setupCalls: TestEnqueuedCall[] = [],
117
+ appCalls: TestEnqueuedCall[] = [],
118
+ teardownCall?: TestEnqueuedCall,
119
+ feePayer: AztecAddress = sender,
120
+ /* need some unique first nullifier for note-nonce computations */
121
+ firstNullifier = new Fr(420000 + this.txCount++),
122
+ globals = defaultGlobals(),
123
+ ): Promise<PublicTxResult> {
124
+ const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier);
125
+
126
+ await this.setFeePayerBalance(feePayer);
127
+
128
+ const simulator = new PublicTxSimulator(this.merkleTrees, this.worldStateDB, globals, /*doMerkleOperations=*/ true);
129
129
 
130
130
  const startTime = performance.now();
131
131
  const avmResult = await simulator.simulate(tx);
132
132
  const endTime = performance.now();
133
133
  this.logger.debug(`Public transaction simulation took ${endTime - startTime}ms`);
134
134
 
135
- if (avmResult.revertCode.isOK()) {
136
- await this.commitTxStateUpdates(avmResult.avmProvingRequest.inputs.publicInputs);
137
- }
138
-
139
135
  return avmResult;
140
136
  }
141
-
142
- private async commitTxStateUpdates(avmCircuitInputs: AvmCircuitPublicInputs) {
143
- await this.merkleTrees.appendLeaves(
144
- MerkleTreeId.NOTE_HASH_TREE,
145
- padArrayEnd(avmCircuitInputs.accumulatedData.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
146
- );
147
- try {
148
- await this.merkleTrees.batchInsert(
149
- MerkleTreeId.NULLIFIER_TREE,
150
- padArrayEnd(avmCircuitInputs.accumulatedData.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(n => n.toBuffer()),
151
- NULLIFIER_SUBTREE_HEIGHT,
152
- );
153
- } catch (error) {
154
- this.logger.warn(`Detected duplicate nullifier.`);
155
- }
156
-
157
- await this.merkleTrees.batchInsert(
158
- MerkleTreeId.PUBLIC_DATA_TREE,
159
- avmCircuitInputs.accumulatedData.publicDataWrites.map(w => w.toBuffer()),
160
- PUBLIC_DATA_TREE_HEIGHT,
161
- );
162
- }
163
137
  }
164
138
 
165
139
  async function executionRequestForCall(
@@ -183,3 +157,11 @@ async function executionRequestForCall(
183
157
  );
184
158
  return new PublicExecutionRequest(callContext, calldata);
185
159
  }
160
+
161
+ function defaultGlobals() {
162
+ const globals = GlobalVariables.empty();
163
+ globals.timestamp = TIMESTAMP;
164
+ globals.gasFees = DEFAULT_GAS_FEES; // apply some nonzero default gas fees
165
+ globals.blockNumber = new Fr(DEFAULT_BLOCK_NUMBER);
166
+ return globals;
167
+ }