@aztec/pxe 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/bin/check_oracle_version.d.ts +1 -1
- package/dest/bin/check_oracle_version.js +110 -10
- package/dest/block_synchronizer/block_synchronizer.d.ts +45 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -0
- package/dest/block_synchronizer/block_synchronizer.js +153 -0
- package/dest/block_synchronizer/index.d.ts +2 -0
- package/dest/block_synchronizer/index.d.ts.map +1 -0
- package/dest/block_synchronizer/index.js +1 -0
- package/dest/config/index.d.ts +11 -17
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +27 -16
- package/dest/config/package_info.d.ts +1 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/benchmarked_node.d.ts +9 -0
- package/dest/contract_function_simulator/benchmarked_node.d.ts.map +1 -0
- package/dest/contract_function_simulator/benchmarked_node.js +77 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +79 -27
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +287 -87
- package/dest/contract_function_simulator/execution_note_cache.d.ts +26 -15
- package/dest/contract_function_simulator/execution_note_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/execution_note_cache.js +65 -37
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts +16 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.d.ts.map +1 -0
- package/dest/contract_function_simulator/execution_tagging_index_cache.js +26 -0
- package/dest/contract_function_simulator/hashed_values_cache.d.ts +2 -2
- package/dest/contract_function_simulator/hashed_values_cache.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.d.ts +5 -3
- package/dest/contract_function_simulator/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/index.js +3 -2
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +5 -4
- 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 +7 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts +5 -4
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_request.js +7 -6
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts +3 -3
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/log_retrieval_response.js +8 -4
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +7 -4
- 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 +13 -4
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts +16 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.d.ts.map +1 -0
- package/dest/contract_function_simulator/noir-structs/utility_context.js +22 -0
- package/dest/contract_function_simulator/oracle/index.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/index.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/index.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +107 -0
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -0
- package/dest/contract_function_simulator/oracle/interfaces.js +4 -0
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/message_load_oracle_inputs.js +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +14 -8
- package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/note_packing_utils.js +16 -11
- package/dest/contract_function_simulator/oracle/oracle.d.ts +26 -22
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +156 -113
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -27
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +3 -48
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +72 -52
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +173 -68
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +116 -53
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +217 -94
- package/dest/contract_function_simulator/pick_notes.d.ts +2 -2
- package/dest/contract_function_simulator/pick_notes.d.ts.map +1 -1
- package/dest/contract_function_simulator/pick_notes.js +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts +4 -4
- package/dest/contract_function_simulator/proxied_contract_data_source.d.ts.map +1 -1
- package/dest/contract_function_simulator/proxied_contract_data_source.js +23 -5
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +45 -0
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -0
- package/dest/debug/pxe_debug_utils.js +48 -0
- package/dest/entrypoints/client/bundle/index.d.ts +7 -3
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +5 -2
- package/dest/entrypoints/client/bundle/utils.d.ts +9 -9
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +40 -17
- package/dest/entrypoints/client/lazy/index.d.ts +7 -3
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +5 -2
- package/dest/entrypoints/client/lazy/utils.d.ts +9 -9
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +40 -17
- package/dest/entrypoints/pxe_creation_options.d.ts +7 -3
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +9 -3
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +7 -2
- package/dest/entrypoints/server/utils.d.ts +5 -24
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +42 -51
- package/dest/error_enriching.d.ts +11 -0
- package/dest/error_enriching.d.ts.map +1 -0
- package/dest/{pxe_service/error_enriching.js → error_enriching.js} +9 -6
- package/dest/events/event_service.d.ts +15 -0
- package/dest/events/event_service.d.ts.map +1 -0
- package/dest/events/event_service.js +44 -0
- package/dest/events/index.d.ts +2 -0
- package/dest/events/index.d.ts.map +1 -0
- package/dest/events/index.js +1 -0
- package/dest/events/private_event_filter_validator.d.ts +9 -0
- package/dest/events/private_event_filter_validator.d.ts.map +1 -0
- package/dest/events/private_event_filter_validator.js +38 -0
- package/dest/job_coordinator/job_coordinator.d.ts +75 -0
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -0
- package/dest/job_coordinator/job_coordinator.js +94 -0
- package/dest/logs/log_service.d.ts +29 -0
- package/dest/logs/log_service.d.ts.map +1 -0
- package/dest/logs/log_service.js +118 -0
- package/dest/notes/index.d.ts +2 -0
- package/dest/notes/index.d.ts.map +1 -0
- package/dest/notes/index.js +1 -0
- package/dest/notes/note_service.d.ts +49 -0
- package/dest/notes/note_service.d.ts.map +1 -0
- package/dest/notes/note_service.js +148 -0
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- 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_expiration_timestamp.js +41 -0
- 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 +28 -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} +22 -16
- package/dest/private_kernel/index.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +11 -3
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +48 -43
- package/dest/private_kernel/private_kernel_oracle.d.ts +26 -25
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +94 -2
- package/dest/pxe.d.ts +250 -0
- package/dest/pxe.d.ts.map +1 -0
- package/dest/pxe.js +774 -0
- package/dest/storage/address_store/address_store.d.ts +11 -0
- package/dest/storage/address_store/address_store.d.ts.map +1 -0
- package/dest/storage/{address_data_provider/address_data_provider.js → address_store/address_store.js} +13 -15
- package/dest/storage/address_store/index.d.ts +2 -0
- package/dest/storage/address_store/index.d.ts.map +1 -0
- package/dest/storage/address_store/index.js +1 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +17 -0
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -0
- package/dest/storage/{sync_data_provider/sync_data_provider.js → anchor_block_store/anchor_block_store.js} +10 -13
- package/dest/storage/anchor_block_store/index.d.ts +2 -0
- package/dest/storage/anchor_block_store/index.d.ts.map +1 -0
- package/dest/storage/anchor_block_store/index.js +1 -0
- package/dest/storage/capsule_store/capsule_store.d.ts +72 -0
- package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -0
- package/dest/storage/capsule_store/capsule_store.js +253 -0
- package/dest/storage/capsule_store/index.d.ts +2 -0
- package/dest/storage/capsule_store/index.d.ts.map +1 -0
- package/dest/storage/capsule_store/index.js +1 -0
- package/dest/storage/contract_store/contract_store.d.ts +93 -0
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -0
- package/dest/storage/contract_store/contract_store.js +309 -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/{contract_data_provider → contract_store}/private_functions_tree.js +1 -1
- package/dest/storage/index.d.ts +8 -9
- package/dest/storage/index.d.ts.map +1 -1
- package/dest/storage/index.js +7 -8
- package/dest/storage/metadata.d.ts +2 -2
- 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/private_event_store/private_event_store.d.ts +91 -0
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -0
- package/dest/storage/private_event_store/private_event_store.js +273 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/index.d.ts +4 -0
- package/dest/storage/tagging_store/index.d.ts.map +1 -0
- package/dest/storage/tagging_store/index.js +3 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +28 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/recipient_tagging_store.js +111 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +14 -0
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_address_book_store.js +36 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +77 -0
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -0
- package/dest/storage/tagging_store/sender_tagging_store.js +348 -0
- package/dest/tagging/constants.d.ts +2 -0
- package/dest/tagging/constants.d.ts.map +1 -0
- package/dest/tagging/constants.js +10 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +60 -0
- package/dest/tagging/index.d.ts +17 -0
- package/dest/tagging/index.d.ts.map +1 -0
- package/dest/tagging/index.js +15 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +15 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +99 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts +12 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +20 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +15 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -0
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +32 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +21 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +74 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +11 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +29 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +21 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -0
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +60 -0
- package/package.json +30 -23
- package/src/access_scopes.ts +9 -0
- package/src/bin/check_oracle_version.ts +135 -10
- package/src/block_synchronizer/block_synchronizer.ts +178 -0
- package/src/block_synchronizer/index.ts +1 -0
- package/src/config/index.ts +32 -32
- 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 +505 -140
- package/src/contract_function_simulator/execution_note_cache.ts +67 -32
- package/src/contract_function_simulator/execution_tagging_index_cache.ts +32 -0
- package/src/contract_function_simulator/hashed_values_cache.ts +1 -1
- package/src/contract_function_simulator/index.ts +4 -2
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +7 -3
- package/src/contract_function_simulator/noir-structs/log_retrieval_request.ts +6 -5
- package/src/contract_function_simulator/noir-structs/log_retrieval_response.ts +10 -5
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +15 -3
- package/src/contract_function_simulator/noir-structs/utility_context.ts +23 -0
- package/src/contract_function_simulator/oracle/index.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +185 -0
- package/src/contract_function_simulator/oracle/message_load_oracle_inputs.ts +1 -1
- package/src/contract_function_simulator/oracle/note_packing_utils.ts +30 -14
- package/src/contract_function_simulator/oracle/oracle.ts +197 -110
- package/src/contract_function_simulator/oracle/private_execution.ts +4 -78
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +248 -122
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +372 -138
- package/src/contract_function_simulator/pick_notes.ts +1 -1
- package/src/contract_function_simulator/proxied_contract_data_source.ts +24 -7
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/helpers.ts +98 -0
- package/src/debug/pxe_debug_utils.ts +93 -0
- package/src/entrypoints/client/bundle/index.ts +6 -2
- package/src/entrypoints/client/bundle/utils.ts +31 -32
- package/src/entrypoints/client/lazy/index.ts +6 -2
- package/src/entrypoints/client/lazy/utils.ts +31 -32
- package/src/entrypoints/pxe_creation_options.ts +6 -2
- package/src/entrypoints/server/index.ts +8 -2
- package/src/entrypoints/server/utils.ts +39 -91
- package/src/{pxe_service/error_enriching.ts → error_enriching.ts} +11 -15
- package/src/events/event_service.ts +71 -0
- package/src/events/index.ts +1 -0
- package/src/events/private_event_filter_validator.ts +46 -0
- package/src/job_coordinator/job_coordinator.ts +150 -0
- package/src/logs/log_service.ts +208 -0
- package/src/notes/index.ts +1 -0
- package/src/notes/note_service.ts +196 -0
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +16 -16
- 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} +44 -37
- package/src/private_kernel/private_kernel_execution_prover.ts +64 -55
- package/src/private_kernel/private_kernel_oracle.ts +118 -37
- package/src/pxe.ts +1137 -0
- package/src/storage/{address_data_provider/address_data_provider.ts → address_store/address_store.ts} +15 -21
- package/src/storage/address_store/index.ts +1 -0
- package/src/storage/{sync_data_provider/sync_data_provider.ts → anchor_block_store/anchor_block_store.ts} +10 -17
- package/src/storage/anchor_block_store/index.ts +1 -0
- package/src/storage/capsule_store/capsule_store.ts +315 -0
- package/src/storage/capsule_store/index.ts +1 -0
- package/src/storage/contract_store/contract_store.ts +429 -0
- package/src/storage/contract_store/index.ts +1 -0
- package/src/storage/{contract_data_provider → contract_store}/private_functions_tree.ts +1 -1
- package/src/storage/index.ts +7 -8
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/index.ts +2 -0
- package/src/storage/note_store/note_store.ts +418 -0
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +384 -0
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/index.ts +3 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +139 -0
- package/src/storage/tagging_store/sender_address_book_store.ts +48 -0
- package/src/storage/tagging_store/sender_tagging_store.ts +429 -0
- package/src/tagging/constants.ts +10 -0
- package/src/tagging/get_all_logs_by_tags.ts +92 -0
- package/src/tagging/index.ts +19 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +143 -0
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +34 -0
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +49 -0
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +99 -0
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +36 -0
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +84 -0
- package/dest/bin/index.d.ts +0 -3
- package/dest/bin/index.d.ts.map +0 -1
- package/dest/bin/index.js +0 -48
- package/dest/contract_function_simulator/execution_data_provider.d.ts +0 -285
- package/dest/contract_function_simulator/execution_data_provider.d.ts.map +0 -1
- package/dest/contract_function_simulator/execution_data_provider.js +0 -14
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts +0 -87
- package/dest/contract_function_simulator/oracle/typed_oracle.d.ts.map +0 -1
- package/dest/contract_function_simulator/oracle/typed_oracle.js +0 -146
- package/dest/contract_function_simulator/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/contract_function_simulator/pxe_oracle_interface.d.ts +0 -158
- package/dest/contract_function_simulator/pxe_oracle_interface.d.ts.map +0 -1
- package/dest/contract_function_simulator/pxe_oracle_interface.js +0 -701
- package/dest/contract_function_simulator/tagging_utils.d.ts +0 -17
- package/dest/contract_function_simulator/tagging_utils.d.ts.map +0 -1
- package/dest/contract_function_simulator/tagging_utils.js +0 -23
- package/dest/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/hints/compute_tx_include_by_timestamp.js +0 -41
- package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -45
- 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/pxe_service/error_enriching.d.ts +0 -11
- package/dest/pxe_service/error_enriching.d.ts.map +0 -1
- package/dest/pxe_service/index.d.ts +0 -3
- package/dest/pxe_service/index.d.ts.map +0 -1
- package/dest/pxe_service/index.js +0 -2
- package/dest/pxe_service/pxe_service.d.ts +0 -101
- package/dest/pxe_service/pxe_service.d.ts.map +0 -1
- package/dest/pxe_service/pxe_service.js +0 -791
- package/dest/storage/address_data_provider/address_data_provider.d.ts +0 -13
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.d.ts +0 -2
- package/dest/storage/address_data_provider/index.d.ts.map +0 -1
- package/dest/storage/address_data_provider/index.js +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +0 -27
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +0 -1
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +0 -122
- 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 -75
- 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 -208
- package/dest/storage/contract_data_provider/index.d.ts +0 -2
- package/dest/storage/contract_data_provider/index.d.ts.map +0 -1
- package/dest/storage/contract_data_provider/index.js +0 -1
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/storage/data_provider.d.ts +0 -4
- package/dest/storage/data_provider.d.ts.map +0 -1
- package/dest/storage/data_provider.js +0 -1
- package/dest/storage/note_data_provider/index.d.ts +0 -3
- package/dest/storage/note_data_provider/index.d.ts.map +0 -1
- package/dest/storage/note_data_provider/index.js +0 -2
- package/dest/storage/note_data_provider/note_dao.d.ts +0 -100
- package/dest/storage/note_data_provider/note_dao.d.ts.map +0 -1
- package/dest/storage/note_data_provider/note_dao.js +0 -102
- package/dest/storage/note_data_provider/note_data_provider.d.ts +0 -20
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +0 -1
- package/dest/storage/note_data_provider/note_data_provider.js +0 -260
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts +0 -37
- package/dest/storage/private_event_data_provider/private_event_data_provider.d.ts.map +0 -1
- package/dest/storage/private_event_data_provider/private_event_data_provider.js +0 -96
- package/dest/storage/sync_data_provider/index.d.ts +0 -2
- package/dest/storage/sync_data_provider/index.d.ts.map +0 -1
- package/dest/storage/sync_data_provider/index.js +0 -1
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +0 -12
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.d.ts +0 -2
- package/dest/storage/tagging_data_provider/index.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/index.js +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +0 -18
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +0 -1
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +0 -82
- package/dest/synchronizer/index.d.ts +0 -2
- package/dest/synchronizer/index.d.ts.map +0 -1
- package/dest/synchronizer/index.js +0 -1
- package/dest/synchronizer/synchronizer.d.ts +0 -35
- package/dest/synchronizer/synchronizer.d.ts.map +0 -1
- package/dest/synchronizer/synchronizer.js +0 -102
- package/dest/test/pxe_test_suite.d.ts +0 -3
- package/dest/test/pxe_test_suite.d.ts.map +0 -1
- package/dest/test/pxe_test_suite.js +0 -97
- package/src/bin/index.ts +0 -62
- package/src/contract_function_simulator/execution_data_provider.ts +0 -361
- package/src/contract_function_simulator/oracle/typed_oracle.ts +0 -289
- package/src/contract_function_simulator/proxied_node.ts +0 -33
- package/src/contract_function_simulator/pxe_oracle_interface.ts +0 -1020
- package/src/contract_function_simulator/tagging_utils.ts +0 -32
- package/src/private_kernel/private_kernel_oracle_impl.ts +0 -132
- package/src/pxe_service/index.ts +0 -2
- package/src/pxe_service/pxe_service.ts +0 -1139
- package/src/storage/address_data_provider/index.ts +0 -1
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +0 -157
- package/src/storage/capsule_data_provider/index.ts +0 -1
- package/src/storage/contract_data_provider/contract_data_provider.ts +0 -300
- package/src/storage/contract_data_provider/index.ts +0 -1
- package/src/storage/data_provider.ts +0 -3
- package/src/storage/note_data_provider/index.ts +0 -2
- package/src/storage/note_data_provider/note_dao.ts +0 -154
- package/src/storage/note_data_provider/note_data_provider.ts +0 -350
- package/src/storage/private_event_data_provider/private_event_data_provider.ts +0 -134
- package/src/storage/sync_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/index.ts +0 -1
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +0 -123
- package/src/synchronizer/index.ts +0 -1
- package/src/synchronizer/synchronizer.ts +0 -121
- package/src/test/pxe_test_suite.ts +0 -113
|
@@ -1,791 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
4
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import { KeyStore } from '@aztec/key-store';
|
|
6
|
-
import { L2TipsKVStore } from '@aztec/kv-store/stores';
|
|
7
|
-
import { ProtocolContractAddress, protocolContractNames } from '@aztec/protocol-contracts';
|
|
8
|
-
import { EventSelector, FunctionSelector, FunctionType, decodeFromAbi, decodeFunctionSignature, encodeArguments } from '@aztec/stdlib/abi';
|
|
9
|
-
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
10
|
-
import { SimulationError } from '@aztec/stdlib/errors';
|
|
11
|
-
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
|
-
import { computeL2ToL1MembershipWitness, getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
13
|
-
import { UniqueNote } from '@aztec/stdlib/note';
|
|
14
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
15
|
-
import { PrivateSimulationResult, TxProfileResult, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
16
|
-
import { inspect } from 'util';
|
|
17
|
-
import { getPackageInfo } from '../config/package_info.js';
|
|
18
|
-
import { ContractFunctionSimulator, generateSimulatedProvingResult } from '../contract_function_simulator/contract_function_simulator.js';
|
|
19
|
-
import { readCurrentClassId } from '../contract_function_simulator/oracle/private_execution.js';
|
|
20
|
-
import { ProxiedContractDataProviderFactory } from '../contract_function_simulator/proxied_contract_data_source.js';
|
|
21
|
-
import { ProxiedNodeFactory } from '../contract_function_simulator/proxied_node.js';
|
|
22
|
-
import { PXEOracleInterface } from '../contract_function_simulator/pxe_oracle_interface.js';
|
|
23
|
-
import { PrivateKernelExecutionProver } from '../private_kernel/private_kernel_execution_prover.js';
|
|
24
|
-
import { PrivateKernelOracleImpl } from '../private_kernel/private_kernel_oracle_impl.js';
|
|
25
|
-
import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
26
|
-
import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
27
|
-
import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
28
|
-
import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
29
|
-
import { PrivateEventDataProvider } from '../storage/private_event_data_provider/private_event_data_provider.js';
|
|
30
|
-
import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
31
|
-
import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
32
|
-
import { Synchronizer } from '../synchronizer/index.js';
|
|
33
|
-
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
34
|
-
/**
|
|
35
|
-
* A Private eXecution Environment (PXE) implementation.
|
|
36
|
-
*/ export class PXEService {
|
|
37
|
-
node;
|
|
38
|
-
synchronizer;
|
|
39
|
-
keyStore;
|
|
40
|
-
contractDataProvider;
|
|
41
|
-
noteDataProvider;
|
|
42
|
-
capsuleDataProvider;
|
|
43
|
-
syncDataProvider;
|
|
44
|
-
taggingDataProvider;
|
|
45
|
-
addressDataProvider;
|
|
46
|
-
privateEventDataProvider;
|
|
47
|
-
simulator;
|
|
48
|
-
packageVersion;
|
|
49
|
-
proverEnabled;
|
|
50
|
-
proofCreator;
|
|
51
|
-
protocolContractsProvider;
|
|
52
|
-
log;
|
|
53
|
-
jobQueue;
|
|
54
|
-
#nodeInfo;
|
|
55
|
-
constructor(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, packageVersion, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue){
|
|
56
|
-
this.node = node;
|
|
57
|
-
this.synchronizer = synchronizer;
|
|
58
|
-
this.keyStore = keyStore;
|
|
59
|
-
this.contractDataProvider = contractDataProvider;
|
|
60
|
-
this.noteDataProvider = noteDataProvider;
|
|
61
|
-
this.capsuleDataProvider = capsuleDataProvider;
|
|
62
|
-
this.syncDataProvider = syncDataProvider;
|
|
63
|
-
this.taggingDataProvider = taggingDataProvider;
|
|
64
|
-
this.addressDataProvider = addressDataProvider;
|
|
65
|
-
this.privateEventDataProvider = privateEventDataProvider;
|
|
66
|
-
this.simulator = simulator;
|
|
67
|
-
this.packageVersion = packageVersion;
|
|
68
|
-
this.proverEnabled = proverEnabled;
|
|
69
|
-
this.proofCreator = proofCreator;
|
|
70
|
-
this.protocolContractsProvider = protocolContractsProvider;
|
|
71
|
-
this.log = log;
|
|
72
|
-
this.jobQueue = jobQueue;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Creates an instance of a PXE Service by instantiating all the necessary data providers and services.
|
|
76
|
-
* Also triggers the registration of the protocol contracts and makes sure the provided node
|
|
77
|
-
* can be contacted.
|
|
78
|
-
*
|
|
79
|
-
* @returns A promise that resolves PXE service is ready to be used.
|
|
80
|
-
*/ static async create(node, store, proofCreator, simulator, protocolContractsProvider, config, loggerOrSuffix) {
|
|
81
|
-
const log = !loggerOrSuffix || typeof loggerOrSuffix === 'string' ? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`) : loggerOrSuffix;
|
|
82
|
-
const packageVersion = getPackageInfo().version;
|
|
83
|
-
const proverEnabled = !!config.proverEnabled;
|
|
84
|
-
const addressDataProvider = new AddressDataProvider(store);
|
|
85
|
-
const privateEventDataProvider = new PrivateEventDataProvider(store);
|
|
86
|
-
const contractDataProvider = new ContractDataProvider(store);
|
|
87
|
-
const noteDataProvider = await NoteDataProvider.create(store);
|
|
88
|
-
const syncDataProvider = new SyncDataProvider(store);
|
|
89
|
-
const taggingDataProvider = new TaggingDataProvider(store);
|
|
90
|
-
const capsuleDataProvider = new CapsuleDataProvider(store);
|
|
91
|
-
const keyStore = new KeyStore(store);
|
|
92
|
-
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
93
|
-
const synchronizer = new Synchronizer(node, syncDataProvider, noteDataProvider, taggingDataProvider, tipsStore, config, loggerOrSuffix);
|
|
94
|
-
const jobQueue = new SerialQueue();
|
|
95
|
-
const pxeService = new PXEService(node, synchronizer, keyStore, contractDataProvider, noteDataProvider, capsuleDataProvider, syncDataProvider, taggingDataProvider, addressDataProvider, privateEventDataProvider, simulator, packageVersion, proverEnabled, proofCreator, protocolContractsProvider, log, jobQueue);
|
|
96
|
-
pxeService.jobQueue.start();
|
|
97
|
-
await pxeService.#registerProtocolContracts();
|
|
98
|
-
const info = await pxeService.getNodeInfo();
|
|
99
|
-
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.rollupVersion}`);
|
|
100
|
-
return pxeService;
|
|
101
|
-
}
|
|
102
|
-
getL1ToL2MessageBlock(l1ToL2Message) {
|
|
103
|
-
return this.node.getL1ToL2MessageBlock(l1ToL2Message);
|
|
104
|
-
}
|
|
105
|
-
// Aztec node proxy methods
|
|
106
|
-
isL1ToL2MessageSynced(l1ToL2Message) {
|
|
107
|
-
return this.node.isL1ToL2MessageSynced(l1ToL2Message);
|
|
108
|
-
}
|
|
109
|
-
async getL2ToL1MembershipWitness(blockNumber, l2Tol1Message) {
|
|
110
|
-
const result = await computeL2ToL1MembershipWitness(this.node, blockNumber, l2Tol1Message);
|
|
111
|
-
if (!result) {
|
|
112
|
-
throw new Error(`L2 to L1 message not found in block ${blockNumber}`);
|
|
113
|
-
}
|
|
114
|
-
return [
|
|
115
|
-
result.leafIndex,
|
|
116
|
-
result.siblingPath
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
getTxReceipt(txHash) {
|
|
120
|
-
return this.node.getTxReceipt(txHash);
|
|
121
|
-
}
|
|
122
|
-
getTxEffect(txHash) {
|
|
123
|
-
return this.node.getTxEffect(txHash);
|
|
124
|
-
}
|
|
125
|
-
getBlockNumber() {
|
|
126
|
-
return this.node.getBlockNumber();
|
|
127
|
-
}
|
|
128
|
-
getProvenBlockNumber() {
|
|
129
|
-
return this.node.getProvenBlockNumber();
|
|
130
|
-
}
|
|
131
|
-
getPublicLogs(filter) {
|
|
132
|
-
return this.node.getPublicLogs(filter);
|
|
133
|
-
}
|
|
134
|
-
getContractClassLogs(filter) {
|
|
135
|
-
return this.node.getContractClassLogs(filter);
|
|
136
|
-
}
|
|
137
|
-
getPublicStorageAt(contract, slot) {
|
|
138
|
-
return this.node.getPublicStorageAt('latest', contract, slot);
|
|
139
|
-
}
|
|
140
|
-
async getL1ToL2MembershipWitness(contractAddress, messageHash, secret) {
|
|
141
|
-
return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
|
|
142
|
-
}
|
|
143
|
-
// Internal methods
|
|
144
|
-
#getSimulatorForTx(overrides) {
|
|
145
|
-
const pxeOracleInterface = new PXEOracleInterface(ProxiedNodeFactory.create(this.node), this.keyStore, ProxiedContractDataProviderFactory.create(this.contractDataProvider, overrides?.contracts), this.noteDataProvider, this.capsuleDataProvider, this.syncDataProvider, this.taggingDataProvider, this.addressDataProvider, this.privateEventDataProvider, this.log);
|
|
146
|
-
return new ContractFunctionSimulator(pxeOracleInterface, this.simulator);
|
|
147
|
-
}
|
|
148
|
-
#contextualizeError(err, ...context) {
|
|
149
|
-
let contextStr = '';
|
|
150
|
-
if (context.length > 0) {
|
|
151
|
-
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
152
|
-
}
|
|
153
|
-
if (err instanceof SimulationError) {
|
|
154
|
-
err.setAztecContext(contextStr);
|
|
155
|
-
} else {
|
|
156
|
-
this.log.error(err.name, err);
|
|
157
|
-
this.log.debug(contextStr);
|
|
158
|
-
}
|
|
159
|
-
return err;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Enqueues a job for execution once no other jobs are running. Returns a promise that will resolve once the job is
|
|
163
|
-
* complete.
|
|
164
|
-
*
|
|
165
|
-
* Useful for tasks that cannot run concurrently, such as contract function simulation.
|
|
166
|
-
*/ #putInJobQueue(fn) {
|
|
167
|
-
// TODO(#12636): relax the conditions under which we forbid concurrency.
|
|
168
|
-
if (this.jobQueue.length() != 0) {
|
|
169
|
-
this.log.warn(`PXE is already processing ${this.jobQueue.length()} jobs, concurrent execution is not supported. Will run once those are complete.`);
|
|
170
|
-
}
|
|
171
|
-
return this.jobQueue.put(fn);
|
|
172
|
-
}
|
|
173
|
-
async #registerProtocolContracts() {
|
|
174
|
-
const registered = {};
|
|
175
|
-
for (const name of protocolContractNames){
|
|
176
|
-
const { address, contractClass, instance, artifact } = await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
177
|
-
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
178
|
-
await this.contractDataProvider.addContractInstance(instance);
|
|
179
|
-
registered[name] = address.toString();
|
|
180
|
-
}
|
|
181
|
-
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
182
|
-
}
|
|
183
|
-
async #isContractClassPubliclyRegistered(id) {
|
|
184
|
-
return !!await this.node.getContractClass(id);
|
|
185
|
-
}
|
|
186
|
-
async #isContractPublished(address) {
|
|
187
|
-
return !!await this.node.getContract(address);
|
|
188
|
-
}
|
|
189
|
-
async #isContractInitialized(address) {
|
|
190
|
-
const initNullifier = await siloNullifier(address, address.toField());
|
|
191
|
-
return !!await this.node.getNullifierMembershipWitness('latest', initNullifier);
|
|
192
|
-
}
|
|
193
|
-
async #getFunctionCall(functionName, args, to) {
|
|
194
|
-
const contract = await this.contractDataProvider.getContract(to);
|
|
195
|
-
if (!contract) {
|
|
196
|
-
throw new Error(`Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`);
|
|
197
|
-
}
|
|
198
|
-
const functionDao = contract.functions.find((f)=>f.name === functionName);
|
|
199
|
-
if (!functionDao) {
|
|
200
|
-
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
201
|
-
}
|
|
202
|
-
return {
|
|
203
|
-
name: functionDao.name,
|
|
204
|
-
args: encodeArguments(functionDao, args),
|
|
205
|
-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
206
|
-
type: functionDao.functionType,
|
|
207
|
-
to,
|
|
208
|
-
isStatic: functionDao.isStatic,
|
|
209
|
-
returnTypes: functionDao.returnTypes
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
// Executes the entrypoint private function, as well as all nested private
|
|
213
|
-
// functions that might arise.
|
|
214
|
-
async #executePrivate(contractFunctionSimulator, txRequest, scopes) {
|
|
215
|
-
const { origin: contractAddress, functionSelector } = txRequest;
|
|
216
|
-
try {
|
|
217
|
-
const result = await contractFunctionSimulator.run(txRequest, contractAddress, functionSelector, undefined, // The sender for tags is set by contracts, typically by an account
|
|
218
|
-
// contract entrypoint
|
|
219
|
-
undefined, scopes);
|
|
220
|
-
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
221
|
-
return result;
|
|
222
|
-
} catch (err) {
|
|
223
|
-
if (err instanceof SimulationError) {
|
|
224
|
-
await enrichSimulationError(err, this.contractDataProvider, this.log);
|
|
225
|
-
}
|
|
226
|
-
throw err;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Simulate a utility function call on the given contract.
|
|
231
|
-
* @param contractFunctionSimulator - The simulator to use for the function call.
|
|
232
|
-
* @param call - The function call to execute.
|
|
233
|
-
* @param authWitnesses - Authentication witnesses required for the function call.
|
|
234
|
-
* @param scopes - Optional array of account addresses whose notes can be accessed in this call. Defaults to all
|
|
235
|
-
* accounts if not specified.
|
|
236
|
-
* @returns The simulation result containing the outputs of the utility function.
|
|
237
|
-
*/ async #simulateUtility(contractFunctionSimulator, call, authWitnesses, scopes) {
|
|
238
|
-
try {
|
|
239
|
-
return contractFunctionSimulator.runUtility(call, authWitnesses ?? [], scopes);
|
|
240
|
-
} catch (err) {
|
|
241
|
-
if (err instanceof SimulationError) {
|
|
242
|
-
await enrichSimulationError(err, this.contractDataProvider, this.log);
|
|
243
|
-
}
|
|
244
|
-
throw err;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Simulate the public part of a transaction.
|
|
249
|
-
* This allows to catch public execution errors before submitting the transaction.
|
|
250
|
-
* It can also be used for estimating gas in the future.
|
|
251
|
-
* @param tx - The transaction to be simulated.
|
|
252
|
-
*/ async #simulatePublicCalls(tx, skipFeeEnforcement) {
|
|
253
|
-
// Simulating public calls can throw if the TX fails in a phase that doesn't allow reverts (setup)
|
|
254
|
-
// Or return as reverted if it fails in a phase that allows reverts (app logic, teardown)
|
|
255
|
-
try {
|
|
256
|
-
const result = await this.node.simulatePublicCalls(tx, skipFeeEnforcement);
|
|
257
|
-
if (result.revertReason) {
|
|
258
|
-
throw result.revertReason;
|
|
259
|
-
}
|
|
260
|
-
return result;
|
|
261
|
-
} catch (err) {
|
|
262
|
-
if (err instanceof SimulationError) {
|
|
263
|
-
try {
|
|
264
|
-
await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
|
|
265
|
-
} catch (enrichErr) {
|
|
266
|
-
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
throw err;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Generate a kernel proof, and create a private kernel output.
|
|
274
|
-
* The function takes in a transaction execution request, and the result of private execution
|
|
275
|
-
* and then generates a kernel proof.
|
|
276
|
-
*
|
|
277
|
-
* @param txExecutionRequest - The transaction request to be simulated and proved.
|
|
278
|
-
* @param proofCreator - The proof creator to use for proving the execution.
|
|
279
|
-
* @param privateExecutionResult - The result of the private execution
|
|
280
|
-
* @param config - The configuration for the kernel execution prover.
|
|
281
|
-
* @returns An object that contains the output of the kernel execution, including the ClientIvcProof if proving is enabled.
|
|
282
|
-
*/ async #prove(txExecutionRequest, proofCreator, privateExecutionResult, config) {
|
|
283
|
-
const block = privateExecutionResult.getSimulationBlockNumber();
|
|
284
|
-
const kernelOracle = new PrivateKernelOracleImpl(this.contractDataProvider, this.keyStore, this.node, block);
|
|
285
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(kernelOracle, proofCreator, !this.proverEnabled);
|
|
286
|
-
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
287
|
-
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
288
|
-
}
|
|
289
|
-
// Public API
|
|
290
|
-
/** Returns an estimate of the db size in bytes. */ async estimateDbSize() {
|
|
291
|
-
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
|
|
292
|
-
const dbSizes = await Promise.all([
|
|
293
|
-
this.addressDataProvider.getSize(),
|
|
294
|
-
this.capsuleDataProvider.getSize(),
|
|
295
|
-
this.contractDataProvider.getSize(),
|
|
296
|
-
this.noteDataProvider.getSize(),
|
|
297
|
-
this.syncDataProvider.getSize(),
|
|
298
|
-
this.taggingDataProvider.getSize()
|
|
299
|
-
]);
|
|
300
|
-
return [
|
|
301
|
-
...dbSizes,
|
|
302
|
-
treeRootsSize
|
|
303
|
-
].reduce((sum, size)=>sum + size, 0);
|
|
304
|
-
}
|
|
305
|
-
getContractInstance(address) {
|
|
306
|
-
return this.contractDataProvider.getContractInstance(address);
|
|
307
|
-
}
|
|
308
|
-
async getContractClassMetadata(id, includeArtifact = false) {
|
|
309
|
-
const artifact = await this.contractDataProvider.getContractArtifact(id);
|
|
310
|
-
if (!artifact) {
|
|
311
|
-
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
contractClass: artifact && await getContractClassFromArtifact(artifact),
|
|
315
|
-
isContractClassPubliclyRegistered: await this.#isContractClassPubliclyRegistered(id),
|
|
316
|
-
artifact: includeArtifact ? artifact : undefined
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
async getContractMetadata(address) {
|
|
320
|
-
let instance;
|
|
321
|
-
try {
|
|
322
|
-
instance = await this.contractDataProvider.getContractInstance(address);
|
|
323
|
-
} catch {
|
|
324
|
-
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
325
|
-
}
|
|
326
|
-
return {
|
|
327
|
-
contractInstance: instance,
|
|
328
|
-
isContractInitialized: await this.#isContractInitialized(address),
|
|
329
|
-
isContractPublished: await this.#isContractPublished(address)
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
async registerAccount(secretKey, partialAddress) {
|
|
333
|
-
const accounts = await this.keyStore.getAccounts();
|
|
334
|
-
const accountCompleteAddress = await this.keyStore.addAccount(secretKey, partialAddress);
|
|
335
|
-
if (accounts.includes(accountCompleteAddress.address)) {
|
|
336
|
-
this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`);
|
|
337
|
-
return accountCompleteAddress;
|
|
338
|
-
} else {
|
|
339
|
-
this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`);
|
|
340
|
-
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
341
|
-
}
|
|
342
|
-
await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
|
|
343
|
-
await this.noteDataProvider.addScope(accountCompleteAddress.address);
|
|
344
|
-
return accountCompleteAddress;
|
|
345
|
-
}
|
|
346
|
-
async registerSender(address) {
|
|
347
|
-
const accounts = await this.keyStore.getAccounts();
|
|
348
|
-
if (accounts.includes(address)) {
|
|
349
|
-
this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
|
|
350
|
-
return address;
|
|
351
|
-
}
|
|
352
|
-
const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
|
|
353
|
-
if (wasAdded) {
|
|
354
|
-
this.log.info(`Added sender:\n ${address.toString()}`);
|
|
355
|
-
} else {
|
|
356
|
-
this.log.info(`Sender:\n "${address.toString()}"\n already registered.`);
|
|
357
|
-
}
|
|
358
|
-
return address;
|
|
359
|
-
}
|
|
360
|
-
getSenders() {
|
|
361
|
-
return this.taggingDataProvider.getSenderAddresses();
|
|
362
|
-
}
|
|
363
|
-
async removeSender(address) {
|
|
364
|
-
const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
|
|
365
|
-
if (wasRemoved) {
|
|
366
|
-
this.log.info(`Removed sender:\n ${address.toString()}`);
|
|
367
|
-
} else {
|
|
368
|
-
this.log.info(`Sender:\n "${address.toString()}"\n not in address book.`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async getRegisteredAccounts() {
|
|
372
|
-
// Get complete addresses of both the recipients and the accounts
|
|
373
|
-
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
374
|
-
// Filter out the addresses not corresponding to accounts
|
|
375
|
-
const accounts = await this.keyStore.getAccounts();
|
|
376
|
-
return completeAddresses.filter((completeAddress)=>accounts.find((address)=>address.equals(completeAddress.address)));
|
|
377
|
-
}
|
|
378
|
-
async registerContractClass(artifact) {
|
|
379
|
-
const { id: contractClassId } = await getContractClassFromArtifact(artifact);
|
|
380
|
-
await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
|
|
381
|
-
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
382
|
-
}
|
|
383
|
-
async registerContract(contract) {
|
|
384
|
-
const { instance } = contract;
|
|
385
|
-
let { artifact } = contract;
|
|
386
|
-
if (artifact) {
|
|
387
|
-
// If the user provides an artifact, validate it against the expected class id and register it
|
|
388
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
389
|
-
const contractClassId = contractClass.id;
|
|
390
|
-
if (!contractClassId.equals(instance.currentContractClassId)) {
|
|
391
|
-
throw new Error(`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.currentContractClassId})`);
|
|
392
|
-
}
|
|
393
|
-
const computedAddress = await computeContractAddressFromInstance(instance);
|
|
394
|
-
if (!computedAddress.equals(instance.address)) {
|
|
395
|
-
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
396
|
-
}
|
|
397
|
-
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
398
|
-
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
399
|
-
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
400
|
-
} else {
|
|
401
|
-
// Otherwise, make sure there is an artifact already registered for that class id
|
|
402
|
-
artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
|
|
403
|
-
if (!artifact) {
|
|
404
|
-
throw new Error(`Artifact not found when registering an instance. Contract class: ${instance.currentContractClassId}.`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
await this.contractDataProvider.addContractInstance(instance);
|
|
408
|
-
this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`);
|
|
409
|
-
}
|
|
410
|
-
updateContract(contractAddress, artifact) {
|
|
411
|
-
// We disable concurrently updating contracts to avoid concurrently syncing with the node, or changing a contract's
|
|
412
|
-
// class while we're simulating it.
|
|
413
|
-
return this.#putInJobQueue(async ()=>{
|
|
414
|
-
const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
|
|
415
|
-
if (!currentInstance) {
|
|
416
|
-
throw new Error(`Instance not found when updating a contract. Contract address: ${contractAddress}.`);
|
|
417
|
-
}
|
|
418
|
-
const contractClass = await getContractClassFromArtifact(artifact);
|
|
419
|
-
await this.synchronizer.sync();
|
|
420
|
-
const header = await this.syncDataProvider.getBlockHeader();
|
|
421
|
-
const currentClassId = await readCurrentClassId(contractAddress, currentInstance, this.node, header.globalVariables.blockNumber, header.globalVariables.timestamp);
|
|
422
|
-
if (!contractClass.id.equals(currentClassId)) {
|
|
423
|
-
throw new Error('Could not update contract to a class different from the current one.');
|
|
424
|
-
}
|
|
425
|
-
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
426
|
-
const publicFunctionSignatures = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PUBLIC).map((fn)=>decodeFunctionSignature(fn.name, fn.parameters));
|
|
427
|
-
await this.node.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
428
|
-
currentInstance.currentContractClassId = contractClass.id;
|
|
429
|
-
await this.contractDataProvider.addContractInstance(currentInstance);
|
|
430
|
-
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
getContracts() {
|
|
434
|
-
return this.contractDataProvider.getContractsAddresses();
|
|
435
|
-
}
|
|
436
|
-
async getNotes(filter) {
|
|
437
|
-
// We need to manually trigger private state sync to have a guarantee that all the events are available.
|
|
438
|
-
await this.simulateUtility('sync_private_state', [], filter.contractAddress);
|
|
439
|
-
const noteDaos = await this.noteDataProvider.getNotes(filter);
|
|
440
|
-
const extendedNotes = noteDaos.map(async (dao)=>{
|
|
441
|
-
let recipient = filter.recipient;
|
|
442
|
-
if (recipient === undefined) {
|
|
443
|
-
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
444
|
-
const completeAddressIndex = completeAddresses.findIndex((completeAddress)=>completeAddress.address.equals(dao.recipient));
|
|
445
|
-
const completeAddress = completeAddresses[completeAddressIndex];
|
|
446
|
-
if (completeAddress === undefined) {
|
|
447
|
-
throw new Error(`Cannot find complete address for recipient ${dao.recipient.toString()}`);
|
|
448
|
-
}
|
|
449
|
-
recipient = completeAddress.address;
|
|
450
|
-
}
|
|
451
|
-
return new UniqueNote(dao.note, recipient, dao.contractAddress, dao.storageSlot, dao.txHash, dao.noteNonce);
|
|
452
|
-
});
|
|
453
|
-
return Promise.all(extendedNotes);
|
|
454
|
-
}
|
|
455
|
-
async getBlock(blockNumber) {
|
|
456
|
-
// If a negative block number is provided the current block number is fetched.
|
|
457
|
-
if (blockNumber < 0) {
|
|
458
|
-
blockNumber = await this.node.getBlockNumber();
|
|
459
|
-
}
|
|
460
|
-
return await this.node.getBlock(blockNumber);
|
|
461
|
-
}
|
|
462
|
-
async getCurrentBaseFees() {
|
|
463
|
-
return await this.node.getCurrentBaseFees();
|
|
464
|
-
}
|
|
465
|
-
proveTx(txRequest, privateExecutionResult) {
|
|
466
|
-
// We disable proving concurrently mostly out of caution, since it accesses some of our stores. Proving is so
|
|
467
|
-
// computationally demanding that it'd be rare for someone to try to do it concurrently regardless.
|
|
468
|
-
return this.#putInJobQueue(async ()=>{
|
|
469
|
-
const totalTimer = new Timer();
|
|
470
|
-
try {
|
|
471
|
-
let syncTime;
|
|
472
|
-
let contractFunctionSimulator;
|
|
473
|
-
if (!privateExecutionResult) {
|
|
474
|
-
const syncTimer = new Timer();
|
|
475
|
-
await this.synchronizer.sync();
|
|
476
|
-
syncTime = syncTimer.ms();
|
|
477
|
-
contractFunctionSimulator = this.#getSimulatorForTx();
|
|
478
|
-
privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
479
|
-
}
|
|
480
|
-
const { publicInputs, clientIvcProof, executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
481
|
-
simulate: false,
|
|
482
|
-
skipFeeEnforcement: false,
|
|
483
|
-
profileMode: 'none'
|
|
484
|
-
});
|
|
485
|
-
const totalTime = totalTimer.ms();
|
|
486
|
-
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
|
|
487
|
-
functionName,
|
|
488
|
-
time: witgen,
|
|
489
|
-
oracles
|
|
490
|
-
}));
|
|
491
|
-
const timings = {
|
|
492
|
-
total: totalTime,
|
|
493
|
-
sync: syncTime,
|
|
494
|
-
proving,
|
|
495
|
-
perFunction,
|
|
496
|
-
unaccounted: totalTime - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
497
|
-
};
|
|
498
|
-
this.log.debug(`Proving completed in ${totalTime}ms`, {
|
|
499
|
-
timings
|
|
500
|
-
});
|
|
501
|
-
return new TxProvingResult(privateExecutionResult, publicInputs, clientIvcProof, {
|
|
502
|
-
timings,
|
|
503
|
-
nodeRPCCalls: contractFunctionSimulator?.getStats().nodeRPCCalls
|
|
504
|
-
});
|
|
505
|
-
} catch (err) {
|
|
506
|
-
throw this.#contextualizeError(err, inspect(txRequest), inspect(privateExecutionResult));
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
profileTx(txRequest, profileMode, skipProofGeneration = true) {
|
|
511
|
-
// We disable concurrent profiles for consistency with simulateTx.
|
|
512
|
-
return this.#putInJobQueue(async ()=>{
|
|
513
|
-
const totalTimer = new Timer();
|
|
514
|
-
try {
|
|
515
|
-
const txInfo = {
|
|
516
|
-
origin: txRequest.origin,
|
|
517
|
-
functionSelector: txRequest.functionSelector,
|
|
518
|
-
simulatePublic: false,
|
|
519
|
-
chainId: txRequest.txContext.chainId,
|
|
520
|
-
version: txRequest.txContext.version,
|
|
521
|
-
authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
|
|
522
|
-
};
|
|
523
|
-
this.log.info(`Profiling transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
524
|
-
const syncTimer = new Timer();
|
|
525
|
-
await this.synchronizer.sync();
|
|
526
|
-
const syncTime = syncTimer.ms();
|
|
527
|
-
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
528
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest);
|
|
529
|
-
const { executionSteps, timings: { proving } = {} } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
530
|
-
simulate: skipProofGeneration,
|
|
531
|
-
skipFeeEnforcement: false,
|
|
532
|
-
profileMode
|
|
533
|
-
});
|
|
534
|
-
const totalTime = totalTimer.ms();
|
|
535
|
-
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>{
|
|
536
|
-
return {
|
|
537
|
-
functionName,
|
|
538
|
-
time: witgen,
|
|
539
|
-
oracles
|
|
540
|
-
};
|
|
541
|
-
});
|
|
542
|
-
// Gate computation is time is not relevant for profiling, so we subtract it from the total time.
|
|
543
|
-
const gateCountComputationTime = executionSteps.reduce((acc, { timings })=>acc + (timings.gateCount ?? 0), 0) ?? 0;
|
|
544
|
-
const total = totalTime - gateCountComputationTime;
|
|
545
|
-
const timings = {
|
|
546
|
-
total,
|
|
547
|
-
sync: syncTime,
|
|
548
|
-
proving,
|
|
549
|
-
perFunction,
|
|
550
|
-
unaccounted: total - ((syncTime ?? 0) + (proving ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
551
|
-
};
|
|
552
|
-
const simulatorStats = contractFunctionSimulator.getStats();
|
|
553
|
-
return new TxProfileResult(executionSteps, {
|
|
554
|
-
timings,
|
|
555
|
-
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
556
|
-
});
|
|
557
|
-
} catch (err) {
|
|
558
|
-
throw this.#contextualizeError(err, inspect(txRequest), `profileMode=${profileMode}`);
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
// TODO(#7456) Prevent msgSender being defined here for the first call
|
|
563
|
-
simulateTx(txRequest, simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes) {
|
|
564
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
565
|
-
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
566
|
-
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
567
|
-
return this.#putInJobQueue(async ()=>{
|
|
568
|
-
try {
|
|
569
|
-
const totalTimer = new Timer();
|
|
570
|
-
const txInfo = {
|
|
571
|
-
origin: txRequest.origin,
|
|
572
|
-
functionSelector: txRequest.functionSelector,
|
|
573
|
-
simulatePublic,
|
|
574
|
-
chainId: txRequest.txContext.chainId,
|
|
575
|
-
version: txRequest.txContext.version,
|
|
576
|
-
authWitnesses: txRequest.authWitnesses.map((w)=>w.requestHash)
|
|
577
|
-
};
|
|
578
|
-
this.log.info(`Simulating transaction execution request to ${txRequest.functionSelector} at ${txRequest.origin}`, txInfo);
|
|
579
|
-
const syncTimer = new Timer();
|
|
580
|
-
await this.synchronizer.sync();
|
|
581
|
-
const syncTime = syncTimer.ms();
|
|
582
|
-
const contractFunctionSimulator = this.#getSimulatorForTx(overrides);
|
|
583
|
-
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
584
|
-
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
585
|
-
// or not.
|
|
586
|
-
const skipKernels = overrides?.contracts !== undefined && Object.keys(overrides.contracts ?? {}).length > 0;
|
|
587
|
-
// Execution of private functions only; no proving, and no kernel logic.
|
|
588
|
-
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes);
|
|
589
|
-
let publicInputs;
|
|
590
|
-
let executionSteps = [];
|
|
591
|
-
if (skipKernels) {
|
|
592
|
-
// According to the protocol rules, the nonce generator for the note hashes
|
|
593
|
-
// can either be the first nullifier in the tx or the hash of the initial tx request
|
|
594
|
-
// if there are none.
|
|
595
|
-
const nonceGenerator = privateExecutionResult.firstNullifier.equals(Fr.ZERO) ? await txRequest.toTxRequest().hash() : privateExecutionResult.firstNullifier;
|
|
596
|
-
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(privateExecutionResult, nonceGenerator, this.contractDataProvider));
|
|
597
|
-
} else {
|
|
598
|
-
// Kernel logic, plus proving of all private functions and kernels.
|
|
599
|
-
({ publicInputs, executionSteps } = await this.#prove(txRequest, this.proofCreator, privateExecutionResult, {
|
|
600
|
-
simulate: true,
|
|
601
|
-
skipFeeEnforcement,
|
|
602
|
-
profileMode: 'none'
|
|
603
|
-
}));
|
|
604
|
-
}
|
|
605
|
-
const privateSimulationResult = new PrivateSimulationResult(privateExecutionResult, publicInputs);
|
|
606
|
-
const simulatedTx = await privateSimulationResult.toSimulatedTx();
|
|
607
|
-
let publicSimulationTime;
|
|
608
|
-
let publicOutput;
|
|
609
|
-
if (simulatePublic && publicInputs.forPublic) {
|
|
610
|
-
const publicSimulationTimer = new Timer();
|
|
611
|
-
publicOutput = await this.#simulatePublicCalls(simulatedTx, skipFeeEnforcement);
|
|
612
|
-
publicSimulationTime = publicSimulationTimer.ms();
|
|
613
|
-
}
|
|
614
|
-
let validationTime;
|
|
615
|
-
if (!skipTxValidation) {
|
|
616
|
-
const validationTimer = new Timer();
|
|
617
|
-
const validationResult = await this.node.isValidTx(simulatedTx, {
|
|
618
|
-
isSimulation: true,
|
|
619
|
-
skipFeeEnforcement
|
|
620
|
-
});
|
|
621
|
-
validationTime = validationTimer.ms();
|
|
622
|
-
if (validationResult.result === 'invalid') {
|
|
623
|
-
throw new Error('The simulated transaction is unable to be added to state and is invalid.');
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
const txHash = simulatedTx.getTxHash();
|
|
627
|
-
const totalTime = totalTimer.ms();
|
|
628
|
-
const perFunction = executionSteps.map(({ functionName, timings: { witgen, oracles } })=>({
|
|
629
|
-
functionName,
|
|
630
|
-
time: witgen,
|
|
631
|
-
oracles
|
|
632
|
-
}));
|
|
633
|
-
const timings = {
|
|
634
|
-
total: totalTime,
|
|
635
|
-
sync: syncTime,
|
|
636
|
-
publicSimulation: publicSimulationTime,
|
|
637
|
-
validation: validationTime,
|
|
638
|
-
perFunction,
|
|
639
|
-
unaccounted: totalTime - (syncTime + (publicSimulationTime ?? 0) + (validationTime ?? 0) + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
640
|
-
};
|
|
641
|
-
this.log.info(`Simulation completed for ${txHash.toString()} in ${totalTime}ms`, {
|
|
642
|
-
txHash,
|
|
643
|
-
...txInfo,
|
|
644
|
-
...publicOutput ? {
|
|
645
|
-
gasUsed: publicOutput.gasUsed,
|
|
646
|
-
revertCode: publicOutput.txEffect.revertCode.getCode(),
|
|
647
|
-
revertReason: publicOutput.revertReason
|
|
648
|
-
} : {}
|
|
649
|
-
});
|
|
650
|
-
const simulatorStats = contractFunctionSimulator.getStats();
|
|
651
|
-
return TxSimulationResult.fromPrivateSimulationResultAndPublicOutput(privateSimulationResult, publicOutput, {
|
|
652
|
-
timings,
|
|
653
|
-
nodeRPCCalls: simulatorStats.nodeRPCCalls
|
|
654
|
-
});
|
|
655
|
-
} catch (err) {
|
|
656
|
-
throw this.#contextualizeError(err, inspect(txRequest), `simulatePublic=${simulatePublic}`, `skipTxValidation=${skipTxValidation}`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
async sendTx(tx) {
|
|
661
|
-
const txHash = tx.getTxHash();
|
|
662
|
-
if (await this.node.getTxEffect(txHash)) {
|
|
663
|
-
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
664
|
-
}
|
|
665
|
-
this.log.debug(`Sending transaction ${txHash}`);
|
|
666
|
-
await this.node.sendTx(tx).catch((err)=>{
|
|
667
|
-
throw this.#contextualizeError(err, inspect(tx));
|
|
668
|
-
});
|
|
669
|
-
this.log.info(`Sent transaction ${txHash}`);
|
|
670
|
-
return txHash;
|
|
671
|
-
}
|
|
672
|
-
simulateUtility(functionName, args, to, authwits, _from, scopes) {
|
|
673
|
-
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
674
|
-
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
675
|
-
// delete the same read value, or reading values that another simulation is currently modifying).
|
|
676
|
-
return this.#putInJobQueue(async ()=>{
|
|
677
|
-
try {
|
|
678
|
-
const totalTimer = new Timer();
|
|
679
|
-
const syncTimer = new Timer();
|
|
680
|
-
await this.synchronizer.sync();
|
|
681
|
-
const syncTime = syncTimer.ms();
|
|
682
|
-
// TODO - Should check if `from` has the permission to call the view function.
|
|
683
|
-
const functionCall = await this.#getFunctionCall(functionName, args, to);
|
|
684
|
-
const functionTimer = new Timer();
|
|
685
|
-
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
686
|
-
const executionResult = await this.#simulateUtility(contractFunctionSimulator, functionCall, authwits ?? [], scopes);
|
|
687
|
-
const functionTime = functionTimer.ms();
|
|
688
|
-
const totalTime = totalTimer.ms();
|
|
689
|
-
const perFunction = [
|
|
690
|
-
{
|
|
691
|
-
functionName,
|
|
692
|
-
time: functionTime
|
|
693
|
-
}
|
|
694
|
-
];
|
|
695
|
-
const timings = {
|
|
696
|
-
total: totalTime,
|
|
697
|
-
sync: syncTime,
|
|
698
|
-
perFunction,
|
|
699
|
-
unaccounted: totalTime - (syncTime + perFunction.reduce((acc, { time })=>acc + time, 0))
|
|
700
|
-
};
|
|
701
|
-
const simulationStats = contractFunctionSimulator.getStats();
|
|
702
|
-
return {
|
|
703
|
-
result: executionResult,
|
|
704
|
-
stats: {
|
|
705
|
-
timings,
|
|
706
|
-
nodeRPCCalls: simulationStats.nodeRPCCalls
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
} catch (err) {
|
|
710
|
-
const stringifiedArgs = args.map((arg)=>arg.toString()).join(', ');
|
|
711
|
-
throw this.#contextualizeError(err, `simulateUtility ${to}:${functionName}(${stringifiedArgs})`, `scopes=${scopes?.map((s)=>s.toString()).join(', ') ?? 'undefined'}`);
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
async getNodeInfo() {
|
|
716
|
-
// This assumes we're connected to a single node, so we cache the info to avoid repeated calls.
|
|
717
|
-
// Load balancers and a myriad other configurations can break this assumption, so review this!
|
|
718
|
-
// Temporary measure to avoid hammering full nodes with requests on testnet.
|
|
719
|
-
if (!this.#nodeInfo) {
|
|
720
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
721
|
-
this.node.getNodeVersion(),
|
|
722
|
-
this.node.getVersion(),
|
|
723
|
-
this.node.getChainId(),
|
|
724
|
-
this.node.getEncodedEnr(),
|
|
725
|
-
this.node.getL1ContractAddresses(),
|
|
726
|
-
this.node.getProtocolContractAddresses()
|
|
727
|
-
]);
|
|
728
|
-
this.#nodeInfo = {
|
|
729
|
-
nodeVersion,
|
|
730
|
-
l1ChainId: chainId,
|
|
731
|
-
rollupVersion,
|
|
732
|
-
enr,
|
|
733
|
-
l1ContractAddresses: contractAddresses,
|
|
734
|
-
protocolContractAddresses: protocolContractAddresses
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
return this.#nodeInfo;
|
|
738
|
-
}
|
|
739
|
-
getPXEInfo() {
|
|
740
|
-
return Promise.resolve({
|
|
741
|
-
pxeVersion: this.packageVersion,
|
|
742
|
-
protocolContractAddresses: {
|
|
743
|
-
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
744
|
-
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
745
|
-
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
746
|
-
multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
async getPrivateEvents(contractAddress, eventMetadataDef, from, numBlocks, recipients) {
|
|
751
|
-
if (recipients.length === 0) {
|
|
752
|
-
throw new Error('Recipients are required to get private events');
|
|
753
|
-
}
|
|
754
|
-
this.log.verbose(`Getting private events for ${contractAddress.toString()} from ${from} to ${from + numBlocks}`);
|
|
755
|
-
// We need to manually trigger private state sync to have a guarantee that all the events are available.
|
|
756
|
-
await this.simulateUtility('sync_private_state', [], contractAddress);
|
|
757
|
-
const events = await this.privateEventDataProvider.getPrivateEvents(contractAddress, from, numBlocks, recipients, eventMetadataDef.eventSelector);
|
|
758
|
-
const decodedEvents = events.map((event)=>decodeFromAbi([
|
|
759
|
-
eventMetadataDef.abiType
|
|
760
|
-
], event));
|
|
761
|
-
return decodedEvents;
|
|
762
|
-
}
|
|
763
|
-
async getPublicEvents(eventMetadataDef, from, limit) {
|
|
764
|
-
const { logs } = await this.node.getPublicLogs({
|
|
765
|
-
fromBlock: from,
|
|
766
|
-
toBlock: from + limit
|
|
767
|
-
});
|
|
768
|
-
const decodedEvents = logs.map((log)=>{
|
|
769
|
-
// +1 for the event selector
|
|
770
|
-
const expectedLength = eventMetadataDef.fieldNames.length + 1;
|
|
771
|
-
if (log.log.emittedLength !== expectedLength) {
|
|
772
|
-
throw new Error(`Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length. Expected ${expectedLength}. Got ${log.log.emittedLength}.`);
|
|
773
|
-
}
|
|
774
|
-
const logFields = log.log.getEmittedFields();
|
|
775
|
-
// We are assuming here that event logs are the last 4 bytes of the event. This is not enshrined but is a function of aztec.nr raw log emission.
|
|
776
|
-
if (!EventSelector.fromField(logFields[logFields.length - 1]).equals(eventMetadataDef.eventSelector)) {
|
|
777
|
-
return undefined;
|
|
778
|
-
}
|
|
779
|
-
return decodeFromAbi([
|
|
780
|
-
eventMetadataDef.abiType
|
|
781
|
-
], log.log.fields);
|
|
782
|
-
}).filter((log)=>log !== undefined);
|
|
783
|
-
return decodedEvents;
|
|
784
|
-
}
|
|
785
|
-
async resetNoteSyncData() {
|
|
786
|
-
return await this.taggingDataProvider.resetNoteSyncData();
|
|
787
|
-
}
|
|
788
|
-
stop() {
|
|
789
|
-
return this.jobQueue.end();
|
|
790
|
-
}
|
|
791
|
-
}
|