Initial commit
This commit is contained in:
2
tinysnark/.gitignore
vendored
Normal file
2
tinysnark/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
||||
13
tinysnark/Cargo.toml
Normal file
13
tinysnark/Cargo.toml
Normal 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
40
tinysnark/build.rs
Normal 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
1
tinysnark/libsnark
Submodule
Submodule tinysnark/libsnark added at 0b928a7b36
9
tinysnark/src/lib.rs
Normal file
9
tinysnark/src/lib.rs
Normal 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
42
tinysnark/tinysnark.cpp
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user