Skip to content

Commit 95b9ad3

Browse files
committed
initial commit
1 parent be426e7 commit 95b9ad3

33 files changed

+8986
-14
lines changed

.github/workflows/rust.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Install
17+
run: rustup default nightly
18+
- name: Build
19+
run: cargo build --verbose
20+
- name: Run tests
21+
run: cargo test --verbose

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7+
Cargo.lock
8+
9+
# These are backup files generated by rustfmt
10+
**/*.rs.bk
11+
12+
*.txt

CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This project welcomes contributions and suggestions. Most contributions require you to
2+
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
3+
and actually do, grant us the rights to use your contribution. For details, visit
4+
https://cla.microsoft.com.
5+
6+
When you submit a pull request, a CLA-bot will automatically determine whether you need
7+
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
8+
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
9+
10+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
11+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
12+
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

Cargo.toml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[package]
2+
name = "spartan"
3+
version = "0.1.0"
4+
authors = ["Srinath Setty <srinath@microsoft.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
curve25519-dalek = { version = "2", features = ["serde"]}
9+
merlin = "2.0.0"
10+
rand = "0.7.3"
11+
digest = "0.8.1"
12+
sha3 = "0.8.2"
13+
byteorder = "1.3.4"
14+
rayon = "1.3.0"
15+
serde = { version = "1.0.106", features = ["derive"] }
16+
bincode = "1.2.1"
17+
subtle = { version = "^2.2.2", default-features = false }
18+
rand_core = { version = "0.5", default-features = false }
19+
zeroize = { version = "1", default-features = false }
20+
itertools = "0.9.0"
21+
colored = "1.9.3"
22+
flate2 = "1.0.14"
23+
24+
[dev-dependencies]
25+
criterion = "0.3.1"
26+
27+
[lib]
28+
name = "libspartan"
29+
path = "src/lib.rs"
30+
31+
[[bin]]
32+
name = "profiler"
33+
path = "src/profiler.rs"
34+
35+
[[bench]]
36+
name = "commitments"
37+
harness = false
38+
39+
[[bench]]
40+
name = "dotproduct"
41+
harness = false
42+
43+
[[bench]]
44+
name = "polycommit"
45+
harness = false
46+
47+
[[bench]]
48+
name = "r1csproof"
49+
harness = false
50+
51+
[[bench]]
52+
name = "spartan"
53+
harness = false
54+
55+
[[bench]]
56+
name = "sumcheck"
57+
harness = false
58+
59+
[features]
60+
simd_backend = ["curve25519-dalek/simd_backend"]
61+
rayon_par = []
62+
profile = []
63+
64+
default = ["simd_backend"]

NOTICE.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
This repository includes the following third-party open-source code.
2+
3+
* The code in scalar_25519.rs is derived from [bls12-381](https://github.com/zkcrypto/bls12_381).
4+
Specifically, from [src/bls12_381/scalar.rs](https://github.com/zkcrypto/bls12_381/blob/master/src/scalar.rs) and [src/bls12_381/util.rs](https://github.com/zkcrypto/bls12_381/blob/master/src/util.rs), which has the following copyright and license.
5+
6+
Permission is hereby granted, free of charge, to any
7+
person obtaining a copy of this software and associated
8+
documentation files (the "Software"), to deal in the
9+
Software without restriction, including without
10+
limitation the rights to use, copy, modify, merge,
11+
publish, distribute, sublicense, and/or sell copies of
12+
the Software, and to permit persons to whom the Software
13+
is furnished to do so, subject to the following
14+
conditions:
15+
16+
The above copyright notice and this permission notice
17+
shall be included in all copies or substantial portions
18+
of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
21+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
22+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
24+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28+
DEALINGS IN THE SOFTWARE.
29+
30+
31+
* The invert and batch_invert methods in src/scalar_25519.rs is from [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek), which has the following copyright and license.
32+
33+
Copyright (c) 2016-2019 Isis Agora Lovecruft, Henry de Valence. All rights reserved.
34+
35+
Redistribution and use in source and binary forms, with or without
36+
modification, are permitted provided that the following conditions are
37+
met:
38+
39+
1. Redistributions of source code must retain the above copyright
40+
notice, this list of conditions and the following disclaimer.
41+
42+
2. Redistributions in binary form must reproduce the above copyright
43+
notice, this list of conditions and the following disclaimer in the
44+
documentation and/or other materials provided with the distribution.
45+
46+
3. Neither the name of the copyright holder nor the names of its
47+
contributors may be used to endorse or promote products derived from
48+
this software without specific prior written permission.
49+
50+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
51+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
53+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
56+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
57+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
58+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
59+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
60+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61+
62+
========================================================================
63+
64+
Portions of curve25519-dalek were originally derived from Adam Langley's
65+
Go ed25519 implementation, found at <https://github.com/agl/ed25519/>,
66+
under the following licence:
67+
68+
========================================================================
69+
70+
Copyright (c) 2012 The Go Authors. All rights reserved.
71+
72+
Redistribution and use in source and binary forms, with or without
73+
modification, are permitted provided that the following conditions are
74+
met:
75+
76+
* Redistributions of source code must retain the above copyright
77+
notice, this list of conditions and the following disclaimer.
78+
* Redistributions in binary form must reproduce the above
79+
copyright notice, this list of conditions and the following disclaimer
80+
in the documentation and/or other materials provided with the
81+
distribution.
82+
* Neither the name of Google Inc. nor the names of its
83+
contributors may be used to endorse or promote products derived from
84+
this software without specific prior written permission.
85+
86+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
87+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
88+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
89+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
90+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
91+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
92+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
93+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
94+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
95+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
96+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97+
98+
99+
* The bullet.rs is derived from [bulletproofs](https://github.com/dalek-cryptography/bulletproofs/), which has the following license:
100+
101+
MIT License
102+
103+
Copyright (c) 2018 Chain, Inc.
104+
105+
Permission is hereby granted, free of charge, to any person obtaining a copy
106+
of this software and associated documentation files (the "Software"), to deal
107+
in the Software without restriction, including without limitation the rights
108+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
109+
copies of the Software, and to permit persons to whom the Software is
110+
furnished to do so, subject to the following conditions:
111+
112+
The above copyright notice and this permission notice shall be included in all
113+
copies or substantial portions of the Software.
114+
115+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
116+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
117+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
118+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
119+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
120+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
121+
SOFTWARE.

README.md

+35-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1-
2-
# Contributing
3-
4-
This project welcomes contributions and suggestions. Most contributions require you to agree to a
5-
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
6-
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
7-
8-
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
9-
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
10-
provided by the bot. You will only need to do this once across all repos using our CLA.
11-
12-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
13-
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
14-
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
1+
# Spartan: High-speed zkSNARKs without trusted setup
2+
3+
![Rust](https://github.com/microsoft/Spartan/workflows/Rust/badge.svg)
4+
5+
Spartan is a research project to design high-speed zero-knowledge proof systems, a cryptographic protocol that enables a prover to prove a mathematical statement (e.g., that a given program was executed correctly) without revealing anything besides the validity of the statement.
6+
7+
The current repository includes a library that implements
8+
a zero-knowledge succinct non-interactive arguments of knowledge (zkSNARKs), a type of zero-knowledge proof system with short proofs and verification times. Unlike many other zkSNARKs, Spartan does not require a trusted setup and its security relies on the hardness of computing discrete logarithms (a well-studied assumption). The scheme is described in our [paper](https://eprint.iacr.org/2019/550).
9+
10+
## Building libspartan
11+
cargo build
12+
# On a machine that supports avx2 or ifma instructions:
13+
export RUSTFLAGS="-C target_cpu=native"
14+
cargo build --features "simd_backend" --release
15+
16+
## Performance
17+
cargo build
18+
# On a machine that supports avx2 or ifma instructions:
19+
export RUSTFLAGS="-C target_cpu=native"
20+
cargo build --features "simd_backend,profile" --release
21+
./target/release/profiler
22+
23+
cargo bench
24+
# On a machine that supports avx2 or ifma instructions:
25+
export RUSTFLAGS="-C target_cpu=native"
26+
cargo bench --features "simd_backend"
27+
28+
29+
## LICENSE
30+
31+
See [LICENSE](./LICENSE)
32+
33+
## Contributing
34+
35+
See [CONTRIBUTING](./CONTRIBUTING.md)

benches/commitments.rs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
extern crate byteorder;
2+
extern crate core;
3+
extern crate criterion;
4+
extern crate curve25519_dalek;
5+
extern crate digest;
6+
extern crate libspartan;
7+
extern crate merlin;
8+
extern crate rand;
9+
extern crate sha3;
10+
11+
use libspartan::commitments::{Commitments, MultiCommitGens};
12+
use libspartan::math::Math;
13+
use libspartan::scalar::Scalar;
14+
use rand::rngs::OsRng;
15+
16+
use criterion::*;
17+
18+
fn commitment_benchmark(c: &mut Criterion) {
19+
let mut rng = OsRng;
20+
for &s in [20].iter() {
21+
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
22+
let mut group = c.benchmark_group("commitment_bools");
23+
group.plot_config(plot_config);
24+
25+
let n = (s as usize).pow2();
26+
let gens = MultiCommitGens::new(n, b"test-m");
27+
let blind = Scalar::random(&mut rng);
28+
let vec: Vec<bool> = vec![true; n];
29+
let name = format!("commitment_bools_{}", n);
30+
group.bench_function(&name, move |b| {
31+
b.iter(|| vec.commit(black_box(&blind), black_box(&gens)));
32+
});
33+
group.finish();
34+
}
35+
}
36+
37+
fn set_duration() -> Criterion {
38+
Criterion::default().sample_size(10)
39+
// .measurement_time(Duration::new(0, 50000000))
40+
}
41+
42+
criterion_group! {
43+
name = benches_commitment;
44+
config = set_duration();
45+
targets = commitment_benchmark
46+
}
47+
48+
criterion_main!(benches_commitment);

0 commit comments

Comments
 (0)