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 e00c836c..f637d19e 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state/mod.rs @@ -17,7 +17,7 @@ use super::account::KakarotAccount; pub trait Evm { // TODO enforce using a marker type that you can only proceed // with execution if the state is initialized. - fn setup_state(&mut self) -> StateResult<()> { + fn setup_state(&mut self, _base_fee: U256) -> StateResult<()> { panic!("Not implemented, use features flag \"v0\" or \"v1\"") } diff --git a/crates/ef-testing/src/evm_sequencer/evm_state/v0.rs b/crates/ef-testing/src/evm_sequencer/evm_state/v0.rs index 69f90c12..aeaa8f50 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state/v0.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state/v0.rs @@ -15,12 +15,38 @@ use super::Evm; use crate::evm_sequencer::account::{AccountType, KakarotAccount}; use crate::evm_sequencer::constants::ETH_FEE_TOKEN_ADDRESS; use crate::evm_sequencer::sequencer::KakarotSequencer; +use crate::evm_sequencer::types::felt::FeltSequencer; use crate::evm_sequencer::utils::{felt_to_bytes, split_u256, to_broadcasted_starknet_transaction}; use crate::starknet_storage; impl Evm for KakarotSequencer { /// Sets up the evm state (coinbase, block number, etc.) - fn setup_state(&mut self) -> StateResult<()> { + fn setup_state(&mut self, base_fee: U256) -> StateResult<()> { + let kakarot_address = self.environment.kakarot_address; + let coinbase_address: FeltSequencer = (*self.address()).try_into().unwrap(); // infallible + + // Set the coinbase address. + self.state_mut().set_storage_at( + kakarot_address, + get_storage_var_address("coinbase", &[]), + coinbase_address.into(), + ); + + // Set the base fee. + let low_fee = base_fee & U256::from(u128::MAX); + let low_fee: u128 = low_fee.try_into().unwrap(); // safe unwrap <= U128::MAX. + let high_fee = base_fee >> U256::from(128); + let high_fee: u128 = high_fee.try_into().unwrap(); // safe unwrap <= U128::MAX. + + let base_address = get_storage_var_address("base_fee", &[]); + self.state_mut() + .set_storage_at(kakarot_address, base_address, StarkFelt::from(low_fee)); + self.state_mut().set_storage_at( + kakarot_address, + next_storage_key(&base_address)?, + StarkFelt::from(high_fee), + ); + Ok(()) } diff --git a/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs b/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs index 661e4503..5bbfe0b8 100644 --- a/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs +++ b/crates/ef-testing/src/evm_sequencer/evm_state/v1.rs @@ -38,7 +38,7 @@ use crate::{ impl Evm for KakarotSequencer { /// Sets up the evm state (coinbase, block number, etc.) - fn setup_state(&mut self) -> StateResult<()> { + fn setup_state(&mut self, _base_fee: U256) -> StateResult<()> { let coinbase_address = *self.address(); let coinbase = KakarotAccount::new(&coinbase_address, &Bytes::default(), U256::ZERO, &[])?; self.setup_account(coinbase)?; @@ -429,7 +429,7 @@ mod tests { transaction.signature = signature; // When - sequencer.setup_state().unwrap(); + sequencer.setup_state(U256::ZERO).unwrap(); let bytecode = Bytes::from(vec![ 0x60, 0x01, 0x60, 0x00, 0x55, 0x60, 0x02, 0x60, 0x00, 0x53, 0x60, 0x01, 0x60, 0x00, 0xf3, diff --git a/crates/ef-testing/src/models/case.rs b/crates/ef-testing/src/models/case.rs index 49efc805..30731433 100644 --- a/crates/ef-testing/src/models/case.rs +++ b/crates/ef-testing/src/models/case.rs @@ -220,6 +220,11 @@ impl Case for BlockchainTestCase { let coinbase_address = maybe_block_header.map(|b| b.coinbase).unwrap_or_default(); + let base_fee = maybe_block_header + .and_then(|block_header| block_header.base_fee_per_gas) + .map(|base_fee| base_fee.0) + .unwrap_or_default(); + let block_number = maybe_block_header.map(|b| b.number.0).unwrap_or_default(); let block_number = TryInto::::try_into(block_number).unwrap_or_default(); @@ -243,7 +248,7 @@ impl Case for BlockchainTestCase { block_timestamp, ); - sequencer.setup_state()?; + sequencer.setup_state(base_fee)?; self.handle_pre_state(&mut sequencer)?;