@aztec/simulator 0.56.0 → 0.57.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 (156) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +2 -5
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +6 -37
  4. package/dest/acvm/oracle/typed_oracle.d.ts +3 -6
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +1 -10
  7. package/dest/avm/avm_execution_environment.d.ts +2 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +3 -4
  10. package/dest/avm/avm_gas.d.ts.map +1 -1
  11. package/dest/avm/avm_gas.js +1 -2
  12. package/dest/avm/avm_memory_types.d.ts +3 -2
  13. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  14. package/dest/avm/avm_memory_types.js +3 -3
  15. package/dest/avm/errors.d.ts +1 -1
  16. package/dest/avm/errors.d.ts.map +1 -1
  17. package/dest/avm/errors.js +12 -3
  18. package/dest/avm/fixtures/index.d.ts.map +1 -1
  19. package/dest/avm/fixtures/index.js +3 -3
  20. package/dest/avm/journal/journal.d.ts +2 -1
  21. package/dest/avm/journal/journal.d.ts.map +1 -1
  22. package/dest/avm/journal/journal.js +7 -6
  23. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  24. package/dest/avm/opcodes/accrued_substate.js +37 -30
  25. package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
  26. package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
  27. package/dest/avm/opcodes/addressing_mode.js +25 -21
  28. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  29. package/dest/avm/opcodes/arithmetic.js +6 -5
  30. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  31. package/dest/avm/opcodes/bitwise.js +11 -9
  32. package/dest/avm/opcodes/commitment.d.ts.map +1 -1
  33. package/dest/avm/opcodes/commitment.js +6 -5
  34. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  35. package/dest/avm/opcodes/comparators.js +6 -5
  36. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  37. package/dest/avm/opcodes/contract.js +6 -5
  38. package/dest/avm/opcodes/control_flow.js +6 -6
  39. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  40. package/dest/avm/opcodes/conversion.js +7 -6
  41. package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
  42. package/dest/avm/opcodes/ec_add.js +8 -7
  43. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  44. package/dest/avm/opcodes/environment_getters.js +6 -5
  45. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  46. package/dest/avm/opcodes/external_calls.js +27 -16
  47. package/dest/avm/opcodes/hashing.d.ts +1 -3
  48. package/dest/avm/opcodes/hashing.d.ts.map +1 -1
  49. package/dest/avm/opcodes/hashing.js +31 -40
  50. package/dest/avm/opcodes/instruction.d.ts +2 -6
  51. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  52. package/dest/avm/opcodes/instruction.js +3 -9
  53. package/dest/avm/opcodes/memory.d.ts +0 -12
  54. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  55. package/dest/avm/opcodes/memory.js +21 -51
  56. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  57. package/dest/avm/opcodes/misc.js +6 -5
  58. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  59. package/dest/avm/opcodes/multi_scalar_mul.js +12 -12
  60. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  61. package/dest/avm/opcodes/storage.js +11 -9
  62. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  63. package/dest/avm/serialization/bytecode_serialization.js +2 -3
  64. package/dest/avm/serialization/instruction_serialization.d.ts +32 -34
  65. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  66. package/dest/avm/serialization/instruction_serialization.js +33 -36
  67. package/dest/client/client_execution_context.d.ts +6 -30
  68. package/dest/client/client_execution_context.d.ts.map +1 -1
  69. package/dest/client/client_execution_context.js +31 -53
  70. package/dest/client/index.d.ts +0 -1
  71. package/dest/client/index.d.ts.map +1 -1
  72. package/dest/client/index.js +1 -2
  73. package/dest/client/private_execution.d.ts +2 -2
  74. package/dest/client/private_execution.d.ts.map +1 -1
  75. package/dest/client/private_execution.js +5 -19
  76. package/dest/client/simulator.d.ts +2 -3
  77. package/dest/client/simulator.d.ts.map +1 -1
  78. package/dest/client/simulator.js +1 -1
  79. package/dest/common/debug_fn_name.d.ts +4 -0
  80. package/dest/common/debug_fn_name.d.ts.map +1 -0
  81. package/dest/common/debug_fn_name.js +15 -0
  82. package/dest/common/index.d.ts +0 -1
  83. package/dest/common/index.d.ts.map +1 -1
  84. package/dest/common/index.js +1 -2
  85. package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
  86. package/dest/public/enqueued_call_simulator.js +3 -4
  87. package/dest/public/execution.d.ts +8 -1
  88. package/dest/public/execution.d.ts.map +1 -1
  89. package/dest/public/execution.js +13 -1
  90. package/dest/public/executor.d.ts +2 -3
  91. package/dest/public/executor.d.ts.map +1 -1
  92. package/dest/public/executor.js +8 -8
  93. package/dest/public/hints_builder.d.ts.map +1 -1
  94. package/dest/public/hints_builder.js +2 -2
  95. package/dest/public/public_processor.d.ts +1 -0
  96. package/dest/public/public_processor.d.ts.map +1 -1
  97. package/dest/public/public_processor.js +5 -2
  98. package/dest/public/side_effect_errors.d.ts +4 -0
  99. package/dest/public/side_effect_errors.d.ts.map +1 -0
  100. package/dest/public/side_effect_errors.js +7 -0
  101. package/dest/public/side_effect_trace.d.ts +2 -2
  102. package/dest/public/side_effect_trace.d.ts.map +1 -1
  103. package/dest/public/side_effect_trace.js +53 -28
  104. package/dest/public/side_effect_trace_interface.d.ts +1 -1
  105. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  106. package/package.json +12 -9
  107. package/src/acvm/oracle/oracle.ts +7 -85
  108. package/src/acvm/oracle/typed_oracle.ts +2 -31
  109. package/src/avm/avm_execution_environment.ts +1 -3
  110. package/src/avm/avm_gas.ts +0 -1
  111. package/src/avm/avm_memory_types.ts +10 -5
  112. package/src/avm/errors.ts +11 -3
  113. package/src/avm/fixtures/index.ts +1 -2
  114. package/src/avm/journal/journal.ts +11 -6
  115. package/src/avm/opcodes/accrued_substate.ts +36 -44
  116. package/src/avm/opcodes/addressing_mode.ts +27 -24
  117. package/src/avm/opcodes/arithmetic.ts +5 -7
  118. package/src/avm/opcodes/bitwise.ts +10 -11
  119. package/src/avm/opcodes/commitment.ts +6 -7
  120. package/src/avm/opcodes/comparators.ts +5 -7
  121. package/src/avm/opcodes/contract.ts +5 -7
  122. package/src/avm/opcodes/control_flow.ts +5 -5
  123. package/src/avm/opcodes/conversion.ts +6 -8
  124. package/src/avm/opcodes/ec_add.ts +14 -16
  125. package/src/avm/opcodes/environment_getters.ts +5 -4
  126. package/src/avm/opcodes/external_calls.ts +27 -20
  127. package/src/avm/opcodes/hashing.ts +30 -55
  128. package/src/avm/opcodes/instruction.ts +3 -10
  129. package/src/avm/opcodes/memory.ts +20 -64
  130. package/src/avm/opcodes/misc.ts +5 -7
  131. package/src/avm/opcodes/multi_scalar_mul.ts +11 -14
  132. package/src/avm/opcodes/storage.ts +10 -8
  133. package/src/avm/serialization/bytecode_serialization.ts +0 -2
  134. package/src/avm/serialization/instruction_serialization.ts +0 -3
  135. package/src/client/client_execution_context.ts +40 -96
  136. package/src/client/index.ts +0 -1
  137. package/src/client/private_execution.ts +9 -9
  138. package/src/client/simulator.ts +2 -3
  139. package/src/common/debug_fn_name.ts +22 -0
  140. package/src/common/index.ts +0 -1
  141. package/src/public/enqueued_call_simulator.ts +2 -3
  142. package/src/public/execution.ts +13 -2
  143. package/src/public/executor.ts +6 -12
  144. package/src/public/hints_builder.ts +7 -9
  145. package/src/public/public_processor.ts +5 -1
  146. package/src/public/side_effect_errors.ts +6 -0
  147. package/src/public/side_effect_trace.ts +72 -27
  148. package/src/public/side_effect_trace_interface.ts +2 -2
  149. package/dest/client/execution_result.d.ts +0 -104
  150. package/dest/client/execution_result.d.ts.map +0 -1
  151. package/dest/client/execution_result.js +0 -136
  152. package/dest/common/return_values.d.ts +0 -11
  153. package/dest/common/return_values.d.ts.map +0 -1
  154. package/dest/common/return_values.js +0 -13
  155. package/src/client/execution_result.ts +0 -228
  156. package/src/common/return_values.ts +0 -18
@@ -1,50 +1,37 @@
1
1
  import {
2
2
  type AuthWitness,
3
3
  type AztecNode,
4
+ CountedLog,
5
+ CountedNoteLog,
6
+ CountedPublicExecutionRequest,
4
7
  EncryptedL2Log,
5
8
  EncryptedL2NoteLog,
6
- Event,
7
- L1EventPayload,
8
- L1NotePayload,
9
9
  Note,
10
+ NoteAndSlot,
10
11
  type NoteStatus,
12
+ type PrivateExecutionResult,
11
13
  PublicExecutionRequest,
12
- TaggedLog,
13
14
  type UnencryptedL2Log,
14
15
  } from '@aztec/circuit-types';
15
16
  import {
16
17
  CallContext,
17
18
  FunctionSelector,
18
19
  type Header,
19
- type KeyValidationRequest,
20
+ PUBLIC_DISPATCH_SELECTOR,
20
21
  PrivateContextInputs,
21
22
  type TxContext,
22
23
  } from '@aztec/circuits.js';
23
- import { Aes128 } from '@aztec/circuits.js/barretenberg';
24
24
  import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
25
- import {
26
- EventSelector,
27
- type FunctionAbi,
28
- type FunctionArtifact,
29
- type NoteSelector,
30
- countArgumentsSize,
31
- } from '@aztec/foundation/abi';
25
+ import { type FunctionAbi, type FunctionArtifact, type NoteSelector, countArgumentsSize } from '@aztec/foundation/abi';
32
26
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
33
27
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
34
- import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
28
+ import { Fr } from '@aztec/foundation/fields';
35
29
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
36
30
 
37
31
  import { type NoteData, toACVMWitness } from '../acvm/index.js';
38
32
  import { type PackedValuesCache } from '../common/packed_values_cache.js';
39
33
  import { type DBOracle } from './db_oracle.js';
40
34
  import { type ExecutionNoteCache } from './execution_note_cache.js';
41
- import {
42
- CountedLog,
43
- CountedNoteLog,
44
- CountedPublicExecutionRequest,
45
- type ExecutionResult,
46
- type NoteAndSlot,
47
- } from './execution_result.js';
48
35
  import { pickNotes } from './pick_notes.js';
49
36
  import { executePrivateFunction } from './private_execution.js';
50
37
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -75,7 +62,7 @@ export class ClientExecutionContext extends ViewDataOracle {
75
62
  private noteEncryptedLogs: CountedNoteLog[] = [];
76
63
  private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
77
64
  private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
78
- private nestedExecutions: ExecutionResult[] = [];
65
+ private nestedExecutions: PrivateExecutionResult[] = [];
79
66
  private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
80
67
  private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
81
68
 
@@ -314,11 +301,7 @@ export class ClientExecutionContext extends ViewDataOracle {
314
301
  },
315
302
  counter,
316
303
  );
317
- this.newNotes.push({
318
- storageSlot,
319
- noteTypeId,
320
- note,
321
- });
304
+ this.newNotes.push(new NoteAndSlot(note, storageSlot, noteTypeId));
322
305
  }
323
306
 
324
307
  /**
@@ -373,62 +356,6 @@ export class ClientExecutionContext extends ViewDataOracle {
373
356
  this.noteEncryptedLogs.push(encryptedLog);
374
357
  }
375
358
 
376
- /**
377
- * Encrypt an event
378
- * @param contractAddress - The contract emitting the encrypted event.
379
- * @param randomness - A value used to mask the contract address we are siloing with.
380
- * @param eventTypeId - The type ID of the event (function selector).
381
- * @param ovKeys - The outgoing viewing keys to use to encrypt.
382
- * @param ivpkM - The master incoming viewing public key.
383
- * @param recipient - The recipient of the encrypted event log.
384
- * @param preimage - The event preimage.
385
- */
386
- public override computeEncryptedEventLog(
387
- contractAddress: AztecAddress,
388
- randomness: Fr,
389
- eventTypeId: Fr,
390
- ovKeys: KeyValidationRequest,
391
- ivpkM: Point,
392
- recipient: AztecAddress,
393
- preimage: Fr[],
394
- ) {
395
- const event = new Event(preimage);
396
- const l1EventPayload = new L1EventPayload(event, contractAddress, randomness, EventSelector.fromField(eventTypeId));
397
- const taggedEvent = new TaggedLog(l1EventPayload);
398
-
399
- const ephSk = GrumpkinScalar.random();
400
-
401
- return taggedEvent.encrypt(ephSk, recipient, ivpkM, ovKeys);
402
- }
403
-
404
- /**
405
- * Encrypt a note
406
- * @param contractAddress - The contract address of the note.
407
- * @param storageSlot - The storage slot the note is at.
408
- * @param noteTypeId - The type ID of the note.
409
- * @param ovKeys - The outgoing viewing keys to use to encrypt.
410
- * @param ivpkM - The master incoming viewing public key.
411
- * @param recipient - The recipient of the encrypted note log.
412
- * @param preimage - The note preimage.
413
- */
414
- public override computeEncryptedNoteLog(
415
- contractAddress: AztecAddress,
416
- storageSlot: Fr,
417
- noteTypeId: NoteSelector,
418
- ovKeys: KeyValidationRequest,
419
- ivpkM: Point,
420
- recipient: AztecAddress,
421
- preimage: Fr[],
422
- ) {
423
- const note = new Note(preimage);
424
- const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
425
- const taggedNote = new TaggedLog(l1NotePayload);
426
-
427
- const ephSk = GrumpkinScalar.random();
428
-
429
- return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys);
430
- }
431
-
432
359
  /**
433
360
  * Emit an unencrypted log.
434
361
  * @param log - The unencrypted log to be emitted.
@@ -457,7 +384,7 @@ export class ClientExecutionContext extends ViewDataOracle {
457
384
  return Fr.fromBuffer(log.hash());
458
385
  }
459
386
 
460
- #checkValidStaticCall(childExecutionResult: ExecutionResult) {
387
+ #checkValidStaticCall(childExecutionResult: PrivateExecutionResult) {
461
388
  if (
462
389
  childExecutionResult.callStackItem.publicInputs.noteHashes.some(item => !item.isEmpty()) ||
463
390
  childExecutionResult.callStackItem.publicInputs.nullifiers.some(item => !item.isEmpty()) ||
@@ -568,7 +495,7 @@ export class ClientExecutionContext extends ViewDataOracle {
568
495
  const args = this.packedValuesCache.unpack(argsHash);
569
496
 
570
497
  this.log.verbose(
571
- `Created PublicExecutionRequest of type [${callType}], side-effect counter [${sideEffectCounter}] to ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
498
+ `Created PublicExecutionRequest to ${targetArtifact.name}@${targetContractAddress}, of type [${callType}], side-effect counter [${sideEffectCounter}]`,
572
499
  );
573
500
 
574
501
  const request = PublicExecutionRequest.from({
@@ -602,16 +529,27 @@ export class ClientExecutionContext extends ViewDataOracle {
602
529
  sideEffectCounter: number,
603
530
  isStaticCall: boolean,
604
531
  isDelegateCall: boolean,
605
- ) {
532
+ ): Promise<Fr> {
533
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
534
+ // WARNING: This is insecure and should be temporary!
535
+ // The oracle repacks the arguments and returns a new args_hash.
536
+ // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
537
+ // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
538
+ // b) this is only temporary.
539
+ const newArgsHash = this.packedValuesCache.pack([
540
+ functionSelector.toField(),
541
+ ...this.packedValuesCache.unpack(argsHash),
542
+ ]);
606
543
  await this.createPublicExecutionRequest(
607
544
  'enqueued',
608
545
  targetContractAddress,
609
- functionSelector,
610
- argsHash,
546
+ FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
547
+ newArgsHash,
611
548
  sideEffectCounter,
612
549
  isStaticCall,
613
550
  isDelegateCall,
614
551
  );
552
+ return newArgsHash;
615
553
  }
616
554
 
617
555
  /**
@@ -632,16 +570,27 @@ export class ClientExecutionContext extends ViewDataOracle {
632
570
  sideEffectCounter: number,
633
571
  isStaticCall: boolean,
634
572
  isDelegateCall: boolean,
635
- ) {
573
+ ): Promise<Fr> {
574
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this.
575
+ // WARNING: This is insecure and should be temporary!
576
+ // The oracle repacks the arguments and returns a new args_hash.
577
+ // new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
578
+ // We don't validate or compute it in the circuit because a) it's harder to do with slices, and
579
+ // b) this is only temporary.
580
+ const newArgsHash = this.packedValuesCache.pack([
581
+ functionSelector.toField(),
582
+ ...this.packedValuesCache.unpack(argsHash),
583
+ ]);
636
584
  await this.createPublicExecutionRequest(
637
585
  'teardown',
638
586
  targetContractAddress,
639
- functionSelector,
640
- argsHash,
587
+ FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
588
+ newArgsHash,
641
589
  sideEffectCounter,
642
590
  isStaticCall,
643
591
  isDelegateCall,
644
592
  );
593
+ return newArgsHash;
645
594
  }
646
595
 
647
596
  public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): void {
@@ -698,11 +647,6 @@ export class ClientExecutionContext extends ViewDataOracle {
698
647
  return values;
699
648
  }
700
649
 
701
- public override aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer {
702
- const aes128 = new Aes128();
703
- return aes128.encryptBufferCBC(input, initializationVector, key);
704
- }
705
-
706
650
  public override debugLog(message: string, fields: Fr[]) {
707
651
  this.log.verbose(`debug_log ${applyStringFormatting(message, fields)}`);
708
652
  }
@@ -1,5 +1,4 @@
1
1
  export * from './simulator.js';
2
2
  export * from './db_oracle.js';
3
- export * from './execution_result.js';
4
3
  export * from './pick_notes.js';
5
4
  export * from './execution_note_cache.js';
@@ -1,3 +1,4 @@
1
+ import { PrivateExecutionResult } from '@aztec/circuit-types';
1
2
  import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
2
3
  import { Fr, FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
3
4
  import type { FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
@@ -9,7 +10,6 @@ import { witnessMapToFields } from '../acvm/deserialize.js';
9
10
  import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
10
11
  import { ExecutionError } from '../common/errors.js';
11
12
  import { type ClientExecutionContext } from './client_execution_context.js';
12
- import { type ExecutionResult } from './execution_result.js';
13
13
 
14
14
  /**
15
15
  * Execute a private function and return the execution result.
@@ -19,10 +19,10 @@ export async function executePrivateFunction(
19
19
  artifact: FunctionArtifact,
20
20
  contractAddress: AztecAddress,
21
21
  functionSelector: FunctionSelector,
22
- log = createDebugLogger('aztec:simulator:secret_execution'),
23
- ): Promise<ExecutionResult> {
22
+ log = createDebugLogger('aztec:simulator:private_execution'),
23
+ ): Promise<PrivateExecutionResult> {
24
24
  const functionName = await context.getDebugFunctionName();
25
- log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${functionName})`);
25
+ log.verbose(`Executing external function ${functionName}@${contractAddress}`);
26
26
  const acir = artifact.bytecode;
27
27
  const initialWitness = context.getInitialWitness(artifact);
28
28
  const acvmCallback = new Oracle(context);
@@ -75,20 +75,20 @@ export async function executePrivateFunction(
75
75
 
76
76
  log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
77
77
 
78
- return {
78
+ return new PrivateExecutionResult(
79
79
  acir,
80
+ Buffer.from(artifact.verificationKey!, 'hex'),
80
81
  partialWitness,
81
82
  callStackItem,
82
- returnValues: rawReturnValues,
83
83
  noteHashLeafIndexMap,
84
84
  newNotes,
85
85
  noteHashNullifierCounterMap,
86
- vk: Buffer.from(artifact.verificationKey!, 'hex'),
86
+ rawReturnValues,
87
87
  nestedExecutions,
88
88
  enqueuedPublicFunctionCalls,
89
- noteEncryptedLogs,
90
89
  publicTeardownFunctionCall,
90
+ noteEncryptedLogs,
91
91
  encryptedLogs,
92
92
  unencryptedLogs,
93
- };
93
+ );
94
94
  }
@@ -1,4 +1,4 @@
1
- import { type AztecNode, type FunctionCall, type Note, type TxExecutionRequest } from '@aztec/circuit-types';
1
+ import type { AztecNode, FunctionCall, Note, PrivateExecutionResult, TxExecutionRequest } from '@aztec/circuit-types';
2
2
  import { CallContext } from '@aztec/circuits.js';
3
3
  import {
4
4
  type ArrayType,
@@ -17,7 +17,6 @@ import { PackedValuesCache } from '../common/packed_values_cache.js';
17
17
  import { ClientExecutionContext } from './client_execution_context.js';
18
18
  import { type DBOracle } from './db_oracle.js';
19
19
  import { ExecutionNoteCache } from './execution_note_cache.js';
20
- import { type ExecutionResult } from './execution_result.js';
21
20
  import { executePrivateFunction } from './private_execution.js';
22
21
  import { executeUnconstrainedFunction } from './unconstrained_execution.js';
23
22
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -47,7 +46,7 @@ export class AcirSimulator {
47
46
  contractAddress: AztecAddress,
48
47
  msgSender = AztecAddress.fromField(Fr.MAX_FIELD_VALUE),
49
48
  scopes?: AztecAddress[],
50
- ): Promise<ExecutionResult> {
49
+ ): Promise<PrivateExecutionResult> {
51
50
  if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
52
51
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
53
52
  }
@@ -0,0 +1,22 @@
1
+ import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js';
2
+
3
+ import { type WorldStateDB } from '../public/public_db_sources.js';
4
+
5
+ export async function getPublicFunctionDebugName(
6
+ db: WorldStateDB,
7
+ contractAddress: AztecAddress,
8
+ fn: FunctionSelector,
9
+ calldata: Fr[],
10
+ ): Promise<string> {
11
+ if (fn.equals(FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)))) {
12
+ // If the function is a dispatch, we need to look up the target function which
13
+ // is expected to be the first argument.
14
+ const targetFunction =
15
+ calldata[0] !== undefined
16
+ ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
17
+ : `<calldata[0] undefined>`;
18
+ return `${targetFunction} (via dispatch)`;
19
+ } else {
20
+ return (await db.getDebugFunctionName(contractAddress, fn)) ?? `${contractAddress}:${fn}`;
21
+ }
22
+ }
@@ -1,4 +1,3 @@
1
1
  export * from './packed_values_cache.js';
2
2
  export * from './errors.js';
3
3
  export * from './side_effect_counter.js';
4
- export * from './return_values.js';
@@ -63,8 +63,7 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
63
63
  import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types';
64
64
  import { type MerkleTreeOperations } from '@aztec/world-state';
65
65
 
66
- import { accumulateReturnValues } from '../common/index.js';
67
- import { type PublicExecutionResult, collectExecutionResults } from './execution.js';
66
+ import { type PublicExecutionResult, accumulatePublicReturnValues, collectExecutionResults } from './execution.js';
68
67
  import { type PublicExecutor } from './executor.js';
69
68
  import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
70
69
 
@@ -226,7 +225,7 @@ export class EnqueuedCallSimulator {
226
225
  provingRequests,
227
226
  kernelOutput,
228
227
  newUnencryptedLogs: topResult.allUnencryptedLogs,
229
- returnValues: accumulateReturnValues(topResult),
228
+ returnValues: accumulatePublicReturnValues(topResult),
230
229
  gasUsed,
231
230
  revertReason,
232
231
  };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ NestedProcessReturnValues,
2
3
  type PublicExecutionRequest,
3
4
  type SimulationError,
4
5
  type UnencryptedFunctionL2Logs,
@@ -86,8 +87,6 @@ export interface PublicExecutionResult {
86
87
  */
87
88
  allUnencryptedLogs: UnencryptedFunctionL2Logs;
88
89
 
89
- // TODO(dbanks12): add contract instance read requests
90
-
91
90
  /** The requests to call public functions made by this call. */
92
91
  publicCallRequests: PublicInnerCallRequest[];
93
92
  /** The results of nested calls. */
@@ -100,6 +99,18 @@ export interface PublicExecutionResult {
100
99
  functionName: string;
101
100
  }
102
101
 
102
+ /**
103
+ * Recursively accummulate the return values of a call result and its nested executions,
104
+ * so they can be retrieved in order.
105
+ * @param executionResult
106
+ * @returns
107
+ */
108
+ export function accumulatePublicReturnValues(executionResult: PublicExecutionResult): NestedProcessReturnValues {
109
+ const acc = new NestedProcessReturnValues(executionResult.returnValues);
110
+ acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulatePublicReturnValues(nestedExecution));
111
+ return acc;
112
+ }
113
+
103
114
  export function collectExecutionResults(result: PublicExecutionResult): PublicExecutionResult[] {
104
115
  return [result, ...result.nestedExecutions.map(collectExecutionResults)].flat();
105
116
  }
@@ -1,6 +1,6 @@
1
1
  import { type PublicExecutionRequest } from '@aztec/circuit-types';
2
2
  import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
3
- import { Fr, Gas, type GlobalVariables, type Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
3
+ import { Fr, Gas, type GlobalVariables, type Nullifier, type TxContext } from '@aztec/circuits.js';
4
4
  import { createDebugLogger } from '@aztec/foundation/log';
5
5
  import { Timer } from '@aztec/foundation/timer';
6
6
  import { type TelemetryClient } from '@aztec/telemetry-client';
@@ -10,6 +10,7 @@ import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
10
10
  import { AvmMachineState } from '../avm/avm_machine_state.js';
11
11
  import { AvmSimulator } from '../avm/avm_simulator.js';
12
12
  import { AvmPersistableStateManager } from '../avm/journal/index.js';
13
+ import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
13
14
  import { type PublicExecutionResult } from './execution.js';
14
15
  import { ExecutorMetrics } from './executor_metrics.js';
15
16
  import { type WorldStateDB } from './public_db_sources.js';
@@ -21,7 +22,7 @@ import { PublicSideEffectTrace } from './side_effect_trace.js';
21
22
  export class PublicExecutor {
22
23
  metrics: ExecutorMetrics;
23
24
 
24
- constructor(private readonly worldStateDB: WorldStateDB, private readonly header: Header, client: TelemetryClient) {
25
+ constructor(private readonly worldStateDB: WorldStateDB, client: TelemetryClient) {
25
26
  this.metrics = new ExecutorMetrics(client, 'PublicExecutor');
26
27
  }
27
28
 
@@ -49,9 +50,9 @@ export class PublicExecutor {
49
50
  ): Promise<PublicExecutionResult> {
50
51
  const address = executionRequest.contractAddress;
51
52
  const selector = executionRequest.callContext.functionSelector;
52
- const fnName = (await this.worldStateDB.getDebugFunctionName(address, selector)) ?? `${address}:${selector}`;
53
+ const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
53
54
 
54
- PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
55
+ PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}@${address}.`);
55
56
  const timer = new Timer();
56
57
 
57
58
  const trace = new PublicSideEffectTrace(startSideEffectCounter);
@@ -61,12 +62,7 @@ export class PublicExecutor {
61
62
  pendingSiloedNullifiers.map(n => n.value),
62
63
  );
63
64
 
64
- const avmExecutionEnv = createAvmExecutionEnvironment(
65
- executionRequest,
66
- this.header,
67
- globalVariables,
68
- transactionFee,
69
- );
65
+ const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, globalVariables, transactionFee);
70
66
 
71
67
  const avmMachineState = new AvmMachineState(availableGas);
72
68
  const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
@@ -120,7 +116,6 @@ export class PublicExecutor {
120
116
  */
121
117
  function createAvmExecutionEnvironment(
122
118
  executionRequest: PublicExecutionRequest,
123
- header: Header,
124
119
  globalVariables: GlobalVariables,
125
120
  transactionFee: Fr,
126
121
  ): AvmExecutionEnvironment {
@@ -131,7 +126,6 @@ function createAvmExecutionEnvironment(
131
126
  executionRequest.callContext.functionSelector,
132
127
  /*contractCallDepth=*/ Fr.zero(),
133
128
  transactionFee,
134
- header,
135
129
  globalVariables,
136
130
  executionRequest.callContext.isStaticCall,
137
131
  executionRequest.callContext.isDelegateCall,
@@ -49,15 +49,13 @@ export class HintsBuilder {
49
49
  nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
50
50
  pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
51
51
  ) {
52
- return (
53
- await buildSiloedNullifierReadRequestHints(
54
- this,
55
- nullifierReadRequests,
56
- pendingNullifiers,
57
- MAX_NULLIFIER_READ_REQUESTS_PER_TX,
58
- MAX_NULLIFIER_READ_REQUESTS_PER_TX,
59
- )
60
- ).hints;
52
+ return await buildSiloedNullifierReadRequestHints(
53
+ this,
54
+ nullifierReadRequests,
55
+ pendingNullifiers,
56
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
57
+ MAX_NULLIFIER_READ_REQUESTS_PER_TX,
58
+ );
61
59
  }
62
60
 
63
61
  getNullifierNonExistentReadRequestHints(
@@ -57,7 +57,7 @@ export class PublicProcessorFactory {
57
57
  const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader();
58
58
 
59
59
  const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
60
- const publicExecutor = new PublicExecutor(worldStateDB, historicalHeader, telemetryClient);
60
+ const publicExecutor = new PublicExecutor(worldStateDB, telemetryClient);
61
61
  const publicKernelSimulator = new RealPublicKernelCircuitSimulator(this.simulator);
62
62
 
63
63
  return PublicProcessor.create(
@@ -70,6 +70,10 @@ export class PublicProcessorFactory {
70
70
  this.telemetryClient,
71
71
  );
72
72
  }
73
+
74
+ public getInitialHeader() {
75
+ return this.merkleTree.getInitialHeader();
76
+ }
73
77
  }
74
78
 
75
79
  /**
@@ -0,0 +1,6 @@
1
+ export class SideEffectLimitReachedError extends Error {
2
+ constructor(sideEffectType: string, limit: number) {
3
+ super(`Reached the limit on number of '${sideEffectType}' side effects: ${limit}`);
4
+ this.name = 'SideEffectLimitReachedError';
5
+ }
6
+ }