Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat(contract-verifier): Adjust contract verifier for zksolc 1.5.0 (m…
Browse files Browse the repository at this point in the history
…atter-labs#2255)

## What ❔

- `system-mode`, `force-evmla` flag are not provided for zksolc post
v1.5.0 compilations
- `solc-path` is not provided for system yul post v1.5.0 compilations 

## Why ❔

Changes in compiler interface

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
perekopskiy authored Jun 18, 2024
1 parent db8e71b commit 63efb2e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 15 deletions.
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

0 comments on commit 63efb2e

Please sign in to comment.