diff --git a/Cargo.toml b/Cargo.toml index 24771c264..212d7a276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,9 @@ rust.unreachable_pub = "warn" rust.unused_must_use = "deny" rust.rust_2018_idioms = { level = "deny", priority = -1 } rustdoc.all = "warn" +clippy.unwrap_used = "warn" +clippy.expect_used = "warn" +clippy.todo = "warn" [workspace.dependencies] ark-bn254 = "0.4.0" @@ -111,11 +114,13 @@ tracing-subscriber = { version = "0.3", features = ["json"] } url = "2.5.2" #misc -rust-bls-bn254 = {git = "https://github.com/Layr-Labs/rust-bls-bn254.git", rev = "be3ef87", features = ["std"] } +rust-bls-bn254 = { git = "https://github.com/Layr-Labs/rust-bls-bn254.git", rev = "be3ef87", features = [ + "std", +] } uuid = { version = "1.10.0", features = ["v4"] } -#misc +#misc parking_lot = "0.12" #alloy @@ -130,7 +135,8 @@ alloy-network = { version = "0.1", default-features = false } alloy-node-bindings = { version = "0.1", default-features = false } alloy-primitives = "0.7.2" alloy-provider = { version = "0.1", default-features = false, features = [ - "reqwest", "ws" + "reqwest", + "ws", ] } alloy-pubsub = { version = "0.1", default-features = false } alloy-rlp = "0.3.4" diff --git a/clippy.toml b/clippy.toml index f1acf4b11..531987760 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,3 @@ msrv = "1.79" +allow-unwrap-in-tests = true +allow-expect-in-tests = true diff --git a/crates/chainio/clients/avsregistry/src/error.rs b/crates/chainio/clients/avsregistry/src/error.rs index 730349aa5..6f23b5470 100644 --- a/crates/chainio/clients/avsregistry/src/error.rs +++ b/crates/chainio/clients/avsregistry/src/error.rs @@ -99,7 +99,7 @@ pub enum AvsRegistryError { GetAvsRegistry, /// Pubey registration msg hash - #[error("Failed to regiser pub key message hash")] + #[error("Failed to register pub key message hash")] PubKeyRegistrationMessageHash, /// Failed to calculate operator avs registration digest hash @@ -149,6 +149,14 @@ pub enum AvsRegistryError { /// Invalid Quorum Numbers #[error("Invalid number of quorum numbers")] InvalidQuorumNums, + + /// Invalid Private Key + #[error("Invalid private key")] + InvalidPrivateKey, + + /// Invalid Signature + #[error("Invalid signature")] + InvalidSignature, } impl From for AvsRegistryError { diff --git a/crates/chainio/clients/avsregistry/src/writer.rs b/crates/chainio/clients/avsregistry/src/writer.rs index 0cd63248d..32c81419e 100644 --- a/crates/chainio/clients/avsregistry/src/writer.rs +++ b/crates/chainio/clients/avsregistry/src/writer.rs @@ -143,7 +143,8 @@ impl AvsRegistryChainWriter { socket: String, ) -> Result { let provider = get_signer(self.signer.clone(), &self.provider); - let wallet = PrivateKeySigner::from_str(&self.signer).expect("failed to generate wallet "); + let wallet = PrivateKeySigner::from_str(&self.signer) + .map_err(|_| AvsRegistryError::InvalidPrivateKey)?; // tracing info info!(avs_service_manager = %self.service_manager_addr, operator= %wallet.address(),quorum_numbers = ?quorum_numbers,"quorum_numbers,registering operator with the AVS's registry coordinator"); @@ -186,7 +187,7 @@ impl AvsRegistryChainWriter { let operator_signature = wallet .sign_hash(&msg_to_sign) .await - .expect("failed to sign message"); + .map_err(|_| AvsRegistryError::InvalidSignature)?; let operator_signature_with_salt_and_expiry = SignatureWithSaltAndExpiry { signature: operator_signature.as_bytes().into(), diff --git a/examples/avsregistry-read/examples/get_operator_from_id.rs b/examples/avsregistry-read/examples/get_operator_from_id.rs index 00dddab37..634d61652 100644 --- a/examples/avsregistry-read/examples/get_operator_from_id.rs +++ b/examples/avsregistry-read/examples/get_operator_from_id.rs @@ -7,6 +7,7 @@ use eyre::Result; use std::str::FromStr; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; @@ -21,10 +22,7 @@ async fn main() -> Result<()> { let operator_id = FixedBytes::from_str("0xb31102e4cf235efcb84545cb656b039782755994835365d1cd11764ccb4f2fdd") .expect("invalid operator id "); - let operator_address = avs_registry - .get_operator_from_id(*operator_id) - .await - .unwrap(); + let operator_address = avs_registry.get_operator_from_id(*operator_id).await?; println!("operator address is :{:?}", operator_address); Ok(()) diff --git a/examples/avsregistry-read/examples/get_operator_id.rs b/examples/avsregistry-read/examples/get_operator_id.rs index 8d63c08b4..2772d8266 100644 --- a/examples/avsregistry-read/examples/get_operator_id.rs +++ b/examples/avsregistry-read/examples/get_operator_id.rs @@ -6,6 +6,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST use eyre::Result; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; let avs_registry = AvsRegistryChainReader::new( @@ -18,7 +19,7 @@ async fn main() -> Result<()> { .expect("failed to build avs registry chain reader"); let operator: Address = address!("1D79000206BAFfaE662fFCdba1C2a6176d14dF48"); - let operator_id = avs_registry.get_operator_id(operator).await.unwrap(); + let operator_id = avs_registry.get_operator_id(operator).await?; println!("operator id is :{:?}", operator_id); Ok(()) diff --git a/examples/avsregistry-read/examples/get_operator_stake_in_quorums_of_operator_at_current_block.rs b/examples/avsregistry-read/examples/get_operator_stake_in_quorums_of_operator_at_current_block.rs index 749a5c652..2a52c8c75 100644 --- a/examples/avsregistry-read/examples/get_operator_stake_in_quorums_of_operator_at_current_block.rs +++ b/examples/avsregistry-read/examples/get_operator_stake_in_quorums_of_operator_at_current_block.rs @@ -7,6 +7,7 @@ use eyre::Result; use std::str::FromStr; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; let avs_registry = AvsRegistryChainReader::new( @@ -24,8 +25,7 @@ async fn main() -> Result<()> { ) .expect("wrong operator id"), ) - .await - .unwrap(); + .await?; println!("operator state at current block is {:?}", operators_state); diff --git a/examples/avsregistry-read/examples/get_operators_stake_in_quorums_at_block.rs b/examples/avsregistry-read/examples/get_operators_stake_in_quorums_at_block.rs index 8ce079e9e..c58f1bdca 100644 --- a/examples/avsregistry-read/examples/get_operators_stake_in_quorums_at_block.rs +++ b/examples/avsregistry-read/examples/get_operators_stake_in_quorums_at_block.rs @@ -6,6 +6,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST use eyre::Result; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; let avs_registry = AvsRegistryChainReader::new( @@ -22,8 +23,7 @@ async fn main() -> Result<()> { block_num, Bytes::from_hex("0x00").expect("failed to generate bytes"), ) - .await - .unwrap(); + .await?; println!( "operator state at block : {:?} is {:?}", diff --git a/examples/avsregistry-read/examples/get_quorum_count.rs b/examples/avsregistry-read/examples/get_quorum_count.rs index 582ff871f..30dc3e0e6 100644 --- a/examples/avsregistry-read/examples/get_quorum_count.rs +++ b/examples/avsregistry-read/examples/get_quorum_count.rs @@ -5,6 +5,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST use eyre::Result; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; let avs_registry = AvsRegistryChainReader::new( @@ -16,7 +17,7 @@ async fn main() -> Result<()> { .await .expect("failed to build avs registry chain reader"); - let quorum_count = avs_registry.get_quorum_count().await.unwrap(); + let quorum_count = avs_registry.get_quorum_count().await?; println!("quorum count is :{:?}", quorum_count); Ok(()) diff --git a/examples/avsregistry-read/examples/query_existing_registered_operator_pub_keys.rs b/examples/avsregistry-read/examples/query_existing_registered_operator_pub_keys.rs index d2bf3a9f3..a2e453b73 100644 --- a/examples/avsregistry-read/examples/query_existing_registered_operator_pub_keys.rs +++ b/examples/avsregistry-read/examples/query_existing_registered_operator_pub_keys.rs @@ -5,6 +5,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST use eyre::Result; #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://holesky.drpc.org"; let avs_registry = AvsRegistryChainReader::new( @@ -23,8 +24,7 @@ async fn main() -> Result<()> { to_block, holesky_provider.to_string(), ) - .await - .unwrap(); + .await?; println!( "operator state from block: {:?} to block: {:?} is {:?}", diff --git a/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs b/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs index 7cec85120..3139e6d8c 100644 --- a/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs +++ b/examples/avsregistry-write/examples/register_operator_in_quorum_with_avs_registry_coordinator.rs @@ -22,6 +22,7 @@ lazy_static! { static ref SIGNATURE_EXPIRY: U256 = U256::from(86400); } #[tokio::main] +#[allow(clippy::expect_used)] async fn main() -> Result<()> { let holesky_provider = "https://ethereum-holesky.blockpi.network/v1/rpc/public"; let pvt_key = "bead471191bea97fc3aeac36c9d74c895e8a6242602e144e43152f96219e96e8"; @@ -39,8 +40,7 @@ async fn main() -> Result<()> { // Create a new key pair instance using the secret key let bls_key_pair = BlsKeyPair::new( "12248929636257230549931416853095037629726205319386239410403476017439825112537".to_string(), - ) - .unwrap(); + )?; let digest_hash: FixedBytes<32> = FixedBytes::from([ 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, @@ -104,7 +104,6 @@ async fn main() -> Result<()> { quorum_nums, "65.109.158.181:33078;31078".to_string(), // socket ) - .await - .unwrap(); + .await?; Ok(()) } diff --git a/testing/testing-utils/src/lib.rs b/testing/testing-utils/src/lib.rs index 8c158a139..f7796ba8e 100644 --- a/testing/testing-utils/src/lib.rs +++ b/testing/testing-utils/src/lib.rs @@ -13,4 +13,5 @@ pub mod mainnet_constants; pub mod m2_holesky_constants; /// Anvil constants +#[allow(clippy::unwrap_used)] pub mod anvil_constants;