diff --git a/zcash_history/examples/long.rs b/zcash_history/examples/long.rs index bcd8d39f0..e074ff38a 100644 --- a/zcash_history/examples/long.rs +++ b/zcash_history/examples/long.rs @@ -80,7 +80,7 @@ fn prepare_tree(vec: &[NodeData]) -> Tree { } fn main() { - let number = match std::env::args().skip(1).next() { + let number = match std::env::args().nth(1) { None => { eprintln!("writer []"); std::process::exit(1); diff --git a/zcash_history/src/tree.rs b/zcash_history/src/tree.rs index 5c4881884..0e014cbfd 100644 --- a/zcash_history/src/tree.rs +++ b/zcash_history/src/tree.rs @@ -90,9 +90,8 @@ impl Tree { result.stored_count = length; - let mut gen = 0; let mut root = EntryLink::Stored(peaks[0].0); - for (idx, node) in peaks.into_iter() { + for (gen, (idx, node)) in peaks.into_iter().enumerate() { result.stored.insert(idx, node); if gen != 0 { let next_generated = combine_nodes( @@ -105,7 +104,6 @@ impl Tree { ); root = result.push_generated(next_generated); } - gen += 1; } for (idx, node) in extra { @@ -683,9 +681,10 @@ mod tests { if number & (number - 1) == 0 { if let EntryLink::Stored(_) = tree.root() { true } else { false } + } else if let EntryLink::Generated(_) = tree.root() { + true } else { - if let EntryLink::Generated(_) = tree.root() { true } - else { false } + false } ) } @@ -711,9 +710,10 @@ mod tests { if total & total - 1 == 0 { if let EntryLink::Stored(_) = tree.root() { true } else { false } + } else if let EntryLink::Generated(_) = tree.root() { + true } else { - if let EntryLink::Generated(_) = tree.root() { true } - else { false } + false } ) } diff --git a/zcash_primitives/src/merkle_tree.rs b/zcash_primitives/src/merkle_tree.rs index 38bce1599..ef5a429e8 100644 --- a/zcash_primitives/src/merkle_tree.rs +++ b/zcash_primitives/src/merkle_tree.rs @@ -607,11 +607,11 @@ mod tests { #[test] fn empty_root_test_vectors() { let mut tmp = [0u8; 32]; - for i in 0..HEX_EMPTY_ROOTS.len() { + for (i, &expected) in HEX_EMPTY_ROOTS.iter().enumerate() { Node::empty_root(i) .write(&mut tmp[..]) .expect("length is 32 bytes"); - assert_eq!(hex::encode(tmp), HEX_EMPTY_ROOTS[i]); + assert_eq!(hex::encode(tmp), expected); } } @@ -632,11 +632,11 @@ mod tests { fn empty_commitment_tree_roots() { let tree = CommitmentTree::::new(); let mut tmp = [0u8; 32]; - for i in 1..HEX_EMPTY_ROOTS.len() { + for (i, &expected) in HEX_EMPTY_ROOTS.iter().enumerate().skip(1) { tree.root_inner(i, PathFiller::empty()) .write(&mut tmp[..]) .expect("length is 32 bytes"); - assert_eq!(hex::encode(tmp), HEX_EMPTY_ROOTS[i]); + assert_eq!(hex::encode(tmp), expected); } } diff --git a/zcash_primitives/src/primitives.rs b/zcash_primitives/src/primitives.rs index 09996d42a..1cdf27c5b 100644 --- a/zcash_primitives/src/primitives.rs +++ b/zcash_primitives/src/primitives.rs @@ -143,9 +143,7 @@ impl PaymentAddress { Diversifier(tmp) }; // Check that the diversifier is valid - if diversifier.g_d().is_none() { - return None; - } + diversifier.g_d()?; let pk_d = jubjub::SubgroupPoint::from_bytes(bytes[11..43].try_into().unwrap()); if pk_d.is_some().into() { diff --git a/zcash_primitives/src/redjubjub.rs b/zcash_primitives/src/redjubjub.rs index 585080278..0382dc28f 100644 --- a/zcash_primitives/src/redjubjub.rs +++ b/zcash_primitives/src/redjubjub.rs @@ -191,9 +191,7 @@ pub fn batch_verify<'a, R: RngCore>( acc = acc + r + (&entry.vk.0 * c) + (p_g * s); } - acc = acc.mul_by_cofactor().into(); - - acc.is_identity().into() + acc.mul_by_cofactor().is_identity().into() } #[cfg(test)] diff --git a/zcash_primitives/src/transaction/tests.rs b/zcash_primitives/src/transaction/tests.rs index 5aa8254d2..8b7762b97 100644 --- a/zcash_primitives/src/transaction/tests.rs +++ b/zcash_primitives/src/transaction/tests.rs @@ -226,12 +226,9 @@ fn test_tze_tx_parse() { match tx { Ok(tx) => assert!(!tx.tze_inputs.is_empty()), - Err(e) => assert!( - false, - format!( - "An error occurred parsing a serialized TZE transaction: {}", - e - ) + Err(e) => panic!( + "An error occurred parsing a serialized TZE transaction: {}", + e ), } }