diff --git a/Cargo.lock b/Cargo.lock index b3e0a2c00d6..c6fcfd24668 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,7 @@ dependencies = [ "serial_test", "tar", "tempfile", + "test-binary", "thiserror", ] diff --git a/crates/acvm_backend_barretenberg/Cargo.toml b/crates/acvm_backend_barretenberg/Cargo.toml index 55d71b54ba3..b925627615f 100644 --- a/crates/acvm_backend_barretenberg/Cargo.toml +++ b/crates/acvm_backend_barretenberg/Cargo.toml @@ -28,6 +28,7 @@ reqwest = { version = "0.11.16", default-features = false, features = [ [dev-dependencies] serial_test = "2.0.0" +test-binary = "3.0.1" [build-dependencies] build-target = "0.4.0" diff --git a/crates/acvm_backend_barretenberg/src/cli/contract.rs b/crates/acvm_backend_barretenberg/src/cli/contract.rs index 6189133a426..992e914e246 100644 --- a/crates/acvm_backend_barretenberg/src/cli/contract.rs +++ b/crates/acvm_backend_barretenberg/src/cli/contract.rs @@ -10,7 +10,6 @@ use crate::BackendError; /// to verify a proof. See acvm_interop/contract.sol for the /// remaining logic that is missing. pub(crate) struct ContractCommand { - pub(crate) verbose: bool, pub(crate) crs_path: PathBuf, pub(crate) vk_path: PathBuf, pub(crate) contract_path: PathBuf, @@ -29,10 +28,6 @@ impl ContractCommand { .arg("-o") .arg(self.contract_path); - if self.verbose { - command.arg("-v"); - } - let output = command.output().expect("Failed to execute command"); if output.status.success() { Ok(()) @@ -47,7 +42,7 @@ impl ContractCommand { fn contract_command() { use tempfile::tempdir; - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let bytecode_path = PathBuf::from("./src/1_mul.bytecode"); @@ -59,7 +54,6 @@ fn contract_command() { let crs_path = backend.backend_directory(); let write_vk_command = super::WriteVkCommand { - verbose: true, bytecode_path, vk_path_output: vk_path.clone(), is_recursive: false, @@ -68,7 +62,7 @@ fn contract_command() { assert!(write_vk_command.run(&backend.binary_path()).is_ok()); - let contract_command = ContractCommand { verbose: true, vk_path, crs_path, contract_path }; + let contract_command = ContractCommand { vk_path, crs_path, contract_path }; assert!(contract_command.run(&backend.binary_path()).is_ok()); drop(temp_directory); diff --git a/crates/acvm_backend_barretenberg/src/cli/gates.rs b/crates/acvm_backend_barretenberg/src/cli/gates.rs index f738cc54f05..ab904b5dbc6 100644 --- a/crates/acvm_backend_barretenberg/src/cli/gates.rs +++ b/crates/acvm_backend_barretenberg/src/cli/gates.rs @@ -54,7 +54,7 @@ impl GatesCommand { #[test] #[serial_test::serial] fn gate_command() { - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let bytecode_path = PathBuf::from("./src/1_mul.bytecode"); let crs_path = backend.backend_directory(); @@ -62,5 +62,6 @@ fn gate_command() { let gate_command = GatesCommand { crs_path, bytecode_path }; let output = gate_command.run(&backend.binary_path()).unwrap(); - assert_eq!(output, 2788); + // Mock backend always returns zero gates. + assert_eq!(output, 0); } diff --git a/crates/acvm_backend_barretenberg/src/cli/mod.rs b/crates/acvm_backend_barretenberg/src/cli/mod.rs index 032bd6b14e3..daad2f9b639 100644 --- a/crates/acvm_backend_barretenberg/src/cli/mod.rs +++ b/crates/acvm_backend_barretenberg/src/cli/mod.rs @@ -17,12 +17,13 @@ pub(crate) use write_vk::WriteVkCommand; fn no_command_provided_works() { // This is a simple test to check that the binaries work - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let output = std::process::Command::new(backend.binary_path()) .output() .expect("Failed to execute command"); let stderr = String::from_utf8_lossy(&output.stderr); - assert_eq!(stderr, "No command provided.\n"); + // Assert help message is printed due to no command being provided. + assert!(stderr.contains("Usage: mock_backend ")); } diff --git a/crates/acvm_backend_barretenberg/src/cli/prove.rs b/crates/acvm_backend_barretenberg/src/cli/prove.rs index 08ad03b17d9..653db87bb39 100644 --- a/crates/acvm_backend_barretenberg/src/cli/prove.rs +++ b/crates/acvm_backend_barretenberg/src/cli/prove.rs @@ -10,7 +10,6 @@ use crate::BackendError; /// /// The proof will be written to the specified output file. pub(crate) struct ProveCommand { - pub(crate) verbose: bool, pub(crate) crs_path: PathBuf, pub(crate) is_recursive: bool, pub(crate) bytecode_path: PathBuf, @@ -33,9 +32,6 @@ impl ProveCommand { .arg("-o") .arg(self.proof_path); - if self.verbose { - command.arg("-v"); - } if self.is_recursive { command.arg("-r"); } @@ -54,7 +50,7 @@ impl ProveCommand { fn prove_command() { use tempfile::tempdir; - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let bytecode_path = PathBuf::from("./src/1_mul.bytecode"); let witness_path = PathBuf::from("./src/witness.tr"); @@ -63,14 +59,8 @@ fn prove_command() { let proof_path = temp_directory.path().join("1_mul").with_extension("proof"); let crs_path = backend.backend_directory(); - let prove_command = ProveCommand { - verbose: true, - crs_path, - bytecode_path, - witness_path, - is_recursive: false, - proof_path, - }; + let prove_command = + ProveCommand { crs_path, bytecode_path, witness_path, is_recursive: false, proof_path }; let proof_created = prove_command.run(&backend.binary_path()); assert!(proof_created.is_ok()); diff --git a/crates/acvm_backend_barretenberg/src/cli/verify.rs b/crates/acvm_backend_barretenberg/src/cli/verify.rs index d6e8aa52443..74d0f7cbb1e 100644 --- a/crates/acvm_backend_barretenberg/src/cli/verify.rs +++ b/crates/acvm_backend_barretenberg/src/cli/verify.rs @@ -3,7 +3,6 @@ use std::path::{Path, PathBuf}; /// VerifyCommand will call the barretenberg binary /// to verify a proof pub(crate) struct VerifyCommand { - pub(crate) verbose: bool, pub(crate) crs_path: PathBuf, pub(crate) is_recursive: bool, pub(crate) proof_path: PathBuf, @@ -23,9 +22,6 @@ impl VerifyCommand { .arg("-k") .arg(self.vk_path); - if self.verbose { - command.arg("-v"); - } if self.is_recursive { command.arg("-r"); } @@ -44,7 +40,7 @@ fn verify_command() { use super::{ProveCommand, WriteVkCommand}; - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let bytecode_path = PathBuf::from("./src/1_mul.bytecode"); let witness_path = PathBuf::from("./src/witness.tr"); @@ -57,7 +53,6 @@ fn verify_command() { let crs_path = backend.backend_directory(); let write_vk_command = WriteVkCommand { - verbose: true, bytecode_path: bytecode_path.clone(), crs_path: crs_path.clone(), is_recursive: false, @@ -68,7 +63,6 @@ fn verify_command() { assert!(vk_written.is_ok()); let prove_command = ProveCommand { - verbose: true, crs_path: crs_path.clone(), is_recursive: false, bytecode_path, @@ -77,13 +71,8 @@ fn verify_command() { }; prove_command.run(&backend.binary_path()).unwrap(); - let verify_command = VerifyCommand { - verbose: true, - crs_path, - is_recursive: false, - proof_path, - vk_path: vk_path_output, - }; + let verify_command = + VerifyCommand { crs_path, is_recursive: false, proof_path, vk_path: vk_path_output }; let verified = verify_command.run(&backend.binary_path()); assert!(verified); diff --git a/crates/acvm_backend_barretenberg/src/cli/write_vk.rs b/crates/acvm_backend_barretenberg/src/cli/write_vk.rs index 839b85d8fa6..2c9fbaa5104 100644 --- a/crates/acvm_backend_barretenberg/src/cli/write_vk.rs +++ b/crates/acvm_backend_barretenberg/src/cli/write_vk.rs @@ -5,7 +5,6 @@ use crate::BackendError; /// WriteCommand will call the barretenberg binary /// to write a verification key to a file pub(crate) struct WriteVkCommand { - pub(crate) verbose: bool, pub(crate) crs_path: PathBuf, pub(crate) is_recursive: bool, pub(crate) bytecode_path: PathBuf, @@ -25,9 +24,6 @@ impl WriteVkCommand { .arg("-o") .arg(self.vk_path_output); - if self.verbose { - command.arg("-v"); - } if self.is_recursive { command.arg("-r"); } @@ -46,7 +42,7 @@ impl WriteVkCommand { fn write_vk_command() { use tempfile::tempdir; - let backend = crate::get_bb(); + let backend = crate::get_mock_backend(); let bytecode_path = PathBuf::from("./src/1_mul.bytecode"); @@ -55,13 +51,8 @@ fn write_vk_command() { let crs_path = backend.backend_directory(); - let write_vk_command = WriteVkCommand { - verbose: true, - bytecode_path, - crs_path, - is_recursive: false, - vk_path_output, - }; + let write_vk_command = + WriteVkCommand { bytecode_path, crs_path, is_recursive: false, vk_path_output }; let vk_written = write_vk_command.run(&backend.binary_path()); assert!(vk_written.is_ok()); diff --git a/crates/acvm_backend_barretenberg/src/lib.rs b/crates/acvm_backend_barretenberg/src/lib.rs index f49016f237d..88b096e00fd 100644 --- a/crates/acvm_backend_barretenberg/src/lib.rs +++ b/crates/acvm_backend_barretenberg/src/lib.rs @@ -16,10 +16,17 @@ pub fn backends_directory() -> PathBuf { } #[cfg(test)] -fn get_bb() -> Backend { - let bb = Backend::new("acvm-backend-barretenberg".to_string()); - crate::assert_binary_exists(&bb); - bb +test_binary::build_test_binary_once!(mock_backend, "test-binaries"); + +#[cfg(test)] +fn get_mock_backend() -> Backend { + std::env::set_var("NARGO_BACKEND_PATH", path_to_mock_backend()); + + let mock_backend = Backend::new("mock_backend".to_string()); + if !mock_backend.binary_path().is_file() { + panic!("Mock backend binary does not exist at expected path"); + } + mock_backend } fn assert_binary_exists(backend: &Backend) -> PathBuf { diff --git a/crates/acvm_backend_barretenberg/src/proof_system.rs b/crates/acvm_backend_barretenberg/src/proof_system.rs index 75f058bdb33..b3e4806e426 100644 --- a/crates/acvm_backend_barretenberg/src/proof_system.rs +++ b/crates/acvm_backend_barretenberg/src/proof_system.rs @@ -81,7 +81,6 @@ impl Backend { let binary_path = assert_binary_exists(self); // Create proof and store it in the specified path ProveCommand { - verbose: true, crs_path: self.crs_directory(), is_recursive, bytecode_path, @@ -140,7 +139,6 @@ impl Backend { let binary_path = assert_binary_exists(self); WriteVkCommand { - verbose: false, crs_path: self.crs_directory(), is_recursive, bytecode_path, @@ -149,14 +147,9 @@ impl Backend { .run(&binary_path)?; // Verify the proof - let valid_proof = VerifyCommand { - verbose: false, - crs_path: self.crs_directory(), - is_recursive, - proof_path, - vk_path, - } - .run(&binary_path); + let valid_proof = + VerifyCommand { crs_path: self.crs_directory(), is_recursive, proof_path, vk_path } + .run(&binary_path); Ok(valid_proof) } diff --git a/crates/acvm_backend_barretenberg/src/smart_contract.rs b/crates/acvm_backend_barretenberg/src/smart_contract.rs index 6e2f3cf276b..af2acae830d 100644 --- a/crates/acvm_backend_barretenberg/src/smart_contract.rs +++ b/crates/acvm_backend_barretenberg/src/smart_contract.rs @@ -26,7 +26,6 @@ impl Backend { let binary_path = assert_binary_exists(self); WriteVkCommand { - verbose: false, crs_path: self.crs_directory(), is_recursive: false, bytecode_path, @@ -36,7 +35,6 @@ impl Backend { let contract_path = temp_directory_path.join("contract"); ContractCommand { - verbose: false, crs_path: self.crs_directory(), vk_path, contract_path: contract_path.clone(), @@ -60,7 +58,7 @@ mod tests { native_types::{Expression, Witness}, }; - use crate::get_bb; + use crate::get_mock_backend; #[test] #[serial_test::serial] @@ -77,7 +75,7 @@ mod tests { assert_messages: Default::default(), }; - let contract = get_bb().eth_contract(&circuit).unwrap(); + let contract = get_mock_backend().eth_contract(&circuit).unwrap(); assert!(contract.contains("contract BaseUltraVerifier")); assert!(contract.contains("contract UltraVerifier")); diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.lock b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.lock new file mode 100644 index 00000000000..c43d1b84915 --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.lock @@ -0,0 +1,306 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "clap" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + +[[package]] +name = "mock_backend" +version = "0.1.0" +dependencies = [ + "clap", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustix" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/crates/nargo_cli/test-binaries/mock_backend/Cargo.toml b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.toml similarity index 78% rename from crates/nargo_cli/test-binaries/mock_backend/Cargo.toml rename to crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.toml index 25528c7a6af..f527b03a7b9 100644 --- a/crates/nargo_cli/test-binaries/mock_backend/Cargo.toml +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/Cargo.toml @@ -8,3 +8,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.3.19", features = ["derive"] } diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/contract_cmd.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/contract_cmd.rs new file mode 100644 index 00000000000..3ef3b4b47ff --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/contract_cmd.rs @@ -0,0 +1,24 @@ +use clap::Args; +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::fs::write( + args.contract_path, + "contract BaseUltraVerifier contract UltraVerifier library UltraVerificationKey", + ) + .unwrap(); +} diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/gates_cmd.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/gates_cmd.rs new file mode 100644 index 00000000000..3cc397d3292 --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/gates_cmd.rs @@ -0,0 +1,18 @@ +use clap::Args; +use std::io::Write; +use std::path::PathBuf; + +#[derive(Debug, Clone, Args)] +pub(crate) struct GatesCommand { + #[clap(short = 'c')] + pub(crate) crs_path: Option, + + #[clap(short = 'b')] + pub(crate) bytecode_path: PathBuf, +} + +pub(crate) fn run(args: GatesCommand) { + assert!(args.bytecode_path.is_file(), "Could not find bytecode file at provided path"); + + std::io::stdout().write_all(&0u64.to_le_bytes()).unwrap(); +} diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/main.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/main.rs new file mode 100644 index 00000000000..74ea82d28f8 --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/main.rs @@ -0,0 +1,41 @@ +#![forbid(unsafe_code)] +#![warn(unreachable_pub)] +#![warn(clippy::semicolon_if_nothing_returned)] +#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] + +use clap::{Parser, Subcommand}; + +mod contract_cmd; +mod gates_cmd; +mod prove_cmd; +mod verify_cmd; +mod write_vk_cmd; + +#[derive(Parser, Debug)] +#[command(name = "mock_backend")] +struct BackendCli { + #[command(subcommand)] + command: BackendCommand, +} + +#[derive(Subcommand, Clone, Debug)] +enum BackendCommand { + Contract(contract_cmd::ContractCommand), + Gates(gates_cmd::GatesCommand), + Prove(prove_cmd::ProveCommand), + Verify(verify_cmd::VerifyCommand), + #[command(name = "write_vk")] + WriteVk(write_vk_cmd::WriteVkCommand), +} + +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), + BackendCommand::WriteVk(args) => write_vk_cmd::run(args), + }; +} diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/prove_cmd.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/prove_cmd.rs new file mode 100644 index 00000000000..bf53b9e694c --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/prove_cmd.rs @@ -0,0 +1,24 @@ +use clap::Args; +use std::path::PathBuf; + +#[derive(Debug, Clone, Args)] +pub(crate) struct ProveCommand { + #[clap(short = 'c')] + pub(crate) crs_path: Option, + + #[clap(short = 'b')] + pub(crate) bytecode_path: PathBuf, + + #[clap(short = 'w')] + pub(crate) witness_path: PathBuf, + + #[clap(short = 'o')] + pub(crate) proof_path: PathBuf, +} + +pub(crate) fn run(args: ProveCommand) { + assert!(args.bytecode_path.is_file(), "Could not find bytecode file at provided path"); + assert!(args.witness_path.is_file(), "Could not find witness file at provided path"); + + std::fs::write(args.proof_path, "proof").unwrap(); +} diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/verify_cmd.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/verify_cmd.rs new file mode 100644 index 00000000000..1a715eea880 --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/verify_cmd.rs @@ -0,0 +1,24 @@ +use clap::Args; +use std::path::PathBuf; + +#[derive(Debug, Clone, Args)] +pub(crate) struct VerifyCommand { + #[clap(short = 'c')] + pub(crate) crs_path: Option, + + #[clap(short = 'p')] + pub(crate) proof_path: PathBuf, + + #[clap(short = 'k')] + pub(crate) vk_path: PathBuf, + + #[clap(short = 'r')] + pub(crate) is_recursive: bool, +} + +pub(crate) fn run(args: VerifyCommand) { + assert!(args.vk_path.is_file(), "Could not find verification key file at provided path"); + assert!(args.proof_path.is_file(), "Could not find proof file at provided path"); + + std::fs::write(args.proof_path, "proof").unwrap(); +} diff --git a/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/write_vk_cmd.rs b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/write_vk_cmd.rs new file mode 100644 index 00000000000..495aae27fc8 --- /dev/null +++ b/crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/write_vk_cmd.rs @@ -0,0 +1,23 @@ +use clap::Args; +use std::path::PathBuf; + +#[derive(Debug, Clone, Args)] +pub(crate) struct WriteVkCommand { + #[clap(short = 'c')] + pub(crate) crs_path: Option, + + #[clap(short = 'b')] + pub(crate) bytecode_path: PathBuf, + + #[clap(short = 'r')] + pub(crate) is_recursive: bool, + + #[clap(short = 'o')] + pub(crate) vk_path: PathBuf, +} + +pub(crate) fn run(args: WriteVkCommand) { + assert!(args.bytecode_path.is_file(), "Could not find bytecode file at provided path"); + + std::fs::write(args.vk_path, "vk").unwrap(); +} diff --git a/crates/nargo_cli/test-binaries/mock_backend/Cargo.lock b/crates/nargo_cli/test-binaries/mock_backend/Cargo.lock deleted file mode 100644 index fd23780289a..00000000000 --- a/crates/nargo_cli/test-binaries/mock_backend/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "mock_backend" -version = "0.1.0" diff --git a/crates/nargo_cli/test-binaries/mock_backend/src/main.rs b/crates/nargo_cli/test-binaries/mock_backend/src/main.rs deleted file mode 100644 index 3d2cd9f79b0..00000000000 --- a/crates/nargo_cli/test-binaries/mock_backend/src/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![forbid(unsafe_code)] -#![warn(unreachable_pub)] -#![warn(clippy::semicolon_if_nothing_returned)] -#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] - -use std::io::Write; - -fn main() { - std::io::stdout().write_all(&0u64.to_be_bytes()).unwrap(); -} diff --git a/crates/nargo_cli/tests/execute.rs b/crates/nargo_cli/tests/execute.rs index 664e9ad6a39..e098f370832 100644 --- a/crates/nargo_cli/tests/execute.rs +++ b/crates/nargo_cli/tests/execute.rs @@ -13,7 +13,10 @@ mod tests { use super::*; - test_binary::build_test_binary_once!(mock_backend, "test-binaries"); + test_binary::build_test_binary_once!( + mock_backend, + "../acvm_backend_barretenberg/test-binaries" + ); // include tests generated by `build.rs` include!(concat!(env!("OUT_DIR"), "/execute.rs"));