@aztec/pxe 0.0.1-commit.c0b82b2 → 0.0.1-commit.c2eed6949
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/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 +50 -45
- 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 +30 -62
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +57 -39
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +134 -56
- 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 +6 -3
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +33 -19
- 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/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 +54 -54
- 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 +32 -80
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +192 -73
- 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 +51 -18
- 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
|
@@ -6,24 +6,27 @@ import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
|
6
6
|
import { LogLevels, type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
8
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
9
|
+
import { isProtocolContract } from '@aztec/protocol-contracts';
|
|
9
10
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
10
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
12
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
12
|
-
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
13
|
+
import type { CompleteAddress, ContractInstance, PartialAddress } from '@aztec/stdlib/contract';
|
|
13
14
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
14
15
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
15
16
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
16
|
-
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
17
|
+
import { type PublicKeys, computeAddressSecret } from '@aztec/stdlib/keys';
|
|
17
18
|
import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
|
|
18
19
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
19
20
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
20
21
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
21
|
-
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
22
|
+
import type { BlockHeader, Capsule, OffchainEffect } from '@aztec/stdlib/tx';
|
|
22
23
|
|
|
23
24
|
import type { AccessScopes } from '../../access_scopes.js';
|
|
24
25
|
import { createContractLogger, logContractMessage } from '../../contract_logging.js';
|
|
26
|
+
import type { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
25
27
|
import { EventService } from '../../events/event_service.js';
|
|
26
28
|
import { LogService } from '../../logs/log_service.js';
|
|
29
|
+
import { MessageContextService } from '../../messages/message_context_service.js';
|
|
27
30
|
import { NoteService } from '../../notes/note_service.js';
|
|
28
31
|
import { ORACLE_VERSION } from '../../oracle_version.js';
|
|
29
32
|
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
@@ -36,6 +39,7 @@ import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_
|
|
|
36
39
|
import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
|
|
37
40
|
import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
|
|
38
41
|
import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
|
|
42
|
+
import { MessageTxContext } from '../noir-structs/message_tx_context.js';
|
|
39
43
|
import { NoteValidationRequest } from '../noir-structs/note_validation_request.js';
|
|
40
44
|
import { UtilityContext } from '../noir-structs/utility_context.js';
|
|
41
45
|
import { pickNotes } from '../pick_notes.js';
|
|
@@ -58,6 +62,8 @@ export type UtilityExecutionOracleArgs = {
|
|
|
58
62
|
senderAddressBookStore: SenderAddressBookStore;
|
|
59
63
|
capsuleStore: CapsuleStore;
|
|
60
64
|
privateEventStore: PrivateEventStore;
|
|
65
|
+
messageContextService: MessageContextService;
|
|
66
|
+
contractSyncService: ContractSyncService;
|
|
61
67
|
jobId: string;
|
|
62
68
|
log?: ReturnType<typeof createLogger>;
|
|
63
69
|
scopes: AccessScopes;
|
|
@@ -71,6 +77,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
71
77
|
isUtility = true as const;
|
|
72
78
|
|
|
73
79
|
private contractLogger: Logger | undefined;
|
|
80
|
+
private offchainEffects: OffchainEffect[] = [];
|
|
74
81
|
|
|
75
82
|
protected readonly contractAddress: AztecAddress;
|
|
76
83
|
protected readonly authWitnesses: AuthWitness[];
|
|
@@ -85,8 +92,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
85
92
|
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
86
93
|
protected readonly capsuleStore: CapsuleStore;
|
|
87
94
|
protected readonly privateEventStore: PrivateEventStore;
|
|
95
|
+
protected readonly messageContextService: MessageContextService;
|
|
96
|
+
protected readonly contractSyncService: ContractSyncService;
|
|
88
97
|
protected readonly jobId: string;
|
|
89
|
-
protected
|
|
98
|
+
protected logger: ReturnType<typeof createLogger>;
|
|
90
99
|
protected readonly scopes: AccessScopes;
|
|
91
100
|
|
|
92
101
|
constructor(args: UtilityExecutionOracleArgs) {
|
|
@@ -103,22 +112,39 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
103
112
|
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
104
113
|
this.capsuleStore = args.capsuleStore;
|
|
105
114
|
this.privateEventStore = args.privateEventStore;
|
|
115
|
+
this.messageContextService = args.messageContextService;
|
|
116
|
+
this.contractSyncService = args.contractSyncService;
|
|
106
117
|
this.jobId = args.jobId;
|
|
107
|
-
this.
|
|
118
|
+
this.logger = args.log ?? createLogger('simulator:client_view_context');
|
|
108
119
|
this.scopes = args.scopes;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
|
-
public
|
|
122
|
+
public assertCompatibleOracleVersion(version: number): void {
|
|
123
|
+
// TODO(F-416): Remove this hack on v5 when protocol contracts are redeployed.
|
|
124
|
+
// Protocol contracts/canonical contracts shipped with committed bytecode that cannot be changed. Assert they use
|
|
125
|
+
// the expected pinned version or the current one. We want to allow for both the pinned and the current versions
|
|
126
|
+
// because we want this code to work with both the pinned and unpinned version since some branches do not have the
|
|
127
|
+
// pinned contracts (like e.g. next)
|
|
128
|
+
const LEGACY_ORACLE_VERSION = 12;
|
|
129
|
+
if (isProtocolContract(this.contractAddress)) {
|
|
130
|
+
if (version !== LEGACY_ORACLE_VERSION && version !== ORACLE_VERSION) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Expected legacy oracle version ${LEGACY_ORACLE_VERSION} or current oracle version ${ORACLE_VERSION} for alpha payload contract at ${this.contractAddress}, got ${version}.`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
112
138
|
if (version !== ORACLE_VERSION) {
|
|
113
139
|
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
|
|
114
140
|
}
|
|
115
141
|
}
|
|
116
142
|
|
|
117
|
-
public
|
|
143
|
+
public getRandomField(): Fr {
|
|
118
144
|
return Fr.random();
|
|
119
145
|
}
|
|
120
146
|
|
|
121
|
-
public
|
|
147
|
+
public getUtilityContext(): UtilityContext {
|
|
122
148
|
return new UtilityContext(this.anchorBlockHeader, this.contractAddress);
|
|
123
149
|
}
|
|
124
150
|
|
|
@@ -129,7 +155,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
129
155
|
* @throws If the keys are not registered in the key store.
|
|
130
156
|
* @throws If scopes are defined and the account is not in the scopes.
|
|
131
157
|
*/
|
|
132
|
-
public async
|
|
158
|
+
public async getKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
133
159
|
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
134
160
|
if (this.scopes !== 'ALL_SCOPES' && this.scopes.length > 0) {
|
|
135
161
|
let hasAccess = false;
|
|
@@ -147,16 +173,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
147
173
|
|
|
148
174
|
/**
|
|
149
175
|
* Fetches the index and sibling path of a leaf at a given block from the note hash tree.
|
|
150
|
-
* @param
|
|
151
|
-
* witness.
|
|
176
|
+
* @param blockHash - The hash of a block that contains the note hash tree root in which to find the
|
|
177
|
+
* membership witness.
|
|
152
178
|
* @param noteHash - The note hash to find in the note hash tree.
|
|
153
179
|
* @returns The membership witness containing the leaf index and sibling path
|
|
154
180
|
*/
|
|
155
|
-
public
|
|
156
|
-
|
|
181
|
+
public getNoteHashMembershipWitness(
|
|
182
|
+
blockHash: BlockHash,
|
|
157
183
|
noteHash: Fr,
|
|
158
184
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
159
|
-
return this
|
|
185
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
186
|
+
this.aztecNode.getNoteHashMembershipWitness(blockHash, noteHash),
|
|
187
|
+
);
|
|
160
188
|
}
|
|
161
189
|
|
|
162
190
|
/**
|
|
@@ -165,16 +193,21 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
165
193
|
* Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
|
|
166
194
|
* its block hash is appended as a new leaf to the archive tree.
|
|
167
195
|
*
|
|
168
|
-
* @param
|
|
196
|
+
* @param referenceBlockHash - The hash of a block that contains the archive tree root in which to find the membership
|
|
169
197
|
* witness.
|
|
170
198
|
* @param blockHash - The block hash to find in the archive tree.
|
|
171
199
|
* @returns The membership witness containing the leaf index and sibling path
|
|
172
200
|
*/
|
|
173
|
-
public
|
|
174
|
-
|
|
201
|
+
public getBlockHashMembershipWitness(
|
|
202
|
+
referenceBlockHash: BlockHash,
|
|
175
203
|
blockHash: BlockHash,
|
|
176
204
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
177
|
-
|
|
205
|
+
// Note that we validate that the reference block hash is at or before the anchor block - we don't test the block
|
|
206
|
+
// hash at all. If the block hash did not exist by the reference block hash, then the node will not return the
|
|
207
|
+
// membership witness as there is none.
|
|
208
|
+
return this.#queryWithBlockHashNotAfterAnchor(referenceBlockHash, () =>
|
|
209
|
+
this.aztecNode.getBlockHashMembershipWitness(referenceBlockHash, blockHash),
|
|
210
|
+
);
|
|
178
211
|
}
|
|
179
212
|
|
|
180
213
|
/**
|
|
@@ -183,11 +216,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
183
216
|
* @param nullifier - Nullifier we try to find witness for.
|
|
184
217
|
* @returns The nullifier membership witness (if found).
|
|
185
218
|
*/
|
|
186
|
-
public
|
|
219
|
+
public getNullifierMembershipWitness(
|
|
187
220
|
blockHash: BlockHash,
|
|
188
221
|
nullifier: Fr,
|
|
189
222
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
190
|
-
return this
|
|
223
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
224
|
+
this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier),
|
|
225
|
+
);
|
|
191
226
|
}
|
|
192
227
|
|
|
193
228
|
/**
|
|
@@ -199,11 +234,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
199
234
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
200
235
|
* we are trying to prove non-inclusion for.
|
|
201
236
|
*/
|
|
202
|
-
public
|
|
237
|
+
public getLowNullifierMembershipWitness(
|
|
203
238
|
blockHash: BlockHash,
|
|
204
239
|
nullifier: Fr,
|
|
205
240
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
206
|
-
return this
|
|
241
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
242
|
+
this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier),
|
|
243
|
+
);
|
|
207
244
|
}
|
|
208
245
|
|
|
209
246
|
/**
|
|
@@ -212,8 +249,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
212
249
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
213
250
|
* @returns - The witness
|
|
214
251
|
*/
|
|
215
|
-
public
|
|
216
|
-
return this
|
|
252
|
+
public getPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
253
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, () =>
|
|
254
|
+
this.aztecNode.getPublicDataWitness(blockHash, leafSlot),
|
|
255
|
+
);
|
|
217
256
|
}
|
|
218
257
|
|
|
219
258
|
/**
|
|
@@ -221,7 +260,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
221
260
|
* @param blockNumber - The number of a block of which to get the block header.
|
|
222
261
|
* @returns Block extracted from a block with block number `blockNumber`.
|
|
223
262
|
*/
|
|
224
|
-
public async
|
|
263
|
+
public async getBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
|
|
225
264
|
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
226
265
|
if (blockNumber > anchorBlockNumber) {
|
|
227
266
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
@@ -232,12 +271,18 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
232
271
|
}
|
|
233
272
|
|
|
234
273
|
/**
|
|
235
|
-
* Retrieve the
|
|
274
|
+
* Retrieve the public keys and partial address associated to a given address.
|
|
236
275
|
* @param account - The account address.
|
|
237
|
-
* @returns
|
|
276
|
+
* @returns The public keys and partial address, or `undefined` if the account is not registered.
|
|
238
277
|
*/
|
|
239
|
-
public
|
|
240
|
-
|
|
278
|
+
public async tryGetPublicKeysAndPartialAddress(
|
|
279
|
+
account: AztecAddress,
|
|
280
|
+
): Promise<{ publicKeys: PublicKeys; partialAddress: PartialAddress } | undefined> {
|
|
281
|
+
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
282
|
+
if (!completeAddress) {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
return { publicKeys: completeAddress.publicKeys, partialAddress: completeAddress.partialAddress };
|
|
241
286
|
}
|
|
242
287
|
|
|
243
288
|
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
@@ -256,11 +301,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
256
301
|
* @param address - Address.
|
|
257
302
|
* @returns A contract instance.
|
|
258
303
|
*/
|
|
259
|
-
public
|
|
260
|
-
return this.getContractInstance(address);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
protected async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
304
|
+
public async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
264
305
|
const instance = await this.contractStore.getContractInstance(address);
|
|
265
306
|
if (!instance) {
|
|
266
307
|
throw new Error(`No contract instance found for address ${address.toString()}`);
|
|
@@ -274,7 +315,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
274
315
|
* @param messageHash - Hash of the message to authenticate.
|
|
275
316
|
* @returns Authentication witness for the requested message hash.
|
|
276
317
|
*/
|
|
277
|
-
public
|
|
318
|
+
public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
278
319
|
return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
|
|
279
320
|
}
|
|
280
321
|
|
|
@@ -300,7 +341,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
300
341
|
* @param status - The status of notes to fetch.
|
|
301
342
|
* @returns Array of note data.
|
|
302
343
|
*/
|
|
303
|
-
public async
|
|
344
|
+
public async getNotes(
|
|
304
345
|
owner: AztecAddress | undefined,
|
|
305
346
|
storageSlot: Fr,
|
|
306
347
|
numSelects: number,
|
|
@@ -340,7 +381,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
340
381
|
* @param innerNullifier - The inner nullifier.
|
|
341
382
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
342
383
|
*/
|
|
343
|
-
public async
|
|
384
|
+
public async checkNullifierExists(innerNullifier: Fr) {
|
|
344
385
|
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
345
386
|
siloNullifier(this.contractAddress, innerNullifier!),
|
|
346
387
|
this.anchorBlockHeader.hash(),
|
|
@@ -352,19 +393,20 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
352
393
|
}
|
|
353
394
|
|
|
354
395
|
/**
|
|
355
|
-
*
|
|
396
|
+
* Returns the membership witness of an un-nullified L1 to L2 message.
|
|
356
397
|
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
357
398
|
* @param messageHash - Hash of the message.
|
|
358
399
|
* @param secret - Secret used to compute a nullifier.
|
|
359
400
|
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
360
401
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
361
402
|
*/
|
|
362
|
-
public async
|
|
403
|
+
public async getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
363
404
|
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
364
405
|
this.aztecNode,
|
|
365
406
|
contractAddress,
|
|
366
407
|
messageHash,
|
|
367
408
|
secret,
|
|
409
|
+
await this.anchorBlockHeader.hash(),
|
|
368
410
|
);
|
|
369
411
|
|
|
370
412
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
@@ -377,25 +419,27 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
377
419
|
* @param startStorageSlot - The starting storage slot.
|
|
378
420
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
379
421
|
*/
|
|
380
|
-
public
|
|
422
|
+
public storageRead(
|
|
381
423
|
blockHash: BlockHash,
|
|
382
424
|
contractAddress: AztecAddress,
|
|
383
425
|
startStorageSlot: Fr,
|
|
384
426
|
numberOfElements: number,
|
|
385
427
|
) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
428
|
+
return this.#queryWithBlockHashNotAfterAnchor(blockHash, async () => {
|
|
429
|
+
const slots = Array(numberOfElements)
|
|
430
|
+
.fill(0)
|
|
431
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
389
432
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
433
|
+
const values = await Promise.all(
|
|
434
|
+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
|
|
435
|
+
);
|
|
393
436
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
437
|
+
this.logger.debug(
|
|
438
|
+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
|
|
439
|
+
);
|
|
397
440
|
|
|
398
|
-
|
|
441
|
+
return values;
|
|
442
|
+
});
|
|
399
443
|
}
|
|
400
444
|
|
|
401
445
|
/**
|
|
@@ -414,7 +458,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
414
458
|
return this.contractLogger;
|
|
415
459
|
}
|
|
416
460
|
|
|
417
|
-
public async
|
|
461
|
+
public async log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
418
462
|
if (!LogLevels[level]) {
|
|
419
463
|
throw new Error(`Invalid log level: ${level}`);
|
|
420
464
|
}
|
|
@@ -422,7 +466,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
422
466
|
logContractMessage(logger, LogLevels[level], message, fields);
|
|
423
467
|
}
|
|
424
468
|
|
|
425
|
-
public async
|
|
469
|
+
public async fetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
426
470
|
const logService = new LogService(
|
|
427
471
|
this.aztecNode,
|
|
428
472
|
this.anchorBlockHeader,
|
|
@@ -432,7 +476,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
432
476
|
this.senderAddressBookStore,
|
|
433
477
|
this.addressStore,
|
|
434
478
|
this.jobId,
|
|
435
|
-
this.
|
|
479
|
+
this.logger.getBindings(),
|
|
436
480
|
);
|
|
437
481
|
|
|
438
482
|
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
@@ -448,10 +492,12 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
448
492
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
449
493
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
450
494
|
*/
|
|
451
|
-
public async
|
|
495
|
+
public async validateAndStoreEnqueuedNotesAndEvents(
|
|
452
496
|
contractAddress: AztecAddress,
|
|
453
497
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
454
498
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
499
|
+
maxNotePackedLen: number,
|
|
500
|
+
maxEventSerializedLen: number,
|
|
455
501
|
) {
|
|
456
502
|
// TODO(#10727): allow other contracts to store notes
|
|
457
503
|
if (!this.contractAddress.equals(contractAddress)) {
|
|
@@ -462,11 +508,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
462
508
|
// faster as we don't need to wait for the network round-trip.
|
|
463
509
|
const noteValidationRequests = (
|
|
464
510
|
await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
|
|
465
|
-
).map(NoteValidationRequest.fromFields);
|
|
511
|
+
).map(fields => NoteValidationRequest.fromFields(fields, maxNotePackedLen));
|
|
466
512
|
|
|
467
513
|
const eventValidationRequests = (
|
|
468
514
|
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
|
|
469
|
-
).map(EventValidationRequest.fromFields);
|
|
515
|
+
).map(fields => EventValidationRequest.fromFields(fields, maxEventSerializedLen));
|
|
470
516
|
|
|
471
517
|
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
472
518
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
@@ -504,7 +550,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
504
550
|
await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
|
|
505
551
|
}
|
|
506
552
|
|
|
507
|
-
public async
|
|
553
|
+
public async bulkRetrieveLogs(
|
|
508
554
|
contractAddress: AztecAddress,
|
|
509
555
|
logRetrievalRequestsArrayBaseSlot: Fr,
|
|
510
556
|
logRetrievalResponsesArrayBaseSlot: Fr,
|
|
@@ -529,7 +575,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
529
575
|
this.senderAddressBookStore,
|
|
530
576
|
this.addressStore,
|
|
531
577
|
this.jobId,
|
|
532
|
-
this.
|
|
578
|
+
this.logger.getBindings(),
|
|
533
579
|
);
|
|
534
580
|
|
|
535
581
|
const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
|
|
@@ -546,7 +592,48 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
546
592
|
);
|
|
547
593
|
}
|
|
548
594
|
|
|
549
|
-
public
|
|
595
|
+
public async utilityResolveMessageContexts(
|
|
596
|
+
contractAddress: AztecAddress,
|
|
597
|
+
messageContextRequestsArrayBaseSlot: Fr,
|
|
598
|
+
messageContextResponsesArrayBaseSlot: Fr,
|
|
599
|
+
) {
|
|
600
|
+
try {
|
|
601
|
+
if (!this.contractAddress.equals(contractAddress)) {
|
|
602
|
+
throw new Error(`Got a message context request from ${contractAddress}, expected ${this.contractAddress}`);
|
|
603
|
+
}
|
|
604
|
+
const requestCapsules = await this.capsuleStore.readCapsuleArray(
|
|
605
|
+
contractAddress,
|
|
606
|
+
messageContextRequestsArrayBaseSlot,
|
|
607
|
+
this.jobId,
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
const txHashes = requestCapsules.map((fields, i) => {
|
|
611
|
+
if (fields.length !== 1) {
|
|
612
|
+
throw new Error(
|
|
613
|
+
`Malformed message context request at index ${i}: expected 1 field (tx hash), got ${fields.length}`,
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
return fields[0];
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
const maybeMessageContexts = await this.messageContextService.resolveMessageContexts(
|
|
620
|
+
txHashes,
|
|
621
|
+
this.anchorBlockHeader.getBlockNumber(),
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
// Leave response in response capsule array.
|
|
625
|
+
await this.capsuleStore.setCapsuleArray(
|
|
626
|
+
contractAddress,
|
|
627
|
+
messageContextResponsesArrayBaseSlot,
|
|
628
|
+
maybeMessageContexts.map(MessageTxContext.toSerializedOption),
|
|
629
|
+
this.jobId,
|
|
630
|
+
);
|
|
631
|
+
} finally {
|
|
632
|
+
await this.capsuleStore.setCapsuleArray(contractAddress, messageContextRequestsArrayBaseSlot, [], this.jobId);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
public storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
|
|
550
637
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
551
638
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
552
639
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -555,7 +642,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
555
642
|
return Promise.resolve();
|
|
556
643
|
}
|
|
557
644
|
|
|
558
|
-
public async
|
|
645
|
+
public async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
|
|
559
646
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
560
647
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
561
648
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -567,7 +654,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
567
654
|
);
|
|
568
655
|
}
|
|
569
656
|
|
|
570
|
-
public
|
|
657
|
+
public deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
|
|
571
658
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
572
659
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
573
660
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -576,12 +663,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
576
663
|
return Promise.resolve();
|
|
577
664
|
}
|
|
578
665
|
|
|
579
|
-
public
|
|
580
|
-
contractAddress: AztecAddress,
|
|
581
|
-
srcSlot: Fr,
|
|
582
|
-
dstSlot: Fr,
|
|
583
|
-
numEntries: number,
|
|
584
|
-
): Promise<void> {
|
|
666
|
+
public copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
|
|
585
667
|
if (!contractAddress.equals(this.contractAddress)) {
|
|
586
668
|
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
|
|
587
669
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
@@ -589,8 +671,19 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
589
671
|
return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
|
|
590
672
|
}
|
|
591
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Clears cached sync state for a contract for a set of scopes, forcing re-sync on the next query so that newly
|
|
676
|
+
* stored notes or events are discovered.
|
|
677
|
+
*/
|
|
678
|
+
public invalidateContractSyncCache(contractAddress: AztecAddress, scopes: AztecAddress[]): void {
|
|
679
|
+
if (!contractAddress.equals(this.contractAddress)) {
|
|
680
|
+
throw new Error(`Contract ${this.contractAddress} cannot invalidate sync cache of ${contractAddress}`);
|
|
681
|
+
}
|
|
682
|
+
this.contractSyncService.invalidateContractForScopes(contractAddress, scopes);
|
|
683
|
+
}
|
|
684
|
+
|
|
592
685
|
// TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
|
|
593
|
-
public
|
|
686
|
+
public aes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer> {
|
|
594
687
|
const aes128 = new Aes128();
|
|
595
688
|
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
596
689
|
}
|
|
@@ -601,11 +694,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
601
694
|
* @param ephPk - The ephemeral public key to get the secret for.
|
|
602
695
|
* @returns The secret for the given address.
|
|
603
696
|
*/
|
|
604
|
-
public
|
|
605
|
-
return this.getSharedSecret(address, ephPk);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
697
|
+
public async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
609
698
|
// TODO(#12656): return an app-siloed secret
|
|
610
699
|
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
611
700
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
@@ -614,4 +703,34 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
614
703
|
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
615
704
|
return deriveEcdhSharedSecret(addressSecret, ephPk);
|
|
616
705
|
}
|
|
706
|
+
|
|
707
|
+
public emitOffchainEffect(data: Fr[]): Promise<void> {
|
|
708
|
+
this.offchainEffects.push({ data, contractAddress: this.contractAddress });
|
|
709
|
+
return Promise.resolve();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/** Returns offchain effects collected during execution. */
|
|
713
|
+
public getOffchainEffects(): OffchainEffect[] {
|
|
714
|
+
return this.offchainEffects;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** Runs a query concurrently with a validation that the block hash is not ahead of the anchor block. */
|
|
718
|
+
async #queryWithBlockHashNotAfterAnchor<T>(blockHash: BlockHash, query: () => Promise<T>): Promise<T> {
|
|
719
|
+
const [response] = await Promise.all([
|
|
720
|
+
query(),
|
|
721
|
+
(async () => {
|
|
722
|
+
const header = await this.aztecNode.getBlockHeader(blockHash);
|
|
723
|
+
if (!header) {
|
|
724
|
+
throw new Error(`Could not find block header for block hash ${blockHash}`);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (header.getBlockNumber() > this.anchorBlockHeader.getBlockNumber()) {
|
|
728
|
+
throw new Error(
|
|
729
|
+
`Made a node query with a reference block hash ${blockHash} with block number ${header.getBlockNumber()}, which is ahead of the anchor block number ${this.anchorBlockHeader.getBlockNumber()} (from anchor block hash ${await this.anchorBlockHeader.hash()}).`,
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
})(),
|
|
733
|
+
]);
|
|
734
|
+
return response;
|
|
735
|
+
}
|
|
617
736
|
}
|