diff --git a/src/absy.rs b/src/absy.rs index 5ac994bb..2a49e993 100644 --- a/src/absy.rs +++ b/src/absy.rs @@ -81,8 +81,10 @@ impl Function { 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") } diff --git a/src/main.rs b/src/main.rs index 18afa07a..fd42cd42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -348,10 +348,6 @@ fn main() { let witness_map = main_flattened.get_witness(arguments); // let witness_map: HashMap = 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)); } } diff --git a/src/r1cs.rs b/src/r1cs.rs index 933e2faa..05da9f5d 100644 --- a/src/r1cs.rs +++ b/src/r1cs.rs @@ -295,7 +295,9 @@ pub fn r1cs_program( // ~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( 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") } },