diff --git a/crates/common/src/zksolc_manager.rs b/crates/common/src/zksolc_manager.rs index 7f44d29a3..fd86bbbd1 100644 --- a/crates/common/src/zksolc_manager.rs +++ b/crates/common/src/zksolc_manager.rs @@ -423,24 +423,34 @@ impl fmt::Display for ZkSolcManager { /// The function returns the `ZkSolcManager` if all steps are successful, or an error if any /// step fails. pub fn setup_zksolc_manager(zksolc_version: String) -> eyre::Result { - let zksolc_manager_opts = ZkSolcManagerOpts::new(zksolc_version); + let zksolc_manager_opts = ZkSolcManagerOpts::new(zksolc_version.clone()); let zksolc_manager_builder = ZkSolcManagerBuilder::new(zksolc_manager_opts); - let zksolc_manager = zksolc_manager_builder - .build() - .map_err(|e| eyre::eyre!("Error building zksolc_manager: {}", e))?; + let zksolc_manager = zksolc_manager_builder.build().map_err(|e| { + eyre::eyre!("Error initializing ZkSolcManager for version '{}': {}", zksolc_version, e) + })?; if let Err(err) = zksolc_manager.check_setup_compilers_dir() { - eyre::bail!("Failed to setup compilers directory: {}", err); + eyre::bail!("Failed to set up or access the ZkSolc compilers directory: {}", err); } if !zksolc_manager.exists() { + let download_url = zksolc_manager + .get_full_download_url() + .map(|url| url.to_string()) + .unwrap_or_else(|_| "unknown URL".to_string()); + println!( - "Downloading zksolc compiler from {:?}", - zksolc_manager.get_full_download_url().unwrap().to_string() + "zksolc not found in `.zksync` directory. Downloading zksolc compiler from {}", + download_url ); - zksolc_manager - .download() - .map_err(|err| eyre::eyre!("Failed to download the file: {}", err))?; + zksolc_manager.download().map_err(|err| { + eyre::eyre!( + "Failed to download zksolc version '{}' from {}: {}", + zksolc_version, + download_url, + err + ) + })?; } Ok(zksolc_manager) diff --git a/crates/zkforge/bin/cmd/test/mod.rs b/crates/zkforge/bin/cmd/test/mod.rs index 48121c4fa..7667e93a6 100644 --- a/crates/zkforge/bin/cmd/test/mod.rs +++ b/crates/zkforge/bin/cmd/test/mod.rs @@ -12,7 +12,7 @@ use foundry_common::{ evm::EvmArgs, get_contract_name, get_file_name, shell, zk_compile::{ZkSolc, ZkSolcOpts}, - zksolc_manager::{ZkSolcManagerBuilder, ZkSolcManagerOpts, DEFAULT_ZKSOLC_VERSION}, + zksolc_manager::{setup_zksolc_manager, DEFAULT_ZKSOLC_VERSION}, }; use foundry_config::{ figment, @@ -167,10 +167,7 @@ impl TestArgs { let toml = config.get_config_path(); let profiles = get_available_profiles(toml)?; - let zksolc_manager = - ZkSolcManagerBuilder::new(ZkSolcManagerOpts::new(DEFAULT_ZKSOLC_VERSION.to_owned())) - .build() - .unwrap(); + let zksolc_manager = setup_zksolc_manager(DEFAULT_ZKSOLC_VERSION.to_owned())?; let zksolc_opts = ZkSolcOpts { compiler_path: zksolc_manager.get_full_compiler_path(), @@ -180,7 +177,10 @@ impl TestArgs { }; let mut zksolc = ZkSolc::new(zksolc_opts, project); - let output = zksolc.compile().unwrap(); + let output = match zksolc.compile() { + Ok(compiled) => compiled, + Err(e) => return Err(eyre::eyre!("Failed to compile with zksolc: {}", e)), + }; let test_options: TestOptions = TestOptionsBuilder::default() .fuzz(config.fuzz)