diff --git a/Cargo.lock b/Cargo.lock index 4269563010..95fb052225 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2103,7 +2103,6 @@ dependencies = [ "cairo-lang-starknet", "cairo-vm", "criterion", - "derive_more", "indexmap 2.1.0", "log", "num-bigint", diff --git a/crates/native_blockifier/Cargo.toml b/crates/native_blockifier/Cargo.toml index 7c4eb6d3c2..4d5a9109ba 100644 --- a/crates/native_blockifier/Cargo.toml +++ b/crates/native_blockifier/Cargo.toml @@ -29,7 +29,6 @@ crate-type = ["cdylib"] blockifier = { path = "../blockifier", features = ["testing"] } cairo-lang-starknet.workspace = true cairo-vm.workspace = true -derive_more.workspace = true indexmap.workspace = true log.workspace = true num-bigint.workspace = true diff --git a/crates/native_blockifier/src/py_block_executor.rs b/crates/native_blockifier/src/py_block_executor.rs index 0a7b7e90d1..831f3c1b3a 100644 --- a/crates/native_blockifier/src/py_block_executor.rs +++ b/crates/native_blockifier/src/py_block_executor.rs @@ -302,7 +302,7 @@ pub fn into_block_context( block_info: BlockInfo { block_number: BlockNumber(block_info.block_number), block_timestamp: BlockTimestamp(block_info.block_timestamp), - sequencer_address: ContractAddress::try_from(block_info.sequencer_address)?, + sequencer_address: ContractAddress::try_from(block_info.sequencer_address.0)?, vm_resource_fee_cost: general_config.cairo_resource_fee_weights.clone(), gas_prices: GasPrices { eth_l1_gas_price: block_info.l1_gas_price.price_in_wei, diff --git a/crates/native_blockifier/src/py_declare.rs b/crates/native_blockifier/src/py_declare.rs index f58cc0cbae..72d96df81c 100644 --- a/crates/native_blockifier/src/py_declare.rs +++ b/crates/native_blockifier/src/py_declare.rs @@ -32,7 +32,7 @@ impl TryFrom for DeclareTransactionV0V1 { signature: TransactionSignature(from_py_felts(tx.signature)), nonce: Nonce(tx.nonce.0), class_hash: ClassHash(tx.class_hash.0), - sender_address: ContractAddress::try_from(tx.sender_address)?, + sender_address: ContractAddress::try_from(tx.sender_address.0)?, }) } } @@ -56,7 +56,7 @@ impl TryFrom for DeclareTransactionV2 { nonce: Nonce(tx.nonce.0), class_hash: ClassHash(tx.class_hash.0), compiled_class_hash: CompiledClassHash(tx.compiled_class_hash.0), - sender_address: ContractAddress::try_from(tx.sender_address)?, + sender_address: ContractAddress::try_from(tx.sender_address.0)?, }) } } @@ -86,7 +86,7 @@ impl TryFrom for DeclareTransactionV3 { nonce: Nonce(tx.nonce.0), class_hash: ClassHash(tx.class_hash.0), compiled_class_hash: CompiledClassHash(tx.compiled_class_hash.0), - sender_address: ContractAddress::try_from(tx.sender_address)?, + sender_address: ContractAddress::try_from(tx.sender_address.0)?, nonce_data_availability_mode: DataAvailabilityMode::from( tx.nonce_data_availability_mode, ), diff --git a/crates/native_blockifier/src/py_deploy_account.rs b/crates/native_blockifier/src/py_deploy_account.rs index 8846f0ed4e..faed5a5a78 100644 --- a/crates/native_blockifier/src/py_deploy_account.rs +++ b/crates/native_blockifier/src/py_deploy_account.rs @@ -91,6 +91,7 @@ pub fn py_deploy_account(py_tx: &PyAny) -> NativeBlockifierResult(py_tx, "hash_value")?.0); - let contract_address = ContractAddress::try_from(py_attr::(py_tx, "sender_address")?)?; + let contract_address = + ContractAddress::try_from(py_attr::(py_tx, "sender_address")?.0)?; Ok(DeployAccountTransaction::new(tx, tx_hash, contract_address)) } diff --git a/crates/native_blockifier/src/py_invoke_function.rs b/crates/native_blockifier/src/py_invoke_function.rs index 310c598a69..00466ac35c 100644 --- a/crates/native_blockifier/src/py_invoke_function.rs +++ b/crates/native_blockifier/src/py_invoke_function.rs @@ -31,7 +31,7 @@ impl TryFrom for InvokeTransactionV0 { Ok(Self { max_fee: Fee(tx.max_fee), signature: TransactionSignature(from_py_felts(tx.signature)), - contract_address: ContractAddress::try_from(tx.sender_address)?, + contract_address: ContractAddress::try_from(tx.sender_address.0)?, entry_point_selector: EntryPointSelector(tx.entry_point_selector.0), calldata: Calldata(Arc::from(from_py_felts(tx.calldata))), }) @@ -54,7 +54,7 @@ impl TryFrom for InvokeTransactionV1 { max_fee: Fee(tx.max_fee), signature: TransactionSignature(from_py_felts(tx.signature)), nonce: Nonce(tx.nonce.0), - sender_address: ContractAddress::try_from(tx.sender_address)?, + sender_address: ContractAddress::try_from(tx.sender_address.0)?, calldata: Calldata(Arc::from(from_py_felts(tx.calldata))), }) } @@ -82,7 +82,7 @@ impl TryFrom for InvokeTransactionV3 { tip: Tip(tx.tip), signature: TransactionSignature(from_py_felts(tx.signature)), nonce: Nonce(tx.nonce.0), - sender_address: ContractAddress::try_from(tx.sender_address)?, + sender_address: ContractAddress::try_from(tx.sender_address.0)?, calldata: Calldata(Arc::from(from_py_felts(tx.calldata))), nonce_data_availability_mode: DataAvailabilityMode::from( tx.nonce_data_availability_mode, diff --git a/crates/native_blockifier/src/py_l1_handler.rs b/crates/native_blockifier/src/py_l1_handler.rs index 2f0665059e..3c72eb7508 100644 --- a/crates/native_blockifier/src/py_l1_handler.rs +++ b/crates/native_blockifier/src/py_l1_handler.rs @@ -23,7 +23,7 @@ impl TryFrom for starknet_api::transaction::L1HandlerTra Ok(Self { version: constants::L1_HANDLER_VERSION, nonce: Nonce(tx.nonce.0), - contract_address: ContractAddress::try_from(tx.contract_address)?, + contract_address: ContractAddress::try_from(tx.contract_address.0)?, entry_point_selector: EntryPointSelector(tx.entry_point_selector.0), calldata: Calldata(Arc::from(from_py_felts(tx.calldata))), }) diff --git a/crates/native_blockifier/src/py_state_diff.rs b/crates/native_blockifier/src/py_state_diff.rs index 858781de1d..1c8e4e83e0 100644 --- a/crates/native_blockifier/src/py_state_diff.rs +++ b/crates/native_blockifier/src/py_state_diff.rs @@ -30,14 +30,14 @@ impl TryFrom for StateDiff { fn try_from(state_diff: PyStateDiff) -> NativeBlockifierResult { let mut deployed_contracts: IndexMap = IndexMap::new(); for (address, class_hash) in state_diff.address_to_class_hash { - let address = ContractAddress::try_from(address)?; + let address = ContractAddress::try_from(address.0)?; let class_hash = ClassHash(class_hash.0); deployed_contracts.insert(address, class_hash); } let mut storage_diffs = IndexMap::new(); for (address, storage_mapping) in state_diff.storage_updates { - let address = ContractAddress::try_from(address)?; + let address = ContractAddress::try_from(address.0)?; storage_diffs.insert(address, IndexMap::new()); for (key, value) in storage_mapping { @@ -51,7 +51,7 @@ impl TryFrom for StateDiff { let mut nonces = IndexMap::new(); for (address, nonce) in state_diff.address_to_nonce { - let address = ContractAddress::try_from(address)?; + let address = ContractAddress::try_from(address.0)?; let nonce = Nonce(nonce.0); nonces.insert(address, nonce); } diff --git a/crates/native_blockifier/src/py_utils.rs b/crates/native_blockifier/src/py_utils.rs index f77d854bf9..e9ef4facae 100644 --- a/crates/native_blockifier/src/py_utils.rs +++ b/crates/native_blockifier/src/py_utils.rs @@ -6,11 +6,10 @@ use pyo3::prelude::*; use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, EthAddress}; use starknet_api::hash::StarkFelt; use starknet_api::state::StorageKey; -use starknet_api::StarknetApiError; use crate::errors::NativeBlockifierResult; -#[derive(Clone, Copy, Debug, Default, Eq, FromPyObject, Hash, PartialEq, derive_more::Deref)] +#[derive(Clone, Copy, Debug, Default, Eq, FromPyObject, Hash, PartialEq)] pub struct PyFelt(#[pyo3(from_py_with = "int_to_stark_felt")] pub StarkFelt); impl IntoPy for PyFelt { @@ -65,14 +64,6 @@ impl From for PyFelt { } } -impl TryFrom for ContractAddress { - type Error = StarknetApiError; - - fn try_from(value: PyFelt) -> Result { - Self::try_from(value.0) - } -} - fn int_to_stark_felt(int: &PyAny) -> PyResult { let biguint: BigUint = int.extract()?; biguint_to_felt(biguint).map_err(|e| PyValueError::new_err(e.to_string())) diff --git a/crates/native_blockifier/src/storage.rs b/crates/native_blockifier/src/storage.rs index 7eeb43dd55..84be5ea8d3 100644 --- a/crates/native_blockifier/src/storage.rs +++ b/crates/native_blockifier/src/storage.rs @@ -147,7 +147,7 @@ impl Storage for PapyrusStorage { // i.e.: pointing to a non-zeroed class hash). Rest would be (newly) deployed classes. let mut replaced_classes = IndexMap::::new(); for (address, class_hash) in &py_state_diff.address_to_class_hash { - let address = ContractAddress::try_from(*address)?; + let address = ContractAddress::try_from(address.0)?; let address_assigned: bool = self .reader() .begin_ro_txn()?