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: re-enable yul settings sanitization #122

Merged
merged 2 commits into from
May 13, 2024
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
33 changes: 2 additions & 31 deletions src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub(crate) type VersionedSources<C> = Vec<(C, Version, Sources)>;
/// A set of different Solc installations with their version and the sources to be compiled
pub(crate) type VersionedFilteredSources<C> = Vec<(C, Version, FilteredSources)>;

const SOLIDITY: &str = "Solidity";
const YUL: &str = "Yul";
pub const SOLIDITY: &str = "Solidity";
pub const YUL: &str = "Yul";

/// Input type `solc` expects.
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -89,25 +89,6 @@ impl SolcInput {
self
}

/// Sets the settings for compilation
#[must_use]
pub fn settings(mut self, mut settings: Settings) -> Self {
if self.is_yul() {
if !settings.remappings.is_empty() {
warn!("omitting remappings supplied for the yul sources");
settings.remappings = vec![];
}
if let Some(debug) = settings.debug.as_mut() {
if debug.revert_strings.is_some() {
warn!("omitting revertStrings supplied for the yul sources");
debug.revert_strings = None;
}
}
}
self.settings = settings;
self
}

/// Sets the EVM version for compilation
#[must_use]
pub fn evm_version(mut self, version: EvmVersion) -> Self {
Expand All @@ -122,16 +103,6 @@ impl SolcInput {
self
}

#[must_use]
pub fn with_remappings(mut self, remappings: Vec<Remapping>) -> Self {
if self.is_yul() {
warn!("omitting remappings supplied for the yul sources");
} else {
self.settings.remappings = remappings;
}
self
}

/// Sets the path of the source files to `root` adjoined to the existing path
#[must_use]
pub fn join_path(mut self, root: impl AsRef<Path>) -> Self {
Expand Down
24 changes: 21 additions & 3 deletions src/compilers/solc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::{
use crate::{
artifacts::{
output_selection::OutputSelection, Error, Settings as SolcSettings, SolcInput, Sources,
SOLIDITY, YUL,
},
error::Result,
remappings::Remapping,
Expand Down Expand Up @@ -88,13 +89,24 @@ impl CompilerInput for SolcInput {
let mut res = Vec::new();
if !solidity_sources.is_empty() {
res.push(Self {
language: "Solidity".to_string(),
language: SOLIDITY.to_string(),
sources: solidity_sources,
settings: settings.clone(),
});
}
if !yul_sources.is_empty() {
res.push(Self { language: "Yul".to_string(), sources: yul_sources, settings });
if !settings.remappings.is_empty() {
warn!("omitting remappings supplied for the yul sources");
settings.remappings = vec![];
}

if let Some(debug) = settings.debug.as_mut() {
if debug.revert_strings.is_some() {
warn!("omitting revertStrings supplied for the yul sources");
debug.revert_strings = None;
}
}
res.push(Self { language: YUL.to_string(), sources: yul_sources, settings });
}
res
}
Expand All @@ -104,7 +116,13 @@ impl CompilerInput for SolcInput {
}

fn with_remappings(mut self, remappings: Vec<Remapping>) -> Self {
self.settings.remappings = remappings;
if self.language == YUL {
if !remappings.is_empty() {
warn!("omitting remappings supplied for the yul sources");
}
} else {
self.settings.remappings = remappings;
}
self
}

Expand Down
15 changes: 15 additions & 0 deletions tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3852,3 +3852,18 @@ fn can_compile_vyper_with_cache() {
assert!(compiled.find_first("Counter").is_some());
assert!(!compiled.is_unchanged());
}

#[test]
fn yul_remappings_ignored() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test-data/yul-sample");
// Add dummy remapping.
let paths = ProjectPathsConfig::builder().sources(root.clone()).remapping(Remapping {
context: None,
name: "@openzeppelin".to_string(),
path: root.to_string_lossy().to_string(),
});
let project = TempProject::<ConfigurableArtifacts>::new(paths).unwrap();

let compiled = project.compile().unwrap();
compiled.assert_success();
}
Loading