Skip to content

Commit

Permalink
fix(cairo_native): remove native FC folder (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware authored Dec 9, 2024
1 parent 7683084 commit ef39c7f
Show file tree
Hide file tree
Showing 12 changed files with 3,334 additions and 10,704 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

648 changes: 0 additions & 648 deletions crates/blockifier/feature_contracts/cairo_native/test_contract.cairo

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ fn test_deploy_account(
message_segment_length: 0,
n_events: 0,
..BouncerWeights::empty()
}
.into();
};
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::transaction::objects::{
#[cfg_attr(
feature = "cairo_native",
test_case(
FeatureContract::SierraExecutionInfoV1Contract,
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native),
ExecutionMode::Validate,
TransactionVersion::ONE,
false;
Expand All @@ -54,7 +54,7 @@ use crate::transaction::objects::{
#[cfg_attr(
feature = "cairo_native",
test_case(
FeatureContract::SierraExecutionInfoV1Contract,
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native),
ExecutionMode::Execute,
TransactionVersion::ONE,
false;
Expand Down Expand Up @@ -181,7 +181,7 @@ fn test_get_execution_info(
vec![]
}
#[cfg(feature = "cairo_native")]
FeatureContract::SierraExecutionInfoV1Contract => {
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native) => {
vec![]
}
_ => {
Expand Down Expand Up @@ -212,7 +212,7 @@ fn test_get_execution_info(
let expected_resource_bounds: Vec<Felt> = match (test_contract, version) {
(FeatureContract::LegacyTestContract, _) => vec![],
#[cfg(feature = "cairo_native")]
(FeatureContract::SierraExecutionInfoV1Contract, _) => vec![],
(FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native), _) => vec![],
(_, version) if version == TransactionVersion::ONE => vec![
felt!(0_u16), // Length of resource bounds array.
],
Expand Down
17 changes: 6 additions & 11 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ pub enum RunnableCairo1 {
Native,
}

impl Default for RunnableCairo1 {
fn default() -> Self {
Self::Casm
}
}

// TODO(Aviv, 14/7/2024): Move from test utils module, and use it in ContractClassVersionMismatch
// error.
#[derive(Clone, Hash, PartialEq, Eq, Copy, Debug)]
Expand Down Expand Up @@ -92,17 +98,6 @@ impl CairoVersion {
}
}

pub fn other(&self) -> Self {
match self {
Self::Cairo0 => CairoVersion::Cairo1(RunnableCairo1::Casm),
CairoVersion::Cairo1(RunnableCairo1::Casm) => Self::Cairo0,
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => {
panic!("There is no other version for native")
}
}
}

pub fn is_cairo0(&self) -> bool {
match self {
Self::Cairo0 => true,
Expand Down
13 changes: 2 additions & 11 deletions crates/blockifier/src/test_utils/cairo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,8 @@ struct CargoToml {
}

pub enum CompilationArtifacts {
Cairo0 {
casm: Vec<u8>,
},
Cairo1 {
casm: Vec<u8>,
sierra: Vec<u8>,
},
#[cfg(feature = "cairo_native")]
Cairo1Native {
sierra: Vec<u8>,
},
Cairo0 { casm: Vec<u8> },
Cairo1 { casm: Vec<u8>, sierra: Vec<u8> },
}

#[cached]
Expand Down
147 changes: 73 additions & 74 deletions crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use crate::execution::contract_class::RunnableCompiledClass;
use crate::execution::entry_point::CallEntryPoint;
#[cfg(feature = "cairo_native")]
use crate::execution::native::contract_class::NativeCompiledClassV1;
#[cfg(feature = "cairo_native")]
use crate::test_utils::cairo_compile::starknet_compile;
use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile, CompilationArtifacts};
use crate::test_utils::struct_impls::LoadContractFromFile;
use crate::test_utils::{get_raw_contract_class, CairoVersion, RunnableCairo1};
Expand Down Expand Up @@ -63,7 +61,6 @@ const SECURITY_TEST_CONTRACT_BASE: u32 = 6 * CLASS_HASH_BASE;
const TEST_CONTRACT_BASE: u32 = 7 * CLASS_HASH_BASE;
const ERC20_CONTRACT_BASE: u32 = 8 * CLASS_HASH_BASE;
const CAIRO_STEPS_TEST_CONTRACT_BASE: u32 = 9 * CLASS_HASH_BASE;
#[cfg(feature = "cairo_native")]
const SIERRA_EXECUTION_INFO_V1_CONTRACT_BASE: u32 = 10 * CLASS_HASH_BASE;

// Contract names.
Expand All @@ -75,7 +72,6 @@ const LEGACY_CONTRACT_NAME: &str = "legacy_test_contract";
const SECURITY_TEST_CONTRACT_NAME: &str = "security_tests_contract";
const TEST_CONTRACT_NAME: &str = "test_contract";
const CAIRO_STEPS_TEST_CONTRACT_NAME: &str = "cairo_steps_test_contract";
#[cfg(feature = "cairo_native")]
const EXECUTION_INFO_V1_CONTRACT_NAME: &str = "test_contract_execution_info_v1";

// ERC20 contract is in a unique location.
Expand Down Expand Up @@ -110,8 +106,7 @@ pub enum FeatureContract {
SecurityTests,
TestContract(CairoVersion),
CairoStepsTestContract,
#[cfg(feature = "cairo_native")]
SierraExecutionInfoV1Contract,
SierraExecutionInfoV1Contract(RunnableCairo1),
}

impl FeatureContract {
Expand All @@ -127,22 +122,9 @@ impl FeatureContract {
Self::LegacyTestContract | Self::CairoStepsTestContract => {
CairoVersion::Cairo1(RunnableCairo1::Casm)
}
#[cfg(feature = "cairo_native")]
Self::SierraExecutionInfoV1Contract => CairoVersion::Cairo1(RunnableCairo1::Native),
}
}

fn has_two_versions(&self) -> bool {
match self {
Self::AccountWithLongValidate(_)
| Self::AccountWithoutValidations(_)
| Self::Empty(_)
| Self::FaultyAccount(_)
| Self::TestContract(_)
| Self::ERC20(_) => true,
#[cfg(feature = "cairo_native")]
Self::SierraExecutionInfoV1Contract => false,
Self::SecurityTests | Self::LegacyTestContract | Self::CairoStepsTestContract => false,
Self::SierraExecutionInfoV1Contract(runnable_version) => {
CairoVersion::Cairo1(*runnable_version)
}
}
}

Expand All @@ -154,11 +136,11 @@ impl FeatureContract {
| Self::FaultyAccount(v)
| Self::TestContract(v)
| Self::ERC20(v) => *v = version,
Self::LegacyTestContract | Self::SecurityTests | Self::CairoStepsTestContract => {
panic!("{self:?} contract has no configurable version.")
}
#[cfg(feature = "cairo_native")]
Self::SierraExecutionInfoV1Contract => {
Self::SierraExecutionInfoV1Contract(rv) => match version {
CairoVersion::Cairo0 => panic!("SierraExecutionInfoV1Contract must be Cairo1"),
CairoVersion::Cairo1(runnable) => *rv = runnable,
},
Self::SecurityTests | Self::CairoStepsTestContract | Self::LegacyTestContract => {
panic!("{self:?} contract has no configurable version.")
}
}
Expand All @@ -171,13 +153,7 @@ impl FeatureContract {
pub fn get_compiled_class_hash(&self) -> CompiledClassHash {
match self.cairo_version() {
CairoVersion::Cairo0 => CompiledClassHash(Felt::ZERO),
CairoVersion::Cairo1(RunnableCairo1::Casm) => {
CompiledClassHash(felt!(self.get_integer_base()))
}
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => {
CompiledClassHash(felt!(self.get_integer_base()))
}
CairoVersion::Cairo1(_) => CompiledClassHash(felt!(self.get_integer_base())),
}
}

Expand Down Expand Up @@ -235,9 +211,7 @@ impl FeatureContract {
fn get_cairo_version_bit(&self) -> u32 {
match self.cairo_version() {
CairoVersion::Cairo0 => 0,
CairoVersion::Cairo1(RunnableCairo1::Casm) => CAIRO1_BIT,
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => CAIRO1_BIT,
CairoVersion::Cairo1(_) => CAIRO1_BIT,
}
}

Expand Down Expand Up @@ -271,8 +245,7 @@ impl FeatureContract {
Self::SecurityTests => SECURITY_TEST_CONTRACT_BASE,
Self::TestContract(_) => TEST_CONTRACT_BASE,
Self::CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_BASE,
#[cfg(feature = "cairo_native")]
Self::SierraExecutionInfoV1Contract => SIERRA_EXECUTION_INFO_V1_CONTRACT_BASE,
Self::SierraExecutionInfoV1Contract(_) => SIERRA_EXECUTION_INFO_V1_CONTRACT_BASE,
}
}

Expand All @@ -286,8 +259,7 @@ impl FeatureContract {
Self::SecurityTests => SECURITY_TEST_CONTRACT_NAME,
Self::TestContract(_) => TEST_CONTRACT_NAME,
Self::CairoStepsTestContract => CAIRO_STEPS_TEST_CONTRACT_NAME,
#[cfg(feature = "cairo_native")]
Self::SierraExecutionInfoV1Contract => EXECUTION_INFO_V1_CONTRACT_NAME,
Self::SierraExecutionInfoV1Contract(_) => EXECUTION_INFO_V1_CONTRACT_NAME,
Self::ERC20(_) => unreachable!(),
}
}
Expand All @@ -309,9 +281,7 @@ impl FeatureContract {
"feature_contracts/cairo{}/{}.cairo",
match self.cairo_version() {
CairoVersion::Cairo0 => "0",
CairoVersion::Cairo1(RunnableCairo1::Casm) => "1",
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => "_native",
CairoVersion::Cairo1(_) => "1",
},
self.get_non_erc20_base_name()
)
Expand Down Expand Up @@ -343,12 +313,12 @@ impl FeatureContract {
} else {
let cairo_version = self.cairo_version();
format!(
"feature_contracts/cairo{}/compiled/{}{}.json",
"feature_contracts/cairo{}/{}{}.json",
match cairo_version {
CairoVersion::Cairo0 => "0",
CairoVersion::Cairo1(RunnableCairo1::Casm) => "1",
CairoVersion::Cairo0 => "0/compiled",
CairoVersion::Cairo1(RunnableCairo1::Casm) => "1/compiled",
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => "_native",
CairoVersion::Cairo1(RunnableCairo1::Native) => "1/sierra",
},
self.get_non_erc20_base_name(),
match cairo_version {
Expand Down Expand Up @@ -378,28 +348,16 @@ impl FeatureContract {
FeatureContract::Empty(_)
| FeatureContract::TestContract(_)
| FeatureContract::LegacyTestContract
| FeatureContract::CairoStepsTestContract => None,
#[cfg(feature = "cairo_native")]
FeatureContract::SierraExecutionInfoV1Contract => None,
| FeatureContract::CairoStepsTestContract
| FeatureContract::SierraExecutionInfoV1Contract(_) => None,
FeatureContract::ERC20(_) => unreachable!(),
};
cairo0_compile(self.get_source_path(), extra_arg, false)
}
CairoVersion::Cairo1(RunnableCairo1::Casm) => {
CairoVersion::Cairo1(_) => {
let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain();
cairo1_compile(self.get_source_path(), tag_override, cargo_nightly_arg)
}
#[cfg(feature = "cairo_native")]
CairoVersion::Cairo1(RunnableCairo1::Native) => {
let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain();
let sierra_output = starknet_compile(
self.get_source_path(),
tag_override,
cargo_nightly_arg,
&mut vec![],
);
CompilationArtifacts::Cairo1Native { sierra: sierra_output }
}
}
}

Expand Down Expand Up @@ -456,18 +414,59 @@ impl FeatureContract {
self.get_offset(selector, EntryPointType::Constructor)
}

pub fn all_contracts() -> impl Iterator<Item = Self> {
// EnumIter iterates over all variants with Default::default() as the cairo
// version.
Self::iter().flat_map(|contract| {
if contract.has_two_versions() {
let mut other_contract = contract;
other_contract.set_cairo_version(contract.cairo_version().other());
vec![contract, other_contract].into_iter()
} else {
vec![contract].into_iter()
fn iter_versions(&self, versions: &[CairoVersion]) -> Vec<FeatureContract> {
versions
.iter()
.map(|&v| {
let mut versioned_contract = *self;
versioned_contract.set_cairo_version(v);
versioned_contract
})
.collect()
}

fn all_contract_versions(&self) -> Vec<FeatureContract> {
match self {
Self::AccountWithLongValidate(_)
| Self::AccountWithoutValidations(_)
| Self::Empty(_)
| Self::FaultyAccount(_)
| Self::TestContract(_)
| Self::ERC20(_) => {
#[cfg(not(feature = "cairo_native"))]
let versions = [CairoVersion::Cairo0, CairoVersion::Cairo1(RunnableCairo1::Casm)];
#[cfg(feature = "cairo_native")]
let versions = [
CairoVersion::Cairo0,
CairoVersion::Cairo1(RunnableCairo1::Casm),
CairoVersion::Cairo1(RunnableCairo1::Native),
];
self.iter_versions(&versions)
}

Self::SierraExecutionInfoV1Contract(_) => {
#[cfg(not(feature = "cairo_native"))]
{
vec![*self]
}
#[cfg(feature = "cairo_native")]
{
let versions = [
CairoVersion::Cairo1(RunnableCairo1::Casm),
CairoVersion::Cairo1(RunnableCairo1::Native),
];
self.iter_versions(&versions)
}
}
})

Self::LegacyTestContract | Self::CairoStepsTestContract | Self::SecurityTests => {
vec![*self]
}
}
}

pub fn all_contracts() -> impl Iterator<Item = Self> {
Self::iter().flat_map(|contract| contract.all_contract_versions())
}

pub fn all_feature_contracts() -> impl Iterator<Item = Self> {
Expand Down
Loading

0 comments on commit ef39c7f

Please sign in to comment.