diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4714b9e673..e09b6ce49e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -489,3 +489,30 @@ jobs: AIR_PUBLIC_INPUT=air_public_input fi ./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT + ./vm/src/tests/compare_vm_state.sh trace memory $PROOF + + 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 063e4701d1..5260624deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ #### Upcoming Changes +* fix: Change return type of `get_execution_resources` to `RunnerError` [#1398](https://github.com/lambdaclass/cairo-vm/pull/1398) + +* Don't build wasm-demo in `build` target + add ci job to run the wasm demo [#1393](https://github.com/lambdaclass/cairo-vm/pull/1393) + + * Adds default-members to workspace + * Crate `examples/wasm-demo` is no longer built during `make build` + * `make check` no longer compiles the cairo file used in the wasm-demo + * Removes Makefile targets `examples/wasm-demo/src/array_sum.json` & `example_program` + * `wasm-demo` now uses the compiled cairo file in `cairo_programs` directory instead of its own copy + * feat: Add `Program::new_for_proof` [#1396](https://github.com/lambdaclass/cairo-vm/pull/1396) #### [0.8.7] - 2023-8-28 @@ -12,7 +22,7 @@ * BREAKING: Add `disable_trace_padding` to `CairoRunConfig`[#1233](https://github.com/lambdaclass/cairo-rs/pull/1233) -* feat: Implement `CairoRunner.get_cairo_pie`[#1375](https://github.com/lambdaclass/cairo-vm/pull/1375/files) +* feat: Implement `CairoRunner.get_cairo_pie`[#1375](https://github.com/lambdaclass/cairo-vm/pull/1375) * fix: Compare air_public_inputs against python vm + Fix how public memory is built [#391](https://github.com/lambdaclass/cairo-vm/pull/1391) diff --git a/Cargo.toml b/Cargo.toml index 8ef96c68dc..f4d6434937 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,11 @@ members = [ "hint_accountant", "examples/wasm-demo", ] +default-members = [ + "cairo-vm-cli", + "felt", + "vm", +] exclude = ["ensure-no_std"] # Explicitly set the resolver to the default for edition >= 2021 diff --git a/Makefile b/Makefile index 926a75cf2d..10ed9eafff 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ STARKNET_SIERRA_COMPILE_CAIRO_2:=cairo2/bin/starknet-sierra-compile compare_trace_memory_proof compare_all_proof compare_trace_proof compare_memory_proof compare_air_public_input \ cairo_bench_programs cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts \ cairo_trace cairo-vm_trace cairo_proof_trace cairo-vm_proof_trace \ - $(RELBIN) $(DBGBIN) example_programs + $(RELBIN) $(DBGBIN) # Proof mode consumes too much memory with cairo-lang to execute # two instances at the same time in the CI without getting killed @@ -210,16 +210,10 @@ build: $(RELBIN) run: cargo run -p cairo-vm-cli -check: example_programs +check: cargo check -examples/wasm-demo/src/array_sum.json: examples/wasm-demo/src/array_sum.cairo - cairo-compile --no_debug_info examples/wasm-demo/src/array_sum.cairo \ - --output examples/wasm-demo/src/array_sum.json - -example_programs: examples/wasm-demo/src/array_sum.json - -cairo_test_programs: $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) example_programs +cairo_test_programs: $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) cairo_proof_programs: $(COMPILED_PROOF_TESTS) cairo_bench_programs: $(COMPILED_BENCHES) cairo_1_test_contracts: $(CAIRO_1_COMPILED_CASM_CONTRACTS) diff --git a/examples/wasm-demo/README.md b/examples/wasm-demo/README.md index e8d58c13eb..26343c2593 100644 --- a/examples/wasm-demo/README.md +++ b/examples/wasm-demo/README.md @@ -1,9 +1,9 @@ -# Demo of `cairo-rs` on WebAssembly +# Demo of `cairo-vm` on WebAssembly -While cairo-rs is compatible with WebAssembly, it doesn't implement any bindings to it. -Instead, create a new WebAssembly crate with cairo-rs as a dependency and implement the required functionality there. +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-rs dependency should disable the default features, which will in turn disable mimalloc. +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. @@ -23,7 +23,7 @@ To compile and run the example you need: To build the example, first compile your Cairo program: ```sh -cairo-compile src/array_sum.cairo --no_debug_info --output src/array_sum.json +cairo-compile ../../cairo_programs/array_sum.cairo --no_debug_info --output ../../cairo_programs/array_sum.json ``` And then the WebAssembly package: diff --git a/examples/wasm-demo/src/lib.rs b/examples/wasm-demo/src/lib.rs index c3ad8d406c..60ffcbe59b 100644 --- a/examples/wasm-demo/src/lib.rs +++ b/examples/wasm-demo/src/lib.rs @@ -27,7 +27,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(); diff --git a/felt/src/lib_lambdaworks.rs b/felt/src/lib_lambdaworks.rs index d988f58f3c..4fd06b38d8 100644 --- a/felt/src/lib_lambdaworks.rs +++ b/felt/src/lib_lambdaworks.rs @@ -761,8 +761,18 @@ impl Integer for Felt252 { } fn div_rem(&self, other: &Self) -> (Self, Self) { - let (div, rem) = self.to_biguint().div_mod_floor(&other.to_biguint()); - (Self::from(div), Self::from(rem)) + let (div, rem) = self + .value + .representative() + .div_rem(&other.value.representative()); + ( + Self { + value: FieldElement::from(&div), + }, + Self { + value: FieldElement::from(&rem), + }, + ) } // NOTE: we overload because the default impl calls div_floor AND mod_floor. diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 2d9aaf492f..a80d7896f5 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -868,7 +868,7 @@ impl CairoRunner { pub fn get_execution_resources( &self, vm: &VirtualMachine, - ) -> Result { + ) -> Result { let n_steps = match self.original_steps { Some(x) => x, None => vm