mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 06:13:07 +00:00
Fixes based on PR comments
This commit is contained in:
parent
c9309eb27b
commit
a11d2ed36b
@ -28,8 +28,16 @@ pub trait OEF<const D: usize>: FieldExtension<D> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> OEF<1> for F {
|
||||
const W: Self::BaseField = F::ZERO;
|
||||
}
|
||||
|
||||
pub trait Extendable<const D: usize>: Sized {
|
||||
type Extension: Field + FieldExtension<D, BaseField = Self> + OEF<D> + From<Self>;
|
||||
type Extension: Field + OEF<D, BaseField = Self> + From<Self>;
|
||||
}
|
||||
|
||||
impl<F: Field> Extendable<1> for F {
|
||||
type Extension = F;
|
||||
}
|
||||
|
||||
pub trait FieldExtension<const D: usize>: Field {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::{FieldExtension, OEF};
|
||||
use crate::field::field::Field;
|
||||
use crate::target::Target;
|
||||
use rand::Rng;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
@ -82,7 +80,7 @@ impl Field for QuadraticCrandallField {
|
||||
return None;
|
||||
}
|
||||
|
||||
let a_pow_r_minus_1 = self.frobenius();
|
||||
let a_pow_r_minus_1 = OEF::<2>::frobenius(self);
|
||||
let a_pow_r = a_pow_r_minus_1 * *self;
|
||||
debug_assert!(FieldExtension::<2>::is_in_basefield(&a_pow_r));
|
||||
|
||||
@ -171,7 +169,7 @@ impl Mul for QuadraticCrandallField {
|
||||
let Self([a0, a1]) = self;
|
||||
let Self([b0, b1]) = rhs;
|
||||
|
||||
let c0 = a0 * b0 + Self::W * a1 * b1;
|
||||
let c0 = a0 * b0 + <Self as OEF<2>>::W * a1 * b1;
|
||||
let c1 = a0 * b1 + a1 * b0;
|
||||
|
||||
Self([c0, c1])
|
||||
@ -250,7 +248,7 @@ mod tests {
|
||||
let x = F::rand();
|
||||
assert_eq!(
|
||||
x.exp(<F as FieldExtension<2>>::BaseField::ORDER),
|
||||
x.frobenius()
|
||||
OEF::<2>::frobenius(&x)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -106,9 +106,9 @@ impl Field for QuarticCrandallField {
|
||||
return None;
|
||||
}
|
||||
|
||||
let a_pow_p = self.frobenius();
|
||||
let a_pow_p = OEF::<4>::frobenius(self);
|
||||
let a_pow_p_plus_1 = a_pow_p * *self;
|
||||
let a_pow_p3_plus_p2 = a_pow_p_plus_1.frobenius().frobenius();
|
||||
let a_pow_p3_plus_p2 = OEF::<4>::frobenius(&OEF::<4>::frobenius(&a_pow_p_plus_1));
|
||||
let a_pow_r_minus_1 = a_pow_p3_plus_p2 * a_pow_p;
|
||||
let a_pow_r = a_pow_r_minus_1 * *self;
|
||||
debug_assert!(FieldExtension::<4>::is_in_basefield(&a_pow_r));
|
||||
@ -214,9 +214,9 @@ impl Mul for QuarticCrandallField {
|
||||
let Self([a0, a1, a2, a3]) = self;
|
||||
let Self([b0, b1, b2, b3]) = rhs;
|
||||
|
||||
let c0 = a0 * b0 + Self::W * (a1 * b3 + a2 * b2 + a3 * b1);
|
||||
let c1 = a0 * b1 + a1 * b0 + Self::W * (a2 * b3 + a3 * b2);
|
||||
let c2 = a0 * b2 + a1 * b1 + a2 * b0 + Self::W * a3 * b3;
|
||||
let c0 = a0 * b0 + <Self as OEF<4>>::W * (a1 * b3 + a2 * b2 + a3 * b1);
|
||||
let c1 = a0 * b1 + a1 * b0 + <Self as OEF<4>>::W * (a2 * b3 + a3 * b2);
|
||||
let c2 = a0 * b2 + a1 * b1 + a2 * b0 + <Self as OEF<4>>::W * a3 * b3;
|
||||
let c3 = a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
|
||||
|
||||
Self([c0, c1, c2, c3])
|
||||
@ -308,7 +308,7 @@ mod tests {
|
||||
let x = F::rand();
|
||||
assert_eq!(
|
||||
exp_naive(x, <F as FieldExtension<4>>::BaseField::ORDER as u128),
|
||||
x.frobenius()
|
||||
OEF::<4>::frobenius(&x)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -63,8 +63,8 @@ impl<F: Field> CircuitBuilder<F> {
|
||||
res[(i + j) % D] = if i + j < D {
|
||||
self.mul_add(a.0[i], b.0[j], res[(i + j) % D])
|
||||
} else {
|
||||
let tmp = self.mul_add(a.0[i], b.0[j], res[(i + j) % D]);
|
||||
self.mul(w, tmp)
|
||||
let tmp = self.mul(a.0[i], b.0[j]);
|
||||
self.mul_add(w, tmp, res[(i + j) % D])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user