Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cairo_native): update cairo native version in rust to 0.3.1 #4160

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 148 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ cairo-lang-sierra = "=2.10.0-rc.1"
cairo-lang-sierra-to-casm = "2.10.0-rc.1"
cairo-lang-starknet-classes = "2.10.0-rc.1"
cairo-lang-utils = "2.10.0-rc.1"
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "981093a" }
cairo-native = "0.3.1"
cairo-vm = "=1.0.2"
camelpaste = "0.1.0"
chrono = "0.4.26"
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl NativeCompiledClassV1 {
let executor = AotContractExecutor::new(
&sierra_program,
&sierra_contract_class.entry_points_by_type,
sierra_version.clone().into(),
cairo_native::OptLevel::Default,
)
.expect("Cannot compile sierra into native");
Expand Down
5 changes: 5 additions & 0 deletions crates/blockifier/src/test_utils/test_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ fn test_cairo_version(cairo_version: CairoVersion) {
fn test_two_cairo_version(cairo_version1: CairoVersion, cairo_version2: CairoVersion) {
println!("test {:?} {:?}", cairo_version1, cairo_version2);
}

#[apply(runnable_version)]
fn test_runnable_version(runnable_version: RunnableCairo1) {
println!("test {:?}", runnable_version);
}
1 change: 1 addition & 0 deletions crates/blockifier/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub const fn const_max(a: u128, b: u128) -> u128 {
[a, b][(a < b) as usize]
}

// TODO(Meshi): Move this code to starknet API.
/// Conversion from u64 to usize. This conversion should only be used if the value came from a
/// usize.
pub fn usize_from_u64(val: u64) -> Result<usize, NumericConversionError> {
Expand Down
15 changes: 15 additions & 0 deletions crates/starknet_api/src/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;
use std::str::FromStr;

use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::compiler_version::VersionId;
use derive_more::Deref;
use semver::Version;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -30,6 +31,10 @@ pub enum EntryPointType {
L1Handler,
}

fn u64_to_usize(val: u64) -> usize {
val.try_into().expect("Failed to convert u64 version tag to usize.")
}

pub type VersionedCasm = (CasmContractClass, SierraVersion);

/// Represents a raw Starknet contract class.
Expand All @@ -53,6 +58,16 @@ impl ContractClass {
#[derive(Deref, Serialize, Deserialize, Clone, Debug, Eq, PartialEq, PartialOrd)]
pub struct SierraVersion(Version);

impl From<SierraVersion> for VersionId {
fn from(val: SierraVersion) -> Self {
VersionId {
major: u64_to_usize(val.0.major),
minor: u64_to_usize(val.0.minor),
patch: u64_to_usize(val.0.patch),
}
}
}

impl SierraVersion {
/// Version of deprecated contract class (Cairo 0).
pub const DEPRECATED: Self = Self(Version::new(0, 0, 0));
Expand Down
13 changes: 2 additions & 11 deletions crates/starknet_sierra_multicompile/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {

const REQUIRED_CAIRO_LANG_VERSION: &str = "2.7.1";
#[cfg(feature = "cairo_native")]
const REQUIRED_CAIRO_NATIVE_VERSION: &str = "0.2.5";
const REQUIRED_CAIRO_NATIVE_VERSION: &str = "0.3.1";

/// Downloads the Cairo crate from StarkWare's release page and extracts its contents into the
/// `target` directory. This crate includes the `starknet-sierra-compile` binary, which is used to
Expand All @@ -40,16 +40,7 @@ fn install_starknet_native_compile() {
let binary_name = CAIRO_NATIVE_BINARY_NAME;
let required_version = REQUIRED_CAIRO_NATIVE_VERSION;

let repo_root_dir =
starknet_infra_utils::path::project_path().expect("Should be able to get the project path");

let starknet_native_compile_crate_path = repo_root_dir.join("crates/bin").join(binary_name);
let starknet_native_compile_crate_path_str = starknet_native_compile_crate_path
.to_str()
.expect("Failed to convert the crate path to str");
println!("cargo:rerun-if-changed={}", starknet_native_compile_crate_path_str);

let cargo_install_args = &["--path", starknet_native_compile_crate_path_str];
let cargo_install_args = &["cairo-native", "--version", required_version, "--bin", binary_name];
install_compiler_binary(binary_name, required_version, cargo_install_args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ impl SierraToNativeCompiler for CommandLineCompiler {
let output_file_path = output_file.path().to_str().ok_or(
CompilationUtilError::UnexpectedError("Failed to get output file path".to_owned()),
)?;
let additional_args = [output_file_path];
// TODO(Meshi): When adding a config for optimization level change it here.
let additional_args = [output_file_path, "--opt-level", "2"];
let resource_limits = ResourceLimits::new(
Some(self.config.max_cpu_time),
Some(self.config.max_native_bytecode_size),
Expand All @@ -92,7 +93,7 @@ impl SierraToNativeCompiler for CommandLineCompiler {
resource_limits,
)?;

Ok(AotContractExecutor::load(Path::new(&output_file_path))?)
Ok(AotContractExecutor::from_path(Path::new(&output_file_path))?.unwrap())
}
}

Expand Down
Loading