Skip to content

Commit

Permalink
new api method + add test for zksync solc
Browse files Browse the repository at this point in the history
  • Loading branch information
elfedy committed Oct 11, 2024
1 parent cf32982 commit bc42775
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/verify/src/zk_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ZkVerificationContext {
let zksolc_version = ZkSolc::get_version_for_path(&project.compiler.zksolc)?;

let (solc_version, is_zksync_solc) = if let Some(solc) = &config.zksync.solc_path {
let solc_type_and_version = zksolc::get_solc_type_and_version(solc)?;
let solc_type_and_version = zksolc::get_solc_version_info(solc)?;
(solc_type_and_version.version, solc_type_and_version.zksync_version.is_some())
} else {
//if there's no `solc_path` specified then we use the same
Expand Down
42 changes: 19 additions & 23 deletions crates/zksync/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use foundry_compilers::{
artifacts::Severity,
error::SolcError,
solc::{Solc, SolcCompiler, SolcLanguage},
zksolc::{ZkSolc, ZkSolcCompiler, ZkSolcSettings},
zksolc::{get_solc_version_info, ZkSolc, ZkSolcCompiler, ZkSolcSettings},

Check failure on line 26 in crates/zksync/compiler/src/lib.rs

View workflow job for this annotation

GitHub Actions / zk-cargo-test

unresolved import `foundry_compilers::zksolc::get_solc_version_info`
zksync::artifact_output::zk::ZkArtifactOutput,
Project, ProjectBuilder, ProjectPathsConfig,
};
Expand Down Expand Up @@ -114,7 +114,7 @@ fn config_solc_compiler(config: &Config) -> Result<SolcCompiler, SolcError> {
if !path.is_file() {
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())))
}
let version = solc_version(path)?;
let version = get_solc_version_info(path)?.version;
let solc =
Solc::new_with_version(path, Version::new(version.major, version.minor, version.patch));
return Ok(SolcCompiler::Specific(solc))
Expand All @@ -141,7 +141,7 @@ fn config_solc_compiler(config: &Config) -> Result<SolcCompiler, SolcError> {
if !path.is_file() {
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())))
}
let version = solc_version(path)?;
let version = get_solc_version_info(path)?.version;
Solc::new_with_version(
path,
Version::new(version.major, version.minor, version.patch),
Expand Down Expand Up @@ -213,25 +213,21 @@ pub fn config_ensure_zksolc(
Ok(None)
}

/// Given a solc path, get the semver. Works for both solc an zkVm solc.
// TODO: Maybe move this to compilers and use it to identify if used binary is zkVm or not
fn solc_version(path: &Path) -> Result<Version, SolcError> {
let mut cmd = Command::new(path);
cmd.arg("--version").stdin(Stdio::piped()).stderr(Stdio::piped()).stdout(Stdio::piped());
debug!(?cmd, "getting Solc version");
let output = cmd.output().map_err(|e| SolcError::io(e, path))?;
trace!(?output);
if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
let version = stdout
.lines()
.filter(|l| !l.trim().is_empty())
.nth(1)
.ok_or_else(|| SolcError::msg("Version not found in Solc output"))?;
debug!(%version);
// NOTE: semver doesn't like `+` in g++ in build metadata which is invalid semver
Ok(Version::from_str(&version.trim_start_matches("Version: ").replace(".g++", ".gcc"))?)
} else {
Err(SolcError::solc_output(&output))
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn zksync_project_has_zksync_solc_when_solc_req_is_a_version() {
let config =
Config { solc: Some(SolcReq::Version(Version::new(0, 8, 26))), ..Default::default() };
let project = config_create_project(&config, false, true).unwrap();
let solc_compiler = project.compiler.solc;
if let SolcCompiler::Specific(path) = solc_compiler {
let version = get_solc_version_info(&path.solc).unwrap();
assert!(version.zksync_version.is_some());
} else {
panic!("Expected SolcCompiler::Specific");
}
}
}

0 comments on commit bc42775

Please sign in to comment.