Skip to content

Commit

Permalink
fix: remove enforce selector constraint (#205)
Browse files Browse the repository at this point in the history
* Start Cairo AIR refactor

* Refactor Cairo execution trace module

* Fix tests so that they compile

* Continue fixes

* Fix cairo output and rc program test

* Rearrange testing folders

* Fix some tests

* Fix all tests

* Fixed transition degrees to the correct ones

* Polish tests and fix benches

* Fix makefile targets

* Add documentation for add_pub_memory_in_public_input_section

* Uncomment test optimizations

* Fix giza bench

* Fix giza bench again

* Save work in progress

* Fix benchmarks

* Fix clippy lints

* Add serialization tests

* Remove Cairo 1

* Fmt

* Remove no longer valid tests

* Fix clippy

* Update Cargo.toml

---------

Co-authored-by: MauroFab <[email protected]>
Co-authored-by: Mauro Toscano <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent c601bb1 commit 3002245
Show file tree
Hide file tree
Showing 25 changed files with 2,746 additions and 1,816 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ COMPILED_CAIRO0_PROGRAMS:=$(patsubst $(CAIRO0_PROGRAMS_DIR)/%.cairo, $(CAIRO0_PR
# When using the docker version, be sure to build the image using `make docker_build_cairo_compiler`.
$(CAIRO0_PROGRAMS_DIR)/%.json: $(CAIRO0_PROGRAMS_DIR)/%.cairo
@echo "Compiling Cairo program..."
@cairo-compile --cairo_path="$(CAIRO0_PROGRAMS_DIR)" $< --output $@ 2> /dev/null || \
docker run --rm -v $(ROOT_DIR)/$(CAIRO0_PROGRAMS_DIR):/pwd/$(CAIRO0_PROGRAMS_DIR) cairo cairo-compile /pwd/$< > $@
@cairo-compile --cairo_path="$(CAIRO0_PROGRAMS_DIR)" $< --output $@ 2> /dev/null --proof_mode || \
docker run --rm -v $(ROOT_DIR)/$(CAIRO0_PROGRAMS_DIR):/pwd/$(CAIRO0_PROGRAMS_DIR) cairo --proof_mode /pwd/$< > $@

build:
cargo build --release
Expand Down Expand Up @@ -66,35 +66,35 @@ docker_build_cairo_compiler:
docker build -f cairo_compile.Dockerfile -t cairo .

docker_compile_cairo:
docker run -v $(ROOT_DIR):/pwd cairo cairo-compile /pwd/$(PROGRAM) > $(OUTPUT)
docker run -v $(ROOT_DIR):/pwd cairo --proof_mode /pwd/$(PROGRAM) > $(OUTPUT)

target/release/cairo-platinum-prover:
cargo build --bin cairo-platinum-prover --release --features instruments

docker_compile_and_run_all: target/release/cairo-platinum-prover
@echo "Compiling program with docker"
@docker run -v $(ROOT_DIR):/pwd cairo cairo-compile /pwd/$(PROGRAM) > $(PROGRAM).json
@docker run -v $(ROOT_DIR):/pwd cairo --proof_mode /pwd/$(PROGRAM) > $(PROGRAM).json
@echo "Compiling done \n"
@cargo run --bin cairo-platinum-prover --features instruments --quiet --release prove_and_verify $(PROGRAM).json
@rm $(PROGRAM).json

docker_compile_and_prove: target/release/cairo-platinum-prover
@echo "Compiling program with docker"
@docker run -v $(ROOT_DIR):/pwd cairo cairo-compile /pwd/$(PROGRAM) > $(PROGRAM).json
@docker run -v $(ROOT_DIR):/pwd cairo --proof_mode /pwd/$(PROGRAM) > $(PROGRAM).json
@echo "Compiling done \n"
@cargo run --bin cairo-platinum-prover --features instruments --quiet --release prove $(PROGRAM).json $(PROOF_PATH)
@rm $(PROGRAM).json

compile_and_run_all: target/release/cairo-platinum-prover
@echo "Compiling program with cairo-compile"
@cairo-compile $(PROGRAM) > $(PROGRAM).json
@cairo-compile --proof_mode $(PROGRAM) > $(PROGRAM).json
@echo "Compiling done \n"
@cargo run --bin cairo-platinum-prover --features instruments --quiet --release prove_and_verify $(PROGRAM).json
@rm $(PROGRAM).json

compile_and_prove: target/release/cairo-platinum-prover
@echo "Compiling program with cairo-compile"
@cairo-compile $(PROGRAM) > $(PROGRAM).json
@cairo-compile --proof_mode $(PROGRAM) > $(PROGRAM).json
@echo "Compiling done \n"
@cargo run --bin cairo-platinum-prover --features instruments --quiet --release prove $(PROGRAM).json $(PROOF_PATH)
@rm $(PROGRAM).json
Expand Down
55 changes: 17 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ CLI currently runs with 100 bits of conjecturable security

## Table of Contents

- [Main Building Blocks](#main-building-blocks)
- [Requirements](#requirements)
- [Trying it](#how-to-try-it)
- [Prove and verify](#-prove-and-verify)
- [Fuzzers](#running-fuzzers)
- [Using cairo-compile for Cairo 0 programs](#using-cairo-compile-for-cairo-0-programs)
- [References](#-references)
- [Related projects](#-related-projects)
- [🌟 Lambdaworks Stark Platinum Prover 🌟](#-lambdaworks-stark-platinum-prover-)
- [An open-source STARK prover, drop-in replacement for Winterfell.](#an-open-source-stark-prover-drop-in-replacement-for-winterfell)
- [⚠️ Disclaimer](#️-disclaimer)
- [Documentation](#documentation)
- [Table of Contents](#table-of-contents)
- [Main building blocks](#main-building-blocks)
- [Requirements](#requirements)
- [How to try it](#how-to-try-it)
- [🚀 Prove and verify](#-prove-and-verify)
- [Using Docker compiler for Cairo 0 programs](#using-docker-compiler-for-cairo-0-programs)
- [Using cairo-compile for Cairo 0 programs](#using-cairo-compile-for-cairo-0-programs)
- [Using WASM verifier](#using-wasm-verifier)
- [Running tests](#running-tests)
- [Running fuzzers](#running-fuzzers)
- [📚 References](#-references)
- [🌞 Related Projects](#-related-projects)

## Main building blocks

Expand Down Expand Up @@ -94,11 +102,9 @@ To be added:

## How to try it

For the moment, only programs in Cairo 0 with no arguments and contracts in Cairo 1 with no arguments are supported.

### 🚀 Prove and verify

To prove Cairo programs you can use:
To prove Cairo 0 programs without arguments you can use:

```bash
make prove PROGRAM_PATH=<compiled_program_path> PROOF_PATH=<output_proof_path>
Expand All @@ -123,7 +129,6 @@ To prove and verify with a single command you can use:
make run_all PROGRAM_PATH=<proof_path>
```


### Using Docker compiler for Cairo 0 programs

Build the compiler image with:
Expand Down Expand Up @@ -160,32 +165,6 @@ Or
make compile_and_prove PROGRAM=program_name.cairo PROOF_PATH=proof_path
```

### Compiling Cairo 1 contracts

Clone `cairo` repository:

``` bash
git clone https://github.com/starkware-libs/cairo
```

Checkout version 1.1.0 (corresponding to that tag of the repository). In the `cairo` folder, run:

``` bash
git checkout v1.1.0
```

- To create json file from Cairo contract:

``` bash
cargo run --bin starknet-compile -- /path/to/input.cairo /path/to/output.json
```

- To create casm file from json file:

``` bash
cargo run --bin starknet-sierra-compile -- /path/to/input.json /path/to/output.casm
```

### Using WASM verifier

To use the verifier in WASM, generate a npm package using `wasm-pack`
Expand Down
2 changes: 1 addition & 1 deletion cairo_compile.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ COPY requirements.txt /

RUN pip install -r /requirements.txt

CMD ["cairo-compile"]
ENTRYPOINT ["cairo-compile"]
8 changes: 3 additions & 5 deletions cairo_prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ version.workspace = true
edition.workspace = true
license.workspace = true

# [[bin]]
# name = "cairo-platinum"
# path = "src/main.rs"
[[bin]]
name = "cairo-platinum-prover"
path = "src/main.rs"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -21,12 +21,10 @@ stark-platinum-prover = { path = "../stark_prover", features = ["wasm"] }
thiserror = "1.0.38"
log = "0.4.17"
bincode = { version = "2.0.0-rc.2", tag = "v2.0.0-rc.2", git = "https://github.com/bincode-org/bincode.git" }
# cairo-vm = { version = "0.6.0", features = ["cairo-1-hints"] }
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "e763cef", default-features = false, features = [
"cairo-1-hints",
]}
sha3 = "0.10.6"
cairo-lang-starknet = { version = "2.1.0-rc2", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
num-integer = "0.1.45"
Expand Down
9 changes: 5 additions & 4 deletions cairo_prover/benches/criterion_giza.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[cfg(feature = "giza")]
use cairo_platinum_prover::{
air::generate_cairo_proof,
runner::run::{generate_prover_args, CairoVersion},
air::generate_cairo_proof, cairo_layout::CairoLayout, runner::run::generate_prover_args,
};
#[cfg(feature = "giza")]
use criterion::{black_box, measurement::WallTime, BenchmarkGroup};
Expand Down Expand Up @@ -41,6 +40,7 @@ fn cairo_benches(c: &mut Criterion) {
&proof_options,
"lambdaworks/fibonacci/1000",
&cairo0_program_path("fibonacci_1000.json"),
CairoLayout::Plain,
);
run_giza_bench(
&mut group,
Expand All @@ -56,6 +56,7 @@ fn cairo_benches(c: &mut Criterion) {
&proof_options,
"lambdaworks/fibonacci/10000",
&cairo0_program_path("fibonacci_10000.json"),
CairoLayout::Plain,
);
run_giza_bench(
&mut group,
Expand All @@ -81,10 +82,10 @@ fn run_lambdaworks_bench(
proof_options: &options::ProofOptions,
benchname: &str,
program_path: &str,
layout: CairoLayout,
) {
let program_content = std::fs::read(program_path).unwrap();
let (main_trace, pub_inputs) =
generate_prover_args(&program_content, &CairoVersion::V0, &None).unwrap();
let (main_trace, pub_inputs) = generate_prover_args(&program_content, &None, layout).unwrap();

group.bench_function(benchname, |bench| {
bench.iter(|| {
Expand Down
15 changes: 10 additions & 5 deletions cairo_prover/benches/criterion_prover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cairo_platinum_prover::{
air::generate_cairo_proof,
runner::run::{generate_prover_args, CairoVersion},
air::generate_cairo_proof, cairo_layout::CairoLayout, runner::run::generate_prover_args,
};
use criterion::{
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
Expand Down Expand Up @@ -29,11 +28,13 @@ fn cairo_benches(c: &mut Criterion) {
&mut group,
"fibonacci/500",
&cairo0_program_path("fibonacci_500.json"),
CairoLayout::Plain,
);
run_cairo_bench(
&mut group,
"fibonacci/1000",
&cairo0_program_path("fibonacci_1000.json"),
CairoLayout::Plain,
);
}

Expand All @@ -44,11 +45,15 @@ fn cairo0_program_path(program_name: &str) -> String {
program_base_path + program_name
}

fn run_cairo_bench(group: &mut BenchmarkGroup<'_, WallTime>, benchname: &str, program_path: &str) {
fn run_cairo_bench(
group: &mut BenchmarkGroup<'_, WallTime>,
benchname: &str,
program_path: &str,
layout: CairoLayout,
) {
let program_content = std::fs::read(program_path).unwrap();
let proof_options = ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3);
let (main_trace, pub_inputs) =
generate_prover_args(&program_content, &CairoVersion::V0, &None).unwrap();
let (main_trace, pub_inputs) = generate_prover_args(&program_content, &None, layout).unwrap();
println!("Generated main trace with {} rows", main_trace.n_rows());

group.bench_function(benchname, |bench| {
Expand Down
17 changes: 10 additions & 7 deletions cairo_prover/benches/criterion_prover_70k.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use cairo_platinum_prover::{
air::generate_cairo_proof,
runner::run::{generate_prover_args, CairoVersion},
};
use cairo_platinum_prover::cairo_layout::CairoLayout;
use cairo_platinum_prover::{air::generate_cairo_proof, runner::run::generate_prover_args};
use criterion::{
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
SamplingMode,
Expand Down Expand Up @@ -31,6 +29,7 @@ fn fibo_70k_bench(c: &mut Criterion) {
&mut group,
"fibonacci/70000",
&cairo0_program_path("fibonacci_70000.json"),
CairoLayout::Plain,
);
}

Expand All @@ -41,11 +40,15 @@ fn cairo0_program_path(program_name: &str) -> String {
program_base_path + program_name
}

fn run_cairo_bench(group: &mut BenchmarkGroup<'_, WallTime>, benchname: &str, program_path: &str) {
fn run_cairo_bench(
group: &mut BenchmarkGroup<'_, WallTime>,
benchname: &str,
program_path: &str,
layout: CairoLayout,
) {
let program_content = std::fs::read(program_path).unwrap();
let proof_options = ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3);
let (main_trace, pub_inputs) =
generate_prover_args(&program_content, &CairoVersion::V0, &None).unwrap();
let (main_trace, pub_inputs) = generate_prover_args(&program_content, &None, layout).unwrap();

group.bench_function(benchname, |bench| {
bench.iter(|| {
Expand Down
18 changes: 0 additions & 18 deletions cairo_prover/cairo_programs/cairo1/fibonacci_cairo1.cairo

This file was deleted.

Loading

0 comments on commit 3002245

Please sign in to comment.