diff --git a/zcash_client_backend/src/data_api.rs b/zcash_client_backend/src/data_api.rs index 4da3c565d..544510f38 100644 --- a/zcash_client_backend/src/data_api.rs +++ b/zcash_client_backend/src/data_api.rs @@ -141,10 +141,7 @@ pub trait WalletRead { /// /// This will return `Ok(None)` if the note identifier does not appear in the /// database as a known note ID. - fn get_memo_as_utf8( - &self, - id_note: Self::NoteRef, - ) -> Result, Self::Error>; + fn get_memo_as_utf8(&self, id_note: Self::NoteRef) -> Result, Self::Error>; /// Returns the note commitment tree at the specified block height. fn get_commitment_tree( @@ -153,6 +150,7 @@ pub trait WalletRead { ) -> Result>, Self::Error>; /// Returns the incremental witnesses as of the specified block height. + #[allow(clippy::type_complexity)] fn get_witnesses( &self, block_height: BlockHeight, @@ -453,10 +451,7 @@ pub mod testing { Ok(Amount::zero()) } - fn get_memo_as_utf8( - &self, - _id_note: Self::NoteRef, - ) -> Result, Self::Error> { + fn get_memo_as_utf8(&self, _id_note: Self::NoteRef) -> Result, Self::Error> { Ok(None) } @@ -467,6 +462,7 @@ pub mod testing { Ok(None) } + #[allow(clippy::type_complexity)] fn get_witnesses( &self, _block_height: BlockHeight, diff --git a/zcash_client_backend/src/data_api/chain.rs b/zcash_client_backend/src/data_api/chain.rs index 3acea2fa9..80fa12afe 100644 --- a/zcash_client_backend/src/data_api/chain.rs +++ b/zcash_client_backend/src/data_api/chain.rs @@ -1,3 +1,4 @@ +#![allow(clippy::needless_doctest_main)] //! Tools for blockchain validation & scanning //! //! # Examples @@ -174,6 +175,7 @@ where }) } +#[allow(clippy::needless_doctest_main)] /// Scans at most `limit` new blocks added to the cache for any transactions received by /// the tracked accounts. /// @@ -267,7 +269,7 @@ where // Get the most recent CommitmentTree let mut tree = data .get_commitment_tree(last_height) - .map(|t| t.unwrap_or(CommitmentTree::new()))?; + .map(|t| t.unwrap_or_else(CommitmentTree::empty))?; // Get most recent incremental witnesses for the notes we are tracking let mut witnesses = data.get_witnesses(last_height)?; diff --git a/zcash_client_backend/src/data_api/wallet.rs b/zcash_client_backend/src/data_api/wallet.rs index 5db29ea77..60b466efb 100644 --- a/zcash_client_backend/src/data_api/wallet.rs +++ b/zcash_client_backend/src/data_api/wallet.rs @@ -24,7 +24,7 @@ pub const ANCHOR_OFFSET: u32 = 10; /// Scans a [`Transaction`] for any information that can be decrypted by the accounts in /// the wallet, and saves it to the wallet. -pub fn decrypt_and_store_transaction<'db, N, E, P, D>( +pub fn decrypt_and_store_transaction( params: &P, data: &mut D, tx: &Transaction, @@ -44,8 +44,8 @@ where .or(data .block_height_extrema()? .map(|(_, max_height)| max_height + 1)) - .or(params.activation_height(NetworkUpgrade::Sapling)) - .ok_or(Error::SaplingNotActive.into())?; + .or_else(|| params.activation_height(NetworkUpgrade::Sapling)) + .ok_or(Error::SaplingNotActive)?; let outputs = decrypt_transaction(params, height, tx, &extfvks); if outputs.is_empty() { @@ -68,6 +68,7 @@ where } } +#[allow(clippy::needless_doctest_main)] /// Creates a transaction paying the specified address from the given account. /// /// Returns the row index of the newly-created transaction in the `transactions` table @@ -153,6 +154,7 @@ where /// # Ok(()) /// # } /// ``` +#[allow(clippy::too_many_arguments)] pub fn create_spend_to_address( wallet_db: &mut D, params: &P, @@ -187,7 +189,7 @@ where // Target the next block, assuming we are up-to-date. let (height, anchor_height) = wallet_db .get_target_and_anchor_heights() - .and_then(|x| x.ok_or(Error::ScanRequired.into()))?; + .and_then(|x| x.ok_or_else(|| Error::ScanRequired.into()))?; let target_value = value + DEFAULT_FEE; let spendable_notes = wallet_db.select_spendable_notes(account, target_value, anchor_height)?; @@ -242,27 +244,25 @@ where }; // Update the database atomically, to ensure the result is internally consistent. - wallet_db - .transactionally(|up| { - let created = time::OffsetDateTime::now_utc(); - let tx_ref = up.put_tx_data(&tx, Some(created))?; + wallet_db.transactionally(|up| { + let created = time::OffsetDateTime::now_utc(); + let tx_ref = up.put_tx_data(&tx, Some(created))?; - // Mark notes as spent. - // - // This locks the notes so they aren't selected again by a subsequent call to - // create_spend_to_address() before this transaction has been mined (at which point the notes - // get re-marked as spent). - // - // Assumes that create_spend_to_address() will never be called in parallel, which is a - // reasonable assumption for a light client such as a mobile phone. - for spend in &tx.shielded_spends { - up.mark_spent(tx_ref, &spend.nullifier)?; - } + // Mark notes as spent. + // + // This locks the notes so they aren't selected again by a subsequent call to + // create_spend_to_address() before this transaction has been mined (at which point the notes + // get re-marked as spent). + // + // Assumes that create_spend_to_address() will never be called in parallel, which is a + // reasonable assumption for a light client such as a mobile phone. + for spend in &tx.shielded_spends { + up.mark_spent(tx_ref, &spend.nullifier)?; + } - up.insert_sent_note(tx_ref, output_index as usize, account, to, value, memo)?; + up.insert_sent_note(tx_ref, output_index as usize, account, to, value, memo)?; - // Return the row number of the transaction, so the caller can fetch it for sending. - Ok(tx_ref) - }) - .map_err(|e| e.into()) + // Return the row number of the transaction, so the caller can fetch it for sending. + Ok(tx_ref) + }) } diff --git a/zcash_client_backend/src/welding_rig.rs b/zcash_client_backend/src/welding_rig.rs index bbc39901b..c4c067d18 100644 --- a/zcash_client_backend/src/welding_rig.rs +++ b/zcash_client_backend/src/welding_rig.rs @@ -22,6 +22,7 @@ use crate::wallet::{AccountId, WalletShieldedOutput, WalletShieldedSpend, Wallet /// /// The given [`CommitmentTree`] and existing [`IncrementalWitness`]es are incremented /// with this output's commitment. +#[allow(clippy::too_many_arguments)] fn scan_output( params: &P, height: BlockHeight, @@ -260,14 +261,14 @@ mod tests { let rseed = generate_random_rseed(&Network::TestNetwork, height, &mut rng); let note = Note { g_d: to.diversifier().g_d().unwrap(), - pk_d: to.pk_d().clone(), + pk_d: *to.pk_d(), value: value.into(), rseed, }; let encryptor = SaplingNoteEncryption::new( Some(extfvk.fvk.ovk), note.clone(), - to.clone(), + to, Memo::default(), &mut rng, ); @@ -325,7 +326,7 @@ mod tests { ); assert_eq!(cb.vtx.len(), 2); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); let txs = scan_block( &Network::TestNetwork, cb, @@ -364,7 +365,7 @@ mod tests { ); assert_eq!(cb.vtx.len(), 3); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); let txs = scan_block( &Network::TestNetwork, cb, @@ -399,12 +400,12 @@ mod tests { let cb = fake_compact_block(1u32.into(), nf, extfvk, Amount::from_u64(5).unwrap(), false); assert_eq!(cb.vtx.len(), 2); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); let txs = scan_block( &Network::TestNetwork, cb, &[], - &[(account, nf.clone())], + &[(account, nf)], &mut tree, &mut [], ); diff --git a/zcash_client_backend/src/zip321.rs b/zcash_client_backend/src/zip321.rs index f4996cf91..a61c5b45b 100644 --- a/zcash_client_backend/src/zip321.rs +++ b/zcash_client_backend/src/zip321.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; use std::fmt; use std::str::FromStr; -use base64; use nom::{ character::complete::char, combinator::all_consuming, multi::separated_list, sequence::preceded, }; @@ -21,10 +20,6 @@ pub enum MemoError { } impl RawMemo { - pub fn from_str(s: &str) -> Result { - RawMemo::from_bytes(s.as_bytes()) - } - // Construct a raw memo from a vector of bytes. pub fn from_bytes(v: &[u8]) -> Result { if v.len() > 512 { @@ -77,7 +72,7 @@ impl FromStr for RawMemo { type Err = MemoError; fn from_str(memo: &str) -> Result { - RawMemo::from_str(memo) + RawMemo::from_bytes(memo.as_bytes()) } } @@ -403,7 +398,7 @@ mod parse { pub enum Param { Addr(RecipientAddress), Amount(Amount), - Memo(RawMemo), + Memo(Box), Label(String), Message(String), Other(String, String), @@ -428,7 +423,7 @@ mod parse { } } - return false; + false } pub fn to_payment(vs: Vec, i: usize) -> Result { @@ -448,10 +443,10 @@ mod parse { for v in vs { match v { - Param::Amount(a) => payment.amount = a.clone(), + Param::Amount(a) => payment.amount = a, Param::Memo(m) => { match payment.recipient_address { - RecipientAddress::Shielded(_) => payment.memo = Some(m), + RecipientAddress::Shielded(_) => payment.memo = Some(*m), RecipientAddress::Transparent(_) => return Err(format!("Payment {} attempted to associate a memo with a transparent recipient address", i)), } }, @@ -463,7 +458,7 @@ mod parse { } } - return Ok(payment); + Ok(payment) } /// Parser that consumes the leading "zcash:[address]" from @@ -601,7 +596,7 @@ mod parse { .map_err(|e| e.to_string()), "memo" => memo_from_base64(value) - .map(Param::Memo) + .map(|m| Param::Memo(Box::new(m))) .map_err(|e| format!("Decoded memo was invalid: {:?}", e)), other if other.starts_with("req-") => { @@ -957,7 +952,7 @@ mod tests { let fragment = memo_param(&memo, i); let (rest, iparam) = zcashparam(&TEST_NETWORK)(&fragment).unwrap(); assert_eq!(rest, ""); - assert_eq!(iparam.param, Param::Memo(memo)); + assert_eq!(iparam.param, Param::Memo(Box::new(memo))); assert_eq!(iparam.payment_index, i.unwrap_or(0)); } diff --git a/zcash_client_sqlite/src/chain.rs b/zcash_client_sqlite/src/chain.rs index b60f9ef06..51f40723b 100644 --- a/zcash_client_sqlite/src/chain.rs +++ b/zcash_client_sqlite/src/chain.rs @@ -223,7 +223,7 @@ mod tests { let (cb4, _) = fake_compact_block( sapling_activation_height() + 3, cb3.hash(), - extfvk.clone(), + extfvk, Amount::from_u64(3).unwrap(), ); insert_into_cache(&db_cache, &cb3); @@ -295,7 +295,7 @@ mod tests { let (cb4, _) = fake_compact_block( sapling_activation_height() + 3, BlockHash([1; 32]), - extfvk.clone(), + extfvk, Amount::from_u64(3).unwrap(), ); insert_into_cache(&db_cache, &cb3); @@ -408,12 +408,8 @@ mod tests { extfvk.clone(), value, ); - let (cb3, _) = fake_compact_block( - sapling_activation_height() + 2, - cb2.hash(), - extfvk.clone(), - value, - ); + let (cb3, _) = + fake_compact_block(sapling_activation_height() + 2, cb2.hash(), extfvk, value); insert_into_cache(&db_cache, &cb3); match scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None) { Err(SqliteClientError::BackendError(e)) => { diff --git a/zcash_client_sqlite/src/error.rs b/zcash_client_sqlite/src/error.rs index f2a02c486..0ae1fb5b2 100644 --- a/zcash_client_sqlite/src/error.rs +++ b/zcash_client_sqlite/src/error.rs @@ -16,7 +16,7 @@ pub enum SqliteClientError { /// The rcm value for a note cannot be decoded to a valid JubJub point. InvalidNote, - /// The note id associated with a witness being stored corresponds to a + /// The note id associated with a witness being stored corresponds to a /// sent note, not a received note. InvalidNoteId, diff --git a/zcash_client_sqlite/src/lib.rs b/zcash_client_sqlite/src/lib.rs index 1dc1d446e..e1c199cc2 100644 --- a/zcash_client_sqlite/src/lib.rs +++ b/zcash_client_sqlite/src/lib.rs @@ -88,7 +88,7 @@ impl WalletDB

{ /// Given a wallet database connection, obtain a handle for the write operations /// for that database. This operation may eagerly initialize and cache sqlite /// prepared statements that are used in write operations. - pub fn get_update_ops<'a>(&'a self) -> Result, SqliteClientError> { + pub fn get_update_ops(&self) -> Result, SqliteClientError> { Ok( DataConnStmtCache { wallet_db: self, @@ -220,6 +220,7 @@ impl WalletRead for WalletDB

{ wallet::get_commitment_tree(self, block_height) } + #[allow(clippy::type_complexity)] fn get_witnesses( &self, block_height: BlockHeight, @@ -317,10 +318,7 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> { self.wallet_db.get_balance_at(account, anchor_height) } - fn get_memo_as_utf8( - &self, - id_note: Self::NoteRef, - ) -> Result, Self::Error> { + fn get_memo_as_utf8(&self, id_note: Self::NoteRef) -> Result, Self::Error> { self.wallet_db.get_memo_as_utf8(id_note) } @@ -331,6 +329,7 @@ impl<'a, P: consensus::Parameters> WalletRead for DataConnStmtCache<'a, P> { self.wallet_db.get_commitment_tree(block_height) } + #[allow(clippy::type_complexity)] fn get_witnesses( &self, block_height: BlockHeight, @@ -571,14 +570,14 @@ mod tests { let rseed = generate_random_rseed(&network(), height, &mut rng); let note = Note { g_d: to.diversifier().g_d().unwrap(), - pk_d: to.pk_d().clone(), + pk_d: *to.pk_d(), value: value.into(), rseed, }; let encryptor = SaplingNoteEncryption::new( Some(extfvk.fvk.ovk), note.clone(), - to.clone(), + to, Memo::default(), &mut rng, ); @@ -631,7 +630,7 @@ mod tests { ctx.outputs.push({ let note = Note { g_d: to.diversifier().g_d().unwrap(), - pk_d: to.pk_d().clone(), + pk_d: *to.pk_d(), value: value.into(), rseed, }; @@ -659,7 +658,7 @@ mod tests { let rseed = generate_random_rseed(&network(), height, &mut rng); let note = Note { g_d: change_addr.diversifier().g_d().unwrap(), - pk_d: change_addr.pk_d().clone(), + pk_d: *change_addr.pk_d(), value: (in_value - value).into(), rseed, }; diff --git a/zcash_client_sqlite/src/wallet.rs b/zcash_client_sqlite/src/wallet.rs index 7b438d57c..014448146 100644 --- a/zcash_client_sqlite/src/wallet.rs +++ b/zcash_client_sqlite/src/wallet.rs @@ -565,7 +565,9 @@ pub fn put_received_note<'a, P, T: ShieldedOutput>( // It isn't there, so insert our note into the database. stmts.stmt_insert_received_note.execute_named(&sql_args)?; - Ok(NoteId::ReceivedNoteId(stmts.wallet_db.conn.last_insert_rowid())) + Ok(NoteId::ReceivedNoteId( + stmts.wallet_db.conn.last_insert_rowid(), + )) } else { // It was there, so grab its row number. stmts diff --git a/zcash_client_sqlite/src/wallet/transact.rs b/zcash_client_sqlite/src/wallet/transact.rs index d109aaa56..16b547aff 100644 --- a/zcash_client_sqlite/src/wallet/transact.rs +++ b/zcash_client_sqlite/src/wallet/transact.rs @@ -416,12 +416,8 @@ mod tests { } // Mine block 11 so that the second note becomes verified - let (cb, _) = fake_compact_block( - sapling_activation_height() + 10, - cb.hash(), - extfvk.clone(), - value, - ); + let (cb, _) = + fake_compact_block(sapling_activation_height() + 10, cb.hash(), extfvk, value); insert_into_cache(&db_cache, &cb); scan_cached_blocks(&tests::network(), &db_cache, &mut db_write, None).unwrap(); @@ -460,7 +456,7 @@ mod tests { let (cb, _) = fake_compact_block( sapling_activation_height(), BlockHash([0; 32]), - extfvk.clone(), + extfvk, value, ); insert_into_cache(&db_cache, &cb); diff --git a/zcash_extensions/src/transparent/demo.rs b/zcash_extensions/src/transparent/demo.rs index 7dad127dd..2f3e5a99a 100644 --- a/zcash_extensions/src/transparent/demo.rs +++ b/zcash_extensions/src/transparent/demo.rs @@ -702,19 +702,14 @@ mod tests { .create_note(110000, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng))) .unwrap(); let cm1 = Node::new(note1.cmu().to_repr()); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); // fake that the note appears in some previous // shielded output tree.append(cm1).unwrap(); let witness1 = IncrementalWitness::from_tree(&tree); builder_a - .add_sapling_spend( - extsk.clone(), - *to.diversifier(), - note1.clone(), - witness1.path().unwrap(), - ) + .add_sapling_spend(extsk, *to.diversifier(), note1, witness1.path().unwrap()) .unwrap(); let mut db_a = DemoBuilder { diff --git a/zcash_primitives/src/group_hash.rs b/zcash_primitives/src/group_hash.rs index da1a54e14..5a9f06a09 100644 --- a/zcash_primitives/src/group_hash.rs +++ b/zcash_primitives/src/group_hash.rs @@ -11,6 +11,7 @@ use blake2s_simd::Params; /// Produces a random point in the Jubjub curve. /// The point is guaranteed to be prime order /// and not the identity. +#[allow(clippy::assertions_on_constants)] pub fn group_hash(tag: &[u8], personalization: &[u8]) -> Option { assert_eq!(personalization.len(), 8); diff --git a/zcash_primitives/src/merkle_tree.rs b/zcash_primitives/src/merkle_tree.rs index 0a2f13477..6258d2299 100644 --- a/zcash_primitives/src/merkle_tree.rs +++ b/zcash_primitives/src/merkle_tree.rs @@ -57,7 +57,7 @@ pub struct CommitmentTree { impl CommitmentTree { /// Creates an empty tree. - pub fn new() -> Self { + pub fn empty() -> Self { CommitmentTree { left: None, right: None, @@ -66,6 +66,7 @@ impl CommitmentTree { } /// Reads a `CommitmentTree` from its serialized form. + #[allow(clippy::redundant_closure)] pub fn read(mut reader: R) -> io::Result { let left = Optional::read(&mut reader, |r| Node::read(r))?; let right = Optional::read(&mut reader, |r| Node::read(r))?; @@ -203,7 +204,7 @@ impl CommitmentTree { /// /// let mut rng = OsRng; /// -/// let mut tree = CommitmentTree::::new(); +/// let mut tree = CommitmentTree::::empty(); /// /// tree.append(Node::new(bls12_381::Scalar::random(&mut rng).to_repr())); /// tree.append(Node::new(bls12_381::Scalar::random(&mut rng).to_repr())); @@ -237,6 +238,7 @@ impl IncrementalWitness { } /// Reads an `IncrementalWitness` from its serialized form. + #[allow(clippy::redundant_closure)] pub fn read(mut reader: R) -> io::Result { let tree = CommitmentTree::read(&mut reader)?; let filled = Vector::read(&mut reader, |r| Node::read(r))?; @@ -348,7 +350,7 @@ impl IncrementalWitness { if self.cursor_depth == 0 { self.filled.push(node); } else { - let mut cursor = CommitmentTree::new(); + let mut cursor = CommitmentTree::empty(); cursor .append_inner(node, depth) .expect("cursor should not be full"); @@ -550,7 +552,7 @@ mod tests { impl TestCommitmentTree { fn new() -> Self { - TestCommitmentTree(CommitmentTree::new()) + TestCommitmentTree(CommitmentTree::empty()) } pub fn read(reader: R) -> io::Result { @@ -618,7 +620,7 @@ mod tests { #[test] fn sapling_empty_root() { let mut tmp = [0u8; 32]; - CommitmentTree::::new() + CommitmentTree::::empty() .root() .write(&mut tmp[..]) .expect("length is 32 bytes"); @@ -630,7 +632,7 @@ mod tests { #[test] fn empty_commitment_tree_roots() { - let tree = CommitmentTree::::new(); + let tree = CommitmentTree::::empty(); let mut tmp = [0u8; 32]; for (i, &expected) in HEX_EMPTY_ROOTS.iter().enumerate().skip(1) { tree.root_inner(i, PathFiller::empty()) diff --git a/zcash_primitives/src/note_encryption.rs b/zcash_primitives/src/note_encryption.rs index d0ec8c293..aabd8d8d0 100644 --- a/zcash_primitives/src/note_encryption.rs +++ b/zcash_primitives/src/note_encryption.rs @@ -635,6 +635,7 @@ pub fn try_sapling_output_recovery_with_ock( /// `PaymentAddress` to which the note was sent. /// /// Implements section 4.17.3 of the Zcash Protocol Specification. +#[allow(clippy::too_many_arguments)] pub fn try_sapling_output_recovery( params: &P, height: BlockHeight, diff --git a/zcash_primitives/src/prover.rs b/zcash_primitives/src/prover.rs index 567b961f4..1bec62829 100644 --- a/zcash_primitives/src/prover.rs +++ b/zcash_primitives/src/prover.rs @@ -22,6 +22,7 @@ pub trait TxProver { /// the context for later use. /// /// [`SpendDescription`]: crate::transaction::components::SpendDescription + #[allow(clippy::too_many_arguments)] fn spend_proof( &self, ctx: &mut Self::SaplingProvingContext, diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index 051d29218..240172b75 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -296,6 +296,7 @@ impl TransparentInputs { } #[cfg(feature = "zfuture")] +#[allow(clippy::type_complexity)] struct TzeInputInfo<'a, BuildCtx> { prevout: TzeOut, builder: Box Result<(u32, Vec), Error> + 'a>, @@ -1043,7 +1044,7 @@ mod tests { .create_note(50000, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng))) .unwrap(); let cmu1 = Node::new(note1.cmu().to_repr()); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); tree.append(cmu1).unwrap(); let witness1 = IncrementalWitness::from_tree(&tree); @@ -1136,7 +1137,7 @@ mod tests { .create_note(50999, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng))) .unwrap(); let cmu1 = Node::new(note1.cmu().to_repr()); - let mut tree = CommitmentTree::new(); + let mut tree = CommitmentTree::empty(); tree.append(cmu1).unwrap(); let mut witness1 = IncrementalWitness::from_tree(&tree); diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index b06e471a4..c326b1393 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -1042,7 +1042,7 @@ mod tests { match xfvk.dk.diversifier(di) { Ok((l, d)) if l == di => assert_eq!(d.0, tv.d0.unwrap()), Ok((_, _)) => assert!(tv.d0.is_none()), - Err(_) => panic!(), + Err(()) => panic!(), } // d1 @@ -1050,7 +1050,7 @@ mod tests { match xfvk.dk.diversifier(di) { Ok((l, d)) if l == di => assert_eq!(d.0, tv.d1.unwrap()), Ok((_, _)) => assert!(tv.d1.is_none()), - Err(_) => panic!(), + Err(()) => panic!(), } // d2 @@ -1058,7 +1058,7 @@ mod tests { match xfvk.dk.diversifier(di) { Ok((l, d)) if l == di => assert_eq!(d.0, tv.d2.unwrap()), Ok((_, _)) => assert!(tv.d2.is_none()), - Err(_) => panic!(), + Err(()) => panic!(), } // dmax diff --git a/zcash_proofs/benches/sapling.rs b/zcash_proofs/benches/sapling.rs index 86f33a17a..c31dec269 100644 --- a/zcash_proofs/benches/sapling.rs +++ b/zcash_proofs/benches/sapling.rs @@ -39,12 +39,9 @@ fn criterion_benchmark(c: &mut Criterion) { randomness: jubjub::Fr::random(&mut rng), }; - let nsk = jubjub::Fr::random(&mut rng); - let ak = jubjub::SubgroupPoint::random(&mut rng); - let proof_generation_key = ProofGenerationKey { - ak: ak.clone(), - nsk: nsk.clone(), + ak: jubjub::SubgroupPoint::random(&mut rng), + nsk: jubjub::Fr::random(&mut rng), }; let viewing_key = proof_generation_key.to_viewing_key(); diff --git a/zcash_proofs/src/circuit/ecc.rs b/zcash_proofs/src/circuit/ecc.rs index 6bde76d67..5167fa5de 100644 --- a/zcash_proofs/src/circuit/ecc.rs +++ b/zcash_proofs/src/circuit/ecc.rs @@ -632,6 +632,7 @@ mod test { use bellman::gadgets::boolean::{AllocatedBit, Boolean}; #[test] + #[allow(clippy::many_single_char_names)] fn test_into_edwards() { let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, @@ -680,7 +681,7 @@ mod test { let p = jubjub::ExtendedPoint::random(&mut rng); let mut cs = TestConstraintSystem::new(); - let q = EdwardsPoint::witness(&mut cs, Some(p.clone())).unwrap(); + let q = EdwardsPoint::witness(&mut cs, Some(p)).unwrap(); let p = p.to_affine(); @@ -744,7 +745,7 @@ mod test { AllocatedBit::alloc(cs.namespace(|| format!("scalar bit {}", i)), Some(b)) .unwrap() }) - .map(|v| Boolean::from(v)) + .map(Boolean::from) .collect::>(); let q = fixed_base_multiplication( @@ -795,7 +796,7 @@ mod test { AllocatedBit::alloc(cs.namespace(|| format!("scalar bit {}", i)), Some(b)) .unwrap() }) - .map(|v| Boolean::from(v)) + .map(Boolean::from) .collect::>(); let q = p.mul(cs.namespace(|| "scalar mul"), &s_bits).unwrap(); @@ -1080,7 +1081,7 @@ mod test { // generator for the prime subgroup let g_prime = g * largest_small_subgroup_order; - check_small_order_from_p(g_prime.clone(), false); + check_small_order_from_p(g_prime, false); let prime_subgroup_order_minus_1 = prime_subgroup_order - jubjub::Fr::one(); let should_not_be_zero = g_prime * prime_subgroup_order_minus_1; @@ -1093,7 +1094,7 @@ mod test { // generator for the small order subgroup let g_small = g * prime_subgroup_order_minus_1; let g_small = g_small + g; - check_small_order_from_p(g_small.clone(), true); + check_small_order_from_p(g_small, true); // g_small does have order 8 let largest_small_subgroup_order_minus_1 = largest_small_subgroup_order - jubjub::Fr::one(); diff --git a/zcash_proofs/src/circuit/pedersen_hash.rs b/zcash_proofs/src/circuit/pedersen_hash.rs index 2ba02f969..685cb8d80 100644 --- a/zcash_proofs/src/circuit/pedersen_hash.rs +++ b/zcash_proofs/src/circuit/pedersen_hash.rs @@ -132,10 +132,10 @@ mod test { let convert_segment = 2; // Conversion to Edwards let add_segments = 6; // Edwards addition - return (chunks) * lookup_chunk - precomputed_booleans + (chunks) * lookup_chunk - precomputed_booleans + segments * convert_segment + all_but_last_segments * ((63 - 1) * add_chunks + add_segments) - + (last_chunks - 1) * add_chunks; + + (last_chunks - 1) * add_chunks } #[test] diff --git a/zcash_proofs/src/circuit/sapling.rs b/zcash_proofs/src/circuit/sapling.rs index 885ceb27f..57d5b468e 100644 --- a/zcash_proofs/src/circuit/sapling.rs +++ b/zcash_proofs/src/circuit/sapling.rs @@ -534,12 +534,9 @@ fn test_input_circuit_with_bls12_381() { randomness: jubjub::Fr::random(&mut rng), }; - let nsk = jubjub::Fr::random(&mut rng); - let ak = jubjub::SubgroupPoint::random(&mut rng); - let proof_generation_key = ProofGenerationKey { - ak: ak.clone(), - nsk: nsk.clone(), + ak: jubjub::SubgroupPoint::random(&mut rng), + nsk: jubjub::Fr::random(&mut rng), }; let viewing_key = proof_generation_key.to_viewing_key(); @@ -571,14 +568,14 @@ fn test_input_circuit_with_bls12_381() { jubjub::ExtendedPoint::from(value_commitment.commitment()).to_affine(); let note = Note { value: value_commitment.value, - g_d: g_d.clone(), - pk_d: payment_address.pk_d().clone(), - rseed: Rseed::BeforeZip212(commitment_randomness.clone()), + g_d, + pk_d: *payment_address.pk_d(), + rseed: Rseed::BeforeZip212(commitment_randomness), }; let mut position = 0u64; let cmu = note.cmu(); - let mut cur = cmu.clone(); + let mut cur = cmu; for (i, val) in auth_path.clone().into_iter().enumerate() { let (uncle, b) = val.unwrap(); @@ -706,12 +703,9 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() { randomness: jubjub::Fr::from_str(&(1000 * (i + 1)).to_string()).unwrap(), }; - let nsk = jubjub::Fr::random(&mut rng); - let ak = jubjub::SubgroupPoint::random(&mut rng); - let proof_generation_key = ProofGenerationKey { - ak: ak.clone(), - nsk: nsk.clone(), + ak: jubjub::SubgroupPoint::random(&mut rng), + nsk: jubjub::Fr::random(&mut rng), }; let viewing_key = proof_generation_key.to_viewing_key(); @@ -751,14 +745,14 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() { ); let note = Note { value: value_commitment.value, - g_d: g_d.clone(), - pk_d: payment_address.pk_d().clone(), - rseed: Rseed::BeforeZip212(commitment_randomness.clone()), + g_d, + pk_d: *payment_address.pk_d(), + rseed: Rseed::BeforeZip212(commitment_randomness), }; let mut position = 0u64; let cmu = note.cmu(); - let mut cur = cmu.clone(); + let mut cur = cmu; for (i, val) in auth_path.clone().into_iter().enumerate() { let (uncle, b) = val.unwrap(); @@ -858,10 +852,7 @@ fn test_output_circuit_with_bls12_381() { let nsk = jubjub::Fr::random(&mut rng); let ak = jubjub::SubgroupPoint::random(&mut rng); - let proof_generation_key = ProofGenerationKey { - ak: ak.clone(), - nsk: nsk.clone(), - }; + let proof_generation_key = ProofGenerationKey { ak, nsk }; let viewing_key = proof_generation_key.to_viewing_key(); @@ -890,7 +881,7 @@ fn test_output_circuit_with_bls12_381() { value_commitment: Some(value_commitment.clone()), payment_address: Some(payment_address.clone()), commitment_randomness: Some(commitment_randomness), - esk: Some(esk.clone()), + esk: Some(esk), }; instance.synthesize(&mut cs).unwrap(); diff --git a/zcash_proofs/src/circuit/sprout/input.rs b/zcash_proofs/src/circuit/sprout/input.rs index bb24e9e2f..9dcede334 100644 --- a/zcash_proofs/src/circuit/sprout/input.rs +++ b/zcash_proofs/src/circuit/sprout/input.rs @@ -13,6 +13,7 @@ pub struct InputNote { } impl InputNote { + #[allow(clippy::too_many_arguments)] pub fn compute( mut cs: CS, a_sk: Option, diff --git a/zcash_proofs/src/circuit/sprout/mod.rs b/zcash_proofs/src/circuit/sprout/mod.rs index 0b167b1b9..97ad21db4 100644 --- a/zcash_proofs/src/circuit/sprout/mod.rs +++ b/zcash_proofs/src/circuit/sprout/mod.rs @@ -347,14 +347,14 @@ fn test_sprout_constraints() { fn get_u256(mut reader: R) -> [u8; 32] { let mut result = [0u8; 32]; - for i in 0..32 { - result[i] = reader.read_u8().unwrap(); + for b in &mut result { + *b = reader.read_u8().unwrap(); } result } - while test_vector.len() != 0 { + while !test_vector.is_empty() { let mut cs = TestConstraintSystem::::new(); let phi = Some(get_u256(&mut test_vector)); @@ -374,8 +374,10 @@ fn test_sprout_constraints() { auth_path[i] = Some((sibling, false)); } let mut position = test_vector.read_u64::().unwrap(); - for i in 0..TREE_DEPTH { - auth_path[i].as_mut().map(|p| p.1 = (position & 1) == 1); + for sibling in &mut auth_path { + if let Some(p) = sibling { + p.1 = (position & 1) == 1; + } position >>= 1; } diff --git a/zcash_proofs/src/circuit/sprout/prfs.rs b/zcash_proofs/src/circuit/sprout/prfs.rs index 240538a9f..6329283f3 100644 --- a/zcash_proofs/src/circuit/sprout/prfs.rs +++ b/zcash_proofs/src/circuit/sprout/prfs.rs @@ -3,6 +3,7 @@ use bellman::gadgets::sha256::sha256_block_no_padding; use bellman::{ConstraintSystem, SynthesisError}; use ff::PrimeField; +#[allow(clippy::many_single_char_names)] fn prf( cs: CS, a: bool, diff --git a/zcash_proofs/src/constants.rs b/zcash_proofs/src/constants.rs index bb83fad89..0aa82344b 100644 --- a/zcash_proofs/src/constants.rs +++ b/zcash_proofs/src/constants.rs @@ -90,6 +90,7 @@ pub fn generate_circuit_generator(mut gen: jubjub::SubgroupPoint) -> FixedGenera /// Returns the coordinates of this point's Montgomery curve representation, or `None` if /// it is the point at infinity. +#[allow(clippy::many_single_char_names)] pub(crate) fn to_montgomery_coords(g: ExtendedPoint) -> Option<(Scalar, Scalar)> { let g = g.to_affine(); let (x, y) = (g.get_u(), g.get_v()); diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 0daf4e8f4..733f9c3ff 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -65,10 +65,9 @@ pub fn default_params_folder() -> Option { #[cfg_attr(docsrs, doc(cfg(feature = "download-params")))] pub fn download_parameters() -> Result<(), minreq::Error> { // Ensure that the default Zcash parameters location exists. - let params_dir = default_params_folder().ok_or(io::Error::new( - io::ErrorKind::Other, - "Could not load default params folder", - ))?; + let params_dir = default_params_folder().ok_or_else(|| { + io::Error::new(io::ErrorKind::Other, "Could not load default params folder") + })?; std::fs::create_dir_all(¶ms_dir)?; let fetch_params = |name: &str, expected_hash: &str| -> Result<(), minreq::Error> { @@ -111,17 +110,19 @@ pub fn download_parameters() -> Result<(), minreq::Error> { Ok(()) } +pub struct ZcashParameters { + pub spend_params: Parameters, + pub spend_vk: PreparedVerifyingKey, + pub output_params: Parameters, + pub output_vk: PreparedVerifyingKey, + pub sprout_vk: Option>, +} + pub fn load_parameters( spend_path: &Path, output_path: &Path, sprout_path: Option<&Path>, -) -> ( - Parameters, - PreparedVerifyingKey, - Parameters, - PreparedVerifyingKey, - Option>, -) { +) -> ZcashParameters { // Load from each of the paths let spend_fs = File::open(spend_path).expect("couldn't load Sapling spend parameters file"); let output_fs = File::open(output_path).expect("couldn't load Sapling output parameters file"); @@ -142,13 +143,7 @@ pub fn parse_parameters( spend_fs: R, output_fs: R, sprout_fs: Option, -) -> ( - Parameters, - PreparedVerifyingKey, - Parameters, - PreparedVerifyingKey, - Option>, -) { +) -> ZcashParameters { let mut spend_fs = hashreader::HashReader::new(spend_fs); let mut output_fs = hashreader::HashReader::new(output_fs); let mut sprout_fs = sprout_fs.map(hashreader::HashReader::new); @@ -201,5 +196,11 @@ pub fn parse_parameters( let output_vk = prepare_verifying_key(&output_params.vk); let sprout_vk = sprout_vk.map(|vk| prepare_verifying_key(&vk)); - (spend_params, spend_vk, output_params, output_vk, sprout_vk) + ZcashParameters { + spend_params, + spend_vk, + output_params, + output_vk, + sprout_vk, + } } diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index 2c6fd2716..7aceebd55 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -45,12 +45,11 @@ impl LocalTxProver { /// This function will panic if the paths do not point to valid parameter files with /// the expected hashes. pub fn new(spend_path: &Path, output_path: &Path) -> Self { - let (spend_params, spend_vk, output_params, _, _) = - load_parameters(spend_path, output_path, None); + let p = load_parameters(spend_path, output_path, None); LocalTxProver { - spend_params, - spend_vk, - output_params, + spend_params: p.spend_params, + spend_vk: p.spend_vk, + output_params: p.output_params, } } @@ -70,13 +69,12 @@ impl LocalTxProver { /// This function will panic if the byte arrays do not contain valid parameters with /// the expected hashes. pub fn from_bytes(spend_param_bytes: &[u8], output_param_bytes: &[u8]) -> Self { - let (spend_params, spend_vk, output_params, _, _) = - parse_parameters(spend_param_bytes, output_param_bytes, None); + let p = parse_parameters(spend_param_bytes, output_param_bytes, None); LocalTxProver { - spend_params, - spend_vk, - output_params, + spend_params: p.spend_params, + spend_vk: p.spend_vk, + output_params: p.output_params, } } @@ -128,13 +126,12 @@ impl LocalTxProver { #[cfg_attr(docsrs, doc(cfg(feature = "bundled-prover")))] pub fn bundled() -> Self { let (spend_buf, output_buf) = wagyu_zcash_parameters::load_sapling_parameters(); - let (spend_params, spend_vk, output_params, _, _) = - parse_parameters(&spend_buf[..], &output_buf[..], None); + let p = parse_parameters(&spend_buf[..], &output_buf[..], None); LocalTxProver { - spend_params, - spend_vk, - output_params, + spend_params: p.spend_params, + spend_vk: p.spend_vk, + output_params: p.output_params, } } } diff --git a/zcash_proofs/src/sapling/prover.rs b/zcash_proofs/src/sapling/prover.rs index abea98544..ee1cb64ed 100644 --- a/zcash_proofs/src/sapling/prover.rs +++ b/zcash_proofs/src/sapling/prover.rs @@ -44,6 +44,7 @@ impl SaplingProvingContext { /// Create the value commitment, re-randomized key, and proof for a Sapling /// SpendDescription, while accumulating its value commitment randomness /// inside the context for later use. + #[allow(clippy::too_many_arguments)] pub fn spend_proof( &mut self, proof_generation_key: ProofGenerationKey, diff --git a/zcash_proofs/src/sapling/verifier.rs b/zcash_proofs/src/sapling/verifier.rs index 8fb14a13c..0f3b23c3d 100644 --- a/zcash_proofs/src/sapling/verifier.rs +++ b/zcash_proofs/src/sapling/verifier.rs @@ -34,6 +34,7 @@ impl SaplingVerificationContext { /// Perform consensus checks on a Sapling SpendDescription, while /// accumulating its value commitment inside the context for later use. + #[allow(clippy::too_many_arguments)] pub fn check_spend( &mut self, cv: jubjub::ExtendedPoint, diff --git a/zcash_proofs/src/sprout.rs b/zcash_proofs/src/sprout.rs index 475e2fb0a..e3fcdd9a4 100644 --- a/zcash_proofs/src/sprout.rs +++ b/zcash_proofs/src/sprout.rs @@ -15,6 +15,7 @@ const GROTH_PROOF_SIZE: usize = 48 // π_A pub const WITNESS_PATH_SIZE: usize = 1 + 33 * TREE_DEPTH + 8; /// Sprout JoinSplit proof generation. +#[allow(clippy::too_many_arguments)] pub fn create_proof( phi: [u8; 32], rt: [u8; 32], @@ -133,6 +134,7 @@ pub fn create_proof( } /// Sprout JoinSplit proof verification. +#[allow(clippy::too_many_arguments)] pub fn verify_proof( proof: &[u8; GROTH_PROOF_SIZE], rt: &[u8; 32],