From 3b8e44df9b48d5bcac65fa2ef9cb48485d34daa3 Mon Sep 17 00:00:00 2001 From: dante <45801863+alexander-camuto@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:35:37 +0000 Subject: [PATCH] chore: version mismatch warnings for artifacts --- src/graph/mod.rs | 19 ++++++++++++++++--- src/lib.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/graph/mod.rs b/src/graph/mod.rs index b5f52f569..e36dc75e7 100644 --- a/src/graph/mod.rs +++ b/src/graph/mod.rs @@ -280,7 +280,13 @@ impl GraphWitness { })?; let reader = std::io::BufReader::with_capacity(*EZKL_BUF_CAPACITY, file); - serde_json::from_reader(reader).map_err(|e| e.into()) + let witness: GraphWitness = + serde_json::from_reader(reader).map_err(|e| Into::::into(e))?; + + // check versions match + crate::check_version_string_matches(witness.version.as_deref().unwrap_or("")); + + Ok(witness) } /// Save the model input to a file @@ -572,10 +578,14 @@ impl GraphSettings { // buf reader let reader = std::io::BufReader::with_capacity(*EZKL_BUF_CAPACITY, std::fs::File::open(path)?); - serde_json::from_reader(reader).map_err(|e| { + let settings: GraphSettings = serde_json::from_reader(reader).map_err(|e| { error!("failed to load settings file at {}", e); std::io::Error::new(std::io::ErrorKind::Other, e) - }) + })?; + + crate::check_version_string_matches(&settings.version); + + Ok(settings) } /// Export the ezkl configuration as json @@ -697,6 +707,9 @@ impl GraphCircuit { let reader = std::io::BufReader::with_capacity(*EZKL_BUF_CAPACITY, f); let result: GraphCircuit = bincode::deserialize_from(reader)?; + // check the versions matche + crate::check_version_string_matches(&result.core.settings.version); + Ok(result) } } diff --git a/src/lib.rs b/src/lib.rs index 69752a804..383221828 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -420,3 +420,30 @@ where let b = s[pos + 2..].parse()?; Ok((a, b)) } + +/// Check if the version string matches the artifact version +/// If the version string does not match the artifact version, log a warning +pub fn check_version_string_matches(artifact_version: &str) { + if artifact_version == "0.0.0" + || artifact_version == "source - no compatibility guaranteed" + || artifact_version.is_empty() + { + log::warn!("Artifact version is 0.0.0, skipping version check"); + return; + } + + let version = crate::version(); + + if version == "source - no compatibility guaranteed" { + log::warn!("Compiled source version is not guaranteed to match artifact version"); + return; + } + + if version != artifact_version { + log::warn!( + "Version mismatch: CLI version is {} but artifact version is {}", + version, + artifact_version + ); + } +}