Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
Browse files Browse the repository at this point in the history
…ename-declare
  • Loading branch information
fmoletta committed Feb 8, 2024
2 parents 62b19c2 + 0436d04 commit 09794d9
Show file tree
Hide file tree
Showing 53 changed files with 176 additions and 191 deletions.
4 changes: 2 additions & 2 deletions bench/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use starknet_in_rust::{
in_memory_state_reader::InMemoryStateReader, state_api::State,
},
transaction::{
declare_deprecated::DeclareDeprecated, Address, Deploy, DeployAccount, InvokeFunction,
declare_deprecated::DeclareDeprecated, Address, ClassHash, Deploy, DeployAccount,
InvokeFunction,
},
utils::ClassHash,
};
use std::{hint::black_box, sync::Arc};

Expand Down
5 changes: 3 additions & 2 deletions bench/yas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
#[cfg(feature = "cairo-native")]
use {
cairo_native::cache::{AotProgramCache, JitProgramCache, ProgramCache},
starknet_in_rust::utils::{get_native_context, ClassHash},
starknet_in_rust::transaction::ClassHash,
starknet_in_rust::utils::get_native_context,
std::{cell::RefCell, rc::Rc},
};

Expand Down Expand Up @@ -988,7 +989,7 @@ mod utils {
in_memory_state_reader::InMemoryStateReader, state_api::State,
},
transaction::Address,
utils::ClassHash,
transaction::ClassHash,
CasmContractClass, ContractClass as SierraContractClass,
};
use std::{fs, path::Path, sync::Arc};
Expand Down
4 changes: 2 additions & 2 deletions examples/lru_cache/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use starknet_in_rust::{
contract_class_cache::{ContractClassCache, PermanentContractClassCache},
in_memory_state_reader::InMemoryStateReader,
},
transaction::{Address, DeclareDeprecated, Deploy, InvokeFunction},
utils::{calculate_sn_keccak, ClassHash},
transaction::{Address, ClassHash, DeclareDeprecated, Deploy, InvokeFunction},
utils::calculate_sn_keccak,
};
use std::{
num::NonZeroUsize,
Expand Down
2 changes: 1 addition & 1 deletion fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate honggfuzz;

use cairo_vm::{vm::runners::cairo_runner::ExecutionResources, Felt252};
use starknet_in_rust::execution::execution_entry_point::ExecutionResult;
use starknet_in_rust::utils::ClassHash;
use starknet_in_rust::transaction::ClassHash;
use starknet_in_rust::EntryPointType;
use starknet_in_rust::{
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},
Expand Down
5 changes: 2 additions & 3 deletions rpc_state_reader/src/sir_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ use starknet_in_rust::{
BlockInfo,
},
transaction::{
declare_tx_from_sn_api_transaction, error::TransactionError, Address, DeployAccount,
InvokeFunction, L1Handler,
declare_tx_from_sn_api_transaction, error::TransactionError, Address, ClassHash,
DeployAccount, InvokeFunction, L1Handler,
},
utils::ClassHash,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cairo_vm::Felt252;
use lazy_static::lazy_static;

use starknet_in_rust::utils::ClassHash;
use starknet_in_rust::transaction::ClassHash;
use starknet_in_rust::{
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},
execution::{
Expand Down
3 changes: 1 addition & 2 deletions src/bin/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use starknet_in_rust::{
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader,
},
transaction::{Address, InvokeFunction, Transaction},
utils::ClassHash,
transaction::{Address, ClassHash, InvokeFunction, Transaction},
};
use std::{path::PathBuf, sync::Arc};

Expand Down
8 changes: 3 additions & 5 deletions src/bin/invoke_with_cachedstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ use starknet_in_rust::{
services::api::contract_classes::{
compiled_class::CompiledClass, deprecated_contract_class::ContractClass,
},
state::in_memory_state_reader::InMemoryStateReader,
state::{
cached_state::CachedState, contract_class_cache::PermanentContractClassCache, BlockInfo,
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader, BlockInfo,
},
transaction::Address,
transaction::{InvokeFunction, VersionSpecificAccountTxFields},
utils::ClassHash,
transaction::{Address, ClassHash, InvokeFunction, VersionSpecificAccountTxFields},
};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

Expand Down
3 changes: 1 addition & 2 deletions src/bin/native_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ use starknet_in_rust::{
},
state::cached_state::CachedState,
state::{in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager},
transaction::Address,
utils::ClassHash,
transaction::{Address, ClassHash},
};
use std::cell::RefCell;
use std::rc::Rc;
Expand Down
5 changes: 3 additions & 2 deletions src/core/errors/state_errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
services::api::contract_class_errors::ContractClassError, state::state_cache::StorageEntry,
transaction::Address, utils::ClassHash,
services::api::contract_class_errors::ContractClassError,
state::state_cache::StorageEntry,
transaction::{Address, ClassHash},
};
use starknet::core::types::FromByteArrayError;
use thiserror::Error;
Expand Down
5 changes: 2 additions & 3 deletions src/execution/execution_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ use crate::{
deprecated_syscall_handler::DeprecatedSyscallHintProcessor,
syscall_handler::SyscallHintProcessor,
},
transaction::{error::TransactionError, Address},
transaction::{error::TransactionError, Address, ClassHash},
utils::{
get_deployed_address_class_hash_at_address, parse_builtin_names,
validate_contract_deployed, ClassHash,
get_deployed_address_class_hash_at_address, parse_builtin_names, validate_contract_deployed,
},
};
use cairo_lang_sierra::program::Program as SierraProgram;
Expand Down
4 changes: 2 additions & 2 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
definitions::{constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR, transaction_type::TransactionType},
state::state_cache::StorageEntry,
syscalls::syscall_handler_errors::SyscallHandlerError,
transaction::{error::TransactionError, Address},
utils::{get_big_int, get_integer, get_relocatable, ClassHash},
transaction::{error::TransactionError, Address, ClassHash},
utils::{get_big_int, get_integer, get_relocatable},
};
use cairo_vm::Felt252;
use cairo_vm::{
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use cairo_lang_starknet::{

#[cfg(feature = "cairo-native")]
use {
crate::utils::ClassHash,
crate::transaction::ClassHash,
cairo_native::cache::ProgramCache,
std::{cell::RefCell, rc::Rc},
};
Expand Down Expand Up @@ -273,16 +273,15 @@ mod test {
ExecutionResourcesManager,
},
transaction::{
Address, Declare, DeclareDeprecated, Deploy, DeployAccount, InvokeFunction, L1Handler,
Transaction, VersionSpecificAccountTxFields,
Address, ClassHash, Declare, DeclareDeprecated, Deploy, DeployAccount, InvokeFunction,
L1Handler, Transaction, VersionSpecificAccountTxFields,
},
utils::{
felt_to_hash,
test_utils::{
create_account_tx_test_state, TEST_ACCOUNT_CONTRACT_ADDRESS,
TEST_FIB_COMPILED_CONTRACT_CLASS_HASH,
},
ClassHash,
},
};
use cairo_lang_starknet::{
Expand Down
4 changes: 2 additions & 2 deletions src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use crate::{
core::errors::state_errors::StateError,
services::api::contract_classes::compiled_class::CompiledClass,
state::StateDiff,
transaction::Address,
transaction::{Address, ClassHash},
utils::{
get_erc20_balance_var_addresses, subtract_mappings, subtract_mappings_keys,
to_cache_state_storage_mapping, ClassHash,
to_cache_state_storage_mapping,
},
};
use cairo_vm::Felt252;
Expand Down
4 changes: 3 additions & 1 deletion src/state/contract_class_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//! cache. It also contains a method to extend the shared cache from an iterator so that it can be
//! used with the private caches.
use crate::{services::api::contract_classes::compiled_class::CompiledClass, utils::ClassHash};
use crate::{
services::api::contract_classes::compiled_class::CompiledClass, transaction::ClassHash,
};
use std::{collections::HashMap, sync::RwLock};

/// The contract class cache trait, which must be implemented by all caches.
Expand Down
5 changes: 4 additions & 1 deletion src/state/contract_storage_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use super::{
contract_class_cache::ContractClassCache,
state_api::{State, StateReader},
};
use crate::{core::errors::state_errors::StateError, transaction::Address, utils::ClassHash};
use crate::{
core::errors::state_errors::StateError,
transaction::{Address, ClassHash},
};
use cairo_vm::Felt252;
use std::collections::HashSet;

Expand Down
3 changes: 1 addition & 2 deletions src/state/in_memory_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
state::{
cached_state::UNINITIALIZED_CLASS_HASH, state_api::StateReader, state_cache::StorageEntry,
},
transaction::Address,
utils::{ClassHash, CompiledClassHash},
transaction::{Address, ClassHash, CompiledClassHash},
};
use cairo_vm::Felt252;
use getset::{Getters, MutGetters};
Expand Down
10 changes: 3 additions & 7 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use self::{
use crate::{
core::errors::state_errors::StateError,
definitions::block_context::GasPrices,
transaction::{error::TransactionError, Address},
utils::{
get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping, ClassHash,
CompiledClassHash,
},
transaction::{error::TransactionError, Address, ClassHash, CompiledClassHash},
utils::{get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping},
};
use cairo_vm::{vm::runners::cairo_runner::ExecutionResources, Felt252};
use getset::Getters;
Expand Down Expand Up @@ -250,8 +247,7 @@ mod test {
state_api::StateReader,
state_cache::{StateCache, StorageEntry},
},
transaction::Address,
utils::ClassHash,
transaction::{Address, ClassHash},
};
use cairo_vm::Felt252;
use std::{collections::HashMap, sync::Arc};
Expand Down
4 changes: 2 additions & 2 deletions src/state/state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
definitions::block_context::{BlockContext, FeeType},
services::api::contract_classes::compiled_class::CompiledClass,
state::StateDiff,
transaction::Address,
utils::{get_erc20_balance_var_addresses, ClassHash, CompiledClassHash},
transaction::{Address, ClassHash, CompiledClassHash},
utils::get_erc20_balance_var_addresses,
};
use cairo_lang_utils::bigint::BigUintAsHex;
use cairo_vm::Felt252;
Expand Down
3 changes: 1 addition & 2 deletions src/state/state_cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
core::errors::state_errors::StateError,
transaction::Address,
utils::{ClassHash, CompiledClassHash},
transaction::{Address, ClassHash, CompiledClassHash},
};
use cairo_vm::Felt252;
use getset::{Getters, MutGetters};
Expand Down
4 changes: 2 additions & 2 deletions src/syscalls/business_logic_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use crate::{
state_api::{State, StateReader},
BlockInfo, ExecutionResourcesManager,
},
transaction::{error::TransactionError, Address},
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range, ClassHash},
transaction::{error::TransactionError, Address, ClassHash},
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range},
};
use cairo_vm::Felt252;
use cairo_vm::{
Expand Down
2 changes: 1 addition & 1 deletion src/syscalls/deprecated_business_logic_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
state_api::{State, StateReader},
BlockInfo, ExecutionResourcesManager,
},
transaction::{error::TransactionError, Address},
transaction::{error::TransactionError, Address, ClassHash},
utils::*,
};
use crate::{
Expand Down
14 changes: 6 additions & 8 deletions src/syscalls/deprecated_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,26 +269,24 @@ fn get_syscall_ptr(
#[cfg(test)]
mod tests {
use super::*;
use crate::services::api::contract_classes::compiled_class::CompiledClass;
use crate::services::api::contract_classes::deprecated_contract_class::EntryPointType;
use crate::state::StateDiff;
use crate::transaction::VersionSpecificAccountTxFields;
use crate::utils::ClassHash;
use crate::{
add_segments, allocate_selector, any_box,
definitions::{block_context::BlockContext, transaction_type::TransactionType},
execution::{OrderedEvent, OrderedL2ToL1Message, TransactionExecutionContext},
memory_insert,
services::api::contract_classes::deprecated_contract_class::ContractClass,
services::api::contract_classes::{
compiled_class::CompiledClass,
deprecated_contract_class::{ContractClass, EntryPointType},
},
state::{
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader, state_api::State,
in_memory_state_reader::InMemoryStateReader, state_api::State, StateDiff,
},
syscalls::deprecated_syscall_request::{
DeprecatedDeployRequest, DeprecatedSendMessageToL1SysCallRequest,
DeprecatedSyscallRequest,
},
transaction::{Address, InvokeFunction},
transaction::{Address, ClassHash, InvokeFunction, VersionSpecificAccountTxFields},
utils::{
get_big_int, get_integer, get_relocatable,
test_utils::{ids_data, vm},
Expand Down
4 changes: 2 additions & 2 deletions src/syscalls/native_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
business_logic_syscall_handler::{KECCAK_ROUND_COST, SYSCALL_BASE, SYSCALL_GAS_COST},
syscall_handler_errors::SyscallHandlerError,
},
transaction::{error::TransactionError, Address},
utils::{felt_to_hash, ClassHash},
transaction::{error::TransactionError, Address, ClassHash},
utils::felt_to_hash,
ContractClassCache, EntryPointType,
};
use cairo_native::starknet::{ResourceBounds, TxV2Info};
Expand Down
11 changes: 6 additions & 5 deletions src/transaction/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::services::api::contract_classes::deprecated_contract_class::EntryPoin
use crate::services::api::contract_classes::compiled_class::CompiledClass;
use crate::state::cached_state::CachedState;
use crate::state::contract_class_cache::ContractClassCache;
use crate::utils::ClassHash;
use crate::{
core::transaction_hash::calculate_declare_transaction_hash,
definitions::{
Expand All @@ -23,10 +22,13 @@ use crate::{
execution_entry_point::ExecutionEntryPoint, CallType, TransactionExecutionContext,
TransactionExecutionInfo,
},
state::state_api::{State, StateReader},
state::ExecutionResourcesManager,
state::{
state_api::{State, StateReader},
ExecutionResourcesManager,
},
transaction::{
error::TransactionError, invoke_function::verify_no_calls_to_other_contracts, Address,
ClassHash,
},
utils::calculate_tx_resources,
};
Expand Down Expand Up @@ -603,13 +605,12 @@ mod tests {
use crate::services::api::contract_classes::compiled_class::CompiledClass;
use crate::state::state_api::StateReader;
use crate::transaction::error::TransactionError;
use crate::utils::ClassHash;
use crate::{
state::{
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader,
},
transaction::Address,
transaction::{Address, ClassHash},
};
use cairo_lang_starknet::casm_contract_class::CasmContractClass;
use cairo_vm::Felt252;
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/declare_deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use crate::{
},
state::ExecutionResourcesManager,
transaction::error::TransactionError,
utils::{calculate_tx_resources, felt_to_hash, verify_no_calls_to_other_contracts, ClassHash},
utils::{calculate_tx_resources, felt_to_hash, verify_no_calls_to_other_contracts},
};
use cairo_vm::Felt252;
use num_traits::Zero;

use super::fee::{
calculate_tx_fee, charge_fee, estimate_minimal_l1_gas, run_post_execution_fee_checks,
};
use super::{get_tx_version, Address, Transaction};
use super::{get_tx_version, Address, ClassHash, Transaction};
use std::fmt::Debug;
use std::sync::Arc;

Expand Down
Loading

0 comments on commit 09794d9

Please sign in to comment.