Skip to content

0xPolygonZero/plonky2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4e0834d · Jan 30, 2025
Aug 29, 2024
Oct 17, 2024
Aug 29, 2024
Jan 30, 2025
Nov 25, 2024
Jan 30, 2025
Sep 15, 2022
Jan 30, 2025
Nov 25, 2024
Oct 27, 2021
Nov 25, 2024
Mar 14, 2024
Aug 27, 2024
Jan 30, 2025
Jan 30, 2025
Jan 30, 2025
Jan 30, 2025
Oct 23, 2021
Feb 12, 2024
Nov 3, 2022

Plonky2 & more

Discord

This repository was originally for Plonky2, a SNARK implementation based on techniques from PLONK and FRI. It has since expanded to include tools such as Starky, a highly performant STARK implementation.

Documentation

For more details about the Plonky2 argument system, see this writeup.

Polymer Labs has written up a helpful tutorial here!

Examples

A good starting point for how to use Plonky2 for simple applications is the included examples:

  • factorial: Proving knowledge of 100!
  • fibonacci: Proving knowledge of the hundredth Fibonacci number
  • range_check: Proving that a field element is in a given range
  • square_root: Proving knowledge of the square root of a given field element

To run an example, use

cargo run --example <example_name>

Building

Plonky2 requires a recent nightly toolchain, although we plan to transition to stable in the future.

To use a nightly toolchain for Plonky2 by default, you can run

rustup override set nightly

in the Plonky2 directory.

Running

To see recursion performance, one can run this bench, which generates a chain of three recursion proofs:

RUSTFLAGS=-Ctarget-cpu=native cargo run --release --example bench_recursion -- -vv

Jemalloc

Plonky2 prefers the Jemalloc memory allocator due to its superior performance. To use it, include jemallocator = "0.5.0" in your Cargo.toml and add the following lines to your main.rs:

use jemallocator::Jemalloc;

#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

Jemalloc is known to cause crashes when a binary compiled for x86 is run on an Apple silicon-based Mac under Rosetta 2. If you are experiencing crashes on your Apple silicon Mac, run rustc --print target-libdir. The output should contain aarch64-apple-darwin. If the output contains x86_64-apple-darwin, then you are running the Rust toolchain for x86; we recommend switching to the native ARM version.

Documentation

Generate documentation locally:

cargo doc --no-deps --open

Contributing guidelines

See CONTRIBUTING.md.

Licenses

All crates of this monorepo are licensed under either of

at your option.

Security

This code has been audited prior to the v1.0.0 release. The audits reports and findings are available in the audits folder of this repository. An audited codebase isn't necessarily free of bugs and security exploits, hence we recommend care when using plonky2 in production settings.

If you find a security issue in the codebase, please refer to our Security guidelines for private disclosure.

While Plonky2 is configurable, its defaults generally target 100 bits of security. The default FRI configuration targets 100 bits of conjectured security based on the conjecture in ethSTARK.

Plonky2's default hash function is Poseidon, configured with 8 full rounds, 22 partial rounds, a width of 12 field elements (each ~64 bits), and an S-box of x^7. BBLP22 suggests that this configuration may have around 95 bits of security, falling a bit short of our 100 bit target.

Links

  • Polygon Zero's zkEVM, an efficient Type 1 zkEVM built on top of Starky and plonky2
  • System Zero, a zkVM built on top of Starky
  • Waksman, Plonky2 gadgets for permutation checking using Waksman networks
  • Insertion, Plonky2 gadgets for insertion into a list
  • u32, Plonky2 gadgets for u32 arithmetic
  • ECDSA, Plonky2 gadgets for the ECDSA algorithm