| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- use group::Curve;
- use halo2::{
- arithmetic::{CurveAffine, FieldExt},
- pasta::pallas,
- };
- use subtle::CtOption;
- use crate::constants::util::gen_const_array;
- /// Coordinate extractor for Pallas.
- ///
- /// Defined in [Zcash Protocol Spec § 5.4.9.7: Coordinate Extractor for Pallas][concreteextractorpallas].
- ///
- /// [concreteextractorpallas]: https://zips.z.cash/protocol/nu5.pdf#concreteextractorpallas
- pub(crate) fn extract_p(point: &pallas::Point) -> pallas::Base {
- point
- .to_affine()
- .coordinates()
- .map(|c| *c.x())
- .unwrap_or_else(pallas::Base::zero)
- }
- /// Coordinate extractor for Pallas.
- ///
- /// Defined in [Zcash Protocol Spec § 5.4.9.7: Coordinate Extractor for Pallas][concreteextractorpallas].
- ///
- /// [concreteextractorpallas]: https://zips.z.cash/protocol/nu5.pdf#concreteextractorpallas
- pub(crate) fn extract_p_bottom(point: CtOption<pallas::Point>) -> CtOption<pallas::Base> {
- point.map(|p| extract_p(&p))
- }
- /// The field element representation of a u64 integer represented by
- /// an L-bit little-endian bitstring.
- pub fn lebs2ip_field<F: FieldExt, const L: usize>(bits: &[bool; L]) -> F {
- F::from_u64(lebs2ip::<L>(bits))
- }
- /// The u64 integer represented by an L-bit little-endian bitstring.
- ///
- /// # Panics
- ///
- /// Panics if the bitstring is longer than 64 bits.
- pub fn lebs2ip<const L: usize>(bits: &[bool; L]) -> u64 {
- assert!(L <= 64);
- bits.iter()
- .enumerate()
- .fold(0u64, |acc, (i, b)| acc + if *b { 1 << i } else { 0 })
- }
- /// The sequence of bits representing a u64 in little-endian order.
- ///
- /// # Panics
- ///
- /// Panics if the expected length of the sequence `NUM_BITS` exceeds
- /// 64.
- pub fn i2lebsp<const NUM_BITS: usize>(int: u64) -> [bool; NUM_BITS] {
- assert!(NUM_BITS <= 64);
- gen_const_array(|mask: usize| (int & (1 << mask)) != 0)
- }
|