Skip to content

Commit

Permalink
chore: update arg names to match type
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 3, 2023
1 parent 010c2fa commit 05fcc61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ pub fn parse_and_solve_witness<P: AsRef<Path>>(

fn solve_witness(
compiled_program: &noirc_driver::CompiledProgram,
abi_map: &InputMap,
input_map: &InputMap,
) -> Result<WitnessMap, CliError> {
let abi = compiled_program.abi.as_ref().unwrap().clone();
let mut solved_witness =
input_map_to_witness_map(abi, abi_map).map_err(|error| match error {
input_map_to_witness_map(abi, input_map).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
CliError::Generic(format!("{error} in the {VERIFIER_INPUT_FILE}.toml file."))
}
Expand All @@ -144,9 +144,9 @@ fn solve_witness(
///
/// In particular, this method shows one how to associate values in a Toml/JSON
/// file with witness indices
fn input_map_to_witness_map(abi: Abi, abi_map: &InputMap) -> Result<WitnessMap, AbiError> {
fn input_map_to_witness_map(abi: Abi, input_map: &InputMap) -> Result<WitnessMap, AbiError> {
// The ABI map is first encoded as a vector of field elements
let encoded_inputs = abi.encode(abi_map, true)?;
let encoded_inputs = abi.encode(input_map, true)?;

Ok(encoded_inputs
.into_iter()
Expand Down
21 changes: 11 additions & 10 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,35 @@ pub fn verify_with_path<P: AsRef<Path>>(
allow_warnings: bool,
) -> Result<bool, CliError> {
let compiled_program = compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?;
let mut public_abi_map: InputMap = BTreeMap::new();
let mut public_inputs_map: InputMap = BTreeMap::new();

// Load public inputs (if any) from `VERIFIER_INPUT_FILE`.
let public_abi = compiled_program.abi.clone().unwrap().public_abi();
let num_pub_params = public_abi.num_parameters();
if num_pub_params != 0 {
let curr_dir = program_dir;
public_abi_map =
public_inputs_map =
read_inputs_from_file(curr_dir, VERIFIER_INPUT_FILE, Format::Toml, public_abi)?;
}

let valid_proof = verify_proof(compiled_program, public_abi_map, load_proof(proof_path)?)?;
let valid_proof = verify_proof(compiled_program, public_inputs_map, load_proof(proof_path)?)?;

Ok(valid_proof)
}

fn verify_proof(
mut compiled_program: CompiledProgram,
public_abi_map: InputMap,
public_inputs_map: InputMap,
proof: Vec<u8>,
) -> Result<bool, CliError> {
let public_abi = compiled_program.abi.unwrap().public_abi();
let public_inputs = public_abi.encode(&public_abi_map, false).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
CliError::Generic(format!("{error} in the {VERIFIER_INPUT_FILE}.toml file."))
}
_ => CliError::from(error),
})?;
let public_inputs =
public_abi.encode(&public_inputs_map, false).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
CliError::Generic(format!("{error} in the {VERIFIER_INPUT_FILE}.toml file."))
}
_ => CliError::from(error),
})?;

// Similarly to when proving -- we must remove the duplicate public witnesses which
// can be present because a public input can also be added as a public output.
Expand Down

0 comments on commit 05fcc61

Please sign in to comment.