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

Generate-proof completed

This commit is contained in:
Jacob Eberhardt 2017-10-27 00:27:38 +02:00
parent 84d6ef1306
commit 3ee13eb4f1
3 changed files with 30 additions and 15 deletions

View file

@ -289,21 +289,26 @@ bool _generate_proof(const char* pk_path, const uint8_t* public_inputs, int publ
for (int i = 1; i < public_inputs_length; i++) {
full_variable_assignment.push_back(Fr<alt_bn128_pp>(libsnarkBigintFromBytes(public_inputs + i*32)));
}
for (int i = 1; i < private_inputs_length; i++) {
for (int i = 0; i < private_inputs_length; i++) {
full_variable_assignment.push_back(Fr<alt_bn128_pp>(libsnarkBigintFromBytes(private_inputs + i*32)));
}
// split up variables into primary and auxiliary inputs. Does *NOT* include the constant 1 */
// Output variables belong to primary input, helper variables are auxiliary input.
r1cs_primary_input<Fr<alt_bn128_pp> > primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + public_inputs_length);
r1cs_primary_input<Fr<alt_bn128_pp> > auxiliary_input(full_variable_assignment.begin() + public_inputs_length, full_variable_assignment.end());
// Public variables belong to primary input, private variables are auxiliary input.
r1cs_primary_input<Fr<alt_bn128_pp>> primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + public_inputs_length-1);
r1cs_primary_input<Fr<alt_bn128_pp>> auxiliary_input(full_variable_assignment.begin() + public_inputs_length-1, full_variable_assignment.end());
// for debugging
cout << "full variable assignment :"<< endl << full_variable_assignment;
cout << "full variable assignment:"<< endl << full_variable_assignment;
cout << "primary input:"<< endl << primary_input;
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);
// print proof
exportProof(proof);
return true;
}
@ -343,8 +348,8 @@ bool _run_libsnark(const uint8_t* A, const uint8_t* B, const uint8_t* C, const u
// Output variables belong to primary input, helper variables are auxiliary input.
// TODO: At the moment, this has implicit assumptions regarding ordering.
// The inputs to the run_libsnark_functions need to put primary inputs first.
r1cs_primary_input<Fr<alt_bn128_pp> > primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + inputs);
r1cs_primary_input<Fr<alt_bn128_pp> > auxiliary_input(full_variable_assignment.begin() + inputs, full_variable_assignment.end());
r1cs_primary_input<Fr<alt_bn128_pp>> primary_input(full_variable_assignment.begin(), full_variable_assignment.begin() + inputs);
r1cs_primary_input<Fr<alt_bn128_pp>> auxiliary_input(full_variable_assignment.begin() + inputs, full_variable_assignment.end());
// for debugging
cout << "full variable assignment :"<< endl << full_variable_assignment;

View file

@ -10,6 +10,7 @@ use self::libc::c_int;
use self::libc::c_char;
use self::libc::uint8_t;
use std::ffi::CString;
use std::cmp::max;
use field::Field;
@ -97,7 +98,11 @@ pub fn setup<T: Field> (
}
}
pub fn generate_proof<T: Field>(pk_path: &str, public_inputs: Vec<T>, private_inputs: Vec<T>) -> bool {
pub fn generate_proof<T: Field>(
pk_path: &str,
public_inputs: Vec<T>,
private_inputs: Vec<T>,
) -> bool {
let pk_path_cstring = CString::new(pk_path).unwrap();
@ -105,7 +110,8 @@ pub fn generate_proof<T: Field>(pk_path: &str, public_inputs: Vec<T>, private_in
let private_inputs_length = private_inputs.len();
let mut public_inputs_arr: Vec<[u8; 32]> = vec![[0u8; 32]; public_inputs_length];
let mut private_inputs_arr: Vec<[u8; 32]> = vec![[0u8; 32]; private_inputs_length];
// length must not be zero here, so we apply the max function
let mut private_inputs_arr: Vec<[u8; 32]> = vec![[0u8; 32]; max(private_inputs_length,1)];
//convert inputs
for (index, value) in public_inputs.into_iter().enumerate() {

View file

@ -386,16 +386,17 @@ fn main() {
// write variables meta information to file
let var_inf_path = Path::new(sub_matches.value_of("meta-information").unwrap());
let var_inf_file = match File::open(&var_inf_path) {
let var_inf_file = match File::create(&var_inf_path) {
Ok(file) => file,
Err(why) => panic!("couldn't open {}: {}", var_inf_path.display(), why),
};
let mut bw = BufWriter::new(var_inf_file);
write!(&mut bw, "Private inputs offset: {}\n", private_inputs_offset).expect("Unable to write data to file.");
write!(&mut bw, "R1CS variable order: \n").expect("Unable to write data to file.");
write!(&mut bw, "Private inputs offset:\n{}\n", private_inputs_offset).expect("Unable to write data to file.");
write!(&mut bw, "R1CS variable order:\n").expect("Unable to write data to file.");
for var in &variables {
write!(&mut bw, "{} ", var).expect("Unable to write data to file.");
}
write!(&mut bw, "\n").expect("Unable to write data to file.");
bw.flush().expect("Unable to flush buffer.");
@ -583,14 +584,15 @@ fn main() {
// get private inputs offset
let private_inputs_offset;
if let Some(Ok(ref o)) = var_lines.next(){
if let Some(Ok(ref o)) = var_lines.nth(1){ // consumes first 2 lines
private_inputs_offset = o.parse().expect("Failed parsing private inputs offset");
} else {
panic!("Error reading private inputs offset");
}
// get variables vector
let mut variables: Vec<String> = Vec::new();
if let Some(Ok(ref v)) = var_lines.next(){
if let Some(Ok(ref v)) = var_lines.nth(1){
let iter = v.split_whitespace();
for i in iter {
variables.push(i.to_string());
@ -605,7 +607,9 @@ fn main() {
// split witness into public and private inputs at offset
let mut public_inputs: Vec<_>= witness.clone();
println!("Public inputs: {:?}", public_inputs);
let private_inputs: Vec<_> = public_inputs.split_off(private_inputs_offset);
println!("Private inputs: {:?}", private_inputs);
let pk_path = sub_matches.value_of("provingkey").unwrap();