@aztec/simulator 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (255) hide show
  1. package/README.md +6 -4
  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 +7 -5
  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 +22 -19
  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_gas.js +3 -3
  33. package/dest/public/avm/avm_machine_state.d.ts +6 -5
  34. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  35. package/dest/public/avm/avm_machine_state.js +3 -2
  36. package/dest/public/avm/avm_memory_types.d.ts +1 -1
  37. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  38. package/dest/public/avm/avm_memory_types.js +3 -0
  39. package/dest/public/avm/avm_simulator.d.ts +3 -2
  40. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  41. package/dest/public/avm/avm_simulator.js +6 -5
  42. package/dest/public/avm/calldata.d.ts +51 -0
  43. package/dest/public/avm/calldata.d.ts.map +1 -0
  44. package/dest/public/avm/calldata.js +64 -0
  45. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  46. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  47. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  48. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  49. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  50. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  51. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
  52. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  53. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +17 -2
  54. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  55. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  56. package/dest/public/avm/fixtures/initializers.js +2 -1
  57. package/dest/public/avm/fixtures/utils.d.ts +1 -1
  58. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  59. package/dest/public/avm/fixtures/utils.js +3 -0
  60. package/dest/public/avm/opcodes/accrued_substate.d.ts +17 -18
  61. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  62. package/dest/public/avm/opcodes/accrued_substate.js +42 -43
  63. package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
  64. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  65. package/dest/public/avm/opcodes/arithmetic.js +1 -1
  66. package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
  67. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  68. package/dest/public/avm/opcodes/bitwise.js +5 -5
  69. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  70. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/comparators.js +1 -1
  72. package/dest/public/avm/opcodes/contract.d.ts +5 -4
  73. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/contract.js +13 -9
  75. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  76. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/control_flow.js +4 -4
  78. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  79. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/conversion.js +4 -4
  81. package/dest/public/avm/opcodes/ec_add.d.ts +4 -6
  82. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/ec_add.js +22 -27
  84. package/dest/public/avm/opcodes/environment_getters.d.ts +5 -5
  85. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  87. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  88. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  89. package/dest/public/avm/opcodes/external_calls.js +23 -22
  90. package/dest/public/avm/opcodes/hashing.d.ts +8 -8
  91. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  92. package/dest/public/avm/opcodes/hashing.js +12 -12
  93. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  94. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  95. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  96. package/dest/public/avm/opcodes/memory.d.ts +14 -14
  97. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  98. package/dest/public/avm/opcodes/memory.js +25 -25
  99. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  100. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  101. package/dest/public/avm/opcodes/misc.js +4 -4
  102. package/dest/public/avm/opcodes/storage.d.ts +16 -15
  103. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  104. package/dest/public/avm/opcodes/storage.js +34 -24
  105. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  106. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  107. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  108. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  109. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  110. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  111. package/dest/public/contracts_db_checkpoint.js +1 -1
  112. package/dest/public/debug_fn_name.d.ts +4 -4
  113. package/dest/public/debug_fn_name.d.ts.map +1 -1
  114. package/dest/public/debug_fn_name.js +7 -5
  115. package/dest/public/executor_metrics.d.ts +1 -1
  116. package/dest/public/executor_metrics.d.ts.map +1 -1
  117. package/dest/public/executor_metrics.js +12 -33
  118. package/dest/public/fixtures/amm_test.js +2 -2
  119. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  120. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  121. package/dest/public/fixtures/bulk_test.js +32 -21
  122. package/dest/public/fixtures/custom_bytecode_tests.d.ts +13 -11
  123. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  124. package/dest/public/fixtures/custom_bytecode_tests.js +79 -19
  125. package/dest/public/fixtures/minimal_public_tx.js +2 -2
  126. package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
  127. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  128. package/dest/public/fixtures/opcode_spammer.js +100 -136
  129. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  130. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  131. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  132. package/dest/public/fixtures/utils.d.ts +2 -2
  133. package/dest/public/fixtures/utils.d.ts.map +1 -1
  134. package/dest/public/fixtures/utils.js +19 -20
  135. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
  136. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  137. package/dest/public/fuzzing/avm_fuzzer_simulator.js +42 -10
  138. package/dest/public/fuzzing/avm_simulator_bin.js +29 -11
  139. package/dest/public/hinting_db_sources.d.ts +5 -5
  140. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  141. package/dest/public/hinting_db_sources.js +10 -7
  142. package/dest/public/public_db_sources.d.ts +9 -5
  143. package/dest/public/public_db_sources.d.ts.map +1 -1
  144. package/dest/public/public_db_sources.js +20 -14
  145. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  146. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  147. package/dest/public/public_processor/guarded_merkle_tree.js +7 -5
  148. package/dest/public/public_processor/public_processor.d.ts +11 -6
  149. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  150. package/dest/public/public_processor/public_processor.js +511 -92
  151. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  152. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  153. package/dest/public/public_processor/public_processor_metrics.js +36 -45
  154. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  155. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  156. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +5 -4
  157. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  158. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  159. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -10
  160. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  161. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  162. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  163. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  164. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  165. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  166. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  167. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  168. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  169. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  170. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  171. package/dest/public/public_tx_simulator/factories.js +4 -4
  172. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
  173. package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
  174. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  175. package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
  176. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +11 -5
  177. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  178. package/dest/public/public_tx_simulator/public_tx_simulator.js +26 -16
  179. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  180. package/dest/public/side_effect_trace.d.ts +5 -4
  181. package/dest/public/side_effect_trace.d.ts.map +1 -1
  182. package/dest/public/side_effect_trace.js +3 -3
  183. package/dest/public/state_manager/state_manager.d.ts +10 -4
  184. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  185. package/dest/public/state_manager/state_manager.js +14 -7
  186. package/dest/public/test_executor_metrics.d.ts +8 -2
  187. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  188. package/dest/public/test_executor_metrics.js +24 -2
  189. package/package.json +17 -17
  190. package/src/private/acvm/acvm.ts +4 -3
  191. package/src/private/acvm_native.ts +11 -5
  192. package/src/private/acvm_wasm.ts +11 -4
  193. package/src/private/circuit_recording/circuit_recorder.ts +23 -20
  194. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  195. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  196. package/src/private/factory.ts +7 -4
  197. package/src/public/avm/avm_context.ts +2 -2
  198. package/src/public/avm/avm_contract_call_result.ts +8 -6
  199. package/src/public/avm/avm_execution_environment.ts +9 -4
  200. package/src/public/avm/avm_gas.ts +2 -2
  201. package/src/public/avm/avm_machine_state.ts +6 -5
  202. package/src/public/avm/avm_memory_types.ts +4 -0
  203. package/src/public/avm/avm_simulator.ts +9 -6
  204. package/src/public/avm/calldata.ts +101 -0
  205. package/src/public/avm/fixtures/account_proof.json +553 -0
  206. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  207. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
  208. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +22 -2
  209. package/src/public/avm/fixtures/initializers.ts +2 -1
  210. package/src/public/avm/fixtures/utils.ts +3 -0
  211. package/src/public/avm/opcodes/accrued_substate.ts +31 -34
  212. package/src/public/avm/opcodes/arithmetic.ts +1 -1
  213. package/src/public/avm/opcodes/bitwise.ts +3 -3
  214. package/src/public/avm/opcodes/comparators.ts +1 -1
  215. package/src/public/avm/opcodes/contract.ts +9 -8
  216. package/src/public/avm/opcodes/control_flow.ts +2 -2
  217. package/src/public/avm/opcodes/conversion.ts +3 -3
  218. package/src/public/avm/opcodes/ec_add.ts +21 -31
  219. package/src/public/avm/opcodes/environment_getters.ts +7 -7
  220. package/src/public/avm/opcodes/external_calls.ts +18 -16
  221. package/src/public/avm/opcodes/hashing.ts +6 -6
  222. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  223. package/src/public/avm/opcodes/memory.ts +19 -19
  224. package/src/public/avm/opcodes/misc.ts +2 -2
  225. package/src/public/avm/opcodes/storage.ts +30 -22
  226. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  227. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  228. package/src/public/contracts_db_checkpoint.ts +1 -1
  229. package/src/public/debug_fn_name.ts +10 -8
  230. package/src/public/executor_metrics.ts +9 -33
  231. package/src/public/fixtures/amm_test.ts +2 -2
  232. package/src/public/fixtures/bulk_test.ts +31 -6
  233. package/src/public/fixtures/custom_bytecode_tests.ts +166 -19
  234. package/src/public/fixtures/minimal_public_tx.ts +2 -2
  235. package/src/public/fixtures/opcode_spammer.ts +200 -125
  236. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  237. package/src/public/fixtures/utils.ts +26 -22
  238. package/src/public/fuzzing/avm_fuzzer_simulator.ts +61 -13
  239. package/src/public/fuzzing/avm_simulator_bin.ts +43 -8
  240. package/src/public/hinting_db_sources.ts +10 -7
  241. package/src/public/public_db_sources.ts +36 -19
  242. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  243. package/src/public/public_processor/public_processor.ts +156 -93
  244. package/src/public/public_processor/public_processor_metrics.ts +28 -44
  245. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +9 -5
  246. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +17 -7
  247. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
  248. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
  249. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  250. package/src/public/public_tx_simulator/factories.ts +6 -3
  251. package/src/public/public_tx_simulator/public_tx_context.ts +21 -16
  252. package/src/public/public_tx_simulator/public_tx_simulator.ts +32 -17
  253. package/src/public/side_effect_trace.ts +5 -2
  254. package/src/public/state_manager/state_manager.ts +29 -20
  255. package/src/public/test_executor_metrics.ts +27 -3
@@ -31,7 +31,7 @@ export class ContractsDbCheckpoint {
31
31
  return this.bytecodeCommitments.get(classId.toString());
32
32
  }
33
33
 
34
- public deepCopy(): ContractsDbCheckpoint {
34
+ public fork(): ContractsDbCheckpoint {
35
35
  const copy = new ContractsDbCheckpoint();
36
36
  this.instances.forEach((value, key) => copy.instances.set(key, value));
37
37
  this.classes.forEach((value, key) => copy.classes.set(key, value));
@@ -1,20 +1,21 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
2
1
  import { FunctionSelector } from '@aztec/stdlib/abi';
3
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
3
 
4
+ import type { CallData } from './avm/calldata.js';
5
5
  import type { PublicContractsDBInterface } from './db_interfaces.js';
6
6
 
7
7
  export async function getPublicFunctionDebugName(
8
8
  db: PublicContractsDBInterface,
9
9
  contractAddress: AztecAddress,
10
- calldata: Fr[],
10
+ calldata: CallData,
11
11
  ): Promise<string> {
12
12
  // Public function is dispatched and therefore the target function is passed in the first argument.
13
- if (!calldata[0]) {
13
+ const selectorField = calldata.read(0);
14
+ if (!selectorField) {
14
15
  return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
16
  }
16
- const fallbackName = `<calldata[0]:${calldata[0].toString()}> (Contract Address: ${contractAddress})`;
17
- const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
17
+ const fallbackName = `<calldata[0]:${selectorField.toString()}> (Contract Address: ${contractAddress})`;
18
+ const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
18
19
  if (!selector) {
19
20
  return fallbackName;
20
21
  }
@@ -32,13 +33,14 @@ export async function getPublicFunctionDebugName(
32
33
  export async function getPublicFunctionSelectorAndName(
33
34
  db: PublicContractsDBInterface,
34
35
  contractAddress: AztecAddress,
35
- calldata: Fr[],
36
+ calldata: CallData,
36
37
  ): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
37
38
  // Public function is dispatched and therefore the target function is passed in the first argument.
38
- if (!calldata[0]) {
39
+ const selectorField = calldata.read(0);
40
+ if (!selectorField) {
39
41
  return {};
40
42
  }
41
- const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
43
+ const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
42
44
  if (!selector) {
43
45
  return {};
44
46
  }
@@ -7,7 +7,7 @@ import {
7
7
  type TelemetryClient,
8
8
  type Tracer,
9
9
  type UpDownCounter,
10
- ValueType,
10
+ createUpDownCounterWithDefault,
11
11
  } from '@aztec/telemetry-client';
12
12
 
13
13
  import type { ExecutorMetricsInterface } from './executor_metrics_interface.js';
@@ -26,45 +26,21 @@ export class ExecutorMetrics implements ExecutorMetricsInterface {
26
26
  this.tracer = client.getTracer(name);
27
27
  const meter = client.getMeter(name);
28
28
 
29
- this.fnCount = meter.createUpDownCounter(Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT, {
30
- description: 'Number of functions executed',
29
+ this.fnCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT, {
30
+ [Attributes.OK]: [true, false],
31
31
  });
32
32
 
33
- this.fnDuration = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_DURATION, {
34
- description: 'How long it takes to execute a function',
35
- unit: 'ms',
36
- valueType: ValueType.INT,
37
- });
33
+ this.fnDuration = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_DURATION);
38
34
 
39
- this.manaPerSecond = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_PER_SECOND, {
40
- description: 'Mana used per second',
41
- unit: 'mana/s',
42
- valueType: ValueType.INT,
43
- });
35
+ this.manaPerSecond = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_PER_SECOND);
44
36
 
45
- this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED, {
46
- description: 'Total mana used',
47
- unit: 'mana',
48
- valueType: ValueType.INT,
49
- });
37
+ this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED);
50
38
 
51
- this.totalInstructionsExecuted = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS, {
52
- description: 'Total number of instructions executed',
53
- unit: '#instructions',
54
- valueType: ValueType.INT,
55
- });
39
+ this.totalInstructionsExecuted = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS);
56
40
 
57
- this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING, {
58
- description: 'Tx hashing time',
59
- unit: 'ms',
60
- valueType: ValueType.INT,
61
- });
41
+ this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING);
62
42
 
63
- this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION, {
64
- description: 'Private effects insertion time',
65
- unit: 'us',
66
- valueType: ValueType.INT,
67
- });
43
+ this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION);
68
44
  }
69
45
 
70
46
  startRecordingTxSimulation(_txLabel: string) {
@@ -1,4 +1,4 @@
1
- import { GeneratorIndex } from '@aztec/constants';
1
+ import { DomainSeparator } from '@aztec/constants';
2
2
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { Logger } from '@aztec/foundation/log';
@@ -326,6 +326,6 @@ async function removeLiquidity(
326
326
  async function computePartialNoteValidityCommitment(partialNote: { commitment: Fr }, completer: AztecAddress) {
327
327
  return await poseidon2HashWithSeparator(
328
328
  [partialNote.commitment, completer],
329
- GeneratorIndex.PARTIAL_NOTE_VALIDITY_COMMITMENT,
329
+ DomainSeparator.PARTIAL_NOTE_VALIDITY_COMMITMENT,
330
330
  );
331
331
  }
@@ -25,14 +25,26 @@ export async function bulkTest(
25
25
  // Register multiple different protocol contracts (to ensure we don't dedup bytecode hashing events):
26
26
  await tester.registerAuthContract();
27
27
  await tester.registerInstanceRegistryContract();
28
+ await tester.registerClassRegistryContract();
28
29
 
29
30
  // Get a deployed contract instance to pass to the contract
30
31
  // for it to use as "expected" values when testing contract instance retrieval.
31
32
  const expectContractInstance = avmTestContract;
32
33
  const argsField = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
33
- const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8].map(x => new Fr(x));
34
- argsU8.push(new Fr(2n ** 128n + 9n)); // Trigger truncation from large (> 128 bits) value (canonical decomposition event)
35
- argsU8.push(new Fr(2n ** 125n + 10n)); // Trigger truncation from small (< 128 bits) value (no canonical decomposition event)
34
+ const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
35
+ // Pinned grumpkin-Poseidon2 Schnorr signature (mirrors the C++ `pinned_test_vector_large`
36
+ // and noir-lang/schnorr v0.4.0's `pinned_vector_large`). Passing these in as calldata
37
+ // (rather than baking them into Noir as constants) keeps MSM + Poseidon2 from being folded
38
+ // by the Noir compiler.
39
+ const schnorrInputs = [
40
+ Fr.fromHexString('0x065812e335a97c2108ea8cf4ccfe2f9dd6b117a0714f5e18461575be93f61da6'), // pubkey.x
41
+ Fr.fromHexString('0x1a915003e8ec534f9a15d926a7ded478e178468ccc4f28e236e67450a55ac622'), // pubkey.y
42
+ Fr.fromHexString('0xf3bc3b7147acb9c621fd9f72dbf15ffa'), // sig_s.lo
43
+ Fr.fromHexString('0x08599f379f0301dfefdbd0272554454d'), // sig_s.hi
44
+ Fr.fromHexString('0x97065383ebbbd76620398792bd259bc2'), // sig_e.lo
45
+ Fr.fromHexString('0x2ceaee87f45b7a417f0ffb05451a8c92'), // sig_e.hi
46
+ Fr.fromHexString('0x0123456789abcdef0fedcba9876543210123456789abcdef0fedcba987654321'), // message
47
+ ];
36
48
  const args = [
37
49
  argsField,
38
50
  argsU8,
@@ -40,6 +52,8 @@ export async function bulkTest(
40
52
  /*expectedDeployer=*/ expectContractInstance.deployer,
41
53
  /*expectedClassId=*/ expectContractInstance.currentContractClassId,
42
54
  /*expectedInitializationHash=*/ expectContractInstance.initializationHash,
55
+ /*expectedImmutablesHash=*/ expectContractInstance.immutablesHash,
56
+ /*schnorrInputs=*/ schnorrInputs,
43
57
  /*skip_strictly_limited_side_effects=*/ false,
44
58
  ];
45
59
 
@@ -62,7 +76,7 @@ export async function bulkTest(
62
76
  {
63
77
  address: avmTestContract.address,
64
78
  fnName: 'assert_calldata_copy',
65
- args: [argsField.slice(3), /* with_selector: */ true],
79
+ args: [argsField.slice(0, 3), /* with_selector: */ true],
66
80
  },
67
81
  {
68
82
  address: avmTestContract.address,
@@ -118,11 +132,20 @@ export async function megaBulkTest(
118
132
  const argsField2 = [5, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
119
133
  const argsField3 = [7, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
120
134
  const argsField4 = [9, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
121
- const argsField5 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
135
+ //const argsField5 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
122
136
  //const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
123
137
  //const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
124
138
  //const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
125
139
  const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
140
+ const schnorrInputs = [
141
+ Fr.fromHexString('0x065812e335a97c2108ea8cf4ccfe2f9dd6b117a0714f5e18461575be93f61da6'), // pubkey.x
142
+ Fr.fromHexString('0x1a915003e8ec534f9a15d926a7ded478e178468ccc4f28e236e67450a55ac622'), // pubkey.y
143
+ Fr.fromHexString('0xf3bc3b7147acb9c621fd9f72dbf15ffa'), // sig_s.lo
144
+ Fr.fromHexString('0x08599f379f0301dfefdbd0272554454d'), // sig_s.hi
145
+ Fr.fromHexString('0x97065383ebbbd76620398792bd259bc2'), // sig_e.lo
146
+ Fr.fromHexString('0x2ceaee87f45b7a417f0ffb05451a8c92'), // sig_e.hi
147
+ Fr.fromHexString('0x0123456789abcdef0fedcba9876543210123456789abcdef0fedcba987654321'), // message
148
+ ];
126
149
  const genArgs = (argsField: Fr[]) => [
127
150
  argsField,
128
151
  argsU8,
@@ -130,6 +153,8 @@ export async function megaBulkTest(
130
153
  /*expectedDeployer=*/ expectContractInstance.deployer.toField(),
131
154
  /*expectedClassId=*/ expectContractInstance.currentContractClassId.toField(),
132
155
  /*expectedInitializationHash=*/ expectContractInstance.initializationHash.toField(),
156
+ /*expectedImmutablesHash=*/ expectContractInstance.immutablesHash.toField(),
157
+ /*schnorrInputs=*/ schnorrInputs,
133
158
  // Must skip strictly limited side effects (logs, messages) so we can spam the bulk test several times.
134
159
  /*skip_strictly_limited_side_effects=*/ true,
135
160
  ];
@@ -144,7 +169,7 @@ export async function megaBulkTest(
144
169
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField2) },
145
170
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField3) },
146
171
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField4) },
147
- { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField5) },
172
+ //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField5) },
148
173
  //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
149
174
  //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
150
175
  //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
@@ -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 { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
5
+ import { Add, CalldataCopy, Cast, 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,
@@ -23,8 +23,8 @@ 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';
@@ -44,11 +44,14 @@ 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';
@@ -69,14 +72,17 @@ export async function addressingWithIndirectThenRelativeTagIssueTest(tester: Pub
69
72
 
70
73
  const bytecode = encodeToBytecode([
71
74
  // Set a U32 value 10 at offset 1 - this will be used as an indirect address
72
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, /*value=*/ 10).as(Opcode.SET_32, Set.wireFormat32),
75
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, /*value=*/ 10).as(
76
+ Opcode.SET_32,
77
+ Set.wireFormat32,
78
+ ),
73
79
  // ADD_16: first operand uses indirect addressing (reads from offset 1, gets value 10, uses as address - succeeds)
74
80
  // second operand uses relative addressing (tries to read base from offset 0, but offset 0 has wrong tag - fails)
75
- new Add(/*indirect=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
81
+ new Add(/*addressing_mode=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
76
82
  Opcode.ADD_16,
77
83
  Add.wireFormat16,
78
84
  ),
79
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
85
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
80
86
  ]);
81
87
 
82
88
  const txLabel = 'AddressingWithIndirectThenRelativeTagInvalid';
@@ -100,15 +106,15 @@ export async function addressingWithRelativeOverflowAndIndirectTagIssueTest(test
100
106
 
101
107
  const bytecode = encodeToBytecode([
102
108
  // Set UINT32_MAX at offset 0 as base address - this will cause overflow when adding relative offset 1
103
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ UINT32_MAX).as(
109
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ UINT32_MAX).as(
104
110
  Opcode.SET_32,
105
111
  Set.wireFormat32,
106
112
  ),
107
- new Add(/*indirect=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
113
+ new Add(/*addressing_mode=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
108
114
  Opcode.ADD_8,
109
115
  Add.wireFormat8,
110
116
  ),
111
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
117
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
112
118
  ]);
113
119
 
114
120
  const txLabel = 'AddressingWithRelativeOverflowAndIndirectTagInvalid';
@@ -118,7 +124,7 @@ export async function addressingWithRelativeOverflowAndIndirectTagIssueTest(test
118
124
  export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
119
125
  const bytecode = encodeToBytecode([
120
126
  new Jump(/*jumpOffset=*/ 123), // Jump to out-of-range pc offset.
121
- new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
127
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
122
128
  ]);
123
129
 
124
130
  const txLabel = 'PcOutOfRange';
@@ -127,14 +133,14 @@ export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
127
133
 
128
134
  export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
129
135
  let bytecode = encodeToBytecode([
130
- 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),
131
137
  ]);
132
138
 
133
139
  const offsetReturnOpcodeByte = bytecode.length;
134
140
 
135
141
  bytecode = Buffer.concat([
136
142
  bytecode,
137
- encodeToBytecode([new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
143
+ encodeToBytecode([new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0)]),
138
144
  ]);
139
145
 
140
146
  // Manipulate the Return opcode to make the opcode invalid (out of range).
@@ -157,7 +163,7 @@ export async function invalidByteTest(tester: PublicTxSimulationTester) {
157
163
  // Truncate the last instruction in the bytecode.
158
164
  export async function instructionTruncatedTest(tester: PublicTxSimulationTester) {
159
165
  let bytecode = encodeToBytecode([
160
- 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),
161
167
  ]);
162
168
 
163
169
  // Truncate the bytecode.
@@ -170,8 +176,8 @@ export async function instructionTruncatedTest(tester: PublicTxSimulationTester)
170
176
  // Invalid tag value byte in an instruction.
171
177
  export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
172
178
  const bytecode = encodeToBytecode([
173
- new Set(/*indirect=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
174
- 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),
175
181
  ]);
176
182
 
177
183
  const tagOffset = getTagOffsetInInstruction(Set.wireFormat8);
@@ -186,7 +192,10 @@ export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
186
192
  export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicTxSimulationTester) {
187
193
  let bytecode = encodeToBytecode([
188
194
  // Important: value argument must be a bigint otherwise a type error will be thrown.
189
- 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
+ ),
190
199
  ]);
191
200
 
192
201
  // Truncate the bytecode.
@@ -199,6 +208,144 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
199
208
  return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
200
209
  }
201
210
 
211
+ // Exercise SET truncation: set values whose widths exceed the target tag and
212
+ // rely on `buildFromTagTruncating` to truncate to the low bits of the tag.
213
+ // Covers sources larger than 128 bits (via SET_FF) and sources in (32, 128]
214
+ // bits (via SET_64) against destination tags U1/U8/U16/U32/U64/U128.
215
+ export async function setTruncationTest(tester: PublicTxSimulationTester) {
216
+ // 200-bit value: forces truncation for every target tag up to U128.
217
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
218
+ // 40-bit value: forces truncation for target tags up to U32.
219
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
220
+
221
+ const bytecode = encodeToBytecode([
222
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
223
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
224
+
225
+ // Source >128 bits (via SET_FF) truncated to smaller target tags.
226
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT128, LARGE_FIELD_VALUE).as(
227
+ Opcode.SET_FF,
228
+ Set.wireFormatFF,
229
+ ),
230
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT64, LARGE_FIELD_VALUE).as(
231
+ Opcode.SET_FF,
232
+ Set.wireFormatFF,
233
+ ),
234
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 3, TypeTag.UINT32, LARGE_FIELD_VALUE).as(
235
+ Opcode.SET_FF,
236
+ Set.wireFormatFF,
237
+ ),
238
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 4, TypeTag.UINT16, LARGE_FIELD_VALUE).as(
239
+ Opcode.SET_FF,
240
+ Set.wireFormatFF,
241
+ ),
242
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 5, TypeTag.UINT8, LARGE_FIELD_VALUE).as(
243
+ Opcode.SET_FF,
244
+ Set.wireFormatFF,
245
+ ),
246
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 6, TypeTag.UINT1, LARGE_FIELD_VALUE).as(
247
+ Opcode.SET_FF,
248
+ Set.wireFormatFF,
249
+ ),
250
+
251
+ // Source in (32, 128] bits (via SET_64) truncated to smaller target tags.
252
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 7, TypeTag.UINT32, LARGE_U64_VALUE).as(
253
+ Opcode.SET_64,
254
+ Set.wireFormat64,
255
+ ),
256
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 8, TypeTag.UINT16, LARGE_U64_VALUE).as(
257
+ Opcode.SET_64,
258
+ Set.wireFormat64,
259
+ ),
260
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 9, TypeTag.UINT8, LARGE_U64_VALUE).as(
261
+ Opcode.SET_64,
262
+ Set.wireFormat64,
263
+ ),
264
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.UINT1, LARGE_U64_VALUE).as(
265
+ Opcode.SET_64,
266
+ Set.wireFormat64,
267
+ ),
268
+
269
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
270
+ ]);
271
+
272
+ const txLabel = 'SetTruncation';
273
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
274
+ }
275
+
276
+ // Exercise CAST truncation: store a wide source value in memory then CAST it
277
+ // to smaller destination tags. Covers sources larger than 128 bits (FIELD
278
+ // source) and sources in (32, 128] bits (UINT64 source) against destination
279
+ // tags U1/U8/U16/U32/U64/U128.
280
+ export async function castTruncationTest(tester: PublicTxSimulationTester) {
281
+ // 200-bit source: stored as FIELD so that CASTs to any integer tag truncate.
282
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
283
+ // 40-bit source: stored as UINT64 so CASTs to U1/U8/U16/U32 truncate.
284
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
285
+
286
+ const bytecode = encodeToBytecode([
287
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
288
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
289
+
290
+ // Store wide FIELD source at offset 10, then CAST to smaller tags.
291
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.FIELD, LARGE_FIELD_VALUE).as(
292
+ Opcode.SET_FF,
293
+ Set.wireFormatFF,
294
+ ),
295
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 11, TypeTag.UINT128).as(
296
+ Opcode.CAST_8,
297
+ Cast.wireFormat8,
298
+ ),
299
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 12, TypeTag.UINT64).as(
300
+ Opcode.CAST_8,
301
+ Cast.wireFormat8,
302
+ ),
303
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 13, TypeTag.UINT32).as(
304
+ Opcode.CAST_8,
305
+ Cast.wireFormat8,
306
+ ),
307
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 14, TypeTag.UINT16).as(
308
+ Opcode.CAST_8,
309
+ Cast.wireFormat8,
310
+ ),
311
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 15, TypeTag.UINT8).as(
312
+ Opcode.CAST_8,
313
+ Cast.wireFormat8,
314
+ ),
315
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 16, TypeTag.UINT1).as(
316
+ Opcode.CAST_8,
317
+ Cast.wireFormat8,
318
+ ),
319
+
320
+ // Store UINT64 source at offset 20, then CAST to smaller integer tags.
321
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 20, TypeTag.UINT64, LARGE_U64_VALUE).as(
322
+ Opcode.SET_64,
323
+ Set.wireFormat64,
324
+ ),
325
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 21, TypeTag.UINT32).as(
326
+ Opcode.CAST_8,
327
+ Cast.wireFormat8,
328
+ ),
329
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 22, TypeTag.UINT16).as(
330
+ Opcode.CAST_8,
331
+ Cast.wireFormat8,
332
+ ),
333
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 23, TypeTag.UINT8).as(
334
+ Opcode.CAST_8,
335
+ Cast.wireFormat8,
336
+ ),
337
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 24, TypeTag.UINT1).as(
338
+ Opcode.CAST_8,
339
+ Cast.wireFormat8,
340
+ ),
341
+
342
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
343
+ ]);
344
+
345
+ const txLabel = 'CastTruncation';
346
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
347
+ }
348
+
202
349
  /**
203
350
  * Returns the offset of the tag in an instruction.
204
351
  * @details Loops over the wire format operand type entries until it finds the tag.
@@ -12,8 +12,8 @@ export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester
12
12
  const minimalBytecode = encodeToBytecode([
13
13
  new Set(/*indirect*/ 0, /*dstOffset*/ 0, TypeTag.UINT32, /*value*/ 1).as(Opcode.SET_8, Set.wireFormat8),
14
14
  new Set(/*indirect*/ 0, /*dstOffset*/ 1, TypeTag.UINT32, /*value*/ 2).as(Opcode.SET_8, Set.wireFormat8),
15
- new Add(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
16
- 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),
17
17
  ]);
18
18
 
19
19
  const result = await deployAndExecuteCustomBytecode(minimalBytecode, tester, 'MinimalTx', 'AvmMinimalContract');