Skip to content

Commit 58900d8

Browse files
authored
fix(coverage): keep EVM version when normalizing for ir-minimum (#9768)
1 parent 4d1f72b commit 58900d8

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

crates/config/src/lib.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ pub struct Config {
226226
///
227227
/// **Note** for backwards compatibility reasons this also accepts solc_version from the toml
228228
/// file, see `BackwardsCompatTomlProvider`.
229+
///
230+
/// Avoid using this field directly; call the related `solc` methods instead.
231+
#[doc(hidden)]
229232
pub solc: Option<SolcReq>,
230-
/// whether to autodetect the solc compiler version to use
233+
/// Whether to autodetect the solc compiler version to use.
231234
pub auto_detect_solc: bool,
232235
/// Offline mode, if set, network access (downloading solc) is disallowed.
233236
///
@@ -801,7 +804,7 @@ impl Config {
801804

802805
self.fs_permissions.join_all(&root);
803806

804-
if let Some(ref mut model_checker) = self.model_checker {
807+
if let Some(model_checker) = &mut self.model_checker {
805808
model_checker.contracts = std::mem::take(&mut model_checker.contracts)
806809
.into_iter()
807810
.map(|(path, contracts)| {
@@ -850,12 +853,9 @@ impl Config {
850853
}
851854
}
852855

853-
/// Returns the normalized [EvmVersion] if a [SolcReq] is set to a valid version or if the solc
854-
/// path is a valid solc binary.
855-
///
856-
/// Otherwise it returns the configured [EvmVersion].
856+
/// Returns the normalized [EvmVersion] for the current solc version, or the configured one.
857857
pub fn get_normalized_evm_version(&self) -> EvmVersion {
858-
if let Some(version) = self.solc.as_ref().and_then(|solc| solc.try_version().ok()) {
858+
if let Some(version) = self.solc_version() {
859859
if let Some(evm_version) = self.evm_version.normalize_version_solc(&version) {
860860
return evm_version;
861861
}
@@ -1118,7 +1118,8 @@ impl Config {
11181118
Err(RecvTimeoutError::Disconnected) => panic!("sender dropped"),
11191119
};
11201120
}
1121-
if let Some(ref solc) = self.solc {
1121+
1122+
if let Some(solc) = &self.solc {
11221123
let solc = match solc {
11231124
SolcReq::Version(version) => {
11241125
if let Some(solc) = Solc::find_svm_installed_version(version)? {
@@ -1216,6 +1217,11 @@ impl Config {
12161217
}
12171218
}
12181219

1220+
/// Returns the solc version, if any.
1221+
pub fn solc_version(&self) -> Option<Version> {
1222+
self.solc.as_ref().and_then(|solc| solc.try_version().ok())
1223+
}
1224+
12191225
/// Returns configured [Vyper] compiler.
12201226
pub fn vyper_compiler(&self) -> Result<Option<Vyper>, SolcError> {
12211227
// Only instantiate Vyper if there are any Vyper files in the project.

crates/forge/bin/cmd/coverage.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use foundry_compilers::{
2222
compilers::multi::MultiCompiler,
2323
Artifact, ArtifactId, Project, ProjectCompileOutput, ProjectPathsConfig,
2424
};
25-
use foundry_config::{Config, SolcReq};
25+
use foundry_config::Config;
2626
use rayon::prelude::*;
2727
use semver::{Version, VersionReq};
2828
use std::{
@@ -150,32 +150,29 @@ impl CoverageArgs {
150150
"See more: https://github.com/foundry-rs/foundry/issues/3357",
151151
))?;
152152

153-
// Enable viaIR with minimum optimization
154-
// https://github.com/ethereum/solidity/issues/12533#issuecomment-1013073350
155-
// And also in new releases of solidity:
156-
// https://github.com/ethereum/solidity/issues/13972#issuecomment-1628632202
153+
// Enable viaIR with minimum optimization: https://github.com/ethereum/solidity/issues/12533#issuecomment-1013073350
154+
// And also in new releases of Solidity: https://github.com/ethereum/solidity/issues/13972#issuecomment-1628632202
157155
project.settings.solc.settings =
158156
project.settings.solc.settings.with_via_ir_minimum_optimization();
159-
let version = if let Some(SolcReq::Version(version)) = &config.solc {
160-
version
161-
} else {
162-
// Sanitize settings for solc 0.8.4 if version cannot be detected.
163-
// See <https://github.com/foundry-rs/foundry/issues/9322>.
164-
&Version::new(0, 8, 4)
165-
};
166-
project.settings.solc.settings.sanitize(version, SolcLanguage::Solidity);
157+
158+
// Sanitize settings for solc 0.8.4 if version cannot be detected: https://github.com/foundry-rs/foundry/issues/9322
159+
// But keep the EVM version: https://github.com/ethereum/solidity/issues/15775
160+
let evm_version = project.settings.solc.evm_version;
161+
let version = config.solc_version().unwrap_or_else(|| Version::new(0, 8, 4));
162+
project.settings.solc.settings.sanitize(&version, SolcLanguage::Solidity);
163+
project.settings.solc.evm_version = evm_version;
167164
} else {
168165
project.settings.solc.optimizer.disable();
169166
project.settings.solc.optimizer.runs = None;
170167
project.settings.solc.optimizer.details = None;
171168
project.settings.solc.via_ir = None;
172169
}
170+
173171
let mut warning =
174172
"optimizer settings have been disabled for accurate coverage reports".to_string();
175173
if !self.ir_minimum {
176174
warning += ", if you encounter \"stack too deep\" errors, consider using `--ir-minimum` which enables viaIR with minimum optimization resolving most of the errors";
177175
}
178-
179176
sh_warn!("{warning}")?;
180177

181178
let output = ProjectCompiler::default()

0 commit comments

Comments
 (0)