@aztec/simulator 0.38.0 → 0.39.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 (131) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +1 -1
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +8 -23
  4. package/dest/acvm/oracle/typed_oracle.d.ts +2 -3
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +4 -7
  7. package/dest/avm/avm_execution_environment.d.ts +4 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +17 -11
  10. package/dest/avm/avm_gas.d.ts.map +1 -1
  11. package/dest/avm/avm_gas.js +3 -1
  12. package/dest/avm/avm_machine_state.d.ts +5 -8
  13. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  14. package/dest/avm/avm_machine_state.js +10 -22
  15. package/dest/avm/avm_message_call_result.d.ts +5 -8
  16. package/dest/avm/avm_message_call_result.d.ts.map +1 -1
  17. package/dest/avm/avm_message_call_result.js +1 -4
  18. package/dest/avm/avm_simulator.d.ts.map +1 -1
  19. package/dest/avm/avm_simulator.js +17 -13
  20. package/dest/avm/errors.d.ts +43 -2
  21. package/dest/avm/errors.d.ts.map +1 -1
  22. package/dest/avm/errors.js +86 -4
  23. package/dest/avm/journal/journal.d.ts.map +1 -1
  24. package/dest/avm/journal/journal.js +4 -3
  25. package/dest/avm/opcodes/conversion.d.ts +16 -0
  26. package/dest/avm/opcodes/conversion.d.ts.map +1 -0
  27. package/dest/avm/opcodes/conversion.js +48 -0
  28. package/dest/avm/opcodes/environment_getters.d.ts +12 -13
  29. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  30. package/dest/avm/opcodes/environment_getters.js +13 -49
  31. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  32. package/dest/avm/opcodes/external_calls.js +11 -1
  33. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  34. package/dest/avm/serialization/bytecode_serialization.js +4 -1
  35. package/dest/avm/serialization/instruction_serialization.d.ts +2 -1
  36. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  37. package/dest/avm/serialization/instruction_serialization.js +3 -1
  38. package/dest/client/client_execution_context.d.ts +28 -1
  39. package/dest/client/client_execution_context.d.ts.map +1 -1
  40. package/dest/client/client_execution_context.js +50 -15
  41. package/dest/client/db_oracle.d.ts +1 -8
  42. package/dest/client/db_oracle.d.ts.map +1 -1
  43. package/dest/client/execution_result.d.ts +4 -1
  44. package/dest/client/execution_result.d.ts.map +1 -1
  45. package/dest/client/execution_result.js +16 -3
  46. package/dest/client/private_execution.d.ts.map +1 -1
  47. package/dest/client/private_execution.js +3 -1
  48. package/dest/client/simulator.d.ts +1 -31
  49. package/dest/client/simulator.d.ts.map +1 -1
  50. package/dest/client/simulator.js +3 -42
  51. package/dest/client/view_data_oracle.d.ts +0 -7
  52. package/dest/client/view_data_oracle.d.ts.map +1 -1
  53. package/dest/client/view_data_oracle.js +1 -10
  54. package/dest/common/errors.d.ts +5 -0
  55. package/dest/common/errors.d.ts.map +1 -1
  56. package/dest/common/errors.js +6 -1
  57. package/dest/index.d.ts +1 -0
  58. package/dest/index.d.ts.map +1 -1
  59. package/dest/index.js +2 -1
  60. package/dest/public/abstract_phase_manager.d.ts +8 -4
  61. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  62. package/dest/public/abstract_phase_manager.js +38 -14
  63. package/dest/public/app_logic_phase_manager.d.ts +1 -0
  64. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  65. package/dest/public/app_logic_phase_manager.js +3 -3
  66. package/dest/public/executor.d.ts.map +1 -1
  67. package/dest/public/executor.js +1 -4
  68. package/dest/public/hints_builder.d.ts +3 -3
  69. package/dest/public/hints_builder.d.ts.map +1 -1
  70. package/dest/public/hints_builder.js +3 -3
  71. package/dest/public/public_processor.d.ts.map +1 -1
  72. package/dest/public/public_processor.js +5 -3
  73. package/dest/public/setup_phase_manager.d.ts +1 -0
  74. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  75. package/dest/public/setup_phase_manager.js +3 -2
  76. package/dest/public/tail_phase_manager.d.ts +1 -0
  77. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  78. package/dest/public/tail_phase_manager.js +2 -1
  79. package/dest/public/teardown_phase_manager.d.ts +1 -0
  80. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  81. package/dest/public/teardown_phase_manager.js +3 -2
  82. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  83. package/dest/public/transitional_adaptors.js +1 -1
  84. package/dest/rollup/index.d.ts +2 -0
  85. package/dest/rollup/index.d.ts.map +1 -0
  86. package/dest/rollup/index.js +2 -0
  87. package/dest/rollup/rollup.d.ts +77 -0
  88. package/dest/rollup/rollup.d.ts.map +1 -0
  89. package/dest/rollup/rollup.js +78 -0
  90. package/dest/stats/index.d.ts +2 -0
  91. package/dest/stats/index.d.ts.map +1 -0
  92. package/dest/stats/index.js +2 -0
  93. package/dest/stats/stats.d.ts +4 -0
  94. package/dest/stats/stats.d.ts.map +1 -0
  95. package/dest/stats/stats.js +11 -0
  96. package/package.json +8 -8
  97. package/src/acvm/oracle/oracle.ts +23 -27
  98. package/src/acvm/oracle/typed_oracle.ts +12 -9
  99. package/src/avm/avm_execution_environment.ts +34 -42
  100. package/src/avm/avm_gas.ts +2 -0
  101. package/src/avm/avm_machine_state.ts +14 -25
  102. package/src/avm/avm_message_call_result.ts +3 -14
  103. package/src/avm/avm_simulator.ts +22 -12
  104. package/src/avm/errors.ts +94 -4
  105. package/src/avm/journal/journal.ts +3 -2
  106. package/src/avm/opcodes/conversion.ts +59 -0
  107. package/src/avm/opcodes/environment_getters.ts +13 -66
  108. package/src/avm/opcodes/external_calls.ts +11 -0
  109. package/src/avm/serialization/bytecode_serialization.ts +3 -0
  110. package/src/avm/serialization/instruction_serialization.ts +2 -0
  111. package/src/client/client_execution_context.ts +87 -15
  112. package/src/client/db_oracle.ts +1 -9
  113. package/src/client/execution_result.ts +21 -2
  114. package/src/client/private_execution.ts +2 -0
  115. package/src/client/simulator.ts +2 -80
  116. package/src/client/view_data_oracle.ts +0 -10
  117. package/src/common/errors.ts +5 -0
  118. package/src/index.ts +1 -0
  119. package/src/public/abstract_phase_manager.ts +46 -18
  120. package/src/public/app_logic_phase_manager.ts +2 -1
  121. package/src/public/executor.ts +0 -4
  122. package/src/public/hints_builder.ts +5 -5
  123. package/src/public/public_processor.ts +8 -2
  124. package/src/public/setup_phase_manager.ts +16 -8
  125. package/src/public/tail_phase_manager.ts +6 -1
  126. package/src/public/teardown_phase_manager.ts +16 -8
  127. package/src/public/transitional_adaptors.ts +1 -0
  128. package/src/rollup/index.ts +1 -0
  129. package/src/rollup/rollup.ts +160 -0
  130. package/src/stats/index.ts +1 -0
  131. package/src/stats/stats.ts +20 -0
@@ -35,14 +35,21 @@ export class SetupPhaseManager extends AbstractPhaseManager {
35
35
  previousPublicKernelProof: Proof,
36
36
  ) {
37
37
  this.log.verbose(`Processing tx ${tx.getTxHash()}`);
38
- const [kernelInputs, publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
39
- await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
40
- // the abstract phase manager throws if simulation gives error in a non-revertible phase
41
- async err => {
42
- await this.publicStateDB.rollbackToCommit();
43
- throw err;
44
- },
45
- );
38
+ const [
39
+ kernelInputs,
40
+ publicKernelOutput,
41
+ publicKernelProof,
42
+ newUnencryptedFunctionLogs,
43
+ revertReason,
44
+ _returnValues,
45
+ gasUsed,
46
+ ] = await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
47
+ // the abstract phase manager throws if simulation gives error in a non-revertible phase
48
+ async err => {
49
+ await this.publicStateDB.rollbackToCommit();
50
+ throw err;
51
+ },
52
+ );
46
53
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
47
54
  await this.publicStateDB.checkpoint();
48
55
 
@@ -61,6 +68,7 @@ export class SetupPhaseManager extends AbstractPhaseManager {
61
68
  publicKernelProof,
62
69
  revertReason,
63
70
  returnValues: undefined,
71
+ gasUsed,
64
72
  };
65
73
  }
66
74
  }
@@ -39,7 +39,11 @@ export class TailPhaseManager extends AbstractPhaseManager {
39
39
  super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
40
40
  }
41
41
 
42
- async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs, previousPublicKernelProof: Proof) {
42
+ override async handle(
43
+ tx: Tx,
44
+ previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
45
+ previousPublicKernelProof: Proof,
46
+ ) {
43
47
  this.log.verbose(`Processing tx ${tx.getTxHash()}`);
44
48
  const [inputs, finalKernelOutput] = await this.runTailKernelCircuit(
45
49
  previousPublicKernelOutput,
@@ -67,6 +71,7 @@ export class TailPhaseManager extends AbstractPhaseManager {
67
71
  publicKernelProof: makeEmptyProof(),
68
72
  revertReason: undefined,
69
73
  returnValues: undefined,
74
+ gasUsed: undefined,
70
75
  };
71
76
  }
72
77
 
@@ -39,14 +39,21 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
39
39
  previousPublicKernelProof: Proof,
40
40
  ) {
41
41
  this.log.verbose(`Processing tx ${tx.getTxHash()}`);
42
- const [kernelInputs, publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
43
- await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
44
- // the abstract phase manager throws if simulation gives error in a non-revertible phase
45
- async err => {
46
- await this.publicStateDB.rollbackToCommit();
47
- throw err;
48
- },
49
- );
42
+ const [
43
+ kernelInputs,
44
+ publicKernelOutput,
45
+ publicKernelProof,
46
+ newUnencryptedFunctionLogs,
47
+ revertReason,
48
+ _returnValues,
49
+ gasUsed,
50
+ ] = await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
51
+ // the abstract phase manager throws if simulation gives error in a non-revertible phase
52
+ async err => {
53
+ await this.publicStateDB.rollbackToCommit();
54
+ throw err;
55
+ },
56
+ );
50
57
  tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
51
58
  await this.publicStateDB.checkpoint();
52
59
 
@@ -65,6 +72,7 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
65
72
  publicKernelProof,
66
73
  revertReason,
67
74
  returnValues: undefined,
75
+ gasUsed,
68
76
  };
69
77
  }
70
78
 
@@ -81,6 +81,7 @@ export function convertAvmResultsToPxResult(
81
81
  ): PublicExecutionResult {
82
82
  const endPersistableState = endAvmContext.persistableState;
83
83
  const endMachineState = endAvmContext.machineState;
84
+
84
85
  return {
85
86
  ...endPersistableState.transitionalExecutionResult, // includes nestedExecutions
86
87
  execution: fromPx,
@@ -0,0 +1 @@
1
+ export * from './rollup.js';
@@ -0,0 +1,160 @@
1
+ import { type CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
+ import {
3
+ type BaseOrMergeRollupPublicInputs,
4
+ type BaseParityInputs,
5
+ type BaseRollupInputs,
6
+ type MergeRollupInputs,
7
+ type ParityPublicInputs,
8
+ type RootParityInputs,
9
+ type RootRollupInputs,
10
+ type RootRollupPublicInputs,
11
+ } from '@aztec/circuits.js';
12
+ import { createDebugLogger } from '@aztec/foundation/log';
13
+ import { elapsed } from '@aztec/foundation/timer';
14
+ import {
15
+ BaseParityArtifact,
16
+ MergeRollupArtifact,
17
+ RootParityArtifact,
18
+ RootRollupArtifact,
19
+ SimulatedBaseRollupArtifact,
20
+ convertBaseParityInputsToWitnessMap,
21
+ convertBaseParityOutputsFromWitnessMap,
22
+ convertMergeRollupInputsToWitnessMap,
23
+ convertMergeRollupOutputsFromWitnessMap,
24
+ convertRootParityInputsToWitnessMap,
25
+ convertRootParityOutputsFromWitnessMap,
26
+ convertRootRollupInputsToWitnessMap,
27
+ convertRootRollupOutputsFromWitnessMap,
28
+ convertSimulatedBaseRollupInputsToWitnessMap,
29
+ convertSimulatedBaseRollupOutputsFromWitnessMap,
30
+ } from '@aztec/noir-protocol-circuits-types';
31
+ import { type SimulationProvider, WASMSimulator } from '@aztec/simulator';
32
+
33
+ /**
34
+ * Circuit simulator for the rollup circuits.
35
+ */
36
+ export interface RollupSimulator {
37
+ /**
38
+ * Simulates the base parity circuit from its inputs.
39
+ * @param inputs - Inputs to the circuit.
40
+ * @returns The public inputs of the parity circuit.
41
+ */
42
+ baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs>;
43
+ /**
44
+ * Simulates the root parity circuit from its inputs.
45
+ * @param inputs - Inputs to the circuit.
46
+ * @returns The public inputs of the parity circuit.
47
+ */
48
+ rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs>;
49
+ /**
50
+ * Simulates the base rollup circuit from its inputs.
51
+ * @param input - Inputs to the circuit.
52
+ * @returns The public inputs as outputs of the simulation.
53
+ */
54
+ baseRollupCircuit(input: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs>;
55
+ /**
56
+ * Simulates the merge rollup circuit from its inputs.
57
+ * @param input - Inputs to the circuit.
58
+ * @returns The public inputs as outputs of the simulation.
59
+ */
60
+ mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs>;
61
+ /**
62
+ * Simulates the root rollup circuit from its inputs.
63
+ * @param input - Inputs to the circuit.
64
+ * @returns The public inputs as outputs of the simulation.
65
+ */
66
+ rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs>;
67
+ }
68
+
69
+ /**
70
+ * Implements the rollup circuit simulator.
71
+ */
72
+ export class RealRollupCircuitSimulator implements RollupSimulator {
73
+ private log = createDebugLogger('aztec:rollup-simulator');
74
+
75
+ // Some circuits are so small it is faster to use WASM
76
+ private wasmSimulator: WASMSimulator = new WASMSimulator();
77
+
78
+ constructor(private simulationProvider: SimulationProvider) {}
79
+
80
+ /**
81
+ * Simulates the base parity circuit from its inputs.
82
+ * @param inputs - Inputs to the circuit.
83
+ * @returns The public inputs of the parity circuit.
84
+ */
85
+ public async baseParityCircuit(inputs: BaseParityInputs): Promise<ParityPublicInputs> {
86
+ const witnessMap = convertBaseParityInputsToWitnessMap(inputs);
87
+
88
+ const witness = await this.simulationProvider.simulateCircuit(witnessMap, BaseParityArtifact);
89
+
90
+ const result = convertBaseParityOutputsFromWitnessMap(witness);
91
+
92
+ return Promise.resolve(result);
93
+ }
94
+
95
+ /**
96
+ * Simulates the root parity circuit from its inputs.
97
+ * @param inputs - Inputs to the circuit.
98
+ * @returns The public inputs of the parity circuit.
99
+ */
100
+ public async rootParityCircuit(inputs: RootParityInputs): Promise<ParityPublicInputs> {
101
+ const witnessMap = convertRootParityInputsToWitnessMap(inputs);
102
+
103
+ const witness = await this.simulationProvider.simulateCircuit(witnessMap, RootParityArtifact);
104
+
105
+ const result = convertRootParityOutputsFromWitnessMap(witness);
106
+
107
+ return Promise.resolve(result);
108
+ }
109
+
110
+ /**
111
+ * Simulates the base rollup circuit from its inputs.
112
+ * @param input - Inputs to the circuit.
113
+ * @returns The public inputs as outputs of the simulation.
114
+ */
115
+ public async baseRollupCircuit(input: BaseRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
116
+ const witnessMap = convertSimulatedBaseRollupInputsToWitnessMap(input);
117
+
118
+ const witness = await this.simulationProvider.simulateCircuit(witnessMap, SimulatedBaseRollupArtifact);
119
+
120
+ const result = convertSimulatedBaseRollupOutputsFromWitnessMap(witness);
121
+
122
+ return Promise.resolve(result);
123
+ }
124
+ /**
125
+ * Simulates the merge rollup circuit from its inputs.
126
+ * @param input - Inputs to the circuit.
127
+ * @returns The public inputs as outputs of the simulation.
128
+ */
129
+ public async mergeRollupCircuit(input: MergeRollupInputs): Promise<BaseOrMergeRollupPublicInputs> {
130
+ const witnessMap = convertMergeRollupInputsToWitnessMap(input);
131
+
132
+ const witness = await this.wasmSimulator.simulateCircuit(witnessMap, MergeRollupArtifact);
133
+
134
+ const result = convertMergeRollupOutputsFromWitnessMap(witness);
135
+
136
+ return result;
137
+ }
138
+
139
+ /**
140
+ * Simulates the root rollup circuit from its inputs.
141
+ * @param input - Inputs to the circuit.
142
+ * @returns The public inputs as outputs of the simulation.
143
+ */
144
+ public async rootRollupCircuit(input: RootRollupInputs): Promise<RootRollupPublicInputs> {
145
+ const witnessMap = convertRootRollupInputsToWitnessMap(input);
146
+
147
+ const [duration, witness] = await elapsed(() => this.wasmSimulator.simulateCircuit(witnessMap, RootRollupArtifact));
148
+
149
+ const result = convertRootRollupOutputsFromWitnessMap(witness);
150
+
151
+ this.log.debug(`Simulated root rollup circuit`, {
152
+ eventName: 'circuit-simulation',
153
+ circuitName: 'root-rollup',
154
+ duration,
155
+ inputSize: input.toBuffer().length,
156
+ outputSize: result.toBuffer().length,
157
+ } satisfies CircuitSimulationStats);
158
+ return result;
159
+ }
160
+ }
@@ -0,0 +1 @@
1
+ export * from './stats.js';
@@ -0,0 +1,20 @@
1
+ import { type CircuitName, type CircuitSimulationStats } from '@aztec/circuit-types/stats';
2
+ import { type Logger } from '@aztec/foundation/log';
3
+
4
+ export function emitCircuitSimulationStats(
5
+ circuitName: CircuitName,
6
+ duration: number,
7
+ inputSize: number,
8
+ outputSize: number,
9
+ logger: Logger,
10
+ ) {
11
+ const stats: CircuitSimulationStats = {
12
+ eventName: 'circuit-simulation',
13
+ circuitName,
14
+ inputSize,
15
+ outputSize,
16
+ duration,
17
+ };
18
+
19
+ logger.debug('Circuit simulation stats', stats);
20
+ }