@aztec/pxe 0.0.1-commit.e6bd8901 → 0.0.1-commit.ec7ac5448
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 +5 -3
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +17 -5
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +60 -31
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +201 -74
- 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 +7 -7
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -11
- 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 +4 -6
- 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 +8 -10
- 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 +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +4 -7
- 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 +6 -11
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +62 -46
- 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 +75 -44
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +310 -113
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +53 -79
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +109 -89
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +124 -67
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +326 -140
- 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 +9 -2
- 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 +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +44 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +104 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +20 -16
- 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 -18
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- 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 +23 -9
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +24 -10
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
- 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 +4 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -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 +30 -11
- package/dest/events/event_service.d.ts +5 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +20 -9
- 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 +8 -9
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +38 -62
- 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 +7 -8
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +23 -15
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- 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/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 +73 -24
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +131 -78
- 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_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 +39 -36
- 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 +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +157 -72
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +13 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +147 -107
- 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 +84 -61
- package/dest/storage/private_event_store/stored_private_event.d.ts +4 -4
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -1
- package/dest/storage/private_event_store/stored_private_event.js +2 -2
- 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 +29 -28
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +233 -137
- package/dest/tagging/get_all_logs_by_tags.d.ts +4 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/index.d.ts +3 -3
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +5 -6
- 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 -8
- 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 +12 -11
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +5 -9
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +13 -7
- 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 +6 -8
- 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 +36 -24
- package/package.json +25 -16
- package/src/bin/check_oracle_version.ts +4 -4
- package/src/block_synchronizer/block_synchronizer.ts +29 -19
- package/src/config/index.ts +1 -1
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +360 -133
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -14
- package/src/contract_function_simulator/index.ts +1 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +9 -9
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +4 -10
- package/src/contract_function_simulator/oracle/interfaces.ts +90 -62
- package/src/contract_function_simulator/oracle/legacy_oracle_mappings.ts +104 -0
- package/src/contract_function_simulator/oracle/oracle.ts +391 -150
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -4
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +136 -187
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +544 -174
- package/src/contract_function_simulator/pick_notes.ts +9 -2
- package/src/contract_function_simulator/proxied_contract_data_source.ts +8 -1
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +170 -0
- package/src/contract_sync/{index.ts → helpers.ts} +23 -25
- package/src/debug/pxe_debug_utils.ts +63 -19
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +18 -18
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +19 -18
- package/src/entrypoints/pxe_creation_options.ts +9 -1
- package/src/entrypoints/server/index.ts +3 -2
- package/src/entrypoints/server/utils.ts +24 -29
- package/src/events/event_service.ts +21 -10
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +72 -106
- package/src/messages/message_context_service.ts +44 -0
- package/src/notes/note_service.ts +24 -16
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -10
- 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 +243 -131
- 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_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +42 -34
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +186 -76
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +166 -132
- package/src/storage/private_event_store/private_event_store.ts +102 -81
- package/src/storage/private_event_store/stored_private_event.ts +3 -3
- 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 +287 -156
- package/src/tagging/get_all_logs_by_tags.ts +31 -7
- package/src/tagging/index.ts +2 -2
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +9 -12
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +12 -17
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +25 -12
- 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 +30 -29
- package/dest/contract_sync/index.d.ts +0 -23
- package/dest/contract_sync/index.d.ts.map +0 -1
- 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
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
export * from '../../notes_filter.js';
|
|
1
2
|
export * from '../../pxe.js';
|
|
2
3
|
export * from '../../config/index.js';
|
|
3
4
|
export * from '../../error_enriching.js';
|
|
4
5
|
export * from '../../storage/index.js';
|
|
5
6
|
export * from './utils.js';
|
|
6
7
|
export { NoteService } from '../../notes/note_service.js';
|
|
7
|
-
export {
|
|
8
|
+
export { ORACLE_VERSION_MAJOR, ORACLE_VERSION_MINOR } from '../../oracle_version.js';
|
|
8
9
|
export { type PXECreationOptions } from '../pxe_creation_options.js';
|
|
9
10
|
export { JobCoordinator } from '../../job_coordinator/job_coordinator.js';
|
|
10
|
-
export {
|
|
11
|
+
export { ContractSyncService } from '../../contract_sync/contract_sync_service.js';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { BBPrivateKernelProver } from '@aztec/bb-prover/client';
|
|
2
1
|
import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
|
|
3
|
-
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
4
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
3
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
4
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
@@ -11,7 +9,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
11
9
|
import type { PXEConfig } from '../../config/index.js';
|
|
12
10
|
import { PXE } from '../../pxe.js';
|
|
13
11
|
import { PXE_DATA_SCHEMA_VERSION } from '../../storage/index.js';
|
|
14
|
-
import type
|
|
12
|
+
import { type PXECreationOptions, isPrivateKernelProver } from '../pxe_creation_options.js';
|
|
15
13
|
|
|
16
14
|
type PXEConfigWithoutDefaults = Omit<PXEConfig, 'l1Contracts' | 'l1ChainId' | 'l2BlockBatchSize' | 'rollupVersion'>;
|
|
17
15
|
|
|
@@ -20,17 +18,13 @@ export async function createPXE(
|
|
|
20
18
|
config: PXEConfigWithoutDefaults,
|
|
21
19
|
options: PXECreationOptions = { loggers: {} },
|
|
22
20
|
) {
|
|
21
|
+
const actor = options.loggerActorLabel;
|
|
22
|
+
const recorderLogger = createLogger('simulator:acvm:recording', { actor });
|
|
23
23
|
const recorder = process.env.CIRCUIT_RECORD_DIR
|
|
24
|
-
? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR)
|
|
25
|
-
: new MemoryCircuitRecorder();
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const logSuffix =
|
|
29
|
-
typeof options.useLogSuffix === 'boolean'
|
|
30
|
-
? options.useLogSuffix
|
|
31
|
-
? randomBytes(3).toString('hex')
|
|
32
|
-
: undefined
|
|
33
|
-
: options.useLogSuffix;
|
|
24
|
+
? new FileCircuitRecorder(process.env.CIRCUIT_RECORD_DIR, recorderLogger)
|
|
25
|
+
: new MemoryCircuitRecorder(recorderLogger);
|
|
26
|
+
const simulatorLogger = createLogger('wasm-simulator', { actor });
|
|
27
|
+
const simulator = new SimulatorRecorderWrapper(new WASMSimulator(simulatorLogger), recorder);
|
|
34
28
|
const loggers = options.loggers ?? {};
|
|
35
29
|
|
|
36
30
|
const { l1ChainId, l1ContractAddresses: l1Contracts, rollupVersion } = await aztecNode.getNodeInfo();
|
|
@@ -43,17 +37,18 @@ export async function createPXE(
|
|
|
43
37
|
};
|
|
44
38
|
|
|
45
39
|
if (!options.store) {
|
|
46
|
-
const storeLogger = loggers.store
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const storeLogger = loggers.store ?? createLogger('pxe:data:lmdb', { actor });
|
|
41
|
+
options.store = await createStore(
|
|
42
|
+
'pxe_data',
|
|
43
|
+
PXE_DATA_SCHEMA_VERSION,
|
|
44
|
+
configWithContracts,
|
|
45
|
+
storeLogger.getBindings(),
|
|
46
|
+
);
|
|
50
47
|
}
|
|
51
|
-
const proverLogger = loggers.prover
|
|
52
|
-
? loggers.prover
|
|
53
|
-
: createLogger('pxe:bb:native' + (logSuffix ? `:${logSuffix}` : ''));
|
|
48
|
+
const proverLogger = loggers.prover ?? createLogger('pxe:bb:native', { actor });
|
|
54
49
|
|
|
55
50
|
let prover;
|
|
56
|
-
if (options.proverOrOptions
|
|
51
|
+
if (isPrivateKernelProver(options.proverOrOptions)) {
|
|
57
52
|
prover = options.proverOrOptions;
|
|
58
53
|
} else {
|
|
59
54
|
prover = new BBBundlePrivateKernelProver(simulator, { ...options.proverOrOptions, logger: proverLogger });
|
|
@@ -61,15 +56,15 @@ export async function createPXE(
|
|
|
61
56
|
|
|
62
57
|
const protocolContractsProvider = new BundledProtocolContractsProvider();
|
|
63
58
|
|
|
64
|
-
const pxeLogger = loggers.pxe
|
|
65
|
-
const pxe = await PXE.create(
|
|
66
|
-
aztecNode,
|
|
67
|
-
options.store,
|
|
68
|
-
prover,
|
|
59
|
+
const pxeLogger = loggers.pxe ?? createLogger('pxe:service', { actor });
|
|
60
|
+
const pxe = await PXE.create({
|
|
61
|
+
node: aztecNode,
|
|
62
|
+
store: options.store,
|
|
63
|
+
proofCreator: prover,
|
|
69
64
|
simulator,
|
|
70
65
|
protocolContractsProvider,
|
|
71
|
-
configWithContracts,
|
|
72
|
-
pxeLogger,
|
|
73
|
-
);
|
|
66
|
+
config: configWithContracts,
|
|
67
|
+
loggerOrSuffix: pxeLogger,
|
|
68
|
+
});
|
|
74
69
|
return pxe;
|
|
75
70
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
3
|
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
5
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
5
6
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
6
|
-
import type { TxHash } from '@aztec/stdlib/tx';
|
|
7
|
+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
7
8
|
|
|
8
|
-
import { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
9
9
|
import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
10
10
|
|
|
11
11
|
export class EventService {
|
|
12
12
|
constructor(
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly anchorBlockHeader: BlockHeader,
|
|
14
14
|
private readonly aztecNode: AztecNode,
|
|
15
15
|
private readonly privateEventStore: PrivateEventStore,
|
|
16
16
|
private readonly jobId: string,
|
|
17
|
+
private readonly log = createLogger('pxe:event_service'),
|
|
17
18
|
) {}
|
|
18
19
|
|
|
19
20
|
public async validateAndStoreEvent(
|
|
@@ -29,28 +30,38 @@ export class EventService {
|
|
|
29
30
|
// (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
|
|
30
31
|
// maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
|
|
31
32
|
// since `fetchTaggedLogs` only processes logs up to the synced block.
|
|
32
|
-
const [
|
|
33
|
-
this.anchorBlockStore.getBlockHeader(),
|
|
33
|
+
const [siloedEventCommitment, txEffect] = await Promise.all([
|
|
34
34
|
siloNullifier(contractAddress, eventCommitment),
|
|
35
35
|
this.aztecNode.getTxEffect(txHash),
|
|
36
36
|
]);
|
|
37
37
|
|
|
38
|
-
const anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
38
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
39
39
|
|
|
40
40
|
if (!txEffect) {
|
|
41
|
-
|
|
41
|
+
// We error out instead of just logging a warning and skipping the event because this would indicate a bug. This
|
|
42
|
+
// is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
|
|
43
|
+
// tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
|
|
44
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} when processing an event.`);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
45
|
-
|
|
48
|
+
// We should never process a message from a tx past the anchor block. If we got here, a preprocessing step made
|
|
49
|
+
// a mistake.
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Obtained a newer tx effect for ${txHash} for an event validation request than the anchor block ${anchorBlockNumber}. This is a bug as smart contracts should not issue event validation requests for events from blocks newer than the anchor block.`,
|
|
52
|
+
);
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
// Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
|
|
49
56
|
const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
|
|
50
57
|
if (eventIndexInTx === -1) {
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
// Unlike in NoteService, this might not be a bug since the commitment hasn't been verified yet in the message
|
|
59
|
+
// processing pipeline. A malformed or malicious message could trigger this condition. Because of this we don't
|
|
60
|
+
// error out and we just show a warning.
|
|
61
|
+
this.log.warn(
|
|
62
|
+
`Skipping event whose commitment is not present in its tx. siloedEventCommitment=${siloedEventCommitment}, contract=${contractAddress}, selector=${selector}, eventCommitment=${eventCommitment}, txHash=${txHash}`,
|
|
53
63
|
);
|
|
64
|
+
return;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
return this.privateEventStore.storePrivateEventLog(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -40,7 +40,7 @@ export interface StagedStore {
|
|
|
40
40
|
* using a job queue with concurrency=1.
|
|
41
41
|
*/
|
|
42
42
|
export class JobCoordinator {
|
|
43
|
-
private readonly log
|
|
43
|
+
private readonly log: Logger;
|
|
44
44
|
|
|
45
45
|
/** The underlying KV store */
|
|
46
46
|
kvStore: AztecAsyncKVStore;
|
|
@@ -48,8 +48,9 @@ export class JobCoordinator {
|
|
|
48
48
|
#currentJobId: string | undefined;
|
|
49
49
|
#stores: Map<string, StagedStore> = new Map();
|
|
50
50
|
|
|
51
|
-
constructor(kvStore: AztecAsyncKVStore) {
|
|
51
|
+
constructor(kvStore: AztecAsyncKVStore, bindings?: LoggerBindings) {
|
|
52
52
|
this.kvStore = kvStore;
|
|
53
|
+
this.log = createLogger('pxe:job_coordinator', bindings);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
package/src/logs/log_service.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
2
|
import type { KeyStore } from '@aztec/key-store';
|
|
4
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
6
|
-
import type { CompleteAddress } from '@aztec/stdlib/contract';
|
|
7
4
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
8
|
-
import {
|
|
5
|
+
import { ExtendedDirectionalAppTaggingSecret, PendingTaggedLog, SiloedTag, Tag } from '@aztec/stdlib/logs';
|
|
6
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
9
7
|
|
|
10
8
|
import type { LogRetrievalRequest } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
|
|
11
9
|
import { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
|
|
12
10
|
import { AddressStore } from '../storage/address_store/address_store.js';
|
|
13
|
-
import { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
14
|
-
import { CapsuleStore } from '../storage/capsule_store/capsule_store.js';
|
|
15
11
|
import type { RecipientTaggingStore } from '../storage/tagging_store/recipient_tagging_store.js';
|
|
16
12
|
import type { SenderAddressBookStore } from '../storage/tagging_store/sender_address_book_store.js';
|
|
17
13
|
import {
|
|
@@ -21,30 +17,41 @@ import {
|
|
|
21
17
|
} from '../tagging/index.js';
|
|
22
18
|
|
|
23
19
|
export class LogService {
|
|
24
|
-
private log
|
|
20
|
+
private log: Logger;
|
|
25
21
|
|
|
26
22
|
constructor(
|
|
27
23
|
private readonly aztecNode: AztecNode,
|
|
28
|
-
private readonly
|
|
24
|
+
private readonly anchorBlockHeader: BlockHeader,
|
|
29
25
|
private readonly keyStore: KeyStore,
|
|
30
|
-
private readonly capsuleStore: CapsuleStore,
|
|
31
26
|
private readonly recipientTaggingStore: RecipientTaggingStore,
|
|
32
27
|
private readonly senderAddressBookStore: SenderAddressBookStore,
|
|
33
28
|
private readonly addressStore: AddressStore,
|
|
34
29
|
private readonly jobId: string,
|
|
35
|
-
|
|
30
|
+
bindings?: LoggerBindings,
|
|
31
|
+
) {
|
|
32
|
+
this.log = createLogger('pxe:log_service', bindings);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async fetchLogsByTag(
|
|
36
|
+
contractAddress: AztecAddress,
|
|
37
|
+
logRetrievalRequests: LogRetrievalRequest[],
|
|
38
|
+
): Promise<(LogRetrievalResponse | null)[]> {
|
|
39
|
+
for (const request of logRetrievalRequests) {
|
|
40
|
+
if (!contractAddress.equals(request.contractAddress)) {
|
|
41
|
+
throw new Error(`Got a log retrieval request from ${request.contractAddress}, expected ${contractAddress}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
36
44
|
|
|
37
|
-
public async bulkRetrieveLogs(logRetrievalRequests: LogRetrievalRequest[]): Promise<(LogRetrievalResponse | null)[]> {
|
|
38
45
|
return await Promise.all(
|
|
39
46
|
logRetrievalRequests.map(async request => {
|
|
40
47
|
const [publicLog, privateLog] = await Promise.all([
|
|
41
48
|
this.#getPublicLogByTag(request.tag, request.contractAddress),
|
|
42
|
-
this.#getPrivateLogByTag(await SiloedTag.
|
|
49
|
+
this.#getPrivateLogByTag(await SiloedTag.computeFromTagAndApp(request.tag, request.contractAddress)),
|
|
43
50
|
]);
|
|
44
51
|
|
|
45
52
|
if (publicLog !== null && privateLog !== null) {
|
|
46
|
-
|
|
47
|
-
`Found both a public and private log
|
|
53
|
+
this.log.warn(
|
|
54
|
+
`Found both a public and private log for tag ${request.tag} from contract ${request.contractAddress}. This may indicate a contract bug. Returning the public log.`,
|
|
48
55
|
);
|
|
49
56
|
}
|
|
50
57
|
|
|
@@ -54,8 +61,7 @@ export class LogService {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
async #getPublicLogByTag(tag: Tag, contractAddress: AztecAddress): Promise<LogRetrievalResponse | null> {
|
|
57
|
-
const
|
|
58
|
-
const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
|
|
64
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
59
65
|
const allLogsPerTag = await getAllPublicLogsByTagsFromContract(
|
|
60
66
|
this.aztecNode,
|
|
61
67
|
contractAddress,
|
|
@@ -67,9 +73,8 @@ export class LogService {
|
|
|
67
73
|
if (logsForTag.length === 0) {
|
|
68
74
|
return null;
|
|
69
75
|
} else if (logsForTag.length > 1) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`,
|
|
76
|
+
this.log.warn(
|
|
77
|
+
`Expected at most 1 public log for tag ${tag} and contract ${contractAddress.toString()}, got ${logsForTag.length}. This may indicate a contract bug. Returning the first log.`,
|
|
73
78
|
);
|
|
74
79
|
}
|
|
75
80
|
|
|
@@ -84,17 +89,15 @@ export class LogService {
|
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
async #getPrivateLogByTag(siloedTag: SiloedTag): Promise<LogRetrievalResponse | null> {
|
|
87
|
-
const
|
|
88
|
-
const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
|
|
92
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
89
93
|
const allLogsPerTag = await getAllPrivateLogsByTags(this.aztecNode, [siloedTag], anchorBlockHash);
|
|
90
94
|
const logsForTag = allLogsPerTag[0];
|
|
91
95
|
|
|
92
96
|
if (logsForTag.length === 0) {
|
|
93
97
|
return null;
|
|
94
98
|
} else if (logsForTag.length > 1) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`,
|
|
99
|
+
this.log.warn(
|
|
100
|
+
`Expected at most 1 private log for tag ${siloedTag}, got ${logsForTag.length}. This may indicate a contract bug. Returning the first log.`,
|
|
98
101
|
);
|
|
99
102
|
}
|
|
100
103
|
|
|
@@ -108,59 +111,46 @@ export class LogService {
|
|
|
108
111
|
);
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
public async
|
|
112
|
-
contractAddress
|
|
113
|
-
pendingTaggedLogArrayBaseSlot: Fr,
|
|
114
|
-
scopes?: AztecAddress[],
|
|
115
|
-
) {
|
|
116
|
-
this.log.verbose('Searching for tagged logs', { contract: contractAddress });
|
|
114
|
+
public async fetchTaggedLogs(contractAddress: AztecAddress, recipient: AztecAddress): Promise<PendingTaggedLog[]> {
|
|
115
|
+
this.log.verbose(`Fetching tagged logs for ${contractAddress.toString()}`);
|
|
117
116
|
|
|
118
117
|
// We only load logs from block up to and including the anchor block number
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
secret,
|
|
138
|
-
contractAddress,
|
|
139
|
-
this.aztecNode,
|
|
140
|
-
this.recipientTaggingStore,
|
|
141
|
-
anchorBlockNumber,
|
|
142
|
-
anchorBlockHash,
|
|
143
|
-
this.jobId,
|
|
144
|
-
),
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
// Flatten all logs from all secrets
|
|
149
|
-
const allLogs = logArrays.flat();
|
|
150
|
-
|
|
151
|
-
// Store the logs for this recipient
|
|
152
|
-
if (allLogs.length > 0) {
|
|
153
|
-
await this.#storePendingTaggedLogs(contractAddress, pendingTaggedLogArrayBaseSlot, recipient, allLogs);
|
|
154
|
-
}
|
|
155
|
-
}),
|
|
118
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
119
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
120
|
+
|
|
121
|
+
// Get all secrets for this recipient (one per sender)
|
|
122
|
+
const secrets = await this.#getSecretsForSenders(contractAddress, recipient);
|
|
123
|
+
|
|
124
|
+
// Load logs for all sender-recipient pairs in parallel
|
|
125
|
+
const logArrays = await Promise.all(
|
|
126
|
+
secrets.map(secret =>
|
|
127
|
+
loadPrivateLogsForSenderRecipientPair(
|
|
128
|
+
secret,
|
|
129
|
+
this.aztecNode,
|
|
130
|
+
this.recipientTaggingStore,
|
|
131
|
+
anchorBlockNumber,
|
|
132
|
+
anchorBlockHash,
|
|
133
|
+
this.jobId,
|
|
134
|
+
),
|
|
135
|
+
),
|
|
156
136
|
);
|
|
137
|
+
|
|
138
|
+
return logArrays
|
|
139
|
+
.flat()
|
|
140
|
+
.map(
|
|
141
|
+
scopedLog =>
|
|
142
|
+
new PendingTaggedLog(scopedLog.logData, scopedLog.txHash, scopedLog.noteHashes, scopedLog.firstNullifier),
|
|
143
|
+
);
|
|
157
144
|
}
|
|
158
145
|
|
|
159
146
|
async #getSecretsForSenders(
|
|
160
147
|
contractAddress: AztecAddress,
|
|
161
148
|
recipient: AztecAddress,
|
|
162
|
-
): Promise<
|
|
163
|
-
const recipientCompleteAddress = await this
|
|
149
|
+
): Promise<ExtendedDirectionalAppTaggingSecret[]> {
|
|
150
|
+
const recipientCompleteAddress = await this.addressStore.getCompleteAddress(recipient);
|
|
151
|
+
if (!recipientCompleteAddress) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
164
154
|
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
165
155
|
|
|
166
156
|
// We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
|
|
@@ -173,49 +163,25 @@ export class LogService {
|
|
|
173
163
|
);
|
|
174
164
|
|
|
175
165
|
return Promise.all(
|
|
176
|
-
deduplicatedSenders.map(sender => {
|
|
177
|
-
|
|
166
|
+
deduplicatedSenders.map(async sender => {
|
|
167
|
+
const secret = await ExtendedDirectionalAppTaggingSecret.compute(
|
|
178
168
|
recipientCompleteAddress,
|
|
179
169
|
recipientIvsk,
|
|
180
170
|
sender,
|
|
181
171
|
contractAddress,
|
|
182
172
|
recipient,
|
|
183
173
|
);
|
|
184
|
-
}),
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
#storePendingTaggedLogs(
|
|
189
|
-
contractAddress: AztecAddress,
|
|
190
|
-
capsuleArrayBaseSlot: Fr,
|
|
191
|
-
recipient: AztecAddress,
|
|
192
|
-
privateLogs: TxScopedL2Log[],
|
|
193
|
-
) {
|
|
194
|
-
// Build all pending tagged logs from the scoped logs
|
|
195
|
-
const pendingTaggedLogs = privateLogs.map(scopedLog => {
|
|
196
|
-
const pendingTaggedLog = new PendingTaggedLog(
|
|
197
|
-
scopedLog.logData,
|
|
198
|
-
scopedLog.txHash,
|
|
199
|
-
scopedLog.noteHashes,
|
|
200
|
-
scopedLog.firstNullifier,
|
|
201
|
-
recipient,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
return pendingTaggedLog.toFields();
|
|
205
|
-
});
|
|
206
174
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
175
|
+
if (!secret) {
|
|
176
|
+
// Note that all senders originate from either the SenderAddressBookStore or the KeyStore.
|
|
177
|
+
// TODO(F-512): make sure we actually prevent registering invalid senders.
|
|
178
|
+
throw new Error(
|
|
179
|
+
`Failed to compute a tagging secret for sender ${sender} - this implies this is an invalid address, which should not happen as they have been previously registered in PXE.`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
210
182
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
throw new Error(
|
|
215
|
-
`No public key registered for address ${account}.
|
|
216
|
-
Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
return completeAddress;
|
|
183
|
+
return secret;
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
220
186
|
}
|
|
221
187
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { MessageContext } from '@aztec/stdlib/logs';
|
|
4
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
/** Resolves transaction hashes into the context needed to process messages. */
|
|
7
|
+
export class MessageContextService {
|
|
8
|
+
constructor(private readonly aztecNode: AztecNode) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a list of tx hashes into their message contexts.
|
|
12
|
+
*
|
|
13
|
+
* For each tx hash, looks up the corresponding tx effect and extracts the note hashes and first nullifier needed to
|
|
14
|
+
* process messages that originated from that transaction. Returns `null` for tx hashes that are zero, not yet
|
|
15
|
+
* available, or in blocks beyond the anchor block.
|
|
16
|
+
*/
|
|
17
|
+
getMessageContextsByTxHash(txHashes: Fr[], anchorBlockNumber: number): Promise<(MessageContext | null)[]> {
|
|
18
|
+
// TODO: optimize, we might be hitting the node to get the same txHash repeatedly
|
|
19
|
+
return Promise.all(
|
|
20
|
+
txHashes.map(async txHashField => {
|
|
21
|
+
// A zero tx hash indicates a tx-less offchain message (e.g. one not tied to any onchain transaction).
|
|
22
|
+
// These messages don't have a transaction context to resolve, so we return null.
|
|
23
|
+
if (txHashField.isZero()) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const txHash = TxHash.fromField(txHashField);
|
|
28
|
+
const txEffect = await this.aztecNode.getTxEffect(txHash);
|
|
29
|
+
if (!txEffect || txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Every tx has at least one nullifier (the first nullifier derived from the tx hash). Hitting this condition
|
|
34
|
+
// would mean a buggy node, but since we need to access data.nullifiers[0], the defensive check does no harm.
|
|
35
|
+
const data = txEffect.data;
|
|
36
|
+
if (data.nullifiers.length === 0) {
|
|
37
|
+
throw new Error(`Tx effect for ${txHash} has no nullifiers`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return new MessageContext(data.txHash, data.noteHashes, data.nullifiers[0]);
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { DataInBlock } from '@aztec/stdlib/block';
|
|
4
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
4
|
import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
6
5
|
import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
|
|
7
6
|
import { Note, NoteDao, NoteStatus } from '@aztec/stdlib/note';
|
|
8
7
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
import type { TxHash } from '@aztec/stdlib/tx';
|
|
8
|
+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
10
9
|
|
|
11
|
-
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
12
10
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
13
11
|
|
|
14
12
|
export class NoteService {
|
|
15
13
|
constructor(
|
|
16
14
|
private readonly noteStore: NoteStore,
|
|
17
15
|
private readonly aztecNode: AztecNode,
|
|
18
|
-
private readonly
|
|
16
|
+
private readonly anchorBlockHeader: BlockHeader,
|
|
19
17
|
private readonly jobId: string,
|
|
20
18
|
) {}
|
|
21
19
|
|
|
@@ -33,7 +31,7 @@ export class NoteService {
|
|
|
33
31
|
owner: AztecAddress | undefined,
|
|
34
32
|
storageSlot: Fr,
|
|
35
33
|
status: NoteStatus,
|
|
36
|
-
scopes
|
|
34
|
+
scopes: AztecAddress[],
|
|
37
35
|
) {
|
|
38
36
|
const noteDaos = await this.noteStore.getNotes(
|
|
39
37
|
{
|
|
@@ -72,10 +70,10 @@ export class NoteService {
|
|
|
72
70
|
*
|
|
73
71
|
* @param contractAddress - The contract whose notes should be checked and nullified.
|
|
74
72
|
*/
|
|
75
|
-
public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
|
|
76
|
-
const anchorBlockHash =
|
|
73
|
+
public async syncNoteNullifiers(contractAddress: AztecAddress, scopes: AztecAddress[]): Promise<void> {
|
|
74
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
77
75
|
|
|
78
|
-
const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
|
|
76
|
+
const contractNotes = await this.noteStore.getNotes({ contractAddress, scopes }, this.jobId);
|
|
79
77
|
|
|
80
78
|
if (contractNotes.length === 0) {
|
|
81
79
|
return;
|
|
@@ -122,7 +120,7 @@ export class NoteService {
|
|
|
122
120
|
noteHash: Fr,
|
|
123
121
|
nullifier: Fr,
|
|
124
122
|
txHash: TxHash,
|
|
125
|
-
|
|
123
|
+
scope: AztecAddress,
|
|
126
124
|
): Promise<void> {
|
|
127
125
|
// We are going to store the new note in the NoteStore, which will let us later return it via `getNotes`.
|
|
128
126
|
// There's two things we need to check before we do this however:
|
|
@@ -143,9 +141,8 @@ export class NoteService {
|
|
|
143
141
|
// number which *should* be recent enough to be available, even for non-archive nodes.
|
|
144
142
|
// Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
|
|
145
143
|
// logs up to the synced block making this only an additional safety check.
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
|
|
144
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
145
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
149
146
|
|
|
150
147
|
// By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
|
|
151
148
|
// of other contracts, which would constitute a security breach.
|
|
@@ -157,16 +154,28 @@ export class NoteService {
|
|
|
157
154
|
this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
158
155
|
]);
|
|
159
156
|
if (!txEffect) {
|
|
160
|
-
|
|
157
|
+
// We error out instead of just logging a warning and skipping the note because this would indicate a bug. This
|
|
158
|
+
// is because the node has already served info about this tx either when obtaining the log (TxScopedL2Log contain
|
|
159
|
+
// tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
|
|
160
|
+
throw new Error(`Could not find tx effect for tx hash ${txHash} when processing a note.`);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
if (txEffect.l2BlockNumber > anchorBlockNumber) {
|
|
164
|
-
|
|
164
|
+
// If the message was delivered onchain, this would indicate a bug: log sync should never load logs from blocks
|
|
165
|
+
// newer than the anchor block. If the note came via an offchain message, it would likely also be a bug, since we
|
|
166
|
+
// sync a new anchor block before calling `process_message`. For this not to be a bug, the message would need to
|
|
167
|
+
// come from a newer block than the anchor served by the node, implying the node isn't properly synced.
|
|
168
|
+
// We therefore error out here rather than assuming the offchain message was constructed by a malicious
|
|
169
|
+
// sender with the intention of bricking recipient's PXE (if we assumed that we would just ignore the message).
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Obtained a newer tx effect for ${txHash} for a note validation request than the anchor block ${anchorBlockNumber}. This is a bug as we should not ever be processing a note from a newer block than the anchor block.`,
|
|
172
|
+
);
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
// Find the index of the note hash in the noteHashes array to determine note ordering within the tx
|
|
168
176
|
const noteIndexInTx = txEffect.data.noteHashes.findIndex(nh => nh.equals(uniqueNoteHash));
|
|
169
177
|
if (noteIndexInTx === -1) {
|
|
178
|
+
// Similar to the comment above - we error out as this would indicate a bug in nonce discovery.
|
|
170
179
|
throw new Error(`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present in tx ${txHash}`);
|
|
171
180
|
}
|
|
172
181
|
|
|
@@ -186,8 +195,7 @@ export class NoteService {
|
|
|
186
195
|
noteIndexInTx,
|
|
187
196
|
);
|
|
188
197
|
|
|
189
|
-
|
|
190
|
-
await this.noteStore.addNotes([noteDao], recipient, this.jobId);
|
|
198
|
+
await this.noteStore.addNotes([noteDao], scope, this.jobId);
|
|
191
199
|
|
|
192
200
|
if (nullifierIndex !== undefined) {
|
|
193
201
|
// We found nullifier index which implies that the note has already been nullified.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A filter used to fetch notes.
|
|
7
|
+
* @remarks This filter is applied as an intersection of all its params.
|
|
8
|
+
*/
|
|
9
|
+
export type NotesFilter = {
|
|
10
|
+
/**
|
|
11
|
+
* The contract address the note belongs to.
|
|
12
|
+
* @remarks Providing a contract address is required as we need that information to trigger private state sync.
|
|
13
|
+
*/
|
|
14
|
+
contractAddress: AztecAddress;
|
|
15
|
+
/** The owner of the note. */
|
|
16
|
+
owner?: AztecAddress;
|
|
17
|
+
/** The specific storage location of the note on the contract. */
|
|
18
|
+
storageSlot?: Fr;
|
|
19
|
+
/** The status of the note. Defaults to 'ACTIVE'. */
|
|
20
|
+
status?: NoteStatus;
|
|
21
|
+
/** The siloed nullifier for the note. */
|
|
22
|
+
siloedNullifier?: Fr;
|
|
23
|
+
scopes: AztecAddress[];
|
|
24
|
+
};
|