diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index e0b53b9d8..280f754e7 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -516,7 +516,7 @@ impl Cheatcodes { tracing::trace!(?address, "ignoring code translation for test contract"); } else { account.info.code_hash = code_hash; - account.info.code = code.clone(); + account.info.code.clone_from(&code); } } } @@ -624,7 +624,7 @@ impl Cheatcodes { tracing::trace!(?address, "ignoring code translation for test contract"); } else { account.info.code_hash = info.code_hash; - account.info.code = info.code.clone(); + account.info.code.clone_from(&info.code); } } } @@ -1407,7 +1407,7 @@ impl Inspector for Cheatcodes { persisted_factory_deps: Some(&mut self.persisted_factory_deps), }; if let Ok(result) = foundry_zksync_core::vm::call::<_, DatabaseError>(call, ecx, ccx) { - self.combined_logs.extend(result.logs.clone().into_iter().map(|log| Some(log))); + self.combined_logs.extend(result.logs.clone().into_iter().map(Some)); //for each log in cloned logs call handle_expect_emit if !self.expected_emits.is_empty() { for log in result.logs { @@ -1788,7 +1788,7 @@ impl Inspector for Cheatcodes { let mut nonce = account.info.nonce; let mut call_init_code = call.init_code.clone(); - let mut zk_tx = if self.use_zk_vm { + let zk_tx = if self.use_zk_vm { to = Some(TxKind::Call(CONTRACT_DEPLOYER_ADDRESS.to_address())); nonce = foundry_zksync_core::nonce(broadcast.new_origin, ecx) as u64; let contract = self @@ -1810,45 +1810,13 @@ impl Inspector for Cheatcodes { ); call_init_code = Bytes::from(create_input); - Some(factory_deps) + Some(ZkTransactionMetadata { factory_deps }) } else { None }; - let rpc = ecx.db.active_fork_url(); - if let Some(factory_deps) = zk_tx { - let mut batched = - foundry_zksync_core::vm::batch_factory_dependencies(factory_deps); - debug!(batches = batched.len(), "splitting factory deps for broadcast"); - // the last batch is the final one that does the deployment - zk_tx = batched.pop(); - - for factory_deps in batched { - self.broadcastable_transactions.push_back(BroadcastableTransaction { - rpc: rpc.clone(), - transaction: TransactionRequest { - from: Some(broadcast.new_origin), - to: Some(TxKind::Call(Address::ZERO)), - value: Some(call.value), - input: TransactionInput::default(), - nonce: Some(nonce), - gas: if is_fixed_gas_limit { - Some(call.gas_limit as u128) - } else { - None - }, - ..Default::default() - }, - zk_tx: Some(ZkTransactionMetadata { factory_deps }), - }); - - //update nonce for each tx - nonce += 1; - } - } - self.broadcastable_transactions.push_back(BroadcastableTransaction { - rpc: rpc.clone(), + rpc: ecx.db.active_fork_url(), transaction: TransactionRequest { from: Some(broadcast.new_origin), to, @@ -1862,7 +1830,7 @@ impl Inspector for Cheatcodes { }, ..Default::default() }, - zk_tx: zk_tx.map(|factory_deps| ZkTransactionMetadata { factory_deps }), + zk_tx, }); let kind = match call.scheme { @@ -1930,7 +1898,7 @@ impl Inspector for Cheatcodes { ecx, ccx, ) { - self.combined_logs.extend(result.logs.clone().into_iter().map(|log| Some(log))); + self.combined_logs.extend(result.logs.clone().into_iter().map(Some)); // for each log in cloned logs call handle_expect_emit if !self.expected_emits.is_empty() { diff --git a/crates/evm/core/src/backend/fork_type.rs b/crates/evm/core/src/backend/fork_type.rs index 60ca7992f..f559adb9e 100644 --- a/crates/evm/core/src/backend/fork_type.rs +++ b/crates/evm/core/src/backend/fork_type.rs @@ -12,12 +12,12 @@ pub enum ForkType { impl ForkType { /// Returns true if type is [ForkType::Zk] pub fn is_zk(&self) -> bool { - matches!(self, ForkType::Zk) + matches!(self, Self::Zk) } /// Returns true if type is [ForkType::Evm] pub fn is_evm(&self) -> bool { - matches!(self, ForkType::Evm) + matches!(self, Self::Evm) } } diff --git a/crates/evm/fuzz/src/strategies/calldata.rs b/crates/evm/fuzz/src/strategies/calldata.rs index a23070403..5697be1f6 100644 --- a/crates/evm/fuzz/src/strategies/calldata.rs +++ b/crates/evm/fuzz/src/strategies/calldata.rs @@ -86,7 +86,7 @@ mod tests { ); let expected = function.abi_encode_input(&[address_fixture]).unwrap(); - let strategy = fuzz_calldata(function, &FuzzFixtures::new(fixtures)); + let strategy = fuzz_calldata(function, &FuzzFixtures::new(fixtures), false); let _ = strategy.prop_map(move |fuzzed| { assert_eq!(expected, fuzzed); }); diff --git a/crates/evm/fuzz/src/strategies/param.rs b/crates/evm/fuzz/src/strategies/param.rs index bc2c1d850..ab1fe8c5b 100644 --- a/crates/evm/fuzz/src/strategies/param.rs +++ b/crates/evm/fuzz/src/strategies/param.rs @@ -70,7 +70,18 @@ fn fuzz_param_inner( }; match *param { - DynSolType::Address => value(), + DynSolType::Address => value() + .prop_map(move |value| match value.as_address() { + Some(addr) => { + if no_zksync_reserved_addresses { + DynSolValue::Address(foundry_zksync_core::to_safe_address(addr)) + } else { + DynSolValue::Address(addr) + } + } + None => value, + }) + .boxed(), DynSolType::Int(n @ 8..=256) => super::IntStrategy::new(n, fuzz_fixtures) .prop_map(move |x| DynSolValue::Int(x, n)) .boxed(), @@ -139,7 +150,7 @@ pub fn fuzz_param_from_state( match *param { DynSolType::Address => value() .prop_map(move |value| { - let addr = Address::from_word(value.into()); + let addr = Address::from_word(value); if no_zksync_reserved_addresses { DynSolValue::Address(foundry_zksync_core::to_safe_address(addr)) } else { diff --git a/crates/evm/traces/src/lib.rs b/crates/evm/traces/src/lib.rs index 99e2bb55b..1eb2af762 100644 --- a/crates/evm/traces/src/lib.rs +++ b/crates/evm/traces/src/lib.rs @@ -301,7 +301,7 @@ pub fn load_contracts<'a>( deployments: &HashMap, ) -> ContractsByAddress { let mut local_identifier = LocalTraceIdentifier::new(known_contracts); - local_identifier.deployments = deployments.clone(); + local_identifier.deployments.clone_from(deployments); let decoder = CallTraceDecoder::new(); let mut contracts = ContractsByAddress::new(); for trace in traces { diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 69ab78989..5690b3d1b 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -196,8 +196,7 @@ impl CreateArgs { let fdep_art = zk_output.find(abs_path_str, contract_name).unwrap_or_else(|| { panic!( - "Could not find contract {} at path {} for compilation output", - contract_name, contract_path + "Could not find contract {contract_name} at path {contract_path} for compilation output", ) }); let fdep_fdeps_map = @@ -513,6 +512,7 @@ impl CreateArgs { } // Deploys the zk contract + #[allow(clippy::too_many_arguments)] async fn deploy_zk, T: Transport + Clone>( self, abi: JsonAbi, diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 49df39d43..8e71dcb9c 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -1547,8 +1547,7 @@ contract DeployScript is Script { assert!(cmd.stdout_lossy().contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL")); - let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast")) - .into_iter() + let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path()) .find(|file| file.ends_with("run-latest.json")) .expect("No broadcast artifacts"); diff --git a/crates/forge/tests/it/config.rs b/crates/forge/tests/it/config.rs index d32692071..1b2a1398d 100644 --- a/crates/forge/tests/it/config.rs +++ b/crates/forge/tests/it/config.rs @@ -1,14 +1,8 @@ //! Test config. -use crate::test_helpers::{COMPILED, COMPILED_ZK, EVM_OPTS, PROJECT, TESTDATA}; use forge::{ result::{SuiteResult, TestStatus}, - MultiContractRunner, MultiContractRunnerBuilder, TestOptions, TestOptionsBuilder, -}; -use foundry_compilers::ProjectPathsConfig; -use foundry_config::{ - fs_permissions::PathPermission, Config, FsPermissions, FuzzConfig, FuzzDictionaryConfig, - InvariantConfig, RpcEndpoint, RpcEndpoints, + MultiContractRunner, }; use foundry_evm::{ decode::decode_console_logs, @@ -16,7 +10,6 @@ use foundry_evm::{ traces::{render_trace_arena, CallTraceDecoderBuilder}, }; use foundry_test_utils::{init_tracing, Filter}; -use foundry_zksync_compiler::DualCompiledContracts; use futures::future::join_all; use itertools::Itertools; use std::collections::BTreeMap; diff --git a/crates/forge/tests/it/test_helpers.rs b/crates/forge/tests/it/test_helpers.rs index e711290bd..b1b00b7aa 100644 --- a/crates/forge/tests/it/test_helpers.rs +++ b/crates/forge/tests/it/test_helpers.rs @@ -1,10 +1,18 @@ //! Test helpers for Forge integration tests. use alloy_primitives::U256; +use forge::{ + revm::primitives::SpecId, MultiContractRunner, MultiContractRunnerBuilder, TestOptions, + TestOptionsBuilder, +}; use foundry_compilers::{ - artifacts::{Libraries, Settings}, + artifacts::{EvmVersion, Libraries, Settings}, zksync::compile::output::ProjectCompileOutput as ZkProjectCompileOutput, - Project, ProjectCompileOutput, ProjectPathsConfig, SolcConfig, + Project, ProjectCompileOutput, SolcConfig, +}; +use foundry_config::{ + fs_permissions::PathPermission, Config, FsPermissions, FuzzConfig, FuzzDictionaryConfig, + InvariantConfig, RpcEndpoint, RpcEndpoints, }; use foundry_evm::{ constants::CALLER, @@ -84,6 +92,7 @@ impl ForgeTestProfile { gas_report_samples: 256, failure_persist_dir: Some(tempfile::tempdir().unwrap().into_path()), failure_persist_file: Some("testfailure".to_string()), + no_zksync_reserved_addresses: false, }) .invariant(InvariantConfig { runs: 256, @@ -101,6 +110,7 @@ impl ForgeTestProfile { max_assume_rejects: 65536, gas_report_samples: 256, failure_persist_dir: Some(tempfile::tempdir().unwrap().into_path()), + no_zksync_reserved_addresses: false, }) .build(output, Path::new(self.project().root())) .expect("Config loaded") @@ -196,6 +206,15 @@ impl ForgeTestData { self.runner_with_config(config) } + /// Builds a non-tracing zksync runner + /// TODO: This needs to be implemented as currently it is a copy of the original function + pub fn runner_zksync(&self) -> MultiContractRunner { + let mut config = self.config.clone(); + config.fs_permissions = + FsPermissions::new(vec![PathPermission::read_write(manifest_root())]); + self.runner_with_zksync_config(config) + } + /// Builds a non-tracing runner pub fn runner_with_config(&self, mut config: Config) -> MultiContractRunner { config.rpc_endpoints = rpc_endpoints(); @@ -222,7 +241,38 @@ impl ForgeTestData { .enable_isolation(opts.isolate) .sender(sender) .with_test_options(self.test_opts.clone()) - .build(root, output, env, opts.clone()) + .build(root, output, None, env, opts.clone(), Default::default()) + .unwrap() + } + + /// Builds a non-tracing runner with zksync + /// TODO: This needs to be added as currently it is a copy of the original function + pub fn runner_with_zksync_config(&self, mut config: Config) -> MultiContractRunner { + config.rpc_endpoints = rpc_endpoints(); + config.allow_paths.push(manifest_root().to_path_buf()); + + // no prompt testing + config.prompt_timeout = 0; + + let root = self.project.root(); + let mut opts = self.evm_opts.clone(); + + if config.isolate { + opts.isolate = true; + } + + let env = opts.local_evm_env(); + let output = self.output.clone(); + + let sender = config.sender; + + let mut builder = self.base_runner(); + builder.config = Arc::new(config); + builder + .enable_isolation(opts.isolate) + .sender(sender) + .with_test_options(self.test_opts.clone()) + .build(root, output, None, env, opts.clone(), Default::default()) .unwrap() } @@ -231,7 +281,14 @@ impl ForgeTestData { let mut opts = self.evm_opts.clone(); opts.verbosity = 5; self.base_runner() - .build(self.project.root(), self.output.clone(), opts.local_evm_env(), opts) + .build( + self.project.root(), + self.output.clone(), + None, + opts.local_evm_env(), + opts, + Default::default(), + ) .unwrap() } @@ -247,7 +304,7 @@ impl ForgeTestData { self.base_runner() .with_fork(fork) - .build(self.project.root(), self.output.clone(), env, opts) + .build(self.project.root(), self.output.clone(), None, env, opts, Default::default()) .unwrap() } } @@ -279,53 +336,17 @@ pub fn get_compiled(project: &Project) -> ProjectCompileOutput { out } -/// Compile ZK project -fn zk_compile(project: Project) -> ZkProjectCompileOutput { - // let compiler_path = - // futures::executor::block_on(setup_zksolc_manager(DEFAULT_ZKSOLC_VERSION.to_owned())) - // .expect("failed setting up zksolc"); - - // let mut zksolc_config = ZkSolcConfigBuilder::new() - // .compiler_path(compiler_path) - // .settings(ZkSettings { - // optimizer: Optimizer { - // enabled: Some(true), - // mode: Some(String::from("3")), - // fallback_to_optimizing_for_size: Some(false), - // disable_system_request_memoization: true, - // ..Default::default() - // }, - // ..Default::default() - // }) - // .build() - // .expect("failed building zksolc config"); - // zksolc_config.contracts_to_compile = Some(vec![ - // globset::Glob::new("zk/*").unwrap().compile_matcher(), - // globset::Glob::new("lib/*").unwrap().compile_matcher(), - // globset::Glob::new("cheats/Vm.sol").unwrap().compile_matcher(), - // ]); - - // let mut zksolc = ZkSolc::new(zksolc_config, project); - // let (zk_out, _) = zksolc.compile().unwrap(); - // zk_out - - project.zksync_compile().expect("failed compiling with zksolc") -} - pub static COMPILED_ZK: Lazy = Lazy::new(|| { const LOCK: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/.lock-zk"); - // let project = &*PROJECT; - let mut paths = ProjectPathsConfig::builder().root(TESTDATA).sources(TESTDATA).build().unwrap(); - paths.zksync_artifacts = format!("{TESTDATA}/zkout").into(); - - let libs = - ["fork/Fork.t.sol:DssExecLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4".to_string()]; - let settings = Settings { libraries: Libraries::parse(&libs).unwrap(), ..Default::default() }; - let solc_config = SolcConfig::builder().settings(settings).build(); + // let libs = + // ["fork/Fork.t.sol:DssExecLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4".to_string()]; - let project = Project::builder().paths(paths).solc_config(solc_config).build().unwrap(); - assert!(project.cached); + // TODO: fix this to adapt to new way of testing + let config = ForgeTestData::new(ForgeTestProfile::Default).config; + let zk_project = foundry_zksync_compiler::create_project(&config, true, false).unwrap(); + let zk_compiler = foundry_common::compile::ProjectCompiler::new(); + assert!(zk_project.cached); // Compile only once per test run. // We need to use a file lock because `cargo-nextest` runs tests in different processes. @@ -334,14 +355,14 @@ pub static COMPILED_ZK: Lazy = Lazy::new(|| { let mut lock = fd_lock::new_lock(LOCK); let read = lock.read().unwrap(); let out; - if project.cache_path().exists() && std::fs::read(LOCK).unwrap() == b"1" { - out = zk_compile(project); + if zk_project.cache_path().exists() && std::fs::read(LOCK).unwrap() == b"1" { + out = zk_compiler.zksync_compile(&zk_project, None).unwrap(); drop(read); } else { drop(read); let mut write = lock.write().unwrap(); write.write_all(b"1").unwrap(); - out = zk_compile(project); + out = zk_compiler.zksync_compile(&zk_project, None).unwrap(); drop(write); }; @@ -368,17 +389,6 @@ pub static EVM_OPTS: Lazy = Lazy::new(|| EvmOpts { ..Default::default() }); -pub fn fuzz_executor(executor: Executor) -> FuzzedExecutor { - let cfg = proptest::test_runner::Config { failure_persistence: None, ..Default::default() }; - - FuzzedExecutor::new( - executor, - proptest::test_runner::TestRunner::new(cfg), - CALLER, - crate::config::test_opts().fuzz, - ) -} - /// Default data for the tests group. pub static TEST_DATA_DEFAULT: Lazy = Lazy::new(|| ForgeTestData::new(ForgeTestProfile::Default)); diff --git a/crates/forge/tests/it/zk.rs b/crates/forge/tests/it/zk.rs index 1439b866f..da988fcdd 100644 --- a/crates/forge/tests/it/zk.rs +++ b/crates/forge/tests/it/zk.rs @@ -4,55 +4,54 @@ use std::collections::BTreeMap; use crate::{ config::*, - test_helpers::{PROJECT, RE_PATH_SEPARATOR}, + test_helpers::{RE_PATH_SEPARATOR, TEST_DATA_DEFAULT}, }; use forge::revm::primitives::SpecId; -use foundry_config::{fs_permissions::PathPermission, Config, FsPermissions}; +use foundry_config::{fs_permissions::PathPermission, FsPermissions}; use foundry_test_utils::Filter; /// Executes all zk basic tests #[tokio::test(flavor = "multi_thread")] async fn test_zk_basic() { - let mut config = Config::with_root(PROJECT.root()); + let mut config = TEST_DATA_DEFAULT.config.clone(); config.fs_permissions = FsPermissions::new(vec![PathPermission::read_write("./")]); - let runner = runner_with_config_and_zk(config); + let runner = TEST_DATA_DEFAULT.runner_with_zksync_config(config); let filter = Filter::new(".*", "ZkBasicTest", &format!(".*zk{RE_PATH_SEPARATOR}*")); - TestConfig::with_filter(runner.await, filter).evm_spec(SpecId::SHANGHAI).run().await; + TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await; } /// Executes all zk contract tests #[tokio::test(flavor = "multi_thread")] async fn test_zk_contracts() { - let mut config = Config::with_root(PROJECT.root()); + let mut config = TEST_DATA_DEFAULT.config.clone(); config.fs_permissions = FsPermissions::new(vec![PathPermission::read_write("./")]); - let runner = runner_with_config_and_zk(config); + let runner = TEST_DATA_DEFAULT.runner_with_zksync_config(config); let filter = Filter::new(".*", "ZkContractsTest", &format!(".*zk{RE_PATH_SEPARATOR}*")); - TestConfig::with_filter(runner.await, filter).evm_spec(SpecId::SHANGHAI).run().await; + TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await; } /// Executes all zk cheatcode tests #[tokio::test(flavor = "multi_thread")] async fn test_zk_cheats() { - let mut config = Config::with_root(PROJECT.root()); + let mut config = TEST_DATA_DEFAULT.config.clone(); config.fs_permissions = FsPermissions::new(vec![PathPermission::read_write("./")]); - let runner = runner_with_config_and_zk(config); + let runner = TEST_DATA_DEFAULT.runner_with_zksync_config(config); let filter = Filter::new(".*", "ZkCheatcodesTest", &format!(".*zk{RE_PATH_SEPARATOR}*")); - TestConfig::with_filter(runner.await, filter).evm_spec(SpecId::SHANGHAI).run().await; + TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).run().await; } /// Executes all zk console tests #[tokio::test(flavor = "multi_thread")] async fn test_zk_logs() { - let mut config = Config::with_root(PROJECT.root()); + let mut config = TEST_DATA_DEFAULT.config.clone(); config.fs_permissions = FsPermissions::new(vec![PathPermission::read_write("./")]); - let runner = runner_with_config_and_zk(config); + let runner = TEST_DATA_DEFAULT.runner_with_zksync_config(config); let filter = Filter::new(".*", "ZkConsoleTest", &format!(".*zk{RE_PATH_SEPARATOR}*")); - let results = - TestConfig::with_filter(runner.await, filter).evm_spec(SpecId::SHANGHAI).test().await; + let results = TestConfig::with_filter(runner, filter).evm_spec(SpecId::SHANGHAI).test(); assert_multiple( &results, diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index 06c72ca0f..2b2b5bb61 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -89,6 +89,7 @@ async fn convert_to_zksync( Ok((deploy_request, signable)) } +#[allow(clippy::too_many_arguments)] pub async fn send_transaction( provider: Arc, mut tx: WithOtherFields, @@ -142,7 +143,7 @@ pub async fn send_transaction( .rlp_signed(signature.to_ethers()) .wrap_err("able to rlp encode deploy request")?; - [&[zksync_web3_rs::zks_utils::EIP712_TX_TYPE], encoded].concat().into() + [&[zksync_web3_rs::zks_utils::EIP712_TX_TYPE], encoded].concat() } else { tx.build(signer).await?.encoded_2718() }; diff --git a/crates/script/src/transaction.rs b/crates/script/src/transaction.rs index 4fbd6f652..6eb6bf17d 100644 --- a/crates/script/src/transaction.rs +++ b/crates/script/src/transaction.rs @@ -66,6 +66,7 @@ impl TransactionWithMetadata { Self { transaction: WithOtherFields::new(transaction), ..Default::default() } } + #[allow(clippy::too_many_arguments)] pub fn new( transaction: TransactionRequest, rpc: String, diff --git a/crates/verify/src/etherscan/mod.rs b/crates/verify/src/etherscan/mod.rs index d5624e156..7b1520fd6 100644 --- a/crates/verify/src/etherscan/mod.rs +++ b/crates/verify/src/etherscan/mod.rs @@ -303,7 +303,7 @@ impl EtherscanVerificationProvider { args: &VerifyArgs, context: &VerificationContext, ) -> Result { - let zk_compiler_version = self.zk_compiler_version(args, &context)?; + let zk_compiler_version = self.zk_compiler_version(args, context)?; let (source, contract_name, code_format) = if let Some(zk) = &zk_compiler_version { let mut zk_context = context.clone(); zk_context.compiler_version = zk.zksolc.clone(); diff --git a/crates/zksync/core/src/cheatcodes.rs b/crates/zksync/core/src/cheatcodes.rs index b60f15d34..dc50d2cb7 100644 --- a/crates/zksync/core/src/cheatcodes.rs +++ b/crates/zksync/core/src/cheatcodes.rs @@ -21,7 +21,7 @@ use crate::{ }; /// Sets `block.timestamp`. -pub fn warp<'a, DB>(timestamp: rU256, ecx: &'a mut InnerEvmContext) +pub fn warp(timestamp: rU256, ecx: &mut InnerEvmContext) where DB: Database, ::Error: Debug, @@ -41,7 +41,7 @@ where } /// Sets `block.number`. -pub fn roll<'a, DB>(number: rU256, ecx: &'a mut InnerEvmContext) +pub fn roll(number: rU256, ecx: &mut InnerEvmContext) where DB: Database, ::Error: Debug, @@ -61,7 +61,7 @@ where } /// Sets balance for a specific address. -pub fn deal<'a, DB>(address: Address, balance: rU256, ecx: &'a mut InnerEvmContext) -> rU256 +pub fn deal(address: Address, balance: rU256, ecx: &mut InnerEvmContext) -> rU256 where DB: Database, ::Error: Debug, @@ -80,7 +80,7 @@ where } /// Sets nonce for a specific address. -pub fn set_nonce<'a, DB>(address: Address, nonce: rU256, ecx: &'a mut InnerEvmContext) +pub fn set_nonce(address: Address, nonce: rU256, ecx: &mut InnerEvmContext) where DB: Database, ::Error: Debug, @@ -98,7 +98,7 @@ where } /// Gets nonce for a specific address. -pub fn get_nonce<'a, DB>(address: Address, ecx: &'a mut InnerEvmContext) -> rU256 +pub fn get_nonce(address: Address, ecx: &mut InnerEvmContext) -> rU256 where DB: Database, ::Error: Debug, @@ -116,7 +116,7 @@ where } /// Sets code for a specific address. -pub fn etch<'a, DB>(address: Address, bytecode: &[u8], ecx: &'a mut InnerEvmContext) +pub fn etch(address: Address, bytecode: &[u8], ecx: &mut InnerEvmContext) where DB: Database, ::Error: Debug, @@ -155,11 +155,8 @@ where /// Sets code for a mocked account. If not done, the mocked call will revert. /// The call has no effect if the mocked account already has a bytecode entry. -pub fn set_mocked_account<'a, DB>( - address: Address, - ecx: &'a mut InnerEvmContext, - caller: Address, -) where +pub fn set_mocked_account(address: Address, ecx: &mut InnerEvmContext, caller: Address) +where DB: Database, ::Error: Debug, { diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 3778859e9..8d132bf56 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -83,14 +83,13 @@ pub async fn new_eip712_transaction< provider: P, signer: S, ) -> Result { - let from = tx.from.clone().ok_or_eyre("`from` cannot be empty")?; + let from = tx.from.ok_or_eyre("`from` cannot be empty")?; let to = tx .to .and_then(|to| match to { alloy_primitives::TxKind::Create => None, alloy_primitives::TxKind::Call(to) => Some(to), }) - .clone() .ok_or_eyre("`to` cannot be empty")?; let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; @@ -160,7 +159,6 @@ pub async fn estimate_gas, T: Transport + Clone>( alloy_primitives::TxKind::Create => None, alloy_primitives::TxKind::Call(to) => Some(to), }) - .clone() .ok_or_eyre("`to` cannot be empty")?; let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; diff --git a/crates/zksync/core/src/vm/env.rs b/crates/zksync/core/src/vm/env.rs index 394dac7a9..0eabbb1b4 100644 --- a/crates/zksync/core/src/vm/env.rs +++ b/crates/zksync/core/src/vm/env.rs @@ -36,8 +36,7 @@ pub(crate) fn create_l1_batch_env( max_virtual_blocks_to_create: 1, } }; - let (mut batch_number, mut batch_timestamp) = - if let Some(batch) = load_last_l1_batch(storage) { batch } else { (0, 0) }; + let (mut batch_number, mut batch_timestamp) = load_last_l1_batch(storage).unwrap_or_default(); batch_number += 1; diff --git a/crates/zksync/core/src/vm/inspect.rs b/crates/zksync/core/src/vm/inspect.rs index e34665d59..579b88682 100644 --- a/crates/zksync/core/src/vm/inspect.rs +++ b/crates/zksync/core/src/vm/inspect.rs @@ -68,7 +68,7 @@ pub type ZKVMResult = EVMResultGeneric; /// immediately. /// All logs will be collected as they happen, and returned with the final result. //TODO: should we make this transparent in `inspect` directly? -pub fn inspect_as_batch<'a, DB, E>( +pub fn inspect_as_batch( tx: L2Tx, ecx: &mut EvmContext, ccx: &mut CheatcodeTracerContext, @@ -125,7 +125,7 @@ where /// Processes a [`L2Tx`] with EraVM and returns the final execution result and logs. /// /// State changes will be reflected in the given `Env`, `DB`, `JournaledState`. -pub fn inspect<'a, DB, E>( +pub fn inspect( mut tx: L2Tx, ecx: &mut EvmContext, ccx: &mut CheatcodeTracerContext, diff --git a/crates/zksync/core/src/vm/runner.rs b/crates/zksync/core/src/vm/runner.rs index 708960ec6..25b1a40e8 100644 --- a/crates/zksync/core/src/vm/runner.rs +++ b/crates/zksync/core/src/vm/runner.rs @@ -40,7 +40,7 @@ where debug!(calldata = ?env.tx.data, fdeps = factory_deps.as_ref().map(|v| v.len()).unwrap_or_default(), "zk transact"); let mut journaled_state = JournaledState::new( SpecId::LATEST, - Precompiles::new(PrecompileSpecId::LATEST).addresses().into_iter().copied().collect(), + Precompiles::new(PrecompileSpecId::LATEST).addresses().copied().collect(), ); let mut ecx = EvmContext::new_with_env(db, Box::new(env.clone())); @@ -92,7 +92,7 @@ where } /// Retrieves L2 ETH balance for a given address. -pub fn balance<'a, DB>(address: Address, ecx: &mut EvmContext) -> rU256 +pub fn balance(address: Address, ecx: &mut EvmContext) -> rU256 where DB: Database, ::Error: Debug, @@ -103,7 +103,7 @@ where /// Retrieves bytecode hash stored at a given address. #[allow(dead_code)] -pub fn code_hash<'a, DB>(address: Address, ecx: &mut EvmContext) -> B256 +pub fn code_hash(address: Address, ecx: &mut EvmContext) -> B256 where DB: Database, ::Error: Debug, @@ -112,7 +112,7 @@ where } /// Retrieves nonce for a given address. -pub fn nonce<'a, DB>(address: Address, ecx: &mut EvmContext) -> u32 +pub fn nonce(address: Address, ecx: &mut EvmContext) -> u32 where DB: Database, ::Error: Debug, @@ -121,7 +121,7 @@ where } /// Executes a CREATE opcode on the ZK-VM. -pub fn create<'a, DB, E>( +pub fn create( call: &CreateInputs, contract: &DualCompiledContract, factory_deps: Vec>, @@ -173,7 +173,7 @@ where } /// Executes a CALL opcode on the ZK-VM. -pub fn call<'a, DB, E>( +pub fn call( call: &CallInputs, ecx: &mut EvmContext, mut ccx: CheatcodeTracerContext, @@ -230,7 +230,7 @@ where } /// Assign gas parameters that satisfy zkSync's fee model. -fn gas_params<'a, DB>(ecx: &mut EvmContext, caller: Address) -> (U256, U256) +fn gas_params(ecx: &mut EvmContext, caller: Address) -> (U256, U256) where DB: Database + Send, ::Error: Debug,