diff --git a/Cargo.lock b/Cargo.lock index 378f37216..cfeba49f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2218,7 +2218,6 @@ dependencies = [ "ethrex-storage", "ethrex-vm", "hex", - "revm 14.0.3", "risc0-zkvm", "serde", "serde_json", @@ -3490,19 +3489,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "kzg-rs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0850eb19206463a61bede4f7b7e6b21731807137619044b1f3c287ebcfe2b3b0" -dependencies = [ - "ff", - "hex", - "sha2", - "sp1_bls12_381", - "spin", -] - [[package]] name = "lazy-regex" version = "3.3.0" @@ -4086,15 +4072,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "parity-scale-codec" version = "3.7.0" @@ -4900,7 +4877,6 @@ dependencies = [ "c-kzg", "cfg-if", "k256", - "kzg-rs", "once_cell", "revm-primitives 10.0.0", "ripemd", @@ -4947,7 +4923,6 @@ dependencies = [ "dyn-clone", "enumn", "hex", - "kzg-rs", "serde", ] @@ -5449,30 +5424,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scale-info" -version = "2.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346a3b32eba2640d17a9cb5927056b08f3de90f65b72fe09402c2ad07d684d0b" -dependencies = [ - "cfg-if", - "derive_more 1.0.0", - "parity-scale-codec", - "scale-info-derive", -] - -[[package]] -name = "scale-info-derive" -version = "2.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6630024bf739e2179b91fb424b28898baf819414262c5d376677dbff1fe7ebf" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.89", -] - [[package]] name = "schannel" version = "0.1.27" @@ -5814,16 +5765,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" -[[package]] -name = "snowbridge-amcl" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460a9ed63cdf03c1b9847e8a12a5f5ba19c4efd5869e4a737e05be25d7c427e5" -dependencies = [ - "parity-scale-codec", - "scale-info", -] - [[package]] name = "socket2" version = "0.5.8" @@ -5834,35 +5775,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "sp1-lib" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bea7811abd2d3a991007fcb284f41152840b8388c171288d0c52c6793956609c" -dependencies = [ - "anyhow", - "bincode", - "cfg-if", - "hex", - "serde", - "snowbridge-amcl", -] - -[[package]] -name = "sp1_bls12_381" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27c4b8901334dc09099dd82f80a72ddfc76b0046f4b342584c808f1931bed5a" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core 0.6.4", - "sp1-lib", - "subtle", -] - [[package]] name = "spin" version = "0.9.8" diff --git a/crates/l2/Cargo.toml b/crates/l2/Cargo.toml index aa4637ec3..f69ea8ae4 100644 --- a/crates/l2/Cargo.toml +++ b/crates/l2/Cargo.toml @@ -46,3 +46,4 @@ expect_used = "deny" indexing_slicing = "deny" as_conversions = "deny" unnecessary_cast = "warn" +panic = "deny" diff --git a/crates/l2/contracts/Cargo.toml b/crates/l2/contracts/Cargo.toml index 9609c5fe3..00ce23d1d 100644 --- a/crates/l2/contracts/Cargo.toml +++ b/crates/l2/contracts/Cargo.toml @@ -31,3 +31,4 @@ expect_used = "deny" indexing_slicing = "deny" as_conversions = "deny" unnecessary_cast = "warn" +panic = "deny" diff --git a/crates/l2/contracts/deployer.rs b/crates/l2/contracts/deployer.rs index 726fb7f37..80d94d753 100644 --- a/crates/l2/contracts/deployer.rs +++ b/crates/l2/contracts/deployer.rs @@ -2,6 +2,7 @@ use bytes::Bytes; use colored::Colorize; use ethereum_types::{Address, H160, H256}; use ethrex_core::U256; +use ethrex_l2::utils::config::errors; use ethrex_l2::utils::eth_client::errors::EthClientError; use ethrex_l2::utils::{ config::{read_env_as_lines, read_env_file, write_env}, @@ -15,7 +16,6 @@ use std::{ process::Command, str::FromStr, }; -use tracing::warn; struct SetupResult { deployer_address: Address, @@ -45,6 +45,8 @@ pub enum DeployError { EthClientError(#[from] EthClientError), #[error("Deployer decoding error: {0}")] DecodingError(String), + #[error("Failed to interact with .env file, error: {0}")] + EnvFileError(#[from] errors::ConfigError), } // 0x4e59b44847b379578588920cA78FbF26c0B4956C @@ -58,35 +60,20 @@ lazy_static::lazy_static! { } #[tokio::main] -async fn main() { - let Ok(setup_result) = setup() else { - panic!("Failed on setup"); - }; - if let Err(e) = download_contract_deps(&setup_result.contracts_path) { - panic!("Failed to download contracts {e}"); - }; - if let Err(e) = compile_contracts(&setup_result.contracts_path) { - panic!("Failed to compile contracts {e}"); - }; +async fn main() -> Result<(), DeployError> { + let setup_result = setup()?; + download_contract_deps(&setup_result.contracts_path)?; + compile_contracts(&setup_result.contracts_path)?; - let on_chain_proposer; - let bridge_address; - match deploy_contracts( + let (on_chain_proposer, bridge_address) = deploy_contracts( setup_result.deployer_address, setup_result.deployer_private_key, &setup_result.eth_client, &setup_result.contracts_path, ) - .await - { - Ok((ocp, ba)) => { - on_chain_proposer = ocp; - bridge_address = ba; - } - Err(e) => panic!("Failed to deploy contracts {e}"), - }; + .await?; - if let Err(err) = initialize_contracts( + initialize_contracts( setup_result.deployer_address, setup_result.deployer_private_key, setup_result.committer_address, @@ -96,14 +83,9 @@ async fn main() { setup_result.contract_verifier_address, &setup_result.eth_client, ) - .await - { - panic!("Failed to initialize contracts: {err}"); - } + .await?; - let Ok(env_lines) = read_env_as_lines() else { - panic!("Failed to read env file as lines."); - }; + let env_lines = read_env_as_lines().map_err(DeployError::EnvFileError)?; let mut wr_lines: Vec = Vec::new(); let mut env_lines_iter = env_lines.into_iter(); @@ -122,18 +104,12 @@ async fn main() { } wr_lines.push(line); } - if let Err(err) = write_env(wr_lines) { - panic!( - "{}", - format!("Failed to write changes to the .env file: {err}") - ); - } + write_env(wr_lines).map_err(DeployError::EnvFileError)?; + Ok(()) } fn setup() -> Result { - if let Err(e) = read_env_file() { - warn!("Failed to read .env file: {e}"); - } + read_env_file()?; let eth_client = EthClient::new(&read_env_var("ETH_RPC_URL")?); @@ -650,13 +626,14 @@ async fn wait_for_transaction_receipt( #[allow(clippy::unwrap_used)] #[allow(clippy::expect_used)] +#[allow(clippy::panic)] #[cfg(test)] mod test { - use crate::{compile_contracts, download_contract_deps}; + use crate::{compile_contracts, download_contract_deps, DeployError}; use std::{env, path::Path}; #[test] - fn test_contract_compilation() { + fn test_contract_compilation() -> Result<(), DeployError> { let binding = env::current_dir().unwrap(); let parent_dir = binding.parent().unwrap(); @@ -676,14 +653,11 @@ mod test { } } - if download_contract_deps(Path::new("contracts")).is_err() { - panic!("failed to download contract deps"); - }; - if compile_contracts(Path::new("contracts")).is_err() { - panic!("failed to compile contracts"); - }; + download_contract_deps(Path::new("contracts"))?; + compile_contracts(Path::new("contracts"))?; std::fs::remove_dir_all(solc_out).unwrap(); std::fs::remove_dir_all(lib).unwrap(); + Ok(()) } } diff --git a/crates/l2/proposer/mod.rs b/crates/l2/proposer/mod.rs index 99e7f1ec3..63efc0dbb 100644 --- a/crates/l2/proposer/mod.rs +++ b/crates/l2/proposer/mod.rs @@ -20,13 +20,15 @@ pub struct Proposer { engine_config: EngineApiConfig, block_production_interval: u64, coinbase_address: Address, + jwt_secret: Vec, } pub async fn start_proposer(store: Store) { info!("Starting Proposer"); if let Err(e) = read_env_file() { - panic!("Failed to read .env file: {e}"); + error!("Failed to read .env file: {e}"); + return; } let mut task_set = JoinSet::new(); @@ -39,10 +41,14 @@ pub async fn start_proposer(store: Store) { match res { Ok(Ok(_)) => {} Ok(Err(err)) => { - panic!("Error starting Proposer: {err}"); + error!("Error starting Proposer: {err}"); + task_set.abort_all(); + break; } Err(err) => { - panic!("Error starting Proposer: {err}"); + error!("JoinSet error: {err}"); + task_set.abort_all(); + break; } }; } @@ -63,10 +69,12 @@ impl Proposer { proposer_config: &ProposerConfig, engine_config: EngineApiConfig, ) -> Result { + let jwt_secret = std::fs::read(&engine_config.jwt_path)?; Ok(Self { engine_config, block_production_interval: proposer_config.interval_ms, coinbase_address: proposer_config.coinbase_address, + jwt_secret, }) } @@ -90,16 +98,9 @@ impl Proposer { .ok_or(ProposerError::StorageDataIsNone)? }; - let Ok(jwt_secret) = std::fs::read(&self.engine_config.jwt_path) else { - panic!( - "Failed to read jwt_secret from: {}", - &self.engine_config.jwt_path - ); - }; - ethrex_dev::block_producer::start_block_producer( self.engine_config.rpc_url.clone(), - jwt_secret.into(), + self.jwt_secret.clone().into(), head_block_hash, 10, self.block_production_interval, diff --git a/crates/l2/prover/Cargo.toml b/crates/l2/prover/Cargo.toml index 2309d4186..eb6e18a8d 100644 --- a/crates/l2/prover/Cargo.toml +++ b/crates/l2/prover/Cargo.toml @@ -26,13 +26,6 @@ ethrex-l2.workspace = true zkvm_interface = { path = "./zkvm/interface", default-features = false } risc0-zkvm = { version = "1.1.2" } -# revm (this dep is temporary, should be replaced with ethrex-vm after ExecutionDB is completely integrated into the L1) -revm = { version = "14.0.3", features = [ - "std", - "serde", - "kzg-rs", -], default-features = false } - [dev-dependencies] ethrex-vm.workspace = true ethrex-storage.workspace = true @@ -57,3 +50,4 @@ expect_used = "deny" indexing_slicing = "deny" as_conversions = "deny" unnecessary_cast = "warn" +panic = "deny" diff --git a/crates/l2/prover/src/main.rs b/crates/l2/prover/src/main.rs index 6f3feb927..9eb5ce426 100644 --- a/crates/l2/prover/src/main.rs +++ b/crates/l2/prover/src/main.rs @@ -10,7 +10,8 @@ async fn main() { .with_max_level(Level::INFO) .finish(); if let Err(e) = tracing::subscriber::set_global_default(subscriber) { - error!("setting default subscriber failed: {e}"); + error!("Failed setting tracing::subscriber: {e}"); + return; } if let Err(e) = read_env_file() { @@ -18,8 +19,10 @@ async fn main() { } let Ok(config) = ProverClientConfig::from_env() else { - panic!("Failed to read ProverClientConfig from .env file"); + error!("Failed to read ProverClientConfig from .env file"); + return; }; + debug!("Prover Client has started"); init_client(config).await; } diff --git a/crates/l2/sdk/Cargo.toml b/crates/l2/sdk/Cargo.toml index 9a99559ba..24223736a 100644 --- a/crates/l2/sdk/Cargo.toml +++ b/crates/l2/sdk/Cargo.toml @@ -26,3 +26,4 @@ expect_used = "deny" indexing_slicing = "deny" as_conversions = "deny" unnecessary_cast = "warn" +panic = "deny" diff --git a/crates/l2/sdk/src/sdk.rs b/crates/l2/sdk/src/sdk.rs index f67c5622c..eec3ad443 100644 --- a/crates/l2/sdk/src/sdk.rs +++ b/crates/l2/sdk/src/sdk.rs @@ -44,7 +44,9 @@ pub async fn wait_for_transaction_receipt( println!("[{try}/{max_retries}] Retrying to get transaction receipt for {tx_hash:#x}"); if max_retries == r#try { - panic!("Transaction receipt for {tx_hash:#x} not found after {max_retries} retries"); + return Err(EthClientError::Custom(format!( + "Transaction receipt for {tx_hash:#x} not found after {max_retries} retries" + ))); } r#try += 1;