Skip to content

Commit

Permalink
migrate cli to extern crate
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Oct 9, 2023
1 parent bc43d72 commit 812d0aa
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 58 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions provers/cairo-prover-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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}
22 changes: 22 additions & 0 deletions provers/cairo-prover-cli/Makefile
Original file line number Diff line number Diff line change
@@ -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)
66 changes: 66 additions & 0 deletions provers/cairo-prover-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div align="center">

# Lambdaworks Cairo Platinum Prover CLI

</div>

## ⚠️ 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=<compiled_program_path> PROOF_PATH=<output_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=<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=<proof_path>
```

For example:

```bash
make run_all PROOF_PATH=fibonacci_5.proof
```
11 changes: 11 additions & 0 deletions provers/cairo-prover-cli/cairo_compile.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
4 changes: 0 additions & 4 deletions provers/cairo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
9 changes: 0 additions & 9 deletions provers/cairo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 1 addition & 44 deletions provers/cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<program_path> PROOF_PATH=<output_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=<compiled_program_path> PROOF_PATH=<output_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=<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=<proof_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`
Expand Down

0 comments on commit 812d0aa

Please sign in to comment.