@aztec/simulator 0.60.0 → 0.61.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 (124) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +2 -0
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +9 -1
  4. package/dest/acvm/oracle/typed_oracle.d.ts +3 -1
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +7 -1
  7. package/dest/avm/avm_gas.d.ts.map +1 -1
  8. package/dest/avm/avm_gas.js +6 -3
  9. package/dest/avm/avm_machine_state.d.ts +2 -0
  10. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  11. package/dest/avm/avm_machine_state.js +3 -1
  12. package/dest/avm/avm_simulator.d.ts +15 -0
  13. package/dest/avm/avm_simulator.d.ts.map +1 -1
  14. package/dest/avm/avm_simulator.js +45 -4
  15. package/dest/avm/fixtures/index.d.ts +1 -1
  16. package/dest/avm/fixtures/index.d.ts.map +1 -1
  17. package/dest/avm/fixtures/index.js +7 -7
  18. package/dest/avm/journal/journal.d.ts +5 -6
  19. package/dest/avm/journal/journal.d.ts.map +1 -1
  20. package/dest/avm/journal/journal.js +42 -17
  21. package/dest/avm/opcodes/contract.d.ts +8 -1
  22. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  23. package/dest/avm/opcodes/contract.js +41 -21
  24. package/dest/avm/opcodes/conversion.d.ts +1 -1
  25. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  26. package/dest/avm/opcodes/conversion.js +12 -9
  27. package/dest/avm/opcodes/environment_getters.d.ts +1 -1
  28. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  29. package/dest/avm/opcodes/environment_getters.js +5 -1
  30. package/dest/avm/opcodes/external_calls.d.ts +3 -6
  31. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  32. package/dest/avm/opcodes/external_calls.js +23 -43
  33. package/dest/avm/opcodes/memory.d.ts +20 -0
  34. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  35. package/dest/avm/opcodes/memory.js +59 -3
  36. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  37. package/dest/avm/serialization/bytecode_serialization.js +5 -3
  38. package/dest/avm/serialization/instruction_serialization.d.ts +36 -34
  39. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  40. package/dest/avm/serialization/instruction_serialization.js +37 -35
  41. package/dest/avm/test_utils.d.ts +2 -1
  42. package/dest/avm/test_utils.d.ts.map +1 -1
  43. package/dest/avm/test_utils.js +4 -1
  44. package/dest/client/client_execution_context.d.ts +0 -8
  45. package/dest/client/client_execution_context.d.ts.map +1 -1
  46. package/dest/client/client_execution_context.js +1 -18
  47. package/dest/client/db_oracle.d.ts +17 -1
  48. package/dest/client/db_oracle.d.ts.map +1 -1
  49. package/dest/client/db_oracle.js +1 -1
  50. package/dest/client/view_data_oracle.d.ts +17 -1
  51. package/dest/client/view_data_oracle.d.ts.map +1 -1
  52. package/dest/client/view_data_oracle.js +21 -1
  53. package/dest/common/index.d.ts +0 -1
  54. package/dest/common/index.d.ts.map +1 -1
  55. package/dest/common/index.js +1 -2
  56. package/dest/public/dual_side_effect_trace.d.ts +3 -5
  57. package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
  58. package/dest/public/dual_side_effect_trace.js +8 -4
  59. package/dest/public/enqueued_call_side_effect_trace.d.ts +4 -6
  60. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  61. package/dest/public/enqueued_call_side_effect_trace.js +19 -7
  62. package/dest/public/enqueued_call_simulator.d.ts +2 -2
  63. package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
  64. package/dest/public/enqueued_call_simulator.js +21 -29
  65. package/dest/public/enqueued_calls_processor.d.ts +2 -3
  66. package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
  67. package/dest/public/enqueued_calls_processor.js +18 -25
  68. package/dest/public/public_kernel.d.ts +0 -1
  69. package/dest/public/public_kernel.d.ts.map +1 -1
  70. package/dest/public/public_kernel.js +5 -8
  71. package/dest/public/public_kernel_tail_simulator.d.ts +1 -5
  72. package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -1
  73. package/dest/public/public_kernel_tail_simulator.js +6 -12
  74. package/dest/public/public_processor.js +4 -4
  75. package/dest/public/side_effect_trace.d.ts +4 -3
  76. package/dest/public/side_effect_trace.d.ts.map +1 -1
  77. package/dest/public/side_effect_trace.js +27 -16
  78. package/dest/public/side_effect_trace_interface.d.ts +3 -3
  79. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  80. package/package.json +9 -9
  81. package/src/acvm/oracle/oracle.ts +13 -0
  82. package/src/acvm/oracle/typed_oracle.ts +9 -0
  83. package/src/avm/avm_gas.ts +5 -2
  84. package/src/avm/avm_machine_state.ts +2 -0
  85. package/src/avm/avm_simulator.ts +69 -6
  86. package/src/avm/fixtures/index.ts +7 -7
  87. package/src/avm/journal/journal.ts +62 -19
  88. package/src/avm/opcodes/contract.ts +45 -21
  89. package/src/avm/opcodes/conversion.ts +9 -6
  90. package/src/avm/opcodes/environment_getters.ts +7 -2
  91. package/src/avm/opcodes/external_calls.ts +21 -45
  92. package/src/avm/opcodes/memory.ts +69 -2
  93. package/src/avm/serialization/bytecode_serialization.ts +6 -2
  94. package/src/avm/serialization/instruction_serialization.ts +3 -1
  95. package/src/avm/test_utils.ts +5 -1
  96. package/src/client/client_execution_context.ts +0 -27
  97. package/src/client/db_oracle.ts +26 -0
  98. package/src/client/view_data_oracle.ts +31 -1
  99. package/src/common/index.ts +0 -1
  100. package/src/public/dual_side_effect_trace.ts +20 -6
  101. package/src/public/enqueued_call_side_effect_trace.ts +46 -8
  102. package/src/public/enqueued_call_simulator.ts +42 -26
  103. package/src/public/enqueued_calls_processor.ts +26 -38
  104. package/src/public/public_kernel.ts +9 -12
  105. package/src/public/public_kernel_tail_simulator.ts +6 -15
  106. package/src/public/public_processor.ts +3 -3
  107. package/src/public/side_effect_trace.ts +54 -15
  108. package/src/public/side_effect_trace_interface.ts +9 -4
  109. package/dest/client/test_utils.d.ts +0 -9
  110. package/dest/client/test_utils.d.ts.map +0 -1
  111. package/dest/client/test_utils.js +0 -27
  112. package/dest/common/side_effect_counter.d.ts +0 -10
  113. package/dest/common/side_effect_counter.d.ts.map +0 -1
  114. package/dest/common/side_effect_counter.js +0 -18
  115. package/dest/rollup/index.d.ts +0 -2
  116. package/dest/rollup/index.d.ts.map +0 -1
  117. package/dest/rollup/index.js +0 -2
  118. package/dest/rollup/rollup.d.ts +0 -101
  119. package/dest/rollup/rollup.d.ts.map +0 -1
  120. package/dest/rollup/rollup.js +0 -100
  121. package/src/client/test_utils.ts +0 -57
  122. package/src/common/side_effect_counter.ts +0 -17
  123. package/src/rollup/index.ts +0 -1
  124. package/src/rollup/rollup.ts +0 -228
@@ -31,6 +31,8 @@ import {
31
31
  Or,
32
32
  Poseidon2,
33
33
  Return,
34
+ ReturndataCopy,
35
+ ReturndataSize,
34
36
  Revert,
35
37
  SLoad,
36
38
  SStore,
@@ -41,7 +43,7 @@ import {
41
43
  Shr,
42
44
  StaticCall,
43
45
  Sub,
44
- ToRadixLE,
46
+ ToRadixBE,
45
47
  Xor,
46
48
  } from '../opcodes/index.js';
47
49
  import { MultiScalarMul } from '../opcodes/multi_scalar_mul.js';
@@ -96,6 +98,8 @@ const INSTRUCTION_SET = () =>
96
98
  // Execution Environment
97
99
  [Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).deserialize],
98
100
  [CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)],
101
+ [Opcode.RETURNDATASIZE, Instruction.deserialize.bind(ReturndataSize)],
102
+ [Opcode.RETURNDATACOPY, Instruction.deserialize.bind(ReturndataCopy)],
99
103
 
100
104
  // Machine State - Internal Control Flow
101
105
  [Jump.opcode, Instruction.deserialize.bind(Jump)],
@@ -141,7 +145,7 @@ const INSTRUCTION_SET = () =>
141
145
  [Sha256Compression.opcode, Instruction.deserialize.bind(Sha256Compression)],
142
146
  [MultiScalarMul.opcode, Instruction.deserialize.bind(MultiScalarMul)],
143
147
  // Conversions
144
- [ToRadixLE.opcode, Instruction.deserialize.bind(ToRadixLE)],
148
+ [ToRadixBE.opcode, Instruction.deserialize.bind(ToRadixBE)],
145
149
  // Future Gadgets -- pending changes in noir
146
150
  // SHA256COMPRESSION,
147
151
  [KeccakF1600.opcode, Instruction.deserialize.bind(KeccakF1600)],
@@ -41,6 +41,8 @@ export enum Opcode {
41
41
  // Execution environment
42
42
  GETENVVAR_16,
43
43
  CALLDATACOPY,
44
+ RETURNDATASIZE,
45
+ RETURNDATACOPY,
44
46
  // Control flow
45
47
  JUMP_16,
46
48
  JUMPI_16,
@@ -81,7 +83,7 @@ export enum Opcode {
81
83
  ECADD,
82
84
  MSM,
83
85
  // Conversion
84
- TORADIXLE,
86
+ TORADIXBE,
85
87
  }
86
88
 
87
89
  // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
@@ -1,4 +1,4 @@
1
- import { type ContractInstanceWithAddress, Fr } from '@aztec/circuits.js';
1
+ import { type ContractClassPublic, type ContractInstanceWithAddress, Fr } from '@aztec/circuits.js';
2
2
 
3
3
  import { type jest } from '@jest/globals';
4
4
  import { mock } from 'jest-mock-extended';
@@ -61,3 +61,7 @@ export function mockL1ToL2MessageExists(
61
61
  export function mockGetContractInstance(worldStateDB: WorldStateDB, contractInstance: ContractInstanceWithAddress) {
62
62
  (worldStateDB as jest.Mocked<WorldStateDB>).getContractInstance.mockResolvedValue(contractInstance);
63
63
  }
64
+
65
+ export function mockGetContractClass(worldStateDB: WorldStateDB, contractClass: ContractClassPublic) {
66
+ (worldStateDB as jest.Mocked<WorldStateDB>).getContractClass.mockResolvedValue(contractClass);
67
+ }
@@ -602,33 +602,6 @@ export class ClientExecutionContext extends ViewDataOracle {
602
602
  );
603
603
  }
604
604
 
605
- /**
606
- * Read the public storage data.
607
- * @param contractAddress - The address to read storage from.
608
- * @param startStorageSlot - The starting storage slot.
609
- * @param blockNumber - The block number to read storage at.
610
- * @param numberOfElements - Number of elements to read from the starting storage slot.
611
- */
612
- public override async storageRead(
613
- contractAddress: Fr,
614
- startStorageSlot: Fr,
615
- blockNumber: number,
616
- numberOfElements: number,
617
- ): Promise<Fr[]> {
618
- const values = [];
619
- for (let i = 0n; i < numberOfElements; i++) {
620
- const storageSlot = new Fr(startStorageSlot.value + i);
621
-
622
- const value = await this.aztecNode.getPublicStorageAt(contractAddress, storageSlot, blockNumber);
623
- this.log.debug(
624
- `Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
625
- );
626
-
627
- values.push(value);
628
- }
629
- return values;
630
- }
631
-
632
605
  public override debugLog(message: string, fields: Fr[]) {
633
606
  this.log.verbose(`debug_log ${applyStringFormatting(message, fields)}`);
634
607
  }
@@ -9,6 +9,7 @@ import {
9
9
  type CompleteAddress,
10
10
  type ContractInstance,
11
11
  type Header,
12
+ type IndexedTaggingSecret,
12
13
  type KeyValidationRequest,
13
14
  } from '@aztec/circuits.js';
14
15
  import { type FunctionArtifact, type FunctionSelector } from '@aztec/foundation/abi';
@@ -193,4 +194,29 @@ export interface DBOracle extends CommitmentsDB {
193
194
  * @returns The block number.
194
195
  */
195
196
  getBlockNumber(): Promise<number>;
197
+
198
+ /**
199
+ * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
200
+ * Includes the last known index used for tagging with this secret.
201
+ * @param contractAddress - The contract address to silo the secret for
202
+ * @param sender - The address sending the note
203
+ * @param recipient - The address receiving the note
204
+ * @returns A tagging secret that can be used to tag notes.
205
+ */
206
+ getAppTaggingSecret(
207
+ contractAddress: AztecAddress,
208
+ sender: AztecAddress,
209
+ recipient: AztecAddress,
210
+ ): Promise<IndexedTaggingSecret>;
211
+
212
+ /**
213
+ * Returns the siloed tagging secrets for a given recipient and all the senders in the address book
214
+ * @param contractAddress - The contract address to silo the secret for
215
+ * @param recipient - The address receiving the notes
216
+ * @returns A list of siloed tagging secrets
217
+ */
218
+ getAppTaggingSecretsForSenders(
219
+ contractAddress: AztecAddress,
220
+ recipient: AztecAddress,
221
+ ): Promise<IndexedTaggingSecret[]>;
196
222
  }
@@ -7,7 +7,12 @@ import {
7
7
  type NullifierMembershipWitness,
8
8
  type PublicDataWitness,
9
9
  } from '@aztec/circuit-types';
10
- import { type ContractInstance, type Header, type KeyValidationRequest } from '@aztec/circuits.js';
10
+ import {
11
+ type ContractInstance,
12
+ type Header,
13
+ type IndexedTaggingSecret,
14
+ type KeyValidationRequest,
15
+ } from '@aztec/circuits.js';
11
16
  import { siloNullifier } from '@aztec/circuits.js/hash';
12
17
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
13
18
  import { Fr } from '@aztec/foundation/fields';
@@ -288,4 +293,29 @@ export class ViewDataOracle extends TypedOracle {
288
293
  const formattedStr = applyStringFormatting(message, fields);
289
294
  this.log.verbose(`debug_log ${formattedStr}`);
290
295
  }
296
+
297
+ /**
298
+ * Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
299
+ * Includes the last known index used for tagging with this secret.
300
+ * For this to work, the ivpsk_m of the sender must be known.
301
+ * @param sender - The address sending the note
302
+ * @param recipient - The address receiving the note
303
+ * @returns A tagging secret that can be used to tag notes.
304
+ */
305
+ public override async getAppTaggingSecret(
306
+ sender: AztecAddress,
307
+ recipient: AztecAddress,
308
+ ): Promise<IndexedTaggingSecret> {
309
+ return await this.db.getAppTaggingSecret(this.contractAddress, sender, recipient);
310
+ }
311
+
312
+ /**
313
+ * Returns the siloed tagging secrets for a given recipient and all the senders in the address book
314
+ * @param contractAddress - The contract address to silo the secret for
315
+ * @param recipient - The address receiving the notes
316
+ * @returns A list of siloed tagging secrets
317
+ */
318
+ public override async getAppTaggingSecretsForSenders(recipient: AztecAddress): Promise<IndexedTaggingSecret[]> {
319
+ return await this.db.getAppTaggingSecretsForSenders(this.contractAddress, recipient);
320
+ }
291
321
  }
@@ -1,3 +1,2 @@
1
1
  export * from './packed_values_cache.js';
2
2
  export * from './errors.js';
3
- export * from './side_effect_counter.js';
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  type CombinedConstantData,
3
- type ContractInstanceWithAddress,
3
+ type ContractClassIdPreimage,
4
4
  type Gas,
5
+ type SerializableContractInstance,
5
6
  type VMCircuitPublicInputs,
6
7
  } from '@aztec/circuits.js';
7
8
  import { type Fr } from '@aztec/foundation/fields';
@@ -15,8 +16,6 @@ import { type PublicExecutionResult } from './execution.js';
15
16
  import { type PublicSideEffectTrace } from './side_effect_trace.js';
16
17
  import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
17
18
 
18
- export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress;
19
-
20
19
  export class DualSideEffectTrace implements PublicSideEffectTraceInterface {
21
20
  constructor(
22
21
  public readonly innerCallTrace: PublicSideEffectTrace,
@@ -78,9 +77,24 @@ export class DualSideEffectTrace implements PublicSideEffectTraceInterface {
78
77
  this.enqueuedCallTrace.traceUnencryptedLog(contractAddress, log);
79
78
  }
80
79
 
81
- public traceGetContractInstance(instance: TracedContractInstance) {
82
- this.innerCallTrace.traceGetContractInstance(instance);
83
- this.enqueuedCallTrace.traceGetContractInstance(instance);
80
+ public traceGetContractInstance(
81
+ contractAddress: Fr,
82
+ exists: boolean,
83
+ instance: SerializableContractInstance | undefined,
84
+ ) {
85
+ this.innerCallTrace.traceGetContractInstance(contractAddress, exists, instance);
86
+ this.enqueuedCallTrace.traceGetContractInstance(contractAddress, exists, instance);
87
+ }
88
+
89
+ public traceGetBytecode(
90
+ contractAddress: Fr,
91
+ exists: boolean,
92
+ bytecode: Buffer,
93
+ contractInstance: SerializableContractInstance | undefined,
94
+ contractClass: ContractClassIdPreimage | undefined,
95
+ ) {
96
+ this.innerCallTrace.traceGetBytecode(contractAddress, exists, bytecode, contractInstance, contractClass);
97
+ this.enqueuedCallTrace.traceGetBytecode(contractAddress, exists, bytecode, contractInstance, contractClass);
84
98
  }
85
99
 
86
100
  /**
@@ -1,5 +1,6 @@
1
1
  import { UnencryptedL2Log } from '@aztec/circuit-types';
2
2
  import {
3
+ AvmContractBytecodeHints,
3
4
  AvmContractInstanceHint,
4
5
  AvmExecutionHints,
5
6
  AvmExternalCallHint,
@@ -7,7 +8,7 @@ import {
7
8
  AztecAddress,
8
9
  CallContext,
9
10
  type CombinedConstantData,
10
- type ContractInstanceWithAddress,
11
+ type ContractClassIdPreimage,
11
12
  ContractStorageRead,
12
13
  ContractStorageUpdateRequest,
13
14
  EthAddress,
@@ -44,6 +45,7 @@ import {
44
45
  ScopedNoteHash,
45
46
  type ScopedNullifier,
46
47
  ScopedReadRequest,
48
+ SerializableContractInstance,
47
49
  TreeLeafReadRequest,
48
50
  VMCircuitPublicInputs,
49
51
  } from '@aztec/circuits.js';
@@ -58,8 +60,6 @@ import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.j
58
60
  import { SideEffectLimitReachedError } from './side_effect_errors.js';
59
61
  import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
60
62
 
61
- export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress;
62
-
63
63
  /**
64
64
  * A struct containing just the side effects as regular arrays
65
65
  * as opposed to "Tuple" arrays used by circuit public inputs.
@@ -307,14 +307,17 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
307
307
  this.incrementSideEffectCounter();
308
308
  }
309
309
 
310
- public traceGetContractInstance(instance: TracedContractInstance) {
310
+ public traceGetContractInstance(
311
+ contractAddress: Fr,
312
+ exists: boolean,
313
+ instance: SerializableContractInstance = SerializableContractInstance.default(),
314
+ ) {
311
315
  this.enforceLimitOnNullifierChecks('(contract address nullifier from GETCONTRACTINSTANCE)');
312
- // TODO(dbanks12): should emit a nullifier read request
313
316
 
314
317
  this.avmCircuitHints.contractInstances.items.push(
315
318
  new AvmContractInstanceHint(
316
- instance.address,
317
- new Fr(instance.exists ? 1 : 0),
319
+ contractAddress,
320
+ exists,
318
321
  instance.salt,
319
322
  instance.deployer,
320
323
  instance.contractClassId,
@@ -326,6 +329,40 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
326
329
  this.incrementSideEffectCounter();
327
330
  }
328
331
 
332
+ // This tracing function gets called everytime we start simulation/execution.
333
+ // This happens both when starting a new top-level trace and the start of every nested trace
334
+ // We use this to collect the AvmContractBytecodeHints
335
+ public traceGetBytecode(
336
+ contractAddress: Fr,
337
+ exists: boolean,
338
+ bytecode: Buffer = Buffer.alloc(0),
339
+ contractInstance: SerializableContractInstance = SerializableContractInstance.default(),
340
+ contractClass: ContractClassIdPreimage = {
341
+ artifactHash: Fr.zero(),
342
+ privateFunctionsRoot: Fr.zero(),
343
+ publicBytecodeCommitment: Fr.zero(),
344
+ },
345
+ ) {
346
+ const instance = new AvmContractInstanceHint(
347
+ contractAddress,
348
+ exists,
349
+ contractInstance.salt,
350
+ contractInstance.deployer,
351
+ contractInstance.contractClassId,
352
+ contractInstance.initializationHash,
353
+ contractInstance.publicKeys,
354
+ );
355
+ // We need to deduplicate the contract instances based on addresses
356
+ this.avmCircuitHints.contractBytecodeHints.items.push(
357
+ new AvmContractBytecodeHints(bytecode, instance, contractClass),
358
+ );
359
+ this.log.debug(
360
+ `Bytecode retrieval for contract execution traced: exists=${exists}, instance=${JSON.stringify(
361
+ contractInstance,
362
+ )}`,
363
+ );
364
+ }
365
+
329
366
  /**
330
367
  * Trace a nested call.
331
368
  * Accept some results from a finished nested call's trace into this one.
@@ -334,7 +371,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
334
371
  /** The trace of the nested call. */
335
372
  nestedCallTrace: this,
336
373
  /** The execution environment of the nested call. */
337
- _nestedEnvironment: AvmExecutionEnvironment,
374
+ nestedEnvironment: AvmExecutionEnvironment,
338
375
  /** How much gas was available for this public execution. */
339
376
  startGasLeft: Gas,
340
377
  /** How much gas was left after this public execution. */
@@ -368,6 +405,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
368
405
  avmCallResults.output,
369
406
  gasUsed,
370
407
  endSideEffectCounter,
408
+ nestedEnvironment.address,
371
409
  ),
372
410
  );
373
411
  }
@@ -1,17 +1,16 @@
1
1
  import {
2
- AVM_REQUEST,
3
2
  type AvmProvingRequest,
4
3
  MerkleTreeId,
5
4
  NestedProcessReturnValues,
6
5
  ProvingRequestType,
7
6
  type PublicExecutionRequest,
8
7
  PublicKernelPhase,
9
- type PublicProvingRequest,
10
8
  type SimulationError,
11
9
  type Tx,
12
10
  UnencryptedFunctionL2Logs,
13
11
  } from '@aztec/circuit-types';
14
12
  import {
13
+ AvmCircuitInputs,
15
14
  AztecAddress,
16
15
  ContractStorageRead,
17
16
  ContractStorageUpdateRequest,
@@ -52,6 +51,7 @@ import {
52
51
  RevertCode,
53
52
  TreeLeafReadRequest,
54
53
  VMCircuitPublicInputs,
54
+ VerificationKeyData,
55
55
  makeEmptyProof,
56
56
  makeEmptyRecursiveProof,
57
57
  } from '@aztec/circuits.js';
@@ -59,33 +59,22 @@ import { computeVarArgsHash } from '@aztec/circuits.js/hash';
59
59
  import { makeTuple } from '@aztec/foundation/array';
60
60
  import { padArrayEnd } from '@aztec/foundation/collection';
61
61
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
62
- import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types';
63
62
  import { type MerkleTreeReadOperations } from '@aztec/world-state';
64
63
 
65
64
  import { type PublicExecutionResult, accumulatePublicReturnValues, collectExecutionResults } from './execution.js';
66
65
  import { type PublicExecutor } from './executor.js';
67
66
  import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
68
67
 
69
- function makeAvmProvingRequest(
70
- inputs: PublicKernelInnerCircuitPrivateInputs,
71
- result: PublicExecutionResult,
72
- ): AvmProvingRequest {
68
+ function makeAvmProvingRequest(inputs: PublicCircuitPublicInputs, result: PublicExecutionResult): AvmProvingRequest {
73
69
  return {
74
- type: AVM_REQUEST,
75
- functionName: result.functionName,
76
- calldata: result.calldata,
77
- bytecode: result.bytecode!,
78
- avmHints: result.avmCircuitHints,
79
- kernelRequest: {
80
- type: ProvingRequestType.PUBLIC_KERNEL_INNER,
81
- inputs,
82
- },
70
+ type: ProvingRequestType.PUBLIC_VM,
71
+ inputs: new AvmCircuitInputs(result.functionName, result.calldata, inputs, result.avmCircuitHints),
83
72
  };
84
73
  }
85
74
 
86
75
  export type EnqueuedCallResult = {
87
76
  /** Inputs to be used for proving */
88
- provingRequests: PublicProvingRequest[];
77
+ avmProvingRequest: AvmProvingRequest;
89
78
  /** The public kernel output at the end of the enqueued call */
90
79
  kernelOutput: VMCircuitPublicInputs;
91
80
  /** Unencrypted logs generated during the execution of this enqueued call */
@@ -186,7 +175,7 @@ export class EnqueuedCallSimulator {
186
175
  ): Promise<EnqueuedCallResult> {
187
176
  const executionResults = collectExecutionResults(topResult);
188
177
 
189
- const provingRequests: AvmProvingRequest[] = [];
178
+ let avmProvingRequest: AvmProvingRequest;
190
179
  let gasUsed = Gas.empty();
191
180
  let revertReason;
192
181
  let kernelOutput = startVMCircuitOutput;
@@ -215,7 +204,7 @@ export class EnqueuedCallSimulator {
215
204
  kernelOutput = output;
216
205
 
217
206
  // Capture the inputs for later proving in the AVM and kernel.
218
- provingRequests.push(makeAvmProvingRequest(inputs, result));
207
+ avmProvingRequest = makeAvmProvingRequest(inputs.publicCall.publicInputs, result);
219
208
 
220
209
  // Safely return the revert reason and the kernel output (which has had its revertible side effects dropped)
221
210
  // TODO(@leila) we shouldn't drop everything when it reverts. The tail kernel needs the data to prove that it's reverted for the correct reason.
@@ -226,7 +215,7 @@ export class EnqueuedCallSimulator {
226
215
  // TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
227
216
 
228
217
  return {
229
- provingRequests,
218
+ avmProvingRequest,
230
219
  kernelOutput,
231
220
  newUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
232
221
  returnValues: NestedProcessReturnValues.empty(),
@@ -237,7 +226,7 @@ export class EnqueuedCallSimulator {
237
226
  }
238
227
 
239
228
  return {
240
- provingRequests,
229
+ avmProvingRequest: avmProvingRequest!,
241
230
  kernelOutput,
242
231
  newUnencryptedLogs: topResult.allUnencryptedLogs,
243
232
  returnValues: accumulatePublicReturnValues(topResult),
@@ -257,7 +246,7 @@ export class EnqueuedCallSimulator {
257
246
  ): Promise<{ inputs: PublicKernelInnerCircuitPrivateInputs; output: VMCircuitPublicInputs }> {
258
247
  // The proof is not used in simulation
259
248
  const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
260
- const vk = ProtocolCircuitVks.PublicKernelInnerArtifact;
249
+ const vk = VerificationKeyData.makeFakeHonk();
261
250
  const previousKernel = new PublicKernelInnerData(previousOutput, proof, vk);
262
251
  const inputs = new PublicKernelInnerCircuitPrivateInputs(previousKernel, callData);
263
252
  return { inputs, output: await this.publicKernelSimulator.publicKernelCircuitInner(inputs) };
@@ -283,9 +272,24 @@ export class EnqueuedCallSimulator {
283
272
  callContext: result.executionRequest.callContext,
284
273
  proverAddress: AztecAddress.ZERO,
285
274
  argsHash: computeVarArgsHash(result.executionRequest.args),
286
- noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL),
287
- nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL),
288
- l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL),
275
+ noteHashes: padArrayEnd(
276
+ result.noteHashes,
277
+ NoteHash.empty(),
278
+ MAX_NOTE_HASHES_PER_CALL,
279
+ `Too many note hashes. Got ${result.noteHashes.length} with max being ${MAX_NOTE_HASHES_PER_CALL}`,
280
+ ),
281
+ nullifiers: padArrayEnd(
282
+ result.nullifiers,
283
+ Nullifier.empty(),
284
+ MAX_NULLIFIERS_PER_CALL,
285
+ `Too many nullifiers. Got ${result.nullifiers.length} with max being ${MAX_NULLIFIERS_PER_CALL}`,
286
+ ),
287
+ l2ToL1Msgs: padArrayEnd(
288
+ result.l2ToL1Messages,
289
+ L2ToL1Message.empty(),
290
+ MAX_L2_TO_L1_MSGS_PER_CALL,
291
+ `Too many L2 to L1 messages. Got ${result.l2ToL1Messages.length} with max being ${MAX_L2_TO_L1_MSGS_PER_CALL}`,
292
+ ),
289
293
  startSideEffectCounter: result.startSideEffectCounter,
290
294
  endSideEffectCounter: result.endSideEffectCounter,
291
295
  returnsHash: computeVarArgsHash(result.returnValues),
@@ -293,38 +297,50 @@ export class EnqueuedCallSimulator {
293
297
  result.noteHashReadRequests,
294
298
  TreeLeafReadRequest.empty(),
295
299
  MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
300
+ `Too many note hash read requests. Got ${result.noteHashReadRequests.length} with max being ${MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}`,
296
301
  ),
297
302
  nullifierReadRequests: padArrayEnd(
298
303
  result.nullifierReadRequests,
299
304
  ReadRequest.empty(),
300
305
  MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
306
+ `Too many nullifier read requests. Got ${result.nullifierReadRequests.length} with max being ${MAX_NULLIFIER_READ_REQUESTS_PER_CALL}`,
301
307
  ),
302
308
  nullifierNonExistentReadRequests: padArrayEnd(
303
309
  result.nullifierNonExistentReadRequests,
304
310
  ReadRequest.empty(),
305
311
  MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
312
+ `Too many nullifier non-existent read requests. Got ${result.nullifierNonExistentReadRequests.length} with max being ${MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL}`,
306
313
  ),
307
314
  l1ToL2MsgReadRequests: padArrayEnd(
308
315
  result.l1ToL2MsgReadRequests,
309
316
  TreeLeafReadRequest.empty(),
310
317
  MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
318
+ `Too many L1 to L2 message read requests. Got ${result.l1ToL2MsgReadRequests.length} with max being ${MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL}`,
311
319
  ),
312
320
  contractStorageReads: padArrayEnd(
313
321
  result.contractStorageReads,
314
322
  ContractStorageRead.empty(),
315
323
  MAX_PUBLIC_DATA_READS_PER_CALL,
324
+ `Too many public data reads. Got ${result.contractStorageReads.length} with max being ${MAX_PUBLIC_DATA_READS_PER_CALL}`,
316
325
  ),
317
326
  contractStorageUpdateRequests: padArrayEnd(
318
327
  result.contractStorageUpdateRequests,
319
328
  ContractStorageUpdateRequest.empty(),
320
329
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
330
+ `Too many public data update requests. Got ${result.contractStorageUpdateRequests.length} with max being ${MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL}`,
321
331
  ),
322
332
  publicCallRequests: padArrayEnd(
323
333
  result.publicCallRequests,
324
334
  PublicInnerCallRequest.empty(),
325
335
  MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
336
+ `Too many public call requests. Got ${result.publicCallRequests.length} with max being ${MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}`,
337
+ ),
338
+ unencryptedLogsHashes: padArrayEnd(
339
+ result.unencryptedLogsHashes,
340
+ LogHash.empty(),
341
+ MAX_UNENCRYPTED_LOGS_PER_CALL,
342
+ `Too many unencrypted logs. Got ${result.unencryptedLogsHashes.length} with max being ${MAX_UNENCRYPTED_LOGS_PER_CALL}`,
326
343
  ),
327
- unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
328
344
  historicalHeader: this.historicalHeader,
329
345
  globalVariables: this.globalVariables,
330
346
  startGasLeft: Gas.from(result.startGasLeft),