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 @@ -6,13 +6,15 @@ mod info;
mod prove;
mod verify;
mod write_vk;
mod version;

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 write_vk::WriteVkCommand;
pub(crate) use version::VersionCommand;

#[test]
fn no_command_provided_works() -> Result<(), crate::BackendError> {
Expand Down
28 changes: 28 additions & 0 deletions tooling/backend_interface/src/cli/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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)))
}
}
}
11 changes: 11 additions & 0 deletions tooling/backend_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod smart_contract;

use acvm::acir::circuit::Opcode;
use bb_abstraction_leaks::ACVM_BACKEND_BARRETENBERG;
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 +106,15 @@ impl Backend {
fn crs_directory(&self) -> PathBuf {
self.backend_directory().join("crs")
}

fn assert_correct_version(&self) -> Result<String, BackendError> {
let binary_path = self.binary_path();
let version_string = VersionCommand{}.run(binary_path)?;
if version_string.as_str() != BB_VERSION {
println!("WARNING!: Configured backend version `{:}` is different from expected `{:}`", version_string, BB_VERSION);
}
Ok(version_string)
}
}

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
1 change: 1 addition & 0 deletions tooling/bb_abstraction_leaks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use acvm::FieldElement;

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