Simplify expressions

This commit is contained in:
Jack Grigg 2020-10-30 13:39:44 +00:00
parent 01f0d7dcda
commit 88474c71c7
6 changed files with 17 additions and 24 deletions

View File

@ -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 <number of nodes> [<out_file>]");
std::process::exit(1);

View File

@ -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
}
)
}

View File

@ -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::<Node>::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);
}
}

View File

@ -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() {

View File

@ -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)]

View File

@ -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
),
}
}