@aztec/pxe 0.0.1-commit.381b1a9 → 0.0.1-commit.3a4ae741b
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.
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +9 -3
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +28 -6
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -3
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +5 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -3
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/message_tx_context.js +57 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -5
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +45 -44
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +42 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +45 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +163 -94
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +22 -47
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +32 -72
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +46 -32
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +91 -40
- package/dest/contract_sync/contract_sync_service.d.ts +5 -3
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +47 -30
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +3 -3
- package/dest/pxe.d.ts +8 -4
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +41 -23
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
- package/package.json +16 -16
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +39 -7
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +8 -5
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -4
- package/src/contract_function_simulator/noir-structs/message_tx_context.ts +55 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +3 -6
- package/src/contract_function_simulator/oracle/interfaces.ts +50 -53
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +135 -0
- package/src/contract_function_simulator/oracle/oracle.ts +176 -138
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +34 -91
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +125 -48
- package/src/contract_sync/contract_sync_service.ts +67 -38
- package/src/messages/message_context_service.ts +45 -0
- package/src/oracle_version.ts +3 -3
- package/src/pxe.ts +59 -22
- package/src/storage/metadata.ts +1 -1
- package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
- package/src/tagging/index.ts +1 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Aes128 } from '@aztec/foundation/crypto/aes128';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { LogLevels, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
4
5
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
5
6
|
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
6
7
|
import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
|
|
@@ -14,6 +15,7 @@ import { ORACLE_VERSION } from '../../oracle_version.js';
|
|
|
14
15
|
import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
|
|
15
16
|
import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
|
|
16
17
|
import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
|
|
18
|
+
import { MessageTxContext } from '../noir-structs/message_tx_context.js';
|
|
17
19
|
import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
|
|
18
20
|
import { UtilityContext } from '../noir-structs/utility_context.js';
|
|
19
21
|
import { pickNotes } from '../pick_notes.js';
|
|
@@ -24,6 +26,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
24
26
|
isMisc = true;
|
|
25
27
|
isUtility = true;
|
|
26
28
|
contractLogger;
|
|
29
|
+
offchainEffects = [];
|
|
27
30
|
contractAddress;
|
|
28
31
|
authWitnesses;
|
|
29
32
|
capsules;
|
|
@@ -37,8 +40,10 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
37
40
|
senderAddressBookStore;
|
|
38
41
|
capsuleStore;
|
|
39
42
|
privateEventStore;
|
|
43
|
+
messageContextService;
|
|
44
|
+
contractSyncService;
|
|
40
45
|
jobId;
|
|
41
|
-
|
|
46
|
+
logger;
|
|
42
47
|
scopes;
|
|
43
48
|
constructor(args){
|
|
44
49
|
this.contractAddress = args.contractAddress;
|
|
@@ -54,19 +59,33 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
54
59
|
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
55
60
|
this.capsuleStore = args.capsuleStore;
|
|
56
61
|
this.privateEventStore = args.privateEventStore;
|
|
62
|
+
this.messageContextService = args.messageContextService;
|
|
63
|
+
this.contractSyncService = args.contractSyncService;
|
|
57
64
|
this.jobId = args.jobId;
|
|
58
|
-
this.
|
|
65
|
+
this.logger = args.log ?? createLogger('simulator:client_view_context');
|
|
59
66
|
this.scopes = args.scopes;
|
|
60
67
|
}
|
|
61
|
-
|
|
68
|
+
assertCompatibleOracleVersion(version) {
|
|
69
|
+
// TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
|
|
70
|
+
// Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
|
|
71
|
+
// the expected pinned version or the current one. We want to allow for both the pinned and the current versions
|
|
72
|
+
// because we want this code to work with both the pinned and unpinned version since some branches do not have the
|
|
73
|
+
// pinned contracts (like e.g. next)
|
|
74
|
+
const LEGACY_ORACLE_VERSION = 12;
|
|
75
|
+
if (isProtocolContract(this.contractAddress)) {
|
|
76
|
+
if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
|
|
77
|
+
throw new Error(`Expected legacy oracle version ${LEGACY_ORACLE_VERSION} or current oracle version ${ORACLE_VERSION} for alpha payload contract at ${this.contractAddress}, got ${version}.`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
62
81
|
if (version !== ORACLE_VERSION) {
|
|
63
82
|
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
|
-
|
|
85
|
+
getRandomField() {
|
|
67
86
|
return Fr.random();
|
|
68
87
|
}
|
|
69
|
-
|
|
88
|
+
getUtilityContext() {
|
|
70
89
|
return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
|
|
71
90
|
}
|
|
72
91
|
/**
|
|
@@ -75,7 +94,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
75
94
|
* @returns A Promise that resolves to nullifier keys.
|
|
76
95
|
* @throws If the keys are not registered in the key store.
|
|
77
96
|
* @throws If scopes are defined and the account is not in the scopes.
|
|
78
|
-
*/ async
|
|
97
|
+
*/ async getKeyValidationRequest(pkMHash) {
|
|
79
98
|
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
80
99
|
if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
|
|
81
100
|
let hasAccess = false;
|
|
@@ -96,7 +115,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
96
115
|
* witness.
|
|
97
116
|
* @param noteHash - The note hash to find in the note hash tree.
|
|
98
117
|
* @returns The membership witness containing the leaf index and sibling path
|
|
99
|
-
*/
|
|
118
|
+
*/ getNoteHashMembershipWitness(anchorBlockHash, noteHash) {
|
|
100
119
|
return this.aztecNode.getNoteHashMembershipWitness(anchorBlockHash, noteHash);
|
|
101
120
|
}
|
|
102
121
|
/**
|
|
@@ -109,7 +128,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
109
128
|
* witness.
|
|
110
129
|
* @param blockHash - The block hash to find in the archive tree.
|
|
111
130
|
* @returns The membership witness containing the leaf index and sibling path
|
|
112
|
-
*/
|
|
131
|
+
*/ getBlockHashMembershipWitness(anchorBlockHash, blockHash) {
|
|
113
132
|
return this.aztecNode.getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
114
133
|
}
|
|
115
134
|
/**
|
|
@@ -117,7 +136,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
117
136
|
* @param blockHash - The block hash at which to get the index.
|
|
118
137
|
* @param nullifier - Nullifier we try to find witness for.
|
|
119
138
|
* @returns The nullifier membership witness (if found).
|
|
120
|
-
*/
|
|
139
|
+
*/ getNullifierMembershipWitness(blockHash, nullifier) {
|
|
121
140
|
return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
|
|
122
141
|
}
|
|
123
142
|
/**
|
|
@@ -128,7 +147,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
128
147
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
129
148
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
130
149
|
* we are trying to prove non-inclusion for.
|
|
131
|
-
*/
|
|
150
|
+
*/ getLowNullifierMembershipWitness(blockHash, nullifier) {
|
|
132
151
|
return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
133
152
|
}
|
|
134
153
|
/**
|
|
@@ -136,14 +155,14 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
136
155
|
* @param blockHash - The block hash at which to get the index.
|
|
137
156
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
138
157
|
* @returns - The witness
|
|
139
|
-
*/
|
|
158
|
+
*/ getPublicDataWitness(blockHash, leafSlot) {
|
|
140
159
|
return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
|
|
141
160
|
}
|
|
142
161
|
/**
|
|
143
162
|
* Fetches a block header of a given block.
|
|
144
163
|
* @param blockNumber - The number of a block of which to get the block header.
|
|
145
164
|
* @returns Block extracted from a block with block number `blockNumber`.
|
|
146
|
-
*/ async
|
|
165
|
+
*/ async getBlockHeader(blockNumber) {
|
|
147
166
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
148
167
|
if (blockNumber > anchorBlockNumber) {
|
|
149
168
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
@@ -155,7 +174,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
155
174
|
* Retrieve the public keys and partial address associated to a given address.
|
|
156
175
|
* @param account - The account address.
|
|
157
176
|
* @returns The public keys and partial address, or `undefined` if the account is not registered.
|
|
158
|
-
*/ async
|
|
177
|
+
*/ async tryGetPublicKeysAndPartialAddress(account) {
|
|
159
178
|
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
160
179
|
if (!completeAddress) {
|
|
161
180
|
return undefined;
|
|
@@ -177,10 +196,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
177
196
|
* Returns a contract instance associated with an address or throws if not found.
|
|
178
197
|
* @param address - Address.
|
|
179
198
|
* @returns A contract instance.
|
|
180
|
-
*/
|
|
181
|
-
return this.getContractInstance(address);
|
|
182
|
-
}
|
|
183
|
-
async getContractInstance(address) {
|
|
199
|
+
*/ async getContractInstance(address) {
|
|
184
200
|
const instance = await this.contractStore.getContractInstance(address);
|
|
185
201
|
if (!instance) {
|
|
186
202
|
throw new Error(`No contract instance found for address ${address.toString()}`);
|
|
@@ -192,7 +208,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
192
208
|
* for this transaction first, and falls back to the local database if not found.
|
|
193
209
|
* @param messageHash - Hash of the message to authenticate.
|
|
194
210
|
* @returns Authentication witness for the requested message hash.
|
|
195
|
-
*/
|
|
211
|
+
*/ getAuthWitness(messageHash) {
|
|
196
212
|
return Promise.resolve(this.authWitnesses.find((w)=>w.requestHash.equals(messageHash))?.witness);
|
|
197
213
|
}
|
|
198
214
|
/**
|
|
@@ -216,7 +232,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
216
232
|
* @param offset - The starting index for pagination.
|
|
217
233
|
* @param status - The status of notes to fetch.
|
|
218
234
|
* @returns Array of note data.
|
|
219
|
-
*/ async
|
|
235
|
+
*/ async getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status) {
|
|
220
236
|
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
221
237
|
const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
|
|
222
238
|
return pickNotes(dbNotes, {
|
|
@@ -245,7 +261,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
245
261
|
* Check if a nullifier exists in the nullifier tree.
|
|
246
262
|
* @param innerNullifier - The inner nullifier.
|
|
247
263
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
248
|
-
*/ async
|
|
264
|
+
*/ async checkNullifierExists(innerNullifier) {
|
|
249
265
|
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
250
266
|
siloNullifier(this.contractAddress, innerNullifier),
|
|
251
267
|
this.anchorBlockHeader.hash()
|
|
@@ -262,7 +278,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
262
278
|
* @param secret - Secret used to compute a nullifier.
|
|
263
279
|
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
264
280
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
265
|
-
*/ async
|
|
281
|
+
*/ async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
|
|
266
282
|
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
|
|
267
283
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
268
284
|
}
|
|
@@ -272,10 +288,10 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
272
288
|
* @param contractAddress - The address to read storage from.
|
|
273
289
|
* @param startStorageSlot - The starting storage slot.
|
|
274
290
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
275
|
-
*/ async
|
|
291
|
+
*/ async storageRead(blockHash, contractAddress, startStorageSlot, numberOfElements) {
|
|
276
292
|
const slots = Array(numberOfElements).fill(0).map((_, i)=>new Fr(startStorageSlot.value + BigInt(i)));
|
|
277
293
|
const values = await Promise.all(slots.map((storageSlot)=>this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)));
|
|
278
|
-
this.
|
|
294
|
+
this.logger.debug(`Oracle storage read: slots=[${slots.map((slot)=>slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`);
|
|
279
295
|
return values;
|
|
280
296
|
}
|
|
281
297
|
/**
|
|
@@ -290,15 +306,15 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
290
306
|
}
|
|
291
307
|
return this.contractLogger;
|
|
292
308
|
}
|
|
293
|
-
async
|
|
309
|
+
async log(level, message, fields) {
|
|
294
310
|
if (!LogLevels[level]) {
|
|
295
311
|
throw new Error(`Invalid log level: ${level}`);
|
|
296
312
|
}
|
|
297
313
|
const logger = await this.#getContractLogger();
|
|
298
314
|
logContractMessage(logger, LogLevels[level], message, fields);
|
|
299
315
|
}
|
|
300
|
-
async
|
|
301
|
-
const logService = new LogService(this.aztecNode, this.anchorBlockHeader, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId, this.
|
|
316
|
+
async fetchTaggedLogs(pendingTaggedLogArrayBaseSlot) {
|
|
317
|
+
const logService = new LogService(this.aztecNode, this.anchorBlockHeader, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId, this.logger.getBindings());
|
|
302
318
|
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
303
319
|
}
|
|
304
320
|
/**
|
|
@@ -310,15 +326,15 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
310
326
|
* @param contractAddress - The address of the contract that the logs are tagged for.
|
|
311
327
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
312
328
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
313
|
-
*/ async
|
|
329
|
+
*/ async validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen) {
|
|
314
330
|
// TODO(#10727): allow other contracts to store notes
|
|
315
331
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
316
332
|
throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
317
333
|
}
|
|
318
334
|
// We read all note and event validation requests and process them all concurrently. This makes the process much
|
|
319
335
|
// faster as we don't need to wait for the network round-trip.
|
|
320
|
-
const noteValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)).map(NoteValidationRequest.fromFields);
|
|
321
|
-
const eventValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)).map(EventValidationRequest.fromFields);
|
|
336
|
+
const noteValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)).map((fields)=>NoteValidationRequest.fromFields(fields, maxNotePackedLen));
|
|
337
|
+
const eventValidationRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)).map((fields)=>EventValidationRequest.fromFields(fields, maxEventSerializedLen));
|
|
322
338
|
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
323
339
|
const noteStorePromises = noteValidationRequests.map((request)=>noteService.validateAndStoreNote(request.contractAddress, request.owner, request.storageSlot, request.randomness, request.noteNonce, request.content, request.noteHash, request.nullifier, request.txHash, request.recipient));
|
|
324
340
|
const eventService = new EventService(this.anchorBlockHeader, this.aztecNode, this.privateEventStore, this.jobId);
|
|
@@ -331,7 +347,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
331
347
|
await this.capsuleStore.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, [], this.jobId);
|
|
332
348
|
await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
|
|
333
349
|
}
|
|
334
|
-
async
|
|
350
|
+
async bulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot) {
|
|
335
351
|
// TODO(#10727): allow other contracts to process partial notes
|
|
336
352
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
337
353
|
throw new Error(`Got a note validation request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
@@ -339,14 +355,33 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
339
355
|
// We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
|
|
340
356
|
// don't need to wait for the network round-trip.
|
|
341
357
|
const logRetrievalRequests = (await this.capsuleStore.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId)).map(LogRetrievalRequest.fromFields);
|
|
342
|
-
const logService = new LogService(this.aztecNode, this.anchorBlockHeader, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId, this.
|
|
358
|
+
const logService = new LogService(this.aztecNode, this.anchorBlockHeader, this.keyStore, this.capsuleStore, this.recipientTaggingStore, this.senderAddressBookStore, this.addressStore, this.jobId, this.logger.getBindings());
|
|
343
359
|
const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
|
|
344
360
|
// Requests are cleared once we're done.
|
|
345
361
|
await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, [], this.jobId);
|
|
346
362
|
// The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
|
|
347
363
|
await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalResponsesArrayBaseSlot, maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption), this.jobId);
|
|
348
364
|
}
|
|
349
|
-
|
|
365
|
+
async utilityResolveMessageContexts(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot) {
|
|
366
|
+
try {
|
|
367
|
+
if (!this.contractAddress.equals(contractAddress)) {
|
|
368
|
+
throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
369
|
+
}
|
|
370
|
+
const requestCapsules = await this.capsuleStore.readCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, this.jobId);
|
|
371
|
+
const txHashes = requestCapsules.map((fields, i)=>{
|
|
372
|
+
if (fields.length !== 1) {
|
|
373
|
+
throw new Error(`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`);
|
|
374
|
+
}
|
|
375
|
+
return fields[0];
|
|
376
|
+
});
|
|
377
|
+
const maybeMessageContexts = await this.messageContextService.resolveMessageContexts(txHashes, this.anchorBlockHeader.getBlockNumber());
|
|
378
|
+
// Leave response in response capsule array.
|
|
379
|
+
await this.capsuleStore.setCapsuleArray(contractAddress, messageContextResponsesArrayBaseSlot, maybeMessageContexts.map(MessageTxContext.toSerializedOption), this.jobId);
|
|
380
|
+
} finally{
|
|
381
|
+
await this.capsuleStore.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
storeCapsule(contractAddress, slot, capsule) {
|
|
350
385
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
351
386
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
352
387
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -354,7 +389,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
354
389
|
this.capsuleStore.storeCapsule(this.contractAddress, slot, capsule, this.jobId);
|
|
355
390
|
return Promise.resolve();
|
|
356
391
|
}
|
|
357
|
-
async
|
|
392
|
+
async loadCapsule(contractAddress, slot) {
|
|
358
393
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
359
394
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
360
395
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -362,7 +397,7 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
362
397
|
return(// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
363
398
|
this.capsules.find((c)=>c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ?? await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId));
|
|
364
399
|
}
|
|
365
|
-
|
|
400
|
+
deleteCapsule(contractAddress, slot) {
|
|
366
401
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
367
402
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
368
403
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -370,15 +405,24 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
370
405
|
this.capsuleStore.deleteCapsule(this.contractAddress, slot, this.jobId);
|
|
371
406
|
return Promise.resolve();
|
|
372
407
|
}
|
|
373
|
-
|
|
408
|
+
copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
|
|
374
409
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
375
410
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
376
411
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
377
412
|
}
|
|
378
413
|
return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
|
|
379
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
|
|
417
|
+
* stored notes or events are discovered.
|
|
418
|
+
*/ invalidateContractSyncCache(contractAddress, scopes) {
|
|
419
|
+
if (!contractAddress.equals(this.contractAddress)) {
|
|
420
|
+
throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
|
|
421
|
+
}
|
|
422
|
+
this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
|
|
423
|
+
}
|
|
380
424
|
// TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
|
|
381
|
-
|
|
425
|
+
aes128Decrypt(ciphertext, iv, symKey) {
|
|
382
426
|
const aes128 = new Aes128();
|
|
383
427
|
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
384
428
|
}
|
|
@@ -387,14 +431,21 @@ import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
|
387
431
|
* @param address - The address to get the secret for.
|
|
388
432
|
* @param ephPk - The ephemeral public key to get the secret for.
|
|
389
433
|
* @returns The secret for the given address.
|
|
390
|
-
*/
|
|
391
|
-
return this.getSharedSecret(address, ephPk);
|
|
392
|
-
}
|
|
393
|
-
async getSharedSecret(address, ephPk) {
|
|
434
|
+
*/ async getSharedSecret(address, ephPk) {
|
|
394
435
|
// TODO(#12656): return an app-siloed secret
|
|
395
436
|
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
396
437
|
const ivskM = await this.keyStore.getMasterSecretKey(recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey);
|
|
397
438
|
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
398
439
|
return deriveEcdhSharedSecret(addressSecret, ephPk);
|
|
399
440
|
}
|
|
441
|
+
emitOffchainEffect(data) {
|
|
442
|
+
this.offchainEffects.push({
|
|
443
|
+
data,
|
|
444
|
+
contractAddress: this.contractAddress
|
|
445
|
+
});
|
|
446
|
+
return Promise.resolve();
|
|
447
|
+
}
|
|
448
|
+
/** Returns offchain effects collected during execution. */ getOffchainEffects() {
|
|
449
|
+
return this.offchainEffects;
|
|
450
|
+
}
|
|
400
451
|
}
|
|
@@ -21,10 +21,10 @@ export declare class ContractSyncService implements StagedStore {
|
|
|
21
21
|
private log;
|
|
22
22
|
readonly storeName = "contract_sync";
|
|
23
23
|
private syncedContracts;
|
|
24
|
-
private
|
|
24
|
+
private excludedFromSync;
|
|
25
25
|
constructor(aztecNode: AztecNode, contractStore: ContractStore, noteStore: NoteStore, log: Logger);
|
|
26
26
|
/** Sets contracts that should be skipped during sync for a specific job. */
|
|
27
|
-
|
|
27
|
+
setExcludedFromSync(jobId: string, addresses: Set<string>): void;
|
|
28
28
|
/**
|
|
29
29
|
* Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
|
|
30
30
|
* Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
@@ -35,9 +35,11 @@ export declare class ContractSyncService implements StagedStore {
|
|
|
35
35
|
* @param scopes - Access scopes to pass through to the utility executor (affects whose account's private state is discovered).
|
|
36
36
|
*/
|
|
37
37
|
ensureContractSynced(contractAddress: AztecAddress, functionToInvokeAfterSync: FunctionSelector | null, utilityExecutor: (call: FunctionCall, scopes: AccessScopes) => Promise<any>, anchorBlockHeader: BlockHeader, jobId: string, scopes: AccessScopes): Promise<void>;
|
|
38
|
+
/** Clears sync cache entries for the given scopes of a contract. Also clears the ALL_SCOPES entry. */
|
|
39
|
+
invalidateContractForScopes(contractAddress: AztecAddress, scopes: AztecAddress[]): void;
|
|
38
40
|
/** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
|
|
39
41
|
wipe(): void;
|
|
40
42
|
commit(jobId: string): Promise<void>;
|
|
41
43
|
discardStaged(jobId: string): Promise<void>;
|
|
42
44
|
}
|
|
43
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJhY3Rfc3luY19zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3Rfc3luYy9jb250cmFjdF9zeW5jX3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsTUFBTSx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O,CAAC,SAAS;IACjB,OAAO,CAAC,GAAG;IAdb,QAAQ,CAAC,SAAS,mBAAmB;IAKrC,OAAO,CAAC,eAAe,CAAyC;IAGhE,OAAO,CAAC,gBAAgB,CAAuC;IAE/D,YACU,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,MAAM,EACjB;IAEJ,4EAA4E;IAC5E,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAE/D;IAED;;;;;;;;OAQG;IACG,oBAAoB,CACxB,eAAe,EAAE,YAAY,EAC7B,yBAAyB,EAAE,gBAAgB,GAAG,IAAI,EAClD,eAAe,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,EAC3E,iBAAiB,EAAE,WAAW,EAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,IAAI,CAAC,CAiBf;IAED,sGAAsG;IACtG,2BAA2B,CAAC,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAMvF;IA4BD,gFAAgF;IAChF,IAAI,IAAI,IAAI,CAGX;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAInC;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1C;CA2CF"}
|
|
@@ -11,11 +11,11 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
11
11
|
log;
|
|
12
12
|
storeName;
|
|
13
13
|
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
14
|
-
// (`contractAddress:scopeAddress`), or `contractAddress:*` for
|
|
14
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for all scopes (all accounts).
|
|
15
15
|
// The value is a promise that resolves when the contract is synced.
|
|
16
16
|
syncedContracts;
|
|
17
|
-
// Per-job
|
|
18
|
-
|
|
17
|
+
// Per-job excluded contract addresses - these contracts should not be synced.
|
|
18
|
+
excludedFromSync;
|
|
19
19
|
constructor(aztecNode, contractStore, noteStore, log){
|
|
20
20
|
this.aztecNode = aztecNode;
|
|
21
21
|
this.contractStore = contractStore;
|
|
@@ -23,10 +23,10 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
23
23
|
this.log = log;
|
|
24
24
|
this.storeName = 'contract_sync';
|
|
25
25
|
this.syncedContracts = new Map();
|
|
26
|
-
this.
|
|
26
|
+
this.excludedFromSync = new Map();
|
|
27
27
|
}
|
|
28
|
-
/** Sets contracts that should be skipped during sync for a specific job. */
|
|
29
|
-
this.
|
|
28
|
+
/** Sets contracts that should be skipped during sync for a specific job. */ setExcludedFromSync(jobId, addresses) {
|
|
29
|
+
this.excludedFromSync.set(jobId, addresses);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
|
|
@@ -37,32 +37,20 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
37
37
|
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
38
38
|
* @param scopes - Access scopes to pass through to the utility executor (affects whose account's private state is discovered).
|
|
39
39
|
*/ async ensureContractSynced(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId, scopes) {
|
|
40
|
-
|
|
41
|
-
const overrides = this.overriddenContracts.get(jobId);
|
|
42
|
-
if (overrides?.has(contractAddress.toString())) {
|
|
40
|
+
if (this.#shouldSkipSync(jobId, contractAddress)) {
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
this.#startSyncIfNeeded(contractAddress, scopes, (scopesToSync)=>this.#syncContract(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId, scopesToSync));
|
|
44
|
+
await this.#awaitSync(contractAddress, scopes);
|
|
45
|
+
}
|
|
46
|
+
/** Clears sync cache entries for the given scopes of a contract. Also clears the ALL_SCOPES entry. */ invalidateContractForScopes(contractAddress, scopes) {
|
|
47
|
+
if (scopes.length === 0) {
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (unsyncedScopesKeys.length > 0) {
|
|
54
|
-
// Start sync and store the promise for all unsynced scopes
|
|
55
|
-
const promise = this.#doSync(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId, unsyncedScopes).catch((err)=>{
|
|
56
|
-
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
57
|
-
unsyncedScopesKeys.forEach((key)=>this.syncedContracts.delete(key));
|
|
58
|
-
throw err;
|
|
59
|
-
});
|
|
60
|
-
unsyncedScopesKeys.forEach((key)=>this.syncedContracts.set(key, promise));
|
|
61
|
-
}
|
|
62
|
-
const promises = toKeys(contractAddress, scopes).map((key)=>this.syncedContracts.get(key));
|
|
63
|
-
await Promise.all(promises);
|
|
50
|
+
scopes.forEach((scope)=>this.syncedContracts.delete(toKey(contractAddress, scope)));
|
|
51
|
+
this.syncedContracts.delete(toKey(contractAddress, 'ALL_SCOPES'));
|
|
64
52
|
}
|
|
65
|
-
async #
|
|
53
|
+
async #syncContract(contractAddress, functionToInvokeAfterSync, utilityExecutor, anchorBlockHeader, jobId, scopes) {
|
|
66
54
|
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
67
55
|
await Promise.all([
|
|
68
56
|
syncState(contractAddress, this.contractStore, functionToInvokeAfterSync, utilityExecutor, this.noteStore, this.aztecNode, anchorBlockHeader, jobId, scopes),
|
|
@@ -75,17 +63,46 @@ import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
|
75
63
|
this.syncedContracts.clear();
|
|
76
64
|
}
|
|
77
65
|
commit(jobId) {
|
|
78
|
-
// Clear
|
|
79
|
-
this.
|
|
66
|
+
// Clear excluded contracts for this job
|
|
67
|
+
this.excludedFromSync.delete(jobId);
|
|
80
68
|
return Promise.resolve();
|
|
81
69
|
}
|
|
82
70
|
discardStaged(jobId) {
|
|
83
71
|
// We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
|
|
84
72
|
// the sync are also undone.
|
|
85
73
|
this.syncedContracts.clear();
|
|
86
|
-
this.
|
|
74
|
+
this.excludedFromSync.delete(jobId);
|
|
87
75
|
return Promise.resolve();
|
|
88
76
|
}
|
|
77
|
+
/** Returns true if sync should be skipped for this contract */ #shouldSkipSync(jobId, contractAddress) {
|
|
78
|
+
return !!this.excludedFromSync.get(jobId)?.has(contractAddress.toString());
|
|
79
|
+
}
|
|
80
|
+
/** If there are unsynced scopes, starts sync and stores the promise in cache with error cleanup. */ #startSyncIfNeeded(contractAddress, scopes, syncFn) {
|
|
81
|
+
const scopesToSync = this.#getScopesToSync(contractAddress, scopes);
|
|
82
|
+
const keys = toKeys(contractAddress, scopesToSync);
|
|
83
|
+
if (keys.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const promise = syncFn(scopesToSync).catch((err)=>{
|
|
87
|
+
keys.forEach((key)=>this.syncedContracts.delete(key));
|
|
88
|
+
throw err;
|
|
89
|
+
});
|
|
90
|
+
keys.forEach((key)=>this.syncedContracts.set(key, promise));
|
|
91
|
+
}
|
|
92
|
+
/** Filters out scopes that are already cached, returning only those that still need syncing. */ #getScopesToSync(contractAddress, scopes) {
|
|
93
|
+
if (this.syncedContracts.has(toKey(contractAddress, 'ALL_SCOPES'))) {
|
|
94
|
+
// If we are already syncing all scopes, then return an empty list
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
if (scopes === 'ALL_SCOPES') {
|
|
98
|
+
return 'ALL_SCOPES';
|
|
99
|
+
}
|
|
100
|
+
return scopes.filter((scope)=>!this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
101
|
+
}
|
|
102
|
+
/** Collects all relevant scope promises (including in-flight ones from concurrent calls) and awaits them. */ async #awaitSync(contractAddress, scopes) {
|
|
103
|
+
const promises = toKeys(contractAddress, scopes).map((key)=>this.syncedContracts.get(key)).filter((p)=>p !== undefined);
|
|
104
|
+
await Promise.all(promises);
|
|
105
|
+
}
|
|
89
106
|
}
|
|
90
107
|
function toKeys(contract, scopes) {
|
|
91
108
|
return scopes === 'ALL_SCOPES' ? [
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { MessageTxContext } from '../contract_function_simulator/noir-structs/message_tx_context.js';
|
|
4
|
+
/** Resolves transaction hashes into the context needed to process messages. */
|
|
5
|
+
export declare class MessageContextService {
|
|
6
|
+
private readonly aztecNode;
|
|
7
|
+
constructor(aztecNode: AztecNode);
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a list of tx hashes into their message contexts.
|
|
10
|
+
*
|
|
11
|
+
* For each tx hash, looks up the corresponding tx effect and extracts the note hashes and first nullifier needed to
|
|
12
|
+
* process messages that originated from that transaction. Returns `null` for tx hashes that are zero, not yet
|
|
13
|
+
* available, or in blocks beyond the anchor block.
|
|
14
|
+
*/
|
|
15
|
+
resolveMessageContexts(txHashes: Fr[], anchorBlockNumber: number): Promise<(MessageTxContext | null)[]>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZV9jb250ZXh0X3NlcnZpY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tZXNzYWdlcy9tZXNzYWdlX2NvbnRleHRfc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFHakUsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sbUVBQW1FLENBQUM7QUFFckcsK0VBQStFO0FBQy9FLHFCQUFhLHFCQUFxQjtJQUNwQixPQUFPLENBQUMsUUFBUSxDQUFDLFNBQVM7SUFBdEMsWUFBNkIsU0FBUyxFQUFFLFNBQVMsRUFBSTtJQUVyRDs7Ozs7O09BTUc7SUFDSCxzQkFBc0IsQ0FBQyxRQUFRLEVBQUUsRUFBRSxFQUFFLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxDQUFDLGdCQUFnQixHQUFHLElBQUksQ0FBQyxFQUFFLENBQUMsQ0EwQnRHO0NBQ0YifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message_context_service.d.ts","sourceRoot":"","sources":["../../src/messages/message_context_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mEAAmE,CAAC;AAErG,+EAA+E;AAC/E,qBAAa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAAtC,YAA6B,SAAS,EAAE,SAAS,EAAI;IAErD;;;;;;OAMG;IACH,sBAAsB,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,gBAAgB,GAAG,IAAI,CAAC,EAAE,CAAC,CA0BtG;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
2
|
+
import { MessageTxContext } from '../contract_function_simulator/noir-structs/message_tx_context.js';
|
|
3
|
+
/** Resolves transaction hashes into the context needed to process messages. */ export class MessageContextService {
|
|
4
|
+
aztecNode;
|
|
5
|
+
constructor(aztecNode){
|
|
6
|
+
this.aztecNode = aztecNode;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a list of tx hashes into their message contexts.
|
|
10
|
+
*
|
|
11
|
+
* For each tx hash, looks up the corresponding tx effect and extracts the note hashes and first nullifier needed to
|
|
12
|
+
* process messages that originated from that transaction. Returns `null` for tx hashes that are zero, not yet
|
|
13
|
+
* available, or in blocks beyond the anchor block.
|
|
14
|
+
*/ resolveMessageContexts(txHashes, anchorBlockNumber) {
|
|
15
|
+
// TODO: optimize, we might be hitting the node to get the same txHash repeatedly
|
|
16
|
+
return Promise.all(txHashes.map(async (txHashField)=>{
|
|
17
|
+
// A zero tx hash indicates a tx-less offchain message (e.g. one not tied to any onchain transaction).
|
|
18
|
+
// These messages don't have a transaction context to resolve, so we return null.
|
|
19
|
+
if (txHashField.isZero()) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const txHash = TxHash.fromField(txHashField);
|
|
23
|
+
const txEffect = await this.aztecNode.getTxEffect(txHash);
|
|
24
|
+
if (!txEffect || txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
// Every tx has at least one nullifier (the first nullifier derived from the tx hash). Hitting this condition
|
|
28
|
+
// would mean a buggy node, but since we need to access data.nullifiers[0], the defensive check does no harm.
|
|
29
|
+
const data = txEffect.data;
|
|
30
|
+
if (data.nullifiers.length === 0) {
|
|
31
|
+
throw new Error(`Tx effect for ${txHash} has no nullifiers`);
|
|
32
|
+
}
|
|
33
|
+
return new MessageTxContext(data.txHash, data.noteHashes, data.nullifiers[0]);
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dest/oracle_version.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const ORACLE_VERSION =
|
|
2
|
-
export declare const ORACLE_INTERFACE_HASH = "
|
|
1
|
+
export declare const ORACLE_VERSION = 18;
|
|
2
|
+
export declare const ORACLE_INTERFACE_HASH = "57e5b07c6d55fb167ef90f8d0f410f9bdb5b154a31159c624a061be40b02a2c2";
|
|
3
3
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3JhY2xlX3ZlcnNpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9vcmFjbGVfdmVyc2lvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxlQUFPLE1BQU0sY0FBYyxLQUFLLENBQUM7QUFLakMsZUFBTyxNQUFNLHFCQUFxQixxRUFBcUUsQ0FBQyJ9
|
package/dest/oracle_version.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
/// to version the oracle interface to ensure that developers get a reasonable error message if they use incompatible
|
|
3
3
|
/// versions of Aztec.nr and PXE. The Noir counterpart is in `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
4
4
|
///
|
|
5
|
-
/// @dev Whenever a contract function or Noir test is run, the `
|
|
5
|
+
/// @dev Whenever a contract function or Noir test is run, the `aztec_utl_assertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 18;
|
|
8
8
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
9
9
|
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
10
10
|
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
11
|
-
export const ORACLE_INTERFACE_HASH = '
|
|
11
|
+
export const ORACLE_INTERFACE_HASH = '57e5b07c6d55fb167ef90f8d0f410f9bdb5b154a31159c624a061be40b02a2c2';
|