From c9ca3c0f35d6b9dd71a6b2f16c681d12ab2ff9d2 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Thu, 12 Sep 2024 02:23:04 -0700 Subject: [PATCH] rm FeltSequencer type (#751) --- .../src/evm_sequencer/account/mod.rs | 6 +-- .../src/evm_sequencer/evm_state/mod.rs | 3 +- .../src/evm_sequencer/sequencer/mod.rs | 12 +++--- .../src/evm_sequencer/types/felt.rs | 39 ------------------- .../ef-testing/src/evm_sequencer/types/mod.rs | 1 - crates/ef-testing/src/evm_sequencer/utils.rs | 12 +++--- 6 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 crates/ef-testing/src/evm_sequencer/types/felt.rs diff --git a/crates/ef-testing/src/evm_sequencer/account/mod.rs b/crates/ef-testing/src/evm_sequencer/account/mod.rs index ddd9cb84..0c0ad7ea 100644 --- a/crates/ef-testing/src/evm_sequencer/account/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/account/mod.rs @@ -2,7 +2,7 @@ use crate::evm_sequencer::constants::storage_variables::{ ACCOUNT_BYTECODE_LEN, ACCOUNT_CODE_HASH, ACCOUNT_EVM_ADDRESS, ACCOUNT_IS_INITIALIZED, ACCOUNT_NONCE, ACCOUNT_STORAGE, ACCOUNT_VALID_JUMPDESTS, }; -use crate::evm_sequencer::{types::felt::FeltSequencer, utils::split_u256}; +use crate::evm_sequencer::utils::split_u256; use crate::starknet_storage; use blockifier::abi::{abi_utils::get_storage_var_address, sierra_types::next_storage_key}; use ef_tests::models::Account; @@ -76,9 +76,7 @@ impl KakarotAccount { } })?); - let evm_address = TryInto::::try_into(*evm_address) - .unwrap() // infallible - .into(); + let evm_address = Felt::from_bytes_be_slice(&evm_address.0[..]); let mut storage = vec![ starknet_storage!(ACCOUNT_EVM_ADDRESS, evm_address), diff --git a/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs b/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs index 01564e0d..d2615426 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs @@ -13,7 +13,6 @@ use crate::{ ETH_FEE_TOKEN_ADDRESS, KAKAROT_ADDRESS, }, sequencer::KakarotSequencer, - types::felt::FeltSequencer, utils::{split_u256, to_broadcasted_starknet_transaction}, }, starknet_storage, @@ -92,7 +91,7 @@ impl Evm for KakarotSequencer { block_gas_limit: U256, ) -> StateResult<()> { let kakarot_address = self.environment.kakarot_address; - let coinbase_address: FeltSequencer = (*self.address()).try_into().unwrap(); // infallible + let coinbase_address = Felt::from_bytes_be_slice(&self.address().0[..]); // Set the coinbase address. self.state_mut().set_storage_at( diff --git a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs index ed1dd7e3..db54bbb9 100644 --- a/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/sequencer/mod.rs @@ -2,7 +2,6 @@ use blockifier::bouncer::BouncerConfig; use starknet::core::types::Felt; use std::ops::{Deref, DerefMut}; -use crate::evm_sequencer::types::felt::FeltSequencer; use crate::evm_sequencer::{ constants::{ storage_variables::{ @@ -97,8 +96,10 @@ impl KakarotSequencer { block_timestamp: u64, ) -> Self { let coinbase_constructor_args = { - let evm_address: FeltSequencer = coinbase_address.try_into().unwrap(); // infallible - vec![Felt::ONE, evm_address.into()] + vec![ + Felt::ONE, + Felt::from_bytes_be_slice(&coinbase_address.0[..]), + ] }; let block_info = BlockInfo { @@ -162,10 +163,7 @@ impl KakarotSequencer { pub fn compute_starknet_address(&self, evm_address: &Address) -> StateResult { let base_class_hash = self.environment.base_account_class_hash.0; - let constructor_args = { - let evm_address: FeltSequencer = (*evm_address).try_into().unwrap(); // infallible - vec![Felt::ONE, evm_address.into()] - }; + let constructor_args = { vec![Felt::ONE, Felt::from_bytes_be_slice(&evm_address.0[..])] }; Ok(compute_starknet_address(evm_address, base_class_hash, &constructor_args).try_into()?) } diff --git a/crates/ef-testing/src/evm_sequencer/types/felt.rs b/crates/ef-testing/src/evm_sequencer/types/felt.rs deleted file mode 100644 index 3377496e..00000000 --- a/crates/ef-testing/src/evm_sequencer/types/felt.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::convert::Infallible; - -use reth_primitives::Address; -use starknet::core::types::Felt; -use starknet_api::{core::ContractAddress, StarknetApiError}; - -/// A wrapper around a Felt in order to facilitate conversion. -#[derive(Debug, Clone, Copy)] -pub struct FeltSequencer(Felt); - -impl From for FeltSequencer { - fn from(felt: Felt) -> Self { - Self(felt) - } -} - -impl From for Felt { - fn from(felt: FeltSequencer) -> Self { - felt.0 - } -} - -impl TryFrom
for FeltSequencer { - type Error = Infallible; - - fn try_from(address: Address) -> Result { - // safe unwrap since Address is 20 bytes - Ok(Self(Felt::from_bytes_be_slice(&address.0[..]))) - } -} - -impl TryFrom for ContractAddress { - type Error = StarknetApiError; - - fn try_from(felt: FeltSequencer) -> Result { - let felt: Felt = felt.into(); - Ok(Self(felt.try_into()?)) - } -} diff --git a/crates/ef-testing/src/evm_sequencer/types/mod.rs b/crates/ef-testing/src/evm_sequencer/types/mod.rs index 44644827..571760b6 100644 --- a/crates/ef-testing/src/evm_sequencer/types/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/types/mod.rs @@ -1,2 +1 @@ pub mod contract_class; -pub mod felt; diff --git a/crates/ef-testing/src/evm_sequencer/utils.rs b/crates/ef-testing/src/evm_sequencer/utils.rs index 82a414dd..780b7b06 100644 --- a/crates/ef-testing/src/evm_sequencer/utils.rs +++ b/crates/ef-testing/src/evm_sequencer/utils.rs @@ -1,4 +1,4 @@ -use super::{constants::KAKAROT_ADDRESS, types::felt::FeltSequencer}; +use super::constants::KAKAROT_ADDRESS; use crate::evm_sequencer::constants::RELAYER_ADDRESS; use bytes::BytesMut; use reth_primitives::{Address, Bytes, TransactionSigned, TxType, U256}; @@ -13,15 +13,13 @@ pub fn compute_starknet_address( evm_address: &Address, class_hash: Felt, constructor_args: &[Felt], -) -> FeltSequencer { - let evm_address: FeltSequencer = (*evm_address).try_into().unwrap(); // infallible - let starknet_address = get_contract_address( - evm_address.into(), +) -> Felt { + get_contract_address( + Felt::from_bytes_be_slice(&evm_address.0[..]), class_hash, constructor_args, *KAKAROT_ADDRESS.0, - ); - starknet_address.into() + ) } /// Split a U256 into low and high u128.