From 67d65a69124a8f824fe5702b5905f04bfe0ebb1a Mon Sep 17 00:00:00 2001 From: RedaOps <32748771+RedaOps@users.noreply.github.com> Date: Sat, 27 Jan 2024 05:05:38 +0200 Subject: [PATCH] fixed clippy --- .github/workflows/rust.yml | 2 +- src/bin/zkbtc.rs | 6 +++--- src/bob_request.rs | 8 ++++---- src/committee/node.rs | 2 +- src/committee/orchestrator.rs | 24 +++++++++++------------- src/constants.rs | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d69c604..0461988 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -100,4 +100,4 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-features -- -D warnings + args: --all-features -- -D warnings -A clippy::absurd_extreme_comparisons diff --git a/src/bin/zkbtc.rs b/src/bin/zkbtc.rs index 88bed6b..976afe6 100644 --- a/src/bin/zkbtc.rs +++ b/src/bin/zkbtc.rs @@ -229,7 +229,7 @@ async fn main() -> Result<()> { info!( "deploying circuit {} with {num_public_inputs} public inputs", - hex::encode(&vk_hash) + hex::encode(vk_hash) ); // sanity check for stateful zkapps @@ -421,7 +421,7 @@ async fn main() -> Result<()> { { let path = output_dir.join("publickey-package.json"); let file = - std::fs::File::create(&path).expect("couldn't create file given output dir"); + std::fs::File::create(path).expect("couldn't create file given output dir"); serde_json::to_writer_pretty(file, &pubkey_package).unwrap(); } @@ -445,7 +445,7 @@ async fn main() -> Result<()> { }; let path = output_dir.join("committee-cfg.json"); let file = - std::fs::File::create(&path).expect("couldn't create file given output dir"); + std::fs::File::create(path).expect("couldn't create file given output dir"); serde_json::to_writer_pretty(file, &committee_cfg).unwrap(); } } diff --git a/src/bob_request.rs b/src/bob_request.rs index 99d7120..bde8323 100644 --- a/src/bob_request.rs +++ b/src/bob_request.rs @@ -146,7 +146,7 @@ impl BobRequest { // extract new_state let new_state = public_inputs .0 - .get(0) + .first() .cloned() .context("the full public input does not contain a new state")?; @@ -196,13 +196,13 @@ impl BobRequest { let amount_in = string_to_amount( proof_inputs .get("amount_in") - .and_then(|x| x.get(0)) + .and_then(|x| x.first()) .context("amount_in in proof inputs must be of length 1")?, )?; let amount_out = string_to_amount( proof_inputs .get("amount_out") - .and_then(|x| x.get(0)) + .and_then(|x| x.first()) .context("amount_out in proof inputs must be of length 1")?, )?; let new_value = smart_contract.locked_value + amount_in - amount_out; @@ -284,7 +284,7 @@ impl BobRequest { let new_state = new_state.unwrap(); ensure!( public_inputs.0.len() - == 1 * 2 /* prev/new_state */ + 1 /* truncated txid */ + 1 /* amount_out */ + 1, /* amount_in */ + == 2 /* prev/new_state */ + 1 /* truncated txid */ + 1 /* amount_out */ + 1, /* amount_in */ "the number of public inputs is not correct" ); diff --git a/src/committee/node.rs b/src/committee/node.rs index 3360815..030ab40 100644 --- a/src/committee/node.rs +++ b/src/committee/node.rs @@ -212,7 +212,7 @@ async fn round_2_signing( } async fn is_alive(params: Params<'static>, _context: Arc) -> RpcResult { - Ok(params.parse::<[u64; 1]>()?[0].clone()) + Ok(params.parse::<[u64; 1]>()?[0]) } // diff --git a/src/committee/orchestrator.rs b/src/committee/orchestrator.rs index 41181ec..c6dca68 100644 --- a/src/committee/orchestrator.rs +++ b/src/committee/orchestrator.rs @@ -81,16 +81,16 @@ impl MemberStatusState { let mut futures = Vec::with_capacity(config.members.len()); for (key, member) in config.members.iter() { - let _ = key_to_addr.insert(key.clone(), member.address.clone()); + let _ = key_to_addr.insert(*key, member.address.clone()); futures.push(( - key.clone(), + *key, Self::check_alive(member.address.clone()), member.address.clone(), )); } for (key, future, address) in futures.into_iter() { - let new_status = if future.await == true { + let new_status = if future.await { info!("{address} is online"); MemberStatus::Online } else { @@ -138,10 +138,8 @@ impl MemberStatusState { for (member, status) in self.status.iter() { match *status { - MemberStatus::Online => online.push(member.clone()), - MemberStatus::Offline | MemberStatus::Disconnected(_) => { - offline.push(member.clone()) - } + MemberStatus::Online => online.push(*member), + MemberStatus::Offline | MemberStatus::Disconnected(_) => offline.push(*member), }; } @@ -156,12 +154,12 @@ impl MemberStatusState { } fn fib(n: u64) -> u64 { - if n <= 0 { - return 0; + if n == 0 { + 0 } else if n == 1 { - return 1; + 1 } else { - return Self::fib(n - 1) + Self::fib(n - 2); + Self::fib(n - 1) + Self::fib(n - 2) } } @@ -211,8 +209,8 @@ impl MemberStatusState { .key_to_addr .iter() .map(|(key, addr)| { - let status = r_lock.status.get(key).unwrap().clone(); - (key.clone(), addr.clone(), status) + let status = *r_lock.status.get(key).unwrap(); + (*key, addr.clone(), status) }) .filter(|(_, _, status)| match *status { MemberStatus::Online => true, diff --git a/src/constants.rs b/src/constants.rs index d66468f..e00f626 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -36,7 +36,7 @@ pub const CIRCOM_ETH_PRIME_BYTELEN: usize = 32; pub const STATELESS_ZKAPP_PUBLIC_INPUT_LEN: usize = 1 /* truncated txid */; /// The expected number of public inputs for a stateful zkapp. -pub const STATEFUL_ZKAPP_PUBLIC_INPUT_LEN: usize = 1 * 2 /* new state + prev state */ + 1 /* truncated txid */ + 1 /* amount_out */ + 1 /* amount_in */; +pub const STATEFUL_ZKAPP_PUBLIC_INPUT_LEN: usize = 2 /* new state + prev state */ + 1 /* truncated txid */ + 1 /* amount_out */ + 1 /* amount_in */; /// The number of seconds to sleep between orchestrator-node keepalive requests pub const KEEPALIVE_WAIT_SECONDS: u64 = 5;