@aztec/simulator 0.82.2-alpha-testnet.4 → 0.82.3

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 (102) hide show
  1. package/README.md +6 -0
  2. package/dest/private/acvm/oracle/oracle.d.ts +1 -1
  3. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/private/acvm/oracle/oracle.js +1 -3
  5. package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
  6. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  7. package/dest/public/avm/avm_contract_call_result.js +9 -5
  8. package/dest/public/avm/avm_machine_state.d.ts +2 -0
  9. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  10. package/dest/public/avm/avm_machine_state.js +2 -0
  11. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  12. package/dest/public/avm/avm_simulator.js +5 -6
  13. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  14. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -2
  15. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
  16. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  17. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
  18. package/dest/public/avm/fixtures/index.d.ts +1 -0
  19. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  20. package/dest/public/avm/fixtures/index.js +1 -1
  21. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
  22. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
  23. package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
  24. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  25. package/dest/public/avm/opcodes/external_calls.js +2 -0
  26. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  27. package/dest/public/avm/opcodes/memory.js +8 -10
  28. package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
  29. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  30. package/dest/public/avm/serialization/instruction_serialization.js +23 -3
  31. package/dest/public/executor_metrics.d.ts +11 -3
  32. package/dest/public/executor_metrics.d.ts.map +1 -1
  33. package/dest/public/executor_metrics.js +40 -6
  34. package/dest/public/executor_metrics_interface.d.ts +10 -0
  35. package/dest/public/executor_metrics_interface.d.ts.map +1 -0
  36. package/dest/public/executor_metrics_interface.js +1 -0
  37. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
  38. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  39. package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
  40. package/dest/public/hinting_db_sources.d.ts +26 -3
  41. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  42. package/dest/public/hinting_db_sources.js +102 -1
  43. package/dest/public/index.d.ts +1 -1
  44. package/dest/public/index.d.ts.map +1 -1
  45. package/dest/public/index.js +1 -1
  46. package/dest/public/public_db_sources.d.ts +2 -3
  47. package/dest/public/public_db_sources.d.ts.map +1 -1
  48. package/dest/public/public_db_sources.js +26 -16
  49. package/dest/public/public_processor/public_processor.d.ts +1 -1
  50. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  51. package/dest/public/public_processor/public_processor.js +3 -3
  52. package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
  53. package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
  54. package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
  55. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
  56. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
  57. package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
  58. package/dest/public/public_tx_simulator/index.d.ts +3 -0
  59. package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
  60. package/dest/public/public_tx_simulator/index.js +2 -0
  61. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
  62. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
  63. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
  64. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  65. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  66. package/dest/public/public_tx_simulator/public_tx_context.js +9 -7
  67. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
  68. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  69. package/dest/public/public_tx_simulator/public_tx_simulator.js +24 -64
  70. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
  71. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
  72. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
  73. package/dest/public/test_executor_metrics.d.ts +43 -0
  74. package/dest/public/test_executor_metrics.d.ts.map +1 -0
  75. package/dest/public/test_executor_metrics.js +158 -0
  76. package/package.json +14 -14
  77. package/src/private/acvm/oracle/oracle.ts +2 -2
  78. package/src/public/avm/avm_contract_call_result.ts +15 -3
  79. package/src/public/avm/avm_machine_state.ts +5 -0
  80. package/src/public/avm/avm_simulator.ts +18 -7
  81. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  82. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
  83. package/src/public/avm/fixtures/index.ts +1 -1
  84. package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
  85. package/src/public/avm/opcodes/external_calls.ts +3 -0
  86. package/src/public/avm/opcodes/memory.ts +8 -10
  87. package/src/public/avm/serialization/instruction_serialization.ts +22 -5
  88. package/src/public/executor_metrics.ts +54 -6
  89. package/src/public/executor_metrics_interface.ts +15 -0
  90. package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
  91. package/src/public/hinting_db_sources.ts +184 -3
  92. package/src/public/index.ts +1 -1
  93. package/src/public/public_db_sources.ts +36 -23
  94. package/src/public/public_processor/public_processor.ts +4 -4
  95. package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
  96. package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
  97. package/src/public/public_tx_simulator/index.ts +2 -0
  98. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
  99. package/src/public/public_tx_simulator/public_tx_context.ts +9 -13
  100. package/src/public/public_tx_simulator/public_tx_simulator.ts +31 -76
  101. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
  102. package/src/public/test_executor_metrics.ts +222 -0
@@ -260,7 +260,16 @@ import { TxContractCache } from './tx_contract_cache.js';
260
260
  * @param slot - Slot to read in the contract storage.
261
261
  * @returns The current value in the storage slot.
262
262
  */ async storageRead(contract, slot) {
263
- return await readPublicState(this.db, contract, slot);
263
+ const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
264
+ const lowLeafResult = await this.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
265
+ if (!lowLeafResult) {
266
+ throw new Error('Low leaf not found');
267
+ }
268
+ // TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
269
+ await this.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
270
+ // Unconditionally fetching the preimage for the hints. Move it to the hinting layer?
271
+ const preimage = await this.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
272
+ return lowLeafResult.alreadyPresent ? preimage.value : Fr.ZERO;
264
273
  }
265
274
  /**
266
275
  * Records a write to public storage.
@@ -271,13 +280,15 @@ import { TxContractCache } from './tx_contract_cache.js';
271
280
  */ async storageWrite(contract, slot, newValue) {
272
281
  const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
273
282
  const publicDataWrite = new PublicDataWrite(leafSlot, newValue);
274
- await this.db.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
283
+ await this.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
275
284
  publicDataWrite.toBuffer()
276
285
  ]);
277
286
  }
278
287
  async getL1ToL2LeafValue(leafIndex) {
279
288
  const timer = new Timer();
280
- const leafValue = await this.db.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
289
+ const leafValue = await this.getLeafValue(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
290
+ // TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
291
+ await this.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, leafIndex);
281
292
  this.logger.debug(`[DB] Fetched L1 to L2 message leaf value`, {
282
293
  eventName: 'public-db-access',
283
294
  duration: timer.ms(),
@@ -287,7 +298,9 @@ import { TxContractCache } from './tx_contract_cache.js';
287
298
  }
288
299
  async getNoteHash(leafIndex) {
289
300
  const timer = new Timer();
290
- const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
301
+ const leafValue = await this.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
302
+ // TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
303
+ await this.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
291
304
  this.logger.debug(`[DB] Fetched note hash leaf value`, {
292
305
  eventName: 'public-db-access',
293
306
  duration: timer.ms(),
@@ -297,9 +310,15 @@ import { TxContractCache } from './tx_contract_cache.js';
297
310
  }
298
311
  async getNullifierIndex(nullifier) {
299
312
  const timer = new Timer();
300
- const index = (await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
301
- nullifier.toBuffer()
302
- ]))[0];
313
+ const lowLeafResult = await this.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
314
+ if (!lowLeafResult) {
315
+ throw new Error('Low leaf not found');
316
+ }
317
+ // TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
318
+ await this.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
319
+ // TODO(fcarreiro): We need this for the hints. Might move it to the hinting layer.
320
+ await this.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, lowLeafResult.index);
321
+ const index = lowLeafResult.alreadyPresent ? lowLeafResult.index : undefined;
303
322
  this.logger.debug(`[DB] Fetched nullifier index`, {
304
323
  eventName: 'public-db-access',
305
324
  duration: timer.ms(),
@@ -308,12 +327,3 @@ import { TxContractCache } from './tx_contract_cache.js';
308
327
  return index;
309
328
  }
310
329
  }
311
- export async function readPublicState(db, contract, slot) {
312
- const leafSlot = (await computePublicDataTreeLeafSlot(contract, slot)).toBigInt();
313
- const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
314
- if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
315
- return Fr.ZERO;
316
- }
317
- const preimage = await db.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
318
- return preimage.value;
319
- }
@@ -7,7 +7,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server'
7
7
  import { type FailedTx, GlobalVariables, NestedProcessReturnValues, type ProcessedTx, Tx, type TxValidator } from '@aztec/stdlib/tx';
8
8
  import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
9
9
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
10
- import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
10
+ import { type PublicTxSimulator } from '../public_tx_simulator/index.js';
11
11
  /**
12
12
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
13
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE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;gBAE5B,eAAe,EAAE,eAAe,EAChC,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,iBAAiB,EAAE,iBAAiB,EACtC,YAAY,EAAE,YAAY,EAClC,eAAe,GAAE,eAAsC,EAC/C,GAAG,yCAA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;OAKG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE;QACN,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,QAAQ,CAAC,EAAE,IAAI,CAAC;KACZ,EACN,UAAU,GAAE;QACV,mBAAmB,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QACtC,oBAAoB,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAChD,cAAc,CAAC,EAAE;YAAE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;SAAE,CAAC;KAC/D,GACL,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YAwKtD,SAAS;YA2BT,gCAAgC;IAyC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,4BAA4B;YAwB5B,oBAAoB;YA6BpB,wBAAwB;CA8CvC"}
1
+ {"version":3,"file":"public_processor.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,yBAAyB,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB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tB,WAAW,EAAE,iBAAiB,EAC9B,iBAAiB,EAAE,iBAAiB,EACtC,YAAY,EAAE,YAAY,EAClC,eAAe,GAAE,eAAsC,EAC/C,GAAG,yCAA6C;IAK1D,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;OAKG;IACU,OAAO,CAClB,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EACrC,MAAM,GAAE;QACN,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,GAAG,CAAC;QAClB,QAAQ,CAAC,EAAE,IAAI,CAAC;KACZ,EACN,UAAU,GAAE;QACV,mBAAmB,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QACtC,oBAAoB,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAChD,cAAc,CAAC,EAAE;YAAE,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;SAAE,CAAC;KAC/D,GACL,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,yBAAyB,EAAE,CAAC,CAAC;YAwKtD,SAAS;YA2BT,gCAAgC;IAyC9C,kFAAkF;YACpE,uBAAuB;IA+BrC;;;;OAIG;YACW,4BAA4B;YAwB5B,oBAAoB;YA6BpB,wBAAwB;CA8CvC"}
@@ -19,7 +19,7 @@ import { NestedProcessReturnValues, Tx, TxExecutionPhase, makeProcessedTxFromPri
19
19
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
20
20
  import { ForkCheckpoint } from '@aztec/world-state/native';
21
21
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
22
- import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
22
+ import { TelemetryPublicTxSimulator } from '../public_tx_simulator/index.js';
23
23
  import { PublicProcessorMetrics } from './public_processor_metrics.js';
24
24
  /**
25
25
  * Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
@@ -45,7 +45,7 @@ import { PublicProcessorMetrics } from './public_processor_metrics.js';
45
45
  return new PublicProcessor(globalVariables, treesDB, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient);
46
46
  }
47
47
  createPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient) {
48
- return new PublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
48
+ return new TelemetryPublicTxSimulator(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, telemetryClient);
49
49
  }
50
50
  }
51
51
  class PublicProcessorTimeoutError extends Error {
@@ -347,7 +347,7 @@ class PublicProcessorTimeoutError extends Error {
347
347
  if (phase.reverted) {
348
348
  this.metrics.recordRevertedPhase(phase.phase);
349
349
  } else {
350
- this.metrics.recordPhaseDuration(phase.phase, phase.durationMs);
350
+ this.metrics.recordPhaseDuration(phase.phase, phase.durationMs ?? 0);
351
351
  }
352
352
  });
353
353
  const siloedContractClassLogs = await tx.filterContractClassLogs(tx.data.getNonEmptyContractClassLogsHashes(), true);
@@ -0,0 +1,9 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
3
+ /**
4
+ * THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
5
+ * `.skip` it or literally just delete it and notify AVM team.
6
+ * You do NOT need permission to remove this test!
7
+ */
8
+ export declare function ammTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
9
+ //# sourceMappingURL=amm_test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amm_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/amm_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAIzF;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBAoG7E"}
@@ -0,0 +1,237 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { AMMContractArtifact } from '@aztec/noir-contracts.js/AMM';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { deployToken } from './token_test.js';
5
+ const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
6
+ /**
7
+ * THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
8
+ * `.skip` it or literally just delete it and notify AVM team.
9
+ * You do NOT need permission to remove this test!
10
+ */ export async function ammTest(tester, logger) {
11
+ const startTime = performance.now();
12
+ const admin = AztecAddress.fromNumber(42);
13
+ const sender = AztecAddress.fromNumber(111);
14
+ logger.debug(`Deploying tokens`);
15
+ const token0 = await deployToken(tester, admin, /*seed=*/ 0);
16
+ const token1 = await deployToken(tester, admin, /*seed=*/ 1);
17
+ const liquidityToken = await deployToken(tester, admin, /*seed=*/ 2);
18
+ logger.debug(`Deploying AMM`);
19
+ const constructorArgs = [
20
+ token0,
21
+ token1,
22
+ liquidityToken
23
+ ];
24
+ const amm = await tester.registerAndDeployContract(constructorArgs, /*deployer=*/ admin, AMMContractArtifact, /*skipNullifierInsertion=*/ false, /*seed=*/ 3);
25
+ const ammConstructorResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'constructor', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
26
+ {
27
+ fnName: 'constructor',
28
+ args: constructorArgs,
29
+ address: amm.address
30
+ }
31
+ ]);
32
+ expect(ammConstructorResult.revertCode.isOK()).toBe(true);
33
+ logger.debug(`Setting AMM as minter for liquidity token`);
34
+ // set the AMM as the minter for the liquidity token
35
+ const setMinterResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'set_minter', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
36
+ {
37
+ fnName: 'set_minter',
38
+ args: [
39
+ /*minter=*/ amm,
40
+ /*approve=*/ true
41
+ ],
42
+ address: liquidityToken.address
43
+ }
44
+ ]);
45
+ expect(setMinterResult.revertCode.isOK()).toBe(true);
46
+ logger.debug(`Adding liquidity`);
47
+ const amount0Max = INITIAL_TOKEN_BALANCE * 6n / 10n;
48
+ const amount0Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
49
+ const amount1Max = INITIAL_TOKEN_BALANCE * 5n / 10n;
50
+ const amount1Min = INITIAL_TOKEN_BALANCE * 4n / 10n;
51
+ const addLiquidityResult = await addLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*amount0Max=*/ amount0Max, /*amount1Max=*/ amount1Max, /*amount0Min=*/ amount0Min, /*amount1Min=*/ amount1Min);
52
+ expect(addLiquidityResult.revertCode.isOK()).toBe(true);
53
+ logger.debug(`Swapping tokens`);
54
+ const swapResult = await swapExactTokensForTokens(tester, sender, /*amm=*/ amm, /*tokenIn=*/ token0, /*tokenOut=*/ token1, /*amountIn=*/ amount0Min / 10n, /*amountOutMin=*/ amount1Min / 100n);
55
+ expect(swapResult.revertCode.isOK()).toBe(true);
56
+ logger.debug(`Removing liquidity`);
57
+ const removeLiquidityResult = await removeLiquidity(tester, sender, /*amm=*/ amm, /*token0=*/ token0, /*token1=*/ token1, /*liquidityToken=*/ liquidityToken, /*liquidity=*/ 100n, /*amount0Min=*/ 1n, /*amount1Min=*/ 1n);
58
+ expect(removeLiquidityResult.revertCode.isOK()).toBe(true);
59
+ const endTime = performance.now();
60
+ logger.info(`AMM public tx simulator test took ${endTime - startTime}ms\n`);
61
+ }
62
+ async function addLiquidity(tester, sender, amm, token0, token1, liquidityToken, amount0Max, amount1Max, amount0Min, amount1Min, _nonce) {
63
+ const refundToken0PartialNote = {
64
+ commitment: new Fr(42)
65
+ };
66
+ const refundToken1PartialNote = {
67
+ commitment: new Fr(66)
68
+ };
69
+ const liquidityPartialNote = {
70
+ commitment: new Fr(99)
71
+ };
72
+ return await tester.simulateTxWithLabel(/*txLabel=*/ 'add_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
73
+ // token0.transfer_to_public enqueues a call to _increase_public_balance
74
+ {
75
+ sender: token0.address,
76
+ fnName: '_increase_public_balance',
77
+ args: [
78
+ /*to=*/ amm.address,
79
+ /*amount=*/ amount0Max
80
+ ],
81
+ address: token0.address
82
+ },
83
+ // token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
84
+ {
85
+ sender: token0.address,
86
+ fnName: '_store_balances_set_partial_note',
87
+ args: [
88
+ refundToken0PartialNote
89
+ ],
90
+ address: token0.address
91
+ },
92
+ // token1.transfer_to_public enqueues a call to _increase_public_balance
93
+ {
94
+ sender: token1.address,
95
+ fnName: '_increase_public_balance',
96
+ args: [
97
+ /*to=*/ amm.address,
98
+ /*amount=*/ amount1Max
99
+ ],
100
+ address: token1.address
101
+ },
102
+ // token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
103
+ {
104
+ sender: token1.address,
105
+ fnName: '_store_balances_set_partial_note',
106
+ args: [
107
+ refundToken1PartialNote
108
+ ],
109
+ address: token1.address
110
+ },
111
+ // liquidityToken.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
112
+ {
113
+ sender: liquidityToken.address,
114
+ fnName: '_store_balances_set_partial_note',
115
+ args: [
116
+ liquidityPartialNote
117
+ ],
118
+ address: liquidityToken.address
119
+ },
120
+ // amm.add_liquidity enqueues a call to _add_liquidity
121
+ {
122
+ sender: amm.address,
123
+ fnName: '_add_liquidity',
124
+ args: [
125
+ /*config=*/ {
126
+ token0: token0.address,
127
+ token1: token1.address,
128
+ // eslint-disable-next-line camelcase
129
+ liquidity_token: liquidityToken.address
130
+ },
131
+ refundToken0PartialNote,
132
+ refundToken1PartialNote,
133
+ liquidityPartialNote,
134
+ amount0Max,
135
+ amount1Max,
136
+ amount0Min,
137
+ amount1Min
138
+ ],
139
+ address: amm.address
140
+ }
141
+ ]);
142
+ }
143
+ async function swapExactTokensForTokens(tester, sender, amm, tokenIn, tokenOut, amountIn, amountOutMin, _nonce) {
144
+ const tokenOutPartialNote = {
145
+ commitment: new Fr(66)
146
+ };
147
+ return await tester.simulateTxWithLabel(/*txLabel=*/ 'swap_exact_tokens_for_tokens', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
148
+ // tokenIn.transfer_to_public enqueues a call to _increase_public_balance
149
+ {
150
+ sender: tokenIn.address,
151
+ fnName: '_increase_public_balance',
152
+ args: [
153
+ /*to=*/ amm.address,
154
+ /*amount=*/ amountIn
155
+ ],
156
+ address: tokenIn.address
157
+ },
158
+ // tokenOut.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
159
+ {
160
+ sender: tokenOut.address,
161
+ fnName: '_store_balances_set_partial_note',
162
+ args: [
163
+ tokenOutPartialNote
164
+ ],
165
+ address: tokenOut.address
166
+ },
167
+ {
168
+ sender: amm.address,
169
+ fnName: '_swap_exact_tokens_for_tokens',
170
+ args: [
171
+ tokenIn.address,
172
+ tokenOut.address,
173
+ amountIn,
174
+ amountOutMin,
175
+ tokenOutPartialNote
176
+ ],
177
+ address: amm.address
178
+ }
179
+ ]);
180
+ }
181
+ async function removeLiquidity(tester, sender, amm, token0, token1, liquidityToken, liquidity, amount0Min, amount1Min, _nonce) {
182
+ const token0PartialNote = {
183
+ commitment: new Fr(111)
184
+ };
185
+ const token1PartialNote = {
186
+ commitment: new Fr(222)
187
+ };
188
+ return await tester.simulateTxWithLabel(/*txLabel=*/ 'remove_liquidity', /*sender=*/ sender, /*setupCalls=*/ [], /*appCalls=*/ [
189
+ // liquidityToken.transfer_to_public enqueues a call to _increase_public_balance
190
+ {
191
+ sender: liquidityToken.address,
192
+ fnName: '_increase_public_balance',
193
+ args: [
194
+ /*to=*/ amm.address,
195
+ /*amount=*/ liquidity
196
+ ],
197
+ address: liquidityToken.address
198
+ },
199
+ // token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
200
+ {
201
+ sender: token0.address,
202
+ fnName: '_store_balances_set_partial_note',
203
+ args: [
204
+ token0PartialNote
205
+ ],
206
+ address: token0.address
207
+ },
208
+ // token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
209
+ {
210
+ sender: token1.address,
211
+ fnName: '_store_balances_set_partial_note',
212
+ args: [
213
+ token1PartialNote
214
+ ],
215
+ address: token1.address
216
+ },
217
+ // amm.remove_liquidity enqueues a call to _remove_liquidity
218
+ {
219
+ sender: amm.address,
220
+ fnName: '_remove_liquidity',
221
+ args: [
222
+ /*config=*/ {
223
+ token0: token0.address,
224
+ token1: token1.address,
225
+ // eslint-disable-next-line camelcase
226
+ liquidity_token: liquidityToken.address
227
+ },
228
+ liquidity,
229
+ token0PartialNote,
230
+ token1PartialNote,
231
+ amount0Min,
232
+ amount1Min
233
+ ],
234
+ address: amm.address
235
+ }
236
+ ]);
237
+ }
@@ -0,0 +1,7 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
+ import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
5
+ export declare function tokenTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
6
+ export declare function deployToken(tester: PublicTxSimulationTester, admin: AztecAddress, seed?: number): Promise<ContractInstanceWithAddress>;
7
+ //# sourceMappingURL=token_test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token_test.d.ts","sourceRoot":"","sources":["../../../../src/public/public_tx_simulator/apps_tests/token_test.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAEzF,wBAAsB,SAAS,CAAC,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,iBA4E/E;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAI,wCAwBhG"}
@@ -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;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,EAAE,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEvG;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,iBAAiB;IAO5D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBALpD,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,qBAAiB,EACnC,kBAAkB,qBAAiB,EAChB,OAAO,EAAE,wBAAwB;IAKhC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;cAWvE,aAAa,CAAC,EAAE,EAAE,EAAE;cAOpB,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;cAMhE,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;cAOhF,aAAa,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;cAOzF,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;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/public/public_tx_simulator/public_tx_context.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,KAAK,sBAAsB,EAAE,iBAAiB,EAAmB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAe,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAGL,KAAK,8BAA8B,EAIpC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,KAAK,eAAe,EACpB,6BAA6B,EAC7B,KAAK,cAAc,EAEnB,KAAK,EAAE,EACP,gBAAgB,EAChB,KAAK,MAAM,EACZ,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK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