mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
ff: Remove SqrtField trait
The sqrt() function is now part of the Field trait. ff_derive returns an error on fields for which it does not support generating a square root function. Note that Fq6 and Fq12 in pairing::bls12_381 leave the function unimplemented. They will be dropped once the migration to the bls12_381 crate is complete. The equivalent structs in that crate are not exposed.
This commit is contained in:
@@ -3,7 +3,7 @@ use rand_core::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||
|
||||
use ff::{Field, PrimeField, SqrtField};
|
||||
use ff::{Field, PrimeField};
|
||||
use pairing::bls12_381::*;
|
||||
|
||||
fn bench_fq_add_assign(c: &mut Criterion) {
|
||||
|
@@ -3,7 +3,7 @@ use rand_core::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
use ff::{Field, SqrtField};
|
||||
use ff::Field;
|
||||
use pairing::bls12_381::*;
|
||||
|
||||
fn bench_fq2_add_assign(c: &mut Criterion) {
|
||||
|
@@ -3,7 +3,7 @@ use rand_core::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||
|
||||
use ff::{Field, PrimeField, SqrtField};
|
||||
use ff::{Field, PrimeField};
|
||||
use pairing::bls12_381::*;
|
||||
|
||||
fn bench_fr_add_assign(c: &mut Criterion) {
|
||||
|
@@ -754,7 +754,7 @@ pub mod g1 {
|
||||
use super::super::{Bls12, Fq, Fq12, FqRepr, Fr};
|
||||
use super::g2::G2Affine;
|
||||
use crate::{Engine, PairingCurveAffine};
|
||||
use ff::{BitIterator, Field, PrimeField, SqrtField};
|
||||
use ff::{BitIterator, Field, PrimeField};
|
||||
use group::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError};
|
||||
use rand_core::RngCore;
|
||||
use std::fmt;
|
||||
@@ -1054,8 +1054,6 @@ pub mod g1 {
|
||||
|
||||
#[test]
|
||||
fn g1_generator() {
|
||||
use crate::SqrtField;
|
||||
|
||||
let mut x = Fq::zero();
|
||||
let mut i = 0;
|
||||
loop {
|
||||
@@ -1366,7 +1364,7 @@ pub mod g2 {
|
||||
use super::super::{Bls12, Fq, Fq12, Fq2, FqRepr, Fr};
|
||||
use super::g1::G1Affine;
|
||||
use crate::{Engine, PairingCurveAffine};
|
||||
use ff::{BitIterator, Field, PrimeField, SqrtField};
|
||||
use ff::{BitIterator, Field, PrimeField};
|
||||
use group::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError};
|
||||
use rand_core::RngCore;
|
||||
use std::fmt;
|
||||
@@ -1708,8 +1706,6 @@ pub mod g2 {
|
||||
|
||||
#[test]
|
||||
fn g2_generator() {
|
||||
use crate::SqrtField;
|
||||
|
||||
let mut x = Fq2::zero();
|
||||
let mut i = 0;
|
||||
loop {
|
||||
|
@@ -1715,8 +1715,6 @@ fn test_fq_pow() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_sqrt() {
|
||||
use ff::SqrtField;
|
||||
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||
0xe5,
|
||||
@@ -1846,8 +1844,6 @@ fn test_fq_num_bits() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_root_of_unity() {
|
||||
use ff::SqrtField;
|
||||
|
||||
assert_eq!(Fq::S, 1);
|
||||
assert_eq!(Fq::multiplicative_generator(), Fq::from(2));
|
||||
assert_eq!(
|
||||
|
@@ -237,6 +237,10 @@ impl Field for Fq12 {
|
||||
c1: t.mul(&self.c1).neg(),
|
||||
})
|
||||
}
|
||||
|
||||
fn sqrt(&self) -> CtOption<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use super::fq::{Fq, FROBENIUS_COEFF_FQ2_C1, NEGATIVE_ONE};
|
||||
use ff::{Field, PowVartime, SqrtField};
|
||||
use ff::{Field, PowVartime};
|
||||
use rand_core::RngCore;
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
@@ -241,9 +241,7 @@ impl Field for Fq2 {
|
||||
fn frobenius_map(&mut self, power: usize) {
|
||||
self.c1.mul_assign(&FROBENIUS_COEFF_FQ2_C1[power % 2]);
|
||||
}
|
||||
}
|
||||
|
||||
impl SqrtField for Fq2 {
|
||||
/// WARNING: THIS IS NOT ACTUALLY CONSTANT TIME YET!
|
||||
/// THIS WILL BE REPLACED BY THE bls12_381 CRATE, WHICH IS CONSTANT TIME!
|
||||
fn sqrt(&self) -> CtOption<Self> {
|
||||
|
@@ -391,6 +391,10 @@ impl Field for Fq6 {
|
||||
tmp
|
||||
})
|
||||
}
|
||||
|
||||
fn sqrt(&self) -> CtOption<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@@ -495,8 +495,6 @@ fn test_fr_pow() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_sqrt() {
|
||||
use ff::SqrtField;
|
||||
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||
0xe5,
|
||||
@@ -628,8 +626,6 @@ fn test_fr_num_bits() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_root_of_unity() {
|
||||
use ff::SqrtField;
|
||||
|
||||
assert_eq!(Fr::S, 32);
|
||||
assert_eq!(Fr::multiplicative_generator(), Fr::from(7));
|
||||
assert_eq!(
|
||||
|
@@ -20,7 +20,7 @@ pub mod tests;
|
||||
|
||||
pub mod bls12_381;
|
||||
|
||||
use ff::{Field, PrimeField, ScalarEngine, SqrtField};
|
||||
use ff::{Field, PrimeField, ScalarEngine};
|
||||
use group::{CurveAffine, CurveOps, CurveOpsOwned, CurveProjective};
|
||||
use subtle::CtOption;
|
||||
|
||||
@@ -61,10 +61,10 @@ pub trait Engine: ScalarEngine {
|
||||
> + From<Self::G2>;
|
||||
|
||||
/// The base field that hosts G1.
|
||||
type Fq: PrimeField + SqrtField;
|
||||
type Fq: PrimeField;
|
||||
|
||||
/// The extension field that hosts G2.
|
||||
type Fqe: SqrtField;
|
||||
type Fqe: Field;
|
||||
|
||||
/// The extension field that hosts the target group of the pairing.
|
||||
type Fqk: Field;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use ff::{Field, PowVartime, PrimeField, SqrtField};
|
||||
use ff::{Field, PowVartime, PrimeField};
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn random_frobenius_tests<F: Field, C: AsRef<[u8]>>(characteristic: C, maxpo
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random_sqrt_tests<F: SqrtField>() {
|
||||
pub fn random_sqrt_tests<F: Field>() {
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||
0xe5,
|
||||
|
Reference in New Issue
Block a user