@aztec/pxe 0.0.1-commit.3469e52 → 0.0.1-commit.54489865
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/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +7 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +56 -16
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +5 -8
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +13 -10
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +5 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +27 -17
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +9 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +16 -5
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +20 -12
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +36 -38
- package/dest/contract_sync/index.d.ts +23 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/index.js +54 -0
- package/dest/debug/pxe_debug_utils.d.ts +16 -6
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +20 -10
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +10 -5
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +11 -6
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +19 -8
- package/dest/events/event_service.d.ts +2 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +1 -1
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +19 -13
- package/dest/notes/note_service.d.ts +4 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +11 -10
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +18 -14
- package/dest/storage/contract_store/contract_store.d.ts +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +0 -12
- package/dest/storage/note_store/note_store.d.ts +43 -55
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +235 -251
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +158 -132
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +2 -1
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- 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 +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
- 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 +7 -4
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +70 -33
- package/src/config/index.ts +14 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +7 -11
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +18 -9
- package/src/contract_function_simulator/oracle/oracle.ts +34 -21
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +32 -6
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +55 -45
- package/src/contract_sync/index.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +26 -11
- package/src/entrypoints/client/bundle/utils.ts +4 -13
- package/src/entrypoints/client/lazy/utils.ts +5 -13
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +15 -19
- package/src/events/event_service.ts +1 -1
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +30 -11
- package/src/notes/note_service.ts +18 -15
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
- package/src/private_kernel/private_kernel_oracle.ts +2 -2
- package/src/pxe.ts +48 -16
- package/src/storage/contract_store/contract_store.ts +0 -20
- package/src/storage/note_store/note_store.ts +273 -312
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +204 -167
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +1 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
- package/dest/tree_membership/tree_membership_service.d.ts +0 -50
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -75
- package/src/tree_membership/tree_membership_service.ts +0 -97
|
@@ -12,9 +12,8 @@ import {
|
|
|
12
12
|
} from '@aztec/simulator/client';
|
|
13
13
|
import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
14
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
|
-
import {
|
|
15
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
16
16
|
import { ContractClassLog, ContractClassLogFields } from '@aztec/stdlib/logs';
|
|
17
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
18
17
|
|
|
19
18
|
import type { IMiscOracle, IPrivateExecutionOracle, IUtilityExecutionOracle } from './interfaces.js';
|
|
20
19
|
import { packAsHintedNote } from './note_packing_utils.js';
|
|
@@ -138,33 +137,39 @@ export class Oracle {
|
|
|
138
137
|
].map(toACVMField);
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
async
|
|
140
|
+
async utilityGetNoteHashMembershipWitness(
|
|
142
141
|
[blockHash]: ACVMField[],
|
|
143
|
-
[treeId]: ACVMField[],
|
|
144
142
|
[leafValue]: ACVMField[],
|
|
145
143
|
): Promise<(ACVMField | ACVMField[])[]> {
|
|
146
|
-
const parsedBlockHash =
|
|
147
|
-
const parsedTreeId = Fr.fromString(treeId).toNumber();
|
|
144
|
+
const parsedBlockHash = BlockHash.fromString(blockHash);
|
|
148
145
|
const parsedLeafValue = Fr.fromString(leafValue);
|
|
149
146
|
|
|
150
|
-
const witness = await this.handlerAsUtility().
|
|
151
|
-
parsedBlockHash,
|
|
152
|
-
parsedTreeId,
|
|
153
|
-
parsedLeafValue,
|
|
154
|
-
);
|
|
147
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(parsedBlockHash, parsedLeafValue);
|
|
155
148
|
if (!witness) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
|
|
158
|
-
|
|
149
|
+
throw new Error(`Leaf ${leafValue} not found in the note hash tree at block hash ${parsedBlockHash.toString()}.`);
|
|
150
|
+
}
|
|
151
|
+
return witness.toNoirRepresentation();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async utilityGetArchiveMembershipWitness(
|
|
155
|
+
[blockHash]: ACVMField[],
|
|
156
|
+
[leafValue]: ACVMField[],
|
|
157
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
158
|
+
const parsedBlockHash = BlockHash.fromString(blockHash);
|
|
159
|
+
const parsedLeafValue = Fr.fromString(leafValue);
|
|
160
|
+
|
|
161
|
+
const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(parsedBlockHash, parsedLeafValue);
|
|
162
|
+
if (!witness) {
|
|
163
|
+
throw new Error(`Leaf ${leafValue} not found in the archive tree at block hash ${parsedBlockHash.toString()}.`);
|
|
159
164
|
}
|
|
160
|
-
return
|
|
165
|
+
return witness.toNoirRepresentation();
|
|
161
166
|
}
|
|
162
167
|
|
|
163
168
|
async utilityGetNullifierMembershipWitness(
|
|
164
169
|
[blockHash]: ACVMField[],
|
|
165
170
|
[nullifier]: ACVMField[], // nullifier, we try to find the witness for (to prove inclusion)
|
|
166
171
|
): Promise<(ACVMField | ACVMField[])[]> {
|
|
167
|
-
const parsedBlockHash =
|
|
172
|
+
const parsedBlockHash = BlockHash.fromString(blockHash);
|
|
168
173
|
const parsedNullifier = Fr.fromString(nullifier);
|
|
169
174
|
|
|
170
175
|
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(
|
|
@@ -183,7 +188,7 @@ export class Oracle {
|
|
|
183
188
|
[blockHash]: ACVMField[],
|
|
184
189
|
[nullifier]: ACVMField[], // nullifier, we try to find the low nullifier witness for (to prove non-inclusion)
|
|
185
190
|
): Promise<(ACVMField | ACVMField[])[]> {
|
|
186
|
-
const parsedBlockHash =
|
|
191
|
+
const parsedBlockHash = BlockHash.fromString(blockHash);
|
|
187
192
|
const parsedNullifier = Fr.fromString(nullifier);
|
|
188
193
|
|
|
189
194
|
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
@@ -202,7 +207,7 @@ export class Oracle {
|
|
|
202
207
|
[blockHash]: ACVMField[],
|
|
203
208
|
[leafSlot]: ACVMField[],
|
|
204
209
|
): Promise<(ACVMField | ACVMField[])[]> {
|
|
205
|
-
const parsedBlockHash =
|
|
210
|
+
const parsedBlockHash = BlockHash.fromString(blockHash);
|
|
206
211
|
const parsedLeafSlot = Fr.fromString(leafSlot);
|
|
207
212
|
|
|
208
213
|
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(parsedBlockHash, parsedLeafSlot);
|
|
@@ -341,6 +346,14 @@ export class Oracle {
|
|
|
341
346
|
return [];
|
|
342
347
|
}
|
|
343
348
|
|
|
349
|
+
async privateIsNullifierPending([innerNullifier]: ACVMField[], [contractAddress]: ACVMField[]): Promise<ACVMField[]> {
|
|
350
|
+
const isPending = await this.handlerAsPrivate().privateIsNullifierPending(
|
|
351
|
+
Fr.fromString(innerNullifier),
|
|
352
|
+
AztecAddress.fromString(contractAddress),
|
|
353
|
+
);
|
|
354
|
+
return [toACVMField(isPending)];
|
|
355
|
+
}
|
|
356
|
+
|
|
344
357
|
async utilityCheckNullifierExists([innerNullifier]: ACVMField[]): Promise<ACVMField[]> {
|
|
345
358
|
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(Fr.fromString(innerNullifier));
|
|
346
359
|
return [toACVMField(exists)];
|
|
@@ -366,7 +379,7 @@ export class Oracle {
|
|
|
366
379
|
[numberOfElements]: ACVMField[],
|
|
367
380
|
): Promise<ACVMField[][]> {
|
|
368
381
|
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
369
|
-
|
|
382
|
+
BlockHash.fromString(blockHash),
|
|
370
383
|
new AztecAddress(Fr.fromString(contractAddress)),
|
|
371
384
|
Fr.fromString(startStorageSlot),
|
|
372
385
|
+numberOfElements,
|
|
@@ -478,12 +491,12 @@ export class Oracle {
|
|
|
478
491
|
return [];
|
|
479
492
|
}
|
|
480
493
|
|
|
481
|
-
async
|
|
494
|
+
async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
482
495
|
[contractAddress]: ACVMField[],
|
|
483
496
|
[noteValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
484
497
|
[eventValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
485
498
|
): Promise<ACVMField[]> {
|
|
486
|
-
await this.handlerAsUtility().
|
|
499
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
487
500
|
AztecAddress.fromString(contractAddress),
|
|
488
501
|
Fr.fromString(noteValidationRequestsArrayBaseSlot),
|
|
489
502
|
Fr.fromString(eventValidationRequestsArrayBaseSlot),
|
|
@@ -2,7 +2,6 @@ import { PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, PRIVATE_CONTEXT_INPUTS_LENGTH } f
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
6
5
|
import {
|
|
7
6
|
type ACVMWitness,
|
|
8
7
|
type CircuitSimulator,
|
|
@@ -18,15 +17,10 @@ import {
|
|
|
18
17
|
countArgumentsSize,
|
|
19
18
|
} from '@aztec/stdlib/abi';
|
|
20
19
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
22
|
-
import type { ContractInstance } from '@aztec/stdlib/contract';
|
|
23
|
-
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
24
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
25
20
|
import { PrivateCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
26
21
|
import type { CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
|
|
27
|
-
import {
|
|
22
|
+
import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
|
|
28
23
|
|
|
29
|
-
import { ContractStore } from '../../storage/contract_store/index.js';
|
|
30
24
|
import { Oracle } from './oracle.js';
|
|
31
25
|
import type { PrivateExecutionOracle } from './private_execution_oracle.js';
|
|
32
26
|
|
|
@@ -145,56 +139,3 @@ export function extractPrivateCircuitPublicInputs(
|
|
|
145
139
|
}
|
|
146
140
|
return PrivateCircuitPublicInputs.fromFields(returnData);
|
|
147
141
|
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
|
|
151
|
-
* from the instance is used.
|
|
152
|
-
* @param contractAddress - The address of the contract to read the class id for.
|
|
153
|
-
* @param instance - The instance of the contract.
|
|
154
|
-
* @param aztecNode - The Aztec node to query for storage.
|
|
155
|
-
* @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
|
|
156
|
-
* @returns The current class id.
|
|
157
|
-
*/
|
|
158
|
-
export async function readCurrentClassId(
|
|
159
|
-
contractAddress: AztecAddress,
|
|
160
|
-
instance: ContractInstance,
|
|
161
|
-
aztecNode: AztecNode,
|
|
162
|
-
header: BlockHeader,
|
|
163
|
-
) {
|
|
164
|
-
const blockHashFr = await header.hash();
|
|
165
|
-
const blockHash = L2BlockHash.fromField(blockHashFr);
|
|
166
|
-
const timestamp = header.globalVariables.timestamp;
|
|
167
|
-
const { delayedPublicMutableSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
|
|
168
|
-
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, slot =>
|
|
169
|
-
aztecNode.getPublicStorageAt(blockHash, ProtocolContractAddress.ContractInstanceRegistry, slot),
|
|
170
|
-
);
|
|
171
|
-
let currentClassId = delayedPublicMutableValues.svc.getCurrentAt(timestamp)[0];
|
|
172
|
-
if (currentClassId.isZero()) {
|
|
173
|
-
currentClassId = instance.originalContractClassId;
|
|
174
|
-
}
|
|
175
|
-
return currentClassId;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
|
|
180
|
-
* provider (i.e. PXE's own storage).
|
|
181
|
-
* @param header - The header of the block at which to verify the current class id.
|
|
182
|
-
*/
|
|
183
|
-
export async function verifyCurrentClassId(
|
|
184
|
-
contractAddress: AztecAddress,
|
|
185
|
-
aztecNode: AztecNode,
|
|
186
|
-
contractStore: ContractStore,
|
|
187
|
-
header: BlockHeader,
|
|
188
|
-
) {
|
|
189
|
-
const instance = await contractStore.getContractInstance(contractAddress);
|
|
190
|
-
if (!instance) {
|
|
191
|
-
throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
|
|
195
|
-
if (!instance.currentContractClassId.equals(currentClassId)) {
|
|
196
|
-
throw new Error(
|
|
197
|
-
`Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`,
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
type TxContext,
|
|
31
31
|
} from '@aztec/stdlib/tx';
|
|
32
32
|
|
|
33
|
+
import { ensureContractSynced } from '../../contract_sync/index.js';
|
|
33
34
|
import { NoteService } from '../../notes/note_service.js';
|
|
34
35
|
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
35
36
|
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
|
|
@@ -46,7 +47,7 @@ import { ExecutionTaggingIndexCache } from '../execution_tagging_index_cache.js'
|
|
|
46
47
|
import type { HashedValuesCache } from '../hashed_values_cache.js';
|
|
47
48
|
import { pickNotes } from '../pick_notes.js';
|
|
48
49
|
import type { IPrivateExecutionOracle, NoteData } from './interfaces.js';
|
|
49
|
-
import { executePrivateFunction
|
|
50
|
+
import { executePrivateFunction } from './private_execution.js';
|
|
50
51
|
import { UtilityExecutionOracle } from './utility_execution_oracle.js';
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -265,7 +266,14 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
265
266
|
// This is a tagging secret we've not yet used in this tx, so first sync our store to make sure its indices
|
|
266
267
|
// are up to date. We do this here because this store is not synced as part of the global sync because
|
|
267
268
|
// that'd be wasteful as most tagging secrets are not used in each tx.
|
|
268
|
-
await syncSenderTaggingIndexes(
|
|
269
|
+
await syncSenderTaggingIndexes(
|
|
270
|
+
secret,
|
|
271
|
+
this.contractAddress,
|
|
272
|
+
this.aztecNode,
|
|
273
|
+
this.senderTaggingStore,
|
|
274
|
+
await this.anchorBlockHeader.hash(),
|
|
275
|
+
this.jobId,
|
|
276
|
+
);
|
|
269
277
|
|
|
270
278
|
const lastUsedIndex = await this.senderTaggingStore.getLastUsedIndex(secret, this.jobId);
|
|
271
279
|
// If lastUsedIndex is undefined, we've never used this secret, so start from 0
|
|
@@ -356,7 +364,7 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
356
364
|
|
|
357
365
|
const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.contractAddress);
|
|
358
366
|
|
|
359
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore);
|
|
367
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
|
|
360
368
|
const dbNotes = await noteService.getNotes(
|
|
361
369
|
this.callContext.contractAddress,
|
|
362
370
|
owner,
|
|
@@ -463,6 +471,19 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
463
471
|
return this.noteCache.nullifierCreated(this.callContext.contractAddress, innerNullifier);
|
|
464
472
|
}
|
|
465
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Check if a nullifier has been emitted in the same transaction, i.e. if privateNotifyCreatedNullifier has been
|
|
476
|
+
* called for this inner nullifier from the contract with the specified address.
|
|
477
|
+
* @param innerNullifier - The inner nullifier to check.
|
|
478
|
+
* @param contractAddress - Address of the contract that emitted the nullifier.
|
|
479
|
+
* @returns A boolean indicating whether the nullifier is pending or not.
|
|
480
|
+
*/
|
|
481
|
+
public async privateIsNullifierPending(innerNullifier: Fr, contractAddress: AztecAddress): Promise<boolean> {
|
|
482
|
+
const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
|
|
483
|
+
const isNullifierPending = this.noteCache.getNullifiers(contractAddress).has(siloedNullifier.toBigInt());
|
|
484
|
+
return Promise.resolve(isNullifierPending);
|
|
485
|
+
}
|
|
486
|
+
|
|
466
487
|
/**
|
|
467
488
|
* Emit a contract class log.
|
|
468
489
|
* This fn exists because we only carry a poseidon hash through the kernels, and need to
|
|
@@ -519,9 +540,14 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
|
|
|
519
540
|
|
|
520
541
|
isStaticCall = isStaticCall || this.callContext.isStaticCall;
|
|
521
542
|
|
|
522
|
-
await
|
|
523
|
-
|
|
524
|
-
|
|
543
|
+
await ensureContractSynced(
|
|
544
|
+
targetContractAddress,
|
|
545
|
+
functionSelector,
|
|
546
|
+
this.utilityExecutor,
|
|
547
|
+
this.aztecNode,
|
|
548
|
+
this.contractStore,
|
|
549
|
+
this.anchorBlockHeader,
|
|
550
|
+
);
|
|
525
551
|
|
|
526
552
|
const targetArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(
|
|
527
553
|
targetContractAddress,
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import type { ARCHIVE_HEIGHT, NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
1
2
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Aes128 } from '@aztec/foundation/crypto/aes128';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
5
6
|
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
6
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
7
9
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
8
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import {
|
|
11
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
10
12
|
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
11
13
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
14
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
13
15
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
14
16
|
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
15
17
|
import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
|
|
18
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
16
19
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
17
20
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
18
21
|
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
@@ -29,7 +32,6 @@ import type { NoteStore } from '../../storage/note_store/note_store.js';
|
|
|
29
32
|
import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
|
|
30
33
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
31
34
|
import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_address_book_store.js';
|
|
32
|
-
import { TreeMembershipService } from '../../tree_membership/tree_membership_service.js';
|
|
33
35
|
import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
|
|
34
36
|
import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
|
|
35
37
|
import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
|
|
@@ -94,15 +96,29 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
/**
|
|
97
|
-
* Fetches the index and sibling path of a leaf at a given block from
|
|
99
|
+
* Fetches the index and sibling path of a leaf at a given block from the note hash tree.
|
|
98
100
|
* @param blockHash - The block hash at which to get the membership witness.
|
|
99
|
-
* @param treeId - Id of the tree to get the sibling path from.
|
|
100
101
|
* @param leafValue - The leaf value
|
|
101
|
-
* @returns The index and sibling path
|
|
102
|
+
* @returns The membership witness containing the leaf index and sibling path
|
|
102
103
|
*/
|
|
103
|
-
public
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
public utilityGetNoteHashMembershipWitness(
|
|
105
|
+
blockHash: BlockHash,
|
|
106
|
+
leafValue: Fr,
|
|
107
|
+
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
108
|
+
return this.aztecNode.getNoteHashMembershipWitness(blockHash, leafValue);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Fetches the index and sibling path of a leaf at a given block from the archive tree.
|
|
113
|
+
* @param blockHash - The block hash at which to get the membership witness.
|
|
114
|
+
* @param leafValue - The leaf value
|
|
115
|
+
* @returns The membership witness containing the leaf index and sibling path
|
|
116
|
+
*/
|
|
117
|
+
public utilityGetArchiveMembershipWitness(
|
|
118
|
+
blockHash: BlockHash,
|
|
119
|
+
leafValue: Fr,
|
|
120
|
+
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
121
|
+
return this.aztecNode.getArchiveMembershipWitness(blockHash, leafValue);
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
/**
|
|
@@ -111,11 +127,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
111
127
|
* @param nullifier - Nullifier we try to find witness for.
|
|
112
128
|
* @returns The nullifier membership witness (if found).
|
|
113
129
|
*/
|
|
114
|
-
public
|
|
115
|
-
blockHash:
|
|
130
|
+
public utilityGetNullifierMembershipWitness(
|
|
131
|
+
blockHash: BlockHash,
|
|
116
132
|
nullifier: Fr,
|
|
117
133
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
118
|
-
return
|
|
134
|
+
return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
/**
|
|
@@ -127,12 +143,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
127
143
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
128
144
|
* we are trying to prove non-inclusion for.
|
|
129
145
|
*/
|
|
130
|
-
public
|
|
131
|
-
blockHash:
|
|
146
|
+
public utilityGetLowNullifierMembershipWitness(
|
|
147
|
+
blockHash: BlockHash,
|
|
132
148
|
nullifier: Fr,
|
|
133
149
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
134
|
-
|
|
135
|
-
return await treeMembershipService.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
150
|
+
return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
136
151
|
}
|
|
137
152
|
|
|
138
153
|
/**
|
|
@@ -141,12 +156,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
141
156
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
142
157
|
* @returns - The witness
|
|
143
158
|
*/
|
|
144
|
-
public
|
|
145
|
-
blockHash
|
|
146
|
-
leafSlot: Fr,
|
|
147
|
-
): Promise<PublicDataWitness | undefined> {
|
|
148
|
-
const treeMembershipService = new TreeMembershipService(this.aztecNode);
|
|
149
|
-
return await treeMembershipService.getPublicDataWitness(blockHash, leafSlot);
|
|
159
|
+
public utilityGetPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
160
|
+
return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
|
|
150
161
|
}
|
|
151
162
|
|
|
152
163
|
/**
|
|
@@ -251,7 +262,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
251
262
|
offset: number,
|
|
252
263
|
status: NoteStatus,
|
|
253
264
|
): Promise<NoteData[]> {
|
|
254
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore);
|
|
265
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
|
|
255
266
|
|
|
256
267
|
const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
|
|
257
268
|
return pickNotes<NoteData>(dbNotes, {
|
|
@@ -276,9 +287,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
276
287
|
*/
|
|
277
288
|
public async utilityCheckNullifierExists(innerNullifier: Fr) {
|
|
278
289
|
const nullifier = await siloNullifier(this.contractAddress, innerNullifier!);
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
return index !== undefined;
|
|
290
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [nullifier]);
|
|
291
|
+
return leafIndex?.data !== undefined;
|
|
282
292
|
}
|
|
283
293
|
|
|
284
294
|
/**
|
|
@@ -290,14 +300,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
290
300
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
291
301
|
*/
|
|
292
302
|
public async utilityGetL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
293
|
-
const
|
|
294
|
-
|
|
303
|
+
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
304
|
+
this.aztecNode,
|
|
295
305
|
contractAddress,
|
|
296
306
|
messageHash,
|
|
297
307
|
secret,
|
|
298
308
|
);
|
|
299
309
|
|
|
300
|
-
// Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
|
|
301
310
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
302
311
|
}
|
|
303
312
|
|
|
@@ -309,24 +318,23 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
309
318
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
310
319
|
*/
|
|
311
320
|
public async utilityStorageRead(
|
|
312
|
-
blockHash:
|
|
321
|
+
blockHash: BlockHash,
|
|
313
322
|
contractAddress: AztecAddress,
|
|
314
323
|
startStorageSlot: Fr,
|
|
315
324
|
numberOfElements: number,
|
|
316
325
|
) {
|
|
317
|
-
const
|
|
326
|
+
const slots = Array(numberOfElements)
|
|
327
|
+
.fill(0)
|
|
328
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
318
329
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
330
|
+
const values = await Promise.all(
|
|
331
|
+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
this.log.debug(
|
|
335
|
+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
|
|
336
|
+
);
|
|
324
337
|
|
|
325
|
-
this.log.debug(
|
|
326
|
-
`Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
|
|
327
|
-
);
|
|
328
|
-
values.push(value);
|
|
329
|
-
}
|
|
330
338
|
return values;
|
|
331
339
|
}
|
|
332
340
|
|
|
@@ -348,9 +356,10 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
348
356
|
this.senderAddressBookStore,
|
|
349
357
|
this.addressStore,
|
|
350
358
|
this.jobId,
|
|
359
|
+
this.log.getBindings(),
|
|
351
360
|
);
|
|
352
361
|
|
|
353
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore);
|
|
362
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
|
|
354
363
|
|
|
355
364
|
// It is acceptable to run the following operations in parallel for several reasons:
|
|
356
365
|
// 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
|
|
@@ -372,7 +381,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
372
381
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
373
382
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
374
383
|
*/
|
|
375
|
-
public async
|
|
384
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
376
385
|
contractAddress: AztecAddress,
|
|
377
386
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
378
387
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
@@ -392,9 +401,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
392
401
|
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
|
|
393
402
|
).map(EventValidationRequest.fromFields);
|
|
394
403
|
|
|
395
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore);
|
|
404
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore, this.jobId);
|
|
396
405
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
397
|
-
noteService.
|
|
406
|
+
noteService.validateAndStoreNote(
|
|
398
407
|
request.contractAddress,
|
|
399
408
|
request.owner,
|
|
400
409
|
request.storageSlot,
|
|
@@ -410,7 +419,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
410
419
|
|
|
411
420
|
const eventService = new EventService(this.anchorBlockStore, this.aztecNode, this.privateEventStore, this.jobId);
|
|
412
421
|
const eventStorePromises = eventValidationRequests.map(request =>
|
|
413
|
-
eventService.
|
|
422
|
+
eventService.validateAndStoreEvent(
|
|
414
423
|
request.contractAddress,
|
|
415
424
|
request.eventTypeId,
|
|
416
425
|
request.randomness,
|
|
@@ -453,6 +462,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
453
462
|
this.senderAddressBookStore,
|
|
454
463
|
this.addressStore,
|
|
455
464
|
this.jobId,
|
|
465
|
+
this.log.getBindings(),
|
|
456
466
|
);
|
|
457
467
|
|
|
458
468
|
const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ProtocolContractAddress, isProtocolContract } from '@aztec/protocol-contracts';
|
|
2
|
+
import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstance } from '@aztec/stdlib/contract';
|
|
5
|
+
import { DelayedPublicMutableValues, DelayedPublicMutableValuesWithHash } from '@aztec/stdlib/delayed-public-mutable';
|
|
6
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
|
+
|
|
9
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Read the current class id of a contract from the execution data provider or AztecNode. If not found, class id
|
|
13
|
+
* from the instance is used.
|
|
14
|
+
* @param contractAddress - The address of the contract to read the class id for.
|
|
15
|
+
* @param instance - The instance of the contract.
|
|
16
|
+
* @param aztecNode - The Aztec node to query for storage.
|
|
17
|
+
* @param header - The header of the block at which to load the DelayedPublicMutable storing the class id.
|
|
18
|
+
* @returns The current class id.
|
|
19
|
+
*/
|
|
20
|
+
export async function readCurrentClassId(
|
|
21
|
+
contractAddress: AztecAddress,
|
|
22
|
+
instance: ContractInstance,
|
|
23
|
+
aztecNode: AztecNode,
|
|
24
|
+
header: BlockHeader,
|
|
25
|
+
) {
|
|
26
|
+
const blockHash = await header.hash();
|
|
27
|
+
const timestamp = header.globalVariables.timestamp;
|
|
28
|
+
const { delayedPublicMutableSlot } = await DelayedPublicMutableValuesWithHash.getContractUpdateSlots(contractAddress);
|
|
29
|
+
const delayedPublicMutableValues = await DelayedPublicMutableValues.readFromTree(delayedPublicMutableSlot, slot =>
|
|
30
|
+
aztecNode.getPublicStorageAt(blockHash, ProtocolContractAddress.ContractInstanceRegistry, slot),
|
|
31
|
+
);
|
|
32
|
+
let currentClassId = delayedPublicMutableValues.svc.getCurrentAt(timestamp)[0];
|
|
33
|
+
if (currentClassId.isZero()) {
|
|
34
|
+
currentClassId = instance.originalContractClassId;
|
|
35
|
+
}
|
|
36
|
+
return currentClassId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function syncState(
|
|
40
|
+
contractAddress: AztecAddress,
|
|
41
|
+
contractStore: ContractStore,
|
|
42
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
43
|
+
utilityExecutor: (privateSyncCall: FunctionCall) => Promise<any>,
|
|
44
|
+
) {
|
|
45
|
+
// Protocol contracts don't have private state to sync
|
|
46
|
+
if (!isProtocolContract(contractAddress)) {
|
|
47
|
+
const syncStateFunctionCall = await contractStore.getFunctionCall('sync_state', [], contractAddress);
|
|
48
|
+
if (functionToInvokeAfterSync && functionToInvokeAfterSync.equals(syncStateFunctionCall.selector)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
'Forbidden `sync_state` invocation. `sync_state` can only be invoked by PXE, manual execution can lead to inconsistencies.',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return utilityExecutor(syncStateFunctionCall);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Verify that the current class id of a contract obtained from AztecNode is the same as the one in contract data
|
|
60
|
+
* provider (i.e. PXE's own storage).
|
|
61
|
+
* @param header - The header of the block at which to verify the current class id.
|
|
62
|
+
*/
|
|
63
|
+
async function verifyCurrentClassId(
|
|
64
|
+
contractAddress: AztecAddress,
|
|
65
|
+
aztecNode: AztecNode,
|
|
66
|
+
contractStore: ContractStore,
|
|
67
|
+
header: BlockHeader,
|
|
68
|
+
) {
|
|
69
|
+
const instance = await contractStore.getContractInstance(contractAddress);
|
|
70
|
+
if (!instance) {
|
|
71
|
+
throw new Error(`No contract instance found for address ${contractAddress.toString()}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const currentClassId = await readCurrentClassId(contractAddress, instance, aztecNode, header);
|
|
75
|
+
if (!instance.currentContractClassId.equals(currentClassId)) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Ensures the contract's private state is synchronized and that the PXE holds the current class artifact for
|
|
84
|
+
* the contract.
|
|
85
|
+
*/
|
|
86
|
+
export async function ensureContractSynced(
|
|
87
|
+
contractAddress: AztecAddress,
|
|
88
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
89
|
+
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
90
|
+
aztecNode: AztecNode,
|
|
91
|
+
contractStore: ContractStore,
|
|
92
|
+
header: BlockHeader,
|
|
93
|
+
): Promise<void> {
|
|
94
|
+
await Promise.all([
|
|
95
|
+
syncState(contractAddress, contractStore, functionToInvokeAfterSync, utilityExecutor),
|
|
96
|
+
verifyCurrentClassId(contractAddress, aztecNode, contractStore, header),
|
|
97
|
+
]);
|
|
98
|
+
}
|