@aztec/pxe 0.0.1-commit.2ed92850 → 0.0.1-commit.3469e52
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 +4 -6
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +11 -51
- package/dest/config/index.d.ts +1 -3
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +0 -17
- 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 +4 -1
- 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 +5 -8
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +11 -21
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +22 -2
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +37 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -9
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +5 -16
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +7 -15
- 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 -34
- package/dest/debug/pxe_debug_utils.d.ts +1 -1
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +2 -3
- package/dest/entrypoints/server/index.d.ts +1 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +0 -1
- 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/logs/log_service.d.ts +1 -1
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +11 -17
- package/dest/notes/note_service.d.ts +3 -4
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +10 -11
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +3 -4
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +9 -11
- package/dest/storage/contract_store/contract_store.d.ts +2 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +12 -0
- package/dest/storage/note_store/note_store.d.ts +55 -43
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +252 -238
- package/dest/storage/private_event_store/private_event_store.d.ts +4 -17
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +135 -163
- package/dest/tagging/index.d.ts +1 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +0 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -3
- 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 +2 -3
- 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 +2 -5
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +2 -3
- 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 +8 -5
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -3
- 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 +4 -7
- package/dest/tree_membership/tree_membership_service.d.ts +50 -0
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
- package/dest/tree_membership/tree_membership_service.js +75 -0
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +0 -1
- package/src/block_synchronizer/block_synchronizer.ts +14 -53
- package/src/config/index.ts +0 -14
- package/src/contract_function_simulator/contract_function_simulator.ts +9 -1
- 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 +4 -13
- package/src/contract_function_simulator/oracle/oracle.ts +15 -28
- package/src/contract_function_simulator/oracle/private_execution.ts +60 -1
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +6 -32
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +41 -49
- package/src/debug/pxe_debug_utils.ts +2 -3
- package/src/entrypoints/server/index.ts +0 -1
- package/src/events/event_service.ts +1 -1
- package/src/logs/log_service.ts +8 -24
- package/src/notes/note_service.ts +15 -18
- package/src/oracle_version.ts +3 -4
- package/src/pxe.ts +10 -33
- package/src/storage/contract_store/contract_store.ts +20 -0
- package/src/storage/note_store/note_store.ts +313 -279
- package/src/storage/private_event_store/private_event_store.ts +175 -214
- package/src/tagging/index.ts +0 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +1 -11
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +1 -7
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +1 -3
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +17 -5
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +3 -12
- package/src/tree_membership/tree_membership_service.ts +97 -0
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- package/dest/contract_sync/index.js +0 -54
- package/dest/storage/note_store/stored_note.d.ts +0 -16
- package/dest/storage/note_store/stored_note.d.ts.map +0 -1
- package/dest/storage/note_store/stored_note.js +0 -43
- package/dest/storage/private_event_store/stored_private_event.d.ts +0 -23
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +0 -1
- package/dest/storage/private_event_store/stored_private_event.js +0 -56
- package/dest/tagging/get_all_logs_by_tags.d.ts +0 -24
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +0 -1
- package/dest/tagging/get_all_logs_by_tags.js +0 -46
- package/src/contract_sync/index.ts +0 -98
- package/src/storage/note_store/stored_note.ts +0 -48
- package/src/storage/private_event_store/stored_private_event.ts +0 -73
- package/src/tagging/get_all_logs_by_tags.ts +0 -68
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
2
2
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
3
|
-
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
4
3
|
/**
|
|
5
4
|
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
|
|
6
5
|
* @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
|
|
@@ -14,14 +13,14 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
|
14
13
|
* @param taggingStore - The data provider to store pending indexes.
|
|
15
14
|
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
16
15
|
* preserving way.
|
|
17
|
-
*/ export async function loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore,
|
|
16
|
+
*/ export async function loadAndStoreNewTaggingIndexes(secret, app, start, end, aztecNode, taggingStore, jobId) {
|
|
18
17
|
// We compute the tags for the current window of indexes
|
|
19
18
|
const preTagsForWindow = Array(end - start).fill(0).map((_, i)=>({
|
|
20
19
|
secret,
|
|
21
20
|
index: start + i
|
|
22
21
|
}));
|
|
23
22
|
const siloedTagsForWindow = await Promise.all(preTagsForWindow.map(async (preTag)=>SiloedTag.compute(await Tag.compute(preTag), app)));
|
|
24
|
-
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode
|
|
23
|
+
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode);
|
|
25
24
|
const highestIndexMap = getTxHighestIndexMap(txsForTags, preTagsForWindow);
|
|
26
25
|
// Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
|
|
27
26
|
for (const [txHashStr, highestIndex] of highestIndexMap.entries()){
|
|
@@ -36,10 +35,8 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
|
36
35
|
}
|
|
37
36
|
// Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
|
|
38
37
|
// an array for each tag.
|
|
39
|
-
async function getTxsContainingTags(tags, aztecNode
|
|
40
|
-
|
|
41
|
-
// pagination here.
|
|
42
|
-
const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
|
|
38
|
+
async function getTxsContainingTags(tags, aztecNode) {
|
|
39
|
+
const allLogs = await aztecNode.getPrivateLogsByTags(tags);
|
|
43
40
|
return allLogs.map((logs)=>logs.map((log)=>log.txHash));
|
|
44
41
|
}
|
|
45
42
|
// Returns a map of txHash to the highest index for that txHash.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
8
|
+
export declare class TreeMembershipService {
|
|
9
|
+
#private;
|
|
10
|
+
private readonly aztecNode;
|
|
11
|
+
constructor(aztecNode: AztecNode);
|
|
12
|
+
/**
|
|
13
|
+
* Gets the index of a nullifier in the nullifier tree.
|
|
14
|
+
* @returns - The index of the nullifier. Undefined if it does not exist in the tree.
|
|
15
|
+
*/
|
|
16
|
+
getNullifierIndex(nullifier: Fr): Promise<bigint | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the index and sibling path of a leaf at a given block from a given tree.
|
|
19
|
+
* @param blockHash - The block hash at which to get the membership witness.
|
|
20
|
+
* @param treeId - Id of the tree to get the sibling path from.
|
|
21
|
+
* @param leafValue - The leaf value
|
|
22
|
+
* @returns The index and sibling path concatenated [index, sibling_path]
|
|
23
|
+
*/
|
|
24
|
+
getMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
27
|
+
* @param blockHash - The block hash at which to get the index.
|
|
28
|
+
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
29
|
+
* @returns The low nullifier membership witness (if found).
|
|
30
|
+
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
31
|
+
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
32
|
+
* we are trying to prove non-inclusion for.
|
|
33
|
+
*/
|
|
34
|
+
getLowNullifierMembershipWitness(blockHash: L2BlockHash, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns a witness for a given slot of the public data tree at a given block.
|
|
37
|
+
* @param blockHash - The block hash at which to get the witness.
|
|
38
|
+
* @param leafSlot - The slot of the public data in the public data tree.
|
|
39
|
+
*/
|
|
40
|
+
getPublicDataWitness(blockHash: L2BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
|
|
43
|
+
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
44
|
+
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
|
|
45
|
+
* The message nullifier is computed locally, so the secret is not sent to the node.
|
|
46
|
+
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
47
|
+
*/
|
|
48
|
+
getL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>]>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJlZV9tZW1iZXJzaGlwX3NlcnZpY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90cmVlX21lbWJlcnNoaXAvdHJlZV9tZW1iZXJzaGlwX3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNqRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbEQsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFakUsT0FBTyxFQUFFLFlBQVksRUFBRSwwQkFBMEIsRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBTWxHLHFCQUFhLHFCQUFxQjs7SUFDcEIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxTQUFTO0lBQXRDLFlBQTZCLFNBQVMsRUFBRSxTQUFTLEVBQUk7SUFFckQ7OztPQUdHO0lBQ1UsaUJBQWlCLENBQUMsU0FBUyxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsTUFBTSxHQUFHLFNBQVMsQ0FBQyxDQUd6RTtJQUVEOzs7Ozs7T0FNRztJQUNVLG9CQUFvQixDQUFDLFNBQVMsRUFBRSxXQUFXLEVBQUUsTUFBTSxFQUFFLFlBQVksRUFBRSxTQUFTLEVBQUUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQVE1RztJQUVEOzs7Ozs7OztPQVFHO0lBQ0ksZ0NBQWdDLENBQ3JDLFNBQVMsRUFBRSxXQUFXLEVBQ3RCLFNBQVMsRUFBRSxFQUFFLEdBQ1osT0FBTyxDQUFDLDBCQUEwQixHQUFHLFNBQVMsQ0FBQyxDQUVqRDtJQUVEOzs7O09BSUc7SUFDSSxvQkFBb0IsQ0FBQyxTQUFTLEVBQUUsV0FBVyxFQUFFLFFBQVEsRUFBRSxFQUFFLEdBQUcsT0FBTyxDQUFDLGlCQUFpQixHQUFHLFNBQVMsQ0FBQyxDQUV4RztJQUVEOzs7Ozs7T0FNRztJQUNJLDBCQUEwQixDQUMvQixlQUFlLEVBQUUsWUFBWSxFQUM3QixXQUFXLEVBQUUsRUFBRSxFQUNmLE1BQU0sRUFBRSxFQUFFLEdBQ1QsT0FBTyxDQUFDLENBQUMsTUFBTSxFQUFFLFdBQVcsQ0FBQyxPQUFPLHdCQUF3QixDQUFDLENBQUMsQ0FBQyxDQUVqRTtDQWdCRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree_membership_service.d.ts","sourceRoot":"","sources":["../../src/tree_membership/tree_membership_service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAMlG,qBAAa,qBAAqB;;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAAtC,YAA6B,SAAS,EAAE,SAAS,EAAI;IAErD;;;OAGG;IACU,iBAAiB,CAAC,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAGzE;IAED;;;;;;OAMG;IACU,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC,CAQ5G;IAED;;;;;;;;OAQG;IACI,gCAAgC,CACrC,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAEjD;IAED;;;;OAIG;IACI,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAExG;IAED;;;;;;OAMG;IACI,0BAA0B,CAC/B,eAAe,EAAE,YAAY,EAC7B,WAAW,EAAE,EAAE,EACf,MAAM,EAAE,EAAE,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAEjE;CAgBF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
2
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
3
|
+
// TODO: REmove this class as it no longer seems valuable. The only somewhat real functionality in this class is in
|
|
4
|
+
// the `getMembershipWitness` method that is used by `utilityGetMembershipWitness` oracle by then in Aztec.nr we
|
|
5
|
+
// have helper functions around that oracle for archive and note hash tree and the generic method itself is not used
|
|
6
|
+
// anywhere else - make sense to just have simple specific handlers for the archive and note hash trees and drop this.
|
|
7
|
+
export class TreeMembershipService {
|
|
8
|
+
aztecNode;
|
|
9
|
+
constructor(aztecNode){
|
|
10
|
+
this.aztecNode = aztecNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets the index of a nullifier in the nullifier tree.
|
|
14
|
+
* @returns - The index of the nullifier. Undefined if it does not exist in the tree.
|
|
15
|
+
*/ async getNullifierIndex(nullifier) {
|
|
16
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes('latest', MerkleTreeId.NULLIFIER_TREE, [
|
|
17
|
+
nullifier
|
|
18
|
+
]);
|
|
19
|
+
return leafIndex?.data;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Fetches the index and sibling path of a leaf at a given block from a given tree.
|
|
23
|
+
* @param blockHash - The block hash at which to get the membership witness.
|
|
24
|
+
* @param treeId - Id of the tree to get the sibling path from.
|
|
25
|
+
* @param leafValue - The leaf value
|
|
26
|
+
* @returns The index and sibling path concatenated [index, sibling_path]
|
|
27
|
+
*/ async getMembershipWitness(blockHash, treeId, leafValue) {
|
|
28
|
+
const witness = await this.#tryGetMembershipWitness(blockHash, treeId, leafValue);
|
|
29
|
+
if (!witness) {
|
|
30
|
+
throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block hash ${blockHash.toString()}`);
|
|
31
|
+
}
|
|
32
|
+
return witness;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
36
|
+
* @param blockHash - The block hash at which to get the index.
|
|
37
|
+
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
38
|
+
* @returns The low nullifier membership witness (if found).
|
|
39
|
+
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
40
|
+
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
41
|
+
* we are trying to prove non-inclusion for.
|
|
42
|
+
*/ getLowNullifierMembershipWitness(blockHash, nullifier) {
|
|
43
|
+
return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns a witness for a given slot of the public data tree at a given block.
|
|
47
|
+
* @param blockHash - The block hash at which to get the witness.
|
|
48
|
+
* @param leafSlot - The slot of the public data in the public data tree.
|
|
49
|
+
*/ getPublicDataWitness(blockHash, leafSlot) {
|
|
50
|
+
return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Looks for the L1 to L2 membership witness of a message at the Aztec node, given its hash.
|
|
54
|
+
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
55
|
+
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages.
|
|
56
|
+
* The message nullifier is computed locally, so the secret is not sent to the node.
|
|
57
|
+
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
58
|
+
*/ getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
|
|
59
|
+
return getNonNullifiedL1ToL2MessageWitness(this.aztecNode, contractAddress, messageHash, secret);
|
|
60
|
+
}
|
|
61
|
+
async #tryGetMembershipWitness(blockHash, treeId, value) {
|
|
62
|
+
switch(treeId){
|
|
63
|
+
case MerkleTreeId.NULLIFIER_TREE:
|
|
64
|
+
return (await this.aztecNode.getNullifierMembershipWitness(blockHash, value))?.withoutPreimage().toFields();
|
|
65
|
+
case MerkleTreeId.NOTE_HASH_TREE:
|
|
66
|
+
return (await this.aztecNode.getNoteHashMembershipWitness(blockHash, value))?.toFields();
|
|
67
|
+
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
68
|
+
return (await this.aztecNode.getPublicDataWitness(blockHash, value))?.withoutPreimage().toFields();
|
|
69
|
+
case MerkleTreeId.ARCHIVE:
|
|
70
|
+
return (await this.aztecNode.getArchiveMembershipWitness(blockHash, value))?.toFields();
|
|
71
|
+
default:
|
|
72
|
+
throw new Error('Not implemented');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.3469e52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/entrypoints/server/index.js",
|
|
@@ -61,19 +61,19 @@
|
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
65
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
66
|
-
"@aztec/builder": "0.0.1-commit.
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
69
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
70
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
71
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
76
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
64
|
+
"@aztec/bb-prover": "0.0.1-commit.3469e52",
|
|
65
|
+
"@aztec/bb.js": "0.0.1-commit.3469e52",
|
|
66
|
+
"@aztec/builder": "0.0.1-commit.3469e52",
|
|
67
|
+
"@aztec/constants": "0.0.1-commit.3469e52",
|
|
68
|
+
"@aztec/ethereum": "0.0.1-commit.3469e52",
|
|
69
|
+
"@aztec/foundation": "0.0.1-commit.3469e52",
|
|
70
|
+
"@aztec/key-store": "0.0.1-commit.3469e52",
|
|
71
|
+
"@aztec/kv-store": "0.0.1-commit.3469e52",
|
|
72
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.3469e52",
|
|
73
|
+
"@aztec/noir-types": "0.0.1-commit.3469e52",
|
|
74
|
+
"@aztec/protocol-contracts": "0.0.1-commit.3469e52",
|
|
75
|
+
"@aztec/simulator": "0.0.1-commit.3469e52",
|
|
76
|
+
"@aztec/stdlib": "0.0.1-commit.3469e52",
|
|
77
77
|
"koa": "^2.16.1",
|
|
78
78
|
"koa-router": "^13.1.1",
|
|
79
79
|
"lodash.omit": "^4.5.0",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
85
|
+
"@aztec/merkle-tree": "0.0.1-commit.3469e52",
|
|
86
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.3469e52",
|
|
87
87
|
"@jest/globals": "^30.0.0",
|
|
88
88
|
"@types/jest": "^30.0.0",
|
|
89
89
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -9,9 +9,8 @@ import {
|
|
|
9
9
|
type L2BlockStreamEventHandler,
|
|
10
10
|
} from '@aztec/stdlib/block';
|
|
11
11
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
12
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
13
12
|
|
|
14
|
-
import type {
|
|
13
|
+
import type { PXEConfig } from '../config/index.js';
|
|
15
14
|
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
16
15
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
17
16
|
import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
@@ -33,7 +32,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
33
32
|
private noteStore: NoteStore,
|
|
34
33
|
private privateEventStore: PrivateEventStore,
|
|
35
34
|
private l2TipsStore: L2TipsKVStore,
|
|
36
|
-
|
|
35
|
+
config: Partial<Pick<PXEConfig, 'l2BlockBatchSize'>> = {},
|
|
37
36
|
loggerOrSuffix?: string | Logger,
|
|
38
37
|
) {
|
|
39
38
|
this.log =
|
|
@@ -43,7 +42,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
43
42
|
this.blockStream = this.createBlockStream(config);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
protected createBlockStream(config: Partial<
|
|
45
|
+
protected createBlockStream(config: Partial<Pick<PXEConfig, 'l2BlockBatchSize'>>) {
|
|
47
46
|
return new L2BlockStream(this.node, this.l2TipsStore, this, createLogger('pxe:block_stream'), {
|
|
48
47
|
batchSize: config.l2BlockBatchSize,
|
|
49
48
|
// Skipping finalized blocks makes us sync much faster - we only need to download blocks other than the latest one
|
|
@@ -58,51 +57,19 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
58
57
|
|
|
59
58
|
switch (event.type) {
|
|
60
59
|
case 'blocks-added': {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (this.config.syncChainTip === 'checkpointed') {
|
|
69
|
-
// Get the last block header from the checkpoint
|
|
70
|
-
const lastBlock = event.checkpoint.checkpoint.blocks.at(-1)!;
|
|
71
|
-
await this.updateAnchorBlockHeader(lastBlock.header);
|
|
72
|
-
}
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
case 'chain-proven': {
|
|
76
|
-
if (this.config.syncChainTip === 'proven') {
|
|
77
|
-
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
78
|
-
if (blockHeader) {
|
|
79
|
-
await this.updateAnchorBlockHeader(blockHeader);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case 'chain-finalized': {
|
|
85
|
-
if (this.config.syncChainTip === 'finalized') {
|
|
86
|
-
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
87
|
-
if (blockHeader) {
|
|
88
|
-
await this.updateAnchorBlockHeader(blockHeader);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
60
|
+
const lastBlock = event.blocks.at(-1)!;
|
|
61
|
+
this.log.verbose(`Updated pxe last block to ${lastBlock.number}`, {
|
|
62
|
+
blockHash: lastBlock.hash(),
|
|
63
|
+
archive: lastBlock.archive.root.toString(),
|
|
64
|
+
header: lastBlock.header.toInspect(),
|
|
65
|
+
});
|
|
66
|
+
await this.anchorBlockStore.setHeader(lastBlock.header);
|
|
91
67
|
break;
|
|
92
68
|
}
|
|
93
69
|
case 'chain-pruned': {
|
|
94
|
-
const currentAnchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
95
|
-
const currentAnchorBlockNumber = currentAnchorBlockHeader.getBlockNumber();
|
|
96
|
-
if (currentAnchorBlockNumber <= event.block.number) {
|
|
97
|
-
this.log.verbose(
|
|
98
|
-
`Ignoring prune event to block ${event.block.number} greater than current anchor block ${currentAnchorBlockNumber}`,
|
|
99
|
-
{ pruneEvent: event, currentAnchorBlockHeader: currentAnchorBlockHeader.toInspect() },
|
|
100
|
-
);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
70
|
this.log.warn(`Pruning data after block ${event.block.number} due to reorg`);
|
|
105
71
|
|
|
72
|
+
const oldAnchorBlockNumber = (await this.anchorBlockStore.getBlockHeader()).getBlockNumber();
|
|
106
73
|
// Note that the following is not necessarily the anchor block that will be used in the transaction - if
|
|
107
74
|
// the chain has already moved past the reorg, we'll also see blocks-added events that will push the anchor
|
|
108
75
|
// forward.
|
|
@@ -116,21 +83,15 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
116
83
|
|
|
117
84
|
// Operations are wrapped in a single transaction to ensure atomicity.
|
|
118
85
|
await this.store.transactionAsync(async () => {
|
|
119
|
-
await this.noteStore.rollback(event.block.number,
|
|
120
|
-
await this.privateEventStore.rollback(event.block.number,
|
|
121
|
-
await this.
|
|
86
|
+
await this.noteStore.rollback(event.block.number, oldAnchorBlockNumber);
|
|
87
|
+
await this.privateEventStore.rollback(event.block.number, oldAnchorBlockNumber);
|
|
88
|
+
await this.anchorBlockStore.setHeader(newAnchorBlockHeader);
|
|
122
89
|
});
|
|
123
90
|
break;
|
|
124
91
|
}
|
|
125
92
|
}
|
|
126
93
|
}
|
|
127
94
|
|
|
128
|
-
/** Updates the anchor block header to the target block */
|
|
129
|
-
private async updateAnchorBlockHeader(blockHeader: BlockHeader) {
|
|
130
|
-
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
131
|
-
await this.anchorBlockStore.setHeader(blockHeader);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
95
|
/**
|
|
135
96
|
* Syncs PXE and the node by downloading the metadata of the latest blocks, allowing simulations to use
|
|
136
97
|
* recent data (e.g. notes), and handling any reorgs that might have occurred.
|
package/src/config/index.ts
CHANGED
|
@@ -24,8 +24,6 @@ export interface KernelProverConfig {
|
|
|
24
24
|
export interface BlockSynchronizerConfig {
|
|
25
25
|
/** Maximum amount of blocks to pull from the stream in one request when synchronizing */
|
|
26
26
|
l2BlockBatchSize: number;
|
|
27
|
-
/** Which chain tip to sync to (proposed, checkpointed, proven, finalized) */
|
|
28
|
-
syncChainTip?: 'proposed' | 'checkpointed' | 'proven' | 'finalized';
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export type PXEConfig = KernelProverConfig & DataStoreConfig & ChainConfig & BlockSynchronizerConfig;
|
|
@@ -55,18 +53,6 @@ export const pxeConfigMappings: ConfigMappingsType<PXEConfig> = {
|
|
|
55
53
|
description: 'Enable real proofs',
|
|
56
54
|
...booleanConfigHelper(true),
|
|
57
55
|
},
|
|
58
|
-
syncChainTip: {
|
|
59
|
-
env: 'PXE_SYNC_CHAIN_TIP',
|
|
60
|
-
description: 'Which chain tip to sync to (proposed, checkpointed, proven, finalized)',
|
|
61
|
-
defaultValue: 'proposed',
|
|
62
|
-
parseEnv: (val: string) => {
|
|
63
|
-
const allowedValues = ['proposed', 'checkpointed', 'proven', 'finalized'];
|
|
64
|
-
if (allowedValues.includes(val)) {
|
|
65
|
-
return val;
|
|
66
|
-
}
|
|
67
|
-
throw new Error(`Invalid value for PXE_SYNC_CHAIN_TIP: ${val}. Allowed values are: ${allowedValues.join(', ')}`);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
56
|
};
|
|
71
57
|
|
|
72
58
|
/**
|
|
@@ -85,7 +85,7 @@ import { ExecutionNoteCache } from './execution_note_cache.js';
|
|
|
85
85
|
import { ExecutionTaggingIndexCache } from './execution_tagging_index_cache.js';
|
|
86
86
|
import { HashedValuesCache } from './hashed_values_cache.js';
|
|
87
87
|
import { Oracle } from './oracle/oracle.js';
|
|
88
|
-
import { executePrivateFunction } from './oracle/private_execution.js';
|
|
88
|
+
import { executePrivateFunction, verifyCurrentClassId } from './oracle/private_execution.js';
|
|
89
89
|
import { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
|
|
90
90
|
import { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
|
|
91
91
|
|
|
@@ -138,6 +138,12 @@ export class ContractFunctionSimulator {
|
|
|
138
138
|
): Promise<PrivateExecutionResult> {
|
|
139
139
|
const simulatorSetupTimer = new Timer();
|
|
140
140
|
|
|
141
|
+
await this.contractStore.syncPrivateState(contractAddress, selector, privateSyncCall =>
|
|
142
|
+
this.runUtility(privateSyncCall, [], anchorBlockHeader, scopes, jobId),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
await verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader);
|
|
146
|
+
|
|
141
147
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(contractAddress, selector);
|
|
142
148
|
|
|
143
149
|
if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
|
|
@@ -262,6 +268,8 @@ export class ContractFunctionSimulator {
|
|
|
262
268
|
scopes: AztecAddress[] | undefined,
|
|
263
269
|
jobId: string,
|
|
264
270
|
): Promise<Fr[]> {
|
|
271
|
+
await verifyCurrentClassId(call.to, this.aztecNode, this.contractStore, anchorBlockHeader);
|
|
272
|
+
|
|
265
273
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
266
274
|
|
|
267
275
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
@@ -8,7 +8,7 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
8
8
|
const MAX_EVENT_SERIALIZED_LEN = 12;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Intermediate struct used to perform batch event validation by PXE. The `
|
|
11
|
+
* Intermediate struct used to perform batch event validation by PXE. The `utilityValidateEnqueuedNotesAndEvents` oracle
|
|
12
12
|
* expects for values of this type to be stored in a `CapsuleArray`.
|
|
13
13
|
*/
|
|
14
14
|
export class EventValidationRequest {
|
|
@@ -7,7 +7,7 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
7
7
|
export const MAX_NOTE_PACKED_LEN = 10;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Intermediate struct used to perform batch note validation by PXE. The `
|
|
10
|
+
* Intermediate struct used to perform batch note validation by PXE. The `utilityValidateEnqueuedNotesAndEvents` oracle
|
|
11
11
|
* expects for values of this type to be stored in a `CapsuleArray`.
|
|
12
12
|
*/
|
|
13
13
|
export class NoteValidationRequest {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
5
|
-
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
6
5
|
import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
7
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
7
|
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
@@ -10,7 +9,7 @@ import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
|
10
9
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
11
10
|
import type { ContractClassLog, Tag } from '@aztec/stdlib/logs';
|
|
12
11
|
import type { Note, NoteStatus } from '@aztec/stdlib/note';
|
|
13
|
-
import { type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
12
|
+
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
14
13
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
15
14
|
|
|
16
15
|
import type { UtilityContext } from '../noir-structs/utility_context.js';
|
|
@@ -67,14 +66,7 @@ export interface IUtilityExecutionOracle {
|
|
|
67
66
|
utilityGetUtilityContext(): UtilityContext;
|
|
68
67
|
utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest>;
|
|
69
68
|
utilityGetContractInstance(address: AztecAddress): Promise<ContractInstance>;
|
|
70
|
-
|
|
71
|
-
blockHash: L2BlockHash,
|
|
72
|
-
leafValue: Fr,
|
|
73
|
-
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined>;
|
|
74
|
-
utilityGetArchiveMembershipWitness(
|
|
75
|
-
blockHash: L2BlockHash,
|
|
76
|
-
leafValue: Fr,
|
|
77
|
-
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined>;
|
|
69
|
+
utilityGetMembershipWitness(blockHash: L2BlockHash, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[] | undefined>;
|
|
78
70
|
utilityGetNullifierMembershipWitness(
|
|
79
71
|
blockHash: L2BlockHash,
|
|
80
72
|
nullifier: Fr,
|
|
@@ -117,7 +109,7 @@ export interface IUtilityExecutionOracle {
|
|
|
117
109
|
numberOfElements: number,
|
|
118
110
|
): Promise<Fr[]>;
|
|
119
111
|
utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr): Promise<void>;
|
|
120
|
-
|
|
112
|
+
utilityValidateEnqueuedNotesAndEvents(
|
|
121
113
|
contractAddress: AztecAddress,
|
|
122
114
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
123
115
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
@@ -155,7 +147,6 @@ export interface IPrivateExecutionOracle {
|
|
|
155
147
|
): void;
|
|
156
148
|
privateNotifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number): Promise<void>;
|
|
157
149
|
privateNotifyCreatedNullifier(innerNullifier: Fr): Promise<void>;
|
|
158
|
-
privateIsNullifierPending(innerNullifier: Fr, contractAddress: AztecAddress): Promise<boolean>;
|
|
159
150
|
privateNotifyCreatedContractClassLog(log: ContractClassLog, counter: number): void;
|
|
160
151
|
privateCallPrivateFunction(
|
|
161
152
|
targetContractAddress: AztecAddress,
|
|
@@ -14,6 +14,7 @@ import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
|
14
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
15
|
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
16
16
|
import { ContractClassLog, ContractClassLogFields } from '@aztec/stdlib/logs';
|
|
17
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
17
18
|
|
|
18
19
|
import type { IMiscOracle, IPrivateExecutionOracle, IUtilityExecutionOracle } from './interfaces.js';
|
|
19
20
|
import { packAsHintedNote } from './note_packing_utils.js';
|
|
@@ -137,32 +138,26 @@ export class Oracle {
|
|
|
137
138
|
].map(toACVMField);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
async
|
|
141
|
+
async utilityGetMembershipWitness(
|
|
141
142
|
[blockHash]: ACVMField[],
|
|
143
|
+
[treeId]: ACVMField[],
|
|
142
144
|
[leafValue]: ACVMField[],
|
|
143
145
|
): Promise<(ACVMField | ACVMField[])[]> {
|
|
144
146
|
const parsedBlockHash = L2BlockHash.fromString(blockHash);
|
|
147
|
+
const parsedTreeId = Fr.fromString(treeId).toNumber();
|
|
145
148
|
const parsedLeafValue = Fr.fromString(leafValue);
|
|
146
149
|
|
|
147
|
-
const witness = await this.handlerAsUtility().
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async utilityGetArchiveMembershipWitness(
|
|
155
|
-
[blockHash]: ACVMField[],
|
|
156
|
-
[leafValue]: ACVMField[],
|
|
157
|
-
): Promise<(ACVMField | ACVMField[])[]> {
|
|
158
|
-
const parsedBlockHash = L2BlockHash.fromString(blockHash);
|
|
159
|
-
const parsedLeafValue = Fr.fromString(leafValue);
|
|
160
|
-
|
|
161
|
-
const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(parsedBlockHash, parsedLeafValue);
|
|
150
|
+
const witness = await this.handlerAsUtility().utilityGetMembershipWitness(
|
|
151
|
+
parsedBlockHash,
|
|
152
|
+
parsedTreeId,
|
|
153
|
+
parsedLeafValue,
|
|
154
|
+
);
|
|
162
155
|
if (!witness) {
|
|
163
|
-
throw new Error(
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Leaf ${leafValue} not found in the tree ${MerkleTreeId[parsedTreeId]} at block hash ${parsedBlockHash.toString()}.`,
|
|
158
|
+
);
|
|
164
159
|
}
|
|
165
|
-
return witness.
|
|
160
|
+
return [toACVMField(witness[0]), witness.slice(1).map(toACVMField)];
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
async utilityGetNullifierMembershipWitness(
|
|
@@ -346,14 +341,6 @@ export class Oracle {
|
|
|
346
341
|
return [];
|
|
347
342
|
}
|
|
348
343
|
|
|
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
|
-
|
|
357
344
|
async utilityCheckNullifierExists([innerNullifier]: ACVMField[]): Promise<ACVMField[]> {
|
|
358
345
|
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(Fr.fromString(innerNullifier));
|
|
359
346
|
return [toACVMField(exists)];
|
|
@@ -491,12 +478,12 @@ export class Oracle {
|
|
|
491
478
|
return [];
|
|
492
479
|
}
|
|
493
480
|
|
|
494
|
-
async
|
|
481
|
+
async utilityValidateEnqueuedNotesAndEvents(
|
|
495
482
|
[contractAddress]: ACVMField[],
|
|
496
483
|
[noteValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
497
484
|
[eventValidationRequestsArrayBaseSlot]: ACVMField[],
|
|
498
485
|
): Promise<ACVMField[]> {
|
|
499
|
-
await this.handlerAsUtility().
|
|
486
|
+
await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
|
|
500
487
|
AztecAddress.fromString(contractAddress),
|
|
501
488
|
Fr.fromString(noteValidationRequestsArrayBaseSlot),
|
|
502
489
|
Fr.fromString(eventValidationRequestsArrayBaseSlot),
|
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
import {
|
|
6
7
|
type ACVMWitness,
|
|
7
8
|
type CircuitSimulator,
|
|
@@ -17,10 +18,15 @@ import {
|
|
|
17
18
|
countArgumentsSize,
|
|
18
19
|
} from '@aztec/stdlib/abi';
|
|
19
20
|
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';
|
|
20
25
|
import { PrivateCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
21
26
|
import type { CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
|
|
22
|
-
import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
|
|
27
|
+
import { BlockHeader, PrivateCallExecutionResult } from '@aztec/stdlib/tx';
|
|
23
28
|
|
|
29
|
+
import { ContractStore } from '../../storage/contract_store/index.js';
|
|
24
30
|
import { Oracle } from './oracle.js';
|
|
25
31
|
import type { PrivateExecutionOracle } from './private_execution_oracle.js';
|
|
26
32
|
|
|
@@ -139,3 +145,56 @@ export function extractPrivateCircuitPublicInputs(
|
|
|
139
145
|
}
|
|
140
146
|
return PrivateCircuitPublicInputs.fromFields(returnData);
|
|
141
147
|
}
|
|
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
|
+
}
|