@aztec/simulator 0.40.1 → 0.42.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 (234) hide show
  1. package/dest/acvm/acvm.d.ts +2 -2
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +3 -3
  4. package/dest/acvm/oracle/oracle.d.ts +6 -2
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +31 -19
  7. package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +17 -5
  10. package/dest/acvm/serialize.js +2 -2
  11. package/dest/avm/avm_execution_environment.d.ts +4 -3
  12. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  13. package/dest/avm/avm_execution_environment.js +7 -5
  14. package/dest/avm/avm_gas.d.ts +1 -5
  15. package/dest/avm/avm_gas.d.ts.map +1 -1
  16. package/dest/avm/avm_gas.js +67 -73
  17. package/dest/avm/avm_simulator.d.ts +5 -0
  18. package/dest/avm/avm_simulator.d.ts.map +1 -1
  19. package/dest/avm/avm_simulator.js +12 -4
  20. package/dest/avm/errors.d.ts +6 -0
  21. package/dest/avm/errors.d.ts.map +1 -1
  22. package/dest/avm/errors.js +10 -1
  23. package/dest/avm/fixtures/index.d.ts +3 -0
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +15 -3
  26. package/dest/avm/index.d.ts +2 -0
  27. package/dest/avm/index.d.ts.map +1 -0
  28. package/dest/avm/index.js +2 -0
  29. package/dest/avm/journal/host_storage.d.ts +1 -1
  30. package/dest/avm/journal/host_storage.d.ts.map +1 -1
  31. package/dest/avm/journal/journal.d.ts +4 -3
  32. package/dest/avm/journal/journal.d.ts.map +1 -1
  33. package/dest/avm/journal/journal.js +10 -11
  34. package/dest/avm/journal/nullifiers.d.ts +17 -5
  35. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  36. package/dest/avm/journal/nullifiers.js +27 -10
  37. package/dest/avm/journal/public_storage.d.ts +19 -6
  38. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  39. package/dest/avm/journal/public_storage.js +30 -12
  40. package/dest/avm/journal/trace.d.ts +2 -0
  41. package/dest/avm/journal/trace.d.ts.map +1 -1
  42. package/dest/avm/journal/trace.js +7 -1
  43. package/dest/avm/journal/trace_types.d.ts +1 -0
  44. package/dest/avm/journal/trace_types.d.ts.map +1 -1
  45. package/dest/avm/journal/trace_types.js +1 -1
  46. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  47. package/dest/avm/opcodes/accrued_substate.js +6 -7
  48. package/dest/avm/opcodes/arithmetic.d.ts +1 -7
  49. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  50. package/dest/avm/opcodes/arithmetic.js +1 -12
  51. package/dest/avm/opcodes/conversion.js +2 -2
  52. package/dest/avm/opcodes/external_calls.d.ts +2 -2
  53. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  54. package/dest/avm/opcodes/external_calls.js +25 -13
  55. package/dest/avm/opcodes/instruction.d.ts +1 -1
  56. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  57. package/dest/avm/opcodes/instruction.js +6 -4
  58. package/dest/avm/opcodes/memory.d.ts +0 -4
  59. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  60. package/dest/avm/opcodes/memory.js +1 -7
  61. package/dest/avm/opcodes/storage.d.ts +0 -12
  62. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  63. package/dest/avm/opcodes/storage.js +3 -18
  64. package/dest/avm/serialization/bytecode_serialization.js +2 -2
  65. package/dest/client/client_execution_context.d.ts +30 -20
  66. package/dest/client/client_execution_context.d.ts.map +1 -1
  67. package/dest/client/client_execution_context.js +59 -39
  68. package/dest/client/db_oracle.d.ts +17 -12
  69. package/dest/client/db_oracle.d.ts.map +1 -1
  70. package/dest/client/execution_note_cache.js +2 -2
  71. package/dest/client/execution_result.d.ts +17 -2
  72. package/dest/client/execution_result.d.ts.map +1 -1
  73. package/dest/client/execution_result.js +32 -4
  74. package/dest/client/private_execution.d.ts +2 -3
  75. package/dest/client/private_execution.d.ts.map +1 -1
  76. package/dest/client/private_execution.js +22 -8
  77. package/dest/client/simulator.d.ts +0 -16
  78. package/dest/client/simulator.d.ts.map +1 -1
  79. package/dest/client/simulator.js +13 -30
  80. package/dest/client/unconstrained_execution.d.ts +2 -3
  81. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  82. package/dest/client/unconstrained_execution.js +5 -7
  83. package/dest/client/view_data_oracle.d.ts +12 -10
  84. package/dest/client/view_data_oracle.d.ts.map +1 -1
  85. package/dest/client/view_data_oracle.js +17 -11
  86. package/dest/common/index.d.ts +1 -0
  87. package/dest/common/index.d.ts.map +1 -1
  88. package/dest/common/index.js +2 -1
  89. package/dest/common/return_values.d.ts +11 -0
  90. package/dest/common/return_values.d.ts.map +1 -0
  91. package/dest/common/return_values.js +13 -0
  92. package/dest/index.d.ts +3 -1
  93. package/dest/index.d.ts.map +1 -1
  94. package/dest/index.js +4 -2
  95. package/dest/mocks/fixtures.d.ts +15 -10
  96. package/dest/mocks/fixtures.d.ts.map +1 -1
  97. package/dest/mocks/fixtures.js +22 -17
  98. package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
  99. package/dest/{simulator → providers}/acvm_native.js +13 -14
  100. package/dest/providers/acvm_wasm.d.ts.map +1 -0
  101. package/dest/providers/acvm_wasm.js +15 -0
  102. package/dest/providers/index.d.ts.map +1 -0
  103. package/dest/{simulator → providers}/index.js +1 -1
  104. package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
  105. package/dest/{simulator → providers}/simulation_provider.js +1 -1
  106. package/dest/public/abstract_phase_manager.d.ts +43 -42
  107. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  108. package/dest/public/abstract_phase_manager.js +81 -103
  109. package/dest/public/app_logic_phase_manager.d.ts +7 -8
  110. package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
  111. package/dest/public/app_logic_phase_manager.js +14 -14
  112. package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
  113. package/dest/public/db_interfaces.d.ts.map +1 -0
  114. package/dest/public/db_interfaces.js +2 -0
  115. package/dest/public/execution.d.ts +17 -14
  116. package/dest/public/execution.d.ts.map +1 -1
  117. package/dest/public/execution.js +1 -1
  118. package/dest/public/executor.d.ts +3 -30
  119. package/dest/public/executor.d.ts.map +1 -1
  120. package/dest/public/executor.js +32 -279
  121. package/dest/public/fee_payment.d.ts +11 -0
  122. package/dest/public/fee_payment.d.ts.map +1 -0
  123. package/dest/public/fee_payment.js +24 -0
  124. package/dest/public/hints_builder.d.ts +3 -2
  125. package/dest/public/hints_builder.d.ts.map +1 -1
  126. package/dest/public/hints_builder.js +8 -4
  127. package/dest/public/index.d.ts +4 -2
  128. package/dest/public/index.d.ts.map +1 -1
  129. package/dest/public/index.js +5 -3
  130. package/dest/public/phase_manager_factory.d.ts +1 -1
  131. package/dest/public/phase_manager_factory.d.ts.map +1 -1
  132. package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
  133. package/dest/public/public_db_sources.d.ts.map +1 -0
  134. package/dest/public/public_db_sources.js +198 -0
  135. package/dest/public/public_kernel.js +14 -14
  136. package/dest/public/public_processor.d.ts +8 -6
  137. package/dest/public/public_processor.d.ts.map +1 -1
  138. package/dest/public/public_processor.js +48 -29
  139. package/dest/public/setup_phase_manager.d.ts +7 -9
  140. package/dest/public/setup_phase_manager.d.ts.map +1 -1
  141. package/dest/public/setup_phase_manager.js +11 -20
  142. package/dest/public/tail_phase_manager.d.ts +5 -11
  143. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  144. package/dest/public/tail_phase_manager.js +16 -36
  145. package/dest/public/teardown_phase_manager.d.ts +7 -9
  146. package/dest/public/teardown_phase_manager.d.ts.map +1 -1
  147. package/dest/public/teardown_phase_manager.js +15 -21
  148. package/dest/public/transitional_adaptors.d.ts +3 -2
  149. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  150. package/dest/public/transitional_adaptors.js +24 -8
  151. package/dest/public/utils.d.ts +2 -2
  152. package/dest/public/utils.d.ts.map +1 -1
  153. package/dest/public/utils.js +21 -14
  154. package/package.json +12 -9
  155. package/src/acvm/acvm.ts +0 -3
  156. package/src/acvm/oracle/oracle.ts +53 -27
  157. package/src/acvm/oracle/typed_oracle.ts +25 -16
  158. package/src/acvm/serialize.ts +1 -1
  159. package/src/avm/avm_execution_environment.ts +9 -5
  160. package/src/avm/avm_gas.ts +66 -73
  161. package/src/avm/avm_simulator.ts +14 -3
  162. package/src/avm/errors.ts +10 -0
  163. package/src/avm/fixtures/index.ts +22 -2
  164. package/src/avm/index.ts +1 -0
  165. package/src/avm/journal/host_storage.ts +1 -1
  166. package/src/avm/journal/journal.ts +15 -14
  167. package/src/avm/journal/nullifiers.ts +27 -14
  168. package/src/avm/journal/public_storage.ts +30 -16
  169. package/src/avm/journal/trace.ts +12 -0
  170. package/src/avm/journal/trace_types.ts +1 -0
  171. package/src/avm/opcodes/accrued_substate.ts +5 -6
  172. package/src/avm/opcodes/arithmetic.ts +1 -14
  173. package/src/avm/opcodes/conversion.ts +1 -1
  174. package/src/avm/opcodes/external_calls.ts +26 -10
  175. package/src/avm/opcodes/instruction.ts +5 -3
  176. package/src/avm/opcodes/memory.ts +1 -8
  177. package/src/avm/opcodes/storage.ts +3 -20
  178. package/src/avm/serialization/bytecode_serialization.ts +1 -1
  179. package/src/client/client_execution_context.ts +70 -44
  180. package/src/client/db_oracle.ts +18 -12
  181. package/src/client/execution_note_cache.ts +1 -1
  182. package/src/client/execution_result.ts +41 -3
  183. package/src/client/private_execution.ts +38 -20
  184. package/src/client/simulator.ts +11 -32
  185. package/src/client/unconstrained_execution.ts +9 -12
  186. package/src/client/view_data_oracle.ts +20 -12
  187. package/src/common/index.ts +1 -0
  188. package/src/common/return_values.ts +18 -0
  189. package/src/index.ts +3 -1
  190. package/src/mocks/fixtures.ts +31 -33
  191. package/src/{simulator → providers}/acvm_native.ts +21 -19
  192. package/src/{simulator → providers}/acvm_wasm.ts +2 -16
  193. package/src/public/abstract_phase_manager.ts +146 -207
  194. package/src/public/app_logic_phase_manager.ts +23 -39
  195. package/src/public/{db.ts → db_interfaces.ts} +2 -2
  196. package/src/public/execution.ts +17 -14
  197. package/src/public/executor.ts +51 -391
  198. package/src/public/fee_payment.ts +26 -0
  199. package/src/public/hints_builder.ts +17 -3
  200. package/src/public/index.ts +4 -2
  201. package/src/public/phase_manager_factory.ts +1 -1
  202. package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
  203. package/src/public/public_kernel.ts +24 -24
  204. package/src/public/public_processor.ts +82 -38
  205. package/src/public/setup_phase_manager.ts +20 -45
  206. package/src/public/tail_phase_manager.ts +18 -68
  207. package/src/public/teardown_phase_manager.ts +22 -41
  208. package/src/public/transitional_adaptors.ts +24 -13
  209. package/src/public/utils.ts +20 -14
  210. package/dest/client/logs_cache.d.ts +0 -33
  211. package/dest/client/logs_cache.d.ts.map +0 -1
  212. package/dest/client/logs_cache.js +0 -59
  213. package/dest/public/db.d.ts.map +0 -1
  214. package/dest/public/db.js +0 -2
  215. package/dest/public/public_execution_context.d.ts +0 -121
  216. package/dest/public/public_execution_context.d.ts.map +0 -1
  217. package/dest/public/public_execution_context.js +0 -214
  218. package/dest/public/public_executor.d.ts.map +0 -1
  219. package/dest/public/public_executor.js +0 -197
  220. package/dest/public/state_actions.d.ts +0 -39
  221. package/dest/public/state_actions.d.ts.map +0 -1
  222. package/dest/public/state_actions.js +0 -80
  223. package/dest/simulator/acvm_wasm.d.ts.map +0 -1
  224. package/dest/simulator/acvm_wasm.js +0 -22
  225. package/dest/simulator/index.d.ts.map +0 -1
  226. package/src/client/logs_cache.ts +0 -65
  227. package/src/public/public_execution_context.ts +0 -289
  228. package/src/public/state_actions.ts +0 -102
  229. /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
  230. /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
  231. /package/dest/{simulator → providers}/index.d.ts +0 -0
  232. /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
  233. /package/src/{simulator → providers}/index.ts +0 -0
  234. /package/src/{simulator → providers}/simulation_provider.ts +0 -0
@@ -1,20 +1,19 @@
1
1
  import {
2
2
  type AuthWitness,
3
3
  type AztecNode,
4
- EncryptedFunctionL2Logs,
5
4
  EncryptedL2Log,
5
+ EncryptedL2NoteLog,
6
6
  L1NotePayload,
7
7
  Note,
8
8
  type NoteStatus,
9
9
  TaggedNote,
10
- UnencryptedFunctionL2Logs,
11
10
  type UnencryptedL2Log,
12
11
  } from '@aztec/circuit-types';
13
12
  import {
14
13
  CallContext,
15
- FunctionData,
16
14
  FunctionSelector,
17
15
  type Header,
16
+ type KeyValidationRequest,
18
17
  PrivateContextInputs,
19
18
  PublicCallRequest,
20
19
  type TxContext,
@@ -22,16 +21,16 @@ import {
22
21
  import { Aes128 } from '@aztec/circuits.js/barretenberg';
23
22
  import { computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
24
23
  import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi';
25
- import { type AztecAddress } from '@aztec/foundation/aztec-address';
26
- import { Fr, type Point } from '@aztec/foundation/fields';
24
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
25
+ import { pedersenHash } from '@aztec/foundation/crypto';
26
+ import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
27
27
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
28
28
 
29
29
  import { type NoteData, toACVMWitness } from '../acvm/index.js';
30
30
  import { type PackedValuesCache } from '../common/packed_values_cache.js';
31
31
  import { type DBOracle } from './db_oracle.js';
32
32
  import { type ExecutionNoteCache } from './execution_note_cache.js';
33
- import { CountedLog, type ExecutionResult, type NoteAndSlot } from './execution_result.js';
34
- import { type LogsCache } from './logs_cache.js';
33
+ import { CountedLog, CountedNoteLog, type ExecutionResult, type NoteAndSlot } from './execution_result.js';
35
34
  import { pickNotes } from './pick_notes.js';
36
35
  import { executePrivateFunction } from './private_execution.js';
37
36
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -59,6 +58,7 @@ export class ClientExecutionContext extends ViewDataOracle {
59
58
  */
60
59
  private noteHashLeafIndexMap: Map<bigint, bigint> = new Map();
61
60
  private nullifiedNoteHashCounters: Map<number, number> = new Map();
61
+ private noteEncryptedLogs: CountedNoteLog[] = [];
62
62
  private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
63
63
  private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
64
64
  private nestedExecutions: ExecutionResult[] = [];
@@ -76,7 +76,6 @@ export class ClientExecutionContext extends ViewDataOracle {
76
76
  authWitnesses: AuthWitness[],
77
77
  private readonly packedValuesCache: PackedValuesCache,
78
78
  private readonly noteCache: ExecutionNoteCache,
79
- private readonly logsCache: LogsCache,
80
79
  db: DBOracle,
81
80
  private node: AztecNode,
82
81
  protected sideEffectCounter: number = 0,
@@ -133,17 +132,17 @@ export class ClientExecutionContext extends ViewDataOracle {
133
132
  }
134
133
 
135
134
  /**
136
- * Return the encrypted logs emitted during this execution.
135
+ * Return the note encrypted logs emitted during this execution.
137
136
  */
138
- public getEncryptedLogs() {
139
- return this.encryptedLogs;
137
+ public getNoteEncryptedLogs() {
138
+ return this.noteEncryptedLogs;
140
139
  }
141
140
 
142
141
  /**
143
- * Return the encrypted logs emitted during this execution and nested executions.
142
+ * Return the encrypted logs emitted during this execution.
144
143
  */
145
- public getAllEncryptedLogs() {
146
- return new EncryptedFunctionL2Logs(this.logsCache.getEncryptedLogs());
144
+ public getEncryptedLogs() {
145
+ return this.encryptedLogs;
147
146
  }
148
147
 
149
148
  /**
@@ -153,13 +152,6 @@ export class ClientExecutionContext extends ViewDataOracle {
153
152
  return this.unencryptedLogs;
154
153
  }
155
154
 
156
- /**
157
- * Return the unencrypted logs emitted during this execution and nested executions.
158
- */
159
- public getAllUnencryptedLogs() {
160
- return new UnencryptedFunctionL2Logs(this.logsCache.getUnencryptedLogs());
161
- }
162
-
163
155
  /**
164
156
  * Return the nested execution results during this execution.
165
157
  */
@@ -337,29 +329,63 @@ export class ClientExecutionContext extends ViewDataOracle {
337
329
  }
338
330
 
339
331
  /**
340
- * Encrypt a note and emit it as a log.
332
+ * Emit encrypted data
333
+ * @param encryptedNote - The encrypted data.
334
+ * @param counter - The effects counter.
335
+ */
336
+ public override emitEncryptedLog(
337
+ contractAddress: AztecAddress,
338
+ randomness: Fr,
339
+ encryptedData: Buffer,
340
+ counter: number,
341
+ ) {
342
+ // In some cases, we actually want to reveal the contract address we are siloing with:
343
+ // e.g. 'handshaking' contract w/ known address
344
+ // An app providing randomness = 0 signals to not mask the address.
345
+ const maskedContractAddress = randomness.isZero()
346
+ ? contractAddress.toField()
347
+ : pedersenHash([contractAddress, randomness], 0);
348
+ const encryptedLog = new CountedLog(new EncryptedL2Log(encryptedData, maskedContractAddress), counter);
349
+ this.encryptedLogs.push(encryptedLog);
350
+ }
351
+
352
+ /**
353
+ * Emit encrypted note data
354
+ * @param noteHashCounter - The note hash counter.
355
+ * @param encryptedNote - The encrypted note data.
356
+ * @param counter - The log counter.
357
+ */
358
+ public override emitEncryptedNoteLog(noteHashCounter: number, encryptedNote: Buffer, counter: number) {
359
+ const encryptedLog = new CountedNoteLog(new EncryptedL2NoteLog(encryptedNote), counter, noteHashCounter);
360
+ this.noteEncryptedLogs.push(encryptedLog);
361
+ }
362
+
363
+ /**
364
+ * Encrypt a note
341
365
  * @param contractAddress - The contract address of the note.
342
366
  * @param storageSlot - The storage slot the note is at.
343
367
  * @param noteTypeId - The type ID of the note.
344
- * @param publicKey - The public key of the account that can decrypt the log.
345
- * @param log - The log contents.
368
+ * @param ovKeys - The outgoing viewing keys to use to encrypt.
369
+ * @param ivpkM - The master incoming viewing public key.
370
+ * @param preimage - The note preimage.
346
371
  */
347
- public override emitEncryptedLog(
372
+ public override computeEncryptedLog(
348
373
  contractAddress: AztecAddress,
349
374
  storageSlot: Fr,
350
375
  noteTypeId: Fr,
351
- publicKey: Point,
352
- log: Fr[],
353
- counter: number,
376
+ ovKeys: KeyValidationRequest,
377
+ ivpkM: Point,
378
+ preimage: Fr[],
354
379
  ) {
355
- const note = new Note(log);
380
+ const note = new Note(preimage);
356
381
  const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId);
357
382
  const taggedNote = new TaggedNote(l1NotePayload);
358
- const encryptedNote = taggedNote.toEncryptedBuffer(publicKey);
359
- const encryptedLog = new EncryptedL2Log(encryptedNote);
360
- this.encryptedLogs.push(new CountedLog(encryptedLog, counter));
361
- this.logsCache.addEncryptedLog(encryptedLog);
362
- return encryptedNote;
383
+
384
+ const ephSk = GrumpkinScalar.random();
385
+
386
+ const recipient = AztecAddress.random();
387
+
388
+ return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys);
363
389
  }
364
390
 
365
391
  /**
@@ -368,7 +394,6 @@ export class ClientExecutionContext extends ViewDataOracle {
368
394
  */
369
395
  public override emitUnencryptedLog(log: UnencryptedL2Log, counter: number) {
370
396
  this.unencryptedLogs.push(new CountedLog(log, counter));
371
- this.logsCache.addUnencryptedLog(log);
372
397
  const text = log.toHumanReadable();
373
398
  this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
374
399
  }
@@ -382,7 +407,6 @@ export class ClientExecutionContext extends ViewDataOracle {
382
407
  */
383
408
  public override emitContractClassUnencryptedLog(log: UnencryptedL2Log, counter: number) {
384
409
  this.unencryptedLogs.push(new CountedLog(log, counter));
385
- this.logsCache.addUnencryptedLog(log);
386
410
  const text = log.toHumanReadable();
387
411
  this.log.verbose(
388
412
  `Emitted unencrypted log from ContractClassRegisterer: "${
@@ -397,10 +421,10 @@ export class ClientExecutionContext extends ViewDataOracle {
397
421
  childExecutionResult.callStackItem.publicInputs.newNoteHashes.some(item => !item.isEmpty()) ||
398
422
  childExecutionResult.callStackItem.publicInputs.newNullifiers.some(item => !item.isEmpty()) ||
399
423
  childExecutionResult.callStackItem.publicInputs.newL2ToL1Msgs.some(item => !item.isEmpty()) ||
400
- !childExecutionResult.callStackItem.publicInputs.encryptedLogPreimagesLength.equals(new Fr(4)) ||
401
- !childExecutionResult.callStackItem.publicInputs.unencryptedLogPreimagesLength.equals(new Fr(4))
424
+ childExecutionResult.callStackItem.publicInputs.encryptedLogsHashes.some(item => !item.isEmpty()) ||
425
+ childExecutionResult.callStackItem.publicInputs.unencryptedLogsHashes.some(item => !item.isEmpty())
402
426
  ) {
403
- throw new Error(`Static call cannot create new notes, emit L2->L1 messages or generate logs`);
427
+ throw new Error(`Static call cannot update the state, emit L2->L1 messages or generate logs`);
404
428
  }
405
429
  }
406
430
 
@@ -411,7 +435,7 @@ export class ClientExecutionContext extends ViewDataOracle {
411
435
  * @param argsHash - The packed arguments to pass to the function.
412
436
  * @param sideEffectCounter - The side effect counter at the start of the call.
413
437
  * @param isStaticCall - Whether the call is a static call.
414
- * @param isStaticCall - Whether the call is a delegate call.
438
+ * @param isDelegateCall - Whether the call is a delegate call.
415
439
  * @returns The execution result.
416
440
  */
417
441
  override async callPrivateFunction(
@@ -429,7 +453,6 @@ export class ClientExecutionContext extends ViewDataOracle {
429
453
  isStaticCall = isStaticCall || this.callContext.isStaticCall;
430
454
 
431
455
  const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
432
- const targetFunctionData = FunctionData.fromAbi(targetArtifact);
433
456
 
434
457
  const derivedTxContext = this.txContext.clone();
435
458
 
@@ -450,7 +473,6 @@ export class ClientExecutionContext extends ViewDataOracle {
450
473
  this.authWitnesses,
451
474
  this.packedValuesCache,
452
475
  this.noteCache,
453
- this.logsCache,
454
476
  this.db,
455
477
  this.node,
456
478
  sideEffectCounter,
@@ -460,7 +482,7 @@ export class ClientExecutionContext extends ViewDataOracle {
460
482
  context,
461
483
  targetArtifact,
462
484
  targetContractAddress,
463
- targetFunctionData,
485
+ functionSelector,
464
486
  );
465
487
 
466
488
  if (isStaticCall) {
@@ -514,7 +536,7 @@ export class ClientExecutionContext extends ViewDataOracle {
514
536
  args,
515
537
  callContext: derivedCallContext,
516
538
  parentCallContext: this.callContext,
517
- functionData: FunctionData.fromAbi(targetArtifact),
539
+ functionSelector,
518
540
  contractAddress: targetContractAddress,
519
541
  });
520
542
  }
@@ -646,4 +668,8 @@ export class ClientExecutionContext extends ViewDataOracle {
646
668
  public override debugLog(message: string, fields: Fr[]) {
647
669
  this.log.verbose(`debug_log ${applyStringFormatting(message, fields)}`);
648
670
  }
671
+
672
+ public getDebugFunctionName() {
673
+ return this.db.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
674
+ }
649
675
  }
@@ -5,14 +5,14 @@ import {
5
5
  type NullifierMembershipWitness,
6
6
  type PublicDataWitness,
7
7
  } from '@aztec/circuit-types';
8
- import { type CompleteAddress, type Header } from '@aztec/circuits.js';
8
+ import { type CompleteAddress, type Header, type KeyValidationRequest } from '@aztec/circuits.js';
9
9
  import { type FunctionArtifact, type FunctionSelector } from '@aztec/foundation/abi';
10
10
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
11
11
  import { type Fr } from '@aztec/foundation/fields';
12
12
  import { type ContractInstance } from '@aztec/types/contracts';
13
13
 
14
- import { type NoteData, type NullifierKeys } from '../acvm/index.js';
15
- import { type CommitmentsDB } from '../public/db.js';
14
+ import { type NoteData } from '../acvm/index.js';
15
+ import { type CommitmentsDB } from '../public/db_interfaces.js';
16
16
 
17
17
  /**
18
18
  * Error thrown when a contract is not found in the database.
@@ -45,10 +45,11 @@ export interface DBOracle extends CommitmentsDB {
45
45
 
46
46
  /**
47
47
  * Retrieve the complete address associated to a given address.
48
- * @param address - Address to fetch the pubkey for.
48
+ * @param account - The account address.
49
49
  * @returns A complete address associated with the input address.
50
+ * @throws An error if the account is not registered in the database.
50
51
  */
51
- getCompleteAddress(address: AztecAddress): Promise<CompleteAddress>;
52
+ getCompleteAddress(account: AztecAddress): Promise<CompleteAddress>;
52
53
 
53
54
  /**
54
55
  * Retrieve the auth witness for a given message hash.
@@ -65,14 +66,12 @@ export interface DBOracle extends CommitmentsDB {
65
66
  popCapsule(): Promise<Fr[]>;
66
67
 
67
68
  /**
68
- * Retrieve nullifier keys associated with a specific account and app/contract address.
69
- *
70
- * @param accountAddress - The account address.
71
- * @param contractAddress - The contract address.
72
- * @returns A Promise that resolves to nullifier keys of a requested account and contract.
73
- * @throws An error if the account is not registered in the database.
69
+ * Retrieve keys associated with a specific master public key and app address.
70
+ * @param pkMHash - The master public key hash.
71
+ * @returns A Promise that resolves to nullifier keys.
72
+ * @throws If the keys are not registered in the key store.
74
73
  */
75
- getNullifierKeys(accountAddress: AztecAddress, contractAddress: AztecAddress): Promise<NullifierKeys>;
74
+ getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise<KeyValidationRequest>;
76
75
 
77
76
  /**
78
77
  * Retrieves a set of notes stored in the database for a given contract address and storage slot.
@@ -96,6 +95,13 @@ export interface DBOracle extends CommitmentsDB {
96
95
  */
97
96
  getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector): Promise<FunctionArtifact>;
98
97
 
98
+ /**
99
+ * Generates a stable function name for debug purposes.
100
+ * @param contractAddress - The contract address.
101
+ * @param selector - The corresponding function selector.
102
+ */
103
+ getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
104
+
99
105
  /**
100
106
  * Retrieves the artifact of a specified function within a given contract.
101
107
  * The function is identified by its name, which is unique within a contract.
@@ -52,7 +52,7 @@ export class ExecutionNoteCache {
52
52
  this.nullifiers.set(contractAddress.toBigInt(), nullifiers);
53
53
 
54
54
  let nullifiedNoteHashCounter: number | undefined = undefined;
55
- // Find and remove the matching new note if the emitted innerNoteHash is not empty.
55
+ // Find and remove the matching new note and log(s) if the emitted innerNoteHash is not empty.
56
56
  if (!innerNoteHash.equals(Fr.ZERO)) {
57
57
  const notes = this.newNotes.get(contractAddress.toBigInt()) ?? [];
58
58
  const noteIndexToRemove = notes.findIndex(n => n.note.innerNoteHash.equals(innerNoteHash));
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  EncryptedFunctionL2Logs,
3
3
  type EncryptedL2Log,
4
+ type EncryptedL2NoteLog,
5
+ EncryptedNoteFunctionL2Logs,
4
6
  type Note,
5
7
  UnencryptedFunctionL2Logs,
6
8
  type UnencryptedL2Log,
@@ -22,7 +24,7 @@ export interface NoteAndSlot {
22
24
  noteTypeId: Fr;
23
25
  }
24
26
 
25
- export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2Log> implements IsEmpty {
27
+ export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2NoteLog | EncryptedL2Log> implements IsEmpty {
26
28
  constructor(public log: TLog, public counter: number) {}
27
29
 
28
30
  isEmpty(): boolean {
@@ -30,6 +32,11 @@ export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2Log> implemen
30
32
  }
31
33
  }
32
34
 
35
+ export class CountedNoteLog extends CountedLog<EncryptedL2NoteLog> {
36
+ constructor(log: EncryptedL2NoteLog, counter: number, public noteHashCounter: number) {
37
+ super(log, counter);
38
+ }
39
+ }
33
40
  /**
34
41
  * The result of executing a private function.
35
42
  */
@@ -58,6 +65,11 @@ export interface ExecutionResult {
58
65
  enqueuedPublicFunctionCalls: PublicCallRequest[];
59
66
  /** Public function execution requested for teardown */
60
67
  publicTeardownFunctionCall: PublicCallRequest;
68
+ /**
69
+ * Encrypted note logs emitted during execution of this function call.
70
+ * Note: These are preimages to `noteEncryptedLogsHashes`.
71
+ */
72
+ noteEncryptedLogs: CountedNoteLog[];
61
73
  /**
62
74
  * Encrypted logs emitted during execution of this function call.
63
75
  * Note: These are preimages to `encryptedLogsHashes`.
@@ -82,13 +94,39 @@ export function collectNullifiedNoteHashCounters(execResult: ExecutionResult, ac
82
94
  return accum;
83
95
  }
84
96
 
97
+ /**
98
+ * Collect all encrypted logs across all nested executions.
99
+ * @param execResult - The topmost execution result.
100
+ * @returns All encrypted logs.
101
+ */
102
+ function collectNoteEncryptedLogs(
103
+ execResult: ExecutionResult,
104
+ nullifiedNoteHashCounters: Map<number, number>,
105
+ ): CountedLog<EncryptedL2NoteLog>[] {
106
+ return [
107
+ execResult.noteEncryptedLogs.filter(noteLog => !nullifiedNoteHashCounters.has(noteLog.noteHashCounter)),
108
+ ...execResult.nestedExecutions.flatMap(res => collectNoteEncryptedLogs(res, nullifiedNoteHashCounters)),
109
+ ].flat();
110
+ }
111
+
112
+ /**
113
+ * Collect all encrypted logs across all nested executions and sorts by counter.
114
+ * @param execResult - The topmost execution result.
115
+ * @returns All encrypted logs.
116
+ */
117
+ export function collectSortedNoteEncryptedLogs(execResult: ExecutionResult): EncryptedNoteFunctionL2Logs {
118
+ const nullifiedNoteHashCounters = collectNullifiedNoteHashCounters(execResult);
119
+ const allLogs = collectNoteEncryptedLogs(execResult, nullifiedNoteHashCounters);
120
+ const sortedLogs = sortByCounter(allLogs);
121
+ return new EncryptedNoteFunctionL2Logs(sortedLogs.map(l => l.log));
122
+ }
85
123
  /**
86
124
  * Collect all encrypted logs across all nested executions.
87
125
  * @param execResult - The topmost execution result.
88
126
  * @returns All encrypted logs.
89
127
  */
90
128
  function collectEncryptedLogs(execResult: ExecutionResult): CountedLog<EncryptedL2Log>[] {
91
- return [execResult.encryptedLogs, ...[...execResult.nestedExecutions].flatMap(collectEncryptedLogs)].flat();
129
+ return [execResult.encryptedLogs, ...execResult.nestedExecutions.flatMap(collectEncryptedLogs)].flat();
92
130
  }
93
131
 
94
132
  /**
@@ -108,7 +146,7 @@ export function collectSortedEncryptedLogs(execResult: ExecutionResult): Encrypt
108
146
  * @returns All unencrypted logs.
109
147
  */
110
148
  function collectUnencryptedLogs(execResult: ExecutionResult): CountedLog<UnencryptedL2Log>[] {
111
- return [execResult.unencryptedLogs, ...[...execResult.nestedExecutions].flatMap(collectUnencryptedLogs)].flat();
149
+ return [execResult.unencryptedLogs, ...execResult.nestedExecutions.flatMap(collectUnencryptedLogs)].flat();
112
150
  }
113
151
 
114
152
  /**
@@ -1,14 +1,15 @@
1
- import { type FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
2
- import { type FunctionArtifact } from '@aztec/foundation/abi';
1
+ import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
2
+ import { Fr, FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
3
+ import type { FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
3
4
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
4
5
  import { createDebugLogger } from '@aztec/foundation/log';
6
+ import { Timer } from '@aztec/foundation/timer';
5
7
 
6
8
  import { witnessMapToFields } from '../acvm/deserialize.js';
7
9
  import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
8
10
  import { ExecutionError } from '../common/errors.js';
9
11
  import { type ClientExecutionContext } from './client_execution_context.js';
10
12
  import { type ExecutionResult } from './execution_result.js';
11
- import { AcirSimulator } from './simulator.js';
12
13
 
13
14
  /**
14
15
  * Execute a private function and return the execution result.
@@ -17,35 +18,51 @@ export async function executePrivateFunction(
17
18
  context: ClientExecutionContext,
18
19
  artifact: FunctionArtifact,
19
20
  contractAddress: AztecAddress,
20
- functionData: FunctionData,
21
+ functionSelector: FunctionSelector,
21
22
  log = createDebugLogger('aztec:simulator:secret_execution'),
22
23
  ): Promise<ExecutionResult> {
23
- const functionSelector = functionData.selector;
24
- log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${artifact.name})`);
24
+ const functionName = await context.getDebugFunctionName();
25
+ log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${functionName})`);
25
26
  const acir = artifact.bytecode;
26
27
  const initialWitness = context.getInitialWitness(artifact);
27
28
  const acvmCallback = new Oracle(context);
28
- const acirExecutionResult = await acvm(await AcirSimulator.getSolver(), acir, initialWitness, acvmCallback).catch(
29
- (err: Error) => {
30
- throw new ExecutionError(
31
- err.message,
32
- {
33
- contractAddress,
34
- functionSelector,
35
- },
36
- extractCallStack(err, artifact.debug),
37
- { cause: err },
38
- );
39
- },
40
- );
29
+ const timer = new Timer();
30
+ const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
31
+ throw new ExecutionError(
32
+ err.message,
33
+ {
34
+ contractAddress,
35
+ functionSelector,
36
+ },
37
+ extractCallStack(err, artifact.debug),
38
+ { cause: err },
39
+ );
40
+ });
41
+ const duration = timer.ms();
41
42
  const partialWitness = acirExecutionResult.partialWitness;
42
43
  const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
43
44
  const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness);
44
45
 
46
+ // TODO (alexg) estimate this size
47
+ const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
48
+ log.debug(`Ran external function ${contractAddress.toString()}:${functionSelector}`, {
49
+ circuitName: 'app-circuit',
50
+ duration,
51
+ eventName: 'circuit-witness-generation',
52
+ inputSize: initialWitnessSize,
53
+ outputSize: publicInputs.toBuffer().length,
54
+ appCircuitName: functionName,
55
+ } satisfies CircuitWitnessGenerationStats);
56
+
57
+ const noteEncryptedLogs = context.getNoteEncryptedLogs();
45
58
  const encryptedLogs = context.getEncryptedLogs();
46
59
  const unencryptedLogs = context.getUnencryptedLogs();
47
60
 
48
- const callStackItem = new PrivateCallStackItem(contractAddress, functionData, publicInputs);
61
+ const callStackItem = new PrivateCallStackItem(
62
+ contractAddress,
63
+ new FunctionData(functionSelector, true),
64
+ publicInputs,
65
+ );
49
66
 
50
67
  const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
51
68
 
@@ -69,6 +86,7 @@ export async function executePrivateFunction(
69
86
  vk: Buffer.from(artifact.verificationKey!, 'hex'),
70
87
  nestedExecutions,
71
88
  enqueuedPublicFunctionCalls,
89
+ noteEncryptedLogs,
72
90
  publicTeardownFunctionCall,
73
91
  encryptedLogs,
74
92
  unencryptedLogs,
@@ -1,5 +1,5 @@
1
1
  import { type AztecNode, type FunctionCall, type Note, type TxExecutionRequest } from '@aztec/circuit-types';
2
- import { CallContext, FunctionData } from '@aztec/circuits.js';
2
+ import { CallContext } from '@aztec/circuits.js';
3
3
  import {
4
4
  type ArrayType,
5
5
  type FunctionArtifact,
@@ -11,15 +11,12 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
11
11
  import { Fr } from '@aztec/foundation/fields';
12
12
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
13
13
 
14
- import { type WasmBlackBoxFunctionSolver, createBlackBoxSolver } from '@noir-lang/acvm_js';
15
-
16
14
  import { createSimulationError } from '../common/errors.js';
17
15
  import { PackedValuesCache } from '../common/packed_values_cache.js';
18
16
  import { ClientExecutionContext } from './client_execution_context.js';
19
17
  import { type DBOracle } from './db_oracle.js';
20
18
  import { ExecutionNoteCache } from './execution_note_cache.js';
21
19
  import { type ExecutionResult } from './execution_result.js';
22
- import { LogsCache } from './logs_cache.js';
23
20
  import { executePrivateFunction } from './private_execution.js';
24
21
  import { executeUnconstrainedFunction } from './unconstrained_execution.js';
25
22
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -28,33 +25,12 @@ import { ViewDataOracle } from './view_data_oracle.js';
28
25
  * The ACIR simulator.
29
26
  */
30
27
  export class AcirSimulator {
31
- private static solver: Promise<WasmBlackBoxFunctionSolver>; // ACVM's backend
32
28
  private log: DebugLogger;
33
29
 
34
30
  constructor(private db: DBOracle, private node: AztecNode) {
35
31
  this.log = createDebugLogger('aztec:simulator');
36
32
  }
37
33
 
38
- /**
39
- * Gets or initializes the ACVM WasmBlackBoxFunctionSolver.
40
- *
41
- * @remarks
42
- *
43
- * Occurs only once across all instances of AcirSimulator.
44
- * Speeds up execution by only performing setup tasks (like pedersen
45
- * generator initialization) one time.
46
- * TODO(https://github.com/AztecProtocol/aztec-packages/issues/1627):
47
- * determine whether this requires a lock
48
- *
49
- * @returns ACVM WasmBlackBoxFunctionSolver
50
- */
51
- public static getSolver(): Promise<WasmBlackBoxFunctionSolver> {
52
- if (!this.solver) {
53
- this.solver = createBlackBoxSolver();
54
- }
55
- return this.solver;
56
- }
57
-
58
34
  /**
59
35
  * Runs a private function.
60
36
  * @param request - The transaction request.
@@ -69,8 +45,8 @@ export class AcirSimulator {
69
45
  contractAddress: AztecAddress,
70
46
  msgSender = AztecAddress.ZERO,
71
47
  ): Promise<ExecutionResult> {
72
- if (entryPointArtifact.functionType !== FunctionType.SECRET) {
73
- throw new Error(`Cannot run ${entryPointArtifact.functionType} function as secret`);
48
+ if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
49
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
74
50
  }
75
51
 
76
52
  if (request.origin !== contractAddress) {
@@ -89,7 +65,7 @@ export class AcirSimulator {
89
65
  contractAddress,
90
66
  FunctionSelector.fromNameAndParameters(entryPointArtifact.name, entryPointArtifact.parameters),
91
67
  false,
92
- false,
68
+ entryPointArtifact.isStatic,
93
69
  startSideEffectCounter,
94
70
  );
95
71
  const context = new ClientExecutionContext(
@@ -101,7 +77,6 @@ export class AcirSimulator {
101
77
  request.authWitnesses,
102
78
  PackedValuesCache.create(request.argsOfCalls),
103
79
  new ExecutionNoteCache(),
104
- new LogsCache(),
105
80
  this.db,
106
81
  this.node,
107
82
  startSideEffectCounter,
@@ -112,7 +87,7 @@ export class AcirSimulator {
112
87
  context,
113
88
  entryPointArtifact,
114
89
  contractAddress,
115
- request.functionData,
90
+ request.functionSelector,
116
91
  );
117
92
  return executionResult;
118
93
  } catch (err) {
@@ -143,7 +118,7 @@ export class AcirSimulator {
143
118
  context,
144
119
  entryPointArtifact,
145
120
  contractAddress,
146
- request.functionData,
121
+ request.selector,
147
122
  request.args,
148
123
  );
149
124
  } catch (err) {
@@ -195,9 +170,13 @@ export class AcirSimulator {
195
170
  const extendedNoteItems = note.items.concat(Array(maxNoteFields - note.items.length).fill(Fr.ZERO));
196
171
 
197
172
  const execRequest: FunctionCall = {
173
+ name: artifact.name,
198
174
  to: contractAddress,
199
- functionData: FunctionData.empty(),
175
+ selector: FunctionSelector.empty(),
176
+ type: FunctionType.UNCONSTRAINED,
177
+ isStatic: artifact.isStatic,
200
178
  args: encodeArguments(artifact, [contractAddress, nonce, storageSlot, noteTypeId, extendedNoteItems]),
179
+ returnTypes: artifact.returnTypes,
201
180
  };
202
181
 
203
182
  const [innerNoteHash, uniqueNoteHash, siloedNoteHash, innerNullifier] = (await this.runUnconstrained(