Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chisel): validate that EVM version is compatible with solc version #7019

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 12 additions & 17 deletions crates/chisel/src/session_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use eyre::Result;
use forge_fmt::solang_ext::SafeUnwrap;
use foundry_compilers::{
artifacts::{Source, Sources},
CompilerInput, CompilerOutput, EvmVersion, Solc,
CompilerInput, CompilerOutput, Solc,
};
use foundry_config::{Config, SolcReq};
use foundry_evm::{backend::Backend, opts::EvmOpts};
Expand Down Expand Up @@ -105,22 +105,17 @@ impl SessionSourceConfig {

match solc_req {
SolcReq::Version(version) => {
// We now need to verify if the solc version provided is supported by the evm
// version set. If not, we bail and ask the user to provide a newer version.
// 1. Do we need solc 0.8.18 or higher?
let evm_version = self.foundry_config.evm_version;
let needs_post_merge_solc = evm_version >= EvmVersion::Paris;
// 2. Check if the version provided is less than 0.8.18 and bail,
// or leave it as-is if we don't need a post merge solc version or the version we
// have is good enough.
let v = if needs_post_merge_solc && version < Version::new(0, 8, 18) {
eyre::bail!("solc {version} is not supported by the set evm version: {evm_version}. Please install and use a version of solc higher or equal to 0.8.18.
You can also set the solc version in your foundry.toml.")
} else {
version.to_string()
};
// Validate that the requested evm version is supported by the solc version
let req_evm_version = self.foundry_config.evm_version;
if let Some(compat_evm_version) = req_evm_version.normalize_version(&version) {
if req_evm_version > compat_evm_version {
eyre::bail!(
"The set evm version, {req_evm_version}, is not supported by solc {version}. Upgrade to a newer solc version."
);
}
}

let mut solc = Solc::find_svm_installed_version(&v)?;
let mut solc = Solc::find_svm_installed_version(version.to_string())?;

if solc.is_none() {
if self.foundry_config.offline {
Expand All @@ -131,7 +126,7 @@ You can also set the solc version in your foundry.toml.")
Paint::green(format!("Installing solidity version {version}..."))
);
Solc::blocking_install(&version)?;
solc = Solc::find_svm_installed_version(&v)?;
solc = Solc::find_svm_installed_version(version.to_string())?;
}
solc.ok_or_else(|| eyre::eyre!("Failed to install {version}"))
}
Expand Down
26 changes: 25 additions & 1 deletion crates/chisel/tests/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chisel::session::ChiselSession;
use foundry_compilers::EvmVersion;
use foundry_config::Config;
use foundry_config::{Config, SolcReq};
use serial_test::serial;
use std::path::Path;

Expand Down Expand Up @@ -220,3 +220,27 @@ fn test_load_latest_cache() {
assert_eq!(new_env.id.unwrap(), "1");
assert_eq!(new_env.session_source.to_repl_source(), env.session_source.to_repl_source());
}

#[test]
#[serial]
fn test_solc_evm_configuration_mismatch() {
// Create and clear the cache directory
ChiselSession::create_cache_dir().unwrap();
ChiselSession::clear_cache().unwrap();

// Force the solc version to be 0.8.13 which does not support Paris
let foundry_config = Config {
evm_version: EvmVersion::Paris,
solc: Some(SolcReq::Version("0.8.13".parse().expect("invalid semver"))),
..Default::default()
};

// Create a new session that is expected to fail
let error = ChiselSession::new(chisel::session_source::SessionSourceConfig {
foundry_config,
..Default::default()
})
.unwrap_err();

assert_eq!(error.to_string(), "The set evm version, paris, is not supported by solc 0.8.13. Upgrade to a newer solc version.");
}
Loading