@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec
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/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -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/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -30
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +175 -74
- 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 +3 -3
- 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 +2 -2
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -3
- 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 +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +51 -29
- 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 +44 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +86 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +62 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +107 -88
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +24 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- 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 +21 -7
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- 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 +22 -8
- 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 +4 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -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 +28 -9
- package/dest/events/event_service.d.ts +5 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +6 -7
- 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 +7 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +28 -32
- package/dest/notes/note_service.d.ts +9 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +17 -16
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- 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/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- 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 +21 -13
- package/dest/private_kernel/private_kernel_oracle.d.ts +8 -4
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +69 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +104 -67
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +42 -16
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -84
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +47 -49
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +278 -252
- 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 +198 -147
- 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/storage/tagging_store/recipient_tagging_store.d.ts +6 -6
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +5 -5
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +184 -114
- 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 +60 -0
- package/dest/tagging/index.d.ts +3 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +2 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -5
- 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 +7 -7
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +7 -7
- 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 +16 -12
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -8
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +3 -6
- 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 +5 -7
- 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 +20 -18
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +76 -33
- package/src/config/index.ts +14 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +324 -137
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +5 -5
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +2 -2
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +2 -2
- package/src/contract_function_simulator/oracle/interfaces.ts +20 -11
- package/src/contract_function_simulator/oracle/oracle.ts +56 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +126 -110
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +172 -95
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +63 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +3 -0
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +5 -7
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +48 -39
- package/src/notes/note_service.ts +24 -22
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +25 -15
- package/src/private_kernel/private_kernel_oracle.ts +9 -9
- package/src/pxe.ts +211 -112
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +186 -96
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +321 -318
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +250 -190
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +38 -24
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +214 -130
- package/src/tagging/get_all_logs_by_tags.ts +92 -0
- package/src/tagging/index.ts +2 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +17 -10
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +17 -16
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +6 -9
- 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 +23 -23
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
- 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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
|
+
import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
4
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Generic pagination helper that fetches all pages of results.
|
|
9
|
+
* @param numTags - The number of tags being queried (determines result array size).
|
|
10
|
+
* @param fetchPage - Function that fetches a single page of results given a page number.
|
|
11
|
+
* @returns An array of arrays, one per tag, containing all results across all pages.
|
|
12
|
+
*/
|
|
13
|
+
async function getAllPages<T>(numTags: number, fetchPage: (page: number) => Promise<T[][]>): Promise<T[][]> {
|
|
14
|
+
const allResultsPerTag: T[][] = Array.from({ length: numTags }, () => []);
|
|
15
|
+
let page = 0;
|
|
16
|
+
let hasMore = true;
|
|
17
|
+
|
|
18
|
+
while (hasMore) {
|
|
19
|
+
const resultsPage = await fetchPage(page);
|
|
20
|
+
hasMore = false;
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < resultsPage.length; i++) {
|
|
23
|
+
allResultsPerTag[i].push(...resultsPage[i]);
|
|
24
|
+
if (resultsPage[i].length === MAX_LOGS_PER_TAG) {
|
|
25
|
+
hasMore = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
page++;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return allResultsPerTag;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
|
|
36
|
+
* back into a single array preserving the original tag order.
|
|
37
|
+
*/
|
|
38
|
+
async function getAllPagesInBatches<Tag, T>(
|
|
39
|
+
tags: Tag[],
|
|
40
|
+
fetchAllPagesForBatch: (batch: Tag[]) => Promise<T[][]>,
|
|
41
|
+
): Promise<T[][]> {
|
|
42
|
+
if (tags.length <= MAX_RPC_LEN) {
|
|
43
|
+
return fetchAllPagesForBatch(tags);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const batches: Tag[][] = [];
|
|
47
|
+
for (let i = 0; i < tags.length; i += MAX_RPC_LEN) {
|
|
48
|
+
batches.push(tags.slice(i, i + MAX_RPC_LEN));
|
|
49
|
+
}
|
|
50
|
+
const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
|
|
51
|
+
return batchResults.flat();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
56
|
+
* @param aztecNode - The Aztec node to query.
|
|
57
|
+
* @param tags - The siloed tags to search for.
|
|
58
|
+
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
59
|
+
* because of reorgs).
|
|
60
|
+
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
61
|
+
*/
|
|
62
|
+
export function getAllPrivateLogsByTags(
|
|
63
|
+
aztecNode: AztecNode,
|
|
64
|
+
tags: SiloedTag[],
|
|
65
|
+
anchorBlockHash: BlockHash,
|
|
66
|
+
): Promise<TxScopedL2Log[][]> {
|
|
67
|
+
return getAllPagesInBatches(tags, batch =>
|
|
68
|
+
getAllPages(batch.length, page => aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
|
|
74
|
+
* @param aztecNode - The Aztec node to query.
|
|
75
|
+
* @param contractAddress - The contract address to search logs for.
|
|
76
|
+
* @param tags - The tags to search for.
|
|
77
|
+
* @param anchorBlockHash - reference block for the Aztec node query, throws if block is not found there (typically
|
|
78
|
+
* because of reorgs).
|
|
79
|
+
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
80
|
+
*/
|
|
81
|
+
export function getAllPublicLogsByTagsFromContract(
|
|
82
|
+
aztecNode: AztecNode,
|
|
83
|
+
contractAddress: AztecAddress,
|
|
84
|
+
tags: Tag[],
|
|
85
|
+
anchorBlockHash: BlockHash,
|
|
86
|
+
): Promise<TxScopedL2Log[][]> {
|
|
87
|
+
return getAllPagesInBatches(tags, batch =>
|
|
88
|
+
getAllPages(batch.length, page =>
|
|
89
|
+
aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash),
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
}
|
package/src/tagging/index.ts
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
export { loadPrivateLogsForSenderRecipientPair } from './recipient_sync/load_private_logs_for_sender_recipient_pair.js';
|
|
13
13
|
export { syncSenderTaggingIndexes } from './sender_sync/sync_sender_tagging_indexes.js';
|
|
14
14
|
export { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from './constants.js';
|
|
15
|
+
export { getAllPrivateLogsByTags, getAllPublicLogsByTagsFromContract } from './get_all_logs_by_tags.js';
|
|
15
16
|
|
|
16
17
|
// Re-export tagging-related types from stdlib
|
|
17
|
-
export {
|
|
18
|
+
export { ExtendedDirectionalAppTaggingSecret, Tag, SiloedTag } from '@aztec/stdlib/logs';
|
|
18
19
|
export { type PreTag } from '@aztec/stdlib/logs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ExtendedDirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
5
|
|
|
6
6
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
7
7
|
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
@@ -9,18 +9,18 @@ import { findHighestIndexes } from './utils/find_highest_indexes.js';
|
|
|
9
9
|
import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Loads private logs for
|
|
12
|
+
* Loads private logs for the app-sender-recipient triplet defined by `secret` and updates the highest aged and
|
|
13
13
|
* finalized indexes in the db. At most load logs from blocks up to and including `anchorBlockNumber`.
|
|
14
14
|
*
|
|
15
15
|
* @dev This function can be safely executed "in parallel" for other sender-recipient pairs because the data in
|
|
16
16
|
* in the tagging data provider is indexed by the secret and hence completely disjoint.
|
|
17
17
|
*/
|
|
18
18
|
export async function loadPrivateLogsForSenderRecipientPair(
|
|
19
|
-
secret:
|
|
20
|
-
app: AztecAddress,
|
|
19
|
+
secret: ExtendedDirectionalAppTaggingSecret,
|
|
21
20
|
aztecNode: AztecNode,
|
|
22
21
|
taggingStore: RecipientTaggingStore,
|
|
23
22
|
anchorBlockNumber: BlockNumber,
|
|
23
|
+
anchorBlockHash: BlockHash,
|
|
24
24
|
jobId: string,
|
|
25
25
|
): Promise<TxScopedL2Log[]> {
|
|
26
26
|
// # Explanation of how the algorithm works
|
|
@@ -28,7 +28,7 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
28
28
|
// (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
|
|
29
29
|
//
|
|
30
30
|
// highestAgedIndex is the highest index that was used in a tx that is included in a block at least
|
|
31
|
-
// `
|
|
31
|
+
// `MAX_TX_LIFETIME` seconds ago.
|
|
32
32
|
// highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
|
|
33
33
|
//
|
|
34
34
|
// "(" denotes an open end of the range - the index is not included in the range.
|
|
@@ -40,19 +40,19 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
40
40
|
// ever appear.
|
|
41
41
|
//
|
|
42
42
|
// This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
|
|
43
|
-
// - a transaction's maximum inclusion timestamp is at most `
|
|
43
|
+
// - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
|
|
44
44
|
// the timestamp of its anchor block; and
|
|
45
45
|
// - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
|
|
46
46
|
//
|
|
47
47
|
// Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
|
|
48
|
-
// least `
|
|
48
|
+
// least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
|
|
49
49
|
// trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
|
|
50
50
|
// a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
|
|
51
51
|
// chosen a larger index.
|
|
52
52
|
// If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
|
|
53
53
|
// because it would already have been expired.
|
|
54
54
|
//
|
|
55
|
-
// Therefore, once we see that index `I` has been used in a block that is at least `
|
|
55
|
+
// Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
|
|
56
56
|
// seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
|
|
57
57
|
//
|
|
58
58
|
// ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
|
|
@@ -92,7 +92,14 @@ export async function loadPrivateLogsForSenderRecipientPair(
|
|
|
92
92
|
|
|
93
93
|
while (true) {
|
|
94
94
|
// Get private logs with their block timestamps and corresponding tagging indexes
|
|
95
|
-
const privateLogsWithIndexes = await loadLogsForRange(
|
|
95
|
+
const privateLogsWithIndexes = await loadLogsForRange(
|
|
96
|
+
secret,
|
|
97
|
+
aztecNode,
|
|
98
|
+
start,
|
|
99
|
+
end,
|
|
100
|
+
anchorBlockNumber,
|
|
101
|
+
anchorBlockHash,
|
|
102
|
+
);
|
|
96
103
|
|
|
97
104
|
if (privateLogsWithIndexes.length === 0) {
|
|
98
105
|
break;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_TX_LIFETIME } from '@aztec/constants';
|
|
2
2
|
import type { TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,7 +16,7 @@ export function findHighestIndexes(
|
|
|
16
16
|
const ageInSeconds = currentTimestamp - log.blockTimestamp;
|
|
17
17
|
|
|
18
18
|
if (
|
|
19
|
-
ageInSeconds >= BigInt(
|
|
19
|
+
ageInSeconds >= BigInt(MAX_TX_LIFETIME) &&
|
|
20
20
|
(highestAgedIndex === undefined || taggingIndex > highestAgedIndex)
|
|
21
21
|
) {
|
|
22
22
|
highestAgedIndex = taggingIndex;
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
3
3
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
4
|
-
import type {
|
|
5
|
-
import { SiloedTag
|
|
4
|
+
import type { ExtendedDirectionalAppTaggingSecret, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
|
+
import { SiloedTag } from '@aztec/stdlib/logs';
|
|
6
|
+
|
|
7
|
+
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
* Gets private logs with their corresponding block timestamps and tagging indexes for the given index range
|
|
9
|
-
* `
|
|
10
|
-
* exclusive.
|
|
10
|
+
* Gets private logs with their corresponding block timestamps and tagging indexes for the given index range and
|
|
11
|
+
* `extendedSecret`. At most load logs from blocks up to and including `anchorBlockNumber`. `start` is inclusive and
|
|
12
|
+
* `end` is exclusive.
|
|
11
13
|
*/
|
|
12
14
|
export async function loadLogsForRange(
|
|
13
|
-
|
|
14
|
-
app: AztecAddress,
|
|
15
|
+
extendedSecret: ExtendedDirectionalAppTaggingSecret,
|
|
15
16
|
aztecNode: AztecNode,
|
|
16
17
|
start: number,
|
|
17
18
|
end: number,
|
|
18
19
|
anchorBlockNumber: BlockNumber,
|
|
20
|
+
anchorBlockHash: BlockHash,
|
|
19
21
|
): Promise<Array<{ log: TxScopedL2Log; taggingIndex: number }>> {
|
|
20
|
-
// Derive tags for the window
|
|
21
|
-
const
|
|
22
|
-
.
|
|
23
|
-
.map((_, i) => ({ secret, index: start + i }));
|
|
24
|
-
const siloedTags = await Promise.all(preTags.map(preTag => Tag.compute(preTag))).then(tags =>
|
|
25
|
-
Promise.all(tags.map(tag => SiloedTag.compute(tag, app))),
|
|
22
|
+
// Derive siloed tags for the window
|
|
23
|
+
const siloedTags = await Promise.all(
|
|
24
|
+
Array.from({ length: end - start }, (_, i) => SiloedTag.compute({ extendedSecret, index: start + i })),
|
|
26
25
|
);
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
28
|
+
// pagination here.
|
|
29
|
+
const logs = await getAllPrivateLogsByTags(aztecNode, siloedTags, anchorBlockHash);
|
|
29
30
|
|
|
30
31
|
// Pair logs with their corresponding tagging indexes
|
|
31
32
|
const logsWithIndexes: Array<{ log: TxScopedL2Log; taggingIndex: number }> = [];
|
|
32
33
|
for (let i = 0; i < logs.length; i++) {
|
|
33
34
|
const logsForTag = logs[i];
|
|
34
|
-
const taggingIndex =
|
|
35
|
+
const taggingIndex = start + i;
|
|
35
36
|
for (const log of logsForTag) {
|
|
36
37
|
if (log.blockNumber <= anchorBlockNumber) {
|
|
37
38
|
logsWithIndexes.push({ log, taggingIndex });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
4
|
|
|
5
5
|
import type { SenderTaggingStore } from '../../storage/tagging_store/sender_tagging_store.js';
|
|
6
6
|
import { UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN } from '../constants.js';
|
|
@@ -10,11 +10,8 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
|
|
|
10
10
|
/**
|
|
11
11
|
* Syncs tagging indexes. This function needs to be called whenever a private log is being sent.
|
|
12
12
|
*
|
|
13
|
-
* @param secret - The secret that's unique for (sender, recipient,
|
|
13
|
+
* @param secret - The secret that's unique for (sender, recipient, app) tuple while the direction of
|
|
14
14
|
* sender -> recipient matters.
|
|
15
|
-
* @param app - The address of the contract that the logs are tagged for. Needs to be provided because we perform
|
|
16
|
-
* second round of siloing in this function which is necessary because kernels do it as well (they silo first field
|
|
17
|
-
* of the private log which corresponds to the tag).
|
|
18
15
|
* @remarks When syncing the indexes as sender we don't care about the log contents - we only care about the highest
|
|
19
16
|
* pending and highest finalized indexes as that guides the next index choice when sending a log. The next index choice
|
|
20
17
|
* is simply the highest pending index plus one (or finalized if pending is undefined).
|
|
@@ -22,10 +19,10 @@ import { loadAndStoreNewTaggingIndexes } from './utils/load_and_store_new_taggin
|
|
|
22
19
|
* updates its status accordingly.
|
|
23
20
|
*/
|
|
24
21
|
export async function syncSenderTaggingIndexes(
|
|
25
|
-
secret:
|
|
26
|
-
app: AztecAddress,
|
|
22
|
+
secret: ExtendedDirectionalAppTaggingSecret,
|
|
27
23
|
aztecNode: AztecNode,
|
|
28
24
|
taggingStore: SenderTaggingStore,
|
|
25
|
+
anchorBlockHash: BlockHash,
|
|
29
26
|
jobId: string,
|
|
30
27
|
): Promise<void> {
|
|
31
28
|
// # Explanation of how syncing works
|
|
@@ -57,7 +54,7 @@ export async function syncSenderTaggingIndexes(
|
|
|
57
54
|
while (true) {
|
|
58
55
|
// Load and store indexes for the current window. These indexes may already exist in the database if txs using
|
|
59
56
|
// them were previously sent from this PXE. Any duplicates are handled by the tagging data provider.
|
|
60
|
-
await loadAndStoreNewTaggingIndexes(secret,
|
|
57
|
+
await loadAndStoreNewTaggingIndexes(secret, start, end, aztecNode, taggingStore, anchorBlockHash, jobId);
|
|
61
58
|
|
|
62
59
|
// Retrieve all indexes within the current window from storage and update their status accordingly.
|
|
63
60
|
const pendingTxHashes = await taggingStore.getTxHashesOfPendingIndexes(secret, start, end, jobId);
|
|
@@ -9,11 +9,8 @@ export async function getStatusChangeOfPending(
|
|
|
9
9
|
pending: TxHash[],
|
|
10
10
|
aztecNode: AztecNode,
|
|
11
11
|
): Promise<{ txHashesToFinalize: TxHash[]; txHashesToDrop: TxHash[] }> {
|
|
12
|
-
// Get receipts for all pending tx hashes
|
|
13
|
-
const
|
|
14
|
-
Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash))),
|
|
15
|
-
aztecNode.getL2Tips(),
|
|
16
|
-
]);
|
|
12
|
+
// Get receipts for all pending tx hashes.
|
|
13
|
+
const receipts = await Promise.all(pending.map(pendingTxHash => aztecNode.getTxReceipt(pendingTxHash)));
|
|
17
14
|
|
|
18
15
|
const txHashesToFinalize: TxHash[] = [];
|
|
19
16
|
const txHashesToDrop: TxHash[] = [];
|
|
@@ -22,25 +19,16 @@ export async function getStatusChangeOfPending(
|
|
|
22
19
|
const receipt = receipts[i];
|
|
23
20
|
const txHash = pending[i];
|
|
24
21
|
|
|
25
|
-
if (
|
|
26
|
-
receipt.status === TxStatus.SUCCESS &&
|
|
27
|
-
receipt.blockNumber &&
|
|
28
|
-
receipt.blockNumber <= tips.finalized.block.number
|
|
29
|
-
) {
|
|
22
|
+
if (receipt.status === TxStatus.FINALIZED && receipt.hasExecutionSucceeded()) {
|
|
30
23
|
// Tx has been included in a block and the corresponding block is finalized --> we mark the indexes as
|
|
31
24
|
// finalized.
|
|
32
25
|
txHashesToFinalize.push(txHash);
|
|
33
|
-
} else if (
|
|
34
|
-
receipt.status === TxStatus.DROPPED ||
|
|
35
|
-
receipt.status === TxStatus.APP_LOGIC_REVERTED ||
|
|
36
|
-
receipt.status === TxStatus.TEARDOWN_REVERTED ||
|
|
37
|
-
receipt.status === TxStatus.BOTH_REVERTED
|
|
38
|
-
) {
|
|
26
|
+
} else if (receipt.isDropped() || receipt.hasExecutionReverted()) {
|
|
39
27
|
// Tx was dropped or reverted --> we drop the corresponding pending indexes.
|
|
40
28
|
// TODO(#17615): Don't drop pending indexes corresponding to non-revertible phases.
|
|
41
29
|
txHashesToDrop.push(txHash);
|
|
42
30
|
} else {
|
|
43
|
-
// Tx is still pending or
|
|
31
|
+
// Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do anything.
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
2
2
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
import type {
|
|
4
|
-
import { SiloedTag
|
|
3
|
+
import type { ExtendedDirectionalAppTaggingSecret } from '@aztec/stdlib/logs';
|
|
4
|
+
import { SiloedTag } from '@aztec/stdlib/logs';
|
|
5
5
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
7
|
import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
|
|
8
|
+
import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
|
|
11
12
|
* @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
|
|
12
13
|
* place is when a tx is being sent from this PXE.
|
|
13
|
-
* @param
|
|
14
|
-
* @param app - The address of the contract that the logs are tagged for. Used for siloing tags to match
|
|
15
|
-
* kernel circuit behavior.
|
|
14
|
+
* @param extendedSecret - The extended directional app tagging secret that's unique for (sender, recipient, app) tuple.
|
|
16
15
|
* @param start - The starting index (inclusive) of the window to process.
|
|
17
16
|
* @param end - The ending index (exclusive) of the window to process.
|
|
18
17
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
@@ -21,50 +20,51 @@ import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_t
|
|
|
21
20
|
* preserving way.
|
|
22
21
|
*/
|
|
23
22
|
export async function loadAndStoreNewTaggingIndexes(
|
|
24
|
-
|
|
25
|
-
app: AztecAddress,
|
|
23
|
+
extendedSecret: ExtendedDirectionalAppTaggingSecret,
|
|
26
24
|
start: number,
|
|
27
25
|
end: number,
|
|
28
26
|
aztecNode: AztecNode,
|
|
29
27
|
taggingStore: SenderTaggingStore,
|
|
28
|
+
anchorBlockHash: BlockHash,
|
|
30
29
|
jobId: string,
|
|
31
30
|
) {
|
|
32
31
|
// We compute the tags for the current window of indexes
|
|
33
|
-
const preTagsForWindow: PreTag[] = Array(end - start)
|
|
34
|
-
.fill(0)
|
|
35
|
-
.map((_, i) => ({ secret, index: start + i }));
|
|
36
32
|
const siloedTagsForWindow = await Promise.all(
|
|
37
|
-
|
|
33
|
+
Array.from({ length: end - start }, (_, i) => SiloedTag.compute({ extendedSecret, index: start + i })),
|
|
38
34
|
);
|
|
39
35
|
|
|
40
|
-
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode);
|
|
41
|
-
const highestIndexMap = getTxHighestIndexMap(txsForTags,
|
|
36
|
+
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
|
|
37
|
+
const highestIndexMap = getTxHighestIndexMap(txsForTags, start, siloedTagsForWindow.length);
|
|
42
38
|
|
|
43
39
|
// Now we iterate over the map, reconstruct the preTags and tx hash and store them in the db.
|
|
44
40
|
for (const [txHashStr, highestIndex] of highestIndexMap.entries()) {
|
|
45
41
|
const txHash = TxHash.fromString(txHashStr);
|
|
46
|
-
await taggingStore.storePendingIndexes([{
|
|
42
|
+
await taggingStore.storePendingIndexes([{ extendedSecret, index: highestIndex }], txHash, jobId);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
// Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
|
|
51
47
|
// an array for each tag.
|
|
52
|
-
async function getTxsContainingTags(
|
|
53
|
-
|
|
48
|
+
async function getTxsContainingTags(
|
|
49
|
+
tags: SiloedTag[],
|
|
50
|
+
aztecNode: AztecNode,
|
|
51
|
+
anchorBlockHash: BlockHash,
|
|
52
|
+
): Promise<TxHash[][]> {
|
|
53
|
+
// We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
|
|
54
|
+
// pagination here.
|
|
55
|
+
const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
|
|
54
56
|
return allLogs.map(logs => logs.map(log => log.txHash));
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// Returns a map of txHash to the highest index for that txHash.
|
|
58
|
-
function getTxHighestIndexMap(txHashesForTags: TxHash[][],
|
|
59
|
-
if (txHashesForTags.length !==
|
|
60
|
-
throw new Error(
|
|
61
|
-
`Number of tx hashes arrays does not match number of pre-tags. ${txHashesForTags.length} !== ${preTagsForWindow.length}`,
|
|
62
|
-
);
|
|
60
|
+
function getTxHighestIndexMap(txHashesForTags: TxHash[][], start: number, count: number): Map<string, number> {
|
|
61
|
+
if (txHashesForTags.length !== count) {
|
|
62
|
+
throw new Error(`Number of tx hashes arrays does not match number of tags. ${txHashesForTags.length} !== ${count}`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const highestIndexMap = new Map<string, number>();
|
|
66
66
|
for (let i = 0; i < txHashesForTags.length; i++) {
|
|
67
|
-
const taggingIndex =
|
|
67
|
+
const taggingIndex = start + i;
|
|
68
68
|
const txHashesForTag = txHashesForTags[i];
|
|
69
69
|
for (const txHash of txHashesForTag) {
|
|
70
70
|
const key = txHash.toString();
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { PrivateKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
|
|
2
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
3
|
-
export declare function computeTxIncludeByTimestamp(previousKernel: PrivateKernelCircuitPublicInputs, maxDuration?: number): UInt64;
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcHV0ZV90eF9pbmNsdWRlX2J5X3RpbWVzdGFtcC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3ByaXZhdGVfa2VybmVsL2hpbnRzL2NvbXB1dGVfdHhfaW5jbHVkZV9ieV90aW1lc3RhbXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsZ0NBQWdDLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUM3RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXFCbEQsd0JBQWdCLDJCQUEyQixDQUN6QyxjQUFjLEVBQUUsZ0NBQWdDLEVBQ2hELFdBQVcsU0FBb0MsR0FDOUMsTUFBTSxDQStCUiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute_tx_include_by_timestamp.d.ts","sourceRoot":"","sources":["../../../src/private_kernel/hints/compute_tx_include_by_timestamp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAqBlD,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,gCAAgC,EAChD,WAAW,SAAoC,GAC9C,MAAM,CA+BR"}
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
-
}
|