Skip to content

Commit

Permalink
Unified crate for Cairo deps used in Katana (dojoengine#1999)
Browse files Browse the repository at this point in the history
* unified cairo crate forr katana

* update

* remove license file field
  • Loading branch information
kariy authored May 27, 2024
1 parent 666d835 commit 492f5ae
Show file tree
Hide file tree
Showing 13 changed files with 718 additions and 250 deletions.
890 changes: 663 additions & 227 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dojo-types = { path = "crates/dojo-types" }
dojo-world = { path = "crates/dojo-world" }

# katana
katana-cairo = { path = "crates/katana/cairo" }
katana-codecs = { path = "crates/katana/storage/codecs" }
katana-codecs-derive = { path = "crates/katana/storage/codecs/derive" }
katana-core = { path = "crates/katana/core", default-features = false }
Expand Down
19 changes: 19 additions & 0 deletions crates/katana/cairo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
description = "Collection of Cairo language dependencies that are used throughout Katana. Unifying the Cairo language based dependencies to avoid dependency conflict with the versions used by Dojo."
edition.workspace = true
license.workspace = true
name = "katana-cairo"
repository.workspace = true
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

# Use from git instead of crates.io registry so that the workspace patches aren't applied.
[dependencies]
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.3" }
cairo-vm = "0.9.2"
13 changes: 13 additions & 0 deletions crates/katana/cairo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![warn(unused_crate_dependencies)]

//! Re-export of the Cairo language crates used throughout Katana.
pub mod lang {
pub use {
cairo_lang_casm as casm, cairo_lang_runner as runner, cairo_lang_sierra as sierra,
cairo_lang_starknet as starknet, cairo_lang_starknet_classes as starknet_classes,
cairo_lang_utils as utils,
};
}

pub use cairo_vm;
8 changes: 4 additions & 4 deletions crates/katana/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ tracing.workspace = true
alloy-primitives.workspace = true

# blockifier deps
blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "7d866a24", features = [ "testing" ], optional = true }
cairo-vm = { workspace = true, optional = true }
blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "57c11586", features = [ "testing" ], optional = true }
katana-cairo = { workspace = true, optional = true }

# Disable SIR for now until they support Cairo 2.6.3
# # starknet_in_rust deps
Expand All @@ -33,7 +33,7 @@ cairo-vm = { workspace = true, optional = true }

[dev-dependencies]
anyhow.workspace = true
cairo-vm.workspace = true
katana-cairo.workspace = true
katana-provider = { workspace = true, features = [ "test-utils" ] }
katana-rpc-types.workspace = true
rstest.workspace = true
Expand All @@ -46,7 +46,7 @@ criterion.workspace = true
pprof = { version = "0.13.0", features = [ "criterion", "flamegraph" ] }

[features]
blockifier = [ "dep:blockifier", "dep:cairo-vm" ]
blockifier = [ "dep:blockifier", "dep:katana-cairo" ]
default = [ "blockifier" ]
# native = [ "sir", "sir/cairo-native" ]
# sir = [ "dep:sir", "dep:starknet-types-core" ]
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/executor/benches/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use cairo_vm::vm::runners::builtin_runner::{
use katana_cairo::cairo_vm::vm::runners::builtin_runner::{
BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, KECCAK_BUILTIN_NAME,
OUTPUT_BUILTIN_NAME, POSEIDON_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME,
SEGMENT_ARENA_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME,
Expand Down
6 changes: 3 additions & 3 deletions crates/katana/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use blockifier::transaction::transactions::{
L1HandlerTransaction,
};
use blockifier::versioned_constants::VersionedConstants;
use cairo_vm::types::errors::program_errors::ProgramError;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_cairo::cairo_vm::types::errors::program_errors::ProgramError;
use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_primitives::env::{BlockEnv, CfgEnv};
use katana_primitives::fee::TxFeeInfo;
use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses};
Expand Down Expand Up @@ -656,7 +656,7 @@ mod tests {

use std::collections::HashSet;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_primitives::chain::{ChainId, NamedChainId};
use starknet_api::core::EntryPointSelector;
use starknet_api::hash::StarkFelt;
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/executor/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod transaction;
use std::collections::HashMap;

use alloy_primitives::U256;
use cairo_vm::vm::runners::builtin_runner::{
use katana_cairo::cairo_vm::vm::runners::builtin_runner::{
BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, KECCAK_BUILTIN_NAME,
OUTPUT_BUILTIN_NAME, POSEIDON_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME,
SEGMENT_ARENA_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME,
Expand Down
5 changes: 1 addition & 4 deletions crates/katana/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version.workspace = true
[dependencies]
anyhow.workspace = true
base64.workspace = true
cairo-vm.workspace = true
derive_more.workspace = true
lazy_static.workspace = true
rand = { workspace = true, features = [ "small_rng" ] }
Expand All @@ -24,10 +23,8 @@ strum_macros.workspace = true
thiserror.workspace = true

alloy-primitives.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-starknet-classes.workspace = true
cairo-lang-starknet.workspace = true
flate2.workspace = true
katana-cairo.workspace = true
starknet_api.workspace = true

[dev-dependencies]
Expand Down
8 changes: 5 additions & 3 deletions crates/katana/primitives/src/class.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use katana_cairo::lang::sierra::program::Program;
use katana_cairo::lang::starknet_classes::casm_contract_class::CasmContractClass;
use katana_cairo::lang::starknet_classes::contract_class::ContractEntryPoints;

use crate::FieldElement;

Expand All @@ -17,8 +19,8 @@ pub type DeprecatedCompiledClass = ::starknet_api::deprecated_contract_class::Co
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SierraProgram {
pub program: cairo_lang_sierra::program::Program,
pub entry_points_by_type: cairo_lang_starknet_classes::contract_class::ContractEntryPoints,
pub program: Program,
pub entry_points_by_type: ContractEntryPoints,
}

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
6 changes: 3 additions & 3 deletions crates/katana/primitives/src/conversion/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
use std::mem;

use anyhow::{Context, Result};
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use katana_cairo::lang::starknet_classes::casm_contract_class::CasmContractClass;
use serde::Deserialize;
use serde_json::json;
use serde_with::serde_as;
Expand Down Expand Up @@ -186,10 +186,10 @@ pub fn legacy_rpc_to_compiled_class(
/// [ContractClass](cairo_lang_starknet::contract_class::ContractClass) type.
fn rpc_to_cairo_contract_class(
contract_class: &FlattenedSierraClass,
) -> Result<cairo_lang_starknet_classes::contract_class::ContractClass, std::io::Error> {
) -> Result<katana_cairo::lang::starknet_classes::contract_class::ContractClass, std::io::Error> {
let value = serde_json::to_value(contract_class)?;

Ok(cairo_lang_starknet_classes::contract_class::ContractClass {
Ok(katana_cairo::lang::starknet_classes::contract_class::ContractClass {
abi: serde_json::from_value(value["abi"].clone()).ok(),
sierra_program: serde_json::from_value(value["sierra_program"].clone())?,
entry_points_by_type: serde_json::from_value(value["entry_points_by_type"].clone())?,
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/primitives/src/genesis/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::sync::Arc;

use alloy_primitives::U256;
use base64::prelude::*;
use cairo_lang_starknet_classes::casm_contract_class::StarknetSierraCompilationError;
use cairo_vm::types::errors::program_errors::ProgramError;
use katana_cairo::cairo_vm::types::errors::program_errors::ProgramError;
use katana_cairo::lang::starknet_classes::casm_contract_class::StarknetSierraCompilationError;
use serde::de::value::MapAccessDeserializer;
use serde::de::Visitor;
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/primitives/src/utils/class.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::contract_class::ContractClass;
use katana_cairo::lang::starknet_classes::casm_contract_class::CasmContractClass;
use katana_cairo::lang::starknet_classes::contract_class::ContractClass;
use serde_json::Value;

use crate::class::{
Expand Down

0 comments on commit 492f5ae

Please sign in to comment.