@aztec/simulator 0.37.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 (181) hide show
  1. package/dest/acvm/acvm.d.ts +1 -1
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +2 -2
  4. package/dest/acvm/oracle/oracle.d.ts +6 -5
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +26 -30
  7. package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +9 -9
  10. package/dest/avm/avm_execution_environment.d.ts +4 -3
  11. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  12. package/dest/avm/avm_execution_environment.js +17 -11
  13. package/dest/avm/avm_gas.d.ts.map +1 -1
  14. package/dest/avm/avm_gas.js +4 -1
  15. package/dest/avm/avm_machine_state.d.ts +5 -8
  16. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  17. package/dest/avm/avm_machine_state.js +10 -22
  18. package/dest/avm/avm_memory_types.d.ts +1 -1
  19. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  20. package/dest/avm/avm_message_call_result.d.ts +5 -8
  21. package/dest/avm/avm_message_call_result.d.ts.map +1 -1
  22. package/dest/avm/avm_message_call_result.js +1 -4
  23. package/dest/avm/avm_simulator.d.ts.map +1 -1
  24. package/dest/avm/avm_simulator.js +19 -13
  25. package/dest/avm/errors.d.ts +43 -2
  26. package/dest/avm/errors.d.ts.map +1 -1
  27. package/dest/avm/errors.js +86 -4
  28. package/dest/avm/journal/journal.d.ts +20 -1
  29. package/dest/avm/journal/journal.d.ts.map +1 -1
  30. package/dest/avm/journal/journal.js +70 -9
  31. package/dest/avm/journal/nullifiers.d.ts +3 -1
  32. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  33. package/dest/avm/journal/nullifiers.js +14 -6
  34. package/dest/avm/journal/public_storage.d.ts +10 -1
  35. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  36. package/dest/avm/journal/public_storage.js +17 -2
  37. package/dest/avm/journal/trace.d.ts +1 -4
  38. package/dest/avm/journal/trace.d.ts.map +1 -1
  39. package/dest/avm/journal/trace.js +4 -5
  40. package/dest/avm/journal/trace_types.d.ts +1 -0
  41. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  42. package/dest/avm/journal/trace_types.js +1 -1
  43. package/dest/avm/opcodes/bitwise.d.ts +4 -1
  44. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  45. package/dest/avm/opcodes/bitwise.js +14 -2
  46. package/dest/avm/opcodes/conversion.d.ts +16 -0
  47. package/dest/avm/opcodes/conversion.d.ts.map +1 -0
  48. package/dest/avm/opcodes/conversion.js +48 -0
  49. package/dest/avm/opcodes/environment_getters.d.ts +16 -12
  50. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  51. package/dest/avm/opcodes/environment_getters.js +19 -48
  52. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  53. package/dest/avm/opcodes/external_calls.js +24 -13
  54. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  55. package/dest/avm/serialization/bytecode_serialization.js +6 -2
  56. package/dest/avm/serialization/instruction_serialization.d.ts +40 -38
  57. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  58. package/dest/avm/serialization/instruction_serialization.js +42 -39
  59. package/dest/client/client_execution_context.d.ts +59 -19
  60. package/dest/client/client_execution_context.d.ts.map +1 -1
  61. package/dest/client/client_execution_context.js +97 -45
  62. package/dest/client/db_oracle.d.ts +4 -11
  63. package/dest/client/db_oracle.d.ts.map +1 -1
  64. package/dest/client/execution_result.d.ts +22 -15
  65. package/dest/client/execution_result.d.ts.map +1 -1
  66. package/dest/client/execution_result.js +59 -13
  67. package/dest/client/logs_cache.d.ts +33 -0
  68. package/dest/client/logs_cache.d.ts.map +1 -0
  69. package/dest/client/logs_cache.js +59 -0
  70. package/dest/client/private_execution.d.ts +2 -2
  71. package/dest/client/private_execution.d.ts.map +1 -1
  72. package/dest/client/private_execution.js +5 -7
  73. package/dest/client/simulator.d.ts +4 -34
  74. package/dest/client/simulator.d.ts.map +1 -1
  75. package/dest/client/simulator.js +5 -43
  76. package/dest/client/unconstrained_execution.d.ts +2 -2
  77. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  78. package/dest/client/unconstrained_execution.js +1 -1
  79. package/dest/client/view_data_oracle.d.ts +0 -7
  80. package/dest/client/view_data_oracle.d.ts.map +1 -1
  81. package/dest/client/view_data_oracle.js +1 -10
  82. package/dest/common/errors.d.ts +5 -0
  83. package/dest/common/errors.d.ts.map +1 -1
  84. package/dest/common/errors.js +6 -1
  85. package/dest/index.d.ts +1 -0
  86. package/dest/index.d.ts.map +1 -1
  87. package/dest/index.js +2 -1
  88. package/dest/mocks/fixtures.d.ts.map +1 -1
  89. package/dest/mocks/fixtures.js +3 -1
  90. package/dest/public/abstract_phase_manager.d.ts +10 -4
  91. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  92. package/dest/public/abstract_phase_manager.js +50 -19
  93. package/dest/public/app_logic_phase_manager.d.ts +1 -0
  94. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  95. package/dest/public/app_logic_phase_manager.js +3 -3
  96. package/dest/public/execution.d.ts +9 -0
  97. package/dest/public/execution.d.ts.map +1 -1
  98. package/dest/public/execution.js +1 -1
  99. package/dest/public/executor.d.ts +2 -2
  100. package/dest/public/executor.d.ts.map +1 -1
  101. package/dest/public/executor.js +34 -17
  102. package/dest/public/hints_builder.d.ts +3 -3
  103. package/dest/public/hints_builder.d.ts.map +1 -1
  104. package/dest/public/hints_builder.js +3 -3
  105. package/dest/public/public_execution_context.d.ts +10 -4
  106. package/dest/public/public_execution_context.d.ts.map +1 -1
  107. package/dest/public/public_execution_context.js +19 -6
  108. package/dest/public/public_processor.d.ts.map +1 -1
  109. package/dest/public/public_processor.js +5 -3
  110. package/dest/public/setup_phase_manager.d.ts +1 -0
  111. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  112. package/dest/public/setup_phase_manager.js +3 -2
  113. package/dest/public/tail_phase_manager.d.ts +1 -1
  114. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  115. package/dest/public/tail_phase_manager.js +4 -26
  116. package/dest/public/teardown_phase_manager.d.ts +1 -0
  117. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  118. package/dest/public/teardown_phase_manager.js +3 -2
  119. package/dest/public/transitional_adaptors.d.ts +4 -17
  120. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  121. package/dest/public/transitional_adaptors.js +27 -119
  122. package/dest/rollup/index.d.ts +2 -0
  123. package/dest/rollup/index.d.ts.map +1 -0
  124. package/dest/rollup/index.js +2 -0
  125. package/dest/rollup/rollup.d.ts +77 -0
  126. package/dest/rollup/rollup.d.ts.map +1 -0
  127. package/dest/rollup/rollup.js +78 -0
  128. package/dest/stats/index.d.ts +2 -0
  129. package/dest/stats/index.d.ts.map +1 -0
  130. package/dest/stats/index.js +2 -0
  131. package/dest/stats/stats.d.ts +4 -0
  132. package/dest/stats/stats.d.ts.map +1 -0
  133. package/dest/stats/stats.js +11 -0
  134. package/package.json +8 -8
  135. package/src/acvm/acvm.ts +2 -2
  136. package/src/acvm/oracle/oracle.ts +62 -36
  137. package/src/acvm/oracle/typed_oracle.ts +19 -11
  138. package/src/avm/avm_execution_environment.ts +34 -42
  139. package/src/avm/avm_gas.ts +3 -0
  140. package/src/avm/avm_machine_state.ts +14 -25
  141. package/src/avm/avm_memory_types.ts +1 -1
  142. package/src/avm/avm_message_call_result.ts +3 -14
  143. package/src/avm/avm_simulator.ts +24 -12
  144. package/src/avm/errors.ts +94 -4
  145. package/src/avm/journal/journal.ts +134 -9
  146. package/src/avm/journal/nullifiers.ts +19 -8
  147. package/src/avm/journal/public_storage.ts +23 -2
  148. package/src/avm/journal/trace.ts +3 -4
  149. package/src/avm/journal/trace_types.ts +1 -0
  150. package/src/avm/opcodes/bitwise.ts +18 -7
  151. package/src/avm/opcodes/conversion.ts +59 -0
  152. package/src/avm/opcodes/environment_getters.ts +21 -65
  153. package/src/avm/opcodes/external_calls.ts +32 -16
  154. package/src/avm/serialization/bytecode_serialization.ts +5 -0
  155. package/src/avm/serialization/instruction_serialization.ts +3 -0
  156. package/src/client/client_execution_context.ts +142 -46
  157. package/src/client/db_oracle.ts +4 -18
  158. package/src/client/execution_result.ts +75 -25
  159. package/src/client/logs_cache.ts +65 -0
  160. package/src/client/private_execution.ts +6 -10
  161. package/src/client/simulator.ts +8 -84
  162. package/src/client/unconstrained_execution.ts +2 -2
  163. package/src/client/view_data_oracle.ts +0 -10
  164. package/src/common/errors.ts +5 -0
  165. package/src/index.ts +1 -0
  166. package/src/mocks/fixtures.ts +2 -0
  167. package/src/public/abstract_phase_manager.ts +59 -23
  168. package/src/public/app_logic_phase_manager.ts +2 -1
  169. package/src/public/execution.ts +9 -0
  170. package/src/public/executor.ts +47 -14
  171. package/src/public/hints_builder.ts +5 -5
  172. package/src/public/public_execution_context.ts +18 -4
  173. package/src/public/public_processor.ts +8 -2
  174. package/src/public/setup_phase_manager.ts +16 -8
  175. package/src/public/tail_phase_manager.ts +8 -35
  176. package/src/public/teardown_phase_manager.ts +16 -8
  177. package/src/public/transitional_adaptors.ts +39 -177
  178. package/src/rollup/index.ts +1 -0
  179. package/src/rollup/rollup.ts +160 -0
  180. package/src/stats/index.ts +1 -0
  181. package/src/stats/stats.ts +20 -0
@@ -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
 
@@ -1,32 +1,21 @@
1
1
  // All code in this file needs to die once the public executor is phased out in favor of the AVM.
2
- import { UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
2
+ import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
3
3
  import {
4
4
  CallContext,
5
- ContractStorageRead,
6
- ContractStorageUpdateRequest,
7
5
  FunctionData,
8
- Gas,
6
+ type Gas,
9
7
  type GasSettings,
10
8
  type GlobalVariables,
11
9
  type Header,
12
- L2ToL1Message,
13
- NoteHash,
14
- Nullifier,
15
- ReadRequest,
16
- SideEffect,
17
10
  } from '@aztec/circuits.js';
18
11
  import { Fr } from '@aztec/foundation/fields';
19
12
 
20
13
  import { type AvmContext } from '../avm/avm_context.js';
21
14
  import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
22
- import { type AvmMachineState } from '../avm/avm_machine_state.js';
23
- import { AvmContractCallResults } from '../avm/avm_message_call_result.js';
24
- import { type JournalData } from '../avm/journal/journal.js';
15
+ import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
25
16
  import { Mov } from '../avm/opcodes/memory.js';
26
17
  import { createSimulationError } from '../common/errors.js';
27
- import { PackedValuesCache, SideEffectCounter } from '../index.js';
28
18
  import { type PublicExecution, type PublicExecutionResult } from './execution.js';
29
- import { PublicExecutionContext } from './public_execution_context.js';
30
19
 
31
20
  /**
32
21
  * Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment
@@ -60,184 +49,57 @@ export function createAvmExecutionEnvironment(
60
49
  );
61
50
  }
62
51
 
63
- export function createPublicExecutionContext(avmContext: AvmContext, calldata: Fr[]): PublicExecutionContext {
64
- const sideEffectCounter = avmContext.persistableState.trace.accessCounter;
52
+ export function createPublicExecution(
53
+ startSideEffectCounter: number,
54
+ avmEnvironment: AvmExecutionEnvironment,
55
+ calldata: Fr[],
56
+ ): PublicExecution {
65
57
  const callContext = CallContext.from({
66
- msgSender: avmContext.environment.sender,
67
- storageContractAddress: avmContext.environment.storageAddress,
68
- functionSelector: avmContext.environment.temporaryFunctionSelector,
69
- isDelegateCall: avmContext.environment.isDelegateCall,
70
- isStaticCall: avmContext.environment.isStaticCall,
71
- sideEffectCounter: sideEffectCounter,
58
+ msgSender: avmEnvironment.sender,
59
+ storageContractAddress: avmEnvironment.storageAddress,
60
+ functionSelector: avmEnvironment.temporaryFunctionSelector,
61
+ isDelegateCall: avmEnvironment.isDelegateCall,
62
+ isStaticCall: avmEnvironment.isStaticCall,
63
+ sideEffectCounter: startSideEffectCounter,
72
64
  });
73
- const functionData = new FunctionData(avmContext.environment.temporaryFunctionSelector, /*isPrivate=*/ false);
65
+ const functionData = new FunctionData(avmEnvironment.temporaryFunctionSelector, /*isPrivate=*/ false);
74
66
  const execution: PublicExecution = {
75
- contractAddress: avmContext.environment.address,
67
+ contractAddress: avmEnvironment.address,
76
68
  callContext,
77
69
  args: calldata,
78
70
  functionData,
79
71
  };
80
- const packedArgs = PackedValuesCache.create([]);
81
-
82
- const context = new PublicExecutionContext(
83
- execution,
84
- avmContext.environment.header,
85
- avmContext.environment.globals,
86
- packedArgs,
87
- new SideEffectCounter(sideEffectCounter),
88
- avmContext.persistableState.hostStorage.publicStateDb,
89
- avmContext.persistableState.hostStorage.contractsDb,
90
- avmContext.persistableState.hostStorage.commitmentsDb,
91
- Gas.from(avmContext.machineState.gasLeft),
92
- avmContext.environment.transactionFee,
93
- avmContext.environment.gasSettings,
94
- );
95
-
96
- return context;
72
+ return execution;
97
73
  }
98
74
 
99
- /**
100
- * Convert the result of an AVM contract call to a PublicExecutionResult for the public kernel
101
- *
102
- * @param execution
103
- * @param newWorldState
104
- * @param result
105
- * @returns
106
- */
107
- export async function convertAvmResults(
108
- executionContext: PublicExecutionContext,
109
- newWorldState: JournalData,
110
- result: AvmContractCallResults,
111
- endMachineState: AvmMachineState,
112
- ): Promise<PublicExecutionResult> {
113
- const execution = executionContext.execution;
114
-
115
- const contractStorageReads: ContractStorageRead[] = newWorldState.storageReads.map(
116
- read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber(), read.storageAddress),
117
- );
118
- const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = newWorldState.storageWrites.map(
119
- write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber(), write.storageAddress),
120
- );
121
- // We need to write the storage updates to the DB, because that's what the ACVM expects.
122
- // Assumes the updates are in the right order.
123
- for (const write of newWorldState.storageWrites) {
124
- await executionContext.stateDb.storageWrite(write.storageAddress, write.slot, write.value);
125
- }
126
-
127
- const newNoteHashes = newWorldState.newNoteHashes.map(
128
- noteHash => new NoteHash(noteHash.noteHash, noteHash.counter.toNumber()),
129
- );
130
- const nullifierReadRequests: ReadRequest[] = newWorldState.nullifierChecks
131
- .filter(nullifierCheck => nullifierCheck.exists)
132
- .map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
133
- const nullifierNonExistentReadRequests: ReadRequest[] = newWorldState.nullifierChecks
134
- .filter(nullifierCheck => !nullifierCheck.exists)
135
- .map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
136
- const newNullifiers: Nullifier[] = newWorldState.newNullifiers.map(
137
- tracedNullifier =>
138
- new Nullifier(
139
- /*value=*/ tracedNullifier.nullifier,
140
- tracedNullifier.counter.toNumber(),
141
- /*noteHash=*/ Fr.ZERO, // NEEDED?
142
- ),
143
- );
144
- const unencryptedLogs: UnencryptedFunctionL2Logs = new UnencryptedFunctionL2Logs(
145
- newWorldState.newLogs.map(log => new UnencryptedL2Log(log.contractAddress, log.selector, log.data)),
146
- );
147
- const unencryptedLogsHashes = newWorldState.newLogsHashes.map(
148
- logHash => new SideEffect(logHash.logHash, logHash.counter),
149
- );
150
- const newL2ToL1Messages = newWorldState.newL1Messages.map(m => new L2ToL1Message(m.recipient, m.content));
151
-
152
- const returnValues = result.output;
153
-
154
- // TODO: Support nested executions.
155
- const nestedExecutions: PublicExecutionResult[] = [];
156
- // TODO keep track of side effect counters
157
- const startSideEffectCounter = Fr.ZERO;
158
- const endSideEffectCounter = Fr.ZERO;
75
+ export function convertAvmResultsToPxResult(
76
+ avmResult: AvmContractCallResults,
77
+ startSideEffectCounter: number,
78
+ fromPx: PublicExecution,
79
+ startGas: Gas,
80
+ endAvmContext: AvmContext,
81
+ ): PublicExecutionResult {
82
+ const endPersistableState = endAvmContext.persistableState;
83
+ const endMachineState = endAvmContext.machineState;
159
84
 
160
85
  return {
161
- execution,
162
- nullifierReadRequests,
163
- nullifierNonExistentReadRequests,
164
- newNoteHashes,
165
- newL2ToL1Messages,
166
- startSideEffectCounter,
167
- endSideEffectCounter,
168
- newNullifiers,
169
- contractStorageReads,
170
- contractStorageUpdateRequests,
171
- returnValues,
172
- nestedExecutions,
173
- unencryptedLogsHashes,
174
- unencryptedLogs,
175
- reverted: result.reverted,
176
- revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
177
- startGasLeft: executionContext.availableGas,
86
+ ...endPersistableState.transitionalExecutionResult, // includes nestedExecutions
87
+ execution: fromPx,
88
+ returnValues: avmResult.output,
89
+ startSideEffectCounter: new Fr(startSideEffectCounter),
90
+ endSideEffectCounter: new Fr(endPersistableState.trace.accessCounter),
91
+ unencryptedLogs: new UnencryptedFunctionL2Logs(endPersistableState.transitionalExecutionResult.unencryptedLogs),
92
+ allUnencryptedLogs: new UnencryptedFunctionL2Logs(
93
+ endPersistableState.transitionalExecutionResult.allUnencryptedLogs,
94
+ ),
95
+ reverted: avmResult.reverted,
96
+ revertReason: avmResult.revertReason ? createSimulationError(avmResult.revertReason) : undefined,
97
+ startGasLeft: startGas,
178
98
  endGasLeft: endMachineState.gasLeft,
179
- transactionFee: executionContext.transactionFee,
99
+ transactionFee: endAvmContext.environment.transactionFee,
180
100
  };
181
101
  }
182
102
 
183
- export function convertPublicExecutionResult(res: PublicExecutionResult): AvmContractCallResults {
184
- return new AvmContractCallResults(res.reverted, res.returnValues, res.revertReason);
185
- }
186
-
187
- export function updateAvmContextFromPublicExecutionResult(ctx: AvmContext, result: PublicExecutionResult): void {
188
- // We have to push these manually and not use the trace* functions
189
- // so that we respect the side effect counters.
190
- for (const readRequest of result.contractStorageReads) {
191
- ctx.persistableState.trace.publicStorageReads.push({
192
- storageAddress: ctx.environment.storageAddress,
193
- exists: true, // FIXME
194
- slot: readRequest.storageSlot,
195
- value: readRequest.currentValue,
196
- counter: new Fr(readRequest.sideEffectCounter ?? Fr.ZERO),
197
- });
198
- }
199
-
200
- for (const updateRequest of result.contractStorageUpdateRequests) {
201
- ctx.persistableState.trace.publicStorageWrites.push({
202
- storageAddress: ctx.environment.storageAddress,
203
- slot: updateRequest.storageSlot,
204
- value: updateRequest.newValue,
205
- counter: new Fr(updateRequest.sideEffectCounter ?? Fr.ZERO),
206
- });
207
-
208
- // We need to manually populate the cache.
209
- ctx.persistableState.publicStorage.write(
210
- ctx.environment.storageAddress,
211
- updateRequest.storageSlot,
212
- updateRequest.newValue,
213
- );
214
- }
215
-
216
- for (const nullifier of result.newNullifiers) {
217
- ctx.persistableState.trace.newNullifiers.push({
218
- storageAddress: ctx.environment.storageAddress,
219
- nullifier: nullifier.value,
220
- counter: new Fr(nullifier.counter),
221
- });
222
- }
223
-
224
- for (const noteHash of result.newNoteHashes) {
225
- ctx.persistableState.trace.newNoteHashes.push({
226
- storageAddress: ctx.environment.storageAddress,
227
- noteHash: noteHash.value,
228
- counter: new Fr(noteHash.counter),
229
- });
230
- }
231
-
232
- for (const message of result.newL2ToL1Messages) {
233
- ctx.persistableState.newL1Messages.push(message);
234
- }
235
-
236
- for (const log of result.unencryptedLogs.logs) {
237
- ctx.persistableState.newLogs.push(new UnencryptedL2Log(log.contractAddress, log.selector, log.data));
238
- }
239
- }
240
-
241
103
  const AVM_MAGIC_SUFFIX = Buffer.from([
242
104
  Mov.opcode, // opcode
243
105
  0x00, // indirect
@@ -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
+ }