diff --git a/tooling/backend_interface/src/lib.rs b/tooling/backend_interface/src/lib.rs index 6c91c181a92..36ebe5ebb91 100644 --- a/tooling/backend_interface/src/lib.rs +++ b/tooling/backend_interface/src/lib.rs @@ -153,6 +153,34 @@ impl BackendOpcodeSupport { } } } + + pub fn all() -> BackendOpcodeSupport { + BackendOpcodeSupport { + opcodes: HashSet::from([ + "arithmetic".to_string(), + "directive".to_string(), + "brillig".to_string(), + "memory_init".to_string(), + "memory_op".to_string(), + ]), + black_box_functions: HashSet::from([ + "sha256".to_string(), + "schnorr_verify".to_string(), + "blake2s".to_string(), + "pedersen".to_string(), + "pedersen_hash".to_string(), + "hash_to_field_128_security".to_string(), + "ecdsa_secp256k1".to_string(), + "fixed_base_scalar_mul".to_string(), + "and".to_string(), + "xor".to_string(), + "range".to_string(), + "keccak256".to_string(), + "recursive_aggregation".to_string(), + "ecdsa_secp256r1".to_string(), + ]), + } + } } #[cfg(test)] diff --git a/tooling/backend_interface/src/proof_system.rs b/tooling/backend_interface/src/proof_system.rs index 95da1462d4e..dcf1dad56b0 100644 --- a/tooling/backend_interface/src/proof_system.rs +++ b/tooling/backend_interface/src/proof_system.rs @@ -36,6 +36,18 @@ impl Backend { InfoCommand { crs_path: self.crs_directory() }.run(binary_path) } + /// If we cannot get a valid backend, returns the default backend which supports all the opcodes + /// and uses Plonk with width 3 + /// The function also prints a message saying we could not find a backend + pub fn get_backend_info_or_default(&self) -> (Language, BackendOpcodeSupport) { + if let Ok(backend_info) = self.get_backend_info() { + (backend_info.0, backend_info.1) + } else { + println!("No valid backend found, defaulting to Plonk with width 3 and all opcodes supported"); + (Language::PLONKCSat { width: 3 }, BackendOpcodeSupport::all()) + } + } + pub fn prove( &self, circuit: &Circuit, diff --git a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs index 59143526b24..02c83adb59a 100644 --- a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -6,8 +6,8 @@ use super::{ use crate::backends::Backend; use crate::errors::CliError; -use acvm::acir::circuit::Opcode; use acvm::Language; +use backend_interface::BackendOpcodeSupport; use bb_abstraction_leaks::ACVM_BACKEND_BARRETENBERG; use clap::Args; use nargo::package::Package; @@ -54,7 +54,7 @@ pub(crate) fn run( package, &args.compile_options, np_language, - &|opcode| opcode_support.is_opcode_supported(opcode), + &opcode_support, )?; let contract_dir = workspace.contracts_directory_path(package); @@ -74,15 +74,10 @@ fn smart_contract_for_package( package: &Package, compile_options: &CompileOptions, np_language: Language, - is_opcode_supported: &impl Fn(&Opcode) -> bool, + opcode_support: &BackendOpcodeSupport, ) -> Result { - let program = compile_bin_package( - workspace, - package, - compile_options, - np_language, - &is_opcode_supported, - )?; + let program = + compile_bin_package(workspace, package, compile_options, np_language, opcode_support)?; let mut smart_contract_string = backend.eth_contract(&program.circuit)?; diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 9ffbc26828e..69533292bbd 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -76,7 +76,7 @@ pub(crate) fn run( .cloned() .partition(|package| package.is_binary()); - let (np_language, opcode_support) = backend.get_backend_info()?; + let (np_language, opcode_support) = backend.get_backend_info_or_default(); let (_, compiled_contracts) = compile_workspace( &workspace, &binary_packages, @@ -102,12 +102,11 @@ pub(super) fn compile_workspace( opcode_support: &BackendOpcodeSupport, compile_options: &CompileOptions, ) -> Result<(Vec, Vec), CliError> { - let is_opcode_supported = |opcode: &_| opcode_support.is_opcode_supported(opcode); - // Compile all of the packages in parallel. let program_results: Vec<(FileManager, CompilationResult)> = binary_packages .par_iter() .map(|package| { + let is_opcode_supported = |opcode: &_| opcode_support.is_opcode_supported(opcode); compile_program(workspace, package, compile_options, np_language, &is_opcode_supported) }) .collect(); @@ -115,6 +114,7 @@ pub(super) fn compile_workspace( contract_packages .par_iter() .map(|package| { + let is_opcode_supported = |opcode: &_| opcode_support.is_opcode_supported(opcode); compile_contract(package, compile_options, np_language, &is_opcode_supported) }) .collect(); @@ -151,14 +151,16 @@ pub(crate) fn compile_bin_package( package: &Package, compile_options: &CompileOptions, np_language: Language, - is_opcode_supported: &impl Fn(&Opcode) -> bool, + opcode_support: &BackendOpcodeSupport, ) -> Result { if package.is_library() { return Err(CompileError::LibraryCrate(package.name.clone()).into()); } let (file_manager, compilation_result) = - compile_program(workspace, package, compile_options, np_language, &is_opcode_supported); + compile_program(workspace, package, compile_options, np_language, &|opcode| { + opcode_support.is_opcode_supported(opcode) + }); let program = report_errors( compilation_result, diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index 1d344058312..0e7579b0721 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -56,10 +56,13 @@ pub(crate) fn run( return Ok(()); }; - let compiled_program = - compile_bin_package(&workspace, package, &args.compile_options, np_language, &|opcode| { - opcode_support.is_opcode_supported(opcode) - })?; + let compiled_program = compile_bin_package( + &workspace, + package, + &args.compile_options, + np_language, + &opcode_support, + )?; println!("[{}] Starting debugger", package.name); let (return_value, solved_witness) = diff --git a/tooling/nargo_cli/src/cli/execute_cmd.rs b/tooling/nargo_cli/src/cli/execute_cmd.rs index 91e4b800453..2f69b4c7df7 100644 --- a/tooling/nargo_cli/src/cli/execute_cmd.rs +++ b/tooling/nargo_cli/src/cli/execute_cmd.rs @@ -56,14 +56,14 @@ pub(crate) fn run( )?; let target_dir = &workspace.target_directory_path(); - let (np_language, opcode_support) = backend.get_backend_info()?; + let (np_language, opcode_support) = backend.get_backend_info_or_default(); for package in &workspace { let compiled_program = compile_bin_package( &workspace, package, &args.compile_options, np_language, - &|opcode| opcode_support.is_opcode_supported(opcode), + &opcode_support, )?; let (return_value, solved_witness) = diff --git a/tooling/nargo_cli/src/cli/info_cmd.rs b/tooling/nargo_cli/src/cli/info_cmd.rs index b1cd5f0b64f..b0f771bfc1c 100644 --- a/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/tooling/nargo_cli/src/cli/info_cmd.rs @@ -67,7 +67,7 @@ pub(crate) fn run( .cloned() .partition(|package| package.is_binary()); - let (np_language, opcode_support) = backend.get_backend_info()?; + let (np_language, opcode_support) = backend.get_backend_info_or_default(); let (compiled_programs, compiled_contracts) = compile_workspace( &workspace, &binary_packages, diff --git a/tooling/nargo_cli/src/cli/prove_cmd.rs b/tooling/nargo_cli/src/cli/prove_cmd.rs index 3586e73ff2e..54b148ec3a2 100644 --- a/tooling/nargo_cli/src/cli/prove_cmd.rs +++ b/tooling/nargo_cli/src/cli/prove_cmd.rs @@ -64,7 +64,7 @@ pub(crate) fn run( package, &args.compile_options, np_language, - &|opcode| opcode_support.is_opcode_supported(opcode), + &opcode_support, )?; prove_package( diff --git a/tooling/nargo_cli/src/cli/verify_cmd.rs b/tooling/nargo_cli/src/cli/verify_cmd.rs index 8c6d92b3d2f..2f8a6efbba4 100644 --- a/tooling/nargo_cli/src/cli/verify_cmd.rs +++ b/tooling/nargo_cli/src/cli/verify_cmd.rs @@ -55,7 +55,7 @@ pub(crate) fn run( package, &args.compile_options, np_language, - &|opcode| opcode_support.is_opcode_supported(opcode), + &opcode_support, )?; verify_package(backend, &workspace, package, program, &args.verifier_name)?;