Skip to content

Commit

Permalink
fix(contract-verifier): YUL system-mode verification (#1863)
Browse files Browse the repository at this point in the history
## What ❔

Adds opportunity to verify yul contract source code with system-mode on.

## Why ❔

Some contract are compiled with system mode off, some with mode on, all
must be verifiable.

## 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`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
perekopskiy authored May 6, 2024
1 parent a8c4599 commit 5aa7d41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 4 additions & 3 deletions core/bin/contract-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ impl ContractVerifier {
compiler_input.settings.output_selection = Some(default_output_selection);
Ok(ZkSolcInput::StandardJson(compiler_input))
}
SourceCodeData::YulSingleFile(source_code) => {
Ok(ZkSolcInput::YulSingleFile(source_code))
}
SourceCodeData::YulSingleFile(source_code) => Ok(ZkSolcInput::YulSingleFile {
source_code,
is_system: request.req.is_system,
}),
_ => panic!("Unexpected SourceCode variant"),
}
}
Expand Down
26 changes: 18 additions & 8 deletions core/bin/contract-verifier/src/zksolc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::error::ContractVerifierError;
#[derive(Debug)]
pub enum ZkSolcInput {
StandardJson(StandardJson),
YulSingleFile(String),
YulSingleFile {
source_code: String,
is_system: bool,
},
}

#[derive(Debug)]
Expand Down Expand Up @@ -102,12 +105,19 @@ impl ZkSolc {
) -> Result<ZkSolcOutput, ContractVerifierError> {
use tokio::io::AsyncWriteExt;
let mut command = tokio::process::Command::new(&self.zksolc_path);
if let ZkSolcInput::StandardJson(input) = &input {
if input.settings.is_system {
command.arg("--system-mode");
match &input {
ZkSolcInput::StandardJson(input) => {
if input.settings.is_system {
command.arg("--system-mode");
}
if input.settings.force_evmla {
command.arg("--force-evmla");
}
}
if input.settings.force_evmla {
command.arg("--force-evmla");
ZkSolcInput::YulSingleFile { is_system, .. } => {
if *is_system {
command.arg("--system-mode");
}
}
}
command
Expand Down Expand Up @@ -149,14 +159,14 @@ impl ZkSolc {
))
}
}
ZkSolcInput::YulSingleFile(content) => {
ZkSolcInput::YulSingleFile { source_code, .. } => {
let mut file = tempfile::Builder::new()
.prefix("input")
.suffix(".yul")
.rand_bytes(0)
.tempfile()
.map_err(|_err| ContractVerifierError::InternalError)?;
file.write_all(content.as_bytes())
file.write_all(source_code.as_bytes())
.map_err(|_err| ContractVerifierError::InternalError)?;
let child = command
.arg(file.path().to_str().unwrap())
Expand Down

0 comments on commit 5aa7d41

Please sign in to comment.