@aztec/pxe 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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,146 +1,113 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
5
|
import { KeyStore } from '@aztec/key-store';
|
|
6
6
|
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
8
|
+
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
9
9
|
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
10
10
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
11
|
-
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
|
-
import { computeL2ToL1MembershipWitness, getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
13
|
-
import { UniqueNote } from '@aztec/stdlib/note';
|
|
14
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
11
|
+
import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
15
12
|
import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
16
13
|
import { inspect } from 'util';
|
|
17
|
-
import {
|
|
18
|
-
import { ContractFunctionSimulator, generateSimulatedProvingResult } from '
|
|
19
|
-
import { readCurrentClassId } from '
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { PXEOracleInterface } from '../contract_function_simulator/pxe_oracle_interface.js';
|
|
23
|
-
import { PrivateKernelExecutionProver } from '../private_kernel/private_kernel_execution_prover.js';
|
|
24
|
-
import { PrivateKernelOracleImpl } from '../private_kernel/private_kernel_oracle_impl.js';
|
|
25
|
-
import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
26
|
-
import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
27
|
-
import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
28
|
-
import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
29
|
-
import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
|
|
30
|
-
import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
31
|
-
import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
32
|
-
import { Synchronizer } from '../synchronizer/index.js';
|
|
14
|
+
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
15
|
+
import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
|
|
16
|
+
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
17
|
+
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
18
|
+
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
33
19
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
20
|
+
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
21
|
+
import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
|
|
22
|
+
import { PrivateKernelOracleImpl } from './private_kernel/private_kernel_oracle_impl.js';
|
|
23
|
+
import { AddressStore } from './storage/address_store/address_store.js';
|
|
24
|
+
import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
|
|
25
|
+
import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
|
|
26
|
+
import { ContractStore } from './storage/contract_store/contract_store.js';
|
|
27
|
+
import { NoteStore } from './storage/note_store/note_store.js';
|
|
28
|
+
import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
|
|
29
|
+
import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
|
|
30
|
+
import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
|
|
31
|
+
import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
|
|
34
32
|
/**
|
|
35
|
-
*
|
|
36
|
-
|
|
33
|
+
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
34
|
+
* manage private state of users.
|
|
35
|
+
*/ export class PXE {
|
|
37
36
|
node;
|
|
38
|
-
|
|
37
|
+
blockStateSynchronizer;
|
|
39
38
|
keyStore;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
contractStore;
|
|
40
|
+
noteStore;
|
|
41
|
+
capsuleStore;
|
|
42
|
+
anchorBlockStore;
|
|
43
|
+
senderTaggingStore;
|
|
44
|
+
senderAddressBookStore;
|
|
45
|
+
recipientTaggingStore;
|
|
46
|
+
addressStore;
|
|
47
|
+
privateEventStore;
|
|
47
48
|
simulator;
|
|
48
|
-
packageVersion;
|
|
49
49
|
proverEnabled;
|
|
50
50
|
proofCreator;
|
|
51
51
|
protocolContractsProvider;
|
|
52
52
|
log;
|
|
53
53
|
jobQueue;
|
|
54
|
-
|
|
55
|
-
constructor(node,
|
|
54
|
+
debug;
|
|
55
|
+
constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, debug){
|
|
56
56
|
this.node = node;
|
|
57
|
-
this.
|
|
57
|
+
this.blockStateSynchronizer = blockStateSynchronizer;
|
|
58
58
|
this.keyStore = keyStore;
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
59
|
+
this.contractStore = contractStore;
|
|
60
|
+
this.noteStore = noteStore;
|
|
61
|
+
this.capsuleStore = capsuleStore;
|
|
62
|
+
this.anchorBlockStore = anchorBlockStore;
|
|
63
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
64
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
65
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
66
|
+
this.addressStore = addressStore;
|
|
67
|
+
this.privateEventStore = privateEventStore;
|
|
66
68
|
this.simulator = simulator;
|
|
67
|
-
this.packageVersion = packageVersion;
|
|
68
69
|
this.proverEnabled = proverEnabled;
|
|
69
70
|
this.proofCreator = proofCreator;
|
|
70
71
|
this.protocolContractsProvider = protocolContractsProvider;
|
|
71
72
|
this.log = log;
|
|
72
73
|
this.jobQueue = jobQueue;
|
|
74
|
+
this.debug = debug;
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
|
-
* Creates an instance of a PXE
|
|
77
|
+
* Creates an instance of a PXE by instantiating all the necessary data providers and services.
|
|
76
78
|
* Also triggers the registration of the protocol contracts and makes sure the provided node
|
|
77
79
|
* can be contacted.
|
|
78
80
|
*
|
|
79
|
-
* @returns A promise that resolves PXE
|
|
81
|
+
* @returns A promise that resolves PXE is ready to be used.
|
|
80
82
|
*/ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
|
|
81
83
|
const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
|
|
82
|
-
const packageVersion = getPackageInfo().version;
|
|
83
84
|
const proverEnabled = !!config.proverEnabled;
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
85
|
+
const addressStore = new AddressStore(store);
|
|
86
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
87
|
+
const contractStore = new ContractStore(store);
|
|
88
|
+
const noteStore = await NoteStore.create(store);
|
|
89
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
90
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
91
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
92
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
93
|
+
const capsuleStore = new CapsuleStore(store);
|
|
91
94
|
const keyStore = new KeyStore(store);
|
|
92
95
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
93
|
-
const synchronizer = new
|
|
96
|
+
const synchronizer = new BlockSynchronizer(node, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, loggerOrSuffix);
|
|
97
|
+
const debugUtils = new PXEDebugUtils(contractStore, noteStore);
|
|
94
98
|
const jobQueue = new SerialQueue();
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, debugUtils);
|
|
100
|
+
debugUtils.setPXE(pxe);
|
|
101
|
+
pxe.jobQueue.start();
|
|
102
|
+
await pxe.#registerProtocolContracts();
|
|
103
|
+
const info = await node.getNodeInfo();
|
|
99
104
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
// Aztec node proxy methods
|
|
103
|
-
isL1ToL2MessageSynced(l1ToL2Message) {
|
|
104
|
-
return this.node.isL1ToL2MessageSynced(l1ToL2Message);
|
|
105
|
-
}
|
|
106
|
-
async getL2ToL1MembershipWitness(blockNumber, l2Tol1Message) {
|
|
107
|
-
const result = await computeL2ToL1MembershipWitness(this.node, blockNumber, l2Tol1Message);
|
|
108
|
-
if (!result) {
|
|
109
|
-
throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
|
|
110
|
-
}
|
|
111
|
-
return [
|
|
112
|
-
result.leafIndex,
|
|
113
|
-
result.siblingPath
|
|
114
|
-
];
|
|
115
|
-
}
|
|
116
|
-
getTxReceipt(txHash) {
|
|
117
|
-
return this.node.getTxReceipt(txHash);
|
|
118
|
-
}
|
|
119
|
-
getTxEffect(txHash) {
|
|
120
|
-
return this.node.getTxEffect(txHash);
|
|
121
|
-
}
|
|
122
|
-
getBlockNumber() {
|
|
123
|
-
return this.node.getBlockNumber();
|
|
124
|
-
}
|
|
125
|
-
getProvenBlockNumber() {
|
|
126
|
-
return this.node.getProvenBlockNumber();
|
|
127
|
-
}
|
|
128
|
-
getPublicLogs(filter) {
|
|
129
|
-
return this.node.getPublicLogs(filter);
|
|
130
|
-
}
|
|
131
|
-
getContractClassLogs(filter) {
|
|
132
|
-
return this.node.getContractClassLogs(filter);
|
|
133
|
-
}
|
|
134
|
-
getPublicStorageAt(contract, slot) {
|
|
135
|
-
return this.node.getPublicStorageAt('latest', contract, slot);
|
|
136
|
-
}
|
|
137
|
-
async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
|
|
138
|
-
return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
|
|
105
|
+
return pxe;
|
|
139
106
|
}
|
|
140
107
|
// Internal methods
|
|
141
108
|
#getSimulatorForTx(overrides) {
|
|
142
|
-
const
|
|
143
|
-
return new ContractFunctionSimulator(
|
|
109
|
+
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
110
|
+
return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, this.node, this.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
|
|
144
111
|
}
|
|
145
112
|
#contextualizeError(err, ...context) {
|
|
146
113
|
let contextStr = '';
|
|
@@ -171,8 +138,8 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
171
138
|
const registered = {};
|
|
172
139
|
for (const name of protocolContractNames){
|
|
173
140
|
const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
174
|
-
await this.
|
|
175
|
-
await this.
|
|
141
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
142
|
+
await this.contractStore.addContractInstance(instance);
|
|
176
143
|
registered[name] = address.toString();
|
|
177
144
|
}
|
|
178
145
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
@@ -187,38 +154,20 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
187
154
|
const initNullifier = await siloNullifier(address, address.toField());
|
|
188
155
|
return !!await this.node.getNullifierMembershipWitness('latest', initNullifier);
|
|
189
156
|
}
|
|
190
|
-
async #getFunctionCall(functionName, args, to) {
|
|
191
|
-
const contract = await this.contractDataProvider.getContract(to);
|
|
192
|
-
if (!contract) {
|
|
193
|
-
throw new Error(`Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`);
|
|
194
|
-
}
|
|
195
|
-
const functionDao = contract.functions.find((f)=>f.name === functionName);
|
|
196
|
-
if (!functionDao) {
|
|
197
|
-
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
name: functionDao.name,
|
|
201
|
-
args: encodeArguments(functionDao, args),
|
|
202
|
-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
203
|
-
type: functionDao.functionType,
|
|
204
|
-
to,
|
|
205
|
-
isStatic: functionDao.isStatic,
|
|
206
|
-
returnTypes: functionDao.returnTypes
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
157
|
// Executes the entrypoint private function, as well as all nested private
|
|
210
158
|
// functions that might arise.
|
|
211
159
|
async #executePrivate(contractFunctionSimulator, txRequest, scopes) {
|
|
212
160
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
213
161
|
try {
|
|
214
|
-
const
|
|
162
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
163
|
+
const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
|
|
215
164
|
// contract entrypoint
|
|
216
165
|
undefined, scopes);
|
|
217
166
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
218
167
|
return result;
|
|
219
168
|
} catch (err) {
|
|
220
169
|
if (err instanceof SimulationError) {
|
|
221
|
-
await enrichSimulationError(err, this.
|
|
170
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
222
171
|
}
|
|
223
172
|
throw err;
|
|
224
173
|
}
|
|
@@ -233,10 +182,11 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
233
182
|
* @returns The simulation result containing the outputs of the utility function.
|
|
234
183
|
*/ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes) {
|
|
235
184
|
try {
|
|
236
|
-
|
|
185
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
186
|
+
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes);
|
|
237
187
|
} catch (err) {
|
|
238
188
|
if (err instanceof SimulationError) {
|
|
239
|
-
await enrichSimulationError(err, this.
|
|
189
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
240
190
|
}
|
|
241
191
|
throw err;
|
|
242
192
|
}
|
|
@@ -258,7 +208,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
258
208
|
} catch (err) {
|
|
259
209
|
if (err instanceof SimulationError) {
|
|
260
210
|
try {
|
|
261
|
-
await enrichPublicSimulationError(err, this.
|
|
211
|
+
await enrichPublicSimulationError(err, this.contractStore, this.log);
|
|
262
212
|
} catch (enrichErr) {
|
|
263
213
|
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
264
214
|
}
|
|
@@ -275,35 +225,33 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
275
225
|
* @param proofCreator - The proof creator to use for proving the execution.
|
|
276
226
|
* @param privateExecutionResult - The result of the private execution
|
|
277
227
|
* @param config - The configuration for the kernel execution prover.
|
|
278
|
-
* @returns An object that contains the output of the kernel execution, including the
|
|
228
|
+
* @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
|
|
279
229
|
*/ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
|
|
280
|
-
const
|
|
281
|
-
const kernelOracle = new PrivateKernelOracleImpl(this.
|
|
230
|
+
const simulationAnchorBlock = privateExecutionResult.getSimulationAnchorBlockNumber();
|
|
231
|
+
const kernelOracle = new PrivateKernelOracleImpl(this.contractStore, this.keyStore, this.node, simulationAnchorBlock);
|
|
282
232
|
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
283
233
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
284
234
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
285
235
|
}
|
|
286
236
|
// Public API
|
|
287
|
-
/** Returns an estimate of the db size in bytes. */ async estimateDbSize() {
|
|
288
|
-
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
|
|
289
|
-
const dbSizes = await Promise.all([
|
|
290
|
-
this.addressDataProvider.getSize(),
|
|
291
|
-
this.capsuleDataProvider.getSize(),
|
|
292
|
-
this.contractDataProvider.getSize(),
|
|
293
|
-
this.noteDataProvider.getSize(),
|
|
294
|
-
this.syncDataProvider.getSize(),
|
|
295
|
-
this.taggingDataProvider.getSize()
|
|
296
|
-
]);
|
|
297
|
-
return [
|
|
298
|
-
...dbSizes,
|
|
299
|
-
treeRootsSize
|
|
300
|
-
].reduce((sum, size)=>sum + size, 0);
|
|
301
|
-
}
|
|
302
237
|
getContractInstance(address) {
|
|
303
|
-
return this.
|
|
238
|
+
return this.contractStore.getContractInstance(address);
|
|
304
239
|
}
|
|
305
|
-
|
|
306
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Returns the contract class metadata given a contract class id.
|
|
242
|
+
* The metadata consists of its contract class, whether it has been publicly registered, and its artifact.
|
|
243
|
+
* @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
|
|
244
|
+
* @param id - Identifier of the class.
|
|
245
|
+
* @param includeArtifact - Identifier of the class.
|
|
246
|
+
* @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
|
|
247
|
+
* for `includeArtifact`
|
|
248
|
+
* TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
|
|
249
|
+
* should the pxe query the node for contract public info, and merge it with its own definitions?
|
|
250
|
+
* TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
|
|
251
|
+
* during a public deployment. We probably want a nicer and more general API for this, but it'll have to
|
|
252
|
+
* do for the time being.
|
|
253
|
+
*/ async getContractClassMetadata(id, includeArtifact = false) {
|
|
254
|
+
const artifact = await this.contractStore.getContractArtifact(id);
|
|
307
255
|
if (!artifact) {
|
|
308
256
|
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
309
257
|
}
|
|
@@ -313,10 +261,20 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
313
261
|
artifact: includeArtifact ? artifact : undefined
|
|
314
262
|
};
|
|
315
263
|
}
|
|
316
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Returns the contract metadata given an address.
|
|
266
|
+
* The metadata consists of its contract instance, which includes the contract class identifier,
|
|
267
|
+
* initialization hash, deployment salt, and public keys hash; whether the contract instance has been initialized;
|
|
268
|
+
* and whether the contract instance with the given address has been publicly deployed.
|
|
269
|
+
* @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
|
|
270
|
+
* This query is not dependent on the PXE.
|
|
271
|
+
* @param address - The address that the contract instance resides at.
|
|
272
|
+
* @returns - It returns the contract metadata
|
|
273
|
+
* TODO(@spalladino): Should we return the public keys in plain as well here?
|
|
274
|
+
*/ async getContractMetadata(address) {
|
|
317
275
|
let instance;
|
|
318
276
|
try {
|
|
319
|
-
instance = await this.
|
|
277
|
+
instance = await this.contractStore.getContractInstance(address);
|
|
320
278
|
} catch {
|
|
321
279
|
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
322
280
|
}
|
|
@@ -326,7 +284,16 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
326
284
|
isContractPublished: await this.#isContractPublished(address)
|
|
327
285
|
};
|
|
328
286
|
}
|
|
329
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Registers a user account in PXE given its master encryption private key.
|
|
289
|
+
* Once a new account is registered, the PXE will trial-decrypt all published notes on
|
|
290
|
+
* the chain and store those that correspond to the registered account. Will do nothing if the
|
|
291
|
+
* account is already registered.
|
|
292
|
+
*
|
|
293
|
+
* @param secretKey - Secret key of the corresponding user master public key.
|
|
294
|
+
* @param partialAddress - The partial address of the account contract corresponding to the account being registered.
|
|
295
|
+
* @returns The complete address of the account.
|
|
296
|
+
*/ async registerAccount(secretKey, partialAddress) {
|
|
330
297
|
const accounts = await this.keyStore.getAccounts();
|
|
331
298
|
const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
|
|
332
299
|
if (accounts.includes(accountCompleteAddress.address)) {
|
|
@@ -336,48 +303,77 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
336
303
|
this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
|
|
337
304
|
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
338
305
|
}
|
|
339
|
-
await this.
|
|
340
|
-
await this.
|
|
306
|
+
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
307
|
+
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
341
308
|
return accountCompleteAddress;
|
|
342
309
|
}
|
|
343
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Registers a sender in this PXE.
|
|
312
|
+
*
|
|
313
|
+
* After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
|
|
314
|
+
* Will do nothing if the address is already registered.
|
|
315
|
+
*
|
|
316
|
+
* @param sender - Address of the sender to register.
|
|
317
|
+
* @returns The address of the sender.
|
|
318
|
+
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
319
|
+
*/ async registerSender(sender) {
|
|
344
320
|
const accounts = await this.keyStore.getAccounts();
|
|
345
|
-
if (accounts.includes(
|
|
346
|
-
this.log.info(`Sender:\n "${
|
|
347
|
-
return
|
|
321
|
+
if (accounts.includes(sender)) {
|
|
322
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
323
|
+
return sender;
|
|
348
324
|
}
|
|
349
|
-
const wasAdded = await this.
|
|
325
|
+
const wasAdded = await this.senderAddressBookStore.addSender(sender);
|
|
350
326
|
if (wasAdded) {
|
|
351
|
-
this.log.info(`Added sender:\n ${
|
|
327
|
+
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
352
328
|
} else {
|
|
353
|
-
this.log.info(`Sender:\n "${
|
|
329
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
354
330
|
}
|
|
355
|
-
return
|
|
331
|
+
return sender;
|
|
356
332
|
}
|
|
357
|
-
|
|
358
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Retrieves senders registered in this PXE.
|
|
335
|
+
* @returns Senders registered in this PXE.
|
|
336
|
+
*/ getSenders() {
|
|
337
|
+
return this.senderAddressBookStore.getSenders();
|
|
359
338
|
}
|
|
360
|
-
|
|
361
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Removes a sender registered in this PXE.
|
|
341
|
+
* @param sender - The address of the sender to remove.
|
|
342
|
+
*/ async removeSender(sender) {
|
|
343
|
+
const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
|
|
362
344
|
if (wasRemoved) {
|
|
363
|
-
this.log.info(`Removed sender:\n ${
|
|
345
|
+
this.log.info(`Removed sender:\n ${sender.toString()}`);
|
|
364
346
|
} else {
|
|
365
|
-
this.log.info(`Sender:\n "${
|
|
347
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
|
|
366
348
|
}
|
|
367
349
|
}
|
|
368
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Retrieves the user accounts registered on this PXE.
|
|
352
|
+
* @returns An array of the accounts registered on this PXE.
|
|
353
|
+
*/ async getRegisteredAccounts() {
|
|
369
354
|
// Get complete addresses of both the recipients and the accounts
|
|
370
|
-
const completeAddresses = await this.
|
|
355
|
+
const completeAddresses = await this.addressStore.getCompleteAddresses();
|
|
371
356
|
// Filter out the addresses not corresponding to accounts
|
|
372
357
|
const accounts = await this.keyStore.getAccounts();
|
|
373
358
|
return completeAddresses.filter((completeAddress)=>accounts.find((address)=>address.equals(completeAddress.address)));
|
|
374
359
|
}
|
|
375
|
-
|
|
360
|
+
/**
|
|
361
|
+
* Registers a contract class in the PXE without registering any associated contract instance with it.
|
|
362
|
+
*
|
|
363
|
+
* @param artifact - The build artifact for the contract class.
|
|
364
|
+
*/ async registerContractClass(artifact) {
|
|
376
365
|
const { id: contractClassId } = await getContractClassFromArtifact(artifact);
|
|
377
|
-
await this.
|
|
366
|
+
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
378
367
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
379
368
|
}
|
|
380
|
-
|
|
369
|
+
/**
|
|
370
|
+
* Adds deployed contracts to the PXE. Deployed contract information is used to access the
|
|
371
|
+
* contract code when simulating local transactions. This is automatically called by aztec.js when
|
|
372
|
+
* deploying a contract. Dapps that wish to interact with contracts already deployed should register
|
|
373
|
+
* these contracts in their users' PXE through this method.
|
|
374
|
+
*
|
|
375
|
+
* @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
|
|
376
|
+
*/ async registerContract(contract) {
|
|
381
377
|
const { instance } = contract;
|
|
382
378
|
let { artifact } = contract;
|
|
383
379
|
if (artifact) {
|
|
@@ -391,90 +387,77 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
391
387
|
if (!computedAddress.equals(instance.address)) {
|
|
392
388
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
393
389
|
}
|
|
394
|
-
await this.
|
|
390
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
395
391
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
396
392
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
397
393
|
} else {
|
|
398
394
|
// Otherwise, make sure there is an artifact already registered for that class id
|
|
399
|
-
artifact = await this.
|
|
395
|
+
artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
400
396
|
if (!artifact) {
|
|
401
397
|
throw new Error(`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`);
|
|
402
398
|
}
|
|
403
399
|
}
|
|
404
|
-
await this.
|
|
400
|
+
await this.contractStore.addContractInstance(instance);
|
|
405
401
|
this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`);
|
|
406
402
|
}
|
|
407
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Updates a deployed contract in the PXE. This is used to update the contract artifact when
|
|
405
|
+
* an update has happened, so the new code can be used in the simulation of local transactions.
|
|
406
|
+
* This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
|
|
407
|
+
* @param contractAddress - The address of the contract to update.
|
|
408
|
+
* @param artifact - The updated artifact for the contract.
|
|
409
|
+
* @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
|
|
410
|
+
* the current one (current one from the point of view of the node to which the PXE is connected).
|
|
411
|
+
*/ updateContract(contractAddress, artifact) {
|
|
408
412
|
// We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
|
|
409
413
|
// class while we're simulating it.
|
|
410
414
|
return this.#putInJobQueue(async ()=>{
|
|
411
|
-
const currentInstance = await this.
|
|
415
|
+
const currentInstance = await this.contractStore.getContractInstance(contractAddress);
|
|
412
416
|
if (!currentInstance) {
|
|
413
417
|
throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
|
|
414
418
|
}
|
|
415
419
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
416
|
-
await this.
|
|
417
|
-
const header = await this.
|
|
420
|
+
await this.blockStateSynchronizer.sync();
|
|
421
|
+
const header = await this.anchorBlockStore.getBlockHeader();
|
|
418
422
|
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header.globalVariables.blockNumber, header.globalVariables.timestamp);
|
|
419
423
|
if (!contractClass.id.equals(currentClassId)) {
|
|
420
424
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
421
425
|
}
|
|
422
|
-
await this.
|
|
426
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
423
427
|
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
424
428
|
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
425
429
|
currentInstance.currentContractClassId = contractClass.id;
|
|
426
|
-
await this.
|
|
430
|
+
await this.contractStore.addContractInstance(currentInstance);
|
|
427
431
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
428
432
|
});
|
|
429
433
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
await this.simulateUtility('sync_private_state', [], filter.contractAddress);
|
|
436
|
-
const noteDaos = await this.noteDataProvider.getNotes(filter);
|
|
437
|
-
const extendedNotes = noteDaos.map(async (dao)=>{
|
|
438
|
-
let recipient = filter.recipient;
|
|
439
|
-
if (recipient === undefined) {
|
|
440
|
-
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
441
|
-
const completeAddressIndex = completeAddresses.findIndex((completeAddress)=>completeAddress.address.equals(dao.recipient));
|
|
442
|
-
const completeAddress = completeAddresses[completeAddressIndex];
|
|
443
|
-
if (completeAddress === undefined) {
|
|
444
|
-
throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
|
|
445
|
-
}
|
|
446
|
-
recipient = completeAddress.address;
|
|
447
|
-
}
|
|
448
|
-
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
|
|
449
|
-
});
|
|
450
|
-
return Promise.all(extendedNotes);
|
|
451
|
-
}
|
|
452
|
-
async getBlock(blockNumber) {
|
|
453
|
-
// If a negative block number is provided the current block number is fetched.
|
|
454
|
-
if (blockNumber < 0) {
|
|
455
|
-
blockNumber = await this.node.getBlockNumber();
|
|
456
|
-
}
|
|
457
|
-
return await this.node.getBlock(blockNumber);
|
|
458
|
-
}
|
|
459
|
-
async getCurrentBaseFees() {
|
|
460
|
-
return await this.node.getCurrentBaseFees();
|
|
434
|
+
/**
|
|
435
|
+
* Retrieves the addresses of contracts added to this PXE.
|
|
436
|
+
* @returns An array of contracts addresses registered on this PXE.
|
|
437
|
+
*/ getContracts() {
|
|
438
|
+
return this.contractStore.getContractsAddresses();
|
|
461
439
|
}
|
|
462
|
-
|
|
440
|
+
/**
|
|
441
|
+
* Proves the private portion of a simulated transaction, ready to send to the network
|
|
442
|
+
* (where validators prove the public portion).
|
|
443
|
+
*
|
|
444
|
+
* @param txRequest - An authenticated tx request ready for proving
|
|
445
|
+
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
446
|
+
* @throws If contract code not found, or public simulation reverts.
|
|
447
|
+
* Also throws if simulatePublic is true and public simulation reverts.
|
|
448
|
+
*/ proveTx(txRequest) {
|
|
449
|
+
let privateExecutionResult;
|
|
463
450
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
464
451
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
465
452
|
return this.#putInJobQueue(async ()=>{
|
|
466
453
|
const totalTimer = new Timer();
|
|
467
454
|
try {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
contractFunctionSimulator = this.#getSimulatorForTx();
|
|
475
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
476
|
-
}
|
|
477
|
-
const { publicInputs, clientIvcProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
455
|
+
const syncTimer = new Timer();
|
|
456
|
+
await this.blockStateSynchronizer.sync();
|
|
457
|
+
const syncTime = syncTimer.ms();
|
|
458
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
459
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
460
|
+
const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
478
461
|
simulate: false,
|
|
479
462
|
skipFeeEnforcement: false,
|
|
480
463
|
profileMode: 'none'
|
|
@@ -495,16 +478,41 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
495
478
|
this.log.debug(`Proving completed in ${totalTime}ms`, {
|
|
496
479
|
timings
|
|
497
480
|
});
|
|
498
|
-
|
|
481
|
+
const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof, {
|
|
499
482
|
timings,
|
|
500
483
|
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
|
|
501
484
|
});
|
|
485
|
+
// While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
|
|
486
|
+
// chain before sending new logs, the sync can only see logs already included in blocks. If we send another
|
|
487
|
+
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
488
|
+
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
489
|
+
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
490
|
+
const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
|
|
491
|
+
if (preTagsUsedInTheTx.length > 0) {
|
|
492
|
+
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
493
|
+
const txHash = (await txProvingResult.toTx()).txHash;
|
|
494
|
+
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
|
|
495
|
+
this.log.debug(`Stored used pre-tags as sender for the tx`, {
|
|
496
|
+
preTagsUsedInTheTx
|
|
497
|
+
});
|
|
498
|
+
} else {
|
|
499
|
+
this.log.debug(`No pre-tags used in the tx`);
|
|
500
|
+
}
|
|
501
|
+
return txProvingResult;
|
|
502
502
|
} catch (err) {
|
|
503
503
|
throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
|
|
504
504
|
}
|
|
505
505
|
});
|
|
506
506
|
}
|
|
507
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
509
|
+
*
|
|
510
|
+
* @param txRequest - An authenticated tx request ready for simulation
|
|
511
|
+
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
512
|
+
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
513
|
+
* @returns A trace of the program execution with gate counts.
|
|
514
|
+
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
515
|
+
*/ profileTx(txRequest, profileMode, skipProofGeneration = true) {
|
|
508
516
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
509
517
|
return this.#putInJobQueue(async ()=>{
|
|
510
518
|
const totalTimer = new Timer();
|
|
@@ -519,7 +527,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
519
527
|
};
|
|
520
528
|
this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
521
529
|
const syncTimer = new Timer();
|
|
522
|
-
await this.
|
|
530
|
+
await this.blockStateSynchronizer.sync();
|
|
523
531
|
const syncTime = syncTimer.ms();
|
|
524
532
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
525
533
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
@@ -556,8 +564,29 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
556
564
|
}
|
|
557
565
|
});
|
|
558
566
|
}
|
|
559
|
-
|
|
560
|
-
|
|
567
|
+
/**
|
|
568
|
+
* Simulates a transaction based on the provided preauthenticated execution request.
|
|
569
|
+
* This will run a local simulation of private execution (and optionally of public as well), run the
|
|
570
|
+
* kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
|
|
571
|
+
* simulation results .
|
|
572
|
+
*
|
|
573
|
+
*
|
|
574
|
+
* Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
|
|
575
|
+
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
576
|
+
*
|
|
577
|
+
*
|
|
578
|
+
* @param txRequest - An authenticated tx request ready for simulation
|
|
579
|
+
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
580
|
+
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
581
|
+
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
582
|
+
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
583
|
+
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
584
|
+
* @returns A simulated transaction result object that includes public and private return values.
|
|
585
|
+
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
586
|
+
* Also throws if simulatePublic is true and public simulation reverts.
|
|
587
|
+
*
|
|
588
|
+
* TODO(#7456) Prevent msgSender being defined here for the first call
|
|
589
|
+
*/ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
|
|
561
590
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
562
591
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
563
592
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -574,7 +603,7 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
574
603
|
};
|
|
575
604
|
this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
576
605
|
const syncTimer = new Timer();
|
|
577
|
-
await this.
|
|
606
|
+
await this.blockStateSynchronizer.sync();
|
|
578
607
|
const syncTime = syncTimer.ms();
|
|
579
608
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
580
609
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
@@ -587,10 +616,9 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
587
616
|
let executionSteps = [];
|
|
588
617
|
if (skipKernels) {
|
|
589
618
|
// According to the protocol rules, the nonce generator for the note hashes
|
|
590
|
-
// can either be the first nullifier in the tx or the
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractDataProvider));
|
|
619
|
+
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
620
|
+
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO) ? await computeProtocolNullifier(await txRequest.toTxRequest().hash()) : privateExecutionResult.firstNullifier;
|
|
621
|
+
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractStore));
|
|
594
622
|
} else {
|
|
595
623
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
596
624
|
({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
@@ -654,19 +682,15 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
654
682
|
}
|
|
655
683
|
});
|
|
656
684
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
this.log.info(`Sent transaction ${txHash}`);
|
|
667
|
-
return txHash;
|
|
668
|
-
}
|
|
669
|
-
simulateUtility(functionName, args, to, authwits, _from, scopes) {
|
|
685
|
+
/**
|
|
686
|
+
* Simulate the execution of a contract utility function.
|
|
687
|
+
*
|
|
688
|
+
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
689
|
+
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
690
|
+
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
691
|
+
* default to all.
|
|
692
|
+
* @returns The result of the utility function call, structured based on the function ABI.
|
|
693
|
+
*/ simulateUtility(call, authwits, scopes) {
|
|
670
694
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
671
695
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
672
696
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
@@ -674,18 +698,17 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
674
698
|
try {
|
|
675
699
|
const totalTimer = new Timer();
|
|
676
700
|
const syncTimer = new Timer();
|
|
677
|
-
await this.
|
|
701
|
+
await this.blockStateSynchronizer.sync();
|
|
678
702
|
const syncTime = syncTimer.ms();
|
|
679
|
-
// TODO - Should check if `from` has the permission to call the view function.
|
|
680
|
-
const functionCall = await this.#getFunctionCall(functionName, args, to);
|
|
681
703
|
const functionTimer = new Timer();
|
|
682
704
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
683
|
-
|
|
705
|
+
await this.contractStore.syncPrivateState(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall));
|
|
706
|
+
const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes);
|
|
684
707
|
const functionTime = functionTimer.ms();
|
|
685
708
|
const totalTime = totalTimer.ms();
|
|
686
709
|
const perFunction = [
|
|
687
710
|
{
|
|
688
|
-
functionName,
|
|
711
|
+
functionName: call.name,
|
|
689
712
|
time: functionTime
|
|
690
713
|
}
|
|
691
714
|
];
|
|
@@ -704,85 +727,37 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
704
727
|
}
|
|
705
728
|
};
|
|
706
729
|
} catch (err) {
|
|
730
|
+
const { to, name, args } = call;
|
|
707
731
|
const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
|
|
708
|
-
throw this.#contextualizeError(err, `simulateUtility ${to}:${
|
|
732
|
+
throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
|
|
709
733
|
}
|
|
710
734
|
});
|
|
711
735
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
return this.#nodeInfo;
|
|
735
|
-
}
|
|
736
|
-
getPXEInfo() {
|
|
737
|
-
return Promise.resolve({
|
|
738
|
-
pxeVersion: this.packageVersion,
|
|
739
|
-
protocolContractAddresses: {
|
|
740
|
-
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
741
|
-
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
742
|
-
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
743
|
-
multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
async getPrivateEvents(contractAddress, eventMetadataDef, from, numBlocks, recipients) {
|
|
748
|
-
if (recipients.length === 0) {
|
|
749
|
-
throw new Error('Recipients are required to get private events');
|
|
750
|
-
}
|
|
751
|
-
this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
|
|
752
|
-
// We need to manually trigger private state sync to have a guarantee that all the events are available.
|
|
753
|
-
await this.simulateUtility('sync_private_state', [], contractAddress);
|
|
754
|
-
const events = await this.privateEventDataProvider.getPrivateEvents(contractAddress, from, numBlocks, recipients, eventMetadataDef.eventSelector);
|
|
755
|
-
const decodedEvents = events.map((event)=>decodeFromAbi([
|
|
756
|
-
eventMetadataDef.abiType
|
|
757
|
-
], event));
|
|
758
|
-
return decodedEvents;
|
|
759
|
-
}
|
|
760
|
-
async getPublicEvents(eventMetadataDef, from, limit) {
|
|
761
|
-
const { logs } = await this.node.getPublicLogs({
|
|
762
|
-
fromBlock: from,
|
|
763
|
-
toBlock: from + limit
|
|
736
|
+
/**
|
|
737
|
+
* Returns the private events given search parameters.
|
|
738
|
+
* @param eventSelector - Event selector to search for.
|
|
739
|
+
* @param filter
|
|
740
|
+
* contractAddress - The address of the contract to get events from. Required.
|
|
741
|
+
* scopes - One or more event scope addresses to filter by. Required.
|
|
742
|
+
* fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
|
|
743
|
+
* Defaults to 0.
|
|
744
|
+
* If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
|
|
745
|
+
* toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
|
|
746
|
+
* Defaults to the latest known block to PXE + 1.
|
|
747
|
+
* @returns - The packed events with block and tx metadata.
|
|
748
|
+
*/ getPrivateEvents(eventSelector, filter) {
|
|
749
|
+
return this.#putInJobQueue(async ()=>{
|
|
750
|
+
await this.blockStateSynchronizer.sync();
|
|
751
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
752
|
+
await this.contractStore.syncPrivateState(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall));
|
|
753
|
+
const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockStore).validate(filter);
|
|
754
|
+
this.log.debug(`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`);
|
|
755
|
+
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
764
756
|
});
|
|
765
|
-
const decodedEvents = logs.map((log)=>{
|
|
766
|
-
// +1 for the event selector
|
|
767
|
-
const expectedLength = eventMetadataDef.fieldNames.length + 1;
|
|
768
|
-
if (log.log.emittedLength !== expectedLength) {
|
|
769
|
-
throw new Error(`Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.emittedLength}.`);
|
|
770
|
-
}
|
|
771
|
-
const logFields = log.log.getEmittedFields();
|
|
772
|
-
// We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission.
|
|
773
|
-
if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) {
|
|
774
|
-
return undefined;
|
|
775
|
-
}
|
|
776
|
-
return decodeFromAbi([
|
|
777
|
-
eventMetadataDef.abiType
|
|
778
|
-
], log.log.fields);
|
|
779
|
-
}).filter((log)=>log !== undefined);
|
|
780
|
-
return decodedEvents;
|
|
781
757
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
stop() {
|
|
758
|
+
/**
|
|
759
|
+
* Stops the PXE's job queue.
|
|
760
|
+
*/ stop() {
|
|
786
761
|
return this.jobQueue.end();
|
|
787
762
|
}
|
|
788
763
|
}
|