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

feat: sanitize EVM version for vyper #181

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
22 changes: 22 additions & 0 deletions crates/artifacts/vyper/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use std::{
};

pub const VYPER_SEARCH_PATHS: Version = Version::new(0, 4, 0);
pub const VYPER_BERLIN: Version = Version::new(0, 3, 0);
pub const VYPER_PARIS: Version = Version::new(0, 3, 7);
pub const VYPER_SHANGHAI: Version = Version::new(0, 3, 8);
pub const VYPER_CANCUN: Version = Version::new(0, 3, 8);

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -79,11 +83,29 @@ impl VyperSettings {
}

self.sanitize_output_selection();
self.normalize_evm_version(version);
}

/// Sanitize the settings based on the compiler version.
pub fn sanitized(mut self, version: &Version) -> Self {
self.sanitize(version);
self
}

/// Adjusts the EVM version based on the compiler version.
pub fn normalize_evm_version(&mut self, version: &Version) {
if let Some(evm_version) = &mut self.evm_version {
*evm_version = if *evm_version >= EvmVersion::Cancun && *version >= VYPER_CANCUN {
EvmVersion::Cancun
} else if *evm_version >= EvmVersion::Shanghai && *version >= VYPER_SHANGHAI {
EvmVersion::Shanghai
} else if *evm_version >= EvmVersion::Paris && *version >= VYPER_PARIS {
EvmVersion::Paris
} else if *evm_version >= EvmVersion::Berlin && *version >= VYPER_BERLIN {
EvmVersion::Berlin
} else {
*evm_version
};
}
}
}