cli - verify_cmd
The verifer now parses a Verifier.toml file for the public inputs.
Using the ABI, the public inputs are put in the correct order.
The acvm backend now accepts public inputs.
-use super::PROOFS_DIR;
+use super::{PROOFS_DIR, PROOF_EXT, VERIFIER_INPUT_FILE};
use crate::resolver::Resolver;
use clap::ArgMatches;
-use std::path::Path;
+use noir_field::FieldElement;
+use noirc_abi::{input_parser::InputValue, Abi};
+use std::{collections::BTreeMap, path::Path};
pub(crate) fn run(args: ArgMatches) {
let proof_name = args
@@ -13,7 +15,7 @@ pub(crate) fn run(args: ArgMatches) {
proof_path.push(Path::new(PROOFS_DIR));
proof_path.push(Path::new(proof_name));
- proof_path.set_extension("proof");
+ proof_path.set_extension(PROOF_EXT);
let result = verify(proof_name);
println!("Proof verified : {}\n", result);
@@ -27,7 +29,22 @@ fn verify(proof_name: &str) -> bool {
let mut proof_path = curr_dir;
proof_path.push(Path::new("proofs"));
proof_path.push(Path::new(proof_name));
- proof_path.set_extension("proof");
+ proof_path.set_extension(PROOF_EXT);
+
+ let curr_dir = std::env::current_dir().unwrap();
+ let public_inputs = noirc_abi::input_parser::Format::Toml.parse(curr_dir, VERIFIER_INPUT_FILE);
+
+ let public_abi = compiled_program.abi.clone().unwrap().public_abi();
+ let num_params = public_abi.num_parameters();
+ if num_params != public_inputs.len() {
+ panic!(
+ "Expected {} number of values, but got {} number of values",
+ num_params,
+ public_inputs.len()
+ )
+ }
+
+ let public_inputs = process_abi_with_verifier_input(public_abi, public_inputs);
// XXX: Instead of unwrap, return a PathNotValidError
let proof_hex: Vec<_> = std::fs::read(proof_path).unwrap();
@@ -36,5 +53,30 @@ fn verify(proof_name: &str) -> bool {
backend_ptr
.backend()
- .verify_from_cs(&proof, compiled_program.circuit)
+ .verify_from_cs(&proof, public_inputs, compiled_program.circuit)
+}
+
+fn process_abi_with_verifier_input(
+ abi: Abi,
+ pi_map: BTreeMap<String, InputValue>,
+) -> Vec<FieldElement> {
+ let mut public_inputs = Vec::with_capacity(pi_map.len());
+
+ let param_names = abi.parameter_names();
+ for param in param_names.into_iter() {
+ let value = pi_map
+ .get(param)
+ .expect(&format!(
+ "ABI expects the parameter `{}`, but this was not found",
+ param
+ ))
+ .clone();
+
+ match value {
+ InputValue::Field(elem) => public_inputs.push(elem),
+ InputValue::Vec(vec_elem) => public_inputs.extend(vec_elem),
+ }
+ }
+
+ public_inputs
}
