Merge pull request #198 from huitseeker/warts

Addressing some trivial Rust option/iterator lints
This commit is contained in:
str4d 2020-02-04 18:18:09 +00:00 committed by GitHub
commit ee32f7facb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 70 deletions

View File

@ -582,7 +582,7 @@ mod test {
let expected = hex!("0af5695115ced92c8a0341e43869209636e9aa6472e4576f0f2b996cf812b30e"); let expected = hex!("0af5695115ced92c8a0341e43869209636e9aa6472e4576f0f2b996cf812b30e");
let mut out = r.into_iter(); let mut out = r.into_iter();
for b in expected.into_iter() { for b in expected.iter() {
for i in 0..8 { for i in 0..8 {
let c = out.next().unwrap().get_value().unwrap(); let c = out.next().unwrap().get_value().unwrap();
@ -619,7 +619,7 @@ mod test {
let expected = hex!("2ab8f0683167ba220eef19dccf4f9b1a8193cc09b35e0235842323950530f18a"); let expected = hex!("2ab8f0683167ba220eef19dccf4f9b1a8193cc09b35e0235842323950530f18a");
let mut out = r.into_iter(); let mut out = r.into_iter();
for b in expected.into_iter() { for b in expected.iter() {
for i in 0..8 { for i in 0..8 {
let c = out.next().unwrap().get_value().unwrap(); let c = out.next().unwrap().get_value().unwrap();

View File

@ -402,26 +402,15 @@ fn priv_get_note(
r: *const [c_uchar; 32], r: *const [c_uchar; 32],
) -> Result<Note<Bls12>, ()> { ) -> Result<Note<Bls12>, ()> {
let diversifier = Diversifier(unsafe { *diversifier }); let diversifier = Diversifier(unsafe { *diversifier });
let g_d = match diversifier.g_d::<Bls12>(&JUBJUB) { let g_d = diversifier.g_d::<Bls12>(&JUBJUB).ok_or(())?;
Some(g_d) => g_d,
None => return Err(()),
};
let pk_d = match edwards::Point::<Bls12, Unknown>::read(&(unsafe { &*pk_d })[..], &JUBJUB) { let pk_d = edwards::Point::<Bls12, Unknown>::read(&(unsafe { &*pk_d })[..], &JUBJUB)
Ok(p) => p, .map_err(|_| ())?;
Err(_) => return Err(()),
};
let pk_d = match pk_d.as_prime_order(&JUBJUB) { let pk_d = pk_d.as_prime_order(&JUBJUB).ok_or(())?;
Some(pk_d) => pk_d,
None => return Err(()),
};
// Deserialize randomness // Deserialize randomness
let r = match Fs::from_repr(read_fs(unsafe { &*r })) { let r = Fs::from_repr(read_fs(unsafe { &*r })).map_err(|_| ())?;
Ok(r) => r,
Err(_) => return Err(()),
};
let note = Note { let note = Note {
value, value,

View File

@ -134,12 +134,11 @@ pub fn scan_block(
// mutable references to wtxs for too long. // mutable references to wtxs for too long.
let mut block_witnesses: Vec<_> = wtxs let mut block_witnesses: Vec<_> = wtxs
.iter_mut() .iter_mut()
.map(|tx| { .flat_map(|tx| {
tx.shielded_outputs tx.shielded_outputs
.iter_mut() .iter_mut()
.map(|output| &mut output.witness) .map(|output| &mut output.witness)
}) })
.flatten()
.collect(); .collect();
for to_scan in tx.outputs.into_iter().enumerate() { for to_scan in tx.outputs.into_iter().enumerate() {

View File

@ -255,18 +255,18 @@ fn tree_validator(p: &Params, state: &Blake2bState, indices: &[u32]) -> Option<N
if indices.len() > 1 { if indices.len() > 1 {
let end = indices.len(); let end = indices.len();
let mid = end / 2; let mid = end / 2;
match tree_validator(p, state, &indices[0..mid]) { match (
Some(a) => match tree_validator(p, state, &indices[mid..end]) { tree_validator(p, state, &indices[0..mid]),
Some(b) => { tree_validator(p, state, &indices[mid..end]),
if validate_subtrees(p, &a, &b) { ) {
Some(Node::from_children(a, b, p.collision_byte_length())) (Some(a), Some(b)) => {
} else { if validate_subtrees(p, &a, &b) {
None Some(Node::from_children(a, b, p.collision_byte_length()))
} } else {
None
} }
None => None, }
}, _ => None,
None => None,
} }
} else { } else {
Some(Node::new(&p, &state, indices[0])) Some(Node::new(&p, &state, indices[0]))

View File

@ -89,10 +89,8 @@ impl<E: JubjubEngine> Point<E, Unknown> {
y_repr.as_mut()[3] &= 0x7fffffffffffffff; y_repr.as_mut()[3] &= 0x7fffffffffffffff;
match E::Fr::from_repr(y_repr) { match E::Fr::from_repr(y_repr) {
Ok(y) => match Self::get_for_y(y, x_sign, params) { Ok(y) => Self::get_for_y(y, x_sign, params)
Some(p) => Ok(p), .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "not on curve")),
None => Err(io::Error::new(io::ErrorKind::InvalidInput, "not on curve")),
},
Err(_) => Err(io::Error::new( Err(_) => Err(io::Error::new(
io::ErrorKind::InvalidInput, io::ErrorKind::InvalidInput,
"y is not in field", "y is not in field",

View File

@ -164,14 +164,8 @@ impl<Node: Hashable> CommitmentTree<Node> {
// - Empty leaves are used as needed. // - Empty leaves are used as needed.
let leaf_root = Node::combine( let leaf_root = Node::combine(
0, 0,
&match self.left { &self.left.unwrap_or_else(|| filler.next(0)),
Some(node) => node, &self.right.unwrap_or_else(|| filler.next(0)),
None => filler.next(0),
},
&match self.right {
Some(node) => node,
None => filler.next(0),
},
); );
// 2) Hash in parents up to the currently-filled depth. // 2) Hash in parents up to the currently-filled depth.

View File

@ -14,13 +14,8 @@ fn read_scalar<E: JubjubEngine, R: Read>(reader: R) -> io::Result<E::Fs> {
let mut s_repr = <E::Fs as PrimeField>::Repr::default(); let mut s_repr = <E::Fs as PrimeField>::Repr::default();
s_repr.read_le(reader)?; s_repr.read_le(reader)?;
match E::Fs::from_repr(s_repr) { E::Fs::from_repr(s_repr)
Ok(s) => Ok(s), .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "scalar is not in field"))
Err(_) => Err(io::Error::new(
io::ErrorKind::InvalidInput,
"scalar is not in field",
)),
}
} }
fn write_scalar<E: JubjubEngine, W: Write>(s: &E::Fs, writer: W) -> io::Result<()> { fn write_scalar<E: JubjubEngine, W: Write>(s: &E::Fs, writer: W) -> io::Result<()> {

View File

@ -75,15 +75,13 @@ mod data;
fn zip_0143() { fn zip_0143() {
for tv in self::data::zip_0143::make_test_vectors() { for tv in self::data::zip_0143::make_test_vectors() {
let tx = Transaction::read(&tv.tx[..]).unwrap(); let tx = Transaction::read(&tv.tx[..]).unwrap();
let transparent_input = if let Some(n) = tv.transparent_input { let transparent_input = tv.transparent_input.map(|n| {
Some(( (
n as usize, n as usize,
&tv.script_code, &tv.script_code,
Amount::from_nonnegative_i64(tv.amount).unwrap(), Amount::from_nonnegative_i64(tv.amount).unwrap(),
)) )
} else { });
None
};
assert_eq!( assert_eq!(
signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input), signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input),
@ -96,15 +94,13 @@ fn zip_0143() {
fn zip_0243() { fn zip_0243() {
for tv in self::data::zip_0243::make_test_vectors() { for tv in self::data::zip_0243::make_test_vectors() {
let tx = Transaction::read(&tv.tx[..]).unwrap(); let tx = Transaction::read(&tv.tx[..]).unwrap();
let transparent_input = if let Some(n) = tv.transparent_input { let transparent_input = tv.transparent_input.map(|n| {
Some(( (
n as usize, n as usize,
&tv.script_code, &tv.script_code,
Amount::from_nonnegative_i64(tv.amount).unwrap(), Amount::from_nonnegative_i64(tv.amount).unwrap(),
)) )
} else { });
None
};
assert_eq!( assert_eq!(
signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input), signature_hash(&tx, tv.consensus_branch_id, tv.hash_type, transparent_input),

View File

@ -83,10 +83,9 @@ impl SaplingProvingContext {
let viewing_key = proof_generation_key.to_viewing_key(params); let viewing_key = proof_generation_key.to_viewing_key(params);
// Construct the payment address with the viewing key / diversifier // Construct the payment address with the viewing key / diversifier
let payment_address = match viewing_key.to_payment_address(diversifier, params) { let payment_address = viewing_key
Some(p) => p, .to_payment_address(diversifier, params)
None => return Err(()), .ok_or(())?;
};
// This is the result of the re-randomization, we compute it for the caller // This is the result of the re-randomization, we compute it for the caller
let rk = PublicKey::<Bls12>(proof_generation_key.ak.clone().into()).randomize( let rk = PublicKey::<Bls12>(proof_generation_key.ak.clone().into()).randomize(
@ -266,10 +265,7 @@ impl SaplingProvingContext {
// against our derived bvk. // against our derived bvk.
{ {
// Compute value balance // Compute value balance
let mut value_balance = match compute_value_balance(value_balance, params) { let mut value_balance = compute_value_balance(value_balance, params).ok_or(())?;
Some(a) => a,
None => return Err(()),
};
// Subtract value_balance from cv_sum to get final bvk // Subtract value_balance from cv_sum to get final bvk
value_balance = value_balance.negate(); value_balance = value_balance.negate();