Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re add Cairo Prover makefile, simplified readme #571

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions provers/cairo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.PHONY: test coverage clippy clean

ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

CAIRO0_PROGRAMS_DIR=cairo_prover/cairo_programs/cairo0
CAIRO0_PROGRAMS:=$(wildcard $(CAIRO0_PROGRAMS_DIR)/*.cairo)
COMPILED_CAIRO0_PROGRAMS:=$(patsubst $(CAIRO0_PROGRAMS_DIR)/%.cairo, $(CAIRO0_PROGRAMS_DIR)/%.json, $(CAIRO0_PROGRAMS))

# Rule to compile Cairo programs for testing purposes.
# If the `cairo-lang` toolchain is installed, programs will be compiled with it.
# Otherwise, the cairo_compile docker image will be used
# 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 --proof_mode || \
docker run --rm -v $(ROOT_DIR)/$(CAIRO0_PROGRAMS_DIR):/pwd/$(CAIRO0_PROGRAMS_DIR) cairo --proof_mode /pwd/$< > $@

build:
cargo build --release

prove: build
cargo run --release prove $(PROGRAM_PATH) $(PROOF_PATH)

verify: build
cargo run --release verify $(PROOF_PATH)

run_all: build
cargo run --release prove_and_verify $(PROGRAM_PATH)

test: $(COMPILED_CAIRO0_PROGRAMS)
cargo test

test_metal: $(COMPILED_CAIRO0_PROGRAMS)
cargo test -F metal

clippy:
cargo clippy --workspace --all-targets -- -D warnings

benchmarks_sequential: $(COMPILED_CAIRO0_PROGRAMS)
cargo bench

benchmarks_parallel: $(COMPILED_CAIRO0_PROGRAMS)
cargo bench -F parallel --bench criterion_prover
cargo bench -F parallel --bench criterion_verifier

benchmarks_parallel_all: $(COMPILED_CAIRO0_PROGRAMS)
cargo bench -F parallel

build_metal:
cargo b --features metal --release

docker_build_cairo_compiler:
docker build -f cairo_compile.Dockerfile -t cairo .

docker_compile_cairo:
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 --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 --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 --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 --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

clean:
rm -f $(CAIRO0_PROGRAMS_DIR)/*.json
rm -f $(CAIRO0_PROGRAMS_DIR)/*.trace
rm -f $(CAIRO0_PROGRAMS_DIR)/*.memory
49 changes: 15 additions & 34 deletions provers/cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ CLI currently runs with 100 bits of conjecturable security
- [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)
Expand Down Expand Up @@ -73,65 +71,48 @@ To be added:

### 🚀 Prove and verify

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

```bash
make prove PROGRAM_PATH=<compiled_program_path> PROOF_PATH=<output_proof_path>
```

To verify a proof you can use:

```bash
make verify PROOF_PATH=<proof_path>
make compile_and_prove PROGRAM=<program_path> PROOF_PATH=<output_proof_path>
```

For example:

```bash
make prove PROGRAM_PATH=fibonacci.json PROOF_PATH=fibonacci_proof
make verify PROOF_PATH=fibonacci_proof
```

To prove and verify with a single command you can use:

```bash
make run_all PROGRAM_PATH=<proof_path>
make prove PROGRAM_PATH=cairo_programs/cairo0/fibonacci_5.json PROOF_PATH=fibonacci_5.proof
```

### Using Docker compiler for Cairo 0 programs
Notice for compilation either `cairo-lang` or `docker` is required

Build the compiler image with:
If the program is already compiled you can use:

```bash
make docker_build_cairo_compiler
make prove PROGRAM_PATH=<compiled_program_path> PROOF_PATH=<output_proof_path>
```

Then for example, if you have a Cairo program in the project folder, you can use:
For example:

```bash
make docker_compile_and_run_all PROGRAM=program_name.cairo
make prove PROGRAM_PATH=cairo_programs/cairo0/fibonacci_5.json PROOF_PATH=program_proof.proof
```

Or

To verify a proof you can use:
```bash
make docker_compile_and_prove PROGRAM=program_name.cairo PROOF_PATH=proof_path
make verify PROOF_PATH=<proof_path>
```

### Using cairo-compile for Cairo 0 programs

If you have `cairo-lang` installed, you can use it instead of the Dockerfile

Then for example, if you have some Cairo program in the project folder, you can use:
For example:

```bash
make compile_and_run_all PROGRAM=program_name.cairo
make verify PROOF_PATH=fibonacci_5.proof
```

Or
To prove and verify with a single command you can use:

```bash
make compile_and_prove PROGRAM=program_name.cairo PROOF_PATH=proof_path
make run_all PROGRAM_PATH=<proof_path>
```

### Using WASM verifier
Expand Down