@aztec/simulator 0.0.1-commit.5476d83 → 0.0.1-commit.59e663cd

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 (295) hide show
  1. package/README.md +2 -0
  2. package/dest/common/errors.d.ts +8 -2
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/private/acvm/deserialize.d.ts +2 -2
  5. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  6. package/dest/private/acvm/deserialize.js +1 -1
  7. package/dest/private/acvm/serialize.d.ts +2 -2
  8. package/dest/private/acvm/serialize.d.ts.map +1 -1
  9. package/dest/private/acvm/serialize.js +1 -1
  10. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  11. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  12. package/dest/private/circuit_recording/circuit_recorder.js +16 -15
  13. package/dest/public/avm/avm_context.d.ts +3 -3
  14. package/dest/public/avm/avm_context.d.ts.map +1 -1
  15. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  16. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  17. package/dest/public/avm/avm_contract_call_result.js +3 -3
  18. package/dest/public/avm/avm_execution_environment.d.ts +7 -6
  19. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  20. package/dest/public/avm/avm_execution_environment.js +1 -1
  21. package/dest/public/avm/avm_gas.d.ts +1 -1
  22. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  23. package/dest/public/avm/avm_machine_state.d.ts +7 -6
  24. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  25. package/dest/public/avm/avm_machine_state.js +3 -2
  26. package/dest/public/avm/avm_memory_types.d.ts +2 -2
  27. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  28. package/dest/public/avm/avm_memory_types.js +4 -1
  29. package/dest/public/avm/avm_simulator.d.ts +4 -3
  30. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  31. package/dest/public/avm/avm_simulator.js +11 -9
  32. package/dest/public/avm/calldata.d.ts +51 -0
  33. package/dest/public/avm/calldata.d.ts.map +1 -0
  34. package/dest/public/avm/calldata.js +63 -0
  35. package/dest/public/avm/errors.d.ts +8 -2
  36. package/dest/public/avm/errors.d.ts.map +1 -1
  37. package/dest/public/avm/errors.js +14 -2
  38. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  39. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  40. package/dest/public/avm/fixtures/avm_simulation_tester.js +4 -3
  41. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  42. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  43. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  44. package/dest/public/avm/fixtures/initializers.d.ts +2 -2
  45. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  46. package/dest/public/avm/fixtures/initializers.js +5 -4
  47. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  48. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  49. package/dest/public/avm/fixtures/utils.js +3 -2
  50. package/dest/public/avm/opcodes/accrued_substate.d.ts +15 -15
  51. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  52. package/dest/public/avm/opcodes/accrued_substate.js +33 -29
  53. package/dest/public/avm/opcodes/addressing_mode.js +2 -2
  54. package/dest/public/avm/opcodes/arithmetic.d.ts +10 -8
  55. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  56. package/dest/public/avm/opcodes/arithmetic.js +12 -2
  57. package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
  58. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  59. package/dest/public/avm/opcodes/bitwise.js +5 -5
  60. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  61. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  62. package/dest/public/avm/opcodes/comparators.js +1 -1
  63. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  64. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  65. package/dest/public/avm/opcodes/contract.js +8 -8
  66. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  67. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  68. package/dest/public/avm/opcodes/control_flow.js +4 -4
  69. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  70. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/conversion.js +4 -4
  72. package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
  73. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/ec_add.js +17 -8
  75. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  76. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  78. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  79. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/external_calls.js +23 -22
  81. package/dest/public/avm/opcodes/hashing.d.ts +8 -8
  82. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/hashing.js +21 -16
  84. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  85. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  87. package/dest/public/avm/opcodes/memory.d.ts +14 -14
  88. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  89. package/dest/public/avm/opcodes/memory.js +26 -26
  90. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  91. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  92. package/dest/public/avm/opcodes/misc.js +6 -6
  93. package/dest/public/avm/opcodes/storage.d.ts +16 -15
  94. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  95. package/dest/public/avm/opcodes/storage.js +34 -24
  96. package/dest/public/avm/revert_reason.d.ts +2 -2
  97. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  98. package/dest/public/avm/revert_reason.js +3 -2
  99. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  100. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  101. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  102. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  103. package/dest/public/avm/test_utils.d.ts +2 -2
  104. package/dest/public/avm/test_utils.d.ts.map +1 -1
  105. package/dest/public/avm/test_utils.js +1 -1
  106. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  107. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  108. package/dest/public/db_interfaces.d.ts +2 -2
  109. package/dest/public/db_interfaces.d.ts.map +1 -1
  110. package/dest/public/debug_fn_name.d.ts +16 -3
  111. package/dest/public/debug_fn_name.d.ts.map +1 -1
  112. package/dest/public/debug_fn_name.js +31 -3
  113. package/dest/public/executor_metrics.d.ts +1 -1
  114. package/dest/public/executor_metrics.d.ts.map +1 -1
  115. package/dest/public/executor_metrics.js +8 -34
  116. package/dest/public/fixtures/amm_test.js +2 -2
  117. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  118. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  119. package/dest/public/fixtures/bulk_test.js +5 -69
  120. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  121. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  122. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  123. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -8
  124. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  125. package/dest/public/fixtures/custom_bytecode_tests.js +83 -18
  126. package/dest/public/fixtures/index.d.ts +4 -2
  127. package/dest/public/fixtures/index.d.ts.map +1 -1
  128. package/dest/public/fixtures/index.js +3 -1
  129. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
  130. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  131. package/dest/public/fixtures/minimal_public_tx.js +4 -14
  132. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  133. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  134. package/dest/public/fixtures/opcode_spammer.js +1693 -0
  135. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +22 -3
  136. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  137. package/dest/public/fixtures/public_tx_simulation_tester.js +50 -13
  138. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  139. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  140. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  141. package/dest/public/fixtures/token_test.d.ts +6 -2
  142. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  143. package/dest/public/fixtures/token_test.js +13 -11
  144. package/dest/public/fixtures/utils.d.ts +2 -2
  145. package/dest/public/fixtures/utils.d.ts.map +1 -1
  146. package/dest/public/fixtures/utils.js +4 -3
  147. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +60 -0
  148. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  149. package/dest/public/fuzzing/avm_fuzzer_simulator.js +171 -0
  150. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  151. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  152. package/dest/public/fuzzing/avm_simulator_bin.js +118 -0
  153. package/dest/public/hinting_db_sources.d.ts +5 -3
  154. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  155. package/dest/public/hinting_db_sources.js +7 -2
  156. package/dest/public/index.d.ts +2 -2
  157. package/dest/public/index.d.ts.map +1 -1
  158. package/dest/public/index.js +1 -1
  159. package/dest/public/public_db_sources.d.ts +2 -2
  160. package/dest/public/public_db_sources.d.ts.map +1 -1
  161. package/dest/public/public_db_sources.js +1 -1
  162. package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -2
  163. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  164. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  165. package/dest/public/public_processor/public_processor.d.ts +6 -6
  166. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  167. package/dest/public/public_processor/public_processor.js +437 -43
  168. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  169. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  170. package/dest/public/public_processor/public_processor_metrics.js +12 -45
  171. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
  172. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  173. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +18 -53
  174. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +21 -34
  175. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  176. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +61 -139
  177. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  178. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  179. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  180. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  181. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  182. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  183. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  184. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  185. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  186. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  187. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  188. package/dest/public/public_tx_simulator/factories.js +28 -0
  189. package/dest/public/public_tx_simulator/index.d.ts +4 -1
  190. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  191. package/dest/public/public_tx_simulator/index.js +3 -0
  192. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -3
  193. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  194. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  195. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  196. package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
  197. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -5
  198. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  199. package/dest/public/public_tx_simulator/public_tx_simulator.js +20 -11
  200. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  201. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  202. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  203. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  204. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  205. package/dest/public/side_effect_trace.d.ts +3 -2
  206. package/dest/public/side_effect_trace.d.ts.map +1 -1
  207. package/dest/public/side_effect_trace.js +1 -1
  208. package/dest/public/side_effect_trace_interface.d.ts +2 -2
  209. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  210. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  211. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  212. package/dest/public/state_manager/public_storage.d.ts +2 -2
  213. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  214. package/dest/public/state_manager/public_storage.js +1 -1
  215. package/dest/public/state_manager/state_manager.d.ts +7 -2
  216. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  217. package/dest/public/state_manager/state_manager.js +7 -4
  218. package/package.json +20 -20
  219. package/src/common/errors.ts +1 -1
  220. package/src/private/acvm/deserialize.ts +1 -1
  221. package/src/private/acvm/serialize.ts +1 -1
  222. package/src/private/circuit_recording/circuit_recorder.ts +17 -16
  223. package/src/public/avm/avm_context.ts +2 -2
  224. package/src/public/avm/avm_contract_call_result.ts +8 -6
  225. package/src/public/avm/avm_execution_environment.ts +10 -5
  226. package/src/public/avm/avm_gas.ts +3 -3
  227. package/src/public/avm/avm_machine_state.ts +7 -6
  228. package/src/public/avm/avm_memory_types.ts +5 -1
  229. package/src/public/avm/avm_simulator.ts +16 -10
  230. package/src/public/avm/calldata.ts +100 -0
  231. package/src/public/avm/errors.ts +17 -3
  232. package/src/public/avm/fixtures/avm_simulation_tester.ts +9 -3
  233. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  234. package/src/public/avm/fixtures/initializers.ts +5 -4
  235. package/src/public/avm/fixtures/utils.ts +3 -2
  236. package/src/public/avm/opcodes/accrued_substate.ts +21 -15
  237. package/src/public/avm/opcodes/addressing_mode.ts +2 -2
  238. package/src/public/avm/opcodes/arithmetic.ts +14 -2
  239. package/src/public/avm/opcodes/bitwise.ts +3 -3
  240. package/src/public/avm/opcodes/comparators.ts +1 -1
  241. package/src/public/avm/opcodes/contract.ts +4 -7
  242. package/src/public/avm/opcodes/control_flow.ts +2 -2
  243. package/src/public/avm/opcodes/conversion.ts +3 -3
  244. package/src/public/avm/opcodes/ec_add.ts +15 -6
  245. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  246. package/src/public/avm/opcodes/external_calls.ts +17 -15
  247. package/src/public/avm/opcodes/hashing.ts +16 -10
  248. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  249. package/src/public/avm/opcodes/memory.ts +20 -20
  250. package/src/public/avm/opcodes/misc.ts +4 -4
  251. package/src/public/avm/opcodes/storage.ts +30 -22
  252. package/src/public/avm/revert_reason.ts +6 -3
  253. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  254. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  255. package/src/public/avm/test_utils.ts +1 -1
  256. package/src/public/contracts_db_checkpoint.ts +1 -1
  257. package/src/public/db_interfaces.ts +1 -1
  258. package/src/public/debug_fn_name.ts +39 -5
  259. package/src/public/executor_metrics.ts +7 -34
  260. package/src/public/fixtures/amm_test.ts +2 -2
  261. package/src/public/fixtures/bulk_test.ts +9 -9
  262. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  263. package/src/public/fixtures/custom_bytecode_tests.ts +111 -18
  264. package/src/public/fixtures/index.ts +7 -1
  265. package/src/public/fixtures/minimal_public_tx.ts +6 -15
  266. package/src/public/fixtures/opcode_spammer.ts +1754 -0
  267. package/src/public/fixtures/public_tx_simulation_tester.ts +69 -13
  268. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  269. package/src/public/fixtures/token_test.ts +18 -9
  270. package/src/public/fixtures/utils.ts +2 -3
  271. package/src/public/fuzzing/avm_fuzzer_simulator.ts +288 -0
  272. package/src/public/fuzzing/avm_simulator_bin.ts +175 -0
  273. package/src/public/hinting_db_sources.ts +8 -3
  274. package/src/public/index.ts +7 -1
  275. package/src/public/public_db_sources.ts +1 -1
  276. package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
  277. package/src/public/public_processor/public_processor.ts +46 -29
  278. package/src/public/public_processor/public_processor_metrics.ts +11 -45
  279. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +19 -60
  280. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +76 -174
  281. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  282. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
  283. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  284. package/src/public/public_tx_simulator/factories.ts +41 -0
  285. package/src/public/public_tx_simulator/index.ts +3 -0
  286. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
  287. package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
  288. package/src/public/public_tx_simulator/public_tx_simulator.ts +36 -14
  289. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
  290. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
  291. package/src/public/side_effect_trace.ts +1 -1
  292. package/src/public/side_effect_trace_interface.ts +1 -1
  293. package/src/public/state_manager/nullifiers.ts +1 -1
  294. package/src/public/state_manager/public_storage.ts +1 -1
  295. package/src/public/state_manager/state_manager.ts +12 -19
@@ -1,4 +1,4 @@
1
- import type { Point } from '@aztec/foundation/fields';
1
+ import type { Point } from '@aztec/foundation/curves/grumpkin';
2
2
  import type { FailingFunction, NoirCallStack } from '@aztec/stdlib/errors';
3
3
 
4
4
  import { ExecutionError } from '../../common/errors.js';
@@ -58,7 +58,7 @@ export class AvmParsingError extends AvmExecutionError {
58
58
  */
59
59
  export class InvalidTagValueError extends AvmExecutionError {
60
60
  constructor(tagValue: number) {
61
- super(`Tag value ${tagValue} is invalid.`);
61
+ super(`Tag check failed: Tag value ${tagValue} is invalid.`);
62
62
  this.name = 'InvalidTagValueError';
63
63
  }
64
64
  }
@@ -77,6 +77,12 @@ export class InstructionExecutionError extends AvmExecutionError {
77
77
  * Error thrown on failed AVM memory tag check.
78
78
  */
79
79
  export class TagCheckError extends AvmExecutionError {
80
+ public static forBaseAddress(gotTag: string): TagCheckError {
81
+ return new TagCheckError(`Base address (mem[0]) is not a valid address (has tag ${gotTag})`);
82
+ }
83
+ public static forIndirectAddress(address: number, gotTag: string): TagCheckError {
84
+ return new TagCheckError(`Address after indirection is not a valid address (address ${address} has tag ${gotTag})`);
85
+ }
80
86
  public static forOffset(offset: number, gotTag: string, expectedTag: string): TagCheckError {
81
87
  return new TagCheckError(`Tag mismatch at offset ${offset}, got ${gotTag}, expected ${expectedTag}`);
82
88
  }
@@ -97,7 +103,7 @@ export class TagCheckError extends AvmExecutionError {
97
103
  */
98
104
  export class RelativeAddressOutOfRangeError extends AvmExecutionError {
99
105
  constructor(baseAddr: number, relOffset: number) {
100
- super(`Address out of range. Base address ${baseAddr}, relative offset ${relOffset}`);
106
+ super(`Relative address out of range. Base address ${baseAddr}, relative offset ${relOffset}`);
101
107
  this.name = 'RelativeAddressOutOfRangeError';
102
108
  }
103
109
  }
@@ -161,3 +167,11 @@ export class AvmRevertReason extends ExecutionError {
161
167
  super(message, failingFunction, noirCallStack, options);
162
168
  }
163
169
  }
170
+
171
+ /**
172
+ * Helper to annotate errors occurring during instruction fetching.
173
+ */
174
+ export function duringInstrFetch(error: Error, pc: number) {
175
+ error.message = `Instruction fetching error at pc ${pc}: ${error.message}`;
176
+ return error;
177
+ }
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { encodeArguments } from '@aztec/stdlib/abi';
3
3
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -13,6 +13,7 @@ import { SimpleContractDataSource } from '../../fixtures/simple_contract_data_so
13
13
  import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
14
14
  import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
15
15
  import { AvmSimulator } from '../avm_simulator.js';
16
+ import { CallDataArray } from '../calldata.js';
16
17
  import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
17
18
  import { initContext, initExecutionEnvironment } from './initializers.js';
18
19
  import {
@@ -89,7 +90,7 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
89
90
  collectCallMetadata: true,
90
91
  });
91
92
  const environment = initExecutionEnvironment({
92
- calldata,
93
+ calldata: new CallDataArray(calldata),
93
94
  globals,
94
95
  address,
95
96
  sender,
@@ -105,7 +106,12 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
105
106
  if (result.reverted) {
106
107
  this.logger.error(`Error in ${fnName}:`);
107
108
  this.logger.error(
108
- resolveContractAssertionMessage(fnName, result.revertReason!, result.output, contractArtifact)!,
109
+ resolveContractAssertionMessage(
110
+ fnName,
111
+ result.revertReason!,
112
+ result.output.bestEffortReadAll(),
113
+ contractArtifact,
114
+ )!,
109
115
  );
110
116
  } else {
111
117
  this.logger.info(`Simulation of function ${fnName} succeeded!`);
@@ -1,5 +1,5 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
5
  import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry';
@@ -1,7 +1,7 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
5
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { GasFees } from '@aztec/stdlib/gas';
@@ -19,6 +19,7 @@ import { AvmContext } from '../avm_context.js';
19
19
  import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
20
20
  import { AvmMachineState } from '../avm_machine_state.js';
21
21
  import { AvmSimulator } from '../avm_simulator.js';
22
+ import { CallDataArray } from '../calldata.js';
22
23
  import { DEFAULT_TIMESTAMP } from './utils.js';
23
24
 
24
25
  /**
@@ -70,7 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
70
71
  overrides?.transactionFee ?? Fr.zero(),
71
72
  overrides?.globals ?? GlobalVariables.empty(),
72
73
  overrides?.isStaticCall ?? false,
73
- overrides?.calldata ?? [],
74
+ overrides?.calldata ?? new CallDataArray([]),
74
75
  overrides?.config ?? PublicSimulatorConfig.empty(),
75
76
  );
76
77
  }
@@ -82,7 +83,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
82
83
  return new GlobalVariables(
83
84
  overrides?.chainId ?? Fr.zero(),
84
85
  overrides?.version ?? Fr.zero(),
85
- overrides?.blockNumber ?? 0,
86
+ overrides?.blockNumber ?? BlockNumber.ZERO,
86
87
  overrides?.slotNumber ?? SlotNumber.ZERO,
87
88
  overrides?.timestamp ?? 0n,
88
89
  overrides?.coinbase ?? EthAddress.ZERO,
@@ -1,5 +1,6 @@
1
1
  import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import {
4
5
  type ContractArtifact,
5
6
  type FunctionAbi,
@@ -28,7 +29,7 @@ import type { AvmRevertReason } from '../errors.js';
28
29
 
29
30
  export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
30
31
  export const DEFAULT_TIMESTAMP: UInt64 = 99833n;
31
- export const DEFAULT_BLOCK_NUMBER = 42;
32
+ export const DEFAULT_BLOCK_NUMBER = BlockNumber(42);
32
33
 
33
34
  /**
34
35
  * Create a new object with all the same properties as the original, except for the ones in the overrides object.
@@ -1,3 +1,5 @@
1
+ import { MAX_ETH_ADDRESS_VALUE } from '@aztec/constants';
2
+
1
3
  import { NullifierCollisionError } from '../../side_effect_errors.js';
2
4
  import type { AvmContext } from '../avm_context.js';
3
5
  import { TypeTag, Uint1 } from '../avm_memory_types.js';
@@ -19,7 +21,7 @@ export class NoteHashExists extends Instruction {
19
21
  ];
20
22
 
21
23
  constructor(
22
- private indirect: number,
24
+ private addressingMode: number,
23
25
  private noteHashOffset: number,
24
26
  private leafIndexOffset: number,
25
27
  private existsOffset: number,
@@ -29,7 +31,7 @@ export class NoteHashExists extends Instruction {
29
31
 
30
32
  public async execute(context: AvmContext): Promise<void> {
31
33
  const memory = context.machineState.memory;
32
- const addressing = Addressing.fromWire(this.indirect);
34
+ const addressing = Addressing.fromWire(this.addressingMode);
33
35
 
34
36
  context.machineState.consumeGas(
35
37
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -55,7 +57,7 @@ export class EmitNoteHash extends Instruction {
55
57
  static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
56
58
 
57
59
  constructor(
58
- private indirect: number,
60
+ private addressingMode: number,
59
61
  private noteHashOffset: number,
60
62
  ) {
61
63
  super();
@@ -63,7 +65,7 @@ export class EmitNoteHash extends Instruction {
63
65
 
64
66
  public async execute(context: AvmContext): Promise<void> {
65
67
  const memory = context.machineState.memory;
66
- const addressing = Addressing.fromWire(this.indirect);
68
+ const addressing = Addressing.fromWire(this.addressingMode);
67
69
 
68
70
  context.machineState.consumeGas(
69
71
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -95,7 +97,7 @@ export class NullifierExists extends Instruction {
95
97
  ];
96
98
 
97
99
  constructor(
98
- private indirect: number,
100
+ private addressingMode: number,
99
101
  private nullifierOffset: number,
100
102
  private addressOffset: number,
101
103
  private existsOffset: number,
@@ -105,7 +107,7 @@ export class NullifierExists extends Instruction {
105
107
 
106
108
  public async execute(context: AvmContext): Promise<void> {
107
109
  const memory = context.machineState.memory;
108
- const addressing = Addressing.fromWire(this.indirect);
110
+ const addressing = Addressing.fromWire(this.addressingMode);
109
111
 
110
112
  context.machineState.consumeGas(
111
113
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -130,7 +132,7 @@ export class EmitNullifier extends Instruction {
130
132
  static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16];
131
133
 
132
134
  constructor(
133
- private indirect: number,
135
+ private addressingMode: number,
134
136
  private nullifierOffset: number,
135
137
  ) {
136
138
  super();
@@ -142,7 +144,7 @@ export class EmitNullifier extends Instruction {
142
144
  }
143
145
 
144
146
  const memory = context.machineState.memory;
145
- const addressing = Addressing.fromWire(this.indirect);
147
+ const addressing = Addressing.fromWire(this.addressingMode);
146
148
 
147
149
  context.machineState.consumeGas(
148
150
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -181,7 +183,7 @@ export class L1ToL2MessageExists extends Instruction {
181
183
  ];
182
184
 
183
185
  constructor(
184
- private indirect: number,
186
+ private addressingMode: number,
185
187
  private msgHashOffset: number,
186
188
  private msgLeafIndexOffset: number,
187
189
  private existsOffset: number,
@@ -191,7 +193,7 @@ export class L1ToL2MessageExists extends Instruction {
191
193
 
192
194
  public async execute(context: AvmContext): Promise<void> {
193
195
  const memory = context.machineState.memory;
194
- const addressing = Addressing.fromWire(this.indirect);
196
+ const addressing = Addressing.fromWire(this.addressingMode);
195
197
 
196
198
  context.machineState.consumeGas(
197
199
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -218,7 +220,7 @@ export class EmitUnencryptedLog extends Instruction {
218
220
  static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
219
221
 
220
222
  constructor(
221
- private indirect: number,
223
+ private addressingMode: number,
222
224
  private logSizeOffset: number,
223
225
  private logOffset: number,
224
226
  ) {
@@ -231,7 +233,7 @@ export class EmitUnencryptedLog extends Instruction {
231
233
  }
232
234
 
233
235
  const memory = context.machineState.memory;
234
- const addressing = Addressing.fromWire(this.indirect);
236
+ const addressing = Addressing.fromWire(this.addressingMode);
235
237
 
236
238
  context.machineState.consumeGas(
237
239
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -241,11 +243,11 @@ export class EmitUnencryptedLog extends Instruction {
241
243
  const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
242
244
  memory.checkTag(TypeTag.UINT32, logSizeOffset);
243
245
  const logSize = memory.get(logSizeOffset).toNumber();
244
- memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
245
246
 
246
247
  const contractAddress = context.environment.address;
247
248
 
248
249
  context.machineState.consumeGas(this.dynamicGasCost(logSize));
250
+ memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
249
251
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
250
252
  context.persistableState.writePublicLog(contractAddress, log);
251
253
  }
@@ -258,7 +260,7 @@ export class SendL2ToL1Message extends Instruction {
258
260
  static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
259
261
 
260
262
  constructor(
261
- private indirect: number,
263
+ private addressingMode: number,
262
264
  private recipientOffset: number,
263
265
  private contentOffset: number,
264
266
  ) {
@@ -271,7 +273,7 @@ export class SendL2ToL1Message extends Instruction {
271
273
  }
272
274
 
273
275
  const memory = context.machineState.memory;
274
- const addressing = Addressing.fromWire(this.indirect);
276
+ const addressing = Addressing.fromWire(this.addressingMode);
275
277
 
276
278
  context.machineState.consumeGas(
277
279
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -282,6 +284,10 @@ export class SendL2ToL1Message extends Instruction {
282
284
  memory.checkTags(TypeTag.FIELD, recipientOffset, contentOffset);
283
285
 
284
286
  const recipient = memory.get(recipientOffset).toFr();
287
+
288
+ if (recipient.toBigInt() > MAX_ETH_ADDRESS_VALUE) {
289
+ throw new InstructionExecutionError(`SENDL2TOL1MSG: Recipient address is too large`);
290
+ }
285
291
  const content = memory.get(contentOffset).toFr();
286
292
  context.persistableState.writeL2ToL1Message(context.environment.address, recipient, content);
287
293
  }
@@ -83,7 +83,7 @@ export class Addressing {
83
83
  baseAddr = mem.get(0);
84
84
  const baseAddrTag = baseAddr.getTag();
85
85
  if (!TaggedMemory.isValidMemoryAddressTag(baseAddrTag!)) {
86
- throw TagCheckError.forOffset(0, TypeTag[baseAddrTag!], TypeTag[TypeTag.UINT32]);
86
+ throw TagCheckError.forBaseAddress(TypeTag[baseAddrTag!]);
87
87
  }
88
88
  }
89
89
  // Here we know that resolved[i] is at most 32 bits and baseAddr is at most 32 bits.
@@ -100,7 +100,7 @@ export class Addressing {
100
100
 
101
101
  // Final check.
102
102
  if (!TaggedMemory.isValidMemoryAddressTag(resolvedTag)) {
103
- throw TagCheckError.forOffset(resolved[i], TypeTag[resolvedTag], TypeTag[TypeTag.UINT32]);
103
+ throw TagCheckError.forIndirectAddress(resolved[i], TypeTag[resolvedTag]);
104
104
  }
105
105
 
106
106
  resolved[i] = Number(resolvedValue.toBigInt());
@@ -15,7 +15,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
15
15
  export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInstruction {
16
16
  public async execute(context: AvmContext): Promise<void> {
17
17
  const memory = context.machineState.memory;
18
- const addressing = Addressing.fromWire(this.indirect);
18
+ const addressing = Addressing.fromWire(this.addressingMode);
19
19
 
20
20
  context.machineState.consumeGas(
21
21
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -88,7 +88,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
88
88
  static readonly opcode = Opcode.FDIV_8; // FIXME: needed for gas.
89
89
 
90
90
  protected compute(a: Field, b: Field): Field {
91
- // return (a as Field).fdiv(b as Field);
91
+ if (b.toBigInt() === 0n) {
92
+ throw new ArithmeticError('Division by zero');
93
+ }
92
94
  return a.fdiv(b);
93
95
  }
94
96
 
@@ -105,6 +107,11 @@ export class Shl extends ThreeOperandArithmeticInstruction {
105
107
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
106
108
  return a.shl(b);
107
109
  }
110
+
111
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
112
+ memory.checkTagsAreSame(aOffset, bOffset);
113
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
114
+ }
108
115
  }
109
116
 
110
117
  export class Shr extends ThreeOperandArithmeticInstruction {
@@ -114,4 +121,9 @@ export class Shr extends ThreeOperandArithmeticInstruction {
114
121
  protected override compute(a: IntegralValue, b: IntegralValue): IntegralValue {
115
122
  return a.shr(b);
116
123
  }
124
+
125
+ protected override checkTags(memory: TaggedMemoryInterface, aOffset: number, bOffset: number) {
126
+ memory.checkTagsAreSame(aOffset, bOffset);
127
+ TaggedMemory.checkIsIntegralTag(memory.getTag(aOffset)); // Follows that bOffset tag is also of integral type
128
+ }
117
129
  }
@@ -9,7 +9,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
9
9
  abstract class ThreeOperandBitwiseInstruction extends ThreeOperandInstruction {
10
10
  public async execute(context: AvmContext): Promise<void> {
11
11
  const memory = context.machineState.memory;
12
- const addressing = Addressing.fromWire(this.indirect);
12
+ const addressing = Addressing.fromWire(this.addressingMode);
13
13
 
14
14
  context.machineState.consumeGas(
15
15
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -87,7 +87,7 @@ export class Not extends Instruction {
87
87
  static readonly wireFormat16 = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
88
88
 
89
89
  constructor(
90
- private indirect: number,
90
+ private addressingMode: number,
91
91
  private srcOffset: number,
92
92
  private dstOffset: number,
93
93
  ) {
@@ -96,7 +96,7 @@ export class Not extends Instruction {
96
96
 
97
97
  public async execute(context: AvmContext): Promise<void> {
98
98
  const memory = context.machineState.memory;
99
- const addressing = Addressing.fromWire(this.indirect);
99
+ const addressing = Addressing.fromWire(this.addressingMode);
100
100
 
101
101
  context.machineState.consumeGas(
102
102
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -7,7 +7,7 @@ import { ThreeOperandInstruction } from './instruction_impl.js';
7
7
  abstract class ComparatorInstruction extends ThreeOperandInstruction {
8
8
  public async execute(context: AvmContext): Promise<void> {
9
9
  const memory = context.machineState.memory;
10
- const addressing = Addressing.fromWire(this.indirect);
10
+ const addressing = Addressing.fromWire(this.addressingMode);
11
11
 
12
12
  context.machineState.consumeGas(
13
13
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -17,14 +17,14 @@ export class GetContractInstance extends Instruction {
17
17
  // Informs (de)serialization. See Instruction.deserialize.
18
18
  static readonly wireFormat: OperandType[] = [
19
19
  OperandType.UINT8, // opcode
20
- OperandType.UINT8, // indirect bits
20
+ OperandType.UINT8, // addressing_mode bits
21
21
  OperandType.UINT16, // addressOffset
22
22
  OperandType.UINT16, // dstOffset
23
23
  OperandType.UINT8, // member enum (immediate)
24
24
  ];
25
25
 
26
26
  constructor(
27
- private indirect: number,
27
+ private addressingMode: number,
28
28
  private addressOffset: number,
29
29
  private dstOffset: number,
30
30
  private memberEnum: number,
@@ -34,7 +34,7 @@ export class GetContractInstance extends Instruction {
34
34
 
35
35
  async execute(context: AvmContext): Promise<void> {
36
36
  const memory = context.machineState.memory;
37
- const addressing = Addressing.fromWire(this.indirect);
37
+ const addressing = Addressing.fromWire(this.addressingMode);
38
38
 
39
39
  context.machineState.consumeGas(
40
40
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -67,9 +67,6 @@ export class GetContractInstance extends Instruction {
67
67
  }
68
68
  }
69
69
 
70
- const existsOffset = dstOffset;
71
- const memberValueOffset = dstOffset + 1;
72
- memory.set(existsOffset, new Uint1(exists ? 1 : 0));
73
- memory.set(memberValueOffset, memberValue);
70
+ memory.setSlice(dstOffset, [new Uint1(exists ? 1 : 0), memberValue]);
74
71
  }
75
72
  }
@@ -39,7 +39,7 @@ export class JumpI extends Instruction {
39
39
  ];
40
40
 
41
41
  constructor(
42
- private indirect: number,
42
+ private addressingMode: number,
43
43
  private condOffset: number,
44
44
  private loc: number,
45
45
  ) {
@@ -48,7 +48,7 @@ export class JumpI extends Instruction {
48
48
 
49
49
  public async execute(context: AvmContext): Promise<void> {
50
50
  const memory = context.machineState.memory;
51
- const addressing = Addressing.fromWire(this.indirect);
51
+ const addressing = Addressing.fromWire(this.addressingMode);
52
52
 
53
53
  context.machineState.consumeGas(
54
54
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -12,7 +12,7 @@ export class ToRadixBE extends Instruction {
12
12
  // Informs (de)serialization. See Instruction.deserialize.
13
13
  static readonly wireFormat: OperandType[] = [
14
14
  OperandType.UINT8, // Opcode
15
- OperandType.UINT16, // Indirect
15
+ OperandType.UINT16, // addressing_mode
16
16
  OperandType.UINT16, // src memory address
17
17
  OperandType.UINT16, // radix memory address
18
18
  OperandType.UINT16, // number of limbs address
@@ -21,7 +21,7 @@ export class ToRadixBE extends Instruction {
21
21
  ];
22
22
 
23
23
  constructor(
24
- private indirect: number,
24
+ private addressingMode: number,
25
25
  private srcOffset: number,
26
26
  private radixOffset: number,
27
27
  private numLimbsOffset: number,
@@ -33,7 +33,7 @@ export class ToRadixBE extends Instruction {
33
33
 
34
34
  public async execute(context: AvmContext): Promise<void> {
35
35
  const memory = context.machineState.memory;
36
- const addressing = Addressing.fromWire(this.indirect);
36
+ const addressing = Addressing.fromWire(this.addressingMode);
37
37
 
38
38
  context.machineState.consumeGas(
39
39
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -1,5 +1,5 @@
1
- import { Grumpkin } from '@aztec/foundation/crypto';
2
- import { Point } from '@aztec/foundation/fields';
1
+ import { Grumpkin } from '@aztec/foundation/crypto/grumpkin';
2
+ import { Point } from '@aztec/foundation/curves/grumpkin';
3
3
 
4
4
  import type { AvmContext } from '../avm_context.js';
5
5
  import { Field, TypeTag, Uint1 } from '../avm_memory_types.js';
@@ -26,7 +26,7 @@ export class EcAdd extends Instruction {
26
26
  ];
27
27
 
28
28
  constructor(
29
- private indirect: number,
29
+ private addressingMode: number,
30
30
  private p1XOffset: number,
31
31
  private p1YOffset: number,
32
32
  private p1IsInfiniteOffset: number,
@@ -40,7 +40,7 @@ export class EcAdd extends Instruction {
40
40
 
41
41
  public async execute(context: AvmContext): Promise<void> {
42
42
  const memory = context.machineState.memory;
43
- const addressing = Addressing.fromWire(this.indirect);
43
+ const addressing = Addressing.fromWire(this.addressingMode);
44
44
 
45
45
  context.machineState.consumeGas(
46
46
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
@@ -79,12 +79,21 @@ export class EcAdd extends Instruction {
79
79
  }
80
80
 
81
81
  let dest;
82
- if (p1IsInfinite) {
82
+ if (p1IsInfinite && p2IsInfinite) {
83
+ dest = Point.ZERO;
84
+ } else if (p1IsInfinite) {
83
85
  dest = p2;
84
86
  } else if (p2IsInfinite) {
85
87
  dest = p1;
86
88
  } else {
87
- dest = await Grumpkin.add(p1, p2);
89
+ // TS<>BB ecc add communication is broken for points that add up to infinity.
90
+ // However, here we know that both points are on the curve, and that none is infinity
91
+ // so we can check for the case where you add p + (-p) = infinity.
92
+ if (p1.x.equals(p2.x) && !p1.y.equals(p2.y)) {
93
+ dest = Point.ZERO;
94
+ } else {
95
+ dest = await Grumpkin.add(p1, p2);
96
+ }
88
97
  }
89
98
 
90
99
  // Important to use setSlice() and not set() in the two following statements as
@@ -13,8 +13,8 @@ export enum EnvironmentVariable {
13
13
  VERSION,
14
14
  BLOCKNUMBER,
15
15
  TIMESTAMP,
16
- BASEFEEPERL2GAS,
17
- BASEFEEPERDAGAS,
16
+ MINFEEPERL2GAS,
17
+ MINFEEPERDAGAS,
18
18
  ISSTATICCALL,
19
19
  L2GASLEFT,
20
20
  DAGASLEFT,
@@ -36,9 +36,9 @@ function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
36
36
  return new Uint32(ctx.environment.globals.blockNumber);
37
37
  case EnvironmentVariable.TIMESTAMP:
38
38
  return new Uint64(ctx.environment.globals.timestamp);
39
- case EnvironmentVariable.BASEFEEPERL2GAS:
39
+ case EnvironmentVariable.MINFEEPERL2GAS:
40
40
  return new Uint128(ctx.environment.globals.gasFees.feePerL2Gas);
41
- case EnvironmentVariable.BASEFEEPERDAGAS:
41
+ case EnvironmentVariable.MINFEEPERDAGAS:
42
42
  return new Uint128(ctx.environment.globals.gasFees.feePerDaGas);
43
43
  case EnvironmentVariable.ISSTATICCALL:
44
44
  return new Uint1(ctx.environment.isStaticCall ? 1 : 0);
@@ -56,13 +56,13 @@ export class GetEnvVar extends Instruction {
56
56
  public static readonly opcode: Opcode = Opcode.GETENVVAR_16;
57
57
  static readonly wireFormat16: OperandType[] = [
58
58
  OperandType.UINT8, // opcode
59
- OperandType.UINT8, // indirect
59
+ OperandType.UINT8, // addressing_mode
60
60
  OperandType.UINT16, // dstOffset
61
61
  OperandType.UINT8, // variable enum (immediate)
62
62
  ];
63
63
 
64
64
  constructor(
65
- private indirect: number,
65
+ private addressingMode: number,
66
66
  private dstOffset: number,
67
67
  private varEnum: number,
68
68
  ) {
@@ -71,7 +71,7 @@ export class GetEnvVar extends Instruction {
71
71
 
72
72
  public async execute(context: AvmContext): Promise<void> {
73
73
  const memory = context.machineState.memory;
74
- const addressing = Addressing.fromWire(this.indirect);
74
+ const addressing = Addressing.fromWire(this.addressingMode);
75
75
 
76
76
  context.machineState.consumeGas(
77
77
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),