@aztec/pxe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/check_oracle_version.d.ts +12 -2
- package/dest/bin/check_oracle_version.d.ts.map +1 -1
- package/dest/bin/check_oracle_version.js +32 -26
- package/dest/bin/index.d.ts +2 -0
- package/dest/bin/index.d.ts.map +1 -0
- package/dest/bin/index.js +1 -0
- package/dest/block_synchronizer/block_stream_source.d.ts +10 -0
- package/dest/block_synchronizer/block_stream_source.d.ts.map +1 -0
- package/dest/block_synchronizer/block_stream_source.js +62 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +22 -12
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +101 -35
- package/dest/config/index.d.ts +10 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -2
- 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 +77 -41
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +251 -96
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts +28 -0
- package/dest/contract_function_simulator/ephemeral_array_service.d.ts.map +1 -0
- package/dest/contract_function_simulator/ephemeral_array_service.js +78 -0
- package/dest/contract_function_simulator/execution_note_cache.d.ts +18 -9
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +45 -28
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +7 -11
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +19 -15
- package/dest/contract_function_simulator/index.d.ts +5 -2
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +4 -1
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts +48 -0
- package/dest/contract_function_simulator/noir-structs/bounded_vec.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/bounded_vec.js +45 -0
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +6 -7
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +12 -10
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +13 -3
- 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 +35 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +2 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +5 -8
- 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 +7 -11
- package/dest/contract_function_simulator/noir-structs/option.d.ts +61 -0
- package/dest/contract_function_simulator/noir-structs/option.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/option.js +62 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +4 -10
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/utility_context.js +7 -18
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +70 -50
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +3 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +7 -7
- 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 -10
- package/dest/contract_function_simulator/oracle/oracle.d.ts +74 -43
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +471 -264
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +147 -0
- package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/oracle_registry.js +1199 -0
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -26
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +5 -39
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +74 -100
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +168 -139
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +169 -90
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +468 -193
- package/dest/contract_function_simulator/pick_notes.d.ts +1 -1
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +20 -3
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +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 +39 -68
- package/dest/contract_logging.d.ts +27 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +38 -0
- package/dest/contract_sync/contract_sync_service.d.ts +42 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +135 -0
- package/dest/contract_sync/helpers.d.ts +27 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +53 -0
- package/dest/debug/pxe_debug_utils.d.ts +21 -12
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +24 -19
- package/dest/entrypoints/client/bundle/index.d.ts +3 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +2 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +2 -2
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +41 -10
- package/dest/entrypoints/client/lazy/index.d.ts +3 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +2 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +3 -3
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +42 -11
- package/dest/entrypoints/pxe_creation_options.d.ts +13 -3
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/pxe_creation_options.js +3 -1
- package/dest/entrypoints/server/index.d.ts +6 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +5 -1
- package/dest/entrypoints/server/utils.d.ts +4 -3
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +49 -18
- package/dest/error_enriching.d.ts +4 -4
- package/dest/error_enriching.d.ts.map +1 -1
- package/dest/error_enriching.js +6 -6
- package/dest/events/event_service.d.ts +19 -10
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +60 -30
- package/dest/events/private_event_filter_validator.d.ts +7 -6
- package/dest/events/private_event_filter_validator.d.ts.map +1 -1
- package/dest/events/private_event_filter_validator.js +20 -6
- package/dest/hooks/authorize_utility_call.d.ts +41 -0
- package/dest/hooks/authorize_utility_call.d.ts.map +1 -0
- package/dest/hooks/authorize_utility_call.js +4 -0
- package/dest/hooks/execution_hooks.d.ts +42 -0
- package/dest/hooks/execution_hooks.d.ts.map +1 -0
- package/dest/hooks/execution_hooks.js +9 -0
- package/dest/hooks/index.d.ts +4 -0
- package/dest/hooks/index.d.ts.map +1 -0
- package/dest/hooks/index.js +1 -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 +21 -35
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +144 -215
- package/dest/messages/message_context_service.d.ts +17 -0
- package/dest/messages/message_context_service.d.ts.map +1 -0
- package/dest/messages/message_context_service.js +38 -0
- package/dest/notes/note_service.d.ts +34 -12
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +102 -82
- package/dest/notes_filter.d.ts +24 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +4 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +20 -9
- package/dest/private_kernel/batch_planner.d.ts +47 -0
- package/dest/private_kernel/batch_planner.d.ts.map +1 -0
- package/dest/private_kernel/batch_planner.js +104 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +3 -3
- package/dest/private_kernel/hints/index.d.ts.map +1 -1
- package/dest/private_kernel/hints/index.js +2 -2
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +29 -0
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -0
- package/dest/private_kernel/hints/{build_private_kernel_reset_private_inputs.js → private_kernel_reset_private_inputs_builder.js} +142 -75
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +202 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +7 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +169 -69
- package/dest/private_kernel/private_kernel_oracle.d.ts +29 -29
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +96 -2
- package/dest/pxe.d.ts +136 -67
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +314 -231
- 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 -12
- 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/backwards_compatibility_tests/kv_store_snapshot.d.ts +42 -0
- package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/kv_store_snapshot.js +93 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts +15 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/schema_tests.js +591 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.d.ts +19 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.d.ts.map +1 -0
- package/dest/storage/backwards_compatibility_tests/store_spy.js +63 -0
- package/dest/storage/capsule_store/capsule_service.d.ts +21 -0
- package/dest/storage/capsule_store/capsule_service.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_service.js +50 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_store.js +261 -0
- package/dest/storage/capsule_store/index.d.ts +3 -0
- package/dest/storage/capsule_store/index.d.ts.map +1 -0
- package/dest/storage/capsule_store/index.js +2 -0
- package/dest/storage/contract_store/contract_store.d.ts +93 -0
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
- package/dest/storage/contract_store/contract_store.js +292 -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_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/index.d.ts +8 -8
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +7 -7
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +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 +83 -0
- package/dest/storage/note_store/note_store.d.ts.map +1 -0
- package/dest/storage/note_store/note_store.js +343 -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/open_pxe_stores.d.ts +33 -0
- package/dest/storage/open_pxe_stores.d.ts.map +1 -0
- package/dest/storage/open_pxe_stores.js +27 -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 +276 -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 +78 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_tagging_store.js +374 -0
- package/dest/tagging/constants.d.ts +2 -2
- package/dest/tagging/constants.d.ts.map +1 -1
- package/dest/tagging/constants.js +10 -3
- package/dest/tagging/get_all_logs_by_tags.d.ts +48 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +59 -0
- package/dest/tagging/index.d.ts +18 -5
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +16 -3
- package/dest/tagging/persist_sender_tagging_index_ranges.d.ts +29 -0
- package/dest/tagging/persist_sender_tagging_index_ranges.d.ts.map +1 -0
- package/dest/tagging/persist_sender_tagging_index_ranges.js +42 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +56 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +163 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +3 -3
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/dest/tagging/reconcile_tagging_index_ranges.d.ts +36 -0
- package/dest/tagging/reconcile_tagging_index_ranges.d.ts.map +1 -0
- package/dest/tagging/reconcile_tagging_index_ranges.js +74 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +16 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/{sync → sender_sync}/sync_sender_tagging_indexes.js +35 -34
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +17 -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 +60 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +19 -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 +72 -0
- package/package.json +31 -19
- package/src/bin/check_oracle_version.ts +42 -31
- package/src/bin/index.ts +1 -0
- package/src/block_synchronizer/block_stream_source.ts +81 -0
- package/src/block_synchronizer/block_synchronizer.ts +123 -48
- package/src/config/index.ts +21 -1
- 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 +431 -161
- package/src/contract_function_simulator/ephemeral_array_service.ts +110 -0
- package/src/contract_function_simulator/execution_note_cache.ts +44 -25
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +19 -18
- package/src/contract_function_simulator/index.ts +4 -1
- package/src/contract_function_simulator/noir-structs/bounded_vec.ts +55 -0
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +15 -10
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +36 -3
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +2 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +6 -11
- package/src/contract_function_simulator/noir-structs/option.ts +69 -0
- package/src/contract_function_simulator/noir-structs/utility_context.ts +6 -25
- package/src/contract_function_simulator/oracle/interfaces.ts +93 -70
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +13 -13
- package/src/contract_function_simulator/oracle/oracle.ts +567 -461
- package/src/contract_function_simulator/oracle/oracle_registry.ts +904 -0
- package/src/contract_function_simulator/oracle/private_execution.ts +5 -73
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +215 -239
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +668 -261
- package/src/contract_function_simulator/pick_notes.ts +22 -3
- package/src/contract_function_simulator/proxied_contract_data_source.ts +47 -70
- package/src/contract_logging.ts +52 -0
- package/src/contract_sync/contract_sync_service.ts +189 -0
- package/src/contract_sync/helpers.ts +86 -0
- package/src/debug/pxe_debug_utils.ts +57 -20
- package/src/entrypoints/client/bundle/index.ts +2 -0
- package/src/entrypoints/client/bundle/utils.ts +31 -19
- package/src/entrypoints/client/lazy/index.ts +2 -0
- package/src/entrypoints/client/lazy/utils.ts +33 -21
- package/src/entrypoints/pxe_creation_options.ts +18 -2
- package/src/entrypoints/server/index.ts +5 -1
- package/src/entrypoints/server/utils.ts +46 -45
- package/src/error_enriching.ts +7 -15
- package/src/events/event_service.ts +83 -41
- package/src/events/private_event_filter_validator.ts +24 -6
- package/src/hooks/authorize_utility_call.ts +44 -0
- package/src/hooks/execution_hooks.ts +48 -0
- package/src/hooks/index.ts +7 -0
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +181 -313
- package/src/messages/message_context_service.ts +45 -0
- package/src/notes/note_service.ts +140 -110
- package/src/notes_filter.ts +24 -0
- package/src/oracle_version.ts +20 -9
- package/src/private_kernel/batch_planner.ts +169 -0
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +2 -2
- package/src/private_kernel/hints/{build_private_kernel_reset_private_inputs.ts → private_kernel_reset_private_inputs_builder.ts} +197 -139
- package/src/private_kernel/hints/test_utils.ts +318 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +262 -96
- package/src/private_kernel/private_kernel_oracle.ts +129 -39
- package/src/pxe.ts +552 -310
- package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +16 -16
- package/src/storage/address_store/index.ts +1 -0
- package/src/storage/{anchor_block_data_provider/anchor_block_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -2
- package/src/storage/anchor_block_store/index.ts +1 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/AddressStore.json +22 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/AnchorBlockStore.json +3 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/CapsuleStore.json +16 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/ContractStore.json +28 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/KeyStore.json +52 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/L2TipsKVStore.json +46 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/NoteStore.json +36 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/PrivateEventStore.json +44 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/RecipientTaggingStore.json +18 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderAddressBookStore.json +16 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/SenderTaggingStore.json +22 -0
- package/src/storage/backwards_compatibility_tests/__snapshots__/opened_stores.json +97 -0
- package/src/storage/backwards_compatibility_tests/kv_store_snapshot.ts +122 -0
- package/src/storage/backwards_compatibility_tests/schema_tests.ts +712 -0
- package/src/storage/backwards_compatibility_tests/store_spy.ts +73 -0
- package/src/storage/capsule_store/capsule_service.ts +90 -0
- package/src/storage/capsule_store/capsule_store.ts +333 -0
- package/src/storage/capsule_store/index.ts +2 -0
- package/src/storage/contract_store/contract_store.ts +408 -0
- package/src/storage/contract_store/index.ts +1 -0
- package/src/storage/index.ts +7 -7
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/index.ts +2 -0
- package/src/storage/note_store/note_store.ts +415 -0
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/open_pxe_stores.ts +49 -0
- package/src/storage/private_event_store/private_event_store.ts +388 -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 +476 -0
- package/src/tagging/constants.ts +10 -3
- package/src/tagging/get_all_logs_by_tags.ts +120 -0
- package/src/tagging/index.ts +20 -4
- package/src/tagging/persist_sender_tagging_index_ranges.ts +57 -0
- package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +240 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +4 -4
- package/src/tagging/reconcile_tagging_index_ranges.ts +102 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +134 -0
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +66 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
- package/dest/contract_function_simulator/proxied_node.d.ts +0 -9
- package/dest/contract_function_simulator/proxied_node.d.ts.map +0 -1
- package/dest/contract_function_simulator/proxied_node.js +0 -27
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +0 -28
- package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
- package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
- package/dest/public_storage/public_storage_service.d.ts +0 -24
- package/dest/public_storage/public_storage_service.d.ts.map +0 -1
- package/dest/public_storage/public_storage_service.js +0 -26
- package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -11
- 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/anchor_block_data_provider/anchor_block_data_provider.d.ts +0 -9
- package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.d.ts.map +0 -1
- package/dest/storage/anchor_block_data_provider/anchor_block_data_provider.js +0 -19
- package/dest/storage/anchor_block_data_provider/index.d.ts +0 -2
- package/dest/storage/anchor_block_data_provider/index.d.ts.map +0 -1
- package/dest/storage/anchor_block_data_provider/index.js +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -57
- 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 -146
- 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 -66
- 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 -224
- 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/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_data_provider.d.ts +0 -84
- 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 -322
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -51
- 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 -115
- package/dest/storage/tagging_data_provider/index.d.ts +0 -3
- package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.js +0 -2
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts +0 -31
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/recipient_tagging_data_provider.js +0 -65
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts +0 -67
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/sender_tagging_data_provider.js +0 -196
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +0 -14
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +0 -99
- package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts +0 -21
- package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/new_recipient_tagging_data_provider.js +0 -42
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +0 -14
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +0 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +0 -29
- package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts +0 -21
- package/dest/tagging/sync/sync_sender_tagging_indexes.d.ts.map +0 -1
- package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts +0 -11
- package/dest/tagging/sync/utils/get_status_change_of_pending.d.ts.map +0 -1
- package/dest/tagging/sync/utils/get_status_change_of_pending.js +0 -32
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts +0 -18
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.d.ts.map +0 -1
- package/dest/tagging/sync/utils/load_and_store_new_tagging_indexes.js +0 -55
- package/dest/tagging/utils.d.ts +0 -18
- package/dest/tagging/utils.d.ts.map +0 -1
- package/dest/tagging/utils.js +0 -25
- package/dest/tree_membership/tree_membership_service.d.ts +0 -52
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -84
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
- package/src/public_storage/public_storage_service.ts +0 -33
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/anchor_block_data_provider/index.ts +0 -1
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -179
- package/src/storage/capsule_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/contract_data_provider.ts +0 -319
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/note_data_provider/index.ts +0 -2
- package/src/storage/note_data_provider/note_data_provider.ts +0 -412
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -162
- package/src/storage/tagging_data_provider/index.ts +0 -2
- package/src/storage/tagging_data_provider/recipient_tagging_data_provider.ts +0 -86
- package/src/storage/tagging_data_provider/sender_tagging_data_provider.ts +0 -244
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +0 -129
- package/src/tagging/recipient_sync/new_recipient_tagging_data_provider.ts +0 -53
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +0 -43
- package/src/tagging/sync/sync_sender_tagging_indexes.ts +0 -112
- package/src/tagging/sync/utils/get_status_change_of_pending.ts +0 -44
- package/src/tagging/sync/utils/load_and_store_new_tagging_indexes.ts +0 -72
- package/src/tagging/utils.ts +0 -32
- package/src/tree_membership/tree_membership_service.ts +0 -112
- /package/dest/storage/{contract_data_provider → contract_store}/private_functions_tree.js +0 -0
- /package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +0 -0
package/src/pxe.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
5
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
7
|
import { KeyStore } from '@aztec/key-store';
|
|
7
8
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
8
|
-
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
9
9
|
import { type ProtocolContractsProvider, protocolContractNames } from '@aztec/protocol-contracts';
|
|
10
10
|
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
11
11
|
import {
|
|
@@ -17,16 +17,15 @@ import {
|
|
|
17
17
|
} from '@aztec/stdlib/abi';
|
|
18
18
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
19
19
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
|
+
import { GENESIS_BLOCK_HEADER_HASH, type L2TipsProvider } from '@aztec/stdlib/block';
|
|
20
21
|
import {
|
|
21
22
|
CompleteAddress,
|
|
22
|
-
type ContractClassWithId,
|
|
23
23
|
type ContractInstanceWithAddress,
|
|
24
24
|
type PartialAddress,
|
|
25
25
|
computeContractAddressFromInstance,
|
|
26
26
|
getContractClassFromArtifact,
|
|
27
27
|
} from '@aztec/stdlib/contract';
|
|
28
28
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
29
|
-
import { computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
30
29
|
import type { AztecNode, PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
|
|
31
30
|
import type {
|
|
32
31
|
PrivateExecutionStep,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -47,41 +47,137 @@ import {
|
|
|
47
47
|
TxProfileResult,
|
|
48
48
|
TxProvingResult,
|
|
49
49
|
TxSimulationResult,
|
|
50
|
-
|
|
50
|
+
UtilityExecutionResult,
|
|
51
51
|
} from '@aztec/stdlib/tx';
|
|
52
52
|
|
|
53
53
|
import { inspect } from 'util';
|
|
54
54
|
|
|
55
55
|
import { BlockSynchronizer } from './block_synchronizer/index.js';
|
|
56
56
|
import type { PXEConfig } from './config/index.js';
|
|
57
|
+
import { BenchmarkedNodeFactory } from './contract_function_simulator/benchmarked_node.js';
|
|
57
58
|
import {
|
|
58
59
|
ContractFunctionSimulator,
|
|
59
60
|
generateSimulatedProvingResult,
|
|
60
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
62
|
+
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { displayDebugLogs } from './contract_logging.js';
|
|
64
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
65
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
63
66
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
64
67
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
65
68
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
69
|
+
import type { ExecutionHooks } from './hooks/index.js';
|
|
70
|
+
import { JobCoordinator } from './job_coordinator/job_coordinator.js';
|
|
71
|
+
import { MessageContextService } from './messages/message_context_service.js';
|
|
66
72
|
import {
|
|
67
73
|
PrivateKernelExecutionProver,
|
|
68
74
|
type PrivateKernelExecutionProverConfig,
|
|
69
75
|
} from './private_kernel/private_kernel_execution_prover.js';
|
|
70
|
-
import {
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
import {
|
|
76
|
-
import {
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
76
|
+
import { PrivateKernelOracle } from './private_kernel/private_kernel_oracle.js';
|
|
77
|
+
import { AddressStore } from './storage/address_store/address_store.js';
|
|
78
|
+
import { AnchorBlockStore } from './storage/anchor_block_store/anchor_block_store.js';
|
|
79
|
+
import { CapsuleStore } from './storage/capsule_store/capsule_store.js';
|
|
80
|
+
import { ContractStore } from './storage/contract_store/contract_store.js';
|
|
81
|
+
import { NoteStore } from './storage/note_store/note_store.js';
|
|
82
|
+
import { openPxeStores } from './storage/open_pxe_stores.js';
|
|
83
|
+
import { PrivateEventStore } from './storage/private_event_store/private_event_store.js';
|
|
84
|
+
import { RecipientTaggingStore } from './storage/tagging_store/recipient_tagging_store.js';
|
|
85
|
+
import { SenderAddressBookStore } from './storage/tagging_store/sender_address_book_store.js';
|
|
86
|
+
import { SenderTaggingStore } from './storage/tagging_store/sender_tagging_store.js';
|
|
87
|
+
import { persistSenderTaggingIndexRangesForTx } from './tagging/index.js';
|
|
79
88
|
|
|
80
89
|
export type PackedPrivateEvent = InTx & {
|
|
81
90
|
packedEvent: Fr[];
|
|
82
91
|
eventSelector: EventSelector;
|
|
83
92
|
};
|
|
84
93
|
|
|
94
|
+
/** Options for PXE.proveTx. */
|
|
95
|
+
export type ProveTxOpts = {
|
|
96
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
97
|
+
scopes: AztecAddress[];
|
|
98
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
99
|
+
senderForTags?: AztecAddress;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Options for PXE.profileTx. */
|
|
103
|
+
export type ProfileTxOpts = {
|
|
104
|
+
/** The profiling mode to use. */
|
|
105
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
106
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
107
|
+
skipProofGeneration?: boolean;
|
|
108
|
+
/** Addresses whose private state and keys are accessible during private execution. */
|
|
109
|
+
scopes: AztecAddress[];
|
|
110
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
111
|
+
senderForTags?: AztecAddress;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Options for PXE.simulateTx. */
|
|
115
|
+
export type SimulateTxOpts = {
|
|
116
|
+
/** Whether to simulate the public part of the transaction. */
|
|
117
|
+
simulatePublic: boolean;
|
|
118
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
119
|
+
skipTxValidation?: boolean;
|
|
120
|
+
/** If false, fees are enforced. */
|
|
121
|
+
skipFeeEnforcement?: boolean;
|
|
122
|
+
/** If true, kernel logic is emulated in TS for simulation */
|
|
123
|
+
skipKernels?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Pre-simulation overrides applied to the ephemeral fork and contract DB. Bundles publicStorage
|
|
126
|
+
* writes (no skipKernels required) and per-address (instance, artifact?) overrides used by both
|
|
127
|
+
* AVM-side public dispatch and PXE-side ACIR private dispatch (requires skipKernels: true).
|
|
128
|
+
*/
|
|
129
|
+
overrides?: SimulationOverrides;
|
|
130
|
+
/** Addresses whose private state and keys are accessible during private execution */
|
|
131
|
+
scopes: AztecAddress[];
|
|
132
|
+
/** Sender address used to derive discovery tags for private messages (notes, events, logs) this tx emits. */
|
|
133
|
+
senderForTags?: AztecAddress;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** Options for PXE.executeUtility. */
|
|
137
|
+
export type ExecuteUtilityOpts = {
|
|
138
|
+
/** The authentication witnesses required for the function call. */
|
|
139
|
+
authwits?: AuthWitness[];
|
|
140
|
+
/** The accounts whose notes we can access in this call */
|
|
141
|
+
scopes: AztecAddress[];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Supplies the set of "nice to have" contracts that every PXE preloads regardless of which wallet
|
|
146
|
+
* drives it. Today this is just the standard multi-call entrypoint: the SDK's self-paid account
|
|
147
|
+
* deploy flow ({@link DeployAccountMethod} with `from = NO_FROM`) routes its payload through it, so a
|
|
148
|
+
* PXE that did not register it would fail contract sync with an opaque "no contract instance" error.
|
|
149
|
+
*
|
|
150
|
+
* Returning a list keeps this extensible: a wallet may supply its own provider that preloads
|
|
151
|
+
* additional contracts. Injected the same way as {@link ProtocolContractsProvider} so the PXE never
|
|
152
|
+
* statically imports the bundled artifacts, keeping the bundle/lazy split intact.
|
|
153
|
+
*/
|
|
154
|
+
export type PreloadedContractsProvider = {
|
|
155
|
+
/** Returns the contract instances and artifacts the PXE should preload on startup. */
|
|
156
|
+
getPreloadedContracts: () => Promise<Array<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>>;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** Args for PXE.create. */
|
|
160
|
+
export type PXECreateArgs = {
|
|
161
|
+
/** The Aztec node to connect to. */
|
|
162
|
+
node: AztecNode;
|
|
163
|
+
/** The key-value store for persisting PXE state. */
|
|
164
|
+
store: AztecAsyncKVStore;
|
|
165
|
+
/** The prover for generating private kernel proofs. */
|
|
166
|
+
proofCreator: PrivateKernelProver;
|
|
167
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
168
|
+
simulator: CircuitSimulator;
|
|
169
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
170
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
171
|
+
/** Provider for the "nice to have" contracts the PXE preloads. */
|
|
172
|
+
preloadedContractsProvider: PreloadedContractsProvider;
|
|
173
|
+
/** PXE configuration options. */
|
|
174
|
+
config: PXEConfig;
|
|
175
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
176
|
+
loggerOrSuffix?: string | Logger;
|
|
177
|
+
/** Optional hooks to observe and influence contract execution. */
|
|
178
|
+
hooks?: ExecutionHooks;
|
|
179
|
+
};
|
|
180
|
+
|
|
85
181
|
/**
|
|
86
182
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
87
183
|
* manage private state of users.
|
|
@@ -89,23 +185,32 @@ export type PackedPrivateEvent = InTx & {
|
|
|
89
185
|
export class PXE {
|
|
90
186
|
private constructor(
|
|
91
187
|
private node: AztecNode,
|
|
188
|
+
private db: AztecAsyncKVStore,
|
|
92
189
|
private blockStateSynchronizer: BlockSynchronizer,
|
|
93
190
|
private keyStore: KeyStore,
|
|
94
|
-
private
|
|
95
|
-
private
|
|
96
|
-
private
|
|
97
|
-
private
|
|
98
|
-
private
|
|
99
|
-
private
|
|
100
|
-
private
|
|
101
|
-
private
|
|
191
|
+
private contractStore: ContractStore,
|
|
192
|
+
private noteStore: NoteStore,
|
|
193
|
+
private capsuleStore: CapsuleStore,
|
|
194
|
+
private anchorBlockStore: AnchorBlockStore,
|
|
195
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
196
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
197
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
198
|
+
private addressStore: AddressStore,
|
|
199
|
+
private privateEventStore: PrivateEventStore,
|
|
200
|
+
private contractSyncService: ContractSyncService,
|
|
201
|
+
private messageContextService: MessageContextService,
|
|
202
|
+
private l2TipsStore: L2TipsProvider,
|
|
102
203
|
private simulator: CircuitSimulator,
|
|
103
204
|
private proverEnabled: boolean,
|
|
205
|
+
private autoSync: boolean,
|
|
104
206
|
private proofCreator: PrivateKernelProver,
|
|
105
207
|
private protocolContractsProvider: ProtocolContractsProvider,
|
|
208
|
+
private preloadedContractsProvider: PreloadedContractsProvider,
|
|
106
209
|
private log: Logger,
|
|
107
210
|
private jobQueue: SerialQueue,
|
|
211
|
+
private jobCoordinator: JobCoordinator,
|
|
108
212
|
public debug: PXEDebugUtils,
|
|
213
|
+
private hooks: ExecutionHooks | undefined,
|
|
109
214
|
) {}
|
|
110
215
|
|
|
111
216
|
/**
|
|
@@ -115,72 +220,123 @@ export class PXE {
|
|
|
115
220
|
*
|
|
116
221
|
* @returns A promise that resolves PXE is ready to be used.
|
|
117
222
|
*/
|
|
118
|
-
public static async create(
|
|
119
|
-
node
|
|
120
|
-
store
|
|
121
|
-
proofCreator
|
|
122
|
-
simulator
|
|
123
|
-
protocolContractsProvider
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
223
|
+
public static async create({
|
|
224
|
+
node,
|
|
225
|
+
store,
|
|
226
|
+
proofCreator,
|
|
227
|
+
simulator,
|
|
228
|
+
protocolContractsProvider,
|
|
229
|
+
preloadedContractsProvider,
|
|
230
|
+
config,
|
|
231
|
+
loggerOrSuffix,
|
|
232
|
+
hooks,
|
|
233
|
+
}: PXECreateArgs) {
|
|
234
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
235
|
+
const bindings: LoggerBindings | undefined =
|
|
236
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
237
|
+
|
|
127
238
|
const log =
|
|
128
239
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
129
240
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
130
241
|
: loggerOrSuffix;
|
|
131
242
|
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
const
|
|
243
|
+
const info = await node.getNodeInfo();
|
|
244
|
+
|
|
245
|
+
// Source the genesis block hash from the node so PXE's L2BlockStream agrees with the node's
|
|
246
|
+
// archiver on the dynamic initial header hash. Without this the tip store would fall back to
|
|
247
|
+
// the static `GENESIS_BLOCK_HEADER_HASH` constant, which only matches deployments with the
|
|
248
|
+
// default empty genesis (timestamp 0, no prefilled public data) and diverges otherwise — the
|
|
249
|
+
// sync at block 0 would then get stuck in `areBlockHashesEqualAt` and abort. If the node does
|
|
250
|
+
// not return a genesis block (older node or test fixture) we fall back to the static constant.
|
|
251
|
+
const initialBlockHash = (await node.getBlock(BlockNumber.ZERO))?.hash ?? GENESIS_BLOCK_HEADER_HASH;
|
|
252
|
+
|
|
253
|
+
const proverEnabled = config.proverEnabled !== undefined ? config.proverEnabled : info.realProofs;
|
|
254
|
+
const {
|
|
255
|
+
addressStore,
|
|
256
|
+
privateEventStore,
|
|
257
|
+
contractStore,
|
|
258
|
+
noteStore,
|
|
259
|
+
anchorBlockStore,
|
|
260
|
+
senderTaggingStore,
|
|
261
|
+
senderAddressBookStore,
|
|
262
|
+
recipientTaggingStore,
|
|
263
|
+
capsuleStore,
|
|
264
|
+
keyStore,
|
|
265
|
+
l2TipsStore,
|
|
266
|
+
} = openPxeStores(store, initialBlockHash);
|
|
267
|
+
const contractSyncService = new ContractSyncService(
|
|
268
|
+
node,
|
|
269
|
+
contractStore,
|
|
270
|
+
noteStore,
|
|
271
|
+
createLogger('pxe:contract_sync', bindings),
|
|
272
|
+
);
|
|
273
|
+
const messageContextService = new MessageContextService(node);
|
|
274
|
+
|
|
143
275
|
const synchronizer = new BlockSynchronizer(
|
|
144
276
|
node,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
277
|
+
store,
|
|
278
|
+
anchorBlockStore,
|
|
279
|
+
noteStore,
|
|
280
|
+
privateEventStore,
|
|
281
|
+
l2TipsStore,
|
|
282
|
+
contractSyncService,
|
|
149
283
|
config,
|
|
150
|
-
|
|
284
|
+
bindings,
|
|
151
285
|
);
|
|
152
286
|
|
|
153
|
-
const
|
|
287
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
288
|
+
jobCoordinator.registerStores([
|
|
289
|
+
capsuleStore,
|
|
290
|
+
senderTaggingStore,
|
|
291
|
+
recipientTaggingStore,
|
|
292
|
+
privateEventStore,
|
|
293
|
+
noteStore,
|
|
294
|
+
contractSyncService,
|
|
295
|
+
]);
|
|
296
|
+
|
|
297
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
154
298
|
|
|
155
299
|
const jobQueue = new SerialQueue();
|
|
156
300
|
|
|
157
301
|
const pxe = new PXE(
|
|
158
302
|
node,
|
|
303
|
+
store,
|
|
159
304
|
synchronizer,
|
|
160
305
|
keyStore,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
306
|
+
contractStore,
|
|
307
|
+
noteStore,
|
|
308
|
+
capsuleStore,
|
|
309
|
+
anchorBlockStore,
|
|
310
|
+
senderTaggingStore,
|
|
311
|
+
senderAddressBookStore,
|
|
312
|
+
recipientTaggingStore,
|
|
313
|
+
addressStore,
|
|
314
|
+
privateEventStore,
|
|
315
|
+
contractSyncService,
|
|
316
|
+
messageContextService,
|
|
317
|
+
l2TipsStore,
|
|
169
318
|
simulator,
|
|
170
319
|
proverEnabled,
|
|
320
|
+
config.autoSync,
|
|
171
321
|
proofCreator,
|
|
172
322
|
protocolContractsProvider,
|
|
323
|
+
preloadedContractsProvider,
|
|
173
324
|
log,
|
|
174
325
|
jobQueue,
|
|
326
|
+
jobCoordinator,
|
|
175
327
|
debugUtils,
|
|
328
|
+
hooks,
|
|
176
329
|
);
|
|
177
330
|
|
|
178
|
-
debugUtils.
|
|
331
|
+
debugUtils.setPXEHelpers(
|
|
332
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
333
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
334
|
+
pxe.#executeUtility.bind(pxe),
|
|
335
|
+
);
|
|
179
336
|
|
|
180
337
|
pxe.jobQueue.start();
|
|
181
338
|
|
|
182
|
-
await pxe.#registerProtocolContracts();
|
|
183
|
-
const info = await node.getNodeInfo();
|
|
339
|
+
await Promise.all([pxe.#registerProtocolContracts(), pxe.#registerPreloadedContracts()]);
|
|
184
340
|
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
185
341
|
return pxe;
|
|
186
342
|
}
|
|
@@ -188,24 +344,25 @@ export class PXE {
|
|
|
188
344
|
// Internal methods
|
|
189
345
|
|
|
190
346
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
this.
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
203
|
-
this.
|
|
204
|
-
this.
|
|
205
|
-
this.
|
|
206
|
-
this.
|
|
207
|
-
this.
|
|
208
|
-
|
|
347
|
+
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
348
|
+
|
|
349
|
+
return new ContractFunctionSimulator({
|
|
350
|
+
contractStore: proxyContractStore,
|
|
351
|
+
noteStore: this.noteStore,
|
|
352
|
+
keyStore: this.keyStore,
|
|
353
|
+
addressStore: this.addressStore,
|
|
354
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
355
|
+
l2TipsStore: this.l2TipsStore,
|
|
356
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
357
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
358
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
359
|
+
capsuleStore: this.capsuleStore,
|
|
360
|
+
privateEventStore: this.privateEventStore,
|
|
361
|
+
simulator: this.simulator,
|
|
362
|
+
contractSyncService: this.contractSyncService,
|
|
363
|
+
messageContextService: this.messageContextService,
|
|
364
|
+
hooks: this.hooks,
|
|
365
|
+
});
|
|
209
366
|
}
|
|
210
367
|
|
|
211
368
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -228,7 +385,7 @@ export class PXE {
|
|
|
228
385
|
*
|
|
229
386
|
* Useful for tasks that cannot run concurrently, such as contract function simulation.
|
|
230
387
|
*/
|
|
231
|
-
#putInJobQueue<T>(fn: () => Promise<T>): Promise<T> {
|
|
388
|
+
#putInJobQueue<T>(fn: (jobId: string) => Promise<T>): Promise<T> {
|
|
232
389
|
// TODO(#12636): relax the conditions under which we forbid concurrency.
|
|
233
390
|
if (this.jobQueue.length() != 0) {
|
|
234
391
|
this.log.warn(
|
|
@@ -236,88 +393,125 @@ export class PXE {
|
|
|
236
393
|
);
|
|
237
394
|
}
|
|
238
395
|
|
|
239
|
-
return this.jobQueue.put(
|
|
396
|
+
return this.jobQueue.put(async () => {
|
|
397
|
+
const jobId = this.jobCoordinator.beginJob();
|
|
398
|
+
this.log.verbose(`Beginning job ${jobId}`);
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
const result = await fn(jobId);
|
|
402
|
+
this.log.verbose(`Committing job ${jobId}`);
|
|
403
|
+
|
|
404
|
+
await this.jobCoordinator.commitJob(jobId);
|
|
405
|
+
return result;
|
|
406
|
+
} catch (err) {
|
|
407
|
+
this.log.verbose(`Aborting job ${jobId}`);
|
|
408
|
+
await this.jobCoordinator.abortJob(jobId);
|
|
409
|
+
throw err;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
240
412
|
}
|
|
241
413
|
|
|
242
414
|
async #registerProtocolContracts() {
|
|
243
|
-
const registered
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
415
|
+
const registered = Object.fromEntries(
|
|
416
|
+
await Promise.all(
|
|
417
|
+
protocolContractNames.map(async name => {
|
|
418
|
+
const { address, instance, artifact } =
|
|
419
|
+
await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
420
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
421
|
+
await this.contractStore.addContractInstance(instance);
|
|
422
|
+
return [name, address.toString()] as const;
|
|
423
|
+
}),
|
|
424
|
+
),
|
|
425
|
+
);
|
|
251
426
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
252
427
|
}
|
|
253
428
|
|
|
254
|
-
async #
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
async #isContractInitialized(address: AztecAddress): Promise<boolean> {
|
|
263
|
-
const initNullifier = await siloNullifier(address, address.toField());
|
|
264
|
-
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
|
|
429
|
+
async #registerPreloadedContracts() {
|
|
430
|
+
const contracts = await this.preloadedContractsProvider.getPreloadedContracts();
|
|
431
|
+
await Promise.all(contracts.map(({ instance, artifact }) => this.registerContract({ instance, artifact })));
|
|
432
|
+
this.log.verbose(`Registered preloaded contracts in pxe`, {
|
|
433
|
+
contracts: contracts.map(({ instance }) => instance.address.toString()),
|
|
434
|
+
});
|
|
265
435
|
}
|
|
266
436
|
|
|
267
437
|
// Executes the entrypoint private function, as well as all nested private
|
|
268
438
|
// functions that might arise.
|
|
269
|
-
async #executePrivate(
|
|
270
|
-
contractFunctionSimulator
|
|
271
|
-
txRequest
|
|
272
|
-
|
|
273
|
-
|
|
439
|
+
async #executePrivate({
|
|
440
|
+
contractFunctionSimulator,
|
|
441
|
+
txRequest,
|
|
442
|
+
anchorBlockHeader,
|
|
443
|
+
scopes,
|
|
444
|
+
jobId,
|
|
445
|
+
senderForTags,
|
|
446
|
+
}: {
|
|
447
|
+
contractFunctionSimulator: ContractFunctionSimulator;
|
|
448
|
+
txRequest: TxExecutionRequest;
|
|
449
|
+
anchorBlockHeader: BlockHeader;
|
|
450
|
+
scopes: AztecAddress[];
|
|
451
|
+
jobId: string;
|
|
452
|
+
senderForTags?: AztecAddress;
|
|
453
|
+
}): Promise<PrivateExecutionResult> {
|
|
274
454
|
const { origin: contractAddress, functionSelector } = txRequest;
|
|
275
455
|
|
|
276
456
|
try {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const result = await contractFunctionSimulator.run(
|
|
280
|
-
txRequest,
|
|
457
|
+
await this.contractSyncService.ensureContractSynced(
|
|
281
458
|
contractAddress,
|
|
282
459
|
functionSelector,
|
|
283
|
-
|
|
460
|
+
(privateSyncCall, execScopes) =>
|
|
461
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
284
462
|
anchorBlockHeader,
|
|
285
|
-
|
|
286
|
-
// contract entrypoint
|
|
287
|
-
undefined, // senderForTags
|
|
463
|
+
jobId,
|
|
288
464
|
scopes,
|
|
289
465
|
);
|
|
466
|
+
|
|
467
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
468
|
+
contractAddress,
|
|
469
|
+
selector: functionSelector,
|
|
470
|
+
anchorBlockHeader,
|
|
471
|
+
scopes,
|
|
472
|
+
jobId,
|
|
473
|
+
senderForTags,
|
|
474
|
+
});
|
|
290
475
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
291
476
|
return result;
|
|
292
477
|
} catch (err) {
|
|
293
478
|
if (err instanceof SimulationError) {
|
|
294
|
-
await enrichSimulationError(err, this.
|
|
479
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
295
480
|
}
|
|
296
481
|
throw err;
|
|
297
482
|
}
|
|
298
483
|
}
|
|
299
484
|
|
|
300
485
|
/**
|
|
301
|
-
*
|
|
486
|
+
* Execute a utility function call on the given contract.
|
|
302
487
|
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
303
488
|
* @param call - The function call to execute.
|
|
304
489
|
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
305
490
|
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
306
491
|
* accounts if not specified.
|
|
307
|
-
* @
|
|
492
|
+
* @param jobId - The job ID for staged writes.
|
|
493
|
+
* @returns The execution result containing the outputs of the utility function.
|
|
308
494
|
*/
|
|
309
|
-
async #
|
|
495
|
+
async #executeUtility(
|
|
310
496
|
contractFunctionSimulator: ContractFunctionSimulator,
|
|
311
497
|
call: FunctionCall,
|
|
312
|
-
authWitnesses
|
|
313
|
-
scopes
|
|
498
|
+
authWitnesses: AuthWitness[] | undefined,
|
|
499
|
+
scopes: AztecAddress[],
|
|
500
|
+
jobId: string,
|
|
314
501
|
) {
|
|
315
502
|
try {
|
|
316
|
-
const anchorBlockHeader = await this.
|
|
317
|
-
|
|
503
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
504
|
+
const { result, offchainEffects } = await contractFunctionSimulator.runUtility(
|
|
505
|
+
call,
|
|
506
|
+
authWitnesses ?? [],
|
|
507
|
+
anchorBlockHeader,
|
|
508
|
+
scopes,
|
|
509
|
+
jobId,
|
|
510
|
+
);
|
|
511
|
+
return { result, offchainEffects };
|
|
318
512
|
} catch (err) {
|
|
319
513
|
if (err instanceof SimulationError) {
|
|
320
|
-
await enrichSimulationError(err, this.
|
|
514
|
+
await enrichSimulationError(err, this.contractStore, this.log);
|
|
321
515
|
}
|
|
322
516
|
throw err;
|
|
323
517
|
}
|
|
@@ -329,11 +523,11 @@ export class PXE {
|
|
|
329
523
|
* It can also be used for estimating gas in the future.
|
|
330
524
|
* @param tx - The transaction to be simulated.
|
|
331
525
|
*/
|
|
332
|
-
async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean) {
|
|
526
|
+
async #simulatePublicCalls(tx: Tx, skipFeeEnforcement: boolean, overrides?: SimulationOverrides) {
|
|
333
527
|
// Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
|
|
334
528
|
// Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
|
|
335
529
|
try {
|
|
336
|
-
const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
530
|
+
const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement, overrides);
|
|
337
531
|
if (result.revertReason) {
|
|
338
532
|
throw result.revertReason;
|
|
339
533
|
}
|
|
@@ -341,7 +535,7 @@ export class PXE {
|
|
|
341
535
|
} catch (err) {
|
|
342
536
|
if (err instanceof SimulationError) {
|
|
343
537
|
try {
|
|
344
|
-
await enrichPublicSimulationError(err, this.
|
|
538
|
+
await enrichPublicSimulationError(err, this.contractStore, this.log);
|
|
345
539
|
} catch (enrichErr) {
|
|
346
540
|
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
347
541
|
}
|
|
@@ -365,87 +559,68 @@ export class PXE {
|
|
|
365
559
|
txExecutionRequest: TxExecutionRequest,
|
|
366
560
|
proofCreator: PrivateKernelProver,
|
|
367
561
|
privateExecutionResult: PrivateExecutionResult,
|
|
562
|
+
anchorBlockHeader: BlockHeader,
|
|
368
563
|
config: PrivateKernelExecutionProverConfig,
|
|
369
564
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
370
|
-
const
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.
|
|
375
|
-
|
|
565
|
+
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHeader);
|
|
566
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
567
|
+
kernelOracle,
|
|
568
|
+
proofCreator,
|
|
569
|
+
!this.proverEnabled,
|
|
570
|
+
this.log.getBindings(),
|
|
376
571
|
);
|
|
377
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
378
572
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
379
573
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
380
574
|
}
|
|
381
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Syncs with the node only when `autoSync` is enabled.
|
|
578
|
+
* When `autoSync` is disabled, callers (typically a wallet) are
|
|
579
|
+
* responsible for invoking `pxe.sync()` at the right granularity.
|
|
580
|
+
*/
|
|
581
|
+
async #maybeSync(): Promise<void> {
|
|
582
|
+
if (this.autoSync) {
|
|
583
|
+
await this.blockStateSynchronizer.sync();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
382
587
|
// Public API
|
|
383
588
|
|
|
384
|
-
|
|
385
|
-
|
|
589
|
+
/**
|
|
590
|
+
* Triggers a sync of PXE state with the node, regardless of the `autoSync` config flag. Use this to
|
|
591
|
+
* batch syncs across composite flows when `autoSync` is disabled (e.g. one sync per simulate+send
|
|
592
|
+
* instead of one per inner PXE call). Serialized through the job queue.
|
|
593
|
+
*/
|
|
594
|
+
public sync(): Promise<void> {
|
|
595
|
+
return this.#putInJobQueue(() => this.blockStateSynchronizer.sync());
|
|
386
596
|
}
|
|
387
597
|
|
|
388
598
|
/**
|
|
389
|
-
* Returns the
|
|
390
|
-
* The
|
|
391
|
-
* @remark - it queries the node to check whether the contract class with the given id has been publicly registered.
|
|
392
|
-
* @param id - Identifier of the class.
|
|
393
|
-
* @param includeArtifact - Identifier of the class.
|
|
394
|
-
* @returns - It returns the contract class metadata, with the artifact field being optional, and will only be returned if true is passed in
|
|
395
|
-
* for `includeArtifact`
|
|
396
|
-
* TODO(@spalladino): The PXE actually holds artifacts and not classes, what should we return? Also,
|
|
397
|
-
* should the pxe query the node for contract public info, and merge it with its own definitions?
|
|
398
|
-
* TODO(@spalladino): This method is strictly needed to decide whether to publicly register a class or not
|
|
399
|
-
* during a public deployment. We probably want a nicer and more general API for this, but it'll have to
|
|
400
|
-
* do for the time being.
|
|
599
|
+
* Returns the block header up to which the PXE has synced.
|
|
600
|
+
* @returns The synced block header
|
|
401
601
|
*/
|
|
402
|
-
public
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
isContractClassPubliclyRegistered: boolean;
|
|
408
|
-
artifact: ContractArtifact | undefined;
|
|
409
|
-
}> {
|
|
410
|
-
const artifact = await this.contractDataProvider.getContractArtifact(id);
|
|
411
|
-
if (!artifact) {
|
|
412
|
-
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
413
|
-
}
|
|
602
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
603
|
+
return this.#putInJobQueue(() => {
|
|
604
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
605
|
+
});
|
|
606
|
+
}
|
|
414
607
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
610
|
+
* @param address - The contract address.
|
|
611
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
612
|
+
*/
|
|
613
|
+
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
614
|
+
return this.contractStore.getContractInstance(address);
|
|
420
615
|
}
|
|
421
616
|
|
|
422
617
|
/**
|
|
423
|
-
* Returns the contract
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* and whether the contract instance with the given address has been publicly deployed.
|
|
427
|
-
* @remark - it queries the node to check whether the contract instance has been initialized / publicly deployed through a node.
|
|
428
|
-
* This query is not dependent on the PXE.
|
|
429
|
-
* @param address - The address that the contract instance resides at.
|
|
430
|
-
* @returns - It returns the contract metadata
|
|
431
|
-
* TODO(@spalladino): Should we return the public keys in plain as well here?
|
|
618
|
+
* Returns the contract artifact for a given contract class id, if it's registered in the PXE.
|
|
619
|
+
* @param id - Identifier of the contract class.
|
|
620
|
+
* @returns The contract artifact if found, undefined otherwise.
|
|
432
621
|
*/
|
|
433
|
-
public async
|
|
434
|
-
|
|
435
|
-
isContractInitialized: boolean;
|
|
436
|
-
isContractPublished: boolean;
|
|
437
|
-
}> {
|
|
438
|
-
let instance;
|
|
439
|
-
try {
|
|
440
|
-
instance = await this.contractDataProvider.getContractInstance(address);
|
|
441
|
-
} catch {
|
|
442
|
-
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
443
|
-
}
|
|
444
|
-
return {
|
|
445
|
-
contractInstance: instance,
|
|
446
|
-
isContractInitialized: await this.#isContractInitialized(address),
|
|
447
|
-
isContractPublished: await this.#isContractPublished(address),
|
|
448
|
-
};
|
|
622
|
+
public async getContractArtifact(id: Fr): Promise<ContractArtifact | undefined> {
|
|
623
|
+
return await this.contractStore.getContractArtifact(id);
|
|
449
624
|
}
|
|
450
625
|
|
|
451
626
|
/**
|
|
@@ -461,7 +636,7 @@ export class PXE {
|
|
|
461
636
|
public async registerAccount(secretKey: Fr, partialAddress: PartialAddress): Promise<CompleteAddress> {
|
|
462
637
|
const accounts = await this.keyStore.getAccounts();
|
|
463
638
|
const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
|
|
464
|
-
if (accounts.
|
|
639
|
+
if (accounts.some(a => a.equals(accountCompleteAddress.address))) {
|
|
465
640
|
this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
|
|
466
641
|
return accountCompleteAddress;
|
|
467
642
|
} else {
|
|
@@ -469,8 +644,7 @@ export class PXE {
|
|
|
469
644
|
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
470
645
|
}
|
|
471
646
|
|
|
472
|
-
await this.
|
|
473
|
-
await this.noteDataProvider.addScope(accountCompleteAddress.address);
|
|
647
|
+
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
474
648
|
return accountCompleteAddress;
|
|
475
649
|
}
|
|
476
650
|
|
|
@@ -485,16 +659,25 @@ export class PXE {
|
|
|
485
659
|
* TODO: It's strange that we return the address here and I (benesjan) think we should drop the return value.
|
|
486
660
|
*/
|
|
487
661
|
public async registerSender(sender: AztecAddress): Promise<AztecAddress> {
|
|
662
|
+
if (!(await sender.isValid())) {
|
|
663
|
+
throw new Error(
|
|
664
|
+
`Address ${sender} is not valid: it does not correspond to a point on the Grumpkin curve. Cannot register it as a sender.`,
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
488
668
|
const accounts = await this.keyStore.getAccounts();
|
|
489
|
-
if (accounts.
|
|
669
|
+
if (accounts.some(a => a.equals(sender))) {
|
|
490
670
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
491
671
|
return sender;
|
|
492
672
|
}
|
|
493
673
|
|
|
494
|
-
const wasAdded = await this.
|
|
674
|
+
const wasAdded = await this.senderAddressBookStore.addSender(sender);
|
|
495
675
|
|
|
496
676
|
if (wasAdded) {
|
|
497
677
|
this.log.info(`Added sender:\n ${sender.toString()}`);
|
|
678
|
+
// Wipe the entire sync cache: the new sender's tagged logs could contain notes/events for any contract, so
|
|
679
|
+
// all contracts must re-sync to discover them. Queued to avoid wiping while a job is in flight.
|
|
680
|
+
await this.#putInJobQueue(() => Promise.resolve(this.contractSyncService.wipe()));
|
|
498
681
|
} else {
|
|
499
682
|
this.log.info(`Sender:\n "${sender.toString()}"\n already registered.`);
|
|
500
683
|
}
|
|
@@ -507,7 +690,7 @@ export class PXE {
|
|
|
507
690
|
* @returns Senders registered in this PXE.
|
|
508
691
|
*/
|
|
509
692
|
public getSenders(): Promise<AztecAddress[]> {
|
|
510
|
-
return this.
|
|
693
|
+
return this.senderAddressBookStore.getSenders();
|
|
511
694
|
}
|
|
512
695
|
|
|
513
696
|
/**
|
|
@@ -515,7 +698,7 @@ export class PXE {
|
|
|
515
698
|
* @param sender - The address of the sender to remove.
|
|
516
699
|
*/
|
|
517
700
|
public async removeSender(sender: AztecAddress): Promise<void> {
|
|
518
|
-
const wasRemoved = await this.
|
|
701
|
+
const wasRemoved = await this.senderAddressBookStore.removeSender(sender);
|
|
519
702
|
|
|
520
703
|
if (wasRemoved) {
|
|
521
704
|
this.log.info(`Removed sender:\n ${sender.toString()}`);
|
|
@@ -530,7 +713,7 @@ export class PXE {
|
|
|
530
713
|
*/
|
|
531
714
|
public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
|
|
532
715
|
// Get complete addresses of both the recipients and the accounts
|
|
533
|
-
const completeAddresses = await this.
|
|
716
|
+
const completeAddresses = await this.addressStore.getCompleteAddresses();
|
|
534
717
|
// Filter out the addresses not corresponding to accounts
|
|
535
718
|
const accounts = await this.keyStore.getAccounts();
|
|
536
719
|
return completeAddresses.filter(completeAddress =>
|
|
@@ -544,8 +727,7 @@ export class PXE {
|
|
|
544
727
|
* @param artifact - The build artifact for the contract class.
|
|
545
728
|
*/
|
|
546
729
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
547
|
-
const
|
|
548
|
-
await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
|
|
730
|
+
const contractClassId = await this.contractStore.addContractArtifact(artifact);
|
|
549
731
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
550
732
|
}
|
|
551
733
|
|
|
@@ -564,25 +746,27 @@ export class PXE {
|
|
|
564
746
|
if (artifact) {
|
|
565
747
|
// If the user provides an artifact, validate it against the expected class id and register it
|
|
566
748
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
567
|
-
|
|
568
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
749
|
+
if (!contractClass.id.equals(instance.currentContractClassId)) {
|
|
569
750
|
throw new Error(
|
|
570
|
-
`Artifact does not match expected class id (computed ${
|
|
751
|
+
`Artifact does not match expected class id (computed ${contractClass.id} but instance refers to ${instance.currentContractClassId})`,
|
|
571
752
|
);
|
|
572
753
|
}
|
|
573
754
|
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
574
755
|
if (!computedAddress.equals(instance.address)) {
|
|
575
756
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
576
757
|
}
|
|
577
|
-
|
|
758
|
+
|
|
759
|
+
await this.contractStore.addContractArtifact(artifact, contractClass);
|
|
578
760
|
|
|
579
761
|
const publicFunctionSignatures = artifact.functions
|
|
580
762
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
581
763
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
582
|
-
|
|
764
|
+
if (publicFunctionSignatures.length > 0) {
|
|
765
|
+
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
766
|
+
}
|
|
583
767
|
} else {
|
|
584
768
|
// Otherwise, make sure there is an artifact already registered for that class id
|
|
585
|
-
artifact = await this.
|
|
769
|
+
artifact = await this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
586
770
|
if (!artifact) {
|
|
587
771
|
throw new Error(
|
|
588
772
|
`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`,
|
|
@@ -590,7 +774,7 @@ export class PXE {
|
|
|
590
774
|
}
|
|
591
775
|
}
|
|
592
776
|
|
|
593
|
-
await this.
|
|
777
|
+
await this.contractStore.addContractInstance(instance);
|
|
594
778
|
this.log.info(
|
|
595
779
|
`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
|
|
596
780
|
);
|
|
@@ -609,35 +793,32 @@ export class PXE {
|
|
|
609
793
|
// We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
|
|
610
794
|
// class while we're simulating it.
|
|
611
795
|
return this.#putInJobQueue(async () => {
|
|
612
|
-
const currentInstance = await this.
|
|
796
|
+
const currentInstance = await this.contractStore.getContractInstance(contractAddress);
|
|
613
797
|
if (!currentInstance) {
|
|
614
798
|
throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
|
|
615
799
|
}
|
|
616
800
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
617
|
-
await this
|
|
801
|
+
await this.#maybeSync();
|
|
618
802
|
|
|
619
|
-
const header = await this.
|
|
803
|
+
const header = await this.anchorBlockStore.getBlockHeader();
|
|
620
804
|
|
|
621
|
-
const currentClassId = await readCurrentClassId(
|
|
622
|
-
contractAddress,
|
|
623
|
-
currentInstance,
|
|
624
|
-
this.node,
|
|
625
|
-
header.globalVariables.blockNumber,
|
|
626
|
-
header.globalVariables.timestamp,
|
|
627
|
-
);
|
|
805
|
+
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header);
|
|
628
806
|
if (!contractClass.id.equals(currentClassId)) {
|
|
629
807
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
630
808
|
}
|
|
631
809
|
|
|
632
|
-
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
633
|
-
|
|
634
810
|
const publicFunctionSignatures = artifact.functions
|
|
635
811
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
636
812
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
637
|
-
|
|
813
|
+
if (publicFunctionSignatures.length > 0) {
|
|
814
|
+
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
815
|
+
}
|
|
638
816
|
|
|
639
817
|
currentInstance.currentContractClassId = contractClass.id;
|
|
640
|
-
await
|
|
818
|
+
await Promise.all([
|
|
819
|
+
this.contractStore.addContractArtifact(artifact, contractClass),
|
|
820
|
+
this.contractStore.addContractInstance(currentInstance),
|
|
821
|
+
]);
|
|
641
822
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
642
823
|
});
|
|
643
824
|
}
|
|
@@ -647,7 +828,7 @@ export class PXE {
|
|
|
647
828
|
* @returns An array of contracts addresses registered on this PXE.
|
|
648
829
|
*/
|
|
649
830
|
public getContracts(): Promise<AztecAddress[]> {
|
|
650
|
-
return this.
|
|
831
|
+
return this.contractStore.getContractsAddresses();
|
|
651
832
|
}
|
|
652
833
|
|
|
653
834
|
/**
|
|
@@ -655,29 +836,38 @@ export class PXE {
|
|
|
655
836
|
* (where validators prove the public portion).
|
|
656
837
|
*
|
|
657
838
|
* @param txRequest - An authenticated tx request ready for proving
|
|
839
|
+
* @param scopes - Addresses whose private state and keys are accessible during private execution.
|
|
658
840
|
* @returns A result containing the proof and public inputs of the tail circuit.
|
|
659
841
|
* @throws If contract code not found, or public simulation reverts.
|
|
660
842
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
661
843
|
*/
|
|
662
|
-
public proveTx(txRequest: TxExecutionRequest): Promise<TxProvingResult> {
|
|
844
|
+
public proveTx(txRequest: TxExecutionRequest, { scopes, senderForTags }: ProveTxOpts): Promise<TxProvingResult> {
|
|
663
845
|
let privateExecutionResult: PrivateExecutionResult;
|
|
664
846
|
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
665
847
|
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
666
|
-
return this.#putInJobQueue(async
|
|
848
|
+
return this.#putInJobQueue(async jobId => {
|
|
667
849
|
const totalTimer = new Timer();
|
|
668
850
|
try {
|
|
669
851
|
const syncTimer = new Timer();
|
|
670
|
-
await this
|
|
852
|
+
await this.#maybeSync();
|
|
853
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
671
854
|
const syncTime = syncTimer.ms();
|
|
672
855
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
673
|
-
privateExecutionResult = await this.#executePrivate(
|
|
856
|
+
privateExecutionResult = await this.#executePrivate({
|
|
857
|
+
contractFunctionSimulator,
|
|
858
|
+
txRequest,
|
|
859
|
+
anchorBlockHeader,
|
|
860
|
+
scopes,
|
|
861
|
+
jobId,
|
|
862
|
+
senderForTags,
|
|
863
|
+
});
|
|
674
864
|
|
|
675
865
|
const {
|
|
676
866
|
publicInputs,
|
|
677
867
|
chonkProof,
|
|
678
868
|
executionSteps,
|
|
679
869
|
timings: { proving } = {},
|
|
680
|
-
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
870
|
+
} = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, anchorBlockHeader, {
|
|
681
871
|
simulate: false,
|
|
682
872
|
skipFeeEnforcement: false,
|
|
683
873
|
profileMode: 'none',
|
|
@@ -707,23 +897,20 @@ export class PXE {
|
|
|
707
897
|
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls,
|
|
708
898
|
});
|
|
709
899
|
|
|
710
|
-
//
|
|
711
|
-
//
|
|
712
|
-
//
|
|
713
|
-
//
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
} else {
|
|
725
|
-
this.log.debug(`No pre-tags used in the tx`);
|
|
726
|
-
}
|
|
900
|
+
// We keep track of which tagging indices we've used in this tx so that we don't repeat them in future txs
|
|
901
|
+
// (which would link them) without having to rely on this tx being mined (and us seeing the indices being used
|
|
902
|
+
// onchain).
|
|
903
|
+
// Note that this must happen _after_ proving as it requires the proof's public inputs, from which the kernels
|
|
904
|
+
// may have removed some logs due to note-nullifier squashing - this may lead to range of tagging indices we've
|
|
905
|
+
// actually used to being reduced.
|
|
906
|
+
await persistSenderTaggingIndexRangesForTx(
|
|
907
|
+
this.senderTaggingStore,
|
|
908
|
+
privateExecutionResult.entrypoint.taggingIndexRanges,
|
|
909
|
+
publicInputs,
|
|
910
|
+
() => txProvingResult.getTxHash(),
|
|
911
|
+
jobId,
|
|
912
|
+
this.log,
|
|
913
|
+
);
|
|
727
914
|
|
|
728
915
|
return txProvingResult;
|
|
729
916
|
} catch (err: any) {
|
|
@@ -734,20 +921,16 @@ export class PXE {
|
|
|
734
921
|
|
|
735
922
|
/**
|
|
736
923
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
737
|
-
*
|
|
738
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
739
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
740
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
924
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
741
925
|
* @returns A trace of the program execution with gate counts.
|
|
742
926
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
743
927
|
*/
|
|
744
928
|
public profileTx(
|
|
745
929
|
txRequest: TxExecutionRequest,
|
|
746
|
-
profileMode
|
|
747
|
-
skipProofGeneration: boolean = true,
|
|
930
|
+
{ profileMode, skipProofGeneration = true, scopes, senderForTags }: ProfileTxOpts,
|
|
748
931
|
): Promise<TxProfileResult> {
|
|
749
932
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
750
|
-
return this.#putInJobQueue(async
|
|
933
|
+
return this.#putInJobQueue(async jobId => {
|
|
751
934
|
const totalTimer = new Timer();
|
|
752
935
|
try {
|
|
753
936
|
const txInfo = {
|
|
@@ -763,16 +946,25 @@ export class PXE {
|
|
|
763
946
|
txInfo,
|
|
764
947
|
);
|
|
765
948
|
const syncTimer = new Timer();
|
|
766
|
-
await this
|
|
949
|
+
await this.#maybeSync();
|
|
950
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
767
951
|
const syncTime = syncTimer.ms();
|
|
768
952
|
|
|
769
953
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
770
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
954
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
955
|
+
contractFunctionSimulator,
|
|
956
|
+
txRequest,
|
|
957
|
+
anchorBlockHeader,
|
|
958
|
+
scopes,
|
|
959
|
+
jobId,
|
|
960
|
+
senderForTags,
|
|
961
|
+
});
|
|
771
962
|
|
|
772
963
|
const { executionSteps, timings: { proving } = {} } = await this.#prove(
|
|
773
964
|
txRequest,
|
|
774
965
|
this.proofCreator,
|
|
775
966
|
privateExecutionResult,
|
|
967
|
+
anchorBlockHeader,
|
|
776
968
|
{
|
|
777
969
|
simulate: skipProofGeneration,
|
|
778
970
|
skipFeeEnforcement: false,
|
|
@@ -824,12 +1016,7 @@ export class PXE {
|
|
|
824
1016
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
825
1017
|
*
|
|
826
1018
|
*
|
|
827
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
828
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
829
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
830
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
831
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
832
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
1019
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
833
1020
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
834
1021
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
835
1022
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -838,16 +1025,20 @@ export class PXE {
|
|
|
838
1025
|
*/
|
|
839
1026
|
public simulateTx(
|
|
840
1027
|
txRequest: TxExecutionRequest,
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1028
|
+
{
|
|
1029
|
+
simulatePublic,
|
|
1030
|
+
skipTxValidation = false,
|
|
1031
|
+
skipFeeEnforcement = false,
|
|
1032
|
+
skipKernels = true,
|
|
1033
|
+
overrides,
|
|
1034
|
+
scopes,
|
|
1035
|
+
senderForTags,
|
|
1036
|
+
}: SimulateTxOpts,
|
|
846
1037
|
): Promise<TxSimulationResult> {
|
|
847
1038
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
848
1039
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
849
1040
|
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
850
|
-
return this.#putInJobQueue(async
|
|
1041
|
+
return this.#putInJobQueue(async jobId => {
|
|
851
1042
|
try {
|
|
852
1043
|
const totalTimer = new Timer();
|
|
853
1044
|
const txInfo = {
|
|
@@ -863,39 +1054,49 @@ export class PXE {
|
|
|
863
1054
|
txInfo,
|
|
864
1055
|
);
|
|
865
1056
|
const syncTimer = new Timer();
|
|
866
|
-
await this
|
|
1057
|
+
await this.#maybeSync();
|
|
1058
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
867
1059
|
const syncTime = syncTimer.ms();
|
|
868
1060
|
|
|
1061
|
+
if (overrides?.contracts && Object.keys(overrides.contracts).length > 0 && !skipKernels) {
|
|
1062
|
+
throw new Error(
|
|
1063
|
+
'Simulating with overridden contracts is not compatible with kernel execution. Please set skipKernels to true when simulating with overridden contracts.',
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
869
1066
|
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
870
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
871
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
872
|
-
// or not.
|
|
873
|
-
const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
|
|
874
1067
|
|
|
875
1068
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
876
|
-
const privateExecutionResult = await this.#executePrivate(
|
|
1069
|
+
const privateExecutionResult = await this.#executePrivate({
|
|
1070
|
+
contractFunctionSimulator,
|
|
1071
|
+
txRequest,
|
|
1072
|
+
anchorBlockHeader,
|
|
1073
|
+
scopes,
|
|
1074
|
+
jobId,
|
|
1075
|
+
senderForTags,
|
|
1076
|
+
});
|
|
877
1077
|
|
|
878
1078
|
let publicInputs: PrivateKernelTailCircuitPublicInputs | undefined;
|
|
879
1079
|
let executionSteps: PrivateExecutionStep[] = [];
|
|
880
1080
|
|
|
881
1081
|
if (skipKernels) {
|
|
882
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
883
|
-
// can either be the first nullifier in the tx or the protocol nullifier if there are none.
|
|
884
|
-
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO)
|
|
885
|
-
? await computeProtocolNullifier(await txRequest.toTxRequest().hash())
|
|
886
|
-
: privateExecutionResult.firstNullifier;
|
|
887
1082
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
888
1083
|
privateExecutionResult,
|
|
889
|
-
|
|
890
|
-
this.
|
|
1084
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
1085
|
+
this.node,
|
|
891
1086
|
));
|
|
892
1087
|
} else {
|
|
893
1088
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
894
|
-
({ publicInputs, executionSteps } = await this.#prove(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
1089
|
+
({ publicInputs, executionSteps } = await this.#prove(
|
|
1090
|
+
txRequest,
|
|
1091
|
+
this.proofCreator,
|
|
1092
|
+
privateExecutionResult,
|
|
1093
|
+
anchorBlockHeader,
|
|
1094
|
+
{
|
|
1095
|
+
simulate: true,
|
|
1096
|
+
skipFeeEnforcement,
|
|
1097
|
+
profileMode: 'none',
|
|
1098
|
+
},
|
|
1099
|
+
));
|
|
899
1100
|
}
|
|
900
1101
|
|
|
901
1102
|
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
@@ -904,8 +1105,11 @@ export class PXE {
|
|
|
904
1105
|
let publicOutput: PublicSimulationOutput | undefined;
|
|
905
1106
|
if (simulatePublic && publicInputs.forPublic) {
|
|
906
1107
|
const publicSimulationTimer = new Timer();
|
|
907
|
-
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
1108
|
+
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement, overrides);
|
|
908
1109
|
publicSimulationTime = publicSimulationTimer.ms();
|
|
1110
|
+
if (publicOutput?.debugLogs?.length) {
|
|
1111
|
+
await displayDebugLogs(publicOutput.debugLogs, addr => this.contractStore.getDebugContractName(addr));
|
|
1112
|
+
}
|
|
909
1113
|
}
|
|
910
1114
|
|
|
911
1115
|
let validationTime: number | undefined;
|
|
@@ -914,7 +1118,8 @@ export class PXE {
|
|
|
914
1118
|
const validationResult = await this.node.isValidTx(simulatedTx, { isSimulation: true, skipFeeEnforcement });
|
|
915
1119
|
validationTime = validationTimer.ms();
|
|
916
1120
|
if (validationResult.result === 'invalid') {
|
|
917
|
-
|
|
1121
|
+
const reason = validationResult.reason.length > 0 ? ` Reason: ${validationResult.reason.join(', ')}` : '';
|
|
1122
|
+
throw new Error(`The simulated transaction is unable to be added to state and is invalid.${reason}`);
|
|
918
1123
|
}
|
|
919
1124
|
}
|
|
920
1125
|
|
|
@@ -965,38 +1170,50 @@ export class PXE {
|
|
|
965
1170
|
inspect(txRequest),
|
|
966
1171
|
`simulatePublic=${simulatePublic}`,
|
|
967
1172
|
`skipTxValidation=${skipTxValidation}`,
|
|
968
|
-
`scopes=${scopes
|
|
1173
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
969
1174
|
);
|
|
970
1175
|
}
|
|
971
1176
|
});
|
|
972
1177
|
}
|
|
973
1178
|
|
|
974
1179
|
/**
|
|
975
|
-
*
|
|
976
|
-
*
|
|
1180
|
+
* Executes a contract utility function.
|
|
977
1181
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
978
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
979
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
980
|
-
* default to all.
|
|
981
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
982
1182
|
*/
|
|
983
|
-
public
|
|
1183
|
+
public executeUtility(
|
|
984
1184
|
call: FunctionCall,
|
|
985
|
-
authwits
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
1185
|
+
{ authwits, scopes }: ExecuteUtilityOpts = { scopes: [] },
|
|
1186
|
+
): Promise<UtilityExecutionResult> {
|
|
1187
|
+
// We disable concurrent executions since those might execute oracles which read and write to the PXE stores (e.g.
|
|
989
1188
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
990
|
-
// delete the same read value, or reading values that another
|
|
991
|
-
return this.#putInJobQueue(async
|
|
1189
|
+
// delete the same read value, or reading values that another execution is currently modifying).
|
|
1190
|
+
return this.#putInJobQueue(async jobId => {
|
|
992
1191
|
try {
|
|
993
1192
|
const totalTimer = new Timer();
|
|
994
1193
|
const syncTimer = new Timer();
|
|
995
|
-
await this
|
|
1194
|
+
await this.#maybeSync();
|
|
996
1195
|
const syncTime = syncTimer.ms();
|
|
997
1196
|
const functionTimer = new Timer();
|
|
998
1197
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
999
|
-
|
|
1198
|
+
|
|
1199
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1200
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1201
|
+
call.to,
|
|
1202
|
+
call.selector,
|
|
1203
|
+
(privateSyncCall, execScopes) =>
|
|
1204
|
+
this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1205
|
+
anchorBlockHeader,
|
|
1206
|
+
jobId,
|
|
1207
|
+
scopes,
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1210
|
+
const { result: executionResult, offchainEffects } = await this.#executeUtility(
|
|
1211
|
+
contractFunctionSimulator,
|
|
1212
|
+
call,
|
|
1213
|
+
authwits ?? [],
|
|
1214
|
+
scopes,
|
|
1215
|
+
jobId,
|
|
1216
|
+
);
|
|
1000
1217
|
const functionTime = functionTimer.ms();
|
|
1001
1218
|
|
|
1002
1219
|
const totalTime = totalTimer.ms();
|
|
@@ -1011,14 +1228,19 @@ export class PXE {
|
|
|
1011
1228
|
};
|
|
1012
1229
|
|
|
1013
1230
|
const simulationStats = contractFunctionSimulator.getStats();
|
|
1014
|
-
return {
|
|
1231
|
+
return {
|
|
1232
|
+
result: executionResult,
|
|
1233
|
+
offchainEffects,
|
|
1234
|
+
anchorBlockTimestamp: anchorBlockHeader.globalVariables.timestamp,
|
|
1235
|
+
stats: { timings, nodeRPCCalls: simulationStats.nodeRPCCalls },
|
|
1236
|
+
};
|
|
1015
1237
|
} catch (err: any) {
|
|
1016
1238
|
const { to, name, args } = call;
|
|
1017
1239
|
const stringifiedArgs = args.map(arg => arg.toString()).join(', ');
|
|
1018
1240
|
throw this.#contextualizeError(
|
|
1019
1241
|
err,
|
|
1020
|
-
`
|
|
1021
|
-
`scopes=${scopes
|
|
1242
|
+
`executeUtility ${to}:${name}(${stringifiedArgs})`,
|
|
1243
|
+
`scopes=${scopes.map(s => s.toString()).join(', ')}`,
|
|
1022
1244
|
);
|
|
1023
1245
|
}
|
|
1024
1246
|
});
|
|
@@ -1041,23 +1263,43 @@ export class PXE {
|
|
|
1041
1263
|
eventSelector: EventSelector,
|
|
1042
1264
|
filter: PrivateEventFilter,
|
|
1043
1265
|
): Promise<PackedPrivateEvent[]> {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
await this
|
|
1266
|
+
let anchorBlockNumber: BlockNumber;
|
|
1267
|
+
|
|
1268
|
+
await this.#putInJobQueue(async jobId => {
|
|
1269
|
+
await this.#maybeSync();
|
|
1270
|
+
|
|
1271
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1272
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1273
|
+
|
|
1274
|
+
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1275
|
+
|
|
1276
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1277
|
+
filter.contractAddress,
|
|
1278
|
+
null,
|
|
1279
|
+
async (privateSyncCall, execScopes) =>
|
|
1280
|
+
await this.#executeUtility(contractFunctionSimulator, privateSyncCall, [], execScopes, jobId),
|
|
1281
|
+
anchorBlockHeader,
|
|
1282
|
+
jobId,
|
|
1283
|
+
filter.scopes,
|
|
1284
|
+
);
|
|
1285
|
+
});
|
|
1047
1286
|
|
|
1048
|
-
|
|
1287
|
+
// anchorBlockNumber is set during the job and fixed to whatever it is after a block sync
|
|
1288
|
+
const sanitizedFilter = new PrivateEventFilterValidator(anchorBlockNumber!).validate(filter);
|
|
1049
1289
|
|
|
1050
1290
|
this.log.debug(
|
|
1051
1291
|
`Getting private events for ${sanitizedFilter.contractAddress.toString()} from ${sanitizedFilter.fromBlock} to ${sanitizedFilter.toBlock}`,
|
|
1052
1292
|
);
|
|
1053
1293
|
|
|
1054
|
-
return this.
|
|
1294
|
+
return this.privateEventStore.getPrivateEvents(eventSelector, sanitizedFilter);
|
|
1055
1295
|
}
|
|
1056
1296
|
|
|
1057
1297
|
/**
|
|
1058
|
-
* Stops the PXE's job queue.
|
|
1298
|
+
* Stops the PXE's job queue and closes the backing store.
|
|
1059
1299
|
*/
|
|
1060
|
-
public stop(): Promise<void> {
|
|
1061
|
-
|
|
1300
|
+
public async stop(): Promise<void> {
|
|
1301
|
+
await this.jobQueue.end();
|
|
1302
|
+
await this.blockStateSynchronizer.stop();
|
|
1303
|
+
await this.db.close();
|
|
1062
1304
|
}
|
|
1063
1305
|
}
|