@aztec/simulator 0.43.0 → 0.44.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 (110) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +2 -0
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +10 -4
  4. package/dest/acvm/oracle/typed_oracle.d.ts +5 -3
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +7 -1
  7. package/dest/avm/avm_execution_environment.d.ts +2 -0
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +9 -4
  10. package/dest/avm/avm_simulator.d.ts.map +1 -1
  11. package/dest/avm/avm_simulator.js +2 -3
  12. package/dest/avm/fixtures/index.d.ts +10 -6
  13. package/dest/avm/fixtures/index.d.ts.map +1 -1
  14. package/dest/avm/fixtures/index.js +8 -15
  15. package/dest/avm/journal/journal.d.ts +56 -65
  16. package/dest/avm/journal/journal.d.ts.map +1 -1
  17. package/dest/avm/journal/journal.js +76 -115
  18. package/dest/avm/journal/nullifiers.d.ts +21 -8
  19. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  20. package/dest/avm/journal/nullifiers.js +26 -8
  21. package/dest/avm/journal/public_storage.d.ts +4 -0
  22. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  23. package/dest/avm/journal/public_storage.js +10 -1
  24. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  25. package/dest/avm/opcodes/accrued_substate.js +4 -4
  26. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  27. package/dest/avm/opcodes/external_calls.js +12 -27
  28. package/dest/avm/test_utils.d.ts +14 -0
  29. package/dest/avm/test_utils.d.ts.map +1 -0
  30. package/dest/avm/test_utils.js +36 -0
  31. package/dest/client/client_execution_context.d.ts +3 -3
  32. package/dest/client/client_execution_context.d.ts.map +1 -1
  33. package/dest/client/client_execution_context.js +3 -3
  34. package/dest/client/execution_note_cache.d.ts.map +1 -1
  35. package/dest/client/execution_note_cache.js +1 -1
  36. package/dest/client/execution_result.d.ts +2 -1
  37. package/dest/client/execution_result.d.ts.map +1 -1
  38. package/dest/client/execution_result.js +1 -1
  39. package/dest/client/index.d.ts +2 -0
  40. package/dest/client/index.d.ts.map +1 -1
  41. package/dest/client/index.js +3 -1
  42. package/dest/client/simulator.d.ts +3 -3
  43. package/dest/client/simulator.d.ts.map +1 -1
  44. package/dest/client/simulator.js +1 -1
  45. package/dest/client/view_data_oracle.d.ts +2 -0
  46. package/dest/client/view_data_oracle.d.ts.map +1 -1
  47. package/dest/client/view_data_oracle.js +7 -1
  48. package/dest/mocks/fixtures.d.ts.map +1 -1
  49. package/dest/mocks/fixtures.js +3 -2
  50. package/dest/public/abstract_phase_manager.d.ts +1 -0
  51. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  52. package/dest/public/abstract_phase_manager.js +11 -8
  53. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  54. package/dest/public/app_logic_phase_manager.js +2 -1
  55. package/dest/public/execution.d.ts +27 -25
  56. package/dest/public/execution.d.ts.map +1 -1
  57. package/dest/public/execution.js +1 -1
  58. package/dest/public/executor.d.ts +9 -4
  59. package/dest/public/executor.d.ts.map +1 -1
  60. package/dest/public/executor.js +29 -25
  61. package/dest/public/public_processor.d.ts +5 -2
  62. package/dest/public/public_processor.d.ts.map +1 -1
  63. package/dest/public/public_processor.js +142 -123
  64. package/dest/public/side_effect_trace.d.ts +86 -0
  65. package/dest/public/side_effect_trace.d.ts.map +1 -0
  66. package/dest/public/side_effect_trace.js +222 -0
  67. package/dest/public/side_effect_trace_interface.d.ts +36 -0
  68. package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
  69. package/dest/public/side_effect_trace_interface.js +2 -0
  70. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  71. package/dest/public/teardown_phase_manager.js +2 -1
  72. package/dest/public/transitional_adaptors.d.ts +2 -6
  73. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  74. package/dest/public/transitional_adaptors.js +1 -49
  75. package/package.json +18 -9
  76. package/src/acvm/oracle/oracle.ts +11 -3
  77. package/src/acvm/oracle/typed_oracle.ts +17 -3
  78. package/src/avm/avm_execution_environment.ts +10 -3
  79. package/src/avm/avm_simulator.ts +2 -3
  80. package/src/avm/fixtures/index.ts +18 -17
  81. package/src/avm/journal/journal.ts +114 -223
  82. package/src/avm/journal/nullifiers.ts +30 -13
  83. package/src/avm/journal/public_storage.ts +10 -0
  84. package/src/avm/opcodes/accrued_substate.ts +7 -3
  85. package/src/avm/opcodes/external_calls.ts +12 -34
  86. package/src/avm/test_utils.ts +53 -0
  87. package/src/client/client_execution_context.ts +10 -4
  88. package/src/client/execution_note_cache.ts +0 -1
  89. package/src/client/execution_result.ts +2 -1
  90. package/src/client/index.ts +2 -0
  91. package/src/client/simulator.ts +8 -2
  92. package/src/client/view_data_oracle.ts +8 -0
  93. package/src/mocks/fixtures.ts +2 -1
  94. package/src/public/abstract_phase_manager.ts +22 -11
  95. package/src/public/app_logic_phase_manager.ts +1 -0
  96. package/src/public/execution.ts +35 -25
  97. package/src/public/executor.ts +44 -37
  98. package/src/public/public_processor.ts +11 -2
  99. package/src/public/side_effect_trace.ts +323 -0
  100. package/src/public/side_effect_trace_interface.ts +41 -0
  101. package/src/public/teardown_phase_manager.ts +1 -0
  102. package/src/public/transitional_adaptors.ts +2 -100
  103. package/dest/avm/journal/trace.d.ts +0 -33
  104. package/dest/avm/journal/trace.d.ts.map +0 -1
  105. package/dest/avm/journal/trace.js +0 -152
  106. package/dest/avm/journal/trace_types.d.ts +0 -55
  107. package/dest/avm/journal/trace_types.d.ts.map +0 -1
  108. package/dest/avm/journal/trace_types.js +0 -2
  109. package/src/avm/journal/trace.ts +0 -181
  110. package/src/avm/journal/trace_types.ts +0 -91
@@ -30,6 +30,7 @@ import {
30
30
  computeFeePayerBalanceLeafSlot,
31
31
  computeFeePayerBalanceStorageSlot,
32
32
  } from '@aztec/simulator';
33
+ import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
33
34
  import { type ContractDataSource } from '@aztec/types/contracts';
34
35
  import { type MerkleTreeOperations } from '@aztec/world-state';
35
36
 
@@ -47,6 +48,7 @@ export class PublicProcessorFactory {
47
48
  private merkleTree: MerkleTreeOperations,
48
49
  private contractDataSource: ContractDataSource,
49
50
  private simulator: SimulationProvider,
51
+ private telemetryClient: TelemetryClient,
50
52
  ) {}
51
53
 
52
54
  /**
@@ -74,6 +76,7 @@ export class PublicProcessorFactory {
74
76
  historicalHeader,
75
77
  publicContractsDB,
76
78
  worldStatePublicDB,
79
+ this.telemetryClient,
77
80
  );
78
81
  }
79
82
  }
@@ -83,6 +86,7 @@ export class PublicProcessorFactory {
83
86
  * any public function calls in them. Txs with private calls only are unaffected.
84
87
  */
85
88
  export class PublicProcessor {
89
+ public readonly tracer: Tracer;
86
90
  constructor(
87
91
  protected db: MerkleTreeOperations,
88
92
  protected publicExecutor: PublicExecutor,
@@ -91,9 +95,11 @@ export class PublicProcessor {
91
95
  protected historicalHeader: Header,
92
96
  protected publicContractsDB: ContractsDataSourcePublicDB,
93
97
  protected publicStateDB: PublicStateDB,
94
-
98
+ telemetryClient: TelemetryClient,
95
99
  private log = createDebugLogger('aztec:sequencer:public-processor'),
96
- ) {}
100
+ ) {
101
+ this.tracer = telemetryClient.getTracer('PublicProcessor');
102
+ }
97
103
 
98
104
  /**
99
105
  * Run each tx through the public circuit and the public kernel circuit if needed.
@@ -208,6 +214,9 @@ export class PublicProcessor {
208
214
  return finalPublicDataUpdateRequests;
209
215
  }
210
216
 
217
+ @trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
218
+ [Attributes.TX_HASH]: tx.getTxHash().toString(),
219
+ }))
211
220
  private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
212
221
  let returnValues: NestedProcessReturnValues[] = [];
213
222
  const publicProvingRequests: PublicProvingRequest[] = [];
@@ -0,0 +1,323 @@
1
+ import { UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
2
+ import {
3
+ AvmContractInstanceHint,
4
+ AvmExecutionHints,
5
+ AvmExternalCallHint,
6
+ AvmKeyValueHint,
7
+ AztecAddress,
8
+ CallContext,
9
+ ContractStorageRead,
10
+ ContractStorageUpdateRequest,
11
+ EthAddress,
12
+ Gas,
13
+ L2ToL1Message,
14
+ LogHash,
15
+ NoteHash,
16
+ Nullifier,
17
+ ReadRequest,
18
+ } from '@aztec/circuits.js';
19
+ import { EventSelector } from '@aztec/foundation/abi';
20
+ import { Fr } from '@aztec/foundation/fields';
21
+ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
22
+
23
+ import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
24
+ import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
25
+ import { createSimulationError } from '../common/errors.js';
26
+ import { type PublicExecution, type PublicExecutionResult } from './execution.js';
27
+ import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
28
+
29
+ export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress;
30
+
31
+ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
32
+ /** The side effect counter increments with every call to the trace. */
33
+ private sideEffectCounter: number; // kept as number until finalized for efficiency
34
+
35
+ private contractStorageReads: ContractStorageRead[] = [];
36
+ private contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
37
+
38
+ private noteHashReadRequests: ReadRequest[] = [];
39
+ private newNoteHashes: NoteHash[] = [];
40
+
41
+ private nullifierReadRequests: ReadRequest[] = [];
42
+ private nullifierNonExistentReadRequests: ReadRequest[] = [];
43
+ private newNullifiers: Nullifier[] = [];
44
+
45
+ private l1ToL2MsgReadRequests: ReadRequest[] = [];
46
+ private newL2ToL1Messages: L2ToL1Message[] = [];
47
+
48
+ private unencryptedLogs: UnencryptedL2Log[] = [];
49
+ private allUnencryptedLogs: UnencryptedL2Log[] = [];
50
+ private unencryptedLogsHashes: LogHash[] = [];
51
+
52
+ private gotContractInstances: ContractInstanceWithAddress[] = [];
53
+
54
+ private nestedExecutions: PublicExecutionResult[] = [];
55
+
56
+ private avmCircuitHints: AvmExecutionHints;
57
+
58
+ constructor(
59
+ /** The counter of this trace's first side effect. */
60
+ public readonly startSideEffectCounter: number = 0,
61
+ ) {
62
+ this.sideEffectCounter = startSideEffectCounter;
63
+ this.avmCircuitHints = AvmExecutionHints.empty();
64
+ }
65
+
66
+ public fork() {
67
+ return new PublicSideEffectTrace(this.sideEffectCounter);
68
+ }
69
+
70
+ public getCounter() {
71
+ return this.sideEffectCounter;
72
+ }
73
+
74
+ private incrementSideEffectCounter() {
75
+ this.sideEffectCounter++;
76
+ }
77
+
78
+ public tracePublicStorageRead(storageAddress: Fr, slot: Fr, value: Fr, _exists: boolean, _cached: boolean) {
79
+ // TODO(4805): check if some threshold is reached for max storage reads
80
+ // (need access to parent length, or trace needs to be initialized with parent's contents)
81
+ // NOTE: exists and cached are unused for now but may be used for optimizations or kernel hints later
82
+ this.contractStorageReads.push(
83
+ new ContractStorageRead(slot, value, this.sideEffectCounter, AztecAddress.fromField(storageAddress)),
84
+ );
85
+ this.avmCircuitHints.storageValues.items.push(
86
+ new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ value),
87
+ );
88
+ this.incrementSideEffectCounter();
89
+ }
90
+
91
+ public tracePublicStorageWrite(storageAddress: Fr, slot: Fr, value: Fr) {
92
+ // TODO(4805): check if some threshold is reached for max storage writes
93
+ // (need access to parent length, or trace needs to be initialized with parent's contents)
94
+ this.contractStorageUpdateRequests.push(
95
+ new ContractStorageUpdateRequest(slot, value, this.sideEffectCounter, storageAddress),
96
+ );
97
+ this.incrementSideEffectCounter();
98
+ }
99
+
100
+ public traceNoteHashCheck(_storageAddress: Fr, noteHash: Fr, _leafIndex: Fr, exists: boolean) {
101
+ // TODO(4805): check if some threshold is reached for max note hash checks
102
+ // NOTE: storageAddress is unused but will be important when an AVM circuit processes an entire enqueued call
103
+ // TODO(dbanks12): leafIndex is unused for now but later must be used by kernel to constrain that the kernel
104
+ // is in fact checking the leaf indicated by the user
105
+ this.noteHashReadRequests.push(new ReadRequest(noteHash, this.sideEffectCounter));
106
+ this.avmCircuitHints.noteHashExists.items.push(
107
+ new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)),
108
+ );
109
+ this.incrementSideEffectCounter();
110
+ }
111
+
112
+ public traceNewNoteHash(_storageAddress: Fr, noteHash: Fr) {
113
+ // TODO(4805): check if some threshold is reached for max new note hash
114
+ // NOTE: storageAddress is unused but will be important when an AVM circuit processes an entire enqueued call
115
+ // TODO(dbanks12): non-existent note hashes should emit a read request of the note hash that actually
116
+ // IS there, and the AVM circuit should accept THAT noteHash as a hint. The circuit will then compare
117
+ // the noteHash against the one provided by the user code to determine what to return to the user (exists or not),
118
+ // and will then propagate the actually-present noteHash to its public inputs.
119
+ this.newNoteHashes.push(new NoteHash(noteHash, this.sideEffectCounter));
120
+ this.incrementSideEffectCounter();
121
+ }
122
+
123
+ public traceNullifierCheck(_storageAddress: Fr, nullifier: Fr, _leafIndex: Fr, exists: boolean, _isPending: boolean) {
124
+ // TODO(4805): check if some threshold is reached for max new nullifier
125
+ // NOTE: storageAddress is unused but will be important when an AVM circuit processes an entire enqueued call
126
+ // NOTE: isPending and leafIndex are unused for now but may be used for optimizations or kernel hints later
127
+ const readRequest = new ReadRequest(nullifier, this.sideEffectCounter);
128
+ if (exists) {
129
+ this.nullifierReadRequests.push(readRequest);
130
+ } else {
131
+ this.nullifierNonExistentReadRequests.push(readRequest);
132
+ }
133
+ this.avmCircuitHints.nullifierExists.items.push(
134
+ new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)),
135
+ );
136
+ this.incrementSideEffectCounter();
137
+ }
138
+
139
+ public traceNewNullifier(_storageAddress: Fr, nullifier: Fr) {
140
+ // TODO(4805): check if some threshold is reached for max new nullifier
141
+ // NOTE: storageAddress is unused but will be important when an AVM circuit processes an entire enqueued call
142
+ this.newNullifiers.push(new Nullifier(nullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
143
+ this.incrementSideEffectCounter();
144
+ }
145
+
146
+ public traceL1ToL2MessageCheck(_contractAddress: Fr, msgHash: Fr, _msgLeafIndex: Fr, exists: boolean) {
147
+ // TODO(4805): check if some threshold is reached for max message reads
148
+ // NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call
149
+ // TODO(dbanks12): leafIndex is unused for now but later must be used by kernel to constrain that the kernel
150
+ // is in fact checking the leaf indicated by the user
151
+ this.l1ToL2MsgReadRequests.push(new ReadRequest(msgHash, this.sideEffectCounter));
152
+ this.avmCircuitHints.l1ToL2MessageExists.items.push(
153
+ new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)),
154
+ );
155
+ this.incrementSideEffectCounter();
156
+ }
157
+
158
+ public traceNewL2ToL1Message(recipient: Fr, content: Fr) {
159
+ // TODO(4805): check if some threshold is reached for max messages
160
+ const recipientAddress = EthAddress.fromField(recipient);
161
+ this.newL2ToL1Messages.push(new L2ToL1Message(recipientAddress, content, this.sideEffectCounter));
162
+ this.incrementSideEffectCounter();
163
+ }
164
+
165
+ public traceUnencryptedLog(contractAddress: Fr, event: Fr, log: Fr[]) {
166
+ // TODO(4805): check if some threshold is reached for max logs
167
+ const ulog = new UnencryptedL2Log(
168
+ AztecAddress.fromField(contractAddress),
169
+ EventSelector.fromField(event),
170
+ Buffer.concat(log.map(f => f.toBuffer())),
171
+ );
172
+ const basicLogHash = Fr.fromBuffer(ulog.hash());
173
+ this.unencryptedLogs.push(ulog);
174
+ this.allUnencryptedLogs.push(ulog);
175
+ // TODO(6578): explain magic number 4 here
176
+ this.unencryptedLogsHashes.push(new LogHash(basicLogHash, this.sideEffectCounter, new Fr(ulog.length + 4)));
177
+ this.incrementSideEffectCounter();
178
+ }
179
+
180
+ public traceGetContractInstance(instance: TracedContractInstance) {
181
+ // TODO(4805): check if some threshold is reached for max contract instance retrievals
182
+ this.gotContractInstances.push(instance);
183
+ this.avmCircuitHints.contractInstances.items.push(
184
+ new AvmContractInstanceHint(
185
+ instance.address,
186
+ new Fr(instance.exists ? 1 : 0),
187
+ instance.salt,
188
+ instance.deployer,
189
+ instance.contractClassId,
190
+ instance.initializationHash,
191
+ instance.publicKeysHash,
192
+ ),
193
+ );
194
+ this.incrementSideEffectCounter();
195
+ }
196
+
197
+ /**
198
+ * Trace a nested call.
199
+ * Accept some results from a finished nested call's trace into this one.
200
+ */
201
+ public traceNestedCall(
202
+ /** The trace of the nested call. */
203
+ nestedCallTrace: PublicSideEffectTrace,
204
+ /** The execution environment of the nested call. */
205
+ nestedEnvironment: AvmExecutionEnvironment,
206
+ /** How much gas was available for this public execution. */
207
+ startGasLeft: Gas,
208
+ /** How much gas was left after this public execution. */
209
+ endGasLeft: Gas,
210
+ /** Bytecode used for this execution. */
211
+ bytecode: Buffer,
212
+ /** The call's results */
213
+ avmCallResults: AvmContractCallResults,
214
+ /** Function name for logging */
215
+ functionName: string = 'unknown',
216
+ ) {
217
+ const result = nestedCallTrace.toPublicExecutionResult(
218
+ nestedEnvironment,
219
+ startGasLeft,
220
+ endGasLeft,
221
+ bytecode,
222
+ avmCallResults,
223
+ functionName,
224
+ );
225
+ this.sideEffectCounter = result.endSideEffectCounter.toNumber();
226
+ // when a nested call returns, caller accepts its updated counter
227
+ this.allUnencryptedLogs.push(...result.allUnencryptedLogs.logs);
228
+ // NOTE: eventually if the AVM circuit processes an entire enqueued call,
229
+ // this function will accept all of the nested's side effects into this instance
230
+ this.nestedExecutions.push(result);
231
+
232
+ const gasUsed = new Gas(
233
+ result.startGasLeft.daGas - result.endGasLeft.daGas,
234
+ result.startGasLeft.l2Gas - result.endGasLeft.l2Gas,
235
+ );
236
+ this.avmCircuitHints.externalCalls.items.push(
237
+ new AvmExternalCallHint(/*success=*/ new Fr(result.reverted ? 0 : 1), result.returnValues, gasUsed),
238
+ );
239
+ }
240
+
241
+ /**
242
+ * Convert this trace to a PublicExecutionResult for use externally to the simulator.
243
+ */
244
+ public toPublicExecutionResult(
245
+ /** The execution environment of the nested call. */
246
+ avmEnvironment: AvmExecutionEnvironment,
247
+ /** How much gas was available for this public execution. */
248
+ startGasLeft: Gas,
249
+ /** How much gas was left after this public execution. */
250
+ endGasLeft: Gas,
251
+ /** Bytecode used for this execution. */
252
+ bytecode: Buffer,
253
+ /** The call's results */
254
+ avmCallResults: AvmContractCallResults,
255
+ /** Function name for logging */
256
+ functionName: string = 'unknown',
257
+ /** The side effect counter of the execution request itself */
258
+ requestSideEffectCounter: number = this.startSideEffectCounter,
259
+ ): PublicExecutionResult {
260
+ return {
261
+ execution: createPublicExecutionRequest(requestSideEffectCounter, avmEnvironment),
262
+
263
+ startSideEffectCounter: new Fr(this.startSideEffectCounter),
264
+ endSideEffectCounter: new Fr(this.sideEffectCounter),
265
+ startGasLeft,
266
+ endGasLeft,
267
+ transactionFee: avmEnvironment.transactionFee,
268
+
269
+ bytecode,
270
+ calldata: avmEnvironment.calldata,
271
+ returnValues: avmCallResults.output,
272
+ reverted: avmCallResults.reverted,
273
+ revertReason: avmCallResults.revertReason ? createSimulationError(avmCallResults.revertReason) : undefined,
274
+
275
+ contractStorageReads: this.contractStorageReads,
276
+ contractStorageUpdateRequests: this.contractStorageUpdateRequests,
277
+ noteHashReadRequests: this.noteHashReadRequests,
278
+ newNoteHashes: this.newNoteHashes,
279
+ nullifierReadRequests: this.nullifierReadRequests,
280
+ nullifierNonExistentReadRequests: this.nullifierNonExistentReadRequests,
281
+ newNullifiers: this.newNullifiers,
282
+ l1ToL2MsgReadRequests: this.l1ToL2MsgReadRequests,
283
+ newL2ToL1Messages: this.newL2ToL1Messages,
284
+ // correct the type on these now that they are finalized (lists won't grow)
285
+ unencryptedLogs: new UnencryptedFunctionL2Logs(this.unencryptedLogs),
286
+ allUnencryptedLogs: new UnencryptedFunctionL2Logs(this.allUnencryptedLogs),
287
+ unencryptedLogsHashes: this.unencryptedLogsHashes,
288
+ // TODO(dbanks12): process contract instance read requests in public kernel
289
+ //gotContractInstances: this.gotContractInstances,
290
+
291
+ nestedExecutions: this.nestedExecutions,
292
+
293
+ avmCircuitHints: this.avmCircuitHints,
294
+
295
+ functionName,
296
+ };
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Helper function to create a public execution request from an AVM execution environment
302
+ */
303
+ function createPublicExecutionRequest(
304
+ requestSideEffectCounter: number,
305
+ avmEnvironment: AvmExecutionEnvironment,
306
+ ): PublicExecution {
307
+ const callContext = CallContext.from({
308
+ msgSender: avmEnvironment.sender,
309
+ storageContractAddress: avmEnvironment.storageAddress,
310
+ functionSelector: avmEnvironment.temporaryFunctionSelector,
311
+ isDelegateCall: avmEnvironment.isDelegateCall,
312
+ isStaticCall: avmEnvironment.isStaticCall,
313
+ sideEffectCounter: requestSideEffectCounter,
314
+ });
315
+ const execution: PublicExecution = {
316
+ contractAddress: avmEnvironment.address,
317
+ functionSelector: avmEnvironment.temporaryFunctionSelector,
318
+ callContext,
319
+ // execution request does not contain AvmContextInputs prefix
320
+ args: avmEnvironment.getCalldataWithoutPrefix(),
321
+ };
322
+ return execution;
323
+ }
@@ -0,0 +1,41 @@
1
+ import { type Gas } from '@aztec/circuits.js';
2
+ import { type Fr } from '@aztec/foundation/fields';
3
+
4
+ import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
5
+ import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
6
+ import { type TracedContractInstance } from './side_effect_trace.js';
7
+
8
+ export interface PublicSideEffectTraceInterface {
9
+ fork(): PublicSideEffectTraceInterface;
10
+ getCounter(): number;
11
+ tracePublicStorageRead(storageAddress: Fr, slot: Fr, value: Fr, exists: boolean, cached: boolean): void;
12
+ tracePublicStorageWrite(storageAddress: Fr, slot: Fr, value: Fr): void;
13
+ traceNoteHashCheck(storageAddress: Fr, noteHash: Fr, leafIndex: Fr, exists: boolean): void;
14
+ traceNewNoteHash(storageAddress: Fr, noteHash: Fr): void;
15
+ traceNullifierCheck(storageAddress: Fr, nullifier: Fr, leafIndex: Fr, exists: boolean, isPending: boolean): void;
16
+ traceNewNullifier(storageAddress: Fr, nullifier: Fr): void;
17
+ traceL1ToL2MessageCheck(contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr, exists: boolean): void;
18
+ // TODO(dbanks12): should new message accept contract address as arg?
19
+ traceNewL2ToL1Message(recipient: Fr, content: Fr): void;
20
+ traceUnencryptedLog(contractAddress: Fr, event: Fr, log: Fr[]): void;
21
+ // TODO(dbanks12): odd that getContractInstance is a one-off in that it accepts an entire object instead of components
22
+ traceGetContractInstance(instance: TracedContractInstance): void;
23
+ traceNestedCall(
24
+ /** The trace of the nested call. */
25
+ nestedCallTrace: PublicSideEffectTraceInterface,
26
+ /** The execution environment of the nested call. */
27
+ nestedEnvironment: AvmExecutionEnvironment,
28
+ /** How much gas was available for this public execution. */
29
+ // TODO(dbanks12): consider moving to AvmExecutionEnvironment
30
+ startGasLeft: Gas,
31
+ /** How much gas was left after this public execution. */
32
+ // TODO(dbanks12): consider moving to AvmContractCallResults
33
+ endGasLeft: Gas,
34
+ /** Bytecode used for this execution. */
35
+ bytecode: Buffer,
36
+ /** The call's results */
37
+ avmCallResults: AvmContractCallResults,
38
+ /** Function name */
39
+ functionName: string,
40
+ ): void;
41
+ }
@@ -44,6 +44,7 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
44
44
  );
45
45
  if (revertReason) {
46
46
  await this.publicStateDB.rollbackToCheckpoint();
47
+ tx.filterRevertedLogs(kernelOutput);
47
48
  } else {
48
49
  // TODO(#6464): Should we allow emitting contracts in the public teardown phase?
49
50
  // if so, we should insert them here
@@ -1,29 +1,13 @@
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 } from '@aztec/circuit-types';
3
- import {
4
- AvmContractInstanceHint,
5
- AvmExecutionHints,
6
- AvmExternalCallHint,
7
- AvmKeyValueHint,
8
- CallContext,
9
- Gas,
10
- type GasSettings,
11
- type GlobalVariables,
12
- type Header,
13
- } from '@aztec/circuits.js';
2
+ import { type GasSettings, type GlobalVariables, type Header } from '@aztec/circuits.js';
14
3
  import { Fr } from '@aztec/foundation/fields';
15
4
 
16
5
  import { promisify } from 'util';
17
6
  import { gunzip } from 'zlib';
18
7
 
19
- import { type AvmContext } from '../avm/avm_context.js';
20
8
  import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
21
- import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
22
- import { type PartialPublicExecutionResult } from '../avm/journal/journal.js';
23
- import { type WorldStateAccessTrace } from '../avm/journal/trace.js';
24
9
  import { Mov } from '../avm/opcodes/memory.js';
25
- import { createSimulationError } from '../common/errors.js';
26
- import { type PublicExecution, type PublicExecutionResult } from './execution.js';
10
+ import { type PublicExecution } from './execution.js';
27
11
 
28
12
  /**
29
13
  * Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment
@@ -57,88 +41,6 @@ export function createAvmExecutionEnvironment(
57
41
  );
58
42
  }
59
43
 
60
- export function createPublicExecution(
61
- startSideEffectCounter: number,
62
- avmEnvironment: AvmExecutionEnvironment,
63
- calldata: Fr[],
64
- ): PublicExecution {
65
- const callContext = CallContext.from({
66
- msgSender: avmEnvironment.sender,
67
- storageContractAddress: avmEnvironment.storageAddress,
68
- functionSelector: avmEnvironment.temporaryFunctionSelector,
69
- isDelegateCall: avmEnvironment.isDelegateCall,
70
- isStaticCall: avmEnvironment.isStaticCall,
71
- sideEffectCounter: startSideEffectCounter,
72
- });
73
- const execution: PublicExecution = {
74
- contractAddress: avmEnvironment.address,
75
- callContext,
76
- args: calldata,
77
- functionSelector: avmEnvironment.temporaryFunctionSelector,
78
- };
79
- return execution;
80
- }
81
-
82
- function computeHints(trace: WorldStateAccessTrace, executionResult: PartialPublicExecutionResult): AvmExecutionHints {
83
- return new AvmExecutionHints(
84
- trace.publicStorageReads.map(read => new AvmKeyValueHint(read.counter, read.value)),
85
- trace.noteHashChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
86
- trace.nullifierChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
87
- trace.l1ToL2MessageChecks.map(check => new AvmKeyValueHint(check.counter, new Fr(check.exists ? 1 : 0))),
88
- executionResult.nestedExecutions.map(nested => {
89
- const gasUsed = new Gas(
90
- nested.startGasLeft.daGas - nested.endGasLeft.daGas,
91
- nested.startGasLeft.l2Gas - nested.endGasLeft.l2Gas,
92
- );
93
- return new AvmExternalCallHint(/*success=*/ new Fr(nested.reverted ? 0 : 1), nested.returnValues, gasUsed);
94
- }),
95
- trace.gotContractInstances.map(
96
- instance =>
97
- new AvmContractInstanceHint(
98
- instance.address,
99
- new Fr(instance.exists ? 1 : 0),
100
- instance.salt,
101
- instance.deployer,
102
- instance.contractClassId,
103
- instance.initializationHash,
104
- instance.publicKeysHash,
105
- ),
106
- ),
107
- );
108
- }
109
-
110
- export function convertAvmResultsToPxResult(
111
- avmResult: AvmContractCallResults,
112
- startSideEffectCounter: number,
113
- fromPx: PublicExecution,
114
- startGas: Gas,
115
- endAvmContext: AvmContext,
116
- bytecode: Buffer | undefined,
117
- ): PublicExecutionResult {
118
- const endPersistableState = endAvmContext.persistableState;
119
- const endMachineState = endAvmContext.machineState;
120
-
121
- return {
122
- ...endPersistableState.transitionalExecutionResult, // includes nestedExecutions
123
- execution: fromPx,
124
- returnValues: avmResult.output,
125
- startSideEffectCounter: new Fr(startSideEffectCounter),
126
- endSideEffectCounter: new Fr(endPersistableState.trace.accessCounter),
127
- unencryptedLogs: new UnencryptedFunctionL2Logs(endPersistableState.transitionalExecutionResult.unencryptedLogs),
128
- allUnencryptedLogs: new UnencryptedFunctionL2Logs(
129
- endPersistableState.transitionalExecutionResult.allUnencryptedLogs,
130
- ),
131
- reverted: avmResult.reverted,
132
- revertReason: avmResult.revertReason ? createSimulationError(avmResult.revertReason) : undefined,
133
- startGasLeft: startGas,
134
- endGasLeft: endMachineState.gasLeft,
135
- transactionFee: endAvmContext.environment.transactionFee,
136
- bytecode: bytecode,
137
- calldata: endAvmContext.environment.calldata,
138
- avmHints: computeHints(endPersistableState.trace, endPersistableState.transitionalExecutionResult),
139
- };
140
- }
141
-
142
44
  const AVM_MAGIC_SUFFIX = Buffer.from([
143
45
  Mov.opcode, // opcode
144
46
  0x00, // indirect
@@ -1,33 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { type TracedContractInstance, type TracedL1toL2MessageCheck, type TracedNoteHash, type TracedNoteHashCheck, type TracedNullifier, type TracedNullifierCheck, type TracedPublicStorageRead, type TracedPublicStorageWrite, type TracedUnencryptedL2Log } from './trace_types.js';
3
- export declare class WorldStateAccessTrace {
4
- accessCounter: number;
5
- publicStorageReads: TracedPublicStorageRead[];
6
- publicStorageWrites: TracedPublicStorageWrite[];
7
- noteHashChecks: TracedNoteHashCheck[];
8
- newNoteHashes: TracedNoteHash[];
9
- nullifierChecks: TracedNullifierCheck[];
10
- newNullifiers: TracedNullifier[];
11
- l1ToL2MessageChecks: TracedL1toL2MessageCheck[];
12
- newLogsHashes: TracedUnencryptedL2Log[];
13
- gotContractInstances: TracedContractInstance[];
14
- constructor(parentTrace?: WorldStateAccessTrace);
15
- getAccessCounter(): number;
16
- tracePublicStorageRead(storageAddress: Fr, slot: Fr, value: Fr, exists: boolean, cached: boolean): void;
17
- tracePublicStorageWrite(storageAddress: Fr, slot: Fr, value: Fr): void;
18
- traceNoteHashCheck(storageAddress: Fr, noteHash: Fr, exists: boolean, leafIndex: Fr): void;
19
- traceNewNoteHash(storageAddress: Fr, noteHash: Fr): void;
20
- traceNullifierCheck(storageAddress: Fr, nullifier: Fr, exists: boolean, isPending: boolean, leafIndex: Fr): void;
21
- traceNewNullifier(storageAddress: Fr, nullifier: Fr): void;
22
- traceL1ToL2MessageCheck(msgHash: Fr, msgLeafIndex: Fr, exists: boolean): void;
23
- traceNewLog(logHash: Fr): void;
24
- traceGetContractInstance(instance: TracedContractInstance): void;
25
- private incrementAccessCounter;
26
- /**
27
- * Merges another trace into this one
28
- *
29
- * @param incomingTrace - the incoming trace to merge into this instance
30
- */
31
- acceptAndMerge(incomingTrace: WorldStateAccessTrace): void;
32
- }
33
- //# sourceMappingURL=trace.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../src/avm/journal/trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,qBAAqB;IACzB,aAAa,EAAE,MAAM,CAAC;IAEtB,kBAAkB,EAAE,uBAAuB,EAAE,CAAM;IACnD,mBAAmB,EAAE,wBAAwB,EAAE,CAAM;IAErD,cAAc,EAAE,mBAAmB,EAAE,CAAM;IAC3C,aAAa,EAAE,cAAc,EAAE,CAAM;IACrC,eAAe,EAAE,oBAAoB,EAAE,CAAM;IAC7C,aAAa,EAAE,eAAe,EAAE,CAAM;IACtC,mBAAmB,EAAE,wBAAwB,EAAE,CAAM;IACrD,aAAa,EAAE,sBAAsB,EAAE,CAAM;IAC7C,oBAAoB,EAAE,sBAAsB,EAAE,CAAM;gBAK/C,WAAW,CAAC,EAAE,qBAAqB;IAKxC,gBAAgB;IAIhB,sBAAsB,CAAC,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO;IAiBhG,uBAAuB,CAAC,cAAc,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE;IAe/D,kBAAkB,CAAC,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;IAcnF,gBAAgB,CAAC,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;IAajD,mBAAmB,CAAC,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;IAgBzG,iBAAiB,CAAC,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE;IAanD,uBAAuB,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO;IActE,WAAW,CAAC,OAAO,EAAE,EAAE;IASvB,wBAAwB,CAAC,QAAQ,EAAE,sBAAsB;IAKhE,OAAO,CAAC,sBAAsB;IAI9B;;;;OAIG;IACI,cAAc,CAAC,aAAa,EAAE,qBAAqB;CAe3D"}