Skip to content

Commit

Permalink
chore: polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
eigmax committed Aug 11, 2023
1 parent 8977833 commit f1a00e8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions plonky/src/field_gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl Fr {
}
impl crate::ff::SqrtField for Fr {
fn legendre(&self) -> crate::ff::LegendreSymbol {
let s = self.pow([9223372034707292160u64, 0u64]);
let s = self.pow([9223372034707292160u64]);
if s == Self::zero() {
crate::ff::LegendreSymbol::Zero
} else if s == Self::one() {
Expand All @@ -490,8 +490,8 @@ impl crate::ff::SqrtField for Fr {
crate::ff::LegendreSymbol::QuadraticNonResidue => None,
crate::ff::LegendreSymbol::QuadraticResidue => {
let mut c = Fr(ROOT_OF_UNITY);
let mut r = self.pow([2147483648u64, 0u64]);
let mut t = self.pow([4294967295u64, 0u64]);
let mut r = self.pow([2147483648u64]);
let mut t = self.pow([4294967295u64]);
let mut m = S;
while t != Self::one() {
let mut i = 1;
Expand Down Expand Up @@ -595,19 +595,27 @@ mod tests {
}

#[test]
fn test_inv() {
fn gl_check_inv() {
let mut rng = rand::thread_rng();
let x = Fr::rand(&mut rng);
let x_inversed = x.inverse().unwrap();
assert_eq!(x * x_inversed, Fr::one());
}

#[test]
fn test_neg() {
fn gl_check_neg() {
let mut rng = rand::thread_rng();
let mut x = Fr::rand(&mut rng);
let y = x.clone();
x.negate();
assert_eq!(x + y, Fr::zero());
}

#[test]
fn gl_check_sqrt() {
let mut rng = rand::thread_rng();
let mut x = Fr::rand(&mut rng);
let sq_x = x.sqrt().unwrap();
assert_eq!(x, sq_x * sq_x);
}
}

0 comments on commit f1a00e8

Please sign in to comment.