refactor r1cs to accept multiple outputs (wip)
This commit is contained in:
parent
1026732360
commit
89e6a1c8d1
3 changed files with 20 additions and 16 deletions
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
24
src/r1cs.rs
24
src/r1cs.rs
|
@ -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")
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue