@aztec/simulator 3.0.0-rc.5 → 4.0.0-nightly.20260107

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 (83) hide show
  1. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  2. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  3. package/dest/private/circuit_recording/circuit_recorder.js +15 -14
  4. package/dest/public/avm/opcodes/accrued_substate.js +1 -1
  5. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  6. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  7. package/dest/public/avm/opcodes/external_calls.js +1 -0
  8. package/dest/public/avm/opcodes/hashing.d.ts +1 -1
  9. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  10. package/dest/public/avm/opcodes/hashing.js +6 -3
  11. package/dest/public/debug_fn_name.d.ts +1 -1
  12. package/dest/public/debug_fn_name.d.ts.map +1 -1
  13. package/dest/public/debug_fn_name.js +10 -3
  14. package/dest/public/fixtures/bulk_test.js +3 -51
  15. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  16. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  17. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  18. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  19. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  20. package/dest/public/fixtures/custom_bytecode_tests.js +54 -10
  21. package/dest/public/fixtures/index.d.ts +4 -2
  22. package/dest/public/fixtures/index.d.ts.map +1 -1
  23. package/dest/public/fixtures/index.js +3 -1
  24. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
  25. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  26. package/dest/public/fixtures/minimal_public_tx.js +2 -12
  27. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  28. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  29. package/dest/public/fixtures/opcode_spammer.js +1681 -0
  30. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +15 -2
  31. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  32. package/dest/public/fixtures/public_tx_simulation_tester.js +34 -7
  33. package/dest/public/fixtures/utils.d.ts +1 -1
  34. package/dest/public/fixtures/utils.d.ts.map +1 -1
  35. package/dest/public/fixtures/utils.js +3 -2
  36. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +1 -1
  37. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  38. package/dest/public/fuzzing/avm_fuzzer_simulator.js +4 -1
  39. package/dest/public/fuzzing/avm_simulator_bin.js +18 -2
  40. package/dest/public/hinting_db_sources.d.ts +2 -1
  41. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  42. package/dest/public/hinting_db_sources.js +5 -0
  43. package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -1
  44. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  45. package/dest/public/public_processor/guarded_merkle_tree.js +5 -0
  46. package/dest/public/public_processor/public_processor.d.ts +2 -2
  47. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  48. package/dest/public/public_processor/public_processor.js +417 -28
  49. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
  50. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  51. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +15 -11
  52. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +16 -1
  53. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  54. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +41 -3
  55. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +1 -1
  56. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  57. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +3 -2
  58. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  59. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  60. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  61. package/package.json +16 -16
  62. package/src/private/circuit_recording/circuit_recorder.ts +16 -15
  63. package/src/public/avm/opcodes/accrued_substate.ts +1 -1
  64. package/src/public/avm/opcodes/external_calls.ts +1 -0
  65. package/src/public/avm/opcodes/hashing.ts +7 -3
  66. package/src/public/debug_fn_name.ts +10 -3
  67. package/src/public/fixtures/bulk_test.ts +6 -6
  68. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  69. package/src/public/fixtures/custom_bytecode_tests.ts +70 -10
  70. package/src/public/fixtures/index.ts +7 -1
  71. package/src/public/fixtures/minimal_public_tx.ts +3 -12
  72. package/src/public/fixtures/opcode_spammer.ts +1638 -0
  73. package/src/public/fixtures/public_tx_simulation_tester.ts +38 -5
  74. package/src/public/fixtures/utils.ts +1 -2
  75. package/src/public/fuzzing/avm_fuzzer_simulator.ts +8 -1
  76. package/src/public/fuzzing/avm_simulator_bin.ts +21 -2
  77. package/src/public/hinting_db_sources.ts +4 -0
  78. package/src/public/public_processor/guarded_merkle_tree.ts +4 -0
  79. package/src/public/public_processor/public_processor.ts +20 -9
  80. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +16 -11
  81. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +48 -3
  82. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +3 -2
  83. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
@@ -108,16 +108,16 @@ export class CircuitRecorder {
108
108
  * contracts as protocol circuits artifacts always contain a single entrypoint function called 'main'.
109
109
  */
110
110
  start(input: ACVMWitness, circuitBytecode: Buffer, circuitName: string, functionName: string): Promise<void> {
111
- const parentRef = this.recording;
112
111
  if (this.newCircuit) {
112
+ const parentRef = this.recording;
113
113
  this.recording = new CircuitRecording(
114
114
  circuitName,
115
115
  functionName,
116
116
  sha512(circuitBytecode).toString('hex'),
117
117
  Object.fromEntries(input),
118
118
  );
119
+ this.recording.setParent(parentRef);
119
120
  }
120
- this.recording!.setParent(parentRef);
121
121
 
122
122
  return Promise.resolve();
123
123
  }
@@ -173,22 +173,22 @@ export class CircuitRecorder {
173
173
  if (result instanceof Promise) {
174
174
  return result.then(async r => {
175
175
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
176
- // since we are going back to the "parent" circuit which can never be new
176
+ // so that the parent circuit continues with its existing recording
177
+ // Note: recording restoration is handled by finish()
177
178
  if (isExternalCall) {
178
179
  this.stackDepth--;
179
180
  this.newCircuit = false;
180
- this.recording = this.recording!.parent;
181
181
  }
182
182
  await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
183
183
  return r;
184
184
  }) as ReturnType<typeof fn>;
185
185
  }
186
186
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
187
- // since we are going back to the "parent" circuit which can never be new
187
+ // so that the parent circuit continues with its existing recording
188
+ // Note: recording restoration is handled by finish()
188
189
  if (isExternalCall) {
189
190
  this.stackDepth--;
190
191
  this.newCircuit = false;
191
- this.recording = this.recording!.parent;
192
192
  }
193
193
  void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
194
194
  return result;
@@ -239,6 +239,12 @@ export class CircuitRecorder {
239
239
  if (!result!.parent) {
240
240
  this.newCircuit = true;
241
241
  this.recording = undefined;
242
+ } else {
243
+ // For nested circuits (utility calls, nested contract calls), restore to parent recording
244
+ // Note: we don't set newCircuit=false here because:
245
+ // - For privateCallPrivateFunction, the callback wrapper will set it to false
246
+ // - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
247
+ this.recording = result!.parent;
242
248
  }
243
249
  return Promise.resolve(result!);
244
250
  }
@@ -247,14 +253,9 @@ export class CircuitRecorder {
247
253
  * Finalizes the recording by resetting the state and returning the recording object with an attached error.
248
254
  * @param error - The error that occurred during circuit execution
249
255
  */
250
- finishWithError(error: unknown): Promise<CircuitRecording> {
251
- const result = this.recording;
252
- // If this is the top-level circuit recording, we reset the state for the next simulator call
253
- if (!result!.parent) {
254
- this.newCircuit = true;
255
- this.recording = undefined;
256
- }
257
- result!.error = JSON.stringify(error);
258
- return Promise.resolve(result!);
256
+ async finishWithError(error: unknown): Promise<CircuitRecording> {
257
+ const result = await this.finish();
258
+ result.error = JSON.stringify(error);
259
+ return result;
259
260
  }
260
261
  }
@@ -241,11 +241,11 @@ export class EmitUnencryptedLog extends Instruction {
241
241
  const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
242
242
  memory.checkTag(TypeTag.UINT32, logSizeOffset);
243
243
  const logSize = memory.get(logSizeOffset).toNumber();
244
- memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
245
244
 
246
245
  const contractAddress = context.environment.address;
247
246
 
248
247
  context.machineState.consumeGas(this.dynamicGasCost(logSize));
248
+ memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
249
249
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
250
250
  context.persistableState.writePublicLog(contractAddress, log);
251
251
  }
@@ -45,6 +45,7 @@ abstract class ExternalCall extends Instruction {
45
45
  memory.checkTag(TypeTag.UINT32, argsSizeOffset);
46
46
 
47
47
  const calldataSize = memory.get(argsSizeOffset).toNumber();
48
+ // This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
48
49
  const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
50
 
50
51
  const callAddress = memory.getAs<Field>(addrOffset);
@@ -132,13 +132,17 @@ export class Sha256Compression extends Instruction {
132
132
  const [outputOffset, stateOffset, inputsOffset] = addressing.resolve(operands, memory);
133
133
 
134
134
  // Note: size of output is same as size of state
135
- const inputs = Uint32Array.from(memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toNumber()));
136
- const state = Uint32Array.from(memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toNumber()));
135
+ const inputs = memory.getSlice(inputsOffset, INPUTS_SIZE).map(word => word.toBigInt());
136
+ const state = memory.getSlice(stateOffset, STATE_SIZE).map(word => word.toBigInt());
137
137
 
138
138
  memory.checkTagsRange(TypeTag.UINT32, inputsOffset, INPUTS_SIZE);
139
139
  memory.checkTagsRange(TypeTag.UINT32, stateOffset, STATE_SIZE);
140
140
 
141
- const output = sha256Compression(state, inputs);
141
+ // At this point both state and inputs are Uint32Array-compatible
142
+ const inputsArray = new Uint32Array(inputs.map(i => Number(i)));
143
+ const stateArray = new Uint32Array(state.map(i => Number(i)));
144
+
145
+ const output = sha256Compression(stateArray, inputsArray);
142
146
 
143
147
  // Conversion required from Uint32Array to Uint32[] (can't map directly, need `...`)
144
148
  const res = [...output].map(word => new Uint32(word));
@@ -13,8 +13,12 @@ export async function getPublicFunctionDebugName(
13
13
  if (!calldata[0]) {
14
14
  return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
15
  }
16
- const selector = FunctionSelector.fromField(calldata[0]);
17
- return (await db.getDebugFunctionName(contractAddress, selector)) ?? selector.toString();
16
+ const fallbackName = `<calldata[0]:${calldata[0].toString()}> (Contract Address: ${contractAddress})`;
17
+ const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
18
+ if (!selector) {
19
+ return fallbackName;
20
+ }
21
+ return (await db.getDebugFunctionName(contractAddress, selector)) ?? fallbackName;
18
22
  }
19
23
 
20
24
  /**
@@ -34,7 +38,10 @@ export async function getPublicFunctionSelectorAndName(
34
38
  if (!calldata[0]) {
35
39
  return {};
36
40
  }
37
- const selector = FunctionSelector.fromField(calldata[0]);
41
+ const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
42
+ if (!selector) {
43
+ return {};
44
+ }
38
45
  const debugName = await db.getDebugFunctionName(contractAddress, selector);
39
46
  return {
40
47
  functionSelector: selector,
@@ -119,9 +119,9 @@ export async function megaBulkTest(
119
119
  const argsField3 = [7, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
120
120
  const argsField4 = [9, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
121
121
  const argsField5 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
122
- const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
123
- const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
124
- const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
122
+ //const argsField6 = [13, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
123
+ //const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
124
+ //const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
125
125
  const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
126
126
  const genArgs = (argsField: Fr[]) => [
127
127
  argsField,
@@ -145,9 +145,9 @@ export async function megaBulkTest(
145
145
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField3) },
146
146
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField4) },
147
147
  { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField5) },
148
- { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
149
- { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
150
- { address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
148
+ //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField6) },
149
+ //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField7) },
150
+ //{ address: avmTestContract.address, fnName: 'bulk_testing', args: genArgs(argsField8) },
151
151
  ],
152
152
  /*teardownCall=*/ undefined,
153
153
  /*feePayer*/ undefined,
@@ -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
@@ -28,7 +28,7 @@ export async function addressingWithBaseTagIssueTest(isIndirect: boolean, tester
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
@@ -52,7 +52,67 @@ export async function addressingWithIndirectTagIssueTest(tester: PublicTxSimulat
52
52
  ]);
53
53
 
54
54
  const txLabel = 'AddressingWithIndirectTagInvalid';
55
- return await testCustomBytecode(bytecode, tester, txLabel);
55
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
56
+ }
57
+
58
+ // First instruction sets a value 10 with tag U32 at offset 1 (direct, no relative).
59
+ // Then an ADD_16 instruction uses INDIRECT addressing for the first operand (offset 1)
60
+ // and RELATIVE addressing for the second operand (offset 2). The indirect addressing
61
+ // succeeds (reads U32 value 10 from offset 1, uses it as address), but the relative
62
+ // addressing fails because the base address at offset 0 has the wrong tag (uninitialized/invalid).
63
+ export async function addressingWithIndirectThenRelativeTagIssueTest(tester: PublicTxSimulationTester) {
64
+ const addressingMode = Addressing.fromModes([
65
+ AddressingMode.INDIRECT, // First operand (aOffset) uses indirect addressing, no relative
66
+ AddressingMode.RELATIVE, // Second operand (bOffset) uses relative addressing
67
+ AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
68
+ ]);
69
+
70
+ const bytecode = encodeToBytecode([
71
+ // 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),
73
+ // ADD_16: first operand uses indirect addressing (reads from offset 1, gets value 10, uses as address - succeeds)
74
+ // 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(
76
+ Opcode.ADD_16,
77
+ Add.wireFormat16,
78
+ ),
79
+ new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
80
+ ]);
81
+
82
+ const txLabel = 'AddressingWithIndirectThenRelativeTagInvalid';
83
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
84
+ }
85
+
86
+ // First instruction sets UINT32_MAX at offset 0 (base address) with tag U32.
87
+ // Then an ADD_8 instruction uses INDIRECT_RELATIVE addressing for the first operand (offset 1)
88
+ // and INDIRECT addressing for the second operand (offset 2). The relative addressing
89
+ // for the first operand will overflow (UINT32_MAX + 1 >= MAX_MEMORY_SIZE), causing the instruction to fail.
90
+ // The second operand will also fail (indirect addressing from offset 2 which is uninitialized with tag FF).
91
+ export async function addressingWithRelativeOverflowAndIndirectTagIssueTest(tester: PublicTxSimulationTester) {
92
+ const addressingMode = Addressing.fromModes([
93
+ AddressingMode.INDIRECT_RELATIVE, // First operand (aOffset) uses both indirect and relative addressing
94
+ AddressingMode.INDIRECT, // Second operand (bOffset) uses indirect addressing only
95
+ AddressingMode.DIRECT, // Third operand (dstOffset) uses direct addressing
96
+ ]);
97
+
98
+ // UINT32_MAX = 2^32 - 1 = 4294967295
99
+ const UINT32_MAX = 0xffffffff;
100
+
101
+ const bytecode = encodeToBytecode([
102
+ // 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(
104
+ Opcode.SET_32,
105
+ Set.wireFormat32,
106
+ ),
107
+ new Add(/*indirect=*/ addressingMode.toWire(), /*aOffset=*/ 1, /*bOffset=*/ 2, /*dstOffset=*/ 3).as(
108
+ Opcode.ADD_8,
109
+ Add.wireFormat8,
110
+ ),
111
+ new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
112
+ ]);
113
+
114
+ const txLabel = 'AddressingWithRelativeOverflowAndIndirectTagInvalid';
115
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
56
116
  }
57
117
 
58
118
  export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
@@ -62,7 +122,7 @@ export async function pcOutOfRangeTest(tester: PublicTxSimulationTester) {
62
122
  ]);
63
123
 
64
124
  const txLabel = 'PcOutOfRange';
65
- return await testCustomBytecode(bytecode, tester, txLabel);
125
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
66
126
  }
67
127
 
68
128
  export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
@@ -81,7 +141,7 @@ export async function invalidOpcodeTest(tester: PublicTxSimulationTester) {
81
141
  bytecode[offsetReturnOpcodeByte] = MAX_OPCODE_VALUE + 1; // opcode is invalid.
82
142
 
83
143
  const txLabel = 'InvalidOpcode';
84
- return await testCustomBytecode(bytecode, tester, txLabel);
144
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
85
145
  }
86
146
 
87
147
  // Single invalid byte in the bytecode.
@@ -91,7 +151,7 @@ export async function invalidByteTest(tester: PublicTxSimulationTester) {
91
151
  const bytecode = Buffer.from([invalidOpcode]);
92
152
 
93
153
  const txLabel = 'InvalidByte';
94
- return await testCustomBytecode(bytecode, tester, txLabel);
154
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
95
155
  }
96
156
 
97
157
  // Truncate the last instruction in the bytecode.
@@ -104,7 +164,7 @@ export async function instructionTruncatedTest(tester: PublicTxSimulationTester)
104
164
  bytecode = bytecode.subarray(0, -1);
105
165
 
106
166
  const txLabel = 'InstructionTruncated';
107
- return await testCustomBytecode(bytecode, tester, txLabel);
167
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
108
168
  }
109
169
 
110
170
  // Invalid tag value byte in an instruction.
@@ -119,7 +179,7 @@ export async function invalidTagValueTest(tester: PublicTxSimulationTester) {
119
179
  bytecode[tagOffset] = TypeTag.INVALID;
120
180
 
121
181
  const txLabel = 'InvalidTagValue';
122
- return await testCustomBytecode(bytecode, tester, txLabel);
182
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
123
183
  }
124
184
 
125
185
  // Combine an invalid tag in the last instruction that is truncated.
@@ -136,7 +196,7 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
136
196
  bytecode[tagOffset] = 0x6f; // Invalid tag value.
137
197
 
138
198
  const txLabel = 'InvalidTagValueAndInstructionTruncated';
139
- return await testCustomBytecode(bytecode, tester, txLabel);
199
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
140
200
  }
141
201
 
142
202
  /**
@@ -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,12 +1,11 @@
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> {
@@ -17,7 +16,7 @@ export async function executeAvmMinimalPublicTx(tester: PublicTxSimulationTester
17
16
  new Return(/*indirect=*/ 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
- }