From d55d390593809da65f46e3841d5f5ccb9be06339 Mon Sep 17 00:00:00 2001 From: "Ya-wen, Jeng" Date: Tue, 7 Nov 2023 16:11:33 +0800 Subject: [PATCH] chore(core): get inputs from witness --- mopro-core/src/middleware/circom/mod.rs | 32 +++++++++---------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/mopro-core/src/middleware/circom/mod.rs b/mopro-core/src/middleware/circom/mod.rs index 25b26c1f..469b9890 100644 --- a/mopro-core/src/middleware/circom/mod.rs +++ b/mopro-core/src/middleware/circom/mod.rs @@ -155,29 +155,12 @@ pub fn generate_proof2( .calculate_witness_element::(inputs, false) .map_err(|e| MoproError::CircomError(e.to_string()))?; - // FIXME: Mock inputs - let public_inputs = vec![Fr::from(0)]; - - // TODO: Get public inputs - // NOTE: Here's what we do to get public inputs with ark-circom - // pub fn get_public_inputs(&self) -> Option> { - // match &self.witness { - // None => None, - // Some(w) => match &self.r1cs.wire_mapping { - // None => Some(w[1..self.r1cs.num_inputs].to_vec()), - // Some(m) => Some(m[1..self.r1cs.num_inputs].iter().map(|i| w[*i]).collect()), - // }, - // } - // } - // - // In or case we have: - // zkey.1.num_instance_variables contains number of instance variables - // We need to extract the public inputs from the full assignment - println!("Witness generation took: {:.2?}", now.elapsed()); let now = std::time::Instant::now(); let zkey = zkey(); + + let public_inputs = full_assignment.as_slice()[1..zkey.1.num_instance_variables].to_vec(); println!("Loading zkey took: {:.2?}", now.elapsed()); let now = std::time::Instant::now(); @@ -516,8 +499,15 @@ mod tests { 116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; - + let expected_output_vec = vec![ + 37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88, + 212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21, + ]; let inputs = bytes_to_circuit_inputs(&input_vec); - let _ = generate_proof2(inputs); + let serialized_outputs = bytes_to_circuit_outputs(&expected_output_vec); + + let generate_proof_res = generate_proof2(inputs); + let (_, serialized_inputs) = generate_proof_res.unwrap(); + assert_eq!(serialized_inputs, serialized_outputs); } }