Initial commit

This commit is contained in:
Sean Bowe 2015-12-24 02:58:38 -07:00
commit 45111d6576
12 changed files with 152 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
Cargo.lock

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tinysnark/libsnark"]
path = tinysnark/libsnark
url = git://github.com/scipr-lab/libsnark.git

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "bellman"
version = "0.0.1"
authors = ["Sean Bowe <ewillbefull@gmail.com>"]
homepage = "https://github.com/ebfull/bellman"
repository = "https://github.com/ebfull/bellman"
documentation = "https://github.com/ebfull/bellman"
license = "MIT"
description = "zk-SNARK library"
[dependencies.tinysnark]
path = "tinysnark"
version = "0.0.1"

21
LICENSE-MIT Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Sean Bowe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1
README.md Normal file
View File

@ -0,0 +1 @@
Bellman is a Rust language zk-SNARK crate.

5
src/main.rs Normal file
View File

@ -0,0 +1,5 @@
extern crate tinysnark;
fn main() {
tinysnark::test();
}

2
tinysnark/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
Cargo.lock

13
tinysnark/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "tinysnark"
homepage = "https://github.com/ebfull/bellman"
repository = "https://github.com/ebfull/bellman"
documentation = "https://github.com/ebfull/bellman"
license = "MIT"
description = "Tiny libsnark bindings"
version = "0.0.1"
authors = ["Sean Bowe <ewillbefull@gmail.com>"]
build = "build.rs"
[build-dependencies]
gcc = "0.3"

40
tinysnark/build.rs Normal file
View File

@ -0,0 +1,40 @@
extern crate gcc;
fn main() {
// we don't need ate-pairing for ALT_BN128, but
// i'll keep this in case i need it for some reason...
/*
let mut cfg = gcc::Config::new();
cfg.cpp(true)
.define("BN_SUPPORT_SNARK", None)
.include("ate-pairing/include")
.include("xbyak")
.file("ate-pairing/src/zm.cpp")
.file("ate-pairing/src/zm2.cpp")
.compile("libzm.a");
*/
println!("cargo:rustc-link-lib=gmp");
println!("cargo:rustc-link-lib=gmpxx");
let mut cfg = gcc::Config::new();
cfg.cpp(true)
.define("NO_PROCPS", None)
.define("STATIC", None)
.define("CURVE_ALT_BN128", None)
.flag("-std=c++11")
.include("libsnark/src")
.file("tinysnark.cpp")
.file("libsnark/src/algebra/curves/alt_bn128/alt_bn128_g1.cpp")
.file("libsnark/src/algebra/curves/alt_bn128/alt_bn128_g2.cpp")
.file("libsnark/src/algebra/curves/alt_bn128/alt_bn128_init.cpp")
.file("libsnark/src/algebra/curves/alt_bn128/alt_bn128_pairing.cpp")
.file("libsnark/src/algebra/curves/alt_bn128/alt_bn128_pp.cpp")
.file("libsnark/src/common/utils.cpp")
.file("libsnark/src/common/profiling.cpp")
;
cfg.compile("libtinysnark.a");
}

1
tinysnark/libsnark Submodule

@ -0,0 +1 @@
Subproject commit 0b928a7b36717db6f67ff7e1e34dfa3bfaee1c97

9
tinysnark/src/lib.rs Normal file
View File

@ -0,0 +1,9 @@
extern "C" {
fn tinysnark_init_public_params();
fn tinysnark_test();
}
pub fn test() {
unsafe { tinysnark_init_public_params(); }
unsafe { tinysnark_test(); }
}

42
tinysnark/tinysnark.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
This is a wrapper around libsnark which provides basic R1CS
zk-SNARK support using the ALT_BN128 curve.
*/
#include "gadgetlib1/gadgets/basic_gadgets.hpp"
#include "zk_proof_systems/ppzksnark/r1cs_ppzksnark/r1cs_ppzksnark.hpp"
#include "common/default_types/r1cs_ppzksnark_pp.hpp"
#include "common/utils.hpp"
using namespace libsnark;
using namespace std;
extern "C" void tinysnark_init_public_params() {
default_r1cs_ppzksnark_pp::init_public_params();
}
extern "C" void tinysnark_test() {
typedef Fr<default_r1cs_ppzksnark_pp> FieldT;
protoboard<FieldT> pb;
linear_combination<FieldT> sum;
sum = sum + 1;
pb.add_r1cs_constraint(r1cs_constraint<FieldT>(1, sum, 1), "testing");
assert(pb.is_satisfied());
const r1cs_constraint_system<FieldT> constraint_system = pb.get_constraint_system();
cout << "Number of R1CS constraints: " << constraint_system.num_constraints() << endl;
auto keypair = r1cs_ppzksnark_generator<default_r1cs_ppzksnark_pp>(constraint_system);
auto proof = r1cs_ppzksnark_prover<default_r1cs_ppzksnark_pp>(keypair.pk, pb.primary_input(), pb.auxiliary_input());
r1cs_primary_input<FieldT> input;
assert(r1cs_ppzksnark_verifier_strong_IC<default_r1cs_ppzksnark_pp>(keypair.vk, input, proof));
}