@aztec/simulator 0.67.1-devnet → 0.68.0

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 (34) hide show
  1. package/dest/providers/acvm_wasm_with_blobs.d.ts +7 -0
  2. package/dest/providers/acvm_wasm_with_blobs.d.ts.map +1 -0
  3. package/dest/providers/acvm_wasm_with_blobs.js +15 -0
  4. package/dest/providers/index.d.ts +1 -0
  5. package/dest/providers/index.d.ts.map +1 -1
  6. package/dest/providers/index.js +2 -1
  7. package/dest/public/executor_metrics.d.ts +2 -0
  8. package/dest/public/executor_metrics.d.ts.map +1 -1
  9. package/dest/public/executor_metrics.js +11 -1
  10. package/dest/public/fixtures/index.d.ts +7 -6
  11. package/dest/public/fixtures/index.d.ts.map +1 -1
  12. package/dest/public/fixtures/index.js +21 -15
  13. package/dest/public/public_processor.d.ts +2 -1
  14. package/dest/public/public_processor.d.ts.map +1 -1
  15. package/dest/public/public_processor.js +15 -5
  16. package/dest/public/public_processor_metrics.d.ts +9 -1
  17. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  18. package/dest/public/public_processor_metrics.js +49 -2
  19. package/dest/public/public_tx_context.d.ts +5 -0
  20. package/dest/public/public_tx_context.d.ts.map +1 -1
  21. package/dest/public/public_tx_context.js +9 -1
  22. package/dest/public/public_tx_simulator.d.ts +2 -1
  23. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  24. package/dest/public/public_tx_simulator.js +24 -6
  25. package/package.json +12 -12
  26. package/src/providers/acvm_wasm.ts +1 -1
  27. package/src/providers/acvm_wasm_with_blobs.ts +25 -0
  28. package/src/providers/index.ts +1 -0
  29. package/src/public/executor_metrics.ts +13 -0
  30. package/src/public/fixtures/index.ts +28 -20
  31. package/src/public/public_processor.ts +15 -1
  32. package/src/public/public_processor_metrics.ts +63 -1
  33. package/src/public/public_tx_context.ts +9 -0
  34. package/src/public/public_tx_simulator.ts +23 -6
@@ -1,7 +1,9 @@
1
1
  import { type TxExecutionPhase } from '@aztec/circuit-types';
2
+ import { type Gas } from '@aztec/circuits.js';
2
3
  import { type ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
3
4
  import {
4
5
  Attributes,
6
+ type Gauge,
5
7
  type Histogram,
6
8
  Metrics,
7
9
  type TelemetryClient,
@@ -21,6 +23,12 @@ export class PublicProcessorMetrics {
21
23
  private phaseCount: UpDownCounter;
22
24
 
23
25
  private bytecodeDeployed: Histogram;
26
+ private totalGas: Gauge;
27
+ private totalGasHistogram: Histogram;
28
+ private gasRate: Histogram;
29
+ private txGas: Histogram;
30
+
31
+ private treeInsertionDuration: Histogram;
24
32
 
25
33
  constructor(client: TelemetryClient, name = 'PublicProcessor') {
26
34
  this.tracer = client.getTracer(name);
@@ -54,6 +62,32 @@ export class PublicProcessorMetrics {
54
62
  description: 'Size of deployed bytecode',
55
63
  unit: 'By',
56
64
  });
65
+
66
+ this.totalGas = meter.createGauge(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS, {
67
+ description: 'Total gas used in block',
68
+ unit: 'gas',
69
+ });
70
+
71
+ this.totalGasHistogram = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TOTAL_GAS_HISTOGRAM, {
72
+ description: 'Total gas used in block as histogram',
73
+ unit: 'gas/block',
74
+ });
75
+
76
+ this.txGas = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TX_GAS, {
77
+ description: 'Gas used in transaction',
78
+ unit: 'gas/tx',
79
+ });
80
+
81
+ this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE, {
82
+ description: 'L2 gas per second for complete block',
83
+ unit: 'gas/s',
84
+ });
85
+
86
+ this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION, {
87
+ description: 'How long it takes for tree insertion',
88
+ unit: 'us',
89
+ valueType: ValueType.INT,
90
+ });
57
91
  }
58
92
 
59
93
  recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
@@ -61,12 +95,36 @@ export class PublicProcessorMetrics {
61
95
  this.phaseDuration.record(Math.ceil(durationMs), { [Attributes.TX_PHASE_NAME]: phaseName });
62
96
  }
63
97
 
64
- recordTx(phaseCount: number, durationMs: number) {
98
+ recordTx(phaseCount: number, durationMs: number, gasUsed: Gas) {
65
99
  this.txPhaseCount.add(phaseCount);
66
100
  this.txDuration.record(Math.ceil(durationMs));
67
101
  this.txCount.add(1, {
68
102
  [Attributes.OK]: true,
69
103
  });
104
+ this.txGas.record(gasUsed.daGas, {
105
+ [Attributes.GAS_DIMENSION]: 'DA',
106
+ });
107
+ this.txGas.record(gasUsed.l2Gas, {
108
+ [Attributes.GAS_DIMENSION]: 'L2',
109
+ });
110
+ }
111
+
112
+ recordAllTxs(totalGas: Gas, gasRate: number) {
113
+ this.totalGas.record(totalGas.daGas, {
114
+ [Attributes.GAS_DIMENSION]: 'DA',
115
+ });
116
+ this.totalGas.record(totalGas.l2Gas, {
117
+ [Attributes.GAS_DIMENSION]: 'L2',
118
+ });
119
+ this.gasRate.record(gasRate, {
120
+ [Attributes.GAS_DIMENSION]: 'L2',
121
+ });
122
+ this.totalGasHistogram.record(totalGas.daGas, {
123
+ [Attributes.GAS_DIMENSION]: 'DA',
124
+ });
125
+ this.totalGasHistogram.record(totalGas.l2Gas, {
126
+ [Attributes.GAS_DIMENSION]: 'L2',
127
+ });
70
128
  }
71
129
 
72
130
  recordFailedTx() {
@@ -89,4 +147,8 @@ export class PublicProcessorMetrics {
89
147
  this.bytecodeDeployed.record(totalBytecode);
90
148
  }
91
149
  }
150
+
151
+ recordTreeInsertions(durationUs: number) {
152
+ this.treeInsertionDuration.record(Math.ceil(durationUs));
153
+ }
92
154
  }
@@ -282,6 +282,15 @@ export class PublicTxContext {
282
282
  return this.getTotalGasUsed().sub(teardownGasLimits).add(this.teardownGasUsed);
283
283
  }
284
284
 
285
+ /**
286
+ * Compute the public gas used using the actual gas used during teardown instead
287
+ * of the teardown gas limit.
288
+ */
289
+ getActualPublicGasUsed(): Gas {
290
+ assert(this.halted, 'Can only compute actual gas used after tx execution ends');
291
+ return this.gasUsedByPublic.add(this.teardownGasUsed);
292
+ }
293
+
285
294
  /**
286
295
  * Get the transaction fee as is available to the specified phase.
287
296
  * Only teardown should have access to the actual transaction fee.
@@ -56,6 +56,7 @@ export class PublicTxSimulator {
56
56
  telemetryClient: TelemetryClient,
57
57
  private globalVariables: GlobalVariables,
58
58
  private doMerkleOperations: boolean = false,
59
+ private enforceFeePayment: boolean = true,
59
60
  ) {
60
61
  this.log = createLogger(`simulator:public_tx_simulator`);
61
62
  this.metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
@@ -90,14 +91,20 @@ export class PublicTxSimulator {
90
91
  // FIXME: we shouldn't need to directly modify worldStateDb here!
91
92
  await this.worldStateDB.addNewContracts(tx);
92
93
 
94
+ const nonRevertStart = process.hrtime.bigint();
93
95
  await this.insertNonRevertiblesFromPrivate(context);
96
+ const nonRevertEnd = process.hrtime.bigint();
97
+ this.metrics.recordPrivateEffectsInsertion(Number(nonRevertEnd - nonRevertStart) / 1_000, 'non-revertible');
94
98
  const processedPhases: ProcessedPhase[] = [];
95
99
  if (context.hasPhase(TxExecutionPhase.SETUP)) {
96
100
  const setupResult: ProcessedPhase = await this.simulateSetupPhase(context);
97
101
  processedPhases.push(setupResult);
98
102
  }
99
103
 
104
+ const revertStart = process.hrtime.bigint();
100
105
  await this.insertRevertiblesFromPrivate(context);
106
+ const revertEnd = process.hrtime.bigint();
107
+ this.metrics.recordPrivateEffectsInsertion(Number(revertEnd - revertStart) / 1_000, 'revertible');
101
108
  if (context.hasPhase(TxExecutionPhase.APP_LOGIC)) {
102
109
  const appLogicResult: ProcessedPhase = await this.simulateAppLogicPhase(context);
103
110
  processedPhases.push(appLogicResult);
@@ -134,7 +141,11 @@ export class PublicTxSimulator {
134
141
 
135
142
  return {
136
143
  avmProvingRequest,
137
- gasUsed: { totalGas: context.getActualGasUsed(), teardownGas: context.teardownGasUsed },
144
+ gasUsed: {
145
+ totalGas: context.getActualGasUsed(),
146
+ teardownGas: context.teardownGasUsed,
147
+ publicGas: context.getActualPublicGasUsed(),
148
+ },
138
149
  revertCode,
139
150
  revertReason: context.revertReason,
140
151
  processedPhases: processedPhases,
@@ -344,7 +355,7 @@ export class PublicTxSimulator {
344
355
  const avmCallResult = await simulator.execute();
345
356
  const result = avmCallResult.finalize();
346
357
 
347
- this.log.debug(
358
+ this.log.verbose(
348
359
  result.reverted
349
360
  ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason}.`
350
361
  : `Simulation of enqueued public call ${fnName} completed successfully.`,
@@ -424,12 +435,18 @@ export class PublicTxSimulator {
424
435
  this.log.debug(`Deducting ${txFee.toBigInt()} balance in Fee Juice for ${context.feePayer}`);
425
436
  const stateManager = context.state.getActiveStateManager();
426
437
 
427
- const currentBalance = await stateManager.readStorage(feeJuiceAddress, balanceSlot);
438
+ let currentBalance = await stateManager.readStorage(feeJuiceAddress, balanceSlot);
439
+ // We allow to fake the balance of the fee payer to allow fee estimation
440
+ // When mocking the balance of the fee payer, the circuit should not be able to prove the simulation
428
441
 
429
442
  if (currentBalance.lt(txFee)) {
430
- throw new Error(
431
- `Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
432
- );
443
+ if (this.enforceFeePayment) {
444
+ throw new Error(
445
+ `Not enough balance for fee payer to pay for transaction (got ${currentBalance.toBigInt()} needs ${txFee.toBigInt()})`,
446
+ );
447
+ } else {
448
+ currentBalance = txFee;
449
+ }
433
450
  }
434
451
 
435
452
  const updatedBalance = currentBalance.sub(txFee);