parazyd 3 лет назад
Родитель
Сommit
8c27c24473
37 измененных файлов с 134 добавлено и 145 удалено
  1. 1 1
      bin/dao/daod/src/contract/dao/exec/validate.rs
  2. 1 1
      bin/dao/daod/src/contract/dao/mint/validate.rs
  3. 2 2
      bin/dao/daod/src/contract/dao/propose/validate.rs
  4. 2 2
      bin/dao/daod/src/contract/dao/vote/validate.rs
  5. 1 1
      bin/dao/daod/src/contract/money/state.rs
  6. 2 2
      bin/dao/daod/src/contract/money/transfer/validate.rs
  7. 1 1
      bin/dao/daod/src/contract/money/transfer/wallet.rs
  8. 18 18
      bin/dao/daod/src/main.rs
  9. 13 13
      bin/dao/daod/src/rpc.rs
  10. 2 2
      bin/dao/daod/src/util.rs
  11. 1 1
      example/dao/src/contract/dao/exec/validate.rs
  12. 1 1
      example/dao/src/contract/dao/mint/validate.rs
  13. 2 2
      example/dao/src/contract/dao/propose/validate.rs
  14. 2 2
      example/dao/src/contract/dao/vote/validate.rs
  15. 1 1
      example/dao/src/contract/example/foo/validate.rs
  16. 2 2
      example/dao/src/contract/money/transfer/validate.rs
  17. 1 1
      example/dao/src/contract/money/transfer/wallet.rs
  18. 3 3
      example/dao/src/main.rs
  19. 2 2
      example/dao/src/util.rs
  20. 7 10
      example/less_than.rs
  21. 1 1
      src/blockchain/mod.rs
  22. 2 2
      src/consensus/clock.rs
  23. 3 3
      src/consensus/coins.rs
  24. 3 3
      src/consensus/state.rs
  25. 4 6
      src/consensus/utils.rs
  26. 3 3
      src/crypto/mimc_vdf.rs
  27. 2 0
      src/lib.rs
  28. 3 9
      src/net/hosts.rs
  29. 1 1
      src/net/p2p.rs
  30. 4 4
      src/runtime/import/db.rs
  31. 2 2
      src/runtime/import/util.rs
  32. 2 4
      src/runtime/vm_runtime.rs
  33. 1 1
      src/sdk/src/crypto/contract_id.rs
  34. 2 2
      src/serial/src/lib.rs
  35. 1 1
      src/util/path.rs
  36. 26 26
      src/zk/circuit/lead_contract.rs
  37. 9 9
      src/zk/circuit/tx_contract.rs

+ 1 - 1
bin/dao/daod/src/contract/dao/exec/validate.rs

@@ -131,7 +131,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 1 - 1
bin/dao/daod/src/contract/dao/mint/validate.rs

@@ -34,7 +34,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 2 - 2
bin/dao/daod/src/contract/dao/propose/validate.rs

@@ -71,7 +71,7 @@ impl CallDataBase for CallData {
         let mut zk_publics = Vec::new();
         let mut total_funds_commit = pallas::Point::identity();
 
-        assert!(self.inputs.len() > 0, "inputs length cannot be zero");
+        assert!(!self.inputs.is_empty(), "inputs length cannot be zero");
         for input in &self.inputs {
             total_funds_commit += input.value_commit;
             let value_coords = input.value_commit.to_affine().coordinates().unwrap();
@@ -149,7 +149,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 2 - 2
bin/dao/daod/src/contract/dao/vote/validate.rs

@@ -74,7 +74,7 @@ impl CallDataBase for CallData {
         let mut zk_publics = Vec::new();
         let mut all_votes_commit = pallas::Point::identity();
 
-        assert!(self.inputs.len() > 0, "inputs length cannot be zero");
+        assert!(!self.inputs.is_empty(), "inputs length cannot be zero");
         for input in &self.inputs {
             all_votes_commit += input.vote_commit;
             let value_coords = input.vote_commit.to_affine().coordinates().unwrap();
@@ -158,7 +158,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 1 - 1
bin/dao/daod/src/contract/money/state.rs

@@ -57,7 +57,7 @@ impl WalletCache {
         for (other_secret, own_coins) in self.cache.iter_mut() {
             if *secret == *other_secret {
                 // clear own_coins vec, and return current contents
-                return std::mem::replace(own_coins, Vec::new())
+                return std::mem::take(own_coins)
             }
         }
         panic!("you forget to track() this secret!");

+ 2 - 2
bin/dao/daod/src/contract/money/transfer/validate.rs

@@ -90,7 +90,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.
@@ -237,7 +237,7 @@ impl CallData {
             error!("tx::verify(): Missing inputs");
             return Err(VerifyFailed::LackingInputs)
         }
-        if self.outputs.len() == 0 {
+        if self.outputs.is_empty() {
             error!("tx::verify(): Missing outputs");
             return Err(VerifyFailed::LackingOutputs)
         }

+ 1 - 1
bin/dao/daod/src/contract/money/transfer/wallet.rs

@@ -173,7 +173,7 @@ impl Builder {
         let mut outputs = vec![];
         let mut output_blinds = vec![];
         // This value_blind calc assumes there will always be at least a single output
-        assert!(self.outputs.len() > 0);
+        assert!(!self.outputs.is_empty());
 
         for (i, output) in self.outputs.iter().enumerate() {
             let value_blind = if i == self.outputs.len() - 1 {

+ 18 - 18
bin/dao/daod/src/main.rs

@@ -345,7 +345,7 @@ impl Client {
 
             if func_call.func_id == *money::transfer::FUNC_ID {
                 debug!("money_contract::transfer::state_transition()");
-                match money::transfer::validate::state_transition(&self.states, idx, &tx) {
+                match money::transfer::validate::state_transition(&self.states, idx, tx) {
                     Ok(update) => {
                         updates.push(update);
                     }
@@ -353,7 +353,7 @@ impl Client {
                 }
             } else if func_call.func_id == *dao::mint::FUNC_ID {
                 debug!("dao_contract::mint::state_transition()");
-                match dao::mint::validate::state_transition(&self.states, idx, &tx) {
+                match dao::mint::validate::state_transition(&self.states, idx, tx) {
                     Ok(update) => {
                         updates.push(update);
                     }
@@ -361,7 +361,7 @@ impl Client {
                 }
             } else if func_call.func_id == *dao::propose::FUNC_ID {
                 debug!(target: "demo", "dao_contract::propose::state_transition()");
-                match dao::propose::validate::state_transition(&self.states, idx, &tx) {
+                match dao::propose::validate::state_transition(&self.states, idx, tx) {
                     Ok(update) => {
                         updates.push(update);
                     }
@@ -369,7 +369,7 @@ impl Client {
                 }
             } else if func_call.func_id == *dao::vote::FUNC_ID {
                 debug!(target: "demo", "dao_contract::vote::state_transition()");
-                match dao::vote::validate::state_transition(&self.states, idx, &tx) {
+                match dao::vote::validate::state_transition(&self.states, idx, tx) {
                     Ok(update) => {
                         updates.push(update);
                     }
@@ -377,7 +377,7 @@ impl Client {
                 }
             } else if func_call.func_id == *dao::exec::FUNC_ID {
                 debug!("dao_contract::exec::state_transition()");
-                match dao::exec::validate::state_transition(&self.states, idx, &tx) {
+                match dao::exec::validate::state_transition(&self.states, idx, tx) {
                     Ok(update) => {
                         updates.push(update);
                     }
@@ -473,7 +473,7 @@ impl Client {
         let sender_wallet = sender_wallet.unwrap();
 
         let tx = sender_wallet.propose_tx(
-            params.clone(),
+            params,
             recipient,
             token_id,
             amount,
@@ -719,7 +719,7 @@ impl DaoWallet {
                 .ok_or(DaoError::StateNotFound)?;
 
             let tree = &state.tree;
-            let leaf_position = own_coin.leaf_position.clone();
+            let leaf_position = own_coin.leaf_position;
             let root = tree.root(0).ok_or(Error::Custom(
                 "Not enough checkpoints available to reach the requested checkpoint depth."
                     .to_owned(),
@@ -760,12 +760,12 @@ impl DaoWallet {
         let user_data = pallas::Base::from(0);
 
         for (coin, is_spent) in &self.own_coins {
-            let is_spent = is_spent.clone();
+            let is_spent = *is_spent;
             if is_spent {
                 continue
             }
             let (treasury_leaf_position, treasury_merkle_path) =
-                self.get_treasury_path(&coin, states)?;
+                self.get_treasury_path(coin, states)?;
 
             let input_value = coin.note.value;
 
@@ -856,8 +856,8 @@ impl DaoWallet {
 
         let builder = {
             dao::exec::wallet::Builder {
-                proposal: proposal.clone(),
-                dao: dao_params.clone(),
+                proposal,
+                dao: dao_params,
                 yes_votes_value,
                 all_votes_value,
                 yes_votes_blind,
@@ -936,11 +936,11 @@ impl MoneyWallet {
         let mut inputs = Vec::new();
 
         for (coin, is_spent) in &self.own_coins {
-            let is_spent = is_spent.clone();
+            let is_spent = *is_spent;
             if is_spent {
                 continue
             }
-            let (money_leaf_position, money_merkle_path) = self.get_path(&states, &coin).unwrap();
+            let (money_leaf_position, money_merkle_path) = self.get_path(states, coin).unwrap();
 
             let input = {
                 dao::propose::wallet::BuilderInput {
@@ -983,7 +983,7 @@ impl MoneyWallet {
         let builder = dao::propose::wallet::Builder {
             inputs,
             proposal,
-            dao: params.clone(),
+            dao: params,
             dao_leaf_position,
             dao_merkle_path,
             dao_merkle_root,
@@ -1012,7 +1012,7 @@ impl MoneyWallet {
                 .ok_or(DaoError::StateNotFound)?;
 
             let tree = &state.tree;
-            let leaf_position = own_coin.leaf_position.clone();
+            let leaf_position = own_coin.leaf_position;
             let root = tree.root(0).ok_or(Error::Custom(
                 "Not enough checkpoints available to reach the requested checkpoint depth."
                     .to_owned(),
@@ -1041,7 +1041,7 @@ impl MoneyWallet {
 
         // We must prove we have sufficient governance tokens in order to vote.
         for (coin, _is_spent) in &self.own_coins {
-            let (money_leaf_position, money_merkle_path) = self.get_path(states, &coin).unwrap();
+            let (money_leaf_position, money_merkle_path) = self.get_path(states, coin).unwrap();
 
             let input = {
                 dao::vote::wallet::BuilderInput {
@@ -1064,8 +1064,8 @@ impl MoneyWallet {
                 },
                 // For this demo votes are encrypted for the DAO.
                 vote_keypair: dao_keypair,
-                proposal: proposal.clone(),
-                dao: dao_params.clone(),
+                proposal,
+                dao: dao_params,
             }
         };
 

+ 13 - 13
bin/dao/daod/src/rpc.rs

@@ -122,7 +122,7 @@ impl JsonRpcInterface {
             }
             Err(e) => {
                 error!("Failed to create DAO: {}", e);
-                return server_error(RpcError::Create, id)
+                server_error(RpcError::Create, id)
             }
         }
     }
@@ -206,12 +206,12 @@ impl JsonRpcInterface {
                 }
                 None => {
                     error!("No wallet found for provided key");
-                    return server_error(RpcError::Balance, id)
+                    server_error(RpcError::Balance, id)
                 }
             },
             Err(_) => {
                 error!("Could not parse PublicKey from string");
-                return server_error(RpcError::Parse, id)
+                server_error(RpcError::Parse, id)
             }
         }
     }
@@ -238,12 +238,12 @@ impl JsonRpcInterface {
                 Ok(_) => JsonResponse::new(json!("DAO treasury minted successfully."), id).into(),
                 Err(e) => {
                     error!("Failed to mint treasury: {}", e);
-                    return server_error(RpcError::Mint, id)
+                    server_error(RpcError::Mint, id)
                 }
             },
             Err(_) => {
                 error!("Failed to parse PublicKey from String");
-                return server_error(RpcError::Parse, id)
+                server_error(RpcError::Parse, id)
             }
         }
     }
@@ -266,7 +266,7 @@ impl JsonRpcInterface {
             }
             Err(e) => {
                 error!("Failed to airdrop tokens: {}", e);
-                return server_error(RpcError::Keygen, id)
+                server_error(RpcError::Keygen, id)
             }
         }
     }
@@ -294,12 +294,12 @@ impl JsonRpcInterface {
                 Ok(_) => JsonResponse::new(json!("Tokens airdropped successfully."), id).into(),
                 Err(e) => {
                     error!("Failed to airdrop tokens: {}", e);
-                    return server_error(RpcError::Airdrop, id)
+                    server_error(RpcError::Airdrop, id)
                 }
             },
             Err(_) => {
                 error!("Failed parsing PublicKey from String");
-                return server_error(RpcError::Parse, id)
+                server_error(RpcError::Parse, id)
             }
         }
     }
@@ -350,7 +350,7 @@ impl JsonRpcInterface {
             }
             Err(e) => {
                 error!("Failed to make Proposal: {}", e);
-                return server_error(RpcError::Propose, id)
+                server_error(RpcError::Propose, id)
             }
         }
     }
@@ -412,12 +412,12 @@ impl JsonRpcInterface {
                 }
                 Err(e) => {
                     error!("Failed casting vote: {}", e);
-                    return server_error(RpcError::Vote, id)
+                    server_error(RpcError::Vote, id)
                 }
             },
             Err(_) => {
                 error!("Failed parsing PublicKey from String");
-                return server_error(RpcError::Parse, id)
+                server_error(RpcError::Parse, id)
             }
         }
     }
@@ -439,12 +439,12 @@ impl JsonRpcInterface {
                 Err(e) => {
                     // Reject proposal instead of returning error?
                     error!("Failed executing proposal: {}", e);
-                    return server_error(RpcError::Exec, id)
+                    server_error(RpcError::Exec, id)
                 }
             },
             Err(e) => {
                 error!("Failed parsing bulla: {}", e);
-                return server_error(RpcError::Parse, id)
+                server_error(RpcError::Parse, id)
             }
         }
     }

+ 2 - 2
bin/dao/daod/src/util.rs

@@ -168,7 +168,7 @@ impl Transaction {
                 match zk_bins.lookup(key).unwrap() {
                     ZkContractInfo::Binary(info) => {
                         let verifying_key = &info.verifying_key;
-                        let verify_result = proof.verify(&verifying_key, public_vals);
+                        let verify_result = proof.verify(verifying_key, public_vals);
                         if verify_result.is_err() {
                             return Err(DaoError::VerifyProofFailed(i, key.to_string()))
                         }
@@ -176,7 +176,7 @@ impl Transaction {
                     }
                     ZkContractInfo::Native(info) => {
                         let verifying_key = &info.verifying_key;
-                        let verify_result = proof.verify(&verifying_key, public_vals);
+                        let verify_result = proof.verify(verifying_key, public_vals);
                         if verify_result.is_err() {
                             return Err(DaoError::VerifyProofFailed(i, key.to_string()))
                         }

+ 1 - 1
example/dao/src/contract/dao/exec/validate.rs

@@ -131,7 +131,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 1 - 1
example/dao/src/contract/dao/mint/validate.rs

@@ -34,7 +34,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 2 - 2
example/dao/src/contract/dao/propose/validate.rs

@@ -71,7 +71,7 @@ impl CallDataBase for CallData {
         let mut zk_publics = Vec::new();
         let mut total_funds_commit = pallas::Point::identity();
 
-        assert!(self.inputs.len() > 0, "inputs length cannot be zero");
+        assert!(!self.inputs.is_empty(), "inputs length cannot be zero");
         for input in &self.inputs {
             total_funds_commit += input.value_commit;
             let value_coords = input.value_commit.to_affine().coordinates().unwrap();
@@ -149,7 +149,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 2 - 2
example/dao/src/contract/dao/vote/validate.rs

@@ -74,7 +74,7 @@ impl CallDataBase for CallData {
         let mut zk_publics = Vec::new();
         let mut all_votes_commit = pallas::Point::identity();
 
-        assert!(self.inputs.len() > 0, "inputs length cannot be zero");
+        assert!(!self.inputs.is_empty(), "inputs length cannot be zero");
         for input in &self.inputs {
             all_votes_commit += input.vote_commit;
             let value_coords = input.vote_commit.to_affine().coordinates().unwrap();
@@ -158,7 +158,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 1 - 1
example/dao/src/contract/example/foo/validate.rs

@@ -82,7 +82,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.

+ 2 - 2
example/dao/src/contract/money/transfer/validate.rs

@@ -88,7 +88,7 @@ pub fn state_transition(
     let func_call = &parent_tx.func_calls[func_call_index];
     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+    assert_eq!((*call_data).type_id(), TypeId::of::<CallData>());
     let call_data = call_data.downcast_ref::<CallData>();
 
     // This will be inside wasm so unwrap is fine.
@@ -235,7 +235,7 @@ impl CallData {
             error!("tx::verify(): Missing inputs");
             return Err(VerifyFailed::LackingInputs)
         }
-        if self.outputs.len() == 0 {
+        if self.outputs.is_empty() {
             error!("tx::verify(): Missing outputs");
             return Err(VerifyFailed::LackingOutputs)
         }

+ 1 - 1
example/dao/src/contract/money/transfer/wallet.rs

@@ -173,7 +173,7 @@ impl Builder {
         let mut outputs = vec![];
         let mut output_blinds = vec![];
         // This value_blind calc assumes there will always be at least a single output
-        assert!(self.outputs.len() > 0);
+        assert!(!self.outputs.is_empty());
 
         for (i, output) in self.outputs.iter().enumerate() {
             let value_blind = if i == self.outputs.len() - 1 {

+ 3 - 3
example/dao/src/main.rs

@@ -86,7 +86,7 @@ impl WalletCache {
         for (other_secret, own_coins) in self.cache.iter_mut() {
             if *secret == *other_secret {
                 // clear own_coins vec, and return current contents
-                return std::mem::replace(own_coins, Vec::new())
+                return std::mem::take(own_coins)
             }
         }
         panic!("you forget to track() this secret!");
@@ -440,7 +440,7 @@ async fn main() -> Result<()> {
             let coin = &output.revealed.coin;
             let enc_note = &output.enc_note;
 
-            cache.try_decrypt_note(coin.clone(), enc_note);
+            cache.try_decrypt_note(*coin, enc_note);
         }
     }
 
@@ -583,7 +583,7 @@ async fn main() -> Result<()> {
             let coin = &output.revealed.coin;
             let enc_note = &output.enc_note;
 
-            cache.try_decrypt_note(coin.clone(), enc_note);
+            cache.try_decrypt_note(*coin, enc_note);
         }
     }
 

+ 2 - 2
example/dao/src/util.rs

@@ -164,7 +164,7 @@ impl Transaction {
                 match zk_bins.lookup(key).unwrap() {
                     ZkContractInfo::Binary(info) => {
                         let verifying_key = &info.verifying_key;
-                        let verify_result = proof.verify(&verifying_key, public_vals);
+                        let verify_result = proof.verify(verifying_key, public_vals);
                         if verify_result.is_err() {
                             return Err(DaoError::VerifyProofFailed(i, key.to_string()))
                         }
@@ -172,7 +172,7 @@ impl Transaction {
                     }
                     ZkContractInfo::Native(info) => {
                         let verifying_key = &info.verifying_key;
-                        let verify_result = proof.verify(&verifying_key, public_vals);
+                        let verify_result = proof.verify(verifying_key, public_vals);
                         if verify_result.is_err() {
                             return Err(DaoError::VerifyProofFailed(i, key.to_string()))
                         }

+ 7 - 10
example/less_than.rs

@@ -1,10 +1,8 @@
 use halo2_proofs::{
-    arithmetic::FieldExt,
-    circuit::{floor_planner, AssignedCell, Chip, Layouter, Region, Value},
-    dev::{CircuitLayout, MockProver},
+    circuit::{floor_planner, Layouter, Value},
+    dev::{MockProver},
     pasta::pallas,
-    plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Expression, Selector, TableColumn},
-    poly::Rotation,
+    plonk::{Advice, Circuit, Column, ConstraintSystem, Error},
 };
 
 use darkfi::{
@@ -17,7 +15,6 @@ use darkfi::{
         less_than::{LessThanChip, LessThanConfig},
         native_range_check::NativeRangeCheckChip,
     },
-    VerifyFailed,
 };
 use log::{error, info};
 use rand::rngs::OsRng;
@@ -113,7 +110,7 @@ fn simple_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
         }
         Err(e) => {
             error!("verification failed: {}", e);
-            return Err(e)
+            Err(e)
         }
     }
 }
@@ -143,7 +140,7 @@ fn fullrange_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
         }
         Err(e) => {
             error!("verification failed: {}", e);
-            return Err(e)
+            Err(e)
         }
     }
 }
@@ -151,6 +148,6 @@ fn fullrange_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
 fn main() {
     env_logger::init();
     let k = 11;
-    let res_simple = simple_lessthan(k).unwrap();
-    let res_fullrange = fullrange_lessthan(k).unwrap();
+    simple_lessthan(k).unwrap();
+    fullrange_lessthan(k).unwrap();
 }

+ 1 - 1
src/blockchain/mod.rs

@@ -180,7 +180,7 @@ impl Blockchain {
     /// Retrieve last finalized block leader proof hash.
     pub fn get_last_proof_hash(&self) -> Result<blake3::Hash> {
         let (slot, _) = self.last().unwrap();
-        let block = &self.get_blocks_by_slot(&vec![slot]).unwrap()[0];
+        let block = &self.get_blocks_by_slot(&[slot]).unwrap()[0];
         let hash = blake3::hash(&serialize(&block.metadata.proof));
         Ok(hash)
     }

+ 2 - 2
src/consensus/clock.rs

@@ -197,9 +197,9 @@ mod tests {
         let mut clock = Clock::new(Some(9), Some(9), Some(9), vec![]);
         //
         let tick: Ticks = block_on(clock.ticks());
-        assert_eq!(matches!(tick, Ticks::GENESIS { e: 0, sl: 0 }), true);
+        assert!(matches!(tick, Ticks::GENESIS { e: 0, sl: 0 }));
         thread::sleep(Duration::from_millis(3000));
         let tock: Ticks = block_on(clock.ticks());
-        assert_eq!(matches!(tock, Ticks::TOCKS), true);
+        assert!(matches!(tock, Ticks::TOCKS));
     }
 }

+ 3 - 3
src/consensus/coins.rs

@@ -91,7 +91,7 @@ pub fn create_epoch_coins(
     let sigma1: pallas::Base = fbig2base(sigma1_fbig);
     info!("sigma1 base: {:?}", sigma1);
     let sigma2_fbig =
-        (c.clone() / total_sigma.clone()).powf(two.clone()) * (field_p.clone() / two.clone());
+        (c / total_sigma).powf(two.clone()) * (field_p / two);
     info!("sigma2: {}", sigma2_fbig);
     let sigma2: pallas::Base = fbig2base(sigma2_fbig);
     info!("sigma2 base: {:?}", sigma2);
@@ -247,7 +247,7 @@ fn create_leadcoin(
     info!("coin pk [{}] y: {:?}", i, c_pk_y);
 
     let c_seed = pallas::Base::from(seed);
-    let sn_msg = [c_seed, c_root_sk.inner(), zero.clone(), one.clone()];
+    let sn_msg = [c_seed, c_root_sk.inner(), zero, one];
     let c_sn: pallas::Base =
         poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<4>, 3, 2>::init()
             .hash(sn_msg);
@@ -287,7 +287,7 @@ fn create_leadcoin(
     };
     */
 
-    let coin_nonce2_msg = [c_seed, c_root_sk.inner(), one.clone(), one.clone()];
+    let coin_nonce2_msg = [c_seed, c_root_sk.inner(), one, one];
     let c_seed2: pallas::Base =
         poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<4>, 3, 2>::init()
             .hash(coin_nonce2_msg);

+ 3 - 3
src/consensus/state.rs

@@ -460,7 +460,7 @@ impl ValidatorState {
         }
 
         // Check if proposal extends any existing fork chains
-        let index = self.find_extended_chain_index(&proposal)?;
+        let index = self.find_extended_chain_index(proposal)?;
         if index == -2 {
             return Err(Error::ExtendedChainIndexNotFoundError)
         }
@@ -482,7 +482,7 @@ impl ValidatorState {
             return Err(Error::InvalidPublicInputsError)
         }
 
-        match proposal.block.metadata.proof.verify(&self.verifying_key, &public_inputs) {
+        match proposal.block.metadata.proof.verify(&self.verifying_key, public_inputs) {
             Ok(_) => info!("receive_proposal(): Proof veryfied succsessfully!"),
             Err(e) => {
                 error!("receive_proposal(): Error during leader proof verification: {}", e);
@@ -524,7 +524,7 @@ impl ValidatorState {
                 self.consensus.proposals.push(pc);
             }
             _ => {
-                self.consensus.proposals[index as usize].add(&proposal);
+                self.consensus.proposals[index as usize].add(proposal);
                 match self.chain_finalization(index).await {
                     Ok(v) => {
                         to_broadcast = v;

+ 4 - 6
src/consensus/utils.rs

@@ -54,14 +54,12 @@ pub fn fbig2base(f: Float10) -> pallas::Base {
     let (sign, word) = val.as_sign_words();
     //TODO (res) set pallas base sign, i.e sigma1 is negative.
     let mut words: [u64; 4] = [0, 0, 0, 0];
-    for i in 0..word.len() {
-        words[i] = word[i];
-    }
-    let base = match sign {
+    words[..word.len()].copy_from_slice(word);
+
+    match sign {
         Sign::Positive => pallas::Base::from_raw(words),
         Sign::Negative => pallas::Base::from_raw(words).neg(),
-    };
-    base
+    }
 }
 
 #[cfg(test)]

+ 3 - 3
src/crypto/mimc_vdf.rs

@@ -96,8 +96,8 @@ mod tests {
 
         let witness = eval(&challenge, steps);
         assert!(verify(&challenge, steps, &witness));
-        assert_eq!(false, verify(&(&challenge - 1_u64), steps, &witness));
-        assert_eq!(false, verify(&challenge, steps - 1, &witness));
-        assert_eq!(false, verify(&challenge, steps, &(&witness - 1_u64)));
+        assert!(!verify(&(&challenge - 1_u64), steps, &witness));
+        assert!(!verify(&challenge, steps - 1, &witness));
+        assert!(!verify(&challenge, steps, &(&witness - 1_u64)));
     }
 }

+ 2 - 0
src/lib.rs

@@ -16,6 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+//#![feature(let_else)]
+
 pub mod error;
 pub use error::{ClientFailed, ClientResult, Error, Result, VerifyFailed, VerifyResult};
 

+ 3 - 9
src/net/hosts.rs

@@ -477,16 +477,10 @@ mod tests {
     #[test]
     fn test_is_valid_onion() {
         // Valid onion
-        assert_eq!(
-            is_valid_onion("facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion"),
-            true
-        );
+        assert!(is_valid_onion("facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion"),);
         // Valid onion without .onion suffix
-        assert_eq!(
-            is_valid_onion("facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd"),
-            true
-        );
+        assert!(is_valid_onion("facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd"),);
         // Invalid onion
-        assert_eq!(is_valid_onion("facebook.com"), false);
+        assert!(!is_valid_onion("facebook.com"));
     }
 }

+ 1 - 1
src/net/p2p.rs

@@ -494,7 +494,7 @@ impl P2p {
     /// Retrieves a random connected channel, exluding seeds
     pub async fn random_channel(self: Arc<Self>) -> Option<Arc<Channel>> {
         let mut channels_map = self.channels().lock().await.clone();
-        channels_map.retain(|c, _| !self.settings.seeds.contains(&c));
+        channels_map.retain(|c, _| !self.settings.seeds.contains(c));
         let mut values = channels_map.values();
 
         if values.len() == 0 {

+ 4 - 4
src/runtime/import/db.rs

@@ -121,11 +121,11 @@ pub(crate) fn db_init(ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u32) -> i
             let mut db_batches = env.db_batches.borrow_mut();
             db_handles.push(DbHandle::new(cid, tree_handle));
             db_batches.push(sled::Batch::default());
-            return (db_handles.len() - 1) as i32
+            (db_handles.len() - 1) as i32
         }
         _ => {
             error!(target: "wasm_runtime::db_init", "db_init called in unauthorized section");
-            return -1
+            -1
         }
     }
 }
@@ -191,11 +191,11 @@ pub(crate) fn db_lookup(ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u32) ->
             let mut db_batches = env.db_batches.borrow_mut();
             db_handles.push(DbHandle::new(cid, tree_handle));
             db_batches.push(sled::Batch::default());
-            return (db_handles.len() - 1) as i32
+            (db_handles.len() - 1) as i32
         }
         _ => {
             error!(target: "wasm_runtime::db_lookup", "db_lookup called in unauthorized section");
-            return -1
+            -1
         }
     }
 }

+ 2 - 2
src/runtime/import/util.rs

@@ -54,7 +54,7 @@ pub(crate) fn set_return_data(ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u
             };
 
             // This function should only ever be called once on the runtime.
-            if !env.contract_return_data.take().is_none() {
+            if env.contract_return_data.take().is_some() {
                 return darkfi_sdk::error::SET_RETVAL_ERROR
             }
             env.contract_return_data.set(Some(return_data));
@@ -123,7 +123,7 @@ pub(crate) fn get_object_bytes(ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, idx:
     };
 
     // Put the result in the VM
-    if let Err(e) = slice.write_slice(&obj) {
+    if let Err(e) = slice.write_slice(obj) {
         error!(target: "wasm_runtime::get_object_bytes", "Failed to write to memory slice: {}", e);
         return -4
     };

+ 2 - 4
src/runtime/vm_runtime.rs

@@ -262,7 +262,7 @@ impl Runtime {
         let entrypoint = self.instance.exports.get_function(section.name())?;
 
         debug!(target: "runtime", "Executing wasm");
-        let ret = match entrypoint.call(&mut self.store, &[Value::I32(0 as i32)]) {
+        let ret = match entrypoint.call(&mut self.store, &[Value::I32(0_i32)]) {
             Ok(retvals) => {
                 self.print_logs();
                 debug!(target: "runtime", "{}", self.gas_info());
@@ -321,7 +321,6 @@ impl Runtime {
             let batch = env_mut.db_batches.borrow()[idx].clone();
             db.apply_batch(batch)?;
             db.flush()?;
-            drop(db);
         }
 
         Ok(())
@@ -352,7 +351,6 @@ impl Runtime {
             let batch = env_mut.db_batches.borrow()[idx].clone();
             db.apply_batch(batch)?;
             db.flush()?;
-            drop(db);
         }
 
         Ok(())
@@ -397,7 +395,7 @@ impl Runtime {
     /// Will panic if memory isn't set.
     fn take_memory(&mut self) -> Memory {
         let env_memory = &mut self.ctx.as_mut(&mut self.store).memory;
-        let memory = std::mem::replace(env_memory, None);
+        let memory = env_memory.take();
         memory.expect("memory should be set")
     }
 

+ 1 - 1
src/sdk/src/crypto/contract_id.rs

@@ -41,7 +41,7 @@ impl ContractId {
     pub fn hash_state_id(&self, tree_name: &str) -> [u8; 32] {
         let mut hasher = blake3::Hasher::new();
         hasher.update(&serialize(self));
-        hasher.update(&tree_name.as_bytes());
+        hasher.update(tree_name.as_bytes());
         let id = hasher.finalize();
         *id.as_bytes()
     }

+ 2 - 2
src/serial/src/lib.rs

@@ -865,7 +865,7 @@ mod tests {
         let ts0_n = deserialize::<TestStruct0>(&ts0_s).unwrap();
         assert_eq!(foo, ts0_n.foo);
         assert_eq!(bar, ts0_n.bar);
-        assert_eq!(baz.clone(), ts0_n.baz);
+        assert_eq!(baz, ts0_n.baz);
         assert_eq!(ts0, ts0_n);
         assert_eq!(ts0_n, TestStruct0 { foo, bar, baz: baz.clone() });
 
@@ -873,6 +873,6 @@ mod tests {
         let ts1_s = serialize(&ts1);
         let ts1_n = deserialize::<TestStruct1>(&ts1_s).unwrap();
         assert_eq!(ts1, ts1_n);
-        assert_eq!(ts1_n, TestStruct1(baz.clone()));
+        assert_eq!(ts1_n, TestStruct1(baz));
     }
 }

+ 1 - 1
src/util/path.rs

@@ -40,7 +40,7 @@ pub fn home_dir() -> Option<PathBuf> {
 /// `getpwuid_r(3)`. If it manages, returns an `OsString`, otherwise returns `None`.
 unsafe fn home_fallback() -> Option<OsString> {
     let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) {
-        n if n < 0 => 512 as usize,
+        n if n < 0 => 512_usize,
         n => n as usize,
     };
 

+ 26 - 26
src/zk/circuit/lead_contract.rs

@@ -457,14 +457,14 @@ impl Circuit<pallas::Base> for LeadContract {
             // For derivation here, we append one 0 and one 1 to the hashed message.
             // TODO: Add these constants to ouroboros/consts.rs
             let poseidon_message =
-                [coin1_nonce.clone(), coin1_sk_root.clone(), zero.clone(), one.clone()];
+                [coin1_nonce.clone(), coin1_sk_root.clone(), zero, one.clone()];
             let poseidon_hasher = PoseidonHash::<_, _, P128Pow5T3, ConstantLength<4>, 3, 2>::init(
                 config.poseidon_chip(),
                 layouter.namespace(|| "sn_commit poseidon init"),
             )?;
-            let poseidon_output = poseidon_hasher
-                .hash(layouter.namespace(|| "sn_commit poseidon hash"), poseidon_message)?;
-            poseidon_output.into()
+            
+            poseidon_hasher
+                .hash(layouter.namespace(|| "sn_commit poseidon hash"), poseidon_message)?
         };
 
         // ==============================
@@ -487,9 +487,9 @@ impl Circuit<pallas::Base> for LeadContract {
                         config.poseidon_chip(),
                         layouter.namespace(|| "nullifier poseidon init"),
                     )?;
-                let poseidon_output = poseidon_hasher
-                    .hash(layouter.namespace(|| "nullifier poseidon hash"), poseidon_message)?;
-                poseidon_output.into()
+                
+                poseidon_hasher
+                    .hash(layouter.namespace(|| "nullifier poseidon hash"), poseidon_message)?
             };
 
             let v = FixedPointBaseField::from_inner(ecc_chip.clone(), NullifierK);
@@ -522,9 +522,9 @@ impl Circuit<pallas::Base> for LeadContract {
                 config.poseidon_chip(),
                 layouter.namespace(|| "coin1_commit_hash poseidon init"),
             )?;
-            let poseidon_output = poseidon_hasher
-                .hash(layouter.namespace(|| "coin1_commit_hash poseidon hash"), poseidon_message)?;
-            poseidon_output.into()
+            
+            poseidon_hasher
+                .hash(layouter.namespace(|| "coin1_commit_hash poseidon hash"), poseidon_message)?
         };
 
         let coin1_cm_root = merkle_inputs.calculate_root(
@@ -544,9 +544,9 @@ impl Circuit<pallas::Base> for LeadContract {
                 config.poseidon_chip(),
                 layouter.namespace(|| "coin2_nonce poseidon init"),
             )?;
-            let poseidon_output = poseidon_hasher
-                .hash(layouter.namespace(|| "coin2_nonce poseidon hash"), poseidon_message)?;
-            poseidon_output.into()
+            
+            poseidon_hasher
+                .hash(layouter.namespace(|| "coin2_nonce poseidon hash"), poseidon_message)?
         };
 
         // ================
@@ -564,18 +564,18 @@ impl Circuit<pallas::Base> for LeadContract {
                     coin_pk.inner().y(),
                     coin1_value.clone(),
                     coin2_nonce.clone(),
-                    one.clone(), // Used here because of poseidon odd-n bug
+                    one, // Used here because of poseidon odd-n bug
                 ];
                 let poseidon_hasher =
                     PoseidonHash::<_, _, P128Pow5T3, ConstantLength<6>, 3, 2>::init(
                         config.poseidon_chip(),
                         layouter.namespace(|| "coin2_commitment_v poseidon init"),
                     )?;
-                let poseidon_output = poseidon_hasher.hash(
+                
+                poseidon_hasher.hash(
                     layouter.namespace(|| "coin2_commitment_v poseidon hash"),
                     poseidon_message,
-                )?;
-                poseidon_output.into()
+                )?
             };
 
             let v = FixedPointBaseField::from_inner(ecc_chip.clone(), NullifierK);
@@ -599,16 +599,16 @@ impl Circuit<pallas::Base> for LeadContract {
         // Commitment to the coin's secret key, coin's nonce, and random value
         // derived from the epoch sampled random eta.
         let lottery_commit_msg: AssignedCell<pallas::Base, pallas::Base> = {
-            let poseidon_message = [coin1_sk_root.clone(), coin1_nonce.clone()];
+            let poseidon_message = [coin1_sk_root, coin1_nonce];
             let poseidon_hasher = PoseidonHash::<_, _, P128Pow5T3, ConstantLength<2>, 3, 2>::init(
                 config.poseidon_chip(),
                 layouter.namespace(|| "lottery_commit_msg poseidon init"),
             )?;
-            let poseidon_output = poseidon_hasher.hash(
+            
+            poseidon_hasher.hash(
                 layouter.namespace(|| "lottery_commit_msg poseidon hash"),
                 poseidon_message,
-            )?;
-            poseidon_output.into()
+            )?
         };
 
         let lottery_commit_v = {
@@ -631,11 +631,11 @@ impl Circuit<pallas::Base> for LeadContract {
                 config.poseidon_chip(),
                 layouter.namespace(|| "lottery_commit coords poseidon init"),
             )?;
-            let poseidon_output = poseidon_hasher.hash(
+            
+            poseidon_hasher.hash(
                 layouter.namespace(|| "lottery_commit coords poseidon hash"),
                 poseidon_message,
-            )?;
-            poseidon_output.into()
+            )?
         };
 
         // y_commit also becomes V of the following pedersen commitment for rho
@@ -645,7 +645,7 @@ impl Circuit<pallas::Base> for LeadContract {
                 layouter.namespace(|| "mau_rho scalar"),
                 self.mau_rho,
             )?;
-            let rho_commit_r = FixedPoint::from_inner(ecc_chip.clone(), ValueCommitR);
+            let rho_commit_r = FixedPoint::from_inner(ecc_chip, ValueCommitR);
             rho_commit_r.mul(layouter.namespace(|| "coin serial number commit R"), mau_rho)?
         };
         let rho_commit = lottery_commit_v.add(layouter.namespace(|| "nonce commit"), &rho_cm)?;
@@ -736,7 +736,7 @@ impl Circuit<pallas::Base> for LeadContract {
         // Constrain y < target
         lessthan_chip.copy_less_than(
             layouter.namespace(|| "y < target"),
-            y_commit_base.clone(),
+            y_commit_base,
             target,
             0,
             true,

+ 9 - 9
src/zk/circuit/tx_contract.rs

@@ -449,7 +449,7 @@ impl Circuit<pallas::Base> for TxContract {
         let com1 = {
             let nullifier2_msg: AssignedCell<Fp, Fp> = {
                 let poseidon_message =
-                    [coin1_pk.clone(), coin1_value.clone(), coin1_nonce.clone(), one.clone()];
+                    [coin1_pk, coin1_value.clone(), coin1_nonce.clone(), one.clone()];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
@@ -502,7 +502,7 @@ impl Circuit<pallas::Base> for TxContract {
         let com2 = {
             let nullifier2_msg: AssignedCell<Fp, Fp> = {
                 let poseidon_message =
-                    [coin2_pk.clone(), coin2_value.clone(), coin2_nonce.clone(), one.clone()];
+                    [coin2_pk, coin2_value.clone(), coin2_nonce.clone(), one.clone()];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
@@ -555,7 +555,7 @@ impl Circuit<pallas::Base> for TxContract {
         let _com3 = {
             let nullifier2_msg: AssignedCell<Fp, Fp> = {
                 let poseidon_message =
-                    [coin3_pk.clone(), coin3_value.clone(), coin3_nonce.clone(), one.clone()];
+                    [coin3_pk, coin3_value.clone(), coin3_nonce, one.clone()];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
@@ -596,7 +596,7 @@ impl Circuit<pallas::Base> for TxContract {
         let _com4 = {
             let nullifier2_msg: AssignedCell<Fp, Fp> = {
                 let poseidon_message =
-                    [coin4_pk.clone(), coin4_value.clone(), coin4_nonce.clone(), one.clone()];
+                    [coin4_pk, coin4_value.clone(), coin4_nonce, one];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
@@ -625,7 +625,7 @@ impl Circuit<pallas::Base> for TxContract {
                 self.coin4_blind,
             )?;
             let coin_commit_r =
-                FixedPoint::from_inner(ecc_chip.clone(), OrchardFixedBasesFull::ValueCommitR);
+                FixedPoint::from_inner(ecc_chip, OrchardFixedBasesFull::ValueCommitR);
             coin_commit_r.mul(layouter.namespace(|| "coin serial number commit R"), coin4_blind)?
         };
         let coin4_commit = com2.add(layouter.namespace(|| " commit"), &blind)?;
@@ -650,7 +650,7 @@ impl Circuit<pallas::Base> for TxContract {
         );
 
         let coin1_cm_hash: AssignedCell<Fp, Fp> = {
-            let poseidon_message = [coin1_commit_x.clone(), coin1_commit_y.clone()];
+            let poseidon_message = [coin1_commit_x, coin1_commit_y];
             let poseidon_hasher = PoseidonHash::<
                 _,
                 _,
@@ -684,7 +684,7 @@ impl Circuit<pallas::Base> for TxContract {
         );
 
         let coin2_cm_hash: AssignedCell<Fp, Fp> = {
-            let poseidon_message = [coin2_commit_x.clone(), coin2_commit_y.clone()];
+            let poseidon_message = [coin2_commit_x, coin2_commit_y];
             let poseidon_hasher = PoseidonHash::<
                 _,
                 _,
@@ -736,7 +736,7 @@ impl Circuit<pallas::Base> for TxContract {
         // coin1 sn
         // ========
         let coin1_sn_commit: AssignedCell<Fp, Fp> = {
-            let poseidon_message = [coin1_nonce.clone(), coin1_root_sk.clone()];
+            let poseidon_message = [coin1_nonce, coin1_root_sk.clone()];
             let poseidon_hasher = PoseidonHash::<
                 _,
                 _,
@@ -758,7 +758,7 @@ impl Circuit<pallas::Base> for TxContract {
         // coin2 sn
         // ========
         let coin2_sn_commit: AssignedCell<Fp, Fp> = {
-            let poseidon_message = [coin2_nonce.clone(), coin2_root_sk.clone()];
+            let poseidon_message = [coin2_nonce, coin2_root_sk.clone()];
             let poseidon_hasher = PoseidonHash::<
                 _,
                 _,