@aztec/pxe 0.0.0-test.0 → 0.0.1-commit.0208eb9
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 +2 -0
- package/dest/bin/check_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_oracle_version.js +129 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +43 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
- package/dest/block_synchronizer/block_synchronizer.js +147 -0
- 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 +13 -24
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +35 -33
- package/dest/config/package_info.d.ts +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +82 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -0
- package/dest/contract_function_simulator/contract_function_simulator.js +339 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +104 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_note_cache.js +208 -0
- 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 +28 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/hashed_values_cache.js +36 -0
- package/dest/contract_function_simulator/index.d.ts +14 -0
- package/dest/contract_function_simulator/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/index.js +12 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +21 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +40 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +26 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +17 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +65 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +24 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +51 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +16 -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 +22 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +14 -0
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/index.js +2 -0
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +107 -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 +19 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +24 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +28 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +54 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts +60 -0
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle.js +368 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +23 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution.js +87 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +239 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +426 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +208 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +367 -0
- package/dest/contract_function_simulator/pick_notes.d.ts +85 -0
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -0
- package/dest/contract_function_simulator/pick_notes.js +51 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +6 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -0
- package/dest/contract_function_simulator/proxied_contract_data_source.js +80 -0
- package/dest/contract_sync/index.d.ts +24 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/index.js +61 -0
- package/dest/debug/pxe_debug_utils.d.ts +41 -0
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
- package/dest/debug/pxe_debug_utils.js +47 -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 +10 -10
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +33 -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 +10 -10
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +33 -12
- package/dest/entrypoints/pxe_creation_options.d.ts +18 -0
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +8 -4
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +6 -3
- package/dest/entrypoints/server/utils.d.ts +8 -16
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +46 -36
- 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} +30 -22
- 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 +44 -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 +38 -0
- package/dest/job_coordinator/job_coordinator.d.ts +75 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +94 -0
- package/dest/logs/log_service.d.ts +28 -0
- package/dest/logs/log_service.d.ts.map +1 -0
- package/dest/logs/log_service.js +123 -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 +147 -0
- package/dest/oracle_version.d.ts +3 -0
- package/dest/oracle_version.d.ts.map +1 -0
- package/dest/oracle_version.js +11 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.js +41 -0
- package/dest/private_kernel/hints/index.d.ts +3 -0
- package/dest/private_kernel/hints/index.d.ts.map +1 -0
- package/dest/private_kernel/hints/index.js +2 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +28 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +277 -0
- package/dest/private_kernel/index.d.ts +3 -0
- package/dest/private_kernel/index.d.ts.map +1 -0
- package/dest/private_kernel/index.js +2 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +45 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -0
- package/dest/private_kernel/private_kernel_execution_prover.js +285 -0
- package/dest/private_kernel/private_kernel_oracle.d.ts +59 -0
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -0
- package/dest/private_kernel/private_kernel_oracle.js +92 -0
- package/dest/pxe.d.ts +204 -0
- package/dest/pxe.d.ts.map +1 -0
- package/dest/pxe.js +742 -0
- 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} +13 -15
- 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 +17 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
- package/dest/storage/anchor_block_store/anchor_block_store.js +26 -0
- 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 +72 -0
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_store.js +253 -0
- 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_store/contract_store.d.ts +66 -0
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
- package/dest/storage/contract_store/contract_store.js +233 -0
- 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_store/private_functions_tree.d.ts +27 -0
- package/dest/storage/contract_store/private_functions_tree.d.ts.map +1 -0
- package/dest/storage/contract_store/private_functions_tree.js +47 -0
- package/dest/storage/index.d.ts +9 -10
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +8 -9
- package/dest/storage/metadata.d.ts +2 -0
- package/dest/storage/metadata.d.ts.map +1 -0
- package/dest/storage/metadata.js +1 -0
- 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 +83 -0
- package/dest/storage/note_store/note_store.d.ts.map +1 -0
- package/dest/storage/note_store/note_store.js +341 -0
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +91 -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 +273 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/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 +28 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/recipient_tagging_store.js +111 -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 +36 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +17 -0
- package/dest/tagging/index.d.ts.map +1 -0
- package/dest/tagging/index.js +15 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -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 +15 -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 +32 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -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 +29 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -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 +60 -0
- package/package.json +37 -34
- package/src/bin/check_oracle_version.ts +161 -0
- package/src/block_synchronizer/block_synchronizer.ts +172 -0
- package/src/block_synchronizer/index.ts +1 -0
- package/src/config/index.ts +41 -55
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/benchmarked_node.ts +103 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +633 -0
- package/src/contract_function_simulator/execution_note_cache.ts +252 -0
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +47 -0
- package/src/contract_function_simulator/index.ts +13 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +51 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +28 -0
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +69 -0
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +64 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +23 -0
- package/src/contract_function_simulator/oracle/index.ts +16 -0
- package/src/contract_function_simulator/oracle/interfaces.ts +185 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +23 -0
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +68 -0
- package/src/contract_function_simulator/oracle/oracle.ts +637 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +141 -0
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +701 -0
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +544 -0
- package/src/contract_function_simulator/pick_notes.ts +141 -0
- package/src/contract_function_simulator/proxied_contract_data_source.ts +83 -0
- package/src/contract_sync/index.ts +119 -0
- package/src/debug/pxe_debug_utils.ts +63 -0
- package/src/entrypoints/client/bundle/index.ts +3 -2
- package/src/entrypoints/client/bundle/utils.ts +35 -36
- package/src/entrypoints/client/lazy/index.ts +3 -2
- package/src/entrypoints/client/lazy/utils.ts +36 -32
- package/src/entrypoints/pxe_creation_options.ts +14 -0
- package/src/entrypoints/server/index.ts +7 -3
- package/src/entrypoints/server/utils.ts +52 -52
- package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +40 -39
- package/src/events/event_service.ts +71 -0
- package/src/events/index.ts +1 -0
- package/src/events/private_event_filter_validator.ts +46 -0
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +220 -0
- package/src/notes/index.ts +1 -0
- package/src/notes/note_service.ts +195 -0
- package/src/oracle_version.ts +12 -0
- package/src/private_kernel/hints/compute_tx_include_by_timestamp.ts +58 -0
- package/src/private_kernel/hints/index.ts +2 -0
- package/src/{kernel_prover/hints/build_private_kernel_reset_private_inputs.ts → private_kernel/hints/private_kernel_reset_private_inputs_builder.ts} +179 -156
- package/src/private_kernel/index.ts +2 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +433 -0
- package/src/private_kernel/private_kernel_oracle.ts +152 -0
- package/src/pxe.ts +1076 -0
- package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +15 -21
- 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} +10 -17
- package/src/storage/anchor_block_store/index.ts +1 -0
- package/src/storage/capsule_store/capsule_store.ts +315 -0
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +330 -0
- package/src/storage/contract_store/index.ts +1 -0
- package/src/storage/contract_store/private_functions_tree.ts +67 -0
- package/src/storage/index.ts +8 -10
- package/src/storage/metadata.ts +1 -0
- package/src/storage/note_store/index.ts +2 -0
- package/src/storage/note_store/note_store.ts +411 -0
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +384 -0
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/index.ts +3 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
- package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +19 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
- package/dest/bin/index.d.ts +0 -3
- package/dest/bin/index.d.ts.map +0 -1
- package/dest/bin/index.js +0 -28
- package/dest/entrypoints/client/pxe_creation_options.d.ts +0 -11
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +0 -1
- package/dest/kernel_oracle/index.d.ts +0 -45
- package/dest/kernel_oracle/index.d.ts.map +0 -1
- package/dest/kernel_oracle/index.js +0 -76
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/kernel_prover/hints/build_private_kernel_reset_private_inputs.js +0 -270
- package/dest/kernel_prover/hints/index.d.ts +0 -2
- package/dest/kernel_prover/hints/index.d.ts.map +0 -1
- package/dest/kernel_prover/hints/index.js +0 -1
- package/dest/kernel_prover/index.d.ts +0 -3
- package/dest/kernel_prover/index.d.ts.map +0 -1
- package/dest/kernel_prover/index.js +0 -2
- package/dest/kernel_prover/kernel_prover.d.ts +0 -38
- package/dest/kernel_prover/kernel_prover.d.ts.map +0 -1
- package/dest/kernel_prover/kernel_prover.js +0 -217
- package/dest/kernel_prover/proving_data_oracle.d.ts +0 -73
- package/dest/kernel_prover/proving_data_oracle.d.ts.map +0 -1
- package/dest/kernel_prover/proving_data_oracle.js +0 -4
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
- package/dest/pxe_http/index.d.ts +0 -2
- package/dest/pxe_http/index.d.ts.map +0 -1
- package/dest/pxe_http/index.js +0 -1
- package/dest/pxe_http/pxe_http_server.d.ts +0 -16
- package/dest/pxe_http/pxe_http_server.d.ts.map +0 -1
- package/dest/pxe_http/pxe_http_server.js +0 -27
- package/dest/pxe_oracle_interface/index.d.ts +0 -159
- package/dest/pxe_oracle_interface/index.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/index.js +0 -692
- package/dest/pxe_oracle_interface/tagging_utils.d.ts +0 -17
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +0 -1
- package/dest/pxe_oracle_interface/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 -111
- package/dest/pxe_service/pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/pxe_service.js +0 -664
- 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/auth_witness_data_provider/auth_witness_data_provider.d.ts +0 -11
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +0 -20
- package/dest/storage/auth_witness_data_provider/index.d.ts +0 -2
- package/dest/storage/auth_witness_data_provider/index.d.ts.map +0 -1
- package/dest/storage/auth_witness_data_provider/index.js +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -16
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -57
- 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 +0 -109
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/contract_data_provider.js +0 -183
- package/dest/storage/contract_data_provider/index.d.ts +0 -3
- package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.js +0 -2
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts +0 -66
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.js +0 -99
- 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 -106
- package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
- package/dest/storage/note_data_provider/note_dao.js +0 -106
- 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/note_data_provider/note_data_provider.js +0 -249
- 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/sync_data_provider/sync_data_provider.js +0 -29
- 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 -65
- 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 -37
- package/dest/synchronizer/synchronizer.d.ts.map +0 -1
- package/dest/synchronizer/synchronizer.js +0 -103
- 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 -38
- package/src/entrypoints/client/pxe_creation_options.ts +0 -7
- package/src/kernel_oracle/index.ts +0 -117
- package/src/kernel_prover/hints/index.ts +0 -1
- package/src/kernel_prover/index.ts +0 -2
- package/src/kernel_prover/kernel_prover.ts +0 -351
- package/src/kernel_prover/proving_data_oracle.ts +0 -83
- package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
- package/src/pxe_http/index.ts +0 -1
- package/src/pxe_http/pxe_http_server.ts +0 -29
- package/src/pxe_oracle_interface/index.ts +0 -925
- package/src/pxe_oracle_interface/tagging_utils.ts +0 -32
- package/src/pxe_service/index.ts +0 -2
- package/src/pxe_service/pxe_service.ts +0 -949
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +0 -34
- package/src/storage/auth_witness_data_provider/index.ts +0 -1
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -80
- package/src/storage/capsule_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/contract_data_provider.ts +0 -261
- package/src/storage/contract_data_provider/index.ts +0 -2
- package/src/storage/contract_data_provider/private_functions_tree.ts +0 -131
- 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 -162
- package/src/storage/note_data_provider/note_data_provider.ts +0 -345
- 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 -92
- package/src/synchronizer/index.ts +0 -1
- package/src/synchronizer/synchronizer.ts +0 -121
- package/src/test/pxe_test_suite.ts +0 -111
- /package/dest/entrypoints/{client/pxe_creation_options.js → pxe_creation_options.js} +0 -0
package/dest/pxe.js
ADDED
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { SerialQueue } from '@aztec/foundation/queue';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { KeyStore } from '@aztec/key-store';
|
|
5
|
+
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
6
|
+
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
7
|
+
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
8
|
+
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
9
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
10
|
+
import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
11
|
+
import { inspect } from 'util';
|
|
12
|
+
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
13
|
+
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
14
|
+
import { ContractFunctionSimulator, generateSimulatedProvingResult } from './contract_function_simulator/contract_function_simulator.js';
|
|
15
|
+
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
16
|
+
import { ensureContractSynced, readCurrentClassId } from './contract_sync/index.js';
|
|
17
|
+
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
18
|
+
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
19
|
+
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
20
|
+
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
21
|
+
import { PrivateKernelExecutionProver } from './private_kernel/private_kernel_execution_prover.js';
|
|
22
|
+
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.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';
|
|
32
|
+
/**
|
|
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 {
|
|
36
|
+
node;
|
|
37
|
+
blockStateSynchronizer;
|
|
38
|
+
keyStore;
|
|
39
|
+
contractStore;
|
|
40
|
+
noteStore;
|
|
41
|
+
capsuleStore;
|
|
42
|
+
anchorBlockStore;
|
|
43
|
+
senderTaggingStore;
|
|
44
|
+
senderAddressBookStore;
|
|
45
|
+
recipientTaggingStore;
|
|
46
|
+
addressStore;
|
|
47
|
+
privateEventStore;
|
|
48
|
+
simulator;
|
|
49
|
+
proverEnabled;
|
|
50
|
+
proofCreator;
|
|
51
|
+
protocolContractsProvider;
|
|
52
|
+
log;
|
|
53
|
+
jobQueue;
|
|
54
|
+
jobCoordinator;
|
|
55
|
+
debug;
|
|
56
|
+
constructor(node, blockStateSynchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debug){
|
|
57
|
+
this.node = node;
|
|
58
|
+
this.blockStateSynchronizer = blockStateSynchronizer;
|
|
59
|
+
this.keyStore = keyStore;
|
|
60
|
+
this.contractStore = contractStore;
|
|
61
|
+
this.noteStore = noteStore;
|
|
62
|
+
this.capsuleStore = capsuleStore;
|
|
63
|
+
this.anchorBlockStore = anchorBlockStore;
|
|
64
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
65
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
66
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
67
|
+
this.addressStore = addressStore;
|
|
68
|
+
this.privateEventStore = privateEventStore;
|
|
69
|
+
this.simulator = simulator;
|
|
70
|
+
this.proverEnabled = proverEnabled;
|
|
71
|
+
this.proofCreator = proofCreator;
|
|
72
|
+
this.protocolContractsProvider = protocolContractsProvider;
|
|
73
|
+
this.log = log;
|
|
74
|
+
this.jobQueue = jobQueue;
|
|
75
|
+
this.jobCoordinator = jobCoordinator;
|
|
76
|
+
this.debug = debug;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates an instance of a PXE by instantiating all the necessary data providers and services.
|
|
80
|
+
* Also triggers the registration of the protocol contracts and makes sure the provided node
|
|
81
|
+
* can be contacted.
|
|
82
|
+
*
|
|
83
|
+
* @returns A promise that resolves PXE is ready to be used.
|
|
84
|
+
*/ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
|
|
85
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
86
|
+
const bindings = loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
87
|
+
const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
|
|
88
|
+
const proverEnabled = !!config.proverEnabled;
|
|
89
|
+
const addressStore = new AddressStore(store);
|
|
90
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
91
|
+
const contractStore = new ContractStore(store);
|
|
92
|
+
const noteStore = new NoteStore(store);
|
|
93
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
94
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
95
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
96
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
97
|
+
const capsuleStore = new CapsuleStore(store);
|
|
98
|
+
const keyStore = new KeyStore(store);
|
|
99
|
+
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
100
|
+
const synchronizer = new BlockSynchronizer(node, store, anchorBlockStore, noteStore, privateEventStore, tipsStore, config, bindings);
|
|
101
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
102
|
+
jobCoordinator.registerStores([
|
|
103
|
+
capsuleStore,
|
|
104
|
+
senderTaggingStore,
|
|
105
|
+
recipientTaggingStore,
|
|
106
|
+
privateEventStore,
|
|
107
|
+
noteStore
|
|
108
|
+
]);
|
|
109
|
+
const debugUtils = new PXEDebugUtils(contractStore, noteStore, synchronizer, anchorBlockStore);
|
|
110
|
+
const jobQueue = new SerialQueue();
|
|
111
|
+
const pxe = new PXE(node, synchronizer, keyStore, contractStore, noteStore, capsuleStore, anchorBlockStore, senderTaggingStore, senderAddressBookStore, recipientTaggingStore, addressStore, privateEventStore, simulator, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue, jobCoordinator, debugUtils);
|
|
112
|
+
debugUtils.setPXE(pxe, pxe.#putInJobQueue.bind(pxe));
|
|
113
|
+
pxe.jobQueue.start();
|
|
114
|
+
await pxe.#registerProtocolContracts();
|
|
115
|
+
const info = await node.getNodeInfo();
|
|
116
|
+
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
117
|
+
return pxe;
|
|
118
|
+
}
|
|
119
|
+
// Internal methods
|
|
120
|
+
#getSimulatorForTx(overrides) {
|
|
121
|
+
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
122
|
+
return new ContractFunctionSimulator(proxyContractStore, this.noteStore, this.keyStore, this.addressStore, BenchmarkedNodeFactory.create(this.node), this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.simulator);
|
|
123
|
+
}
|
|
124
|
+
#contextualizeError(err, ...context) {
|
|
125
|
+
let contextStr = '';
|
|
126
|
+
if (context.length > 0) {
|
|
127
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
128
|
+
}
|
|
129
|
+
if (err instanceof SimulationError) {
|
|
130
|
+
err.setAztecContext(contextStr);
|
|
131
|
+
} else {
|
|
132
|
+
this.log.error(err.name, err);
|
|
133
|
+
this.log.debug(contextStr);
|
|
134
|
+
}
|
|
135
|
+
return err;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is
|
|
139
|
+
* complete.
|
|
140
|
+
*
|
|
141
|
+
* Useful for tasks that cannot run concurrently, such as contract function simulation.
|
|
142
|
+
*/ #putInJobQueue(fn) {
|
|
143
|
+
// TODO(#12636): relax the conditions under which we forbid concurrency.
|
|
144
|
+
if (this.jobQueue.length() != 0) {
|
|
145
|
+
this.log.warn(`PXE is already processing ${this.jobQueue.length()} jobs, concurrent execution is not supported. Will run once those are complete.`);
|
|
146
|
+
}
|
|
147
|
+
return this.jobQueue.put(async ()=>{
|
|
148
|
+
const jobId = this.jobCoordinator.beginJob();
|
|
149
|
+
this.log.verbose(`Beginning job ${jobId}`);
|
|
150
|
+
try {
|
|
151
|
+
const result = await fn(jobId);
|
|
152
|
+
this.log.verbose(`Committing job ${jobId}`);
|
|
153
|
+
await this.jobCoordinator.commitJob(jobId);
|
|
154
|
+
return result;
|
|
155
|
+
} catch (err) {
|
|
156
|
+
this.log.verbose(`Aborting job ${jobId}`);
|
|
157
|
+
await this.jobCoordinator.abortJob(jobId);
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async #registerProtocolContracts() {
|
|
163
|
+
const registered = {};
|
|
164
|
+
for (const name of protocolContractNames){
|
|
165
|
+
const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
166
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
167
|
+
await this.contractStore.addContractInstance(instance);
|
|
168
|
+
registered[name] = address.toString();
|
|
169
|
+
}
|
|
170
|
+
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
171
|
+
}
|
|
172
|
+
// Executes the entrypoint private function, as well as all nested private
|
|
173
|
+
// functions that might arise.
|
|
174
|
+
async #executePrivate(contractFunctionSimulator, txRequest, scopes, jobId) {
|
|
175
|
+
const { origin: contractAddress, functionSelector } = txRequest;
|
|
176
|
+
try {
|
|
177
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
178
|
+
await ensureContractSynced(contractAddress, functionSelector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, this.noteStore, anchorBlockHeader, jobId);
|
|
179
|
+
const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, anchorBlockHeader, // The sender for tags is set by contracts, typically by an account
|
|
180
|
+
// contract entrypoint
|
|
181
|
+
undefined, scopes, jobId);
|
|
182
|
+
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
183
|
+
return result;
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (err instanceof SimulationError) {
|
|
186
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
187
|
+
}
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Simulate a utility function call on the given contract.
|
|
193
|
+
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
194
|
+
* @param call - The function call to execute.
|
|
195
|
+
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
196
|
+
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
197
|
+
* accounts if not specified.
|
|
198
|
+
* @param jobId - The job ID for staged writes.
|
|
199
|
+
* @returns The simulation result containing the outputs of the utility function.
|
|
200
|
+
*/ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes, jobId) {
|
|
201
|
+
try {
|
|
202
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
203
|
+
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], anchorBlockHeader, scopes, jobId);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
if (err instanceof SimulationError) {
|
|
206
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
207
|
+
}
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Simulate the public part of a transaction.
|
|
213
|
+
* This allows to catch public execution errors before submitting the transaction.
|
|
214
|
+
* It can also be used for estimating gas in the future.
|
|
215
|
+
* @param tx - The transaction to be simulated.
|
|
216
|
+
*/ async #simulatePublicCalls(tx, skipFeeEnforcement) {
|
|
217
|
+
// Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
|
|
218
|
+
// Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
|
|
219
|
+
try {
|
|
220
|
+
const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
221
|
+
if (result.revertReason) {
|
|
222
|
+
throw result.revertReason;
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
} catch (err) {
|
|
226
|
+
if (err instanceof SimulationError) {
|
|
227
|
+
try {
|
|
228
|
+
await enrichPublicSimulationError(err, this.contractStore, this.log);
|
|
229
|
+
} catch (enrichErr) {
|
|
230
|
+
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
throw err;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Generate a kernel proof, and create a private kernel output.
|
|
238
|
+
* The function takes in a transaction execution request, and the result of private execution
|
|
239
|
+
* and then generates a kernel proof.
|
|
240
|
+
*
|
|
241
|
+
* @param txExecutionRequest - The transaction request to be simulated and proved.
|
|
242
|
+
* @param proofCreator - The proof creator to use for proving the execution.
|
|
243
|
+
* @param privateExecutionResult - The result of the private execution
|
|
244
|
+
* @param config - The configuration for the kernel execution prover.
|
|
245
|
+
* @returns An object that contains the output of the kernel execution, including the ChonkProof if proving is enabled.
|
|
246
|
+
*/ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
|
|
247
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
248
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
249
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
250
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled, this.log.getBindings());
|
|
251
|
+
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
252
|
+
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
253
|
+
}
|
|
254
|
+
// Public API
|
|
255
|
+
getContractInstance(address) {
|
|
256
|
+
return this.contractStore.getContractInstance(address);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Returns the contract artifact for a given contract class id, if it's registered in the PXE.
|
|
260
|
+
* @param id - Identifier of the contract class.
|
|
261
|
+
* @returns The contract artifact if found, undefined otherwise.
|
|
262
|
+
*/ async getContractArtifact(id) {
|
|
263
|
+
return await this.contractStore.getContractArtifact(id);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Registers a user account in PXE given its master encryption private key.
|
|
267
|
+
* Once a new account is registered, the PXE will trial-decrypt all published notes on
|
|
268
|
+
* the chain and store those that correspond to the registered account. Will do nothing if the
|
|
269
|
+
* account is already registered.
|
|
270
|
+
*
|
|
271
|
+
* @param secretKey - Secret key of the corresponding user master public key.
|
|
272
|
+
* @param partialAddress - The partial address of the account contract corresponding to the account being registered.
|
|
273
|
+
* @returns The complete address of the account.
|
|
274
|
+
*/ async registerAccount(secretKey, partialAddress) {
|
|
275
|
+
const accounts = await this.keyStore.getAccounts();
|
|
276
|
+
const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
|
|
277
|
+
if (accounts.includes(accountCompleteAddress.address)) {
|
|
278
|
+
this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
|
|
279
|
+
return accountCompleteAddress;
|
|
280
|
+
} else {
|
|
281
|
+
this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
|
|
282
|
+
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
283
|
+
}
|
|
284
|
+
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
285
|
+
return accountCompleteAddress;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Registers a sender in this PXE.
|
|
289
|
+
*
|
|
290
|
+
* After registering a new sender, the PXE will sync private logs that are tagged with this sender's address.
|
|
291
|
+
* Will do nothing if the address is already registered.
|
|
292
|
+
*
|
|
293
|
+
* @param sender - Address of the sender to register.
|
|
294
|
+
* @returns The address of the sender.
|
|
295
|
+
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
296
|
+
*/ async registerSender(sender) {
|
|
297
|
+
const accounts = await this.keyStore.getAccounts();
|
|
298
|
+
if (accounts.includes(sender)) {
|
|
299
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
300
|
+
return sender;
|
|
301
|
+
}
|
|
302
|
+
const wasAdded = await this.senderAddressBookStore.addSender(sender);
|
|
303
|
+
if (wasAdded) {
|
|
304
|
+
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
305
|
+
} else {
|
|
306
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
307
|
+
}
|
|
308
|
+
return sender;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Retrieves senders registered in this PXE.
|
|
312
|
+
* @returns Senders registered in this PXE.
|
|
313
|
+
*/ getSenders() {
|
|
314
|
+
return this.senderAddressBookStore.getSenders();
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Removes a sender registered in this PXE.
|
|
318
|
+
* @param sender - The address of the sender to remove.
|
|
319
|
+
*/ async removeSender(sender) {
|
|
320
|
+
const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
|
|
321
|
+
if (wasRemoved) {
|
|
322
|
+
this.log.info(`Removed sender:\n ${sender.toString()}`);
|
|
323
|
+
} else {
|
|
324
|
+
this.log.info(`Sender:\n "${sender.toString()}"\n not registered in PXE.`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Retrieves the user accounts registered on this PXE.
|
|
329
|
+
* @returns An array of the accounts registered on this PXE.
|
|
330
|
+
*/ async getRegisteredAccounts() {
|
|
331
|
+
// Get complete addresses of both the recipients and the accounts
|
|
332
|
+
const completeAddresses = await this.addressStore.getCompleteAddresses();
|
|
333
|
+
// Filter out the addresses not corresponding to accounts
|
|
334
|
+
const accounts = await this.keyStore.getAccounts();
|
|
335
|
+
return completeAddresses.filter((completeAddress)=>accounts.find((address)=>address.equals(completeAddress.address)));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Registers a contract class in the PXE without registering any associated contract instance with it.
|
|
339
|
+
*
|
|
340
|
+
* @param artifact - The build artifact for the contract class.
|
|
341
|
+
*/ async registerContractClass(artifact) {
|
|
342
|
+
const { id: contractClassId } = await getContractClassFromArtifact(artifact);
|
|
343
|
+
await this.contractStore.addContractArtifact(contractClassId, artifact);
|
|
344
|
+
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Adds deployed contracts to the PXE. Deployed contract information is used to access the
|
|
348
|
+
* contract code when simulating local transactions. This is automatically called by aztec.js when
|
|
349
|
+
* deploying a contract. Dapps that wish to interact with contracts already deployed should register
|
|
350
|
+
* these contracts in their users' PXE through this method.
|
|
351
|
+
*
|
|
352
|
+
* @param contract - A contract instance to register, with an optional artifact which can be omitted if the contract class has already been registered.
|
|
353
|
+
*/ async registerContract(contract) {
|
|
354
|
+
const { instance } = contract;
|
|
355
|
+
let { artifact } = contract;
|
|
356
|
+
if (artifact) {
|
|
357
|
+
// If the user provides an artifact, validate it against the expected class id and register it
|
|
358
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
359
|
+
const contractClassId = contractClass.id;
|
|
360
|
+
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
361
|
+
throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
|
|
362
|
+
}
|
|
363
|
+
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
364
|
+
if (!computedAddress.equals(instance.address)) {
|
|
365
|
+
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
366
|
+
}
|
|
367
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
368
|
+
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
369
|
+
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
370
|
+
} else {
|
|
371
|
+
// Otherwise, make sure there is an artifact already registered for that class id
|
|
372
|
+
artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
373
|
+
if (!artifact) {
|
|
374
|
+
throw new Error(`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
await this.contractStore.addContractInstance(instance);
|
|
378
|
+
this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Updates a deployed contract in the PXE. This is used to update the contract artifact when
|
|
382
|
+
* an update has happened, so the new code can be used in the simulation of local transactions.
|
|
383
|
+
* This is called by aztec.js when instantiating a contract in a given address with a mismatching artifact.
|
|
384
|
+
* @param contractAddress - The address of the contract to update.
|
|
385
|
+
* @param artifact - The updated artifact for the contract.
|
|
386
|
+
* @throws If the artifact's contract class is not found in the PXE or if the contract class is different from
|
|
387
|
+
* the current one (current one from the point of view of the node to which the PXE is connected).
|
|
388
|
+
*/ updateContract(contractAddress, artifact) {
|
|
389
|
+
// We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
|
|
390
|
+
// class while we're simulating it.
|
|
391
|
+
return this.#putInJobQueue(async ()=>{
|
|
392
|
+
const currentInstance = await this.contractStore.getContractInstance(contractAddress);
|
|
393
|
+
if (!currentInstance) {
|
|
394
|
+
throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
|
|
395
|
+
}
|
|
396
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
397
|
+
await this.blockStateSynchronizer.sync();
|
|
398
|
+
const header = await this.anchorBlockStore.getBlockHeader();
|
|
399
|
+
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
400
|
+
if (!contractClass.id.equals(currentClassId)) {
|
|
401
|
+
throw new Error('Could not update contract to a class different from the current one.');
|
|
402
|
+
}
|
|
403
|
+
await this.contractStore.addContractArtifact(contractClass.id, artifact);
|
|
404
|
+
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
405
|
+
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
406
|
+
currentInstance.currentContractClassId = contractClass.id;
|
|
407
|
+
await this.contractStore.addContractInstance(currentInstance);
|
|
408
|
+
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Retrieves the addresses of contracts added to this PXE.
|
|
413
|
+
* @returns An array of contracts addresses registered on this PXE.
|
|
414
|
+
*/ getContracts() {
|
|
415
|
+
return this.contractStore.getContractsAddresses();
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Proves the private portion of a simulated transaction, ready to send to the network
|
|
419
|
+
* (where validators prove the public portion).
|
|
420
|
+
*
|
|
421
|
+
* @param txRequest - An authenticated tx request ready for proving
|
|
422
|
+
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
423
|
+
* @throws If contract code not found, or public simulation reverts.
|
|
424
|
+
* Also throws if simulatePublic is true and public simulation reverts.
|
|
425
|
+
*/ proveTx(txRequest) {
|
|
426
|
+
let privateExecutionResult;
|
|
427
|
+
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
428
|
+
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
429
|
+
return this.#putInJobQueue(async (jobId)=>{
|
|
430
|
+
const totalTimer = new Timer();
|
|
431
|
+
try {
|
|
432
|
+
const syncTimer = new Timer();
|
|
433
|
+
await this.blockStateSynchronizer.sync();
|
|
434
|
+
const syncTime = syncTimer.ms();
|
|
435
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
436
|
+
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
|
|
437
|
+
const { publicInputs, chonkProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
438
|
+
simulate: false,
|
|
439
|
+
skipFeeEnforcement: false,
|
|
440
|
+
profileMode: 'none'
|
|
441
|
+
});
|
|
442
|
+
const totalTime = totalTimer.ms();
|
|
443
|
+
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
|
|
444
|
+
functionName,
|
|
445
|
+
time: witgen,
|
|
446
|
+
oracles
|
|
447
|
+
}));
|
|
448
|
+
const timings = {
|
|
449
|
+
total: totalTime,
|
|
450
|
+
sync: syncTime,
|
|
451
|
+
proving,
|
|
452
|
+
perFunction,
|
|
453
|
+
unaccounted: totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
454
|
+
};
|
|
455
|
+
this.log.debug(`Proving completed in ${totalTime}ms`, {
|
|
456
|
+
timings
|
|
457
|
+
});
|
|
458
|
+
const txProvingResult = new TxProvingResult(privateExecutionResult, publicInputs, chonkProof, {
|
|
459
|
+
timings,
|
|
460
|
+
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
|
|
461
|
+
});
|
|
462
|
+
// While not strictly necessary to store tagging cache contents in the DB since we sync tagging indexes from
|
|
463
|
+
// chain before sending new logs, the sync can only see logs already included in blocks. If we send another
|
|
464
|
+
// transaction before this one is included in a block from this PXE, and that transaction contains a log with
|
|
465
|
+
// a tag derived from the same secret, we would reuse the tag and the transactions would be linked. Hence
|
|
466
|
+
// storing the tags here prevents linkage of txs sent from the same PXE.
|
|
467
|
+
const preTagsUsedInTheTx = privateExecutionResult.entrypoint.preTags;
|
|
468
|
+
if (preTagsUsedInTheTx.length > 0) {
|
|
469
|
+
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
|
|
470
|
+
const txHash = (await txProvingResult.toTx()).txHash;
|
|
471
|
+
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
|
|
472
|
+
this.log.debug(`Stored used pre-tags as sender for the tx`, {
|
|
473
|
+
preTagsUsedInTheTx
|
|
474
|
+
});
|
|
475
|
+
} else {
|
|
476
|
+
this.log.debug(`No pre-tags used in the tx`);
|
|
477
|
+
}
|
|
478
|
+
return txProvingResult;
|
|
479
|
+
} catch (err) {
|
|
480
|
+
throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
486
|
+
*
|
|
487
|
+
* @param txRequest - An authenticated tx request ready for simulation
|
|
488
|
+
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
489
|
+
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
490
|
+
* @returns A trace of the program execution with gate counts.
|
|
491
|
+
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
492
|
+
*/ profileTx(txRequest, profileMode, skipProofGeneration = true) {
|
|
493
|
+
// We disable concurrent profiles for consistency with simulateTx.
|
|
494
|
+
return this.#putInJobQueue(async (jobId)=>{
|
|
495
|
+
const totalTimer = new Timer();
|
|
496
|
+
try {
|
|
497
|
+
const txInfo = {
|
|
498
|
+
origin: txRequest.origin,
|
|
499
|
+
functionSelector: txRequest.functionSelector,
|
|
500
|
+
simulatePublic: false,
|
|
501
|
+
chainId: txRequest.txContext.chainId,
|
|
502
|
+
version: txRequest.txContext.version,
|
|
503
|
+
authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
|
|
504
|
+
};
|
|
505
|
+
this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
506
|
+
const syncTimer = new Timer();
|
|
507
|
+
await this.blockStateSynchronizer.sync();
|
|
508
|
+
const syncTime = syncTimer.ms();
|
|
509
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
510
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, undefined, jobId);
|
|
511
|
+
const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
512
|
+
simulate: skipProofGeneration,
|
|
513
|
+
skipFeeEnforcement: false,
|
|
514
|
+
profileMode
|
|
515
|
+
});
|
|
516
|
+
const totalTime = totalTimer.ms();
|
|
517
|
+
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>{
|
|
518
|
+
return {
|
|
519
|
+
functionName,
|
|
520
|
+
time: witgen,
|
|
521
|
+
oracles
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
// Gate computation is time is not relevant for profiling, so we subtract it from the total time.
|
|
525
|
+
const gateCountComputationTime = executionSteps.reduce((acc, { timings })=>acc + (timings.gateCount ?? 0), 0) ?? 0;
|
|
526
|
+
const total = totalTime - gateCountComputationTime;
|
|
527
|
+
const timings = {
|
|
528
|
+
total,
|
|
529
|
+
sync: syncTime,
|
|
530
|
+
proving,
|
|
531
|
+
perFunction,
|
|
532
|
+
unaccounted: total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
533
|
+
};
|
|
534
|
+
const simulatorStats = contractFunctionSimulator.getStats();
|
|
535
|
+
return new TxProfileResult(executionSteps, {
|
|
536
|
+
timings,
|
|
537
|
+
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
538
|
+
});
|
|
539
|
+
} catch (err) {
|
|
540
|
+
throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Simulates a transaction based on the provided preauthenticated execution request.
|
|
546
|
+
* This will run a local simulation of private execution (and optionally of public as well), run the
|
|
547
|
+
* kernel circuits to ensure adherence to protocol rules (without generating a proof), and return the
|
|
548
|
+
* simulation results .
|
|
549
|
+
*
|
|
550
|
+
*
|
|
551
|
+
* Note that this is used with `ContractFunctionInteraction::simulateTx` to bypass certain checks.
|
|
552
|
+
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
553
|
+
*
|
|
554
|
+
*
|
|
555
|
+
* @param txRequest - An authenticated tx request ready for simulation
|
|
556
|
+
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
557
|
+
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
558
|
+
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
559
|
+
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
560
|
+
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
561
|
+
* @returns A simulated transaction result object that includes public and private return values.
|
|
562
|
+
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
563
|
+
* Also throws if simulatePublic is true and public simulation reverts.
|
|
564
|
+
*
|
|
565
|
+
* TODO(#7456) Prevent msgSender being defined here for the first call
|
|
566
|
+
*/ simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
|
|
567
|
+
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
568
|
+
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
569
|
+
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
570
|
+
return this.#putInJobQueue(async (jobId)=>{
|
|
571
|
+
try {
|
|
572
|
+
const totalTimer = new Timer();
|
|
573
|
+
const txInfo = {
|
|
574
|
+
origin: txRequest.origin,
|
|
575
|
+
functionSelector: txRequest.functionSelector,
|
|
576
|
+
simulatePublic,
|
|
577
|
+
chainId: txRequest.txContext.chainId,
|
|
578
|
+
version: txRequest.txContext.version,
|
|
579
|
+
authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
|
|
580
|
+
};
|
|
581
|
+
this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
582
|
+
const syncTimer = new Timer();
|
|
583
|
+
await this.blockStateSynchronizer.sync();
|
|
584
|
+
const syncTime = syncTimer.ms();
|
|
585
|
+
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
586
|
+
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
587
|
+
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
588
|
+
// or not.
|
|
589
|
+
const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
|
|
590
|
+
// Execution of private functions only; no proving, and no kernel logic.
|
|
591
|
+
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
592
|
+
let publicInputs;
|
|
593
|
+
let executionSteps = [];
|
|
594
|
+
if (skipKernels) {
|
|
595
|
+
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, this.contractStore));
|
|
596
|
+
} else {
|
|
597
|
+
// Kernel logic, plus proving of all private functions and kernels.
|
|
598
|
+
({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
599
|
+
simulate: true,
|
|
600
|
+
skipFeeEnforcement,
|
|
601
|
+
profileMode: 'none'
|
|
602
|
+
}));
|
|
603
|
+
}
|
|
604
|
+
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
605
|
+
const simulatedTx = await privateSimulationResult.toSimulatedTx();
|
|
606
|
+
let publicSimulationTime;
|
|
607
|
+
let publicOutput;
|
|
608
|
+
if (simulatePublic && publicInputs.forPublic) {
|
|
609
|
+
const publicSimulationTimer = new Timer();
|
|
610
|
+
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
611
|
+
publicSimulationTime = publicSimulationTimer.ms();
|
|
612
|
+
}
|
|
613
|
+
let validationTime;
|
|
614
|
+
if (!skipTxValidation) {
|
|
615
|
+
const validationTimer = new Timer();
|
|
616
|
+
const validationResult = await this.node.isValidTx(simulatedTx, {
|
|
617
|
+
isSimulation: true,
|
|
618
|
+
skipFeeEnforcement
|
|
619
|
+
});
|
|
620
|
+
validationTime = validationTimer.ms();
|
|
621
|
+
if (validationResult.result === 'invalid') {
|
|
622
|
+
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const txHash = simulatedTx.getTxHash();
|
|
626
|
+
const totalTime = totalTimer.ms();
|
|
627
|
+
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
|
|
628
|
+
functionName,
|
|
629
|
+
time: witgen,
|
|
630
|
+
oracles
|
|
631
|
+
}));
|
|
632
|
+
const timings = {
|
|
633
|
+
total: totalTime,
|
|
634
|
+
sync: syncTime,
|
|
635
|
+
publicSimulation: publicSimulationTime,
|
|
636
|
+
validation: validationTime,
|
|
637
|
+
perFunction,
|
|
638
|
+
unaccounted: totalTime - (syncTime + (publicSimulationTime ?? 0) + (validationTime ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
639
|
+
};
|
|
640
|
+
this.log.info(`Simulation completed for ${txHash.toString()} in ${totalTime}ms`, {
|
|
641
|
+
txHash,
|
|
642
|
+
...txInfo,
|
|
643
|
+
...publicOutput ? {
|
|
644
|
+
gasUsed: publicOutput.gasUsed,
|
|
645
|
+
revertCode: publicOutput.txEffect.revertCode.getCode(),
|
|
646
|
+
revertReason: publicOutput.revertReason
|
|
647
|
+
} : {}
|
|
648
|
+
});
|
|
649
|
+
const simulatorStats = contractFunctionSimulator.getStats();
|
|
650
|
+
return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
|
|
651
|
+
timings,
|
|
652
|
+
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
653
|
+
});
|
|
654
|
+
} catch (err) {
|
|
655
|
+
throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Simulate the execution of a contract utility function.
|
|
661
|
+
*
|
|
662
|
+
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
663
|
+
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
664
|
+
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
665
|
+
* default to all.
|
|
666
|
+
* @returns The result of the utility function call, structured based on the function ABI.
|
|
667
|
+
*/ simulateUtility(call, authwits, scopes) {
|
|
668
|
+
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
669
|
+
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
670
|
+
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
671
|
+
return this.#putInJobQueue(async (jobId)=>{
|
|
672
|
+
try {
|
|
673
|
+
const totalTimer = new Timer();
|
|
674
|
+
const syncTimer = new Timer();
|
|
675
|
+
await this.blockStateSynchronizer.sync();
|
|
676
|
+
const syncTime = syncTimer.ms();
|
|
677
|
+
const functionTimer = new Timer();
|
|
678
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
679
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
680
|
+
await ensureContractSynced(call.to, call.selector, (privateSyncCall)=>this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, this.noteStore, anchorBlockHeader, jobId);
|
|
681
|
+
const executionResult = await this.#simulateUtility(contractFunctionSimulator, call, authwits ?? [], scopes, jobId);
|
|
682
|
+
const functionTime = functionTimer.ms();
|
|
683
|
+
const totalTime = totalTimer.ms();
|
|
684
|
+
const perFunction = [
|
|
685
|
+
{
|
|
686
|
+
functionName: call.name,
|
|
687
|
+
time: functionTime
|
|
688
|
+
}
|
|
689
|
+
];
|
|
690
|
+
const timings = {
|
|
691
|
+
total: totalTime,
|
|
692
|
+
sync: syncTime,
|
|
693
|
+
perFunction,
|
|
694
|
+
unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
695
|
+
};
|
|
696
|
+
const simulationStats = contractFunctionSimulator.getStats();
|
|
697
|
+
return {
|
|
698
|
+
result: executionResult,
|
|
699
|
+
stats: {
|
|
700
|
+
timings,
|
|
701
|
+
nodeRPCCalls: simulationStats.nodeRPCCalls
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
} catch (err) {
|
|
705
|
+
const { to, name, args } = call;
|
|
706
|
+
const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
|
|
707
|
+
throw this.#contextualizeError(err, `simulateUtility ${to}:${name}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Returns the private events given search parameters.
|
|
713
|
+
* @param eventSelector - Event selector to search for.
|
|
714
|
+
* @param filter
|
|
715
|
+
* contractAddress - The address of the contract to get events from. Required.
|
|
716
|
+
* scopes - One or more event scope addresses to filter by. Required.
|
|
717
|
+
* fromBlock - The block number to search from (inclusive). Optional. If provided, it must be >= 0.
|
|
718
|
+
* Defaults to 0.
|
|
719
|
+
* If toBlock is defined but fromBlock is not, fromBlock defaults to toBlock - 1.
|
|
720
|
+
* toBlock - The block number to search up to (exclusive). Optional. If provided, it must be > 0.
|
|
721
|
+
* Defaults to the latest known block to PXE + 1.
|
|
722
|
+
* @returns - The packed events with block and tx metadata.
|
|
723
|
+
*/ async getPrivateEvents(eventSelector, filter) {
|
|
724
|
+
let anchorBlockNumber;
|
|
725
|
+
await this.#putInJobQueue(async (jobId)=>{
|
|
726
|
+
await this.blockStateSynchronizer.sync();
|
|
727
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
728
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
729
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
730
|
+
await ensureContractSynced(filter.contractAddress, null, async (privateSyncCall)=>await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId), this.node, this.contractStore, this.noteStore, anchorBlockHeader, jobId);
|
|
731
|
+
});
|
|
732
|
+
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
733
|
+
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber).validate(filter);
|
|
734
|
+
this.log.debug(`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`);
|
|
735
|
+
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Stops the PXE's job queue.
|
|
739
|
+
*/ stop() {
|
|
740
|
+
return this.jobQueue.end();
|
|
741
|
+
}
|
|
742
|
+
}
|