@aztec/pxe 0.87.4 → 0.87.6

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 (99) hide show
  1. package/dest/config/package_info.js +1 -1
  2. package/dest/contract_function_simulator/contract_function_simulator.d.ts +37 -0
  3. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
  4. package/dest/contract_function_simulator/contract_function_simulator.js +117 -0
  5. package/dest/contract_function_simulator/execution_data_provider.d.ts +301 -0
  6. package/dest/contract_function_simulator/execution_data_provider.d.ts.map +1 -0
  7. package/dest/contract_function_simulator/execution_data_provider.js +14 -0
  8. package/dest/contract_function_simulator/execution_note_cache.d.ts +93 -0
  9. package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
  10. package/dest/contract_function_simulator/execution_note_cache.js +180 -0
  11. package/dest/contract_function_simulator/hashed_values_cache.d.ts +28 -0
  12. package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
  13. package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
  14. package/dest/contract_function_simulator/index.d.ts +10 -0
  15. package/dest/contract_function_simulator/index.d.ts.map +1 -0
  16. package/dest/contract_function_simulator/index.js +8 -0
  17. package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
  18. package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
  19. package/dest/contract_function_simulator/oracle/index.js +2 -0
  20. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +19 -0
  21. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
  22. package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
  23. package/dest/contract_function_simulator/oracle/oracle.d.ts +53 -0
  24. package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
  25. package/dest/contract_function_simulator/oracle/oracle.js +317 -0
  26. package/dest/contract_function_simulator/oracle/private_execution.d.ts +24 -0
  27. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
  28. package/dest/contract_function_simulator/oracle/private_execution.js +100 -0
  29. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +187 -0
  30. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
  31. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +325 -0
  32. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +83 -0
  33. package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +1 -0
  34. package/dest/contract_function_simulator/oracle/typed_oracle.js +138 -0
  35. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +163 -0
  36. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
  37. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +257 -0
  38. package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
  39. package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
  40. package/dest/contract_function_simulator/pick_notes.js +51 -0
  41. package/dest/contract_function_simulator/proxied_node.d.ts +9 -0
  42. package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -0
  43. package/dest/contract_function_simulator/proxied_node.js +27 -0
  44. package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.d.ts +5 -4
  45. package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +1 -0
  46. package/dest/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.js +16 -15
  47. package/dest/contract_function_simulator/tagging_utils.d.ts.map +1 -0
  48. package/dest/entrypoints/client/bundle/index.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/index.js +1 -1
  51. package/dest/entrypoints/client/bundle/utils.js +3 -3
  52. package/dest/entrypoints/client/lazy/index.d.ts +1 -1
  53. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  54. package/dest/entrypoints/client/lazy/index.js +1 -1
  55. package/dest/entrypoints/client/lazy/utils.js +3 -3
  56. package/dest/entrypoints/server/index.d.ts +1 -1
  57. package/dest/entrypoints/server/index.d.ts.map +1 -1
  58. package/dest/entrypoints/server/index.js +1 -1
  59. package/dest/entrypoints/server/utils.d.ts +4 -4
  60. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  61. package/dest/entrypoints/server/utils.js +12 -12
  62. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  63. package/dest/private_kernel/private_kernel_execution_prover.js +4 -4
  64. package/dest/pxe_service/pxe_service.d.ts +2 -2
  65. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  66. package/dest/pxe_service/pxe_service.js +46 -21
  67. package/dest/storage/note_data_provider/note_dao.d.ts +1 -1
  68. package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
  69. package/package.json +17 -15
  70. package/src/config/package_info.ts +1 -1
  71. package/src/contract_function_simulator/contract_function_simulator.ts +193 -0
  72. package/src/contract_function_simulator/execution_data_provider.ts +391 -0
  73. package/src/contract_function_simulator/execution_note_cache.ts +217 -0
  74. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  75. package/src/contract_function_simulator/index.ts +9 -0
  76. package/src/contract_function_simulator/oracle/index.ts +16 -0
  77. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  78. package/src/contract_function_simulator/oracle/oracle.ts +541 -0
  79. package/src/contract_function_simulator/oracle/private_execution.ts +171 -0
  80. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +518 -0
  81. package/src/contract_function_simulator/oracle/typed_oracle.ts +273 -0
  82. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +384 -0
  83. package/src/contract_function_simulator/pick_notes.ts +141 -0
  84. package/src/contract_function_simulator/proxied_node.ts +33 -0
  85. package/src/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.ts +18 -21
  86. package/src/entrypoints/client/bundle/index.ts +1 -1
  87. package/src/entrypoints/client/bundle/utils.ts +3 -3
  88. package/src/entrypoints/client/lazy/index.ts +1 -1
  89. package/src/entrypoints/client/lazy/utils.ts +3 -3
  90. package/src/entrypoints/server/index.ts +1 -1
  91. package/src/entrypoints/server/utils.ts +14 -14
  92. package/src/private_kernel/private_kernel_execution_prover.ts +5 -4
  93. package/src/pxe_service/pxe_service.ts +75 -39
  94. package/src/storage/note_data_provider/note_dao.ts +2 -1
  95. package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts.map +0 -1
  96. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  97. /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.d.ts +0 -0
  98. /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.js +0 -0
  99. /package/src/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.ts +0 -0
@@ -0,0 +1,391 @@
1
+ import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
+ import type { Fr, Point } from '@aztec/foundation/fields';
3
+ import type {
4
+ EventSelector,
5
+ FunctionArtifact,
6
+ FunctionArtifactWithContractName,
7
+ FunctionSelector,
8
+ } from '@aztec/stdlib/abi';
9
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import type { L2Block } from '@aztec/stdlib/block';
11
+ import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
12
+ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
13
+ import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
14
+ import type { NoteStatus } from '@aztec/stdlib/note';
15
+ import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
16
+ import type { BlockHeader, NodeStats, TxHash } from '@aztec/stdlib/tx';
17
+
18
+ import type { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
19
+ import type { NoteData } from './oracle/typed_oracle.js';
20
+
21
+ /**
22
+ * Error thrown when a contract is not found in the database.
23
+ */
24
+ export class ContractNotFoundError extends Error {
25
+ constructor(contractAddress: string) {
26
+ super(`DB has no contract with address ${contractAddress}`);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Error thrown when a contract class is not found in the database.
32
+ */
33
+ export class ContractClassNotFoundError extends Error {
34
+ constructor(contractClassId: string) {
35
+ super(`DB has no contract class with id ${contractClassId}`);
36
+ }
37
+ }
38
+
39
+ /*
40
+ * Collected stats during the execution of a transaction.
41
+ */
42
+ export type ExecutionStats = {
43
+ /**
44
+ * Contains an entry for each RPC call performed during the execution
45
+ */
46
+ nodeRPCCalls: NodeStats;
47
+ };
48
+
49
+ /**
50
+ * The interface for the data layer required to perform private and utility execution.
51
+ */
52
+ export interface ExecutionDataProvider {
53
+ /**
54
+ * Returns a contract instance associated with an address, if available.
55
+ * @param address - Address.
56
+ * @returns A contract instance.
57
+ */
58
+ getContractInstance(address: AztecAddress): Promise<ContractInstance>;
59
+
60
+ /**
61
+ * Retrieve the complete address associated to a given address.
62
+ * @param account - The account address.
63
+ * @returns A complete address associated with the input address.
64
+ * @throws An error if the account is not registered in the database.
65
+ */
66
+ getCompleteAddress(account: AztecAddress): Promise<CompleteAddress>;
67
+
68
+ /**
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.
73
+ */
74
+ getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise<KeyValidationRequest>;
75
+
76
+ /**
77
+ * Retrieves a set of notes stored in the database for a given contract address and storage slot.
78
+ * The query result is paginated using 'limit' and 'offset' values.
79
+ * Returns an object containing an array of note data.
80
+ *
81
+ * @param contractAddress - The contract address of the notes.
82
+ * @param storageSlot - The storage slot of the notes.
83
+ * @param status - The status of notes to fetch.
84
+ * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
85
+ * @returns A Promise that resolves to an array of note data.
86
+ */
87
+ getNotes(
88
+ contractAddress: AztecAddress,
89
+ storageSlot: Fr,
90
+ status: NoteStatus,
91
+ scopes?: AztecAddress[],
92
+ ): Promise<NoteData[]>;
93
+
94
+ /**
95
+ * Retrieve the artifact information of a specific function within a contract.
96
+ * The function is identified by its selector, which is a unique identifier generated from the function signature.
97
+ *
98
+ * @param contractAddress - The contract address.
99
+ * @param selector - The corresponding function selector.
100
+ * @returns A Promise that resolves to a FunctionArtifact object.
101
+ */
102
+ getFunctionArtifact(
103
+ contractAddress: AztecAddress,
104
+ selector: FunctionSelector,
105
+ ): Promise<FunctionArtifactWithContractName>;
106
+
107
+ /**
108
+ * Generates a stable function name for debug purposes.
109
+ * @param contractAddress - The contract address.
110
+ * @param selector - The corresponding function selector.
111
+ */
112
+ getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
113
+
114
+ /**
115
+ * Retrieves the artifact of a specified function within a given contract.
116
+ * The function is identified by its name, which is unique within a contract.
117
+ *
118
+ * @param contractAddress - The AztecAddress representing the contract containing the function.
119
+ * @param functionName - The name of the function.
120
+ * @returns The corresponding function's artifact as an object.
121
+ */
122
+ getFunctionArtifactByName(contractAddress: AztecAddress, functionName: string): Promise<FunctionArtifact | undefined>;
123
+
124
+ /**
125
+ * Gets the index of a nullifier in the nullifier tree.
126
+ * @param nullifier - The nullifier.
127
+ * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
128
+ */
129
+ getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
130
+
131
+ /**
132
+ * Gets the index of a nullifier in the nullifier tree.
133
+ * @param nullifier - The nullifier.
134
+ * @returns - The index of the nullifier. Undefined if it does not exist in the tree.
135
+ */
136
+ getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
137
+
138
+ /**
139
+ * Returns a nullifier membership witness for the given nullifier or undefined if not found.
140
+ * REFACTOR: Same as getL1ToL2MembershipWitness, can be combined with aztec-node method that does almost the same thing.
141
+ * @param nullifier - Nullifier we're looking for.
142
+ */
143
+ getNullifierMembershipWitnessAtLatestBlock(nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
144
+
145
+ /**
146
+ * Fetches a message from the db, given its key.
147
+ * @param contractAddress - Address of a contract by which the message was emitted.
148
+ * @param messageHash - Hash of the message.
149
+ * @param secret - Secret used to compute a nullifier.
150
+ * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
151
+ * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
152
+ */
153
+ getL1ToL2MembershipWitness(
154
+ contractAddress: AztecAddress,
155
+ messageHash: Fr,
156
+ secret: Fr,
157
+ ): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
158
+
159
+ /**
160
+ * Retrieve the databases view of the Block Header object.
161
+ * This structure is fed into the circuits simulator and is used to prove against certain historical roots.
162
+ *
163
+ * @returns A Promise that resolves to a Header object.
164
+ */
165
+ getBlockHeader(): Promise<BlockHeader>;
166
+
167
+ /**
168
+ * Fetches the index and sibling path of a leaf at a given block from a given tree.
169
+ * @param blockNumber - The block number at which to get the membership witness.
170
+ * @param treeId - Id of the tree to get the sibling path from.
171
+ * @param leafValue - The leaf value
172
+ * @returns The index and sibling path concatenated [index, sibling_path]
173
+ */
174
+ getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;
175
+
176
+ /**
177
+ * Returns a nullifier membership witness for a given nullifier at a given block.
178
+ * @param blockNumber - The block number at which to get the index.
179
+ * @param nullifier - Nullifier we try to find witness for.
180
+ * @returns The nullifier membership witness (if found).
181
+ */
182
+ getNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
183
+
184
+ /**
185
+ * Returns a low nullifier membership witness for a given nullifier at a given block.
186
+ * @param blockNumber - The block number at which to get the index.
187
+ * @param nullifier - Nullifier we try to find the low nullifier witness for.
188
+ * @returns The low nullifier membership witness (if found).
189
+ * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
190
+ * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
191
+ * we are trying to prove non-inclusion for.
192
+ */
193
+ getLowNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
194
+
195
+ /**
196
+ * Returns a witness for a given slot of the public data tree at a given block.
197
+ * @param blockNumber - The block number at which to get the witness.
198
+ * @param leafSlot - The slot of the public data in the public data tree.
199
+ */
200
+ getPublicDataWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
201
+
202
+ /**
203
+ * Gets the storage value at the given contract storage slot.
204
+ *
205
+ * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
206
+ * Aztec's version of `eth_getStorageAt`.
207
+ *
208
+ * @param blockNumber - The block number at which to get the data.
209
+ * @param contract - Address of the contract to query.
210
+ * @param slot - Slot to query.
211
+ * @returns Storage value at the given contract slot.
212
+ * @throws If the contract is not deployed.
213
+ */
214
+ getPublicStorageAt(blockNumber: number, contract: AztecAddress, slot: Fr): Promise<Fr>;
215
+
216
+ /**
217
+ * Fetch a block corresponding to the given block number.
218
+ * @param blockNumber - The block number of a block to fetch.
219
+ * @returns - The block corresponding to the given block number. Undefined if it does not exist.
220
+ */
221
+ getBlock(blockNumber: number): Promise<L2Block | undefined>;
222
+
223
+ /**
224
+ * Fetches the current block number.
225
+ * @returns The block number.
226
+ */
227
+ getBlockNumber(): Promise<number>;
228
+
229
+ /**
230
+ * Fetches the current chain id.
231
+ * @returns The chain id.
232
+ */
233
+ getChainId(): Promise<number>;
234
+
235
+ /**
236
+ * Fetches the current chain id.
237
+ * @returns The chain id.
238
+ */
239
+ getVersion(): Promise<number>;
240
+
241
+ /**
242
+ * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
243
+ * Includes the next index to be used used for tagging with this secret.
244
+ * @param contractAddress - The contract address to silo the secret for
245
+ * @param sender - The address sending the note
246
+ * @param recipient - The address receiving the note
247
+ * @returns A tagging secret that can be used to tag notes.
248
+ */
249
+ getIndexedTaggingSecretAsSender(
250
+ contractAddress: AztecAddress,
251
+ sender: AztecAddress,
252
+ recipient: AztecAddress,
253
+ ): Promise<IndexedTaggingSecret>;
254
+
255
+ /**
256
+ * Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
257
+ * @param contractAddress - The contract address to silo the secret for
258
+ * @param sender - The address sending the note
259
+ * @param recipient - The address receiving the note
260
+ */
261
+ incrementAppTaggingSecretIndexAsSender(
262
+ contractAddress: AztecAddress,
263
+ sender: AztecAddress,
264
+ recipient: AztecAddress,
265
+ ): Promise<void>;
266
+
267
+ /**
268
+ * Synchronizes the logs tagged with scoped addresses and all the senders in the address book. Stores the found logs
269
+ * in CapsuleArray ready for a later retrieval in Aztec.nr.
270
+ * @param contractAddress - The address of the contract that the logs are tagged for.
271
+ * @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged log capsule array in which found logs will be stored.
272
+ * @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
273
+ * synced.
274
+ */
275
+ syncTaggedLogs(
276
+ contractAddress: AztecAddress,
277
+ pendingTaggedLogArrayBaseSlot: Fr,
278
+ scopes?: AztecAddress[],
279
+ ): Promise<void>;
280
+
281
+ /**
282
+ * Delivers the preimage and metadata of a committed note so that it can be later requested via the `getNotes`
283
+ * oracle.
284
+ *
285
+ * @param contractAddress - The address of the contract that created the note (i.e. the siloing contract)
286
+ * @param storageSlot - The storage slot of the note - used for indexing in `getNotes`
287
+ * @param nonce - The nonce of the note used by the kernel to compute the unique note hash
288
+ * @param content - The note's content: this is the primary item to return in `getNotes`
289
+ * @param noteHash - The non-unique non-siloed note hash
290
+ * @param nullifier - The inner (non-siloed) note nullifier
291
+ * @param txHash - The transaction in which the note was added to the note hash tree
292
+ * @param recipient - The account that discovered the note
293
+ */
294
+ deliverNote(
295
+ contractAddress: AztecAddress,
296
+ storageSlot: Fr,
297
+ nonce: Fr,
298
+ content: Fr[],
299
+ noteHash: Fr,
300
+ nullifier: Fr,
301
+ txHash: TxHash,
302
+ recipient: AztecAddress,
303
+ ): Promise<void>;
304
+
305
+ /**
306
+ * Searches for a log with the corresponding `tag` and returns it along with contextual transaction information.
307
+ * Returns null if no such log exists, and throws if more than one exists.
308
+ *
309
+ * @param tag - The log tag to search for.
310
+ */
311
+ getLogByTag(tag: Fr): Promise<LogWithTxData | null>;
312
+
313
+ /**
314
+ * Removes all of a contract's notes that have been nullified from the note database.
315
+ */
316
+ removeNullifiedNotes(contractAddress: AztecAddress): Promise<void>;
317
+
318
+ /**
319
+ * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
320
+ * * If data was already stored at this slot, it is overwritten.
321
+ * @param contractAddress - The contract address to scope the data under.
322
+ * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
323
+ * @param capsule - An array of field elements representing the capsule.
324
+ * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
325
+ * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
326
+ * network state it's backed by local PXE db.
327
+ */
328
+ storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void>;
329
+
330
+ /**
331
+ * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
332
+ * @param contractAddress - The contract address under which the data is scoped.
333
+ * @param slot - The slot in the database to read.
334
+ * @returns The stored data or `null` if no data is stored under the slot.
335
+ */
336
+ loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
337
+
338
+ /**
339
+ * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
340
+ * @param contractAddress - The contract address under which the data is scoped.
341
+ * @param slot - The slot in the database to delete.
342
+ */
343
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void>;
344
+
345
+ /**
346
+ * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
347
+ * structures by avoiding repeated calls to `loadCapsule` and `storeCapsule`.
348
+ * Supports overlapping source and destination regions (which will result in the overlapped source values being
349
+ * overwritten). All copied slots must exist in the database (i.e. have been stored and not deleted)
350
+ *
351
+ * @param contractAddress - The contract address under which the data is scoped.
352
+ * @param srcSlot - The first slot to copy from.
353
+ * @param dstSlot - The first slot to copy to.
354
+ * @param numEntries - The number of entries to copy.
355
+ */
356
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
357
+
358
+ /**
359
+ * Retrieves the shared secret for a given address and ephemeral public key.
360
+ * @param address - The address to get the secret for.
361
+ * @param ephPk - The ephemeral public key to get the secret for.
362
+ * @returns The secret for the given address.
363
+ */
364
+ getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
365
+
366
+ /**
367
+ * Stores an event log in the database.
368
+ * @param contractAddress - The address of the contract that emitted the log.
369
+ * @param recipient - The address of the recipient.
370
+ * @param eventSelector - The event selector of the event.
371
+ * @param msgContent - The content of the private event message.
372
+ * @param txHash - The hash of the transaction that emitted the log.
373
+ * @param logIndexInTx - The index of the log within the transaction.
374
+ * @param txIndexInBlock - The index of the transaction in which the log was emitted in the block.
375
+ */
376
+ storePrivateEventLog(
377
+ contractAddress: AztecAddress,
378
+ recipient: AztecAddress,
379
+ eventSelector: EventSelector,
380
+ msgContent: Fr[],
381
+ txHash: TxHash,
382
+ logIndexInTx: number,
383
+ txIndexInBlock: number,
384
+ ): Promise<void>;
385
+
386
+ /**
387
+ * Returns the execution statistics collected during the simulator run.
388
+ * @returns The execution statistics.
389
+ */
390
+ getStats(): ExecutionStats;
391
+ }
@@ -0,0 +1,217 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
4
+
5
+ import type { NoteData } from './oracle/typed_oracle.js';
6
+
7
+ interface PendingNote {
8
+ note: NoteData;
9
+ counter: number;
10
+ noteHashForConsumption: Fr;
11
+ }
12
+
13
+ /**
14
+ * Data that's accessible by all the function calls in an execution.
15
+ */
16
+ export class ExecutionNoteCache {
17
+ /**
18
+ * New notes created in this transaction.
19
+ * They are pushed to this array in the same order as they are emitted.
20
+ */
21
+ private notes: PendingNote[] = [];
22
+ /**
23
+ * This mapping maps from a contract address to the notes in the contract.
24
+ */
25
+ private noteMap: Map<bigint, PendingNote[]> = new Map();
26
+
27
+ /**
28
+ * This maps from a contract address to the nullifiers emitted from the contract.
29
+ * The note which is nullified might be new or not (i.e., was generated in a previous transaction).
30
+ * Note that their value (bigint representation) is used because Frs cannot be looked up in Sets.
31
+ */
32
+ private nullifierMap: Map<bigint, Set<bigint>> = new Map();
33
+
34
+ /**
35
+ * All nullifiers emitted in this transaction.
36
+ */
37
+ private allNullifiers: Set<bigint> = new Set();
38
+
39
+ private minRevertibleSideEffectCounter = 0;
40
+
41
+ private inRevertiblePhase = false;
42
+
43
+ /**
44
+ * We don't need to use the tx request hash for nonces if another non revertible nullifier is emitted.
45
+ * In that case we disable injecting the tx request hash as a nullifier.
46
+ */
47
+ private usedTxRequestHashForNonces = true;
48
+
49
+ constructor(private readonly txRequestHash: Fr) {}
50
+
51
+ /**
52
+ * Enters the revertible phase of the transaction.
53
+ * @param minRevertibleSideEffectCounter - The counter at which the transaction enters the revertible phase.
54
+ */
55
+ public async setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number) {
56
+ if (this.inRevertiblePhase) {
57
+ throw new Error(
58
+ `Cannot enter the revertible phase twice. Current counter: ${minRevertibleSideEffectCounter}. Previous enter counter: ${this.minRevertibleSideEffectCounter}`,
59
+ );
60
+ }
61
+ this.inRevertiblePhase = true;
62
+ this.minRevertibleSideEffectCounter = minRevertibleSideEffectCounter;
63
+
64
+ let nonceGenerator = this.txRequestHash;
65
+ const nullifiers = this.getAllNullifiers();
66
+ if (nullifiers.length > 0) {
67
+ nonceGenerator = new Fr(nullifiers[0]);
68
+ this.usedTxRequestHashForNonces = false;
69
+ }
70
+
71
+ // The existing pending notes are all non-revertible.
72
+ // They cannot be squashed by nullifiers emitted after minRevertibleSideEffectCounter is set.
73
+ // Their indexes in the tx are known at this point and won't change. So we can assign a nonce to each one of them.
74
+ // The nonces will be used to create the "complete" nullifier.
75
+ const updatedNotes = await Promise.all(
76
+ this.notes.map(async ({ note, counter }, i) => {
77
+ const nonce = await computeNoteHashNonce(nonceGenerator, i);
78
+ const uniqueNoteHash = await computeUniqueNoteHash(
79
+ nonce,
80
+ await siloNoteHash(note.contractAddress, note.noteHash),
81
+ );
82
+ return {
83
+ counter,
84
+ note: { ...note, nonce },
85
+ noteHashForConsumption: uniqueNoteHash,
86
+ };
87
+ }),
88
+ );
89
+ // Rebuild the data.
90
+ this.notes = [];
91
+ this.noteMap = new Map();
92
+ updatedNotes.forEach(n => this.#addNote(n));
93
+ }
94
+
95
+ public finish() {
96
+ // If we never entered the revertible phase, we need to use the tx request hash as a nonce for the notes if no nullifiers have been emitted.
97
+ if (!this.inRevertiblePhase) {
98
+ this.usedTxRequestHashForNonces = this.getAllNullifiers().length === 0;
99
+ }
100
+ // If we entered the revertible phase, the nonce generator was decided based on wether or not a nullifier was emitted before entering.
101
+ return {
102
+ usedTxRequestHashForNonces: this.usedTxRequestHashForNonces,
103
+ };
104
+ }
105
+
106
+ /**
107
+ * Add a new note to cache.
108
+ * @param note - New note created during execution.
109
+ */
110
+ public addNewNote(note: NoteData, counter: number) {
111
+ const previousNote = this.notes[this.notes.length - 1];
112
+ if (previousNote && previousNote.counter >= counter) {
113
+ throw new Error(
114
+ `Note hash counters must be strictly increasing. Current counter: ${counter}. Previous counter: ${previousNote.counter}.`,
115
+ );
116
+ }
117
+
118
+ this.#addNote({ note, counter, noteHashForConsumption: note.noteHash });
119
+ }
120
+
121
+ /**
122
+ * Add a nullifier to cache. It could be for a db note or a new note created during execution.
123
+ * @param contractAddress - Contract address of the note.
124
+ * @param innerNullifier - Inner nullifier of the note.
125
+ * @param noteHash - A hash of the note. If this value equals 0, it means the note being nullified is from a previous
126
+ * transaction (and thus not a new note).
127
+ */
128
+ public async nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, noteHash: Fr) {
129
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
130
+ let nullifiedNoteHashCounter: number | undefined = undefined;
131
+ // Find and remove the matching new note and log(s) if the emitted noteHash is not empty.
132
+ if (!noteHash.isEmpty()) {
133
+ const notesInContract = this.noteMap.get(contractAddress.toBigInt()) ?? [];
134
+ const noteIndexToRemove = notesInContract.findIndex(n => n.noteHashForConsumption.equals(noteHash));
135
+ if (noteIndexToRemove === -1) {
136
+ throw new Error('Attempt to remove a pending note that does not exist.');
137
+ }
138
+
139
+ const note = notesInContract.splice(noteIndexToRemove, 1)[0];
140
+ nullifiedNoteHashCounter = note.counter;
141
+ this.noteMap.set(contractAddress.toBigInt(), notesInContract);
142
+ this.notes = this.notes.filter(n => n.counter !== note.counter);
143
+
144
+ // If the note is non revertible and the nullifier was emitted in the revertible phase, both the note hash and the nullifier will be emitted
145
+ if (this.inRevertiblePhase && note.counter < this.minRevertibleSideEffectCounter) {
146
+ this.recordNullifier(contractAddress, siloedNullifier);
147
+ }
148
+ } else {
149
+ // If the note being nullified comes from a previous tx the nullifier will be emitted.
150
+ this.recordNullifier(contractAddress, siloedNullifier);
151
+ }
152
+ return nullifiedNoteHashCounter;
153
+ }
154
+
155
+ /**
156
+ * Adds a nullifier to the cache. Note cache needs to track all nullifiers to decide which nullifier to use for note siloing.
157
+ * @param contractAddress - Contract address that emitted the nullifier.
158
+ * @param innerNullifier
159
+ */
160
+ public async nullifierCreated(contractAddress: AztecAddress, innerNullifier: Fr) {
161
+ const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
162
+ this.recordNullifier(contractAddress, siloedNullifier);
163
+ }
164
+
165
+ /**
166
+ * Return notes created up to current point in execution.
167
+ * If a nullifier for a note in this list is emitted, the note will be deleted.
168
+ * @param contractAddress - Contract address of the notes.
169
+ * @param storageSlot - Storage slot of the notes.
170
+ **/
171
+ public getNotes(contractAddress: AztecAddress, storageSlot: Fr) {
172
+ const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
173
+ return notes.filter(n => n.note.storageSlot.equals(storageSlot)).map(n => n.note);
174
+ }
175
+
176
+ /**
177
+ * Check if a note exists in the newNotes array.
178
+ * @param contractAddress - Contract address of the note.
179
+ * @param storageSlot - Storage slot of the note.
180
+ * @param noteHash - A hash of the note.
181
+ **/
182
+ public checkNoteExists(contractAddress: AztecAddress, noteHash: Fr) {
183
+ const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
184
+ return notes.some(n => n.note.noteHash.equals(noteHash));
185
+ }
186
+
187
+ /**
188
+ * Return all nullifiers emitted from a contract.
189
+ * @param contractAddress - Address of the contract.
190
+ */
191
+ public getNullifiers(contractAddress: AztecAddress): Set<bigint> {
192
+ return this.nullifierMap.get(contractAddress.toBigInt()) ?? new Set();
193
+ }
194
+
195
+ #addNote(note: PendingNote) {
196
+ this.notes.push(note);
197
+
198
+ const notes = this.noteMap.get(note.note.contractAddress.toBigInt()) ?? [];
199
+ notes.push(note);
200
+ this.noteMap.set(note.note.contractAddress.toBigInt(), notes);
201
+ }
202
+
203
+ getAllNotes(): PendingNote[] {
204
+ return this.notes;
205
+ }
206
+
207
+ getAllNullifiers(): Fr[] {
208
+ return [...this.allNullifiers].map(n => new Fr(n));
209
+ }
210
+
211
+ recordNullifier(contractAddress: AztecAddress, siloedNullifier: Fr) {
212
+ const nullifiers = this.getNullifiers(contractAddress);
213
+ nullifiers.add(siloedNullifier.toBigInt());
214
+ this.nullifierMap.set(contractAddress.toBigInt(), nullifiers);
215
+ this.allNullifiers.add(siloedNullifier.toBigInt());
216
+ }
217
+ }
@@ -0,0 +1,47 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { HashedValues } from '@aztec/stdlib/tx';
3
+
4
+ /**
5
+ * A cache for hashed values (arguments, returns) during transaction execution.
6
+ */
7
+ export class HashedValuesCache {
8
+ private cache: Map<bigint, Fr[]>;
9
+
10
+ constructor(initialArguments: HashedValues[] = []) {
11
+ this.cache = new Map();
12
+ for (const initialArg of initialArguments) {
13
+ this.cache.set(initialArg.hash.toBigInt(), initialArg.values);
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Creates a new hashed values cache.
19
+ * @param initialArguments - The initial arguments to add to the cache.
20
+ * @returns The new hashed values cache.
21
+ */
22
+ public static create(initialArguments: HashedValues[] = []) {
23
+ return new HashedValuesCache(initialArguments);
24
+ }
25
+
26
+ /**
27
+ * Gets preimage of a hash.
28
+ * @param hash - The hash to get the preimage of.
29
+ * @returns The preimage.
30
+ */
31
+ public getPreimage(hash: Fr): Fr[] | undefined {
32
+ if (hash.isEmpty()) {
33
+ return [];
34
+ } else {
35
+ return this.cache.get(hash.toBigInt());
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Stores values in cache and returns its hash.
41
+ * @param values - The values to store.
42
+ * @returns The hash of the values.
43
+ */
44
+ public store(values: Fr[], hash: Fr) {
45
+ this.cache.set(hash.toBigInt(), values);
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ export { ExecutionNoteCache } from './execution_note_cache.js';
2
+ export { HashedValuesCache } from './hashed_values_cache.js';
3
+ export { pickNotes } from './pick_notes.js';
4
+ export type { NoteData, TypedOracle } from './oracle/typed_oracle.js';
5
+ export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
6
+ export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
7
+ export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
8
+ export { Oracle } from './oracle/oracle.js';
9
+ export { executePrivateFunction, extractPrivateCircuitPublicInputs } from './oracle/private_execution.js';
@@ -0,0 +1,16 @@
1
+ import type { Oracle } from './oracle.js';
2
+
3
+ export * from './oracle.js';
4
+ export * from './typed_oracle.js';
5
+
6
+ /**
7
+ * A conditional type that takes a type `T` and returns a union of its method names.
8
+ */
9
+ type MethodNames<T> = {
10
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
11
+ }[keyof T];
12
+
13
+ /**
14
+ * Available oracle function names.
15
+ */
16
+ export type ORACLE_NAMES = MethodNames<Oracle>;