@aztec/simulator 0.66.0 → 0.67.1-devnet

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 (158) hide show
  1. package/dest/acvm/acvm.js +3 -3
  2. package/dest/acvm/oracle/oracle.d.ts +2 -2
  3. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/acvm/oracle/oracle.js +5 -5
  5. package/dest/acvm/oracle/typed_oracle.d.ts +3 -3
  6. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/acvm/oracle/typed_oracle.js +5 -5
  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 +3 -3
  16. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  17. package/dest/avm/avm_memory_types.js +29 -29
  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 +27 -15
  21. package/dest/avm/avm_tree.d.ts +2 -1
  22. package/dest/avm/avm_tree.d.ts.map +1 -1
  23. package/dest/avm/avm_tree.js +6 -2
  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 +2 -0
  28. package/dest/avm/fixtures/index.d.ts.map +1 -1
  29. package/dest/avm/fixtures/index.js +7 -7
  30. package/dest/avm/journal/journal.d.ts +31 -8
  31. package/dest/avm/journal/journal.d.ts.map +1 -1
  32. package/dest/avm/journal/journal.js +139 -42
  33. package/dest/avm/opcodes/conversion.d.ts +4 -4
  34. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  35. package/dest/avm/opcodes/conversion.js +22 -18
  36. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  37. package/dest/avm/opcodes/external_calls.js +4 -11
  38. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  39. package/dest/avm/opcodes/misc.js +3 -3
  40. package/dest/avm/test_utils.d.ts +1 -0
  41. package/dest/avm/test_utils.d.ts.map +1 -1
  42. package/dest/avm/test_utils.js +4 -1
  43. package/dest/client/client_execution_context.d.ts +3 -3
  44. package/dest/client/client_execution_context.d.ts.map +1 -1
  45. package/dest/client/client_execution_context.js +15 -8
  46. package/dest/client/db_oracle.d.ts +9 -5
  47. package/dest/client/db_oracle.d.ts.map +1 -1
  48. package/dest/client/execution_note_cache.d.ts +9 -1
  49. package/dest/client/execution_note_cache.d.ts.map +1 -1
  50. package/dest/client/execution_note_cache.js +10 -3
  51. package/dest/client/index.d.ts +1 -0
  52. package/dest/client/index.d.ts.map +1 -1
  53. package/dest/client/index.js +2 -1
  54. package/dest/client/private_execution.d.ts.map +1 -1
  55. package/dest/client/private_execution.js +4 -4
  56. package/dest/client/simulator.d.ts.map +1 -1
  57. package/dest/client/simulator.js +4 -4
  58. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  59. package/dest/client/unconstrained_execution.js +3 -3
  60. package/dest/client/view_data_oracle.d.ts +4 -4
  61. package/dest/client/view_data_oracle.d.ts.map +1 -1
  62. package/dest/client/view_data_oracle.js +9 -9
  63. package/dest/common/debug_fn_name.d.ts +2 -2
  64. package/dest/common/debug_fn_name.d.ts.map +1 -1
  65. package/dest/common/debug_fn_name.js +8 -14
  66. package/dest/providers/acvm_native.js +4 -4
  67. package/dest/providers/acvm_wasm.js +2 -2
  68. package/dest/providers/factory.d.ts +2 -2
  69. package/dest/providers/factory.d.ts.map +1 -1
  70. package/dest/providers/factory.js +4 -4
  71. package/dest/providers/index.d.ts +0 -1
  72. package/dest/providers/index.d.ts.map +1 -1
  73. package/dest/providers/index.js +1 -2
  74. package/dest/public/enqueued_call_side_effect_trace.d.ts +15 -26
  75. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  76. package/dest/public/enqueued_call_side_effect_trace.js +42 -62
  77. package/dest/public/execution.d.ts +2 -2
  78. package/dest/public/execution.d.ts.map +1 -1
  79. package/dest/public/execution.js +1 -1
  80. package/dest/public/executor_metrics.d.ts.map +1 -1
  81. package/dest/public/executor_metrics.js +2 -5
  82. package/dest/public/fee_payment.d.ts.map +1 -1
  83. package/dest/public/fee_payment.js +4 -3
  84. package/dest/public/fixtures/index.d.ts +24 -1
  85. package/dest/public/fixtures/index.d.ts.map +1 -1
  86. package/dest/public/fixtures/index.js +17 -11
  87. package/dest/public/index.d.ts +0 -1
  88. package/dest/public/index.d.ts.map +1 -1
  89. package/dest/public/index.js +1 -2
  90. package/dest/public/public_db_sources.d.ts.map +1 -1
  91. package/dest/public/public_db_sources.js +10 -9
  92. package/dest/public/public_processor.d.ts +12 -12
  93. package/dest/public/public_processor.d.ts.map +1 -1
  94. package/dest/public/public_processor.js +80 -68
  95. package/dest/public/public_processor_metrics.d.ts +1 -1
  96. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  97. package/dest/public/public_tx_context.d.ts +13 -10
  98. package/dest/public/public_tx_context.d.ts.map +1 -1
  99. package/dest/public/public_tx_context.js +72 -45
  100. package/dest/public/public_tx_simulator.d.ts +2 -2
  101. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  102. package/dest/public/public_tx_simulator.js +54 -23
  103. package/dest/public/side_effect_trace_interface.d.ts +6 -18
  104. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  105. package/dest/public/transitional_adapters.d.ts +2 -2
  106. package/dest/public/transitional_adapters.d.ts.map +1 -1
  107. package/dest/public/transitional_adapters.js +10 -39
  108. package/package.json +16 -9
  109. package/src/acvm/acvm.ts +2 -2
  110. package/src/acvm/oracle/oracle.ts +4 -4
  111. package/src/acvm/oracle/typed_oracle.ts +5 -5
  112. package/src/acvm/serialize.ts +1 -1
  113. package/src/avm/avm_context.ts +2 -3
  114. package/src/avm/avm_execution_environment.ts +6 -31
  115. package/src/avm/avm_memory_types.ts +31 -29
  116. package/src/avm/avm_simulator.ts +28 -22
  117. package/src/avm/avm_tree.ts +6 -1
  118. package/src/avm/errors.ts +12 -14
  119. package/src/avm/fixtures/index.ts +6 -5
  120. package/src/avm/journal/journal.ts +230 -71
  121. package/src/avm/opcodes/conversion.ts +21 -16
  122. package/src/avm/opcodes/external_calls.ts +3 -19
  123. package/src/avm/opcodes/misc.ts +2 -2
  124. package/src/avm/test_utils.ts +4 -0
  125. package/src/client/client_execution_context.ts +19 -9
  126. package/src/client/db_oracle.ts +10 -5
  127. package/src/client/execution_note_cache.ts +13 -3
  128. package/src/client/index.ts +1 -0
  129. package/src/client/private_execution.ts +3 -3
  130. package/src/client/simulator.ts +4 -4
  131. package/src/client/unconstrained_execution.ts +2 -2
  132. package/src/client/view_data_oracle.ts +11 -9
  133. package/src/common/debug_fn_name.ts +7 -13
  134. package/src/providers/acvm_native.ts +3 -3
  135. package/src/providers/acvm_wasm.ts +2 -2
  136. package/src/providers/factory.ts +3 -3
  137. package/src/providers/index.ts +0 -1
  138. package/src/public/enqueued_call_side_effect_trace.ts +62 -86
  139. package/src/public/execution.ts +1 -2
  140. package/src/public/executor_metrics.ts +0 -4
  141. package/src/public/fee_payment.ts +3 -2
  142. package/src/public/fixtures/index.ts +25 -12
  143. package/src/public/index.ts +0 -1
  144. package/src/public/public_db_sources.ts +9 -8
  145. package/src/public/public_processor.ts +109 -105
  146. package/src/public/public_processor_metrics.ts +1 -1
  147. package/src/public/public_tx_context.ts +97 -50
  148. package/src/public/public_tx_simulator.ts +69 -38
  149. package/src/public/side_effect_trace_interface.ts +10 -16
  150. package/src/public/transitional_adapters.ts +12 -48
  151. package/dest/public/dual_side_effect_trace.d.ts +0 -77
  152. package/dest/public/dual_side_effect_trace.d.ts.map +0 -1
  153. package/dest/public/dual_side_effect_trace.js +0 -119
  154. package/dest/public/side_effect_trace.d.ts +0 -96
  155. package/dest/public/side_effect_trace.d.ts.map +0 -1
  156. package/dest/public/side_effect_trace.js +0 -309
  157. package/src/public/dual_side_effect_trace.ts +0 -242
  158. 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,
@@ -41,7 +42,6 @@ import {
41
42
  PublicDataWrite,
42
43
  ScopedL2ToL1Message,
43
44
  ScopedLogHash,
44
- type ScopedNoteHash,
45
45
  SerializableContractInstance,
46
46
  type TreeSnapshots,
47
47
  } from '@aztec/circuits.js';
@@ -49,11 +49,11 @@ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
49
49
  import { padArrayEnd } from '@aztec/foundation/collection';
50
50
  import { Fr } from '@aztec/foundation/fields';
51
51
  import { jsonStringify } from '@aztec/foundation/json-rpc';
52
- import { createDebugLogger } from '@aztec/foundation/log';
52
+ import { createLogger } from '@aztec/foundation/log';
53
53
 
54
- import { assert } from 'console';
54
+ import { strict as assert } from 'assert';
55
55
 
56
- import { type AvmContractCallResult, type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
56
+ import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
57
57
  import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
58
58
  import { type EnqueuedPublicCallExecutionResultWithSideEffects, type PublicFunctionCallResult } from './execution.js';
59
59
  import { SideEffectLimitReachedError } from './side_effect_errors.js';
@@ -73,7 +73,7 @@ export type SideEffects = {
73
73
  enqueuedCalls: PublicCallRequest[];
74
74
 
75
75
  publicDataWrites: PublicDataUpdateRequest[];
76
- noteHashes: ScopedNoteHash[];
76
+ noteHashes: NoteHash[];
77
77
  nullifiers: Nullifier[];
78
78
  l2ToL1Msgs: ScopedL2ToL1Message[];
79
79
 
@@ -84,6 +84,7 @@ export type SideEffects = {
84
84
  export class SideEffectArrayLengths {
85
85
  constructor(
86
86
  public readonly publicDataWrites: number,
87
+ public readonly protocolPublicDataWrites: number,
87
88
  public readonly noteHashes: number,
88
89
  public readonly nullifiers: number,
89
90
  public readonly l2ToL1Msgs: number,
@@ -91,7 +92,7 @@ export class SideEffectArrayLengths {
91
92
  ) {}
92
93
 
93
94
  static empty() {
94
- return new this(0, 0, 0, 0, 0);
95
+ return new this(0, 0, 0, 0, 0, 0);
95
96
  }
96
97
  }
97
98
 
@@ -99,7 +100,7 @@ export class SideEffectArrayLengths {
99
100
  * Trace side effects for an entire enqueued call.
100
101
  */
101
102
  export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceInterface {
102
- public log = createDebugLogger('aztec:public_enqueued_call_side_effect_trace');
103
+ public log = createLogger('simulator:public_enqueued_call_side_effect_trace');
103
104
 
104
105
  /** The side effect counter increments with every call to the trace. */
105
106
  private sideEffectCounter: number;
@@ -107,7 +108,9 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
107
108
  private enqueuedCalls: PublicCallRequest[] = [];
108
109
 
109
110
  private publicDataWrites: PublicDataUpdateRequest[] = [];
110
- private noteHashes: ScopedNoteHash[] = [];
111
+ private protocolPublicDataWritesLength: number = 0;
112
+ private userPublicDataWritesLength: number = 0;
113
+ private noteHashes: NoteHash[] = [];
111
114
  private nullifiers: Nullifier[] = [];
112
115
  private l2ToL1Messages: ScopedL2ToL1Message[] = [];
113
116
  private unencryptedLogs: UnencryptedL2Log[] = [];
@@ -135,7 +138,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
135
138
  return new PublicEnqueuedCallSideEffectTrace(
136
139
  this.sideEffectCounter,
137
140
  new SideEffectArrayLengths(
138
- this.previousSideEffectArrayLengths.publicDataWrites + this.publicDataWrites.length,
141
+ this.previousSideEffectArrayLengths.publicDataWrites + this.userPublicDataWritesLength,
142
+ this.previousSideEffectArrayLengths.protocolPublicDataWrites + this.protocolPublicDataWritesLength,
139
143
  this.previousSideEffectArrayLengths.noteHashes + this.noteHashes.length,
140
144
  this.previousSideEffectArrayLengths.nullifiers + this.nullifiers.length,
141
145
  this.previousSideEffectArrayLengths.l2ToL1Msgs + this.l2ToL1Messages.length,
@@ -169,13 +173,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
169
173
  private mergeHints(forkedTrace: this) {
170
174
  this.avmCircuitHints.enqueuedCalls.items.push(...forkedTrace.avmCircuitHints.enqueuedCalls.items);
171
175
 
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
176
  this.avmCircuitHints.contractInstances.items.push(...forkedTrace.avmCircuitHints.contractInstances.items);
180
177
  this.avmCircuitHints.contractBytecodeHints.items.push(...forkedTrace.avmCircuitHints.contractBytecodeHints.items);
181
178
 
@@ -196,21 +193,22 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
196
193
  this.sideEffectCounter++;
197
194
  }
198
195
 
196
+ public getNoteHashCount() {
197
+ return this.previousSideEffectArrayLengths.noteHashes + this.noteHashes.length;
198
+ }
199
+
199
200
  public tracePublicStorageRead(
200
- _contractAddress: AztecAddress,
201
+ contractAddress: AztecAddress,
201
202
  slot: Fr,
202
203
  value: Fr,
203
204
  leafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
204
205
  leafIndex: Fr = Fr.zero(),
205
206
  path: Fr[] = emptyPublicDataPath(),
206
207
  ) {
207
- if (!leafIndex.equals(Fr.zero())) {
208
- // if we have real merkle hint content, make sure the value matches the the provided preimage
209
- assert(leafPreimage.value.equals(value), 'Value mismatch when tracing in public data write');
210
- }
211
-
212
208
  this.avmCircuitHints.publicDataReads.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
213
- this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
209
+ this.log.debug(
210
+ `Tracing storage read (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter})`,
211
+ );
214
212
  this.incrementSideEffectCounter();
215
213
  }
216
214
 
@@ -218,24 +216,35 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
218
216
  contractAddress: AztecAddress,
219
217
  slot: Fr,
220
218
  value: Fr,
219
+ protocolWrite: boolean,
221
220
  lowLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
222
221
  lowLeafIndex: Fr = Fr.zero(),
223
222
  lowLeafPath: Fr[] = emptyPublicDataPath(),
224
223
  newLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
225
224
  insertionPath: Fr[] = emptyPublicDataPath(),
226
225
  ) {
227
- if (!lowLeafIndex.equals(Fr.zero())) {
228
- // if we have real merkle hint content, make sure the value matches the the provided preimage
229
- assert(newLeafPreimage.value.equals(value), 'Value mismatch when tracing in public data read');
230
- }
231
- if (
232
- this.publicDataWrites.length + this.previousSideEffectArrayLengths.publicDataWrites >=
233
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
234
- ) {
235
- throw new SideEffectLimitReachedError(
236
- 'public data (contract storage) write',
237
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
238
- );
226
+ if (protocolWrite) {
227
+ if (
228
+ this.protocolPublicDataWritesLength + this.previousSideEffectArrayLengths.protocolPublicDataWrites >=
229
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
230
+ ) {
231
+ throw new SideEffectLimitReachedError(
232
+ 'protocol public data (contract storage) write',
233
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
234
+ );
235
+ }
236
+ this.protocolPublicDataWritesLength++;
237
+ } else {
238
+ if (
239
+ this.userPublicDataWritesLength + this.previousSideEffectArrayLengths.publicDataWrites >=
240
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
241
+ ) {
242
+ throw new SideEffectLimitReachedError(
243
+ 'public data (contract storage) write',
244
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
245
+ );
246
+ }
247
+ this.userPublicDataWritesLength++;
239
248
  }
240
249
 
241
250
  const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot);
@@ -248,7 +257,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
248
257
  );
249
258
 
250
259
  this.log.debug(
251
- `Traced public data write (address=${contractAddress}, slot=${slot}, leafSlot=${leafSlot}): value=${value} (counter=${this.sideEffectCounter})`,
260
+ `Traced public data write (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter}, isProtocol:${protocolWrite})`,
252
261
  );
253
262
  this.incrementSideEffectCounter();
254
263
  }
@@ -266,19 +275,12 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
266
275
  // NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
267
276
  }
268
277
 
269
- public traceNewNoteHash(
270
- contractAddress: AztecAddress,
271
- noteHash: Fr,
272
- leafIndex: Fr = Fr.zero(),
273
- path: Fr[] = emptyNoteHashPath(),
274
- ) {
278
+ public traceNewNoteHash(noteHash: Fr, leafIndex: Fr = Fr.zero(), path: Fr[] = emptyNoteHashPath()) {
275
279
  if (this.noteHashes.length + this.previousSideEffectArrayLengths.noteHashes >= MAX_NOTE_HASHES_PER_TX) {
276
280
  throw new SideEffectLimitReachedError('note hash', MAX_NOTE_HASHES_PER_TX);
277
281
  }
278
282
 
279
- // TODO(dbanks12): make unique and silo instead of scoping
280
- //const siloedNoteHash = siloNoteHash(contractAddress, noteHash);
281
- this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter).scope(contractAddress));
283
+ this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter));
282
284
  this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
283
285
  this.avmCircuitHints.noteHashWrites.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
284
286
  this.incrementSideEffectCounter();
@@ -365,7 +367,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
365
367
  contractAddress: AztecAddress,
366
368
  exists: boolean,
367
369
  instance: SerializableContractInstance = SerializableContractInstance.default(),
370
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
371
+ lowLeafIndex: Fr = Fr.zero(),
372
+ lowLeafPath: Fr[] = emptyNullifierPath(),
368
373
  ) {
374
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
369
375
  this.avmCircuitHints.contractInstances.items.push(
370
376
  new AvmContractInstanceHint(
371
377
  contractAddress,
@@ -375,6 +381,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
375
381
  instance.contractClassId,
376
382
  instance.initializationHash,
377
383
  instance.publicKeys,
384
+ membershipHint,
378
385
  ),
379
386
  );
380
387
  this.log.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`);
@@ -394,7 +401,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
394
401
  privateFunctionsRoot: Fr.zero(),
395
402
  publicBytecodeCommitment: Fr.zero(),
396
403
  },
404
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
405
+ lowLeafIndex: Fr = Fr.zero(),
406
+ lowLeafPath: Fr[] = emptyNullifierPath(),
397
407
  ) {
408
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
398
409
  const instance = new AvmContractInstanceHint(
399
410
  contractAddress,
400
411
  exists,
@@ -403,6 +414,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
403
414
  contractInstance.contractClassId,
404
415
  contractInstance.initializationHash,
405
416
  contractInstance.publicKeys,
417
+ membershipHint,
406
418
  );
407
419
  // We need to deduplicate the contract instances based on addresses
408
420
  this.avmCircuitHints.contractBytecodeHints.items.push(
@@ -413,45 +425,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
413
425
  );
414
426
  }
415
427
 
416
- /**
417
- * Trace a nested call.
418
- * Accept some results from a finished nested call's trace into this one.
419
- */
420
- public traceNestedCall(
421
- /** The trace of the nested call. */
422
- _nestedCallTrace: this,
423
- /** The execution environment of the nested call. */
424
- nestedEnvironment: AvmExecutionEnvironment,
425
- /** How much gas was available for this public execution. */
426
- startGasLeft: Gas,
427
- /** Bytecode used for this execution. */
428
- _bytecode: Buffer,
429
- /** The call's results */
430
- avmCallResults: AvmContractCallResult,
431
- /** Function name for logging */
432
- _functionName: string = 'unknown',
433
- ) {
434
- // TODO(4805): check if some threshold is reached for max nested calls (to unique contracts?)
435
- //
436
- // Store end side effect counter before it gets updated by absorbing nested call trace
437
- const endSideEffectCounter = new Fr(this.sideEffectCounter);
438
-
439
- const gasUsed = new Gas(
440
- startGasLeft.daGas - avmCallResults.gasLeft.daGas,
441
- startGasLeft.l2Gas - avmCallResults.gasLeft.l2Gas,
442
- );
443
-
444
- this.avmCircuitHints.externalCalls.items.push(
445
- new AvmExternalCallHint(
446
- /*success=*/ new Fr(avmCallResults.reverted ? 0 : 1),
447
- avmCallResults.output,
448
- gasUsed,
449
- endSideEffectCounter,
450
- nestedEnvironment.address,
451
- ),
452
- );
453
- }
454
-
455
428
  /**
456
429
  * Trace an enqueued call.
457
430
  * Accept some results from a finished call's trace into this one.
@@ -515,6 +488,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
515
488
  startGasUsed: Gas,
516
489
  /** How much gas was available for this public execution. */
517
490
  gasLimits: GasSettings,
491
+ /** Address of the fee payer. */
492
+ feePayer: AztecAddress,
518
493
  /** Call requests for setup phase. */
519
494
  publicSetupCallRequests: PublicCallRequest[],
520
495
  /** Call requests for app logic phase. */
@@ -538,6 +513,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
538
513
  startTreeSnapshots,
539
514
  startGasUsed,
540
515
  gasLimits,
516
+ feePayer,
541
517
  padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
542
518
  padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
543
519
  publicTeardownCallRequest,
@@ -593,7 +569,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
593
569
  padArrayEnd(
594
570
  this.publicDataWrites.map(w => new PublicDataWrite(w.leafSlot, w.newValue)),
595
571
  PublicDataWrite.empty(),
596
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
572
+ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
597
573
  ),
598
574
  );
599
575
  }
@@ -20,7 +20,6 @@ import {
20
20
  RevertCode,
21
21
  type ScopedL2ToL1Message,
22
22
  type ScopedLogHash,
23
- type ScopedNoteHash,
24
23
  type TreeLeafReadRequest,
25
24
  } from '@aztec/circuits.js';
26
25
  import { computeVarArgsHash } from '@aztec/circuits.js/hash';
@@ -29,7 +28,7 @@ export interface PublicSideEffects {
29
28
  /** The contract storage update requests performed. */
30
29
  publicDataWrites: PublicDataUpdateRequest[];
31
30
  /** The new note hashes to be inserted into the note hashes tree. */
32
- noteHashes: ScopedNoteHash[];
31
+ noteHashes: NoteHash[];
33
32
  /** The new nullifiers to be inserted into the nullifier tree. */
34
33
  nullifiers: Nullifier[];
35
34
  /** The new l2 to l1 messages generated to be inserted into the messages tree. */
@@ -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,13 +1,14 @@
1
1
  import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
2
2
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
- import { ProtocolContractAddress, ProtocolContractArtifact } from '@aztec/protocol-contracts';
4
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
+ import { FeeJuiceArtifact } from '@aztec/protocol-contracts/fee-juice';
5
6
 
6
7
  /**
7
8
  * Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
8
9
  */
9
10
  export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress) {
10
- return deriveStorageSlotInMap(ProtocolContractArtifact.FeeJuice.storageLayout.balances.slot, feePayer);
11
+ return deriveStorageSlotInMap(FeeJuiceArtifact.storageLayout.balances.slot, feePayer);
11
12
  }
12
13
 
13
14
  /**
@@ -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,12 +23,13 @@ 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';
30
- import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
31
+ import { openTmpStore } from '@aztec/kv-store/lmdb';
32
+ import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest';
31
33
  import { PublicTxSimulator, WorldStateDB } from '@aztec/simulator';
32
34
  import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
33
35
  import { MerkleTrees } from '@aztec/world-state';
@@ -54,13 +56,23 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
54
56
  const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
55
57
 
56
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);
57
70
 
58
71
  const simulator = new PublicTxSimulator(
59
72
  merkleTrees,
60
73
  worldStateDB,
61
74
  new NoopTelemetryClient(),
62
75
  globalVariables,
63
- /*realAvmProving=*/ true,
64
76
  /*doMerkleOperations=*/ true,
65
77
  );
66
78
 
@@ -101,7 +113,7 @@ export function createTxForPublicCall(
101
113
  ): Tx {
102
114
  const callRequest = executionRequest.toCallRequest();
103
115
  // use max limits
104
- 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);
105
117
 
106
118
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
107
119
  // TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
@@ -113,9 +125,9 @@ export function createTxForPublicCall(
113
125
  }
114
126
 
115
127
  const teardownGasLimits = isTeardown ? gasLimits : Gas.empty();
116
- const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty());
128
+ const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
117
129
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
118
- const constantData = new TxConstantData(Header.empty(), txContext, Fr.zero(), Fr.zero());
130
+ const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
119
131
 
120
132
  const txData = new PrivateKernelTailCircuitPublicInputs(
121
133
  constantData,
@@ -132,7 +144,7 @@ export function createTxForPublicCall(
132
144
  return tx;
133
145
  }
134
146
 
135
- class MockedAvmTestContractDataSource {
147
+ export class MockedAvmTestContractDataSource {
136
148
  private fnName = 'public_dispatch';
137
149
  private bytecode: Buffer;
138
150
  public fnSelector: FunctionSelector;
@@ -140,7 +152,7 @@ class MockedAvmTestContractDataSource {
140
152
  private contractClass: ContractClassPublic;
141
153
  public contractInstance: ContractInstanceWithAddress;
142
154
  private bytecodeCommitment: Fr;
143
- private otherContractInstance: ContractInstanceWithAddress;
155
+ public otherContractInstance: ContractInstanceWithAddress;
144
156
 
145
157
  constructor() {
146
158
  this.bytecode = getAvmTestContractBytecode(this.fnName);
@@ -150,6 +162,7 @@ class MockedAvmTestContractDataSource {
150
162
  this.contractInstance = makeContractInstanceFromClassId(this.contractClass.id);
151
163
  this.bytecodeCommitment = computePublicBytecodeCommitment(this.bytecode);
152
164
  // The values here should match those in `avm_simulator.test.ts`
165
+ // Used for GETCONTRACTINSTANCE test
153
166
  this.otherContractInstance = new SerializableContractInstance({
154
167
  version: 1,
155
168
  salt: new Fr(0x123),
@@ -162,7 +175,7 @@ class MockedAvmTestContractDataSource {
162
175
  new Point(new Fr(0x252627), new Fr(0x282930), false),
163
176
  new Point(new Fr(0x313233), new Fr(0x343536), false),
164
177
  ),
165
- }).withAddress(this.contractInstance.address);
178
+ }).withAddress(AztecAddress.fromNumber(0x4444));
166
179
  }
167
180
 
168
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';
@@ -20,9 +20,10 @@ import {
20
20
  computePublicBytecodeCommitment,
21
21
  } from '@aztec/circuits.js';
22
22
  import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
23
- import { createDebugLogger } from '@aztec/foundation/log';
23
+ import { createLogger } from '@aztec/foundation/log';
24
24
  import { Timer } from '@aztec/foundation/timer';
25
- import { ContractClassRegisteredEvent, ContractInstanceDeployedEvent } from '@aztec/protocol-contracts';
25
+ import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
26
+ import { ContractInstanceDeployedEvent } from '@aztec/protocol-contracts/instance-deployer';
26
27
  import {
27
28
  type CommitmentsDB,
28
29
  MessageLoadOracleInputs,
@@ -39,7 +40,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
39
40
  private classCache = new Map<string, ContractClassPublic>();
40
41
  private bytecodeCommitmentCache = new Map<string, Fr>();
41
42
 
42
- private log = createDebugLogger('aztec:sequencer:contracts-data-source');
43
+ private log = createLogger('simulator:contracts-data-source');
43
44
 
44
45
  constructor(private dataSource: ContractDataSource) {}
45
46
  /**
@@ -152,7 +153,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
152
153
  * A public state DB that reads and writes to the world state.
153
154
  */
154
155
  export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, CommitmentsDB {
155
- private logger = createDebugLogger('aztec:sequencer:world-state-db');
156
+ private logger = createLogger('simulator:world-state-db');
156
157
 
157
158
  private publicCommittedWriteCache: Map<bigint, Fr> = new Map();
158
159
  private publicCheckpointedWriteCache: Map<bigint, Fr> = new Map();
@@ -207,7 +208,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
207
208
  nullifier: Fr,
208
209
  ): Promise<NullifierMembershipWitness | undefined> {
209
210
  const timer = new Timer();
210
- const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
211
+ const index = (await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]))[0];
211
212
  if (!index) {
212
213
  return undefined;
213
214
  }
@@ -240,7 +241,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
240
241
  ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
241
242
  const timer = new Timer();
242
243
 
243
- const messageIndex = await this.db.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, messageHash);
244
+ const messageIndex = (await this.db.findLeafIndices(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [messageHash]))[0];
244
245
  if (messageIndex === undefined) {
245
246
  throw new Error(`No L1 to L2 message found for message hash ${messageHash.toString()}`);
246
247
  }
@@ -279,7 +280,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
279
280
 
280
281
  public async getCommitmentIndex(commitment: Fr): Promise<bigint | undefined> {
281
282
  const timer = new Timer();
282
- const index = await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment);
283
+ const index = (await this.db.findLeafIndices(MerkleTreeId.NOTE_HASH_TREE, [commitment]))[0];
283
284
  this.logger.debug(`[DB] Fetched commitment index`, {
284
285
  eventName: 'public-db-access',
285
286
  duration: timer.ms(),
@@ -301,7 +302,7 @@ export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicS
301
302
 
302
303
  public async getNullifierIndex(nullifier: Fr): Promise<bigint | undefined> {
303
304
  const timer = new Timer();
304
- const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
305
+ const index = (await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]))[0];
305
306
  this.logger.debug(`[DB] Fetched nullifier index`, {
306
307
  eventName: 'public-db-access',
307
308
  duration: timer.ms(),