Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nargo): Allow user-specified file for prover inputs instead of Prover.toml #1531

Merged
merged 6 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub(crate) struct ExecuteCommand {
/// Write the execution witness to named file
witness_name: Option<String>,

/// The name of the toml file which contains the inputs for the prover
#[clap(long, short, default_value = PROVER_INPUT_FILE)]
prover_name: String,

#[clap(flatten)]
compile_options: CompileOptions,
}
Expand All @@ -31,7 +35,7 @@ pub(crate) fn run<B: Backend>(
config: NargoConfig,
) -> Result<(), CliError<B>> {
let (return_value, solved_witness) =
execute_with_path(backend, &config.program_dir, &args.compile_options)?;
execute_with_path(backend, &config.program_dir, args.prover_name, &args.compile_options)?;

println!("Circuit witness successfully solved");
if let Some(return_value) = return_value {
Expand All @@ -50,13 +54,14 @@ pub(crate) fn run<B: Backend>(
fn execute_with_path<B: Backend>(
backend: &B,
program_dir: &Path,
prover_name: String,
compile_options: &CompileOptions,
) -> Result<(Option<InputValue>, WitnessMap), CliError<B>> {
let CompiledProgram { abi, circuit } = compile_circuit(backend, program_dir, compile_options)?;

// Parse the initial witness values from Prover.toml
let (inputs_map, _) =
read_inputs_from_file(program_dir, PROVER_INPUT_FILE, Format::Toml, &abi)?;
read_inputs_from_file(program_dir, prover_name.as_str(), Format::Toml, &abi)?;

let solved_witness = execute_program(backend, circuit, &abi, &inputs_map)?;

Expand Down
17 changes: 15 additions & 2 deletions crates/nargo_cli/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ pub(crate) struct ProveCommand {
/// The name of the circuit build files (ACIR, proving and verification keys)
circuit_name: Option<String>,

/// The name of the toml file which contains the inputs for the prover
#[clap(long, short, default_value = PROVER_INPUT_FILE)]
prover_name: String,

/// The name of the toml file which contains the inputs for the verifier
#[clap(long, short, default_value = VERIFIER_INPUT_FILE)]
verifier_name: String,

/// Verify proof after proving
#[arg(short, long)]
verify: bool,
Expand All @@ -57,6 +65,8 @@ pub(crate) fn run<B: Backend>(
prove_with_path(
backend,
args.proof_name,
args.prover_name,
args.verifier_name,
config.program_dir,
proof_dir,
circuit_build_path,
Expand All @@ -67,9 +77,12 @@ pub(crate) fn run<B: Backend>(
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn prove_with_path<B: Backend, P: AsRef<Path>>(
backend: &B,
proof_name: Option<String>,
prover_name: String,
verifier_name: String,
program_dir: P,
proof_dir: P,
circuit_build_path: Option<PathBuf>,
Expand Down Expand Up @@ -107,7 +120,7 @@ pub(crate) fn prove_with_path<B: Backend, P: AsRef<Path>>(

// Parse the initial witness values from Prover.toml
let (inputs_map, _) =
read_inputs_from_file(&program_dir, PROVER_INPUT_FILE, Format::Toml, &abi)?;
read_inputs_from_file(&program_dir, prover_name.as_str(), Format::Toml, &abi)?;

let solved_witness = execute_program(backend, bytecode.clone(), &abi, &inputs_map)?;

Expand All @@ -119,7 +132,7 @@ pub(crate) fn prove_with_path<B: Backend, P: AsRef<Path>>(
&public_inputs,
&return_value,
&program_dir,
VERIFIER_INPUT_FILE,
verifier_name.as_str(),
Format::Toml,
)?;

Expand Down
10 changes: 8 additions & 2 deletions crates/nargo_cli/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub(crate) struct VerifyCommand {
/// The name of the circuit build files (ACIR, proving and verification keys)
circuit_name: Option<String>,

/// The name of the toml file which contains the inputs for the verifier
#[clap(long, short, default_value = VERIFIER_INPUT_FILE)]
verifier_name: String,

#[clap(flatten)]
compile_options: CompileOptions,
}
Expand All @@ -52,6 +56,7 @@ pub(crate) fn run<B: Backend>(
&config.program_dir,
proof_path,
circuit_build_path.as_ref(),
args.verifier_name,
&args.compile_options,
)
}
Expand All @@ -61,6 +66,7 @@ fn verify_with_path<B: Backend, P: AsRef<Path>>(
program_dir: P,
proof_path: PathBuf,
circuit_build_path: Option<P>,
verifier_name: String,
compile_options: &CompileOptions,
) -> Result<(), CliError<B>> {
let common_reference_string = read_cached_common_reference_string();
Expand Down Expand Up @@ -91,10 +97,10 @@ fn verify_with_path<B: Backend, P: AsRef<Path>>(

let PreprocessedProgram { abi, bytecode, verification_key, .. } = preprocessed_program;

// Load public inputs (if any) from `VERIFIER_INPUT_FILE`.
// Load public inputs (if any) from `verifier_name`.
let public_abi = abi.public_abi();
let (public_inputs_map, return_value) =
read_inputs_from_file(program_dir, VERIFIER_INPUT_FILE, Format::Toml, &public_abi)?;
read_inputs_from_file(program_dir, verifier_name.as_str(), Format::Toml, &public_abi)?;

let public_inputs = public_abi.encode(&public_inputs_map, return_value)?;
let proof = load_hex_data(&proof_path)?;
Expand Down