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

fix(nargo): restore nargo codegen-verifier functionality #1185

Merged
merged 1 commit into from
Apr 20, 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
6 changes: 4 additions & 2 deletions crates/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::fs::{create_named_dir, write_to_file};
use super::NargoConfig;
use crate::{cli::compile_cmd::compile_circuit, constants::CONTRACT_DIR, errors::CliError};
use acvm::SmartContract;
use clap::Args;
use nargo::ops::{codegen_verifier, preprocess_program};
use nargo::ops::preprocess_program;
use noirc_driver::CompileOptions;

/// Generates a Solidity verifier smart contract for the program
Expand All @@ -18,7 +19,8 @@ pub(crate) fn run(args: CodegenVerifierCommand, config: NargoConfig) -> Result<(
let compiled_program = compile_circuit(&backend, &config.program_dir, &args.compile_options)?;
let preprocessed_program = preprocess_program(&backend, compiled_program)?;

let smart_contract_string = codegen_verifier(&backend, &preprocessed_program.verification_key)?;
#[allow(deprecated)]
let smart_contract_string = backend.eth_contract_from_cs(preprocessed_program.bytecode);

let contract_dir = config.program_dir.join(CONTRACT_DIR);
create_named_dir(&contract_dir, "contract");
Expand Down
33 changes: 33 additions & 0 deletions crates/nargo_cli/tests/codegen-verifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! This integration test aims to check that the `nargo codegen-verifier` will successfully create a
//! file containing a verifier for a simple program.

use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

use assert_fs::prelude::{PathAssert, PathChild};

#[test]
fn simple_verifier_codegen() {
let test_dir = assert_fs::TempDir::new().unwrap();
std::env::set_current_dir(&test_dir).unwrap();

// Create trivial program
let project_name = "hello_world";
let project_dir = test_dir.child(project_name);

let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("new").arg(project_name);
cmd.assert().success();

std::env::set_current_dir(&project_dir).unwrap();

// Run `nargo codegen-verifier`
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.arg("codegen-verifier");
cmd.assert()
.success()
.stdout(predicate::str::contains("Contract successfully created and located at"));

project_dir.child("contract").child("plonk_vk.sol").assert(predicate::path::is_file());
}