Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use foundry_zksync_compilers::compilers::{
};

use num_format::{Locale, ToFormattedString};

use std::{
collections::BTreeMap,
fmt::Display,
Expand Down
41 changes: 28 additions & 13 deletions crates/config/src/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl ZkSyncConfig {
libraries: Libraries,
evm_version: EvmVersion,
via_ir: bool,
offline: bool,
) -> ZkSolcSettings {
let optimizer = Optimizer {
enabled: Some(self.optimizer),
Expand Down Expand Up @@ -146,8 +147,16 @@ impl ZkSyncConfig {
suppressed_errors: self.suppressed_errors.clone(),
};

let zksolc_path = get_zksolc_compiler(self.zksolc.as_ref(), offline)
.unwrap_or_else(|e| panic!("Could not find zksolc compiler: {e}"));

// `cli_settings` get set from `Project` values when building `ZkSolcVersionedInput`
ZkSolcSettings { settings: zk_settings, cli_settings: CliSettings::default() }
ZkSolcSettings {
settings: zk_settings,
cli_settings: CliSettings::default(),
zksolc_version: ZkSolc::get_version_for_path(zksolc_path.as_ref())
.unwrap_or_else(|_| panic!("Could not find zksolc version for this path")),
}
}
}

Expand All @@ -163,19 +172,14 @@ pub fn config_zksolc_settings(config: &Config) -> Result<ZkSolcSettings, SolcErr
Err(e) => return Err(SolcError::msg(format!("Failed to parse libraries: {e}"))),
};

Ok(config.zksync.settings(libraries, config.evm_version, config.via_ir))
Ok(config.zksync.settings(libraries, config.evm_version, config.via_ir, config.offline))
}

/// Return the configured `zksolc` compiler
///
/// If not `offline`, will install the default version automatically
/// Will fallback to `zksolc` present in the environment
pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcError> {
let zksolc = if let Some(zksolc) =
config_ensure_zksolc(config.zksync.zksolc.as_ref(), config.offline)?
{
/// get the configured `zksolc` compiler
pub fn get_zksolc_compiler(zksolc: Option<&SolcReq>, offline: bool) -> Result<PathBuf, SolcError> {
Comment thread
elfedy marked this conversation as resolved.
Outdated
let zksolc = if let Some(zksolc) = config_ensure_zksolc(zksolc, offline)? {
zksolc
} else if !config.offline {
} else if !offline {
let default_version = semver::Version::new(1, 5, 10);
let mut zksolc = ZkSolc::find_installed_version(&default_version)?;
if zksolc.is_none() {
Expand All @@ -187,10 +191,21 @@ pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcErr
"zksolc".into()
};

Ok(ZkSolcCompiler { zksolc, solc: config_solc_compiler(config)? })
Ok(zksolc)
}

/// Return the configured `zksolc` compiler
///
/// If not `offline`, will install the default version automatically
/// Will fallback to `zksolc` present in the environment
pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcError> {
Ok(ZkSolcCompiler {
zksolc: get_zksolc_compiler(config.zksync.zksolc.as_ref(), config.offline)?,
solc: config_solc_compiler(config)?,
})
}

/// Create a new zkSync project
/// Create a new ZKsync project
pub fn config_create_project(
config: &Config,
cached: bool,
Expand Down
2 changes: 2 additions & 0 deletions crates/zksync/compilers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ similar-asserts.workspace = true
fd-lock = "4.0.2"
tempfile.workspace = true
foundry-test-utils.workspace = true
regex = { workspace = true, default-features = false }

2 changes: 1 addition & 1 deletion crates/zksync/compilers/src/compilers/zksolc/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CompilerInput for ZkSolcVersionedInput {
language: Self::Language,
version: Version,
) -> Self {
let ZkSolcSettings { settings, cli_settings } = settings;
let ZkSolcSettings { settings, cli_settings, .. } = settings;
let input = ZkSolcInput::new(language, sources, settings).sanitized(&version);

Self { solc_version: version, input, cli_settings }
Expand Down
6 changes: 5 additions & 1 deletion crates/zksync/compilers/src/compilers/zksolc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const ZKSOLC: &str = "zksolc";
/// ZKsync solc release used for all ZKsync solc versions
pub const ZKSYNC_SOLC_RELEASE: Version = Version::new(1, 0, 1);
/// Default zksolc version
pub const ZKSOLC_VERSION: Version = Version::new(1, 5, 10);
pub const ZKSOLC_VERSION: Version = Version::new(1, 5, 9);

#[cfg(test)]
macro_rules! take_solc_installer_lock {
Expand Down Expand Up @@ -151,7 +151,11 @@ impl Compiler for ZkSolcCompiler {
) -> Result<CompilerOutput<Self::CompilationError, Self::CompilerContract>> {
let zksolc = self.zksolc(input)?;

println!("paso por aca 1");

let mut zk_output = zksolc.compile(&input.input)?;
println!("zk_output {:?}", zk_output);

let mut metadata = BTreeMap::new();
if let Some(solc_version) = zk_output.version.take() {
metadata.insert("solcVersion".to_string(), solc_version.into());
Expand Down
22 changes: 20 additions & 2 deletions crates/zksync/compilers/src/compilers/zksolc/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};

use super::{ZkSolc, ZkSolcCompiler};
///
/// The Solidity compiler codegen.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -90,7 +92,7 @@ pub struct ZkSettings {
}

/// Analogous to SolcSettings for zksolc compiler
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ZkSolcSettings {
/// JSON settings expected by Solc
Expand All @@ -99,6 +101,19 @@ pub struct ZkSolcSettings {
/// Additional CLI args configuration
#[serde(flatten)]
pub cli_settings: solc::CliSettings,
/// The version of the zksolc compiler to use.
pub zksolc_version: Version,
}

impl Default for ZkSolcSettings {
fn default() -> Self {
Self {
settings: Default::default(),
cli_settings: Default::default(),
zksolc_version: ZkSolc::get_version_for_path(ZkSolcCompiler::default().zksolc.as_ref())
.expect("Failed to get zksolc version"),
}
}
}

impl ZkSettings {
Expand Down Expand Up @@ -210,6 +225,8 @@ impl CompilerSettings for ZkSolcSettings {
..
} = self;

println!("ybue: zksolc_version: {:?}", self.zksolc_version);

*via_ir == other.settings.via_ir &&
*remappings == other.settings.remappings &&
*evm_version == other.settings.evm_version &&
Expand All @@ -222,7 +239,8 @@ impl CompilerSettings for ZkSolcSettings {
*force_evmla == other.settings.force_evmla &&
*codegen == other.settings.codegen &&
*suppressed_warnings == other.settings.suppressed_warnings &&
*suppressed_errors == other.settings.suppressed_errors
*suppressed_errors == other.settings.suppressed_errors &&
self.zksolc_version == other.zksolc_version
}

fn with_remappings(mut self, remappings: &[Remapping]) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions crates/zksync/compilers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ pub mod link;
#[cfg(test)]
use foundry_test_utils as _;
#[cfg(test)]
use regex as _;
#[cfg(test)]
use tempfile as _;
Loading