Skip to content

Commit

Permalink
Merge branch 'add_rescue_prime' of https://github.com/lambdaclass/lam…
Browse files Browse the repository at this point in the history
…bdaworks into add_rescue_prime
  • Loading branch information
jotabulacios committed Oct 16, 2024
2 parents cabe504 + 37417c2 commit 29e0e08
Show file tree
Hide file tree
Showing 111 changed files with 2,695 additions and 10,879 deletions.
33 changes: 3 additions & 30 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- name: Run cargo check
run: cargo check

- name: Run cargo check cli and stark instruments
- name: Run cargo check and stark instruments
run: |
cargo check --features cli,instruments
cargo check --features instruments
- name: Run cargo check cli, stark instruments and parallel
run: |
cargo check --features cli,instruments,parallel
cargo check --features instruments,parallel
- name: Run cargo check for math with no-std
run: cargo check --package lambdaworks-math --no-default-features
Expand Down Expand Up @@ -104,15 +104,6 @@ jobs:
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2

- name: Python3 build
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"

- name: Install cairo-lang toolchain and dependencies
run: pip install -r provers/cairo/requirements.txt

- name: Install testing tools
uses: taiki-e/install-action@v2
with:
Expand Down Expand Up @@ -171,12 +162,6 @@ jobs:
- name: Install wasm-pack tools for testing
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Run wasm-pack tests in firefox
run: cd provers/cairo && wasm-pack test --release --firefox --headless -- --features wasm

- name: Run wasm-pack tests in chrome
run: cd provers/cairo && wasm-pack test --release --chrome --headless -- --features wasm

test_macos:
name: Test (macOS, Apple sillicon)
runs-on: macos-latest
Expand All @@ -196,18 +181,6 @@ jobs:
toolchain: stable
components: clippy

- name: Python3 build
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"

- name: Install cairo-lang toolchain and dependencies
env:
CFLAGS: "-I/opt/homebrew/opt/gmp/include"
LDFLAGS: "-L/opt/homebrew/opt/gmp/lib"
run: pip install -r provers/cairo/requirements.txt

- name: Run clippy
run: make clippy-metal

Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/criterion_benchs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ jobs:
run: |
brew install gcc
brew install gmp
- name: Python3 build
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Install cairo-lang toolchain and dependencies
env:
CFLAGS: "-I/opt/homebrew/opt/gmp/include"
LDFLAGS: "-L/opt/homebrew/opt/gmp/lib"
run: pip install -r provers/cairo/requirements.txt
- name: Run benchmark
run: |
cargo bench -F metal --no-fail-fast --bench "criterion_metal" \
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]

members = ["math", "crypto", "gpu", "benches", "provers/plonk", "provers/stark", "provers/cairo", "provers/groth16", "provers/groth16/arkworks-adapter", "provers/groth16/circom-adapter", "examples/merkle-tree-cli", "examples/prove-miden", "provers/winterfell_adapter", "examples/shamir_secret_sharing","examples/pinocchio", "examples/prove-verify-circom", "provers/cairo/ffi", "examples/baby-snark"]
members = ["math", "crypto", "gpu", "benches", "provers/plonk", "provers/stark", "provers/groth16", "provers/groth16/arkworks-adapter", "provers/groth16/circom-adapter", "examples/merkle-tree-cli", "examples/prove-miden", "provers/winterfell_adapter", "examples/shamir_secret_sharing","examples/pinocchio", "examples/prove-verify-circom", "examples/baby-snark"]
exclude = ["ensure-no_std"]
resolver = "2"

Expand All @@ -16,7 +16,6 @@ lambdaworks-crypto = { path = "./crypto", version = "0.10.0", default-features =
lambdaworks-gpu = { path = "./gpu", version = "0.10.0" }
lambdaworks-math = { path = "./math", version = "0.10.0", default-features = false }
stark-platinum-prover = { path = "./provers/stark" }
cairo-platinum-prover = { path = "./provers/cairo" }
lambdaworks-winterfell-adapter = { path = "./provers/winterfell_adapter"}
lambdaworks-groth16 = { path = "./provers/groth16" }
lambdaworks-circom-adapter = { path = "./provers/groth16/circom-adapter" }
Expand Down
26 changes: 3 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@ FUZZ_DIR = fuzz/no_gpu_fuzz

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

CAIRO0_PROGRAMS_DIR=provers/cairo/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/$< > $@

test: $(COMPILED_CAIRO0_PROGRAMS)
test:
cargo test

clippy:
cargo clippy --workspace --all-targets -- -D warnings
cargo clippy --workspace --all-targets --features wasm -- -D warnings
cargo clippy --workspace --all-targets --features cli -- -D warnings
cargo clippy --workspace --all-targets --features parallel -- -D warnings
cargo clippy --tests

Expand All @@ -47,7 +33,7 @@ benchmark:
flamegraph_stark:
CARGO_PROFILE_BENCH_DEBUG=true cargo flamegraph --root --bench stark_benchmarks -- --bench

coverage: $(COMPILED_CAIRO0_PROGRAMS)
coverage:
cargo llvm-cov nextest --lcov --output-path lcov.info

METAL_DIR = math/src/gpu/metal
Expand All @@ -57,7 +43,7 @@ build-metal:
clippy-metal:
cargo clippy --workspace --all-targets -F metal -- -D warnings

test-metal: $(COMPILED_CAIRO0_PROGRAMS)
test-metal:
cargo test -F metal

CUDA_DIR = math/src/gpu/cuda/shaders
Expand Down Expand Up @@ -91,9 +77,3 @@ run-metal-fuzzer:
run-cuda-fuzzer:
cd fuzz/cuda_fuzz
cargo hfuzz run $(CUDAFUZZER)

build_wasm:
cd provers/cairo && wasm-pack build --release --target=web -- --features wasm

test_wasm_with_firefox:
cd provers/cairo && wasm-pack test --release --firefox --headless -- --features wasm
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ This library provides efficient implementation of cryptographic primitives used

</div>

## Examples - mini apps

Below is a list of examples to understand lambdaworks and learn what you can build with the tools provided.

- [Merkle Tree CLI](./examples/merkle-tree-cli/)
- [Proving Miden](./examples/prove-miden/)
- [Shamir's secret sharing](./examples/shamir_secret_sharing/)
- [BabySNARK](./examples/baby-snark/)
- [Pinocchio](./examples/pinocchio/)
- [Using Circom with lambdaworks's Groth16](./provers/groth16/circom-adapter/src/README.md)

- You can use Circom to generate circuits and use lambdaworks's capabilities to prove the execution with [Groth16](./provers/groth16/README.md).
- You can use the [Stark prover](./provers/stark/src/) to define an algebraic intermediate representation (AIR) and prove the execution of a program

## Why we built lambdaworks

Zero-Knowledge and Validity Proofs have gained a lot of attention over the last few years. We strongly believe in this potential and that is why we decided to start working in this challenging ecosystem, where math, cryptography and distributed systems meet. The main barrier in the beginning was not the cryptography or math but the lack of good libraries which are performant and developer friendly. There are some exceptions, though, like gnark or halo2. Some have nice APIs and are easy to work with, but they are not written in Rust, and some are written in Rust but have poor programming and engineering practices. Most of them don't have support for CUDA, Metal and WebGPU or distributed FFT calculation using schedulers like Dask.
Expand All @@ -29,7 +43,6 @@ So, we decided to build our library, focusing on performance, with clear documen
- [Crypto primitives](https://github.com/lambdaclass/lambdaworks/tree/main/crypto)
- [STARK Prover](https://github.com/lambdaclass/lambdaworks/tree/main/provers/stark)
- [Plonk Prover](https://github.com/lambdaclass/lambdaworks/tree/main/provers/plonk)
- [Cairo Prover](https://github.com/lambdaclass/lambdaworks/tree/main/provers/cairo)
- [Groth 16](https://github.com/lambdaclass/lambdaworks/tree/main/provers/groth16)

### Crypto
Expand All @@ -42,14 +55,6 @@ Most of math and crypto crates supports no-std without allocation with `no-defau

Both Math and Crypto support wasm with target `wasm32-unknown-unknown`. To see an example of how to use this to deploy a verifier in a browser, check the Cairo Prover wasm-pack verifier.

## Examples - mini apps

- [Merkle Tree CLI](https://github.com/lambdaclass/lambdaworks/tree/main/examples/merkle-tree-cli)
- [Proving Miden](https://github.com/lambdaclass/lambdaworks/tree/main/examples/prove-miden)
- [Shamir's secret sharing](https://github.com/lambdaclass/lambdaworks/tree/main/examples/shamir_secret_sharing)
- [BabySNARK](https://github.com/lambdaclass/lambdaworks/tree/main/examples/baby-snark)
- [Pinocchio](https://github.com/lambdaclass/lambdaworks/tree/main/examples/pinocchio)

## Exercises and Challenges

- [lambdaworks exercises and challenges](https://github.com/lambdaclass/lambdaworks_exercises/tree/main)
Expand Down Expand Up @@ -83,9 +88,10 @@ List of symbols:
| Mersenne 31 | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| Baby Bear | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| MiniGoldilocks | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :x: |
| Binary fields | :x: | :x: | :x: | :x: | :x: |
| **ZK friendly Hash function** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| Poseidon | 🏗️ | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| Pedersen | 🏗️ | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| Poseidon | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| Pedersen | 🏗️ | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| Rescue Prime XLIX | :x: | :x: | :x: | :x: | :x: |
| **Elliptic Curves** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| BLS12-381 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Expand All @@ -99,24 +105,16 @@ List of symbols:
| secq256r1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| **STARKs** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| STARK Prover | :heavy_check_mark: | :x: | :x: | :x: | :x: |
| CAIRO Prover | 🏗️ | :x: | :x: | :x: | :x: |
| Circle STARKs | :x: | :x: | :x: | :x: | :x: |
| **SNARKs** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| Groth16 | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| Plonk | 🏗️ | :heavy_check_mark: | ✔️ | :heavy_check_mark: | :x: |
| Spartan | :x: | :heavy_check_mark: | :x: | :x: | :x: |
| Marlin | :x: | :heavy_check_mark: | :x: | :x: | :x: |
| GKR | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
| **Polynomial Commitment Schemes** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| KZG10 | :heavy_check_mark: | ✔️ | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| FRI | 🏗️ | :x: | :x: | :heavy_check_mark: | :x: |
| IPA | 🏗️ | ✔️ | :heavy_check_mark: | :x: | :x: |
| Brakedown | :x: | :x: | :x: | :x: | :x: |
| Basefold | :x: | :x: | :x: | :x: | :x: |
| **Folding Schemes** | **Lambdaworks** | **Arkworks** | **Halo2** | **gnark** | **Constantine** |
| Nova | :x: | :heavy_check_mark: | :x: | :x: | :x: |
| Supernova | :x: | :x: | :x: | :x: | :x: |
| Protostar | :x: | :x: | :x: | :x: | :x: |
| Protogalaxy | :x: | :heavy_check_mark: | :x: | :x: | :x: |
| Binius | :x: | :x: | :x: | :x: | :x: |
| Circle FRI | :x: | :x: | :x: | :x: | :x: |

Additionally, provers are compatible with the following frontends and VMs:

Expand All @@ -129,7 +127,6 @@ Additionally, provers are compatible with the following frontends and VMs:
| Plonk | Noir | :x: |
| Stark | Winterfell | :heavy_check_mark: |
| Stark | Miden | :heavy_check_mark: |
| Stark | Cairo | :heavy_check_mark: |

This can be used in a multi prover setting for extra security, or as a standalone to be used with Rust.

Expand Down
Binary file removed bootcamp/0_groth_16.jpg
Binary file not shown.
Binary file removed bootcamp/0_snarks_starks.jpg
Binary file not shown.
Binary file removed bootcamp/0_starks_constraints.jpg
Binary file not shown.
Binary file removed bootcamp/0_starks_general.jpg
Binary file not shown.
Binary file removed bootcamp/0_starks_proof.jpg
Binary file not shown.
Loading

0 comments on commit 29e0e08

Please sign in to comment.