|
1 | | -# zkp |
| 1 | +# zkp: a toolkit for Schnorr proofs |
2 | 2 |
|
3 | | -This crate has an experimental zero-knowledge proof compiler |
4 | | -implemented using Rust macros. |
| 3 | +This crate has a toolkit for Schnorr-style zero-knowledge proofs, |
| 4 | +instantiated using the ristretto255 group. |
5 | 5 |
|
6 | | -It provides a DSL resembling Camenisch-Stadler notation for proving |
7 | | -statements about discrete logarithms in the Decaf group on |
8 | | -Curve25519, as implemented in |
9 | | -[`curve25519-dalek`](https://github.com/isislovecruft/curve25519-dalek). |
10 | | -Note that both the Decaf implementation in `curve25519-dalek`, *as |
11 | | -well as this library*, are currently **UNFINISHED, UNREVIEWED, AND |
12 | | -EXPERIMENTAL**. (I haven't actually checked carefully that the |
13 | | -proofs are sound, for instance...) |
| 6 | +It provides two levels of API: |
14 | 7 |
|
15 | | -## Warning |
| 8 | +* a higher-level, declarative API based around the `define_proof` macro, |
| 9 | + which provides an embedded DSL for specifying proof statements in |
| 10 | + Camenisch-Stadler-like notation: |
| 11 | + ``` |
| 12 | + define_proof! { |
| 13 | + vrf_proof, // Name of the module for generated implementation |
| 14 | + "VRF", // Label for the proof statement |
| 15 | + (x), // Secret variables |
| 16 | + (A, G, H), // Public variables unique to each proof |
| 17 | + (B) : // Public variables common between proofs |
| 18 | + A = (x * B), // Statements to prove |
| 19 | + G = (x * H) |
| 20 | + } |
| 21 | + ``` |
| 22 | + This expands into a module containing an implementation of proving, |
| 23 | + verification, and batch verification. Proving uses constant-time |
| 24 | + implementations, and the proofs have a derived implementation of |
| 25 | + (memory-safe) serialization and deserialization via Serde. |
16 | 26 |
|
17 | | -This code has **not** yet received sufficient peer review by other qualified |
18 | | -cryptographers to be considered in any way, shape, or form, safe. |
| 27 | +* a lower-level, imperative API inspired by [Bellman][bellman], which |
| 28 | + provides a constraint system for Schnorr-style statements. This |
| 29 | + allows programmable construction of proof statements at runtime. The |
| 30 | + higher-level `define_proof` macro expands into an invocation of the |
| 31 | + lower-level API. |
| 32 | + The lower-level API is contained in the `toolbox` module. |
19 | 33 |
|
20 | | -**USE AT YOUR OWN RISK** |
| 34 | +# Examples |
21 | 35 |
|
22 | | -## Documentation |
| 36 | +Examples of how to use the API can be found in the library's `tests` |
| 37 | +directory. |
23 | 38 |
|
24 | | -Extensive documentation is available [here](https://docs.rs/zkp). |
| 39 | +Currently, the examples include: |
25 | 40 |
|
26 | | -# Pre-Release TODOs |
| 41 | +* Specification of an "anonymous credential presentation with 10 hidden |
| 42 | + attributes" proof from CMZ'13. Depending on the backend selection, the |
| 43 | + generated implementation is between 20 to 40 times faster than the benchmark |
| 44 | + numbers reported in that paper. |
27 | 45 |
|
28 | | -* don't use any yolocrypto features (i.e. stabilise decaf in curve25519-dalek) |
29 | | -* make sure proofs are sound |
30 | | -* make a CONTRIBUTING.md |
| 46 | +* A transcript-based signature and VRF construction with an auto-generated |
| 47 | + implementation. This includes an example of using the online interactive |
| 48 | + composition [described in the Merlin blog post][merlin_blog] to provide chained |
| 49 | + signatures with a counterparty. |
31 | 50 |
|
32 | | -# Future TODOs |
| 51 | +* An example of using the lower-level constraint system API. |
33 | 52 |
|
34 | | -* ??? |
| 53 | + |
| 54 | +# Use and features |
| 55 | + |
| 56 | +To enable the `define_proof` macro, import the crate like so: |
| 57 | +``` |
| 58 | +#[macro_use] |
| 59 | +extern crate zkp; |
| 60 | +``` |
| 61 | + |
| 62 | +#### Nightly features |
| 63 | + |
| 64 | +The `nightly` feature enables nightly-specific features. It is required |
| 65 | +to build the documentation. |
| 66 | + |
| 67 | +#### Backend selection |
| 68 | + |
| 69 | +`zkp` provides the following pass-through features to select a |
| 70 | +`curve25519-dalek` backend: |
| 71 | + |
| 72 | +* `u32_backend` |
| 73 | +* `u64_backend` |
| 74 | +* `simd_backend` |
| 75 | + |
| 76 | +#### Transcript debugging |
| 77 | + |
| 78 | +The `debug-transcript` feature is for development and testing, and |
| 79 | +prints a log of the data fed into the proof transcript. |
| 80 | + |
| 81 | +#### Autogenerated benchmarks |
| 82 | + |
| 83 | +The `define_proof` macro builds benchmarks for the generated proof |
| 84 | +statements, but because these are generated in the client crate (where |
| 85 | +the macro expansion happens), they need an extra step to be enabled. |
| 86 | + |
| 87 | +**To enable generated benchmarks in your crate, do the following**: |
| 88 | + |
| 89 | +* Add a `bench` feature to your crate's `Cargo.toml`; |
| 90 | +* Add `#[cfg_attr(feature = "bench", feature(test))]` to your crate's |
| 91 | + `lib.rs` or `main.rs`, to enable Rust's nightly-only benchmark |
| 92 | + feature. |
| 93 | + |
| 94 | +# WARNING |
| 95 | + |
| 96 | +**THIS IMPLEMENTATION IS NOT YET READY FOR PRODUCTION USE** |
| 97 | + |
| 98 | +While I expect the 1.0 version to be largely unchanged from the current |
| 99 | +code, for now there are no stability guarantees on the proofs, so they |
| 100 | +should not yet be deployed. |
| 101 | + |
| 102 | +[bellman]: https://github.com/zkcrypto/bellman |
| 103 | +[merlin_blog]: https://medium.com/@hdevalence/merlin-flexible-composable-transcripts-for-zero-knowledge-proofs-28d9fda22d9a |
0 commit comments