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: add assemblycreate for warning suppression for zksolc 1.5.10 #840

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion crates/cli/src/opts/build/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct ZkSyncArgs {
long = "zk-suppressed-errors",
visible_alias = "suppressed-errors",
value_delimiter = ',',
help = "Set the errors to suppress for zksolc, possible values: [sendtransfer]"
help = "Set the errors to suppress for zksolc, possible values: [sendtransfer, assemblycreate]"
)]
#[serde(skip_serializing_if = "Option::is_none")]
pub suppressed_errors: Option<Vec<ZkSolcError>>,
Expand Down
4 changes: 4 additions & 0 deletions crates/zksync/compilers/src/compilers/zksolc/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ pub enum ZkSolcError {
/// `sendtransfer` error: Using `send()` or `transfer()` methods on `address payable` instead
/// of `call()`.
SendTransfer,

elfedy marked this conversation as resolved.
Show resolved Hide resolved
/// `assemblycreate` error: Using `assembly { create }` instead of `new MyContract()`.
AssemblyCreate,
}

impl FromStr for ZkSolcError {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"sendtransfer" => Ok(Self::SendTransfer),
"assemblycreate" => Ok(Self::AssemblyCreate),
s => Err(format!("Unknown zksolc error: {s}")),
}
}
Expand Down
43 changes: 43 additions & 0 deletions crates/zksync/compilers/tests/zksync_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,49 @@ fn zksync_pre_1_5_7_can_compile_contract_with_suppressed_warnings() {
test_zksync_can_compile_contract_with_suppressed_warnings(compiler);
}

fn test_zksync_can_compile_contract_with_assembly_create_suppressed_errors(
compiler: ZkSolcCompiler,
) {
let mut project = TempProject::<ZkSolcCompiler, ZkArtifactOutput>::dapptools().unwrap();
project.project_mut().compiler = compiler;

project
.add_source(
"Erroneous",
r#"
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.10;
contract Erroneous {
function deployWithCreate(bytes memory bytecode) public returns (address addr) {
assembly {
addr := create(0, add(bytecode, 0x20), mload(bytecode))
}
}
}
"#,
)
.unwrap();

let compiled = project.compile().unwrap();
assert!(compiled.has_compiler_errors());

project.project_mut().settings.settings.suppressed_errors =
HashSet::from([ZkSolcError::AssemblyCreate]);

let compiled = project.compile().unwrap();
compiled.assert_success();
assert!(compiled.find_first("Erroneous").is_some());
}

#[test]
fn zksync_can_compile_contract_with_assembly_create_suppressed_errors() {
let compiler = ZkSolcCompiler {
zksolc: ZkSolc::get_path_for_version(&semver::Version::new(1, 5, 9)).unwrap(),
solc: Default::default(),
};
test_zksync_can_compile_contract_with_assembly_create_suppressed_errors(compiler);
}

#[test]
fn zksync_can_compile_dapp_detect_changes_in_libs() {
// let _ = tracing_subscriber::fmt()
Expand Down
Loading