PolyhedraZK / Expander

Expander, an open-source GKR prover designed for scaling large-scale parallel computing.
https://expander.polyhedra.network
GNU Affero General Public License v3.0
76 stars 26 forks source link

Expander

Expander

Paper | Benchmarks | Your Code Compiler | Telegram Group

Expander is a proof generation backend for Polyhedra Network. It aims to support fast proof generation.

This is the rust version of the "core" repo.

For more technical introduction, visit our markdown files here.

And here for an example on how to use the gkr lib.

This is a core repo for our prover, to write circuits on our prover, please visit our compiler

Developer helper

We understand that the product is currently in development and may not be very user-friendly yet. We encourage developers to join our Telegram chat group for Q&A: https://t.me/+XEdEEknIdaI0YjEx

Additionally, please take a look at our circuit compiler: https://github.com/PolyhedraZK/ExpanderCompilerCollection

This compiler is your entry point for using our prover; the repository you have is primarily the core executor, not the developer frontend. Our product pipeline is as follows:

Your circuit code -> Expander Compiler -> circuit.txt & witness.txt -> Expander-rs -> proof

Please note that the witness generation process is not yet optimal, and we are actively working on improving it.

AVX

We use AVX2 by default. On an x86 or a mac, you can simply do

RUSTFLAGS="-C target-cpu=native" cargo test --release --workspace

For some platforms, if you do not indicate target-cpu=native it may simulate avx2 instructions, rather than use it directly, and this will cause performance decrease.

Our code also supports avx512. This is not turned on by default. To use avx512

RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f" cargo test --release --workspace

Environment Setup

Before executing setup, please make sure you read through the system requirements, and make sure your CPU is in the list.

cargo run --bin=dev-setup --release

Benchmarks

Make sure you include RUSTFLAGS="-C target-cpu=native" to allow platform specific accelerations.

Command template:

RUSTFLAGS="-C target-cpu=native" cargo run --release --bin gkr -- -f [fr|m31ext3] -t [#threads] -s [keccak|poseidon]

Concretely if you are running on a 16 physical core CPU for Bn256 scalar field:

RUSTFLAGS="-C target-cpu=native" cargo run --release --bin gkr -- -f fr -t 16

Correctness test

Here we provide a test case for end-to-end proof generation and verification. To check the correctness, run the follow standard Rust test command:

RUSTFLAGS="-C target-cpu=native" cargo test --release -- --nocapture

CLI

Usage:

RUSTFLAGS="-C target-cpu=native" cargo run --bin expander-exec --release -- prove <input:circuit_file> <input:witness_file> <output:proof>
RUSTFLAGS="-C target-cpu=native" cargo run --bin expander-exec --release -- verify <input:circuit_file> <input:witness_file> <input:proof>
RUSTFLAGS="-C target-cpu=native" cargo run --bin expander-exec --release -- serve <input:circuit_file> <input:ip> <input:port>

Example:

RUSTFLAGS="-C target-cpu=native" mpiexec -n 1 cargo run --bin expander-exec --release -- prove ./data/circuit_m31.txt ./data/witness_m31.txt ./data/out_m31.bin
RUSTFLAGS="-C target-cpu=native" mpiexec -n 1 cargo run --bin expander-exec --release -- verify ./data/circuit_m31.txt ./data/witness_m31.txt ./data/out_m31.bin
RUSTFLAGS="-C target-cpu=native" mpiexec -n 1 cargo run --bin expander-exec --release -- serve ./data/circuit_m31.txt 127.0.0.1 3030

To test the service started by expander-exec serve, you can use the following command:

python ./scripts/test_http.py  # need "requests" package

How to contribute?

Thank you for your interest in contributing to our project! We seek contributors with a robust background in cryptography and programming, aiming to improve and expand the capabilities of our proof generation system.

Contribution Guidelines:

Pull Requests

We welcome your pull requests (PRs) and ask that you follow these guidelines to facilitate the review process:

Review Process

Each pull request will undergo a review by one or more core contributors. We may ask for changes to better align with the project's goals and standards. Once approved, a maintainer will merge the PR.

We value your contributions greatly and are excited to see what you bring to this project. Let’s build something great together!

Acknowledgements

We would like to thank the following projects and individuals:

  1. Gnark: for their exceptional frontend circuit language.
  2. Plonky2&3: for their inspiring work on Merseene prime AVX and ARM-Neon assembly implementation.
  3. Justin Thaler: for pointing out the soundness issue of using repetition.
  4. Stwo: for inspiring us to make the benchmark page.
  5. Intel: for their detailed implementation of GF(2^128) field multiplication.