Skip to content

Commit

Permalink
rm FeltSequencer type (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Sep 12, 2024
1 parent d195369 commit c9ca3c0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 60 deletions.
6 changes: 2 additions & 4 deletions crates/ef-testing/src/evm_sequencer/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,9 +76,7 @@ impl KakarotAccount {
}
})?);

let evm_address = TryInto::<FeltSequencer>::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),
Expand Down
3 changes: 1 addition & 2 deletions crates/ef-testing/src/evm_sequencer/evm_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 5 additions & 7 deletions crates/ef-testing/src/evm_sequencer/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -162,10 +163,7 @@ impl KakarotSequencer {
pub fn compute_starknet_address(&self, evm_address: &Address) -> StateResult<ContractAddress> {
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()?)
}
Expand Down
39 changes: 0 additions & 39 deletions crates/ef-testing/src/evm_sequencer/types/felt.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/ef-testing/src/evm_sequencer/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod contract_class;
pub mod felt;
12 changes: 5 additions & 7 deletions crates/ef-testing/src/evm_sequencer/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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.
Expand Down

0 comments on commit c9ca3c0

Please sign in to comment.