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

Fix WASM32 compilation for Cairo1-run and cairo-vm #1792

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions cairo1-run/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this value works, why not just use this?
Otherwise, why not change initial_gas to a u64 instead of usize?

Copy link
Author

@wraitii wraitii Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this value works, why not just use this?

It compiles, but that doesn't tell me it's 'working' - I haven't really checked what it's being used for, and this is a billion gas - perhaps an achievable amount (where 1 trillion wasn't). If it's used to initialise a "Max" value, it's perhaps unsafe - would need someone to know why 999999999999 was chosen in the first place.

Otherwise, why not change initial_gas to a u64 instead of usize?

Much smaller change / laziness, but I can update the PR to change this to u64 for sure
Edit: mh actually should probably just have tried that, it's just a few lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It compiles, but that doesn't tell me it's 'working' - I haven't really checked what it's being used for, and this is a billion gas - perhaps an achievable amount (where 1 trillion wasn't). If it's used to initialise a "Max" value, it's perhaps unsafe - would need someone to know why 999999999999 was chosen in the first place.

IIUC that's just a "should be enough to not fail due to gas exhaustion" value, nothing else. I personally prefer to use the MAX constant for whatever type I'm using to make it more obvious that this is just a sloppy infinity value.


#[cfg(not(target_pointer_width = "32"))]
let initial_gas = 9999999999999_usize;

// Fetch return type data
Expand Down
4 changes: 1 addition & 3 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/runners/cairo_pie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Loading