Skip to content

Commit

Permalink
Merge branch 'main' into compare-public-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta authored Aug 29, 2023
2 parents ffa4628 + 2aed1ba commit e860e0e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions examples/wasm-demo/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/wasm-demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! wrap_error {

#[wasm_bindgen(js_name = runCairoProgram)]
pub fn run_cairo_program() -> Result<String, JsError> {
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();

Expand Down
14 changes: 12 additions & 2 deletions felt/src/lib_lambdaworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ impl CairoRunner {
pub fn get_execution_resources(
&self,
vm: &VirtualMachine,
) -> Result<ExecutionResources, TraceError> {
) -> Result<ExecutionResources, RunnerError> {
let n_steps = match self.original_steps {
Some(x) => x,
None => vm
Expand Down

0 comments on commit e860e0e

Please sign in to comment.