diff --git a/src/constants.rs b/src/constants.rs index 4df36f86..92accdf7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -2,9 +2,10 @@ use arrayvec::ArrayVec; use ff::{Field, PrimeField}; use group::Curve; -use halo2::{ - arithmetic::{lagrange_interpolate, CurveAffine, FieldExt}, - pasta::pallas, +use halo2::arithmetic::lagrange_interpolate; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, }; pub mod commit_ivk_r; diff --git a/src/constants/commit_ivk_r.rs b/src/constants/commit_ivk_r.rs index 90c5f16c..c0e0b508 100644 --- a/src/constants/commit_ivk_r.rs +++ b/src/constants/commit_ivk_r.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; /// Generator used in SinsemillaCommit randomness for IVK commitment pub const GENERATOR: ([u8; 32], [u8; 32]) = ( @@ -2917,10 +2920,10 @@ pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -2933,9 +2936,9 @@ mod tests { use super::*; use crate::primitives::sinsemilla::CommitDomain; use group::Curve; - use halo2::{ + use pasta_curves::{ arithmetic::{CurveAffine, FieldExt}, - pasta::pallas, + pallas, }; #[test] @@ -2950,13 +2953,13 @@ mod tests { #[test] fn lagrange_coeffs() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS); } #[test] fn z() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z, &U, NUM_WINDOWS); } } diff --git a/src/constants/load.rs b/src/constants/load.rs index 88a2c093..e18b3b22 100644 --- a/src/constants/load.rs +++ b/src/constants/load.rs @@ -1,51 +1,50 @@ use std::convert::TryInto; use crate::constants::{self, compute_lagrange_coeffs, H, NUM_WINDOWS, NUM_WINDOWS_SHORT}; -use halo2::arithmetic::{CurveAffine, FieldExt}; -use std::marker::PhantomData; +use pasta_curves::{arithmetic::FieldExt, pallas}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum OrchardFixedBasesFull { - CommitIvkR(PhantomData), - NoteCommitR(PhantomData), - NullifierK(PhantomData), - ValueCommitR(PhantomData), - SpendAuthG(PhantomData), +pub enum OrchardFixedBasesFull { + CommitIvkR, + NoteCommitR, + NullifierK, + ValueCommitR, + SpendAuthG, } /// A fixed base to be used in scalar multiplication with a full-width scalar. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct OrchardFixedBase { - pub generator: C, - pub lagrange_coeffs: LagrangeCoeffs, - pub z: Z, - pub u: U, +pub struct OrchardFixedBase { + pub generator: pallas::Affine, + pub lagrange_coeffs: LagrangeCoeffs, + pub z: Z, + pub u: U, } -impl From> for OrchardFixedBase { - fn from(base: OrchardFixedBasesFull) -> Self { +impl From for OrchardFixedBase { + fn from(base: OrchardFixedBasesFull) -> Self { let (generator, z, u) = match base { - OrchardFixedBasesFull::CommitIvkR(_) => ( + OrchardFixedBasesFull::CommitIvkR => ( super::commit_ivk_r::generator(), super::commit_ivk_r::Z.into(), super::commit_ivk_r::U.into(), ), - OrchardFixedBasesFull::NoteCommitR(_) => ( + OrchardFixedBasesFull::NoteCommitR => ( super::note_commit_r::generator(), super::note_commit_r::Z.into(), super::note_commit_r::U.into(), ), - OrchardFixedBasesFull::NullifierK(_) => ( + OrchardFixedBasesFull::NullifierK => ( super::nullifier_k::generator(), super::nullifier_k::Z.into(), super::nullifier_k::U.into(), ), - OrchardFixedBasesFull::ValueCommitR(_) => ( + OrchardFixedBasesFull::ValueCommitR => ( super::value_commit_r::generator(), super::value_commit_r::Z.into(), super::value_commit_r::U.into(), ), - OrchardFixedBasesFull::SpendAuthG(_) => ( + OrchardFixedBasesFull::SpendAuthG => ( super::spend_auth_g::generator(), super::spend_auth_g::Z.into(), super::spend_auth_g::U.into(), @@ -63,14 +62,14 @@ impl From> for OrchardFixedBase { /// A fixed base to be used in scalar multiplication with a short signed exponent. #[derive(Clone, Debug, Eq, PartialEq)] -pub struct ValueCommitV { - pub generator: C, - pub lagrange_coeffs_short: LagrangeCoeffsShort, - pub z_short: ZShort, - pub u_short: UShort, +pub struct ValueCommitV { + pub generator: pallas::Affine, + pub lagrange_coeffs_short: LagrangeCoeffsShort, + pub z_short: ZShort, + pub u_short: UShort, } -impl ValueCommitV { +impl ValueCommitV { pub fn get() -> Self { let generator = super::value_commit_v::generator(); Self { @@ -84,59 +83,57 @@ impl ValueCommitV { #[derive(Clone, Debug, Eq, PartialEq)] // 8 coefficients per window -pub struct WindowLagrangeCoeffs(pub Box<[F; H]>); +pub struct WindowLagrangeCoeffs(pub Box<[pallas::Base; H]>); -impl From<&[F; H]> for WindowLagrangeCoeffs { - fn from(array: &[F; H]) -> Self { +impl From<&[pallas::Base; H]> for WindowLagrangeCoeffs { + fn from(array: &[pallas::Base; H]) -> Self { Self(Box::new(*array)) } } #[derive(Clone, Debug, Eq, PartialEq)] // 85 windows per base (with the exception of ValueCommitV) -pub struct LagrangeCoeffs(pub Box<[WindowLagrangeCoeffs; constants::NUM_WINDOWS]>); +pub struct LagrangeCoeffs(pub Box<[WindowLagrangeCoeffs; constants::NUM_WINDOWS]>); -impl From>> for LagrangeCoeffs { - fn from(windows: Vec>) -> Self { +impl From> for LagrangeCoeffs { + fn from(windows: Vec) -> Self { Self(windows.into_boxed_slice().try_into().unwrap()) } } -impl From> for LagrangeCoeffs { - fn from(arrays: Vec<[F; H]>) -> Self { - let windows: Vec> = - arrays.iter().map(|array| array.into()).collect(); +impl From> for LagrangeCoeffs { + fn from(arrays: Vec<[pallas::Base; H]>) -> Self { + let windows: Vec = arrays.iter().map(|array| array.into()).collect(); windows.into() } } #[derive(Clone, Debug, Eq, PartialEq)] // 22 windows for ValueCommitV -pub struct LagrangeCoeffsShort(pub Box<[WindowLagrangeCoeffs; NUM_WINDOWS_SHORT]>); +pub struct LagrangeCoeffsShort(pub Box<[WindowLagrangeCoeffs; NUM_WINDOWS_SHORT]>); -impl From>> for LagrangeCoeffsShort { - fn from(windows: Vec>) -> Self { +impl From> for LagrangeCoeffsShort { + fn from(windows: Vec) -> Self { Self(windows.into_boxed_slice().try_into().unwrap()) } } -impl From> for LagrangeCoeffsShort { - fn from(arrays: Vec<[F; H]>) -> Self { - let windows: Vec> = - arrays.iter().map(|array| array.into()).collect(); +impl From> for LagrangeCoeffsShort { + fn from(arrays: Vec<[pallas::Base; H]>) -> Self { + let windows: Vec = arrays.iter().map(|array| array.into()).collect(); windows.into() } } #[derive(Clone, Debug, Eq, PartialEq)] // 85 Z's per base (with the exception of ValueCommitV) -pub struct Z(pub Box<[F; NUM_WINDOWS]>); +pub struct Z(pub Box<[pallas::Base; NUM_WINDOWS]>); -impl From<[u64; NUM_WINDOWS]> for Z { +impl From<[u64; NUM_WINDOWS]> for Z { fn from(zs: [u64; NUM_WINDOWS]) -> Self { Self( zs.iter() - .map(|z| F::from_u64(*z)) + .map(|z| pallas::Base::from_u64(*z)) .collect::>() .into_boxed_slice() .try_into() @@ -147,13 +144,13 @@ impl From<[u64; NUM_WINDOWS]> for Z { #[derive(Clone, Debug, Eq, PartialEq)] // 22 Z's for ValueCommitV -pub struct ZShort(pub Box<[F; NUM_WINDOWS_SHORT]>); +pub struct ZShort(pub Box<[pallas::Base; NUM_WINDOWS_SHORT]>); -impl From<[u64; NUM_WINDOWS_SHORT]> for ZShort { +impl From<[u64; NUM_WINDOWS_SHORT]> for ZShort { fn from(zs: [u64; NUM_WINDOWS_SHORT]) -> Self { Self( zs.iter() - .map(|z| F::from_u64(*z)) + .map(|z| pallas::Base::from_u64(*z)) .collect::>() .into_boxed_slice() .try_into() @@ -164,14 +161,14 @@ impl From<[u64; NUM_WINDOWS_SHORT]> for ZShort { #[derive(Clone, Debug, Eq, PartialEq)] // 8 u's per window -pub struct WindowUs(pub Box<[F; H]>); +pub struct WindowUs(pub Box<[pallas::Base; H]>); -impl From<&[[u8; 32]; H]> for WindowUs { +impl From<&[[u8; 32]; H]> for WindowUs { fn from(window_us: &[[u8; 32]; H]) -> Self { Self( window_us .iter() - .map(|u| F::from_bytes(u).unwrap()) + .map(|u| pallas::Base::from_bytes(u).unwrap()) .collect::>() .into_boxed_slice() .try_into() @@ -182,34 +179,34 @@ impl From<&[[u8; 32]; H]> for WindowUs { #[derive(Clone, Debug, Eq, PartialEq)] // 85 windows per base (with the exception of ValueCommitV) -pub struct U(pub Box<[WindowUs; NUM_WINDOWS]>); +pub struct U(pub Box<[WindowUs; NUM_WINDOWS]>); -impl From>> for U { - fn from(windows: Vec>) -> Self { +impl From> for U { + fn from(windows: Vec) -> Self { Self(windows.into_boxed_slice().try_into().unwrap()) } } -impl From<[[[u8; 32]; H]; NUM_WINDOWS]> for U { +impl From<[[[u8; 32]; H]; NUM_WINDOWS]> for U { fn from(window_us: [[[u8; 32]; H]; NUM_WINDOWS]) -> Self { - let windows: Vec> = window_us.iter().map(|us| us.into()).collect(); + let windows: Vec = window_us.iter().map(|us| us.into()).collect(); windows.into() } } #[derive(Clone, Debug, Eq, PartialEq)] // 22 windows for ValueCommitV -pub struct UShort(pub Box<[WindowUs; NUM_WINDOWS_SHORT]>); +pub struct UShort(pub Box<[WindowUs; NUM_WINDOWS_SHORT]>); -impl From>> for UShort { - fn from(windows: Vec>) -> Self { +impl From> for UShort { + fn from(windows: Vec) -> Self { Self(windows.into_boxed_slice().try_into().unwrap()) } } -impl From<[[[u8; 32]; H]; NUM_WINDOWS_SHORT]> for UShort { +impl From<[[[u8; 32]; H]; NUM_WINDOWS_SHORT]> for UShort { fn from(window_us: [[[u8; 32]; H]; NUM_WINDOWS_SHORT]) -> Self { - let windows: Vec> = window_us.iter().map(|us| us.into()).collect(); + let windows: Vec = window_us.iter().map(|us| us.into()).collect(); windows.into() } } diff --git a/src/constants/note_commit_r.rs b/src/constants/note_commit_r.rs index ecae83d4..4a12734d 100644 --- a/src/constants/note_commit_r.rs +++ b/src/constants/note_commit_r.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; /// Generator used in SinsemillaCommit randomness for note commitment pub const GENERATOR: ([u8; 32], [u8; 32]) = ( @@ -2917,10 +2920,10 @@ pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -2933,9 +2936,9 @@ mod tests { use super::*; use crate::primitives::sinsemilla::CommitDomain; use group::Curve; - use halo2::{ + use pasta_curves::{ arithmetic::{CurveAffine, FieldExt}, - pasta::pallas, + pallas, }; #[test] @@ -2950,13 +2953,13 @@ mod tests { #[test] fn lagrange_coeffs() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS); } #[test] fn z() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z, &U, NUM_WINDOWS); } } diff --git a/src/constants/nullifier_k.rs b/src/constants/nullifier_k.rs index dff07bcc..37db6fda 100644 --- a/src/constants/nullifier_k.rs +++ b/src/constants/nullifier_k.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; pub const GENERATOR: ([u8; 32], [u8; 32]) = ( [ @@ -2916,10 +2919,10 @@ pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -2931,9 +2934,9 @@ mod tests { }; use super::*; use group::Curve; - use halo2::{ - arithmetic::{CurveAffine, CurveExt, FieldExt}, - pasta::pallas, + use pasta_curves::{ + arithmetic::{CurveExt, FieldExt}, + pallas, }; #[test] @@ -2948,13 +2951,13 @@ mod tests { #[test] fn lagrange_coeffs() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS); } #[test] fn z() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z, &U, NUM_WINDOWS); } } diff --git a/src/constants/spend_auth_g.rs b/src/constants/spend_auth_g.rs index fb6b1af4..41b99c90 100644 --- a/src/constants/spend_auth_g.rs +++ b/src/constants/spend_auth_g.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; /// The value commitment is used to check balance between inputs and outputs. The value is /// placed over this generator. @@ -2918,10 +2921,10 @@ pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -2933,9 +2936,9 @@ mod tests { }; use super::*; use group::Curve; - use halo2::{ + use pasta_curves::{ arithmetic::{CurveAffine, CurveExt, FieldExt}, - pasta::pallas, + pallas, }; #[test] @@ -2950,13 +2953,13 @@ mod tests { #[test] fn lagrange_coeffs() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS); } #[test] fn z() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z, &U, NUM_WINDOWS); } } diff --git a/src/constants/value_commit_r.rs b/src/constants/value_commit_r.rs index bff41877..402df337 100644 --- a/src/constants/value_commit_r.rs +++ b/src/constants/value_commit_r.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; /// The value commitment is used to check balance between inputs and outputs. The value is /// placed over this generator. @@ -2918,10 +2921,10 @@ pub const U: [[[u8; 32]; super::H]; super::NUM_WINDOWS] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -2933,9 +2936,9 @@ mod tests { }; use super::*; use group::Curve; - use halo2::{ + use pasta_curves::{ arithmetic::{CurveAffine, CurveExt, FieldExt}, - pasta::pallas, + pallas, }; #[test] @@ -2950,13 +2953,13 @@ mod tests { #[test] fn lagrange_coeffs() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS); } #[test] fn z() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z, &U, NUM_WINDOWS); } } diff --git a/src/constants/value_commit_v.rs b/src/constants/value_commit_v.rs index 0ad8661b..7ffc9899 100644 --- a/src/constants/value_commit_v.rs +++ b/src/constants/value_commit_v.rs @@ -1,4 +1,7 @@ -use halo2::arithmetic::{CurveAffine, FieldExt}; +use pasta_curves::{ + arithmetic::{CurveAffine, FieldExt}, + pallas, +}; /// The value commitment is used to check balance between inputs and outputs. The value is /// placed over this generator. @@ -771,10 +774,10 @@ pub const U_SHORT: [[[u8; 32]; super::H]; super::NUM_WINDOWS_SHORT] = [ ], ]; -pub fn generator() -> C { - C::from_xy( - C::Base::from_bytes(&GENERATOR.0).unwrap(), - C::Base::from_bytes(&GENERATOR.1).unwrap(), +pub fn generator() -> pallas::Affine { + pallas::Affine::from_xy( + pallas::Base::from_bytes(&GENERATOR.0).unwrap(), + pallas::Base::from_bytes(&GENERATOR.1).unwrap(), ) .unwrap() } @@ -786,9 +789,9 @@ mod tests { }; use super::*; use group::Curve; - use halo2::{ + use pasta_curves::{ arithmetic::{CurveAffine, CurveExt, FieldExt}, - pasta::pallas, + pallas, }; #[test] @@ -803,13 +806,13 @@ mod tests { #[test] fn lagrange_coeffs_short() { - let base = super::generator::(); + let base = super::generator(); test_lagrange_coeffs(base, NUM_WINDOWS_SHORT); } #[test] fn z_short() { - let base = super::generator::(); + let base = super::generator(); test_zs_and_us(base, &Z_SHORT, &U_SHORT, NUM_WINDOWS_SHORT); } }