From eed3b12b724e5286debccdf8bbfb29676440af03 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Mon, 27 Jan 2025 12:50:43 +0200 Subject: [PATCH] refactor(starknet_os): move hint implementation functions into separate folder --- crates/starknet_os/src/hints.rs | 19 +------- .../starknet_os/src/hints/enum_definition.rs | 45 +++++++++++-------- .../src/hints/hint_implementation.rs | 18 ++++++++ .../block_context.rs | 0 .../{ => hint_implementation}/bls_field.rs | 0 .../{ => hint_implementation}/builtins.rs | 0 .../compiled_class.rs | 0 .../deprecated_compiled_class.rs | 0 .../execute_transactions.rs | 0 .../{ => hint_implementation}/execution.rs | 0 .../{ => hint_implementation}/find_element.rs | 0 .../hints/{ => hint_implementation}/kzg.rs | 0 .../hints/{ => hint_implementation}/math.rs | 0 .../src/hints/{ => hint_implementation}/os.rs | 0 .../hints/{ => hint_implementation}/output.rs | 0 .../{ => hint_implementation}/patricia.rs | 0 .../hints/{ => hint_implementation}/secp.rs | 0 .../hints/{ => hint_implementation}/state.rs | 0 .../stateless_compression.rs | 0 .../{ => hint_implementation}/syscalls.rs | 0 .../transaction_hash.rs | 0 21 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 crates/starknet_os/src/hints/hint_implementation.rs rename crates/starknet_os/src/hints/{ => hint_implementation}/block_context.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/bls_field.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/builtins.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/compiled_class.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/deprecated_compiled_class.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/execute_transactions.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/execution.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/find_element.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/kzg.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/math.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/os.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/output.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/patricia.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/secp.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/state.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/stateless_compression.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/syscalls.rs (100%) rename crates/starknet_os/src/hints/{ => hint_implementation}/transaction_hash.rs (100%) diff --git a/crates/starknet_os/src/hints.rs b/crates/starknet_os/src/hints.rs index e124a27d417..6ae3d2f4fa8 100644 --- a/crates/starknet_os/src/hints.rs +++ b/crates/starknet_os/src/hints.rs @@ -1,22 +1,5 @@ -pub mod block_context; -pub mod bls_field; -pub mod builtins; -pub mod compiled_class; -pub mod deprecated_compiled_class; pub mod enum_definition; pub mod enum_generation; pub mod error; -pub mod execute_transactions; -pub mod execution; -pub mod find_element; -pub mod kzg; -pub mod math; -pub mod os; -pub mod output; -pub mod patricia; -pub mod secp; -pub mod state; -pub mod stateless_compression; -pub mod syscalls; -pub mod transaction_hash; +pub mod hint_implementation; pub mod types; diff --git a/crates/starknet_os/src/hints/enum_definition.rs b/crates/starknet_os/src/hints/enum_definition.rs index 1881abf8c72..5262c5be1a9 100644 --- a/crates/starknet_os/src/hints/enum_definition.rs +++ b/crates/starknet_os/src/hints/enum_definition.rs @@ -7,7 +7,8 @@ use cairo_vm::vm::vm_core::VirtualMachine; use indoc::indoc; use starknet_types_core::felt::Felt; -use crate::hints::block_context::{ +use crate::hints::error::{HintExtensionResult, HintResult, OsHintError}; +use crate::hints::hint_implementation::block_context::{ block_number, block_timestamp, bytecode_segment_structure, @@ -24,21 +25,24 @@ use crate::hints::block_context::{ sequencer_address, write_use_kzg_da_to_memory, }; -use crate::hints::bls_field::compute_ids_low; -use crate::hints::builtins::{select_builtin, selected_builtins, update_builtin_ptrs}; -use crate::hints::compiled_class::{ +use crate::hints::hint_implementation::bls_field::compute_ids_low; +use crate::hints::hint_implementation::builtins::{ + select_builtin, + selected_builtins, + update_builtin_ptrs, +}; +use crate::hints::hint_implementation::compiled_class::{ assert_end_of_bytecode_segments, assign_bytecode_segments, iter_current_segment_info, set_ap_to_segment_hash, }; -use crate::hints::deprecated_compiled_class::{ +use crate::hints::hint_implementation::deprecated_compiled_class::{ load_deprecated_class, load_deprecated_class_facts, load_deprecated_class_inner, }; -use crate::hints::error::{HintExtensionResult, HintResult, OsHintError}; -use crate::hints::execute_transactions::{ +use crate::hints::hint_implementation::execute_transactions::{ fill_holes_in_rc96_segment, log_remaining_txs, set_component_hashes, @@ -46,7 +50,7 @@ use crate::hints::execute_transactions::{ sha2_finalize, start_tx_validate_declare_execution_context, }; -use crate::hints::execution::{ +use crate::hints::hint_implementation::execution::{ add_relocation_rule, assert_transaction_hash, cache_contract_storage_request_key, @@ -108,22 +112,22 @@ use crate::hints::execution::{ write_syscall_result, write_syscall_result_deprecated, }; -use crate::hints::find_element::search_sorted_optimistic; -use crate::hints::kzg::store_da_segment; -use crate::hints::math::log2_ceil; -use crate::hints::os::{ +use crate::hints::hint_implementation::find_element::search_sorted_optimistic; +use crate::hints::hint_implementation::kzg::store_da_segment; +use crate::hints::hint_implementation::math::log2_ceil; +use crate::hints::hint_implementation::os::{ configure_kzg_manager, set_ap_to_new_block_hash, set_ap_to_prev_block_hash, write_full_output_to_memory, }; -use crate::hints::output::{ +use crate::hints::hint_implementation::output::{ set_compressed_start, set_n_updates_small, set_state_updates_start, set_tree_structure, }; -use crate::hints::patricia::{ +use crate::hints::hint_implementation::patricia::{ assert_case_is_right, build_descent_map, height_is_zero_or_len_node_preimage_is_two, @@ -135,8 +139,8 @@ use crate::hints::patricia::{ split_descend, write_case_not_left_to_ap, }; -use crate::hints::secp::read_ec_point_from_address; -use crate::hints::state::{ +use crate::hints::hint_implementation::secp::read_ec_point_from_address; +use crate::hints::hint_implementation::state::{ decode_node, enter_scope_commitment_info_by_address, load_bottom, @@ -146,13 +150,13 @@ use crate::hints::state::{ set_preimage_for_state_commitments, write_split_result, }; -use crate::hints::stateless_compression::{ +use crate::hints::hint_implementation::stateless_compression::{ compression_hint, dictionary_from_bucket, get_prev_offset, set_decompressed_dst, }; -use crate::hints::syscalls::{ +use crate::hints::hint_implementation::syscalls::{ call_contract, delegate_call, delegate_l1_handler, @@ -206,7 +210,10 @@ use crate::hints::syscalls::{ storage_read, storage_write, }; -use crate::hints::transaction_hash::{additional_data_new_segment, data_to_hash_new_segment}; +use crate::hints::hint_implementation::transaction_hash::{ + additional_data_new_segment, + data_to_hash_new_segment, +}; use crate::hints::types::{HintEnum, HintExtensionImplementation, HintImplementation}; use crate::{define_hint_enum, define_hint_extension_enum}; diff --git a/crates/starknet_os/src/hints/hint_implementation.rs b/crates/starknet_os/src/hints/hint_implementation.rs new file mode 100644 index 00000000000..ff2e472c996 --- /dev/null +++ b/crates/starknet_os/src/hints/hint_implementation.rs @@ -0,0 +1,18 @@ +pub mod block_context; +pub mod bls_field; +pub mod builtins; +pub mod compiled_class; +pub mod deprecated_compiled_class; +pub mod execute_transactions; +pub mod execution; +pub mod find_element; +pub mod kzg; +pub mod math; +pub mod os; +pub mod output; +pub mod patricia; +pub mod secp; +pub mod state; +pub mod stateless_compression; +pub mod syscalls; +pub mod transaction_hash; diff --git a/crates/starknet_os/src/hints/block_context.rs b/crates/starknet_os/src/hints/hint_implementation/block_context.rs similarity index 100% rename from crates/starknet_os/src/hints/block_context.rs rename to crates/starknet_os/src/hints/hint_implementation/block_context.rs diff --git a/crates/starknet_os/src/hints/bls_field.rs b/crates/starknet_os/src/hints/hint_implementation/bls_field.rs similarity index 100% rename from crates/starknet_os/src/hints/bls_field.rs rename to crates/starknet_os/src/hints/hint_implementation/bls_field.rs diff --git a/crates/starknet_os/src/hints/builtins.rs b/crates/starknet_os/src/hints/hint_implementation/builtins.rs similarity index 100% rename from crates/starknet_os/src/hints/builtins.rs rename to crates/starknet_os/src/hints/hint_implementation/builtins.rs diff --git a/crates/starknet_os/src/hints/compiled_class.rs b/crates/starknet_os/src/hints/hint_implementation/compiled_class.rs similarity index 100% rename from crates/starknet_os/src/hints/compiled_class.rs rename to crates/starknet_os/src/hints/hint_implementation/compiled_class.rs diff --git a/crates/starknet_os/src/hints/deprecated_compiled_class.rs b/crates/starknet_os/src/hints/hint_implementation/deprecated_compiled_class.rs similarity index 100% rename from crates/starknet_os/src/hints/deprecated_compiled_class.rs rename to crates/starknet_os/src/hints/hint_implementation/deprecated_compiled_class.rs diff --git a/crates/starknet_os/src/hints/execute_transactions.rs b/crates/starknet_os/src/hints/hint_implementation/execute_transactions.rs similarity index 100% rename from crates/starknet_os/src/hints/execute_transactions.rs rename to crates/starknet_os/src/hints/hint_implementation/execute_transactions.rs diff --git a/crates/starknet_os/src/hints/execution.rs b/crates/starknet_os/src/hints/hint_implementation/execution.rs similarity index 100% rename from crates/starknet_os/src/hints/execution.rs rename to crates/starknet_os/src/hints/hint_implementation/execution.rs diff --git a/crates/starknet_os/src/hints/find_element.rs b/crates/starknet_os/src/hints/hint_implementation/find_element.rs similarity index 100% rename from crates/starknet_os/src/hints/find_element.rs rename to crates/starknet_os/src/hints/hint_implementation/find_element.rs diff --git a/crates/starknet_os/src/hints/kzg.rs b/crates/starknet_os/src/hints/hint_implementation/kzg.rs similarity index 100% rename from crates/starknet_os/src/hints/kzg.rs rename to crates/starknet_os/src/hints/hint_implementation/kzg.rs diff --git a/crates/starknet_os/src/hints/math.rs b/crates/starknet_os/src/hints/hint_implementation/math.rs similarity index 100% rename from crates/starknet_os/src/hints/math.rs rename to crates/starknet_os/src/hints/hint_implementation/math.rs diff --git a/crates/starknet_os/src/hints/os.rs b/crates/starknet_os/src/hints/hint_implementation/os.rs similarity index 100% rename from crates/starknet_os/src/hints/os.rs rename to crates/starknet_os/src/hints/hint_implementation/os.rs diff --git a/crates/starknet_os/src/hints/output.rs b/crates/starknet_os/src/hints/hint_implementation/output.rs similarity index 100% rename from crates/starknet_os/src/hints/output.rs rename to crates/starknet_os/src/hints/hint_implementation/output.rs diff --git a/crates/starknet_os/src/hints/patricia.rs b/crates/starknet_os/src/hints/hint_implementation/patricia.rs similarity index 100% rename from crates/starknet_os/src/hints/patricia.rs rename to crates/starknet_os/src/hints/hint_implementation/patricia.rs diff --git a/crates/starknet_os/src/hints/secp.rs b/crates/starknet_os/src/hints/hint_implementation/secp.rs similarity index 100% rename from crates/starknet_os/src/hints/secp.rs rename to crates/starknet_os/src/hints/hint_implementation/secp.rs diff --git a/crates/starknet_os/src/hints/state.rs b/crates/starknet_os/src/hints/hint_implementation/state.rs similarity index 100% rename from crates/starknet_os/src/hints/state.rs rename to crates/starknet_os/src/hints/hint_implementation/state.rs diff --git a/crates/starknet_os/src/hints/stateless_compression.rs b/crates/starknet_os/src/hints/hint_implementation/stateless_compression.rs similarity index 100% rename from crates/starknet_os/src/hints/stateless_compression.rs rename to crates/starknet_os/src/hints/hint_implementation/stateless_compression.rs diff --git a/crates/starknet_os/src/hints/syscalls.rs b/crates/starknet_os/src/hints/hint_implementation/syscalls.rs similarity index 100% rename from crates/starknet_os/src/hints/syscalls.rs rename to crates/starknet_os/src/hints/hint_implementation/syscalls.rs diff --git a/crates/starknet_os/src/hints/transaction_hash.rs b/crates/starknet_os/src/hints/hint_implementation/transaction_hash.rs similarity index 100% rename from crates/starknet_os/src/hints/transaction_hash.rs rename to crates/starknet_os/src/hints/hint_implementation/transaction_hash.rs