diff --git a/crates/verify/src/etherscan/mod.rs b/crates/verify/src/etherscan/mod.rs index 60f8daf962adf..071d229a85468 100644 --- a/crates/verify/src/etherscan/mod.rs +++ b/crates/verify/src/etherscan/mod.rs @@ -317,7 +317,9 @@ impl EtherscanVerificationProvider { }; let compiler_version = if matches!(lang, ContractLanguage::Vyper) { - format!("vyper:{}", compiler_version.to_string().split('+').next().unwrap_or("0.0.0")) + let base = crate::utils::version_without_build(&compiler_version.to_string()); + let base = if base.is_empty() { "0.0.0".to_string() } else { base }; + format!("vyper:{}", base) } else { format!("v{}", ensure_solc_build_metadata(context.compiler_version.clone()).await?) }; diff --git a/crates/verify/src/utils.rs b/crates/verify/src/utils.rs index 8f24e67ebf3f1..be0078b4f0b35 100644 --- a/crates/verify/src/utils.rs +++ b/crates/verify/src/utils.rs @@ -59,6 +59,14 @@ pub struct JsonResult { pub message: Option, } +pub(crate) fn version_without_build(version: &str) -> Option<&str> { + version.split('+').next().filter(|s| !s.is_empty()) +} + +pub(crate) fn normalize_compiler_version_str(version: &str) -> String { + version_without_build(version).unwrap_or("").trim_start_matches('v').to_string() +} + pub fn match_bytecodes( local_bytecode: &[u8], bytecode: &[u8], @@ -113,8 +121,8 @@ pub fn build_using_cache( if version.starts_with("vyper:") { eyre::bail!("Vyper contracts are not supported") } - // Parse etherscan version string - let version = version.split('+').next().unwrap_or("").trim_start_matches('v').to_string(); + // Parse etherscan version string using a shared normalizer + let version = normalize_compiler_version_str(&version); // Check if `out/directory` name matches the contract name if key.ends_with(name.as_str()) {