1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

remove foo, narrow down segfault

This commit is contained in:
schaeff 2018-05-13 10:26:27 +02:00
parent c58a484be9
commit a6ff893b06
8 changed files with 25 additions and 43 deletions

View file

@ -24,5 +24,6 @@ RUN curl https://sh.rustup.rs -sSf | \
ENV PATH=/root/.cargo/bin:$PATH
COPY . .
RUN cargo build --release
COPY . /root/ZoKrates
RUN cd ZoKrates \
&& cargo build

View file

@ -48,7 +48,7 @@ fn main() {
println!("cargo:rustc-link-lib=gmp");
println!("cargo:rustc-link-lib=gmpxx");
println!("cargo:rustc-link-lib=static=snark");
println!("cargo:rustc-link-lib=static=ff");
println!("cargo:rustc-link-lib=static=snarkd");
println!("cargo:rustc-link-lib=static=ffd");
}
}

View file

@ -240,13 +240,7 @@ void printProof(r1cs_ppzksnark_proof<libff::alt_bn128_pp> proof){
cout << "proof.K = Pairing.G1Point(" << outputPointG1AffineAsHex(proof.g_K)<<");"<< endl;
}
bool _setup(const uint8_t* A, const uint8_t* B, const uint8_t* C, int constraints, int variables, int inputs, const char* pk_path, const char* vk_path)
{
return(true);
}
/*bool _setup(const uint8_t* A, const uint8_t* B, const uint8_t* C, int constraints, int variables, int inputs, const char* pk_path, const char* vk_path)
{
//libsnark::inhibit_profiling_info = true;
//libsnark::inhibit_profiling_counters = true;
@ -254,15 +248,14 @@ bool _setup(const uint8_t* A, const uint8_t* B, const uint8_t* C, int constraint
//initialize curve parameters
libff::alt_bn128_pp::init_public_params();
r1cs_constraint_system<libff::alt_bn128_pp> cs;
cs = createConstraintSystem(A, B ,C , constraints, variables, inputs);
auto cs = createConstraintSystem(A, B ,C , constraints, variables, inputs);
assert(cs.num_variables() >= inputs);
assert(cs.num_inputs() == inputs);
assert(cs.num_constraints() == constraints);
// create keypair
r1cs_ppzksnark_keypair<alt_bn128_pp> keypair = r1cs_ppzksnark_generator<alt_bn128_pp>(cs);
auto keypair = r1cs_ppzksnark_generator<libff::alt_bn128_pp>(cs);
// Export vk and pk to files
serializeProvingKeyToFile(keypair.pk, pk_path);
@ -272,7 +265,7 @@ bool _setup(const uint8_t* A, const uint8_t* B, const uint8_t* C, int constraint
exportVerificationKey(keypair);
return true;
}*/
}
bool _generate_proof(const char* pk_path, const uint8_t* public_inputs, int public_inputs_length, const uint8_t* private_inputs, int private_inputs_length)
{
@ -286,7 +279,7 @@ bool _generate_proof(const char* pk_path, const uint8_t* public_inputs, int publ
//initialize curve parameters
libff::alt_bn128_pp::init_public_params();
r1cs_ppzksnark_proving_key<libff::alt_bn128_pp> pk = deserializeProvingKeyFromFile(pk_path);
auto pk = deserializeProvingKeyFromFile(pk_path);
// assign variables based on witness values, excludes ~one
r1cs_variable_assignment<libff::alt_bn128_pp> full_variable_assignment;
@ -299,8 +292,8 @@ bool _generate_proof(const char* pk_path, const uint8_t* public_inputs, int publ
// split up variables into primary and auxiliary inputs. Does *NOT* include the constant 1
// Public variables belong to primary input, private variables are auxiliary input.
r1cs_primary_input<libff::alt_bn128_pp> primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + public_inputs_length-1);
r1cs_primary_input<libff::alt_bn128_pp> auxiliary_input(full_variable_assignment.begin() + public_inputs_length-1, full_variable_assignment.end());
auto primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + public_inputs_length-1);
auto auxiliary_input(full_variable_assignment.begin() + public_inputs_length-1, full_variable_assignment.end());
// for debugging
// cout << "full variable assignment:"<< endl << full_variable_assignment;
@ -308,7 +301,7 @@ bool _generate_proof(const char* pk_path, const uint8_t* public_inputs, int publ
// cout << "auxiliary input:"<< endl << auxiliary_input;
// Proof Generation
r1cs_ppzksnark_proof<alt_bn128_pp> proof = r1cs_ppzksnark_prover<alt_bn128_pp>(pk, primary_input, auxiliary_input);
auto proof = r1cs_ppzksnark_prover<libff::alt_bn128_pp>(pk, primary_input, auxiliary_input);
// print proof
printProof(proof);

View file

@ -20,7 +20,7 @@ std::string r1cs_to_json(protoboard<FieldT> pb, uint input_variables)
for (size_t i = 0; i < input_variables + 1; ++i)
{
ss << '"' << constraints.variable_annotations[i].c_str() << '"';
// ss << '"' << constraints.variable_annotations[i].c_str() << '"';
if (i < input_variables ) {
ss << ", ";
}
@ -47,24 +47,22 @@ std::string r1cs_to_json(protoboard<FieldT> pb, uint input_variables)
return ss.str();
}
const char* _sha256Constraints()
void _sha256Constraints()
{
protoboard<FieldT> pb;
std::shared_ptr<sha256_ethereum> hash;
// block_variable<FieldT> input;
// block_variable<FieldT> output;
// auto hash = std::make_shared<sha256_ethereum>(pb, 256, input; output, "cm_hash");
// std::shared_ptr<sha256_ethereum> hash;
protoboard<FieldT> pb;
// hash.reset(new sha256_ethereum(
// pb, 256, input, output, "cm_hash"
// ));
// hash->generate_r1cs_constraints(true);
// return(r1cs_to_json(pb, 10));
return std::string{}.c_str();
}
bool _foo() {
return true;
//return "";
}
std::string array_to_json(protoboard<FieldT> pb)

View file

@ -12,8 +12,7 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
const char* _sha256Constraints();
bool _foo();
void _sha256Constraints();
#ifdef __cplusplus
} // extern "C"

View file

@ -50,6 +50,7 @@ impl fmt::Display for CompileError<FieldPrime> {
}
pub fn compile<T: Field>(path: PathBuf) -> Result<Prog<T>, CompileError<T>> {
println!("compile {:?}", path);
let file = File::open(&path)?;
let program_ast: Prog<T> = parse_program(file)?;

View file

@ -34,10 +34,7 @@ extern "C" {
private_inputs_length: c_int,
) -> bool;
fn _sha256Constraints() -> CString;
fn _foo() -> bool;
fn _sha256Constraints() -> ();
}
pub fn setup<T: Field> (
@ -122,18 +119,12 @@ pub fn generate_proof<T: Field>(
}
}
pub fn getSha256Constraints() -> CString {
pub fn getSha256Constraints() -> () {
unsafe {
_sha256Constraints()
}
}
pub fn foo() -> bool {
unsafe {
_foo()
}
}
// utility function. Converts a Fields vector-based byte representation to fixed size array.
fn vec_as_u8_32_array(vec: &Vec<u8>) -> [u8; 32] {
assert!(vec.len() <= 32);

View file

@ -38,7 +38,7 @@ use compile::compile;
use r1cs::r1cs_program;
use clap::{App, AppSettings, Arg, SubCommand};
#[cfg(not(feature = "nolibsnark"))]
use libsnark::{setup, generate_proof, getSha256Constraints, foo};
use libsnark::{setup, generate_proof, getSha256Constraints};
use bincode::{serialize_into, deserialize_from , Infinite};
use regex::Regex;
use verification::CONTRACT_TEMPLATE;
@ -199,7 +199,6 @@ fn main() {
match matches.subcommand() {
("compile", Some(sub_matches)) => {
foo();
println!("{:?}", getSha256Constraints());
println!("Compiling {}", sub_matches.value_of("input").unwrap());