plonky2/README.md

84 lines
3.6 KiB
Markdown
Raw Normal View History

2022-08-14 21:52:10 -07:00
# Plonky2 & more
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
## Documentation
For more details about the Plonky2 argument system, see this [writeup](plonky2/plonky2.pdf).
2021-05-05 19:24:04 -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:
* [`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
* [`square_root`](plonky2/examples/square_root.rs): Proving knowledge of the square root of a given field element
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
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
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
Plonky2 prefers the [Jemalloc](http://jemalloc.net) memory allocator due to its superior performance. To use it, include `jemallocator = "0.5.0"` in`Cargo.toml`and add the following lines
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.
2022-08-14 21:52:10 -07:00
## Licenses
2022-01-03 10:00:15 -08:00
2022-08-14 21:52:10 -07:00
As this is a monorepo, see the individual crates within for license information.
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
- [System Zero](https://github.com/mir-protocol/system-zero), a zkVM built on top of Starky (no longer maintained)
2023-03-03 16:11:05 -08:00
- [Waksman](https://github.com/mir-protocol/plonky2-waksman), Plonky2 gadgets for permutation checking using Waksman networks (no longer maintained)
- [Insertion](https://github.com/mir-protocol/plonky2-insertion), Plonky2 gadgets for insertion into a list (no longer maintained)
- [u32](https://github.com/mir-protocol/plonky2-u32), Plonky2 gadgets for u32 arithmetic (no longer actively maintained)
2023-03-03 16:12:40 -08:00
- [ECDSA](https://github.com/mir-protocol/plonky2-ecdsa), Plonky2 gadgets for the ECDSA algorithm (no longer actively maintained)