From 3c5ea311e069ae3ca66adda042f03a32d162e346 Mon Sep 17 00:00:00 2001 From: Danil Date: Thu, 23 May 2024 18:15:08 +0200 Subject: [PATCH] Revert "feat(zk-toolbox): add balance check (#2016)" This reverts commit a8b8e4b1b1a3f91b1a52762f2fd30006d323e348. --- zk_toolbox/crates/common/src/ethereum.rs | 18 +++----- zk_toolbox/crates/common/src/forge.rs | 42 ------------------- .../crates/common/src/prompt/confirm.rs | 3 +- .../zk_inception/src/accept_ownership.rs | 10 ++--- .../src/commands/chain/deploy_paymaster.rs | 8 ++-- .../zk_inception/src/commands/chain/init.rs | 12 ++---- .../src/commands/chain/initialize_bridges.rs | 8 ++-- .../zk_inception/src/commands/chain/mod.rs | 4 +- .../src/commands/ecosystem/init.rs | 29 +++++-------- zk_toolbox/crates/zk_inception/src/consts.rs | 2 - .../crates/zk_inception/src/forge_utils.rs | 17 -------- 11 files changed, 31 insertions(+), 122 deletions(-) diff --git a/zk_toolbox/crates/common/src/ethereum.rs b/zk_toolbox/crates/common/src/ethereum.rs index a3bb611d48d5..7771b7500d4f 100644 --- a/zk_toolbox/crates/common/src/ethereum.rs +++ b/zk_toolbox/crates/common/src/ethereum.rs @@ -1,25 +1,14 @@ use std::{ops::Add, time::Duration}; use ethers::{ - core::k256::ecdsa::SigningKey, middleware::MiddlewareBuilder, - prelude::{Http, LocalWallet, Provider}, - prelude::{SignerMiddleware, H256}, + prelude::{Http, LocalWallet, Provider, Signer}, providers::Middleware, types::{Address, TransactionRequest}, }; use crate::wallets::Wallet; -pub fn create_ethers_client( - private_key: H256, - l1_rpc: String, -) -> anyhow::Result, ethers::prelude::Wallet>> { - let wallet = LocalWallet::from_bytes(private_key.as_bytes())?; - let client = Provider::::try_from(l1_rpc)?.with_signer(wallet); - Ok(client) -} - pub async fn distribute_eth( main_wallet: Wallet, addresses: Vec
, @@ -27,7 +16,10 @@ pub async fn distribute_eth( chain_id: u32, amount: u128, ) -> anyhow::Result<()> { - let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc)?; + let wallet = LocalWallet::from_bytes(main_wallet.private_key.unwrap().as_bytes())? + .with_chain_id(chain_id); + let client = Provider::::try_from(l1_rpc)?.with_signer(wallet); + let mut pending_txs = vec![]; let mut nonce = client.get_transaction_count(client.address(), None).await?; for address in addresses { diff --git a/zk_toolbox/crates/common/src/forge.rs b/zk_toolbox/crates/common/src/forge.rs index 28369beb7a80..ac2d9252ba22 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zk_toolbox/crates/common/src/forge.rs @@ -1,17 +1,12 @@ use std::path::{Path, PathBuf}; -use std::str::FromStr; use clap::Parser; -use ethers::abi::Address; -use ethers::middleware::Middleware; -use ethers::prelude::{LocalWallet, Signer, U256}; use ethers::{abi::AbiEncode, types::H256}; use serde::{Deserialize, Serialize}; use strum_macros::Display; use xshell::{cmd, Shell}; use crate::cmd::Cmd; -use crate::ethereum::create_ethers_client; /// Forge is a wrapper around the forge binary. pub struct Forge { @@ -98,43 +93,6 @@ impl ForgeScript { }); self } - // Do not start the script if balance is not enough - pub fn private_key(&self) -> Option { - self.args.args.iter().find_map(|a| { - if let ForgeScriptArg::PrivateKey { private_key } = a { - Some(H256::from_str(private_key).unwrap()) - } else { - None - } - }) - } - - pub fn rpc_url(&self) -> Option { - self.args.args.iter().find_map(|a| { - if let ForgeScriptArg::RpcUrl { url } = a { - Some(url.clone()) - } else { - None - } - }) - } - - pub fn address(&self) -> Option
{ - self.private_key() - .flat_map(|a| LocalWallet::from_bytes(a.as_bytes()).map(|a| a.address())) - } - - pub async fn check_the_balance(&self, minimum_value: U256) -> anyhow::Result { - let Some(rpc_url) = self.rpc_url() else { - return Ok(true) - }; - let Some(private_key) = self.private_key() else { - return Ok(true) - }; - let client = create_ethers_client(private_key, rpc_url)?; - let balance = client.get_balance(client.address(), None).await?; - Ok(balance > minimum_value)) - } } const PROHIBITED_ARGS: [&str; 10] = [ diff --git a/zk_toolbox/crates/common/src/prompt/confirm.rs b/zk_toolbox/crates/common/src/prompt/confirm.rs index 195654e7d65a..19239c31c799 100644 --- a/zk_toolbox/crates/common/src/prompt/confirm.rs +++ b/zk_toolbox/crates/common/src/prompt/confirm.rs @@ -1,12 +1,11 @@ use cliclack::Confirm; -use std::fmt::Display; pub struct PromptConfirm { inner: Confirm, } impl PromptConfirm { - pub fn new(question: impl Display) -> Self { + pub fn new(question: &str) -> Self { Self { inner: Confirm::new(question), } diff --git a/zk_toolbox/crates/zk_inception/src/accept_ownership.rs b/zk_toolbox/crates/zk_inception/src/accept_ownership.rs index 932666db70be..420c4efcaa88 100644 --- a/zk_toolbox/crates/zk_inception/src/accept_ownership.rs +++ b/zk_toolbox/crates/zk_inception/src/accept_ownership.rs @@ -5,7 +5,6 @@ use common::{ use ethers::{abi::Address, types::H256}; use xshell::Shell; -use crate::forge_utils::check_the_balance; use crate::{ configs::{ forge_interface::accept_ownership::AcceptOwnershipInput, EcosystemConfig, SaveConfig, @@ -14,7 +13,7 @@ use crate::{ forge_utils::fill_forge_private_key, }; -pub async fn accept_admin( +pub fn accept_admin( shell: &Shell, ecosystem_config: &EcosystemConfig, governor_contract: Address, @@ -37,10 +36,9 @@ pub async fn accept_admin( target_address, forge, ) - .await } -pub async fn accept_owner( +pub fn accept_owner( shell: &Shell, ecosystem_config: &EcosystemConfig, governor_contract: Address, @@ -63,10 +61,9 @@ pub async fn accept_owner( target_address, forge, ) - .await } -async fn accept_ownership( +fn accept_ownership( shell: &Shell, ecosystem_config: &EcosystemConfig, governor_contract: Address, @@ -85,7 +82,6 @@ async fn accept_ownership( forge = fill_forge_private_key(forge, governor)?; - check_the_balance(&forge).await?; let spinner = Spinner::new("Accepting governance"); forge.run(shell)?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index 1b0e78883d14..23016856bfbe 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -6,7 +6,6 @@ use common::{ }; use xshell::Shell; -use crate::forge_utils::check_the_balance; use crate::{ configs::{ forge_interface::paymaster::{DeployPaymasterInput, DeployPaymasterOutput}, @@ -16,16 +15,16 @@ use crate::{ forge_utils::fill_forge_private_key, }; -pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { +pub fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let chain_name = global_config().chain_name.clone(); let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain_config = ecosystem_config .load_chain(chain_name) .context("Chain not initialized. Please create a chain first")?; - deploy_paymaster(shell, &chain_config, &ecosystem_config, args).await + deploy_paymaster(shell, &chain_config, &ecosystem_config, args) } -pub async fn deploy_paymaster( +pub fn deploy_paymaster( shell: &Shell, chain_config: &ChainConfig, ecosystem_config: &EcosystemConfig, @@ -47,7 +46,6 @@ pub async fn deploy_paymaster( )?; let spinner = Spinner::new("Deploying paymaster"); - check_the_balance(&forge).await?; forge.run(shell)?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 1f6ac66b9d2a..ae14ef1fc2ac 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -8,7 +8,6 @@ use common::{ use xshell::Shell; use super::args::init::InitArgsFinal; -use crate::forge_utils::check_the_balance; use crate::{ accept_ownership::accept_admin, commands::chain::{ @@ -73,8 +72,7 @@ pub async fn init( chain_config.get_wallets_config()?.governor_private_key(), contracts_config.l1.diamond_proxy_addr, &init_args.forge_args.clone(), - ) - .await?; + )?; spinner.finish(); initialize_bridges::initialize_bridges( @@ -82,8 +80,7 @@ pub async fn init( chain_config, ecosystem_config, init_args.forge_args.clone(), - ) - .await?; + )?; if init_args.deploy_paymaster { deploy_paymaster::deploy_paymaster( @@ -91,8 +88,7 @@ pub async fn init( chain_config, ecosystem_config, init_args.forge_args.clone(), - ) - .await?; + )?; } genesis( @@ -128,7 +124,7 @@ async fn register_chain( .with_broadcast(); forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; - check_the_balance(&forge).await?; + forge.run(shell)?; let register_chain_output = diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs index 84635c6cd032..c28965a97c2b 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs @@ -9,7 +9,6 @@ use common::{ }; use xshell::{cmd, Shell}; -use crate::forge_utils::check_the_balance; use crate::{ configs::{ forge_interface::initialize_bridges::{ @@ -21,7 +20,7 @@ use crate::{ forge_utils::fill_forge_private_key, }; -pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { +pub fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let chain_name = global_config().chain_name.clone(); let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain_config = ecosystem_config @@ -29,13 +28,13 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { .context("Chain not initialized. Please create a chain first")?; let spinner = Spinner::new("Initializing bridges"); - initialize_bridges(shell, &chain_config, &ecosystem_config, args).await?; + initialize_bridges(shell, &chain_config, &ecosystem_config, args)?; spinner.finish(); Ok(()) } -pub async fn initialize_bridges( +pub fn initialize_bridges( shell: &Shell, chain_config: &ChainConfig, ecosystem_config: &EcosystemConfig, @@ -57,7 +56,6 @@ pub async fn initialize_bridges( ecosystem_config.get_wallets()?.governor_private_key(), )?; - check_the_balance(&forge).await?; forge.run(shell)?; let output = diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index 759b4aaea557..b7f219a7f159 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -32,7 +32,7 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<() ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(args, shell).await, ChainCommands::Genesis(args) => genesis::run(args, shell).await, - ChainCommands::InitializeBridges(args) => initialize_bridges::run(args, shell).await, - ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell).await, + ChainCommands::InitializeBridges(args) => initialize_bridges::run(args, shell), + ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell), } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 005c81736cff..b9eb6594ecf7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -15,7 +15,6 @@ use common::{ use xshell::{cmd, Shell}; use super::args::init::{EcosystemArgsFinal, EcosystemInitArgs, EcosystemInitArgsFinal}; -use crate::forge_utils::check_the_balance; use crate::{ accept_ownership::accept_owner, commands::{ @@ -60,8 +59,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { shell, &ecosystem_config, &initial_deployment_config, - ) - .await?; + )?; if final_ecosystem_args.deploy_erc20 { logger::info("Deploying ERC20 contracts"); @@ -75,8 +73,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { &ecosystem_config, &contracts_config, final_ecosystem_args.forge_args.clone(), - ) - .await?; + )?; } // If the name of chain passed then we deploy exactly this chain otherwise deploy all chains @@ -149,7 +146,7 @@ pub async fn distribute_eth( Ok(()) } -async fn init( +fn init( init_args: &mut EcosystemInitArgsFinal, shell: &Shell, ecosystem_config: &EcosystemConfig, @@ -167,13 +164,12 @@ async fn init( init_args.forge_args.clone(), ecosystem_config, initial_deployment_config, - ) - .await?; + )?; contracts.save(shell, ecosystem_config.config.clone().join(CONTRACTS_FILE))?; Ok(contracts) } -async fn deploy_erc20( +fn deploy_erc20( shell: &Shell, erc20_deployment_config: &Erc20DeploymentConfig, ecosystem_config: &EcosystemConfig, @@ -196,7 +192,6 @@ async fn deploy_erc20( )?; let spinner = Spinner::new("Deploying ERC20 contracts..."); - check_the_balance(&forge).await?; forge.run(shell)?; spinner.finish(); @@ -206,7 +201,7 @@ async fn deploy_erc20( Ok(result) } -async fn deploy_ecosystem( +fn deploy_ecosystem( shell: &Shell, ecosystem: &mut EcosystemArgsFinal, forge_args: ForgeScriptArgs, @@ -219,8 +214,7 @@ async fn deploy_ecosystem( forge_args, ecosystem_config, initial_deployment_config, - ) - .await; + ); } let ecosystem_contracts_path = match &ecosystem.ecosystem_contracts_path { @@ -259,7 +253,7 @@ async fn deploy_ecosystem( ContractsConfig::read(shell, ecosystem_contracts_path) } -async fn deploy_ecosystem_inner( +fn deploy_ecosystem_inner( shell: &Shell, forge_args: ForgeScriptArgs, config: &EcosystemConfig, @@ -298,7 +292,6 @@ async fn deploy_ecosystem_inner( forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; let spinner = Spinner::new("Deploying ecosystem contracts..."); - check_the_balance(&forge).await?; forge.run(shell)?; spinner.finish(); @@ -312,8 +305,7 @@ async fn deploy_ecosystem_inner( config.get_wallets()?.governor_private_key(), contracts_config.ecosystem_contracts.bridgehub_proxy_addr, &forge_args, - ) - .await?; + )?; accept_owner( shell, @@ -322,8 +314,7 @@ async fn deploy_ecosystem_inner( config.get_wallets()?.governor_private_key(), contracts_config.bridges.shared.l1_address, &forge_args, - ) - .await?; + )?; Ok(contracts_config) } diff --git a/zk_toolbox/crates/zk_inception/src/consts.rs b/zk_toolbox/crates/zk_inception/src/consts.rs index 8993981c4c98..f00cdd48cd94 100644 --- a/zk_toolbox/crates/zk_inception/src/consts.rs +++ b/zk_toolbox/crates/zk_inception/src/consts.rs @@ -42,8 +42,6 @@ pub(super) const TEST_CONFIG_PATH: &str = "etc/test_config/constant/eth.json"; pub(super) const BASE_PATH: &str = "m/44'/60'/0'"; pub(super) const AMOUNT_FOR_DISTRIBUTION_TO_WALLETS: u128 = 1000000000000000000000; -pub(super) const MINIMUM_BALANCE_FOR_WALLET: u128 = 5000000000000000000; - #[derive(PartialEq, Debug, Clone)] pub struct ForgeScriptParams { input: &'static str, diff --git a/zk_toolbox/crates/zk_inception/src/forge_utils.rs b/zk_toolbox/crates/zk_inception/src/forge_utils.rs index 5ee7564ddf74..f2f8a13b2c85 100644 --- a/zk_toolbox/crates/zk_inception/src/forge_utils.rs +++ b/zk_toolbox/crates/zk_inception/src/forge_utils.rs @@ -1,4 +1,3 @@ -use crate::consts::MINIMUM_BALANCE_FOR_WALLET; use anyhow::anyhow; use common::forge::ForgeScript; use ethers::types::H256; @@ -13,19 +12,3 @@ pub fn fill_forge_private_key( } Ok(forge) } - -pub async fn check_the_balance(forge: &ForgeScript) -> anyhow::Result<()> { - let Some(address) = forge.address() else { - return Ok(()); - }; - - while !forge - .check_the_balance(MINIMUM_BALANCE_FOR_WALLET.into()) - .await? - { - if common::PromptConfirm::new(format!("Address {address:?} doesn't have enough money to deploy contracts do you want to continue?")).ask() { - break; - } - } - Ok(()) -}