From 96b58f74273c5ff78aa31a54ced0c3fe0c984506 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 9 May 2024 23:14:09 +0000 Subject: [PATCH] chore!: remove `codegen-verifier` command --- .../backend_interface/src/cli/contract.rs | 71 ------------------- .../tooling/backend_interface/src/cli/mod.rs | 2 - .../tooling/backend_interface/src/lib.rs | 1 - .../backend_interface/src/smart_contract.rs | 55 -------------- .../mock_backend/src/contract_cmd.rs | 21 ------ .../test-binaries/mock_backend/src/main.rs | 3 - .../nargo_cli/src/cli/codegen_verifier_cmd.rs | 68 ------------------ .../tooling/nargo_cli/src/cli/mod.rs | 3 - .../nargo_cli/tests/codegen-verifier.rs | 37 ---------- 9 files changed, 261 deletions(-) delete mode 100644 noir/noir-repo/tooling/backend_interface/src/cli/contract.rs delete mode 100644 noir/noir-repo/tooling/backend_interface/src/smart_contract.rs delete mode 100644 noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/contract_cmd.rs delete mode 100644 noir/noir-repo/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs delete mode 100644 noir/noir-repo/tooling/nargo_cli/tests/codegen-verifier.rs diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/contract.rs b/noir/noir-repo/tooling/backend_interface/src/cli/contract.rs deleted file mode 100644 index 935b96b3ac4..00000000000 --- a/noir/noir-repo/tooling/backend_interface/src/cli/contract.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::path::{Path, PathBuf}; - -use crate::BackendError; - -use super::string_from_stderr; - -/// VerifyCommand will call the barretenberg binary -/// to return a solidity library with the verification key -/// that can be used to verify proofs on-chain. -/// -/// This does not return a Solidity file that is able -/// to verify a proof. See acvm_interop/contract.sol for the -/// remaining logic that is missing. -pub(crate) struct ContractCommand { - pub(crate) crs_path: PathBuf, - pub(crate) vk_path: PathBuf, -} - -impl ContractCommand { - pub(crate) fn run(self, binary_path: &Path) -> Result { - let mut command = std::process::Command::new(binary_path); - - command - .arg("contract") - .arg("-c") - .arg(self.crs_path) - .arg("-k") - .arg(self.vk_path) - .arg("-o") - .arg("-"); - - let output = command.output()?; - - if output.status.success() { - String::from_utf8(output.stdout) - .map_err(|error| BackendError::InvalidUTF8Vector(error.into_bytes())) - } else { - Err(BackendError::CommandFailed(string_from_stderr(&output.stderr))) - } - } -} - -#[test] -fn contract_command() -> Result<(), BackendError> { - use tempfile::tempdir; - - let backend = crate::get_mock_backend()?; - - let temp_directory = tempdir().expect("could not create a temporary directory"); - let temp_directory_path = temp_directory.path(); - let artifact_path = temp_directory_path.join("program.json"); - let vk_path = temp_directory_path.join("vk"); - - let crs_path = backend.backend_directory(); - - std::fs::File::create(&artifact_path).expect("file should be created"); - - let write_vk_command = super::WriteVkCommand { - artifact_path, - vk_path_output: vk_path.clone(), - crs_path: crs_path.clone(), - }; - write_vk_command.run(backend.binary_path())?; - - let contract_command = ContractCommand { vk_path, crs_path }; - contract_command.run(backend.binary_path())?; - - drop(temp_directory); - - Ok(()) -} diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs index 16a9517e129..ba084165e72 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs @@ -1,6 +1,5 @@ // Reference: https://github.com/AztecProtocol/aztec-packages/blob/master/barretenberg/cpp/src/barretenberg/bb/main.cpp -mod contract; mod gates; mod proof_as_fields; mod prove; @@ -9,7 +8,6 @@ mod version; mod vk_as_fields; mod write_vk; -pub(crate) use contract::ContractCommand; pub(crate) use gates::GatesCommand; pub(crate) use proof_as_fields::ProofAsFieldsCommand; pub(crate) use prove::ProveCommand; diff --git a/noir/noir-repo/tooling/backend_interface/src/lib.rs b/noir/noir-repo/tooling/backend_interface/src/lib.rs index eab98852555..f0499548818 100644 --- a/noir/noir-repo/tooling/backend_interface/src/lib.rs +++ b/noir/noir-repo/tooling/backend_interface/src/lib.rs @@ -6,7 +6,6 @@ use std::path::PathBuf; mod cli; mod download; mod proof_system; -mod smart_contract; pub use bb_abstraction_leaks::ACVM_BACKEND_BARRETENBERG; use bb_abstraction_leaks::BB_VERSION; diff --git a/noir/noir-repo/tooling/backend_interface/src/smart_contract.rs b/noir/noir-repo/tooling/backend_interface/src/smart_contract.rs deleted file mode 100644 index 8b26ea07a2f..00000000000 --- a/noir/noir-repo/tooling/backend_interface/src/smart_contract.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::path::PathBuf; - -use crate::{ - cli::{ContractCommand, WriteVkCommand}, - Backend, BackendError, -}; -use tempfile::tempdir; - -impl Backend { - pub fn eth_contract(&self, artifact_path: PathBuf) -> Result { - let binary_path = self.assert_binary_exists()?; - self.assert_correct_version()?; - - let temp_directory = tempdir().expect("could not create a temporary directory"); - let temp_directory_path = temp_directory.path().to_path_buf(); - - // Create the verification key and write it to the specified path - let vk_path = temp_directory_path.join("vk"); - - WriteVkCommand { - crs_path: self.crs_directory(), - artifact_path, - vk_path_output: vk_path.clone(), - } - .run(binary_path)?; - - ContractCommand { crs_path: self.crs_directory(), vk_path }.run(binary_path) - } -} - -#[cfg(test)] -mod tests { - - use serde_json::json; - use tempfile::tempdir; - - use crate::{get_mock_backend, proof_system::write_to_file, BackendError}; - - #[test] - fn test_smart_contract() -> Result<(), BackendError> { - let dummy_artifact = json!({"bytecode": ""}); - let artifact_bytes = serde_json::to_vec(&dummy_artifact).unwrap(); - - let temp_directory = tempdir().expect("could not create a temporary directory"); - let temp_directory_path = temp_directory.path(); - let artifact_path = temp_directory_path.join("program.json"); - write_to_file(&artifact_bytes, &artifact_path); - - let contract = get_mock_backend()?.eth_contract(artifact_path)?; - - assert!(contract.contains("contract VerifierContract")); - - Ok(()) - } -} diff --git a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/contract_cmd.rs b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/contract_cmd.rs deleted file mode 100644 index 7ee41121d61..00000000000 --- a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/contract_cmd.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clap::Args; -use std::io::Write; -use std::path::PathBuf; - -#[derive(Debug, Clone, Args)] -pub(crate) struct ContractCommand { - #[clap(short = 'c')] - pub(crate) crs_path: Option, - - #[clap(short = 'k')] - pub(crate) vk_path: PathBuf, - - #[clap(short = 'o')] - pub(crate) contract_path: PathBuf, -} - -pub(crate) fn run(args: ContractCommand) { - assert!(args.vk_path.is_file(), "Could not find vk file at provided path"); - - std::io::stdout().write_all(b"contract VerifierContract {}").unwrap(); -} diff --git a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/main.rs b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/main.rs index 74ea82d28f8..166f59b5a3b 100644 --- a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/main.rs +++ b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/main.rs @@ -5,7 +5,6 @@ use clap::{Parser, Subcommand}; -mod contract_cmd; mod gates_cmd; mod prove_cmd; mod verify_cmd; @@ -20,7 +19,6 @@ struct BackendCli { #[derive(Subcommand, Clone, Debug)] enum BackendCommand { - Contract(contract_cmd::ContractCommand), Gates(gates_cmd::GatesCommand), Prove(prove_cmd::ProveCommand), Verify(verify_cmd::VerifyCommand), @@ -32,7 +30,6 @@ fn main() { let BackendCli { command } = BackendCli::parse(); match command { - BackendCommand::Contract(args) => contract_cmd::run(args), BackendCommand::Gates(args) => gates_cmd::run(args), BackendCommand::Prove(args) => prove_cmd::run(args), BackendCommand::Verify(args) => verify_cmd::run(args), diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs deleted file mode 100644 index 6247560f621..00000000000 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ /dev/null @@ -1,68 +0,0 @@ -use super::compile_cmd::compile_workspace_full; -use super::fs::{create_named_dir, write_to_file}; -use super::NargoConfig; -use crate::backends::Backend; -use crate::cli::fs::program::read_program_from_file; -use crate::errors::CliError; - -use clap::Args; -use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; -use noirc_driver::{CompileOptions, NOIR_ARTIFACT_VERSION_STRING}; -use noirc_frontend::graph::CrateName; - -/// Generates a Solidity verifier smart contract for the program -#[derive(Debug, Clone, Args)] -pub(crate) struct CodegenVerifierCommand { - /// The name of the package to codegen - #[clap(long, conflicts_with = "workspace")] - package: Option, - - /// Codegen all packages in the workspace - #[clap(long, conflicts_with = "package")] - workspace: bool, - - #[clap(flatten)] - compile_options: CompileOptions, -} - -pub(crate) fn run( - backend: &Backend, - args: CodegenVerifierCommand, - config: NargoConfig, -) -> Result<(), CliError> { - let toml_path = get_package_manifest(&config.program_dir)?; - let default_selection = - if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; - let selection = args.package.map_or(default_selection, PackageSelection::Selected); - let workspace = resolve_workspace_from_toml( - &toml_path, - selection, - Some(NOIR_ARTIFACT_VERSION_STRING.to_string()), - )?; - - // Compile the full workspace in order to generate any build artifacts. - compile_workspace_full(&workspace, &args.compile_options)?; - - let binary_packages = workspace.into_iter().filter(|package| package.is_binary()); - for package in binary_packages { - let program_artifact_path = workspace.package_build_path(package); - let program = read_program_from_file(&program_artifact_path)?; - - // TODO(https://github.com/noir-lang/noir/issues/4428): - // We do not expect to have a smart contract verifier for a foldable program with multiple circuits. - // However, in the future we can expect to possibly have non-inlined ACIR functions during compilation - // that will be inlined at a later step such as by the ACVM compiler or by the backend. - // Add appropriate handling here once the compiler enables multiple ACIR functions. - assert_eq!(program.bytecode.functions.len(), 1); - let smart_contract_string = backend.eth_contract(program_artifact_path)?; - - let contract_dir = workspace.contracts_directory_path(package); - create_named_dir(&contract_dir, "contract"); - let contract_path = contract_dir.join("plonk_vk").with_extension("sol"); - - let path = write_to_file(smart_contract_string.as_bytes(), &contract_path); - println!("[{}] Contract successfully created and located at {path}", package.name); - } - - Ok(()) -} diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/mod.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/mod.rs index ad778549ac0..b19bec2b83c 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/mod.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/mod.rs @@ -12,7 +12,6 @@ mod fs; mod backend_cmd; mod check_cmd; -mod codegen_verifier_cmd; mod compile_cmd; mod dap_cmd; mod debug_cmd; @@ -63,7 +62,6 @@ enum NargoCommand { Backend(backend_cmd::BackendCommand), Check(check_cmd::CheckCommand), Fmt(fmt_cmd::FormatCommand), - CodegenVerifier(codegen_verifier_cmd::CodegenVerifierCommand), #[command(alias = "build")] Compile(compile_cmd::CompileCommand), New(new_cmd::NewCommand), @@ -118,7 +116,6 @@ pub(crate) fn start_cli() -> eyre::Result<()> { NargoCommand::Verify(args) => verify_cmd::run(&backend, args, config), NargoCommand::Test(args) => test_cmd::run(args, config), NargoCommand::Info(args) => info_cmd::run(&backend, args, config), - NargoCommand::CodegenVerifier(args) => codegen_verifier_cmd::run(&backend, args, config), NargoCommand::Backend(args) => backend_cmd::run(args), NargoCommand::Lsp(args) => lsp_cmd::run(args, config), NargoCommand::Dap(args) => dap_cmd::run(args, config), diff --git a/noir/noir-repo/tooling/nargo_cli/tests/codegen-verifier.rs b/noir/noir-repo/tooling/nargo_cli/tests/codegen-verifier.rs deleted file mode 100644 index f991f72b108..00000000000 --- a/noir/noir-repo/tooling/nargo_cli/tests/codegen-verifier.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! 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("hello_world") - .child("plonk_vk.sol") - .assert(predicate::path::is_file()); -}