From 4ffb768fac5655823d5dbd91cef4ff0f70f2edad Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Sun, 10 Mar 2024 05:23:44 +0000 Subject: [PATCH] feat: add support for Sierra 1.5.0 --- Cargo.lock | 199 +++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 5 +- src/casm.rs | 6 +- src/compiler.rs | 26 ++++++- 4 files changed, 202 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e82d747..222b2b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,6 +418,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cairo-lang-casm" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-lang-utils 2.6.2", + "indoc", + "num-bigint", + "num-traits 0.2.16", + "parity-scale-codec", + "serde", +] + [[package]] name = "cairo-lang-compiler" version = "2.4.0" @@ -549,6 +562,15 @@ dependencies = [ "good_lp", ] +[[package]] +name = "cairo-lang-eq-solver" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-lang-utils 2.6.2", + "good_lp", +] + [[package]] name = "cairo-lang-filesystem" version = "2.4.0" @@ -841,6 +863,31 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "anyhow", + "cairo-felt 0.9.1", + "cairo-lang-utils 2.6.2", + "const-fnv1a-hash", + "convert_case", + "derivative", + "itertools 0.11.0", + "lalrpop", + "lalrpop-util", + "num-bigint", + "num-traits 0.2.16", + "regex", + "salsa", + "serde", + "serde_json", + "sha3", + "smol_str", + "thiserror", +] + [[package]] name = "cairo-lang-sierra-ap-change" version = "2.4.0" @@ -868,6 +915,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra-ap-change" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-lang-eq-solver 2.6.2", + "cairo-lang-sierra 2.6.2", + "cairo-lang-sierra-type-size 2.6.2", + "cairo-lang-utils 2.6.2", + "itertools 0.11.0", + "num-traits 0.2.16", + "thiserror", +] + [[package]] name = "cairo-lang-sierra-gas" version = "2.4.0" @@ -895,6 +956,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra-gas" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-lang-eq-solver 2.6.2", + "cairo-lang-sierra 2.6.2", + "cairo-lang-sierra-type-size 2.6.2", + "cairo-lang-utils 2.6.2", + "itertools 0.11.0", + "num-traits 0.2.16", + "thiserror", +] + [[package]] name = "cairo-lang-sierra-generator" version = "2.4.0" @@ -980,6 +1055,26 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-sierra-to-casm" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "assert_matches", + "cairo-felt 0.9.1", + "cairo-lang-casm 2.6.2", + "cairo-lang-sierra 2.6.2", + "cairo-lang-sierra-ap-change 2.6.2", + "cairo-lang-sierra-gas 2.6.2", + "cairo-lang-sierra-type-size 2.6.2", + "cairo-lang-utils 2.6.2", + "indoc", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.16", + "thiserror", +] + [[package]] name = "cairo-lang-sierra-type-size" version = "2.4.0" @@ -998,6 +1093,15 @@ dependencies = [ "cairo-lang-utils 2.5.4", ] +[[package]] +name = "cairo-lang-sierra-type-size" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-lang-sierra 2.6.2", + "cairo-lang-utils 2.6.2", +] + [[package]] name = "cairo-lang-starknet" version = "2.4.0" @@ -1071,6 +1175,30 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cairo-lang-starknet-classes" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "cairo-felt 0.9.1", + "cairo-lang-casm 2.6.2", + "cairo-lang-sierra 2.6.2", + "cairo-lang-sierra-to-casm 2.6.2", + "cairo-lang-utils 2.6.2", + "convert_case", + "itertools 0.11.0", + "num-bigint", + "num-integer", + "num-traits 0.2.16", + "once_cell", + "serde", + "serde_json", + "sha3", + "smol_str", + "starknet-crypto 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror", +] + [[package]] name = "cairo-lang-syntax" version = "2.4.0" @@ -1147,6 +1275,20 @@ dependencies = [ "serde", ] +[[package]] +name = "cairo-lang-utils" +version = "2.6.2" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.2#fb76dd901e5bb3d8155c3d4e2d8a39d22b6aefab" +dependencies = [ + "hashbrown 0.14.3", + "indexmap 2.1.0", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.16", + "schemars", + "serde", +] + [[package]] name = "cc" version = "1.0.82" @@ -3295,6 +3437,7 @@ dependencies = [ "bigdecimal 0.4.1", "cairo-lang-starknet 2.4.0", "cairo-lang-starknet 2.5.4", + "cairo-lang-starknet-classes", "chrono", "clap", "clap_complete", @@ -3318,7 +3461,7 @@ dependencies = [ "serde_with", "shellexpand", "starknet", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d)", "tempfile", "thiserror", "tokio", @@ -3329,13 +3472,13 @@ dependencies = [ [[package]] name = "starknet" -version = "0.8.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.9.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "starknet-accounts", "starknet-contract", "starknet-core", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d)", "starknet-ff 0.3.6", "starknet-macros", "starknet-providers", @@ -3344,8 +3487,8 @@ dependencies = [ [[package]] name = "starknet-accounts" -version = "0.7.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.8.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "async-trait", "auto_impl", @@ -3357,8 +3500,8 @@ dependencies = [ [[package]] name = "starknet-contract" -version = "0.7.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.8.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "serde", "serde_json", @@ -3371,8 +3514,8 @@ dependencies = [ [[package]] name = "starknet-core" -version = "0.8.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.9.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "base64 0.21.2", "flate2", @@ -3382,7 +3525,7 @@ dependencies = [ "serde_json_pythonic", "serde_with", "sha3", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d)", "starknet-ff 0.3.6", ] @@ -3401,7 +3544,7 @@ dependencies = [ "rfc6979", "sha2", "starknet-crypto-codegen 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-curve 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-curve 0.4.0", "starknet-ff 0.3.5", "zeroize", ] @@ -3409,7 +3552,7 @@ dependencies = [ [[package]] name = "starknet-crypto" version = "0.6.1" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "crypto-bigint", "hex", @@ -3419,8 +3562,8 @@ dependencies = [ "num-traits 0.2.16", "rfc6979", "sha2", - "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", - "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-crypto-codegen 0.3.2 (git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d)", + "starknet-curve 0.4.1", "starknet-ff 0.3.6", "zeroize", ] @@ -3431,7 +3574,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" dependencies = [ - "starknet-curve 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-curve 0.4.0", "starknet-ff 0.3.5", "syn 2.0.41", ] @@ -3439,9 +3582,9 @@ dependencies = [ [[package]] name = "starknet-crypto-codegen" version = "0.3.2" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ - "starknet-curve 0.4.0 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-curve 0.4.1", "starknet-ff 0.3.6", "syn 2.0.41", ] @@ -3457,8 +3600,8 @@ dependencies = [ [[package]] name = "starknet-curve" -version = "0.4.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.4.1" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "starknet-ff 0.3.6", ] @@ -3478,7 +3621,7 @@ dependencies = [ [[package]] name = "starknet-ff" version = "0.3.6" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "ark-ff", "bigdecimal 0.3.1", @@ -3491,8 +3634,8 @@ dependencies = [ [[package]] name = "starknet-macros" -version = "0.1.5" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.1.6" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "starknet-core", "syn 2.0.41", @@ -3500,8 +3643,8 @@ dependencies = [ [[package]] name = "starknet-providers" -version = "0.8.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.9.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "async-trait", "auto_impl", @@ -3519,8 +3662,8 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.6.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed#c974e5cb42e8d8344cee910b76005ec46b4dd3ed" +version = "0.7.0" +source = "git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d#d980869d44ef86249b4077f4ec809165f470678d" dependencies = [ "async-trait", "auto_impl", @@ -3528,7 +3671,7 @@ dependencies = [ "eth-keystore", "rand", "starknet-core", - "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=c974e5cb42e8d8344cee910b76005ec46b4dd3ed)", + "starknet-crypto 0.6.1 (git+https://github.com/xJonathanLEI/starknet-rs?rev=d980869d44ef86249b4077f4ec809165f470678d)", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 34726f0..4f9d3f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ auto_impl = "1.1.0" bigdecimal = "0.4.1" cairo-starknet-2-4-0 = { package = "cairo-lang-starknet", git = "https://github.com/starkware-libs/cairo", tag = "v2.4.0" } cairo-starknet-2-5-4 = { package = "cairo-lang-starknet", git = "https://github.com/starkware-libs/cairo", tag = "v2.5.4" } +cairo-starknet-2-6-2 = { package = "cairo-lang-starknet-classes", git = "https://github.com/starkware-libs/cairo", tag = "v2.6.2" } chrono = "0.4.26" clap = { version = "4.3.8", features = ["derive", "env", "string"] } clap_complete = "4.3.1" @@ -35,8 +36,8 @@ serde = { version = "1.0.164", features = ["derive"] } serde_json = { version = "1.0.99", features = ["preserve_order"] } serde_with = "2.3.3" shellexpand = "3.1.0" -starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "c974e5cb42e8d8344cee910b76005ec46b4dd3ed" } -starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "c974e5cb42e8d8344cee910b76005ec46b4dd3ed" } +starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "d980869d44ef86249b4077f4ec809165f470678d" } +starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "d980869d44ef86249b4077f4ec809165f470678d" } tempfile = "3.8.0" thiserror = "1.0.40" tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] } diff --git a/src/casm.rs b/src/casm.rs index 34f9adb..65bf143 100644 --- a/src/casm.rs +++ b/src/casm.rs @@ -72,11 +72,11 @@ impl CasmArgs { match network { Some(network) => { let auto_version = match network { - Network::Mainnet - | Network::Goerli + Network::Mainnet => CompilerVersion::V2_5_4, + Network::Goerli | Network::Sepolia | Network::GoerliIntegration - | Network::SepoliaIntegration => CompilerVersion::V2_5_4, + | Network::SepoliaIntegration => CompilerVersion::V2_6_2, }; eprintln!( diff --git a/src/compiler.rs b/src/compiler.rs index 218d0fe..77ed287 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -14,12 +14,18 @@ use cairo_starknet_2_5_4::{ casm_contract_class::CasmContractClass as Cairo253CasmClass, contract_class::ContractClass as Cairo253Class, }; +use cairo_starknet_2_6_2::{ + casm_contract_class::CasmContractClass as Cairo262CasmClass, + contract_class::ContractClass as Cairo262Class, +}; use clap::{builder::PossibleValue, ValueEnum}; use starknet::core::types::{ contract::{CompiledClass, SierraClass}, FieldElement, }; +const MAX_BYTECODE_SIZE: usize = 180000; + #[derive(Debug)] pub struct BuiltInCompiler { version: CompilerVersion, @@ -35,6 +41,7 @@ pub struct CompilerBinary { pub enum CompilerVersion { V2_4_0, V2_5_4, + V2_6_2, } impl BuiltInCompiler { @@ -70,6 +77,20 @@ impl BuiltInCompiler { let casm_contract = Cairo253CasmClass::from_contract_class(contract_class, false)?; + serde_json::to_string(&casm_contract)? + } + CompilerVersion::V2_6_2 => { + // TODO: directly convert type without going through JSON + let contract_class: Cairo262Class = serde_json::from_str(&sierra_class_json)?; + + // TODO: implement the `validate_compatible_sierra_version` call + + let casm_contract = Cairo262CasmClass::from_contract_class( + contract_class, + false, + MAX_BYTECODE_SIZE, + )?; + serde_json::to_string(&casm_contract)? } }; @@ -132,13 +153,14 @@ impl Default for CompilerVersion { impl ValueEnum for CompilerVersion { fn value_variants<'a>() -> &'a [Self] { - &[Self::V2_4_0, Self::V2_5_4] + &[Self::V2_4_0, Self::V2_5_4, Self::V2_6_2] } fn to_possible_value(&self) -> Option { match self { Self::V2_4_0 => Some(PossibleValue::new("2.4.0").alias("v2.4.0")), Self::V2_5_4 => Some(PossibleValue::new("2.5.4").alias("v2.5.4")), + Self::V2_6_2 => Some(PossibleValue::new("2.6.2").alias("v2.6.2")), } } } @@ -150,6 +172,7 @@ impl FromStr for CompilerVersion { match s { "2.4.0" | "v2.4.0" => Ok(Self::V2_4_0), "2.5.4" | "v2.5.4" => Ok(Self::V2_5_4), + "2.6.2" | "v2.6.2" => Ok(Self::V2_6_2), _ => Err(anyhow::anyhow!("unknown version: {}", s)), } } @@ -160,6 +183,7 @@ impl Display for CompilerVersion { match self { CompilerVersion::V2_4_0 => write!(f, "2.4.0"), CompilerVersion::V2_5_4 => write!(f, "2.5.4"), + CompilerVersion::V2_6_2 => write!(f, "2.6.2"), } } }