Skip to content

Commit

Permalink
feat(verifier): zksolc full match support (#912)
Browse files Browse the repository at this point in the history
* Add basic zksync endpoints definitions. Create ZksyncCompilers struct; use it to fetch solc compilers

* Add zkevm settings

* Make VersionNotFound error internal String

* Create a generic fetcher structs

* Remove non-generic fetcher structs. Make use of generic fetcher instead of non-generic one. Finish implementation of list_compilers for zksolidity service

* Implement zksolc contracts parsing

* Move zksync related code into a separate module. Finish the basic contract comparison

* Add verifier_alliance related definitions into verification-common lib

* Implement zksolc verification

* chore(libs-verification-common): bump blockscout_display_bytes to v1.1.0

* chore: bump blockscout-display-bytes to v1.1.0, solidity-metadata to v1.1.0
  • Loading branch information
rimrakhimov authored Jul 2, 2024
1 parent 08b38a5 commit bd6352d
Show file tree
Hide file tree
Showing 90 changed files with 4,307 additions and 788 deletions.
7 changes: 7 additions & 0 deletions libs/verification-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
alloy-dyn-abi = "0.7"
alloy-json-abi = "0.7"
anyhow = "1.0"
blockscout-display-bytes = "1.1.0"
bytes = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "3.8"

[dev-dependencies]
hex = "0.4.3"
1 change: 1 addition & 0 deletions libs/verification-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod blueprint_contracts;
pub mod verifier_alliance;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub trait ToCompilationArtifacts {
fn abi(&self) -> Option<Value> {
None
}
fn devdoc(&self) -> Option<Value> {
None
}
fn userdoc(&self) -> Option<Value> {
None
}
fn storage_layout(&self) -> Option<Value> {
None
}
}

impl<T: ToCompilationArtifacts> ToCompilationArtifacts for &T {
fn abi(&self) -> Option<Value> {
(*self).abi()
}
fn devdoc(&self) -> Option<Value> {
(*self).devdoc()
}
fn userdoc(&self) -> Option<Value> {
(*self).userdoc()
}
fn storage_layout(&self) -> Option<Value> {
(*self).storage_layout()
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CompilationArtifacts {
#[serde(skip_serializing_if = "Option::is_none")]
pub abi: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub devdoc: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub userdoc: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub storage_layout: Option<Value>,
}

impl<T: ToCompilationArtifacts> From<T> for CompilationArtifacts {
fn from(value: T) -> Self {
Self {
abi: value.abi(),
devdoc: value.devdoc(),
userdoc: value.userdoc(),
storage_layout: value.storage_layout(),
}
}
}

impl From<CompilationArtifacts> for Value {
fn from(value: CompilationArtifacts) -> Self {
serde_json::to_value(value).expect("compilation artifacts serialization must succeed")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub trait ToCreationCodeArtifacts {
fn cbor_auxdata(&self) -> Option<Value> {
None
}
fn link_references(&self) -> Option<Value> {
None
}
fn source_map(&self) -> Option<Value> {
None
}
}

impl<T: ToCreationCodeArtifacts> ToCreationCodeArtifacts for &T {
fn cbor_auxdata(&self) -> Option<Value> {
(*self).cbor_auxdata()
}
fn link_references(&self) -> Option<Value> {
(*self).link_references()
}
fn source_map(&self) -> Option<Value> {
(*self).source_map()
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreationCodeArtifacts {
#[serde(skip_serializing_if = "Option::is_none")]
pub source_map: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub link_references: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cbor_auxdata: Option<Value>,
}

impl<T: ToCreationCodeArtifacts> From<T> for CreationCodeArtifacts {
fn from(value: T) -> Self {
Self {
link_references: value.link_references(),
source_map: value.source_map(),
cbor_auxdata: value.cbor_auxdata(),
}
}
}

impl From<CreationCodeArtifacts> for Value {
fn from(value: CreationCodeArtifacts) -> Self {
serde_json::to_value(value).expect("creation code artifacts serialization must succeed")
}
}
12 changes: 12 additions & 0 deletions libs/verification-common/src/verifier_alliance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod compilation_artifacts;
mod creation_code_artifacts;
mod runtime_code_artifacts;
mod verification_match;

mod verification_match_transformations;
mod verification_match_values;

pub use compilation_artifacts::{CompilationArtifacts, ToCompilationArtifacts};
pub use creation_code_artifacts::{CreationCodeArtifacts, ToCreationCodeArtifacts};
pub use runtime_code_artifacts::{RuntimeCodeArtifacts, ToRuntimeCodeArtifacts};
pub use verification_match::{Match, MatchBuilder, MatchTransformation, MatchType, MatchValues};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;

pub trait ToRuntimeCodeArtifacts {
fn cbor_auxdata(&self) -> Option<Value> {
None
}
fn immutable_references(&self) -> Option<Value> {
None
}
fn link_references(&self) -> Option<Value> {
None
}
fn source_map(&self) -> Option<Value> {
None
}
}

impl<T: ToRuntimeCodeArtifacts> ToRuntimeCodeArtifacts for &T {
fn cbor_auxdata(&self) -> Option<Value> {
(*self).cbor_auxdata()
}
fn immutable_references(&self) -> Option<Value> {
(*self).immutable_references()
}
fn link_references(&self) -> Option<Value> {
(*self).link_references()
}
fn source_map(&self) -> Option<Value> {
(*self).source_map()
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RuntimeCodeArtifacts {
#[serde(skip_serializing_if = "Option::is_none")]
pub cbor_auxdata: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub immutable_references: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub link_references: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_map: Option<Value>,
}

impl<T: ToRuntimeCodeArtifacts> From<T> for RuntimeCodeArtifacts {
fn from(value: T) -> Self {
Self {
cbor_auxdata: value.cbor_auxdata(),
immutable_references: value.immutable_references(),
link_references: value.link_references(),
source_map: value.source_map(),
}
}
}

impl From<(RuntimeCodeArtifacts, RuntimeCodeArtifacts)> for RuntimeCodeArtifacts {
fn from(
(base_artifacts, merged_artifacts): (RuntimeCodeArtifacts, RuntimeCodeArtifacts),
) -> Self {
Self {
cbor_auxdata: merged_artifacts
.cbor_auxdata
.or(base_artifacts.cbor_auxdata),
immutable_references: merged_artifacts
.immutable_references
.or(base_artifacts.immutable_references),
link_references: merged_artifacts
.link_references
.or(base_artifacts.link_references),
source_map: merged_artifacts.source_map.or(base_artifacts.source_map),
}
}
}

impl From<RuntimeCodeArtifacts> for Value {
fn from(value: RuntimeCodeArtifacts) -> Self {
serde_json::to_value(value).expect("runtime code artifacts serialization must succeed")
}
}
Loading

0 comments on commit bd6352d

Please sign in to comment.