@aztec/pxe 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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 +4 -4
- package/dest/block_synchronizer/block_synchronizer.d.ts +6 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +19 -1
- package/dest/config/index.d.ts +1 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +7 -14
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +13 -5
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +35 -10
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +5 -5
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +17 -9
- package/dest/contract_function_simulator/index.d.ts +2 -1
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +3 -4
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +3 -6
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +3 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +3 -6
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +32 -19
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts +9 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/legacy_oracle_mappings.js +47 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +50 -18
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +186 -39
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +12 -23
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +30 -28
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +74 -42
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +252 -87
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +3 -0
- package/dest/contract_logging.d.ts +9 -4
- package/dest/contract_logging.d.ts.map +1 -1
- package/dest/contract_logging.js +21 -6
- package/dest/contract_sync/contract_sync_service.d.ts +6 -5
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -1
- package/dest/contract_sync/contract_sync_service.js +62 -43
- package/dest/contract_sync/helpers.d.ts +2 -3
- package/dest/contract_sync/helpers.d.ts.map +1 -1
- package/dest/contract_sync/helpers.js +7 -2
- package/dest/debug/pxe_debug_utils.d.ts +3 -3
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.d.ts +1 -2
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +0 -1
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -2
- package/dest/entrypoints/client/lazy/index.d.ts +1 -2
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +0 -1
- 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 +2 -2
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -1
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +2 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -2
- package/dest/entrypoints/server/utils.d.ts +2 -2
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +2 -2
- package/dest/events/event_service.d.ts +3 -2
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +26 -5
- package/dest/events/private_event_filter_validator.d.ts +3 -2
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +15 -0
- package/dest/logs/log_service.d.ts +7 -8
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +27 -37
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +36 -0
- package/dest/notes/note_service.d.ts +4 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -5
- package/dest/notes_filter.d.ts +2 -3
- package/dest/notes_filter.d.ts.map +1 -1
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -10
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +4 -7
- package/dest/private_kernel/private_kernel_oracle.d.ts +5 -5
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +12 -15
- package/dest/pxe.d.ts +10 -7
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +58 -35
- package/dest/storage/anchor_block_store/anchor_block_store.js +1 -1
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +9 -9
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
- package/dest/storage/capsule_store/capsule_store.js +36 -28
- package/dest/storage/capsule_store/index.d.ts +2 -1
- package/dest/storage/capsule_store/index.d.ts.map +1 -1
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +4 -2
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +1 -1
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +2 -2
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +3 -0
- package/dest/storage/private_event_store/stored_private_event.js +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +26 -25
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +141 -115
- package/dest/tagging/index.d.ts +2 -2
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +2 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -16
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +10 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +4 -3
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +20 -10
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +2 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +24 -11
- package/package.json +16 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +22 -2
- package/src/config/index.ts +2 -8
- package/src/contract_function_simulator/contract_function_simulator.ts +49 -14
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +16 -11
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -4
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -4
- package/src/contract_function_simulator/oracle/interfaces.ts +51 -17
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +258 -34
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +40 -34
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +423 -114
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +18 -5
- package/src/contract_sync/contract_sync_service.ts +99 -75
- package/src/contract_sync/helpers.ts +4 -4
- package/src/debug/pxe_debug_utils.ts +3 -3
- package/src/entrypoints/client/bundle/index.ts +0 -1
- package/src/entrypoints/client/bundle/utils.ts +2 -3
- package/src/entrypoints/client/lazy/index.ts +0 -1
- package/src/entrypoints/client/lazy/utils.ts +2 -3
- package/src/entrypoints/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +1 -2
- package/src/entrypoints/server/utils.ts +2 -3
- package/src/events/event_service.ts +30 -5
- package/src/events/private_event_filter_validator.ts +21 -1
- package/src/logs/log_service.ts +57 -78
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +18 -8
- package/src/notes_filter.ts +1 -3
- package/src/oracle_version.ts +20 -10
- package/src/private_kernel/private_kernel_execution_prover.ts +4 -9
- package/src/private_kernel/private_kernel_oracle.ts +14 -14
- package/src/pxe.ts +113 -42
- package/src/storage/anchor_block_store/anchor_block_store.ts +1 -1
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +44 -26
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +8 -6
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +2 -5
- package/src/storage/private_event_store/private_event_store.ts +4 -0
- package/src/storage/private_event_store/stored_private_event.ts +1 -1
- package/src/storage/tagging_store/sender_tagging_store.ts +182 -135
- package/src/tagging/index.ts +1 -1
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +5 -15
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +19 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +26 -11
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +19 -9
- package/dest/access_scopes.d.ts +0 -9
- package/dest/access_scopes.d.ts.map +0 -1
- package/dest/access_scopes.js +0 -6
- package/src/access_scopes.ts +0 -9
|
@@ -10,6 +10,7 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
|
10
10
|
* @param end - The ending index (exclusive) of the window to process.
|
|
11
11
|
* @param aztecNode - The Aztec node instance to query for logs.
|
|
12
12
|
* @param taggingStore - The data provider to store pending indexes.
|
|
13
|
+
* @param anchorBlockHash - Hash of a block to use as reference block when querying node.
|
|
13
14
|
* @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
|
|
14
15
|
* preserving way.
|
|
15
16
|
*/ export async function loadAndStoreNewTaggingIndexes(extendedSecret, start, end, aztecNode, taggingStore, anchorBlockHash, jobId) {
|
|
@@ -21,16 +22,18 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
|
|
|
21
22
|
index: start + i
|
|
22
23
|
})));
|
|
23
24
|
const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
|
|
24
|
-
const
|
|
25
|
-
// Now we iterate over the map,
|
|
26
|
-
for (const [txHashStr,
|
|
25
|
+
const txIndexesMap = getTxIndexesMap(txsForTags, start, siloedTagsForWindow.length);
|
|
26
|
+
// Now we iterate over the map, construct the tagging index ranges and store them in the db.
|
|
27
|
+
for (const [txHashStr, indexes] of txIndexesMap.entries()){
|
|
27
28
|
const txHash = TxHash.fromString(txHashStr);
|
|
28
|
-
|
|
29
|
+
const ranges = [
|
|
29
30
|
{
|
|
30
31
|
extendedSecret,
|
|
31
|
-
|
|
32
|
+
lowestIndex: Math.min(...indexes),
|
|
33
|
+
highestIndex: Math.max(...indexes)
|
|
32
34
|
}
|
|
33
|
-
]
|
|
35
|
+
];
|
|
36
|
+
await taggingStore.storePendingIndexes(ranges, txHash, jobId);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
// Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
|
|
@@ -41,19 +44,29 @@ async function getTxsContainingTags(tags, aztecNode, anchorBlockHash) {
|
|
|
41
44
|
const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
|
|
42
45
|
return allLogs.map((logs)=>logs.map((log)=>log.txHash));
|
|
43
46
|
}
|
|
44
|
-
// Returns a map of txHash to
|
|
45
|
-
function
|
|
47
|
+
// Returns a map of txHash to all indexes for that txHash.
|
|
48
|
+
function getTxIndexesMap(txHashesForTags, start, count) {
|
|
46
49
|
if (txHashesForTags.length !== count) {
|
|
47
50
|
throw new Error(`Number of tx hashes arrays does not match number of tags. ${txHashesForTags.length} !== ${count}`);
|
|
48
51
|
}
|
|
49
|
-
const
|
|
52
|
+
const indexesMap = new Map();
|
|
53
|
+
// Iterate over indexes
|
|
50
54
|
for(let i = 0; i < txHashesForTags.length; i++){
|
|
51
55
|
const taggingIndex = start + i;
|
|
52
56
|
const txHashesForTag = txHashesForTags[i];
|
|
57
|
+
// iterate over tx hashes that used that index (tag)
|
|
53
58
|
for (const txHash of txHashesForTag){
|
|
54
59
|
const key = txHash.toString();
|
|
55
|
-
|
|
60
|
+
const existing = indexesMap.get(key);
|
|
61
|
+
// Add the index to the tx's indexes
|
|
62
|
+
if (existing) {
|
|
63
|
+
existing.push(taggingIndex);
|
|
64
|
+
} else {
|
|
65
|
+
indexesMap.set(key, [
|
|
66
|
+
taggingIndex
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
|
-
return
|
|
71
|
+
return indexesMap;
|
|
59
72
|
}
|
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.b2a5d0dd1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"typedocOptions": {
|
|
6
6
|
"entryPoints": [
|
|
@@ -70,19 +70,19 @@
|
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
74
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
75
|
-
"@aztec/builder": "0.0.1-commit.
|
|
76
|
-
"@aztec/constants": "0.0.1-commit.
|
|
77
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
78
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
79
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
80
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
81
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
82
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
83
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
84
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
85
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb-prover": "0.0.1-commit.b2a5d0dd1",
|
|
74
|
+
"@aztec/bb.js": "0.0.1-commit.b2a5d0dd1",
|
|
75
|
+
"@aztec/builder": "0.0.1-commit.b2a5d0dd1",
|
|
76
|
+
"@aztec/constants": "0.0.1-commit.b2a5d0dd1",
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.b2a5d0dd1",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.b2a5d0dd1",
|
|
79
|
+
"@aztec/key-store": "0.0.1-commit.b2a5d0dd1",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.b2a5d0dd1",
|
|
81
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.b2a5d0dd1",
|
|
82
|
+
"@aztec/noir-types": "0.0.1-commit.b2a5d0dd1",
|
|
83
|
+
"@aztec/protocol-contracts": "0.0.1-commit.b2a5d0dd1",
|
|
84
|
+
"@aztec/simulator": "0.0.1-commit.b2a5d0dd1",
|
|
85
|
+
"@aztec/stdlib": "0.0.1-commit.b2a5d0dd1",
|
|
86
86
|
"koa": "^2.16.1",
|
|
87
87
|
"koa-router": "^13.1.1",
|
|
88
88
|
"lodash.omit": "^4.5.0",
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@aztec/
|
|
95
|
-
"@aztec/
|
|
94
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.b2a5d0dd1",
|
|
95
|
+
"@aztec/world-state": "0.0.1-commit.b2a5d0dd1",
|
|
96
96
|
"@jest/globals": "^30.0.0",
|
|
97
97
|
"@types/jest": "^30.0.0",
|
|
98
98
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -13,8 +13,9 @@ import { ORACLE_INTERFACE_HASH } from '../oracle_version.js';
|
|
|
13
13
|
*
|
|
14
14
|
* The Oracle interface needs to be versioned to ensure compatibility between Aztec.nr and PXE. This function computes
|
|
15
15
|
* a hash of the Oracle interface and compares it against a known hash. If they don't match, it means the interface has
|
|
16
|
-
* changed and the
|
|
17
|
-
*
|
|
16
|
+
* changed and the oracle version needs to be bumped:
|
|
17
|
+
* - If the change is backward-breaking (e.g. removing/renaming an oracle), bump ORACLE_VERSION_MAJOR.
|
|
18
|
+
* - If the change is an oracle addition (non-breaking), bump ORACLE_VERSION_MINOR.
|
|
18
19
|
*
|
|
19
20
|
* TODO(#16581): The following only takes into consideration changes to the oracles defined in Oracle.ts and omits TXE
|
|
20
21
|
* oracles. Ensure this checks TXE oracles as well. This hasn't been implemented yet since we don't have a clean TXE
|
|
@@ -26,9 +27,8 @@ function assertOracleInterfaceMatches(): void {
|
|
|
26
27
|
// We use keccak256 here just because we already have it in the dependencies.
|
|
27
28
|
const oracleInterfaceHash = keccak256String(oracleInterfaceSignature);
|
|
28
29
|
if (oracleInterfaceHash !== ORACLE_INTERFACE_HASH) {
|
|
29
|
-
// This check exists only to notify you when you need to update the ORACLE_VERSION constant.
|
|
30
30
|
throw new Error(
|
|
31
|
-
`The Oracle interface has changed
|
|
31
|
+
`The Oracle interface has changed. Update ORACLE_INTERFACE_HASH to ${oracleInterfaceHash} in pxe/src/oracle_version.ts and bump the oracle version (ORACLE_VERSION_MAJOR for breaking changes, ORACLE_VERSION_MINOR for oracle additions).`,
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
4
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
5
|
import type { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
5
6
|
import { BlockHash, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
|
|
@@ -20,6 +21,7 @@ import type { PrivateEventStore } from '../storage/private_event_store/private_e
|
|
|
20
21
|
export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
21
22
|
private log: Logger;
|
|
22
23
|
private isSyncing: Promise<void> | undefined;
|
|
24
|
+
private readonly eventQueue = new SerialQueue();
|
|
23
25
|
protected readonly blockStream: L2BlockStream;
|
|
24
26
|
|
|
25
27
|
constructor(
|
|
@@ -35,6 +37,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
35
37
|
) {
|
|
36
38
|
this.log = createLogger('pxe:block_synchronizer', bindings);
|
|
37
39
|
this.blockStream = this.createBlockStream(config);
|
|
40
|
+
this.eventQueue.start();
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
protected createBlockStream(config: Partial<BlockSynchronizerConfig>): L2BlockStream {
|
|
@@ -52,8 +55,12 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
52
55
|
);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
/** Handle events emitted by the block stream. */
|
|
56
|
-
public
|
|
58
|
+
/** Handle events emitted by the block stream. Serialized to prevent concurrent mutations to anchor state. */
|
|
59
|
+
public handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
60
|
+
return this.eventQueue.put(() => this.doHandleBlockStreamEvent(event));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async doHandleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void> {
|
|
57
64
|
await this.l2TipsStore.handleBlockStreamEvent(event);
|
|
58
65
|
|
|
59
66
|
switch (event.type) {
|
|
@@ -77,6 +84,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
77
84
|
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
78
85
|
if (blockHeader) {
|
|
79
86
|
await this.updateAnchorBlockHeader(blockHeader);
|
|
87
|
+
} else {
|
|
88
|
+
this.log.warn(`Block header not found for proven block ${event.block.number}, skipping anchor update`);
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
break;
|
|
@@ -86,6 +95,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
86
95
|
const blockHeader = await this.node.getBlockHeader(BlockNumber(event.block.number));
|
|
87
96
|
if (blockHeader) {
|
|
88
97
|
await this.updateAnchorBlockHeader(blockHeader);
|
|
98
|
+
} else {
|
|
99
|
+
this.log.warn(`Block header not found for finalized block ${event.block.number}, skipping anchor update`);
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
break;
|
|
@@ -152,6 +163,8 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
this.log.debug(`Syncing PXE with the node`);
|
|
166
|
+
// Capture the promise locally so we always await the exact promise we created, even if this.isSyncing is modified
|
|
167
|
+
// between assignment and await (e.g. due to future refactors introducing a yield point).
|
|
155
168
|
const isSyncing = this.doSync();
|
|
156
169
|
this.isSyncing = isSyncing;
|
|
157
170
|
try {
|
|
@@ -161,6 +174,13 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
161
174
|
}
|
|
162
175
|
}
|
|
163
176
|
|
|
177
|
+
/** Stops the block synchronizer, waiting for any in-progress sync and queued events to complete. */
|
|
178
|
+
public async stop() {
|
|
179
|
+
await this.isSyncing;
|
|
180
|
+
await this.blockStream.stop();
|
|
181
|
+
await this.eventQueue.end();
|
|
182
|
+
}
|
|
183
|
+
|
|
164
184
|
private async doSync() {
|
|
165
185
|
let currentHeader;
|
|
166
186
|
|
package/src/config/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ConfigMappingsType,
|
|
3
3
|
booleanConfigHelper,
|
|
4
|
+
enumConfigHelper,
|
|
4
5
|
getConfigFromMappings,
|
|
5
6
|
numberConfigHelper,
|
|
6
7
|
parseBooleanEnv,
|
|
@@ -58,14 +59,7 @@ export const pxeConfigMappings: ConfigMappingsType<PXEConfig> = {
|
|
|
58
59
|
syncChainTip: {
|
|
59
60
|
env: 'PXE_SYNC_CHAIN_TIP',
|
|
60
61
|
description: 'Which chain tip to sync to (proposed, checkpointed, proven, finalized)',
|
|
61
|
-
|
|
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
|
-
},
|
|
62
|
+
...enumConfigHelper(['proposed', 'checkpointed', 'proven', 'finalized'], 'proposed'),
|
|
69
63
|
},
|
|
70
64
|
};
|
|
71
65
|
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
MAX_NULLIFIERS_PER_TX,
|
|
18
18
|
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
19
19
|
MAX_PRIVATE_LOGS_PER_TX,
|
|
20
|
+
MAX_TX_LIFETIME,
|
|
20
21
|
PRIVATE_TX_L2_GAS_OVERHEAD,
|
|
21
22
|
PUBLIC_TX_L2_GAS_OVERHEAD,
|
|
22
23
|
TX_DA_GAS_OVERHEAD,
|
|
@@ -41,7 +42,7 @@ import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
|
41
42
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
42
43
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
43
44
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
-
import type { BlockParameter } from '@aztec/stdlib/block';
|
|
45
|
+
import type { BlockParameter, L2TipsProvider } from '@aztec/stdlib/block';
|
|
45
46
|
import { Gas } from '@aztec/stdlib/gas';
|
|
46
47
|
import {
|
|
47
48
|
computeNoteHashNonce,
|
|
@@ -79,6 +80,7 @@ import {
|
|
|
79
80
|
BlockHeader,
|
|
80
81
|
CallContext,
|
|
81
82
|
HashedValues,
|
|
83
|
+
type OffchainEffect,
|
|
82
84
|
PrivateExecutionResult,
|
|
83
85
|
TxConstantData,
|
|
84
86
|
TxExecutionRequest,
|
|
@@ -87,9 +89,10 @@ import {
|
|
|
87
89
|
getFinalMinRevertibleSideEffectCounter,
|
|
88
90
|
} from '@aztec/stdlib/tx';
|
|
89
91
|
|
|
90
|
-
import type { AccessScopes } from '../access_scopes.js';
|
|
91
92
|
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
93
|
+
import type { MessageContextService } from '../messages/message_context_service.js';
|
|
92
94
|
import type { AddressStore } from '../storage/address_store/address_store.js';
|
|
95
|
+
import { CapsuleService } from '../storage/capsule_store/capsule_service.js';
|
|
93
96
|
import type { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
|
|
94
97
|
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
95
98
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
@@ -119,7 +122,7 @@ export type ContractSimulatorRunOpts = {
|
|
|
119
122
|
/** The address used as a tagging sender when emitting private logs. */
|
|
120
123
|
senderForTags?: AztecAddress;
|
|
121
124
|
/** The accounts whose notes we can access in this call. */
|
|
122
|
-
scopes:
|
|
125
|
+
scopes: AztecAddress[];
|
|
123
126
|
/** The job ID for staged writes. */
|
|
124
127
|
jobId: string;
|
|
125
128
|
};
|
|
@@ -131,6 +134,7 @@ export type ContractFunctionSimulatorArgs = {
|
|
|
131
134
|
keyStore: KeyStore;
|
|
132
135
|
addressStore: AddressStore;
|
|
133
136
|
aztecNode: AztecNode;
|
|
137
|
+
l2TipsStore: L2TipsProvider;
|
|
134
138
|
senderTaggingStore: SenderTaggingStore;
|
|
135
139
|
recipientTaggingStore: RecipientTaggingStore;
|
|
136
140
|
senderAddressBookStore: SenderAddressBookStore;
|
|
@@ -138,6 +142,7 @@ export type ContractFunctionSimulatorArgs = {
|
|
|
138
142
|
privateEventStore: PrivateEventStore;
|
|
139
143
|
simulator: CircuitSimulator;
|
|
140
144
|
contractSyncService: ContractSyncService;
|
|
145
|
+
messageContextService: MessageContextService;
|
|
141
146
|
};
|
|
142
147
|
|
|
143
148
|
/**
|
|
@@ -150,6 +155,7 @@ export class ContractFunctionSimulator {
|
|
|
150
155
|
private readonly keyStore: KeyStore;
|
|
151
156
|
private readonly addressStore: AddressStore;
|
|
152
157
|
private readonly aztecNode: AztecNode;
|
|
158
|
+
private readonly l2TipsStore: L2TipsProvider;
|
|
153
159
|
private readonly senderTaggingStore: SenderTaggingStore;
|
|
154
160
|
private readonly recipientTaggingStore: RecipientTaggingStore;
|
|
155
161
|
private readonly senderAddressBookStore: SenderAddressBookStore;
|
|
@@ -157,6 +163,7 @@ export class ContractFunctionSimulator {
|
|
|
157
163
|
private readonly privateEventStore: PrivateEventStore;
|
|
158
164
|
private readonly simulator: CircuitSimulator;
|
|
159
165
|
private readonly contractSyncService: ContractSyncService;
|
|
166
|
+
private readonly messageContextService: MessageContextService;
|
|
160
167
|
|
|
161
168
|
constructor(args: ContractFunctionSimulatorArgs) {
|
|
162
169
|
this.contractStore = args.contractStore;
|
|
@@ -164,6 +171,7 @@ export class ContractFunctionSimulator {
|
|
|
164
171
|
this.keyStore = args.keyStore;
|
|
165
172
|
this.addressStore = args.addressStore;
|
|
166
173
|
this.aztecNode = args.aztecNode;
|
|
174
|
+
this.l2TipsStore = args.l2TipsStore;
|
|
167
175
|
this.senderTaggingStore = args.senderTaggingStore;
|
|
168
176
|
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
169
177
|
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
@@ -171,6 +179,7 @@ export class ContractFunctionSimulator {
|
|
|
171
179
|
this.privateEventStore = args.privateEventStore;
|
|
172
180
|
this.simulator = args.simulator;
|
|
173
181
|
this.contractSyncService = args.contractSyncService;
|
|
182
|
+
this.messageContextService = args.messageContextService;
|
|
174
183
|
this.log = createLogger('simulator');
|
|
175
184
|
}
|
|
176
185
|
|
|
@@ -199,7 +208,7 @@ export class ContractFunctionSimulator {
|
|
|
199
208
|
}
|
|
200
209
|
|
|
201
210
|
if (request.origin !== contractAddress) {
|
|
202
|
-
|
|
211
|
+
throw new Error(
|
|
203
212
|
`Request origin does not match contract address in simulation. Request origin: ${request.origin}, contract address: ${contractAddress}`,
|
|
204
213
|
);
|
|
205
214
|
}
|
|
@@ -239,8 +248,9 @@ export class ContractFunctionSimulator {
|
|
|
239
248
|
senderTaggingStore: this.senderTaggingStore,
|
|
240
249
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
241
250
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
242
|
-
|
|
251
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
243
252
|
privateEventStore: this.privateEventStore,
|
|
253
|
+
messageContextService: this.messageContextService,
|
|
244
254
|
contractSyncService: this.contractSyncService,
|
|
245
255
|
jobId,
|
|
246
256
|
totalPublicCalldataCount: 0,
|
|
@@ -248,6 +258,7 @@ export class ContractFunctionSimulator {
|
|
|
248
258
|
scopes,
|
|
249
259
|
senderForTags,
|
|
250
260
|
simulator: this.simulator,
|
|
261
|
+
l2TipsStore: this.l2TipsStore,
|
|
251
262
|
});
|
|
252
263
|
|
|
253
264
|
const setupTime = simulatorSetupTimer.ms();
|
|
@@ -277,7 +288,7 @@ export class ContractFunctionSimulator {
|
|
|
277
288
|
);
|
|
278
289
|
const publicFunctionsCalldata = await Promise.all(
|
|
279
290
|
publicCallRequests.map(async r => {
|
|
280
|
-
const calldata = await privateExecutionOracle.
|
|
291
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
281
292
|
return new HashedValues(calldata, r.calldataHash);
|
|
282
293
|
}),
|
|
283
294
|
);
|
|
@@ -298,7 +309,6 @@ export class ContractFunctionSimulator {
|
|
|
298
309
|
}
|
|
299
310
|
}
|
|
300
311
|
|
|
301
|
-
// docs:start:execute_utility_function
|
|
302
312
|
/**
|
|
303
313
|
* Runs a utility function.
|
|
304
314
|
* @param call - The function call to execute.
|
|
@@ -312,9 +322,9 @@ export class ContractFunctionSimulator {
|
|
|
312
322
|
call: FunctionCall,
|
|
313
323
|
authwits: AuthWitness[],
|
|
314
324
|
anchorBlockHeader: BlockHeader,
|
|
315
|
-
scopes:
|
|
325
|
+
scopes: AztecAddress[],
|
|
316
326
|
jobId: string,
|
|
317
|
-
): Promise<Fr[]> {
|
|
327
|
+
): Promise<{ result: Fr[]; offchainEffects: OffchainEffect[] }> {
|
|
318
328
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
319
329
|
|
|
320
330
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
@@ -333,8 +343,11 @@ export class ContractFunctionSimulator {
|
|
|
333
343
|
aztecNode: this.aztecNode,
|
|
334
344
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
335
345
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
336
|
-
|
|
346
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
337
347
|
privateEventStore: this.privateEventStore,
|
|
348
|
+
messageContextService: this.messageContextService,
|
|
349
|
+
contractSyncService: this.contractSyncService,
|
|
350
|
+
l2TipsStore: this.l2TipsStore,
|
|
338
351
|
jobId,
|
|
339
352
|
scopes,
|
|
340
353
|
});
|
|
@@ -362,12 +375,14 @@ export class ContractFunctionSimulator {
|
|
|
362
375
|
});
|
|
363
376
|
|
|
364
377
|
this.log.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
365
|
-
return
|
|
378
|
+
return {
|
|
379
|
+
result: witnessMapToFields(acirExecutionResult.returnWitness),
|
|
380
|
+
offchainEffects: oracle.getOffchainEffects(),
|
|
381
|
+
};
|
|
366
382
|
} catch (err) {
|
|
367
383
|
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
368
384
|
}
|
|
369
385
|
}
|
|
370
|
-
// docs:end:execute_utility_function
|
|
371
386
|
|
|
372
387
|
/**
|
|
373
388
|
* Returns the execution statistics collected during the simulator run.
|
|
@@ -432,14 +447,34 @@ export async function generateSimulatedProvingResult(
|
|
|
432
447
|
|
|
433
448
|
let publicTeardownCallRequest;
|
|
434
449
|
|
|
450
|
+
// We set expiration timestamp to anchor_block_timestamp + MAX_TX_LIFETIME (24h) just like kernels do
|
|
451
|
+
let expirationTimestamp =
|
|
452
|
+
privateExecutionResult.entrypoint.publicInputs.anchorBlockHeader.globalVariables.timestamp +
|
|
453
|
+
BigInt(MAX_TX_LIFETIME);
|
|
454
|
+
|
|
455
|
+
let feePayer = AztecAddress.zero();
|
|
456
|
+
|
|
435
457
|
const executions = [privateExecutionResult.entrypoint];
|
|
436
458
|
|
|
437
459
|
while (executions.length !== 0) {
|
|
438
460
|
const execution = executions.shift()!;
|
|
439
461
|
executions.unshift(...execution!.nestedExecutionResults);
|
|
440
462
|
|
|
463
|
+
// Just like kernels we overwrite the default value if the call sets it.
|
|
464
|
+
const callExpirationTimestamp = execution.publicInputs.expirationTimestamp;
|
|
465
|
+
if (callExpirationTimestamp !== 0n && callExpirationTimestamp < expirationTimestamp) {
|
|
466
|
+
expirationTimestamp = callExpirationTimestamp;
|
|
467
|
+
}
|
|
468
|
+
|
|
441
469
|
const { contractAddress } = execution.publicInputs.callContext;
|
|
442
470
|
|
|
471
|
+
if (execution.publicInputs.isFeePayer) {
|
|
472
|
+
if (!feePayer.isZero()) {
|
|
473
|
+
throw new Error('Multiple fee payers found in private execution result');
|
|
474
|
+
}
|
|
475
|
+
feePayer = contractAddress;
|
|
476
|
+
}
|
|
477
|
+
|
|
443
478
|
scopedNoteHashes.push(
|
|
444
479
|
...execution.publicInputs.noteHashes
|
|
445
480
|
.getActiveItems()
|
|
@@ -660,8 +695,8 @@ export async function generateSimulatedProvingResult(
|
|
|
660
695
|
daGas: TX_DA_GAS_OVERHEAD,
|
|
661
696
|
}),
|
|
662
697
|
),
|
|
663
|
-
/*feePayer=*/
|
|
664
|
-
/*expirationTimestamp=*/
|
|
698
|
+
/*feePayer=*/ feePayer,
|
|
699
|
+
/*expirationTimestamp=*/ expirationTimestamp,
|
|
665
700
|
hasPublicCalls ? inputsForPublic : undefined,
|
|
666
701
|
!hasPublicCalls ? inputsForRollup : undefined,
|
|
667
702
|
);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
|
|
3
|
+
/** In-memory store for ephemeral arrays scoped to a single contract call frame. */
|
|
4
|
+
export class EphemeralArrayService {
|
|
5
|
+
/**
|
|
6
|
+
* Maps a slot to the elements of the array stored at that slot. Each element is a serialized representation of
|
|
7
|
+
* the original type.
|
|
8
|
+
*/
|
|
9
|
+
#arrays: Map<string, Fr[][]> = new Map();
|
|
10
|
+
|
|
11
|
+
/** Returns all elements in the array, or an empty array if uninitialized. */
|
|
12
|
+
readArrayAt(slot: Fr): Fr[][] {
|
|
13
|
+
return this.#arrays.get(slot.toString()) ?? [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
#setArray(slot: Fr, array: Fr[][]): void {
|
|
17
|
+
this.#arrays.set(slot.toString(), array);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Returns the number of elements in the array at the given slot. */
|
|
21
|
+
len(slot: Fr): number {
|
|
22
|
+
return this.readArrayAt(slot).length;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Appends an element to the array and returns the new length. */
|
|
26
|
+
push(slot: Fr, elements: Fr[]): number {
|
|
27
|
+
const array = this.readArrayAt(slot);
|
|
28
|
+
array.push(elements);
|
|
29
|
+
this.#setArray(slot, array);
|
|
30
|
+
return array.length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Removes and returns the last element. Throws if empty. */
|
|
34
|
+
pop(slot: Fr): Fr[] {
|
|
35
|
+
const array = this.readArrayAt(slot);
|
|
36
|
+
if (array.length === 0) {
|
|
37
|
+
throw new Error(`Ephemeral array at slot ${slot} is empty`);
|
|
38
|
+
}
|
|
39
|
+
const element = array.pop()!;
|
|
40
|
+
this.#setArray(slot, array);
|
|
41
|
+
return element;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Returns the element at the given index. Throws if out of bounds. */
|
|
45
|
+
get(slot: Fr, index: number): Fr[] {
|
|
46
|
+
const array = this.readArrayAt(slot);
|
|
47
|
+
if (index < 0 || index >= array.length) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return array[index];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Overwrites the element at the given index. Throws if out of bounds. */
|
|
56
|
+
set(slot: Fr, index: number, value: Fr[]): void {
|
|
57
|
+
const array = this.readArrayAt(slot);
|
|
58
|
+
if (index < 0 || index >= array.length) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
array[index] = value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Removes the element at the given index, shifting subsequent elements backward. Throws if out of bounds. */
|
|
67
|
+
remove(slot: Fr, index: number): void {
|
|
68
|
+
const array = this.readArrayAt(slot);
|
|
69
|
+
if (index < 0 || index >= array.length) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Ephemeral array index ${index} out of bounds for array of length ${array.length} at slot ${slot}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
array.splice(index, 1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Removes all elements from the array. */
|
|
78
|
+
clear(slot: Fr): void {
|
|
79
|
+
this.#arrays.delete(slot.toString());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Allocates a fresh, unused slot for a new ephemeral array. */
|
|
83
|
+
allocateSlot(): Fr {
|
|
84
|
+
let slot: Fr;
|
|
85
|
+
do {
|
|
86
|
+
slot = Fr.random();
|
|
87
|
+
} while (this.#arrays.has(slot.toString()));
|
|
88
|
+
return slot;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Creates a new ephemeral array pre-populated with the given elements and returns its slot. */
|
|
92
|
+
newArray(elements: Fr[][]): Fr {
|
|
93
|
+
const slot = this.allocateSlot();
|
|
94
|
+
this.#setArray(slot, elements);
|
|
95
|
+
return slot;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Copies `count` elements from the source array to the destination array (overwrites destination). */
|
|
99
|
+
copy(srcSlot: Fr, dstSlot: Fr, count: number): void {
|
|
100
|
+
const srcArray = this.readArrayAt(srcSlot);
|
|
101
|
+
if (count > srcArray.length) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Cannot copy ${count} elements from ephemeral array of length ${srcArray.length} at slot ${srcSlot}`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
// Deep copy the elements to avoid aliasing
|
|
107
|
+
const copied = srcArray.slice(0, count).map(el => [...el]);
|
|
108
|
+
this.#setArray(dstSlot, copied);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
import { ExtendedDirectionalAppTaggingSecret, type
|
|
1
|
+
import { ExtendedDirectionalAppTaggingSecret, type TaggingIndexRange } from '@aztec/stdlib/logs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A map that stores the tagging index for a given extended directional app tagging secret.
|
|
4
|
+
* A map that stores the tagging index range for a given extended directional app tagging secret.
|
|
5
5
|
* Note: The directional app tagging secret is unique for a (sender, recipient, contract) tuple while the direction
|
|
6
6
|
* of sender -> recipient matters.
|
|
7
7
|
*/
|
|
8
8
|
export class ExecutionTaggingIndexCache {
|
|
9
|
-
private taggingIndexMap: Map<string, number> = new Map();
|
|
9
|
+
private taggingIndexMap: Map<string, { lowestIndex: number; highestIndex: number }> = new Map();
|
|
10
10
|
|
|
11
11
|
public getLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret): number | undefined {
|
|
12
|
-
return this.taggingIndexMap.get(secret.toString());
|
|
12
|
+
return this.taggingIndexMap.get(secret.toString())?.highestIndex;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
public setLastUsedIndex(secret: ExtendedDirectionalAppTaggingSecret, index: number) {
|
|
16
16
|
const currentValue = this.taggingIndexMap.get(secret.toString());
|
|
17
|
-
if (currentValue !== undefined && currentValue !== index - 1) {
|
|
18
|
-
throw new Error(`Invalid tagging index update. Current value: ${currentValue}, new value: ${index}`);
|
|
17
|
+
if (currentValue !== undefined && currentValue.highestIndex !== index - 1) {
|
|
18
|
+
throw new Error(`Invalid tagging index update. Current value: ${currentValue.highestIndex}, new value: ${index}`);
|
|
19
|
+
}
|
|
20
|
+
if (currentValue !== undefined) {
|
|
21
|
+
currentValue.highestIndex = index;
|
|
22
|
+
} else {
|
|
23
|
+
this.taggingIndexMap.set(secret.toString(), { lowestIndex: index, highestIndex: index });
|
|
19
24
|
}
|
|
20
|
-
this.taggingIndexMap.set(secret.toString(), index);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
|
-
* Returns the
|
|
28
|
+
* Returns the tagging index ranges that were used in this execution (and that need to be stored in the db).
|
|
25
29
|
*/
|
|
26
|
-
public
|
|
27
|
-
return Array.from(this.taggingIndexMap.entries()).map(([secret,
|
|
30
|
+
public getUsedTaggingIndexRanges(): TaggingIndexRange[] {
|
|
31
|
+
return Array.from(this.taggingIndexMap.entries()).map(([secret, { lowestIndex, highestIndex }]) => ({
|
|
28
32
|
extendedSecret: ExtendedDirectionalAppTaggingSecret.fromString(secret),
|
|
29
|
-
|
|
33
|
+
lowestIndex,
|
|
34
|
+
highestIndex,
|
|
30
35
|
}));
|
|
31
36
|
}
|
|
32
37
|
}
|
|
@@ -4,6 +4,7 @@ export { HashedValuesCache } from './hashed_values_cache.js';
|
|
|
4
4
|
export { pickNotes } from './pick_notes.js';
|
|
5
5
|
export type { NoteData, IMiscOracle, IUtilityExecutionOracle, IPrivateExecutionOracle } from './oracle/interfaces.js';
|
|
6
6
|
export { MessageLoadOracleInputs } from './oracle/message_load_oracle_inputs.js';
|
|
7
|
+
export { MessageContextService } from '../messages/message_context_service.js';
|
|
7
8
|
export { UtilityExecutionOracle } from './oracle/utility_execution_oracle.js';
|
|
8
9
|
export { PrivateExecutionOracle } from './oracle/private_execution_oracle.js';
|
|
9
10
|
export { Oracle } from './oracle/oracle.js';
|
|
@@ -6,7 +6,7 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Intermediate struct used to perform batch event validation by PXE. The `utilityValidateAndStoreEnqueuedNotesAndEvents` oracle
|
|
9
|
-
* expects for values of this type to be stored in a `
|
|
9
|
+
* expects for values of this type to be stored in a `EphemeralArray`.
|
|
10
10
|
*/
|
|
11
11
|
export class EventValidationRequest {
|
|
12
12
|
constructor(
|
|
@@ -16,7 +16,6 @@ export class EventValidationRequest {
|
|
|
16
16
|
public serializedEvent: Fr[],
|
|
17
17
|
public eventCommitment: Fr,
|
|
18
18
|
public txHash: TxHash,
|
|
19
|
-
public recipient: AztecAddress,
|
|
20
19
|
) {}
|
|
21
20
|
|
|
22
21
|
static fromFields(fields: Fr[], maxEventSerializedLen: number): EventValidationRequest {
|
|
@@ -33,7 +32,6 @@ export class EventValidationRequest {
|
|
|
33
32
|
|
|
34
33
|
const eventCommitment = reader.readField();
|
|
35
34
|
const txHash = TxHash.fromField(reader.readField());
|
|
36
|
-
const recipient = AztecAddress.fromField(reader.readField());
|
|
37
35
|
|
|
38
36
|
if (reader.remainingFields() !== 0) {
|
|
39
37
|
throw new Error(
|
|
@@ -48,7 +46,6 @@ export class EventValidationRequest {
|
|
|
48
46
|
serializedEvent,
|
|
49
47
|
eventCommitment,
|
|
50
48
|
txHash,
|
|
51
|
-
recipient,
|
|
52
49
|
);
|
|
53
50
|
}
|
|
54
51
|
}
|