You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: use `XofReader` instead of `io::Read` for no_std compatibility
* feat: remove `thiserror` dependency
thiserror is not no_std safe
* feat: move deps std features behind new `std` feature
- add new `std` feature
- add `simd_backend`
- move `colored` dep behind profile feature
* feat: use old rand(v0.7) for cubic example.
since curve25519-dalek (v3) uses old rand(v0.7) we need this.
should upgrade curve25519-dalek to v4 once it out of pre release
* feat: only build bench & profile if std in enabled
* feat: remove rand_core as dependency
* feat(ci): add job to test wasm build
* fix: rollback rand to v7 and update debug test
* fix(ci): Cargo.toml patching
* feat: make clippy happy
* feat: add wasm doc in readme
* feat: readme formatting
* feat: derive `Default` for `ProofVerifyError`
Spartan is a high-speed zero-knowledge proof system, a cryptographic primitive that enables a prover to prove a mathematical statement to a verifier without revealing anything besides the validity of the statement. This repository provides `libspartan,` a Rust library that implements a zero-knowledge succinct non-interactive argument of knowledge (zkSNARK), which is a type of zero-knowledge proof system with short proofs and fast verification times. The details of the Spartan proof system are described in our [paper](https://eprint.iacr.org/2019/550) published at [CRYPTO 2020](https://crypto.iacr.org/2020/). The security of the Spartan variant implemented in this library is based on the discrete logarithm problem in the random oracle model.
7
7
8
8
A simple example application is proving the knowledge of a secret s such that H(s) == d for a public d, where H is a cryptographic hash function (e.g., SHA-256, Keccak). A more complex application is a database-backed cloud service that produces proofs of correct state machine transitions for auditability. See this [paper](https://eprint.iacr.org/2020/758.pdf) for an overview and this [paper](https://eprint.iacr.org/2018/907.pdf) for details.
9
9
10
-
Note that this library has *not* received a security review or audit.
10
+
Note that this library has _not_ received a security review or audit.
11
11
12
12
## Highlights
13
+
13
14
We now highlight Spartan's distinctive features.
14
15
15
-
***No "toxic" waste:** Spartan is a *transparent* zkSNARK and does not require a trusted setup. So, it does not involve any trapdoors that must be kept secret or require a multi-party ceremony to produce public parameters.
16
+
-**No "toxic" waste:** Spartan is a _transparent_ zkSNARK and does not require a trusted setup. So, it does not involve any trapdoors that must be kept secret or require a multi-party ceremony to produce public parameters.
16
17
17
-
***General-purpose:** Spartan produces proofs for arbitrary NP statements. `libspartan` supports NP statements expressed as rank-1 constraint satisfiability (R1CS) instances, a popular language for which there exists efficient transformations and compiler toolchains from high-level programs of interest.
18
+
-**General-purpose:** Spartan produces proofs for arbitrary NP statements. `libspartan` supports NP statements expressed as rank-1 constraint satisfiability (R1CS) instances, a popular language for which there exists efficient transformations and compiler toolchains from high-level programs of interest.
18
19
19
-
***Sub-linear verification costs:** Spartan is the first transparent proof system with sub-linear verification costs for arbitrary NP statements (e.g., R1CS).
20
+
-**Sub-linear verification costs:** Spartan is the first transparent proof system with sub-linear verification costs for arbitrary NP statements (e.g., R1CS).
20
21
21
-
***Standardized security:** Spartan's security relies on the hardness of computing discrete logarithms (a standard cryptographic assumption) in the random oracle model. `libspartan` uses `ristretto255`, a prime-order group abstraction atop `curve25519` (a high-speed elliptic curve). We use [`curve25519-dalek`](https://docs.rs/curve25519-dalek) for arithmetic over `ristretto255`.
22
+
-**Standardized security:** Spartan's security relies on the hardness of computing discrete logarithms (a standard cryptographic assumption) in the random oracle model. `libspartan` uses `ristretto255`, a prime-order group abstraction atop `curve25519` (a high-speed elliptic curve). We use [`curve25519-dalek`](https://docs.rs/curve25519-dalek) for arithmetic over `ristretto255`.
22
23
23
-
***State-of-the-art performance:**
24
-
Among transparent SNARKs, Spartan offers the fastest prover with speedups of 36–152× depending on the baseline, produces proofs that are shorter by 1.2–416×, and incurs the lowest verification times with speedups of 3.6–1326×. The only exception is proof sizes under Bulletproofs, but Bulletproofs incurs slower verification both asymptotically and concretely. When compared to the state-of-the-art zkSNARK with trusted setup, Spartan’s prover is 2× faster for arbitrary R1CS instances and 16× faster for data-parallel workloads.
24
+
-**State-of-the-art performance:**
25
+
Among transparent SNARKs, Spartan offers the fastest prover with speedups of 36–152× depending on the baseline, produces proofs that are shorter by 1.2–416×, and incurs the lowest verification times with speedups of 3.6–1326×. The only exception is proof sizes under Bulletproofs, but Bulletproofs incurs slower verification both asymptotically and concretely. When compared to the state-of-the-art zkSNARK with trusted setup, Spartan’s prover is 2× faster for arbitrary R1CS instances and 16× faster for data-parallel workloads.
25
26
26
27
### Implementation details
27
-
`libspartan` uses [`merlin`](https://docs.rs/merlin/) to automate the Fiat-Shamir transform. We also introduce a new type called `RandomTape` that extends a `Transcript` in `merlin` to allow the prover's internal methods to produce private randomness using its private transcript without having to create `OsRng` objects throughout the code. An object of type `RandomTape` is initialized with a new random seed from `OsRng` for each proof produced by the library.
28
+
29
+
`libspartan` uses [`merlin`](https://docs.rs/merlin/) to automate the Fiat-Shamir transform. We also introduce a new type called `RandomTape` that extends a `Transcript` in `merlin` to allow the prover's internal methods to produce private randomness using its private transcript without having to create `OsRng` objects throughout the code. An object of type `RandomTape` is initialized with a new random seed from `OsRng` for each proof produced by the library.
28
30
29
31
## Examples
32
+
30
33
To import `libspartan` into your Rust project, add the following dependency to `Cargo.toml`:
34
+
31
35
```text
32
36
spartan = "0.7.1"
33
37
```
@@ -36,11 +40,11 @@ The following example shows how to use `libspartan` to create and verify a SNARK
36
40
Some of our public APIs' style is inspired by the underlying crates we use.
37
41
38
42
```rust
39
-
# externcrate libspartan;
40
-
# externcrate merlin;
41
-
# uselibspartan::{Instance, SNARKGens, SNARK};
42
-
# usemerlin::Transcript;
43
-
# fnmain() {
43
+
externcrate libspartan;
44
+
externcrate merlin;
45
+
uselibspartan::{Instance, SNARKGens, SNARK};
46
+
usemerlin::Transcript;
47
+
fnmain() {
44
48
// specify the size of an R1CS instance
45
49
letnum_vars=1024;
46
50
letnum_cons=1024;
@@ -66,16 +70,17 @@ Some of our public APIs' style is inspired by the underlying crates we use.
> NOTE: We enable SIMD instructions in `curve25519-dalek` by default, so if it fails to build remove the "simd_backend" feature argument in `Cargo.toml`.
285
298
286
299
### Supported features
287
-
*`profile`: enables fine-grained profiling information (see below for its use)
300
+
301
+
-`std`: enables std features (enabled by default)
302
+
-`simd_backend`: enables `curve25519-dalek`'s simd feature (enabled by default)
303
+
-`profile`: enables fine-grained profiling information (see below for its use)
304
+
305
+
### WASM Support
306
+
307
+
`libspartan` depends upon `rand::OsRng` (internally uses `getrandom` crate), it has out of box support for `wasm32-wasi`.
308
+
309
+
For the target `wasm32-unknown-unknown` disable default features for spartan
310
+
and add direct dependency on `getrandom` with `wasm-bindgen` feature enabled.
311
+
312
+
```toml
313
+
[dependencies]
314
+
spartan = { version = "0.7", default-features = false }
315
+
# since spartan uses getrandom(rand's OsRng), we need to enable 'wasm-bindgen'
316
+
# feature to make it feed rand seed from js/nodejs env
getrandom = { version = "0.1", features = ["wasm-bindgen"] }
319
+
```
288
320
289
321
## Performance
290
322
291
323
### End-to-end benchmarks
324
+
292
325
`libspartan` includes two benches: `benches/nizk.rs` and `benches/snark.rs`. If you report the performance of Spartan in a research paper, we recommend using these benches for higher accuracy instead of fine-grained profiling (listed below).
293
326
294
327
To run end-to-end benchmarks:
295
-
```text
328
+
329
+
```text
296
330
RUSTFLAGS="-C target_cpu=native" cargo bench
297
331
```
298
332
299
333
### Fine-grained profiling
334
+
300
335
Build `libspartan` with `profile` feature enabled. It creates two profilers: `./target/release/snark` and `./target/release/nizk`.
301
336
302
337
These profilers report performance as depicted below (for varying R1CS instance sizes). The reported
303
338
performance is from running the profilers on a Microsoft Surface Laptop 3 on a single CPU core of Intel Core i7-1065G7 running Ubuntu 20.04 (atop WSL2 on Windows 10).
304
339
See Section 9 in our [paper](https://eprint.iacr.org/2019/550) to see how this compares with other zkSNARKs in the literature.
0 commit comments