From e3005276c55bdd6c831bd948b44885757348b843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lancelot=20de=20Ferri=C3=A8re?= Date: Fri, 21 Jun 2024 18:45:46 +0200 Subject: [PATCH 1/3] Fix WASM32 compilation for Cairo1-run and cairo-vm --- cairo1-run/src/cairo_run.rs | 4 ++++ vm/Cargo.toml | 4 +--- vm/src/lib.rs | 2 +- vm/src/vm/runners/cairo_pie.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 52a5ea2676..79b431c668 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -141,6 +141,10 @@ pub fn cairo_run_program( let main_func = find_function(sierra_program, "::main")?; + #[cfg(target_pointer_width = "32")] + let initial_gas = 999999999_usize; + + #[cfg(not(target_pointer_width = "32"))] let initial_gas = 9999999999999_usize; // Fetch return type data diff --git a/vm/Cargo.toml b/vm/Cargo.toml index b5ee76dc53..eb487e9631 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -37,7 +37,7 @@ test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet extensive_hints = [] [dependencies] -zip = {version = "0.6.6", optional = true } +zip = {version = "0.6.6", optional = true, default_features = false, features=["deflate"] } num-bigint = { workspace = true } rand = { workspace = true } num-traits = { workspace = true } @@ -67,8 +67,6 @@ bitvec = { workspace = true } cairo-lang-starknet = { workspace = true, optional = true } cairo-lang-starknet-classes = { workspace = true, optional = true } cairo-lang-casm = { workspace = true, optional = true } - -# TODO: check these dependencies for wasm compatibility ark-ff = { workspace = true, optional = true } ark-std = { workspace = true, optional = true } diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 5d78058f13..8ab07dbd86 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -12,7 +12,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(warnings)] #![forbid(unsafe_code)] -#![cfg_attr(any(target_arch = "wasm32", not(feature = "std")), no_std)] +#![cfg_attr(any(not(feature = "std")), no_std)] #[cfg(feature = "std")] include!("./with_std.rs"); diff --git a/vm/src/vm/runners/cairo_pie.rs b/vm/src/vm/runners/cairo_pie.rs index 371b6de82f..317cd406f3 100644 --- a/vm/src/vm/runners/cairo_pie.rs +++ b/vm/src/vm/runners/cairo_pie.rs @@ -373,7 +373,7 @@ pub(super) mod serde_impl { use super::CAIRO_PIE_VERSION; use super::{CairoPieMemory, Pages, PublicMemoryPage, SegmentInfo}; - #[cfg(any(target_arch = "wasm32", no_std, not(feature = "std")))] + #[cfg(any(no_std, not(feature = "std")))] use crate::alloc::string::ToString; use crate::stdlib::prelude::{String, Vec}; use crate::{ From bbc41271abe0e75007558d572e87e5bf60310b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lancelot=20de=20Ferri=C3=A8re?= Date: Mon, 24 Jun 2024 18:44:29 +0200 Subject: [PATCH 2/3] Switch from usize to u64 --- cairo1-run/src/cairo_run.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 79b431c668..de1bfcdbc8 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -141,11 +141,7 @@ pub fn cairo_run_program( let main_func = find_function(sierra_program, "::main")?; - #[cfg(target_pointer_width = "32")] - let initial_gas = 999999999_usize; - - #[cfg(not(target_pointer_width = "32"))] - let initial_gas = 9999999999999_usize; + let initial_gas = 9999999999999_u64; // Fetch return type data let return_type_id = match main_func.signature.ret_types.last() { @@ -457,7 +453,7 @@ fn load_arguments( runner: &mut CairoRunner, cairo_run_config: &Cairo1RunConfig, main_func: &Function, - initial_gas: usize, + initial_gas: u64, ) -> Result<(), Error> { let got_gas_builtin = main_func .signature From 8f1772a5d775cc53feba2fc19af6dc15f03084fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lancelot=20de=20Ferri=C3=A8re?= Date: Tue, 25 Jun 2024 09:37:42 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0f217250f..a7fa59f552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* fix: Fix compilation of cairo-1-run and cairo-vm on wasm32 [#1792](https://github.com/lambdaclass/cairo-vm/pull/1792) + * fix: Remove validation of CairoPie memory values [#1783](https://github.com/lambdaclass/cairo-vm/pull/1783) * fix: Handle `GasBuiltin` in cairo1-run crate [#1789](https://github.com/lambdaclass/cairo-vm/pull/1789)