From f304afc535bb5507cdb6d278ba61d09f8da67296 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 20 Feb 2023 15:35:09 +0000 Subject: [PATCH] chore: remove `witness` flag from `nargo compile` (#878) * chore: make preprocess_with_path private * chore: remove option to generate a witness in `nargo compile` --- crates/nargo/src/cli/compile_cmd.rs | 51 ++++++++--------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/crates/nargo/src/cli/compile_cmd.rs b/crates/nargo/src/cli/compile_cmd.rs index 398de901f1a..e4f318e33eb 100644 --- a/crates/nargo/src/cli/compile_cmd.rs +++ b/crates/nargo/src/cli/compile_cmd.rs @@ -1,13 +1,11 @@ use acvm::ProofSystemCompiler; use acvm::{acir::circuit::Circuit, hash_constraint_system}; -use noirc_abi::input_parser::Format; use std::path::{Path, PathBuf}; use clap::Args; use crate::{ - cli::{execute_cmd::save_witness_to_dir, read_inputs_from_file}, - constants::{ACIR_EXT, PK_EXT, PROVER_INPUT_FILE, TARGET_DIR, VK_EXT}, + constants::{ACIR_EXT, PK_EXT, TARGET_DIR, VK_EXT}, errors::CliError, resolver::Resolver, }; @@ -20,10 +18,6 @@ pub(crate) struct CompileCommand { /// The name of the ACIR file circuit_name: String, - /// Solve the witness and write it to file along with the ACIR - #[arg(short, long)] - witness: bool, - /// Issue a warning for each unused variable instead of an error #[arg(short, long)] allow_warnings: bool, @@ -33,45 +27,28 @@ pub(crate) fn run(args: CompileCommand, config: NargoConfig) -> Result<(), CliEr let mut circuit_path = config.program_dir.clone(); circuit_path.push(TARGET_DIR); - generate_circuit_and_witness_to_disk( + let circuit_path = compile_and_preprocess_circuit( &args.circuit_name, config.program_dir, circuit_path, - args.witness, args.allow_warnings, - ) - .map(|_| ()) + )?; + + println!("Generated ACIR code into {}", circuit_path.display()); + + Ok(()) } -pub fn generate_circuit_and_witness_to_disk>( +fn compile_and_preprocess_circuit>( circuit_name: &str, program_dir: P, circuit_dir: P, - generate_witness: bool, allow_warnings: bool, ) -> Result { - let compiled_program = compile_circuit(program_dir.as_ref(), false, allow_warnings)?; + let compiled_program = compile_circuit(program_dir, false, allow_warnings)?; + let circuit_path = save_acir_to_dir(&compiled_program.circuit, circuit_name, &circuit_dir); - preprocess_with_path(circuit_name, circuit_dir.as_ref(), compiled_program.circuit.clone())?; - - let mut circuit_path = - save_acir_to_dir(compiled_program.circuit.clone(), circuit_name, circuit_dir.as_ref()); - println!("Generated ACIR code into {}", circuit_path.display()); - - if generate_witness { - // Parse the initial witness values from Prover.toml - let inputs_map = read_inputs_from_file( - program_dir, - PROVER_INPUT_FILE, - Format::Toml, - &compiled_program.abi, - )?; - - let solved_witness = super::execute_cmd::execute_program(&compiled_program, &inputs_map)?; - - circuit_path.pop(); - save_witness_to_dir(solved_witness, circuit_name, &circuit_path)?; - } + preprocess_with_path(circuit_name, circuit_dir, compiled_program.circuit)?; Ok(circuit_path) } @@ -90,7 +67,7 @@ pub fn compile_circuit>( .map_err(|_| std::process::exit(1)) } -pub fn preprocess_with_path>( +fn preprocess_with_path>( key_name: &str, preprocess_dir: P, circuit: Circuit, @@ -108,7 +85,7 @@ pub fn preprocess_with_path>( } fn save_acir_to_dir>( - circuit: Circuit, + circuit: &Circuit, circuit_name: &str, circuit_dir: P, ) -> PathBuf { @@ -116,7 +93,7 @@ fn save_acir_to_dir>( circuit_path.push(circuit_name); // Save a checksum of the circuit to compare against during proving and verification - let acir_hash = hash_constraint_system(&circuit); + let acir_hash = hash_constraint_system(circuit); circuit_path.set_extension(ACIR_EXT.to_owned() + ".sha256"); write_to_file(hex::encode(acir_hash).as_bytes(), &circuit_path);