@aztec/simulator 0.62.0 → 0.63.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 (216) hide show
  1. package/dest/acvm/acvm.d.ts +2 -16
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +2 -70
  4. package/dest/acvm/oracle/oracle.d.ts +4 -4
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +10 -11
  7. package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +8 -8
  10. package/dest/avm/avm_gas.d.ts.map +1 -1
  11. package/dest/avm/avm_gas.js +2 -1
  12. package/dest/avm/avm_machine_state.d.ts +27 -8
  13. package/dest/avm/avm_machine_state.d.ts.map +1 -1
  14. package/dest/avm/avm_machine_state.js +6 -10
  15. package/dest/avm/avm_memory_types.d.ts +8 -0
  16. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  17. package/dest/avm/avm_memory_types.js +5 -1
  18. package/dest/avm/avm_simulator.d.ts +2 -19
  19. package/dest/avm/avm_simulator.d.ts.map +1 -1
  20. package/dest/avm/avm_simulator.js +12 -14
  21. package/dest/avm/avm_tree.d.ts +249 -0
  22. package/dest/avm/avm_tree.d.ts.map +1 -0
  23. package/dest/avm/avm_tree.js +637 -0
  24. package/dest/avm/errors.d.ts +4 -17
  25. package/dest/avm/errors.d.ts.map +1 -1
  26. package/dest/avm/errors.js +21 -50
  27. package/dest/avm/fixtures/index.d.ts +7 -2
  28. package/dest/avm/fixtures/index.d.ts.map +1 -1
  29. package/dest/avm/fixtures/index.js +12 -12
  30. package/dest/avm/index.d.ts +1 -0
  31. package/dest/avm/index.d.ts.map +1 -1
  32. package/dest/avm/index.js +2 -1
  33. package/dest/avm/journal/journal.d.ts +43 -24
  34. package/dest/avm/journal/journal.d.ts.map +1 -1
  35. package/dest/avm/journal/journal.js +172 -39
  36. package/dest/avm/journal/nullifiers.d.ts +5 -4
  37. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  38. package/dest/avm/journal/nullifiers.js +2 -3
  39. package/dest/avm/journal/public_storage.d.ts +6 -5
  40. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  41. package/dest/avm/journal/public_storage.js +1 -1
  42. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  43. package/dest/avm/opcodes/accrued_substate.js +4 -10
  44. package/dest/avm/opcodes/arithmetic.d.ts +4 -1
  45. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  46. package/dest/avm/opcodes/arithmetic.js +18 -4
  47. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  48. package/dest/avm/opcodes/bitwise.js +1 -3
  49. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  50. package/dest/avm/opcodes/comparators.js +1 -2
  51. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  52. package/dest/avm/opcodes/contract.js +2 -3
  53. package/dest/avm/opcodes/control_flow.d.ts +4 -0
  54. package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
  55. package/dest/avm/opcodes/control_flow.js +21 -6
  56. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  57. package/dest/avm/opcodes/conversion.js +1 -2
  58. package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
  59. package/dest/avm/opcodes/ec_add.js +5 -11
  60. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  61. package/dest/avm/opcodes/environment_getters.js +1 -2
  62. package/dest/avm/opcodes/external_calls.d.ts +4 -2
  63. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  64. package/dest/avm/opcodes/external_calls.js +38 -22
  65. package/dest/avm/opcodes/hashing.d.ts.map +1 -1
  66. package/dest/avm/opcodes/hashing.js +1 -4
  67. package/dest/avm/opcodes/instruction.d.ts +4 -0
  68. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  69. package/dest/avm/opcodes/instruction.js +7 -1
  70. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  71. package/dest/avm/opcodes/memory.js +1 -7
  72. package/dest/avm/opcodes/misc.js +3 -3
  73. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  74. package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
  75. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  76. package/dest/avm/opcodes/storage.js +2 -4
  77. package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
  78. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  79. package/dest/avm/serialization/bytecode_serialization.js +24 -20
  80. package/dest/client/client_execution_context.d.ts +7 -11
  81. package/dest/client/client_execution_context.d.ts.map +1 -1
  82. package/dest/client/client_execution_context.js +18 -20
  83. package/dest/client/db_oracle.d.ts +17 -10
  84. package/dest/client/db_oracle.d.ts.map +1 -1
  85. package/dest/client/db_oracle.js +1 -1
  86. package/dest/client/private_execution.d.ts.map +1 -1
  87. package/dest/client/private_execution.js +5 -4
  88. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  89. package/dest/client/unconstrained_execution.js +3 -2
  90. package/dest/client/view_data_oracle.d.ts +6 -12
  91. package/dest/client/view_data_oracle.d.ts.map +1 -1
  92. package/dest/client/view_data_oracle.js +10 -12
  93. package/dest/common/errors.d.ts +15 -2
  94. package/dest/common/errors.d.ts.map +1 -1
  95. package/dest/common/errors.js +85 -4
  96. package/dest/mocks/fixtures.d.ts +9 -28
  97. package/dest/mocks/fixtures.d.ts.map +1 -1
  98. package/dest/mocks/fixtures.js +12 -57
  99. package/dest/public/dual_side_effect_trace.d.ts +34 -26
  100. package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
  101. package/dest/public/dual_side_effect_trace.js +48 -36
  102. package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
  103. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  104. package/dest/public/enqueued_call_side_effect_trace.js +212 -138
  105. package/dest/public/execution.d.ts +50 -17
  106. package/dest/public/execution.d.ts.map +1 -1
  107. package/dest/public/execution.js +1 -29
  108. package/dest/public/executor.d.ts +28 -11
  109. package/dest/public/executor.d.ts.map +1 -1
  110. package/dest/public/executor.js +33 -33
  111. package/dest/public/index.d.ts +4 -5
  112. package/dest/public/index.d.ts.map +1 -1
  113. package/dest/public/index.js +4 -5
  114. package/dest/public/public_db_sources.d.ts +1 -0
  115. package/dest/public/public_db_sources.d.ts.map +1 -1
  116. package/dest/public/public_db_sources.js +12 -5
  117. package/dest/public/public_processor.d.ts +7 -11
  118. package/dest/public/public_processor.d.ts.map +1 -1
  119. package/dest/public/public_processor.js +60 -42
  120. package/dest/public/public_processor_metrics.d.ts +3 -3
  121. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  122. package/dest/public/public_processor_metrics.js +1 -1
  123. package/dest/public/public_tx_context.d.ts +130 -0
  124. package/dest/public/public_tx_context.d.ts.map +1 -0
  125. package/dest/public/public_tx_context.js +293 -0
  126. package/dest/public/public_tx_simulator.d.ts +36 -0
  127. package/dest/public/public_tx_simulator.d.ts.map +1 -0
  128. package/dest/public/public_tx_simulator.js +148 -0
  129. package/dest/public/side_effect_trace.d.ts +30 -15
  130. package/dest/public/side_effect_trace.d.ts.map +1 -1
  131. package/dest/public/side_effect_trace.js +70 -16
  132. package/dest/public/side_effect_trace_interface.d.ts +43 -12
  133. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  134. package/dest/public/transitional_adapters.d.ts +9 -0
  135. package/dest/public/transitional_adapters.d.ts.map +1 -0
  136. package/dest/public/transitional_adapters.js +127 -0
  137. package/dest/public/utils.d.ts +5 -0
  138. package/dest/public/utils.d.ts.map +1 -0
  139. package/dest/public/utils.js +30 -0
  140. package/package.json +12 -9
  141. package/src/acvm/acvm.ts +3 -94
  142. package/src/acvm/oracle/oracle.ts +9 -14
  143. package/src/acvm/oracle/typed_oracle.ts +8 -8
  144. package/src/avm/avm_gas.ts +1 -0
  145. package/src/avm/avm_machine_state.ts +28 -12
  146. package/src/avm/avm_memory_types.ts +5 -0
  147. package/src/avm/avm_simulator.ts +13 -16
  148. package/src/avm/avm_tree.ts +785 -0
  149. package/src/avm/errors.ts +25 -48
  150. package/src/avm/fixtures/index.ts +16 -12
  151. package/src/avm/index.ts +1 -0
  152. package/src/avm/journal/journal.ts +291 -52
  153. package/src/avm/journal/nullifiers.ts +7 -7
  154. package/src/avm/journal/public_storage.ts +5 -5
  155. package/src/avm/opcodes/accrued_substate.ts +3 -9
  156. package/src/avm/opcodes/arithmetic.ts +26 -4
  157. package/src/avm/opcodes/bitwise.ts +0 -2
  158. package/src/avm/opcodes/comparators.ts +0 -1
  159. package/src/avm/opcodes/contract.ts +1 -2
  160. package/src/avm/opcodes/control_flow.ts +24 -5
  161. package/src/avm/opcodes/conversion.ts +0 -1
  162. package/src/avm/opcodes/ec_add.ts +6 -9
  163. package/src/avm/opcodes/environment_getters.ts +0 -1
  164. package/src/avm/opcodes/external_calls.ts +39 -21
  165. package/src/avm/opcodes/hashing.ts +0 -3
  166. package/src/avm/opcodes/instruction.ts +7 -0
  167. package/src/avm/opcodes/memory.ts +0 -6
  168. package/src/avm/opcodes/misc.ts +2 -2
  169. package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
  170. package/src/avm/opcodes/storage.ts +1 -3
  171. package/src/avm/serialization/bytecode_serialization.ts +31 -22
  172. package/src/client/client_execution_context.ts +22 -23
  173. package/src/client/db_oracle.ts +22 -11
  174. package/src/client/private_execution.ts +5 -4
  175. package/src/client/unconstrained_execution.ts +2 -1
  176. package/src/client/view_data_oracle.ts +14 -13
  177. package/src/common/errors.ts +119 -3
  178. package/src/mocks/fixtures.ts +15 -106
  179. package/src/public/dual_side_effect_trace.ts +138 -50
  180. package/src/public/enqueued_call_side_effect_trace.ts +352 -212
  181. package/src/public/execution.ts +58 -42
  182. package/src/public/executor.ts +52 -67
  183. package/src/public/index.ts +7 -5
  184. package/src/public/public_db_sources.ts +12 -4
  185. package/src/public/public_processor.ts +111 -73
  186. package/src/public/public_processor_metrics.ts +3 -3
  187. package/src/public/public_tx_context.ts +411 -0
  188. package/src/public/public_tx_simulator.ts +232 -0
  189. package/src/public/side_effect_trace.ts +154 -28
  190. package/src/public/side_effect_trace_interface.ts +92 -14
  191. package/src/public/transitional_adapters.ts +347 -0
  192. package/src/public/utils.ts +32 -0
  193. package/dest/public/enqueued_call_simulator.d.ts +0 -43
  194. package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
  195. package/dest/public/enqueued_call_simulator.js +0 -156
  196. package/dest/public/enqueued_calls_processor.d.ts +0 -43
  197. package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
  198. package/dest/public/enqueued_calls_processor.js +0 -209
  199. package/dest/public/hints_builder.d.ts +0 -29
  200. package/dest/public/hints_builder.d.ts.map +0 -1
  201. package/dest/public/hints_builder.js +0 -75
  202. package/dest/public/public_kernel.d.ts +0 -30
  203. package/dest/public/public_kernel.d.ts.map +0 -1
  204. package/dest/public/public_kernel.js +0 -67
  205. package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
  206. package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
  207. package/dest/public/public_kernel_circuit_simulator.js +0 -2
  208. package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
  209. package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
  210. package/dest/public/public_kernel_tail_simulator.js +0 -39
  211. package/src/public/enqueued_call_simulator.ts +0 -360
  212. package/src/public/enqueued_calls_processor.ts +0 -372
  213. package/src/public/hints_builder.ts +0 -168
  214. package/src/public/public_kernel.ts +0 -100
  215. package/src/public/public_kernel_circuit_simulator.ts +0 -32
  216. package/src/public/public_kernel_tail_simulator.ts +0 -97
@@ -24,7 +24,7 @@ import {
24
24
  } from '@aztec/circuits.js';
25
25
  import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
26
26
  import { type FunctionAbi, type FunctionArtifact, type NoteSelector, countArgumentsSize } from '@aztec/foundation/abi';
27
- import { type AztecAddress } from '@aztec/foundation/aztec-address';
27
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
28
28
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
29
29
  import { Fr } from '@aztec/foundation/fields';
30
30
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
@@ -62,7 +62,7 @@ export class ClientExecutionContext extends ViewDataOracle {
62
62
  private noteHashNullifierCounterMap: Map<number, number> = new Map();
63
63
  private noteEncryptedLogs: CountedNoteLog[] = [];
64
64
  private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
65
- private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
65
+ private contractClassLogs: CountedLog<UnencryptedL2Log>[] = [];
66
66
  private nestedExecutions: PrivateExecutionResult[] = [];
67
67
  private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
68
68
  private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
@@ -151,10 +151,10 @@ export class ClientExecutionContext extends ViewDataOracle {
151
151
  }
152
152
 
153
153
  /**
154
- * Return the encrypted logs emitted during this execution.
154
+ * Return the contract class logs emitted during this execution.
155
155
  */
156
- public getUnencryptedLogs() {
157
- return this.unencryptedLogs;
156
+ public getContractClassLogs() {
157
+ return this.contractClassLogs;
158
158
  }
159
159
 
160
160
  /**
@@ -360,16 +360,6 @@ export class ClientExecutionContext extends ViewDataOracle {
360
360
  this.noteEncryptedLogs.push(encryptedLog);
361
361
  }
362
362
 
363
- /**
364
- * Emit an unencrypted log.
365
- * @param log - The unencrypted log to be emitted.
366
- */
367
- public override emitUnencryptedLog(log: UnencryptedL2Log, counter: number) {
368
- this.unencryptedLogs.push(new CountedLog(log, counter));
369
- const text = log.toHumanReadable();
370
- this.log.verbose(`Emitted unencrypted log: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`);
371
- }
372
-
373
363
  /**
374
364
  * Emit a contract class unencrypted log.
375
365
  * This fn exists separately from emitUnencryptedLog because sha hashing the preimage
@@ -377,13 +367,11 @@ export class ClientExecutionContext extends ViewDataOracle {
377
367
  * See private_context.nr
378
368
  * @param log - The unencrypted log to be emitted.
379
369
  */
380
- public override emitContractClassUnencryptedLog(log: UnencryptedL2Log, counter: number) {
381
- this.unencryptedLogs.push(new CountedLog(log, counter));
370
+ public override emitContractClassLog(log: UnencryptedL2Log, counter: number) {
371
+ this.contractClassLogs.push(new CountedLog(log, counter));
382
372
  const text = log.toHumanReadable();
383
373
  this.log.verbose(
384
- `Emitted unencrypted log from ContractClassRegisterer: "${
385
- text.length > 100 ? text.slice(0, 100) + '...' : text
386
- }"`,
374
+ `Emitted log from ContractClassRegisterer: "${text.length > 100 ? text.slice(0, 100) + '...' : text}"`,
387
375
  );
388
376
  return Fr.fromBuffer(log.hash());
389
377
  }
@@ -394,7 +382,7 @@ export class ClientExecutionContext extends ViewDataOracle {
394
382
  childExecutionResult.publicInputs.nullifiers.some(item => !item.isEmpty()) ||
395
383
  childExecutionResult.publicInputs.l2ToL1Msgs.some(item => !item.isEmpty()) ||
396
384
  childExecutionResult.publicInputs.encryptedLogsHashes.some(item => !item.isEmpty()) ||
397
- childExecutionResult.publicInputs.unencryptedLogsHashes.some(item => !item.isEmpty())
385
+ childExecutionResult.publicInputs.contractClassLogsHashes.some(item => !item.isEmpty())
398
386
  ) {
399
387
  throw new Error(`Static call cannot update the state, emit L2->L1 messages or generate logs`);
400
388
  }
@@ -610,7 +598,18 @@ export class ClientExecutionContext extends ViewDataOracle {
610
598
  return this.db.getDebugFunctionName(this.contractAddress, this.callContext.functionSelector);
611
599
  }
612
600
 
613
- public override async incrementAppTaggingSecret(sender: AztecAddress, recipient: AztecAddress) {
614
- await this.db.incrementAppTaggingSecret(this.contractAddress, sender, recipient);
601
+ public override async incrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress) {
602
+ await this.db.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
603
+ }
604
+
605
+ public override async syncNotes() {
606
+ const taggedLogsByRecipient = await this.db.syncTaggedLogs(
607
+ this.contractAddress,
608
+ this.historicalHeader.globalVariables.blockNumber.toNumber(),
609
+ this.scopes,
610
+ );
611
+ for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
612
+ await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
613
+ }
615
614
  }
616
615
  }
@@ -1,9 +1,11 @@
1
1
  import {
2
2
  type L2Block,
3
+ type L2BlockNumber,
3
4
  type MerkleTreeId,
4
5
  type NoteStatus,
5
6
  type NullifierMembershipWitness,
6
7
  type PublicDataWitness,
8
+ type TxScopedL2Log,
7
9
  } from '@aztec/circuit-types';
8
10
  import {
9
11
  type CompleteAddress,
@@ -145,7 +147,7 @@ export interface DBOracle extends CommitmentsDB {
145
147
  * @param leafValue - The leaf value buffer.
146
148
  * @returns - The index of the leaf. Undefined if it does not exist in the tree.
147
149
  */
148
- findLeafIndex(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;
150
+ findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined>;
149
151
 
150
152
  /**
151
153
  * Fetch the sibling path of the leaf in the respective tree
@@ -197,13 +199,13 @@ export interface DBOracle extends CommitmentsDB {
197
199
 
198
200
  /**
199
201
  * 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.
202
+ * Includes the next index to be used used for tagging with this secret.
201
203
  * @param contractAddress - The contract address to silo the secret for
202
204
  * @param sender - The address sending the note
203
205
  * @param recipient - The address receiving the note
204
206
  * @returns A tagging secret that can be used to tag notes.
205
207
  */
206
- getAppTaggingSecret(
208
+ getAppTaggingSecretAsSender(
207
209
  contractAddress: AztecAddress,
208
210
  sender: AztecAddress,
209
211
  recipient: AztecAddress,
@@ -215,20 +217,29 @@ export interface DBOracle extends CommitmentsDB {
215
217
  * @param sender - The address sending the note
216
218
  * @param recipient - The address receiving the note
217
219
  */
218
- incrementAppTaggingSecret(
220
+ incrementAppTaggingSecretIndexAsSender(
219
221
  contractAddress: AztecAddress,
220
222
  sender: AztecAddress,
221
223
  recipient: AztecAddress,
222
224
  ): Promise<void>;
223
225
 
224
226
  /**
225
- * Returns the siloed tagging secrets for a given recipient and all the senders in the address book
226
- * @param contractAddress - The contract address to silo the secret for
227
- * @param recipient - The address receiving the notes
228
- * @returns A list of siloed tagging secrets
227
+ * Synchronizes the logs tagged with the recipient's address and all the senders in the addressbook.
228
+ * Returns the unsynched logs and updates the indexes of the secrets used to tag them until there are no more logs to sync.
229
+ * @param contractAddress - The address of the contract that the logs are tagged for
230
+ * @param recipient - The address of the recipient
231
+ * @returns A list of encrypted logs tagged with the recipient's address
229
232
  */
230
- getAppTaggingSecretsForSenders(
233
+ syncTaggedLogs(
231
234
  contractAddress: AztecAddress,
232
- recipient: AztecAddress,
233
- ): Promise<IndexedTaggingSecret[]>;
235
+ maxBlockNumber: number,
236
+ scopes?: AztecAddress[],
237
+ ): Promise<Map<string, TxScopedL2Log[]>>;
238
+
239
+ /**
240
+ * Processes the tagged logs returned by syncTaggedLogs by decrypting them and storing them in the database.
241
+ * @param logs - The logs to process.
242
+ * @param recipient - The recipient of the logs.
243
+ */
244
+ processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise<void>;
234
245
  }
@@ -13,7 +13,7 @@ import { Timer } from '@aztec/foundation/timer';
13
13
 
14
14
  import { fromACVMField, witnessMapToFields } from '../acvm/deserialize.js';
15
15
  import { type ACVMWitness, Oracle, acvm, extractCallStack } from '../acvm/index.js';
16
- import { ExecutionError } from '../common/errors.js';
16
+ import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
17
17
  import { type ClientExecutionContext } from './client_execution_context.js';
18
18
 
19
19
  /**
@@ -33,6 +33,7 @@ export async function executePrivateFunction(
33
33
  const acvmCallback = new Oracle(context);
34
34
  const timer = new Timer();
35
35
  const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
36
+ err.message = resolveAssertionMessageFromError(err, artifact);
36
37
  throw new ExecutionError(
37
38
  err.message,
38
39
  {
@@ -60,7 +61,7 @@ export async function executePrivateFunction(
60
61
 
61
62
  const noteEncryptedLogs = context.getNoteEncryptedLogs();
62
63
  const encryptedLogs = context.getEncryptedLogs();
63
- const unencryptedLogs = context.getUnencryptedLogs();
64
+ const contractClassLogs = context.getContractClassLogs();
64
65
 
65
66
  const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
66
67
 
@@ -75,7 +76,7 @@ export async function executePrivateFunction(
75
76
 
76
77
  return new PrivateExecutionResult(
77
78
  acir,
78
- Buffer.from(artifact.verificationKey!, 'hex'),
79
+ Buffer.from(artifact.verificationKey!, 'base64'),
79
80
  partialWitness,
80
81
  publicInputs,
81
82
  noteHashLeafIndexMap,
@@ -87,7 +88,7 @@ export async function executePrivateFunction(
87
88
  publicTeardownFunctionCall,
88
89
  noteEncryptedLogs,
89
90
  encryptedLogs,
90
- unencryptedLogs,
91
+ contractClassLogs,
91
92
  );
92
93
  }
93
94
 
@@ -5,7 +5,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
5
5
 
6
6
  import { witnessMapToFields } from '../acvm/deserialize.js';
7
7
  import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
8
- import { ExecutionError } from '../common/errors.js';
8
+ import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
9
9
  import { type ViewDataOracle } from './view_data_oracle.js';
10
10
 
11
11
  // docs:start:execute_unconstrained_function
@@ -25,6 +25,7 @@ export async function executeUnconstrainedFunction(
25
25
  const acir = artifact.bytecode;
26
26
  const initialWitness = toACVMWitness(0, args);
27
27
  const acirExecutionResult = await acvm(acir, initialWitness, new Oracle(oracle)).catch((err: Error) => {
28
+ err.message = resolveAssertionMessageFromError(err, artifact);
28
29
  throw new ExecutionError(
29
30
  err.message,
30
31
  {
@@ -14,7 +14,7 @@ import {
14
14
  type KeyValidationRequest,
15
15
  } from '@aztec/circuits.js';
16
16
  import { siloNullifier } from '@aztec/circuits.js/hash';
17
- import { type AztecAddress } from '@aztec/foundation/aztec-address';
17
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
18
18
  import { Fr } from '@aztec/foundation/fields';
19
19
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
20
20
 
@@ -271,7 +271,7 @@ export class ViewDataOracle extends TypedOracle {
271
271
  * @param numberOfElements - Number of elements to read from the starting storage slot.
272
272
  */
273
273
  public override async storageRead(
274
- contractAddress: Fr,
274
+ contractAddress: AztecAddress,
275
275
  startStorageSlot: Fr,
276
276
  blockNumber: number,
277
277
  numberOfElements: number,
@@ -296,26 +296,27 @@ export class ViewDataOracle extends TypedOracle {
296
296
 
297
297
  /**
298
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.
299
+ * Includes the next index to be used used for tagging with this secret.
300
300
  * For this to work, the ivpsk_m of the sender must be known.
301
301
  * @param sender - The address sending the note
302
302
  * @param recipient - The address receiving the note
303
303
  * @returns A tagging secret that can be used to tag notes.
304
304
  */
305
- public override async getAppTaggingSecret(
305
+ public override async getAppTaggingSecretAsSender(
306
306
  sender: AztecAddress,
307
307
  recipient: AztecAddress,
308
308
  ): Promise<IndexedTaggingSecret> {
309
- return await this.db.getAppTaggingSecret(this.contractAddress, sender, recipient);
309
+ return await this.db.getAppTaggingSecretAsSender(this.contractAddress, sender, recipient);
310
310
  }
311
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);
312
+ public override async syncNotes() {
313
+ const taggedLogsByRecipient = await this.db.syncTaggedLogs(
314
+ this.contractAddress,
315
+ await this.aztecNode.getBlockNumber(),
316
+ this.scopes,
317
+ );
318
+ for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
319
+ await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
320
+ }
320
321
  }
321
322
  }
@@ -1,4 +1,14 @@
1
- import { type FailingFunction, type NoirCallStack, SimulationError } from '@aztec/circuit-types';
1
+ import {
2
+ type FailingFunction,
3
+ type NoirCallStack,
4
+ SimulationError,
5
+ type SourceCodeLocation,
6
+ } from '@aztec/circuit-types';
7
+ import { type Fr } from '@aztec/circuits.js';
8
+ import type { BrilligFunctionId, FunctionAbi, FunctionDebugMetadata, OpcodeLocation } from '@aztec/foundation/abi';
9
+
10
+ import { type RawAssertionPayload } from '@noir-lang/acvm_js';
11
+ import { abiDecodeError } from '@noir-lang/noirc_abi';
2
12
 
3
13
  /**
4
14
  * An error that occurred during the execution of a function.
@@ -47,7 +57,7 @@ export function traverseCauseChain(error: Error, callback: (error: Error) => voi
47
57
  * @param error - The error thrown during execution.
48
58
  * @returns - A simulation error.
49
59
  */
50
- export function createSimulationError(error: Error): SimulationError {
60
+ export function createSimulationError(error: Error, revertData?: Fr[]): SimulationError {
51
61
  let rootCause = error;
52
62
  let noirCallStack: NoirCallStack | undefined = undefined;
53
63
  const aztecCallStack: FailingFunction[] = [];
@@ -62,5 +72,111 @@ export function createSimulationError(error: Error): SimulationError {
62
72
  }
63
73
  });
64
74
 
65
- return new SimulationError(rootCause.message, aztecCallStack, noirCallStack, { cause: rootCause });
75
+ return new SimulationError(rootCause.message, aztecCallStack, revertData, noirCallStack, { cause: rootCause });
76
+ }
77
+
78
+ /**
79
+ * Extracts a brillig location from an opcode location.
80
+ * @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
81
+ * @returns The brillig location if the opcode location contains one.
82
+ */
83
+ function extractBrilligLocation(opcodeLocation: string): string | undefined {
84
+ const splitted = opcodeLocation.split('.');
85
+ if (splitted.length === 2) {
86
+ return splitted[1];
87
+ }
88
+ return undefined;
89
+ }
90
+
91
+ /**
92
+ * Extracts the call stack from the location of a failing opcode and the debug metadata.
93
+ * One opcode can point to multiple calls due to inlining.
94
+ */
95
+ function getSourceCodeLocationsFromOpcodeLocation(
96
+ opcodeLocation: string,
97
+ debug: FunctionDebugMetadata,
98
+ brilligFunctionId?: BrilligFunctionId,
99
+ ): SourceCodeLocation[] {
100
+ const { debugSymbols, files } = debug;
101
+
102
+ let callStack = debugSymbols.locations[opcodeLocation] || [];
103
+ if (callStack.length === 0) {
104
+ const brilligLocation = extractBrilligLocation(opcodeLocation);
105
+ if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
106
+ callStack = debugSymbols.brillig_locations[brilligFunctionId][brilligLocation] || [];
107
+ }
108
+ }
109
+ return callStack.map(call => {
110
+ const { file: fileId, span } = call;
111
+
112
+ const { path, source } = files[fileId];
113
+
114
+ const locationText = source.substring(span.start, span.end);
115
+ const precedingText = source.substring(0, span.start);
116
+ const previousLines = precedingText.split('\n');
117
+ // Lines and columns in stacks are one indexed.
118
+ const line = previousLines.length;
119
+ const column = previousLines[previousLines.length - 1].length + 1;
120
+
121
+ return {
122
+ filePath: path,
123
+ line,
124
+ column,
125
+ fileSource: source,
126
+ locationText,
127
+ };
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Extracts the source code locations for an array of opcode locations
133
+ * @param opcodeLocations - The opcode locations that caused the error.
134
+ * @param debug - The debug metadata of the function.
135
+ * @returns The source code locations.
136
+ */
137
+ export function resolveOpcodeLocations(
138
+ opcodeLocations: OpcodeLocation[],
139
+ debug: FunctionDebugMetadata,
140
+ brilligFunctionId?: BrilligFunctionId,
141
+ ): SourceCodeLocation[] {
142
+ return opcodeLocations.flatMap(opcodeLocation =>
143
+ getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, brilligFunctionId),
144
+ );
145
+ }
146
+
147
+ export function resolveAssertionMessage(errorPayload: RawAssertionPayload, abi: FunctionAbi): string | undefined {
148
+ const decoded = abiDecodeError(
149
+ { parameters: [], error_types: abi.errorTypes, return_type: null }, // eslint-disable-line camelcase
150
+ errorPayload,
151
+ );
152
+
153
+ if (typeof decoded === 'string') {
154
+ return decoded;
155
+ } else {
156
+ return JSON.stringify(decoded);
157
+ }
158
+ }
159
+
160
+ export function resolveAssertionMessageFromRevertData(revertData: Fr[], abi: FunctionAbi): string | undefined {
161
+ if (revertData.length == 0) {
162
+ return undefined;
163
+ }
164
+
165
+ const [errorSelector, ...errorData] = revertData;
166
+
167
+ return resolveAssertionMessage(
168
+ {
169
+ selector: errorSelector.toBigInt().toString(),
170
+ data: errorData.map(f => f.toString()),
171
+ },
172
+ abi,
173
+ );
174
+ }
175
+
176
+ export function resolveAssertionMessageFromError(err: Error, abi: FunctionAbi): string {
177
+ if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err && err.rawAssertionPayload) {
178
+ return `Assertion failed: ${resolveAssertionMessage(err.rawAssertionPayload as RawAssertionPayload, abi)}`;
179
+ } else {
180
+ return err.message;
181
+ }
66
182
  }
@@ -1,90 +1,35 @@
1
- import {
2
- type FunctionCall,
3
- PublicExecutionRequest,
4
- type SimulationError,
5
- UnencryptedFunctionL2Logs,
6
- } from '@aztec/circuit-types';
7
- import {
8
- ARGS_LENGTH,
9
- AvmExecutionHints,
10
- type AztecAddress,
11
- CallContext,
12
- type ContractStorageRead,
13
- type ContractStorageUpdateRequest,
14
- Fr,
15
- Gas,
16
- } from '@aztec/circuits.js';
1
+ import { SimulationError } from '@aztec/circuit-types';
2
+ import { ARGS_LENGTH, Fr, Gas } from '@aztec/circuits.js';
17
3
  import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
18
4
  import { FunctionType } from '@aztec/foundation/abi';
19
5
  import { padArrayEnd } from '@aztec/foundation/collection';
20
6
 
21
- import { type PublicExecutionResult, resultToPublicCallRequest } from '../public/execution.js';
7
+ import { type EnqueuedPublicCallExecutionResult } from '../public/execution.js';
22
8
 
23
9
  export class PublicExecutionResultBuilder {
24
- private _executionRequest: PublicExecutionRequest;
25
- private _nestedExecutions: PublicExecutionResult[] = [];
26
- private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
27
- private _contractStorageReads: ContractStorageRead[] = [];
28
10
  private _returnValues: Fr[] = [];
29
11
  private _reverted = false;
30
12
  private _revertReason: SimulationError | undefined = undefined;
31
13
 
32
- constructor(executionRequest: PublicExecutionRequest) {
33
- this._executionRequest = executionRequest;
34
- }
35
-
36
- static fromPublicExecutionRequest({
37
- request,
38
- returnValues = [new Fr(1n)],
39
- nestedExecutions = [],
40
- contractStorageUpdateRequests = [],
41
- contractStorageReads = [],
42
- revertReason = undefined,
43
- }: {
44
- request: PublicExecutionRequest;
45
- returnValues?: Fr[];
46
- nestedExecutions?: PublicExecutionResult[];
47
- contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
48
- contractStorageReads?: ContractStorageRead[];
49
- revertReason?: SimulationError;
50
- }): PublicExecutionResultBuilder {
51
- const builder = new PublicExecutionResultBuilder(request);
14
+ constructor() {}
52
15
 
53
- builder.withNestedExecutions(...nestedExecutions);
54
- builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
55
- builder.withContractStorageRead(...contractStorageReads);
56
- builder.withReturnValues(...returnValues);
57
- if (revertReason) {
58
- builder.withReverted(revertReason);
16
+ static empty(basicRevert = false) {
17
+ const builder = new PublicExecutionResultBuilder();
18
+ if (basicRevert) {
19
+ builder.withReverted(new SimulationError('Simulation failed', []));
59
20
  }
60
-
61
21
  return builder;
62
22
  }
63
23
 
64
- static fromFunctionCall({
65
- from,
66
- tx,
24
+ static fromPublicExecutionRequest({
67
25
  returnValues = [new Fr(1n)],
68
- nestedExecutions = [],
69
- contractStorageUpdateRequests = [],
70
- contractStorageReads = [],
71
- revertReason,
26
+ revertReason = undefined,
72
27
  }: {
73
- from: AztecAddress;
74
- tx: FunctionCall;
75
28
  returnValues?: Fr[];
76
- nestedExecutions?: PublicExecutionResult[];
77
- contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
78
- contractStorageReads?: ContractStorageRead[];
79
29
  revertReason?: SimulationError;
80
- }) {
81
- const builder = new PublicExecutionResultBuilder(
82
- new PublicExecutionRequest(new CallContext(from, tx.to, tx.selector, false), tx.args),
83
- );
30
+ }): PublicExecutionResultBuilder {
31
+ const builder = new PublicExecutionResultBuilder();
84
32
 
85
- builder.withNestedExecutions(...nestedExecutions);
86
- builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
87
- builder.withContractStorageRead(...contractStorageReads);
88
33
  builder.withReturnValues(...returnValues);
89
34
  if (revertReason) {
90
35
  builder.withReverted(revertReason);
@@ -93,21 +38,6 @@ export class PublicExecutionResultBuilder {
93
38
  return builder;
94
39
  }
95
40
 
96
- withNestedExecutions(...nested: PublicExecutionResult[]): PublicExecutionResultBuilder {
97
- this._nestedExecutions.push(...nested);
98
- return this;
99
- }
100
-
101
- withContractStorageUpdateRequest(...request: ContractStorageUpdateRequest[]): PublicExecutionResultBuilder {
102
- this._contractStorageUpdateRequests.push(...request);
103
- return this;
104
- }
105
-
106
- withContractStorageRead(...reads: ContractStorageRead[]): PublicExecutionResultBuilder {
107
- this._contractStorageReads.push(...reads);
108
- return this;
109
- }
110
-
111
41
  withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
112
42
  this._returnValues.push(...values);
113
43
  return this;
@@ -119,34 +49,13 @@ export class PublicExecutionResultBuilder {
119
49
  return this;
120
50
  }
121
51
 
122
- build(overrides: Partial<PublicExecutionResult> = {}): PublicExecutionResult {
52
+ build(overrides: Partial<EnqueuedPublicCallExecutionResult> = {}): EnqueuedPublicCallExecutionResult {
123
53
  return {
124
- executionRequest: this._executionRequest,
125
- nestedExecutions: this._nestedExecutions,
126
- publicCallRequests: this._nestedExecutions.map(resultToPublicCallRequest),
127
- noteHashReadRequests: [],
128
- nullifierReadRequests: [],
129
- nullifierNonExistentReadRequests: [],
130
- l1ToL2MsgReadRequests: [],
131
- contractStorageUpdateRequests: this._contractStorageUpdateRequests,
132
- returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
133
- noteHashes: [],
134
- nullifiers: [],
135
- l2ToL1Messages: [],
136
- contractStorageReads: [],
137
- unencryptedLogsHashes: [],
138
- unencryptedLogs: UnencryptedFunctionL2Logs.empty(),
139
- allUnencryptedLogs: UnencryptedFunctionL2Logs.empty(),
140
- startSideEffectCounter: Fr.ZERO,
54
+ endGasLeft: Gas.empty(),
141
55
  endSideEffectCounter: Fr.ZERO,
56
+ returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
142
57
  reverted: this._reverted,
143
58
  revertReason: this._revertReason,
144
- startGasLeft: Gas.test(),
145
- endGasLeft: Gas.test(),
146
- transactionFee: Fr.ZERO,
147
- calldata: [],
148
- avmCircuitHints: AvmExecutionHints.empty(),
149
- functionName: 'unknown',
150
59
  ...overrides,
151
60
  };
152
61
  }