@aztec/simulator 3.0.3 → 4.0.0-devnet.1-patch.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +2 -0
  2. package/dest/common/errors.d.ts +7 -1
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.d.ts +4 -2
  5. package/dest/private/acvm/acvm.d.ts.map +1 -1
  6. package/dest/private/acvm/acvm.js +4 -3
  7. package/dest/private/acvm_native.d.ts +5 -3
  8. package/dest/private/acvm_native.d.ts.map +1 -1
  9. package/dest/private/acvm_native.js +8 -6
  10. package/dest/private/acvm_wasm.d.ts +4 -3
  11. package/dest/private/acvm_wasm.d.ts.map +1 -1
  12. package/dest/private/acvm_wasm.js +4 -4
  13. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  14. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  15. package/dest/private/circuit_recording/circuit_recorder.js +20 -17
  16. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  17. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  18. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  19. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  20. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  21. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  22. package/dest/private/factory.d.ts +3 -3
  23. package/dest/private/factory.d.ts.map +1 -1
  24. package/dest/private/factory.js +7 -4
  25. package/dest/public/avm/avm_context.d.ts +3 -3
  26. package/dest/public/avm/avm_context.d.ts.map +1 -1
  27. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  28. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  29. package/dest/public/avm/avm_contract_call_result.js +3 -3
  30. package/dest/public/avm/avm_execution_environment.d.ts +6 -5
  31. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  32. package/dest/public/avm/avm_machine_state.d.ts +6 -5
  33. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  34. package/dest/public/avm/avm_machine_state.js +3 -2
  35. package/dest/public/avm/avm_memory_types.d.ts +1 -1
  36. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  37. package/dest/public/avm/avm_memory_types.js +3 -0
  38. package/dest/public/avm/avm_simulator.d.ts +3 -2
  39. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  40. package/dest/public/avm/avm_simulator.js +5 -4
  41. package/dest/public/avm/calldata.d.ts +51 -0
  42. package/dest/public/avm/calldata.d.ts.map +1 -0
  43. package/dest/public/avm/calldata.js +63 -0
  44. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  45. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  46. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  47. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  48. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  49. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  50. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  51. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  52. package/dest/public/avm/fixtures/initializers.js +2 -1
  53. package/dest/public/avm/opcodes/accrued_substate.d.ts +16 -17
  54. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  55. package/dest/public/avm/opcodes/accrued_substate.js +39 -39
  56. package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
  57. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  58. package/dest/public/avm/opcodes/arithmetic.js +1 -1
  59. package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
  60. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  61. package/dest/public/avm/opcodes/bitwise.js +5 -5
  62. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  63. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  64. package/dest/public/avm/opcodes/comparators.js +1 -1
  65. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  66. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  67. package/dest/public/avm/opcodes/contract.js +8 -8
  68. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  69. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  70. package/dest/public/avm/opcodes/control_flow.js +4 -4
  71. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  72. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  73. package/dest/public/avm/opcodes/conversion.js +4 -4
  74. package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
  75. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  76. package/dest/public/avm/opcodes/ec_add.js +15 -6
  77. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  78. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  79. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  80. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  81. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  82. package/dest/public/avm/opcodes/external_calls.js +23 -22
  83. package/dest/public/avm/opcodes/hashing.d.ts +8 -8
  84. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  85. package/dest/public/avm/opcodes/hashing.js +18 -15
  86. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  87. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  88. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  89. package/dest/public/avm/opcodes/memory.d.ts +14 -14
  90. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  91. package/dest/public/avm/opcodes/memory.js +25 -25
  92. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  93. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  94. package/dest/public/avm/opcodes/misc.js +4 -4
  95. package/dest/public/avm/opcodes/storage.d.ts +16 -15
  96. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  97. package/dest/public/avm/opcodes/storage.js +34 -24
  98. package/dest/public/debug_fn_name.d.ts +4 -4
  99. package/dest/public/debug_fn_name.d.ts.map +1 -1
  100. package/dest/public/debug_fn_name.js +14 -5
  101. package/dest/public/executor_metrics.d.ts +1 -1
  102. package/dest/public/executor_metrics.d.ts.map +1 -1
  103. package/dest/public/executor_metrics.js +12 -33
  104. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  105. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  106. package/dest/public/fixtures/bulk_test.js +4 -68
  107. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  108. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  109. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  110. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -9
  111. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  112. package/dest/public/fixtures/custom_bytecode_tests.js +66 -22
  113. package/dest/public/fixtures/index.d.ts +4 -2
  114. package/dest/public/fixtures/index.d.ts.map +1 -1
  115. package/dest/public/fixtures/index.js +3 -1
  116. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
  117. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  118. package/dest/public/fixtures/minimal_public_tx.js +4 -14
  119. package/dest/public/fixtures/opcode_spammer.d.ts +122 -0
  120. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  121. package/dest/public/fixtures/opcode_spammer.js +1653 -0
  122. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +15 -2
  123. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  124. package/dest/public/fixtures/public_tx_simulation_tester.js +34 -7
  125. package/dest/public/fixtures/utils.d.ts +1 -1
  126. package/dest/public/fixtures/utils.d.ts.map +1 -1
  127. package/dest/public/fixtures/utils.js +3 -2
  128. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
  129. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  130. package/dest/public/fuzzing/avm_fuzzer_simulator.js +46 -11
  131. package/dest/public/fuzzing/avm_simulator_bin.js +47 -13
  132. package/dest/public/hinting_db_sources.d.ts +2 -1
  133. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  134. package/dest/public/hinting_db_sources.js +5 -0
  135. package/dest/public/public_db_sources.d.ts +4 -3
  136. package/dest/public/public_db_sources.d.ts.map +1 -1
  137. package/dest/public/public_db_sources.js +4 -4
  138. package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -1
  139. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  140. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  141. package/dest/public/public_processor/public_processor.d.ts +6 -4
  142. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  143. package/dest/public/public_processor/public_processor.js +428 -34
  144. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  145. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  146. package/dest/public/public_processor/public_processor_metrics.js +28 -45
  147. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  148. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  149. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +17 -13
  150. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +20 -5
  151. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  152. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +50 -11
  153. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  154. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  155. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +5 -5
  156. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  157. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  158. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +8 -7
  159. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  160. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  161. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  162. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  163. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  164. package/dest/public/public_tx_simulator/factories.js +3 -3
  165. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
  166. package/dest/public/public_tx_simulator/public_tx_context.d.ts +4 -3
  167. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  168. package/dest/public/public_tx_simulator/public_tx_context.js +8 -8
  169. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -4
  170. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  171. package/dest/public/public_tx_simulator/public_tx_simulator.js +12 -7
  172. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  173. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  174. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  175. package/dest/public/side_effect_trace.d.ts +5 -4
  176. package/dest/public/side_effect_trace.d.ts.map +1 -1
  177. package/dest/public/side_effect_trace.js +3 -3
  178. package/dest/public/state_manager/state_manager.d.ts +10 -4
  179. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  180. package/dest/public/state_manager/state_manager.js +14 -7
  181. package/dest/public/test_executor_metrics.d.ts +3 -2
  182. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  183. package/dest/public/test_executor_metrics.js +2 -2
  184. package/package.json +17 -17
  185. package/src/private/acvm/acvm.ts +4 -3
  186. package/src/private/acvm_native.ts +11 -5
  187. package/src/private/acvm_wasm.ts +7 -3
  188. package/src/private/circuit_recording/circuit_recorder.ts +21 -18
  189. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  190. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  191. package/src/private/factory.ts +7 -4
  192. package/src/public/avm/avm_context.ts +2 -2
  193. package/src/public/avm/avm_contract_call_result.ts +8 -6
  194. package/src/public/avm/avm_execution_environment.ts +9 -4
  195. package/src/public/avm/avm_machine_state.ts +6 -5
  196. package/src/public/avm/avm_memory_types.ts +4 -0
  197. package/src/public/avm/avm_simulator.ts +8 -5
  198. package/src/public/avm/calldata.ts +100 -0
  199. package/src/public/avm/fixtures/account_proof.json +553 -0
  200. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  201. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
  202. package/src/public/avm/fixtures/initializers.ts +2 -1
  203. package/src/public/avm/opcodes/accrued_substate.ts +28 -30
  204. package/src/public/avm/opcodes/arithmetic.ts +1 -1
  205. package/src/public/avm/opcodes/bitwise.ts +3 -3
  206. package/src/public/avm/opcodes/comparators.ts +1 -1
  207. package/src/public/avm/opcodes/contract.ts +4 -7
  208. package/src/public/avm/opcodes/control_flow.ts +2 -2
  209. package/src/public/avm/opcodes/conversion.ts +3 -3
  210. package/src/public/avm/opcodes/ec_add.ts +13 -4
  211. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  212. package/src/public/avm/opcodes/external_calls.ts +17 -15
  213. package/src/public/avm/opcodes/hashing.ts +13 -9
  214. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  215. package/src/public/avm/opcodes/memory.ts +19 -19
  216. package/src/public/avm/opcodes/misc.ts +2 -2
  217. package/src/public/avm/opcodes/storage.ts +30 -22
  218. package/src/public/debug_fn_name.ts +17 -8
  219. package/src/public/executor_metrics.ts +9 -33
  220. package/src/public/fixtures/bulk_test.ts +8 -8
  221. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  222. package/src/public/fixtures/custom_bytecode_tests.ts +91 -22
  223. package/src/public/fixtures/index.ts +7 -1
  224. package/src/public/fixtures/minimal_public_tx.ts +5 -14
  225. package/src/public/fixtures/opcode_spammer.ts +1721 -0
  226. package/src/public/fixtures/public_tx_simulation_tester.ts +38 -5
  227. package/src/public/fixtures/utils.ts +1 -2
  228. package/src/public/fuzzing/avm_fuzzer_simulator.ts +67 -12
  229. package/src/public/fuzzing/avm_simulator_bin.ts +64 -10
  230. package/src/public/hinting_db_sources.ts +4 -0
  231. package/src/public/public_db_sources.ts +15 -5
  232. package/src/public/public_processor/guarded_merkle_tree.ts +4 -0
  233. package/src/public/public_processor/public_processor.ts +41 -16
  234. package/src/public/public_processor/public_processor_metrics.ts +16 -44
  235. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +22 -14
  236. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +65 -9
  237. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +6 -4
  238. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +9 -6
  239. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  240. package/src/public/public_tx_simulator/factories.ts +4 -2
  241. package/src/public/public_tx_simulator/public_tx_context.ts +13 -6
  242. package/src/public/public_tx_simulator/public_tx_simulator.ts +18 -7
  243. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
  244. package/src/public/side_effect_trace.ts +5 -2
  245. package/src/public/state_manager/state_manager.ts +29 -20
  246. package/src/public/test_executor_metrics.ts +3 -3
@@ -1,49 +1,83 @@
1
1
  import { FunctionType, emptyContractArtifact, emptyFunctionArtifact } from '@aztec/stdlib/abi';
2
2
  import type { PublicTxResult } from '@aztec/stdlib/avm';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
5
 
5
6
  import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
6
7
 
7
8
  /**
8
- *
9
- * Test custom bytecode (simulation or proving) with the provided bytecode.
9
+ * Deploy a contract with the provided bytecode.
10
10
  * @param bytecode - The bytecode buffer to use
11
- * @param tester - The tester to use (simulation or proving)
12
- * @param txLabel - The label of the transaction
13
- * @param contractName - The name of the contract (default: 'CustomBytecodeContract')
11
+ * @param tester - The tester to use
12
+ * @param contractName - The name of the contract
13
+ * @param deployer - The deployer address
14
+ * @returns The deployed contract instance
14
15
  */
15
- export async function testCustomBytecode(
16
+ export async function deployCustomBytecode(
16
17
  bytecode: Buffer,
17
18
  tester: PublicTxSimulationTester,
18
- txLabel: string,
19
19
  contractName: string = 'CustomBytecodeContract',
20
- ): Promise<PublicTxResult> {
21
- const deployer = AztecAddress.fromNumber(42);
22
-
20
+ deployer: AztecAddress = AztecAddress.fromNumber(42),
21
+ ): Promise<ContractInstanceWithAddress> {
23
22
  const contractArtifact = emptyContractArtifact();
24
23
  contractArtifact.name = contractName;
25
24
  contractArtifact.functions = [emptyFunctionArtifact()];
25
+ // We use name 'public_dispatch' since that is what is expected
26
+ // in a ContractArtifact. But function selectors are not required
27
+ // when executing since the custom bytecode likely has no dispatch.
26
28
  contractArtifact.functions[0].name = 'public_dispatch';
27
29
  contractArtifact.functions[0].functionType = FunctionType.PUBLIC;
28
30
  contractArtifact.functions[0].bytecode = bytecode;
29
31
 
30
- const testContract = await tester.registerAndDeployContract(
32
+ // return the contract instance
33
+ return await tester.registerAndDeployContract(
31
34
  /*constructorArgs=*/ [],
32
35
  deployer,
33
36
  /*contractArtifact=*/ contractArtifact,
34
37
  );
38
+ }
35
39
 
40
+ /**
41
+ * Execute a custom bytecode contract.
42
+ * @param contract - The contract instance to execute
43
+ * @param tester - The tester to use
44
+ * @param txLabel - The label of the transaction
45
+ * @param calldata - The calldata to use
46
+ * @returns The execution result
47
+ */
48
+ export async function executeCustomBytecode(
49
+ contract: ContractInstanceWithAddress,
50
+ tester: PublicTxSimulationTester,
51
+ txLabel: string = 'CustomBytecodeTest',
52
+ calldata: any[] = [],
53
+ ): Promise<PublicTxResult> {
36
54
  // EXECUTE! This means that if using AvmProvingTester subclass, it will PROVE the transaction!
37
55
  return await tester.executeTxWithLabel(
38
56
  /*txLabel=*/ txLabel,
39
- /*sender=*/ deployer,
57
+ /*sender=*/ contract.deployer,
40
58
  /*setupCalls=*/ [],
41
- /*appCalls=*/ [
42
- {
43
- address: testContract.address,
44
- fnName: 'public_dispatch',
45
- args: [],
46
- },
47
- ],
59
+ /*appCalls=*/ [{ address: contract.address, args: calldata }],
48
60
  );
49
61
  }
62
+
63
+ /**
64
+ * Deploy and execute a custom bytecode contract.
65
+ * @param bytecode - The bytecode buffer to use
66
+ * @param tester - The tester to use
67
+ * @param txLabel - The label of the transaction
68
+ * @param contractName - The name of the contract
69
+ * @param deployer - The deployer address
70
+ * @param calldata - The calldata to use
71
+ * @returns The execution result
72
+ */
73
+ export async function deployAndExecuteCustomBytecode(
74
+ bytecode: Buffer,
75
+ tester: PublicTxSimulationTester,
76
+ txLabel: string = 'CustomBytecodeTest',
77
+ contractName: string = 'CustomBytecodeContract',
78
+ deployer: AztecAddress = AztecAddress.fromNumber(42),
79
+ calldata: any[] = [],
80
+ ): Promise<PublicTxResult> {
81
+ const testContract = await deployCustomBytecode(bytecode, tester, contractName, deployer);
82
+ return await executeCustomBytecode(testContract, tester, txLabel, calldata);
83
+ }
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
2
2
 
3
3
  import { TypeTag } from '../avm/avm_memory_types.js';
4
4
  import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
5
- import { CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
5
+ import { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
6
6
  import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
7
7
  import {
8
8
  MAX_OPCODE_VALUE,
@@ -10,7 +10,7 @@ import {
10
10
  OperandType,
11
11
  getOperandSize,
12
12
  } from '../avm/serialization/instruction_serialization.js';
13
- import { testCustomBytecode } from './custom_bytecode_tester.js';
13
+ import { deployAndExecuteCustomBytecode } from './custom_bytecode_tester.js';
14
14
  import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
15
15
 
16
16
  // First instruction resolved a base address (offset 0) which is uninitialized and therefore
@@ -23,12 +23,12 @@ export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester
23
23
  ]);
24
24
 
25
25
  const bytecode = encodeToBytecode([
26
- new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 0),
27
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
26
+ new CalldataCopy(/*addressing_mode=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 0),
27
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
28
28
  ]);
29
29
 
30
30
  const txLabel = isIndirect ? 'AddressingWithBaseTagInvalidIndirect' : 'AddressingWithBaseTagInvalidDirect';
31
- return await testCustomBytecode(bytecode, tester, txLabel);
31
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
32
32
  }
33
33
 
34
34
  // First instruction sets a value with tag U64 at offset 0. Then a CalldataCopy instruction
@@ -44,44 +44,110 @@ export async function addressingWithIndirectTagIssueTest(tester: PublicTxSimulat
44
44
 
45
45
  const bytecode = encodeToBytecode([
46
46
  // Set a U64 value at offset 0 - this has the wrong tag for an address (should be U32)
47
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT64, /*value=*/ 100n).as(Opcode.SET_64, Set.wireFormat64),
47
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT64, /*value=*/ 100n).as(
48
+ Opcode.SET_64,
49
+ Set.wireFormat64,
50
+ ),
48
51
  // Try to use indirect addressing: read from offset 0, which contains a U64 value
49
52
  // This should fail because U64 is not a valid address tag (must be U32)
50
- new CalldataCopy(/*indirect=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 1),
51
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
53
+ new CalldataCopy(/*addressing_mode=*/ addressingMode.toWire(), /*copySize=*/ 1, /*cdOffset=*/ 0, /*dstOffset=*/ 1),
54
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
52
55
  ]);
53
56
 
54
57
  const txLabel = 'AddressingWithIndirectTagInvalid';
55
- return await testCustomBytecode(bytecode, tester, txLabel);
58
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
59
+ }
60
+
61
+ // First instruction sets a value 10 with tag U32 at offset 1 (direct, no relative).
62
+ // Then an ADD_16 instruction uses INDIRECT addressing for the first operand (offset 1)
63
+ // and RELATIVE addressing for the second operand (offset 2). The indirect addressing
64
+ // succeeds (reads U32 value 10 from offset 1, uses it as address), but the relative
65
+ // addressing fails because the base address at offset 0 has the wrong tag (uninitialized/invalid).
66
+ export async function addressingWithIndirectThenRelativeTagIssueTest(tester: PublicTxSimulationTester) {
67
+ const addressingMode = Addressing.fromModes([
68
+ AddressingMode.INDIRECT, // First operand (aOffset) uses indirect addressing, no relative
69
+ AddressingMode.RELATIVE, // Second operand (bOffset) uses relative addressing
70
+ AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
71
+ ]);
72
+
73
+ const bytecode = encodeToBytecode([
74
+ // Set a U32 value 10 at offset 1 - this will be used as an indirect address
75
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, /*value=*/ 10).as(
76
+ Opcode.SET_32,
77
+ Set.wireFormat32,
78
+ ),
79
+ // ADD_16: first operand uses indirect addressing (reads from offset 1, gets value 10, uses as address - succeeds)
80
+ // second operand uses relative addressing (tries to read base from offset 0, but offset 0 has wrong tag - fails)
81
+ new Add(/*addressing_mode=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
82
+ Opcode.ADD_16,
83
+ Add.wireFormat16,
84
+ ),
85
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
86
+ ]);
87
+
88
+ const txLabel = 'AddressingWithIndirectThenRelativeTagInvalid';
89
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
90
+ }
91
+
92
+ // First instruction sets UINT32_MAX at offset 0 (base address) with tag U32.
93
+ // Then an ADD_8 instruction uses INDIRECT_RELATIVE addressing for the first operand (offset 1)
94
+ // and INDIRECT addressing for the second operand (offset 2). The relative addressing
95
+ // for the first operand will overflow (UINT32_MAX + 1 >= MAX_MEMORY_SIZE), causing the instruction to fail.
96
+ // The second operand will also fail (indirect addressing from offset 2 which is uninitialized with tag FF).
97
+ export async function addressingWithRelativeOverflowAndIndirectTagIssueTest(tester: PublicTxSimulationTester) {
98
+ const addressingMode = Addressing.fromModes([
99
+ AddressingMode.INDIRECT_RELATIVE, // First operand (aOffset) uses both indirect and relative addressing
100
+ AddressingMode.INDIRECT, // Second operand (bOffset) uses indirect addressing only
101
+ AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
102
+ ]);
103
+
104
+ // UINT32_MAX = 2^32 - 1 = 4294967295
105
+ const UINT32_MAX = 0xffffffff;
106
+
107
+ const bytecode = encodeToBytecode([
108
+ // Set UINT32_MAX at offset 0 as base address - this will cause overflow when adding relative offset 1
109
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ UINT32_MAX).as(
110
+ Opcode.SET_32,
111
+ Set.wireFormat32,
112
+ ),
113
+ new Add(/*addressing_mode=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
114
+ Opcode.ADD_8,
115
+ Add.wireFormat8,
116
+ ),
117
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
118
+ ]);
119
+
120
+ const txLabel = 'AddressingWithRelativeOverflowAndIndirectTagInvalid';
121
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
56
122
  }
57
123
 
58
124
  export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
59
125
  const bytecode = encodeToBytecode([
60
126
  new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
61
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
127
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
62
128
  ]);
63
129
 
64
130
  const txLabel = 'PcOutOfRange';
65
- return await testCustomBytecode(bytecode, tester, txLabel);
131
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
66
132
  }
67
133
 
68
134
  export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
69
135
  let bytecode = encodeToBytecode([
70
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
136
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
71
137
  ]);
72
138
 
73
139
  const offsetReturnOpcodeByte = bytecode.length;
74
140
 
75
141
  bytecode = Buffer.concat([
76
142
  bytecode,
77
- encodeToBytecode([new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
143
+ encodeToBytecode([new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
78
144
  ]);
79
145
 
80
146
  // Manipulate the Return opcode to make the opcode invalid (out of range).
81
147
  bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
82
148
 
83
149
  const txLabel = 'InvalidOpcode';
84
- return await testCustomBytecode(bytecode, tester, txLabel);
150
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
85
151
  }
86
152
 
87
153
  // Single invalid byte in the bytecode.
@@ -91,27 +157,27 @@ export async function invalidByteTest(tester: PublicTxSimulationTester) {
91
157
  const bytecode = Buffer.from([invalidOpcode]);
92
158
 
93
159
  const txLabel = 'InvalidByte';
94
- return await testCustomBytecode(bytecode, tester, txLabel);
160
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
95
161
  }
96
162
 
97
163
  // Truncate the last instruction in the bytecode.
98
164
  export async function instructionTruncatedTest(tester: PublicTxSimulationTester) {
99
165
  let bytecode = encodeToBytecode([
100
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
166
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
101
167
  ]);
102
168
 
103
169
  // Truncate the bytecode.
104
170
  bytecode = bytecode.subarray(0, -1);
105
171
 
106
172
  const txLabel = 'InstructionTruncated';
107
- return await testCustomBytecode(bytecode, tester, txLabel);
173
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
108
174
  }
109
175
 
110
176
  // Invalid tag value byte in an instruction.
111
177
  export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
112
178
  const bytecode = encodeToBytecode([
113
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
114
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
179
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
180
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
115
181
  ]);
116
182
 
117
183
  const tagOffset = getTagOffsetInInstruction(Set.wireFormat8);
@@ -119,14 +185,17 @@ export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
119
185
  bytecode[tagOffset] = TypeTag.INVALID;
120
186
 
121
187
  const txLabel = 'InvalidTagValue';
122
- return await testCustomBytecode(bytecode, tester, txLabel);
188
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
123
189
  }
124
190
 
125
191
  // Combine an invalid tag in the last instruction that is truncated.
126
192
  export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicTxSimulationTester) {
127
193
  let bytecode = encodeToBytecode([
128
194
  // Important: value argument must be a bigint otherwise a type error will be thrown.
129
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT128, /*value=*/ 0n).as(Opcode.SET_128, Set.wireFormat128),
195
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT128, /*value=*/ 0n).as(
196
+ Opcode.SET_128,
197
+ Set.wireFormat128,
198
+ ),
130
199
  ]);
131
200
 
132
201
  // Truncate the bytecode.
@@ -136,7 +205,7 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
136
205
  bytecode[tagOffset] = 0x6f; // Invalid tag value.
137
206
 
138
207
  const txLabel = 'InvalidTagValueAndInstructionTruncated';
139
- return await testCustomBytecode(bytecode, tester, txLabel);
208
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
140
209
  }
141
210
 
142
211
  /**
@@ -1,9 +1,15 @@
1
1
  export * from './public_tx_simulation_tester.js';
2
2
  export * from './utils.js';
3
3
  export * from './simple_contract_data_source.js';
4
- export { readAvmMinimalPublicTxInputsFromFile, executeAvmMinimalPublicTx } from './minimal_public_tx.js';
4
+ export { executeAvmMinimalPublicTx } from './minimal_public_tx.js';
5
5
  export { TestExecutorMetrics } from '../test_executor_metrics.js';
6
6
  export { ammTest } from './amm_test.js';
7
7
  export { bulkTest, megaBulkTest } from './bulk_test.js';
8
8
  export { tokenTest } from './token_test.js';
9
9
  export * from './custom_bytecode_tests.js';
10
+ export {
11
+ deployCustomBytecode,
12
+ executeCustomBytecode,
13
+ deployAndExecuteCustomBytecode,
14
+ } from './custom_bytecode_tester.js';
15
+ export { getSpamConfigsPerOpcode, testOpcodeSpamCase } from './opcode_spammer.js';
@@ -1,23 +1,22 @@
1
- import { AvmCircuitInputs, type PublicTxResult } from '@aztec/stdlib/avm';
1
+ import type { PublicTxResult } from '@aztec/stdlib/avm';
2
2
  import { ProtocolContracts } from '@aztec/stdlib/tx';
3
3
 
4
- import avmMinimalCircuitInputsJson from '../../../artifacts/avm_minimal_inputs.json' with { type: 'json' };
5
4
  import { TypeTag } from '../avm/avm_memory_types.js';
6
5
  import { Add, Return, Set } from '../avm/opcodes/index.js';
7
6
  import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
8
7
  import { Opcode } from '../avm/serialization/instruction_serialization.js';
9
- import { testCustomBytecode } from './custom_bytecode_tester.js';
8
+ import { deployAndExecuteCustomBytecode } from './custom_bytecode_tester.js';
10
9
  import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
11
10
 
12
11
  export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester): Promise<PublicTxResult> {
13
12
  const minimalBytecode = encodeToBytecode([
14
13
  new Set(/*indirect*/ 0, /*dstOffset*/ 0, TypeTag.UINT32, /*value*/ 1).as(Opcode.SET_8, Set.wireFormat8),
15
14
  new Set(/*indirect*/ 0, /*dstOffset*/ 1, TypeTag.UINT32, /*value*/ 2).as(Opcode.SET_8, Set.wireFormat8),
16
- new Add(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
17
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
15
+ new Add(/*addressing_mode=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
16
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
18
17
  ]);
19
18
 
20
- const result = await testCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');
19
+ const result = await deployAndExecuteCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');
21
20
 
22
21
  // Modify the protocol contracts to be all zeros
23
22
  result.hints!.protocolContracts = ProtocolContracts.empty();
@@ -25,11 +24,3 @@ export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester
25
24
 
26
25
  return result;
27
26
  }
28
-
29
- /**
30
- * Reads the AVM circuit inputs for the minimal public tx from a pre-generated JSON file.
31
- * @returns The AvmCircuitInputs for the minimal public tx.
32
- */
33
- export function readAvmMinimalPublicTxInputsFromFile(): AvmCircuitInputs {
34
- return AvmCircuitInputs.schema.parse(avmMinimalCircuitInputsJson);
35
- }