From 129c51bd2ea5b6669179f1d964e438e30a77436b Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 29 Aug 2024 18:06:23 -0300 Subject: [PATCH 01/37] refeactor cairo1-run to use no-std --- Cargo.lock | 51 +++++++++------------ Cargo.toml | 6 +++ cairo1-run/Cargo.toml | 11 ++++- cairo1-run/src/cairo_run.rs | 6 +-- cairo1-run/src/error.rs | 4 ++ cairo1-run/src/main.rs | 1 + examples/wasm-demo-cairo1/Cargo.toml | 32 +++++++++++++ examples/wasm-demo-cairo1/README.md | 48 +++++++++++++++++++ examples/wasm-demo-cairo1/index.html | 30 ++++++++++++ examples/wasm-demo-cairo1/src/bitwise.cairo | 13 ++++++ examples/wasm-demo-cairo1/src/lib.rs | 51 +++++++++++++++++++++ examples/wasm-demo-cairo1/src/utils.rs | 10 ++++ vm/Cargo.toml | 2 +- 13 files changed, 230 insertions(+), 35 deletions(-) create mode 100644 examples/wasm-demo-cairo1/Cargo.toml create mode 100644 examples/wasm-demo-cairo1/README.md create mode 100644 examples/wasm-demo-cairo1/index.html create mode 100644 examples/wasm-demo-cairo1/src/bitwise.cairo create mode 100644 examples/wasm-demo-cairo1/src/lib.rs create mode 100644 examples/wasm-demo-cairo1/src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 667a43f353..baf1d51ba8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1039,6 +1039,7 @@ dependencies = [ "rstest", "serde_json", "thiserror", + "thiserror-no-std", ] [[package]] @@ -2593,11 +2594,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit 0.21.1", + "toml_edit", ] [[package]] @@ -2839,18 +2840,18 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags 2.6.0", "errno", @@ -3433,7 +3434,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.20", + "toml_edit", ] [[package]] @@ -3445,17 +3446,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap 2.4.0", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.20" @@ -3466,7 +3456,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.18", + "winnow", ] [[package]] @@ -3802,6 +3792,18 @@ dependencies = [ "wasm-bindgen-test", ] +[[package]] +name = "wasm-demo-cairo1" +version = "1.0.1" +dependencies = [ + "cairo-vm", + "cairo1-run", + "console_error_panic_hook", + "serde_json", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "web-sys" version = "0.3.69" @@ -3991,15 +3993,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.6.18" diff --git a/Cargo.toml b/Cargo.toml index f5f2d34118..74cbc103d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "vm", "hint_accountant", "examples/wasm-demo", + "examples/wasm-demo-cairo1", "cairo1-run", "cairo-vm-tracer", "examples/hyper_threading" @@ -29,6 +30,7 @@ keywords = ["starknet", "cairo", "vm", "wasm", "no_std"] [workspace.dependencies] cairo-vm = { path = "./vm", version = "1.0.1", default-features = false } +cairo1-run = { path = "./cairo1-run", version = "1.0.1", default-features = false } cairo-vm-tracer = { path = "./cairo-vm-tracer", version = "1.0.1", default-features = false } mimalloc = { version = "0.1.37", default-features = false } num-bigint = { version = "0.4", default-features = false, features = [ @@ -93,6 +95,10 @@ lto = "fat" # Tell `rustc` to optimize for small code size. opt-level = "s" +[profile.release.package.wasm-demo-cairo1] +# Tell `rustc` to optimize for small code size. +opt-level = "s" + [profile.test.package.proptest] opt-level = 3 diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index b5022d994b..2ed6d89ab4 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -23,7 +23,8 @@ cairo-lang-utils.workspace = true cairo-lang-casm.workspace = true itertools = "0.11.0" clap = { version = "4.3.10", features = ["derive"] } -thiserror = { version = "1.0.40" } +thiserror = { version = "1.0.40", optional = true } +thiserror-no-std = { workspace = true } bincode.workspace = true assert_matches = "1.5.0" rstest = "0.17.0" @@ -32,5 +33,11 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc"] +default = ["with_mimalloc", "cli"] with_mimalloc = ["dep:mimalloc"] +cli = ["dep:thiserror"] + +[[bin]] +name = "cairo1-run" +path = "./src/main.rs" +required-features = ["cli"] diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index 700225b880..ad484f6d59 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -47,11 +47,11 @@ use cairo_vm::{ vm_core::VirtualMachine, }, Felt252, + stdlib::{collections::HashMap, iter::Peekable, cmp, prelude::*} }; use itertools::{chain, Itertools}; use num_bigint::{BigInt, Sign}; use num_traits::{cast::ToPrimitive, Zero}; -use std::{collections::HashMap, iter::Peekable}; /// Representation of a cairo argument /// Can consist of a single Felt or an array of Felts @@ -140,7 +140,7 @@ pub fn cairo_run_program( let main_func = find_function(sierra_program, "::main")?; - let initial_gas = 9999999999999_usize; + let initial_gas = 9_usize;//9999999999999_usize; // Fetch return type data let return_type_id = match main_func.signature.ret_types.last() { @@ -1384,7 +1384,7 @@ fn serialize_output_inner<'a>( let mut max_variant_size = 0; for variant in &info.variants { let variant_size = type_sizes.get(variant).unwrap(); - max_variant_size = std::cmp::max(max_variant_size, *variant_size) + max_variant_size = cmp::max(max_variant_size, *variant_size) } for _ in 0..max_variant_size - type_sizes.get(variant_type_id).unwrap() { // Remove padding diff --git a/cairo1-run/src/error.rs b/cairo1-run/src/error.rs index 49f2c18cb9..f0ac6d7dcf 100644 --- a/cairo1-run/src/error.rs +++ b/cairo1-run/src/error.rs @@ -10,12 +10,16 @@ use cairo_vm::{ }, Felt252, }; +#[cfg(feature = "cli")] use thiserror::Error; +#[cfg(not(feature = "cli"))] +use thiserror_no_std::Error; #[derive(Debug, Error)] pub enum Error { #[error("Invalid arguments")] Cli(#[from] clap::Error), + #[cfg(feature = "cli")] #[error("Failed to interact with the file system")] IO(#[from] std::io::Error), #[error(transparent)] diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 8a4a5058bb..a337cc6fae 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -10,6 +10,7 @@ use cairo_vm::{ }; use clap::{Parser, ValueHint}; use itertools::Itertools; +use cairo_vm::stdlib::prelude::*; use std::{ io::{self, Write}, path::PathBuf, diff --git a/examples/wasm-demo-cairo1/Cargo.toml b/examples/wasm-demo-cairo1/Cargo.toml new file mode 100644 index 0000000000..9caa19279a --- /dev/null +++ b/examples/wasm-demo-cairo1/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "wasm-demo-cairo1" +description = "A demo using cairo-vm in a WASM environment" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +readme = "README.md" +keywords.workspace = true +publish = false + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["console_error_panic_hook"] + +[dependencies] +serde_json.workspace = true +wasm-bindgen = "0.2.87" + +# The `console_error_panic_hook` crate provides better debugging of panics by +# logging them with `console.error`. This is great for development, but requires +# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for +# code size when deploying. +console_error_panic_hook = { version = "0.1.6", optional = true } + +cairo1-run = { workspace = true } +cairo-vm = { workspace = true } + +[dev-dependencies] +wasm-bindgen-test = "0.3.34" diff --git a/examples/wasm-demo-cairo1/README.md b/examples/wasm-demo-cairo1/README.md new file mode 100644 index 0000000000..26343c2593 --- /dev/null +++ b/examples/wasm-demo-cairo1/README.md @@ -0,0 +1,48 @@ +# Demo of `cairo-vm` on WebAssembly + +While cairo-vm is compatible with WebAssembly, it doesn't implement any bindings to it. +Instead, create a new WebAssembly crate with cairo-vm as a dependency and implement the required functionality there. + +Since mimalloc is not automatically compilable to WebAssembly, the cairo-vm dependency should disable the default features, which will in turn disable mimalloc. + +A working example is provided in this repository. + +## Dependencies + +To compile and run the example you need: + +- a Cairo 0 compiler +- the _wasm-pack_ crate +- some HTTP server (for example: the `live-server` npm module) + +> **Note** +> The first two dependencies can be installed via the repository's installation script (see ["Installation script"](../../README.md#installation-script)) + +## Building + +To build the example, first compile your Cairo program: + +```sh +cairo-compile ../../cairo_programs/array_sum.cairo --no_debug_info --output ../../cairo_programs/array_sum.json +``` + +And then the WebAssembly package: + +```sh +wasm-pack build --target=web +``` + +This will generate a javascript module that is directly loadable by the browser. + +## Running + +To run the example webpage, you need to run an HTTP server. +For example, using the _live-server_ npm module: + +```sh +# while in /examples/wasm-demo +npx live-server +``` + +> **Warning** +> Trying to run `index.html` directly (i.e. URL starts with `file://`) will result in a CORS error. diff --git a/examples/wasm-demo-cairo1/index.html b/examples/wasm-demo-cairo1/index.html new file mode 100644 index 0000000000..5d0f1b7676 --- /dev/null +++ b/examples/wasm-demo-cairo1/index.html @@ -0,0 +1,30 @@ + + + + + + + + + Cairo WebAssembly Demo + + + + + +

Result:

+ + + diff --git a/examples/wasm-demo-cairo1/src/bitwise.cairo b/examples/wasm-demo-cairo1/src/bitwise.cairo new file mode 100644 index 0000000000..2a09d1348c --- /dev/null +++ b/examples/wasm-demo-cairo1/src/bitwise.cairo @@ -0,0 +1,13 @@ +fn main() { + let a = 1234_u128; + let b = 5678_u128; + + let c0 = a & b; + let c1 = a ^ b; + let c2 = a | b; + + let c3 = c0 + c1 + c2; + println!("{}", c3); + + return c3; +} diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs new file mode 100644 index 0000000000..6e2df2e65e --- /dev/null +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -0,0 +1,51 @@ +mod utils; + +use cairo1_run::{cairo_run_program, Cairo1RunConfig}; +use cairo_vm::types::layout_name::LayoutName; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_namespace = console)] + fn log(msg: &str); +} + +#[wasm_bindgen(start)] +pub fn start() { + crate::utils::set_panic_hook(); +} + +// TODO: check why this is needed. Seems wasm-bindgen expects us to use +// `std::error::Error` even if it's not yet in `core` +macro_rules! wrap_error { + ($xp: expr) => { + $xp.map_err(|e| JsError::new(e.to_string().as_str())) + }; +} + +#[wasm_bindgen(js_name = runCairoProgram)] +pub fn run_cairo_program() -> Result { + const PROGRAM: &[u8] = include_bytes!("../bitwise.sierra"); + + let cairo_run_config = Cairo1RunConfig { + layout: LayoutName::all_cairo, + relocate_mem: true, + trace_enabled: true, + ..Default::default() + }; + + let sierra_program = serde_json::from_slice(PROGRAM)?; + + let (mut runner, _, _) = wrap_error!(cairo_run_program( + &sierra_program, + cairo_run_config, + ))?; + + let mut buffer = String::new(); + + wrap_error!(runner.vm.write_output(&mut buffer))?; + + log(buffer.as_str()); + + Ok(buffer) +} diff --git a/examples/wasm-demo-cairo1/src/utils.rs b/examples/wasm-demo-cairo1/src/utils.rs new file mode 100644 index 0000000000..b1d7929dc9 --- /dev/null +++ b/examples/wasm-demo-cairo1/src/utils.rs @@ -0,0 +1,10 @@ +pub fn set_panic_hook() { + // When the `console_error_panic_hook` feature is enabled, we can call the + // `set_panic_hook` function at least once during initialization, and then + // we will get better error messages if our code ever panics. + // + // For more details see + // https://github.com/rustwasm/console_error_panic_hook#readme + #[cfg(feature = "console_error_panic_hook")] + console_error_panic_hook::set_once(); +} diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 6311f1b562..a64781cab1 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -18,7 +18,7 @@ std = [ "starknet-crypto/std", "dep:num-prime", "thiserror-no-std/std", - "dep:zip", + "dep:zip" ] cairo-1-hints = [ "dep:cairo-lang-starknet", From 2416a963b7705e654ccce277b53800ef1984918f Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 14:43:21 -0300 Subject: [PATCH 02/37] cairo 1 running with wasm --- Cargo.lock | 9 +++-- cairo1-run/Cargo.toml | 2 +- cairo1-run/src/cairo_run.rs | 6 +-- cairo1-run/src/main.rs | 3 +- examples/wasm-demo-cairo1/Cargo.toml | 1 + examples/wasm-demo-cairo1/index.html | 42 ++++++++++----------- examples/wasm-demo-cairo1/src/bitwise.cairo | 5 +-- examples/wasm-demo-cairo1/src/lib.rs | 31 ++++++++------- examples/wasm-demo/src/lib.rs | 2 +- vm/Cargo.toml | 20 +++++++--- 10 files changed, 67 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index baf1d51ba8..06222e1586 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2330,9 +2330,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -3387,9 +3387,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -3796,6 +3796,7 @@ dependencies = [ name = "wasm-demo-cairo1" version = "1.0.1" dependencies = [ + "cairo-lang-sierra", "cairo-vm", "cairo1-run", "console_error_panic_hook", diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 2ed6d89ab4..e2b4dfd6e8 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -9,7 +9,7 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cairo-vm = {workspace = true, features = ["std", "cairo-1-hints", "clap"]} +cairo-vm = { workspace = true, features = ["cairo-1-hints", "clap"] } serde_json = { workspace = true } cairo-lang-sierra-type-size = { version = "2.7.1", default-features = false } diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index ad484f6d59..40e19f729d 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -37,6 +37,7 @@ use cairo_vm::{ hint_processor::cairo_1_hint_processor::hint_processor::Cairo1HintProcessor, math_utils::signed_felt, serde::deserialize_program::{ApTracking, FlowTrackingData, HintParams, ReferenceManager}, + stdlib::{cmp, collections::HashMap, iter::Peekable}, types::{ builtin_name::BuiltinName, layout_name::LayoutName, program::Program, relocatable::MaybeRelocatable, @@ -47,7 +48,6 @@ use cairo_vm::{ vm_core::VirtualMachine, }, Felt252, - stdlib::{collections::HashMap, iter::Peekable, cmp, prelude::*} }; use itertools::{chain, Itertools}; use num_bigint::{BigInt, Sign}; @@ -140,7 +140,7 @@ pub fn cairo_run_program( let main_func = find_function(sierra_program, "::main")?; - let initial_gas = 9_usize;//9999999999999_usize; + let initial_gas = u32::MAX as usize; // Fetch return type data let return_type_id = match main_func.signature.ret_types.last() { @@ -1231,7 +1231,7 @@ fn serialize_output_inner<'a>( .expect("Missing return value") .get_relocatable() .expect("Box Pointer is not Relocatable"); - let type_size = type_sizes[&info.ty].try_into().expect("could not parse to usize"); + let type_size = type_sizes[&info.ty].try_into().expect("could not parse to usize"); let data = vm .get_continuous_range(ptr, type_size) .expect("Failed to extract value from nullable ptr"); diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index a337cc6fae..037675ae41 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -10,7 +10,6 @@ use cairo_vm::{ }; use clap::{Parser, ValueHint}; use itertools::Itertools; -use cairo_vm::stdlib::prelude::*; use std::{ io::{self, Write}, path::PathBuf, @@ -33,7 +32,7 @@ struct Args { air_public_input: Option, #[clap( long = "air_private_input", - requires_all = ["proof_mode", "trace_file", "memory_file"] + requires_all = ["proof_mode", "trace_file", "memory_file"] )] air_private_input: Option, #[clap( diff --git a/examples/wasm-demo-cairo1/Cargo.toml b/examples/wasm-demo-cairo1/Cargo.toml index 9caa19279a..731cedb7d4 100644 --- a/examples/wasm-demo-cairo1/Cargo.toml +++ b/examples/wasm-demo-cairo1/Cargo.toml @@ -18,6 +18,7 @@ default = ["console_error_panic_hook"] [dependencies] serde_json.workspace = true wasm-bindgen = "0.2.87" +cairo-lang-sierra = { workspace = true } # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/examples/wasm-demo-cairo1/index.html b/examples/wasm-demo-cairo1/index.html index 5d0f1b7676..beb451b259 100644 --- a/examples/wasm-demo-cairo1/index.html +++ b/examples/wasm-demo-cairo1/index.html @@ -1,30 +1,28 @@ - + + + + + - - - - + Cairo WebAssembly Demo - Cairo WebAssembly Demo + - - - -

Result:

- + // Display the result. + document.getElementById("result").innerHTML += value; + + + +

Result:

+ diff --git a/examples/wasm-demo-cairo1/src/bitwise.cairo b/examples/wasm-demo-cairo1/src/bitwise.cairo index 2a09d1348c..5b772d31c6 100644 --- a/examples/wasm-demo-cairo1/src/bitwise.cairo +++ b/examples/wasm-demo-cairo1/src/bitwise.cairo @@ -1,4 +1,4 @@ -fn main() { +fn main() -> u128 { let a = 1234_u128; let b = 5678_u128; @@ -7,7 +7,6 @@ fn main() { let c2 = a | b; let c3 = c0 + c1 + c2; - println!("{}", c3); - return c3; + c3 } diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 6e2df2e65e..9d4bf39e73 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -1,6 +1,7 @@ mod utils; use cairo1_run::{cairo_run_program, Cairo1RunConfig}; +use cairo_lang_sierra::ProgramParser; use cairo_vm::types::layout_name::LayoutName; use wasm_bindgen::prelude::*; @@ -25,27 +26,31 @@ macro_rules! wrap_error { #[wasm_bindgen(js_name = runCairoProgram)] pub fn run_cairo_program() -> Result { - const PROGRAM: &[u8] = include_bytes!("../bitwise.sierra"); - let cairo_run_config = Cairo1RunConfig { layout: LayoutName::all_cairo, relocate_mem: true, trace_enabled: true, + serialize_output: true, ..Default::default() }; + let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { + Ok(sierra) => sierra, + Err(_) => { + let program_str = include_str!("../bitwise.sierra"); + + let parser = ProgramParser::new(); + parser + .parse(&program_str) + .map_err(|e| e.map_token(|t| t.to_string()))? + } + }; - let sierra_program = serde_json::from_slice(PROGRAM)?; - - let (mut runner, _, _) = wrap_error!(cairo_run_program( - &sierra_program, - cairo_run_config, - ))?; - - let mut buffer = String::new(); + let (_, _, serielized_output_option) = + cairo_run_program(&sierra_program, cairo_run_config).unwrap(); - wrap_error!(runner.vm.write_output(&mut buffer))?; + let output = serielized_output_option.unwrap(); - log(buffer.as_str()); + log(&output); - Ok(buffer) + Ok(output) } diff --git a/examples/wasm-demo/src/lib.rs b/examples/wasm-demo/src/lib.rs index fc126f9499..8e5a53739a 100644 --- a/examples/wasm-demo/src/lib.rs +++ b/examples/wasm-demo/src/lib.rs @@ -28,7 +28,7 @@ macro_rules! wrap_error { #[wasm_bindgen(js_name = runCairoProgram)] pub fn run_cairo_program() -> Result { - const PROGRAM_JSON: &[u8] = include_bytes!("../../../cairo_programs/array_sum.json"); + const PROGRAM_JSON: &[u8] = include_bytes!("../array_sum.json"); let mut hint_executor = BuiltinHintProcessor::new_empty(); diff --git a/vm/Cargo.toml b/vm/Cargo.toml index a64781cab1..4f238e1938 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -18,7 +18,7 @@ std = [ "starknet-crypto/std", "dep:num-prime", "thiserror-no-std/std", - "dep:zip" + "dep:zip", ] cairo-1-hints = [ "dep:cairo-lang-starknet", @@ -31,13 +31,18 @@ tracer = [] mod_builtin = [] # Note that these features are not retro-compatible with the cairo Python VM. -test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet-types-core/std"] # This feature will reference every test-oriented feature +test_utils = [ + "std", + "dep:arbitrary", + "starknet-types-core/arbitrary", + "starknet-types-core/std", +] # This feature will reference every test-oriented feature # Allows extending the set of hints for the current vm run from within a hint. # For a usage example checkout vm/src/tests/run_deprecated_contract_class_simplified.rs extensive_hints = [] [dependencies] -zip = {version = "0.6.6", optional = true } +zip = { version = "0.6.6", optional = true } num-bigint = { workspace = true } rand = { workspace = true } num-traits = { workspace = true } @@ -56,7 +61,12 @@ keccak = { workspace = true } hashbrown = { workspace = true } anyhow = { workspace = true } thiserror-no-std = { workspace = true } -starknet-types-core = { version = "0.1.2", default-features = false, features = ["serde", "curve", "num-traits", "hash"] } +starknet-types-core = { version = "0.1.2", default-features = false, features = [ + "serde", + "curve", + "num-traits", + "hash", +] } rust_decimal = { version = "1.35.0", default-features = false } # only for std @@ -76,7 +86,7 @@ ark-std = { workspace = true, optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true } # Used to derive clap traits for CLIs -clap = { version = "4.3.10", features = ["derive"], optional = true} +clap = { version = "4.3.10", features = ["derive"], optional = true } # Pin wasm-bindgen version to fix ensure-no_std CI workflow # It's not used directly From dd55d884d5e37e915315454cf17f770dc2afaac5 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 15:02:07 -0300 Subject: [PATCH 03/37] update changelog + linting --- examples/wasm-demo-cairo1/README.md | 3 ++- examples/wasm-demo-cairo1/src/lib.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/wasm-demo-cairo1/README.md b/examples/wasm-demo-cairo1/README.md index 26343c2593..7fae7fd317 100644 --- a/examples/wasm-demo-cairo1/README.md +++ b/examples/wasm-demo-cairo1/README.md @@ -23,8 +23,9 @@ To compile and run the example you need: To build the example, first compile your Cairo program: ```sh -cairo-compile ../../cairo_programs/array_sum.cairo --no_debug_info --output ../../cairo_programs/array_sum.json +cairo1/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra ``` +> It's important to use the `-r` flag. If not, the `main`function won't be recognized. And then the WebAssembly package: diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 9d4bf39e73..2695831ff5 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -36,7 +36,8 @@ pub fn run_cairo_program() -> Result { let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { - let program_str = include_str!("../bitwise.sierra"); + let program_str = + include_str!("../../../cairo_programs/cairo-1-programs/bitwise.sierra"); let parser = ProgramParser::new(); parser @@ -46,7 +47,7 @@ pub fn run_cairo_program() -> Result { }; let (_, _, serielized_output_option) = - cairo_run_program(&sierra_program, cairo_run_config).unwrap(); + wrap_error!(cairo_run_program(&sierra_program, cairo_run_config))?; let output = serielized_output_option.unwrap(); From fc2bc99a0151329fedb2488d6a04a2d0335a9870 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 15:03:26 -0300 Subject: [PATCH 04/37] update changelog + linting --- CHANGELOG.md | 4 +++- examples/wasm-demo/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fab13c1fb..518858ee78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ #### Upcoming Changes +* chore: make cairo 1.0 compatible with wasm + * chore: bump `cairo-lang-` dependencies to 2.7.1 [#1823](https://github.com/lambdaclass/cairo-vm/pull/1823) #### [1.0.1] - 2024-08-12 -* fix(BREAKING): [#1818](https://github.com/lambdaclass/cairo-vm/pull/1818): +* fix(BREAKING): [#1818](https://github.com/lambdaclass/cairo-vm/pull/1818): * Fix `MemorySegmentManager::add_zero_segment` function when resizing a segment * Signature change(BREAKING): `MemorySegmentManager::get_memory_holes` now receives `builtin_segment_indexes: HashSet` diff --git a/examples/wasm-demo/src/lib.rs b/examples/wasm-demo/src/lib.rs index 8e5a53739a..fc126f9499 100644 --- a/examples/wasm-demo/src/lib.rs +++ b/examples/wasm-demo/src/lib.rs @@ -28,7 +28,7 @@ macro_rules! wrap_error { #[wasm_bindgen(js_name = runCairoProgram)] pub fn run_cairo_program() -> Result { - const PROGRAM_JSON: &[u8] = include_bytes!("../array_sum.json"); + const PROGRAM_JSON: &[u8] = include_bytes!("../../../cairo_programs/array_sum.json"); let mut hint_executor = BuiltinHintProcessor::new_empty(); From b5f043338f9b2fb97e0c419b99c76158c4ba1e5b Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 15:22:51 -0300 Subject: [PATCH 05/37] fix lint errors --- cairo1-run/Cargo.toml | 2 +- examples/wasm-demo-cairo1/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index e2b4dfd6e8..c74ba212f6 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -33,7 +33,7 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc", "cli"] +default = ["with_mimalloc"] with_mimalloc = ["dep:mimalloc"] cli = ["dep:thiserror"] diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 2695831ff5..d66ba681d9 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -36,8 +36,7 @@ pub fn run_cairo_program() -> Result { let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { - let program_str = - include_str!("../../../cairo_programs/cairo-1-programs/bitwise.sierra"); + let program_str = include_str!("../bitwise.sierra"); let parser = ProgramParser::new(); parser From 49d14cd63b6f801f0d1a790c1ab2f318740aa811 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 16:36:27 -0300 Subject: [PATCH 06/37] compile example test in cairo1 wasm --- CHANGELOG.md | 2 +- Makefile | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 518858ee78..1b2cbf46fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ #### Upcoming Changes -* chore: make cairo 1.0 compatible with wasm +* chore: make cairo 1.0 compatible with wasm [#1830](https://github.com/lambdaclass/cairo-vm/pull/1830) * chore: bump `cairo-lang-` dependencies to 2.7.1 [#1823](https://github.com/lambdaclass/cairo-vm/pull/1823) diff --git a/Makefile b/Makefile index f96e41a1ea..71dbd2d17a 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,9 @@ $(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ +$(TEST_DIR)/cairo-1-programs/bitwise.sierra: $(TEST_DIR)/cairo-1-programs/bitwise.cairo + ..cairo1/bin/cairo-compile $< --output $@ + $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN) cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $(@D)/$(*F).rs.trace --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip @@ -244,6 +247,7 @@ cairo_proof_programs: $(COMPILED_PROOF_TESTS) $(COMPILED_MOD_BUILTIN_PROOF_TESTS cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) cairo_2_test_contracts: $(CAIRO_2_COMPILED_CASM_CONTRACTS) +cairo_1_program_wasm: $(TEST_DIR)/cairo-1-programs/bitwise.sierra cairo_proof_trace: $(CAIRO_TRACE_PROOF) $(CAIRO_MEM_PROOF) $(CAIRO_AIR_PUBLIC_INPUT) $(CAIRO_AIR_PRIVATE_INPUT) cairo-vm_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_RS_AIR_PUBLIC_INPUT) $(CAIRO_RS_AIR_PRIVATE_INPUT) @@ -256,7 +260,7 @@ ifdef TEST_COLLECT_COVERAGE TEST_COMMAND:=cargo llvm-cov nextest --no-report endif -test: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts +test: cairo_proof_programs cairo_1_program_wasm cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts $(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints" test-no_std: cairo_proof_programs cairo_test_programs $(TEST_COMMAND) --workspace --features test_utils --no-default-features @@ -355,6 +359,7 @@ clean: rm -f $(TEST_PROOF_DIR)/*.trace rm -f $(TEST_PROOF_DIR)/*.air_public_input rm -f $(TEST_PROOF_DIR)/*.air_private_input + rm -f $(TEST_DIR)/bitwise.sierra rm -rf cairo-vm-env rm -rf cairo-vm-pypy-env rm -rf cairo From 22f9787f74689effcd831bd02c4de5c5baeca385 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 16:42:09 -0300 Subject: [PATCH 07/37] remove example once finished testing --- Makefile | 2 +- examples/wasm-demo-cairo1/src/lib.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 71dbd2d17a..9c2a43eaa3 100644 --- a/Makefile +++ b/Makefile @@ -359,7 +359,7 @@ clean: rm -f $(TEST_PROOF_DIR)/*.trace rm -f $(TEST_PROOF_DIR)/*.air_public_input rm -f $(TEST_PROOF_DIR)/*.air_private_input - rm -f $(TEST_DIR)/bitwise.sierra + rm -f $(TEST_DIR)/cairo-1-programs/bitwise.sierra rm -rf cairo-vm-env rm -rf cairo-vm-pypy-env rm -rf cairo diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index d66ba681d9..511a41002b 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -33,10 +33,12 @@ pub fn run_cairo_program() -> Result { serialize_output: true, ..Default::default() }; - let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { + let sierra_program = match serde_json::from_slice(include_bytes!( + "../../cairo_programs/cairo-1-programs/bitwise.sierra" + )) { Ok(sierra) => sierra, Err(_) => { - let program_str = include_str!("../bitwise.sierra"); + let program_str = include_str!("../../cairo_programs/cairo-1-programs/bitwise.sierra"); let parser = ProgramParser::new(); parser From 71a5805efa3b6875fb08286e75c6219c79be6eec Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 16:53:08 -0300 Subject: [PATCH 08/37] fix example --- Makefile | 2 +- examples/wasm-demo-cairo1/src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9c2a43eaa3..79c4427bd8 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ $(TEST_DIR)/cairo-1-programs/bitwise.sierra: $(TEST_DIR)/cairo-1-programs/bitwise.cairo - ..cairo1/bin/cairo-compile $< --output $@ + cairo1/bin/cairo-compile -r $< $@ $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN) cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $(@D)/$(*F).rs.trace --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 511a41002b..6e051a1119 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -34,11 +34,12 @@ pub fn run_cairo_program() -> Result { ..Default::default() }; let sierra_program = match serde_json::from_slice(include_bytes!( - "../../cairo_programs/cairo-1-programs/bitwise.sierra" + "../../../cairo_programs/cairo-1-programs/bitwise.sierra" )) { Ok(sierra) => sierra, Err(_) => { - let program_str = include_str!("../../cairo_programs/cairo-1-programs/bitwise.sierra"); + let program_str = + include_str!("../../../cairo_programs/cairo-1-programs/bitwise.sierra"); let parser = ProgramParser::new(); parser From bca85b30a385adf2c4f8419a36ff174f388f160d Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:01:16 -0300 Subject: [PATCH 09/37] change workflows --- .github/workflows/rust.yml | 1255 ++++++++++++++++++------------------ 1 file changed, 630 insertions(+), 625 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7f2b270f01..d7fa24a2d3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,9 +3,9 @@ name: QA on: merge_group: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ '**' ] + branches: ["**"] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -22,86 +22,87 @@ env: PROPTEST_CASES: 100 jobs: - # We need to use the same files across all jobs or else hashing will fail upload_proof_programs_symlinks: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Create proof_programs symlinks - run: make create-proof-programs-symlinks - - uses: actions/upload-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/*.cairo - + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create proof_programs symlinks + run: make create-proof-programs-symlinks + - uses: actions/upload-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/*.cairo + build-programs: needs: upload_proof_programs_symlinks strategy: matrix: # NOTE: we build cairo_bench_programs so clippy can check the benchmarks too - program-target: [ - cairo_bench_programs, - cairo_proof_programs, - cairo_test_programs, - cairo_1_test_contracts, - cairo_2_test_contracts, - ] + program-target: + [ + cairo_bench_programs, + cairo_proof_programs, + cairo_test_programs, + cairo_1_test_contracts, + cairo_2_test_contracts, + cairo_1_program_wasm, + ] name: Build Cairo programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch from cache - uses: actions/cache@v3 - id: cache-programs - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-cache- - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - uses: chetan/git-restore-mtime-action@v1 - - - name: Python3 Build - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - if: | - steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - run: pip install -r requirements.txt - - - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' - run: make build-cairo-1-compiler - - - name: Install cairo 2 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' - run: make build-cairo-2-compiler - - - name: Build programs - if: steps.cache-programs.outputs.cache-hit != 'true' - run: make -j ${{ matrix.program-target }} + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch from cache + uses: actions/cache@v3 + id: cache-programs + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-cache- + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + uses: chetan/git-restore-mtime-action@v1 + + - name: Python3 Build + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + if: | + steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + run: pip install -r requirements.txt + + - name: Install cairo 1 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + run: make build-cairo-1-compiler + + - name: Install cairo 2 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' + run: make build-cairo-2-compiler + + - name: Build programs + if: steps.cache-programs.outputs.cache-hit != 'true' + run: make -j ${{ matrix.program-target }} # NOTE: used to reduce the amount of cache steps we need in later jobs # TODO: remove this cache once the workflow finishes @@ -110,84 +111,82 @@ jobs: runs-on: ubuntu-22.04 needs: build-programs steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch test programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch proof programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch bench programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 1) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 2) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Merge caches - uses: actions/cache/save@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch test programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch proof programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch bench programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 1) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 2) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Merge caches + uses: actions/cache/save@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} lint: needs: build-programs name: Run Lints runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: rustfmt, clippy - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Format - run: make check-fmt + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + - name: Format + run: make check-fmt - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Run clippy - run: make clippy + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Run clippy + run: make clippy # NOTE: the term "smoke test" comes from electronics design: the minimal # expectations anyone has in their device is to not catch fire on boot. @@ -200,42 +199,42 @@ jobs: crate: ["vm", "cairo-vm-cli", "cairo1-run"] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # NOTE: we do this separately because --workspace operates in weird ways - - name: Check all features (${{ matrix.crate }}) - run: | - cd ${{ matrix.crate }} - cargo check-all-features - cargo check-all-features --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # NOTE: we do this separately because --workspace operates in weird ways + - name: Check all features (${{ matrix.crate }}) + run: | + cd ${{ matrix.crate }} + cargo check-all-features + cargo check-all-features --workspace --all-targets smoke-workspace: needs: merge-caches @@ -246,77 +245,77 @@ jobs: chunk: [1, 2, 3, 4, 5, 6] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check all features (workspace) - run: | - cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check all features (workspace) + run: | + cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets smoke-no-std: needs: merge-caches name: Make sure all builds work (no_std) runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check no-std - run: | - cd ensure-no_std - cargo check --no-default-features - cargo check + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check no-std + run: | + cd ensure-no_std + cargo check --no-default-features + cargo check tests: needs: merge-caches @@ -324,443 +323,449 @@ jobs: fail-fast: false matrix: special_features: ["", "extensive_hints", "mod_builtin"] - target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ] + target: + [ + test#1, + test#2, + test#3, + test#4, + test-no_std#1, + test-no_std#2, + test-no_std#3, + test-no_std#4, + test-wasm, + ] name: Run tests runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: llvm-tools-preview - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Install testing tools - uses: taiki-e/install-action@v2 - with: - tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack - - - name: Install cairo 1 dependencies for running programs - run: | - cd cairo1-run - make deps - - - name: Run ${{ matrix.target }} - run: | - # this splits the `test#1` into `test` and `1` - export MATRIX_TARGET=${{ matrix.target }} - export NAME=${MATRIX_TARGET%#*} - export PARTITION=${MATRIX_TARGET#*#} - # FIXME: we need to update the Makefile to do this correctly - case ${NAME} in - 'test') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" - ;; - 'test-no_std') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --no-default-features --features "${{ matrix.special_features }}" - ;; - 'test-wasm') - # NOTE: release mode is needed to avoid "too many locals" error - wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" - ;; - esac - - - name: Save coverage - if: matrix.target != 'test-wasm' - uses: actions/cache/save@v3 - with: - path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info - key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Install testing tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack + + - name: Install cairo 1 dependencies for running programs + run: | + cd cairo1-run + make deps + + - name: Run ${{ matrix.target }} + run: | + # this splits the `test#1` into `test` and `1` + export MATRIX_TARGET=${{ matrix.target }} + export NAME=${MATRIX_TARGET%#*} + export PARTITION=${MATRIX_TARGET#*#} + # FIXME: we need to update the Makefile to do this correctly + case ${NAME} in + 'test') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" + ;; + 'test-no_std') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --no-default-features --features "${{ matrix.special_features }}" + ;; + 'test-wasm') + # NOTE: release mode is needed to avoid "too many locals" error + wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" + ;; + esac + + - name: Save coverage + if: matrix.target != 'test-wasm' + uses: actions/cache/save@v3 + with: + path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info + key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} build-release: name: Build release binary for comparisons runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - name: Build - run: cargo b --release -p cairo-vm-cli - # We don't read from cache because it should always miss - - name: Store in cache - uses: actions/cache/save@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + - name: Build + run: cargo b --release -p cairo-vm-cli + # We don't read from cache because it should always miss + - name: Store in cache + uses: actions/cache/save@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli run-cairo-reference: strategy: matrix: include: - - program-target: cairo_proof_programs - trace-target: cairo_proof_trace - nprocs: 1 - - program-target: cairo_test_programs - trace-target: cairo_trace - nprocs: 2 + - program-target: cairo_proof_programs + trace-target: cairo_proof_trace + nprocs: 1 + - program-target: cairo_test_programs + trace-target: cairo_trace + nprocs: 2 name: Compute memory and execution traces with cairo-lang needs: build-programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Check cache - uses: actions/cache@v3 - id: trace-cache - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - - - name: Python3 Build - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - if: steps.trace-cache.outputs.cache-hit != 'true' - run: pip install -r requirements.txt - - - name: Fetch programs - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: chetan/git-restore-mtime-action@v1 - - - name: Generate traces - if: steps.trace-cache.outputs.cache-hit != 'true' - run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Check cache + uses: actions/cache@v3 + id: trace-cache + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-reference-trace-cache- + + - name: Python3 Build + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + if: steps.trace-cache.outputs.cache-hit != 'true' + run: pip install -r requirements.txt + + - name: Fetch programs + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: chetan/git-restore-mtime-action@v1 + + - name: Generate traces + if: steps.trace-cache.outputs.cache-hit != 'true' + run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} run-cairo-release: strategy: matrix: include: - - program-target: cairo_proof_programs - programs-dir: cairo_programs/proof_programs - extra-args: '--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input ' - - program-target: cairo_test_programs - programs-dir: cairo_programs - extra-args: '--cairo_pie_output {program}.rs.pie.zip' + - program-target: cairo_proof_programs + programs-dir: cairo_programs/proof_programs + extra-args: "--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input " + - program-target: cairo_test_programs + programs-dir: cairo_programs + extra-args: "--cairo_pie_output {program}.rs.pie.zip" name: Compute memory and execution traces with cairo-vm - needs: [ build-programs, build-release ] + needs: [build-programs, build-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Generate traces - run: | - ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ - xargs -P 2 -I '{program}' \ - ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ - --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ - ${{ matrix.extra-args }} - - name: Update cache - uses: actions/cache/save@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Generate traces + run: | + ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ + xargs -P 2 -I '{program}' \ + ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ + --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ + ${{ matrix.extra-args }} + - name: Update cache + uses: actions/cache/save@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} upload-coverage: name: Upload coverage results to codecov.io needs: tests runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch results for tests with stdlib (part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-.info - key: codecov-cache-test#1--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-.info - key: codecov-cache-test#2--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-.info - key: codecov-cache-test#3--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-.info - key: codecov-cache-test#4--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib - uses: actions/cache/restore@v3 - with: - path: lcov-test-no_std-.info - key: codecov-cache-test-no_std--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-extensive_hints.info - key: codecov-cache-test#1-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-extensive_hints.info - key: codecov-cache-test#2-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-extensive_hints.info - key: codecov-cache-test#3-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-extensive_hints.info - key: codecov-cache-test#4-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib (w/extensive_hints) - uses: actions/cache/restore@v3 - with: - path: lcov-no_std-extensive_hints.info - key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - - - name: Upload coverage to codecov.io - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: '*.info' - fail_ci_if_error: true - + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch results for tests with stdlib (part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-.info + key: codecov-cache-test#1--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-.info + key: codecov-cache-test#2--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-.info + key: codecov-cache-test#3--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-.info + key: codecov-cache-test#4--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib + uses: actions/cache/restore@v3 + with: + path: lcov-test-no_std-.info + key: codecov-cache-test-no_std--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-extensive_hints.info + key: codecov-cache-test#1-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-extensive_hints.info + key: codecov-cache-test#2-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-extensive_hints.info + key: codecov-cache-test#3-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-extensive_hints.info + key: codecov-cache-test#4-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib (w/extensive_hints) + uses: actions/cache/restore@v3 + with: + path: lcov-no_std-extensive_hints.info + key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: "*.info" + fail_ci_if_error: true compare-memory-and-trace: strategy: matrix: - program-target: [ cairo_proof_programs, cairo_test_programs ] + program-target: [cairo_proof_programs, cairo_test_programs] name: Compare memory and execution traces from cairo-lang and cairo-vm - needs: [ run-cairo-reference, run-cairo-release ] + needs: [run-cairo-reference, run-cairo-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch traces for cairo-lang - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison script - run: | - if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then - PROOF=proof_mode - AIR_PUBLIC_INPUT=air_public_input - AIR_PRIVATE_INPUT=air_private_input - else - PIE=pie - fi - ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch traces for cairo-lang + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison script + run: | + if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then + PROOF=proof_mode + AIR_PUBLIC_INPUT=air_public_input + AIR_PRIVATE_INPUT=air_private_input + else + PIE=pie + fi + ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE wasm-demo: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo - run: | - cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json - cd examples/wasm-demo - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo + run: | + cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json + cd examples/wasm-demo + wasm-pack build --target=web + compare-factorial-outputs-all-layouts: name: Compare factorial outputs for all layouts - needs: [ build-programs, build-release ] + needs: [build-programs, build-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Run script - run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Run script + run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh compare-run-from-cairo-pie-all-outputs: name: Compare all outputs from running Cairo PIEs - needs: [ build-programs, build-release, run-cairo-release ] + needs: [build-programs, build-release, run-cairo-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: cairo_test_programs-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison - run: ./vm/src/tests/compare_all_pie_outputs.sh - + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: cairo_test_programs-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison + run: ./vm/src/tests/compare_all_pie_outputs.sh From aca5a0a3fc35beecd971292843b55a53af6655b6 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:14:04 -0300 Subject: [PATCH 10/37] change workflows --- .github/workflows/rust.yml | 26 ++++++++++++++++++++++++++ Makefile | 7 +------ cairo1-run/Cargo.toml | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d7fa24a2d3..d39a7b7229 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -692,6 +692,32 @@ jobs: cd examples/wasm-demo wasm-pack build --target=web + wasm-demo-cairo1: + name: Build the wasm demo + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo + run: | + cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra + cd examples/wasm-demo-cairo1 + wasm-pack build --target=web + compare-factorial-outputs-all-layouts: name: Compare factorial outputs for all layouts needs: [build-programs, build-release] diff --git a/Makefile b/Makefile index 79c4427bd8..f96e41a1ea 100644 --- a/Makefile +++ b/Makefile @@ -108,9 +108,6 @@ $(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ -$(TEST_DIR)/cairo-1-programs/bitwise.sierra: $(TEST_DIR)/cairo-1-programs/bitwise.cairo - cairo1/bin/cairo-compile -r $< $@ - $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN) cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $(@D)/$(*F).rs.trace --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip @@ -247,7 +244,6 @@ cairo_proof_programs: $(COMPILED_PROOF_TESTS) $(COMPILED_MOD_BUILTIN_PROOF_TESTS cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) cairo_2_test_contracts: $(CAIRO_2_COMPILED_CASM_CONTRACTS) -cairo_1_program_wasm: $(TEST_DIR)/cairo-1-programs/bitwise.sierra cairo_proof_trace: $(CAIRO_TRACE_PROOF) $(CAIRO_MEM_PROOF) $(CAIRO_AIR_PUBLIC_INPUT) $(CAIRO_AIR_PRIVATE_INPUT) cairo-vm_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_RS_AIR_PUBLIC_INPUT) $(CAIRO_RS_AIR_PRIVATE_INPUT) @@ -260,7 +256,7 @@ ifdef TEST_COLLECT_COVERAGE TEST_COMMAND:=cargo llvm-cov nextest --no-report endif -test: cairo_proof_programs cairo_1_program_wasm cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts +test: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts $(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints" test-no_std: cairo_proof_programs cairo_test_programs $(TEST_COMMAND) --workspace --features test_utils --no-default-features @@ -359,7 +355,6 @@ clean: rm -f $(TEST_PROOF_DIR)/*.trace rm -f $(TEST_PROOF_DIR)/*.air_public_input rm -f $(TEST_PROOF_DIR)/*.air_private_input - rm -f $(TEST_DIR)/cairo-1-programs/bitwise.sierra rm -rf cairo-vm-env rm -rf cairo-vm-pypy-env rm -rf cairo diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index c74ba212f6..be6efa855c 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -9,7 +9,7 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cairo-vm = { workspace = true, features = ["cairo-1-hints", "clap"] } +cairo-vm = { workspace = true, features = ["std", "cairo-1-hints", "clap"] } serde_json = { workspace = true } cairo-lang-sierra-type-size = { version = "2.7.1", default-features = false } From 8ddd66d93d7bb3d5dcc510411dda97be5ceea7a2 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:30:11 -0300 Subject: [PATCH 11/37] make default the cli feature --- .github/workflows/rust.yml | 6 +++--- cairo1-run/Cargo.toml | 2 +- cairo1-run/Makefile | 2 +- cairo1-run/README.md | 11 ++++++----- examples/wasm-demo-cairo1/Cargo.toml | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d39a7b7229..ce21e2bdd4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -699,13 +699,13 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 0 - name: Python3 Build uses: actions/setup-python@v4 with: - python-version: "3.9" - cache: "pip" + python-version: "3.9" + cache: "pip" - name: Install cairo-lang and deps run: | diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index be6efa855c..11345657e6 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -33,7 +33,7 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc"] +default = ["with_mimalloc", "cli"] with_mimalloc = ["dep:mimalloc"] cli = ["dep:thiserror"] diff --git a/cairo1-run/Makefile b/cairo1-run/Makefile index 16244e05d9..10ce0f24fe 100644 --- a/cairo1-run/Makefile +++ b/cairo1-run/Makefile @@ -3,7 +3,7 @@ CAIRO_1_FOLDER=../cairo_programs/cairo-1-programs $(CAIRO_1_FOLDER)/%.trace: $(CAIRO_1_FOLDER)/%.cairo - cargo run --release $< --trace_file $@ --layout all_cairo + cargo run --release --features cli $< --trace_file $@ --layout all_cairo $(CAIRO_1_FOLDER)/%.memory: $(CAIRO_1_FOLDER)/%.cairo cargo run --release $< --memory_file $@ --layout all_cairo diff --git a/cairo1-run/README.md b/cairo1-run/README.md index 9271d860bb..6d0378e630 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -7,7 +7,7 @@ Once you are inside the `./cairo1-run` folder, use the CLI with the following co To install the required dependencies(cairo corelib) run ```bash -make deps +make deps ``` Now that you have the dependencies necessary to run the tests, you can run: @@ -19,14 +19,15 @@ make test To execute a Cairo 1 program (either as Cairo 1 source file or Sierra) ```bash -cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo +cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo ``` Arguments to generate the trace and memory files ```bash -cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory +cargo run --features cli ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory ``` +> In order to use cairo1-run as a binary, the `cli` feature needs to be enabled To pass arguments to `main` @@ -44,7 +45,7 @@ cargo run ../cairo_programs/cairo-1-programs/with_input/array_input_sum.cairo -- To execute all the cairo 1 programs inside `../cairo_programs/cairo-1-programs/` and generate the corresponding trace and the memory files ```bash -make run +make run ``` ## CLI argument list @@ -86,7 +87,7 @@ Then run the compiled project's sierra file located at `project_name/target/proj Example: ```bash - cargo run path-to-project/target/project_name.sierra.json + cargo run path-to-project/target/project_name.sierra.json ``` # Known bugs & issues diff --git a/examples/wasm-demo-cairo1/Cargo.toml b/examples/wasm-demo-cairo1/Cargo.toml index 731cedb7d4..ce72bb93ce 100644 --- a/examples/wasm-demo-cairo1/Cargo.toml +++ b/examples/wasm-demo-cairo1/Cargo.toml @@ -27,7 +27,7 @@ cairo-lang-sierra = { workspace = true } console_error_panic_hook = { version = "0.1.6", optional = true } cairo1-run = { workspace = true } -cairo-vm = { workspace = true } +cairo-vm = { workspace = true, default_features = false } [dev-dependencies] wasm-bindgen-test = "0.3.34" From 5257e47d76da6cb43b7ebb5146bf2cc04a745f4d Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:32:11 -0300 Subject: [PATCH 12/37] update readme cairo1-run --- cairo1-run/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cairo1-run/README.md b/cairo1-run/README.md index 6d0378e630..a86748f7d5 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -25,10 +25,8 @@ cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo Arguments to generate the trace and memory files ```bash -cargo run --features cli ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory +cargo run ./cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory ``` -> In order to use cairo1-run as a binary, the `cli` feature needs to be enabled - To pass arguments to `main` * Separate arguments with a whitespace inbetween From a53878c80fe86f2d2ee485597c10906f50f8a704 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:36:40 -0300 Subject: [PATCH 13/37] fix workflows --- .github/workflows/rust.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ce21e2bdd4..5f7bedff18 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,7 +48,6 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, - cairo_1_program_wasm, ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -693,7 +692,7 @@ jobs: wasm-pack build --target=web wasm-demo-cairo1: - name: Build the wasm demo + name: Build the wasm-demo-cairoo runs-on: ubuntu-22.04 steps: - name: Checkout @@ -712,7 +711,7 @@ jobs: pip install -r requirements.txt npm install -g wasm-pack - - name: Build wasm-demo + - name: Build wasm-demo-cairo run: | cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra cd examples/wasm-demo-cairo1 From dccb10cb7294179c480cdd79d4e0e0d062a452eb Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Fri, 30 Aug 2024 17:55:47 -0300 Subject: [PATCH 14/37] fix workflows --- .github/workflows/rust.yml | 5 +++-- Makefile | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5f7bedff18..33f0c8d71a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,7 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, + cairo_1_wasm_example, ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -692,7 +693,7 @@ jobs: wasm-pack build --target=web wasm-demo-cairo1: - name: Build the wasm-demo-cairoo + name: Build the wasm-demo-cairo1 runs-on: ubuntu-22.04 steps: - name: Checkout @@ -711,7 +712,7 @@ jobs: pip install -r requirements.txt npm install -g wasm-pack - - name: Build wasm-demo-cairo + - name: Build wasm-demo-cairo1 run: | cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra cd examples/wasm-demo-cairo1 diff --git a/Makefile b/Makefile index f96e41a1ea..633113f04d 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,9 @@ $(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ +$(TEST_DIR)/cairo-1-programs/bitwise.sierra: $(TEST_DIR)/cairo-1-programs/bitwise.cairo + cairo1/bin/cairo-compile -r $< $@ + $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN) cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $(@D)/$(*F).rs.trace --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip @@ -244,6 +247,7 @@ cairo_proof_programs: $(COMPILED_PROOF_TESTS) $(COMPILED_MOD_BUILTIN_PROOF_TESTS cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) cairo_2_test_contracts: $(CAIRO_2_COMPILED_CASM_CONTRACTS) +cairo_1_wasm_example: $(TEST_DIR)/cairo-1-programs/bitwise.sierra cairo_proof_trace: $(CAIRO_TRACE_PROOF) $(CAIRO_MEM_PROOF) $(CAIRO_AIR_PUBLIC_INPUT) $(CAIRO_AIR_PRIVATE_INPUT) cairo-vm_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_RS_AIR_PUBLIC_INPUT) $(CAIRO_RS_AIR_PRIVATE_INPUT) @@ -256,11 +260,11 @@ ifdef TEST_COLLECT_COVERAGE TEST_COMMAND:=cargo llvm-cov nextest --no-report endif -test: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts +test: cairo_proof_programs cairo_1_wasm_example cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts $(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints" -test-no_std: cairo_proof_programs cairo_test_programs +test-no_std: cairo_proof_programs cairo_1_wasm_example cairo_test_programs $(TEST_COMMAND) --workspace --features test_utils --no-default-features -test-wasm: cairo_proof_programs cairo_test_programs +test-wasm: cairo_proof_programs cairo_1_wasm_example cairo_test_programs # NOTE: release mode is needed to avoid "too many locals" error wasm-pack test --release --node vm --no-default-features test-extensive_hints: cairo_proof_programs cairo_test_programs @@ -350,6 +354,7 @@ clean: rm -f $(TEST_PROOF_DIR)/*.cairo rm -f $(CAIRO_2_CONTRACTS_TEST_DIR)/*.sierra rm -f $(CAIRO_2_CONTRACTS_TEST_DIR)/*.casm + rm -f $(TEST_DIR)/cairo-1-programs/bitwise.sierra rm -f $(TEST_PROOF_DIR)/*.json rm -f $(TEST_PROOF_DIR)/*.memory rm -f $(TEST_PROOF_DIR)/*.trace From 8780cc633dabbd60edd2ca5ef8add1fd005dadc6 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 09:36:23 -0300 Subject: [PATCH 15/37] add workflows to build the wasm example --- .github/workflows/rust.yml | 113 ++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 19 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 33f0c8d71a..d0013b27ec 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,7 +48,6 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, - cairo_1_wasm_example, ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -68,7 +67,11 @@ jobs: id: cache-programs with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} restore-keys: ${{ matrix.program-target }}-cache- # This is not pretty, but we need `make` to see the compiled programs are @@ -93,7 +96,9 @@ jobs: run: pip install -r requirements.txt - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target == 'cairo_1_test_contracts' + && matrix.program-target =='cairo_1_wasm_example' run: make build-cairo-1-compiler - name: Install cairo 2 compiler @@ -123,38 +128,62 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_test_programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Fetch proof programs uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_proof_programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Fetch bench programs uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_bench_programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Fetch test contracts (Cairo 1) uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_1_test_contracts-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Fetch test contracts (Cairo 2) uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_2_test_contracts-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Merge caches uses: actions/cache/save@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} lint: needs: build-programs @@ -182,7 +211,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Run clippy @@ -226,7 +259,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true # NOTE: we do this separately because --workspace operates in weird ways @@ -273,7 +310,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Check all features (workspace) @@ -308,7 +349,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Check no-std @@ -356,7 +401,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: all-programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Install testing tools @@ -453,7 +502,11 @@ jobs: cairo_programs/**/*.air_public_input cairo_programs/**/*.air_private_input cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - name: Python3 Build @@ -472,7 +525,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true # This is not pretty, but we need `make` to see the compiled programs are @@ -518,7 +575,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Generate traces @@ -640,7 +701,11 @@ jobs: cairo_programs/**/*.air_public_input cairo_programs/**/*.air_private_input cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Fetch traces for cairo-vm @@ -712,6 +777,12 @@ jobs: pip install -r requirements.txt npm install -g wasm-pack + - name: Install cairo 1 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target == 'cairo_1_test_contracts' + && matrix.program-target =='cairo_1_wasm_example' + run: make build-cairo-1-compiler + - name: Build wasm-demo-cairo1 run: | cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra @@ -751,7 +822,11 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + key: cairo_proof_programs-cache-${{ hashFiles( + 'cairo_programs/**/*.cairo', + 'examples/wasm-demo/src/array_sum.cairo', + 'examples/wasm-demo-cairo1/src/bitwise.cairo' + ) }} fail-on-cache-miss: true - name: Run script From 439f20dffebb864fbfb8670c565798adaf78db29 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 09:50:19 -0300 Subject: [PATCH 16/37] fix workflow --- .github/workflows/rust.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d0013b27ec..3966ae1d24 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,7 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, + cairo_1_wasm_example, ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -98,7 +99,6 @@ jobs: - name: Install cairo 1 compiler if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' - && matrix.program-target =='cairo_1_wasm_example' run: make build-cairo-1-compiler - name: Install cairo 2 compiler @@ -778,9 +778,6 @@ jobs: npm install -g wasm-pack - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target == 'cairo_1_test_contracts' - && matrix.program-target =='cairo_1_wasm_example' run: make build-cairo-1-compiler - name: Build wasm-demo-cairo1 From 3f4ab6f05caff8dcfc4c21c8d8bcd2a542715e0d Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 10:14:44 -0300 Subject: [PATCH 17/37] format workflows as before --- .github/workflows/rust.yml | 1297 ++++++++++++++++++------------------ 1 file changed, 645 insertions(+), 652 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3966ae1d24..e7518d720d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,9 +3,9 @@ name: QA on: merge_group: push: - branches: [main] + branches: [ main ] pull_request: - branches: ["**"] + branches: [ '**' ] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -22,92 +22,90 @@ env: PROPTEST_CASES: 100 jobs: + # We need to use the same files across all jobs or else hashing will fail upload_proof_programs_symlinks: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Create proof_programs symlinks - run: make create-proof-programs-symlinks - - uses: actions/upload-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/*.cairo - + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create proof_programs symlinks + run: make create-proof-programs-symlinks + - uses: actions/upload-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/*.cairo + build-programs: needs: upload_proof_programs_symlinks strategy: matrix: # NOTE: we build cairo_bench_programs so clippy can check the benchmarks too - program-target: - [ - cairo_bench_programs, - cairo_proof_programs, - cairo_test_programs, - cairo_1_test_contracts, - cairo_2_test_contracts, - cairo_1_wasm_example, - ] + program-target: [ + cairo_bench_programs, + cairo_proof_programs, + cairo_test_programs, + cairo_1_test_contracts, + cairo_2_test_contracts, + ] name: Build Cairo programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch from cache - uses: actions/cache@v3 - id: cache-programs - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch from cache + uses: actions/cache@v3 + id: cache-programs + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - restore-keys: ${{ matrix.program-target }}-cache- - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - uses: chetan/git-restore-mtime-action@v1 - - - name: Python3 Build - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - if: | - steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - run: pip install -r requirements.txt - - - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target == 'cairo_1_test_contracts' - run: make build-cairo-1-compiler - - - name: Install cairo 2 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' - run: make build-cairo-2-compiler - - - name: Build programs - if: steps.cache-programs.outputs.cache-hit != 'true' - run: make -j ${{ matrix.program-target }} + restore-keys: ${{ matrix.program-target }}-cache- + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + uses: chetan/git-restore-mtime-action@v1 + + - name: Python3 Build + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + if: | + steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + run: pip install -r requirements.txt + + - name: Install cairo 1 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + run: make build-cairo-1-compiler + + - name: Install cairo 2 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' + run: make build-cairo-2-compiler + + - name: Build programs + if: steps.cache-programs.outputs.cache-hit != 'true' + run: make -j ${{ matrix.program-target }} # NOTE: used to reduce the amount of cache steps we need in later jobs # TODO: remove this cache once the workflow finishes @@ -116,70 +114,70 @@ jobs: runs-on: ubuntu-22.04 needs: build-programs steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch test programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch test programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_test_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - name: Fetch proof programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles( + fail-on-cache-miss: true + - name: Fetch proof programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - name: Fetch bench programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles( + fail-on-cache-miss: true + - name: Fetch bench programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_bench_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 1) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles( + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 1) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 2) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles( + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 2) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_2_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true - - name: Merge caches - uses: actions/cache/save@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Merge caches + uses: actions/cache/save@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' @@ -190,36 +188,38 @@ jobs: name: Run Lints runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: rustfmt, clippy - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Format - run: make check-fmt - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Format + run: make check-fmt + + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true + + - name: Run clippy + run: make clippy - - name: Run clippy - run: make clippy # NOTE: the term "smoke test" comes from electronics design: the minimal # expectations anyone has in their device is to not catch fire on boot. @@ -232,46 +232,46 @@ jobs: crate: ["vm", "cairo-vm-cli", "cairo1-run"] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true - # NOTE: we do this separately because --workspace operates in weird ways - - name: Check all features (${{ matrix.crate }}) - run: | - cd ${{ matrix.crate }} - cargo check-all-features - cargo check-all-features --workspace --all-targets + # NOTE: we do this separately because --workspace operates in weird ways + - name: Check all features (${{ matrix.crate }}) + run: | + cd ${{ matrix.crate }} + cargo check-all-features + cargo check-all-features --workspace --all-targets smoke-workspace: needs: merge-caches @@ -282,85 +282,85 @@ jobs: chunk: [1, 2, 3, 4, 5, 6] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true - - name: Check all features (workspace) - run: | - cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets + - name: Check all features (workspace) + run: | + cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets smoke-no-std: needs: merge-caches name: Make sure all builds work (no_std) runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true - - name: Check no-std - run: | - cd ensure-no_std - cargo check --no-default-features - cargo check + - name: Check no-std + run: | + cd ensure-no_std + cargo check --no-default-features + cargo check tests: needs: merge-caches @@ -368,502 +368,495 @@ jobs: fail-fast: false matrix: special_features: ["", "extensive_hints", "mod_builtin"] - target: - [ - test#1, - test#2, - test#3, - test#4, - test-no_std#1, - test-no_std#2, - test-no_std#3, - test-no_std#4, - test-wasm, - ] + target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ] name: Run tests runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: llvm-tools-preview - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - - name: Install testing tools - uses: taiki-e/install-action@v2 - with: - tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack - - - name: Install cairo 1 dependencies for running programs - run: | - cd cairo1-run - make deps - - - name: Run ${{ matrix.target }} - run: | - # this splits the `test#1` into `test` and `1` - export MATRIX_TARGET=${{ matrix.target }} - export NAME=${MATRIX_TARGET%#*} - export PARTITION=${MATRIX_TARGET#*#} - # FIXME: we need to update the Makefile to do this correctly - case ${NAME} in - 'test') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" - ;; - 'test-no_std') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --no-default-features --features "${{ matrix.special_features }}" - ;; - 'test-wasm') - # NOTE: release mode is needed to avoid "too many locals" error - wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" - ;; - esac - - - name: Save coverage - if: matrix.target != 'test-wasm' - uses: actions/cache/save@v3 - with: - path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info - key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} + fail-on-cache-miss: true + + - name: Install testing tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack + + - name: Install cairo 1 dependencies for running programs + run: | + cd cairo1-run + make deps + + - name: Run ${{ matrix.target }} + run: | + # this splits the `test#1` into `test` and `1` + export MATRIX_TARGET=${{ matrix.target }} + export NAME=${MATRIX_TARGET%#*} + export PARTITION=${MATRIX_TARGET#*#} + # FIXME: we need to update the Makefile to do this correctly + case ${NAME} in + 'test') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" + ;; + 'test-no_std') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --no-default-features --features "${{ matrix.special_features }}" + ;; + 'test-wasm') + # NOTE: release mode is needed to avoid "too many locals" error + wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" + ;; + esac + + - name: Save coverage + if: matrix.target != 'test-wasm' + uses: actions/cache/save@v3 + with: + path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info + key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} build-release: name: Build release binary for comparisons runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - name: Build - run: cargo b --release -p cairo-vm-cli - # We don't read from cache because it should always miss - - name: Store in cache - uses: actions/cache/save@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + - name: Build + run: cargo b --release -p cairo-vm-cli + # We don't read from cache because it should always miss + - name: Store in cache + uses: actions/cache/save@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli run-cairo-reference: strategy: matrix: include: - - program-target: cairo_proof_programs - trace-target: cairo_proof_trace - nprocs: 1 - - program-target: cairo_test_programs - trace-target: cairo_trace - nprocs: 2 + - program-target: cairo_proof_programs + trace-target: cairo_proof_trace + nprocs: 1 + - program-target: cairo_test_programs + trace-target: cairo_trace + nprocs: 2 name: Compute memory and execution traces with cairo-lang needs: build-programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Check cache - uses: actions/cache@v3 - id: trace-cache - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Check cache + uses: actions/cache@v3 + id: trace-cache + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - - - name: Python3 Build - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - if: steps.trace-cache.outputs.cache-hit != 'true' - run: pip install -r requirements.txt - - - name: Fetch programs - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( + restore-keys: ${{ matrix.program-target }}-reference-trace-cache- + + - name: Python3 Build + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + if: steps.trace-cache.outputs.cache-hit != 'true' + run: pip install -r requirements.txt + + - name: Fetch programs + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true + fail-on-cache-miss: true + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: chetan/git-restore-mtime-action@v1 - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: chetan/git-restore-mtime-action@v1 + - name: Generate traces + if: steps.trace-cache.outputs.cache-hit != 'true' + run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} - - name: Generate traces - if: steps.trace-cache.outputs.cache-hit != 'true' - run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} run-cairo-release: strategy: matrix: include: - - program-target: cairo_proof_programs - programs-dir: cairo_programs/proof_programs - extra-args: "--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input " - - program-target: cairo_test_programs - programs-dir: cairo_programs - extra-args: "--cairo_pie_output {program}.rs.pie.zip" + - program-target: cairo_proof_programs + programs-dir: cairo_programs/proof_programs + extra-args: '--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input ' + - program-target: cairo_test_programs + programs-dir: cairo_programs + extra-args: '--cairo_pie_output {program}.rs.pie.zip' name: Compute memory and execution traces with cairo-vm - needs: [build-programs, build-release] + needs: [ build-programs, build-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - - name: Generate traces - run: | - ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ - xargs -P 2 -I '{program}' \ - ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ - --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ - ${{ matrix.extra-args }} - - name: Update cache - uses: actions/cache/save@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Generate traces + run: | + ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ + xargs -P 2 -I '{program}' \ + ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ + --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ + ${{ matrix.extra-args }} + - name: Update cache + uses: actions/cache/save@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + upload-coverage: name: Upload coverage results to codecov.io needs: tests runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch results for tests with stdlib (part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-.info - key: codecov-cache-test#1--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-.info - key: codecov-cache-test#2--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-.info - key: codecov-cache-test#3--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-.info - key: codecov-cache-test#4--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib - uses: actions/cache/restore@v3 - with: - path: lcov-test-no_std-.info - key: codecov-cache-test-no_std--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-extensive_hints.info - key: codecov-cache-test#1-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-extensive_hints.info - key: codecov-cache-test#2-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-extensive_hints.info - key: codecov-cache-test#3-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-extensive_hints.info - key: codecov-cache-test#4-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib (w/extensive_hints) - uses: actions/cache/restore@v3 - with: - path: lcov-no_std-extensive_hints.info - key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - - name: Upload coverage to codecov.io - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: "*.info" - fail_ci_if_error: true + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch results for tests with stdlib (part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-.info + key: codecov-cache-test#1--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-.info + key: codecov-cache-test#2--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-.info + key: codecov-cache-test#3--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-.info + key: codecov-cache-test#4--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib + uses: actions/cache/restore@v3 + with: + path: lcov-test-no_std-.info + key: codecov-cache-test-no_std--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-extensive_hints.info + key: codecov-cache-test#1-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-extensive_hints.info + key: codecov-cache-test#2-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-extensive_hints.info + key: codecov-cache-test#3-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-extensive_hints.info + key: codecov-cache-test#4-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib (w/extensive_hints) + uses: actions/cache/restore@v3 + with: + path: lcov-no_std-extensive_hints.info + key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: '*.info' + fail_ci_if_error: true + compare-memory-and-trace: strategy: matrix: - program-target: [cairo_proof_programs, cairo_test_programs] + program-target: [ cairo_proof_programs, cairo_test_programs ] name: Compare memory and execution traces from cairo-lang and cairo-vm - needs: [run-cairo-reference, run-cairo-release] + needs: [ run-cairo-reference, run-cairo-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch traces for cairo-lang - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch traces for cairo-lang + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison script - run: | - if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then - PROOF=proof_mode - AIR_PUBLIC_INPUT=air_public_input - AIR_PRIVATE_INPUT=air_private_input - else - PIE=pie - fi - ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison script + run: | + if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then + PROOF=proof_mode + AIR_PUBLIC_INPUT=air_public_input + AIR_PRIVATE_INPUT=air_private_input + else + PIE=pie + fi + ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE wasm-demo: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo - run: | - cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json - cd examples/wasm-demo - wasm-pack build --target=web + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo + run: | + cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json + cd examples/wasm-demo + wasm-pack build --target=web wasm-demo-cairo1: name: Build the wasm-demo-cairo1 runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Install cairo 1 compiler - run: make build-cairo-1-compiler - - - name: Build wasm-demo-cairo1 - run: | - cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra - cd examples/wasm-demo-cairo1 - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Install cairo 1 compiler + run: make build-cairo-1-compiler + + - name: Build wasm-demo-cairo1 + run: | + cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra + cd examples/wasm-demo-cairo1 + wasm-pack build --target=web + compare-factorial-outputs-all-layouts: name: Compare factorial outputs for all layouts - needs: [build-programs, build-release] + needs: [ build-programs, build-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles( + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo', 'examples/wasm-demo-cairo1/src/bitwise.cairo' ) }} - fail-on-cache-miss: true - - - name: Run script - run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh + fail-on-cache-miss: true + + - name: Run script + run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh compare-run-from-cairo-pie-all-outputs: name: Compare all outputs from running Cairo PIEs - needs: [build-programs, build-release, run-cairo-release] + needs: [ build-programs, build-release, run-cairo-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: cairo_test_programs-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison - run: ./vm/src/tests/compare_all_pie_outputs.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: cairo_test_programs-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison + run: ./vm/src/tests/compare_all_pie_outputs.sh From 0471e283a6219af8f6c829a554ba2c3434ae4893 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 10:45:06 -0300 Subject: [PATCH 18/37] add workflow to build cairo_1_wasm_example program --- .github/workflows/rust.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e7518d720d..566321af78 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,7 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, + cairo_1_wasm_example ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -96,7 +97,9 @@ jobs: run: pip install -r requirements.txt - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target == 'cairo_1_test_contracts' + && matrix.program-target == 'cairo_1_wasm_example' run: make build-cairo-1-compiler - name: Install cairo 2 compiler From 4a16c736d91e515c66ddb1d37bde7087e11de76e Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 10:52:39 -0300 Subject: [PATCH 19/37] forgot to install cairo 1 compiler --- .github/workflows/rust.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 566321af78..9ba89e4f6f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -98,8 +98,10 @@ jobs: - name: Install cairo 1 compiler if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target == 'cairo_1_test_contracts' - && matrix.program-target == 'cairo_1_wasm_example' + && ( + matrix.program-target == 'cairo_1_test_contracts' + || matrix.program-target == 'cairo_1_wasm_example' + ) run: make build-cairo-1-compiler - name: Install cairo 2 compiler From 6a5867092bc45231b07768f3bf109d23758af68c Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 10:53:31 -0300 Subject: [PATCH 20/37] format --- .github/workflows/rust.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9ba89e4f6f..dfb78c71a6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -97,7 +97,8 @@ jobs: run: pip install -r requirements.txt - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' + if: | + steps.cache-programs.outputs.cache-hit != 'true' && ( matrix.program-target == 'cairo_1_test_contracts' || matrix.program-target == 'cairo_1_wasm_example' From f455fccf76c812b355b04dc4fcace37ca2b8f9ca Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 12:07:06 -0300 Subject: [PATCH 21/37] workflow fix --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dfb78c71a6..a8596a8385 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,6 +18,7 @@ env: cairo_programs/**/*.json !cairo_programs/manually_compiled/* examples/wasm-demo/src/array_sum.json + examples/wasm-demo-cairo1/src/bitwise.sierra TEST_COLLECT_COVERAGE: 1 PROPTEST_CASES: 100 From 7dd993bf92033d1aa04aac51825cfaea6685f194 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 13:35:50 -0300 Subject: [PATCH 22/37] add sierra to wasm example --- examples/wasm-demo-cairo1/bitwise.sierra | 136 +++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 examples/wasm-demo-cairo1/bitwise.sierra diff --git a/examples/wasm-demo-cairo1/bitwise.sierra b/examples/wasm-demo-cairo1/bitwise.sierra new file mode 100644 index 0000000000..e1131d67ec --- /dev/null +++ b/examples/wasm-demo-cairo1/bitwise.sierra @@ -0,0 +1,136 @@ +type u128 = u128; +type Bitwise = Bitwise; +type RangeCheck = RangeCheck; +type Tuple = Struct; +type felt252 = felt252; +type Array = Array; +type core::PanicResult::<(core::integer::u128,)> = Enum, Tuple, Array>; +type core::result::Result:: = Enum, u128, u128>; + +libfunc u128_const<1234> = u128_const<1234>; +libfunc u128_const<5678> = u128_const<5678>; +libfunc store_temp = store_temp; +libfunc dup = dup; +libfunc bitwise = bitwise; +libfunc drop = drop; +libfunc store_temp = store_temp; +libfunc function_call = function_call; +libfunc store_temp = store_temp; +libfunc enum_match> = enum_match>; +libfunc branch_align = branch_align; +libfunc struct_deconstruct> = struct_deconstruct>; +libfunc struct_construct> = struct_construct>; +libfunc enum_init, 0> = enum_init, 0>; +libfunc store_temp> = store_temp>; +libfunc enum_init, 1> = enum_init, 1>; +libfunc u128_overflowing_add = u128_overflowing_add; +libfunc enum_init, 0> = enum_init, 0>; +libfunc store_temp> = store_temp>; +libfunc jump = jump; +libfunc enum_init, 1> = enum_init, 1>; +libfunc felt252_const<39878429859757942499084499860145094553463> = felt252_const<39878429859757942499084499860145094553463>; +libfunc rename> = rename>; +libfunc store_temp = store_temp; +libfunc function_call::expect::> = function_call::expect::>; +libfunc enum_match> = enum_match>; +libfunc drop = drop; +libfunc array_new = array_new; +libfunc array_append = array_append; + +u128_const<1234>() -> ([2]); +u128_const<5678>() -> ([3]); +store_temp([2]) -> ([2]); +dup([2]) -> ([2], [8]); +store_temp([3]) -> ([3]); +dup([3]) -> ([3], [9]); +bitwise([1], [8], [9]) -> ([4], [5], [6], [7]); +drop([6]) -> (); +drop([7]) -> (); +dup([2]) -> ([2], [14]); +dup([3]) -> ([3], [15]); +bitwise([4], [14], [15]) -> ([10], [11], [12], [13]); +drop([11]) -> (); +drop([13]) -> (); +bitwise([10], [2], [3]) -> ([16], [17], [18], [19]); +drop([17]) -> (); +drop([18]) -> (); +store_temp([0]) -> ([22]); +store_temp([5]) -> ([23]); +store_temp([12]) -> ([24]); +function_call([22], [23], [24]) -> ([20], [21]); +store_temp([19]) -> ([19]); +store_temp([16]) -> ([16]); +enum_match>([21]) { fallthrough([25]) 45([26]) }; +branch_align() -> (); +struct_deconstruct>([25]) -> ([27]); +store_temp([20]) -> ([30]); +store_temp([27]) -> ([31]); +store_temp([19]) -> ([32]); +function_call([30], [31], [32]) -> ([28], [29]); +enum_match>([29]) { fallthrough([33]) 39([34]) }; +branch_align() -> (); +struct_deconstruct>([33]) -> ([35]); +struct_construct>([35]) -> ([36]); +enum_init, 0>([36]) -> ([37]); +store_temp([28]) -> ([38]); +store_temp([16]) -> ([39]); +store_temp>([37]) -> ([40]); +return([38], [39], [40]); +branch_align() -> (); +enum_init, 1>([34]) -> ([41]); +store_temp([28]) -> ([42]); +store_temp([16]) -> ([43]); +store_temp>([41]) -> ([44]); +return([42], [43], [44]); +branch_align() -> (); +drop([19]) -> (); +enum_init, 1>([26]) -> ([45]); +store_temp([20]) -> ([46]); +store_temp([16]) -> ([47]); +store_temp>([45]) -> ([48]); +return([46], [47], [48]); +u128_overflowing_add([0], [1], [2]) { fallthrough([3], [4]) 58([5], [6]) }; +branch_align() -> (); +enum_init, 0>([4]) -> ([7]); +store_temp([3]) -> ([8]); +store_temp>([7]) -> ([9]); +jump() { 62() }; +branch_align() -> (); +enum_init, 1>([6]) -> ([10]); +store_temp([5]) -> ([8]); +store_temp>([10]) -> ([9]); +felt252_const<39878429859757942499084499860145094553463>() -> ([11]); +rename>([9]) -> ([13]); +store_temp([11]) -> ([14]); +function_call::expect::>([13], [14]) -> ([12]); +enum_match>([12]) { fallthrough([15]) 74([16]) }; +branch_align() -> (); +struct_deconstruct>([15]) -> ([17]); +struct_construct>([17]) -> ([18]); +enum_init, 0>([18]) -> ([19]); +store_temp([8]) -> ([20]); +store_temp>([19]) -> ([21]); +return([20], [21]); +branch_align() -> (); +enum_init, 1>([16]) -> ([22]); +store_temp([8]) -> ([23]); +store_temp>([22]) -> ([24]); +return([23], [24]); +enum_match>([0]) { fallthrough([2]) 86([3]) }; +branch_align() -> (); +drop([1]) -> (); +struct_construct>([2]) -> ([4]); +enum_init, 0>([4]) -> ([5]); +store_temp>([5]) -> ([6]); +return([6]); +branch_align() -> (); +drop([3]) -> (); +array_new() -> ([7]); +array_append([7], [1]) -> ([8]); +enum_init, 1>([8]) -> ([9]); +store_temp>([9]) -> ([10]); +return([10]); + +bitwise::bitwise::main@0([0]: RangeCheck, [1]: Bitwise) -> (RangeCheck, Bitwise, core::PanicResult::<(core::integer::u128,)>); +core::integer::U128Add::add@52([0]: RangeCheck, [1]: u128, [2]: u128) -> (RangeCheck, core::PanicResult::<(core::integer::u128,)>); +core::result::ResultTraitImpl::::expect::@79([0]: core::result::Result::, [1]: felt252) -> (core::PanicResult::<(core::integer::u128,)>); From 2fdc4356ca16d9d4397ba2ca8181699b4127bcc0 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 14:17:54 -0300 Subject: [PATCH 23/37] add sierra to wasm example --- .github/workflows/rust.yml | 131 ++++++++----------------------------- 1 file changed, 26 insertions(+), 105 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a8596a8385..af8e08bf5a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,6 @@ env: cairo_programs/**/*.json !cairo_programs/manually_compiled/* examples/wasm-demo/src/array_sum.json - examples/wasm-demo-cairo1/src/bitwise.sierra TEST_COLLECT_COVERAGE: 1 PROPTEST_CASES: 100 @@ -49,7 +48,6 @@ jobs: cairo_test_programs, cairo_1_test_contracts, cairo_2_test_contracts, - cairo_1_wasm_example ] name: Build Cairo programs runs-on: ubuntu-22.04 @@ -69,11 +67,7 @@ jobs: id: cache-programs with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} restore-keys: ${{ matrix.program-target }}-cache- # This is not pretty, but we need `make` to see the compiled programs are @@ -98,12 +92,7 @@ jobs: run: pip install -r requirements.txt - name: Install cairo 1 compiler - if: | - steps.cache-programs.outputs.cache-hit != 'true' - && ( - matrix.program-target == 'cairo_1_test_contracts' - || matrix.program-target == 'cairo_1_wasm_example' - ) + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' run: make build-cairo-1-compiler - name: Install cairo 2 compiler @@ -133,62 +122,38 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Fetch proof programs uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Fetch bench programs uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Fetch test contracts (Cairo 1) uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Fetch test contracts (Cairo 2) uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Merge caches uses: actions/cache/save@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} lint: needs: build-programs @@ -217,11 +182,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Run clippy @@ -266,11 +227,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true # NOTE: we do this separately because --workspace operates in weird ways @@ -317,11 +274,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Check all features (workspace) @@ -356,11 +309,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Check no-std @@ -397,11 +346,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Install testing tools @@ -498,11 +443,7 @@ jobs: cairo_programs/**/*.air_public_input cairo_programs/**/*.air_private_input cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - name: Python3 Build @@ -521,11 +462,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true # This is not pretty, but we need `make` to see the compiled programs are @@ -572,11 +509,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Generate traces @@ -701,11 +634,7 @@ jobs: cairo_programs/**/*.air_public_input cairo_programs/**/*.air_private_input cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Fetch traces for cairo-vm @@ -756,9 +685,9 @@ jobs: cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json cd examples/wasm-demo wasm-pack build --target=web - + wasm-demo-cairo1: - name: Build the wasm-demo-cairo1 + name: Build the wasm demo runs-on: ubuntu-22.04 steps: - name: Checkout @@ -769,21 +698,17 @@ jobs: - name: Python3 Build uses: actions/setup-python@v4 with: - python-version: "3.9" - cache: "pip" - + python-version: '3.9' + cache: 'pip' + - name: Install cairo-lang and deps - run: | + run: | pip install -r requirements.txt npm install -g wasm-pack - - name: Install cairo 1 compiler - run: make build-cairo-1-compiler - - - name: Build wasm-demo-cairo1 + - name: Build wasm-demo run: | - cairo1/bin/cairo-compile cairo_programs/cairo-1-programs/bitwise.cairo cairo_programs/cairo-1-programs/bitwise.sierra - cd examples/wasm-demo-cairo1 + cd examples/wasm-demo wasm-pack build --target=web compare-factorial-outputs-all-layouts: @@ -819,11 +744,7 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles( - 'cairo_programs/**/*.cairo', - 'examples/wasm-demo/src/array_sum.cairo', - 'examples/wasm-demo-cairo1/src/bitwise.cairo' - ) }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} fail-on-cache-miss: true - name: Run script From ab04371e0e37644b0b6109ccb5f93ab7408902e8 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 14:23:53 -0300 Subject: [PATCH 24/37] fix workflows --- .github/workflows/rust.yml | 4 ++-- Makefile | 11 +++-------- cairo1-run/Cargo.toml | 2 +- examples/wasm-demo-cairo1/src/lib.rs | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index af8e08bf5a..7010da6461 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -706,9 +706,9 @@ jobs: pip install -r requirements.txt npm install -g wasm-pack - - name: Build wasm-demo + - name: Build wasm-demo-cairo1 run: | - cd examples/wasm-demo + cd examples/wasm-demo-cairo1 wasm-pack build --target=web compare-factorial-outputs-all-layouts: diff --git a/Makefile b/Makefile index 633113f04d..f96e41a1ea 100644 --- a/Makefile +++ b/Makefile @@ -108,9 +108,6 @@ $(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@ -$(TEST_DIR)/cairo-1-programs/bitwise.sierra: $(TEST_DIR)/cairo-1-programs/bitwise.cairo - cairo1/bin/cairo-compile -r $< $@ - $(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory $(TEST_DIR)/%.rs.pie.zip: $(TEST_DIR)/%.json $(RELBIN) cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $(@D)/$(*F).rs.trace --memory_file $(@D)/$(*F).rs.memory --cairo_pie_output $(@D)/$(*F).rs.pie.zip @@ -247,7 +244,6 @@ cairo_proof_programs: $(COMPILED_PROOF_TESTS) $(COMPILED_MOD_BUILTIN_PROOF_TESTS cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) cairo_2_test_contracts: $(CAIRO_2_COMPILED_CASM_CONTRACTS) -cairo_1_wasm_example: $(TEST_DIR)/cairo-1-programs/bitwise.sierra cairo_proof_trace: $(CAIRO_TRACE_PROOF) $(CAIRO_MEM_PROOF) $(CAIRO_AIR_PUBLIC_INPUT) $(CAIRO_AIR_PRIVATE_INPUT) cairo-vm_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_RS_AIR_PUBLIC_INPUT) $(CAIRO_RS_AIR_PRIVATE_INPUT) @@ -260,11 +256,11 @@ ifdef TEST_COLLECT_COVERAGE TEST_COMMAND:=cargo llvm-cov nextest --no-report endif -test: cairo_proof_programs cairo_1_wasm_example cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts +test: cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts $(TEST_COMMAND) --workspace --features "test_utils, cairo-1-hints" -test-no_std: cairo_proof_programs cairo_1_wasm_example cairo_test_programs +test-no_std: cairo_proof_programs cairo_test_programs $(TEST_COMMAND) --workspace --features test_utils --no-default-features -test-wasm: cairo_proof_programs cairo_1_wasm_example cairo_test_programs +test-wasm: cairo_proof_programs cairo_test_programs # NOTE: release mode is needed to avoid "too many locals" error wasm-pack test --release --node vm --no-default-features test-extensive_hints: cairo_proof_programs cairo_test_programs @@ -354,7 +350,6 @@ clean: rm -f $(TEST_PROOF_DIR)/*.cairo rm -f $(CAIRO_2_CONTRACTS_TEST_DIR)/*.sierra rm -f $(CAIRO_2_CONTRACTS_TEST_DIR)/*.casm - rm -f $(TEST_DIR)/cairo-1-programs/bitwise.sierra rm -f $(TEST_PROOF_DIR)/*.json rm -f $(TEST_PROOF_DIR)/*.memory rm -f $(TEST_PROOF_DIR)/*.trace diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 11345657e6..e2b4dfd6e8 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -9,7 +9,7 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cairo-vm = { workspace = true, features = ["std", "cairo-1-hints", "clap"] } +cairo-vm = { workspace = true, features = ["cairo-1-hints", "clap"] } serde_json = { workspace = true } cairo-lang-sierra-type-size = { version = "2.7.1", default-features = false } diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 6e051a1119..a4554b547e 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -34,12 +34,12 @@ pub fn run_cairo_program() -> Result { ..Default::default() }; let sierra_program = match serde_json::from_slice(include_bytes!( - "../../../cairo_programs/cairo-1-programs/bitwise.sierra" + "../bitwise.sierra" )) { Ok(sierra) => sierra, Err(_) => { let program_str = - include_str!("../../../cairo_programs/cairo-1-programs/bitwise.sierra"); + include_str!("../bitwise.sierra"); let parser = ProgramParser::new(); parser From debfed4b7fcf1f1fd18ce2608bdd89e3b31cef1b Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 14:27:11 -0300 Subject: [PATCH 25/37] format --- examples/wasm-demo-cairo1/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index a4554b547e..d66ba681d9 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -33,13 +33,10 @@ pub fn run_cairo_program() -> Result { serialize_output: true, ..Default::default() }; - let sierra_program = match serde_json::from_slice(include_bytes!( - "../bitwise.sierra" - )) { + let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { - let program_str = - include_str!("../bitwise.sierra"); + let program_str = include_str!("../bitwise.sierra"); let parser = ProgramParser::new(); parser From 85dc2de41ae16de608961210e21253de72e76c16 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 14:33:44 -0300 Subject: [PATCH 26/37] fix clippy --- examples/wasm-demo-cairo1/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index d66ba681d9..d49122428e 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -40,7 +40,7 @@ pub fn run_cairo_program() -> Result { let parser = ProgramParser::new(); parser - .parse(&program_str) + .parse(program_str) .map_err(|e| e.map_token(|t| t.to_string()))? } }; From b0e1e6d517b02043275558faf111bc05a954afa3 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 15:19:20 -0300 Subject: [PATCH 27/37] fix cairo1-run dependency to std --- cairo1-run/Cargo.toml | 4 ++-- cairo1-run/Makefile | 4 ++-- cairo1-run/README.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index e2b4dfd6e8..26a8073bfa 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -33,9 +33,9 @@ num-traits = { version = "0.2", default-features = false } num-bigint.workspace = true [features] -default = ["with_mimalloc", "cli"] +default = ["with_mimalloc"] with_mimalloc = ["dep:mimalloc"] -cli = ["dep:thiserror"] +cli = ["dep:thiserror", "cairo-vm/std"] [[bin]] name = "cairo1-run" diff --git a/cairo1-run/Makefile b/cairo1-run/Makefile index 10ce0f24fe..cb66ece2f6 100644 --- a/cairo1-run/Makefile +++ b/cairo1-run/Makefile @@ -6,7 +6,7 @@ $(CAIRO_1_FOLDER)/%.trace: $(CAIRO_1_FOLDER)/%.cairo cargo run --release --features cli $< --trace_file $@ --layout all_cairo $(CAIRO_1_FOLDER)/%.memory: $(CAIRO_1_FOLDER)/%.cairo - cargo run --release $< --memory_file $@ --layout all_cairo + cargo run --release --features cli $< --memory_file $@ --layout all_cairo CAIRO_1_PROGRAMS=$(wildcard ../cairo_programs/cairo-1-programs/*.cairo) TRACES:=$(patsubst $(CAIRO_1_FOLDER)/%.cairo, $(CAIRO_1_FOLDER)/%.trace, $(CAIRO_1_PROGRAMS)) @@ -20,7 +20,7 @@ deps: run: $(TRACES) $(MEMORY) test: - cargo test + cargo --features cli test clean: rm -rf corelib diff --git a/cairo1-run/README.md b/cairo1-run/README.md index a86748f7d5..91386690b9 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -16,7 +16,7 @@ Now that you have the dependencies necessary to run the tests, you can run: make test ``` -To execute a Cairo 1 program (either as Cairo 1 source file or Sierra) +To execute a Cairo 1 program (either as Cairo 1 source file or Sierra). Make sure the `cli` feature is active in order to use `cairo1-run` as a binary. ```bash cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo From bdd20b30844f742b82de63d3d331f414037f5156 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 15:20:18 -0300 Subject: [PATCH 28/37] fix cairo1-run dependency to std --- Cargo.lock | 56 ++++++++++++++-------------- examples/wasm-demo-cairo1/Cargo.toml | 4 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06222e1586..5112db0899 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,13 +249,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -668,7 +668,7 @@ checksum = "124402d8fad2a033bb36910dd7d0651f3100845c63dce679c58797a8cb0448c2" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -929,7 +929,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55a394e545f1500bea093d01be40895d3234faaa24d9585d08a509c514cabd88" dependencies = [ "hashbrown 0.14.5", - "indexmap 2.4.0", + "indexmap 2.5.0", "itertools 0.12.1", "num-bigint", "num-traits 0.2.19", @@ -1133,7 +1133,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1343,7 +1343,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1529,7 +1529,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1587,7 +1587,7 @@ checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1869,9 +1869,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -2477,7 +2477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.4.0", + "indexmap 2.5.0", ] [[package]] @@ -2512,7 +2512,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2944,7 +2944,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2985,7 +2985,7 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2996,7 +2996,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3174,7 +3174,7 @@ checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ "starknet-curve", "starknet-ff", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3252,9 +3252,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -3314,7 +3314,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3409,7 +3409,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3452,7 +3452,7 @@ version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", @@ -3537,7 +3537,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3711,7 +3711,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -3745,7 +3745,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3778,7 +3778,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -4051,7 +4051,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -4071,7 +4071,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] diff --git a/examples/wasm-demo-cairo1/Cargo.toml b/examples/wasm-demo-cairo1/Cargo.toml index ce72bb93ce..afe575a1c4 100644 --- a/examples/wasm-demo-cairo1/Cargo.toml +++ b/examples/wasm-demo-cairo1/Cargo.toml @@ -26,8 +26,8 @@ cairo-lang-sierra = { workspace = true } # code size when deploying. console_error_panic_hook = { version = "0.1.6", optional = true } -cairo1-run = { workspace = true } -cairo-vm = { workspace = true, default_features = false } +cairo-vm = { workspace = true } +cairo1-run = { workspace = true } [dev-dependencies] wasm-bindgen-test = "0.3.34" From d559aed796a92060a7590e666e20a0a032f0cb98 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 15:23:58 -0300 Subject: [PATCH 29/37] fix test command on cairo1-run --- cairo1-run/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cairo1-run/Makefile b/cairo1-run/Makefile index cb66ece2f6..92c380830f 100644 --- a/cairo1-run/Makefile +++ b/cairo1-run/Makefile @@ -20,7 +20,7 @@ deps: run: $(TRACES) $(MEMORY) test: - cargo --features cli test + cargo test --features cli clean: rm -rf corelib From 74ecf9fcc6b6e1d8cad194fff17dcc034bf35139 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 15:41:48 -0300 Subject: [PATCH 30/37] small typo --- .github/workflows/rust.yml | 1295 +++++++++++++------------- cairo1-run/README.md | 2 +- examples/wasm-demo-cairo1/Cargo.toml | 2 +- examples/wasm-demo-cairo1/README.md | 2 +- 4 files changed, 653 insertions(+), 648 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7010da6461..dde85bab8a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,9 +3,9 @@ name: QA on: merge_group: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ '**' ] + branches: ["**"] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -22,86 +22,86 @@ env: PROPTEST_CASES: 100 jobs: - # We need to use the same files across all jobs or else hashing will fail upload_proof_programs_symlinks: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Create proof_programs symlinks - run: make create-proof-programs-symlinks - - uses: actions/upload-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/*.cairo - + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create proof_programs symlinks + run: make create-proof-programs-symlinks + - uses: actions/upload-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/*.cairo + build-programs: needs: upload_proof_programs_symlinks strategy: matrix: # NOTE: we build cairo_bench_programs so clippy can check the benchmarks too - program-target: [ - cairo_bench_programs, - cairo_proof_programs, - cairo_test_programs, - cairo_1_test_contracts, - cairo_2_test_contracts, - ] + program-target: + [ + cairo_bench_programs, + cairo_proof_programs, + cairo_test_programs, + cairo_1_test_contracts, + cairo_2_test_contracts, + ] name: Build Cairo programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch from cache - uses: actions/cache@v3 - id: cache-programs - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-cache- - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - uses: chetan/git-restore-mtime-action@v1 - - - name: Python3 Build - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - if: | - steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - run: pip install -r requirements.txt - - - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' - run: make build-cairo-1-compiler - - - name: Install cairo 2 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' - run: make build-cairo-2-compiler - - - name: Build programs - if: steps.cache-programs.outputs.cache-hit != 'true' - run: make -j ${{ matrix.program-target }} + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch from cache + uses: actions/cache@v3 + id: cache-programs + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-cache- + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + uses: chetan/git-restore-mtime-action@v1 + + - name: Python3 Build + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + if: | + steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + run: pip install -r requirements.txt + + - name: Install cairo 1 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + run: make build-cairo-1-compiler + + - name: Install cairo 2 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' + run: make build-cairo-2-compiler + + - name: Build programs + if: steps.cache-programs.outputs.cache-hit != 'true' + run: make -j ${{ matrix.program-target }} # NOTE: used to reduce the amount of cache steps we need in later jobs # TODO: remove this cache once the workflow finishes @@ -110,84 +110,82 @@ jobs: runs-on: ubuntu-22.04 needs: build-programs steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch test programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch proof programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch bench programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 1) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 2) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Merge caches - uses: actions/cache/save@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch test programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch proof programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch bench programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 1) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 2) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Merge caches + uses: actions/cache/save@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} lint: needs: build-programs name: Run Lints runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: rustfmt, clippy - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Format - run: make check-fmt + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + - name: Format + run: make check-fmt - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Run clippy - run: make clippy + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Run clippy + run: make clippy # NOTE: the term "smoke test" comes from electronics design: the minimal # expectations anyone has in their device is to not catch fire on boot. @@ -200,42 +198,42 @@ jobs: crate: ["vm", "cairo-vm-cli", "cairo1-run"] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # NOTE: we do this separately because --workspace operates in weird ways - - name: Check all features (${{ matrix.crate }}) - run: | - cd ${{ matrix.crate }} - cargo check-all-features - cargo check-all-features --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # NOTE: we do this separately because --workspace operates in weird ways + - name: Check all features (${{ matrix.crate }}) + run: | + cd ${{ matrix.crate }} + cargo check-all-features + cargo check-all-features --workspace --all-targets smoke-workspace: needs: merge-caches @@ -246,77 +244,77 @@ jobs: chunk: [1, 2, 3, 4, 5, 6] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check all features (workspace) - run: | - cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check all features (workspace) + run: | + cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets smoke-no-std: needs: merge-caches name: Make sure all builds work (no_std) runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check no-std - run: | - cd ensure-no_std - cargo check --no-default-features - cargo check + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check no-std + run: | + cd ensure-no_std + cargo check --no-default-features + cargo check tests: needs: merge-caches @@ -324,467 +322,474 @@ jobs: fail-fast: false matrix: special_features: ["", "extensive_hints", "mod_builtin"] - target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ] + target: + [ + test#1, + test#2, + test#3, + test#4, + test-no_std#1, + test-no_std#2, + test-no_std#3, + test-no_std#4, + test-wasm, + ] name: Run tests runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: llvm-tools-preview - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Install testing tools - uses: taiki-e/install-action@v2 - with: - tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack - - - name: Install cairo 1 dependencies for running programs - run: | - cd cairo1-run - make deps - - - name: Run ${{ matrix.target }} - run: | - # this splits the `test#1` into `test` and `1` - export MATRIX_TARGET=${{ matrix.target }} - export NAME=${MATRIX_TARGET%#*} - export PARTITION=${MATRIX_TARGET#*#} - # FIXME: we need to update the Makefile to do this correctly - case ${NAME} in - 'test') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" - ;; - 'test-no_std') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --no-default-features --features "${{ matrix.special_features }}" - ;; - 'test-wasm') - # NOTE: release mode is needed to avoid "too many locals" error - wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" - ;; - esac - - - name: Save coverage - if: matrix.target != 'test-wasm' - uses: actions/cache/save@v3 - with: - path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info - key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Install testing tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack + + - name: Install cairo 1 dependencies for running programs + run: | + cd cairo1-run + make deps + + - name: Run ${{ matrix.target }} + run: | + # this splits the `test#1` into `test` and `1` + export MATRIX_TARGET=${{ matrix.target }} + export NAME=${MATRIX_TARGET%#*} + export PARTITION=${MATRIX_TARGET#*#} + # FIXME: we need to update the Makefile to do this correctly + case ${NAME} in + 'test') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" + ;; + 'test-no_std') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --no-default-features --features "${{ matrix.special_features }}" + ;; + 'test-wasm') + # NOTE: release mode is needed to avoid "too many locals" error + wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" + ;; + esac + + - name: Save coverage + if: matrix.target != 'test-wasm' + uses: actions/cache/save@v3 + with: + path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info + key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} build-release: name: Build release binary for comparisons runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - name: Build - run: cargo b --release -p cairo-vm-cli - # We don't read from cache because it should always miss - - name: Store in cache - uses: actions/cache/save@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + - name: Build + run: cargo b --release -p cairo-vm-cli + # We don't read from cache because it should always miss + - name: Store in cache + uses: actions/cache/save@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli run-cairo-reference: strategy: matrix: include: - - program-target: cairo_proof_programs - trace-target: cairo_proof_trace - nprocs: 1 - - program-target: cairo_test_programs - trace-target: cairo_trace - nprocs: 2 + - program-target: cairo_proof_programs + trace-target: cairo_proof_trace + nprocs: 1 + - program-target: cairo_test_programs + trace-target: cairo_trace + nprocs: 2 name: Compute memory and execution traces with cairo-lang needs: build-programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Check cache - uses: actions/cache@v3 - id: trace-cache - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - - - name: Python3 Build - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - if: steps.trace-cache.outputs.cache-hit != 'true' - run: pip install -r requirements.txt - - - name: Fetch programs - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: chetan/git-restore-mtime-action@v1 - - - name: Generate traces - if: steps.trace-cache.outputs.cache-hit != 'true' - run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Check cache + uses: actions/cache@v3 + id: trace-cache + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-reference-trace-cache- + + - name: Python3 Build + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + if: steps.trace-cache.outputs.cache-hit != 'true' + run: pip install -r requirements.txt + + - name: Fetch programs + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: chetan/git-restore-mtime-action@v1 + + - name: Generate traces + if: steps.trace-cache.outputs.cache-hit != 'true' + run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} run-cairo-release: strategy: matrix: include: - - program-target: cairo_proof_programs - programs-dir: cairo_programs/proof_programs - extra-args: '--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input ' - - program-target: cairo_test_programs - programs-dir: cairo_programs - extra-args: '--cairo_pie_output {program}.rs.pie.zip' + - program-target: cairo_proof_programs + programs-dir: cairo_programs/proof_programs + extra-args: "--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input " + - program-target: cairo_test_programs + programs-dir: cairo_programs + extra-args: "--cairo_pie_output {program}.rs.pie.zip" name: Compute memory and execution traces with cairo-vm - needs: [ build-programs, build-release ] + needs: [build-programs, build-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Generate traces - run: | - ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ - xargs -P 2 -I '{program}' \ - ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ - --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ - ${{ matrix.extra-args }} - - name: Update cache - uses: actions/cache/save@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Generate traces + run: | + ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ + xargs -P 2 -I '{program}' \ + ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ + --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ + ${{ matrix.extra-args }} + - name: Update cache + uses: actions/cache/save@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} upload-coverage: name: Upload coverage results to codecov.io needs: tests runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch results for tests with stdlib (part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-.info - key: codecov-cache-test#1--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-.info - key: codecov-cache-test#2--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-.info - key: codecov-cache-test#3--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-.info - key: codecov-cache-test#4--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib - uses: actions/cache/restore@v3 - with: - path: lcov-test-no_std-.info - key: codecov-cache-test-no_std--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-extensive_hints.info - key: codecov-cache-test#1-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-extensive_hints.info - key: codecov-cache-test#2-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-extensive_hints.info - key: codecov-cache-test#3-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-extensive_hints.info - key: codecov-cache-test#4-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib (w/extensive_hints) - uses: actions/cache/restore@v3 - with: - path: lcov-no_std-extensive_hints.info - key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - - - name: Upload coverage to codecov.io - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: '*.info' - fail_ci_if_error: true - + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch results for tests with stdlib (part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-.info + key: codecov-cache-test#1--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-.info + key: codecov-cache-test#2--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-.info + key: codecov-cache-test#3--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-.info + key: codecov-cache-test#4--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib + uses: actions/cache/restore@v3 + with: + path: lcov-test-no_std-.info + key: codecov-cache-test-no_std--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-extensive_hints.info + key: codecov-cache-test#1-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-extensive_hints.info + key: codecov-cache-test#2-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-extensive_hints.info + key: codecov-cache-test#3-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-extensive_hints.info + key: codecov-cache-test#4-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib (w/extensive_hints) + uses: actions/cache/restore@v3 + with: + path: lcov-no_std-extensive_hints.info + key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: "*.info" + fail_ci_if_error: true compare-memory-and-trace: strategy: matrix: - program-target: [ cairo_proof_programs, cairo_test_programs ] + program-target: [cairo_proof_programs, cairo_test_programs] name: Compare memory and execution traces from cairo-lang and cairo-vm - needs: [ run-cairo-reference, run-cairo-release ] + needs: [run-cairo-reference, run-cairo-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch traces for cairo-lang - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison script - run: | - if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then - PROOF=proof_mode - AIR_PUBLIC_INPUT=air_public_input - AIR_PRIVATE_INPUT=air_private_input - else - PIE=pie - fi - ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch traces for cairo-lang + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison script + run: | + if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then + PROOF=proof_mode + AIR_PUBLIC_INPUT=air_public_input + AIR_PRIVATE_INPUT=air_private_input + else + PIE=pie + fi + ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE wasm-demo: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo - run: | - cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json - cd examples/wasm-demo - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo + run: | + cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json + cd examples/wasm-demo + wasm-pack build --target=web + wasm-demo-cairo1: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo-cairo1 - run: | - cd examples/wasm-demo-cairo1 - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo-cairo1 + run: | + cd examples/wasm-demo-cairo1 + wasm-pack build --target=web + compare-factorial-outputs-all-layouts: name: Compare factorial outputs for all layouts - needs: [ build-programs, build-release ] + needs: [build-programs, build-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Run script - run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Run script + run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh compare-run-from-cairo-pie-all-outputs: name: Compare all outputs from running Cairo PIEs - needs: [ build-programs, build-release, run-cairo-release ] + needs: [build-programs, build-release, run-cairo-release] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: '3.9' - cache: 'pip' - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: cairo_test_programs-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison - run: ./vm/src/tests/compare_all_pie_outputs.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: cairo_test_programs-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison + run: ./vm/src/tests/compare_all_pie_outputs.sh diff --git a/cairo1-run/README.md b/cairo1-run/README.md index 91386690b9..bbd8f5de4b 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -25,7 +25,7 @@ cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo Arguments to generate the trace and memory files ```bash -cargo run ./cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory +cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory ``` To pass arguments to `main` diff --git a/examples/wasm-demo-cairo1/Cargo.toml b/examples/wasm-demo-cairo1/Cargo.toml index afe575a1c4..648d63ceb7 100644 --- a/examples/wasm-demo-cairo1/Cargo.toml +++ b/examples/wasm-demo-cairo1/Cargo.toml @@ -27,7 +27,7 @@ cairo-lang-sierra = { workspace = true } console_error_panic_hook = { version = "0.1.6", optional = true } cairo-vm = { workspace = true } - cairo1-run = { workspace = true } + [dev-dependencies] wasm-bindgen-test = "0.3.34" diff --git a/examples/wasm-demo-cairo1/README.md b/examples/wasm-demo-cairo1/README.md index 7fae7fd317..ec51c31131 100644 --- a/examples/wasm-demo-cairo1/README.md +++ b/examples/wasm-demo-cairo1/README.md @@ -20,7 +20,7 @@ To compile and run the example you need: ## Building -To build the example, first compile your Cairo program: +To build the example, first compile your Cairo 1.x program: ```sh cairo1/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra From af0f3a47dffc69fa70c33562429aa4edac32c6c1 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 16:09:19 -0300 Subject: [PATCH 31/37] comments --- examples/wasm-demo-cairo1/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index d49122428e..ca794b5e75 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -36,6 +36,7 @@ pub fn run_cairo_program() -> Result { let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { + // using cairo-lang 1.1.1 and ../caigo-programs/cairo-1-programs/bitwise.cairo let program_str = include_str!("../bitwise.sierra"); let parser = ProgramParser::new(); From 567ea7d912c07f4eb2311b817b65693bebc31757 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Mon, 2 Sep 2024 17:00:28 -0300 Subject: [PATCH 32/37] format --- .github/workflows/rust.yml | 1294 ++++++++++++++++++------------------ cairo1-run/fibonacci.cairo | 17 + 2 files changed, 661 insertions(+), 650 deletions(-) create mode 100644 cairo1-run/fibonacci.cairo diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dde85bab8a..df8ceb9b03 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,9 +3,9 @@ name: QA on: merge_group: push: - branches: [main] + branches: [ main ] pull_request: - branches: ["**"] + branches: [ '**' ] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -22,86 +22,86 @@ env: PROPTEST_CASES: 100 jobs: + # We need to use the same files across all jobs or else hashing will fail upload_proof_programs_symlinks: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Create proof_programs symlinks - run: make create-proof-programs-symlinks - - uses: actions/upload-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/*.cairo - + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create proof_programs symlinks + run: make create-proof-programs-symlinks + - uses: actions/upload-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/*.cairo + build-programs: needs: upload_proof_programs_symlinks strategy: matrix: # NOTE: we build cairo_bench_programs so clippy can check the benchmarks too - program-target: - [ - cairo_bench_programs, - cairo_proof_programs, - cairo_test_programs, - cairo_1_test_contracts, - cairo_2_test_contracts, - ] + program-target: [ + cairo_bench_programs, + cairo_proof_programs, + cairo_test_programs, + cairo_1_test_contracts, + cairo_2_test_contracts, + ] name: Build Cairo programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch from cache - uses: actions/cache@v3 - id: cache-programs - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-cache- - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - uses: chetan/git-restore-mtime-action@v1 - - - name: Python3 Build - if: steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - if: | - steps.cache-programs.outputs.cache-hit != 'true' - && matrix.program-target != 'cairo_1_test_contracts' - && matrix.program-target != 'cairo_2_test_contracts' - run: pip install -r requirements.txt - - - name: Install cairo 1 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' - run: make build-cairo-1-compiler - - - name: Install cairo 2 compiler - if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' - run: make build-cairo-2-compiler - - - name: Build programs - if: steps.cache-programs.outputs.cache-hit != 'true' - run: make -j ${{ matrix.program-target }} + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch from cache + uses: actions/cache@v3 + id: cache-programs + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-cache- + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + uses: chetan/git-restore-mtime-action@v1 + + - name: Python3 Build + if: steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + if: | + steps.cache-programs.outputs.cache-hit != 'true' + && matrix.program-target != 'cairo_1_test_contracts' + && matrix.program-target != 'cairo_2_test_contracts' + run: pip install -r requirements.txt + + - name: Install cairo 1 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts' + run: make build-cairo-1-compiler + + - name: Install cairo 2 compiler + if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts' + run: make build-cairo-2-compiler + + - name: Build programs + if: steps.cache-programs.outputs.cache-hit != 'true' + run: make -j ${{ matrix.program-target }} # NOTE: used to reduce the amount of cache steps we need in later jobs # TODO: remove this cache once the workflow finishes @@ -110,82 +110,84 @@ jobs: runs-on: ubuntu-22.04 needs: build-programs steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch test programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch proof programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch bench programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 1) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - name: Fetch test contracts (Cairo 2) - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Merge caches - uses: actions/cache/save@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch test programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch proof programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch bench programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 1) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + - name: Fetch test contracts (Cairo 2) + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Merge caches + uses: actions/cache/save@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} lint: needs: build-programs name: Run Lints runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: rustfmt, clippy - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ + - name: Format + run: make check-fmt - - name: Format - run: make check-fmt - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Run clippy + run: make clippy - - name: Run clippy - run: make clippy # NOTE: the term "smoke test" comes from electronics design: the minimal # expectations anyone has in their device is to not catch fire on boot. @@ -198,42 +200,42 @@ jobs: crate: ["vm", "cairo-vm-cli", "cairo1-run"] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # NOTE: we do this separately because --workspace operates in weird ways - - name: Check all features (${{ matrix.crate }}) - run: | - cd ${{ matrix.crate }} - cargo check-all-features - cargo check-all-features --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # NOTE: we do this separately because --workspace operates in weird ways + - name: Check all features (${{ matrix.crate }}) + run: | + cd ${{ matrix.crate }} + cargo check-all-features + cargo check-all-features --workspace --all-targets smoke-workspace: needs: merge-caches @@ -244,77 +246,77 @@ jobs: chunk: [1, 2, 3, 4, 5, 6] runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Install cargo-all-features - uses: taiki-e/install-action@v2 - with: - tool: cargo-all-features - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check all features (workspace) - run: | - cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Install cargo-all-features + uses: taiki-e/install-action@v2 + with: + tool: cargo-all-features + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check all features (workspace) + run: | + cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets smoke-no-std: needs: merge-caches name: Make sure all builds work (no_std) runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: - targets: wasm32-unknown-unknown - - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - - name: Checkout - uses: actions/checkout@v3 - - - name: Download proof programs symlinks - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Check no-std - run: | - cd ensure-no_std - cargo check --no-default-features - cargo check + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: + targets: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Checkout + uses: actions/checkout@v3 + + - name: Download proof programs symlinks + uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Check no-std + run: | + cd ensure-no_std + cargo check --no-default-features + cargo check tests: needs: merge-caches @@ -322,474 +324,466 @@ jobs: fail-fast: false matrix: special_features: ["", "extensive_hints", "mod_builtin"] - target: - [ - test#1, - test#2, - test#3, - test#4, - test-no_std#1, - test-no_std#2, - test-no_std#3, - test-no_std#4, - test-wasm, - ] + target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ] name: Run tests runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - with: + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + with: components: llvm-tools-preview - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Install testing tools - uses: taiki-e/install-action@v2 - with: - tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack - - - name: Install cairo 1 dependencies for running programs - run: | - cd cairo1-run - make deps - - - name: Run ${{ matrix.target }} - run: | - # this splits the `test#1` into `test` and `1` - export MATRIX_TARGET=${{ matrix.target }} - export NAME=${MATRIX_TARGET%#*} - export PARTITION=${MATRIX_TARGET#*#} - # FIXME: we need to update the Makefile to do this correctly - case ${NAME} in - 'test') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" - ;; - 'test-no_std') - cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ - --partition count:${PARTITION}/4 \ - --workspace --no-default-features --features "${{ matrix.special_features }}" - ;; - 'test-wasm') - # NOTE: release mode is needed to avoid "too many locals" error - wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" - ;; - esac - - - name: Save coverage - if: matrix.target != 'test-wasm' - uses: actions/cache/save@v3 - with: - path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info - key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Install testing tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest@0.9.49,cargo-llvm-cov,wasm-pack + + - name: Install cairo 1 dependencies for running programs + run: | + cd cairo1-run + make deps + + - name: Run ${{ matrix.target }} + run: | + # this splits the `test#1` into `test` and `1` + export MATRIX_TARGET=${{ matrix.target }} + export NAME=${MATRIX_TARGET%#*} + export PARTITION=${MATRIX_TARGET#*#} + # FIXME: we need to update the Makefile to do this correctly + case ${NAME} in + 'test') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" + ;; + 'test-no_std') + cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ + --partition count:${PARTITION}/4 \ + --workspace --no-default-features --features "${{ matrix.special_features }}" + ;; + 'test-wasm') + # NOTE: release mode is needed to avoid "too many locals" error + wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" + ;; + esac + + - name: Save coverage + if: matrix.target != 'test-wasm' + uses: actions/cache/save@v3 + with: + path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info + key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }} build-release: name: Build release binary for comparisons runs-on: ubuntu-22.04 steps: - - name: Install Rust - uses: dtolnay/rust-toolchain@1.76.0 - - name: Set up cargo cache - uses: Swatinem/rust-cache@v2 - - name: Checkout - uses: actions/checkout@v3 - - name: Build - run: cargo b --release -p cairo-vm-cli - # We don't read from cache because it should always miss - - name: Store in cache - uses: actions/cache/save@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli + - name: Install Rust + uses: dtolnay/rust-toolchain@1.76.0 + - name: Set up cargo cache + uses: Swatinem/rust-cache@v2 + - name: Checkout + uses: actions/checkout@v3 + - name: Build + run: cargo b --release -p cairo-vm-cli + # We don't read from cache because it should always miss + - name: Store in cache + uses: actions/cache/save@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli run-cairo-reference: strategy: matrix: include: - - program-target: cairo_proof_programs - trace-target: cairo_proof_trace - nprocs: 1 - - program-target: cairo_test_programs - trace-target: cairo_trace - nprocs: 2 + - program-target: cairo_proof_programs + trace-target: cairo_proof_trace + nprocs: 1 + - program-target: cairo_test_programs + trace-target: cairo_trace + nprocs: 2 name: Compute memory and execution traces with cairo-lang needs: build-programs runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Check cache - uses: actions/cache@v3 - id: trace-cache - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - restore-keys: ${{ matrix.program-target }}-reference-trace-cache- - - - name: Python3 Build - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - if: steps.trace-cache.outputs.cache-hit != 'true' - run: pip install -r requirements.txt - - - name: Fetch programs - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - # This is not pretty, but we need `make` to see the compiled programs are - # actually newer than the sources, otherwise it will try to rebuild them - - name: Restore timestamps - if: steps.trace-cache.outputs.cache-hit != 'true' - uses: chetan/git-restore-mtime-action@v1 - - - name: Generate traces - if: steps.trace-cache.outputs.cache-hit != 'true' - run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Check cache + uses: actions/cache@v3 + id: trace-cache + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + restore-keys: ${{ matrix.program-target }}-reference-trace-cache- + + - name: Python3 Build + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + if: steps.trace-cache.outputs.cache-hit != 'true' + run: pip install -r requirements.txt + + - name: Fetch programs + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + # This is not pretty, but we need `make` to see the compiled programs are + # actually newer than the sources, otherwise it will try to rebuild them + - name: Restore timestamps + if: steps.trace-cache.outputs.cache-hit != 'true' + uses: chetan/git-restore-mtime-action@v1 + + - name: Generate traces + if: steps.trace-cache.outputs.cache-hit != 'true' + run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }} + run-cairo-release: strategy: matrix: include: - - program-target: cairo_proof_programs - programs-dir: cairo_programs/proof_programs - extra-args: "--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input " - - program-target: cairo_test_programs - programs-dir: cairo_programs - extra-args: "--cairo_pie_output {program}.rs.pie.zip" + - program-target: cairo_proof_programs + programs-dir: cairo_programs/proof_programs + extra-args: '--proof_mode --air_public_input {program}.rs.air_public_input --air_private_input {program}.rs.air_private_input ' + - program-target: cairo_test_programs + programs-dir: cairo_programs + extra-args: '--cairo_pie_output {program}.rs.pie.zip' name: Compute memory and execution traces with cairo-vm - needs: [build-programs, build-release] + needs: [ build-programs, build-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Generate traces - run: | - ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ - xargs -P 2 -I '{program}' \ - ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ - --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ - ${{ matrix.extra-args }} - - name: Update cache - uses: actions/cache/save@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Generate traces + run: | + ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \ + xargs -P 2 -I '{program}' \ + ./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \ + --memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \ + ${{ matrix.extra-args }} + - name: Update cache + uses: actions/cache/save@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + upload-coverage: name: Upload coverage results to codecov.io needs: tests runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Fetch results for tests with stdlib (part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-.info - key: codecov-cache-test#1--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-.info - key: codecov-cache-test#2--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-.info - key: codecov-cache-test#3--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-.info - key: codecov-cache-test#4--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib - uses: actions/cache/restore@v3 - with: - path: lcov-test-no_std-.info - key: codecov-cache-test-no_std--${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-extensive_hints.info - key: codecov-cache-test#1-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-extensive_hints.info - key: codecov-cache-test#2-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-extensive_hints.info - key: codecov-cache-test#3-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-extensive_hints.info - key: codecov-cache-test#4-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib (w/extensive_hints) - uses: actions/cache/restore@v3 - with: - path: lcov-no_std-extensive_hints.info - key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - - name: Upload coverage to codecov.io - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: "*.info" - fail_ci_if_error: true + - name: Checkout + uses: actions/checkout@v3 + + - name: Fetch results for tests with stdlib (part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-.info + key: codecov-cache-test#1--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-.info + key: codecov-cache-test#2--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-.info + key: codecov-cache-test#3--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-.info + key: codecov-cache-test#4--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib + uses: actions/cache/restore@v3 + with: + path: lcov-test-no_std-.info + key: codecov-cache-test-no_std--${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) + uses: actions/cache/restore@v3 + with: + path: lcov-test#1-extensive_hints.info + key: codecov-cache-test#1-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) + uses: actions/cache/restore@v3 + with: + path: lcov-test#2-extensive_hints.info + key: codecov-cache-test#2-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) + uses: actions/cache/restore@v3 + with: + path: lcov-test#3-extensive_hints.info + key: codecov-cache-test#3-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) + uses: actions/cache/restore@v3 + with: + path: lcov-test#4-extensive_hints.info + key: codecov-cache-test#4-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + - name: Fetch results for tests without stdlib (w/extensive_hints) + uses: actions/cache/restore@v3 + with: + path: lcov-no_std-extensive_hints.info + key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} + fail-on-cache-miss: true + + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: '*.info' + fail_ci_if_error: true + compare-memory-and-trace: strategy: matrix: - program-target: [cairo_proof_programs, cairo_test_programs] + program-target: [ cairo_proof_programs, cairo_test_programs ] name: Compare memory and execution traces from cairo-lang and cairo-vm - needs: [run-cairo-reference, run-cairo-release] + needs: [ run-cairo-reference, run-cairo-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch traces for cairo-lang - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison script - run: | - if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then - PROOF=proof_mode - AIR_PUBLIC_INPUT=air_public_input - AIR_PRIVATE_INPUT=air_private_input - else - PIE=pie - fi - ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch traces for cairo-lang + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison script + run: | + if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then + PROOF=proof_mode + AIR_PUBLIC_INPUT=air_public_input + AIR_PRIVATE_INPUT=air_private_input + else + PIE=pie + fi + ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT $AIR_PRIVATE_INPUT $PIE wasm-demo: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo - run: | - cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json - cd examples/wasm-demo - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + + - name: Build wasm-demo + run: | + cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json + cd examples/wasm-demo + wasm-pack build --target=web + wasm-demo-cairo1: name: Build the wasm demo runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: | - pip install -r requirements.txt - npm install -g wasm-pack - - - name: Build wasm-demo-cairo1 - run: | - cd examples/wasm-demo-cairo1 - wasm-pack build --target=web - + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install cairo-lang and deps + run: | + pip install -r requirements.txt + npm install -g wasm-pack + - name: Build wasm-demo-cairo1 + run: | + cd examples/wasm-demo-cairo1 + wasm-pack build --target=web + compare-factorial-outputs-all-layouts: name: Compare factorial outputs for all layouts - needs: [build-programs, build-release] + needs: [ build-programs, build-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - uses: actions/download-artifact@master - with: - name: proof_programs - path: cairo_programs/proof_programs/ - - - name: Fetch programs - uses: actions/cache/restore@v3 - with: - path: ${{ env.CAIRO_PROGRAMS_PATH }} - key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} - fail-on-cache-miss: true - - - name: Run script - run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - uses: actions/download-artifact@master + with: + name: proof_programs + path: cairo_programs/proof_programs/ + + - name: Fetch programs + uses: actions/cache/restore@v3 + with: + path: ${{ env.CAIRO_PROGRAMS_PATH }} + key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }} + fail-on-cache-miss: true + + - name: Run script + run: ./vm/src/tests/compare_factorial_outputs_all_layouts.sh compare-run-from-cairo-pie-all-outputs: name: Compare all outputs from running Cairo PIEs - needs: [build-programs, build-release, run-cairo-release] + needs: [ build-programs, build-release, run-cairo-release ] runs-on: ubuntu-22.04 steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - - name: Install cairo-lang and deps - run: pip install -r requirements.txt - - - name: Fetch release binary - uses: actions/cache/restore@v3 - with: - key: cli-bin-rel-${{ github.sha }} - path: target/release/cairo-vm-cli - fail-on-cache-miss: true - - - name: Fetch traces for cairo-vm - uses: actions/cache/restore@v3 - with: - path: | - cairo_programs/**/*.memory - cairo_programs/**/*.trace - cairo_programs/**/*.air_public_input - cairo_programs/**/*.air_private_input - cairo_programs/**/*.pie.zip - key: cairo_test_programs-release-trace-cache-${{ github.sha }} - fail-on-cache-miss: true - - - name: Run comparison - run: ./vm/src/tests/compare_all_pie_outputs.sh + - name: Checkout + uses: actions/checkout@v3 + + - name: Python3 Build + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install cairo-lang and deps + run: pip install -r requirements.txt + + - name: Fetch release binary + uses: actions/cache/restore@v3 + with: + key: cli-bin-rel-${{ github.sha }} + path: target/release/cairo-vm-cli + fail-on-cache-miss: true + + - name: Fetch traces for cairo-vm + uses: actions/cache/restore@v3 + with: + path: | + cairo_programs/**/*.memory + cairo_programs/**/*.trace + cairo_programs/**/*.air_public_input + cairo_programs/**/*.air_private_input + cairo_programs/**/*.pie.zip + key: cairo_test_programs-release-trace-cache-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run comparison + run: ./vm/src/tests/compare_all_pie_outputs.sh diff --git a/cairo1-run/fibonacci.cairo b/cairo1-run/fibonacci.cairo new file mode 100644 index 0000000000..3b55898999 --- /dev/null +++ b/cairo1-run/fibonacci.cairo @@ -0,0 +1,17 @@ +use core::felt252; + +fn main() -> Array { + let n = 10; + let result = fib(1, 1, n); + + let mut output: Array = ArrayTrait::new(); + result.serialize(ref output); + output +} + +fn fib(a: felt252, b: felt252, n: felt252) -> felt252 { + match n { + 0 => a, + _ => fib(b, a + b, n - 1), + } +} From 4eef4d9d28cdb9511e0252b2d70688936b094169 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Tue, 3 Sep 2024 11:48:44 -0300 Subject: [PATCH 33/37] place the comment better --- examples/wasm-demo-cairo1/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index ca794b5e75..1822e67e2f 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -33,10 +33,11 @@ pub fn run_cairo_program() -> Result { serialize_output: true, ..Default::default() }; + + // using cairo-lang 1.1.1 and ../caigo-programs/cairo-1-programs/bitwise.cairo let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { - // using cairo-lang 1.1.1 and ../caigo-programs/cairo-1-programs/bitwise.cairo let program_str = include_str!("../bitwise.sierra"); let parser = ProgramParser::new(); From d249eb6433f3f2fd5a1b340eedf74715fdd9ecdb Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Wed, 4 Sep 2024 12:35:58 -0300 Subject: [PATCH 34/37] make requested changes --- cairo1-run/fibonacci.cairo | 17 ----------------- examples/wasm-demo-cairo1/README.md | 5 +++-- .../wasm-demo-cairo1/{src => }/bitwise.cairo | 0 examples/wasm-demo-cairo1/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 cairo1-run/fibonacci.cairo rename examples/wasm-demo-cairo1/{src => }/bitwise.cairo (100%) diff --git a/cairo1-run/fibonacci.cairo b/cairo1-run/fibonacci.cairo deleted file mode 100644 index 3b55898999..0000000000 --- a/cairo1-run/fibonacci.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use core::felt252; - -fn main() -> Array { - let n = 10; - let result = fib(1, 1, n); - - let mut output: Array = ArrayTrait::new(); - result.serialize(ref output); - output -} - -fn fib(a: felt252, b: felt252, n: felt252) -> felt252 { - match n { - 0 => a, - _ => fib(b, a + b, n - 1), - } -} diff --git a/examples/wasm-demo-cairo1/README.md b/examples/wasm-demo-cairo1/README.md index ec51c31131..0d0f444a30 100644 --- a/examples/wasm-demo-cairo1/README.md +++ b/examples/wasm-demo-cairo1/README.md @@ -23,9 +23,10 @@ To compile and run the example you need: To build the example, first compile your Cairo 1.x program: ```sh -cairo1/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra +../../cairo1/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra ``` -> It's important to use the `-r` flag. If not, the `main`function won't be recognized. + +> It's important to use the `-r` flag. If not, the `main` function won't be recognized. And then the WebAssembly package: diff --git a/examples/wasm-demo-cairo1/src/bitwise.cairo b/examples/wasm-demo-cairo1/bitwise.cairo similarity index 100% rename from examples/wasm-demo-cairo1/src/bitwise.cairo rename to examples/wasm-demo-cairo1/bitwise.cairo diff --git a/examples/wasm-demo-cairo1/src/lib.rs b/examples/wasm-demo-cairo1/src/lib.rs index 1822e67e2f..00ff0a2407 100644 --- a/examples/wasm-demo-cairo1/src/lib.rs +++ b/examples/wasm-demo-cairo1/src/lib.rs @@ -34,7 +34,7 @@ pub fn run_cairo_program() -> Result { ..Default::default() }; - // using cairo-lang 1.1.1 and ../caigo-programs/cairo-1-programs/bitwise.cairo + // using cairo-lang 1.1.1 and wasm-demo-cairo1/bitwise.sierra let sierra_program = match serde_json::from_slice(include_bytes!("../bitwise.sierra")) { Ok(sierra) => sierra, Err(_) => { From 316648482da94b465ea088c8dd8035db183eccd7 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 5 Sep 2024 09:37:17 -0300 Subject: [PATCH 35/37] make requested changes --- examples/wasm-demo-cairo1/README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/wasm-demo-cairo1/README.md b/examples/wasm-demo-cairo1/README.md index 0d0f444a30..5b3a466c53 100644 --- a/examples/wasm-demo-cairo1/README.md +++ b/examples/wasm-demo-cairo1/README.md @@ -1,7 +1,7 @@ # Demo of `cairo-vm` on WebAssembly While cairo-vm is compatible with WebAssembly, it doesn't implement any bindings to it. -Instead, create a new WebAssembly crate with cairo-vm as a dependency and implement the required functionality there. +Instead, create a new WebAssembly crate with cairo-vm and cairo1-run as dependencies and implement the required functionality there. Since mimalloc is not automatically compilable to WebAssembly, the cairo-vm dependency should disable the default features, which will in turn disable mimalloc. @@ -11,7 +11,7 @@ A working example is provided in this repository. To compile and run the example you need: -- a Cairo 0 compiler +- an either Cairo 1 or Cairo 2 compiler - the _wasm-pack_ crate - some HTTP server (for example: the `live-server` npm module) @@ -20,12 +20,20 @@ To compile and run the example you need: ## Building -To build the example, first compile your Cairo 1.x program: +To build the example, first compile your Cairo 1 / 2 program: + +Cairo 1 ```sh ../../cairo1/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra ``` +Cairo 2 + +```sh +../../cairo2/bin/cairo-compile -r ./bitwise.cairo bitwise.sierra +``` + > It's important to use the `-r` flag. If not, the `main` function won't be recognized. And then the WebAssembly package: @@ -42,7 +50,7 @@ To run the example webpage, you need to run an HTTP server. For example, using the _live-server_ npm module: ```sh -# while in /examples/wasm-demo +# while in /examples/wasm-demo-cairo1 npx live-server ``` From 5dc92e8cd0b39f986d3cf694c2d526932abc37be Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 5 Sep 2024 09:39:34 -0300 Subject: [PATCH 36/37] make requested changes --- .github/workflows/rust.yml | 8 +------- CHANGELOG.md | 2 +- Cargo.toml | 1 - cairo1-run/Cargo.toml | 2 +- cairo1-run/README.md | 8 ++++---- cairo1-run/src/main.rs | 2 +- vm/Cargo.toml | 16 +++------------- 7 files changed, 11 insertions(+), 28 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index df8ceb9b03..29ce43364f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -687,7 +687,7 @@ jobs: wasm-pack build --target=web wasm-demo-cairo1: - name: Build the wasm demo + name: Build the wasm demo cairo1 runs-on: ubuntu-22.04 steps: - name: Checkout @@ -695,12 +695,6 @@ jobs: with: fetch-depth: 0 - - name: Python3 Build - uses: actions/setup-python@v4 - with: - python-version: "3.9" - cache: "pip" - - name: Install cairo-lang and deps run: | pip install -r requirements.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2cbf46fc..a61c29b929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ #### [1.0.1] - 2024-08-12 -* fix(BREAKING): [#1818](https://github.com/lambdaclass/cairo-vm/pull/1818): +* fix(BREAKING): [#1818](https://github.com/lambdaclass/cairo-vm/pull/1818): * Fix `MemorySegmentManager::add_zero_segment` function when resizing a segment * Signature change(BREAKING): `MemorySegmentManager::get_memory_holes` now receives `builtin_segment_indexes: HashSet` diff --git a/Cargo.toml b/Cargo.toml index 74cbc103d7..c9afe6dffa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,6 @@ lto = "fat" opt-level = "s" [profile.release.package.wasm-demo-cairo1] -# Tell `rustc` to optimize for small code size. opt-level = "s" [profile.test.package.proptest] diff --git a/cairo1-run/Cargo.toml b/cairo1-run/Cargo.toml index 26a8073bfa..01d1d907c1 100644 --- a/cairo1-run/Cargo.toml +++ b/cairo1-run/Cargo.toml @@ -9,7 +9,7 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cairo-vm = { workspace = true, features = ["cairo-1-hints", "clap"] } +cairo-vm = {workspace = true, features = ["cairo-1-hints", "clap"]} serde_json = { workspace = true } cairo-lang-sierra-type-size = { version = "2.7.1", default-features = false } diff --git a/cairo1-run/README.md b/cairo1-run/README.md index bbd8f5de4b..e41814d261 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -19,13 +19,13 @@ make test To execute a Cairo 1 program (either as Cairo 1 source file or Sierra). Make sure the `cli` feature is active in order to use `cairo1-run` as a binary. ```bash -cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo +cargo run --features cli ../cairo_programs/cairo-1-programs/fibonacci.cairo ``` Arguments to generate the trace and memory files ```bash -cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory +cargo run --features cli ../cairo_programs/cairo-1-programs/fibonacci.cairo --trace_file ../cairo_programs/cairo-1-programs/fibonacci.trace --memory_file ../cairo_programs/cairo-1-programs/fibonacci.memory ``` To pass arguments to `main` @@ -36,7 +36,7 @@ Example: ```bash -cargo run ../cairo_programs/cairo-1-programs/with_input/array_input_sum.cairo --layout all_cairo --args '2 [1 2 3 4] 0 [9 8]' +cargo run --features cli ../cairo_programs/cairo-1-programs/with_input/array_input_sum.cairo --layout all_cairo --args '2 [1 2 3 4] 0 [9 8]' ``` @@ -85,7 +85,7 @@ Then run the compiled project's sierra file located at `project_name/target/proj Example: ```bash - cargo run path-to-project/target/project_name.sierra.json + cargo run --features cli path-to-project/target/project_name.sierra.json ``` # Known bugs & issues diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 037675ae41..8a4a5058bb 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -32,7 +32,7 @@ struct Args { air_public_input: Option, #[clap( long = "air_private_input", - requires_all = ["proof_mode", "trace_file", "memory_file"] + requires_all = ["proof_mode", "trace_file", "memory_file"] )] air_private_input: Option, #[clap( diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 9d9ab36151..70f92be998 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -31,12 +31,7 @@ tracer = [] mod_builtin = [] # Note that these features are not retro-compatible with the cairo Python VM. -test_utils = [ - "std", - "dep:arbitrary", - "starknet-types-core/arbitrary", - "starknet-types-core/std", -] # This feature will reference every test-oriented feature +test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet-types-core/std"] # This feature will reference every test-oriented feature # Allows extending the set of hints for the current vm run from within a hint. # For a usage example checkout vm/src/tests/run_deprecated_contract_class_simplified.rs extensive_hints = [] @@ -61,12 +56,7 @@ keccak = { workspace = true } hashbrown = { workspace = true } anyhow = { workspace = true } thiserror-no-std = { workspace = true } -starknet-types-core = { version = "0.1.2", default-features = false, features = [ - "serde", - "curve", - "num-traits", - "hash", -] } +starknet-types-core = { version = "0.1.2", default-features = false, features = [ "serde", "curve", "num-traits", "hash"] } rust_decimal = { version = "1.35.0", default-features = false } # only for std @@ -86,7 +76,7 @@ ark-std = { workspace = true, optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true } # Used to derive clap traits for CLIs -clap = { version = "4.3.10", features = ["derive"], optional = true } +clap = { version = "4.3.10", features = ["derive"], optional = true} # Pin wasm-bindgen version to fix ensure-no_std CI workflow # It's not used directly From 50bd9ee8dbbeaf379d2ae2dbfdfb94d8e97ee1b7 Mon Sep 17 00:00:00 2001 From: FrancoGiachetta Date: Thu, 5 Sep 2024 09:53:41 -0300 Subject: [PATCH 37/37] update workflows --- .github/workflows/rust.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 29ce43364f..6ab211259f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -697,7 +697,6 @@ jobs: - name: Install cairo-lang and deps run: | - pip install -r requirements.txt npm install -g wasm-pack - name: Build wasm-demo-cairo1 run: |