@aztec/simulator 0.71.0 → 0.73.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 (137) hide show
  1. package/README.md +1 -1
  2. package/dest/acvm/oracle/oracle.d.ts +0 -1
  3. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/acvm/oracle/oracle.js +1 -5
  5. package/dest/acvm/oracle/typed_oracle.d.ts +0 -1
  6. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/acvm/oracle/typed_oracle.js +1 -4
  8. package/dest/avm/avm_simulator.d.ts +0 -1
  9. package/dest/avm/avm_simulator.d.ts.map +1 -1
  10. package/dest/avm/avm_simulator.js +4 -19
  11. package/dest/avm/avm_tree.d.ts +9 -8
  12. package/dest/avm/avm_tree.d.ts.map +1 -1
  13. package/dest/avm/avm_tree.js +35 -30
  14. package/dest/avm/errors.d.ts +6 -0
  15. package/dest/avm/errors.d.ts.map +1 -1
  16. package/dest/avm/errors.js +10 -1
  17. package/dest/avm/fixtures/avm_simulation_tester.d.ts +21 -0
  18. package/dest/avm/fixtures/avm_simulation_tester.d.ts.map +1 -0
  19. package/dest/avm/fixtures/avm_simulation_tester.js +74 -0
  20. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts +35 -0
  21. package/dest/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -0
  22. package/dest/avm/fixtures/base_avm_simulation_tester.js +76 -0
  23. package/dest/avm/fixtures/index.d.ts +6 -2
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +28 -14
  26. package/dest/avm/fixtures/simple_contract_data_source.d.ts +31 -0
  27. package/dest/avm/fixtures/simple_contract_data_source.d.ts.map +1 -0
  28. package/dest/avm/fixtures/simple_contract_data_source.js +75 -0
  29. package/dest/avm/journal/journal.d.ts +5 -6
  30. package/dest/avm/journal/journal.d.ts.map +1 -1
  31. package/dest/avm/journal/journal.js +28 -26
  32. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  33. package/dest/avm/opcodes/accrued_substate.js +4 -3
  34. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  35. package/dest/avm/opcodes/conversion.js +10 -7
  36. package/dest/avm/opcodes/ec_add.js +2 -2
  37. package/dest/avm/opcodes/hashing.js +2 -2
  38. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  39. package/dest/avm/opcodes/multi_scalar_mul.js +9 -7
  40. package/dest/avm/test_utils.d.ts +1 -1
  41. package/dest/avm/test_utils.d.ts.map +1 -1
  42. package/dest/avm/test_utils.js +4 -3
  43. package/dest/client/client_execution_context.d.ts +2 -6
  44. package/dest/client/client_execution_context.d.ts.map +1 -1
  45. package/dest/client/client_execution_context.js +23 -26
  46. package/dest/client/execution_note_cache.d.ts +3 -3
  47. package/dest/client/execution_note_cache.d.ts.map +1 -1
  48. package/dest/client/execution_note_cache.js +10 -10
  49. package/dest/client/pick_notes.js +5 -5
  50. package/dest/client/simulator.js +4 -4
  51. package/dest/client/view_data_oracle.js +2 -2
  52. package/dest/common/hashed_values_cache.d.ts +1 -1
  53. package/dest/common/hashed_values_cache.d.ts.map +1 -1
  54. package/dest/common/hashed_values_cache.js +5 -5
  55. package/dest/providers/acvm_wasm.d.ts +2 -0
  56. package/dest/providers/acvm_wasm.d.ts.map +1 -1
  57. package/dest/providers/acvm_wasm.js +15 -2
  58. package/dest/public/execution.d.ts +8 -26
  59. package/dest/public/execution.d.ts.map +1 -1
  60. package/dest/public/execution.js +3 -3
  61. package/dest/public/fee_payment.d.ts +2 -2
  62. package/dest/public/fee_payment.d.ts.map +1 -1
  63. package/dest/public/fee_payment.js +3 -3
  64. package/dest/public/fixtures/index.d.ts +2 -37
  65. package/dest/public/fixtures/index.d.ts.map +1 -1
  66. package/dest/public/fixtures/index.js +3 -247
  67. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +21 -0
  68. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
  69. package/dest/public/fixtures/public_tx_simulation_tester.js +89 -0
  70. package/dest/public/fixtures/utils.d.ts +17 -0
  71. package/dest/public/fixtures/utils.d.ts.map +1 -0
  72. package/dest/public/fixtures/utils.js +66 -0
  73. package/dest/public/index.d.ts +1 -1
  74. package/dest/public/index.d.ts.map +1 -1
  75. package/dest/public/index.js +2 -2
  76. package/dest/public/public_db_sources.d.ts +2 -1
  77. package/dest/public/public_db_sources.d.ts.map +1 -1
  78. package/dest/public/public_db_sources.js +27 -21
  79. package/dest/public/public_processor.d.ts +4 -5
  80. package/dest/public/public_processor.d.ts.map +1 -1
  81. package/dest/public/public_processor.js +28 -28
  82. package/dest/public/public_tx_context.d.ts +5 -5
  83. package/dest/public/public_tx_context.d.ts.map +1 -1
  84. package/dest/public/public_tx_context.js +44 -18
  85. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  86. package/dest/public/public_tx_simulator.js +9 -12
  87. package/dest/public/{enqueued_call_side_effect_trace.d.ts → side_effect_trace.d.ts} +12 -15
  88. package/dest/public/side_effect_trace.d.ts.map +1 -0
  89. package/dest/public/side_effect_trace.js +350 -0
  90. package/dest/public/side_effect_trace_interface.d.ts +4 -5
  91. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  92. package/dest/test/utils.d.ts +1 -1
  93. package/dest/test/utils.d.ts.map +1 -1
  94. package/dest/test/utils.js +3 -3
  95. package/package.json +10 -10
  96. package/src/acvm/oracle/oracle.ts +0 -5
  97. package/src/acvm/oracle/typed_oracle.ts +0 -4
  98. package/src/avm/avm_simulator.ts +3 -27
  99. package/src/avm/avm_tree.ts +39 -37
  100. package/src/avm/errors.ts +10 -0
  101. package/src/avm/fixtures/avm_simulation_tester.ts +105 -0
  102. package/src/avm/fixtures/base_avm_simulation_tester.ts +104 -0
  103. package/src/avm/fixtures/index.ts +46 -17
  104. package/src/avm/fixtures/simple_contract_data_source.ts +98 -0
  105. package/src/avm/journal/journal.ts +28 -26
  106. package/src/avm/opcodes/accrued_substate.ts +3 -2
  107. package/src/avm/opcodes/conversion.ts +15 -6
  108. package/src/avm/opcodes/ec_add.ts +1 -1
  109. package/src/avm/opcodes/hashing.ts +1 -1
  110. package/src/avm/opcodes/multi_scalar_mul.ts +8 -6
  111. package/src/avm/test_utils.ts +3 -4
  112. package/src/client/client_execution_context.ts +29 -30
  113. package/src/client/execution_note_cache.ts +19 -14
  114. package/src/client/pick_notes.ts +4 -4
  115. package/src/client/simulator.ts +3 -3
  116. package/src/client/view_data_oracle.ts +1 -1
  117. package/src/common/hashed_values_cache.ts +4 -4
  118. package/src/providers/acvm_wasm.ts +13 -2
  119. package/src/public/execution.ts +10 -34
  120. package/src/public/fee_payment.ts +2 -2
  121. package/src/public/fixtures/index.ts +2 -381
  122. package/src/public/fixtures/public_tx_simulation_tester.ts +174 -0
  123. package/src/public/fixtures/utils.ts +110 -0
  124. package/src/public/index.ts +1 -1
  125. package/src/public/public_db_sources.ts +31 -20
  126. package/src/public/public_processor.ts +32 -30
  127. package/src/public/public_tx_context.ts +87 -28
  128. package/src/public/public_tx_simulator.ts +7 -14
  129. package/src/public/{enqueued_call_side_effect_trace.ts → side_effect_trace.ts} +29 -41
  130. package/src/public/side_effect_trace_interface.ts +4 -4
  131. package/src/test/utils.ts +2 -2
  132. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +0 -1
  133. package/dest/public/enqueued_call_side_effect_trace.js +0 -357
  134. package/dest/public/transitional_adapters.d.ts +0 -4
  135. package/dest/public/transitional_adapters.d.ts.map +0 -1
  136. package/dest/public/transitional_adapters.js +0 -29
  137. package/src/public/transitional_adapters.ts +0 -113
@@ -95,7 +95,7 @@ export class ClientExecutionContext extends ViewDataOracle {
95
95
  const args = this.executionCache.getPreimage(this.argsHash);
96
96
 
97
97
  if (args.length !== argumentsSize) {
98
- throw new Error('Invalid arguments size');
98
+ throw new Error(`Invalid arguments size: expected ${argumentsSize}, got ${args.length}`);
99
99
  }
100
100
 
101
101
  const privateContextInputs = new PrivateContextInputs(
@@ -160,21 +160,13 @@ export class ClientExecutionContext extends ViewDataOracle {
160
160
  return this.publicTeardownFunctionCall;
161
161
  }
162
162
 
163
- /**
164
- * Store values in the execution cache.
165
- * @param values - Values to store.
166
- */
167
- public override storeArrayInExecutionCache(args: Fr[]): Promise<Fr> {
168
- return Promise.resolve(this.executionCache.store(args));
169
- }
170
-
171
163
  /**
172
164
  * Store values in the execution cache.
173
165
  * @param values - Values to store.
174
166
  * @returns The hash of the values.
175
167
  */
176
168
  public override storeInExecutionCache(values: Fr[]): Promise<Fr> {
177
- return Promise.resolve(this.executionCache.store(values));
169
+ return this.executionCache.store(values);
178
170
  }
179
171
 
180
172
  /**
@@ -249,14 +241,22 @@ export class ClientExecutionContext extends ViewDataOracle {
249
241
  .join(', ')}`,
250
242
  );
251
243
 
252
- notes.forEach(n => {
253
- if (n.index !== undefined) {
254
- const siloedNoteHash = siloNoteHash(n.contractAddress, n.noteHash);
255
- const uniqueNoteHash = computeUniqueNoteHash(n.nonce, siloedNoteHash);
244
+ const noteHashesAndIndexes = await Promise.all(
245
+ notes.map(async n => {
246
+ if (n.index !== undefined) {
247
+ const siloedNoteHash = await siloNoteHash(n.contractAddress, n.noteHash);
248
+ const uniqueNoteHash = await computeUniqueNoteHash(n.nonce, siloedNoteHash);
256
249
 
257
- this.noteHashLeafIndexMap.set(uniqueNoteHash.toBigInt(), n.index);
258
- }
259
- });
250
+ return { hash: uniqueNoteHash, index: n.index };
251
+ }
252
+ }),
253
+ );
254
+
255
+ noteHashesAndIndexes
256
+ .filter(n => n !== undefined)
257
+ .forEach(n => {
258
+ this.noteHashLeafIndexMap.set(n!.hash.toBigInt(), n!.index);
259
+ });
260
260
 
261
261
  return notes;
262
262
  }
@@ -299,8 +299,8 @@ export class ClientExecutionContext extends ViewDataOracle {
299
299
  * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
300
300
  * @param noteHash - A hash of the new note.
301
301
  */
302
- public override notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number) {
303
- const nullifiedNoteHashCounter = this.noteCache.nullifyNote(
302
+ public override async notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number) {
303
+ const nullifiedNoteHashCounter = await this.noteCache.nullifyNote(
304
304
  this.callContext.contractAddress,
305
305
  innerNullifier,
306
306
  noteHash,
@@ -308,7 +308,6 @@ export class ClientExecutionContext extends ViewDataOracle {
308
308
  if (nullifiedNoteHashCounter !== undefined) {
309
309
  this.noteHashNullifierCounterMap.set(nullifiedNoteHashCounter, counter);
310
310
  }
311
- return Promise.resolve();
312
311
  }
313
312
 
314
313
  /**
@@ -318,8 +317,7 @@ export class ClientExecutionContext extends ViewDataOracle {
318
317
  * @param noteHash - A hash of the new note.
319
318
  */
320
319
  public override notifyCreatedNullifier(innerNullifier: Fr) {
321
- this.noteCache.nullifierCreated(this.callContext.contractAddress, innerNullifier);
322
- return Promise.resolve();
320
+ return this.noteCache.nullifierCreated(this.callContext.contractAddress, innerNullifier);
323
321
  }
324
322
 
325
323
  /**
@@ -327,6 +325,7 @@ export class ClientExecutionContext extends ViewDataOracle {
327
325
  * This fn exists because sha hashing the preimage
328
326
  * is too large to compile (16,200 fields, 518,400 bytes) => the oracle hashes it.
329
327
  * See private_context.nr
328
+ * TODO(#8945): Contract class logs are currently sha hashes. When these are fields, delete this.
330
329
  * @param log - The unencrypted log to be emitted.
331
330
  */
332
331
  public override emitContractClassLog(log: UnencryptedL2Log, counter: number) {
@@ -376,7 +375,7 @@ export class ClientExecutionContext extends ViewDataOracle {
376
375
 
377
376
  const derivedTxContext = this.txContext.clone();
378
377
 
379
- const derivedCallContext = this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
378
+ const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
380
379
 
381
380
  const context = new ClientExecutionContext(
382
381
  argsHash,
@@ -433,7 +432,7 @@ export class ClientExecutionContext extends ViewDataOracle {
433
432
  isStaticCall: boolean,
434
433
  ) {
435
434
  const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
436
- const derivedCallContext = this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
435
+ const derivedCallContext = await this.deriveCallContext(targetContractAddress, targetArtifact, isStaticCall);
437
436
  const args = this.executionCache.getPreimage(argsHash);
438
437
 
439
438
  this.log.verbose(
@@ -483,7 +482,7 @@ export class ClientExecutionContext extends ViewDataOracle {
483
482
  // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
484
483
  // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
485
484
  // b) this is only temporary.
486
- const newArgsHash = this.executionCache.store([
485
+ const newArgsHash = await this.executionCache.store([
487
486
  functionSelector.toField(),
488
487
  ...this.executionCache.getPreimage(argsHash),
489
488
  ]);
@@ -522,7 +521,7 @@ export class ClientExecutionContext extends ViewDataOracle {
522
521
  // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
523
522
  // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
524
523
  // b) this is only temporary.
525
- const newArgsHash = this.executionCache.store([
524
+ const newArgsHash = await this.executionCache.store([
526
525
  functionSelector.toField(),
527
526
  ...this.executionCache.getPreimage(argsHash),
528
527
  ]);
@@ -537,8 +536,8 @@ export class ClientExecutionContext extends ViewDataOracle {
537
536
  return newArgsHash;
538
537
  }
539
538
 
540
- public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): void {
541
- this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
539
+ public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): Promise<void> {
540
+ return this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
542
541
  }
543
542
 
544
543
  /**
@@ -548,7 +547,7 @@ export class ClientExecutionContext extends ViewDataOracle {
548
547
  * @param isStaticCall - Whether the call is a static call.
549
548
  * @returns The derived call context.
550
549
  */
551
- private deriveCallContext(
550
+ private async deriveCallContext(
552
551
  targetContractAddress: AztecAddress,
553
552
  targetArtifact: FunctionArtifact,
554
553
  isStaticCall = false,
@@ -556,7 +555,7 @@ export class ClientExecutionContext extends ViewDataOracle {
556
555
  return new CallContext(
557
556
  this.contractAddress,
558
557
  targetContractAddress,
559
- FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
558
+ await FunctionSelector.fromNameAndParameters(targetArtifact.name, targetArtifact.parameters),
560
559
  isStaticCall,
561
560
  );
562
561
  }
@@ -52,7 +52,7 @@ export class ExecutionNoteCache {
52
52
  * Enters the revertible phase of the transaction.
53
53
  * @param minRevertibleSideEffectCounter - The counter at which the transaction enters the revertible phase.
54
54
  */
55
- public setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number) {
55
+ public async setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number) {
56
56
  if (this.inRevertiblePhase) {
57
57
  throw new Error(
58
58
  `Cannot enter the revertible phase twice. Current counter: ${minRevertibleSideEffectCounter}. Previous enter counter: ${this.minRevertibleSideEffectCounter}`,
@@ -72,15 +72,20 @@ export class ExecutionNoteCache {
72
72
  // They cannot be squashed by nullifiers emitted after minRevertibleSideEffectCounter is set.
73
73
  // Their indexes in the tx are known at this point and won't change. So we can assign a nonce to each one of them.
74
74
  // The nonces will be used to create the "complete" nullifier.
75
- const updatedNotes = this.notes.map(({ note, counter }, i) => {
76
- const nonce = computeNoteHashNonce(nonceGenerator, i);
77
- const uniqueNoteHash = computeUniqueNoteHash(nonce, siloNoteHash(note.contractAddress, note.noteHash));
78
- return {
79
- counter,
80
- note: { ...note, nonce },
81
- noteHashForConsumption: uniqueNoteHash,
82
- };
83
- });
75
+ const updatedNotes = await Promise.all(
76
+ this.notes.map(async ({ note, counter }, i) => {
77
+ const nonce = await computeNoteHashNonce(nonceGenerator, i);
78
+ const uniqueNoteHash = await computeUniqueNoteHash(
79
+ nonce,
80
+ await siloNoteHash(note.contractAddress, note.noteHash),
81
+ );
82
+ return {
83
+ counter,
84
+ note: { ...note, nonce },
85
+ noteHashForConsumption: uniqueNoteHash,
86
+ };
87
+ }),
88
+ );
84
89
  // Rebuild the data.
85
90
  this.notes = [];
86
91
  this.noteMap = new Map();
@@ -120,8 +125,8 @@ export class ExecutionNoteCache {
120
125
  * @param noteHash - A hash of the note. If this value equals 0, it means the note being nullified is from a previous
121
126
  * transaction (and thus not a new note).
122
127
  */
123
- public nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, noteHash: Fr) {
124
- const siloedNullifier = siloNullifier(contractAddress, innerNullifier);
128
+ public async nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, noteHash: Fr) {
129
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
125
130
  let nullifiedNoteHashCounter: number | undefined = undefined;
126
131
  // Find and remove the matching new note and log(s) if the emitted noteHash is not empty.
127
132
  if (!noteHash.isEmpty()) {
@@ -152,8 +157,8 @@ export class ExecutionNoteCache {
152
157
  * @param contractAddress - Contract address that emitted the nullifier.
153
158
  * @param innerNullifier
154
159
  */
155
- public nullifierCreated(contractAddress: AztecAddress, innerNullifier: Fr) {
156
- const siloedNullifier = siloNullifier(contractAddress, innerNullifier);
160
+ public async nullifierCreated(contractAddress: AztecAddress, innerNullifier: Fr) {
161
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
157
162
  this.recordNullifier(contractAddress, siloedNullifier);
158
163
  }
159
164
 
@@ -84,7 +84,7 @@ interface ContainsNote {
84
84
  note: Note;
85
85
  }
86
86
 
87
- const selectPropertyFromSerializedNote = (noteData: Fr[], selector: PropertySelector): Fr => {
87
+ const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
88
88
  const noteValueBuffer = noteData[selector.index].toBuffer();
89
89
  const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
90
90
  return Fr.fromBuffer(noteValue);
@@ -93,7 +93,7 @@ const selectPropertyFromSerializedNote = (noteData: Fr[], selector: PropertySele
93
93
  const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
94
94
  noteDatas.filter(noteData =>
95
95
  selects.every(({ selector, value, comparator }) => {
96
- const noteValueFr = selectPropertyFromSerializedNote(noteData.note.items, selector);
96
+ const noteValueFr = selectPropertyFromPackedNoteContent(noteData.note.items, selector);
97
97
  const comparatorSelector = {
98
98
  [Comparator.EQ]: () => noteValueFr.equals(value),
99
99
  [Comparator.NEQ]: () => !noteValueFr.equals(value),
@@ -117,8 +117,8 @@ const sortNotes = (a: Fr[], b: Fr[], sorts: Sort[], level = 0): number => {
117
117
  return 0;
118
118
  }
119
119
 
120
- const aValue = selectPropertyFromSerializedNote(a, selector);
121
- const bValue = selectPropertyFromSerializedNote(b, selector);
120
+ const aValue = selectPropertyFromPackedNoteContent(a, selector);
121
+ const bValue = selectPropertyFromPackedNoteContent(b, selector);
122
122
 
123
123
  const dir = order === 1 ? [-1, 1] : [1, -1];
124
124
  return aValue.toBigInt() === bValue.toBigInt()
@@ -72,11 +72,11 @@ export class AcirSimulator {
72
72
  const callContext = new CallContext(
73
73
  msgSender,
74
74
  contractAddress,
75
- FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
75
+ await FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
76
76
  entryPointArtifact.isStatic,
77
77
  );
78
78
 
79
- const txRequestHash = request.toTxRequest().hash();
79
+ const txRequestHash = await request.toTxRequest().hash();
80
80
  const noteCache = new ExecutionNoteCache(txRequestHash);
81
81
 
82
82
  const context = new ClientExecutionContext(
@@ -192,7 +192,7 @@ export class AcirSimulator {
192
192
  const execRequest: FunctionCall = {
193
193
  name: artifact.name,
194
194
  to: contractAddress,
195
- selector: FunctionSelector.fromNameAndParameters(artifact),
195
+ selector: await FunctionSelector.fromNameAndParameters(artifact),
196
196
  type: FunctionType.UNCONSTRAINED,
197
197
  isStatic: artifact.isStatic,
198
198
  args: encodeArguments(artifact, [
@@ -230,7 +230,7 @@ export class ViewDataOracle extends TypedOracle {
230
230
  * @returns A boolean indicating whether the nullifier exists in the tree or not.
231
231
  */
232
232
  public override async checkNullifierExists(innerNullifier: Fr) {
233
- const nullifier = siloNullifier(this.contractAddress, innerNullifier!);
233
+ const nullifier = await siloNullifier(this.contractAddress, innerNullifier!);
234
234
  const index = await this.db.getNullifierIndex(nullifier);
235
235
  return index !== undefined;
236
236
  }
@@ -32,7 +32,7 @@ export class HashedValuesCache {
32
32
  if (hash.equals(Fr.ZERO)) {
33
33
  return [];
34
34
  }
35
- const hashedValues = this.cache.get(hash.value);
35
+ const hashedValues = this.cache.get(hash.toBigInt());
36
36
  if (!hashedValues) {
37
37
  throw new Error(`Preimage for hash ${hash.toString()} not found in cache`);
38
38
  }
@@ -44,12 +44,12 @@ export class HashedValuesCache {
44
44
  * @param values - The values to store.
45
45
  * @returns The hash of the values.
46
46
  */
47
- public store(values: Fr[]) {
47
+ public async store(values: Fr[]) {
48
48
  if (values.length === 0) {
49
49
  return Fr.ZERO;
50
50
  }
51
- const hashedValues = HashedValues.fromValues(values);
52
- this.cache.set(hashedValues.hash.value, hashedValues.values);
51
+ const hashedValues = await HashedValues.fromValues(values);
52
+ this.cache.set(hashedValues.hash.toBigInt(), hashedValues.values);
53
53
  return hashedValues.hash;
54
54
  }
55
55
  }
@@ -1,3 +1,4 @@
1
+ import { createLogger } from '@aztec/foundation/log';
1
2
  import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/client';
2
3
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
3
4
 
@@ -10,6 +11,8 @@ import { type ACVMWitness } from '../acvm/acvm_types.js';
10
11
  import { type SimulationProvider, parseErrorPayload } from '../common/simulation_provider.js';
11
12
 
12
13
  export class WASMSimulator implements SimulationProvider {
14
+ constructor(protected log = createLogger('wasm-simulator')) {}
15
+
13
16
  async init(): Promise<void> {
14
17
  // If these are available, then we are in the
15
18
  // web environment. For the node environment, this
@@ -21,6 +24,7 @@ export class WASMSimulator implements SimulationProvider {
21
24
  }
22
25
 
23
26
  async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
27
+ this.log.debug('init', { hash: compiledCircuit.hash });
24
28
  await this.init();
25
29
  // Execute the circuit on those initial witness values
26
30
  //
@@ -34,13 +38,20 @@ export class WASMSimulator implements SimulationProvider {
34
38
  input,
35
39
  foreignCallHandler, // handle calls to debug_log
36
40
  );
37
-
41
+ this.log.debug('execution successful', { hash: compiledCircuit.hash });
38
42
  return _witnessMap;
39
43
  } catch (err) {
40
44
  // Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
41
45
  if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
42
- throw parseErrorPayload(compiledCircuit.abi, err as ExecutionError);
46
+ const parsed = parseErrorPayload(compiledCircuit.abi, err as ExecutionError);
47
+ this.log.debug('execution failed', {
48
+ hash: compiledCircuit.hash,
49
+ error: parsed,
50
+ message: parsed.message,
51
+ });
52
+ throw parsed;
43
53
  }
54
+ this.log.debug('execution failed', { hash: compiledCircuit.hash, error: err });
44
55
  throw new Error(`Circuit execution failed: ${err}`);
45
56
  }
46
57
  }
@@ -1,8 +1,4 @@
1
- import {
2
- type PublicExecutionRequest,
3
- type SimulationError,
4
- type UnencryptedFunctionL2Logs,
5
- } from '@aztec/circuit-types';
1
+ import { type PublicExecutionRequest, type SimulationError } from '@aztec/circuit-types';
6
2
  import {
7
3
  type AvmExecutionHints,
8
4
  type ContractStorageRead,
@@ -10,16 +6,15 @@ import {
10
6
  type Fr,
11
7
  Gas,
12
8
  type L2ToL1Message,
13
- type LogHash,
14
9
  type NoteHash,
15
10
  type Nullifier,
16
11
  PublicCallStackItemCompressed,
17
12
  type PublicDataUpdateRequest,
18
13
  PublicInnerCallRequest,
14
+ type PublicLog,
19
15
  type ReadRequest,
20
16
  RevertCode,
21
17
  type ScopedL2ToL1Message,
22
- type ScopedLogHash,
23
18
  type TreeLeafReadRequest,
24
19
  } from '@aztec/circuits.js';
25
20
  import { computeVarArgsHash } from '@aztec/circuits.js/hash';
@@ -33,16 +28,8 @@ export interface PublicSideEffects {
33
28
  nullifiers: Nullifier[];
34
29
  /** The new l2 to l1 messages generated to be inserted into the messages tree. */
35
30
  l2ToL1Messages: ScopedL2ToL1Message[];
36
- /**
37
- * The hashed logs with side effect counter.
38
- * Note: required as we don't track the counter anywhere else.
39
- */
40
- unencryptedLogsHashes: ScopedLogHash[];
41
- /**
42
- * Unencrypted logs emitted during execution.
43
- * Note: These are preimages to `unencryptedLogsHashes`.
44
- */
45
- unencryptedLogs: UnencryptedFunctionL2Logs;
31
+ /** Public logs emitted during execution. */
32
+ publicLogs: PublicLog[];
46
33
  }
47
34
 
48
35
  export interface EnqueuedPublicCallExecutionResult {
@@ -124,21 +111,10 @@ export interface PublicFunctionCallResult {
124
111
  /** L1 to L2 message read requests emitted in this call. */
125
112
  l1ToL2MsgReadRequests: TreeLeafReadRequest[];
126
113
  /**
127
- * The hashed logs with side effect counter.
128
- * Note: required as we don't track the counter anywhere else.
114
+ * The public logs emitted in this call.
115
+ * Note: PublicLog has no counter - unsure if this is needed bc this struct is unused
129
116
  */
130
- unencryptedLogsHashes: LogHash[];
131
- /**
132
- * Unencrypted logs emitted during execution of this function call.
133
- * Note: These are preimages to `unencryptedLogsHashes`.
134
- */
135
- unencryptedLogs: UnencryptedFunctionL2Logs;
136
- /**
137
- * Unencrypted logs emitted during this call AND any nested calls.
138
- * Useful for maintaining correct ordering in ts.
139
- */
140
- allUnencryptedLogs: UnencryptedFunctionL2Logs;
141
-
117
+ publicLogs: PublicLog[];
142
118
  /** The requests to call public functions made by this call. */
143
119
  publicCallRequests: PublicInnerCallRequest[];
144
120
  /** The results of nested calls. */
@@ -151,13 +127,13 @@ export interface PublicFunctionCallResult {
151
127
  functionName: string;
152
128
  }
153
129
 
154
- export function resultToPublicCallRequest(result: PublicFunctionCallResult) {
130
+ export async function resultToPublicCallRequest(result: PublicFunctionCallResult) {
155
131
  const request = result.executionRequest;
156
132
  const item = new PublicCallStackItemCompressed(
157
133
  request.callContext.contractAddress,
158
134
  request.callContext,
159
- computeVarArgsHash(request.args),
160
- computeVarArgsHash(result.returnValues),
135
+ await computeVarArgsHash(request.args),
136
+ await computeVarArgsHash(result.returnValues),
161
137
  // TODO(@just-mitch): need better mapping from simulator to revert code.
162
138
  result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
163
139
  Gas.from(result.startGasLeft),
@@ -14,10 +14,10 @@ export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress) {
14
14
  /**
15
15
  * Computes the leaf slot in the public data tree for the balance of the fee payer in the Fee Juice.
16
16
  */
17
- export function computeFeePayerBalanceLeafSlot(feePayer: AztecAddress): Fr {
17
+ export async function computeFeePayerBalanceLeafSlot(feePayer: AztecAddress): Promise<Fr> {
18
18
  if (feePayer.isZero()) {
19
19
  return Fr.ZERO;
20
20
  }
21
- const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
21
+ const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
22
22
  return computePublicDataTreeLeafSlot(ProtocolContractAddress.FeeJuice, balanceSlot);
23
23
  }