@aztec/pxe 0.87.5 → 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 (108) 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.d.ts +1 -1
  52. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  53. package/dest/entrypoints/client/bundle/utils.js +10 -4
  54. package/dest/entrypoints/client/lazy/index.d.ts +1 -1
  55. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/index.js +1 -1
  57. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  58. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  59. package/dest/entrypoints/client/lazy/utils.js +10 -4
  60. package/dest/entrypoints/{client/pxe_creation_options.d.ts → pxe_creation_options.d.ts} +4 -1
  61. package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
  62. package/dest/entrypoints/server/index.d.ts +1 -1
  63. package/dest/entrypoints/server/index.d.ts.map +1 -1
  64. package/dest/entrypoints/server/index.js +1 -1
  65. package/dest/entrypoints/server/utils.d.ts +6 -6
  66. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  67. package/dest/entrypoints/server/utils.js +26 -18
  68. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  69. package/dest/private_kernel/private_kernel_execution_prover.js +6 -5
  70. package/dest/pxe_service/pxe_service.d.ts +2 -2
  71. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  72. package/dest/pxe_service/pxe_service.js +58 -28
  73. package/dest/storage/note_data_provider/note_dao.d.ts +1 -1
  74. package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
  75. package/package.json +17 -15
  76. package/src/config/package_info.ts +1 -1
  77. package/src/contract_function_simulator/contract_function_simulator.ts +193 -0
  78. package/src/contract_function_simulator/execution_data_provider.ts +391 -0
  79. package/src/contract_function_simulator/execution_note_cache.ts +217 -0
  80. package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
  81. package/src/contract_function_simulator/index.ts +9 -0
  82. package/src/contract_function_simulator/oracle/index.ts +16 -0
  83. package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
  84. package/src/contract_function_simulator/oracle/oracle.ts +541 -0
  85. package/src/contract_function_simulator/oracle/private_execution.ts +171 -0
  86. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +518 -0
  87. package/src/contract_function_simulator/oracle/typed_oracle.ts +273 -0
  88. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +384 -0
  89. package/src/contract_function_simulator/pick_notes.ts +141 -0
  90. package/src/contract_function_simulator/proxied_node.ts +33 -0
  91. package/src/{pxe_oracle_interface → contract_function_simulator}/pxe_oracle_interface.ts +18 -21
  92. package/src/entrypoints/client/bundle/index.ts +1 -1
  93. package/src/entrypoints/client/bundle/utils.ts +24 -16
  94. package/src/entrypoints/client/lazy/index.ts +1 -1
  95. package/src/entrypoints/client/lazy/utils.ts +25 -12
  96. package/src/entrypoints/{client/pxe_creation_options.ts → pxe_creation_options.ts} +4 -1
  97. package/src/entrypoints/server/index.ts +1 -1
  98. package/src/entrypoints/server/utils.ts +44 -26
  99. package/src/private_kernel/private_kernel_execution_prover.ts +6 -4
  100. package/src/pxe_service/pxe_service.ts +86 -45
  101. package/src/storage/note_data_provider/note_dao.ts +2 -1
  102. package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
  103. package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts.map +0 -1
  104. package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
  105. /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.d.ts +0 -0
  106. /package/dest/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.js +0 -0
  107. /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
  108. /package/src/{pxe_oracle_interface → contract_function_simulator}/tagging_utils.ts +0 -0
@@ -0,0 +1,163 @@
1
+ import { Fr, Point } from '@aztec/foundation/fields';
2
+ import type { EventSelector } from '@aztec/stdlib/abi';
3
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
6
+ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
7
+ import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
8
+ import type { NoteStatus } from '@aztec/stdlib/note';
9
+ import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
10
+ import type { BlockHeader, Capsule, TxHash } from '@aztec/stdlib/tx';
11
+ import type { ExecutionDataProvider } from '../execution_data_provider.js';
12
+ import { type NoteData, TypedOracle } from './typed_oracle.js';
13
+ /**
14
+ * The oracle for an execution of utility contract functions.
15
+ */
16
+ export declare class UtilityExecutionOracle extends TypedOracle {
17
+ protected readonly contractAddress: AztecAddress;
18
+ /** List of transient auth witnesses to be used during this simulation */
19
+ protected readonly authWitnesses: AuthWitness[];
20
+ protected readonly capsules: Capsule[];
21
+ protected readonly executionDataProvider: ExecutionDataProvider;
22
+ protected log: import("@aztec/foundation/log").Logger;
23
+ protected readonly scopes?: AztecAddress[] | undefined;
24
+ constructor(contractAddress: AztecAddress,
25
+ /** List of transient auth witnesses to be used during this simulation */
26
+ authWitnesses: AuthWitness[], capsules: Capsule[], // TODO(#12425): Rename to transientCapsules
27
+ executionDataProvider: ExecutionDataProvider, log?: import("@aztec/foundation/log").Logger, scopes?: AztecAddress[] | undefined);
28
+ getBlockNumber(): Promise<number>;
29
+ getContractAddress(): Promise<AztecAddress>;
30
+ getChainId(): Promise<Fr>;
31
+ getVersion(): Promise<Fr>;
32
+ /**
33
+ * Retrieve keys associated with a specific master public key and app address.
34
+ * @param pkMHash - The master public key hash.
35
+ * @returns A Promise that resolves to nullifier keys.
36
+ * @throws If the keys are not registered in the key store.
37
+ */
38
+ getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest>;
39
+ /**
40
+ * Fetches the index and sibling path of a leaf at a given block from a given tree.
41
+ * @param blockNumber - The block number at which to get the membership witness.
42
+ * @param treeId - Id of the tree to get the sibling path from.
43
+ * @param leafValue - The leaf value
44
+ * @returns The index and sibling path concatenated [index, sibling_path]
45
+ */
46
+ getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;
47
+ /**
48
+ * Returns a nullifier membership witness for a given nullifier at a given block.
49
+ * @param blockNumber - The block number at which to get the index.
50
+ * @param nullifier - Nullifier we try to find witness for.
51
+ * @returns The nullifier membership witness (if found).
52
+ */
53
+ getNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
54
+ /**
55
+ * Returns a low nullifier membership witness for a given nullifier at a given block.
56
+ * @param blockNumber - The block number at which to get the index.
57
+ * @param nullifier - Nullifier we try to find the low nullifier witness for.
58
+ * @returns The low nullifier membership witness (if found).
59
+ * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
60
+ * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
61
+ * we are trying to prove non-inclusion for.
62
+ */
63
+ getLowNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
64
+ /**
65
+ * Returns a public data tree witness for a given leaf slot at a given block.
66
+ * @param blockNumber - The block number at which to get the index.
67
+ * @param leafSlot - The slot of the public data tree to get the witness for.
68
+ * @returns - The witness
69
+ */
70
+ getPublicDataWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
71
+ /**
72
+ * Fetches a block header of a given block.
73
+ * @param blockNumber - The number of a block of which to get the block header.
74
+ * @returns Block extracted from a block with block number `blockNumber`.
75
+ */
76
+ getBlockHeader(blockNumber: number): Promise<BlockHeader | undefined>;
77
+ /**
78
+ * Retrieve the complete address associated to a given address.
79
+ * @param account - The account address.
80
+ * @returns A complete address associated with the input address.
81
+ * @throws An error if the account is not registered in the database.
82
+ */
83
+ getCompleteAddress(account: AztecAddress): Promise<CompleteAddress>;
84
+ /**
85
+ * Returns a contract instance associated with an address or throws if not found.
86
+ * @param address - Address.
87
+ * @returns A contract instance.
88
+ */
89
+ getContractInstance(address: AztecAddress): Promise<ContractInstance>;
90
+ /**
91
+ * Returns an auth witness for the given message hash. Checks on the list of transient witnesses
92
+ * for this transaction first, and falls back to the local database if not found.
93
+ * @param messageHash - Hash of the message to authenticate.
94
+ * @returns Authentication witness for the requested message hash.
95
+ */
96
+ getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined>;
97
+ /**
98
+ * Gets some notes for a contract address and storage slot.
99
+ * Returns a flattened array containing filtered notes.
100
+ *
101
+ * @remarks
102
+ * Check for pending notes with matching slot.
103
+ * Real notes coming from DB will have a leafIndex which
104
+ * represents their index in the note hash tree.
105
+ *
106
+ * @param storageSlot - The storage slot.
107
+ * @param numSelects - The number of valid selects in selectBy and selectValues.
108
+ * @param selectBy - An array of indices of the fields to selects.
109
+ * @param selectValues - The values to match.
110
+ * @param selectComparators - The comparators to use to match values.
111
+ * @param sortBy - An array of indices of the fields to sort.
112
+ * @param sortOrder - The order of the corresponding index in sortBy. (1: DESC, 2: ASC, 0: Do nothing)
113
+ * @param limit - The number of notes to retrieve per query.
114
+ * @param offset - The starting index for pagination.
115
+ * @param status - The status of notes to fetch.
116
+ * @returns Array of note data.
117
+ */
118
+ getNotes(storageSlot: Fr, numSelects: number, selectByIndexes: number[], selectByOffsets: number[], selectByLengths: number[], selectValues: Fr[], selectComparators: number[], sortByIndexes: number[], sortByOffsets: number[], sortByLengths: number[], sortOrder: number[], limit: number, offset: number, status: NoteStatus): Promise<NoteData[]>;
119
+ /**
120
+ * Check if a nullifier exists in the nullifier tree.
121
+ * @param innerNullifier - The inner nullifier.
122
+ * @returns A boolean indicating whether the nullifier exists in the tree or not.
123
+ */
124
+ checkNullifierExists(innerNullifier: Fr): Promise<boolean>;
125
+ /**
126
+ * Fetches a message from the executionDataProvider, given its key.
127
+ * @param contractAddress - Address of a contract by which the message was emitted.
128
+ * @param messageHash - Hash of the message.
129
+ * @param secret - Secret used to compute a nullifier.
130
+ * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
131
+ * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
132
+ */
133
+ getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr): Promise<import("./message_load_oracle_inputs.js").MessageLoadOracleInputs<39>>;
134
+ /**
135
+ * Read the public storage data.
136
+ * @param contractAddress - The address to read storage from.
137
+ * @param startStorageSlot - The starting storage slot.
138
+ * @param blockNumber - The block number to read storage at.
139
+ * @param numberOfElements - Number of elements to read from the starting storage slot.
140
+ */
141
+ storageRead(contractAddress: AztecAddress, startStorageSlot: Fr, blockNumber: number, numberOfElements: number): Promise<Fr[]>;
142
+ debugLog(message: string, fields: Fr[]): void;
143
+ /**
144
+ * Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
145
+ * Includes the next index to be used used for tagging with this secret.
146
+ * For this to work, the ivsk_m of the sender must be known.
147
+ * @param sender - The address sending the note
148
+ * @param recipient - The address receiving the note
149
+ * @returns A tagging secret that can be used to tag notes.
150
+ */
151
+ getIndexedTaggingSecretAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<IndexedTaggingSecret>;
152
+ fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr): Promise<void>;
153
+ deliverNote(contractAddress: AztecAddress, storageSlot: Fr, nonce: Fr, content: Fr[], noteHash: Fr, nullifier: Fr, txHash: TxHash, recipient: AztecAddress): Promise<void>;
154
+ getLogByTag(tag: Fr): Promise<LogWithTxData | null>;
155
+ storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void>;
156
+ loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
157
+ deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void>;
158
+ copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
159
+ aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
160
+ getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
161
+ storePrivateEventLog(contractAddress: AztecAddress, recipient: AztecAddress, eventSelector: EventSelector, msgContent: Fr[], txHash: TxHash, logIndexInTx: number, txIndexInBlock: number): Promise<void>;
162
+ }
163
+ //# sourceMappingURL=utility_execution_oracle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility_execution_oracle.d.ts","sourceRoot":"","sources":["../../../src/contract_function_simulator/oracle/utility_execution_oracle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,KAAK,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,WAAW;IAEnD,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,YAAY;IAChD,yEAAyE;IACzE,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,EAAE;IAC/C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE;IACtC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IAC/D,SAAS,CAAC,GAAG;IACb,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
+ import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
4
+ import { siloNullifier } from '@aztec/stdlib/hash';
5
+ import { pickNotes } from '../pick_notes.js';
6
+ import { TypedOracle } from './typed_oracle.js';
7
+ /**
8
+ * The oracle for an execution of utility contract functions.
9
+ */ export class UtilityExecutionOracle extends TypedOracle {
10
+ contractAddress;
11
+ authWitnesses;
12
+ capsules;
13
+ executionDataProvider;
14
+ log;
15
+ scopes;
16
+ constructor(contractAddress, /** List of transient auth witnesses to be used during this simulation */ authWitnesses, capsules, executionDataProvider, log = createLogger('simulator:client_view_context'), scopes){
17
+ super(), this.contractAddress = contractAddress, this.authWitnesses = authWitnesses, this.capsules = capsules, this.executionDataProvider = executionDataProvider, this.log = log, this.scopes = scopes;
18
+ }
19
+ getBlockNumber() {
20
+ return this.executionDataProvider.getBlockNumber();
21
+ }
22
+ getContractAddress() {
23
+ return Promise.resolve(this.contractAddress);
24
+ }
25
+ getChainId() {
26
+ return Promise.resolve(this.executionDataProvider.getChainId().then((id)=>new Fr(id)));
27
+ }
28
+ getVersion() {
29
+ return Promise.resolve(this.executionDataProvider.getVersion().then((v)=>new Fr(v)));
30
+ }
31
+ /**
32
+ * Retrieve keys associated with a specific master public key and app address.
33
+ * @param pkMHash - The master public key hash.
34
+ * @returns A Promise that resolves to nullifier keys.
35
+ * @throws If the keys are not registered in the key store.
36
+ */ getKeyValidationRequest(pkMHash) {
37
+ return this.executionDataProvider.getKeyValidationRequest(pkMHash, this.contractAddress);
38
+ }
39
+ /**
40
+ * Fetches the index and sibling path of a leaf at a given block from a given tree.
41
+ * @param blockNumber - The block number at which to get the membership witness.
42
+ * @param treeId - Id of the tree to get the sibling path from.
43
+ * @param leafValue - The leaf value
44
+ * @returns The index and sibling path concatenated [index, sibling_path]
45
+ */ getMembershipWitness(blockNumber, treeId, leafValue) {
46
+ return this.executionDataProvider.getMembershipWitness(blockNumber, treeId, leafValue);
47
+ }
48
+ /**
49
+ * Returns a nullifier membership witness for a given nullifier at a given block.
50
+ * @param blockNumber - The block number at which to get the index.
51
+ * @param nullifier - Nullifier we try to find witness for.
52
+ * @returns The nullifier membership witness (if found).
53
+ */ async getNullifierMembershipWitness(blockNumber, nullifier) {
54
+ return await this.executionDataProvider.getNullifierMembershipWitness(blockNumber, nullifier);
55
+ }
56
+ /**
57
+ * Returns a low nullifier membership witness for a given nullifier at a given block.
58
+ * @param blockNumber - The block number at which to get the index.
59
+ * @param nullifier - Nullifier we try to find the low nullifier witness for.
60
+ * @returns The low nullifier membership witness (if found).
61
+ * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
62
+ * list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
63
+ * we are trying to prove non-inclusion for.
64
+ */ async getLowNullifierMembershipWitness(blockNumber, nullifier) {
65
+ return await this.executionDataProvider.getLowNullifierMembershipWitness(blockNumber, nullifier);
66
+ }
67
+ /**
68
+ * Returns a public data tree witness for a given leaf slot at a given block.
69
+ * @param blockNumber - The block number at which to get the index.
70
+ * @param leafSlot - The slot of the public data tree to get the witness for.
71
+ * @returns - The witness
72
+ */ async getPublicDataWitness(blockNumber, leafSlot) {
73
+ return await this.executionDataProvider.getPublicDataWitness(blockNumber, leafSlot);
74
+ }
75
+ /**
76
+ * Fetches a block header of a given block.
77
+ * @param blockNumber - The number of a block of which to get the block header.
78
+ * @returns Block extracted from a block with block number `blockNumber`.
79
+ */ async getBlockHeader(blockNumber) {
80
+ const block = await this.executionDataProvider.getBlock(blockNumber);
81
+ if (!block) {
82
+ return undefined;
83
+ }
84
+ return block.header;
85
+ }
86
+ /**
87
+ * Retrieve the complete address associated to a given address.
88
+ * @param account - The account address.
89
+ * @returns A complete address associated with the input address.
90
+ * @throws An error if the account is not registered in the database.
91
+ */ getCompleteAddress(account) {
92
+ return this.executionDataProvider.getCompleteAddress(account);
93
+ }
94
+ /**
95
+ * Returns a contract instance associated with an address or throws if not found.
96
+ * @param address - Address.
97
+ * @returns A contract instance.
98
+ */ getContractInstance(address) {
99
+ return this.executionDataProvider.getContractInstance(address);
100
+ }
101
+ /**
102
+ * Returns an auth witness for the given message hash. Checks on the list of transient witnesses
103
+ * for this transaction first, and falls back to the local database if not found.
104
+ * @param messageHash - Hash of the message to authenticate.
105
+ * @returns Authentication witness for the requested message hash.
106
+ */ getAuthWitness(messageHash) {
107
+ return Promise.resolve(this.authWitnesses.find((w)=>w.requestHash.equals(messageHash))?.witness);
108
+ }
109
+ /**
110
+ * Gets some notes for a contract address and storage slot.
111
+ * Returns a flattened array containing filtered notes.
112
+ *
113
+ * @remarks
114
+ * Check for pending notes with matching slot.
115
+ * Real notes coming from DB will have a leafIndex which
116
+ * represents their index in the note hash tree.
117
+ *
118
+ * @param storageSlot - The storage slot.
119
+ * @param numSelects - The number of valid selects in selectBy and selectValues.
120
+ * @param selectBy - An array of indices of the fields to selects.
121
+ * @param selectValues - The values to match.
122
+ * @param selectComparators - The comparators to use to match values.
123
+ * @param sortBy - An array of indices of the fields to sort.
124
+ * @param sortOrder - The order of the corresponding index in sortBy. (1: DESC, 2: ASC, 0: Do nothing)
125
+ * @param limit - The number of notes to retrieve per query.
126
+ * @param offset - The starting index for pagination.
127
+ * @param status - The status of notes to fetch.
128
+ * @returns Array of note data.
129
+ */ async getNotes(storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
130
+ const dbNotes = await this.executionDataProvider.getNotes(this.contractAddress, storageSlot, status, this.scopes);
131
+ return pickNotes(dbNotes, {
132
+ selects: selectByIndexes.slice(0, numSelects).map((index, i)=>({
133
+ selector: {
134
+ index,
135
+ offset: selectByOffsets[i],
136
+ length: selectByLengths[i]
137
+ },
138
+ value: selectValues[i],
139
+ comparator: selectComparators[i]
140
+ })),
141
+ sorts: sortByIndexes.map((index, i)=>({
142
+ selector: {
143
+ index,
144
+ offset: sortByOffsets[i],
145
+ length: sortByLengths[i]
146
+ },
147
+ order: sortOrder[i]
148
+ })),
149
+ limit,
150
+ offset
151
+ });
152
+ }
153
+ /**
154
+ * Check if a nullifier exists in the nullifier tree.
155
+ * @param innerNullifier - The inner nullifier.
156
+ * @returns A boolean indicating whether the nullifier exists in the tree or not.
157
+ */ async checkNullifierExists(innerNullifier) {
158
+ const nullifier = await siloNullifier(this.contractAddress, innerNullifier);
159
+ const index = await this.executionDataProvider.getNullifierIndex(nullifier);
160
+ return index !== undefined;
161
+ }
162
+ /**
163
+ * Fetches a message from the executionDataProvider, given its key.
164
+ * @param contractAddress - Address of a contract by which the message was emitted.
165
+ * @param messageHash - Hash of the message.
166
+ * @param secret - Secret used to compute a nullifier.
167
+ * @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
168
+ * @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
169
+ */ async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
170
+ return await this.executionDataProvider.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
171
+ }
172
+ /**
173
+ * Read the public storage data.
174
+ * @param contractAddress - The address to read storage from.
175
+ * @param startStorageSlot - The starting storage slot.
176
+ * @param blockNumber - The block number to read storage at.
177
+ * @param numberOfElements - Number of elements to read from the starting storage slot.
178
+ */ async storageRead(contractAddress, startStorageSlot, blockNumber, numberOfElements) {
179
+ const values = [];
180
+ for(let i = 0n; i < numberOfElements; i++){
181
+ const storageSlot = new Fr(startStorageSlot.value + i);
182
+ const value = await this.executionDataProvider.getPublicStorageAt(blockNumber, contractAddress, storageSlot);
183
+ this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`);
184
+ values.push(value);
185
+ }
186
+ return values;
187
+ }
188
+ debugLog(message, fields) {
189
+ this.log.verbose(`${applyStringFormatting(message, fields)}`, {
190
+ module: `${this.log.module}:debug_log`
191
+ });
192
+ }
193
+ /**
194
+ * Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
195
+ * Includes the next index to be used used for tagging with this secret.
196
+ * For this to work, the ivsk_m of the sender must be known.
197
+ * @param sender - The address sending the note
198
+ * @param recipient - The address receiving the note
199
+ * @returns A tagging secret that can be used to tag notes.
200
+ */ async getIndexedTaggingSecretAsSender(sender, recipient) {
201
+ return await this.executionDataProvider.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
202
+ }
203
+ async fetchTaggedLogs(pendingTaggedLogArrayBaseSlot) {
204
+ await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
205
+ await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
206
+ }
207
+ async deliverNote(contractAddress, storageSlot, nonce, content, noteHash, nullifier, txHash, recipient) {
208
+ // TODO(#10727): allow other contracts to deliver notes
209
+ if (!this.contractAddress.equals(contractAddress)) {
210
+ throw new Error(`Got a note delivery request from ${contractAddress}, expected ${this.contractAddress}`);
211
+ }
212
+ await this.executionDataProvider.deliverNote(contractAddress, storageSlot, nonce, content, noteHash, nullifier, txHash, recipient);
213
+ }
214
+ getLogByTag(tag) {
215
+ return this.executionDataProvider.getLogByTag(tag);
216
+ }
217
+ storeCapsule(contractAddress, slot, capsule) {
218
+ if (!contractAddress.equals(this.contractAddress)) {
219
+ // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
220
+ throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
221
+ }
222
+ return this.executionDataProvider.storeCapsule(this.contractAddress, slot, capsule);
223
+ }
224
+ async loadCapsule(contractAddress, slot) {
225
+ if (!contractAddress.equals(this.contractAddress)) {
226
+ // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
227
+ throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
228
+ }
229
+ return(// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
230
+ this.capsules.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ?? await this.executionDataProvider.loadCapsule(this.contractAddress, slot));
231
+ }
232
+ deleteCapsule(contractAddress, slot) {
233
+ if (!contractAddress.equals(this.contractAddress)) {
234
+ // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
235
+ throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
236
+ }
237
+ return this.executionDataProvider.deleteCapsule(this.contractAddress, slot);
238
+ }
239
+ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
240
+ if (!contractAddress.equals(this.contractAddress)) {
241
+ // TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
242
+ throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
243
+ }
244
+ return this.executionDataProvider.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
245
+ }
246
+ // TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
247
+ aes128Decrypt(ciphertext, iv, symKey) {
248
+ const aes128 = new Aes128();
249
+ return aes128.decryptBufferCBC(ciphertext, iv, symKey);
250
+ }
251
+ getSharedSecret(address, ephPk) {
252
+ return this.executionDataProvider.getSharedSecret(address, ephPk);
253
+ }
254
+ storePrivateEventLog(contractAddress, recipient, eventSelector, msgContent, txHash, logIndexInTx, txIndexInBlock) {
255
+ return this.executionDataProvider.storePrivateEventLog(contractAddress, recipient, eventSelector, msgContent, txHash, logIndexInTx, txIndexInBlock);
256
+ }
257
+ }
@@ -0,0 +1,85 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { Comparator, type Note } from '@aztec/stdlib/note';
3
+ export interface PropertySelector {
4
+ index: number;
5
+ offset: number;
6
+ length: number;
7
+ }
8
+ /**
9
+ * Configuration for selecting values.
10
+ */
11
+ export interface Select {
12
+ /**
13
+ * Selector of the field to select and match.
14
+ */
15
+ selector: PropertySelector;
16
+ /**
17
+ * Required value of the field.
18
+ */
19
+ value: Fr;
20
+ /**
21
+ * The comparator to use
22
+ */
23
+ comparator: Comparator;
24
+ }
25
+ /**
26
+ * The order to sort an array.
27
+ */
28
+ export declare enum SortOrder {
29
+ NADA = 0,
30
+ DESC = 1,
31
+ ASC = 2
32
+ }
33
+ /**
34
+ * Configuration for sorting values.
35
+ */
36
+ export interface Sort {
37
+ /**
38
+ * Selector of the field to sort.
39
+ */
40
+ selector: PropertySelector;
41
+ /**
42
+ * Order to sort the field.
43
+ */
44
+ order: SortOrder;
45
+ }
46
+ /**
47
+ * Options for picking items from an array of BasicNoteData.
48
+ */
49
+ interface GetOptions {
50
+ /**
51
+ * Configurations for selecting items.
52
+ * Default: empty array.
53
+ */
54
+ selects?: Select[];
55
+ /**
56
+ * Configurations for sorting items.
57
+ * Default: empty array.
58
+ */
59
+ sorts?: Sort[];
60
+ /**
61
+ * The number of items to retrieve per query.
62
+ * Default: 0. No limit.
63
+ */
64
+ limit?: number;
65
+ /**
66
+ * The starting index for pagination.
67
+ * Default: 0.
68
+ */
69
+ offset?: number;
70
+ }
71
+ /**
72
+ * Data needed from to perform sort.
73
+ */
74
+ interface ContainsNote {
75
+ /**
76
+ * The note.
77
+ */
78
+ note: Note;
79
+ }
80
+ /**
81
+ * Pick from a note array a number of notes that meet the criteria.
82
+ */
83
+ export declare function pickNotes<T extends ContainsNote>(noteDatas: T[], { selects, sorts, limit, offset }: GetOptions): T[];
84
+ export {};
85
+ //# sourceMappingURL=pick_notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick_notes.d.ts","sourceRoot":"","sources":["../../src/contract_function_simulator/pick_notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,EAAE,CAAC;IACV;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,IAAI,IAAI;IACR,IAAI,IAAI;IACR,GAAG,IAAI;CACR;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;CAClB;AAED;;GAEG;AACH,UAAU,UAAU;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,UAAU,YAAY;IACpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AA8CD;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,YAAY,EAC9C,SAAS,EAAE,CAAC,EAAE,EACd,EAAE,OAAY,EAAE,KAAU,EAAE,KAAS,EAAE,MAAU,EAAE,EAAE,UAAU,GAC9D,CAAC,EAAE,CAIL"}
@@ -0,0 +1,51 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { Comparator } from '@aztec/stdlib/note';
3
+ /**
4
+ * The order to sort an array.
5
+ */ export var SortOrder = /*#__PURE__*/ function(SortOrder) {
6
+ SortOrder[SortOrder["NADA"] = 0] = "NADA";
7
+ SortOrder[SortOrder["DESC"] = 1] = "DESC";
8
+ SortOrder[SortOrder["ASC"] = 2] = "ASC";
9
+ return SortOrder;
10
+ }({});
11
+ const selectPropertyFromPackedNoteContent = (noteData, selector)=>{
12
+ const noteValueBuffer = noteData[selector.index].toBuffer();
13
+ const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
14
+ return Fr.fromBuffer(noteValue);
15
+ };
16
+ const selectNotes = (noteDatas, selects)=>noteDatas.filter((noteData)=>selects.every(({ selector, value, comparator })=>{
17
+ const noteValueFr = selectPropertyFromPackedNoteContent(noteData.note.items, selector);
18
+ const comparatorSelector = {
19
+ [Comparator.EQ]: ()=>noteValueFr.equals(value),
20
+ [Comparator.NEQ]: ()=>!noteValueFr.equals(value),
21
+ [Comparator.LT]: ()=>noteValueFr.lt(value),
22
+ [Comparator.LTE]: ()=>noteValueFr.lt(value) || noteValueFr.equals(value),
23
+ [Comparator.GT]: ()=>!noteValueFr.lt(value) && !noteValueFr.equals(value),
24
+ [Comparator.GTE]: ()=>!noteValueFr.lt(value)
25
+ };
26
+ return comparatorSelector[comparator]();
27
+ }));
28
+ const sortNotes = (a, b, sorts, level = 0)=>{
29
+ if (sorts[level] === undefined) {
30
+ return 0;
31
+ }
32
+ const { selector, order } = sorts[level];
33
+ if (order === 0) {
34
+ return 0;
35
+ }
36
+ const aValue = selectPropertyFromPackedNoteContent(a, selector);
37
+ const bValue = selectPropertyFromPackedNoteContent(b, selector);
38
+ const dir = order === 1 ? [
39
+ -1,
40
+ 1
41
+ ] : [
42
+ 1,
43
+ -1
44
+ ];
45
+ return aValue.toBigInt() === bValue.toBigInt() ? sortNotes(a, b, sorts, level + 1) : aValue.toBigInt() > bValue.toBigInt() ? dir[0] : dir[1];
46
+ };
47
+ /**
48
+ * Pick from a note array a number of notes that meet the criteria.
49
+ */ export function pickNotes(noteDatas, { selects = [], sorts = [], limit = 0, offset = 0 }) {
50
+ return selectNotes(noteDatas, selects).sort((a, b)=>sortNotes(a.note.items, b.note.items, sorts)).slice(offset, limit ? offset + limit : undefined);
51
+ }
@@ -0,0 +1,9 @@
1
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
2
+ import type { NodeStats } from '@aztec/stdlib/tx';
3
+ export type ProxiedNode = AztecNode & {
4
+ getStats(): NodeStats;
5
+ };
6
+ export declare class ProxiedNodeFactory {
7
+ static create(node: AztecNode): ProxiedNode;
8
+ }
9
+ //# sourceMappingURL=proxied_node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxied_node.d.ts","sourceRoot":"","sources":["../../src/contract_function_simulator/proxied_node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,IAAI,SAAS,CAAA;CAAE,CAAC;AAEhE,qBAAa,kBAAkB;IAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,GAoBrB,WAAW;CAEpB"}
@@ -0,0 +1,27 @@
1
+ import { Timer } from '@aztec/foundation/timer';
2
+ export class ProxiedNodeFactory {
3
+ static create(node) {
4
+ const stats = {};
5
+ return new Proxy(node, {
6
+ get (target, prop) {
7
+ if (prop === 'getStats') {
8
+ return ()=>{
9
+ return stats;
10
+ };
11
+ } else {
12
+ return async function(...args) {
13
+ if (!stats[prop]) {
14
+ stats[prop] = {
15
+ times: []
16
+ };
17
+ }
18
+ const timer = new Timer();
19
+ const result = await target[prop].apply(target, args);
20
+ stats[prop].times.push(timer.ms());
21
+ return result;
22
+ };
23
+ }
24
+ }
25
+ });
26
+ }
27
+ }