Skip to content
2 changes: 2 additions & 0 deletions tooling/backend_interface/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ mod gates;
mod info;
mod prove;
mod verify;
mod version;
mod write_vk;

pub(crate) use contract::ContractCommand;
pub(crate) use gates::GatesCommand;
pub(crate) use info::InfoCommand;
pub(crate) use prove::ProveCommand;
pub(crate) use verify::VerifyCommand;
pub(crate) use version::VersionCommand;
pub(crate) use write_vk::WriteVkCommand;

#[test]
Expand Down
29 changes: 29 additions & 0 deletions tooling/backend_interface/src/cli/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::path::Path;

use crate::BackendError;

use super::string_from_stderr;

/// VersionCommand will call the backend binary
/// to query installed version.
pub(crate) struct VersionCommand;

impl VersionCommand {
pub(crate) fn run(self, binary_path: &Path) -> Result<String, BackendError> {
let mut command = std::process::Command::new(binary_path);

command.arg("--version");

let output = command.output()?;
if output.status.success() {
match String::from_utf8(output.stdout) {
Ok(result) => Ok(result),
Err(_) => Err(BackendError::CommandFailed(
"Unexpected output from --version check.".to_owned(),
)),
}
} else {
Err(BackendError::CommandFailed(string_from_stderr(&output.stderr)))
}
}
}
15 changes: 15 additions & 0 deletions tooling/backend_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mod smart_contract;

use acvm::acir::circuit::Opcode;
use bb_abstraction_leaks::ACVM_BACKEND_BARRETENBERG;
use bb_abstraction_leaks::BACKEND_BARRETENBERG_SEARCH_STR;
use bb_abstraction_leaks::BB_VERSION;
use cli::VersionCommand;
pub use download::download_backend;

const BACKENDS_DIR: &str = ".nargo/backends";
Expand Down Expand Up @@ -104,6 +107,18 @@ impl Backend {
fn crs_directory(&self) -> PathBuf {
self.backend_directory().join("crs")
}

fn assert_correct_version(&self) {
let binary_path = self.binary_path();
if binary_path.to_string_lossy().contains(BACKEND_BARRETENBERG_SEARCH_STR) {
let version_result = VersionCommand.run(binary_path);
if let Ok(version_string) = version_result {
if version_string.as_str() != BB_VERSION {
println!("WARNING!: Configured backend version `{version_string}` is different from expected `{BB_VERSION}`");
}
}
}
}
}

pub struct BackendOpcodeSupport {
Expand Down
3 changes: 3 additions & 0 deletions tooling/backend_interface/src/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ impl Backend {
) -> Result<Vec<u8>, BackendError> {
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 = temp_directory.path().to_path_buf();

Expand Down Expand Up @@ -78,6 +80,7 @@ impl Backend {
is_recursive: bool,
) -> Result<bool, BackendError> {
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 = temp_directory.path().to_path_buf();
Expand Down
2 changes: 2 additions & 0 deletions tooling/backend_interface/src/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ impl Backend {
pub fn eth_contract(&self, circuit: &Circuit) -> Result<String, BackendError> {
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();

Expand Down
1 change: 1 addition & 0 deletions tooling/bb_abstraction_leaks/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn main() -> Result<(), String> {
};

println!("cargo:rustc-env=BB_BINARY_URL={}", get_bb_download_url(arch, os));
println!("cargo:rustc-env=BB_VERSION={}", VERSION);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions tooling/bb_abstraction_leaks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

use acvm::FieldElement;

pub const BACKEND_BARRETENBERG_SEARCH_STR: &str = "barretenberg";
pub const ACVM_BACKEND_BARRETENBERG: &str = "acvm-backend-barretenberg";
pub const BB_DOWNLOAD_URL: &str = env!("BB_BINARY_URL");
pub const BB_VERSION: &str = env!("BB_VERSION");

/// Embed the Solidity verifier file
const ULTRA_VERIFIER_CONTRACT: &str = include_str!("contract.sol");
Expand Down