2022-08-14 21:52:10 -07:00
# Plonky2 & more
2021-04-06 13:14:59 -07:00
2022-08-14 21:52:10 -07:00
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.
2022-01-09 09:52:19 -08:00
2024-12-06 14:26:53 +01:00
## Codex fork
2024-12-09 18:46:16 +01:00
This repo is Codex's fork of [Polygon Zero's Plonky2 repository ](https://github.com/0xPolygonZero/plonky2/ ).
2024-12-06 14:26:53 +01:00
For now at least, our modifications are in the [`codex` branch ](https://github.com/codex-storage/plonky2/tree/codex ).
These include:
- [x] option to turn off randomizing unused wires
- [x] option to export the witness and related metadata
- [x] simple web-based tool to visualize the witness
- [ ] tooling to analyze circuits
2024-12-09 18:46:16 +01:00
- [ ] detailed documentation of how Plonky2 actually works
- [ ] maybe some additional gates / gadgets
2024-12-06 14:26:53 +01:00
- [ ] support for Poseidon2-Goldilocks hash
- [ ] support for Poseidon2-BN254 hash (for more efficient BN254 wrapper)
2024-12-09 18:46:16 +01:00
- [ ] support for Monolith hash (ideally also for recursion)
- [ ] BN254 wrapper circuit (Groth16 and/or Plonk-KZG)
2022-01-09 09:52:19 -08:00
## Documentation
2022-05-12 22:47:11 +08:00
For more details about the Plonky2 argument system, see this [writeup ](plonky2/plonky2.pdf ).
2021-05-05 19:24:04 -07:00
2023-04-05 13:00:58 -07:00
Polymer Labs has written up a helpful tutorial [here ](https://polymerlabs.medium.com/a-tutorial-on-writing-zk-proofs-with-plonky2-part-i-be5812f6b798 )!
## Examples
2023-04-05 13:58:39 -07:00
A good starting point for how to use Plonky2 for simple applications is the included examples:
2023-04-05 13:00:58 -07:00
* [`factorial` ](plonky2/examples/factorial.rs ): Proving knowledge of 100!
* [`fibonacci` ](plonky2/examples/fibonacci.rs ): Proving knowledge of the hundredth Fibonacci number
2023-04-06 09:23:49 -07:00
* [`range_check` ](plonky2/examples/range_check.rs ): Proving that a field element is in a given range
2023-04-05 13:00:58 -07:00
* [`square_root` ](plonky2/examples/square_root.rs ): Proving knowledge of the square root of a given field element
2024-12-09 18:46:16 +01:00
* [`lookup` ](plonky2/examples/lookup_example.rs ): Proving that a few members of an arithmetic progression are all primes
2023-04-05 13:00:58 -07:00
2023-04-06 09:23:49 -07:00
To run an example, use
```sh
cargo run --example < example_name >
```
2021-05-05 19:24:04 -07:00
2022-01-11 19:36:32 -08:00
## 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.
2021-05-05 19:24:04 -07:00
## Running
2022-04-15 04:23:43 +02:00
To see recursion performance, one can run this bench, which generates a chain of three recursion proofs:
2021-05-05 19:24:04 -07:00
```sh
2022-04-15 04:23:43 +02:00
RUSTFLAGS=-Ctarget-cpu=native cargo run --release --example bench_recursion -- -vv
2021-05-05 19:24:04 -07:00
```
2021-04-08 09:37:08 -07:00
2022-01-24 13:35:26 -08:00
## Jemalloc
2023-07-13 12:10:54 +08:00
Plonky2 prefers the [Jemalloc ](http://jemalloc.net ) memory allocator due to its superior performance. To use it, include `jemallocator = "0.5.0"` in your `Cargo.toml` and add the following lines
2022-05-03 13:16:53 -07:00
to your `main.rs` :
```rust
use jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
```
2022-01-24 13:35:26 -08:00
Jemalloc is known to cause crashes when a binary compiled for x86 is run on an Apple silicon-based Mac under [Rosetta 2 ](https://support.apple.com/en-us/HT211861 ). 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.
2024-08-29 14:22:37 +02:00
## Documentation
Generate documentation locally:
```sh
cargo doc --no-deps --open
```
2024-03-14 20:01:23 +09:00
## Contributing guidelines
2022-01-24 13:35:26 -08:00
2024-03-14 20:01:23 +09:00
See [CONTRIBUTING.md ](./CONTRIBUTING.md ).
2023-08-16 00:45:01 +10:00
2022-08-14 21:52:10 -07:00
## Licenses
2022-01-03 10:00:15 -08:00
2024-02-19 07:35:51 -05:00
All crates of this monorepo are licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE ](LICENSE-APACHE ) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT ](LICENSE-MIT ) or http://opensource.org/licenses/MIT)
at your option.
2022-01-03 10:00:15 -08:00
2022-11-08 12:03:58 -08:00
## Security
2021-04-08 09:37:08 -07:00
2022-01-09 09:52:19 -08:00
This code has not yet been audited, and should not be used in any production systems.
2021-04-08 09:37:08 -07:00
2022-11-08 12:03:58 -08:00
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 ](https://eprint.iacr.org/2021/582 ).
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 ](https://tosc.iacr.org/index.php/ToSC/article/view/9850 ) suggests that this configuration may have around 95 bits of security, falling a bit short of our 100 bit target.
2023-02-25 16:55:19 -08:00
## Links
2024-02-17 11:04:07 -05:00
#### Actively maintained
- [Polygon Zero's zkEVM ](https://github.com/0xPolygonZero/zk_evm ), an efficient Type 1 zkEVM built on top of Starky and plonky2
#### No longer maintained
- [System Zero ](https://github.com/0xPolygonZero/system-zero ), a zkVM built on top of Starky
- [Waksman ](https://github.com/0xPolygonZero/plonky2-waksman ), Plonky2 gadgets for permutation checking using Waksman networks
- [Insertion ](https://github.com/0xPolygonZero/plonky2-insertion ), Plonky2 gadgets for insertion into a list
- [u32 ](https://github.com/0xPolygonZero/plonky2-u32 ), Plonky2 gadgets for u32 arithmetic
- [ECDSA ](https://github.com/0xPolygonZero/plonky2-ecdsa ), Plonky2 gadgets for the ECDSA algorithm