diff --git a/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs b/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs index 025244cc5..97d32318d 100644 --- a/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs +++ b/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs @@ -58,34 +58,39 @@ impl SinsemillaChip = message - .0 - .iter() - .map(|piece: &MessagePiece| { - piece - .field_elem() - .unwrap() - .to_le_bits() - .into_iter() - .take(K * piece.num_words()) - .collect::>() - }) - .flatten() - .collect(); - - let hasher_S = C::CurveExt::hash_to_curve(S_PERSONALIZATION); - let S = |chunk: &[bool]| hasher_S(&lebs2ip_k(chunk).to_le_bytes()); - - let expected_point = bitstring - .chunks(K) - .fold(Q.to_curve(), |acc, chunk| (acc + S(chunk)) + acc); - let actual_point = C::from_xy(x_a.value().unwrap(), y_a.unwrap()).unwrap(); - assert_eq!(expected_point.to_affine(), actual_point); + let field_elems: Option> = + message.0.iter().map(|piece| piece.field_elem()).collect(); + + if let Some(_) = field_elems { + // Get message as a bitstring. + let bitstring: Vec = message + .0 + .iter() + .map(|piece: &MessagePiece| { + piece + .field_elem() + .unwrap() + .to_le_bits() + .into_iter() + .take(K * piece.num_words()) + .collect::>() + }) + .flatten() + .collect(); + + let hasher_S = C::CurveExt::hash_to_curve(S_PERSONALIZATION); + let S = |chunk: &[bool]| hasher_S(&lebs2ip_k(chunk).to_le_bytes()); + + let expected_point = bitstring + .chunks(K) + .fold(Q.to_curve(), |acc, chunk| (acc + S(chunk)) + acc); + let actual_point = C::from_xy(x_a.value().unwrap(), y_a.unwrap()).unwrap(); + assert_eq!(expected_point.to_affine(), actual_point); + } } // Enable `Sinsemilla` selector on the last double-and-add row for expr1