Skip to content

Commit

Permalink
fix ef-testing crate
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Dec 4, 2024
1 parent 9e64186 commit 2c46a78
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1,263 deletions.
1,226 changes: 0 additions & 1,226 deletions crates/ef-testing/program.sierra

This file was deleted.

6 changes: 3 additions & 3 deletions crates/ef-testing/src/evm_sequencer/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::starknet_storage;
use alloy_consensus::constants::KECCAK_EMPTY;
use alloy_primitives::keccak256;
use alloy_primitives::{Address, U256};
use blockifier::abi::{abi_utils::get_storage_var_address, sierra_types::next_storage_key};
use starknet_api::abi::abi_utils::get_storage_var_address;
use ef_tests::models::Account;
use revm_interpreter::analysis::to_analysed;
use revm_primitives::Bytecode;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl KakarotAccount {

let code_hash_values = split_u256(code_hash);
let code_hash_low_key = get_storage_var_address(ACCOUNT_CODE_HASH, &[]);
let code_hash_high_key = next_storage_key(&code_hash_low_key)?;
let code_hash_high_key = code_hash_low_key.next_storage_key()?;
storage.extend([
(code_hash_low_key, Felt::from(code_hash_values[0])),
(code_hash_high_key, Felt::from(code_hash_values[1])),
Expand Down Expand Up @@ -143,7 +143,7 @@ impl KakarotAccount {
let keys = split_u256(*k).map(Into::into);
let values = split_u256(*v).map(Into::<Felt>::into);
let low_key = get_storage_var_address(ACCOUNT_STORAGE, &keys);
let high_key = next_storage_key(&low_key).unwrap(); // can fail only if low is the max key
let high_key = low_key.next_storage_key().unwrap(); // can fail only if low is the max key
vec![(low_key, values[0]), (high_key, values[1])]
})
.collect();
Expand Down
4 changes: 1 addition & 3 deletions crates/ef-testing/src/evm_sequencer/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use serde::de::DeserializeOwned;
use starknet::core::types::contract::CompiledClass;
use starknet::signers::VerifyingKey;
use starknet::{core::types::contract::legacy::LegacyContractClass, signers::SigningKey};
use starknet_api::felt;
use starknet_api::{
contract_address,
core::{ClassHash, ContractAddress, PatriciaKey},
patricia_key,
core::{ClassHash, ContractAddress},
};
use starknet_crypto::Felt;

Expand Down
15 changes: 6 additions & 9 deletions crates/ef-testing/src/evm_sequencer/evm_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ use crate::{
use alloy_primitives::Address;
use alloy_primitives::Bytes;
use alloy_primitives::U256;
use starknet_api::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address};
use blockifier::{
abi::{
abi_utils::{get_fee_token_var_address, get_storage_var_address},
sierra_types::next_storage_key,
},
execution::errors::EntryPointExecutionError,
state::state_api::{State as _, StateReader as _, StateResult},
transaction::{
Expand Down Expand Up @@ -112,7 +109,7 @@ impl Evm for KakarotSequencer {
.set_storage_at(kakarot_address, basefee_address, low_fee.into())?;
self.state_mut().set_storage_at(
kakarot_address,
next_storage_key(&basefee_address)?,
basefee_address.next_storage_key()?,
high_fee.into(),
)?;

Expand All @@ -126,7 +123,7 @@ impl Evm for KakarotSequencer {
)?;
self.state_mut().set_storage_at(
kakarot_address,
next_storage_key(&prev_randao_address)?,
prev_randao_address.next_storage_key()?,
high_prev_randao.into(),
)?;

Expand Down Expand Up @@ -187,7 +184,7 @@ impl Evm for KakarotSequencer {

// Initialize the balance storage var.
let balance_key_low = get_fee_token_var_address(starknet_address);
let balance_key_high = next_storage_key(&balance_key_low)?;
let balance_key_high = balance_key_low.next_storage_key()?;
storage.append(&mut vec![
(balance_key_low, balance_values[0].into()),
(balance_key_high, balance_values[1].into()),
Expand All @@ -198,7 +195,7 @@ impl Evm for KakarotSequencer {
"ERC20_allowances",
&[*starknet_address.0.key(), *KAKAROT_ADDRESS.0.key()],
);
let allowance_key_high = next_storage_key(&allowance_key_low)?;
let allowance_key_high = allowance_key_low.next_storage_key()?;
storage.append(&mut vec![
(allowance_key_low, u128::MAX.into()),
(allowance_key_high, u128::MAX.into()),
Expand All @@ -216,7 +213,7 @@ impl Evm for KakarotSequencer {
fn storage_at(&mut self, evm_address: &Address, key: U256) -> StateResult<U256> {
let keys = split_u256(key).map(Into::into);
let key_low = get_storage_var_address(ACCOUNT_STORAGE, &keys);
let key_high = next_storage_key(&key_low)?;
let key_high = key_low.next_storage_key()?;

let starknet_address = self.compute_starknet_address(evm_address)?;

Expand Down
29 changes: 12 additions & 17 deletions crates/ef-testing/src/evm_sequencer/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,31 @@ use crate::evm_sequencer::{
ACCOUNT_PUBLIC_KEY, ERC20_BALANCES, KAKAROT_ACCOUNT_CONTRACT_CLASS_HASH,
KAKAROT_BLOCK_GAS_LIMIT, KAKAROT_CHAIN_ID, KAKAROT_NATIVE_TOKEN_ADDRESS,
KAKAROT_UNINITIALIZED_ACCOUNT_CLASS_HASH, OWNABLE_OWNER,
},
ACCOUNT_CONTRACT_CLASS, ACCOUNT_CONTRACT_CLASS_HASH, BLOCK_GAS_LIMIT, CHAIN_ID,
ETH_FEE_TOKEN_ADDRESS, FEE_TOKEN_CLASS, FEE_TOKEN_CLASS_HASH, KAKAROT_ADDRESS,
KAKAROT_CLASS, KAKAROT_CLASS_HASH, KAKAROT_OWNER_ADDRESS, OPENZEPPELIN_ACCOUNT_CLASS,
}, ACCOUNT_CONTRACT_CLASS_HASH, BLOCK_GAS_LIMIT, CHAIN_ID,
ETH_FEE_TOKEN_ADDRESS, FEE_TOKEN_CLASS, FEE_TOKEN_CLASS_HASH, KAKAROT_ADDRESS, KAKAROT_CLASS_HASH, KAKAROT_OWNER_ADDRESS, OPENZEPPELIN_ACCOUNT_CLASS,
OPENZEPPELIN_ACCOUNT_CLASS_HASH, RELAYER_ADDRESS, RELAYER_BALANCE, RELAYER_VERIFYING_KEY,
STRK_FEE_TOKEN_ADDRESS, UNINITIALIZED_ACCOUNT_CLASS, UNINITIALIZED_ACCOUNT_CLASS_HASH,
STRK_FEE_TOKEN_ADDRESS, UNINITIALIZED_ACCOUNT_CLASS_HASH,
},
types::contract_class::CasmContractClassWrapper,
utils::compute_starknet_address,
};
use alloy_primitives::Address;
use blockifier::blockifier::block::BlockInfo;
use starknet_api::block::{GasPrices, GasPriceVector};
use starknet_api::block::{BlockInfo, GasPrices, GasPriceVector};
use blockifier::context::ChainInfo;
use blockifier::context::{BlockContext, FeeTokenAddresses};
use blockifier::versioned_constants::VersionedConstants;
use blockifier::{
execution::contract_class::{ContractClass, ContractClassV0, ContractClassV1},
execution::contract_class::{RunnableCompiledClass, CompiledClassV0, CompiledClassV1},
state::state_api::StateResult,
};
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_vm::types::errors::program_errors::ProgramError;
use reth_primitives::Address;
use sequencer::{native::class_from_json_str, sequencer::Sequencer, state::State};
use alloy_primitives::Address;
use sequencer::{sequencer::Sequencer, state::State};
use starknet::core::types::contract::{legacy::LegacyContractClass, CompiledClass};
use starknet_api::{
block::{BlockNumber, BlockTimestamp},
core::{ChainId, ClassHash, ContractAddress},
};
use std::num::NonZeroU128;

#[cfg(feature = "v0")]
use crate::evm_sequencer::constants::{
Expand Down Expand Up @@ -187,18 +182,18 @@ impl DerefMut for KakarotSequencer {

pub fn convert_contract_class_v0(
class: &LegacyContractClass,
) -> Result<ContractClass, eyre::Error> {
Result::<ContractClass, eyre::Error>::Ok(ContractClass::V0(
ContractClassV0::try_from_json_string(
) -> Result<RunnableCompiledClass, eyre::Error> {
Result::<RunnableCompiledClass, eyre::Error>::Ok(RunnableCompiledClass::V0(
CompiledClassV0::try_from_json_string(
&serde_json::to_string(class).map_err(ProgramError::Parse)?,
)?,
))
}

pub fn convert_contract_class_v1(class: &CompiledClass) -> Result<ContractClass, eyre::Error> {
pub fn convert_contract_class_v1(class: &CompiledClass) -> Result<RunnableCompiledClass, eyre::Error> {
let casm_contract_class = CasmContractClassWrapper::try_from(class)?;
let casm_contract_class: CasmContractClass = casm_contract_class.into();
Ok(ContractClass::V1(ContractClassV1::try_from(
Ok(RunnableCompiledClass::V1(CompiledClassV1::try_from(
casm_contract_class,
)?))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ef-testing/src/models/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl TryFrom<&EventData> for EVMOutput {
#[cfg(target_os = "macos")]
mod debug_ram {
use std::mem;
use std::ptr;


#[link(name = "c")]
extern "C" {
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) fn extract_output_and_log_execution_result(
TransactionExecutionResult::Ok(info) => {
/* trunk-ignore(clippy/option_if_let_else) */
if let Some(err) = info.revert_error.as_ref() {
warn!("{} reverted:\n{}", case, err.replace("\\n", "\n"));
warn!("{} reverted:\n{}", case, err.to_string());
return None;
}

Expand Down
4 changes: 1 addition & 3 deletions crates/ef-testing/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ pub fn setup() {

pub struct TestMonitor {
thresholds: Vec<u64>, // thresholds in seconds
last_threshold: u64, // last reported threshold
}

impl TestMonitor {
pub fn new(thresholds: Vec<u64>) -> Self {
TestMonitor {
thresholds: thresholds,
last_threshold: 0,
thresholds,
}
}

Expand Down

0 comments on commit 2c46a78

Please sign in to comment.