1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00

refactor r1cs to accept multiple outputs (wip)

This commit is contained in:
schaeff 2018-01-23 09:15:44 +01:00
parent 1026732360
commit 89e6a1c8d1
3 changed files with 20 additions and 16 deletions

View file

@ -81,8 +81,10 @@ impl<T: Field> Function<T> {
Statement::Return(ref expr) => {
match expr.clone() {
Expression::List(values) => {
let s = values[0].solve(&mut witness);
witness.insert("~out".to_string(), s);
for (i, val) in values.iter().enumerate() {
let s = val.solve(&mut witness);
witness.insert(format!("~out_{}", i).to_string(), s);
}
},
_ => panic!("should return a list")
}

View file

@ -348,10 +348,6 @@ fn main() {
let witness_map = main_flattened.get_witness(arguments);
// let witness_map: HashMap<String, FieldPrime> = main_flattened.get_witness(args);
println!("Witness: {:?}", witness_map);
match witness_map.get("~out") {
Some(out) => println!("Returned (~out): {}", out),
None => println!("~out not found, no value returned")
}
// write witness to file
let output_path = Path::new(sub_matches.value_of("output").unwrap());
@ -425,7 +421,7 @@ fn main() {
// run setup phase
#[cfg(not(feature="nolibsnark"))]{
// number of inputs in the zkSNARK sense, i.e., input variables + output variables
let num_inputs = main_flattened.arguments.iter().filter(|x| !x.private).count() + 1;
let num_inputs = main_flattened.arguments.iter().filter(|x| !x.private).count() + main_flattened.return_count;
println!("setup successful: {:?}", setup(variables, a, b, c, num_inputs, pk_path, vk_path));
}
}

View file

@ -295,7 +295,9 @@ pub fn r1cs_program<T: Field>(
// ~out is added after main's arguments as we want variables (columns)
// in the r1cs to be aligned like "public inputs | private inputs"
variables.push("~out".to_string());
for i in 0..main.return_count {
variables.push(format!("~out_{}", i).to_string());
}
// position where private part of witness starts
let private_inputs_offset = variables.len();
@ -307,14 +309,18 @@ pub fn r1cs_program<T: Field>(
match *def {
Statement::Return(ref expr) => {
match expr.clone() {
Expression::List(values) => r1cs_expression(
Identifier("~out".to_string()),
values[0].clone(),
&mut variables,
&mut a_row,
&mut b_row,
&mut c_row,
),
Expression::List(values) => {
for (i, val) in values.iter().enumerate() {
r1cs_expression(
Identifier(format!("~out_{}", i).to_string()),
val.clone(),
&mut variables,
&mut a_row,
&mut b_row,
&mut c_row,
)
}
},
_ => panic!("should return a List")
}
},