Skip to content

Commit

Permalink
feat: upgrade cairo compiler to 2.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Sep 22, 2024
1 parent db63131 commit 14ad06f
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 4 deletions.
189 changes: 189 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ auto_impl = "1.1.0"
bigdecimal = "0.4.1"
cairo-starknet-2-6-4 = { package = "cairo-lang-starknet-classes", git = "https://github.com/starkware-libs/cairo", tag = "v2.6.4" }
cairo-starknet-2-7-1 = { package = "cairo-lang-starknet-classes", git = "https://github.com/starkware-libs/cairo", tag = "v2.7.1" }
cairo-starknet-2-8-2 = { package = "cairo-lang-starknet-classes", git = "https://github.com/starkware-libs/cairo", tag = "v2.8.2" }
chrono = "0.4.26"
clap = { version = "4.3.8", features = ["derive", "env", "string"] }
clap_complete = "4.3.1"
Expand Down
5 changes: 2 additions & 3 deletions src/casm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ impl CasmArgs {
match network {
Some(network) => {
let auto_version = match network {
Network::Sepolia | Network::SepoliaIntegration => {
CompilerVersion::V2_7_1
Network::Sepolia | Network::SepoliaIntegration | Network::Mainnet => {
CompilerVersion::V2_8_2
}
Network::Mainnet => CompilerVersion::V2_6_4,
};

eprintln!(
Expand Down
29 changes: 28 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use cairo_starknet_2_7_1::{
casm_contract_class::CasmContractClass as Cairo271CasmClass,
contract_class::ContractClass as Cairo271Class,
};
use cairo_starknet_2_8_2::{
casm_contract_class::CasmContractClass as Cairo282CasmClass,
contract_class::ContractClass as Cairo282Class,
};
use clap::{builder::PossibleValue, ValueEnum};
use starknet::core::types::{
contract::{CompiledClass, SierraClass},
Expand All @@ -37,6 +41,7 @@ pub struct CompilerBinary {
pub enum CompilerVersion {
V2_6_4,
V2_7_1,
V2_8_2,
}

impl BuiltInCompiler {
Expand Down Expand Up @@ -69,6 +74,20 @@ impl BuiltInCompiler {
serde_json::to_string(&casm_contract)?
}
CompilerVersion::V2_7_1 => {
// TODO: directly convert type without going through JSON
let contract_class: Cairo282Class = serde_json::from_str(&sierra_class_json)?;

// TODO: implement the `validate_compatible_sierra_version` call

let casm_contract = Cairo282CasmClass::from_contract_class(
contract_class,
false,
MAX_BYTECODE_SIZE,
)?;

serde_json::to_string(&casm_contract)?
}
CompilerVersion::V2_8_2 => {
// TODO: directly convert type without going through JSON
let contract_class: Cairo271Class = serde_json::from_str(&sierra_class_json)?;

Expand Down Expand Up @@ -142,7 +161,7 @@ impl Default for CompilerVersion {

impl ValueEnum for CompilerVersion {
fn value_variants<'a>() -> &'a [Self] {
&[Self::V2_6_4, Self::V2_7_1]
&[Self::V2_6_4, Self::V2_7_1, Self::V2_8_2]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
Expand All @@ -159,6 +178,12 @@ impl ValueEnum for CompilerVersion {
.alias("2.7")
.alias("v2.7"),
),
Self::V2_8_2 => Some(
PossibleValue::new("2.8.2")
.alias("v2.8.2")
.alias("2.8")
.alias("v2.8"),
),
}
}
}
Expand All @@ -170,6 +195,7 @@ impl FromStr for CompilerVersion {
match s {
"2.6.4" | "v2.6.4" | "2.6" | "v2.6" => Ok(Self::V2_6_4),
"2.7.1" | "v2.7.1" | "2.7" | "v2.7" => Ok(Self::V2_7_1),
"2.8.2" | "v2.8.2" | "2.8" | "v2.8" => Ok(Self::V2_8_2),
_ => Err(anyhow::anyhow!("unknown version: {}", s)),
}
}
Expand All @@ -180,6 +206,7 @@ impl Display for CompilerVersion {
match self {
CompilerVersion::V2_6_4 => write!(f, "2.6.4"),
CompilerVersion::V2_7_1 => write!(f, "2.7.1"),
CompilerVersion::V2_8_2 => write!(f, "2.8.2"),
}
}
}
Expand Down

0 comments on commit 14ad06f

Please sign in to comment.