Skip to content

Commit

Permalink
Remove use of unwrap() in sinsemilla::merkle test
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed Jun 5, 2021
1 parent ffee0c4 commit 19bcfa0
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/circuit/gadget/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,32 +452,30 @@ impl<C: CurveAffine, const PATH_LENGTH: usize, const K: usize, const MAX_WORDS:
use crate::constants::{L_ORCHARD_BASE, MERKLE_CRH_PERSONALIZATION};
use crate::primitives::sinsemilla::HashDomain;

let l_star = i2lebsp::<10>(l_star as u32);
let left: Vec<_> = left
.value()
.unwrap()
.to_le_bits()
.iter()
.by_val()
.take(L_ORCHARD_BASE)
.collect();
let right: Vec<_> = right
.value()
.unwrap()
.to_le_bits()
.iter()
.by_val()
.take(L_ORCHARD_BASE)
.collect();
let merkle_crh = HashDomain::new(MERKLE_CRH_PERSONALIZATION);
if let (Some(left), Some(right)) = (left.value(), right.value()) {
let l_star = i2lebsp::<10>(l_star as u32);
let left: Vec<_> = left
.to_le_bits()
.iter()
.by_val()
.take(L_ORCHARD_BASE)
.collect();
let right: Vec<_> = right
.to_le_bits()
.iter()
.by_val()
.take(L_ORCHARD_BASE)
.collect();
let merkle_crh = HashDomain::new(MERKLE_CRH_PERSONALIZATION);

let mut message = l_star.to_vec();
message.extend_from_slice(&left);
message.extend_from_slice(&right);
let mut message = l_star.to_vec();
message.extend_from_slice(&left);
message.extend_from_slice(&right);

let expected = merkle_crh.hash(message.into_iter()).unwrap();
let expected = merkle_crh.hash(message.into_iter()).unwrap();

assert_eq!(expected.to_bytes(), result.value().unwrap().to_bytes());
assert_eq!(expected.to_bytes(), result.value().unwrap().to_bytes());
}
}

Ok(result)
Expand Down

0 comments on commit 19bcfa0

Please sign in to comment.