Skip to content

Commit

Permalink
fix(verifier): update zksync input related structs to correspond to t…
Browse files Browse the repository at this point in the history
…he latest zksync compiler version
  • Loading branch information
rimrakhimov committed Oct 23, 2024
1 parent fed5068 commit d2c66ee
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"file_name": "src/Greeter.sol",
"contract_name": "Greeter",
"expected_sources": {
"src/Greeter.sol": "//SPDX-License-Identifier: Unlicense\npragma solidity ^0.8.0;\n\ncontract Greeter {\n string private greeting;\n\n constructor(string memory _greeting) {\n greeting = _greeting;\n }\n\n function greet() public view returns (string memory) {\n return greeting;\n }\n\n function setGreeting(string memory _greeting) public {\n greeting = _greeting;\n }\n}\n"
"src/Greeter.sol": "//SPDX-License-Identifier: Unlicense\npragma solidity ^0.8.0;\n\ncontract Greeter {\n string private greeting;\n\n constructor(string memory _greeting) {\n greeting = _greeting;\n }\n\n function greet() public view returns (string memory) {\n return greeting;\n }\n\n function setGreeting(string memory _greeting) public {\n greeting = _greeting;\n }\n}\n\n"
},
"expected_compilation_artifacts": {"abi":[{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"greet","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1},"storageLayout":{"storage":[{"astId":3,"contract":"contracts/Greeter.sol:Greeter","label":"greeting","offset":0,"slot":"0","type":"t_string_storage"}],"types":{"t_string_storage":{"encoding":"bytes","label":"string","numberOfBytes":"32"}}}},
"expected_compilation_artifacts": {"abi":[{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"greet","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_greeting","type":"string"}],"name":"setGreeting","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1},"storageLayout":{"storage":[{"astId":3,"contract":"src/Greeter.sol:Greeter","label":"greeting","offset":0,"slot":"0","type":"t_string_storage"}],"types":{"t_string_storage":{"encoding":"bytes","label":"string","numberOfBytes":"32"}}}},
"expected_creation_code_artifacts": {},
"expected_runtime_code_artifacts": {},

Expand All @@ -19,7 +19,7 @@
{
"type": "insert",
"reason": "constructor",
"offset": 4192
"offset": 4512
}
],
"expected_creation_values": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
use serde::{Deserialize, Serialize};
//!
//! The hash type.
//!
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MetadataHash {
use std::str::FromStr;

///
/// The hash type.
///
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum Type {
/// Do not include bytecode hash.
#[serde(rename = "none")]
None,
/// The default keccak256 hash.
/// The `keccak256`` hash type.
#[serde(rename = "keccak256")]
Keccak256,
/// The `ipfs` hash.
#[serde(rename = "ipfs")]
Ipfs,
}

impl FromStr for Type {
type Err = anyhow::Error;

fn from_str(string: &str) -> Result<Self, Self::Err> {
match string {
"none" => Ok(Self::None),
"keccak256" => Ok(Self::Keccak256),
"ipfs" => Ok(Self::Ipfs),
string => anyhow::bail!("unknown bytecode hash mode: `{string}`"),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod eravm_metadata_hash;

pub use eravm_metadata_hash::MetadataHash as EraVMMetadataHash;
pub use eravm_metadata_hash::Type as HashType;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
pub struct Metadata {
/// The bytecode hash mode.
#[serde(skip_serializing_if = "Option::is_none")]
pub bytecode_hash: Option<era_compiler_llvm_context::EraVMMetadataHash>,
pub bytecode_hash: Option<era_compiler_llvm_context::HashType>,
/// Whether to use literal content.
#[serde(skip_serializing_if = "Option::is_none")]
pub use_literal_content: Option<bool>,
Expand All @@ -24,7 +24,7 @@ impl Metadata {
/// A shortcut constructor.
///
pub fn new(
bytecode_hash: era_compiler_llvm_context::EraVMMetadataHash,
bytecode_hash: era_compiler_llvm_context::HashType,
use_literal_content: bool,
) -> Self {
Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,35 @@ pub struct Settings {
/// The output selection filters.
#[serde(skip_serializing_if = "Option::is_none")]
pub output_selection: Option<Selection>,
/// Whether to compile via IR. Only for testing with solc >=0.8.13.
/// Whether to compile via EVM assembly.
#[serde(rename = "forceEVMLA", skip_serializing_if = "Option::is_none")]
pub force_evmla: Option<bool>,
/// Whether to add the Yul step to compilation via EVM assembly.
#[serde(rename = "viaIR", skip_serializing_if = "Option::is_none")]
pub via_ir: Option<bool>,
/// Whether to enable EraVM extensions.
#[serde(
rename = "viaIR",
skip_serializing_if = "Option::is_none",
skip_deserializing
rename = "enableEraVMExtensions",
skip_serializing_if = "Option::is_none"
)]
pub via_ir: Option<bool>,
pub enable_eravm_extensions: Option<bool>,
/// Whether to enable the missing libraries detection mode.
#[serde(
rename = "detectMissingLibraries",
skip_serializing_if = "Option::is_none"
)]
pub detect_missing_libraries: Option<bool>,
/// The optimizer settings.
pub optimizer: Optimizer,
/// The extra LLVM options.
#[serde(rename = "LLVMOptions", skip_serializing_if = "Option::is_none")]
pub llvm_options: Option<Vec<String>>,
/// The metadata settings.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
}

impl Settings {
///
/// A shortcut constructor.
///
pub fn new(
evm_version: Option<era_compiler_common::EVMVersion>,
libraries: BTreeMap<String, BTreeMap<String, String>>,
remappings: Option<BTreeSet<String>>,
output_selection: Selection,
via_ir: bool,
optimizer: Optimizer,
metadata: Option<Metadata>,
) -> Self {
Self {
evm_version,
libraries: Some(libraries),
remappings,
output_selection: Some(output_selection),
via_ir: if via_ir { Some(true) } else { None },
optimizer,
metadata,
}
}

///
/// Sets the necessary defaults.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ pub struct Optimizer {
/// Set the jump table density threshold.
#[serde(skip_serializing_if = "Option::is_none")]
pub jump_table_density_threshold: Option<u32>,
// The original structure contained `camelCase` modifier for all optimizer fields.
// But sometimes those parameters are supplied in a snake case.
// To support such cases, we also add explicit snake case variations.
/// Whether to try to recompile with -Oz if the bytecode is too large.
#[serde(
rename = "fallback_to_optimizing_for_size",
skip_serializing_if = "Option::is_none"
)]
pub fallback_to_optimizing_for_size_snake: Option<bool>,
/// Whether to disable the system request memoization.
#[serde(
rename = "disable_system_request_memoization",
skip_serializing_if = "Option::is_none"
)]
pub disable_system_request_memoization_snake: Option<bool>,
/// Set the jump table density threshold.
#[serde(
rename = "jump_table_density_threshold",
skip_serializing_if = "Option::is_none"
)]
pub jump_table_density_threshold_snake: Option<u32>,
}

impl Optimizer {
Expand All @@ -52,6 +73,9 @@ impl Optimizer {
fallback_to_optimizing_for_size: Some(fallback_to_optimizing_for_size),
disable_system_request_memoization: Some(disable_system_request_memoization),
jump_table_density_threshold,
fallback_to_optimizing_for_size_snake: Some(fallback_to_optimizing_for_size),
disable_system_request_memoization_snake: Some(disable_system_request_memoization),
jump_table_density_threshold_snake: jump_table_density_threshold,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub enum Flag {
/// The user documentation.
#[serde(rename = "userdoc")]
Userdoc,
/// The function signature hashes JSON.
#[serde(rename = "evm.methodIdentifiers")]
MethodIdentifiers,
/// The storage layout.
#[serde(rename = "storageLayout")]
StorageLayout,
Expand All @@ -33,23 +30,16 @@ pub enum Flag {
/// The Yul IR.
#[serde(rename = "irOptimized")]
Yul,
/// The EVM bytecode.
#[serde(rename = "evm")]
EVM,
/// The EVM legacy assembly JSON.
#[serde(rename = "evm.legacyAssembly")]
EVMLA,
}

impl std::fmt::Display for Flag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ABI => write!(f, "abi"),
Self::Metadata => write!(f, "metadata"),
Self::Devdoc => write!(f, "devdoc"),
Self::Userdoc => write!(f, "userdoc"),
Self::MethodIdentifiers => write!(f, "evm.methodIdentifiers"),
Self::StorageLayout => write!(f, "storageLayout"),
Self::AST => write!(f, "ast"),
Self::Yul => write!(f, "irOptimized"),
Self::EVMLA => write!(f, "evm.legacyAssembly"),
}
}
/// The function signature hashes JSON.
#[serde(rename = "evm.methodIdentifiers")]
MethodIdentifiers,
/// The EraVM assembly.
#[serde(rename = "eravm.assembly")]
EraVMAssembly,
}

0 comments on commit d2c66ee

Please sign in to comment.