@aztec/simulator 0.82.2 → 0.82.3-nightly.20250330

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 (113) hide show
  1. package/README.md +6 -0
  2. package/dest/private/acvm/oracle/oracle.d.ts +2 -1
  3. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/private/acvm/oracle/oracle.js +7 -4
  5. package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -2
  6. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/private/acvm/oracle/typed_oracle.js +3 -0
  8. package/dest/private/execution_data_provider.d.ts +12 -2
  9. package/dest/private/execution_data_provider.d.ts.map +1 -1
  10. package/dest/private/unconstrained_execution_oracle.d.ts +3 -1
  11. package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
  12. package/dest/private/unconstrained_execution_oracle.js +3 -0
  13. package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
  14. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  15. package/dest/public/avm/avm_contract_call_result.js +9 -5
  16. package/dest/public/avm/avm_machine_state.d.ts +2 -0
  17. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  18. package/dest/public/avm/avm_machine_state.js +2 -0
  19. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  20. package/dest/public/avm/avm_simulator.js +5 -6
  21. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  22. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -2
  23. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
  24. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  25. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
  26. package/dest/public/avm/fixtures/index.d.ts +1 -0
  27. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  28. package/dest/public/avm/fixtures/index.js +1 -1
  29. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
  30. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
  31. package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
  32. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  33. package/dest/public/avm/opcodes/external_calls.js +2 -0
  34. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  35. package/dest/public/avm/opcodes/memory.js +8 -10
  36. package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
  37. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  38. package/dest/public/avm/serialization/instruction_serialization.js +25 -7
  39. package/dest/public/executor_metrics.d.ts +11 -3
  40. package/dest/public/executor_metrics.d.ts.map +1 -1
  41. package/dest/public/executor_metrics.js +40 -6
  42. package/dest/public/executor_metrics_interface.d.ts +10 -0
  43. package/dest/public/executor_metrics_interface.d.ts.map +1 -0
  44. package/dest/public/executor_metrics_interface.js +1 -0
  45. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
  46. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  47. package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
  48. package/dest/public/hinting_db_sources.d.ts +26 -3
  49. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  50. package/dest/public/hinting_db_sources.js +102 -1
  51. package/dest/public/index.d.ts +1 -1
  52. package/dest/public/index.d.ts.map +1 -1
  53. package/dest/public/index.js +1 -1
  54. package/dest/public/public_db_sources.d.ts +2 -3
  55. package/dest/public/public_db_sources.d.ts.map +1 -1
  56. package/dest/public/public_db_sources.js +26 -16
  57. package/dest/public/public_processor/public_processor.d.ts +4 -4
  58. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  59. package/dest/public/public_processor/public_processor.js +7 -28
  60. package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
  61. package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
  62. package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
  63. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
  64. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
  65. package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
  66. package/dest/public/public_tx_simulator/index.d.ts +3 -0
  67. package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
  68. package/dest/public/public_tx_simulator/index.js +2 -0
  69. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
  70. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
  71. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
  72. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  73. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  74. package/dest/public/public_tx_simulator/public_tx_context.js +9 -7
  75. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
  76. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  77. package/dest/public/public_tx_simulator/public_tx_simulator.js +24 -64
  78. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
  79. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
  80. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
  81. package/dest/public/test_executor_metrics.d.ts +43 -0
  82. package/dest/public/test_executor_metrics.d.ts.map +1 -0
  83. package/dest/public/test_executor_metrics.js +158 -0
  84. package/package.json +14 -14
  85. package/src/private/acvm/oracle/oracle.ts +24 -3
  86. package/src/private/acvm/oracle/typed_oracle.ts +13 -2
  87. package/src/private/execution_data_provider.ts +25 -2
  88. package/src/private/unconstrained_execution_oracle.ts +20 -1
  89. package/src/public/avm/avm_contract_call_result.ts +15 -3
  90. package/src/public/avm/avm_machine_state.ts +5 -0
  91. package/src/public/avm/avm_simulator.ts +18 -7
  92. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  93. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
  94. package/src/public/avm/fixtures/index.ts +1 -1
  95. package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
  96. package/src/public/avm/opcodes/external_calls.ts +3 -0
  97. package/src/public/avm/opcodes/memory.ts +8 -10
  98. package/src/public/avm/serialization/instruction_serialization.ts +24 -9
  99. package/src/public/executor_metrics.ts +54 -6
  100. package/src/public/executor_metrics_interface.ts +15 -0
  101. package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
  102. package/src/public/hinting_db_sources.ts +184 -3
  103. package/src/public/index.ts +1 -1
  104. package/src/public/public_db_sources.ts +36 -23
  105. package/src/public/public_processor/public_processor.ts +8 -28
  106. package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
  107. package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
  108. package/src/public/public_tx_simulator/index.ts +2 -0
  109. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
  110. package/src/public/public_tx_simulator/public_tx_context.ts +9 -13
  111. package/src/public/public_tx_simulator/public_tx_simulator.ts +31 -76
  112. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
  113. package/src/public/test_executor_metrics.ts +222 -0
@@ -1,5 +1,5 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import { PUBLIC_DISPATCH_FN_NAME } from './index.js';
2
+ import { getFunctionSelector } from './index.js';
3
3
  /**
4
4
  * This class is used during public/avm testing to function as a database of
5
5
  * contract contract classes and instances. Tests can populate it with classes
@@ -14,18 +14,31 @@ import { PUBLIC_DISPATCH_FN_NAME } from './index.js';
14
14
  contractInstances = new Map();
15
15
  // maps contract instance address to address
16
16
  contractArtifacts = new Map();
17
+ // maps `${classID}:${fnSelector}` to name
18
+ debugFunctionName = new Map();
17
19
  /////////////////////////////////////////////////////////////
18
20
  // Helper functions not in the contract data source interface
19
21
  /**
20
22
  * Derive the contract class and instance with some seed.
21
23
  * Add both to the contract data source along with the contract artifact.
22
24
  */ async addNewContract(contractArtifact, contractClass, contractInstance) {
23
- this.addContractArtifact(contractClass.id, contractArtifact);
25
+ await this.addContractArtifact(contractClass.id, contractArtifact);
24
26
  await this.addContractClass(contractClass);
25
27
  await this.addContractInstance(contractInstance);
26
28
  }
27
- addContractArtifact(classId, artifact) {
29
+ async addContractArtifact(classId, artifact) {
28
30
  this.contractArtifacts.set(classId.toString(), artifact);
31
+ const classIdStr = classId.toString();
32
+ const publicFns = artifact.nonDispatchPublicFunctions;
33
+ if (publicFns.length !== 0) {
34
+ for (const fn of publicFns){
35
+ const actualFnName = `${fn.name}`;
36
+ const fnSelector = await getFunctionSelector(actualFnName, artifact);
37
+ const key = `${classIdStr}:${fnSelector.toString()}`;
38
+ const longFnName = `${artifact.name}.${actualFnName}`;
39
+ this.debugFunctionName.set(key, longFnName);
40
+ }
41
+ }
29
42
  }
30
43
  /////////////////////////////////////////////////////////////
31
44
  // ContractDataSource function implementations
@@ -52,10 +65,21 @@ import { PUBLIC_DISPATCH_FN_NAME } from './index.js';
52
65
  }
53
66
  this.logger.debug(`Retrieved contract artifact for address: ${address}`);
54
67
  this.logger.debug(`Contract class ID: ${contractInstance.currentContractClassId}`);
55
- return Promise.resolve(this.contractArtifacts.get(contractInstance.currentContractClassId.toString()));
68
+ return this.contractArtifacts.get(contractInstance.currentContractClassId.toString());
56
69
  }
57
- getDebugFunctionName(_address, _selector) {
58
- return Promise.resolve(PUBLIC_DISPATCH_FN_NAME);
70
+ async getDebugFunctionName(address, selector) {
71
+ const contractInstance = await this.getContract(address);
72
+ if (!contractInstance) {
73
+ this.logger.warn(`Couldn't get fn name for debugging. Contract not in tester's ContractDataSource. Using selector:${selector} instead...`);
74
+ return `selector:${selector.toString()}`;
75
+ }
76
+ const key = `${contractInstance.currentContractClassId.toString()}:${selector.toString()}`;
77
+ const fnName = this.debugFunctionName.get(key);
78
+ if (!fnName) {
79
+ this.logger.warn(`Couldn't get fn name for debugging. Using selector:${selector} instead...`);
80
+ return selector.toString();
81
+ }
82
+ return fnName;
59
83
  }
60
84
  registerContractFunctionSignatures(_address, _signatures) {
61
85
  return Promise.resolve();
@@ -1 +1 @@
1
- {"version":3,"file":"external_calls.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/external_calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,uBAAe,YAAa,SAAQ,WAAW;IAY3C,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IAdxB,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAOvC;gBAGQ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM;IAKnB,OAAO,CAAC,OAAO,EAAE,UAAU;IAmExC,aAA6B,IAAI,IAAI,MAAM,GAAG,YAAY,CAAC;CAC5D;AAED,qBAAa,IAAK,SAAQ,YAAY;IACpC,MAAM,CAAC,IAAI,SAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAe;IAE7C,IAAW,IAAI,WAEd;CACF;AAED,qBAAa,UAAW,SAAQ,YAAY;IAC1C,MAAM,CAAC,IAAI,eAAyB;IACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAqB;IAEnD,IAAW,IAAI,iBAEd;CACF;AAED,qBAAa,WAAY,SAAQ,WAAW;IAU9B,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,SAAS;IATvD,MAAM,CAAC,IAA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,EAAE,CAIvC;gBAEkB,QAAQ,EAAE,MAAM,EAAU,SAAS,EAAE,MAAM;IAIlD,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAazD;AAED,qBAAa,MAAO,SAAQ,WAAW;IAWzB,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,YAAY;IAAU,OAAO,CAAC,gBAAgB;IAV5F,MAAM,CAAC,IAAI,EAAE,MAAM,CAAY;IAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAiB;IAE/C,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAKvC;gBAEkB,QAAQ,EAAE,MAAM,EAAU,YAAY,EAAE,MAAM,EAAU,gBAAgB,EAAE,MAAM;IAIvF,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxC,SAAS,IAAI,OAAO;CAGrC;AAED,qBAAa,MAAO,SAAQ,WAAW;IAiBzB,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,YAAY;IAAU,OAAO,CAAC,aAAa;IAhBzF,MAAM,CAAC,IAAI,EAAE,MAAM,CAAY;IAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAmB;IAEjD,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,CAKxC;IACF,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,CAKzC;gBAEkB,QAAQ,EAAE,MAAM,EAAU,YAAY,EAAE,MAAM,EAAU,aAAa,EAAE,MAAM;IAIpF,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxC,SAAS,IAAI,OAAO;CAGrC"}
@@ -62,6 +62,8 @@ class ExternalCall extends Instruction {
62
62
  context.machineState.nestedReturndata = fullReturnData;
63
63
  // Track the success status directly
64
64
  context.machineState.nestedCallSuccess = success;
65
+ // Account for all instructions executed in the nested call
66
+ context.machineState.instrCounter += nestedCallResults.totalInstructions;
65
67
  // If the nested call reverted, we try to save the reason and the revert data.
66
68
  // This will be used by the caller to try to reconstruct the call stack.
67
69
  // This is only a heuristic and may not always work. It is intended to work
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,GAAI,SAAQ,WAAW;IAiDhC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,KAAK;IAnDf,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAS;IAErC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAgB;IAE9C,gBAAuB,WAAW,EAAE,WAAW,EAAE,CAM/C;IACF,gBAAuB,YAAY,EAAE,WAAW,EAAE,CAMhD;IACF,gBAAuB,YAAY,EAAE,WAAW,EAAE,CAMhD;IACF,gBAAuB,YAAY,EAAE,WAAW,EAAE,CAMhD;IACF,gBAAuB,aAAa,EAAE,WAAW,EAAE,CAMjD;IACF,gBAAuB,YAAY,EAAE,WAAW,EAAE,CAMhD;gBAGQ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,MAAM;IAMnB,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAYzD;AAED,qBAAa,IAAK,SAAQ,WAAW;IAmBvB,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,SAAS;IAAU,OAAO,CAAC,SAAS;IAA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BAEnF,QAAQ,EAAE,MAAM,EAAU,SAAS,EAAE,MAAM;IAIlD,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CASzD;AAED,qBAAa,cAAe,SAAQ,WAAW;IAa3C,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,SAAS;IAfnB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAoB;IAChD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAyB;IAEvD,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAMvC;gBAGQ,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM;IAKd,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBzD"}
@@ -14,47 +14,46 @@ export class Set extends Instruction {
14
14
  OperandType.UINT8,
15
15
  OperandType.UINT8,
16
16
  OperandType.UINT8,
17
- OperandType.UINT8,
17
+ OperandType.TAG,
18
18
  OperandType.UINT8
19
19
  ];
20
20
  static wireFormat16 = [
21
21
  OperandType.UINT8,
22
22
  OperandType.UINT8,
23
23
  OperandType.UINT16,
24
- OperandType.UINT8,
24
+ OperandType.TAG,
25
25
  OperandType.UINT16
26
26
  ];
27
27
  static wireFormat32 = [
28
28
  OperandType.UINT8,
29
29
  OperandType.UINT8,
30
30
  OperandType.UINT16,
31
- OperandType.UINT8,
31
+ OperandType.TAG,
32
32
  OperandType.UINT32
33
33
  ];
34
34
  static wireFormat64 = [
35
35
  OperandType.UINT8,
36
36
  OperandType.UINT8,
37
37
  OperandType.UINT16,
38
- OperandType.UINT8,
38
+ OperandType.TAG,
39
39
  OperandType.UINT64
40
40
  ];
41
41
  static wireFormat128 = [
42
42
  OperandType.UINT8,
43
43
  OperandType.UINT8,
44
44
  OperandType.UINT16,
45
- OperandType.UINT8,
45
+ OperandType.TAG,
46
46
  OperandType.UINT128
47
47
  ];
48
48
  static wireFormatFF = [
49
49
  OperandType.UINT8,
50
50
  OperandType.UINT8,
51
51
  OperandType.UINT16,
52
- OperandType.UINT8,
52
+ OperandType.TAG,
53
53
  OperandType.FF
54
54
  ];
55
55
  constructor(indirect, dstOffset, inTag, value){
56
56
  super(), this.indirect = indirect, this.dstOffset = dstOffset, this.inTag = inTag, this.value = value;
57
- TaggedMemory.checkIsValidTag(inTag);
58
57
  }
59
58
  async execute(context) {
60
59
  // Constructor ensured that this.inTag is a valid tag
@@ -81,18 +80,17 @@ export class Cast extends Instruction {
81
80
  OperandType.UINT8,
82
81
  OperandType.UINT8,
83
82
  OperandType.UINT8,
84
- OperandType.UINT8
83
+ OperandType.TAG
85
84
  ];
86
85
  static wireFormat16 = [
87
86
  OperandType.UINT8,
88
87
  OperandType.UINT8,
89
88
  OperandType.UINT16,
90
89
  OperandType.UINT16,
91
- OperandType.UINT8
90
+ OperandType.TAG
92
91
  ];
93
92
  constructor(indirect, srcOffset, dstOffset, dstTag){
94
93
  super(), this.indirect = indirect, this.srcOffset = srcOffset, this.dstOffset = dstOffset, this.dstTag = dstTag;
95
- TaggedMemory.checkIsValidTag(dstTag);
96
94
  }
97
95
  async execute(context) {
98
96
  const memory = context.machineState.memory;
@@ -82,15 +82,17 @@ export declare enum OperandType {
82
82
  UINT32 = 2,
83
83
  UINT64 = 3,
84
84
  UINT128 = 4,
85
- FF = 5
85
+ FF = 5,
86
+ TAG = 6
86
87
  }
88
+ type DeserializedValue = number | bigint;
87
89
  /**
88
90
  * Reads an array of operands from a buffer.
89
91
  * @param cursor Buffer to read from. Might be longer than needed.
90
92
  * @param operands Specification of the operand types.
91
93
  * @returns An array as big as {@code operands}, with the converted TS values.
92
94
  */
93
- export declare function deserialize(cursor: BufferCursor | Buffer, operands: OperandType[]): (number | bigint)[];
95
+ export declare function deserialize(cursor: BufferCursor | Buffer, operands: OperandType[]): DeserializedValue[];
94
96
  /**
95
97
  * Serializes a class using the specified operand types.
96
98
  * More specifically, this serializes {@code [cls.constructor.opcode, ...Object.values(cls)]}.
@@ -102,4 +104,5 @@ export declare function deserialize(cursor: BufferCursor | Buffer, operands: Ope
102
104
  * @returns
103
105
  */
104
106
  export declare function serializeAs(operands: OperandType[], opcode: Opcode, cls: any): Buffer;
107
+ export {};
105
108
  //# sourceMappingURL=instruction_serialization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instruction_serialization.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/serialization/instruction_serialization.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,oBAAY,MAAM;IAEhB,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;IACN,OAAO,IAAA;IACP,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,MAAM,KAAA;IACN,OAAO,KAAA;IAEP,YAAY,KAAA;IACZ,YAAY,KAAA;IACZ,WAAW,KAAA;IACX,cAAc,KAAA;IACd,cAAc,KAAA;IAEd,OAAO,KAAA;IACP,QAAQ,KAAA;IACR,YAAY,KAAA;IACZ,cAAc,KAAA;IAEd,KAAK,KAAA;IACL,MAAM,KAAA;IACN,MAAM,KAAA;IACN,MAAM,KAAA;IACN,OAAO,KAAA;IACP,MAAM,KAAA;IACN,KAAK,KAAA;IACL,MAAM,KAAA;IAEN,KAAK,KAAA;IACL,MAAM,KAAA;IACN,cAAc,KAAA;IACd,YAAY,KAAA;IACZ,eAAe,KAAA;IACf,aAAa,KAAA;IACb,eAAe,KAAA;IACf,mBAAmB,KAAA;IACnB,kBAAkB,KAAA;IAClB,aAAa,KAAA;IAEb,IAAI,KAAA;IACJ,UAAU,KAAA;IACV,MAAM,KAAA;IACN,QAAQ,KAAA;IACR,SAAS,KAAA;IAET,QAAQ,KAAA;IAER,SAAS,KAAA;IACT,iBAAiB,KAAA;IACjB,WAAW,KAAA;IACX,KAAK,KAAA;IAEL,SAAS,KAAA;CACV;AAED,eAAO,MAAM,gBAAgB,QAI5B,CAAC;AAMF,oBAAY,WAAW;IACrB,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;IACN,MAAM,IAAA;IACN,OAAO,IAAA;IACP,EAAE,IAAA;CACH;AAmDD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAcvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CAmBrF"}
1
+ {"version":3,"file":"instruction_serialization.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/serialization/instruction_serialization.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AACH,oBAAY,MAAM;IAEhB,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,MAAM,IAAA;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,GAAG,MAAM,GAAG,MAAM,CAAC;AAoDzC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,iBAAiB,EAAE,CAyBvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CAmBrF"}
@@ -1,4 +1,5 @@
1
1
  import { strict as assert } from 'assert';
2
+ import { TaggedMemory } from '../avm_memory_types.js';
2
3
  import { BufferCursor } from './buffer_cursor.js';
3
4
  /**
4
5
  * All AVM opcodes. (Keep in sync with cpp counterpart code avm_opcode.hpp and rs in opcodes.rs).
@@ -84,10 +85,8 @@ import { BufferCursor } from './buffer_cursor.js';
84
85
  return Opcode;
85
86
  }({});
86
87
  export const MAX_OPCODE_VALUE = Math.max(...Object.values(Opcode).map((k)=>+k).filter((k)=>!isNaN(k)));
87
- // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
88
- // See vm/avm_trace/deserialization.cpp)
89
- // Note that cpp code introduced an additional enum value TAG to express the instruction tag. In TS,
90
- // this one is parsed as UINT8.
88
+ // Possible types for an instruction's operand in its wire format.
89
+ // The counterpart cpp file is: vm2/simulation/lib/serialization.hpp.
91
90
  export var OperandType = /*#__PURE__*/ function(OperandType) {
92
91
  OperandType[OperandType["UINT8"] = 0] = "UINT8";
93
92
  OperandType[OperandType["UINT16"] = 1] = "UINT16";
@@ -95,6 +94,7 @@ export var OperandType = /*#__PURE__*/ function(OperandType) {
95
94
  OperandType[OperandType["UINT64"] = 3] = "UINT64";
96
95
  OperandType[OperandType["UINT128"] = 4] = "UINT128";
97
96
  OperandType[OperandType["FF"] = 5] = "FF";
97
+ OperandType[OperandType["TAG"] = 6] = "TAG";
98
98
  return OperandType;
99
99
  }({});
100
100
  // Specifies how to read and write each operand type.
@@ -146,6 +146,14 @@ const OPERAND_SPEC = new Map([
146
146
  readBigInt254BE,
147
147
  writeBigInt254BE
148
148
  ]
149
+ ],
150
+ [
151
+ 6,
152
+ [
153
+ 1,
154
+ Buffer.prototype.readUint8,
155
+ Buffer.prototype.writeUint8
156
+ ]
149
157
  ]
150
158
  ]);
151
159
  function readBigInt254BE(offset) {
@@ -190,12 +198,22 @@ function writeBigInt128BE(value) {
190
198
  if (Buffer.isBuffer(cursor)) {
191
199
  cursor = new BufferCursor(cursor);
192
200
  }
193
- for (const op of operands){
194
- const opType = op;
201
+ for (const opType of operands){
195
202
  const [sizeBytes, reader, _writer] = OPERAND_SPEC.get(opType);
196
- argValues.push(reader.call(cursor.buffer(), cursor.position()));
203
+ const value = reader.call(cursor.buffer(), cursor.position());
204
+ argValues.push(value);
197
205
  cursor.advance(sizeBytes);
198
206
  }
207
+ // We first want to detect other parsing errors (e.g., instruction size
208
+ // is longer than remaining bytes) first and therefore tag validation is done after completion
209
+ // of parsing above. Order of errors need to match with circuit.
210
+ for(let i = 0; i < operands.length; i++){
211
+ if (operands[i] === 6) {
212
+ // We parsed a single byte (readUInt8()) and therefore value is of number type (not bigint)
213
+ // We need to cast to number because checkIsValidTag expects a number.
214
+ TaggedMemory.checkIsValidTag(Number(argValues[i] ?? 0));
215
+ }
216
+ }
199
217
  return argValues;
200
218
  }
201
219
  /**
@@ -1,13 +1,21 @@
1
+ import type { RevertCode } from '@aztec/stdlib/avm';
1
2
  import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
2
- export declare class ExecutorMetrics {
3
+ import type { ExecutorMetricsInterface } from './executor_metrics_interface.js';
4
+ export declare class ExecutorMetrics implements ExecutorMetricsInterface {
3
5
  readonly tracer: Tracer;
4
6
  private fnCount;
5
7
  private fnDuration;
6
8
  private manaPerSecond;
9
+ private manaUsed;
10
+ private totalInstructions;
11
+ private txHashing;
7
12
  private privateEffectsInsertions;
8
13
  constructor(client: TelemetryClient, name?: string);
9
- recordFunctionSimulation(durationMs: number, manaUsed: number, fnName: string): void;
10
- recordFunctionSimulationFailure(): void;
14
+ startRecordingTxSimulation(_txLabel: string): void;
15
+ stopRecordingTxSimulation(_txLabel: string, _revertedCode?: RevertCode): void;
16
+ recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
17
+ recordEnqueuedCallSimulationFailure(_fnName: string, _durationMs: number, _manaUsed: number, _totalInstructions: number): void;
18
+ recordTxHashComputation(durationMs: number): void;
11
19
  recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
12
20
  }
13
21
  //# sourceMappingURL=executor_metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,eAAe;IAC1B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,wBAAwB,CAAY;gBAEhC,MAAM,EAAE,eAAe,EAAE,IAAI,SAAmB;IA2B5D,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAe7E,+BAA+B;IAM/B,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB;CAKxF"}
1
+ {"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,qBAAa,eAAgB,YAAW,wBAAwB;IAC9D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,wBAAwB,CAAY;gBAEhC,MAAM,EAAE,eAAe,EAAE,IAAI,SAAmB;IA6C5D,0BAA0B,CAAC,QAAQ,EAAE,MAAM;IAI3C,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,UAAU;IAItE,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAsB5G,mCAAmC,CACjC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM;IAO5B,uBAAuB,CAAC,UAAU,EAAE,MAAM;IAI1C,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB;CAKxF"}
@@ -4,6 +4,9 @@ export class ExecutorMetrics {
4
4
  fnCount;
5
5
  fnDuration;
6
6
  manaPerSecond;
7
+ manaUsed;
8
+ totalInstructions;
9
+ txHashing;
7
10
  privateEffectsInsertions;
8
11
  constructor(client, name = 'PublicExecutor'){
9
12
  this.tracer = client.getTracer(name);
@@ -21,19 +24,47 @@ export class ExecutorMetrics {
21
24
  unit: 'mana/s',
22
25
  valueType: ValueType.INT
23
26
  });
24
- this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTION_PRIVATE_EFFECTS_INSERTION, {
27
+ this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED, {
28
+ description: 'Total mana used',
29
+ unit: 'mana',
30
+ valueType: ValueType.INT
31
+ });
32
+ this.totalInstructions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS, {
33
+ description: 'Total number of instructions executed',
34
+ unit: 'instructions',
35
+ valueType: ValueType.INT
36
+ });
37
+ this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING, {
38
+ description: 'Tx hashing time',
39
+ unit: 'ms',
40
+ valueType: ValueType.INT
41
+ });
42
+ this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION, {
25
43
  description: 'Private effects insertion time',
26
44
  unit: 'us',
27
45
  valueType: ValueType.INT
28
46
  });
29
47
  }
30
- recordFunctionSimulation(durationMs, manaUsed, fnName) {
48
+ startRecordingTxSimulation(_txLabel) {
49
+ // do nothing (unimplemented)
50
+ }
51
+ stopRecordingTxSimulation(_txLabel, _revertedCode) {
52
+ // do nothing (unimplemented)
53
+ }
54
+ recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions) {
31
55
  this.fnCount.add(1, {
32
56
  [Attributes.OK]: true,
33
- [Attributes.APP_CIRCUIT_NAME]: fnName,
34
- [Attributes.MANA_USED]: manaUsed
57
+ [Attributes.APP_CIRCUIT_NAME]: fnName
58
+ });
59
+ this.manaUsed.record(Math.ceil(manaUsed), {
60
+ [Attributes.APP_CIRCUIT_NAME]: fnName
61
+ });
62
+ this.totalInstructions.record(Math.ceil(totalInstructions), {
63
+ [Attributes.APP_CIRCUIT_NAME]: fnName
64
+ });
65
+ this.fnDuration.record(Math.ceil(durationMs), {
66
+ [Attributes.APP_CIRCUIT_NAME]: fnName
35
67
  });
36
- this.fnDuration.record(Math.ceil(durationMs));
37
68
  if (durationMs > 0 && manaUsed > 0) {
38
69
  const manaPerSecond = Math.round(manaUsed * 1000 / durationMs);
39
70
  this.manaPerSecond.record(manaPerSecond, {
@@ -41,11 +72,14 @@ export class ExecutorMetrics {
41
72
  });
42
73
  }
43
74
  }
44
- recordFunctionSimulationFailure() {
75
+ recordEnqueuedCallSimulationFailure(_fnName, _durationMs, _manaUsed, _totalInstructions) {
45
76
  this.fnCount.add(1, {
46
77
  [Attributes.OK]: false
47
78
  });
48
79
  }
80
+ recordTxHashComputation(durationMs) {
81
+ this.txHashing.record(Math.ceil(durationMs));
82
+ }
49
83
  recordPrivateEffectsInsertion(durationUs, type) {
50
84
  this.privateEffectsInsertions.record(Math.ceil(durationUs), {
51
85
  [Attributes.REVERTIBILITY]: type
@@ -0,0 +1,10 @@
1
+ import type { RevertCode } from '@aztec/stdlib/avm';
2
+ export interface ExecutorMetricsInterface {
3
+ startRecordingTxSimulation(txLabel: string): void;
4
+ stopRecordingTxSimulation(txLabel: string, revertedCode?: RevertCode): void;
5
+ recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
6
+ recordEnqueuedCallSimulationFailure(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
7
+ recordTxHashComputation(durationMs: number): void;
8
+ recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
9
+ }
10
+ //# sourceMappingURL=executor_metrics_interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor_metrics_interface.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,wBAAwB;IACvC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5E,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpH,mCAAmC,CACjC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,GACxB,IAAI,CAAC;IACR,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAChG"}
@@ -0,0 +1 @@
1
+ export { };
@@ -5,9 +5,10 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server'
5
5
  import { GlobalVariables, type Tx } from '@aztec/stdlib/tx';
6
6
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
7
7
  import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
8
- import { type PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
9
- export declare const DEFAULT_BLOCK_NUMBER = 42;
8
+ import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
9
+ import { TestExecutorMetrics } from '../test_executor_metrics.js';
10
10
  export type TestEnqueuedCall = {
11
+ sender?: AztecAddress;
11
12
  address: AztecAddress;
12
13
  fnName: string;
13
14
  args: any[];
@@ -21,12 +22,17 @@ export type TestEnqueuedCall = {
21
22
  */
22
23
  export declare class PublicTxSimulationTester extends BaseAvmSimulationTester {
23
24
  #private;
24
- private merkleTree;
25
+ private metrics;
25
26
  private txCount;
26
- constructor(merkleTree: MerkleTreeWriteOperations, contractDataSource: SimpleContractDataSource);
27
- static create(): Promise<PublicTxSimulationTester>;
27
+ private simulator;
28
+ private metricsPrefix?;
29
+ constructor(merkleTree: MerkleTreeWriteOperations, contractDataSource: SimpleContractDataSource, globals?: GlobalVariables, metrics?: TestExecutorMetrics);
30
+ static create(globals?: GlobalVariables, metrics?: TestExecutorMetrics): Promise<PublicTxSimulationTester>;
31
+ setMetricsPrefix(prefix: string): void;
28
32
  createTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr): Promise<Tx>;
29
- simulateTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr, globals?: GlobalVariables): Promise<PublicTxResult>;
33
+ simulateTx(sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr, txLabel?: string): Promise<PublicTxResult>;
34
+ simulateTxWithLabel(txLabel: string, sender: AztecAddress, setupCalls?: TestEnqueuedCall[], appCalls?: TestEnqueuedCall[], teardownCall?: TestEnqueuedCall, feePayer?: AztecAddress, firstNullifier?: Fr): Promise<PublicTxResult>;
35
+ prettyPrintMetrics(): void;
30
36
  }
31
37
  export declare function defaultGlobals(): GlobalVariables;
32
38
  //# sourceMappingURL=public_tx_simulation_tester.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulation_tester.d.ts","sourceRoot":"","sources":["../../../src/public/fixtures/public_tx_simulation_tester.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAiC,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MA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AAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,GAC/C,OAAO,CAAC,EAAE,CAAC;IAcD,UAAU,CACrB,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,gBAAgB,EAAO,EACnC,QAAQ,GAAE,gBAAgB,EAAO,EACjC,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,GAAE,YAAqB,EAE/B,cAAc,KAAkC,EAChD,OAAO,GAAE,MAAsB,GAC9B,OAAO,CAAC,cAAc,CAAC;IAyBb,mBAAmB,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,EACpB,UAAU,CAAC,EAAE,gBAAgB,EAAE,EAC/B,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAC7B,YAAY,CAAC,EAAE,gBAAgB,EAC/B,QAAQ,CAAC,EAAE,YAAY,EACvB,cAAc,CAAC,EAAE,EAAE,GAClB,OAAO,CAAC,cAAc,CAAC;IAInB,kBAAkB;CAuB1B;AAED,wBAAgB,cAAc,oBAM7B"}
@@ -6,47 +6,67 @@ import { PublicCallRequest } from '@aztec/stdlib/kernel';
6
6
  import { GlobalVariables, PublicCallRequestWithCalldata } from '@aztec/stdlib/tx';
7
7
  import { NativeWorldStateService } from '@aztec/world-state';
8
8
  import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
9
- import { getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
9
+ import { DEFAULT_BLOCK_NUMBER, getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
10
10
  import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
11
11
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
12
- import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
12
+ import { MeasuredPublicTxSimulator } from '../public_tx_simulator/measured_public_tx_simulator.js';
13
+ import { TestExecutorMetrics } from '../test_executor_metrics.js';
13
14
  import { createTxForPublicCalls } from './utils.js';
14
15
  const TIMESTAMP = new Fr(99833);
15
16
  const DEFAULT_GAS_FEES = new GasFees(2, 3);
16
- export const DEFAULT_BLOCK_NUMBER = 42;
17
17
  /**
18
18
  * A test class that extends the BaseAvmSimulationTester to enable real-app testing of the PublicTxSimulator.
19
19
  * It provides an interface for simulating one transaction at a time and maintains state between subsequent
20
20
  * transactions.
21
21
  */ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
22
- merkleTree;
22
+ metrics;
23
23
  txCount;
24
- constructor(merkleTree, contractDataSource){
25
- super(contractDataSource, merkleTree), this.merkleTree = merkleTree, this.txCount = 0;
24
+ simulator;
25
+ metricsPrefix;
26
+ constructor(merkleTree, contractDataSource, globals = defaultGlobals(), metrics = new TestExecutorMetrics()){
27
+ super(contractDataSource, merkleTree), this.metrics = metrics, this.txCount = 0;
28
+ const treesDB = new PublicTreesDB(merkleTree);
29
+ const contractsDB = new PublicContractsDB(contractDataSource);
30
+ this.simulator = new MeasuredPublicTxSimulator(treesDB, contractsDB, globals, /*doMerkleOperations=*/ true, /*skipFeeEnforcement=*/ false, this.metrics);
26
31
  }
27
- static async create() {
32
+ static async create(globals = defaultGlobals(), metrics = new TestExecutorMetrics()) {
28
33
  const contractDataSource = new SimpleContractDataSource();
29
34
  const merkleTree = await (await NativeWorldStateService.tmp()).fork();
30
- return new PublicTxSimulationTester(merkleTree, contractDataSource);
35
+ return new PublicTxSimulationTester(merkleTree, contractDataSource, globals, metrics);
36
+ }
37
+ setMetricsPrefix(prefix) {
38
+ this.metricsPrefix = prefix;
31
39
  }
32
40
  async createTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++)) {
33
- const setupCallRequests = await asyncMap(setupCalls, (call)=>this.#createPubicCallRequestForCall(call, sender));
34
- const appCallRequests = await asyncMap(appCalls, (call)=>this.#createPubicCallRequestForCall(call, sender));
35
- const teardownCallRequest = teardownCall ? await this.#createPubicCallRequestForCall(teardownCall, sender) : undefined;
41
+ const setupCallRequests = await asyncMap(setupCalls, (call)=>this.#createPubicCallRequestForCall(call, call.sender ?? sender));
42
+ const appCallRequests = await asyncMap(appCalls, (call)=>this.#createPubicCallRequestForCall(call, call.sender ?? sender));
43
+ const teardownCallRequest = teardownCall ? await this.#createPubicCallRequestForCall(teardownCall, teardownCall.sender ?? sender) : undefined;
36
44
  return createTxForPublicCalls(firstNullifier, setupCallRequests, appCallRequests, teardownCallRequest, feePayer);
37
45
  }
38
- async simulateTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++), globals = defaultGlobals()) {
46
+ async simulateTx(sender, setupCalls = [], appCalls = [], teardownCall, feePayer = sender, /* need some unique first nullifier for note-nonce computations */ firstNullifier = new Fr(420000 + this.txCount++), txLabel = 'unlabeledTx') {
39
47
  const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier);
40
48
  await this.setFeePayerBalance(feePayer);
41
- const treesDB = new PublicTreesDB(this.merkleTree);
42
- const contractsDB = new PublicContractsDB(this.contractDataSource);
43
- const simulator = new PublicTxSimulator(treesDB, contractsDB, globals, /*doMerkleOperations=*/ true);
44
- const startTime = performance.now();
45
- const avmResult = await simulator.simulate(tx);
46
- const endTime = performance.now();
47
- this.logger.debug(`Public transaction simulation took ${endTime - startTime}ms`);
49
+ const txLabelWithCount = `${txLabel}.${this.txCount - 1}`;
50
+ const fullTxLabel = this.metricsPrefix ? `${this.metricsPrefix}.${txLabelWithCount}` : txLabelWithCount;
51
+ const avmResult = await this.simulator.simulate(tx, fullTxLabel);
52
+ // Something like this is often useful for debugging:
53
+ //if (avmResult.revertReason) {
54
+ // // resolve / enrich revert reason
55
+ // const lastAppCall = appCalls[appCalls.length - 1];
56
+ // const contractArtifact =
57
+ // lastAppCall.contractArtifact || (await this.contractDataSource.getContractArtifact(lastAppCall.address));
58
+ // const fnAbi = getContractFunctionAbi(lastAppCall.fnName, contractArtifact!);
59
+ // const revertReason = resolveAssertionMessageFromRevertData(avmResult.revertReason.revertData, fnAbi!);
60
+ // this.logger.debug(`Revert reason: ${revertReason}`);
61
+ //}
48
62
  return avmResult;
49
63
  }
64
+ async simulateTxWithLabel(txLabel, sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier) {
65
+ return await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, firstNullifier, txLabel);
66
+ }
67
+ prettyPrintMetrics() {
68
+ this.metrics.prettyPrint();
69
+ }
50
70
  async #createPubicCallRequestForCall(call, sender) {
51
71
  const address = call.address;
52
72
  const contractArtifact = call.contractArtifact || await this.contractDataSource.getContractArtifact(address);
@@ -1,19 +1,42 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
2
5
  import type { FunctionSelector } from '@aztec/stdlib/abi';
3
6
  import { type AvmExecutionHints } from '@aztec/stdlib/avm';
4
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
8
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
- import type { PublicContractsDBInterface } from '../server.js';
9
+ import { type IndexedTreeId, MerkleTreeId, type MerkleTreeLeafType, type SequentialInsertionResult } from '@aztec/stdlib/trees';
10
+ import type { PublicContractsDBInterface } from '../common/db_interfaces.js';
11
+ import { PublicTreesDB } from './public_db_sources.js';
7
12
  /**
8
13
  * A public contracts database that forwards requests and collects AVM hints.
9
14
  */
10
15
  export declare class HintingPublicContractsDB implements PublicContractsDBInterface {
11
16
  private readonly db;
12
- readonly hints: AvmExecutionHints;
17
+ private hints;
13
18
  constructor(db: PublicContractsDBInterface, hints: AvmExecutionHints);
14
19
  getContractInstance(address: AztecAddress, blockNumber: number): Promise<ContractInstanceWithAddress | undefined>;
15
20
  getContractClass(contractClassId: Fr): Promise<ContractClassPublic | undefined>;
16
21
  getBytecodeCommitment(contractClassId: Fr): Promise<Fr | undefined>;
17
22
  getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
18
23
  }
24
+ /**
25
+ * A public trees database that forwards requests and collects AVM hints.
26
+ */
27
+ export declare class HintingPublicTreesDB extends PublicTreesDB {
28
+ private hints;
29
+ private static readonly log;
30
+ constructor(db: PublicTreesDB, hints: AvmExecutionHints);
31
+ getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>>;
32
+ getPreviousValueIndex<ID extends IndexedTreeId>(treeId: ID, value: bigint): Promise<{
33
+ index: bigint;
34
+ alreadyPresent: boolean;
35
+ } | undefined>;
36
+ getLeafPreimage<ID extends IndexedTreeId>(treeId: ID, index: bigint): Promise<IndexedTreeLeafPreimage | undefined>;
37
+ getLeafValue<ID extends MerkleTreeId>(treeId: ID, index: bigint): Promise<MerkleTreeLeafType<typeof treeId> | undefined>;
38
+ sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(treeId: ID, leaves: Buffer[]): Promise<SequentialInsertionResult<TreeHeight>>;
39
+ revertCheckpoint(): Promise<void>;
40
+ private getHintKey;
41
+ }
19
42
  //# sourceMappingURL=hinting_db_sources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hinting_db_sources.d.ts","sourceRoot":"","sources":["../../src/public/hinting_db_sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,M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