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

Commit 0436d04

Browse files
authored
Move ClassHash into transaction module (#1232)
* Move ClassHash into transaction module * fmt
1 parent 8f9b552 commit 0436d04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+169
-184
lines changed

bench/internals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use starknet_in_rust::{
1818
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
1919
in_memory_state_reader::InMemoryStateReader, state_api::State,
2020
},
21+
transaction::ClassHash,
2122
transaction::{declare::Declare, Address, Deploy, DeployAccount, InvokeFunction},
22-
utils::ClassHash,
2323
};
2424
use std::{hint::black_box, sync::Arc};
2525

bench/yas.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
3333
#[cfg(feature = "cairo-native")]
3434
use {
3535
cairo_native::cache::{AotProgramCache, JitProgramCache, ProgramCache},
36-
starknet_in_rust::utils::{get_native_context, ClassHash},
36+
starknet_in_rust::transaction::ClassHash,
37+
starknet_in_rust::utils::get_native_context,
3738
std::{cell::RefCell, rc::Rc},
3839
};
3940

@@ -989,7 +990,7 @@ mod utils {
989990
in_memory_state_reader::InMemoryStateReader, state_api::State,
990991
},
991992
transaction::Address,
992-
utils::ClassHash,
993+
transaction::ClassHash,
993994
CasmContractClass, ContractClass as SierraContractClass,
994995
};
995996
use std::{fs, path::Path, sync::Arc};

examples/lru_cache/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use starknet_in_rust::{
1212
contract_class_cache::{ContractClassCache, PermanentContractClassCache},
1313
in_memory_state_reader::InMemoryStateReader,
1414
},
15-
transaction::{Address, Declare, Deploy, InvokeFunction},
16-
utils::{calculate_sn_keccak, ClassHash},
15+
transaction::{Address, ClassHash, Declare, Deploy, InvokeFunction},
16+
utils::calculate_sn_keccak,
1717
};
1818
use std::{
1919
num::NonZeroUsize,

fuzzer/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate honggfuzz;
55

66
use cairo_vm::{vm::runners::cairo_runner::ExecutionResources, Felt252};
77
use starknet_in_rust::execution::execution_entry_point::ExecutionResult;
8-
use starknet_in_rust::utils::ClassHash;
8+
use starknet_in_rust::transaction::ClassHash;
99
use starknet_in_rust::EntryPointType;
1010
use starknet_in_rust::{
1111
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},

rpc_state_reader/src/sir_state_reader.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ use starknet_in_rust::{
2828
BlockInfo,
2929
},
3030
transaction::{
31-
declare_tx_from_sn_api_transaction, error::TransactionError, Address, DeployAccount,
32-
InvokeFunction, L1Handler,
31+
declare_tx_from_sn_api_transaction, error::TransactionError, Address, ClassHash,
32+
DeployAccount, InvokeFunction, L1Handler,
3333
},
34-
utils::ClassHash,
3534
};
3635

3736
use crate::{

src/bin/fibonacci.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cairo_vm::Felt252;
22
use lazy_static::lazy_static;
33

4-
use starknet_in_rust::utils::ClassHash;
4+
use starknet_in_rust::transaction::ClassHash;
55
use starknet_in_rust::{
66
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},
77
execution::{

src/bin/invoke.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use starknet_in_rust::{
1010
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
1111
in_memory_state_reader::InMemoryStateReader,
1212
},
13-
transaction::{Address, InvokeFunction, Transaction},
14-
utils::ClassHash,
13+
transaction::{Address, ClassHash, InvokeFunction, Transaction},
1514
};
1615
use std::{path::PathBuf, sync::Arc};
1716

src/bin/invoke_with_cachedstate.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ use starknet_in_rust::{
99
services::api::contract_classes::{
1010
compiled_class::CompiledClass, deprecated_contract_class::ContractClass,
1111
},
12-
state::in_memory_state_reader::InMemoryStateReader,
1312
state::{
14-
cached_state::CachedState, contract_class_cache::PermanentContractClassCache, BlockInfo,
13+
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
14+
in_memory_state_reader::InMemoryStateReader, BlockInfo,
1515
},
16-
transaction::Address,
17-
transaction::{InvokeFunction, VersionSpecificAccountTxFields},
18-
utils::ClassHash,
16+
transaction::{Address, ClassHash, InvokeFunction, VersionSpecificAccountTxFields},
1917
};
2018
use std::{collections::HashMap, path::PathBuf, sync::Arc};
2119

src/bin/native_bench.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ use starknet_in_rust::{
3232
},
3333
state::cached_state::CachedState,
3434
state::{in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager},
35-
transaction::Address,
36-
utils::ClassHash,
35+
transaction::{Address, ClassHash},
3736
};
3837
use std::cell::RefCell;
3938
use std::rc::Rc;

src/core/errors/state_errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
2-
services::api::contract_class_errors::ContractClassError, state::state_cache::StorageEntry,
3-
transaction::Address, utils::ClassHash,
2+
services::api::contract_class_errors::ContractClassError,
3+
state::state_cache::StorageEntry,
4+
transaction::{Address, ClassHash},
45
};
56
use starknet::core::types::FromByteArrayError;
67
use thiserror::Error;

src/execution/execution_entry_point.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ use crate::{
2121
deprecated_syscall_handler::DeprecatedSyscallHintProcessor,
2222
syscall_handler::SyscallHintProcessor,
2323
},
24-
transaction::{error::TransactionError, Address},
24+
transaction::{error::TransactionError, Address, ClassHash},
2525
utils::{
26-
get_deployed_address_class_hash_at_address, parse_builtin_names,
27-
validate_contract_deployed, ClassHash,
26+
get_deployed_address_class_hash_at_address, parse_builtin_names, validate_contract_deployed,
2827
},
2928
};
3029
use cairo_lang_sierra::program::Program as SierraProgram;

src/execution/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
definitions::{constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR, transaction_type::TransactionType},
99
state::state_cache::StorageEntry,
1010
syscalls::syscall_handler_errors::SyscallHandlerError,
11-
transaction::{error::TransactionError, Address},
12-
utils::{get_big_int, get_integer, get_relocatable, ClassHash},
11+
transaction::{error::TransactionError, Address, ClassHash},
12+
utils::{get_big_int, get_integer, get_relocatable},
1313
};
1414
use cairo_vm::Felt252;
1515
use cairo_vm::{

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use cairo_lang_starknet::{
3737

3838
#[cfg(feature = "cairo-native")]
3939
use {
40-
crate::utils::ClassHash,
40+
crate::transaction::ClassHash,
4141
cairo_native::cache::ProgramCache,
4242
std::{cell::RefCell, rc::Rc},
4343
};
@@ -273,16 +273,15 @@ mod test {
273273
ExecutionResourcesManager,
274274
},
275275
transaction::{
276-
Address, Declare, DeclareV2, Deploy, DeployAccount, InvokeFunction, L1Handler,
277-
Transaction, VersionSpecificAccountTxFields,
276+
Address, ClassHash, Declare, DeclareV2, Deploy, DeployAccount, InvokeFunction,
277+
L1Handler, Transaction, VersionSpecificAccountTxFields,
278278
},
279279
utils::{
280280
felt_to_hash,
281281
test_utils::{
282282
create_account_tx_test_state, TEST_ACCOUNT_CONTRACT_ADDRESS,
283283
TEST_FIB_COMPILED_CONTRACT_CLASS_HASH,
284284
},
285-
ClassHash,
286285
},
287286
};
288287
use cairo_lang_starknet::{

src/state/cached_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use crate::{
77
core::errors::state_errors::StateError,
88
services::api::contract_classes::compiled_class::CompiledClass,
99
state::StateDiff,
10-
transaction::Address,
10+
transaction::{Address, ClassHash},
1111
utils::{
1212
get_erc20_balance_var_addresses, subtract_mappings, subtract_mappings_keys,
13-
to_cache_state_storage_mapping, ClassHash,
13+
to_cache_state_storage_mapping,
1414
},
1515
};
1616
use cairo_vm::Felt252;

src/state/contract_class_cache.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//! cache. It also contains a method to extend the shared cache from an iterator so that it can be
88
//! used with the private caches.
99
10-
use crate::{services::api::contract_classes::compiled_class::CompiledClass, utils::ClassHash};
10+
use crate::{
11+
services::api::contract_classes::compiled_class::CompiledClass, transaction::ClassHash,
12+
};
1113
use std::{collections::HashMap, sync::RwLock};
1214

1315
/// The contract class cache trait, which must be implemented by all caches.

src/state/contract_storage_state.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use super::{
33
contract_class_cache::ContractClassCache,
44
state_api::{State, StateReader},
55
};
6-
use crate::{core::errors::state_errors::StateError, transaction::Address, utils::ClassHash};
6+
use crate::{
7+
core::errors::state_errors::StateError,
8+
transaction::{Address, ClassHash},
9+
};
710
use cairo_vm::Felt252;
811
use std::collections::HashSet;
912

src/state/in_memory_state_reader.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use crate::{
44
state::{
55
cached_state::UNINITIALIZED_CLASS_HASH, state_api::StateReader, state_cache::StorageEntry,
66
},
7-
transaction::Address,
8-
utils::{ClassHash, CompiledClassHash},
7+
transaction::{Address, ClassHash, CompiledClassHash},
98
};
109
use cairo_vm::Felt252;
1110
use getset::{Getters, MutGetters};

src/state/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use self::{
55
use crate::{
66
core::errors::state_errors::StateError,
77
definitions::block_context::GasPrices,
8-
transaction::{error::TransactionError, Address},
9-
utils::{
10-
get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping, ClassHash,
11-
CompiledClassHash,
12-
},
8+
transaction::{error::TransactionError, Address, ClassHash, CompiledClassHash},
9+
utils::{get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping},
1310
};
1411
use cairo_vm::{vm::runners::cairo_runner::ExecutionResources, Felt252};
1512
use getset::Getters;
@@ -250,8 +247,7 @@ mod test {
250247
state_api::StateReader,
251248
state_cache::{StateCache, StorageEntry},
252249
},
253-
transaction::Address,
254-
utils::ClassHash,
250+
transaction::{Address, ClassHash},
255251
};
256252
use cairo_vm::Felt252;
257253
use std::{collections::HashMap, sync::Arc};

src/state/state_api.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
definitions::block_context::{BlockContext, FeeType},
55
services::api::contract_classes::compiled_class::CompiledClass,
66
state::StateDiff,
7-
transaction::Address,
8-
utils::{get_erc20_balance_var_addresses, ClassHash, CompiledClassHash},
7+
transaction::{Address, ClassHash, CompiledClassHash},
8+
utils::get_erc20_balance_var_addresses,
99
};
1010
use cairo_lang_utils::bigint::BigUintAsHex;
1111
use cairo_vm::Felt252;

src/state/state_cache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
core::errors::state_errors::StateError,
3-
transaction::Address,
4-
utils::{ClassHash, CompiledClassHash},
3+
transaction::{Address, ClassHash, CompiledClassHash},
54
};
65
use cairo_vm::Felt252;
76
use getset::{Getters, MutGetters};

src/syscalls/business_logic_syscall_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use crate::{
3636
state_api::{State, StateReader},
3737
BlockInfo, ExecutionResourcesManager,
3838
},
39-
transaction::{error::TransactionError, Address},
40-
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range, ClassHash},
39+
transaction::{error::TransactionError, Address, ClassHash},
40+
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range},
4141
};
4242
use cairo_vm::Felt252;
4343
use cairo_vm::{

src/syscalls/deprecated_business_logic_syscall_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
state_api::{State, StateReader},
3131
BlockInfo, ExecutionResourcesManager,
3232
},
33-
transaction::{error::TransactionError, Address},
33+
transaction::{error::TransactionError, Address, ClassHash},
3434
utils::*,
3535
};
3636
use crate::{

src/syscalls/deprecated_syscall_handler.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -269,26 +269,24 @@ fn get_syscall_ptr(
269269
#[cfg(test)]
270270
mod tests {
271271
use super::*;
272-
use crate::services::api::contract_classes::compiled_class::CompiledClass;
273-
use crate::services::api::contract_classes::deprecated_contract_class::EntryPointType;
274-
use crate::state::StateDiff;
275-
use crate::transaction::VersionSpecificAccountTxFields;
276-
use crate::utils::ClassHash;
277272
use crate::{
278273
add_segments, allocate_selector, any_box,
279274
definitions::{block_context::BlockContext, transaction_type::TransactionType},
280275
execution::{OrderedEvent, OrderedL2ToL1Message, TransactionExecutionContext},
281276
memory_insert,
282-
services::api::contract_classes::deprecated_contract_class::ContractClass,
277+
services::api::contract_classes::{
278+
compiled_class::CompiledClass,
279+
deprecated_contract_class::{ContractClass, EntryPointType},
280+
},
283281
state::{
284282
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
285-
in_memory_state_reader::InMemoryStateReader, state_api::State,
283+
in_memory_state_reader::InMemoryStateReader, state_api::State, StateDiff,
286284
},
287285
syscalls::deprecated_syscall_request::{
288286
DeprecatedDeployRequest, DeprecatedSendMessageToL1SysCallRequest,
289287
DeprecatedSyscallRequest,
290288
},
291-
transaction::{Address, InvokeFunction},
289+
transaction::{Address, ClassHash, InvokeFunction, VersionSpecificAccountTxFields},
292290
utils::{
293291
get_big_int, get_integer, get_relocatable,
294292
test_utils::{ids_data, vm},

src/syscalls/native_syscall_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::{
2020
business_logic_syscall_handler::{KECCAK_ROUND_COST, SYSCALL_BASE, SYSCALL_GAS_COST},
2121
syscall_handler_errors::SyscallHandlerError,
2222
},
23-
transaction::{error::TransactionError, Address},
24-
utils::{felt_to_hash, ClassHash},
23+
transaction::{error::TransactionError, Address, ClassHash},
24+
utils::felt_to_hash,
2525
ContractClassCache, EntryPointType,
2626
};
2727
use cairo_native::starknet::{ResourceBounds, TxV2Info};

src/transaction/declare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ use crate::{
1717
},
1818
state::ExecutionResourcesManager,
1919
transaction::error::TransactionError,
20-
utils::{calculate_tx_resources, felt_to_hash, verify_no_calls_to_other_contracts, ClassHash},
20+
utils::{calculate_tx_resources, felt_to_hash, verify_no_calls_to_other_contracts},
2121
};
2222
use cairo_vm::Felt252;
2323
use num_traits::Zero;
2424

2525
use super::fee::{
2626
calculate_tx_fee, charge_fee, estimate_minimal_l1_gas, run_post_execution_fee_checks,
2727
};
28-
use super::{get_tx_version, Address, Transaction};
28+
use super::{get_tx_version, Address, ClassHash, Transaction};
2929
use std::fmt::Debug;
3030
use std::sync::Arc;
3131

src/transaction/declare_v2.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::services::api::contract_classes::deprecated_contract_class::EntryPoin
1111
use crate::services::api::contract_classes::compiled_class::CompiledClass;
1212
use crate::state::cached_state::CachedState;
1313
use crate::state::contract_class_cache::ContractClassCache;
14-
use crate::utils::ClassHash;
1514
use crate::{
1615
core::transaction_hash::calculate_declare_v2_transaction_hash,
1716
definitions::{
@@ -23,9 +22,13 @@ use crate::{
2322
execution_entry_point::ExecutionEntryPoint, CallType, TransactionExecutionContext,
2423
TransactionExecutionInfo,
2524
},
26-
state::state_api::{State, StateReader},
27-
state::ExecutionResourcesManager,
28-
transaction::{error::TransactionError, invoke_function::verify_no_calls_to_other_contracts},
25+
state::{
26+
state_api::{State, StateReader},
27+
ExecutionResourcesManager,
28+
},
29+
transaction::{
30+
error::TransactionError, invoke_function::verify_no_calls_to_other_contracts, ClassHash,
31+
},
2932
utils::calculate_tx_resources,
3033
};
3134
use cairo_lang_starknet::casm_contract_class::CasmContractClass;
@@ -601,13 +604,12 @@ mod tests {
601604
use crate::services::api::contract_classes::compiled_class::CompiledClass;
602605
use crate::state::state_api::StateReader;
603606
use crate::transaction::error::TransactionError;
604-
use crate::utils::ClassHash;
605607
use crate::{
606608
state::{
607609
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
608610
in_memory_state_reader::InMemoryStateReader,
609611
},
610-
transaction::Address,
612+
transaction::{Address, ClassHash},
611613
};
612614
use cairo_lang_starknet::casm_contract_class::CasmContractClass;
613615
use cairo_vm::Felt252;

src/transaction/deploy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Address, Transaction, VersionSpecificAccountTxFields};
1+
use super::{Address, ClassHash, Transaction, VersionSpecificAccountTxFields};
22
use crate::{
33
core::{
44
contract_address::compute_deprecated_class_hash, errors::hash_errors::HashError,
@@ -29,7 +29,7 @@ use crate::{
2929
},
3030
syscalls::syscall_handler_errors::SyscallHandlerError,
3131
transaction::error::TransactionError,
32-
utils::{calculate_tx_resources, felt_to_hash, ClassHash},
32+
utils::{calculate_tx_resources, felt_to_hash},
3333
};
3434
use cairo_vm::Felt252;
3535

0 commit comments

Comments
 (0)