@aztec/pxe 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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/README.md +5 -5
- package/dest/bin/check_oracle_version.d.ts +1 -1
- package/dest/bin/check_oracle_version.js +110 -10
- package/dest/block_synchronizer/block_synchronizer.d.ts +39 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
- package/dest/{synchronizer/synchronizer.js → block_synchronizer/block_synchronizer.js} +23 -23
- package/dest/block_synchronizer/index.d.ts +2 -0
- package/dest/block_synchronizer/index.d.ts.map +1 -0
- package/dest/block_synchronizer/index.js +1 -0
- package/dest/config/index.d.ts +9 -17
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +10 -16
- package/dest/config/package_info.d.ts +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +44 -15
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +142 -57
- package/dest/contract_function_simulator/execution_note_cache.d.ts +11 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +28 -17
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.d.ts +4 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +2 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
- 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 +8 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +6 -3
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +12 -3
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +22 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.js +33 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/index.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +103 -0
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -4
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +10 -4
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +10 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts +17 -15
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +101 -81
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +11 -12
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +15 -24
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +51 -25
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +103 -27
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +65 -36
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +171 -69
- package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
- package/dest/contract_function_simulator/proxied_node.d.ts +1 -1
- package/dest/contract_function_simulator/proxied_node.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.d.ts +31 -0
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
- package/dest/debug/pxe_debug_utils.js +37 -0
- package/dest/entrypoints/client/bundle/index.d.ts +4 -3
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +21 -12
- package/dest/entrypoints/client/lazy/index.d.ts +4 -3
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts +8 -8
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +20 -11
- package/dest/entrypoints/pxe_creation_options.d.ts +5 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +5 -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 +5 -24
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +17 -45
- package/dest/error_enriching.d.ts +11 -0
- package/dest/error_enriching.d.ts.map +1 -0
- package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
- package/dest/events/event_service.d.ts +15 -0
- package/dest/events/event_service.d.ts.map +1 -0
- package/dest/events/event_service.js +47 -0
- package/dest/events/index.d.ts +2 -0
- package/dest/events/index.d.ts.map +1 -0
- package/dest/events/index.js +1 -0
- package/dest/events/private_event_filter_validator.d.ts +9 -0
- package/dest/events/private_event_filter_validator.d.ts.map +1 -0
- package/dest/events/private_event_filter_validator.js +39 -0
- package/dest/logs/log_service.d.ts +26 -0
- package/dest/logs/log_service.d.ts.map +1 -0
- package/dest/logs/log_service.js +120 -0
- package/dest/notes/index.d.ts +2 -0
- package/dest/notes/index.d.ts.map +1 -0
- package/dest/notes/index.js +1 -0
- package/dest/notes/note_service.d.ts +48 -0
- package/dest/notes/note_service.d.ts.map +1 -0
- package/dest/notes/note_service.js +152 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +3 -3
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +7 -7
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +1 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +6 -6
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/index.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +9 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +38 -32
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +10 -9
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +7 -7
- package/dest/public_storage/public_storage_service.d.ts +24 -0
- package/dest/public_storage/public_storage_service.d.ts.map +1 -0
- package/dest/public_storage/public_storage_service.js +26 -0
- package/dest/pxe.d.ts +232 -0
- package/dest/pxe.d.ts.map +1 -0
- package/dest/{pxe_service/pxe_service.js → pxe.js} +299 -324
- package/dest/storage/address_store/address_store.d.ts +11 -0
- package/dest/storage/address_store/address_store.d.ts.map +1 -0
- package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +1 -4
- package/dest/storage/address_store/index.d.ts +2 -0
- package/dest/storage/address_store/index.d.ts.map +1 -0
- package/dest/storage/address_store/index.js +1 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
- package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +2 -12
- package/dest/storage/anchor_block_store/index.d.ts +2 -0
- package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
- package/dest/storage/anchor_block_store/index.js +1 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +57 -0
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
- package/dest/storage/{capsule_data_provider/capsule_data_provider.js → capsule_store/capsule_store.js} +34 -10
- package/dest/storage/capsule_store/index.d.ts +2 -0
- package/dest/storage/capsule_store/index.d.ts.map +1 -0
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/{contract_data_provider/contract_data_provider.d.ts → contract_store/contract_store.d.ts} +10 -18
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
- package/dest/storage/{contract_data_provider/contract_data_provider.js → contract_store/contract_store.js} +46 -18
- package/dest/storage/contract_store/index.d.ts +2 -0
- package/dest/storage/contract_store/index.d.ts.map +1 -0
- package/dest/storage/contract_store/index.js +1 -0
- package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.d.ts +1 -1
- package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
- package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
- package/dest/storage/index.d.ts +8 -9
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +7 -8
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/note_store/index.d.ts +3 -0
- package/dest/storage/note_store/index.d.ts.map +1 -0
- package/dest/storage/note_store/index.js +2 -0
- package/dest/storage/note_store/note_store.d.ts +84 -0
- package/dest/storage/note_store/note_store.d.ts.map +1 -0
- package/dest/storage/{note_data_provider/note_data_provider.js → note_store/note_store.js} +144 -82
- package/dest/storage/private_event_store/private_event_store.d.ts +56 -0
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
- package/dest/storage/private_event_store/private_event_store.js +157 -0
- package/dest/storage/tagging_store/index.d.ts +4 -0
- package/dest/storage/tagging_store/index.d.ts.map +1 -0
- package/dest/storage/tagging_store/index.js +3 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +21 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/recipient_tagging_store.js +42 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_address_book_store.js +30 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +67 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_tagging_store.js +196 -0
- package/dest/tagging/index.d.ts +16 -0
- package/dest/tagging/index.d.ts.map +1 -0
- package/dest/tagging/index.js +23 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +14 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +14 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +29 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +20 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +32 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +18 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +55 -0
- package/dest/tree_membership/tree_membership_service.d.ts +52 -0
- package/dest/tree_membership/tree_membership_service.d.ts.map +1 -0
- package/dest/tree_membership/tree_membership_service.js +84 -0
- package/package.json +22 -24
- package/src/bin/check_oracle_version.ts +134 -10
- package/src/{synchronizer/synchronizer.ts → block_synchronizer/block_synchronizer.ts} +22 -23
- package/src/block_synchronizer/index.ts +1 -0
- package/src/config/index.ts +18 -32
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +233 -75
- package/src/contract_function_simulator/execution_note_cache.ts +33 -17
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
- package/src/contract_function_simulator/index.ts +3 -1
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +14 -2
- package/src/contract_function_simulator/noir-structs/utility_context.ts +42 -0
- package/src/contract_function_simulator/oracle/index.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +175 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +21 -5
- package/src/contract_function_simulator/oracle/oracle.ts +135 -80
- package/src/contract_function_simulator/oracle/private_execution.ts +22 -28
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +200 -56
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +260 -109
- package/src/contract_function_simulator/pick_notes.ts +1 -1
- package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
- package/src/debug/pxe_debug_utils.ts +48 -0
- package/src/entrypoints/client/bundle/index.ts +3 -2
- package/src/entrypoints/client/bundle/utils.ts +21 -23
- package/src/entrypoints/client/lazy/index.ts +3 -2
- package/src/entrypoints/client/lazy/utils.ts +20 -23
- package/src/entrypoints/pxe_creation_options.ts +4 -1
- package/src/entrypoints/server/index.ts +4 -2
- package/src/entrypoints/server/utils.ts +20 -68
- package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
- package/src/events/event_service.ts +77 -0
- package/src/events/index.ts +1 -0
- package/src/events/private_event_filter_validator.ts +48 -0
- package/src/logs/log_service.ts +202 -0
- package/src/notes/index.ts +1 -0
- package/src/notes/note_service.ts +200 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +5 -9
- package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +6 -6
- package/src/private_kernel/private_kernel_execution_prover.ts +51 -43
- package/src/private_kernel/private_kernel_oracle.ts +2 -1
- package/src/private_kernel/private_kernel_oracle_impl.ts +10 -9
- package/src/public_storage/public_storage_service.ts +33 -0
- package/src/{pxe_service/pxe_service.ts → pxe.ts} +349 -410
- package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +1 -7
- package/src/storage/address_store/index.ts +1 -0
- package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +2 -17
- package/src/storage/anchor_block_store/index.ts +1 -0
- package/src/storage/{capsule_data_provider/capsule_data_provider.ts → capsule_store/capsule_store.ts} +34 -12
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/{contract_data_provider/contract_data_provider.ts → contract_store/contract_store.ts} +67 -28
- package/src/storage/contract_store/index.ts +1 -0
- package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
- package/src/storage/index.ts +7 -8
- package/src/storage/note_store/index.ts +2 -0
- package/src/storage/{note_data_provider/note_data_provider.ts → note_store/note_store.ts} +173 -111
- package/src/storage/private_event_store/private_event_store.ts +213 -0
- package/src/storage/tagging_store/index.ts +3 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +53 -0
- package/src/storage/tagging_store/sender_address_book_store.ts +42 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +244 -0
- package/src/tagging/index.ts +28 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +129 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +43 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +96 -0
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +44 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +72 -0
- package/src/tree_membership/tree_membership_service.ts +112 -0
- package/dest/bin/index.d.ts +0 -3
- package/dest/bin/index.d.ts.map +0 -1
- package/dest/bin/index.js +0 -48
- package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
- package/dest/contract_function_simulator/execution_data_provider.js +0 -14
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
- package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
- package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
- package/dest/contract_function_simulator/tagging_utils.js +0 -23
- package/dest/pxe_service/error_enriching.d.ts +0 -11
- package/dest/pxe_service/error_enriching.d.ts.map +0 -1
- package/dest/pxe_service/index.d.ts +0 -3
- package/dest/pxe_service/index.d.ts.map +0 -1
- package/dest/pxe_service/index.js +0 -2
- package/dest/pxe_service/pxe_service.d.ts +0 -100
- package/dest/pxe_service/pxe_service.d.ts.map +0 -1
- package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.d.ts +0 -2
- package/dest/storage/address_data_provider/index.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.js +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/index.d.ts +0 -2
- package/dest/storage/capsule_data_provider/index.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.d.ts +0 -2
- package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/storage/data_provider.d.ts +0 -4
- package/dest/storage/data_provider.d.ts.map +0 -1
- package/dest/storage/data_provider.js +0 -1
- package/dest/storage/note_data_provider/index.d.ts +0 -3
- package/dest/storage/note_data_provider/index.d.ts.map +0 -1
- package/dest/storage/note_data_provider/index.js +0 -2
- package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
- package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
- package/dest/storage/note_data_provider/note_dao.js +0 -102
- package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
- package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
- package/dest/storage/sync_data_provider/index.d.ts +0 -2
- package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
- package/dest/storage/sync_data_provider/index.js +0 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.d.ts +0 -2
- package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.js +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
- package/dest/synchronizer/index.d.ts +0 -2
- package/dest/synchronizer/index.d.ts.map +0 -1
- package/dest/synchronizer/index.js +0 -1
- package/dest/synchronizer/synchronizer.d.ts +0 -35
- package/dest/synchronizer/synchronizer.d.ts.map +0 -1
- package/dest/test/pxe_test_suite.d.ts +0 -3
- package/dest/test/pxe_test_suite.d.ts.map +0 -1
- package/dest/test/pxe_test_suite.js +0 -97
- package/src/bin/index.ts +0 -62
- package/src/contract_function_simulator/execution_data_provider.ts +0 -361
- package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
- package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
- package/src/contract_function_simulator/tagging_utils.ts +0 -32
- package/src/pxe_service/index.ts +0 -2
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/capsule_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/data_provider.ts +0 -3
- package/src/storage/note_data_provider/index.ts +0 -2
- package/src/storage/note_data_provider/note_dao.ts +0 -154
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
- package/src/storage/sync_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
- package/src/synchronizer/index.ts +0 -1
- package/src/test/pxe_test_suite.ts +0 -113
|
@@ -1,1020 +0,0 @@
|
|
|
1
|
-
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { timesParallel } from '@aztec/foundation/collection';
|
|
3
|
-
import { Fr, Point } from '@aztec/foundation/fields';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
-
import type { KeyStore } from '@aztec/key-store';
|
|
6
|
-
import {
|
|
7
|
-
EventSelector,
|
|
8
|
-
type FunctionArtifactWithContractName,
|
|
9
|
-
FunctionSelector,
|
|
10
|
-
getFunctionArtifact,
|
|
11
|
-
} from '@aztec/stdlib/abi';
|
|
12
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import type { InBlock, L2Block, L2BlockNumber } from '@aztec/stdlib/block';
|
|
14
|
-
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
15
|
-
import { computeUniqueNoteHash, siloNoteHash, siloNullifier, siloPrivateLog } from '@aztec/stdlib/hash';
|
|
16
|
-
import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
|
|
17
|
-
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
18
|
-
import { computeAddressSecret, computeAppTaggingSecret } from '@aztec/stdlib/keys';
|
|
19
|
-
import {
|
|
20
|
-
IndexedTaggingSecret,
|
|
21
|
-
PendingTaggedLog,
|
|
22
|
-
PrivateLogWithTxData,
|
|
23
|
-
PublicLog,
|
|
24
|
-
PublicLogWithTxData,
|
|
25
|
-
TxScopedL2Log,
|
|
26
|
-
deriveEcdhSharedSecret,
|
|
27
|
-
} from '@aztec/stdlib/logs';
|
|
28
|
-
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
29
|
-
import { Note, type NoteStatus } from '@aztec/stdlib/note';
|
|
30
|
-
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
31
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
32
|
-
import { TxHash } from '@aztec/stdlib/tx';
|
|
33
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
34
|
-
|
|
35
|
-
import type { ExecutionDataProvider, ExecutionStats } from '../contract_function_simulator/execution_data_provider.js';
|
|
36
|
-
import { MessageLoadOracleInputs } from '../contract_function_simulator/oracle/message_load_oracle_inputs.js';
|
|
37
|
-
import { ORACLE_VERSION } from '../oracle_version.js';
|
|
38
|
-
import type { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
39
|
-
import type { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
40
|
-
import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
41
|
-
import { NoteDao } from '../storage/note_data_provider/note_dao.js';
|
|
42
|
-
import type { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
43
|
-
import type { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
|
|
44
|
-
import type { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
45
|
-
import type { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
46
|
-
import { EventValidationRequest } from './noir-structs/event_validation_request.js';
|
|
47
|
-
import { LogRetrievalRequest } from './noir-structs/log_retrieval_request.js';
|
|
48
|
-
import { LogRetrievalResponse } from './noir-structs/log_retrieval_response.js';
|
|
49
|
-
import { NoteValidationRequest } from './noir-structs/note_validation_request.js';
|
|
50
|
-
import type { ProxiedNode } from './proxied_node.js';
|
|
51
|
-
import { WINDOW_HALF_SIZE, getIndexedTaggingSecretsForTheWindow, getInitialIndexesMap } from './tagging_utils.js';
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* A data layer that provides and stores information needed for simulating/proving a transaction.
|
|
55
|
-
*/
|
|
56
|
-
export class PXEOracleInterface implements ExecutionDataProvider {
|
|
57
|
-
constructor(
|
|
58
|
-
private aztecNode: AztecNode | ProxiedNode,
|
|
59
|
-
private keyStore: KeyStore,
|
|
60
|
-
private contractDataProvider: ContractDataProvider,
|
|
61
|
-
private noteDataProvider: NoteDataProvider,
|
|
62
|
-
private capsuleDataProvider: CapsuleDataProvider,
|
|
63
|
-
private syncDataProvider: SyncDataProvider,
|
|
64
|
-
private taggingDataProvider: TaggingDataProvider,
|
|
65
|
-
private addressDataProvider: AddressDataProvider,
|
|
66
|
-
private privateEventDataProvider: PrivateEventDataProvider,
|
|
67
|
-
private log = createLogger('pxe:pxe_oracle_interface'),
|
|
68
|
-
) {}
|
|
69
|
-
|
|
70
|
-
getKeyValidationRequest(pkMHash: Fr, contractAddress: AztecAddress): Promise<KeyValidationRequest> {
|
|
71
|
-
return this.keyStore.getKeyValidationRequest(pkMHash, contractAddress);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
|
|
75
|
-
const completeAddress = await this.addressDataProvider.getCompleteAddress(account);
|
|
76
|
-
if (!completeAddress) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`No public key registered for address ${account}.
|
|
79
|
-
Register it by calling pxe.addAccount(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#simulation-error-no-public-key-registered-for-address-0x0-register-it-by-calling-pxeregisterrecipient-or-pxeregisteraccount`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
return completeAddress;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async getContractInstance(address: AztecAddress): Promise<ContractInstance> {
|
|
86
|
-
const instance = await this.contractDataProvider.getContractInstance(address);
|
|
87
|
-
if (!instance) {
|
|
88
|
-
throw new Error(`No contract instance found for address ${address.toString()}`);
|
|
89
|
-
}
|
|
90
|
-
return instance;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]) {
|
|
94
|
-
const noteDaos = await this.noteDataProvider.getNotes({
|
|
95
|
-
contractAddress,
|
|
96
|
-
storageSlot,
|
|
97
|
-
status,
|
|
98
|
-
scopes,
|
|
99
|
-
});
|
|
100
|
-
return noteDaos.map(({ contractAddress, storageSlot, noteNonce, note, noteHash, siloedNullifier, index }) => ({
|
|
101
|
-
contractAddress,
|
|
102
|
-
storageSlot,
|
|
103
|
-
noteNonce,
|
|
104
|
-
note,
|
|
105
|
-
noteHash,
|
|
106
|
-
siloedNullifier,
|
|
107
|
-
// PXE can use this index to get full MembershipWitness
|
|
108
|
-
index,
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async getFunctionArtifact(
|
|
113
|
-
contractAddress: AztecAddress,
|
|
114
|
-
selector: FunctionSelector,
|
|
115
|
-
): Promise<FunctionArtifactWithContractName> {
|
|
116
|
-
const artifact = await this.contractDataProvider.getFunctionArtifact(contractAddress, selector);
|
|
117
|
-
if (!artifact) {
|
|
118
|
-
throw new Error(`Function artifact not found for contract ${contractAddress} and selector ${selector}.`);
|
|
119
|
-
}
|
|
120
|
-
const debug = await this.contractDataProvider.getFunctionDebugMetadata(contractAddress, selector);
|
|
121
|
-
return {
|
|
122
|
-
...artifact,
|
|
123
|
-
debug,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async getFunctionArtifactByName(
|
|
128
|
-
contractAddress: AztecAddress,
|
|
129
|
-
functionName: string,
|
|
130
|
-
): Promise<FunctionArtifactWithContractName | undefined> {
|
|
131
|
-
const instance = await this.contractDataProvider.getContractInstance(contractAddress);
|
|
132
|
-
if (!instance) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
|
|
136
|
-
return artifact && getFunctionArtifact(artifact, functionName);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Fetches a message from the db, given its key.
|
|
141
|
-
* @param contractAddress - Address of a contract by which the message was emitted.
|
|
142
|
-
* @param messageHash - Hash of the message.
|
|
143
|
-
* @param secret - Secret used to compute a nullifier.
|
|
144
|
-
* @dev Contract address and secret are only used to compute the nullifier to get non-nullified messages
|
|
145
|
-
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
146
|
-
*/
|
|
147
|
-
async getL1ToL2MembershipWitness(
|
|
148
|
-
contractAddress: AztecAddress,
|
|
149
|
-
messageHash: Fr,
|
|
150
|
-
secret: Fr,
|
|
151
|
-
): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
|
|
152
|
-
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
153
|
-
this.aztecNode,
|
|
154
|
-
contractAddress,
|
|
155
|
-
messageHash,
|
|
156
|
-
secret,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
// Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
|
|
160
|
-
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async getNullifierIndex(nullifier: Fr) {
|
|
164
|
-
return await this.#findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async #findLeafIndex(blockNumber: L2BlockNumber, treeId: MerkleTreeId, leafValue: Fr): Promise<bigint | undefined> {
|
|
168
|
-
const [leafIndex] = await this.aztecNode.findLeavesIndexes(blockNumber, treeId, [leafValue]);
|
|
169
|
-
return leafIndex?.data;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public async getMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[]> {
|
|
173
|
-
const witness = await this.#tryGetMembershipWitness(blockNumber, treeId, leafValue);
|
|
174
|
-
if (!witness) {
|
|
175
|
-
throw new Error(`Leaf value ${leafValue} not found in tree ${MerkleTreeId[treeId]} at block ${blockNumber}`);
|
|
176
|
-
}
|
|
177
|
-
return witness;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async #tryGetMembershipWitness(blockNumber: number, treeId: MerkleTreeId, value: Fr): Promise<Fr[] | undefined> {
|
|
181
|
-
switch (treeId) {
|
|
182
|
-
case MerkleTreeId.NULLIFIER_TREE:
|
|
183
|
-
return (await this.aztecNode.getNullifierMembershipWitness(blockNumber, value))?.withoutPreimage().toFields();
|
|
184
|
-
case MerkleTreeId.NOTE_HASH_TREE:
|
|
185
|
-
return (await this.aztecNode.getNoteHashMembershipWitness(blockNumber, value))?.toFields();
|
|
186
|
-
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
187
|
-
return (await this.aztecNode.getPublicDataWitness(blockNumber, value))?.withoutPreimage().toFields();
|
|
188
|
-
case MerkleTreeId.ARCHIVE:
|
|
189
|
-
return (await this.aztecNode.getArchiveMembershipWitness(blockNumber, value))?.toFields();
|
|
190
|
-
default:
|
|
191
|
-
throw new Error('Not implemented');
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
public async getNullifierMembershipWitnessAtLatestBlock(nullifier: Fr) {
|
|
196
|
-
return this.getNullifierMembershipWitness(await this.getBlockNumber(), nullifier);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
public getNullifierMembershipWitness(
|
|
200
|
-
blockNumber: number,
|
|
201
|
-
nullifier: Fr,
|
|
202
|
-
): Promise<NullifierMembershipWitness | undefined> {
|
|
203
|
-
return this.aztecNode.getNullifierMembershipWitness(blockNumber, nullifier);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public getLowNullifierMembershipWitness(
|
|
207
|
-
blockNumber: number,
|
|
208
|
-
nullifier: Fr,
|
|
209
|
-
): Promise<NullifierMembershipWitness | undefined> {
|
|
210
|
-
return this.aztecNode.getLowNullifierMembershipWitness(blockNumber, nullifier);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public async getBlock(blockNumber: number): Promise<L2Block | undefined> {
|
|
214
|
-
return await this.aztecNode.getBlock(blockNumber);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
public async getPublicDataWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
218
|
-
return await this.aztecNode.getPublicDataWitness(blockNumber, leafSlot);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public async getPublicStorageAt(blockNumber: number, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
222
|
-
return await this.aztecNode.getPublicStorageAt(blockNumber, contract, slot);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Retrieve the latest block header synchronized by the PXE.
|
|
227
|
-
* @dev This structure is fed into the circuits simulator and is used to prove against certain historical roots.
|
|
228
|
-
* @returns The BlockHeader object.
|
|
229
|
-
* TODO: I think this naming is bad as it's not the latest block header synched by the node, but the latest block
|
|
230
|
-
* header synchronized by the PXE. Would rename this to something like getSynchronizedBlockHeader().
|
|
231
|
-
*/
|
|
232
|
-
getBlockHeader(): Promise<BlockHeader> {
|
|
233
|
-
return this.syncDataProvider.getBlockHeader();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public assertCompatibleOracleVersion(version: number): void {
|
|
237
|
-
if (version !== ORACLE_VERSION) {
|
|
238
|
-
throw new Error(`Incompatible oracle version. Expected version ${ORACLE_VERSION}, got ${version}.`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Fetches the latest block number synchronized by the node.
|
|
244
|
-
* @returns The block number.
|
|
245
|
-
*/
|
|
246
|
-
public async getBlockNumber(): Promise<number> {
|
|
247
|
-
return await this.aztecNode.getBlockNumber();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Fetches the timestamp of the latest block synchronized by the node.
|
|
252
|
-
* @returns The timestamp.
|
|
253
|
-
*/
|
|
254
|
-
public async getTimestamp(): Promise<UInt64> {
|
|
255
|
-
const latestBlockHeader = await this.aztecNode.getBlockHeader();
|
|
256
|
-
if (!latestBlockHeader) {
|
|
257
|
-
throw new Error('Latest block header not found when getting timestamp');
|
|
258
|
-
}
|
|
259
|
-
return latestBlockHeader.globalVariables.timestamp;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Fetches the current chain id.
|
|
264
|
-
* @returns The chain id.
|
|
265
|
-
*/
|
|
266
|
-
public async getChainId(): Promise<number> {
|
|
267
|
-
return await this.aztecNode.getChainId();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Fetches the current version.
|
|
272
|
-
* @returns The version.
|
|
273
|
-
*/
|
|
274
|
-
public async getVersion(): Promise<number> {
|
|
275
|
-
return await this.aztecNode.getVersion();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
|
|
279
|
-
return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Returns the full contents of your address book.
|
|
284
|
-
* This is used when calculating tags for incoming notes by deriving the shared secret, the contract-siloed tagging secret, and
|
|
285
|
-
* finally the index specified tag. We will then query the node with this tag for each address in the address book.
|
|
286
|
-
* @returns The full list of the users contact addresses.
|
|
287
|
-
*/
|
|
288
|
-
public getSenders(): Promise<AztecAddress[]> {
|
|
289
|
-
return this.taggingDataProvider.getSenderAddresses();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
|
|
294
|
-
* Includes the next index to be used used for tagging with this secret.
|
|
295
|
-
* @param contractAddress - The contract address to silo the secret for
|
|
296
|
-
* @param sender - The address sending the note
|
|
297
|
-
* @param recipient - The address receiving the note
|
|
298
|
-
* @returns An indexed tagging secret that can be used to tag notes.
|
|
299
|
-
*/
|
|
300
|
-
public async getIndexedTaggingSecretAsSender(
|
|
301
|
-
contractAddress: AztecAddress,
|
|
302
|
-
sender: AztecAddress,
|
|
303
|
-
recipient: AztecAddress,
|
|
304
|
-
): Promise<IndexedTaggingSecret> {
|
|
305
|
-
await this.syncTaggedLogsAsSender(contractAddress, sender, recipient);
|
|
306
|
-
|
|
307
|
-
const appTaggingSecret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
|
|
308
|
-
const [index] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([appTaggingSecret], sender);
|
|
309
|
-
|
|
310
|
-
return new IndexedTaggingSecret(appTaggingSecret, index);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
|
|
315
|
-
* @param contractAddress - The contract address to silo the secret for
|
|
316
|
-
* @param sender - The address sending the note
|
|
317
|
-
* @param recipient - The address receiving the note
|
|
318
|
-
*/
|
|
319
|
-
public async incrementAppTaggingSecretIndexAsSender(
|
|
320
|
-
contractAddress: AztecAddress,
|
|
321
|
-
sender: AztecAddress,
|
|
322
|
-
recipient: AztecAddress,
|
|
323
|
-
): Promise<void> {
|
|
324
|
-
const secret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
|
|
325
|
-
const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
|
|
326
|
-
this.log.debug(`Incrementing app tagging secret at ${contractName}(${contractAddress})`, {
|
|
327
|
-
secret,
|
|
328
|
-
sender,
|
|
329
|
-
recipient,
|
|
330
|
-
contractName,
|
|
331
|
-
contractAddress,
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const [index] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([secret], sender);
|
|
335
|
-
await this.taggingDataProvider.setTaggingSecretsIndexesAsSender(
|
|
336
|
-
[new IndexedTaggingSecret(secret, index + 1)],
|
|
337
|
-
sender,
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
async #calculateAppTaggingSecret(contractAddress: AztecAddress, sender: AztecAddress, recipient: AztecAddress) {
|
|
342
|
-
const senderCompleteAddress = await this.getCompleteAddress(sender);
|
|
343
|
-
const senderIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(sender);
|
|
344
|
-
return computeAppTaggingSecret(senderCompleteAddress, senderIvsk, recipient, contractAddress);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Returns the indexed tagging secrets for a given recipient and all the senders in the address book
|
|
349
|
-
* This method should be exposed as an oracle call to allow aztec.nr to perform the orchestration
|
|
350
|
-
* of the syncTaggedLogs and processTaggedLogs methods. However, it is not possible to do so at the moment,
|
|
351
|
-
* so we're keeping it private for now.
|
|
352
|
-
* @param contractAddress - The contract address to silo the secret for
|
|
353
|
-
* @param recipient - The address receiving the notes
|
|
354
|
-
* @returns A list of indexed tagging secrets
|
|
355
|
-
*/
|
|
356
|
-
async #getIndexedTaggingSecretsForSenders(
|
|
357
|
-
contractAddress: AztecAddress,
|
|
358
|
-
recipient: AztecAddress,
|
|
359
|
-
): Promise<IndexedTaggingSecret[]> {
|
|
360
|
-
const recipientCompleteAddress = await this.getCompleteAddress(recipient);
|
|
361
|
-
const recipientIvsk = await this.keyStore.getMasterIncomingViewingSecretKey(recipient);
|
|
362
|
-
|
|
363
|
-
// We implicitly add all PXE accounts as senders, this helps us decrypt tags on notes that we send to ourselves
|
|
364
|
-
// (recipient = us, sender = us)
|
|
365
|
-
const senders = [
|
|
366
|
-
...(await this.taggingDataProvider.getSenderAddresses()),
|
|
367
|
-
...(await this.keyStore.getAccounts()),
|
|
368
|
-
].filter((address, index, self) => index === self.findIndex(otherAddress => otherAddress.equals(address)));
|
|
369
|
-
const appTaggingSecrets = await Promise.all(
|
|
370
|
-
senders.map(contact =>
|
|
371
|
-
computeAppTaggingSecret(recipientCompleteAddress, recipientIvsk, contact, contractAddress),
|
|
372
|
-
),
|
|
373
|
-
);
|
|
374
|
-
const indexes = await this.taggingDataProvider.getTaggingSecretsIndexesAsRecipient(appTaggingSecrets, recipient);
|
|
375
|
-
return appTaggingSecrets.map((secret, i) => new IndexedTaggingSecret(secret, indexes[i]));
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Updates the local index of the shared tagging secret of a sender / recipient pair
|
|
380
|
-
* if a log with a larger index is found from the node.
|
|
381
|
-
* @param contractAddress - The address of the contract that the logs are tagged for
|
|
382
|
-
* @param sender - The address of the sender, we must know the sender's ivsk_m.
|
|
383
|
-
* @param recipient - The address of the recipient.
|
|
384
|
-
*/
|
|
385
|
-
public async syncTaggedLogsAsSender(
|
|
386
|
-
contractAddress: AztecAddress,
|
|
387
|
-
sender: AztecAddress,
|
|
388
|
-
recipient: AztecAddress,
|
|
389
|
-
): Promise<void> {
|
|
390
|
-
const appTaggingSecret = await this.#calculateAppTaggingSecret(contractAddress, sender, recipient);
|
|
391
|
-
const [oldIndex] = await this.taggingDataProvider.getTaggingSecretsIndexesAsSender([appTaggingSecret], sender);
|
|
392
|
-
|
|
393
|
-
// This algorithm works such that:
|
|
394
|
-
// 1. If we find minimum consecutive empty logs in a window of logs we set the index to the index of the last log
|
|
395
|
-
// we found and quit.
|
|
396
|
-
// 2. If we don't find minimum consecutive empty logs in a window of logs we slide the window to latest log index
|
|
397
|
-
// and repeat the process.
|
|
398
|
-
const MIN_CONSECUTIVE_EMPTY_LOGS = 10;
|
|
399
|
-
const WINDOW_SIZE = MIN_CONSECUTIVE_EMPTY_LOGS * 2;
|
|
400
|
-
|
|
401
|
-
let [numConsecutiveEmptyLogs, currentIndex] = [0, oldIndex];
|
|
402
|
-
do {
|
|
403
|
-
// We compute the tags for the current window of indexes
|
|
404
|
-
const currentTags = await timesParallel(WINDOW_SIZE, i => {
|
|
405
|
-
const indexedAppTaggingSecret = new IndexedTaggingSecret(appTaggingSecret, currentIndex + i);
|
|
406
|
-
return indexedAppTaggingSecret.computeSiloedTag(recipient, contractAddress);
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// We fetch the logs for the tags
|
|
410
|
-
const possibleLogs = await this.#getPrivateLogsByTags(currentTags);
|
|
411
|
-
|
|
412
|
-
// We find the index of the last log in the window that is not empty
|
|
413
|
-
const indexOfLastLog = possibleLogs.findLastIndex(possibleLog => possibleLog.length !== 0);
|
|
414
|
-
|
|
415
|
-
if (indexOfLastLog === -1) {
|
|
416
|
-
// We haven't found any logs in the current window so we stop looking
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// We move the current index to that of the last log we found
|
|
421
|
-
currentIndex += indexOfLastLog + 1;
|
|
422
|
-
|
|
423
|
-
// We compute the number of consecutive empty logs we found and repeat the process if we haven't found enough.
|
|
424
|
-
numConsecutiveEmptyLogs = WINDOW_SIZE - indexOfLastLog - 1;
|
|
425
|
-
} while (numConsecutiveEmptyLogs < MIN_CONSECUTIVE_EMPTY_LOGS);
|
|
426
|
-
|
|
427
|
-
const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
|
|
428
|
-
if (currentIndex !== oldIndex) {
|
|
429
|
-
await this.taggingDataProvider.setTaggingSecretsIndexesAsSender(
|
|
430
|
-
[new IndexedTaggingSecret(appTaggingSecret, currentIndex)],
|
|
431
|
-
sender,
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
this.log.debug(`Syncing logs for sender ${sender} at contract ${contractName}(${contractAddress})`, {
|
|
435
|
-
sender,
|
|
436
|
-
secret: appTaggingSecret,
|
|
437
|
-
index: currentIndex,
|
|
438
|
-
contractName,
|
|
439
|
-
contractAddress,
|
|
440
|
-
});
|
|
441
|
-
} else {
|
|
442
|
-
this.log.debug(`No new logs found for sender ${sender} at contract ${contractName}(${contractAddress})`);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Synchronizes the private logs tagged with scoped addresses and all the senders in the address book. Stores the found
|
|
448
|
-
* logs in CapsuleArray ready for a later retrieval in Aztec.nr.
|
|
449
|
-
* @param contractAddress - The address of the contract that the logs are tagged for.
|
|
450
|
-
* @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged logs capsule array in which
|
|
451
|
-
* found logs will be stored.
|
|
452
|
-
* @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
|
|
453
|
-
* synced.
|
|
454
|
-
*/
|
|
455
|
-
public async syncTaggedLogs(
|
|
456
|
-
contractAddress: AztecAddress,
|
|
457
|
-
pendingTaggedLogArrayBaseSlot: Fr,
|
|
458
|
-
scopes?: AztecAddress[],
|
|
459
|
-
) {
|
|
460
|
-
this.log.verbose('Searching for tagged logs', { contract: contractAddress });
|
|
461
|
-
|
|
462
|
-
const maxBlockNumber = await this.syncDataProvider.getBlockNumber();
|
|
463
|
-
|
|
464
|
-
// Ideally this algorithm would be implemented in noir, exposing its building blocks as oracles.
|
|
465
|
-
// However it is impossible at the moment due to the language not supporting nested slices.
|
|
466
|
-
// This nesting is necessary because for a given set of tags we don't
|
|
467
|
-
// know how many logs we will get back. Furthermore, these logs are of undetermined
|
|
468
|
-
// length, since we don't really know the note they correspond to until we decrypt them.
|
|
469
|
-
|
|
470
|
-
const recipients = scopes ? scopes : await this.keyStore.getAccounts();
|
|
471
|
-
const contractName = await this.contractDataProvider.getDebugContractName(contractAddress);
|
|
472
|
-
for (const recipient of recipients) {
|
|
473
|
-
// Get all the secrets for the recipient and sender pairs (#9365)
|
|
474
|
-
const secrets = await this.#getIndexedTaggingSecretsForSenders(contractAddress, recipient);
|
|
475
|
-
|
|
476
|
-
// We fetch logs for a window of indexes in a range:
|
|
477
|
-
// <latest_log_index - WINDOW_HALF_SIZE, latest_log_index + WINDOW_HALF_SIZE>.
|
|
478
|
-
//
|
|
479
|
-
// We use this window approach because it could happen that a sender might have messed up and inadvertently
|
|
480
|
-
// incremented their index without us getting any logs (for example, in case of a revert). If we stopped looking
|
|
481
|
-
// for logs the first time we don't receive any logs for a tag, we might never receive anything from that sender again.
|
|
482
|
-
// Also there's a possibility that we have advanced our index, but the sender has reused it, so we might have missed
|
|
483
|
-
// some logs. For these reasons, we have to look both back and ahead of the stored index.
|
|
484
|
-
let secretsAndWindows = secrets.map(secret => {
|
|
485
|
-
return {
|
|
486
|
-
appTaggingSecret: secret.appTaggingSecret,
|
|
487
|
-
leftMostIndex: Math.max(0, secret.index - WINDOW_HALF_SIZE),
|
|
488
|
-
rightMostIndex: secret.index + WINDOW_HALF_SIZE,
|
|
489
|
-
};
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
// As we iterate we store the largest index we have seen for a given secret to later on store it in the db.
|
|
493
|
-
const newLargestIndexMapToStore: { [k: string]: number } = {};
|
|
494
|
-
|
|
495
|
-
// The initial/unmodified indexes of the secrets stored in a key-value map where key is the app tagging secret.
|
|
496
|
-
const initialIndexesMap = getInitialIndexesMap(secrets);
|
|
497
|
-
|
|
498
|
-
while (secretsAndWindows.length > 0) {
|
|
499
|
-
const secretsForTheWholeWindow = getIndexedTaggingSecretsForTheWindow(secretsAndWindows);
|
|
500
|
-
const tagsForTheWholeWindow = await Promise.all(
|
|
501
|
-
secretsForTheWholeWindow.map(secret => secret.computeSiloedTag(recipient, contractAddress)),
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
// We store the new largest indexes we find in the iteration in the following map to later on construct
|
|
505
|
-
// a new set of secrets and windows to fetch logs for.
|
|
506
|
-
const newLargestIndexMapForIteration: { [k: string]: number } = {};
|
|
507
|
-
|
|
508
|
-
// Fetch the private logs for the tags and iterate over them
|
|
509
|
-
const logsByTags = await this.#getPrivateLogsByTags(tagsForTheWholeWindow);
|
|
510
|
-
this.log.debug(`Found ${logsByTags.filter(logs => logs.length > 0).length} logs as recipient ${recipient}`, {
|
|
511
|
-
recipient,
|
|
512
|
-
contractName,
|
|
513
|
-
contractAddress,
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
for (let logIndex = 0; logIndex < logsByTags.length; logIndex++) {
|
|
517
|
-
const logsByTag = logsByTags[logIndex];
|
|
518
|
-
if (logsByTag.length > 0) {
|
|
519
|
-
// We filter out the logs that are newer than the historical block number of the tx currently being constructed
|
|
520
|
-
const filteredLogsByBlockNumber = logsByTag.filter(l => l.blockNumber <= maxBlockNumber);
|
|
521
|
-
|
|
522
|
-
// We store the logs in capsules (to later be obtained in Noir)
|
|
523
|
-
await this.#storePendingTaggedLogs(
|
|
524
|
-
contractAddress,
|
|
525
|
-
pendingTaggedLogArrayBaseSlot,
|
|
526
|
-
recipient,
|
|
527
|
-
filteredLogsByBlockNumber,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
// We retrieve the indexed tagging secret corresponding to the log as I need that to evaluate whether
|
|
531
|
-
// a new largest index have been found.
|
|
532
|
-
const secretCorrespondingToLog = secretsForTheWholeWindow[logIndex];
|
|
533
|
-
const initialIndex = initialIndexesMap[secretCorrespondingToLog.appTaggingSecret.toString()];
|
|
534
|
-
|
|
535
|
-
if (
|
|
536
|
-
secretCorrespondingToLog.index >= initialIndex &&
|
|
537
|
-
(newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()] === undefined ||
|
|
538
|
-
secretCorrespondingToLog.index >=
|
|
539
|
-
newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()])
|
|
540
|
-
) {
|
|
541
|
-
// We have found a new largest index so we store it for later processing (storing it in the db + fetching
|
|
542
|
-
// the difference of the window sets of current and the next iteration)
|
|
543
|
-
newLargestIndexMapForIteration[secretCorrespondingToLog.appTaggingSecret.toString()] =
|
|
544
|
-
secretCorrespondingToLog.index + 1;
|
|
545
|
-
|
|
546
|
-
this.log.debug(
|
|
547
|
-
`Incrementing index to ${
|
|
548
|
-
secretCorrespondingToLog.index + 1
|
|
549
|
-
} at contract ${contractName}(${contractAddress})`,
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Now based on the new largest indexes we found, we will construct a new secrets and windows set to fetch logs
|
|
556
|
-
// for. Note that it's very unlikely that a new log from the current window would appear between the iterations
|
|
557
|
-
// so we fetch the logs only for the difference of the window sets.
|
|
558
|
-
const newSecretsAndWindows = [];
|
|
559
|
-
for (const [appTaggingSecret, newIndex] of Object.entries(newLargestIndexMapForIteration)) {
|
|
560
|
-
const secret = secrets.find(secret => secret.appTaggingSecret.toString() === appTaggingSecret);
|
|
561
|
-
if (secret) {
|
|
562
|
-
newSecretsAndWindows.push({
|
|
563
|
-
appTaggingSecret: secret.appTaggingSecret,
|
|
564
|
-
// We set the left most index to the new index to avoid fetching the same logs again
|
|
565
|
-
leftMostIndex: newIndex,
|
|
566
|
-
rightMostIndex: newIndex + WINDOW_HALF_SIZE,
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
// We store the new largest index in the map to later store it in the db.
|
|
570
|
-
newLargestIndexMapToStore[appTaggingSecret] = newIndex;
|
|
571
|
-
} else {
|
|
572
|
-
throw new Error(
|
|
573
|
-
`Secret not found for appTaggingSecret ${appTaggingSecret}. This is a bug as it should never happen!`,
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// Now we set the new secrets and windows and proceed to the next iteration.
|
|
579
|
-
secretsAndWindows = newSecretsAndWindows;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// At this point we have processed all the logs for the recipient so we store the new largest indexes in the db.
|
|
583
|
-
await this.taggingDataProvider.setTaggingSecretsIndexesAsRecipient(
|
|
584
|
-
Object.entries(newLargestIndexMapToStore).map(
|
|
585
|
-
([appTaggingSecret, index]) => new IndexedTaggingSecret(Fr.fromHexString(appTaggingSecret), index),
|
|
586
|
-
),
|
|
587
|
-
recipient,
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
async #storePendingTaggedLogs(
|
|
593
|
-
contractAddress: AztecAddress,
|
|
594
|
-
capsuleArrayBaseSlot: Fr,
|
|
595
|
-
recipient: AztecAddress,
|
|
596
|
-
privateLogs: TxScopedL2Log[],
|
|
597
|
-
) {
|
|
598
|
-
// Build all pending tagged logs upfront with their tx effects
|
|
599
|
-
const pendingTaggedLogs = await Promise.all(
|
|
600
|
-
privateLogs.map(async scopedLog => {
|
|
601
|
-
// TODO(#9789): get these effects along with the log
|
|
602
|
-
const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
|
|
603
|
-
if (!txEffect) {
|
|
604
|
-
throw new Error(`Could not find tx effect for tx hash ${scopedLog.txHash}`);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
const pendingTaggedLog = new PendingTaggedLog(
|
|
608
|
-
scopedLog.log.fields,
|
|
609
|
-
scopedLog.txHash,
|
|
610
|
-
txEffect.data.noteHashes,
|
|
611
|
-
txEffect.data.nullifiers[0],
|
|
612
|
-
recipient,
|
|
613
|
-
);
|
|
614
|
-
|
|
615
|
-
return pendingTaggedLog.toFields();
|
|
616
|
-
}),
|
|
617
|
-
);
|
|
618
|
-
|
|
619
|
-
return this.capsuleDataProvider.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
public async validateEnqueuedNotesAndEvents(
|
|
623
|
-
contractAddress: AztecAddress,
|
|
624
|
-
noteValidationRequestsArrayBaseSlot: Fr,
|
|
625
|
-
eventValidationRequestsArrayBaseSlot: Fr,
|
|
626
|
-
): Promise<void> {
|
|
627
|
-
// We read all note and event validation requests and process them all concurrently. This makes the process much
|
|
628
|
-
// faster as we don't need to wait for the network round-trip.
|
|
629
|
-
const noteValidationRequests = (
|
|
630
|
-
await this.capsuleDataProvider.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)
|
|
631
|
-
).map(NoteValidationRequest.fromFields);
|
|
632
|
-
|
|
633
|
-
const eventValidationRequests = (
|
|
634
|
-
await this.capsuleDataProvider.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)
|
|
635
|
-
).map(EventValidationRequest.fromFields);
|
|
636
|
-
|
|
637
|
-
const noteDeliveries = noteValidationRequests.map(request =>
|
|
638
|
-
this.deliverNote(
|
|
639
|
-
request.contractAddress,
|
|
640
|
-
request.storageSlot,
|
|
641
|
-
request.noteNonce,
|
|
642
|
-
request.content,
|
|
643
|
-
request.noteHash,
|
|
644
|
-
request.nullifier,
|
|
645
|
-
request.txHash,
|
|
646
|
-
request.recipient,
|
|
647
|
-
),
|
|
648
|
-
);
|
|
649
|
-
|
|
650
|
-
const eventDeliveries = eventValidationRequests.map(request =>
|
|
651
|
-
this.deliverEvent(
|
|
652
|
-
request.contractAddress,
|
|
653
|
-
request.eventTypeId,
|
|
654
|
-
request.serializedEvent,
|
|
655
|
-
request.eventCommitment,
|
|
656
|
-
request.txHash,
|
|
657
|
-
request.recipient,
|
|
658
|
-
),
|
|
659
|
-
);
|
|
660
|
-
|
|
661
|
-
await Promise.all([...noteDeliveries, ...eventDeliveries]);
|
|
662
|
-
|
|
663
|
-
// Requests are cleared once we're done.
|
|
664
|
-
await this.capsuleDataProvider.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
|
|
665
|
-
await this.capsuleDataProvider.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
async deliverNote(
|
|
669
|
-
contractAddress: AztecAddress,
|
|
670
|
-
storageSlot: Fr,
|
|
671
|
-
noteNonce: Fr,
|
|
672
|
-
content: Fr[],
|
|
673
|
-
noteHash: Fr,
|
|
674
|
-
nullifier: Fr,
|
|
675
|
-
txHash: TxHash,
|
|
676
|
-
recipient: AztecAddress,
|
|
677
|
-
): Promise<void> {
|
|
678
|
-
// We are going to store the new note in the NoteDataProvider, which will let us later return it via `getNotes`.
|
|
679
|
-
// There's two things we need to check before we do this however:
|
|
680
|
-
// - we must make sure the note does actually exist in the note hash tree
|
|
681
|
-
// - we need to check if the note has already been nullified
|
|
682
|
-
//
|
|
683
|
-
// Failing to do either of the above would result in circuits getting either non-existent notes and failing to
|
|
684
|
-
// produce inclusion proofs for them, or getting nullified notes and producing duplicate nullifiers, both of which
|
|
685
|
-
// are catastrophic failure modes.
|
|
686
|
-
//
|
|
687
|
-
// Note that adding a note and removing it is *not* equivalent to never adding it in the first place. A nullifier
|
|
688
|
-
// emitted in a block that comes after note creation might result in the note being de-nullified by a chain reorg,
|
|
689
|
-
// so we must store both the note hash and nullifier block information.
|
|
690
|
-
|
|
691
|
-
// We avoid making node queries at 'latest' since we don't want to process notes or nullifiers that only exist ahead
|
|
692
|
-
// in time of the locally synced state.
|
|
693
|
-
// Note that while this technically results in historical queries, we perform it at the latest locally synced block
|
|
694
|
-
// number which *should* be recent enough to be available, even for non-archive nodes.
|
|
695
|
-
// Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
|
|
696
|
-
// logs up to the synced block making this only an additional safety check.
|
|
697
|
-
const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
|
|
698
|
-
|
|
699
|
-
// By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
|
|
700
|
-
// of other contracts, which would constitute a security breach.
|
|
701
|
-
const uniqueNoteHash = await computeUniqueNoteHash(noteNonce, await siloNoteHash(contractAddress, noteHash));
|
|
702
|
-
const siloedNullifier = await siloNullifier(contractAddress, nullifier);
|
|
703
|
-
|
|
704
|
-
// We store notes by their index in the global note hash tree, which has the convenient side effect of validating
|
|
705
|
-
// note existence in said tree. We concurrently also check if the note's nullifier exists, performing all node
|
|
706
|
-
// queries in a single round-trip.
|
|
707
|
-
const [[uniqueNoteHashTreeIndexInBlock], [nullifierIndex]] = await Promise.all([
|
|
708
|
-
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NOTE_HASH_TREE, [uniqueNoteHash]),
|
|
709
|
-
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [siloedNullifier]),
|
|
710
|
-
]);
|
|
711
|
-
|
|
712
|
-
if (uniqueNoteHashTreeIndexInBlock === undefined) {
|
|
713
|
-
throw new Error(
|
|
714
|
-
`Note hash ${noteHash} (uniqued as ${uniqueNoteHash}) is not present on the tree at block ${syncedBlockNumber} (from tx ${txHash})`,
|
|
715
|
-
);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const noteDao = new NoteDao(
|
|
719
|
-
new Note(content),
|
|
720
|
-
contractAddress,
|
|
721
|
-
storageSlot,
|
|
722
|
-
noteNonce,
|
|
723
|
-
noteHash,
|
|
724
|
-
siloedNullifier,
|
|
725
|
-
txHash,
|
|
726
|
-
uniqueNoteHashTreeIndexInBlock?.l2BlockNumber,
|
|
727
|
-
uniqueNoteHashTreeIndexInBlock?.l2BlockHash.toString(),
|
|
728
|
-
uniqueNoteHashTreeIndexInBlock?.data,
|
|
729
|
-
recipient,
|
|
730
|
-
);
|
|
731
|
-
|
|
732
|
-
await this.noteDataProvider.addNotes([noteDao], recipient);
|
|
733
|
-
this.log.verbose('Added note', {
|
|
734
|
-
index: noteDao.index,
|
|
735
|
-
contract: noteDao.contractAddress.toString(),
|
|
736
|
-
slot: noteDao.storageSlot.toString(),
|
|
737
|
-
noteHash: noteDao.noteHash.toString(),
|
|
738
|
-
nullifier: noteDao.siloedNullifier.toString(),
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
if (nullifierIndex !== undefined) {
|
|
742
|
-
const { data: _, ...blockHashAndNum } = nullifierIndex;
|
|
743
|
-
await this.noteDataProvider.removeNullifiedNotes([{ data: siloedNullifier, ...blockHashAndNum }], recipient);
|
|
744
|
-
|
|
745
|
-
this.log.verbose(`Removed just-added note`, {
|
|
746
|
-
contract: contractAddress,
|
|
747
|
-
slot: storageSlot,
|
|
748
|
-
noteHash: noteHash,
|
|
749
|
-
nullifier: siloedNullifier.toString(),
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
public async bulkRetrieveLogs(
|
|
755
|
-
contractAddress: AztecAddress,
|
|
756
|
-
logRetrievalRequestsArrayBaseSlot: Fr,
|
|
757
|
-
logRetrievalResponsesArrayBaseSlot: Fr,
|
|
758
|
-
) {
|
|
759
|
-
// We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
|
|
760
|
-
// don't need to wait for the network round-trip.
|
|
761
|
-
const logRetrievalRequests = (
|
|
762
|
-
await this.capsuleDataProvider.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)
|
|
763
|
-
).map(LogRetrievalRequest.fromFields);
|
|
764
|
-
|
|
765
|
-
const maybeLogRetrievalResponses = await Promise.all(
|
|
766
|
-
logRetrievalRequests.map(async request => {
|
|
767
|
-
// TODO(#14555): remove these internal functions and have node endpoints that do this instead
|
|
768
|
-
const [publicLog, privateLog] = await Promise.all([
|
|
769
|
-
this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
|
|
770
|
-
this.getPrivateLogByTag(await siloPrivateLog(request.contractAddress, request.unsiloedTag)),
|
|
771
|
-
]);
|
|
772
|
-
|
|
773
|
-
if (publicLog !== null) {
|
|
774
|
-
if (privateLog !== null) {
|
|
775
|
-
throw new Error(
|
|
776
|
-
`Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`,
|
|
777
|
-
);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
return new LogRetrievalResponse(
|
|
781
|
-
publicLog.logPayload,
|
|
782
|
-
publicLog.txHash,
|
|
783
|
-
publicLog.uniqueNoteHashesInTx,
|
|
784
|
-
publicLog.firstNullifierInTx,
|
|
785
|
-
);
|
|
786
|
-
} else if (privateLog !== null) {
|
|
787
|
-
return new LogRetrievalResponse(
|
|
788
|
-
privateLog.logPayload,
|
|
789
|
-
privateLog.txHash,
|
|
790
|
-
privateLog.uniqueNoteHashesInTx,
|
|
791
|
-
privateLog.firstNullifierInTx,
|
|
792
|
-
);
|
|
793
|
-
} else {
|
|
794
|
-
null;
|
|
795
|
-
}
|
|
796
|
-
}),
|
|
797
|
-
);
|
|
798
|
-
|
|
799
|
-
// Requests are cleared once we're done.
|
|
800
|
-
await this.capsuleDataProvider.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
|
|
801
|
-
|
|
802
|
-
// The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
|
|
803
|
-
await this.capsuleDataProvider.setCapsuleArray(
|
|
804
|
-
contractAddress,
|
|
805
|
-
logRetrievalResponsesArrayBaseSlot,
|
|
806
|
-
maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
async deliverEvent(
|
|
811
|
-
contractAddress: AztecAddress,
|
|
812
|
-
selector: EventSelector,
|
|
813
|
-
content: Fr[],
|
|
814
|
-
eventCommitment: Fr,
|
|
815
|
-
txHash: TxHash,
|
|
816
|
-
recipient: AztecAddress,
|
|
817
|
-
): Promise<void> {
|
|
818
|
-
// While using 'latest' block number would be fine for private events since they cannot be accessed from Aztec.nr
|
|
819
|
-
// (and thus we're less concerned about being ahead of the synced block), we use the synced block number to
|
|
820
|
-
// maintain consistent behavior in the PXE. Additionally, events should never be ahead of the synced block here
|
|
821
|
-
// since `fetchTaggedLogs` only processes logs up to the synced block.
|
|
822
|
-
const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
|
|
823
|
-
|
|
824
|
-
const siloedEventCommitment = await siloNullifier(contractAddress, eventCommitment);
|
|
825
|
-
|
|
826
|
-
const [nullifierIndex] = await this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, [
|
|
827
|
-
siloedEventCommitment,
|
|
828
|
-
]);
|
|
829
|
-
|
|
830
|
-
if (nullifierIndex === undefined) {
|
|
831
|
-
throw new Error(
|
|
832
|
-
`Event commitment ${eventCommitment} (siloed as ${siloedEventCommitment}) is not present on the nullifier tree at block ${syncedBlockNumber} (from tx ${txHash})`,
|
|
833
|
-
);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
return this.privateEventDataProvider.storePrivateEventLog(
|
|
837
|
-
contractAddress,
|
|
838
|
-
recipient,
|
|
839
|
-
selector,
|
|
840
|
-
content,
|
|
841
|
-
txHash,
|
|
842
|
-
Number(nullifierIndex.data), // Index of the event commitment in the nullifier tree
|
|
843
|
-
nullifierIndex.l2BlockNumber, // Block in which the event was emitted
|
|
844
|
-
);
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
// TODO(#14555): delete this function and implement this behavior in the node instead
|
|
848
|
-
async getPublicLogByTag(tag: Fr, contractAddress: AztecAddress): Promise<PublicLogWithTxData | null> {
|
|
849
|
-
const logs = await this.#getPublicLogsByTagsFromContract([tag], contractAddress);
|
|
850
|
-
const logsForTag = logs[0];
|
|
851
|
-
|
|
852
|
-
this.log.debug(`Got ${logsForTag.length} public logs for tag ${tag}`);
|
|
853
|
-
|
|
854
|
-
if (logsForTag.length == 0) {
|
|
855
|
-
return null;
|
|
856
|
-
} else if (logsForTag.length > 1) {
|
|
857
|
-
// TODO(#11627): handle this case
|
|
858
|
-
throw new Error(
|
|
859
|
-
`Got ${logsForTag.length} logs for tag ${tag} and contract ${contractAddress.toString()}. getPublicLogByTag currently only supports a single log per tag`,
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
const scopedLog = logsForTag[0];
|
|
864
|
-
|
|
865
|
-
// getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
|
|
866
|
-
// we need to make a second call to the node for `getTxEffect`.
|
|
867
|
-
// TODO(#9789): bundle this information in the `getLogsByTag` call.
|
|
868
|
-
const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
|
|
869
|
-
if (txEffect == undefined) {
|
|
870
|
-
throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
return new PublicLogWithTxData(
|
|
874
|
-
scopedLog.log.getEmittedFieldsWithoutTag(),
|
|
875
|
-
scopedLog.txHash,
|
|
876
|
-
txEffect.data.noteHashes,
|
|
877
|
-
txEffect.data.nullifiers[0],
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
// TODO(#14555): delete this function and implement this behavior in the node instead
|
|
882
|
-
async getPrivateLogByTag(siloedTag: Fr): Promise<PrivateLogWithTxData | null> {
|
|
883
|
-
const logs = await this.#getPrivateLogsByTags([siloedTag]);
|
|
884
|
-
const logsForTag = logs[0];
|
|
885
|
-
|
|
886
|
-
this.log.debug(`Got ${logsForTag.length} private logs for tag ${siloedTag}`);
|
|
887
|
-
|
|
888
|
-
if (logsForTag.length == 0) {
|
|
889
|
-
return null;
|
|
890
|
-
} else if (logsForTag.length > 1) {
|
|
891
|
-
// TODO(#11627): handle this case
|
|
892
|
-
throw new Error(
|
|
893
|
-
`Got ${logsForTag.length} logs for tag ${siloedTag}. getPrivateLogByTag currently only supports a single log per tag`,
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
const scopedLog = logsForTag[0];
|
|
898
|
-
|
|
899
|
-
// getLogsByTag doesn't have all of the information that we need (notably note hashes and the first nullifier), so
|
|
900
|
-
// we need to make a second call to the node for `getTxEffect`.
|
|
901
|
-
// TODO(#9789): bundle this information in the `getLogsByTag` call.
|
|
902
|
-
const txEffect = await this.aztecNode.getTxEffect(scopedLog.txHash);
|
|
903
|
-
if (txEffect == undefined) {
|
|
904
|
-
throw new Error(`Unexpected: failed to retrieve tx effects for tx ${scopedLog.txHash} which is known to exist`);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
return new PrivateLogWithTxData(
|
|
908
|
-
scopedLog.log.getEmittedFieldsWithoutTag(),
|
|
909
|
-
scopedLog.txHash,
|
|
910
|
-
txEffect.data.noteHashes,
|
|
911
|
-
txEffect.data.nullifiers[0],
|
|
912
|
-
);
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
public async removeNullifiedNotes(contractAddress: AztecAddress) {
|
|
916
|
-
this.log.verbose('Searching for nullifiers of known notes', { contract: contractAddress });
|
|
917
|
-
|
|
918
|
-
// We avoid making node queries at 'latest' since we mark notes as nullified only if the corresponding nullifier
|
|
919
|
-
// has been included in a block up to which PXE has synced. Note that while this technically results in historical
|
|
920
|
-
// queries, we perform it at the latest locally synced block number which *should* be recent enough to be
|
|
921
|
-
// available, even for non-archive nodes.
|
|
922
|
-
const syncedBlockNumber = await this.syncDataProvider.getBlockNumber();
|
|
923
|
-
|
|
924
|
-
for (const recipient of await this.keyStore.getAccounts()) {
|
|
925
|
-
const currentNotesForRecipient = await this.noteDataProvider.getNotes({ contractAddress, recipient });
|
|
926
|
-
|
|
927
|
-
if (currentNotesForRecipient.length === 0) {
|
|
928
|
-
// Save a call to the node if there are no notes for the recipient
|
|
929
|
-
continue;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
const nullifiersToCheck = currentNotesForRecipient.map(note => note.siloedNullifier);
|
|
933
|
-
const nullifierBatches = nullifiersToCheck.reduce(
|
|
934
|
-
(acc, nullifier) => {
|
|
935
|
-
if (acc[acc.length - 1].length < MAX_RPC_LEN) {
|
|
936
|
-
acc[acc.length - 1].push(nullifier);
|
|
937
|
-
} else {
|
|
938
|
-
acc.push([nullifier]);
|
|
939
|
-
}
|
|
940
|
-
return acc;
|
|
941
|
-
},
|
|
942
|
-
[[]] as Fr[][],
|
|
943
|
-
);
|
|
944
|
-
const nullifierIndexes = (
|
|
945
|
-
await Promise.all(
|
|
946
|
-
nullifierBatches.map(batch =>
|
|
947
|
-
this.aztecNode.findLeavesIndexes(syncedBlockNumber, MerkleTreeId.NULLIFIER_TREE, batch),
|
|
948
|
-
),
|
|
949
|
-
)
|
|
950
|
-
).flat();
|
|
951
|
-
|
|
952
|
-
const foundNullifiers = nullifiersToCheck
|
|
953
|
-
.map((nullifier, i) => {
|
|
954
|
-
if (nullifierIndexes[i] !== undefined) {
|
|
955
|
-
return { ...nullifierIndexes[i], ...{ data: nullifier } } as InBlock<Fr>;
|
|
956
|
-
}
|
|
957
|
-
})
|
|
958
|
-
.filter(nullifier => nullifier !== undefined) as InBlock<Fr>[];
|
|
959
|
-
|
|
960
|
-
const nullifiedNotes = await this.noteDataProvider.removeNullifiedNotes(foundNullifiers, recipient);
|
|
961
|
-
nullifiedNotes.forEach(noteDao => {
|
|
962
|
-
this.log.verbose(`Removed note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, {
|
|
963
|
-
contract: noteDao.contractAddress,
|
|
964
|
-
slot: noteDao.storageSlot,
|
|
965
|
-
nullifier: noteDao.siloedNullifier.toString(),
|
|
966
|
-
});
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
|
|
972
|
-
return this.capsuleDataProvider.storeCapsule(contractAddress, slot, capsule);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
|
|
976
|
-
return this.capsuleDataProvider.loadCapsule(contractAddress, slot);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
|
|
980
|
-
return this.capsuleDataProvider.deleteCapsule(contractAddress, slot);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
|
|
984
|
-
return this.capsuleDataProvider.copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
988
|
-
// TODO(#12656): return an app-siloed secret
|
|
989
|
-
const recipientCompleteAddress = await this.getCompleteAddress(address);
|
|
990
|
-
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
991
|
-
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
992
|
-
);
|
|
993
|
-
const addressSecret = await computeAddressSecret(await recipientCompleteAddress.getPreaddress(), ivskM);
|
|
994
|
-
return deriveEcdhSharedSecret(addressSecret, ephPk);
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
// TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
|
|
998
|
-
// was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
|
|
999
|
-
async #getPrivateLogsByTags(tags: Fr[]): Promise<TxScopedL2Log[][]> {
|
|
1000
|
-
const allLogs = await this.aztecNode.getLogsByTags(tags);
|
|
1001
|
-
return allLogs.map(logs => logs.filter(log => !log.isFromPublic));
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// TODO(#12656): Make this a public function on the AztecNode interface and remove the original getLogsByTags. This
|
|
1005
|
-
// was not done yet as we were unsure about the API and we didn't want to introduce a breaking change.
|
|
1006
|
-
async #getPublicLogsByTagsFromContract(tags: Fr[], contractAddress: AztecAddress): Promise<TxScopedL2Log[][]> {
|
|
1007
|
-
const allLogs = await this.aztecNode.getLogsByTags(tags);
|
|
1008
|
-
const allPublicLogs = allLogs.map(logs => logs.filter(log => log.isFromPublic));
|
|
1009
|
-
return allPublicLogs.map(logs =>
|
|
1010
|
-
logs.filter(log => (log.log as PublicLog).contractAddress.equals(contractAddress)),
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
getStats(): ExecutionStats {
|
|
1015
|
-
const nodeRPCCalls =
|
|
1016
|
-
typeof (this.aztecNode as ProxiedNode).getStats === 'function' ? (this.aztecNode as ProxiedNode).getStats() : {};
|
|
1017
|
-
|
|
1018
|
-
return { nodeRPCCalls };
|
|
1019
|
-
}
|
|
1020
|
-
}
|