From ad0360bc1c6bae5d94822b9aca0f9cea75b4a872 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 20 Sep 2021 21:43:31 +0100 Subject: [PATCH] Remove `FieldExt::from_u64` --- CHANGELOG.md | 1 + src/arithmetic/fields.rs | 3 --- src/fields/fp.rs | 10 +++------- src/fields/fq.rs | 10 +++------- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9fc650..933a8f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to Rust's notion of - `FieldExt::{T_MINUS1_OVER2, pow_by_t_minus1_over2, sqrt_alt, sqrt_ratio}` (moved to `SqrtRatio` trait). - `FieldExt::{RESCUE_ALPHA, RESCUE_INVALPHA}` + - `FieldExt::from_u64` (use `From for ff::PrimeField` instead). ## [0.2.1] - 2021-09-17 ### Changed diff --git a/src/arithmetic/fields.rs b/src/arithmetic/fields.rs index 79803b2..b2f236d 100644 --- a/src/arithmetic/fields.rs +++ b/src/arithmetic/fields.rs @@ -82,9 +82,6 @@ pub trait FieldExt: SqrtRatio + From + Ord + Group { Self::random(rand::rngs::OsRng) } - /// Obtains a field element congruent to the integer `v`. - fn from_u64(v: u64) -> Self; - /// Obtains a field element congruent to the integer `v`. fn from_u128(v: u128) -> Self; diff --git a/src/fields/fp.rs b/src/fields/fp.rs index 8e67510..0ec5fcf 100644 --- a/src/fields/fp.rs +++ b/src/fields/fp.rs @@ -737,10 +737,6 @@ impl FieldExt for Fp { 0x12ccca834acdba71, ]); - fn from_u64(v: u64) -> Self { - Fp::from_raw([v as u64, 0, 0, 0]) - } - fn from_u128(v: u128) -> Self { Fp::from_raw([v as u64, (v >> 64) as u64, 0, 0]) } @@ -821,9 +817,9 @@ fn test_pow_by_t_minus1_over2() { fn test_sqrt_ratio_and_alt() { // (true, sqrt(num/div)), if num and div are nonzero and num/div is a square in the field let num = (Fp::TWO_INV).square(); - let div = Fp::from_u64(25); + let div = Fp::from(25); let div_inverse = div.invert().unwrap(); - let expected = Fp::TWO_INV * Fp::from_u64(5).invert().unwrap(); + let expected = Fp::TWO_INV * Fp::from(5).invert().unwrap(); let (is_square, v) = Fp::sqrt_ratio(&num, &div); assert!(bool::from(is_square)); assert!(v == expected || (-v) == expected); @@ -834,7 +830,7 @@ fn test_sqrt_ratio_and_alt() { // (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field let num = num * Fp::root_of_unity(); - let expected = Fp::TWO_INV * Fp::root_of_unity() * Fp::from_u64(5).invert().unwrap(); + let expected = Fp::TWO_INV * Fp::root_of_unity() * Fp::from(5).invert().unwrap(); let (is_square, v) = Fp::sqrt_ratio(&num, &div); assert!(!bool::from(is_square)); assert!(v == expected || (-v) == expected); diff --git a/src/fields/fq.rs b/src/fields/fq.rs index 548c488..fe2045a 100644 --- a/src/fields/fq.rs +++ b/src/fields/fq.rs @@ -737,10 +737,6 @@ impl FieldExt for Fq { 0x06819a58283e528e, ]); - fn from_u64(v: u64) -> Self { - Fq::from_raw([v as u64, 0, 0, 0]) - } - fn from_u128(v: u128) -> Self { Fq::from_raw([v as u64, (v >> 64) as u64, 0, 0]) } @@ -821,9 +817,9 @@ fn test_pow_by_t_minus1_over2() { fn test_sqrt_ratio_and_alt() { // (true, sqrt(num/div)), if num and div are nonzero and num/div is a square in the field let num = (Fq::TWO_INV).square(); - let div = Fq::from_u64(25); + let div = Fq::from(25); let div_inverse = div.invert().unwrap(); - let expected = Fq::TWO_INV * Fq::from_u64(5).invert().unwrap(); + let expected = Fq::TWO_INV * Fq::from(5).invert().unwrap(); let (is_square, v) = Fq::sqrt_ratio(&num, &div); assert!(bool::from(is_square)); assert!(v == expected || (-v) == expected); @@ -834,7 +830,7 @@ fn test_sqrt_ratio_and_alt() { // (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field let num = num * Fq::root_of_unity(); - let expected = Fq::TWO_INV * Fq::root_of_unity() * Fq::from_u64(5).invert().unwrap(); + let expected = Fq::TWO_INV * Fq::root_of_unity() * Fq::from(5).invert().unwrap(); let (is_square, v) = Fq::sqrt_ratio(&num, &div); assert!(!bool::from(is_square)); assert!(v == expected || (-v) == expected);