impl TryInto<Goldilocks> for Ext2/3

This commit is contained in:
zhenfei
2024-01-11 22:04:45 -05:00
parent 3d940fec0a
commit f1d114461a
3 changed files with 28 additions and 2 deletions

View File

@@ -383,3 +383,17 @@ impl GoldilocksExt2 {
Self(res)
}
}
impl TryInto<Goldilocks> for GoldilocksExt2 {
/// The type returned in the event of a conversion error.
type Error = &'static str;
/// Performs the conversion.
fn try_into(self) -> Result<Goldilocks, Self::Error> {
if self.0[1].is_zero_vartime() {
Ok(self.0[0])
} else {
Err("extension field is not zero")
}
}
}

View File

@@ -369,3 +369,17 @@ impl FromUniformBytes<64> for GoldilocksExt3 {
])
}
}
impl TryInto<Goldilocks> for GoldilocksExt3 {
/// The type returned in the event of a conversion error.
type Error = &'static str;
/// Performs the conversion.
fn try_into(self) -> Result<Goldilocks, Self::Error> {
if self.0[1].is_zero_vartime() && self.0[2].is_zero_vartime() {
Ok(self.0[0])
} else {
Err("extension field is not zero")
}
}
}

View File

@@ -11,7 +11,6 @@ use rand_xorshift::XorShiftRng;
use crate::SmallField;
pub fn random_small_field_tests<F: SmallField>(type_name: String) {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
@@ -41,7 +40,6 @@ pub fn random_small_field_tests<F: SmallField>(type_name: String) {
assert_eq!(t1, t2);
}
end_timer!(start);
}
pub fn random_field_tests<F: Field>(type_name: String) {