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(contract-verifier): Adjust contract verifier for zksolc 1.5.0 #2255

Merged
merged 6 commits into from
Jun 18, 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
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 core/lib/contract_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ lazy_static.workspace = true
tempfile.workspace = true
regex.workspace = true
tracing.workspace = true
semver.workspace = true
6 changes: 5 additions & 1 deletion core/lib/contract_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ impl ContractVerifier {
));
}

let zksolc = ZkSolc::new(zksolc_path, solc_path);
let zksolc = ZkSolc::new(
zksolc_path,
solc_path,
request.req.compiler_versions.zk_compiler_version(),
);

let output = time::timeout(config.compilation_timeout(), zksolc.async_compile(input))
.await
Expand Down
92 changes: 79 additions & 13 deletions core/lib/contract_verifier/src/zksolc_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, io::Write, path::PathBuf, process::Stdio};

use semver::Version;
use serde::{Deserialize, Serialize};

use crate::error::ContractVerifierError;
Expand Down Expand Up @@ -77,13 +78,19 @@ impl Default for Optimizer {
pub struct ZkSolc {
zksolc_path: PathBuf,
solc_path: PathBuf,
zksolc_version: String,
}

impl ZkSolc {
pub fn new(zksolc_path: impl Into<PathBuf>, solc_path: impl Into<PathBuf>) -> Self {
pub fn new(
zksolc_path: impl Into<PathBuf>,
solc_path: impl Into<PathBuf>,
zksolc_version: String,
) -> Self {
ZkSolc {
zksolc_path: zksolc_path.into(),
solc_path: solc_path.into(),
zksolc_version,
}
}

Expand All @@ -93,26 +100,36 @@ impl ZkSolc {
) -> Result<ZkSolcOutput, ContractVerifierError> {
use tokio::io::AsyncWriteExt;
let mut command = tokio::process::Command::new(&self.zksolc_path);
command.stdout(Stdio::piped()).stderr(Stdio::piped());

match &input {
ZkSolcInput::StandardJson(input) => {
if input.settings.is_system {
command.arg("--system-mode");
}
if input.settings.force_evmla {
command.arg("--force-evmla");
if !self.is_post_1_5_0() {
if input.settings.is_system {
command.arg("--system-mode");
}
if input.settings.force_evmla {
command.arg("--force-evmla");
}
}

command.arg("--solc").arg(self.solc_path.to_str().unwrap());
}
ZkSolcInput::YulSingleFile { is_system, .. } => {
if *is_system {
command.arg("--system-mode");
if self.is_post_1_5_0() {
if *is_system {
command.arg("--enable-eravm-extensions");
} else {
command.arg("--solc").arg(self.solc_path.to_str().unwrap());
}
} else {
if *is_system {
command.arg("--system-mode");
}
command.arg("--solc").arg(self.solc_path.to_str().unwrap());
}
}
}
command
.arg("--solc")
.arg(self.solc_path.to_str().unwrap())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
match input {
ZkSolcInput::StandardJson(input) => {
let mut child = command
Expand Down Expand Up @@ -181,4 +198,53 @@ impl ZkSolc {
}
}
}

pub fn is_post_1_5_0(&self) -> bool {
// Special case
if &self.zksolc_version == "vm-1.5.0-a167aa3" {
false
} else if let Some(version) = self.zksolc_version.strip_prefix("v") {
if let Ok(semver) = Version::parse(version) {
let target = Version::new(1, 5, 0);
semver >= target
} else {
true
}
} else {
true
}
}
}

#[cfg(test)]
mod tests {
use crate::zksolc_utils::ZkSolc;

#[test]
fn check_is_post_1_5_0() {
// Special case.
let mut zksolc = ZkSolc::new(".", ".", "vm-1.5.0-a167aa3".to_string());
assert!(!zksolc.is_post_1_5_0(), "vm-1.5.0-a167aa3");

zksolc.zksolc_version = "v1.5.0".to_string();
assert!(zksolc.is_post_1_5_0(), "v1.5.0");

zksolc.zksolc_version = "v1.5.1".to_string();
assert!(zksolc.is_post_1_5_0(), "v1.5.1");

zksolc.zksolc_version = "v1.10.1".to_string();
assert!(zksolc.is_post_1_5_0(), "v1.10.1");

zksolc.zksolc_version = "v2.0.0".to_string();
assert!(zksolc.is_post_1_5_0(), "v2.0.0");

zksolc.zksolc_version = "v1.4.15".to_string();
assert!(!zksolc.is_post_1_5_0(), "v1.4.15");

zksolc.zksolc_version = "v1.3.21".to_string();
assert!(!zksolc.is_post_1_5_0(), "v1.3.21");

zksolc.zksolc_version = "v0.5.1".to_string();
assert!(!zksolc.is_post_1_5_0(), "v0.5.1");
}
}
2 changes: 1 addition & 1 deletion core/lib/types/src/contract_verification_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub struct VerificationIncomingRequest {
pub optimizer_mode: Option<String>,
#[serde(default)]
pub constructor_arguments: Bytes,
#[serde(default)]
#[serde(default, alias = "enableEraVMExtensions")]
pub is_system: bool,
#[serde(default)]
pub force_evmla: bool,
Expand Down
Loading