mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-30 15:32:14 +00:00
ff: Rename PrimeField::into_repr -> PrimeField::to_repr
This commit is contained in:
parent
9114c367f4
commit
c597db59a6
@ -221,7 +221,7 @@ impl<G: CurveProjective> Group<G::Engine> for Point<G> {
|
|||||||
Point(G::zero())
|
Point(G::zero())
|
||||||
}
|
}
|
||||||
fn group_mul_assign(&mut self, by: &G::Scalar) {
|
fn group_mul_assign(&mut self, by: &G::Scalar) {
|
||||||
self.0.mul_assign(by.into_repr());
|
self.0.mul_assign(by.to_repr());
|
||||||
}
|
}
|
||||||
fn group_add_assign(&mut self, other: &Self) {
|
fn group_add_assign(&mut self, other: &Self) {
|
||||||
self.0.add_assign(&other.0);
|
self.0.add_assign(&other.0);
|
||||||
|
@ -318,7 +318,7 @@ pub fn field_into_allocated_bits_le<E: ScalarEngine, CS: ConstraintSystem<E>, F:
|
|||||||
let mut tmp = Vec::with_capacity(F::NUM_BITS as usize);
|
let mut tmp = Vec::with_capacity(F::NUM_BITS as usize);
|
||||||
|
|
||||||
let mut found_one = false;
|
let mut found_one = false;
|
||||||
for b in BitIterator::<u8, _>::new(value.into_repr()) {
|
for b in BitIterator::<u8, _>::new(value.to_repr()) {
|
||||||
// Skip leading bits
|
// Skip leading bits
|
||||||
found_one |= field_char.next().unwrap();
|
found_one |= field_char.next().unwrap();
|
||||||
if !found_one {
|
if !found_one {
|
||||||
|
@ -103,8 +103,8 @@ impl<E: ScalarEngine> AllocatedNum<E> {
|
|||||||
|
|
||||||
// We want to ensure that the bit representation of a is
|
// We want to ensure that the bit representation of a is
|
||||||
// less than or equal to r - 1.
|
// less than or equal to r - 1.
|
||||||
let mut a = self.value.map(|e| BitIterator::<u8, _>::new(e.into_repr()));
|
let mut a = self.value.map(|e| BitIterator::<u8, _>::new(e.to_repr()));
|
||||||
let b = (-E::Fr::one()).into_repr();
|
let b = (-E::Fr::one()).to_repr();
|
||||||
|
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ mod test {
|
|||||||
|
|
||||||
assert!(cs.is_satisfied());
|
assert!(cs.is_satisfied());
|
||||||
|
|
||||||
for (b, a) in BitIterator::<u8, _>::new(r.into_repr())
|
for (b, a) in BitIterator::<u8, _>::new(r.to_repr())
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.zip(bits.iter().rev())
|
.zip(bits.iter().rev())
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ fn hash_lc<E: ScalarEngine>(terms: &[(Variable, E::Fr)], h: &mut Blake2sState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut coeff_repr = coeff.into_repr();
|
let mut coeff_repr = coeff.to_repr();
|
||||||
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut coeff_repr);
|
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut coeff_repr);
|
||||||
let coeff_be: Vec<_> = coeff_repr.as_ref().iter().cloned().rev().collect();
|
let coeff_be: Vec<_> = coeff_repr.as_ref().iter().cloned().rev().collect();
|
||||||
buf[9..].copy_from_slice(&coeff_be[..]);
|
buf[9..].copy_from_slice(&coeff_be[..]);
|
||||||
|
@ -287,7 +287,7 @@ impl PrimeField for Fr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_repr(&self) -> FrRepr {
|
fn to_repr(&self) -> FrRepr {
|
||||||
FrRepr::from(*self)
|
FrRepr::from(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ pub fn verify_proof<'a, E: Engine>(
|
|||||||
let mut acc = pvk.ic[0].into_projective();
|
let mut acc = pvk.ic[0].into_projective();
|
||||||
|
|
||||||
for (i, b) in public_inputs.iter().zip(pvk.ic.iter().skip(1)) {
|
for (i, b) in public_inputs.iter().zip(pvk.ic.iter().skip(1)) {
|
||||||
AddAssign::<&E::G1>::add_assign(&mut acc, &b.mul(i.into_repr()));
|
AddAssign::<&E::G1>::add_assign(&mut acc, &b.mul(i.to_repr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The original verification equation is:
|
// The original verification equation is:
|
||||||
|
@ -195,7 +195,7 @@ where
|
|||||||
bases.skip(1)?;
|
bases.skip(1)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut exp = exp.into_repr();
|
let mut exp = exp.to_repr();
|
||||||
<<G::Engine as ScalarEngine>::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut exp);
|
<<G::Engine as ScalarEngine>::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut exp);
|
||||||
|
|
||||||
let exp = exp
|
let exp = exp
|
||||||
@ -305,7 +305,7 @@ fn test_with_bls12() {
|
|||||||
let mut acc = G::zero();
|
let mut acc = G::zero();
|
||||||
|
|
||||||
for (base, exp) in bases.iter().zip(exponents.iter()) {
|
for (base, exp) in bases.iter().zip(exponents.iter()) {
|
||||||
AddAssign::<&G>::add_assign(&mut acc, &base.mul(exp.into_repr()));
|
AddAssign::<&G>::add_assign(&mut acc, &base.mul(exp.to_repr()));
|
||||||
}
|
}
|
||||||
|
|
||||||
acc
|
acc
|
||||||
|
@ -83,7 +83,7 @@ impl ReprEndianness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_repr(
|
fn to_repr(
|
||||||
&self,
|
&self,
|
||||||
repr: &syn::Ident,
|
repr: &syn::Ident,
|
||||||
mont_reduce_self_params: &proc_macro2::TokenStream,
|
mont_reduce_self_params: &proc_macro2::TokenStream,
|
||||||
@ -914,7 +914,7 @@ fn prime_field_impl(
|
|||||||
|
|
||||||
let repr_endianness = endianness.repr_endianness();
|
let repr_endianness = endianness.repr_endianness();
|
||||||
let from_repr_impl = endianness.from_repr(name, limbs);
|
let from_repr_impl = endianness.from_repr(name, limbs);
|
||||||
let into_repr_impl = endianness.into_repr(repr, &mont_reduce_self_params, limbs);
|
let to_repr_impl = endianness.to_repr(repr, &mont_reduce_self_params, limbs);
|
||||||
|
|
||||||
let top_limb_index = limbs - 1;
|
let top_limb_index = limbs - 1;
|
||||||
|
|
||||||
@ -935,7 +935,7 @@ fn prime_field_impl(
|
|||||||
|
|
||||||
impl ::subtle::ConstantTimeEq for #name {
|
impl ::subtle::ConstantTimeEq for #name {
|
||||||
fn ct_eq(&self, other: &#name) -> ::subtle::Choice {
|
fn ct_eq(&self, other: &#name) -> ::subtle::Choice {
|
||||||
self.into_repr().ct_eq(&other.into_repr())
|
self.to_repr().ct_eq(&other.to_repr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,7 +951,7 @@ fn prime_field_impl(
|
|||||||
impl ::core::fmt::Debug for #name
|
impl ::core::fmt::Debug for #name
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||||
write!(f, "{}({:?})", stringify!(#name), self.into_repr())
|
write!(f, "{}({:?})", stringify!(#name), self.to_repr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -982,7 +982,7 @@ fn prime_field_impl(
|
|||||||
|
|
||||||
impl ::core::fmt::Display for #name {
|
impl ::core::fmt::Display for #name {
|
||||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||||
write!(f, "{}({})", stringify!(#name), self.into_repr())
|
write!(f, "{}({})", stringify!(#name), self.to_repr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,13 +997,13 @@ fn prime_field_impl(
|
|||||||
|
|
||||||
impl From<#name> for #repr {
|
impl From<#name> for #repr {
|
||||||
fn from(e: #name) -> #repr {
|
fn from(e: #name) -> #repr {
|
||||||
e.into_repr()
|
e.to_repr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a #name> for #repr {
|
impl<'a> From<&'a #name> for #repr {
|
||||||
fn from(e: &'a #name) -> #repr {
|
fn from(e: &'a #name) -> #repr {
|
||||||
e.into_repr()
|
e.to_repr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1153,8 +1153,8 @@ fn prime_field_impl(
|
|||||||
#from_repr_impl
|
#from_repr_impl
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_repr(&self) -> #repr {
|
fn to_repr(&self) -> #repr {
|
||||||
#into_repr_impl
|
#to_repr_impl
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -181,7 +181,7 @@ pub trait PrimeField: Field + From<u64> {
|
|||||||
///
|
///
|
||||||
/// The endianness of the byte representation is defined by
|
/// The endianness of the byte representation is defined by
|
||||||
/// [`PrimeField::ReprEndianness`].
|
/// [`PrimeField::ReprEndianness`].
|
||||||
fn into_repr(&self) -> Self::Repr;
|
fn to_repr(&self) -> Self::Repr;
|
||||||
|
|
||||||
/// Returns true iff this element is odd.
|
/// Returns true iff this element is odd.
|
||||||
fn is_odd(&self) -> bool;
|
fn is_odd(&self) -> bool;
|
||||||
|
@ -90,7 +90,7 @@ fn random_wnaf_tests<G: CurveProjective>() {
|
|||||||
g1.mul_assign(s);
|
g1.mul_assign(s);
|
||||||
|
|
||||||
wnaf_table(&mut table, g, w);
|
wnaf_table(&mut table, g, w);
|
||||||
wnaf_form(&mut wnaf, s.into_repr(), w);
|
wnaf_form(&mut wnaf, s.to_repr(), w);
|
||||||
let g2 = wnaf_exp(&table, &wnaf);
|
let g2 = wnaf_exp(&table, &wnaf);
|
||||||
|
|
||||||
assert_eq!(g1, g2);
|
assert_eq!(g1, g2);
|
||||||
|
@ -149,7 +149,7 @@ impl<G: CurveProjective> Wnaf<(), Vec<G>, Vec<i64>> {
|
|||||||
let window_size = G::recommended_wnaf_for_scalar(&scalar);
|
let window_size = G::recommended_wnaf_for_scalar(&scalar);
|
||||||
|
|
||||||
// Compute the wNAF form of the scalar.
|
// Compute the wNAF form of the scalar.
|
||||||
wnaf_form(&mut self.scalar, scalar.into_repr(), window_size);
|
wnaf_form(&mut self.scalar, scalar.to_repr(), window_size);
|
||||||
|
|
||||||
// Return a Wnaf object that mutably borrows the base storage location, but
|
// Return a Wnaf object that mutably borrows the base storage location, but
|
||||||
// immutably borrows the computed wNAF form scalar location.
|
// immutably borrows the computed wNAF form scalar location.
|
||||||
@ -203,7 +203,7 @@ impl<B, S: AsMut<Vec<i64>>> Wnaf<usize, B, S> {
|
|||||||
where
|
where
|
||||||
B: AsRef<[G]>,
|
B: AsRef<[G]>,
|
||||||
{
|
{
|
||||||
wnaf_form(self.scalar.as_mut(), scalar.into_repr(), self.window_size);
|
wnaf_form(self.scalar.as_mut(), scalar.to_repr(), self.window_size);
|
||||||
wnaf_exp(self.base.as_ref(), self.scalar.as_mut())
|
wnaf_exp(self.base.as_ref(), self.scalar.as_mut())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ fn bench_fq_sqrt(c: &mut Criterion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_fq_into_repr(c: &mut Criterion) {
|
fn bench_fq_to_repr(c: &mut Criterion) {
|
||||||
const SAMPLES: usize = 1000;
|
const SAMPLES: usize = 1000;
|
||||||
|
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
@ -166,10 +166,10 @@ fn bench_fq_into_repr(c: &mut Criterion) {
|
|||||||
let v: Vec<Fq> = (0..SAMPLES).map(|_| Fq::random(&mut rng)).collect();
|
let v: Vec<Fq> = (0..SAMPLES).map(|_| Fq::random(&mut rng)).collect();
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
c.bench_function("Fq::into_repr", |b| {
|
c.bench_function("Fq::to_repr", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
count = (count + 1) % SAMPLES;
|
count = (count + 1) % SAMPLES;
|
||||||
v[count].into_repr()
|
v[count].to_repr()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ fn bench_fq_from_repr(c: &mut Criterion) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
let v: Vec<FqRepr> = (0..SAMPLES)
|
let v: Vec<FqRepr> = (0..SAMPLES)
|
||||||
.map(|_| Fq::random(&mut rng).into_repr())
|
.map(|_| Fq::random(&mut rng).to_repr())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
@ -204,6 +204,6 @@ criterion_group!(
|
|||||||
bench_fq_invert,
|
bench_fq_invert,
|
||||||
bench_fq_neg,
|
bench_fq_neg,
|
||||||
bench_fq_sqrt,
|
bench_fq_sqrt,
|
||||||
bench_fq_into_repr,
|
bench_fq_to_repr,
|
||||||
bench_fq_from_repr,
|
bench_fq_from_repr,
|
||||||
);
|
);
|
||||||
|
@ -155,7 +155,7 @@ fn bench_fr_sqrt(c: &mut Criterion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bench_fr_into_repr(c: &mut Criterion) {
|
fn bench_fr_to_repr(c: &mut Criterion) {
|
||||||
const SAMPLES: usize = 1000;
|
const SAMPLES: usize = 1000;
|
||||||
|
|
||||||
let mut rng = XorShiftRng::from_seed([
|
let mut rng = XorShiftRng::from_seed([
|
||||||
@ -166,10 +166,10 @@ fn bench_fr_into_repr(c: &mut Criterion) {
|
|||||||
let v: Vec<Fr> = (0..SAMPLES).map(|_| Fr::random(&mut rng)).collect();
|
let v: Vec<Fr> = (0..SAMPLES).map(|_| Fr::random(&mut rng)).collect();
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
c.bench_function("Fr::into_repr", |b| {
|
c.bench_function("Fr::to_repr", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
count = (count + 1) % SAMPLES;
|
count = (count + 1) % SAMPLES;
|
||||||
v[count].into_repr()
|
v[count].to_repr()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ fn bench_fr_from_repr(c: &mut Criterion) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
let v: Vec<FrRepr> = (0..SAMPLES)
|
let v: Vec<FrRepr> = (0..SAMPLES)
|
||||||
.map(|_| Fr::random(&mut rng).into_repr())
|
.map(|_| Fr::random(&mut rng).to_repr())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
@ -204,6 +204,6 @@ criterion_group!(
|
|||||||
bench_fr_invert,
|
bench_fr_invert,
|
||||||
bench_fr_neg,
|
bench_fr_neg,
|
||||||
bench_fr_sqrt,
|
bench_fr_sqrt,
|
||||||
bench_fr_into_repr,
|
bench_fr_to_repr,
|
||||||
bench_fr_from_repr,
|
bench_fr_from_repr,
|
||||||
);
|
);
|
||||||
|
@ -872,8 +872,8 @@ pub mod g1 {
|
|||||||
// is at infinity.
|
// is at infinity.
|
||||||
res.0[0] |= 1 << 6;
|
res.0[0] |= 1 << 6;
|
||||||
} else {
|
} else {
|
||||||
res.0[..48].copy_from_slice(&affine.x.into_repr().0);
|
res.0[..48].copy_from_slice(&affine.x.to_repr().0);
|
||||||
res.0[48..].copy_from_slice(&affine.y.into_repr().0);
|
res.0[48..].copy_from_slice(&affine.y.to_repr().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
@ -969,7 +969,7 @@ pub mod g1 {
|
|||||||
// is at infinity.
|
// is at infinity.
|
||||||
res.0[0] |= 1 << 6;
|
res.0[0] |= 1 << 6;
|
||||||
} else {
|
} else {
|
||||||
res.0 = affine.x.into_repr().0;
|
res.0 = affine.x.to_repr().0;
|
||||||
|
|
||||||
let negy = affine.y.neg();
|
let negy = affine.y.neg();
|
||||||
|
|
||||||
@ -1494,10 +1494,10 @@ pub mod g2 {
|
|||||||
// is at infinity.
|
// is at infinity.
|
||||||
res.0[0] |= 1 << 6;
|
res.0[0] |= 1 << 6;
|
||||||
} else {
|
} else {
|
||||||
res.0[0..48].copy_from_slice(&affine.x.c1.into_repr().0);
|
res.0[0..48].copy_from_slice(&affine.x.c1.to_repr().0);
|
||||||
res.0[48..96].copy_from_slice(&affine.x.c0.into_repr().0);
|
res.0[48..96].copy_from_slice(&affine.x.c0.to_repr().0);
|
||||||
res.0[96..144].copy_from_slice(&affine.y.c1.into_repr().0);
|
res.0[96..144].copy_from_slice(&affine.y.c1.to_repr().0);
|
||||||
res.0[144..192].copy_from_slice(&affine.y.c0.into_repr().0);
|
res.0[144..192].copy_from_slice(&affine.y.c0.to_repr().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
@ -1608,8 +1608,8 @@ pub mod g2 {
|
|||||||
// is at infinity.
|
// is at infinity.
|
||||||
res.0[0] |= 1 << 6;
|
res.0[0] |= 1 << 6;
|
||||||
} else {
|
} else {
|
||||||
res.0[..48].copy_from_slice(&affine.x.c1.into_repr().0);
|
res.0[..48].copy_from_slice(&affine.x.c1.to_repr().0);
|
||||||
res.0[48..].copy_from_slice(&affine.x.c0.into_repr().0);
|
res.0[48..].copy_from_slice(&affine.x.c0.to_repr().0);
|
||||||
|
|
||||||
let negy = affine.y.neg();
|
let negy = affine.y.neg();
|
||||||
|
|
||||||
|
@ -1687,7 +1687,7 @@ fn test_fq_sqrt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fq_from_into_repr() {
|
fn test_fq_from_to_repr() {
|
||||||
// q + 1 should not be in the field
|
// q + 1 should not be in the field
|
||||||
assert!(Fq::from_repr(FqRepr([
|
assert!(Fq::from_repr(FqRepr([
|
||||||
0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac,
|
0x1a, 0x01, 0x11, 0xea, 0x39, 0x7f, 0xe6, 0x9a, 0x4b, 0x1b, 0xa7, 0xb6, 0x43, 0x4b, 0xac,
|
||||||
@ -1722,7 +1722,7 @@ fn test_fq_from_into_repr() {
|
|||||||
0x17, 0x91, 0x4c,
|
0x17, 0x91, 0x4c,
|
||||||
]);
|
]);
|
||||||
a_fq.mul_assign(&b_fq);
|
a_fq.mul_assign(&b_fq);
|
||||||
assert_eq!(a_fq.into_repr(), c);
|
assert_eq!(a_fq.to_repr(), c);
|
||||||
|
|
||||||
// Zero should be in the field.
|
// Zero should be in the field.
|
||||||
assert!(Fq::from_repr(FqRepr([0; 48])).unwrap().is_zero());
|
assert!(Fq::from_repr(FqRepr([0; 48])).unwrap().is_zero());
|
||||||
@ -1735,7 +1735,7 @@ fn test_fq_from_into_repr() {
|
|||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
// Try to turn Fq elements into representations and back again, and compare.
|
// Try to turn Fq elements into representations and back again, and compare.
|
||||||
let a = Fq::random(&mut rng);
|
let a = Fq::random(&mut rng);
|
||||||
let a_repr = a.into_repr();
|
let a_repr = a.to_repr();
|
||||||
let b_repr = FqRepr::from(a);
|
let b_repr = FqRepr::from(a);
|
||||||
assert_eq!(a_repr, b_repr);
|
assert_eq!(a_repr, b_repr);
|
||||||
let a_again = Fq::from_repr(a_repr).unwrap();
|
let a_again = Fq::from_repr(a_repr).unwrap();
|
||||||
|
@ -472,7 +472,7 @@ fn test_fr_sqrt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fr_from_into_repr() {
|
fn test_fr_from_to_repr() {
|
||||||
// r + 1 should not be in the field
|
// r + 1 should not be in the field
|
||||||
assert!(Fr::from_repr(FrRepr([
|
assert!(Fr::from_repr(FrRepr([
|
||||||
0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x5b, 0xfe, 0xff, 0x02, 0xa4, 0xbd,
|
0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x5b, 0xfe, 0xff, 0x02, 0xa4, 0xbd,
|
||||||
@ -503,7 +503,7 @@ fn test_fr_from_into_repr() {
|
|||||||
0x61, 0x71,
|
0x61, 0x71,
|
||||||
]);
|
]);
|
||||||
a_fr.mul_assign(&b_fr);
|
a_fr.mul_assign(&b_fr);
|
||||||
assert_eq!(a_fr.into_repr(), c);
|
assert_eq!(a_fr.to_repr(), c);
|
||||||
|
|
||||||
// Zero should be in the field.
|
// Zero should be in the field.
|
||||||
assert!(Fr::from_repr(FrRepr([0; 32])).unwrap().is_zero());
|
assert!(Fr::from_repr(FrRepr([0; 32])).unwrap().is_zero());
|
||||||
@ -516,7 +516,7 @@ fn test_fr_from_into_repr() {
|
|||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
// Try to turn Fr elements into representations and back again, and compare.
|
// Try to turn Fr elements into representations and back again, and compare.
|
||||||
let a = Fr::random(&mut rng);
|
let a = Fr::random(&mut rng);
|
||||||
let a_repr = a.into_repr();
|
let a_repr = a.to_repr();
|
||||||
let b_repr = FrRepr::from(a);
|
let b_repr = FrRepr::from(a);
|
||||||
assert_eq!(a_repr, b_repr);
|
assert_eq!(a_repr, b_repr);
|
||||||
let a_again = Fr::from_repr(a_repr).unwrap();
|
let a_again = Fr::from_repr(a_repr).unwrap();
|
||||||
|
@ -172,7 +172,7 @@ fn test_g1_uncompressed_invalid_vectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let m = Fq::zero().into_repr();
|
let m = Fq::zero().to_repr();
|
||||||
|
|
||||||
let mut o = o;
|
let mut o = o;
|
||||||
o.as_mut()[..48].copy_from_slice(m.as_ref());
|
o.as_mut()[..48].copy_from_slice(m.as_ref());
|
||||||
@ -198,8 +198,8 @@ fn test_g1_uncompressed_invalid_vectors() {
|
|||||||
let y = y.unwrap();
|
let y = y.unwrap();
|
||||||
|
|
||||||
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
||||||
o.as_mut()[..48].copy_from_slice(x.into_repr().as_ref());
|
o.as_mut()[..48].copy_from_slice(x.to_repr().as_ref());
|
||||||
o.as_mut()[48..].copy_from_slice(y.into_repr().as_ref());
|
o.as_mut()[48..].copy_from_slice(y.to_repr().as_ref());
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
||||||
break;
|
break;
|
||||||
@ -310,7 +310,7 @@ fn test_g2_uncompressed_invalid_vectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let m = Fq::zero().into_repr();
|
let m = Fq::zero().to_repr();
|
||||||
|
|
||||||
let mut o = o;
|
let mut o = o;
|
||||||
o.as_mut()[..48].copy_from_slice(m.as_ref());
|
o.as_mut()[..48].copy_from_slice(m.as_ref());
|
||||||
@ -340,10 +340,10 @@ fn test_g2_uncompressed_invalid_vectors() {
|
|||||||
let y = y.unwrap();
|
let y = y.unwrap();
|
||||||
|
|
||||||
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
||||||
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
|
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
|
||||||
o.as_mut()[48..96].copy_from_slice(x.c0.into_repr().as_ref());
|
o.as_mut()[48..96].copy_from_slice(x.c0.to_repr().as_ref());
|
||||||
o.as_mut()[96..144].copy_from_slice(y.c1.into_repr().as_ref());
|
o.as_mut()[96..144].copy_from_slice(y.c1.to_repr().as_ref());
|
||||||
o.as_mut()[144..].copy_from_slice(y.c0.into_repr().as_ref());
|
o.as_mut()[144..].copy_from_slice(y.c0.to_repr().as_ref());
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
||||||
break;
|
break;
|
||||||
@ -433,7 +433,7 @@ fn test_g1_compressed_invalid_vectors() {
|
|||||||
if x3b.sqrt().is_some().into() {
|
if x3b.sqrt().is_some().into() {
|
||||||
x.add_assign(&Fq::one());
|
x.add_assign(&Fq::one());
|
||||||
} else {
|
} else {
|
||||||
o.as_mut().copy_from_slice(x.into_repr().as_ref());
|
o.as_mut().copy_from_slice(x.to_repr().as_ref());
|
||||||
o.as_mut()[0] |= 0b1000_0000;
|
o.as_mut()[0] |= 0b1000_0000;
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
|
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
|
||||||
@ -456,7 +456,7 @@ fn test_g1_compressed_invalid_vectors() {
|
|||||||
|
|
||||||
if x3b.sqrt().is_some().into() {
|
if x3b.sqrt().is_some().into() {
|
||||||
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
||||||
o.as_mut().copy_from_slice(x.into_repr().as_ref());
|
o.as_mut().copy_from_slice(x.to_repr().as_ref());
|
||||||
o.as_mut()[0] |= 0b1000_0000;
|
o.as_mut()[0] |= 0b1000_0000;
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
||||||
@ -565,8 +565,8 @@ fn test_g2_compressed_invalid_vectors() {
|
|||||||
if x3b.sqrt().is_some().into() {
|
if x3b.sqrt().is_some().into() {
|
||||||
x.add_assign(&Fq2::one());
|
x.add_assign(&Fq2::one());
|
||||||
} else {
|
} else {
|
||||||
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
|
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
|
||||||
o.as_mut()[48..].copy_from_slice(x.c0.into_repr().as_ref());
|
o.as_mut()[48..].copy_from_slice(x.c0.to_repr().as_ref());
|
||||||
o.as_mut()[0] |= 0b1000_0000;
|
o.as_mut()[0] |= 0b1000_0000;
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
|
if let Err(GroupDecodingError::NotOnCurve) = o.into_affine() {
|
||||||
@ -595,8 +595,8 @@ fn test_g2_compressed_invalid_vectors() {
|
|||||||
|
|
||||||
if x3b.sqrt().is_some().into() {
|
if x3b.sqrt().is_some().into() {
|
||||||
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
// We know this is on the curve, but it's likely not going to be in the correct subgroup.
|
||||||
o.as_mut()[..48].copy_from_slice(x.c1.into_repr().as_ref());
|
o.as_mut()[..48].copy_from_slice(x.c1.to_repr().as_ref());
|
||||||
o.as_mut()[48..].copy_from_slice(x.c0.into_repr().as_ref());
|
o.as_mut()[48..].copy_from_slice(x.c0.to_repr().as_ref());
|
||||||
o.as_mut()[0] |= 0b1000_0000;
|
o.as_mut()[0] |= 0b1000_0000;
|
||||||
|
|
||||||
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
if let Err(GroupDecodingError::NotInSubgroup) = o.into_affine() {
|
||||||
|
@ -130,7 +130,7 @@ fn random_bilinearity_tests<E: Engine>() {
|
|||||||
|
|
||||||
let mut cd = c;
|
let mut cd = c;
|
||||||
cd.mul_assign(&d);
|
cd.mul_assign(&d);
|
||||||
let mut cd = cd.into_repr();
|
let mut cd = cd.to_repr();
|
||||||
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut cd);
|
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut cd);
|
||||||
|
|
||||||
use byteorder::ByteOrder;
|
use byteorder::ByteOrder;
|
||||||
|
@ -15,7 +15,7 @@ fn random_encoding_tests<P: PrimeField>() {
|
|||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let r = P::random(&mut rng);
|
let r = P::random(&mut rng);
|
||||||
|
|
||||||
let v = r.into_repr();
|
let v = r.to_repr();
|
||||||
let rdecoded = P::from_repr(v).unwrap();
|
let rdecoded = P::from_repr(v).unwrap();
|
||||||
|
|
||||||
assert_eq!(r, rdecoded);
|
assert_eq!(r, rdecoded);
|
||||||
|
@ -36,7 +36,7 @@ fn scan_output(
|
|||||||
let ct = output.ciphertext;
|
let ct = output.ciphertext;
|
||||||
|
|
||||||
// Increment tree and witnesses
|
// Increment tree and witnesses
|
||||||
let node = Node::new(cmu.into_repr());
|
let node = Node::new(cmu.to_repr());
|
||||||
for witness in existing_witnesses {
|
for witness in existing_witnesses {
|
||||||
witness.append(node).unwrap();
|
witness.append(node).unwrap();
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let fake_cmu = {
|
let fake_cmu = {
|
||||||
let fake_cmu = Fr::random(rng);
|
let fake_cmu = Fr::random(rng);
|
||||||
fake_cmu.into_repr().as_ref().to_owned()
|
fake_cmu.to_repr().as_ref().to_owned()
|
||||||
};
|
};
|
||||||
let fake_epk = {
|
let fake_epk = {
|
||||||
let mut buffer = vec![0; 64];
|
let mut buffer = vec![0; 64];
|
||||||
@ -262,7 +262,7 @@ mod tests {
|
|||||||
Memo::default(),
|
Memo::default(),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
);
|
);
|
||||||
let cmu = note.cm(&JUBJUB).into_repr().as_ref().to_owned();
|
let cmu = note.cm(&JUBJUB).to_repr().as_ref().to_owned();
|
||||||
let mut epk = vec![];
|
let mut epk = vec![];
|
||||||
encryptor.epk().write(&mut epk).unwrap();
|
encryptor.epk().write(&mut epk).unwrap();
|
||||||
let enc_ciphertext = encryptor.encrypt_note_plaintext();
|
let enc_ciphertext = encryptor.encrypt_note_plaintext();
|
||||||
|
@ -172,7 +172,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
|
|||||||
|
|
||||||
assert_eq!(E::Fr::NUM_BITS, 255);
|
assert_eq!(E::Fr::NUM_BITS, 255);
|
||||||
|
|
||||||
let mut y_repr = y.into_repr();
|
let mut y_repr = y.to_repr();
|
||||||
if x.is_odd() {
|
if x.is_odd() {
|
||||||
y_repr.as_mut()[31] |= 0x80;
|
y_repr.as_mut()[31] |= 0x80;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ impl ConstantTimeEq for Fs {
|
|||||||
|
|
||||||
impl ::std::fmt::Display for Fs {
|
impl ::std::fmt::Display for Fs {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||||
write!(f, "Fs({})", self.into_repr())
|
write!(f, "Fs({})", self.to_repr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,13 +137,13 @@ impl From<u64> for Fs {
|
|||||||
|
|
||||||
impl From<Fs> for FsRepr {
|
impl From<Fs> for FsRepr {
|
||||||
fn from(e: Fs) -> FsRepr {
|
fn from(e: Fs) -> FsRepr {
|
||||||
e.into_repr()
|
e.to_repr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a Fs> for FsRepr {
|
impl<'a> From<&'a Fs> for FsRepr {
|
||||||
fn from(e: &'a Fs) -> FsRepr {
|
fn from(e: &'a Fs) -> FsRepr {
|
||||||
e.into_repr()
|
e.to_repr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ impl PrimeField for Fs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_repr(&self) -> FsRepr {
|
fn to_repr(&self) -> FsRepr {
|
||||||
let mut r = *self;
|
let mut r = *self;
|
||||||
r.mont_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);
|
r.mont_reduce(self.0[0], self.0[1], self.0[2], self.0[3], 0, 0, 0, 0);
|
||||||
|
|
||||||
@ -1095,7 +1095,7 @@ fn test_fs_sqrt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fs_from_into_repr() {
|
fn test_fs_from_to_repr() {
|
||||||
// r + 1 should not be in the field
|
// r + 1 should not be in the field
|
||||||
assert!(Fs::from_repr(FsRepr([
|
assert!(Fs::from_repr(FsRepr([
|
||||||
0xb8, 0x2c, 0xf7, 0xd6, 0x5e, 0x0e, 0x97, 0xd0, 0x82, 0x10, 0xc8, 0xcc, 0x93, 0x20, 0x68,
|
0xb8, 0x2c, 0xf7, 0xd6, 0x5e, 0x0e, 0x97, 0xd0, 0x82, 0x10, 0xc8, 0xcc, 0x93, 0x20, 0x68,
|
||||||
@ -1140,7 +1140,7 @@ fn test_fs_from_into_repr() {
|
|||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
// Try to turn Fs elements into representations and back again, and compare.
|
// Try to turn Fs elements into representations and back again, and compare.
|
||||||
let a = Fs::random(&mut rng);
|
let a = Fs::random(&mut rng);
|
||||||
let a_repr = a.into_repr();
|
let a_repr = a.to_repr();
|
||||||
let b_repr = FsRepr::from(a);
|
let b_repr = FsRepr::from(a);
|
||||||
assert_eq!(a_repr, b_repr);
|
assert_eq!(a_repr, b_repr);
|
||||||
let a_again = Fs::from_repr(a_repr).unwrap();
|
let a_again = Fs::from_repr(a_repr).unwrap();
|
||||||
|
@ -374,7 +374,7 @@ fn test_jubjub_params<E: JubjubEngine>(params: &E::Params) {
|
|||||||
|
|
||||||
let max = {
|
let max = {
|
||||||
// Grab char - 1 in little endian.
|
// Grab char - 1 in little endian.
|
||||||
let mut tmp = (-E::Fs::one()).into_repr();
|
let mut tmp = (-E::Fs::one()).to_repr();
|
||||||
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut tmp);
|
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut tmp);
|
||||||
|
|
||||||
// Shift right by 1 bit.
|
// Shift right by 1 bit.
|
||||||
@ -399,8 +399,8 @@ fn test_jubjub_params<E: JubjubEngine>(params: &E::Params) {
|
|||||||
pacc += &tmp;
|
pacc += &tmp;
|
||||||
nacc -= &tmp; // The first subtraction wraps intentionally.
|
nacc -= &tmp; // The first subtraction wraps intentionally.
|
||||||
|
|
||||||
let mut pacc_repr = pacc.into_repr();
|
let mut pacc_repr = pacc.to_repr();
|
||||||
let mut nacc_repr = nacc.into_repr();
|
let mut nacc_repr = nacc.to_repr();
|
||||||
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut pacc_repr);
|
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut pacc_repr);
|
||||||
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut nacc_repr);
|
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut nacc_repr);
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ impl<E: JubjubEngine> ExpandedSpendingKey<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
writer.write_all(self.ask.into_repr().as_ref())?;
|
writer.write_all(self.ask.to_repr().as_ref())?;
|
||||||
writer.write_all(self.nsk.into_repr().as_ref())?;
|
writer.write_all(self.nsk.to_repr().as_ref())?;
|
||||||
writer.write_all(&self.ovk.0)?;
|
writer.write_all(&self.ovk.0)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -211,13 +211,13 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
|||||||
///
|
///
|
||||||
/// let mut tree = CommitmentTree::<Node>::new();
|
/// let mut tree = CommitmentTree::<Node>::new();
|
||||||
///
|
///
|
||||||
/// tree.append(Node::new(Fr::random(&mut rng).into_repr()));
|
/// tree.append(Node::new(Fr::random(&mut rng).to_repr()));
|
||||||
/// tree.append(Node::new(Fr::random(&mut rng).into_repr()));
|
/// tree.append(Node::new(Fr::random(&mut rng).to_repr()));
|
||||||
/// let mut witness = IncrementalWitness::from_tree(&tree);
|
/// let mut witness = IncrementalWitness::from_tree(&tree);
|
||||||
/// assert_eq!(witness.position(), 1);
|
/// assert_eq!(witness.position(), 1);
|
||||||
/// assert_eq!(tree.root(), witness.root());
|
/// assert_eq!(tree.root(), witness.root());
|
||||||
///
|
///
|
||||||
/// let cmu = Node::new(Fr::random(&mut rng).into_repr());
|
/// let cmu = Node::new(Fr::random(&mut rng).to_repr());
|
||||||
/// tree.append(cmu);
|
/// tree.append(cmu);
|
||||||
/// witness.append(cmu);
|
/// witness.append(cmu);
|
||||||
/// assert_eq!(tree.root(), witness.root());
|
/// assert_eq!(tree.root(), witness.root());
|
||||||
|
@ -193,7 +193,7 @@ fn prf_ock(
|
|||||||
let mut ock_input = [0u8; 128];
|
let mut ock_input = [0u8; 128];
|
||||||
ock_input[0..32].copy_from_slice(&ovk.0);
|
ock_input[0..32].copy_from_slice(&ovk.0);
|
||||||
cv.write(&mut ock_input[32..64]).unwrap();
|
cv.write(&mut ock_input[32..64]).unwrap();
|
||||||
ock_input[64..96].copy_from_slice(cmu.into_repr().as_ref());
|
ock_input[64..96].copy_from_slice(cmu.to_repr().as_ref());
|
||||||
epk.write(&mut ock_input[96..128]).unwrap();
|
epk.write(&mut ock_input[96..128]).unwrap();
|
||||||
|
|
||||||
Blake2bParams::new()
|
Blake2bParams::new()
|
||||||
@ -303,7 +303,7 @@ impl SaplingNoteEncryption {
|
|||||||
(&mut input[12..20])
|
(&mut input[12..20])
|
||||||
.write_u64::<LittleEndian>(self.note.value)
|
.write_u64::<LittleEndian>(self.note.value)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
input[20..COMPACT_NOTE_SIZE].copy_from_slice(self.note.r.into_repr().as_ref());
|
input[20..COMPACT_NOTE_SIZE].copy_from_slice(self.note.r.to_repr().as_ref());
|
||||||
input[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE].copy_from_slice(&self.memo.0);
|
input[COMPACT_NOTE_SIZE..NOTE_PLAINTEXT_SIZE].copy_from_slice(&self.memo.0);
|
||||||
|
|
||||||
let mut output = [0u8; ENC_CIPHERTEXT_SIZE];
|
let mut output = [0u8; ENC_CIPHERTEXT_SIZE];
|
||||||
@ -327,7 +327,7 @@ impl SaplingNoteEncryption {
|
|||||||
|
|
||||||
let mut input = [0u8; OUT_PLAINTEXT_SIZE];
|
let mut input = [0u8; OUT_PLAINTEXT_SIZE];
|
||||||
self.note.pk_d.write(&mut input[0..32]).unwrap();
|
self.note.pk_d.write(&mut input[0..32]).unwrap();
|
||||||
input[32..OUT_PLAINTEXT_SIZE].copy_from_slice(self.esk.into_repr().as_ref());
|
input[32..OUT_PLAINTEXT_SIZE].copy_from_slice(self.esk.to_repr().as_ref());
|
||||||
|
|
||||||
let mut output = [0u8; OUT_CIPHERTEXT_SIZE];
|
let mut output = [0u8; OUT_CIPHERTEXT_SIZE];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -366,7 +366,7 @@ fn parse_note_plaintext_without_memo(
|
|||||||
let diversifier = Diversifier(d);
|
let diversifier = Diversifier(d);
|
||||||
let pk_d = diversifier
|
let pk_d = diversifier
|
||||||
.g_d::<Bls12>(&JUBJUB)?
|
.g_d::<Bls12>(&JUBJUB)?
|
||||||
.mul(ivk.into_repr(), &JUBJUB);
|
.mul(ivk.to_repr(), &JUBJUB);
|
||||||
|
|
||||||
let to = PaymentAddress::from_parts(diversifier, pk_d)?;
|
let to = PaymentAddress::from_parts(diversifier, pk_d)?;
|
||||||
let note = to.create_note(v, rcm, &JUBJUB).unwrap();
|
let note = to.create_note(v, rcm, &JUBJUB).unwrap();
|
||||||
@ -525,7 +525,7 @@ pub fn try_sapling_output_recovery(
|
|||||||
let diversifier = Diversifier(d);
|
let diversifier = Diversifier(d);
|
||||||
if diversifier
|
if diversifier
|
||||||
.g_d::<Bls12>(&JUBJUB)?
|
.g_d::<Bls12>(&JUBJUB)?
|
||||||
.mul(esk.into_repr(), &JUBJUB)
|
.mul(esk.to_repr(), &JUBJUB)
|
||||||
!= *epk
|
!= *epk
|
||||||
{
|
{
|
||||||
// Published epk doesn't match calculated epk
|
// Published epk doesn't match calculated epk
|
||||||
|
@ -89,7 +89,7 @@ where
|
|||||||
let window = JubjubBls12::pedersen_hash_exp_window_size() as usize;
|
let window = JubjubBls12::pedersen_hash_exp_window_size() as usize;
|
||||||
let window_mask = (1u64 << window) - 1;
|
let window_mask = (1u64 << window) - 1;
|
||||||
|
|
||||||
let mut acc = acc.into_repr();
|
let mut acc = acc.to_repr();
|
||||||
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut acc);
|
<E::Fs as PrimeField>::ReprEndianness::toggle_little_endian(&mut acc);
|
||||||
let num_limbs: usize = acc.as_ref().len() / 8;
|
let num_limbs: usize = acc.as_ref().len() / 8;
|
||||||
let mut limbs = vec![0u64; num_limbs + 1];
|
let mut limbs = vec![0u64; num_limbs + 1];
|
||||||
|
@ -20,7 +20,7 @@ fn read_scalar<E: JubjubEngine, R: Read>(mut reader: R) -> io::Result<E::Fs> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_scalar<E: JubjubEngine, W: Write>(s: &E::Fs, mut writer: W) -> io::Result<()> {
|
fn write_scalar<E: JubjubEngine, W: Write>(s: &E::Fs, mut writer: W) -> io::Result<()> {
|
||||||
writer.write_all(s.into_repr().as_ref())
|
writer.write_all(s.to_repr().as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn h_star<E: JubjubEngine>(a: &[u8], b: &[u8]) -> E::Fs {
|
fn h_star<E: JubjubEngine>(a: &[u8], b: &[u8]) -> E::Fs {
|
||||||
|
@ -45,7 +45,7 @@ pub fn merkle_hash(depth: usize, lhs: &FrRepr, rhs: &FrRepr) -> FrRepr {
|
|||||||
)
|
)
|
||||||
.to_xy()
|
.to_xy()
|
||||||
.0
|
.0
|
||||||
.into_repr()
|
.to_repr()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A node within the Sapling commitment tree.
|
/// A node within the Sapling commitment tree.
|
||||||
@ -79,7 +79,7 @@ impl Hashable for Node {
|
|||||||
|
|
||||||
fn blank() -> Self {
|
fn blank() -> Self {
|
||||||
Node {
|
Node {
|
||||||
repr: Note::<Bls12>::uncommitted().into_repr(),
|
repr: Note::<Bls12>::uncommitted().to_repr(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,7 +745,7 @@ mod tests {
|
|||||||
let note1 = to
|
let note1 = to
|
||||||
.create_note(50000, Fs::random(&mut rng), &JUBJUB)
|
.create_note(50000, Fs::random(&mut rng), &JUBJUB)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let cm1 = Node::new(note1.cm(&JUBJUB).into_repr());
|
let cm1 = Node::new(note1.cm(&JUBJUB).to_repr());
|
||||||
let mut tree = CommitmentTree::new();
|
let mut tree = CommitmentTree::new();
|
||||||
tree.append(cm1).unwrap();
|
tree.append(cm1).unwrap();
|
||||||
let witness1 = IncrementalWitness::from_tree(&tree);
|
let witness1 = IncrementalWitness::from_tree(&tree);
|
||||||
@ -844,7 +844,7 @@ mod tests {
|
|||||||
let note1 = to
|
let note1 = to
|
||||||
.create_note(59999, Fs::random(&mut rng), &JUBJUB)
|
.create_note(59999, Fs::random(&mut rng), &JUBJUB)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let cm1 = Node::new(note1.cm(&JUBJUB).into_repr());
|
let cm1 = Node::new(note1.cm(&JUBJUB).to_repr());
|
||||||
let mut tree = CommitmentTree::new();
|
let mut tree = CommitmentTree::new();
|
||||||
tree.append(cm1).unwrap();
|
tree.append(cm1).unwrap();
|
||||||
let mut witness1 = IncrementalWitness::from_tree(&tree);
|
let mut witness1 = IncrementalWitness::from_tree(&tree);
|
||||||
@ -882,7 +882,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let note2 = to.create_note(1, Fs::random(&mut rng), &JUBJUB).unwrap();
|
let note2 = to.create_note(1, Fs::random(&mut rng), &JUBJUB).unwrap();
|
||||||
let cm2 = Node::new(note2.cm(&JUBJUB).into_repr());
|
let cm2 = Node::new(note2.cm(&JUBJUB).to_repr());
|
||||||
tree.append(cm2).unwrap();
|
tree.append(cm2).unwrap();
|
||||||
witness1.append(cm2).unwrap();
|
witness1.append(cm2).unwrap();
|
||||||
let witness2 = IncrementalWitness::from_tree(&tree);
|
let witness2 = IncrementalWitness::from_tree(&tree);
|
||||||
|
@ -176,7 +176,7 @@ impl SpendDescription {
|
|||||||
|
|
||||||
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
self.cv.write(&mut writer)?;
|
self.cv.write(&mut writer)?;
|
||||||
writer.write_all(self.anchor.into_repr().as_ref())?;
|
writer.write_all(self.anchor.to_repr().as_ref())?;
|
||||||
writer.write_all(&self.nullifier)?;
|
writer.write_all(&self.nullifier)?;
|
||||||
self.rk.write(&mut writer)?;
|
self.rk.write(&mut writer)?;
|
||||||
writer.write_all(&self.zkproof)?;
|
writer.write_all(&self.zkproof)?;
|
||||||
@ -254,7 +254,7 @@ impl OutputDescription {
|
|||||||
|
|
||||||
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
self.cv.write(&mut writer)?;
|
self.cv.write(&mut writer)?;
|
||||||
writer.write_all(self.cmu.into_repr().as_ref())?;
|
writer.write_all(self.cmu.to_repr().as_ref())?;
|
||||||
self.ephemeral_key.write(&mut writer)?;
|
self.ephemeral_key.write(&mut writer)?;
|
||||||
writer.write_all(&self.enc_ciphertext)?;
|
writer.write_all(&self.enc_ciphertext)?;
|
||||||
writer.write_all(&self.out_ciphertext)?;
|
writer.write_all(&self.out_ciphertext)?;
|
||||||
|
@ -128,7 +128,7 @@ fn shielded_spends_hash(tx: &TransactionData) -> Blake2bHash {
|
|||||||
let mut data = Vec::with_capacity(tx.shielded_spends.len() * 384);
|
let mut data = Vec::with_capacity(tx.shielded_spends.len() * 384);
|
||||||
for s_spend in &tx.shielded_spends {
|
for s_spend in &tx.shielded_spends {
|
||||||
s_spend.cv.write(&mut data).unwrap();
|
s_spend.cv.write(&mut data).unwrap();
|
||||||
data.extend_from_slice(s_spend.anchor.into_repr().as_ref());
|
data.extend_from_slice(s_spend.anchor.to_repr().as_ref());
|
||||||
data.extend_from_slice(&s_spend.nullifier);
|
data.extend_from_slice(&s_spend.nullifier);
|
||||||
s_spend.rk.write(&mut data).unwrap();
|
s_spend.rk.write(&mut data).unwrap();
|
||||||
data.extend_from_slice(&s_spend.zkproof);
|
data.extend_from_slice(&s_spend.zkproof);
|
||||||
|
@ -1014,8 +1014,8 @@ mod tests {
|
|||||||
let xsk = &xsks[j];
|
let xsk = &xsks[j];
|
||||||
let tv = &test_vectors[j];
|
let tv = &test_vectors[j];
|
||||||
|
|
||||||
assert_eq!(xsk.expsk.ask.into_repr().as_ref(), tv.ask.unwrap());
|
assert_eq!(xsk.expsk.ask.to_repr().as_ref(), tv.ask.unwrap());
|
||||||
assert_eq!(xsk.expsk.nsk.into_repr().as_ref(), tv.nsk.unwrap());
|
assert_eq!(xsk.expsk.nsk.to_repr().as_ref(), tv.nsk.unwrap());
|
||||||
|
|
||||||
assert_eq!(xsk.expsk.ovk.0, tv.ovk);
|
assert_eq!(xsk.expsk.ovk.0, tv.ovk);
|
||||||
assert_eq!(xsk.dk.0, tv.dk);
|
assert_eq!(xsk.dk.0, tv.dk);
|
||||||
@ -1040,7 +1040,7 @@ mod tests {
|
|||||||
assert_eq!(xfvk.dk.0, tv.dk);
|
assert_eq!(xfvk.dk.0, tv.dk);
|
||||||
assert_eq!(xfvk.chain_code.0, tv.c);
|
assert_eq!(xfvk.chain_code.0, tv.c);
|
||||||
|
|
||||||
assert_eq!(xfvk.fvk.vk.ivk().into_repr().as_ref(), tv.ivk);
|
assert_eq!(xfvk.fvk.vk.ivk().to_repr().as_ref(), tv.ivk);
|
||||||
|
|
||||||
let mut ser = vec![];
|
let mut ser = vec![];
|
||||||
xfvk.write(&mut ser).unwrap();
|
xfvk.write(&mut ser).unwrap();
|
||||||
|
@ -769,7 +769,7 @@ mod test {
|
|||||||
let q = p.mul(s, params);
|
let q = p.mul(s, params);
|
||||||
let (x1, y1) = q.to_xy();
|
let (x1, y1) = q.to_xy();
|
||||||
|
|
||||||
let mut s_bits = BitIterator::<u8, _>::new(s.into_repr()).collect::<Vec<_>>();
|
let mut s_bits = BitIterator::<u8, _>::new(s.to_repr()).collect::<Vec<_>>();
|
||||||
s_bits.reverse();
|
s_bits.reverse();
|
||||||
s_bits.truncate(Fs::NUM_BITS as usize);
|
s_bits.truncate(Fs::NUM_BITS as usize);
|
||||||
|
|
||||||
@ -822,7 +822,7 @@ mod test {
|
|||||||
y: num_y0,
|
y: num_y0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut s_bits = BitIterator::<u8, _>::new(s.into_repr()).collect::<Vec<_>>();
|
let mut s_bits = BitIterator::<u8, _>::new(s.to_repr()).collect::<Vec<_>>();
|
||||||
s_bits.reverse();
|
s_bits.reverse();
|
||||||
s_bits.truncate(Fs::NUM_BITS as usize);
|
s_bits.truncate(Fs::NUM_BITS as usize);
|
||||||
|
|
||||||
|
@ -615,8 +615,8 @@ fn test_input_circuit_with_bls12_381() {
|
|||||||
::std::mem::swap(&mut lhs, &mut rhs);
|
::std::mem::swap(&mut lhs, &mut rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut lhs: Vec<bool> = BitIterator::<u8, _>::new(lhs.into_repr()).collect();
|
let mut lhs: Vec<bool> = BitIterator::<u8, _>::new(lhs.to_repr()).collect();
|
||||||
let mut rhs: Vec<bool> = BitIterator::<u8, _>::new(rhs.into_repr()).collect();
|
let mut rhs: Vec<bool> = BitIterator::<u8, _>::new(rhs.to_repr()).collect();
|
||||||
|
|
||||||
lhs.reverse();
|
lhs.reverse();
|
||||||
rhs.reverse();
|
rhs.reverse();
|
||||||
@ -799,8 +799,8 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {
|
|||||||
::std::mem::swap(&mut lhs, &mut rhs);
|
::std::mem::swap(&mut lhs, &mut rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut lhs: Vec<bool> = BitIterator::<u8, _>::new(lhs.into_repr()).collect();
|
let mut lhs: Vec<bool> = BitIterator::<u8, _>::new(lhs.to_repr()).collect();
|
||||||
let mut rhs: Vec<bool> = BitIterator::<u8, _>::new(rhs.into_repr()).collect();
|
let mut rhs: Vec<bool> = BitIterator::<u8, _>::new(rhs.to_repr()).collect();
|
||||||
|
|
||||||
lhs.reverse();
|
lhs.reverse();
|
||||||
rhs.reverse();
|
rhs.reverse();
|
||||||
|
Loading…
Reference in New Issue
Block a user