@aztec/simulator 0.65.2 → 0.67.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 (136) hide show
  1. package/dest/acvm/acvm.js +3 -3
  2. package/dest/acvm/oracle/oracle.d.ts +1 -4
  3. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/acvm/oracle/oracle.js +3 -19
  5. package/dest/acvm/oracle/typed_oracle.d.ts +2 -7
  6. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/acvm/oracle/typed_oracle.js +3 -12
  8. package/dest/acvm/serialize.js +2 -2
  9. package/dest/avm/avm_context.d.ts +2 -2
  10. package/dest/avm/avm_context.d.ts.map +1 -1
  11. package/dest/avm/avm_context.js +3 -4
  12. package/dest/avm/avm_execution_environment.d.ts +4 -6
  13. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  14. package/dest/avm/avm_execution_environment.js +8 -13
  15. package/dest/avm/avm_memory_types.d.ts +2 -2
  16. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  17. package/dest/avm/avm_memory_types.js +7 -7
  18. package/dest/avm/avm_simulator.d.ts +3 -3
  19. package/dest/avm/avm_simulator.d.ts.map +1 -1
  20. package/dest/avm/avm_simulator.js +26 -16
  21. package/dest/avm/avm_tree.d.ts +31 -14
  22. package/dest/avm/avm_tree.d.ts.map +1 -1
  23. package/dest/avm/avm_tree.js +34 -40
  24. package/dest/avm/errors.d.ts +3 -3
  25. package/dest/avm/errors.d.ts.map +1 -1
  26. package/dest/avm/errors.js +8 -15
  27. package/dest/avm/fixtures/index.d.ts.map +1 -1
  28. package/dest/avm/fixtures/index.js +4 -4
  29. package/dest/avm/journal/journal.d.ts +15 -4
  30. package/dest/avm/journal/journal.d.ts.map +1 -1
  31. package/dest/avm/journal/journal.js +121 -36
  32. package/dest/avm/opcodes/environment_getters.d.ts +10 -11
  33. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  34. package/dest/avm/opcodes/environment_getters.js +12 -15
  35. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  36. package/dest/avm/opcodes/external_calls.js +4 -11
  37. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  38. package/dest/avm/opcodes/misc.js +3 -3
  39. package/dest/client/client_execution_context.d.ts +6 -33
  40. package/dest/client/client_execution_context.d.ts.map +1 -1
  41. package/dest/client/client_execution_context.js +18 -54
  42. package/dest/client/db_oracle.d.ts +2 -2
  43. package/dest/client/db_oracle.d.ts.map +1 -1
  44. package/dest/client/execution_note_cache.d.ts +9 -1
  45. package/dest/client/execution_note_cache.d.ts.map +1 -1
  46. package/dest/client/execution_note_cache.js +10 -3
  47. package/dest/client/private_execution.d.ts.map +1 -1
  48. package/dest/client/private_execution.js +5 -7
  49. package/dest/client/simulator.d.ts.map +1 -1
  50. package/dest/client/simulator.js +4 -4
  51. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  52. package/dest/client/unconstrained_execution.js +3 -3
  53. package/dest/client/view_data_oracle.d.ts +2 -2
  54. package/dest/client/view_data_oracle.d.ts.map +1 -1
  55. package/dest/client/view_data_oracle.js +5 -6
  56. package/dest/common/debug_fn_name.d.ts +2 -2
  57. package/dest/common/debug_fn_name.d.ts.map +1 -1
  58. package/dest/common/debug_fn_name.js +8 -14
  59. package/dest/providers/acvm_native.js +4 -4
  60. package/dest/providers/factory.d.ts +2 -2
  61. package/dest/providers/factory.d.ts.map +1 -1
  62. package/dest/providers/factory.js +4 -4
  63. package/dest/public/enqueued_call_side_effect_trace.d.ts +11 -23
  64. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  65. package/dest/public/enqueued_call_side_effect_trace.js +51 -72
  66. package/dest/public/executor_metrics.d.ts.map +1 -1
  67. package/dest/public/executor_metrics.js +2 -5
  68. package/dest/public/fixtures/index.d.ts +25 -7
  69. package/dest/public/fixtures/index.d.ts.map +1 -1
  70. package/dest/public/fixtures/index.js +20 -17
  71. package/dest/public/index.d.ts +0 -1
  72. package/dest/public/index.d.ts.map +1 -1
  73. package/dest/public/index.js +1 -2
  74. package/dest/public/public_db_sources.d.ts.map +1 -1
  75. package/dest/public/public_db_sources.js +30 -16
  76. package/dest/public/public_processor.d.ts +7 -8
  77. package/dest/public/public_processor.d.ts.map +1 -1
  78. package/dest/public/public_processor.js +37 -26
  79. package/dest/public/public_processor_metrics.d.ts +1 -1
  80. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  81. package/dest/public/public_tx_context.d.ts +13 -14
  82. package/dest/public/public_tx_context.d.ts.map +1 -1
  83. package/dest/public/public_tx_context.js +63 -54
  84. package/dest/public/public_tx_simulator.d.ts +2 -2
  85. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  86. package/dest/public/public_tx_simulator.js +43 -25
  87. package/dest/public/side_effect_trace_interface.d.ts +4 -17
  88. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  89. package/dest/public/transitional_adapters.d.ts +2 -6
  90. package/dest/public/transitional_adapters.d.ts.map +1 -1
  91. package/dest/public/transitional_adapters.js +29 -88
  92. package/package.json +16 -9
  93. package/src/acvm/acvm.ts +2 -2
  94. package/src/acvm/oracle/oracle.ts +2 -32
  95. package/src/acvm/oracle/typed_oracle.ts +3 -20
  96. package/src/acvm/serialize.ts +1 -1
  97. package/src/avm/avm_context.ts +2 -3
  98. package/src/avm/avm_execution_environment.ts +6 -31
  99. package/src/avm/avm_memory_types.ts +6 -6
  100. package/src/avm/avm_simulator.ts +28 -23
  101. package/src/avm/avm_tree.ts +67 -53
  102. package/src/avm/errors.ts +12 -14
  103. package/src/avm/fixtures/index.ts +2 -3
  104. package/src/avm/journal/journal.ts +206 -68
  105. package/src/avm/opcodes/environment_getters.ts +1 -4
  106. package/src/avm/opcodes/external_calls.ts +3 -19
  107. package/src/avm/opcodes/misc.ts +2 -2
  108. package/src/client/client_execution_context.ts +22 -68
  109. package/src/client/db_oracle.ts +2 -2
  110. package/src/client/execution_note_cache.ts +13 -3
  111. package/src/client/private_execution.ts +3 -7
  112. package/src/client/simulator.ts +4 -4
  113. package/src/client/unconstrained_execution.ts +2 -2
  114. package/src/client/view_data_oracle.ts +5 -6
  115. package/src/common/debug_fn_name.ts +7 -13
  116. package/src/providers/acvm_native.ts +3 -3
  117. package/src/providers/factory.ts +3 -3
  118. package/src/public/enqueued_call_side_effect_trace.ts +68 -90
  119. package/src/public/executor_metrics.ts +0 -4
  120. package/src/public/fixtures/index.ts +28 -17
  121. package/src/public/index.ts +0 -1
  122. package/src/public/public_db_sources.ts +32 -19
  123. package/src/public/public_processor.ts +52 -55
  124. package/src/public/public_processor_metrics.ts +1 -1
  125. package/src/public/public_tx_context.ts +89 -76
  126. package/src/public/public_tx_simulator.ts +58 -49
  127. package/src/public/side_effect_trace_interface.ts +8 -15
  128. package/src/public/transitional_adapters.ts +43 -215
  129. package/dest/public/dual_side_effect_trace.d.ts +0 -77
  130. package/dest/public/dual_side_effect_trace.d.ts.map +0 -1
  131. package/dest/public/dual_side_effect_trace.js +0 -119
  132. package/dest/public/side_effect_trace.d.ts +0 -96
  133. package/dest/public/side_effect_trace.d.ts.map +0 -1
  134. package/dest/public/side_effect_trace.js +0 -309
  135. package/src/public/dual_side_effect_trace.ts +0 -242
  136. package/src/public/side_effect_trace.ts +0 -536
@@ -7,7 +7,6 @@ import {
7
7
  AvmContractInstanceHint,
8
8
  AvmEnqueuedCallHint,
9
9
  AvmExecutionHints,
10
- AvmExternalCallHint,
11
10
  AvmNullifierReadTreeHint,
12
11
  AvmNullifierWriteTreeHint,
13
12
  AvmPublicDataReadTreeHint,
@@ -26,12 +25,14 @@ import {
26
25
  MAX_NOTE_HASHES_PER_TX,
27
26
  MAX_NULLIFIERS_PER_TX,
28
27
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
28
+ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
29
29
  MAX_UNENCRYPTED_LOGS_PER_TX,
30
30
  NOTE_HASH_TREE_HEIGHT,
31
31
  NULLIFIER_TREE_HEIGHT,
32
32
  NoteHash,
33
33
  Nullifier,
34
34
  NullifierLeafPreimage,
35
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
35
36
  PUBLIC_DATA_TREE_HEIGHT,
36
37
  PrivateToAvmAccumulatedData,
37
38
  PrivateToAvmAccumulatedDataArrayLengths,
@@ -49,11 +50,11 @@ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
49
50
  import { padArrayEnd } from '@aztec/foundation/collection';
50
51
  import { Fr } from '@aztec/foundation/fields';
51
52
  import { jsonStringify } from '@aztec/foundation/json-rpc';
52
- import { createDebugLogger } from '@aztec/foundation/log';
53
+ import { createLogger } from '@aztec/foundation/log';
53
54
 
54
- import { assert } from 'console';
55
+ import { strict as assert } from 'assert';
55
56
 
56
- import { type AvmContractCallResult, type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
57
+ import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
57
58
  import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
58
59
  import { type EnqueuedPublicCallExecutionResultWithSideEffects, type PublicFunctionCallResult } from './execution.js';
59
60
  import { SideEffectLimitReachedError } from './side_effect_errors.js';
@@ -84,6 +85,7 @@ export type SideEffects = {
84
85
  export class SideEffectArrayLengths {
85
86
  constructor(
86
87
  public readonly publicDataWrites: number,
88
+ public readonly protocolPublicDataWrites: number,
87
89
  public readonly noteHashes: number,
88
90
  public readonly nullifiers: number,
89
91
  public readonly l2ToL1Msgs: number,
@@ -91,7 +93,7 @@ export class SideEffectArrayLengths {
91
93
  ) {}
92
94
 
93
95
  static empty() {
94
- return new this(0, 0, 0, 0, 0);
96
+ return new this(0, 0, 0, 0, 0, 0);
95
97
  }
96
98
  }
97
99
 
@@ -99,7 +101,7 @@ export class SideEffectArrayLengths {
99
101
  * Trace side effects for an entire enqueued call.
100
102
  */
101
103
  export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceInterface {
102
- public log = createDebugLogger('aztec:public_enqueued_call_side_effect_trace');
104
+ public log = createLogger('simulator:public_enqueued_call_side_effect_trace');
103
105
 
104
106
  /** The side effect counter increments with every call to the trace. */
105
107
  private sideEffectCounter: number;
@@ -107,6 +109,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
107
109
  private enqueuedCalls: PublicCallRequest[] = [];
108
110
 
109
111
  private publicDataWrites: PublicDataUpdateRequest[] = [];
112
+ private protocolPublicDataWritesLength: number = 0;
113
+ private userPublicDataWritesLength: number = 0;
110
114
  private noteHashes: ScopedNoteHash[] = [];
111
115
  private nullifiers: Nullifier[] = [];
112
116
  private l2ToL1Messages: ScopedL2ToL1Message[] = [];
@@ -135,7 +139,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
135
139
  return new PublicEnqueuedCallSideEffectTrace(
136
140
  this.sideEffectCounter,
137
141
  new SideEffectArrayLengths(
138
- this.previousSideEffectArrayLengths.publicDataWrites + this.publicDataWrites.length,
142
+ this.previousSideEffectArrayLengths.publicDataWrites + this.userPublicDataWritesLength,
143
+ this.previousSideEffectArrayLengths.protocolPublicDataWrites + this.protocolPublicDataWritesLength,
139
144
  this.previousSideEffectArrayLengths.noteHashes + this.noteHashes.length,
140
145
  this.previousSideEffectArrayLengths.nullifiers + this.nullifiers.length,
141
146
  this.previousSideEffectArrayLengths.l2ToL1Msgs + this.l2ToL1Messages.length,
@@ -169,25 +174,16 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
169
174
  private mergeHints(forkedTrace: this) {
170
175
  this.avmCircuitHints.enqueuedCalls.items.push(...forkedTrace.avmCircuitHints.enqueuedCalls.items);
171
176
 
172
- this.avmCircuitHints.storageValues.items.push(...forkedTrace.avmCircuitHints.storageValues.items);
173
- this.avmCircuitHints.noteHashExists.items.push(...forkedTrace.avmCircuitHints.noteHashExists.items);
174
- this.avmCircuitHints.nullifierExists.items.push(...forkedTrace.avmCircuitHints.nullifierExists.items);
175
- this.avmCircuitHints.l1ToL2MessageExists.items.push(...forkedTrace.avmCircuitHints.l1ToL2MessageExists.items);
176
-
177
- this.avmCircuitHints.externalCalls.items.push(...forkedTrace.avmCircuitHints.externalCalls.items);
178
-
179
177
  this.avmCircuitHints.contractInstances.items.push(...forkedTrace.avmCircuitHints.contractInstances.items);
180
178
  this.avmCircuitHints.contractBytecodeHints.items.push(...forkedTrace.avmCircuitHints.contractBytecodeHints.items);
181
179
 
182
- this.avmCircuitHints.storageReadRequest.items.push(...forkedTrace.avmCircuitHints.storageReadRequest.items);
183
- this.avmCircuitHints.storageUpdateRequest.items.push(...forkedTrace.avmCircuitHints.storageUpdateRequest.items);
184
- this.avmCircuitHints.nullifierReadRequest.items.push(...forkedTrace.avmCircuitHints.nullifierReadRequest.items);
185
- this.avmCircuitHints.nullifierWriteHints.items.push(...forkedTrace.avmCircuitHints.nullifierWriteHints.items);
186
- this.avmCircuitHints.noteHashReadRequest.items.push(...forkedTrace.avmCircuitHints.noteHashReadRequest.items);
187
- this.avmCircuitHints.noteHashWriteRequest.items.push(...forkedTrace.avmCircuitHints.noteHashWriteRequest.items);
188
- this.avmCircuitHints.l1ToL2MessageReadRequest.items.push(
189
- ...forkedTrace.avmCircuitHints.l1ToL2MessageReadRequest.items,
190
- );
180
+ this.avmCircuitHints.publicDataReads.items.push(...forkedTrace.avmCircuitHints.publicDataReads.items);
181
+ this.avmCircuitHints.publicDataWrites.items.push(...forkedTrace.avmCircuitHints.publicDataWrites.items);
182
+ this.avmCircuitHints.nullifierReads.items.push(...forkedTrace.avmCircuitHints.nullifierReads.items);
183
+ this.avmCircuitHints.nullifierWrites.items.push(...forkedTrace.avmCircuitHints.nullifierWrites.items);
184
+ this.avmCircuitHints.noteHashReads.items.push(...forkedTrace.avmCircuitHints.noteHashReads.items);
185
+ this.avmCircuitHints.noteHashWrites.items.push(...forkedTrace.avmCircuitHints.noteHashWrites.items);
186
+ this.avmCircuitHints.l1ToL2MessageReads.items.push(...forkedTrace.avmCircuitHints.l1ToL2MessageReads.items);
191
187
  }
192
188
 
193
189
  public getCounter() {
@@ -199,20 +195,17 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
199
195
  }
200
196
 
201
197
  public tracePublicStorageRead(
202
- _contractAddress: AztecAddress,
198
+ contractAddress: AztecAddress,
203
199
  slot: Fr,
204
200
  value: Fr,
205
201
  leafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
206
202
  leafIndex: Fr = Fr.zero(),
207
203
  path: Fr[] = emptyPublicDataPath(),
208
204
  ) {
209
- if (!leafIndex.equals(Fr.zero())) {
210
- // if we have real merkle hint content, make sure the value matches the the provided preimage
211
- assert(leafPreimage.value.equals(value), 'Value mismatch when tracing in public data write');
212
- }
213
-
214
- this.avmCircuitHints.storageReadRequest.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
215
- this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
205
+ this.avmCircuitHints.publicDataReads.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
206
+ this.log.debug(
207
+ `Tracing storage read (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter})`,
208
+ );
216
209
  this.incrementSideEffectCounter();
217
210
  }
218
211
 
@@ -220,24 +213,35 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
220
213
  contractAddress: AztecAddress,
221
214
  slot: Fr,
222
215
  value: Fr,
216
+ protocolWrite: boolean,
223
217
  lowLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
224
218
  lowLeafIndex: Fr = Fr.zero(),
225
219
  lowLeafPath: Fr[] = emptyPublicDataPath(),
226
220
  newLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
227
221
  insertionPath: Fr[] = emptyPublicDataPath(),
228
222
  ) {
229
- if (!lowLeafIndex.equals(Fr.zero())) {
230
- // if we have real merkle hint content, make sure the value matches the the provided preimage
231
- assert(newLeafPreimage.value.equals(value), 'Value mismatch when tracing in public data read');
232
- }
233
- if (
234
- this.publicDataWrites.length + this.previousSideEffectArrayLengths.publicDataWrites >=
235
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
236
- ) {
237
- throw new SideEffectLimitReachedError(
238
- 'public data (contract storage) write',
239
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
240
- );
223
+ if (protocolWrite) {
224
+ if (
225
+ this.protocolPublicDataWritesLength + this.previousSideEffectArrayLengths.protocolPublicDataWrites >=
226
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
227
+ ) {
228
+ throw new SideEffectLimitReachedError(
229
+ 'protocol public data (contract storage) write',
230
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
231
+ );
232
+ }
233
+ this.protocolPublicDataWritesLength++;
234
+ } else {
235
+ if (
236
+ this.userPublicDataWritesLength + this.previousSideEffectArrayLengths.publicDataWrites >=
237
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
238
+ ) {
239
+ throw new SideEffectLimitReachedError(
240
+ 'public data (contract storage) write',
241
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
242
+ );
243
+ }
244
+ this.userPublicDataWritesLength++;
241
245
  }
242
246
 
243
247
  const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot);
@@ -245,12 +249,12 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
245
249
 
246
250
  // New hinting
247
251
  const readHint = new AvmPublicDataReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
248
- this.avmCircuitHints.storageUpdateRequest.items.push(
252
+ this.avmCircuitHints.publicDataWrites.items.push(
249
253
  new AvmPublicDataWriteTreeHint(readHint, newLeafPreimage, insertionPath),
250
254
  );
251
255
 
252
256
  this.log.debug(
253
- `Traced public data write (address=${contractAddress}, slot=${slot}, leafSlot=${leafSlot}): value=${value} (counter=${this.sideEffectCounter})`,
257
+ `Traced public data write (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter}, isProtocol:${protocolWrite})`,
254
258
  );
255
259
  this.incrementSideEffectCounter();
256
260
  }
@@ -264,7 +268,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
264
268
  path: Fr[] = emptyNoteHashPath(),
265
269
  ) {
266
270
  // New Hinting
267
- this.avmCircuitHints.noteHashReadRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
271
+ this.avmCircuitHints.noteHashReads.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
268
272
  // NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
269
273
  }
270
274
 
@@ -282,7 +286,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
282
286
  //const siloedNoteHash = siloNoteHash(contractAddress, noteHash);
283
287
  this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter).scope(contractAddress));
284
288
  this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
285
- this.avmCircuitHints.noteHashWriteRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
289
+ this.avmCircuitHints.noteHashWrites.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
286
290
  this.incrementSideEffectCounter();
287
291
  }
288
292
 
@@ -293,7 +297,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
293
297
  lowLeafIndex: Fr = Fr.zero(),
294
298
  lowLeafPath: Fr[] = emptyNullifierPath(),
295
299
  ) {
296
- this.avmCircuitHints.nullifierReadRequest.items.push(
300
+ this.avmCircuitHints.nullifierReads.items.push(
297
301
  new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath),
298
302
  );
299
303
  this.log.debug(`NULLIFIER_EXISTS cnt: ${this.sideEffectCounter}`);
@@ -314,7 +318,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
314
318
  this.nullifiers.push(new Nullifier(siloedNullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
315
319
 
316
320
  const lowLeafReadHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
317
- this.avmCircuitHints.nullifierWriteHints.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
321
+ this.avmCircuitHints.nullifierWrites.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
318
322
  this.log.debug(`NEW_NULLIFIER cnt: ${this.sideEffectCounter}`);
319
323
  this.incrementSideEffectCounter();
320
324
  }
@@ -327,7 +331,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
327
331
  _exists: boolean,
328
332
  path: Fr[] = emptyL1ToL2MessagePath(),
329
333
  ) {
330
- this.avmCircuitHints.l1ToL2MessageReadRequest.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
334
+ this.avmCircuitHints.l1ToL2MessageReads.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
331
335
  }
332
336
 
333
337
  public traceNewL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr) {
@@ -367,7 +371,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
367
371
  contractAddress: AztecAddress,
368
372
  exists: boolean,
369
373
  instance: SerializableContractInstance = SerializableContractInstance.default(),
374
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
375
+ lowLeafIndex: Fr = Fr.zero(),
376
+ lowLeafPath: Fr[] = emptyNullifierPath(),
370
377
  ) {
378
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
371
379
  this.avmCircuitHints.contractInstances.items.push(
372
380
  new AvmContractInstanceHint(
373
381
  contractAddress,
@@ -377,6 +385,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
377
385
  instance.contractClassId,
378
386
  instance.initializationHash,
379
387
  instance.publicKeys,
388
+ membershipHint,
380
389
  ),
381
390
  );
382
391
  this.log.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`);
@@ -396,7 +405,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
396
405
  privateFunctionsRoot: Fr.zero(),
397
406
  publicBytecodeCommitment: Fr.zero(),
398
407
  },
408
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
409
+ lowLeafIndex: Fr = Fr.zero(),
410
+ lowLeafPath: Fr[] = emptyNullifierPath(),
399
411
  ) {
412
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
400
413
  const instance = new AvmContractInstanceHint(
401
414
  contractAddress,
402
415
  exists,
@@ -405,6 +418,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
405
418
  contractInstance.contractClassId,
406
419
  contractInstance.initializationHash,
407
420
  contractInstance.publicKeys,
421
+ membershipHint,
408
422
  );
409
423
  // We need to deduplicate the contract instances based on addresses
410
424
  this.avmCircuitHints.contractBytecodeHints.items.push(
@@ -415,45 +429,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
415
429
  );
416
430
  }
417
431
 
418
- /**
419
- * Trace a nested call.
420
- * Accept some results from a finished nested call's trace into this one.
421
- */
422
- public traceNestedCall(
423
- /** The trace of the nested call. */
424
- _nestedCallTrace: this,
425
- /** The execution environment of the nested call. */
426
- nestedEnvironment: AvmExecutionEnvironment,
427
- /** How much gas was available for this public execution. */
428
- startGasLeft: Gas,
429
- /** Bytecode used for this execution. */
430
- _bytecode: Buffer,
431
- /** The call's results */
432
- avmCallResults: AvmContractCallResult,
433
- /** Function name for logging */
434
- _functionName: string = 'unknown',
435
- ) {
436
- // TODO(4805): check if some threshold is reached for max nested calls (to unique contracts?)
437
- //
438
- // Store end side effect counter before it gets updated by absorbing nested call trace
439
- const endSideEffectCounter = new Fr(this.sideEffectCounter);
440
-
441
- const gasUsed = new Gas(
442
- startGasLeft.daGas - avmCallResults.gasLeft.daGas,
443
- startGasLeft.l2Gas - avmCallResults.gasLeft.l2Gas,
444
- );
445
-
446
- this.avmCircuitHints.externalCalls.items.push(
447
- new AvmExternalCallHint(
448
- /*success=*/ new Fr(avmCallResults.reverted ? 0 : 1),
449
- avmCallResults.output,
450
- gasUsed,
451
- endSideEffectCounter,
452
- nestedEnvironment.address,
453
- ),
454
- );
455
- }
456
-
457
432
  /**
458
433
  * Trace an enqueued call.
459
434
  * Accept some results from a finished call's trace into this one.
@@ -517,6 +492,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
517
492
  startGasUsed: Gas,
518
493
  /** How much gas was available for this public execution. */
519
494
  gasLimits: GasSettings,
495
+ /** Address of the fee payer. */
496
+ feePayer: AztecAddress,
520
497
  /** Call requests for setup phase. */
521
498
  publicSetupCallRequests: PublicCallRequest[],
522
499
  /** Call requests for app logic phase. */
@@ -540,6 +517,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
540
517
  startTreeSnapshots,
541
518
  startGasUsed,
542
519
  gasLimits,
520
+ feePayer,
543
521
  padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
544
522
  padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
545
523
  publicTeardownCallRequest,
@@ -595,7 +573,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
595
573
  padArrayEnd(
596
574
  this.publicDataWrites.map(w => new PublicDataWrite(w.leafSlot, w.newValue)),
597
575
  PublicDataWrite.empty(),
598
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
576
+ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
599
577
  ),
600
578
  );
601
579
  }
@@ -6,7 +6,6 @@ import {
6
6
  type Tracer,
7
7
  type UpDownCounter,
8
8
  ValueType,
9
- linearBuckets,
10
9
  } from '@aztec/telemetry-client';
11
10
 
12
11
  export class ExecutorMetrics {
@@ -33,9 +32,6 @@ export class ExecutorMetrics {
33
32
  description: 'Mana used per second',
34
33
  unit: 'mana/s',
35
34
  valueType: ValueType.INT,
36
- advice: {
37
- explicitBucketBoundaries: linearBuckets(0, 10_000_000, 10),
38
- },
39
35
  });
40
36
  }
41
37
 
@@ -1,17 +1,18 @@
1
- import { PublicExecutionRequest, Tx } from '@aztec/circuit-types';
1
+ import { MerkleTreeId, PublicExecutionRequest, Tx } from '@aztec/circuit-types';
2
2
  import {
3
3
  type AvmCircuitInputs,
4
+ BlockHeader,
4
5
  CallContext,
5
6
  type ContractClassPublic,
6
7
  type ContractInstanceWithAddress,
7
8
  DEFAULT_GAS_LIMIT,
9
+ DEPLOYER_CONTRACT_ADDRESS,
8
10
  FunctionSelector,
9
11
  Gas,
10
12
  GasFees,
11
13
  GasSettings,
12
14
  GlobalVariables,
13
- Header,
14
- MAX_L2_GAS_PER_ENQUEUED_CALL,
15
+ MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
15
16
  PartialPrivateTailPublicInputsForPublic,
16
17
  PrivateKernelTailCircuitPublicInputs,
17
18
  type PublicFunction,
@@ -22,11 +23,12 @@ import {
22
23
  TxContext,
23
24
  computePublicBytecodeCommitment,
24
25
  } from '@aztec/circuits.js';
26
+ import { siloNullifier } from '@aztec/circuits.js/hash';
25
27
  import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/circuits.js/testing';
26
28
  import { type ContractArtifact, type FunctionArtifact } from '@aztec/foundation/abi';
27
29
  import { AztecAddress } from '@aztec/foundation/aztec-address';
28
30
  import { Fr, Point } from '@aztec/foundation/fields';
29
- import { openTmpStore } from '@aztec/kv-store/utils';
31
+ import { openTmpStore } from '@aztec/kv-store/lmdb';
30
32
  import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
31
33
  import { PublicTxSimulator, WorldStateDB } from '@aztec/simulator';
32
34
  import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
@@ -34,14 +36,10 @@ import { MerkleTrees } from '@aztec/world-state';
34
36
 
35
37
  import { strict as assert } from 'assert';
36
38
 
37
- /**
38
- * If assertionErrString is set, we expect a (non exceptional halting) revert due to a failing assertion and
39
- * we check that the revert reason error contains this string. However, the circuit must correctly prove the
40
- * execution.
41
- */
42
39
  export async function simulateAvmTestContractGenerateCircuitInputs(
43
40
  functionName: string,
44
41
  calldata: Fr[] = [],
42
+ expectRevert: boolean = false,
45
43
  assertionErrString?: string,
46
44
  ): Promise<AvmCircuitInputs> {
47
45
  const sender = AztecAddress.random();
@@ -58,13 +56,23 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
58
56
  const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
59
57
 
60
58
  const contractInstance = contractDataSource.contractInstance;
59
+ const contractAddressNullifier = siloNullifier(
60
+ AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
61
+ contractInstance.address.toField(),
62
+ );
63
+ await merkleTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, [contractAddressNullifier.toBuffer()], 0);
64
+ // other contract address used by the bulk test's GETCONTRACTINSTANCE test
65
+ const otherContractAddressNullifier = siloNullifier(
66
+ AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
67
+ contractDataSource.otherContractInstance.address.toField(),
68
+ );
69
+ await merkleTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, [otherContractAddressNullifier.toBuffer()], 0);
61
70
 
62
71
  const simulator = new PublicTxSimulator(
63
72
  merkleTrees,
64
73
  worldStateDB,
65
74
  new NoopTelemetryClient(),
66
75
  globalVariables,
67
- /*realAvmProving=*/ true,
68
76
  /*doMerkleOperations=*/ true,
69
77
  );
70
78
 
@@ -80,13 +88,15 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
80
88
 
81
89
  const avmResult = await simulator.simulate(tx);
82
90
 
83
- if (assertionErrString == undefined) {
91
+ if (!expectRevert) {
84
92
  expect(avmResult.revertCode.isOK()).toBe(true);
85
93
  } else {
86
94
  // Explicit revert when an assertion failed.
87
95
  expect(avmResult.revertCode.isOK()).toBe(false);
88
96
  expect(avmResult.revertReason).toBeDefined();
89
- expect(avmResult.revertReason?.getMessage()).toContain(assertionErrString);
97
+ if (assertionErrString !== undefined) {
98
+ expect(avmResult.revertReason?.getMessage()).toContain(assertionErrString);
99
+ }
90
100
  }
91
101
 
92
102
  const avmCircuitInputs: AvmCircuitInputs = avmResult.avmProvingRequest.inputs;
@@ -103,7 +113,7 @@ export function createTxForPublicCall(
103
113
  ): Tx {
104
114
  const callRequest = executionRequest.toCallRequest();
105
115
  // use max limits
106
- const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_ENQUEUED_CALL);
116
+ const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
107
117
 
108
118
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
109
119
  // TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
@@ -117,7 +127,7 @@ export function createTxForPublicCall(
117
127
  const teardownGasLimits = isTeardown ? gasLimits : Gas.empty();
118
128
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty());
119
129
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
120
- const constantData = new TxConstantData(Header.empty(), txContext, Fr.zero(), Fr.zero());
130
+ const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
121
131
 
122
132
  const txData = new PrivateKernelTailCircuitPublicInputs(
123
133
  constantData,
@@ -134,7 +144,7 @@ export function createTxForPublicCall(
134
144
  return tx;
135
145
  }
136
146
 
137
- class MockedAvmTestContractDataSource {
147
+ export class MockedAvmTestContractDataSource {
138
148
  private fnName = 'public_dispatch';
139
149
  private bytecode: Buffer;
140
150
  public fnSelector: FunctionSelector;
@@ -142,7 +152,7 @@ class MockedAvmTestContractDataSource {
142
152
  private contractClass: ContractClassPublic;
143
153
  public contractInstance: ContractInstanceWithAddress;
144
154
  private bytecodeCommitment: Fr;
145
- private otherContractInstance: ContractInstanceWithAddress;
155
+ public otherContractInstance: ContractInstanceWithAddress;
146
156
 
147
157
  constructor() {
148
158
  this.bytecode = getAvmTestContractBytecode(this.fnName);
@@ -152,6 +162,7 @@ class MockedAvmTestContractDataSource {
152
162
  this.contractInstance = makeContractInstanceFromClassId(this.contractClass.id);
153
163
  this.bytecodeCommitment = computePublicBytecodeCommitment(this.bytecode);
154
164
  // The values here should match those in `avm_simulator.test.ts`
165
+ // Used for GETCONTRACTINSTANCE test
155
166
  this.otherContractInstance = new SerializableContractInstance({
156
167
  version: 1,
157
168
  salt: new Fr(0x123),
@@ -164,7 +175,7 @@ class MockedAvmTestContractDataSource {
164
175
  new Point(new Fr(0x252627), new Fr(0x282930), false),
165
176
  new Point(new Fr(0x313233), new Fr(0x343536), false),
166
177
  ),
167
- }).withAddress(this.contractInstance.address);
178
+ }).withAddress(AztecAddress.fromNumber(0x4444));
168
179
  }
169
180
 
170
181
  getPublicFunction(_address: AztecAddress, _selector: FunctionSelector): Promise<PublicFunction> {
@@ -4,6 +4,5 @@ export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult }
4
4
  export * from './fee_payment.js';
5
5
  export * from './public_db_sources.js';
6
6
  export { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
7
- export { PublicSideEffectTrace } from './side_effect_trace.js';
8
7
  export { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
9
8
  export { getExecutionRequestsByPhase } from './utils.js';
@@ -9,9 +9,7 @@ import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
9
9
  import {
10
10
  type AztecAddress,
11
11
  type ContractClassPublic,
12
- ContractClassRegisteredEvent,
13
12
  type ContractDataSource,
14
- ContractInstanceDeployedEvent,
15
13
  type ContractInstanceWithAddress,
16
14
  Fr,
17
15
  type FunctionSelector,
@@ -22,9 +20,9 @@ import {
22
20
  computePublicBytecodeCommitment,
23
21
  } from '@aztec/circuits.js';
24
22
  import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
25
- import { createDebugLogger } from '@aztec/foundation/log';
23
+ import { createLogger } from '@aztec/foundation/log';
26
24
  import { Timer } from '@aztec/foundation/timer';
27
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
25
+ import { ContractClassRegisteredEvent, ContractInstanceDeployedEvent } from '@aztec/protocol-contracts';
28
26
  import {
29
27
  type CommitmentsDB,
30
28
  MessageLoadOracleInputs,
@@ -41,7 +39,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
41
39
  private classCache = new Map<string, ContractClassPublic>();
42
40
  private bytecodeCommitmentCache = new Map<string, Fr>();
43
41
 
44
- private log = createDebugLogger('aztec:sequencer:contracts-data-source');
42
+ private log = createLogger('simulator:contracts-data-source');
45
43
 
46
44
  constructor(private dataSource: ContractDataSource) {}
47
45
  /**
@@ -51,13 +49,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
51
49
  public addNewContracts(tx: Tx): Promise<void> {
52
50
  // Extract contract class and instance data from logs and add to cache for this block
53
51
  const logs = tx.contractClassLogs.unrollLogs();
54
- ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e => {
55
- this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
56
- this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
57
- });
58
- // We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
59
- const encLogs = tx.encryptedLogs.unrollLogs();
60
- ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => {
52
+ logs
53
+ .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
54
+ .forEach(log => {
55
+ const event = ContractClassRegisteredEvent.fromLog(log.data);
56
+ this.log.debug(`Adding class ${event.contractClassId.toString()} to public execution contract cache`);
57
+ this.classCache.set(event.contractClassId.toString(), event.toContractClassPublic());
58
+ });
59
+
60
+ // We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
61
+ const contractInstanceEvents = tx.data
62
+ .getNonEmptyPrivateLogs()
63
+ .filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
64
+ .map(ContractInstanceDeployedEvent.fromLog);
65
+ contractInstanceEvents.forEach(e => {
61
66
  this.log.debug(
62
67
  `Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to public execution contract cache`,
63
68
  );
@@ -76,12 +81,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
76
81
  // Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
77
82
  // wouldn't that accidentally remove the contract added on the first one?
78
83
  const logs = tx.contractClassLogs.unrollLogs();
79
- ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e =>
80
- this.classCache.delete(e.contractClassId.toString()),
81
- );
82
- // We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
83
- const encLogs = tx.encryptedLogs.unrollLogs();
84
- ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => this.instanceCache.delete(e.address.toString()));
84
+ logs
85
+ .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
86
+ .forEach(log => {
87
+ const event = ContractClassRegisteredEvent.fromLog(log.data);
88
+ this.classCache.delete(event.contractClassId.toString());
89
+ });
90
+
91
+ // We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
92
+ const contractInstanceEvents = tx.data
93
+ .getNonEmptyPrivateLogs()
94
+ .filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
95
+ .map(ContractInstanceDeployedEvent.fromLog);
96
+ contractInstanceEvents.forEach(e => this.instanceCache.delete(e.address.toString()));
97
+
85
98
  return Promise.resolve();
86
99
  }
87
100
 
@@ -139,7 +152,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
139
152
  * A public state DB that reads and writes to the world state.
140
153
  */
141
154
  export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, CommitmentsDB {
142
- private logger = createDebugLogger('aztec:sequencer:world-state-db');
155
+ private logger = createLogger('simulator:world-state-db');
143
156
 
144
157
  private publicCommittedWriteCache: Map<bigint, Fr> = new Map();
145
158
  private publicCheckpointedWriteCache: Map<bigint, Fr> = new Map();