@aztec/simulator 1.2.1 → 2.0.0-nightly.20250813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dest/private/circuit_recording/circuit_recorder.js +2 -2
  2. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +2 -2
  3. package/dest/public/avm/fixtures/utils.js +2 -2
  4. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  5. package/dest/public/avm/opcodes/accrued_substate.js +5 -3
  6. package/dest/public/avm/opcodes/comparators.js +1 -1
  7. package/dest/public/avm/opcodes/environment_getters.d.ts +2 -2
  8. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  9. package/dest/public/avm/opcodes/environment_getters.js +6 -6
  10. package/dest/public/avm/opcodes/misc.js +1 -1
  11. package/dest/public/avm/test_utils.d.ts +2 -2
  12. package/dest/public/avm/test_utils.d.ts.map +1 -1
  13. package/dest/public/avm/test_utils.js +2 -2
  14. package/dest/public/executor_metrics.d.ts +0 -1
  15. package/dest/public/executor_metrics.d.ts.map +1 -1
  16. package/dest/public/executor_metrics.js +0 -3
  17. package/dest/public/executor_metrics_interface.d.ts +0 -1
  18. package/dest/public/executor_metrics_interface.d.ts.map +1 -1
  19. package/dest/public/fixtures/index.d.ts +1 -0
  20. package/dest/public/fixtures/index.d.ts.map +1 -1
  21. package/dest/public/fixtures/index.js +1 -0
  22. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  23. package/dest/public/fixtures/minimal_public_tx.js +1 -1
  24. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  25. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  26. package/dest/public/fixtures/public_tx_simulation_tester.js +2 -1
  27. package/dest/public/fixtures/utils.d.ts +5 -2
  28. package/dest/public/fixtures/utils.d.ts.map +1 -1
  29. package/dest/public/fixtures/utils.js +37 -13
  30. package/dest/public/public_db_sources.js +4 -4
  31. package/dest/public/public_processor/public_processor.d.ts +3 -2
  32. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  33. package/dest/public/public_processor/public_processor.js +30 -19
  34. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  35. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  36. package/dest/public/public_processor/public_processor_metrics.js +1 -1
  37. package/dest/public/public_tx_simulator/apps_tests/amm_test.js +4 -4
  38. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +1 -1
  39. package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -1
  40. package/dest/public/public_tx_simulator/apps_tests/token_test.js +2 -2
  41. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +0 -1
  42. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  43. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +0 -6
  44. package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
  45. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  46. package/dest/public/public_tx_simulator/public_tx_context.js +6 -12
  47. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +1 -20
  48. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  49. package/dest/public/public_tx_simulator/public_tx_simulator.js +49 -81
  50. package/dest/public/side_effect_trace.d.ts.map +1 -1
  51. package/dest/public/side_effect_trace.js +17 -11
  52. package/dest/public/state_manager/state_manager.d.ts +1 -1
  53. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  54. package/dest/public/state_manager/state_manager.js +16 -16
  55. package/dest/public/test_executor_metrics.d.ts +13 -3
  56. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  57. package/dest/public/test_executor_metrics.js +159 -47
  58. package/package.json +15 -15
  59. package/src/private/circuit_recording/circuit_recorder.ts +2 -2
  60. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +2 -2
  61. package/src/public/avm/fixtures/utils.ts +2 -2
  62. package/src/public/avm/opcodes/accrued_substate.ts +6 -3
  63. package/src/public/avm/opcodes/comparators.ts +1 -1
  64. package/src/public/avm/opcodes/environment_getters.ts +8 -8
  65. package/src/public/avm/opcodes/misc.ts +1 -1
  66. package/src/public/avm/test_utils.ts +4 -4
  67. package/src/public/executor_metrics.ts +0 -4
  68. package/src/public/executor_metrics_interface.ts +0 -1
  69. package/src/public/fixtures/index.ts +1 -0
  70. package/src/public/fixtures/minimal_public_tx.ts +2 -0
  71. package/src/public/fixtures/public_tx_simulation_tester.ts +3 -2
  72. package/src/public/fixtures/utils.ts +45 -16
  73. package/src/public/public_db_sources.ts +7 -7
  74. package/src/public/public_processor/public_processor.ts +38 -29
  75. package/src/public/public_processor/public_processor_metrics.ts +2 -2
  76. package/src/public/public_tx_simulator/apps_tests/amm_test.ts +4 -4
  77. package/src/public/public_tx_simulator/apps_tests/token_test.ts +2 -2
  78. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +0 -7
  79. package/src/public/public_tx_simulator/public_tx_context.ts +13 -19
  80. package/src/public/public_tx_simulator/public_tx_simulator.ts +63 -105
  81. package/src/public/side_effect_trace.ts +29 -23
  82. package/src/public/state_manager/state_manager.ts +23 -21
  83. package/src/public/test_executor_metrics.ts +172 -46
@@ -8,9 +8,10 @@ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT
8
8
  import { padArrayEnd } from '@aztec/foundation/collection';
9
9
  import { Fr } from '@aztec/foundation/fields';
10
10
  import { createLogger } from '@aztec/foundation/log';
11
+ import { sleep } from '@aztec/foundation/sleep';
11
12
  import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
12
13
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
13
- import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
14
+ import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
14
15
  import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
15
16
  import { PublicDataWrite } from '@aztec/stdlib/avm';
16
17
  import { Gas } from '@aztec/stdlib/gas';
@@ -65,14 +66,16 @@ class PublicProcessorTimeoutError extends Error {
65
66
  publicTxSimulator;
66
67
  dateProvider;
67
68
  log;
69
+ opts;
68
70
  metrics;
69
- constructor(globalVariables, guardedMerkleTree, contractsDB, publicTxSimulator, dateProvider, telemetryClient = getTelemetryClient(), log = createLogger('simulator:public-processor')){
71
+ constructor(globalVariables, guardedMerkleTree, contractsDB, publicTxSimulator, dateProvider, telemetryClient = getTelemetryClient(), log = createLogger('simulator:public-processor'), opts = {}){
70
72
  this.globalVariables = globalVariables;
71
73
  this.guardedMerkleTree = guardedMerkleTree;
72
74
  this.contractsDB = contractsDB;
73
75
  this.publicTxSimulator = publicTxSimulator;
74
76
  this.dateProvider = dateProvider;
75
77
  this.log = log;
78
+ this.opts = opts;
76
79
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
77
80
  }
78
81
  get tracer() {
@@ -107,7 +110,7 @@ class PublicProcessorTimeoutError extends Error {
107
110
  break;
108
111
  }
109
112
  // Skip this tx if it'd exceed max block size
110
- const txHash = (await origTx.getTxHash()).toString();
113
+ const txHash = origTx.getTxHash().toString();
111
114
  const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
112
115
  if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
113
116
  this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
@@ -134,10 +137,10 @@ class PublicProcessorTimeoutError extends Error {
134
137
  // We validate the tx before processing it, to avoid unnecessary work.
135
138
  if (preprocessValidator) {
136
139
  const result = await preprocessValidator.validateTx(tx);
137
- const txHash = await tx.getTxHash();
140
+ const txHash = tx.getTxHash();
138
141
  if (result.result === 'invalid') {
139
142
  const reason = result.reason.join(', ');
140
- this.log.warn(`Rejecting tx ${txHash.toString()} due to pre-process validation fail: ${reason}`);
143
+ this.log.debug(`Rejecting tx ${txHash.toString()} due to pre-process validation fail: ${reason}`);
141
144
  failed.push({
142
145
  tx,
143
146
  error: new Error(`Tx failed preprocess validation: ${reason}`)
@@ -146,7 +149,7 @@ class PublicProcessorTimeoutError extends Error {
146
149
  continue;
147
150
  } else if (result.result === 'skipped') {
148
151
  const reason = result.reason.join(', ');
149
- this.log.warn(`Skipping tx ${txHash.toString()} due to pre-process validation: ${reason}`);
152
+ this.log.debug(`Skipping tx ${txHash.toString()} due to pre-process validation: ${reason}`);
150
153
  returns.push(new NestedProcessReturnValues([]));
151
154
  continue;
152
155
  } else {
@@ -165,7 +168,7 @@ class PublicProcessorTimeoutError extends Error {
165
168
  // If the actual size of this tx would exceed block size, skip it
166
169
  const txSize = processedTx.txEffect.getDASize();
167
170
  if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
168
- this.log.warn(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
171
+ this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
169
172
  txHash,
170
173
  sizeInBytes: txSize,
171
174
  totalSizeInBytes,
@@ -299,11 +302,19 @@ class PublicProcessorTimeoutError extends Error {
299
302
  this.metrics.recordTreeInsertions(Number(treeInsertionEnd - treeInsertionStart) / 1_000);
300
303
  }
301
304
  /** Processes the given tx within deadline. Returns timeout if deadline is hit. */ async processTxWithinDeadline(tx, deadline) {
302
- const processFn = tx.hasPublicCalls() ? ()=>this.processTxWithPublicCalls(tx) : ()=>this.processPrivateOnlyTx(tx);
305
+ const innerProcessFn = tx.hasPublicCalls() ? ()=>this.processTxWithPublicCalls(tx) : ()=>this.processPrivateOnlyTx(tx);
306
+ // Fake a delay per tx if instructed (used for tests)
307
+ const fakeDelayPerTxMs = this.opts.fakeProcessingDelayPerTxMs;
308
+ const processFn = fakeDelayPerTxMs && fakeDelayPerTxMs > 0 ? async ()=>{
309
+ const result = await innerProcessFn();
310
+ this.log.warn(`Sleeping ${fakeDelayPerTxMs}ms after processing tx ${tx.getTxHash().toString()}`);
311
+ await sleep(fakeDelayPerTxMs);
312
+ return result;
313
+ } : innerProcessFn;
303
314
  if (!deadline) {
304
315
  return await processFn();
305
316
  }
306
- const txHash = await tx.getTxHash();
317
+ const txHash = tx.getTxHash();
307
318
  const timeout = +deadline - this.dateProvider.now();
308
319
  if (timeout <= 0) {
309
320
  throw new PublicProcessorTimeoutError();
@@ -338,8 +349,8 @@ class PublicProcessorTimeoutError extends Error {
338
349
  const gasFees = this.globalVariables.gasFees;
339
350
  const transactionFee = tx.data.gasUsed.computeFee(gasFees);
340
351
  const feePaymentPublicDataWrite = await this.performFeePaymentPublicDataWrite(transactionFee, tx.data.feePayer);
341
- const processedTx = await makeProcessedTxFromPrivateOnlyTx(tx, transactionFee, feePaymentPublicDataWrite, this.globalVariables);
342
- this.metrics.recordClassRegistration(...tx.getContractClassLogs().filter((log)=>ContractClassRegisteredEvent.isContractClassRegisteredEvent(log)).map((log)=>ContractClassRegisteredEvent.fromLog(log)));
352
+ const processedTx = makeProcessedTxFromPrivateOnlyTx(tx, transactionFee, feePaymentPublicDataWrite, this.globalVariables);
353
+ this.metrics.recordClassPublication(...tx.getContractClassLogs().filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log)));
343
354
  // Fee payment insertion has already been done. Do the rest.
344
355
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
345
356
  // Add any contracts registered/deployed in this private-only tx to the block-level cache
@@ -366,11 +377,11 @@ class PublicProcessorTimeoutError extends Error {
366
377
  }
367
378
  });
368
379
  const contractClassLogs = revertCode.isOK() ? tx.getContractClassLogs() : tx.getSplitContractClassLogs(false);
369
- this.metrics.recordClassRegistration(...contractClassLogs.filter((log)=>ContractClassRegisteredEvent.isContractClassRegisteredEvent(log)).map((log)=>ContractClassRegisteredEvent.fromLog(log)));
380
+ this.metrics.recordClassPublication(...contractClassLogs.filter((log)=>ContractClassPublishedEvent.isContractClassPublishedEvent(log)).map((log)=>ContractClassPublishedEvent.fromLog(log)));
370
381
  const phaseCount = processedPhases.length;
371
382
  const durationMs = timer.ms();
372
383
  this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
373
- const processedTx = await makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
384
+ const processedTx = makeProcessedTxFromTxWithPublicCalls(tx, avmProvingRequest, gasUsed, revertCode, revertReason);
374
385
  const returnValues = processedPhases.find(({ phase })=>phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
375
386
  return [
376
387
  processedTx,
@@ -379,17 +390,17 @@ class PublicProcessorTimeoutError extends Error {
379
390
  }
380
391
  }
381
392
  _ts_decorate([
382
- trackSpan('PublicProcessor.processTx', async (tx)=>({
383
- [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
393
+ trackSpan('PublicProcessor.processTx', (tx)=>({
394
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
384
395
  }))
385
396
  ], PublicProcessor.prototype, "processTx", null);
386
397
  _ts_decorate([
387
- trackSpan('PublicProcessor.processPrivateOnlyTx', async (tx)=>({
388
- [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
398
+ trackSpan('PublicProcessor.processPrivateOnlyTx', (tx)=>({
399
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
389
400
  }))
390
401
  ], PublicProcessor.prototype, "processPrivateOnlyTx", null);
391
402
  _ts_decorate([
392
- trackSpan('PublicProcessor.processTxWithPublicCalls', async (tx)=>({
393
- [Attributes.TX_HASH]: (await tx.getTxHash()).toString()
403
+ trackSpan('PublicProcessor.processTxWithPublicCalls', (tx)=>({
404
+ [Attributes.TX_HASH]: tx.getTxHash().toString()
394
405
  }))
395
406
  ], PublicProcessor.prototype, "processTxWithPublicCalls", null);
@@ -1,4 +1,4 @@
1
- import type { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
1
+ import type { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
2
2
  import type { Gas } from '@aztec/stdlib/gas';
3
3
  import type { TxExecutionPhase } from '@aztec/stdlib/tx';
4
4
  import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
@@ -21,7 +21,7 @@ export declare class PublicProcessorMetrics {
21
21
  recordAllTxs(totalGas: Gas, gasRate: number): void;
22
22
  recordFailedTx(): void;
23
23
  recordRevertedPhase(phaseName: TxExecutionPhase): void;
24
- recordClassRegistration(...events: ContractClassRegisteredEvent[]): void;
24
+ recordClassPublication(...events: ContractClassPublishedEvent[]): void;
25
25
  recordTreeInsertions(durationUs: number): void;
26
26
  }
27
27
  //# sourceMappingURL=public_processor_metrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public_processor_metrics.d.ts","sourceRoot":"","sources":["../../../src/public/public_processor/public_processor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,sBAAsB;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,YAAY,CAAgB;IAEpC,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,KAAK,CAAY;IAEzB,OAAO,CAAC,qBAAqB,C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D7D,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM;IAKnE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAc7D,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAkB3C,cAAc;IAMd,mBAAmB,CAAC,SAAS,EAAE,gBAAgB;IAI/C,sBAAsB,CAAC,GAAG,MAAM,EAAE,2BAA2B,EAAE;IAW/D,oBAAoB,CAAC,UAAU,EAAE,MAAM;CAGxC"}
@@ -110,7 +110,7 @@ export class PublicProcessorMetrics {
110
110
  [Attributes.OK]: false
111
111
  });
112
112
  }
113
- recordClassRegistration(...events) {
113
+ recordClassPublication(...events) {
114
114
  let totalBytecode = 0;
115
115
  for (const event of events){
116
116
  totalBytecode += event.packedPublicBytecode.length;
@@ -3,7 +3,7 @@ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import { AMMContractArtifact } from '@aztec/noir-contracts.js/AMM';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import { deployToken } from './token_test.js';
6
+ import { setUpToken } from './token_test.js';
7
7
  const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
8
8
  /**
9
9
  * THIS TEST IS BRITTLE! If it breaks, don't try fixing it.
@@ -14,9 +14,9 @@ const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
14
14
  const admin = AztecAddress.fromNumber(42);
15
15
  const sender = AztecAddress.fromNumber(111);
16
16
  logger.debug(`Deploying tokens`);
17
- const token0 = await deployToken(tester, admin, /*seed=*/ 0);
18
- const token1 = await deployToken(tester, admin, /*seed=*/ 1);
19
- const liquidityToken = await deployToken(tester, admin, /*seed=*/ 2);
17
+ const token0 = await setUpToken(tester, admin, /*seed=*/ 0);
18
+ const token1 = await setUpToken(tester, admin, /*seed=*/ 1);
19
+ const liquidityToken = await setUpToken(tester, admin, /*seed=*/ 2);
20
20
  logger.debug(`Deploying AMM`);
21
21
  const constructorArgs = [
22
22
  token0,
@@ -3,5 +3,5 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
4
  import { PublicTxSimulationTester } from '../../fixtures/public_tx_simulation_tester.js';
5
5
  export declare function tokenTest(tester: PublicTxSimulationTester, logger: Logger): Promise<void>;
6
- export declare function deployToken(tester: PublicTxSimulationTester, admin: AztecAddress, seed?: number): Promise<ContractInstanceWithAddress>;
6
+ export declare function setUpToken(tester: PublicTxSimulationTester, admin: AztecAddress, seed?: number): Promise<ContractInstanceWithAddress>;
7
7
  //# sourceMappingURL=token_test.d.ts.map
@@ -1 +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"}
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,UAAU,CAAC,MAAM,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,SAAI,wCAwB/F"}
@@ -6,7 +6,7 @@ export async function tokenTest(tester, logger) {
6
6
  const admin = AztecAddress.fromNumber(42);
7
7
  const sender = AztecAddress.fromNumber(111);
8
8
  const receiver = AztecAddress.fromNumber(222);
9
- const token = await deployToken(tester, admin);
9
+ const token = await setUpToken(tester, admin);
10
10
  const mintAmount = 100n;
11
11
  const mintResult = await tester.simulateTxWithLabel(/*txLabel=*/ 'Token/mint_to_public', /*sender=*/ admin, /*setupCalls=*/ [], /*appCalls=*/ [
12
12
  {
@@ -64,7 +64,7 @@ export async function tokenTest(tester, logger) {
64
64
  const endTime = performance.now();
65
65
  logger.info(`TokenContract public tx simulator test took ${endTime - startTime}ms\n`);
66
66
  }
67
- export async function deployToken(tester, admin, seed = 0) {
67
+ export async function setUpToken(tester, admin, seed = 0) {
68
68
  const constructorArgs = [
69
69
  admin,
70
70
  /*name=*/ 'Token',
@@ -15,7 +15,6 @@ export declare class MeasuredPublicTxSimulator extends PublicTxSimulator {
15
15
  protected readonly metrics: ExecutorMetricsInterface;
16
16
  constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations: boolean | undefined, skipFeeEnforcement: boolean | undefined, clientInitiatedSimulation: boolean | undefined, metrics: ExecutorMetricsInterface);
17
17
  simulate(tx: Tx, txLabel?: string): Promise<PublicTxResult>;
18
- protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
19
18
  protected insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<void>;
20
19
  protected insertRevertiblesFromPrivate(context: PublicTxContext, tx: Tx): Promise<boolean>;
21
20
  protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
@@ -1 +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,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,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,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,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;IAQ5D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBANpD,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,yBAAyB,EAAE,OAAO,YAAQ,EACvB,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,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAsCnC"}
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,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,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,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,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;IAQ5D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB;gBANpD,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,kBAAkB,EAAE,OAAO,YAAQ,EACnC,yBAAyB,EAAE,OAAO,YAAQ,EACvB,OAAO,EAAE,wBAAwB;IAKhC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,GAAE,MAAsB,GAAG,OAAO,CAAC,cAAc,CAAC;cAWvE,+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,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAsCnC"}
@@ -17,12 +17,6 @@ import { PublicTxSimulator } from './public_tx_simulator.js';
17
17
  }
18
18
  return avmResult;
19
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
20
  async insertNonRevertiblesFromPrivate(context, tx) {
27
21
  const timer = new Timer();
28
22
  await super.insertNonRevertiblesFromPrivate(context, tx);
@@ -41,7 +41,7 @@ export declare class PublicTxContext {
41
41
  * All phases have been processed.
42
42
  * Actual transaction fee and actual total consumed gas can now be queried.
43
43
  */
44
- halt(): Promise<void>;
44
+ halt(): void;
45
45
  /**
46
46
  * Revert execution a phase. Populate revertReason & revertCode.
47
47
  * If in setup, throw an error (transaction will be thrown out).
@@ -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;AAE9C,OAAO,EAGL,sBAAsB,EAEtB,UAAU,EAEX,MAAM,mBAAmB,CAAC;AAC3B,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,8BAA8B,EAI/B,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,eAAe,EACpB,6BAA6B,EAE7B,KAAK,EAAE,EACP,gBAAgB,EAChB,KAAK,MAAM,EACZ,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF;;GAEG;AACH,qBAAa,eAAe;aAeR,MAAM,EAAE,MAAM;aACd,KAAK,EAAE,iBAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,4BAA4B;IAC7C,OAAO,CAAC,QAAQ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GAAG,EAAE,GAAG;IAQ5C;;;OAGG;IACH,eAAe,IAAI,GAAG;IAItB;;;;;OAKG;IACH,gBAAgB,IAAI,GAAG;IAOvB;;;OAGG;IACH,sBAAsB,IAAI,GAAG;IAK7B;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,EAAE;IAQ9C;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAa/B;;OAEG;IACU,8BAA8B,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAuH/E;AAED;;;;;;;;;GASG;AACH,cAAM,iBAAiB;IAKT,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJ3C,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,2BAA2B,CAA4C;gBAElD,cAAc,EAAE,6BAA6B;IAIpE,IAAI;IAMV,qBAAqB;IAIrB,QAAQ;IAIF,gBAAgB;IAQhB,kBAAkB;CAOzB"}
@@ -75,16 +75,14 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
75
75
  const clampedGasSettings = clampGasSettingsForAVM(gasSettings, gasUsedByPrivate);
76
76
  const gasAllocatedToPublic = clampedGasSettings.gasLimits.sub(gasUsedByPrivate);
77
77
  const gasAllocatedToPublicTeardown = clampedGasSettings.teardownGasLimits;
78
- return new PublicTxContext(await tx.getTxHash(), new PhaseStateManager(txStateManager), await txStateManager.getTreeSnapshots(), globalVariables, gasSettings, clampedGasSettings, gasUsedByPrivate, gasAllocatedToPublic, gasAllocatedToPublicTeardown, getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace);
78
+ return new PublicTxContext(tx.getTxHash(), new PhaseStateManager(txStateManager), await txStateManager.getTreeSnapshots(), globalVariables, gasSettings, clampedGasSettings, gasUsedByPrivate, gasAllocatedToPublic, gasAllocatedToPublicTeardown, getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace);
79
79
  }
80
80
  /**
81
81
  * Signal that the entire transaction execution is done.
82
82
  * All phases have been processed.
83
83
  * Actual transaction fee and actual total consumed gas can now be queried.
84
- */ async halt() {
85
- if (this.state.isForked()) {
86
- await this.state.mergeForkedState();
87
- }
84
+ */ halt() {
85
+ assert(!this.state.isForked(), 'Cannot halt when state is forked');
88
86
  this.halted = true;
89
87
  }
90
88
  /**
@@ -100,11 +98,6 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
100
98
  }
101
99
  if (phase === TxExecutionPhase.SETUP) {
102
100
  this.log.warn(`Setup phase reverted! The transaction will be thrown out.`);
103
- if (revertReason) {
104
- throw revertReason;
105
- } else {
106
- throw new Error(`Setup phase reverted! The transaction will be thrown out. ${culprit} failed`);
107
- }
108
101
  } else if (phase === TxExecutionPhase.APP_LOGIC) {
109
102
  this.revertCode = RevertCode.APP_LOGIC_REVERTED;
110
103
  } else if (phase === TxExecutionPhase.TEARDOWN) {
@@ -237,6 +230,8 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
237
230
  }
238
231
  return Array.from(squashedPublicDataWrites.entries()).map(([slot, value])=>new PublicDataWrite(new Fr(slot), value));
239
232
  })();
233
+ // Count before padding.
234
+ const accumulatedDataArrayLengths = new AvmAccumulatedDataArrayLengths(avmNoteHashes.length, avmNullifiers.length, avmL2ToL1Msgs.length, finalPublicLogs.length, finalPublicDataWrites.length);
240
235
  const accumulatedData = new AvmAccumulatedData(/*noteHashes=*/ padArrayEnd(avmNoteHashes.map((n)=>n.value), Fr.zero(), MAX_NOTE_HASHES_PER_TX), /*nullifiers=*/ padArrayEnd(avmNullifiers.map((n)=>n.value), Fr.zero(), MAX_NULLIFIERS_PER_TX), /*l2ToL1Msgs=*/ padArrayEnd(avmL2ToL1Msgs, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX), /*publicLogs=*/ padArrayEnd(finalPublicLogs, PublicLog.empty(), MAX_PUBLIC_LOGS_PER_TX), /*publicDataWrites=*/ padArrayEnd(finalPublicDataWrites, PublicDataWrite.empty(), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX));
241
236
  // Now we finally have enough information to pad the trees.
242
237
  // NOTE(fcarreiro): a bit weird that a method that generates the PIs does this,
@@ -249,8 +244,7 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
249
244
  // This converts the private accumulated data to the avm accumulated data format.
250
245
  const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
251
246
  const getPreviousAccumulatedDataArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
252
- const getAvmAccumulatedDataArrayLengths = (from)=>new AvmAccumulatedDataArrayLengths(from.noteHashes.length, from.nullifiers.length, from.l2ToL1Msgs.length, from.publicLogs.length, from.publicDataWrites.length);
253
- return new AvmCircuitPublicInputs(this.globalVariables, this.startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.clampedGasSettings, computeEffectiveGasFees(this.globalVariables.gasFees, this.gasSettings), this.feePayer, /*publicCallRequestArrayLengths=*/ new PublicCallRequestArrayLengths(this.setupCallRequests.length, this.appLogicCallRequests.length, this.teardownCallRequests.length > 0), /*publicSetupCallRequests=*/ padArrayEnd(this.setupCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicAppLogicCallRequests=*/ padArrayEnd(this.appLogicCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicTeardownCallRequests=*/ this.teardownCallRequests.length > 0 ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), getPreviousAccumulatedDataArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate), getPreviousAccumulatedDataArrayLengths(this.revertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate), endTreeSnapshots, this.getTotalGasUsed(), getAvmAccumulatedDataArrayLengths(accumulatedData), accumulatedData, /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*isReverted=*/ !this.revertCode.isOK());
247
+ return new AvmCircuitPublicInputs(this.globalVariables, this.startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.clampedGasSettings, computeEffectiveGasFees(this.globalVariables.gasFees, this.gasSettings), this.feePayer, /*publicCallRequestArrayLengths=*/ new PublicCallRequestArrayLengths(this.setupCallRequests.length, this.appLogicCallRequests.length, this.teardownCallRequests.length > 0), /*publicSetupCallRequests=*/ padArrayEnd(this.setupCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicAppLogicCallRequests=*/ padArrayEnd(this.appLogicCallRequests.map((r)=>r.request), PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), /*publicTeardownCallRequests=*/ this.teardownCallRequests.length > 0 ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), getPreviousAccumulatedDataArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate), getPreviousAccumulatedDataArrayLengths(this.revertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate), convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate), endTreeSnapshots, this.getTotalGasUsed(), accumulatedDataArrayLengths, accumulatedData, /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*isReverted=*/ !this.revertCode.isOK());
254
248
  }
255
249
  }
256
250
  /**
@@ -40,31 +40,12 @@ export declare class PublicTxSimulator {
40
40
  * @returns The result of the transaction's public execution.
41
41
  */
42
42
  simulate(tx: Tx): Promise<PublicTxResult>;
43
- protected computeTxHash(tx: Tx): Promise<import("@aztec/stdlib/tx").TxHash>;
43
+ protected computeTxHash(tx: Tx): import("@aztec/stdlib/tx").TxHash;
44
44
  /**
45
45
  * Simulate the setup phase of a transaction's public execution.
46
46
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
47
47
  * @returns The phase result.
48
48
  */
49
- private simulateSetupPhase;
50
- /**
51
- * Simulate the app logic phase of a transaction's public execution.
52
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
53
- * @returns The phase result.
54
- */
55
- private simulateAppLogicPhase;
56
- /**
57
- * Simulate the teardown phase of a transaction's public execution.
58
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
59
- * @returns The phase result.
60
- */
61
- private simulateTeardownPhase;
62
- /**
63
- * Simulate a phase of a transaction's public execution.
64
- * @param phase - The current phase
65
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
66
- * @returns The phase result.
67
- */
68
49
  protected simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase>;
69
50
  /**
70
51
  * Simulate an enqueued public call.
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,iBAAiB,EAEtB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MA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AAe,EACnC,yBAAyB,GAAE,OAAe;IAKpD;;;;OAIG;IACU,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;cA+EtC,aAAa,CAAC,EAAE,EAAE,EAAE;IAIpC;;;;OAIG;YACW,kBAAkB;IAIhC;;;;OAIG;YACW,qBAAqB;IAkBnC;;;;OAIG;YACW,qBAAqB;IAoBnC;;;;;OAKG;cACa,aAAa,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAqCzG;;;;;;OAMG;cACa,oBAAoB,CAClC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;IA6BlC;;;;;;;;;;;;OAYG;cACa,4BAA4B,CAC1C,YAAY,EAAE,6BAA6B,EAC3C,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,6BAA6B,EACpD,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;IAuBlC;;OAEG;cACa,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;IAiChF;;;OAGG;cACa,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,GAAgB,OAAO,CAAC,OAAO,CAAC;YA2C/F,MAAM;IAgCpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAStC"}
1
+ {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,iBAAiB,EA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AE,MAAM,CAAC;gBAGZ,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,OAAe,EACnC,kBAAkB,GAAE,OAAe,EACnC,yBAAyB,GAAE,OAAe;IAKpD;;;;OAIG;IACU,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAgHtD,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE;IAI9B;;;;OAIG;cACa,aAAa,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAqCzG;;;;;;OAMG;cACa,oBAAoB,CAClC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;IA6BlC;;;;;;;;;;;;OAYG;cACa,4BAA4B,CAC1C,YAAY,EAAE,6BAA6B,EAC3C,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,6BAA6B,EACpD,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;IAuBlC;;OAEG;cACa,+BAA+B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;IA0BhF;;;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"}
@@ -5,12 +5,10 @@ import { AvmCircuitInputs, AvmExecutionHints, AvmTxHint } from '@aztec/stdlib/av
5
5
  import { SimulationError } from '@aztec/stdlib/errors';
6
6
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
7
7
  import { NestedProcessReturnValues, TxExecutionPhase } from '@aztec/stdlib/tx';
8
- import { strict as assert } from 'assert';
9
8
  import { AvmSimulator } from '../avm/index.js';
10
9
  import { getPublicFunctionDebugName } from '../debug_fn_name.js';
11
10
  import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
12
11
  import { PublicTreesDB } from '../public_db_sources.js';
13
- import { NullifierCollisionError } from '../state_manager/nullifiers.js';
14
12
  import { PublicTxContext } from './public_tx_context.js';
15
13
  export class PublicTxSimulator {
16
14
  merkleTree;
@@ -35,37 +33,66 @@ export class PublicTxSimulator {
35
33
  * @returns The result of the transaction's public execution.
36
34
  */ async simulate(tx) {
37
35
  try {
38
- const txHash = await this.computeTxHash(tx);
36
+ const txHash = this.computeTxHash(tx);
39
37
  this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
40
38
  txHash
41
39
  });
42
40
  // Create hinting DBs.
43
- const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
41
+ const hints = new AvmExecutionHints(this.globalVariables, AvmTxHint.fromTx(tx));
44
42
  const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
45
43
  const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
46
44
  const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
47
45
  const context = await PublicTxContext.create(hintingTreesDB, hintingContractsDB, tx, this.globalVariables, this.doMerkleOperations);
46
+ // This will throw if there is a nullifier collision.
47
+ // In that case the transaction will be thrown out.
48
48
  await this.insertNonRevertiblesFromPrivate(context, tx);
49
49
  const processedPhases = [];
50
50
  if (context.hasPhase(TxExecutionPhase.SETUP)) {
51
- const setupResult = await this.simulateSetupPhase(context);
51
+ // This will throw if the setup phase reverts.
52
+ // In that case the transaction will be thrown out.
53
+ const setupResult = await this.simulatePhase(TxExecutionPhase.SETUP, context);
54
+ if (setupResult.reverted) {
55
+ throw new Error(`Setup phase reverted! The transaction will be thrown out. ${setupResult.revertReason?.message}`);
56
+ }
52
57
  processedPhases.push(setupResult);
53
58
  }
54
- const success = await this.insertRevertiblesFromPrivate(context, tx);
55
- if (success) {
56
- // Only proceed with app logic if there was no revert during revertible insertion
59
+ // The checkpoint we should go back to if anything from now on reverts.
60
+ await context.state.fork();
61
+ try {
62
+ // This will throw if there is a nullifier collision.
63
+ await this.insertRevertiblesFromPrivate(context, tx);
64
+ // Only proceed with app logic if there was no revert during revertible insertion.
57
65
  if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
58
- const appLogicResult = await this.simulateAppLogicPhase(context);
66
+ const appLogicResult = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
59
67
  processedPhases.push(appLogicResult);
68
+ if (appLogicResult.reverted) {
69
+ throw new Error(`App logic phase reverted! ${appLogicResult.revertReason?.message}`);
70
+ }
60
71
  }
61
- } else {
62
- this.log.debug(`Revertible insertions failed. Skipping app logic.`);
72
+ } catch (e) {
73
+ this.log.debug(String(e));
74
+ // We revert to the post-setup state.
75
+ await context.state.discardForkedState();
76
+ // But we also create a new fork so that the teardown phase can transparently
77
+ // commit or rollback at the end of teardown.
78
+ await context.state.fork();
63
79
  }
64
- if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
65
- const teardownResult = await this.simulateTeardownPhase(context);
66
- processedPhases.push(teardownResult);
80
+ try {
81
+ if (context.hasPhase(TxExecutionPhase.TEARDOWN)) {
82
+ const teardownResult = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
83
+ processedPhases.push(teardownResult);
84
+ if (teardownResult.reverted) {
85
+ throw new Error(`Teardown phase reverted! ${teardownResult.revertReason?.message}`);
86
+ }
87
+ }
88
+ // We commit the forked state and we are done.
89
+ await context.state.mergeForkedState();
90
+ } catch (e) {
91
+ this.log.debug(String(e));
92
+ // We rollback to the post-setup state.
93
+ await context.state.discardForkedState();
67
94
  }
68
- await context.halt();
95
+ context.halt();
69
96
  await this.payFee(context);
70
97
  const publicInputs = await context.generateAvmCircuitPublicInputs();
71
98
  const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, hints);
@@ -96,59 +123,13 @@ export class PublicTxSimulator {
96
123
  this.contractsDB.clearContractsForTx();
97
124
  }
98
125
  }
99
- async computeTxHash(tx) {
100
- return await tx.getTxHash();
126
+ computeTxHash(tx) {
127
+ return tx.getTxHash();
101
128
  }
102
129
  /**
103
130
  * Simulate the setup phase of a transaction's public execution.
104
131
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
105
132
  * @returns The phase result.
106
- */ async simulateSetupPhase(context) {
107
- return await this.simulatePhase(TxExecutionPhase.SETUP, context);
108
- }
109
- /**
110
- * Simulate the app logic phase of a transaction's public execution.
111
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
112
- * @returns The phase result.
113
- */ async simulateAppLogicPhase(context) {
114
- assert(context.state.isForked(), 'App logic phase should operate with forked state.');
115
- const result = await this.simulatePhase(TxExecutionPhase.APP_LOGIC, context);
116
- if (result.reverted) {
117
- // Drop the currently active forked state manager and rollback to end of setup.
118
- await context.state.discardForkedState();
119
- } else {
120
- if (!context.hasPhase(TxExecutionPhase.TEARDOWN)) {
121
- // Nothing to do after this (no teardown), so merge state updates now instead of letting teardown handle it.
122
- await context.state.mergeForkedState();
123
- }
124
- }
125
- return result;
126
- }
127
- /**
128
- * Simulate the teardown phase of a transaction's public execution.
129
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
130
- * @returns The phase result.
131
- */ async simulateTeardownPhase(context) {
132
- if (!context.state.isForked()) {
133
- // If state isn't forked (app logic reverted), fork now
134
- // so we can rollback to the end of setup if teardown reverts.
135
- await context.state.fork();
136
- }
137
- const result = await this.simulatePhase(TxExecutionPhase.TEARDOWN, context);
138
- if (result.reverted) {
139
- // Drop the currently active forked state manager and rollback to end of setup.
140
- await context.state.discardForkedState();
141
- } else {
142
- // Merge state updates from teardown,
143
- await context.state.mergeForkedState();
144
- }
145
- return result;
146
- }
147
- /**
148
- * Simulate a phase of a transaction's public execution.
149
- * @param phase - The current phase
150
- * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
151
- * @returns The phase result.
152
133
  */ async simulatePhase(phase, context) {
153
134
  const callRequests = context.getCallRequestsForPhase(phase);
154
135
  this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
@@ -195,7 +176,7 @@ export class PublicTxSimulator {
195
176
  this.log.debug(`Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`);
196
177
  if (result.reverted) {
197
178
  const culprit = `${contractAddress}:${callRequest.functionSelector}`;
198
- context.revert(phase, result.revertReason, culprit); // throws if in setup (non-revertible) phase
179
+ context.revert(phase, result.revertReason, culprit);
199
180
  }
200
181
  return result;
201
182
  }
@@ -223,14 +204,8 @@ export class PublicTxSimulator {
223
204
  * Insert the non-revertible accumulated data from private into the public state.
224
205
  */ async insertNonRevertiblesFromPrivate(context, tx) {
225
206
  const stateManager = context.state.getActiveStateManager();
226
- try {
227
- for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
228
- await stateManager.writeSiloedNullifier(siloedNullifier);
229
- }
230
- } catch (e) {
231
- if (e instanceof NullifierCollisionError) {
232
- throw new NullifierCollisionError(`Nullifier collision encountered when inserting non-revertible nullifiers from private.\nDetails: ${e.message}\nStack:${e.stack}`);
233
- }
207
+ for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
208
+ await stateManager.writeSiloedNullifier(siloedNullifier);
234
209
  }
235
210
  for (const noteHash of context.nonRevertibleAccumulatedDataFromPrivate.noteHashes){
236
211
  if (!noteHash.isEmpty()) {
@@ -252,21 +227,14 @@ export class PublicTxSimulator {
252
227
  * Insert the revertible accumulated data from private into the public state.
253
228
  * Start by forking state so we can rollback to the end of setup if app logic or teardown reverts.
254
229
  */ async insertRevertiblesFromPrivate(context, tx) {
255
- // Fork the state manager so we can rollback to end of setup if app logic reverts.
256
- await context.state.fork();
257
230
  const stateManager = context.state.getActiveStateManager();
258
231
  try {
259
232
  for (const siloedNullifier of context.revertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
260
233
  await stateManager.writeSiloedNullifier(siloedNullifier);
261
234
  }
262
235
  } catch (e) {
263
- if (e instanceof NullifierCollisionError) {
264
- // Instead of throwing, revert the app_logic phase
265
- context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Nullifier collision encountered when inserting revertible nullifiers from private\nDetails: ${e.message}\nError stack: ${e.stack}`, []), /*culprit=*/ 'insertRevertiblesFromPrivate');
266
- return /*success=*/ false;
267
- } else {
268
- throw e;
269
- }
236
+ context.revert(TxExecutionPhase.APP_LOGIC, new SimulationError(`Nullifier collision encountered when inserting revertible nullifiers from private.\nDetails: ${String(e)}`, []));
237
+ throw e;
270
238
  }
271
239
  for (const noteHash of context.revertibleAccumulatedDataFromPrivate.noteHashes){
272
240
  if (!noteHash.isEmpty()) {
@@ -1 +1 @@
1
- {"version":3,"file":"side_effect_trace.d.ts","sourceRoot":"","sources":["../../src/public/side_effect_trace.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAiB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAK7E,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;IAII;AACJ,MAAM,MAAM,WAAW,GAAG;IACxB,gBAAgB,EAAE,uBA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