From b38109de7566f47bbb9f13130c96e6624cb1f817 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Thu, 12 Dec 2024 15:53:26 +0100 Subject: [PATCH] remove unused parts --- Cargo.lock | 9 -- Cargo.toml | 2 - crates/cheatcodes/src/config.rs | 5 +- crates/cheatcodes/src/inspector.rs | 191 +----------------------- crates/cheatcodes/src/strategy.rs | 33 ++-- crates/evm/core/src/backend/cow.rs | 5 - crates/evm/core/src/backend/mod.rs | 20 ++- crates/forge/src/runner.rs | 15 +- crates/script/src/runner.rs | 15 +- crates/strategy/core/Cargo.toml | 16 -- crates/strategy/core/src/lib.rs | 26 ---- crates/strategy/zksync/Cargo.toml | 2 - crates/strategy/zksync/src/backend.rs | 29 ++-- crates/strategy/zksync/src/cheatcode.rs | 15 +- crates/strategy/zksync/src/lib.rs | 34 +---- 15 files changed, 67 insertions(+), 350 deletions(-) delete mode 100644 crates/strategy/core/Cargo.toml delete mode 100644 crates/strategy/core/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3c3ae1388..60cfe14c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5305,13 +5305,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "foundry-strategy-core" -version = "0.0.2" -dependencies = [ - "foundry-evm-core", -] - [[package]] name = "foundry-strategy-zksync" version = "0.0.2" @@ -5319,7 +5312,6 @@ dependencies = [ "alloy-json-abi", "alloy-primitives", "alloy-rpc-types", - "alloy-serde", "alloy-sol-types", "eyre", "foundry-cheatcodes", @@ -5329,7 +5321,6 @@ dependencies = [ "foundry-evm", "foundry-evm-core", "foundry-evm-traces", - "foundry-strategy-core", "foundry-zksync-compiler", "foundry-zksync-core", "itertools 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index a77c9f12d..ae9d8abfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ members = [ "crates/script-sequence/", "crates/macros/", "crates/test-utils/", - "crates/strategy/core/", "crates/strategy/zksync/", ] resolver = "2" @@ -175,7 +174,6 @@ foundry-linking = { path = "crates/linking" } foundry-zksync-core = { path = "crates/zksync/core" } foundry-zksync-compiler = { path = "crates/zksync/compiler" } foundry-zksync-inspectors = { path = "crates/zksync/inspectors" } -foundry-strategy-core = { path = "crates/strategy/core" } foundry-strategy-zksync = { path = "crates/strategy/zksync" } # solc & compilation utilities diff --git a/crates/cheatcodes/src/config.rs b/crates/cheatcodes/src/config.rs index 81fb1b3cd..f96f1438d 100644 --- a/crates/cheatcodes/src/config.rs +++ b/crates/cheatcodes/src/config.rs @@ -57,10 +57,7 @@ pub struct CheatsConfig { pub running_contract: Option, /// Version of the script/test contract which is currently running. pub running_version: Option, - // /// ZKSolc -> Solc Contract codes - // pub dual_compiled_contracts: DualCompiledContracts, - // /// Use ZK-VM on startup - // pub use_zk: bool, + /// The behavior strategy. pub strategy: Arc>, /// Whether to enable legacy (non-reverting) assertions. pub assertions_revert: bool, diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 6658a88c6..c3955b430 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -526,44 +526,8 @@ pub struct Cheatcodes { /// Unlocked wallets used in scripts and testing of scripts. pub wallets: Option, - /// Cheatcode inspector strategy + /// The behavior strategy. pub strategy: Arc>, - // /// Use ZK-VM to execute CALLs and CREATEs. - // pub use_zk_vm: bool, - - // /// When in zkEVM context, execute the next CALL or CREATE in the EVM instead. - // pub skip_zk_vm: bool, - - // /// Any contracts that were deployed in `skip_zk_vm` step. - // /// This makes it easier to dispatch calls to any of these addresses in zkEVM context, - // directly /// to EVM. Alternatively, we'd need to add `vm.zkVmSkip()` to these calls - // manually. pub skip_zk_vm_addresses: HashSet
, - - // /// Records the next create address for `skip_zk_vm_addresses`. - // pub record_next_create_address: bool, - - // /// Paymaster params - // pub paymaster_params: Option, - - // /// Dual compiled contracts - // pub dual_compiled_contracts: DualCompiledContracts, - - // /// The migration status of the database to zkEVM storage, `None` if we start in EVM - // context. pub zk_startup_migration: Option, - - // /// Factory deps stored through `zkUseFactoryDep`. These factory deps are used in the next - // /// CREATE or CALL, and cleared after. - // pub zk_use_factory_deps: Vec, - - // /// The list of factory_deps seen so far during a test or script execution. - // /// Ideally these would be persisted in the storage, but since modifying - // [revm::JournaledState] /// would be a significant refactor, we maintain the factory_dep - // part in the [Cheatcodes]. /// This can be done as each test runs with its own - // [Cheatcodes] instance, thereby /// providing the necessary level of isolation. - // pub persisted_factory_deps: HashMap>, - - // /// Nonce update persistence behavior in zkEVM for the tx caller. - // pub zk_persist_nonce_update: ZkPersistNonceUpdate, } // This is not derived because calling this in `fn new` with `..Default::default()` creates a second @@ -578,53 +542,10 @@ impl Default for Cheatcodes { impl Cheatcodes { /// Creates a new `Cheatcodes` with the given settings. pub fn new(config: Arc) -> Self { - // let mut dual_compiled_contracts = config.dual_compiled_contracts.clone(); - - // // We add the empty bytecode manually so it is correctly translated in zk mode. - // // This is used in many places in foundry, e.g. in cheatcode contract's account code. - // let empty_bytes = Bytes::from_static(&[0]); - // let zk_bytecode_hash = - // foundry_zksync_core::hash_bytecode(&foundry_zksync_core::EMPTY_CODE); - // let zk_deployed_bytecode = foundry_zksync_core::EMPTY_CODE.to_vec(); - - // dual_compiled_contracts.push(DualCompiledContract { - // name: String::from("EmptyEVMBytecode"), - // zk_bytecode_hash, - // zk_deployed_bytecode: zk_deployed_bytecode.clone(), - // zk_factory_deps: Default::default(), - // evm_bytecode_hash: B256::from_slice(&keccak256(&empty_bytes)[..]), - // evm_deployed_bytecode: Bytecode::new_raw(empty_bytes.clone()).bytecode().to_vec(), - // evm_bytecode: Bytecode::new_raw(empty_bytes).bytecode().to_vec(), - // }); - - // let cheatcodes_bytecode = { - // let mut bytecode = CHEATCODE_ADDRESS.abi_encode_packed(); - // bytecode.append(&mut [0; 12].to_vec()); - // Bytes::from(bytecode) - // }; - // dual_compiled_contracts.push(DualCompiledContract { - // name: String::from("CheatcodeBytecode"), - // // we put a different bytecode hash here so when importing back to EVM - // // we avoid collision with EmptyEVMBytecode for the cheatcodes - // zk_bytecode_hash: - // foundry_zksync_core::hash_bytecode(CHEATCODE_CONTRACT_HASH.as_ref()), - // zk_deployed_bytecode: cheatcodes_bytecode.to_vec(), - // zk_factory_deps: Default::default(), - // evm_bytecode_hash: CHEATCODE_CONTRACT_HASH, - // evm_deployed_bytecode: cheatcodes_bytecode.to_vec(), - // evm_bytecode: cheatcodes_bytecode.to_vec(), - // }); - - // let mut persisted_factory_deps = HashMap::new(); - // persisted_factory_deps.insert(zk_bytecode_hash, zk_deployed_bytecode); - - // let zk_startup_migration = config.use_zk.then_some(ZkStartupMigration::Defer); - - let strategy = config.strategy.clone(); - Self { fs_commit: true, labels: config.labels.clone(), + strategy: config.strategy.clone(), config, block: Default::default(), active_delegation: Default::default(), @@ -657,18 +578,6 @@ impl Cheatcodes { arbitrary_storage: Default::default(), deprecated: Default::default(), wallets: Default::default(), - strategy, - // dual_compiled_contracts, - // zk_startup_migration, - // use_zk_vm: Default::default(), - // skip_zk_vm: Default::default(), - // skip_zk_vm_addresses: Default::default(), - // record_next_create_address: Default::default(), - // //TODO(zk): use initialized above - // persisted_factory_deps: Default::default(), - // paymaster_params: None, - // zk_use_factory_deps: Default::default(), - // zk_persist_nonce_update: Default::default(), } } @@ -810,8 +719,6 @@ impl Cheatcodes { if ecx_inner.journaled_state.depth() == broadcast.depth { input.set_caller(broadcast.new_origin); - // let is_fixed_gas_limit = check_if_fixed_gas_limit(ecx_inner, - // input.gas_limit()); self.strategy .lock() @@ -824,100 +731,6 @@ impl Cheatcodes { &mut self.broadcastable_transactions, ); - // let mut to = None; - // let mut nonce: u64 = - // ecx_inner.journaled_state.state()[&broadcast.new_origin].info.nonce; - // //drop the mutable borrow of account - // let mut call_init_code = input.init_code(); - // let mut 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_inner) as - // u64; let init_code = input.init_code(); - // let find_contract = self - // .dual_compiled_contracts - // .find_bytecode(&init_code.0) - // .unwrap_or_else(|| panic!("failed finding contract for - // {init_code:?}")); - - // let constructor_args = find_contract.constructor_args(); - // let contract = find_contract.contract(); - - // let factory_deps = - // self.dual_compiled_contracts.fetch_all_factory_deps(contract); - - // let create_input = foundry_zksync_core::encode_create_params( - // &input.scheme().unwrap_or(CreateScheme::Create), - // contract.zk_bytecode_hash, - // constructor_args.to_vec(), - // ); - // call_init_code = Bytes::from(create_input); - - // Some(factory_deps) - // } else { - // None - // }; - // let rpc = ecx_inner.db.active_fork_url(); - // let paymaster_params = - // self.paymaster_params.clone().map(|paymaster_data| PaymasterParams { - // paymaster: paymaster_data.address.to_h160(), - // paymaster_input: paymaster_data.input.to_vec(), - // }); - // if let Some(mut factory_deps) = zk_tx { - // let injected_factory_deps = - // self.zk_use_factory_deps.iter().map(|contract| { - // crate::fs::get_artifact_code(self, contract, false) - // .inspect(|_| info!(contract, "pushing factory dep")) - // .unwrap_or_else(|_| { - // panic!("failed to get bytecode for factory deps contract - // {contract}") }) - // .to_vec() - // }).collect_vec(); - // factory_deps.extend(injected_factory_deps); - // 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(input.value()), - // nonce: Some(nonce), - // ..Default::default() - // } - // .into(), - // zk_tx: Some(ZkTransactionMetadata { - // factory_deps, - // paymaster_data: paymaster_params.clone(), - // }), - // }); - - // //update nonce for each tx - // nonce += 1; - // } - // } - - // self.broadcastable_transactions.push_back(BroadcastableTransaction { - // rpc, - // transaction: TransactionRequest { - // from: Some(broadcast.new_origin), - // to, - // value: Some(input.value()), - // input: TransactionInput::new(call_init_code), - // nonce: Some(nonce), - // gas: if is_fixed_gas_limit { Some(input.gas_limit()) } else { None }, - // ..Default::default() - // } - // .into(), - // zk_tx: zk_tx.map(|factory_deps| { - // ZkTransactionMetadata::new(factory_deps, paymaster_params) - // }), - // }); - input.log_debug(self, &input.scheme().unwrap_or(CreateScheme::Create)); } } diff --git a/crates/cheatcodes/src/strategy.rs b/crates/cheatcodes/src/strategy.rs index ed1cfe7dd..f1a37063b 100644 --- a/crates/cheatcodes/src/strategy.rs +++ b/crates/cheatcodes/src/strategy.rs @@ -19,25 +19,28 @@ use crate::{ }; pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { + /// Get nonce. fn get_nonce(&mut self, ccx: &mut CheatsCtxt, address: Address) -> Result { let account = ccx.ecx.journaled_state.load_account(address, &mut ccx.ecx.db)?; Ok(account.info.nonce) } - fn cheatcode_get_nonce(&mut self, ccx: &mut CheatsCtxt, address: Address) -> Result { - evm::get_nonce(ccx, &address) - } + /// Called when the main test or script contract is deployed. + fn base_contract_deployed(&mut self) {} + /// Cheatcode: roll. fn cheatcode_roll(&mut self, ccx: &mut CheatsCtxt, new_height: U256) -> Result { ccx.ecx.env.block.number = new_height; Ok(Default::default()) } + /// Cheatcode: warp. fn cheatcode_warp(&mut self, ccx: &mut CheatsCtxt, new_timestamp: U256) -> Result { ccx.ecx.env.block.number = new_timestamp; Ok(Default::default()) } + /// Cheatcode: deal. fn cheatcode_deal( &mut self, ccx: &mut CheatsCtxt, @@ -51,6 +54,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Cheatcode: etch. fn cheatcode_etch( &mut self, ccx: &mut CheatsCtxt, @@ -64,6 +68,12 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Cheatcode: getNonce. + fn cheatcode_get_nonce(&mut self, ccx: &mut CheatsCtxt, address: Address) -> Result { + evm::get_nonce(ccx, &address) + } + + /// Cheatcode: resetNonce. fn cheatcode_reset_nonce(&mut self, ccx: &mut CheatsCtxt, account: Address) -> Result { let account = journaled_account(ccx.ecx, account)?; // Per EIP-161, EOA nonces start at 0, but contract nonces @@ -76,6 +86,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Cheatcode: setNonce. fn cheatcode_set_nonce( &mut self, ccx: &mut CheatsCtxt, @@ -94,6 +105,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Cheatcode: setNonceUnsafe. fn cheatcode_set_nonce_unsafe( &mut self, ccx: &mut CheatsCtxt, @@ -105,6 +117,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Mocks a call to return with a value. fn mock_call( &mut self, ccx: &mut CheatsCtxt, @@ -117,6 +130,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Mocks a call to revert with a value. fn mock_call_revert( &mut self, ccx: &mut CheatsCtxt, @@ -129,10 +143,12 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { Ok(Default::default()) } + /// Retrieve artifact code. fn get_artifact_code(&self, state: &Cheatcodes, path: &str, deployed: bool) -> Result { Ok(crate::fs::get_artifact_code(state, path, deployed)?.abi_encode()) } + /// Record broadcastable transaction during CREATE. fn record_broadcastable_create_transactions( &mut self, config: Arc, @@ -142,6 +158,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { broadcastable_transactions: &mut BroadcastableTransactions, ); + /// Record broadcastable transaction during CALL. fn record_broadcastable_call_transactions( &mut self, config: Arc, @@ -154,7 +171,7 @@ pub trait CheatcodeInspectorStrategy: Debug + Send + Sync { fn post_initialize_interp(&mut self, _interpreter: &mut Interpreter, _ecx: Ecx) {} - /// Returns true if handled. + /// Used to override opcode behaviors. Returns true if handled. fn pre_step_end(&mut self, _interpreter: &mut Interpreter, _ecx: Ecx) -> bool { false } @@ -230,14 +247,6 @@ pub trait CheatcodeInspectorStrategyExt: CheatcodeInspectorStrategy { fn zksync_select_zk_vm(&mut self, _data: InnerEcx, _enable: bool) { unimplemented!() } - - fn zksync_allow_startup_migration(&mut self) { - unimplemented!() - } - - fn zksync_persist_next_nonce_update(&mut self) { - unimplemented!() - } } #[derive(Debug, Default, Clone)] diff --git a/crates/evm/core/src/backend/cow.rs b/crates/evm/core/src/backend/cow.rs index ea6f6bd66..06d1f305b 100644 --- a/crates/evm/core/src/backend/cow.rs +++ b/crates/evm/core/src/backend/cow.rs @@ -114,11 +114,6 @@ impl<'a> CowBackend<'a> { } impl DatabaseExt for CowBackend<'_> { - fn initialize(&mut self, env: &EnvWithHandlerCfg) { - self.backend.to_mut().initialize(&env); - self.is_initialized = true; - } - fn get_fork_info(&mut self, id: LocalForkId) -> eyre::Result { self.backend.to_mut().get_fork_info(id) } diff --git a/crates/evm/core/src/backend/mod.rs b/crates/evm/core/src/backend/mod.rs index 52fd6b942..3f117e81b 100644 --- a/crates/evm/core/src/backend/mod.rs +++ b/crates/evm/core/src/backend/mod.rs @@ -88,9 +88,6 @@ pub struct ForkInfo { /// An extension trait that allows us to easily extend the `revm::Inspector` capabilities #[auto_impl::auto_impl(&mut)] pub trait DatabaseExt: Database + DatabaseCommit { - /// Initialize any settings that must be tracked while switching evms. - fn initialize(&mut self, env: &EnvWithHandlerCfg); - /// Creates a new state snapshot at the current point of execution. /// /// A state snapshot is associated with a new unique id that's created for the snapshot. @@ -468,6 +465,7 @@ struct _ObjectSafe(dyn DatabaseExt); #[derive(Clone, Debug)] #[must_use] pub struct Backend { + /// The behavior strategy. pub strategy: Arc>, /// The access point for managing forks @@ -818,6 +816,14 @@ impl Backend { logs } + /// Initializes settings we need to keep track of. + /// + /// We need to track these mainly to prevent issues when switching between different evms + pub(crate) fn initialize(&mut self, env: &EnvWithHandlerCfg) { + self.set_caller(env.tx.caller); + self.set_spec_id(env.handler_cfg.spec_id); + } + /// Returns the `EnvWithHandlerCfg` with the current `spec_id` set. fn env_with_handler_cfg(&self, env: Env) -> EnvWithHandlerCfg { EnvWithHandlerCfg::new_with_spec_id(Box::new(env), self.inner.spec_id) @@ -975,14 +981,6 @@ impl Backend { } impl DatabaseExt for Backend { - /// Initializes settings we need to keep track of. - /// - /// We need to track these mainly to prevent issues when switching between different evms - fn initialize(&mut self, env: &EnvWithHandlerCfg) { - self.set_caller(env.tx.caller); - self.set_spec_id(env.handler_cfg.spec_id); - } - fn get_fork_info(&mut self, id: LocalForkId) -> eyre::Result { let fork_id = self.ensure_fork_id(id).cloned()?; let fork_env = self diff --git a/crates/forge/src/runner.rs b/crates/forge/src/runner.rs index 3a3e91f8d..5563a909f 100644 --- a/crates/forge/src/runner.rs +++ b/crates/forge/src/runner.rs @@ -150,19 +150,8 @@ impl ContractRunner<'_> { // to simulate EVM behavior where only the tx that deploys the test contract increments the // nonce. if let Some(cheatcodes) = &mut self.executor.inspector.cheatcodes { - debug!("test contract deployed, allowing startup storage migration"); - cheatcodes - .strategy - .lock() - .expect("failed acquiring strategy") - .zksync_allow_startup_migration(); - - debug!("test contract deployed, allowing persisting next nonce update"); - cheatcodes - .strategy - .lock() - .expect("failed acquiring strategy") - .zksync_persist_next_nonce_update(); + debug!("test contract deployed"); + cheatcodes.strategy.lock().expect("failed acquiring strategy").base_contract_deployed(); } // Optionally call the `setUp` function diff --git a/crates/script/src/runner.rs b/crates/script/src/runner.rs index 3e4b92a3e..429751e50 100644 --- a/crates/script/src/runner.rs +++ b/crates/script/src/runner.rs @@ -173,19 +173,8 @@ impl ScriptRunner { // to simulate EVM behavior where only the tx that deploys the test contract increments the // nonce. if let Some(cheatcodes) = &mut self.executor.inspector.cheatcodes { - debug!("script deployed, allowing startup storage migration"); - cheatcodes - .strategy - .lock() - .expect("failed acquiring strategy") - .zksync_allow_startup_migration(); - - debug!("script deployed, allowing persisting next nonce update"); - cheatcodes - .strategy - .lock() - .expect("failed acquiring strategy") - .zksync_persist_next_nonce_update(); + debug!("script deployed"); + cheatcodes.strategy.lock().expect("failed acquiring strategy").base_contract_deployed(); } // Optionally call the `setUp` function diff --git a/crates/strategy/core/Cargo.toml b/crates/strategy/core/Cargo.toml deleted file mode 100644 index 8098bfab8..000000000 --- a/crates/strategy/core/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "foundry-strategy-core" - -version.workspace = true -edition.workspace = true -rust-version.workspace = true -authors.workspace = true -license.workspace = true -homepage.workspace = true -repository.workspace = true - -[lints] -workspace = true - -[dependencies] -foundry-evm-core.workspace = true diff --git a/crates/strategy/core/src/lib.rs b/crates/strategy/core/src/lib.rs deleted file mode 100644 index b8bbb73cd..000000000 --- a/crates/strategy/core/src/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::sync::{Arc, Mutex}; - -use foundry_evm_core::backend::strategy::{BackendStrategy, EvmBackendStrategy}; - -pub trait RunnerStrategy: Send + Sync { - fn name(&self) -> &'static str; - fn backend_strategy(&self) -> Arc>; -} - -pub struct EvmRunnerStrategy { - pub backend: Arc>, -} -impl Default for EvmRunnerStrategy { - fn default() -> Self { - Self { backend: Arc::new(Mutex::new(EvmBackendStrategy)) } - } -} -impl RunnerStrategy for EvmRunnerStrategy { - fn name(&self) -> &'static str { - "evm" - } - - fn backend_strategy(&self) -> Arc> { - self.backend.clone() - } -} diff --git a/crates/strategy/zksync/Cargo.toml b/crates/strategy/zksync/Cargo.toml index 65c7c2ac1..255023872 100644 --- a/crates/strategy/zksync/Cargo.toml +++ b/crates/strategy/zksync/Cargo.toml @@ -14,7 +14,6 @@ workspace = true [dependencies] alloy-sol-types.workspace = true -alloy-serde.workspace = true alloy-json-abi.workspace = true foundry-common.workspace = true foundry-config.workspace = true @@ -23,7 +22,6 @@ foundry-evm.workspace = true foundry-evm-traces.workspace = true foundry-evm-core.workspace = true foundry-cheatcodes.workspace = true -foundry-strategy-core.workspace = true foundry-zksync-core.workspace = true foundry-zksync-compiler.workspace = true revm-inspectors.workspace = true diff --git a/crates/strategy/zksync/src/backend.rs b/crates/strategy/zksync/src/backend.rs index 2fe0de98d..1cc2b1b71 100644 --- a/crates/strategy/zksync/src/backend.rs +++ b/crates/strategy/zksync/src/backend.rs @@ -73,8 +73,9 @@ impl BackendStrategy for ZksyncBackendStrategy { fork_journaled_state: &mut JournaledState, ) { self.evm.merge_journaled_state_data(addr, active_journaled_state, fork_journaled_state); - let zk_state = &ZkMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; - ZkBackendMergeStrategy::merge_zk_journaled_state_data( + let zk_state = + &ZksyncMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; + ZksyncBackendMerge::merge_zk_journaled_state_data( addr, active_journaled_state, fork_journaled_state, @@ -84,8 +85,9 @@ impl BackendStrategy for ZksyncBackendStrategy { fn merge_db_account_data(&self, addr: Address, active: &ForkDB, fork_db: &mut ForkDB) { self.evm.merge_db_account_data(addr, active, fork_db); - let zk_state = &ZkMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; - ZkBackendMergeStrategy::merge_zk_account_data(addr, active, fork_db, zk_state); + let zk_state = + &ZksyncMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; + ZksyncBackendMerge::merge_zk_account_data(addr, active, fork_db, zk_state); } fn set_inspect_context(&mut self, other_fields: OtherFields) { @@ -157,9 +159,10 @@ impl ZksyncBackendStrategy { // } let accounts = backend_inner.persistent_accounts.iter().copied(); - let zk_state = &ZkMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; + let zk_state = + &ZksyncMergeState { persistent_immutable_keys: &self.persistent_immutable_keys }; if let Some(db) = fork_info.active_fork.map(|f| &f.db) { - ZkBackendMergeStrategy::merge_account_data( + ZksyncBackendMerge::merge_account_data( accounts, db, active_journaled_state, @@ -167,7 +170,7 @@ impl ZksyncBackendStrategy { zk_state, ) } else { - ZkBackendMergeStrategy::merge_account_data( + ZksyncBackendMerge::merge_account_data( accounts, mem_db, active_journaled_state, @@ -178,14 +181,14 @@ impl ZksyncBackendStrategy { } } -pub(crate) struct ZkBackendMergeStrategy; +pub(crate) struct ZksyncBackendMerge; /// Defines the zksync specific state to help during merge. -pub(crate) struct ZkMergeState<'a> { +pub(crate) struct ZksyncMergeState<'a> { persistent_immutable_keys: &'a HashMap>, } -impl ZkBackendMergeStrategy { +impl ZksyncBackendMerge { /// Clones the data of the given `accounts` from the `active` database into the `fork_db` /// This includes the data held in storage (`CacheDB`) and kept in the `JournaledState`. pub fn merge_account_data( @@ -193,7 +196,7 @@ impl ZkBackendMergeStrategy { active: &CacheDB, active_journaled_state: &mut JournaledState, target_fork: &mut Fork, - zk_state: &ZkMergeState<'_>, + zk_state: &ZksyncMergeState<'_>, ) { for addr in accounts.into_iter() { EvmBackendMergeStrategy::merge_db_account_data(addr, active, &mut target_fork.db); @@ -225,7 +228,7 @@ impl ZkBackendMergeStrategy { addr: Address, active: &CacheDB, fork_db: &mut ForkDB, - _zk_state: &ZkMergeState<'_>, + _zk_state: &ZksyncMergeState<'_>, ) { let merge_system_contract_entry = |fork_db: &mut ForkDB, system_contract: Address, slot: U256| { @@ -293,7 +296,7 @@ impl ZkBackendMergeStrategy { addr: Address, active_journaled_state: &JournaledState, fork_journaled_state: &mut JournaledState, - zk_state: &ZkMergeState<'_>, + zk_state: &ZksyncMergeState<'_>, ) { let merge_system_contract_entry = |fork_journaled_state: &mut JournaledState, system_contract: Address, slot: U256| { diff --git a/crates/strategy/zksync/src/cheatcode.rs b/crates/strategy/zksync/src/cheatcode.rs index 37d8fbfe6..75e2f11dc 100644 --- a/crates/strategy/zksync/src/cheatcode.rs +++ b/crates/strategy/zksync/src/cheatcode.rs @@ -216,6 +216,13 @@ impl CheatcodeInspectorStrategy for ZksyncCheatcodeInspectorStrategy { Ok(nonce) } + fn base_contract_deployed(&mut self) { + debug!("allowing startup storage migration"); + self.zk_startup_migration.allow(); + debug!("allowing persisting next nonce update"); + self.zk_persist_nonce_update.persist_next(); + } + fn cheatcode_get_nonce( &mut self, ccx: &mut CheatsCtxt<'_, '_, '_, '_>, @@ -1092,14 +1099,6 @@ impl CheatcodeInspectorStrategyExt for ZksyncCheatcodeInspectorStrategy { self.select_evm(data); } } - - fn zksync_allow_startup_migration(&mut self) { - self.zk_startup_migration.allow(); - } - - fn zksync_persist_next_nonce_update(&mut self) { - self.zk_persist_nonce_update.persist_next(); - } } impl ZksyncCheatcodeInspectorStrategy { diff --git a/crates/strategy/zksync/src/lib.rs b/crates/strategy/zksync/src/lib.rs index e5218d0ba..8deee5653 100644 --- a/crates/strategy/zksync/src/lib.rs +++ b/crates/strategy/zksync/src/lib.rs @@ -1,3 +1,10 @@ +//! # foundry-strategy-zksync +//! +//! Strategies for ZKsync network. + +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + mod backend; mod cheatcode; mod executor; @@ -5,30 +12,3 @@ mod executor; pub use backend::{get_zksync_transaction_metadata, ZksyncBackendStrategy}; pub use cheatcode::ZksyncCheatcodeInspectorStrategy; pub use executor::ZksyncExecutorStrategy; - -// #[derive(Debug, Default, Clone)] -// pub struct ZksyncStrategy; - -// impl GlobalStrategy for ZksyncStrategy { -// type Backend = ZkBackendStrategy; -// type Executor = ZkExecutor; -// type CheatcodeInspector = ZkCheatcodeInspector; -// } - -// pub struct ZkRunnerStrategy { -// pub backend: Arc>, -// } -// impl Default for ZkRunnerStrategy { -// fn default() -> Self { -// Self { backend: Arc::new(Mutex::new(ZksyncBackendStrategy::default())) } -// } -// } -// impl RunnerStrategy for ZkRunnerStrategy { -// fn name(&self) -> &'static str { -// "zk" -// } - -// fn backend_strategy(&self) -> Arc> { -// self.backend.clone() -// } -// }