@aztec/simulator 3.0.0-nightly.20251216 → 3.0.0-nightly.20251218

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 (35) hide show
  1. package/dest/public/debug_fn_name.d.ts +1 -1
  2. package/dest/public/debug_fn_name.d.ts.map +1 -1
  3. package/dest/public/debug_fn_name.js +10 -3
  4. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  5. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  6. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  7. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  8. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  9. package/dest/public/fixtures/custom_bytecode_tests.js +54 -10
  10. package/dest/public/fixtures/index.d.ts +3 -1
  11. package/dest/public/fixtures/index.d.ts.map +1 -1
  12. package/dest/public/fixtures/index.js +2 -0
  13. package/dest/public/fixtures/minimal_public_tx.js +2 -2
  14. package/dest/public/fixtures/opcode_spammer.d.ts +86 -0
  15. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  16. package/dest/public/fixtures/opcode_spammer.js +1539 -0
  17. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +2 -2
  18. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  19. package/dest/public/fixtures/public_tx_simulation_tester.js +19 -7
  20. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
  21. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  22. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +15 -11
  23. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +1 -1
  24. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  25. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +2 -1
  26. package/package.json +16 -16
  27. package/src/public/debug_fn_name.ts +10 -3
  28. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  29. package/src/public/fixtures/custom_bytecode_tests.ts +70 -10
  30. package/src/public/fixtures/index.ts +6 -0
  31. package/src/public/fixtures/minimal_public_tx.ts +2 -2
  32. package/src/public/fixtures/opcode_spammer.ts +1516 -0
  33. package/src/public/fixtures/public_tx_simulation_tester.ts +19 -5
  34. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +16 -11
  35. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +2 -1
@@ -31,7 +31,7 @@ const DEFAULT_GAS_FEES = new GasFees(2, 3);
31
31
  export type TestEnqueuedCall = {
32
32
  sender?: AztecAddress;
33
33
  address: AztecAddress;
34
- fnName: string;
34
+ fnName?: string;
35
35
  args: any[];
36
36
  isStaticCall?: boolean;
37
37
  contractArtifact?: ContractArtifact;
@@ -235,10 +235,24 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
235
235
  throw new Error(`Contract artifact not found for address: ${address}`);
236
236
  }
237
237
 
238
- const fnSelector = await getFunctionSelector(call.fnName, contractArtifact);
239
- const fnAbi = getContractFunctionAbi(call.fnName, contractArtifact)!;
240
- const encodedArgs = encodeArguments(fnAbi, call.args);
241
- const calldata = [fnSelector.toField(), ...encodedArgs];
238
+ let calldata: Fr[] = [];
239
+ if (!call.fnName) {
240
+ this.logger.debug(
241
+ `No function name specified for call to contract ${call.address.toString()}. Assuming this is a custom bytecode with no public_dispatch function.`,
242
+ );
243
+ this.logger.debug(`Not using ABI to encode arguments. Not prepending fn selector to calldata.`);
244
+ try {
245
+ calldata = call.args.map(arg => new Fr(arg));
246
+ } catch (error) {
247
+ this.logger.warn(`Tried assuming that all arguments are Field-like. Failed. Error: ${error}`);
248
+ throw error;
249
+ }
250
+ } else {
251
+ const fnSelector = await getFunctionSelector(call.fnName, contractArtifact);
252
+ const fnAbi = getContractFunctionAbi(call.fnName, contractArtifact)!;
253
+ const encodedArgs = encodeArguments(fnAbi, call.args);
254
+ calldata = [fnSelector.toField(), ...encodedArgs];
255
+ }
242
256
  const isStaticCall = call.isStaticCall ?? false;
243
257
  const request = await PublicCallRequest.fromCalldata(sender, address, isStaticCall, calldata);
244
258
 
@@ -18,7 +18,7 @@ export class ContractProviderForCpp implements ContractProvider {
18
18
  ) {}
19
19
 
20
20
  public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
21
- this.log.debug(`Contract provider callback: getContractInstance(${address})`);
21
+ this.log.trace(`Contract provider callback: getContractInstance(${address})`);
22
22
 
23
23
  const aztecAddr = AztecAddress.fromString(address);
24
24
 
@@ -33,7 +33,7 @@ export class ContractProviderForCpp implements ContractProvider {
33
33
  };
34
34
 
35
35
  public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
36
- this.log.debug(`Contract provider callback: getContractClass(${classId})`);
36
+ this.log.trace(`Contract provider callback: getContractClass(${classId})`);
37
37
 
38
38
  // Parse classId string to Fr
39
39
  const classIdFr = Fr.fromString(classId);
@@ -50,7 +50,7 @@ export class ContractProviderForCpp implements ContractProvider {
50
50
  };
51
51
 
52
52
  public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
53
- this.log.debug(`Contract provider callback: addContracts`);
53
+ this.log.trace(`Contract provider callback: addContracts`);
54
54
 
55
55
  const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
56
56
 
@@ -58,12 +58,12 @@ export class ContractProviderForCpp implements ContractProvider {
58
58
  const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
59
59
 
60
60
  // Add contracts to the contracts DB
61
- this.log.debug(`Calling contractsDB.addContracts`);
61
+ this.log.trace(`Calling contractsDB.addContracts`);
62
62
  await this.contractsDB.addContracts(contractDeploymentData);
63
63
  };
64
64
 
65
65
  public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
66
- this.log.debug(`Contract provider callback: getBytecodeCommitment(${classId})`);
66
+ this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
67
67
 
68
68
  // Parse classId string to Fr
69
69
  const classIdFr = Fr.fromString(classId);
@@ -81,18 +81,23 @@ export class ContractProviderForCpp implements ContractProvider {
81
81
  };
82
82
 
83
83
  public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
84
- this.log.debug(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
84
+ this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
85
85
 
86
86
  // Parse address and selector strings
87
87
  const aztecAddr = AztecAddress.fromString(address);
88
88
  const selectorFr = Fr.fromString(selector);
89
- const functionSelector = FunctionSelector.fromField(selectorFr);
89
+ const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
90
+
91
+ if (!functionSelector) {
92
+ this.log.trace(`calldata[0] is not a function selector: ${selector}`);
93
+ return undefined;
94
+ }
90
95
 
91
96
  // Fetch debug function name from the contracts DB
92
97
  const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
93
98
 
94
99
  if (!name) {
95
- this.log.debug(`Debug function name not found for ${address}:${selector}`);
100
+ this.log.trace(`Debug function name not found for ${address}:${selector}`);
96
101
  return undefined;
97
102
  }
98
103
 
@@ -100,17 +105,17 @@ export class ContractProviderForCpp implements ContractProvider {
100
105
  };
101
106
 
102
107
  public createCheckpoint = (): Promise<void> => {
103
- this.log.debug(`Contract provider callback: createCheckpoint`);
108
+ this.log.trace(`Contract provider callback: createCheckpoint`);
104
109
  return Promise.resolve(this.contractsDB.createCheckpoint());
105
110
  };
106
111
 
107
112
  public commitCheckpoint = (): Promise<void> => {
108
- this.log.debug(`Contract provider callback: commitCheckpoint`);
113
+ this.log.trace(`Contract provider callback: commitCheckpoint`);
109
114
  return Promise.resolve(this.contractsDB.commitCheckpoint());
110
115
  };
111
116
 
112
117
  public revertCheckpoint = (): Promise<void> => {
113
- this.log.debug(`Contract provider callback: revertCheckpoint`);
118
+ this.log.trace(`Contract provider callback: revertCheckpoint`);
114
119
  return Promise.resolve(this.contractsDB.revertCheckpoint());
115
120
  };
116
121
  }
@@ -205,7 +205,8 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
205
205
  cppGasUsed: cppResult.gasUsed.totalGas.l2Gas,
206
206
  });
207
207
 
208
- return tsResult;
208
+ // Return cpp result as it has more detailed metadata / revert reasons
209
+ return cppResult;
209
210
  }
210
211
  }
211
212