From 812d0aa383ed203b7b814428b045bf32f9356989 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 9 Oct 2023 15:16:05 -0300 Subject: [PATCH] migrate cli to extern crate --- Cargo.toml | 3 +- README.md | 1 + provers/cairo-prover-cli/Cargo.toml | 15 +++++ provers/cairo-prover-cli/Makefile | 22 +++++++ provers/cairo-prover-cli/README.md | 66 +++++++++++++++++++ .../cairo-prover-cli/cairo_compile.Dockerfile | 11 ++++ .../{cairo => cairo-prover-cli}/src/main.rs | 0 provers/cairo/Cargo.toml | 4 -- provers/cairo/Makefile | 9 --- provers/cairo/README.md | 45 +------------ 10 files changed, 118 insertions(+), 58 deletions(-) create mode 100644 provers/cairo-prover-cli/Cargo.toml create mode 100644 provers/cairo-prover-cli/Makefile create mode 100644 provers/cairo-prover-cli/README.md create mode 100644 provers/cairo-prover-cli/cairo_compile.Dockerfile rename provers/{cairo => cairo-prover-cli}/src/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index c88c5cff0..59fc41ff6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["math", "crypto", "gpu", "benches", "provers/plonk", "provers/stark", "provers/cairo"] +members = ["math", "crypto", "gpu", "benches", "provers/plonk", "provers/stark", "provers/cairo", "provers/cairo-prover-cli"] exclude = ["ensure-no_std"] resolver = "2" @@ -15,6 +15,7 @@ lambdaworks-crypto = { path = "./crypto", version = "0.2.0" } lambdaworks-gpu = { path = "./gpu", version = "0.2.0" } lambdaworks-math = { path = "./math", version = "0.2.0" } stark-platinum-prover = { path = "./provers/stark", version = "0.2.0" } +cairo-platinum-prover = { path = "./provers/cairo", version = "0.2.0" } [profile.bench] lto = true diff --git a/README.md b/README.md index a8b667f9d..c3dbb5b98 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Right now Plonk prover is in this repo, you can find the others here: - [Math](https://github.com/lambdaclass/lambdaworks/tree/main/math) - [Crypto primitives](https://github.com/lambdaclass/lambdaworks/tree/main/crypto) - [Plonk Prover](https://github.com/lambdaclass/lambdaworks/tree/main/provers/plonk) +- [Cairo Prover CLI](https://github.com/lambdaclass/lambdaworks/tree/main/provers/cairo-prover-cli) ### Crypto - [Elliptic curves](https://github.com/lambdaclass/lambdaworks/tree/main/math/src/elliptic_curve) diff --git a/provers/cairo-prover-cli/Cargo.toml b/provers/cairo-prover-cli/Cargo.toml new file mode 100644 index 000000000..39b3f9044 --- /dev/null +++ b/provers/cairo-prover-cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cairo-platinum-prover-cli" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true + +[[bin]] +name = "cairo-platinum-prover-cli" +path = "src/main.rs" + +[dependencies] +lambdaworks-math = { workspace = true , features = ["lambdaworks-serde"] } +stark-platinum-prover = { workspace = true, features = ["wasm"] } +cairo-platinum-prover = { workspace = true} \ No newline at end of file diff --git a/provers/cairo-prover-cli/Makefile b/provers/cairo-prover-cli/Makefile new file mode 100644 index 000000000..b3fdf9cf0 --- /dev/null +++ b/provers/cairo-prover-cli/Makefile @@ -0,0 +1,22 @@ +.PHONY: test coverage clippy clean + +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) + +clippy: + cargo clippy --workspace --all-targets -- -D warnings + +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) diff --git a/provers/cairo-prover-cli/README.md b/provers/cairo-prover-cli/README.md new file mode 100644 index 000000000..a42aef827 --- /dev/null +++ b/provers/cairo-prover-cli/README.md @@ -0,0 +1,66 @@ +
+ +# Lambdaworks Cairo Platinum Prover CLI + +
+ +## ⚠️ Disclaimer + +CLI currently runs with 100 bits of conjecturable security + +## [Cairo Platinum Prover Docs]([lambdaclass.github.io/lambdaworks/](https://github.com/lambdaclass/lambdaworks/blob/main/provers/cairo/README.md)) + +## Requirements + +- Cargo 1.69+ + +## Usage + +Note: to use cairo compiler with docker, build the image by running: + +```bash + make docker_build_cairo_compiler +``` + +### 🚀 Prove and verify +Sample Cairo 0 programs can be found [here](https://github.com/lambdaclass/lambdaworks/tree/main/provers/cairo/cairo_programs/cairo0) (need to be compiled first). + +Notice for compilation either `cairo-lang` or `docker` is required + +#### Usage: + +To create prove for a program you can use: + +```bash +make prove PROGRAM_PATH= PROOF_PATH= +``` + +For example: + +```bash +make prove PROGRAM_PATH=cairo_programs/cairo0/fibonacci_5.json PROOF_PATH=program_proof.proof +``` + +To verify a proof you can use: + +```bash +make verify PROOF_PATH= +``` + +For example: + +```bash +make verify PROOF_PATH=fibonacci_5.proof +``` + +To prove and verify with a single command you can use: + +```bash +make run_all PROOF_PATH= +``` + +For example: + +```bash +make run_all PROOF_PATH=fibonacci_5.proof +``` \ No newline at end of file diff --git a/provers/cairo-prover-cli/cairo_compile.Dockerfile b/provers/cairo-prover-cli/cairo_compile.Dockerfile new file mode 100644 index 000000000..369f6db84 --- /dev/null +++ b/provers/cairo-prover-cli/cairo_compile.Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.9-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y --no-install-recommends g++ libgmp3-dev + +COPY requirements.txt / + +RUN pip install -r /requirements.txt + +ENTRYPOINT ["cairo-compile"] diff --git a/provers/cairo/src/main.rs b/provers/cairo-prover-cli/src/main.rs similarity index 100% rename from provers/cairo/src/main.rs rename to provers/cairo-prover-cli/src/main.rs diff --git a/provers/cairo/Cargo.toml b/provers/cairo/Cargo.toml index b0518ca9a..8b1679300 100644 --- a/provers/cairo/Cargo.toml +++ b/provers/cairo/Cargo.toml @@ -6,10 +6,6 @@ version.workspace = true edition.workspace = true license.workspace = true -[[bin]] -name = "cairo-platinum-prover" -path = "src/main.rs" - [lib] crate-type = ["cdylib", "rlib"] diff --git a/provers/cairo/Makefile b/provers/cairo/Makefile index 37bcb4484..640ab230b 100644 --- a/provers/cairo/Makefile +++ b/provers/cairo/Makefile @@ -18,15 +18,6 @@ $(CAIRO0_PROGRAMS_DIR)/%.json: $(CAIRO0_PROGRAMS_DIR)/%.cairo 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 diff --git a/provers/cairo/README.md b/provers/cairo/README.md index 3d4a3fc0c..2553028b3 100644 --- a/provers/cairo/README.md +++ b/provers/cairo/README.md @@ -71,50 +71,7 @@ To be added: ### 🚀 Prove and verify -To compile and prove Cairo 0 programs without arguments you can use: - -```bash - make compile_and_prove PROGRAM= PROOF_PATH= -``` - -For example: - -```bash - make prove PROGRAM_PATH=cairo_programs/cairo0/fibonacci_5.json PROOF_PATH=fibonacci_5.proof -``` - -Notice for compilation either `cairo-lang` or `docker` is required - -If the program is already compiled you can use: - -```bash -make prove PROGRAM_PATH= PROOF_PATH= -``` - -For example: - -```bash -make prove PROGRAM_PATH=cairo_programs/cairo0/fibonacci_5.json PROOF_PATH=program_proof.proof -``` - -To verify a proof you can use: - -```bash -make verify PROOF_PATH= -``` - -For example: - -```bash -make verify PROOF_PATH=fibonacci_5.proof -``` - -To prove and verify with a single command you can use: - -```bash -make run_all PROGRAM_PATH= -``` - +To prove and verify a program through the CLI, refer to the [CLI documentation](https://lambdaclass.github.io/lambdaworks/tree/main/provers/cairo-prover-cli/README.md). ### Using WASM verifier To use the verifier in WASM, generate a npm package using `wasm-pack`