From 1ce534b84a80aa15aa0fd5aa1f284a2e145cacc1 Mon Sep 17 00:00:00 2001 From: joe bebel <55120843+joebebel@users.noreply.github.com> Date: Fri, 15 Sep 2023 03:04:13 -0700 Subject: [PATCH] fix clippy lints --- masp_primitives/src/asset_type.rs | 2 +- masp_primitives/src/lib.rs | 2 +- masp_primitives/src/memo.rs | 9 ++------- masp_primitives/src/merkle_tree.rs | 1 - masp_primitives/src/sapling.rs | 12 ++++++------ masp_primitives/src/sapling/note_encryption.rs | 4 ++-- masp_primitives/src/sapling/pedersen_hash.rs | 5 +---- masp_primitives/src/sapling/redjubjub.rs | 4 ++-- masp_primitives/src/transaction.rs | 10 +++------- .../src/transaction/components/amount.rs | 2 +- .../src/transaction/components/sapling.rs | 4 ++-- .../transaction/components/sapling/builder.rs | 2 +- masp_primitives/src/zip32.rs | 2 +- masp_primitives/src/zip32/sapling.rs | 16 ++-------------- masp_proofs/src/circuit/sapling.rs | 4 ++-- 15 files changed, 27 insertions(+), 52 deletions(-) diff --git a/masp_primitives/src/asset_type.rs b/masp_primitives/src/asset_type.rs index 24a48021..1492dabe 100644 --- a/masp_primitives/src/asset_type.rs +++ b/masp_primitives/src/asset_type.rs @@ -179,7 +179,7 @@ impl Hash for AssetType { impl PartialOrd for AssetType { fn partial_cmp(&self, other: &Self) -> Option { - self.get_identifier().partial_cmp(other.get_identifier()) + Some(self.cmp(other)) } } diff --git a/masp_primitives/src/lib.rs b/masp_primitives/src/lib.rs index d1b2d6d2..308e9323 100644 --- a/masp_primitives/src/lib.rs +++ b/masp_primitives/src/lib.rs @@ -13,7 +13,7 @@ // Allow manual RangeIncludes for now #![allow(clippy::manual_range_contains)] // TODO -#![allow(clippy::derive_hash_xor_eq)] +#![allow(clippy::derived_hash_with_manual_eq)] pub mod asset_type; pub mod consensus; diff --git a/masp_primitives/src/memo.rs b/masp_primitives/src/memo.rs index aeaf664d..4c53a478 100644 --- a/masp_primitives/src/memo.rs +++ b/masp_primitives/src/memo.rs @@ -146,9 +146,10 @@ impl Deref for TextMemo { } /// An unencrypted memo received alongside a shielded note in a Zcash transaction. -#[derive(Clone)] +#[derive(Clone, Default)] pub enum Memo { /// An empty memo field. + #[default] Empty, /// A memo field containing a UTF-8 string. Text(TextMemo), @@ -173,12 +174,6 @@ impl fmt::Debug for Memo { } } -impl Default for Memo { - fn default() -> Self { - Memo::Empty - } -} - impl PartialEq for Memo { fn eq(&self, rhs: &Memo) -> bool { match (self, rhs) { diff --git a/masp_primitives/src/merkle_tree.rs b/masp_primitives/src/merkle_tree.rs index 26ae6635..e9a82e51 100644 --- a/masp_primitives/src/merkle_tree.rs +++ b/masp_primitives/src/merkle_tree.rs @@ -303,7 +303,6 @@ impl CommitmentTree { left, right, parents: (1..DEPTH) - .into_iter() .map(|i| { if upos & (1 << i) == 0 { None diff --git a/masp_primitives/src/sapling.rs b/masp_primitives/src/sapling.rs index 05b74f97..a7b244be 100644 --- a/masp_primitives/src/sapling.rs +++ b/masp_primitives/src/sapling.rs @@ -314,7 +314,7 @@ impl BorshDeserialize for ViewingKey { impl PartialOrd for ViewingKey { fn partial_cmp(&self, other: &Self) -> Option { - self.to_bytes().partial_cmp(&other.to_bytes()) + Some(self.cmp(other)) } } @@ -462,7 +462,7 @@ impl FromStr for PaymentAddress { impl PartialOrd for PaymentAddress { fn partial_cmp(&self, other: &Self) -> Option { - self.to_bytes().partial_cmp(&other.to_bytes()) + Some(self.cmp(other)) } } impl Ord for PaymentAddress { @@ -538,7 +538,7 @@ impl TryFrom for NoteValue { type Error = (); fn try_from(value: u64) -> Result { - if value <= MAX_MONEY as u64 { + if value <= MAX_MONEY { Ok(NoteValue(value)) } else { Err(()) @@ -759,7 +759,7 @@ pub mod testing { }; prop_compose! { - pub fn arb_note_value()(value in 0u64..=MAX_MONEY as u64) -> NoteValue { + pub fn arb_note_value()(value in 0u64..=MAX_MONEY) -> NoteValue { NoteValue::try_from(value).unwrap() } } @@ -767,7 +767,7 @@ pub mod testing { prop_compose! { /// The pub fn arb_positive_note_value(bound: u64)( - value in 1u64..=(min(bound, MAX_MONEY as u64)) + value in 1u64..=(min(bound, MAX_MONEY)) ) -> NoteValue { NoteValue::try_from(value).unwrap() } @@ -826,7 +826,7 @@ mod tests { proptest! { #![proptest_config(ProptestConfig::with_cases(10))] #[test] - fn note_serialization(note in arb_positive_note_value(MAX_MONEY as u64).prop_flat_map(arb_note)) { + fn note_serialization(note in arb_positive_note_value(MAX_MONEY).prop_flat_map(arb_note)) { // BorshSerialize let borsh = note.try_to_vec().unwrap(); // BorshDeserialize diff --git a/masp_primitives/src/sapling/note_encryption.rs b/masp_primitives/src/sapling/note_encryption.rs index fa3f5fe8..efad1941 100644 --- a/masp_primitives/src/sapling/note_encryption.rs +++ b/masp_primitives/src/sapling/note_encryption.rs @@ -368,7 +368,7 @@ impl BatchDomain for SaplingDomain

{ shared_secrets .into_iter() .map(|s| s.and_then(|_| secrets_affine.next())) - .zip(ephemeral_keys.into_iter()) + .zip(ephemeral_keys) .map(|(secret, ephemeral_key)| { secret.map(|dhsecret| { Blake2bParams::new() @@ -389,7 +389,7 @@ impl BatchDomain for SaplingDomain

{ let ephemeral_keys: Vec<_> = ephemeral_keys.collect(); let epks = jubjub::AffinePoint::batch_from_bytes(ephemeral_keys.iter().map(|b| b.0)); epks.into_iter() - .zip(ephemeral_keys.into_iter()) + .zip(ephemeral_keys) .map(|(epk, ephemeral_key)| { ( epk.map(jubjub::ExtendedPoint::from) diff --git a/masp_primitives/src/sapling/pedersen_hash.rs b/masp_primitives/src/sapling/pedersen_hash.rs index 31e8de70..89640a90 100644 --- a/masp_primitives/src/sapling/pedersen_hash.rs +++ b/masp_primitives/src/sapling/pedersen_hash.rs @@ -32,10 +32,7 @@ pub fn pedersen_hash(personalization: Personalization, bits: I) -> jubjub::Su where I: IntoIterator, { - let mut bits = personalization - .get_bits() - .into_iter() - .chain(bits.into_iter()); + let mut bits = personalization.get_bits().into_iter().chain(bits); let mut result = jubjub::SubgroupPoint::identity(); let mut generators = PEDERSEN_HASH_EXP_TABLE.iter(); diff --git a/masp_primitives/src/sapling/redjubjub.rs b/masp_primitives/src/sapling/redjubjub.rs index 72c68b78..57c476b0 100644 --- a/masp_primitives/src/sapling/redjubjub.rs +++ b/masp_primitives/src/sapling/redjubjub.rs @@ -215,9 +215,9 @@ pub struct BatchEntry<'a> { // TODO: #82: This is a naive implementation currently, // and doesn't use multiexp. -pub fn batch_verify<'a, R: RngCore>( +pub fn batch_verify( mut rng: &mut R, - batch: &[BatchEntry<'a>], + batch: &[BatchEntry<'_>], p_g: SubgroupPoint, ) -> bool { let mut acc = ExtendedPoint::identity(); diff --git a/masp_primitives/src/transaction.rs b/masp_primitives/src/transaction.rs index 4525b425..3aaa4e74 100644 --- a/masp_primitives/src/transaction.rs +++ b/masp_primitives/src/transaction.rs @@ -439,11 +439,7 @@ impl Transaction { let shielded_spends = sd_v5s .into_iter() - .zip( - v_spend_proofs - .into_iter() - .zip(v_spend_auth_sigs.into_iter()), - ) + .zip(v_spend_proofs.into_iter().zip(v_spend_auth_sigs)) .map(|(sd_5, (zkproof, spend_auth_sig))| { // the following `unwrap` is safe because we know n_spends > 0. sd_5.into_spend_description(spend_anchor.unwrap(), zkproof, spend_auth_sig) @@ -452,13 +448,13 @@ impl Transaction { let shielded_converts = cd_v5s .into_iter() - .zip(v_convert_proofs.into_iter()) + .zip(v_convert_proofs) .map(|(cd_5, zkproof)| cd_5.into_convert_description(convert_anchor.unwrap(), zkproof)) .collect(); let shielded_outputs = od_v5s .into_iter() - .zip(v_output_proofs.into_iter()) + .zip(v_output_proofs) .map(|(od_5, zkproof)| od_5.into_output_description(zkproof)) .collect(); diff --git a/masp_primitives/src/transaction/components/amount.rs b/masp_primitives/src/transaction/components/amount.rs index 6342a398..ae2a644f 100644 --- a/masp_primitives/src/transaction/components/amount.rs +++ b/masp_primitives/src/transaction/components/amount.rs @@ -645,7 +645,7 @@ pub mod testing { prop_compose! { pub fn arb_i128_sum()(asset_type in arb_asset_type(), amt in i128::MIN..i128::MAX) -> I128Sum { - ValueSum::from_pair(asset_type, amt as i128).unwrap() + ValueSum::from_pair(asset_type, amt).unwrap() } } diff --git a/masp_primitives/src/transaction/components/sapling.rs b/masp_primitives/src/transaction/components/sapling.rs index 7ce04153..293f0630 100644 --- a/masp_primitives/src/transaction/components/sapling.rs +++ b/masp_primitives/src/transaction/components/sapling.rs @@ -498,12 +498,12 @@ pub struct ConvertDescriptionV5 { } impl ConvertDescriptionV5 { - pub fn read(mut reader: &mut R) -> io::Result { + pub fn read(reader: &mut R) -> io::Result { // Consensus rules (§4.4) & (§4.5): // - Canonical encoding is enforced here. // - "Not small order" is enforced in SaplingVerificationContext::(check_spend()/check_output()) // (located in zcash_proofs::sapling::verifier). - let cv = read_point(&mut reader, "cv")?; + let cv = read_point(reader, "cv")?; Ok(ConvertDescriptionV5 { cv }) } diff --git a/masp_primitives/src/transaction/components/sapling/builder.rs b/masp_primitives/src/transaction/components/sapling/builder.rs index 9d5594ca..f29dd2e6 100644 --- a/masp_primitives/src/transaction/components/sapling/builder.rs +++ b/masp_primitives/src/transaction/components/sapling/builder.rs @@ -864,7 +864,7 @@ pub mod testing { fn arb_bundle()(n_notes in 1..30usize)( extsk in arb_extended_spending_key(), spendable_notes in vec( - arb_positive_note_value(MAX_MONEY as u64 / 10000).prop_flat_map(arb_note), + arb_positive_note_value(MAX_MONEY / 10000).prop_flat_map(arb_note), n_notes ), commitment_trees in vec( diff --git a/masp_primitives/src/zip32.rs b/masp_primitives/src/zip32.rs index 2e1c9725..03846473 100644 --- a/masp_primitives/src/zip32.rs +++ b/masp_primitives/src/zip32.rs @@ -151,7 +151,7 @@ mod tests { let too_big = DiversifierIndex([ 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]); - assert!(matches!(u32::try_from(too_big), Err(_))); + assert!((u32::try_from(too_big).is_err())); } } diff --git a/masp_primitives/src/zip32/sapling.rs b/masp_primitives/src/zip32/sapling.rs index cef06ca8..13ce9072 100644 --- a/masp_primitives/src/zip32/sapling.rs +++ b/masp_primitives/src/zip32/sapling.rs @@ -554,13 +554,7 @@ impl BorshSerialize for ExtendedFullViewingKey { impl PartialOrd for ExtendedFullViewingKey { fn partial_cmp(&self, other: &Self) -> Option { - let a = self - .try_to_vec() - .expect("unable to canonicalize ExtendedFullViewingKey"); - let b = other - .try_to_vec() - .expect("unable to canonicalize ExtendedFullViewingKey"); - a.partial_cmp(&b) + Some(self.cmp(other)) } } @@ -878,13 +872,7 @@ impl FromStr for ExtendedSpendingKey { impl PartialOrd for ExtendedSpendingKey { fn partial_cmp(&self, other: &Self) -> Option { - let a = self - .try_to_vec() - .expect("unable to canonicalize ExtendedSpendingKey"); - let b = other - .try_to_vec() - .expect("unable to canonicalize ExtendedSpendingKey"); - a.partial_cmp(&b) + Some(self.cmp(other)) } } diff --git a/masp_proofs/src/circuit/sapling.rs b/masp_proofs/src/circuit/sapling.rs index 95e2d669..757ffed3 100644 --- a/masp_proofs/src/circuit/sapling.rs +++ b/masp_proofs/src/circuit/sapling.rs @@ -778,7 +778,7 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() { let tree_depth = 32; - let expected_commitment_us = vec![ + let expected_commitment_us = [ "15274760159508878651789682992925045402656388195689586056903525226511870631006", "17926082480702379779301751040578316677060182517930108360303758506447415843229", "47560733217722603616763811825500591868568811326811130069535870262273364981945", @@ -791,7 +791,7 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() { "27618789340710350120647137095252986938132361388195675764406370494688910938013", ]; - let expected_commitment_vs = vec![ + let expected_commitment_vs = [ "34821791232396287888199995100305255761362584209078006239735148846881442279277", "25119990066174545608121950753413857831099772082356729649061420500567639159355", "37379068700729686079521798425830021519833420633231595656391703260880647751299",