@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
@@ -0,0 +1,109 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ export async function tokenTest(tester, logger) {
5
+ const startTime = performance.now();
6
+ const admin = AztecAddress.fromNumber(42);
7
+ const sender = AztecAddress.fromNumber(111);
8
+ const receiver = AztecAddress.fromNumber(222);
9
+ const token = await deployToken(tester, admin);
10
+ const mintAmount = 100n;
11
+ const mintResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'mint_to_public', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
12
+ {
13
+ address: token.address,
14
+ fnName: 'mint_to_public',
15
+ args: [
16
+ /*to=*/ sender,
17
+ mintAmount
18
+ ]
19
+ }
20
+ ]);
21
+ expect(mintResult.revertCode.isOK()).toBe(true);
22
+ await checkBalance(tester, token, sender, sender, mintAmount);
23
+ const nonce = new Fr(0);
24
+ const transferAmount = 50n;
25
+ const transferResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'transfer_in_public', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
26
+ {
27
+ address: token.address,
28
+ fnName: 'transfer_in_public',
29
+ args: [
30
+ /*from=*/ sender,
31
+ /*to=*/ receiver,
32
+ transferAmount,
33
+ nonce
34
+ ]
35
+ }
36
+ ]);
37
+ expect(transferResult.revertCode.isOK()).toBe(true);
38
+ await checkBalance(tester, token, sender, receiver, mintAmount - transferAmount);
39
+ await checkBalance(tester, token, sender, receiver, transferAmount);
40
+ const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
41
+ {
42
+ address: token.address,
43
+ fnName: 'balance_of_public',
44
+ args: [
45
+ /*owner=*/ receiver
46
+ ],
47
+ isStaticCall: true
48
+ }
49
+ ]);
50
+ expect(balResult.revertCode.isOK()).toBe(true);
51
+ const burnResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'burn_public', /*sender=*/ receiver, /*setupCalls=*/ [], /*appCalls=*/ [
52
+ {
53
+ address: token.address,
54
+ fnName: 'burn_public',
55
+ args: [
56
+ /*from=*/ receiver,
57
+ transferAmount,
58
+ nonce
59
+ ]
60
+ }
61
+ ]);
62
+ expect(burnResult.revertCode.isOK()).toBe(true);
63
+ await checkBalance(tester, token, sender, receiver, 0n);
64
+ const endTime = performance.now();
65
+ logger.info(`TokenContract public tx simulator test took ${endTime - startTime}ms\n`);
66
+ }
67
+ export async function deployToken(tester, admin, seed = 0) {
68
+ const constructorArgs = [
69
+ admin,
70
+ /*name=*/ 'Token',
71
+ /*symbol=*/ 'TOK',
72
+ /*decimals=*/ new Fr(18)
73
+ ];
74
+ const token = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, TokenContractArtifact, /*skipNullifierInsertion=*/ false, seed);
75
+ const result = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token.constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
76
+ {
77
+ fnName: 'constructor',
78
+ args: constructorArgs,
79
+ address: token.address
80
+ }
81
+ ]);
82
+ expect(result.revertCode.isOK()).toBe(true);
83
+ return token;
84
+ }
85
+ async function checkBalance(tester, token, sender, account, expectedBalance) {
86
+ const balResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'balance_of_public', sender, /*setupCalls=*/ [], /*appCalls=*/ [
87
+ {
88
+ address: token.address,
89
+ fnName: 'balance_of_public',
90
+ args: [
91
+ /*owner=*/ account
92
+ ],
93
+ isStaticCall: true
94
+ }
95
+ ]);
96
+ expect(balResult.revertCode.isOK()).toBe(true);
97
+ // should be 1 call with 1 return value that is expectedBalance
98
+ expect(balResult.processedPhases).toEqual([
99
+ expect.objectContaining({
100
+ returnValues: [
101
+ expect.objectContaining({
102
+ values: [
103
+ new Fr(expectedBalance)
104
+ ]
105
+ })
106
+ ]
107
+ })
108
+ ]);
109
+ }
@@ -0,0 +1,3 @@
1
+ export * from './public_tx_simulator.js';
2
+ export { TelemetryPublicTxSimulator } from './telemetry_public_tx_simulator.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './public_tx_simulator.js';
2
+ export { TelemetryPublicTxSimulator } from './telemetry_public_tx_simulator.js';
@@ -0,0 +1,23 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { Gas } from '@aztec/stdlib/gas';
3
+ import { type GlobalVariables, PublicCallRequestWithCalldata, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
4
+ import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
5
+ import type { AvmPersistableStateManager } from '../avm/index.js';
6
+ import type { ExecutorMetricsInterface } from '../executor_metrics_interface.js';
7
+ import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
8
+ import { PublicTxContext } from './public_tx_context.js';
9
+ import { type ProcessedPhase, type PublicTxResult, PublicTxSimulator } from './public_tx_simulator.js';
10
+ /**
11
+ * A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
12
+ */
13
+ export declare class MeasuredPublicTxSimulator extends PublicTxSimulator {
14
+ protected readonly metrics: ExecutorMetricsInterface;
15
+ constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean | undefined, skipFeeEnforcement: boolean | undefined, metrics: ExecutorMetricsInterface);
16
+ simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
17
+ protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
18
+ protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
19
+ protected insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<boolean>;
20
+ protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
21
+ protected simulateEnqueuedCallInternal(stateManager: AvmPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
22
+ }
23
+ //# sourceMappingURL=measured_public_tx_simulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measured_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/measured_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE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AAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAsCnC"}
@@ -0,0 +1,58 @@
1
+ import { Timer } from '@aztec/foundation/timer';
2
+ import { PublicTxSimulator } from './public_tx_simulator.js';
3
+ /**
4
+ * A public tx simulator that tracks miscellaneous simulation metrics without telemetry.
5
+ */ export class MeasuredPublicTxSimulator extends PublicTxSimulator {
6
+ metrics;
7
+ constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, metrics){
8
+ super(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement), this.metrics = metrics;
9
+ }
10
+ async simulate(tx, txLabel = 'unlabeledTx') {
11
+ this.metrics.startRecordingTxSimulation(txLabel);
12
+ let avmResult;
13
+ try {
14
+ avmResult = await super.simulate(tx);
15
+ } finally{
16
+ this.metrics.stopRecordingTxSimulation(txLabel, avmResult?.revertCode);
17
+ }
18
+ return avmResult;
19
+ }
20
+ async computeTxHash(tx) {
21
+ const timer = new Timer();
22
+ const txHash = await super.computeTxHash(tx);
23
+ this.metrics.recordTxHashComputation(timer.ms());
24
+ return txHash;
25
+ }
26
+ async insertNonRevertiblesFromPrivate(context, tx) {
27
+ const timer = new Timer();
28
+ await super.insertNonRevertiblesFromPrivate(context, tx);
29
+ this.metrics.recordPrivateEffectsInsertion(timer.us(), 'non-revertible');
30
+ }
31
+ async insertRevertiblesFromPrivate(context, tx) {
32
+ const timer = new Timer();
33
+ const result = await super.insertRevertiblesFromPrivate(context, tx);
34
+ this.metrics.recordPrivateEffectsInsertion(timer.us(), 'revertible');
35
+ return result;
36
+ }
37
+ async simulatePhase(phase, context) {
38
+ const timer = new Timer();
39
+ const result = await super.simulatePhase(phase, context);
40
+ result.durationMs = timer.ms();
41
+ return result;
42
+ }
43
+ async simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName) {
44
+ const timer = new Timer();
45
+ const result = await super.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName);
46
+ this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
47
+ eventName: 'avm-simulation',
48
+ appCircuitName: fnName,
49
+ duration: timer.ms()
50
+ });
51
+ if (result.reverted) {
52
+ this.metrics.recordEnqueuedCallSimulationFailure(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
53
+ } else {
54
+ this.metrics.recordEnqueuedCallSimulation(fnName, timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, result.totalInstructions);
55
+ }
56
+ return result;
57
+ }
58
+ }
@@ -4,7 +4,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { SimulationError } from '@aztec/stdlib/errors';
5
5
  import { Gas } from '@aztec/stdlib/gas';
6
6
  import { type PrivateToPublicAccumulatedData } from '@aztec/stdlib/kernel';
7
- import { type GlobalVariables, PublicCallRequestWithCalldata, type StateReference, type Tx, TxExecutionPhase, type TxHash } from '@aztec/stdlib/tx';
7
+ import { type GlobalVariables, PublicCallRequestWithCalldata, type Tx, TxExecutionPhase, type TxHash } from '@aztec/stdlib/tx';
8
8
  import type { PublicContractsDBInterface } from '../../server.js';
9
9
  import { AvmPersistableStateManager } from '../avm/index.js';
10
10
  import type { PublicTreesDB } from '../public_db_sources.js';
@@ -98,7 +98,7 @@ export declare class PublicTxContext {
98
98
  /**
99
99
  * Generate the public inputs for the AVM circuit.
100
100
  */
101
- generateAvmCircuitPublicInputs(endStateReference: StateReference): Promise<AvmCircuitPublicInputs>;
101
+ generateAvmCircuitPublicInputs(): Promise<AvmCircuitPublicInputs>;
102
102
  }
103
103
  /**
104
104
  * Thin wrapper around the state manager to handle forking and merging for phases.
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_context.d.ts","sourceRoot":"","sources":["../../../src/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gB,GAAG,EAAE;IAQ9C;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAa/B;;OAEG;IACU,8BAA8B,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAqG/E;AAED;;;;;;;;;GASG;AACH,cAAM,iBAAiB;IAKT,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJ3C,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,2BAA2B,CAAyC;gBAE/C,cAAc,EAAE,0BAA0B;IAIjE,IAAI;IAMV,qBAAqB;IAIrB,QAAQ;IAIF,gBAAgB;IAQhB,kBAAkB;CAOzB"}
@@ -12,7 +12,7 @@ import { TreeSnapshots, TxExecutionPhase } from '@aztec/stdlib/tx';
12
12
  import { strict as assert } from 'assert';
13
13
  import { inspect } from 'util';
14
14
  import { AvmPersistableStateManager } from '../avm/index.js';
15
- import { HintingPublicContractsDB } from '../hinting_db_sources.js';
15
+ import { HintingPublicContractsDB, HintingPublicTreesDB } from '../hinting_db_sources.js';
16
16
  import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
17
17
  import { getCallRequestsWithCalldataByPhase } from '../utils.js';
18
18
  /**
@@ -69,9 +69,9 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
69
69
  // We wrap the DB to collect AVM hints.
70
70
  const hints = new AvmExecutionHints();
71
71
  const hintingContractsDB = new HintingPublicContractsDB(contractsDB, hints);
72
- // TODO: Wrap merkle db.
72
+ const hintingTreesDB = new HintingPublicTreesDB(treesDB, hints);
73
73
  // Transaction level state manager that will be forked for revertible phases.
74
- const txStateManager = AvmPersistableStateManager.create(treesDB, hintingContractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.blockNumber.toNumber());
74
+ const txStateManager = AvmPersistableStateManager.create(hintingTreesDB, hintingContractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.blockNumber.toNumber());
75
75
  const gasSettings = tx.data.constants.txContext.gasSettings;
76
76
  const gasUsedByPrivate = tx.data.gasUsed;
77
77
  // Gas allocated to public is "whatever's left" after private, but with some max applied.
@@ -215,13 +215,15 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
215
215
  }
216
216
  /**
217
217
  * Generate the public inputs for the AVM circuit.
218
- */ async generateAvmCircuitPublicInputs(endStateReference) {
218
+ */ async generateAvmCircuitPublicInputs() {
219
219
  assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
220
220
  const stateManager = this.state.getActiveStateManager();
221
221
  const startTreeSnapshots = new TreeSnapshots(this.startStateReference.l1ToL2MessageTree, this.startStateReference.partial.noteHashTree, this.startStateReference.partial.nullifierTree, this.startStateReference.partial.publicDataTree);
222
- // Will be patched/padded at the end of this fn
223
- const endTreeSnapshots = new TreeSnapshots(endStateReference.l1ToL2MessageTree, endStateReference.partial.noteHashTree, endStateReference.partial.nullifierTree, endStateReference.partial.publicDataTree);
224
- const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(this.globalVariables, startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, this.setupCallRequests.map((r)=>r.request), this.appLogicCallRequests.map((r)=>r.request), /*teardownCallRequest=*/ this.teardownCallRequests.length ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), endTreeSnapshots, /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
222
+ // FIXME: We are first creating the PIs with the wrong endTreeSnapshots, then patching them.
223
+ // This is because we need to know the lengths of the accumulated data arrays to pad them.
224
+ // We should refactor this to avoid this hack.
225
+ // We should just get the info we need from the trace, and create the rest of the PIs here.
226
+ const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(this.globalVariables, startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, this.setupCallRequests.map((r)=>r.request), this.appLogicCallRequests.map((r)=>r.request), /*teardownCallRequest=*/ this.teardownCallRequests.length ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), /*endTreeSnapshots=*/ TreeSnapshots.empty(), /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
225
227
  const getArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
226
228
  const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
227
229
  // Temporary overrides as these entries aren't yet populated in trace
@@ -1,14 +1,16 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import { type Logger } from '@aztec/foundation/log';
1
3
  import { type AvmProvingRequest, type RevertCode } from '@aztec/stdlib/avm';
2
4
  import { SimulationError } from '@aztec/stdlib/errors';
3
- import type { GasUsed } from '@aztec/stdlib/gas';
4
- import { type GlobalVariables, NestedProcessReturnValues, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
5
- import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
6
- import { ExecutorMetrics } from '../executor_metrics.js';
5
+ import type { Gas, GasUsed } from '@aztec/stdlib/gas';
6
+ import { type GlobalVariables, NestedProcessReturnValues, PublicCallRequestWithCalldata, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
7
+ import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
8
+ import { type AvmPersistableStateManager } from '../avm/index.js';
7
9
  import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
8
10
  import { PublicTxContext } from './public_tx_context.js';
9
11
  export type ProcessedPhase = {
10
12
  phase: TxExecutionPhase;
11
- durationMs: number;
13
+ durationMs?: number;
12
14
  returnValues: NestedProcessReturnValues[];
13
15
  reverted: boolean;
14
16
  revertReason?: SimulationError;
@@ -24,20 +26,19 @@ export type PublicTxResult = {
24
26
  };
25
27
  export declare class PublicTxSimulator {
26
28
  private treesDB;
27
- private contractsDB;
29
+ protected contractsDB: PublicContractsDB;
28
30
  private globalVariables;
29
31
  private doMerkleOperations;
30
32
  private skipFeeEnforcement;
31
- metrics: ExecutorMetrics;
32
- private log;
33
- constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, telemetryClient?: TelemetryClient);
34
- get tracer(): Tracer;
33
+ protected log: Logger;
34
+ constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean);
35
35
  /**
36
36
  * Simulate a transaction's public portion including all of its phases.
37
37
  * @param tx - The transaction to simulate.
38
38
  * @returns The result of the transaction's public execution.
39
39
  */
40
40
  simulate(tx: Tx): Promise<PublicTxResult>;
41
+ protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
41
42
  /**
42
43
  * Simulate the setup phase of a transaction's public execution.
43
44
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
@@ -62,7 +63,7 @@ export declare class PublicTxSimulator {
62
63
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
63
64
  * @returns The phase result.
64
65
  */
65
- private simulatePhase;
66
+ protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
66
67
  /**
67
68
  * Simulate an enqueued public call.
68
69
  * @param phase - The current phase of public execution
@@ -70,7 +71,7 @@ export declare class PublicTxSimulator {
70
71
  * @param callRequest - The public function call request, including the calldata.
71
72
  * @returns The result of execution.
72
73
  */
73
- private simulateEnqueuedCall;
74
+ protected simulateEnqueuedCall(phase: TxExecutionPhase, context: PublicTxContext, callRequest: PublicCallRequestWithCalldata): Promise<AvmFinalizedCallResult>;
74
75
  /**
75
76
  * Simulate an enqueued public call, without modifying the context (PublicTxContext).
76
77
  * Resulting modifications to the context can be applied by the caller.
@@ -79,22 +80,21 @@ export declare class PublicTxSimulator {
79
80
  * while still simulating phases and generating a proving request.
80
81
  *
81
82
  * @param stateManager - The state manager for AvmSimulation
82
- * @param context - The context of the currently executing public transaction portion
83
83
  * @param callRequest - The public function call request, including the calldata.
84
84
  * @param allocatedGas - The gas allocated to the enqueued call
85
85
  * @param fnName - The name of the function
86
86
  * @returns The result of execution.
87
87
  */
88
- private simulateEnqueuedCallInternal;
88
+ protected simulateEnqueuedCallInternal(stateManager: AvmPersistableStateManager, { request, calldata }: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
89
89
  /**
90
90
  * Insert the non-revertible accumulated data from private into the public state.
91
91
  */
92
- insertNonRevertiblesFromPrivate(context: PublicTxContext): Promise<void>;
92
+ protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
93
93
  /**
94
94
  * Insert the revertible accumulated data from private into the public state.
95
95
  * Start by forking state so we can rollback to the end of setup if app logic or teardown reverts.
96
96
  */
97
- insertRevertiblesFromPrivate(context: PublicTxContext): Promise<boolean>;
97
+ protected insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<boolean>;
98
98
  private payFee;
99
99
  /**
100
100
  * Generate the proving request for the AVM circuit.
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAKA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAO,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EAEzB,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;A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AE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;IAsBlC;;OAEG;cACa,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;IAuBhF;;;OAGG;cACa,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,GAAgB,OAAO,CAAC,OAAO,CAAC;YAoC/F,MAAM;IAgCpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAStC"}
@@ -1,23 +1,14 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
1
  import { createLogger } from '@aztec/foundation/log';
8
- import { Timer } from '@aztec/foundation/timer';
9
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
10
3
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
11
4
  import { AvmCircuitInputs, AvmEnqueuedCallHint } from '@aztec/stdlib/avm';
12
5
  import { SimulationError } from '@aztec/stdlib/errors';
13
6
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
14
7
  import { NestedProcessReturnValues, TxExecutionPhase } from '@aztec/stdlib/tx';
15
- import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
16
8
  import { strict as assert } from 'assert';
17
9
  import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
18
10
  import { AvmSimulator } from '../avm/index.js';
19
11
  import { NullifierCollisionError } from '../avm/journal/nullifiers.js';
20
- import { ExecutorMetrics } from '../executor_metrics.js';
21
12
  import { PublicTxContext } from './public_tx_context.js';
22
13
  export class PublicTxSimulator {
23
14
  treesDB;
@@ -25,19 +16,14 @@ export class PublicTxSimulator {
25
16
  globalVariables;
26
17
  doMerkleOperations;
27
18
  skipFeeEnforcement;
28
- metrics;
29
19
  log;
30
- constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, telemetryClient = getTelemetryClient()){
20
+ constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false){
31
21
  this.treesDB = treesDB;
32
22
  this.contractsDB = contractsDB;
33
23
  this.globalVariables = globalVariables;
34
24
  this.doMerkleOperations = doMerkleOperations;
35
25
  this.skipFeeEnforcement = skipFeeEnforcement;
36
26
  this.log = createLogger(`simulator:public_tx_simulator`);
37
- this.metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
38
- }
39
- get tracer() {
40
- return this.metrics.tracer;
41
27
  }
42
28
  /**
43
29
  * Simulate a transaction's public portion including all of its phases.
@@ -45,31 +31,19 @@ export class PublicTxSimulator {
45
31
  * @returns The result of the transaction's public execution.
46
32
  */ async simulate(tx) {
47
33
  try {
48
- const startTime = process.hrtime.bigint();
49
- const txHash = await tx.getTxHash();
34
+ const txHash = await this.computeTxHash(tx);
50
35
  this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
51
36
  txHash
52
37
  });
53
38
  const context = await PublicTxContext.create(this.treesDB, this.contractsDB, tx, this.globalVariables, this.doMerkleOperations);
54
- const nonRevertStart = process.hrtime.bigint();
55
- await this.insertNonRevertiblesFromPrivate(context);
56
- // add new contracts to the contracts db so that their functions may be found and called
57
- // TODO(#6464): Should we allow emitting contracts in the private setup phase?
58
- await this.contractsDB.addNewNonRevertibleContracts(tx);
59
- const nonRevertEnd = process.hrtime.bigint();
60
- this.metrics.recordPrivateEffectsInsertion(Number(nonRevertEnd - nonRevertStart) / 1_000, 'non-revertible');
39
+ await this.insertNonRevertiblesFromPrivate(context, tx);
61
40
  const processedPhases = [];
62
41
  if (context.hasPhase(TxExecutionPhase.SETUP)) {
63
42
  const setupResult = await this.simulateSetupPhase(context);
64
43
  processedPhases.push(setupResult);
65
44
  }
66
- const revertStart = process.hrtime.bigint();
67
- const success = await this.insertRevertiblesFromPrivate(context);
45
+ const success = await this.insertRevertiblesFromPrivate(context, tx);
68
46
  if (success) {
69
- // add new contracts to the contracts db so that their functions may be found and called
70
- await this.contractsDB.addNewRevertibleContracts(tx);
71
- const revertEnd = process.hrtime.bigint();
72
- this.metrics.recordPrivateEffectsInsertion(Number(revertEnd - revertStart) / 1_000, 'revertible');
73
47
  // Only proceed with app logic if there was no revert during revertible insertion
74
48
  if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
75
49
  const appLogicResult = await this.simulateAppLogicPhase(context);
@@ -84,7 +58,7 @@ export class PublicTxSimulator {
84
58
  }
85
59
  await context.halt();
86
60
  await this.payFee(context);
87
- const publicInputs = await context.generateAvmCircuitPublicInputs(await this.treesDB.getStateReference());
61
+ const publicInputs = await context.generateAvmCircuitPublicInputs();
88
62
  const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, context.hints);
89
63
  const revertCode = context.getFinalRevertCode();
90
64
  if (!revertCode.isOK()) {
@@ -93,9 +67,9 @@ export class PublicTxSimulator {
93
67
  // Commit contracts from this TX to the block-level cache and clear tx cache
94
68
  // If the tx reverted, only commit non-revertible contracts
95
69
  // NOTE: You can't create contracts in public, so this is only relevant for private-created contracts
70
+ // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
71
+ // However things should work as they are now because the hinted db would still pick up the new contracts.
96
72
  this.contractsDB.commitContractsForTx(/*onlyNonRevertibles=*/ !revertCode.isOK());
97
- const endTime = process.hrtime.bigint();
98
- this.log.debug(`Public TX simulator took ${Number(endTime - startTime) / 1_000_000} ms\n`);
99
73
  return {
100
74
  avmProvingRequest,
101
75
  gasUsed: {
@@ -111,9 +85,14 @@ export class PublicTxSimulator {
111
85
  } finally{
112
86
  // Make sure there are no new contracts in the tx-level cache.
113
87
  // They should either be committed to block-level cache or cleared.
88
+ // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
89
+ // However things should work as they are now because the hinted db would still pick up the new contracts.
114
90
  this.contractsDB.clearContractsForTx();
115
91
  }
116
92
  }
93
+ async computeTxHash(tx) {
94
+ return await tx.getTxHash();
95
+ }
117
96
  /**
118
97
  * Simulate the setup phase of a transaction's public execution.
119
98
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
@@ -174,7 +153,6 @@ export class PublicTxSimulator {
174
153
  const returnValues = [];
175
154
  let reverted = false;
176
155
  let revertReason;
177
- const phaseTimer = new Timer();
178
156
  for(let i = callRequests.length - 1; i >= 0; i--){
179
157
  if (reverted) {
180
158
  break;
@@ -189,7 +167,6 @@ export class PublicTxSimulator {
189
167
  }
190
168
  return {
191
169
  phase,
192
- durationMs: phaseTimer.ms(),
193
170
  returnValues,
194
171
  reverted,
195
172
  revertReason
@@ -229,7 +206,6 @@ export class PublicTxSimulator {
229
206
  * while still simulating phases and generating a proving request.
230
207
  *
231
208
  * @param stateManager - The state manager for AvmSimulation
232
- * @param context - The context of the currently executing public transaction portion
233
209
  * @param callRequest - The public function call request, including the calldata.
234
210
  * @param allocatedGas - The gas allocated to the enqueued call
235
211
  * @param fnName - The name of the function
@@ -238,25 +214,13 @@ export class PublicTxSimulator {
238
214
  const address = request.contractAddress;
239
215
  const sender = request.msgSender;
240
216
  this.log.debug(`Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`);
241
- const timer = new Timer();
242
217
  const simulator = await AvmSimulator.create(stateManager, address, sender, transactionFee, this.globalVariables, request.isStaticCall, calldata, allocatedGas);
243
218
  const avmCallResult = await simulator.execute();
244
- const result = avmCallResult.finalize();
245
- this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
246
- eventName: 'avm-simulation',
247
- appCircuitName: fnName,
248
- duration: timer.ms()
249
- });
250
- if (result.reverted) {
251
- this.metrics.recordFunctionSimulationFailure();
252
- } else {
253
- this.metrics.recordFunctionSimulation(timer.ms(), allocatedGas.sub(result.gasLeft).l2Gas, fnName);
254
- }
255
- return result;
219
+ return avmCallResult.finalize();
256
220
  }
257
221
  /**
258
222
  * Insert the non-revertible accumulated data from private into the public state.
259
- */ async insertNonRevertiblesFromPrivate(context) {
223
+ */ async insertNonRevertiblesFromPrivate(context, tx) {
260
224
  const stateManager = context.state.getActiveStateManager();
261
225
  try {
262
226
  await stateManager.writeSiloedNullifiersFromPrivate(context.nonRevertibleAccumulatedDataFromPrivate.nullifiers);
@@ -270,11 +234,16 @@ export class PublicTxSimulator {
270
234
  await stateManager.writeUniqueNoteHash(noteHash);
271
235
  }
272
236
  }
237
+ // add new contracts to the contracts db so that their functions may be found and called
238
+ // TODO(#6464): Should we allow emitting contracts in the private setup phase?
239
+ // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
240
+ // However things should work as they are now because the hinted db would still pick up the new contracts.
241
+ await this.contractsDB.addNewNonRevertibleContracts(tx);
273
242
  }
274
243
  /**
275
244
  * Insert the revertible accumulated data from private into the public state.
276
245
  * Start by forking state so we can rollback to the end of setup if app logic or teardown reverts.
277
- */ async insertRevertiblesFromPrivate(context) {
246
+ */ async insertRevertiblesFromPrivate(context, tx) {
278
247
  // Fork the state manager so we can rollback to end of setup if app logic reverts.
279
248
  await context.state.fork();
280
249
  const stateManager = context.state.getActiveStateManager();
@@ -295,6 +264,10 @@ export class PublicTxSimulator {
295
264
  await stateManager.writeSiloedNoteHash(noteHash);
296
265
  }
297
266
  }
267
+ // add new contracts to the contracts db so that their functions may be found and called
268
+ // FIXME(fcarreiro): this should conceptually use the hinted contracts db.
269
+ // However things should work as they are now because the hinted db would still pick up the new contracts.
270
+ await this.contractsDB.addNewRevertibleContracts(tx);
298
271
  return /*success=*/ true;
299
272
  }
300
273
  async payFee(context) {
@@ -329,16 +302,3 @@ export class PublicTxSimulator {
329
302
  };
330
303
  }
331
304
  }
332
- _ts_decorate([
333
- trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest)=>({
334
- [Attributes.TX_HASH]: context.txHash.toString(),
335
- [Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
336
- [Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
337
- [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString()
338
- }))
339
- ], PublicTxSimulator.prototype, "simulateEnqueuedCall", null);
340
- _ts_decorate([
341
- trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName)=>({
342
- [Attributes.APP_CIRCUIT_NAME]: fnName
343
- }))
344
- ], PublicTxSimulator.prototype, "simulateEnqueuedCallInternal", null);
@@ -0,0 +1,19 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { Gas } from '@aztec/stdlib/gas';
3
+ import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
4
+ import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
5
+ import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
6
+ import type { AvmPersistableStateManager } from '../avm/index.js';
7
+ import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
8
+ import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
9
+ import { PublicTxContext } from './public_tx_context.js';
10
+ /**
11
+ * A public tx simulator that tracks runtime/production metrics with telemetry.
12
+ */
13
+ export declare class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
14
+ readonly tracer: Tracer;
15
+ constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, telemetryClient?: TelemetryClient);
16
+ protected simulateEnqueuedCall(phase: TxExecutionPhase, context: PublicTxContext, callRequest: PublicCallRequestWithCalldata): Promise<AvmFinalizedCallResult>;
17
+ protected simulateEnqueuedCallInternal(stateManager: AvmPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
18
+ }
19
+ //# sourceMappingURL=telemetry_public_tx_simulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/telemetry_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,yBAAyB;IAEvE,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAG7B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,OAAe,EACnC,kBAAkB,GAAE,OAAe,EACnC,eAAe,GAAE,eAAsC;cAahC,oBAAoB,CAC3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;cAUT,4BAA4B,CACnD,YAAY,EAAE,0BAA0B,EACxC,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAGnC"}