From 6f46f171b497c4d3d8319075ea6daf201b1bbded Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Mon, 18 Sep 2023 05:08:59 +0530 Subject: [PATCH 01/12] improve fp6 debug format --- src/fp6.rs | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/fp6.rs b/src/fp6.rs index bfe404e..f097e06 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -56,11 +56,33 @@ pub struct Fp6 { impl fmt::Debug for Fp6 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!( - f, - "{:?} + {:?}*u + {:?}*u^2 + {:?}*u^3 + {:?}*u^4 + {:?}*u^5", - self.c0, self.c1, self.c2, self.c3, self.c4, self.c5 - ) + let coeffs = [self.c0, self.c1, self.c2, self.c3, self.c4, self.c5]; + + for i in 0..6 { + if coeffs[i] == Fp::zero() { + continue; + } + + let coefficient = format!("{}", coeffs[i]); + + if i >= 1 { + if coeffs[i] != Fp::one() { + write!(f, " + {}", coefficient)? + } + + if i >= 1 { + write!(f, "u")?; + } + + if i >= 2 { + write!(f, "^{}", i)?; + } + } else { + write!(f, "{coefficient}")?; + } + } + + Ok(()) } } @@ -1258,24 +1280,19 @@ mod tests { #[test] fn test_debug() { + assert_eq!(format!("{:?}", Fp6::one()), "1"); + assert_eq!(format!("{:?}", Fp6::zero()), ""); assert_eq!( - format!("{:?}", Fp6::zero()), - "0 + 0*u + 0*u^2 + 0*u^3 + 0*u^4 + 0*u^5" - ); - assert_eq!( - format!("{:?}", Fp6::one()), - "1 + 0*u + 0*u^2 + 0*u^3 + 0*u^4 + 0*u^5" + format!("{:?}", Fp6::new([1, 2, 3, 4, 5, 6])), + "1 + 2u + 3u^2 + 4u^3 + 5u^4 + 6u^5" ); assert_eq!( - format!("{:?}", Fp6::new([1, 2, 3, 4, 5, 6])), - "1 + 2*u + 3*u^2 + 4*u^3 + 5*u^4 + 6*u^5" + format!("{:?}", Fp6::new([0, 1, 2, 0, 5, 23])), + "u + 2u^2 + 5u^4 + 23u^5" ); let a = Fp6::one().neg(); - assert_eq!( - format!("{:?}", a), - "18446744069414584320 + 0*u + 0*u^2 + 0*u^3 + 0*u^4 + 0*u^5" - ); + assert_eq!(format!("{:?}", a), "18446744069414584320"); } #[test] From 515637a4e7b32f098b7e26e32cdf455e5575fd8c Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Thu, 21 Sep 2023 22:52:28 +0530 Subject: [PATCH 02/12] Improve debug format for Fp3 and Fp6 --- src/fp3.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/fp6.rs | 34 ++++++++++++++++++----------- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index 5689c39..2d66ed5 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -42,7 +42,38 @@ pub(crate) struct Fp3 { impl fmt::Debug for Fp3 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{:?} + {:?}*u + {:?}*u^2", self.a0, self.a1, self.a2) + let coeffs = [self.a0, self.a1, self.a2]; + let mut first_term = true; + for i in 0..3 { + if coeffs[i] == Fp::zero() { + continue; + } + + if !first_term { + write!(f, " + ")?; + } + + if coeffs[i] == Fp::one() && i > 0usize { + write!(f, "u")?; // Display "u" instead of "1u" + } else { + write!(f, "{}", coeffs[i])?; + if i > 0 { + write!(f, "u")?; + } + } + + if i > 1 { + write!(f, "^{}", i)?; + } + + first_term = false; + } + + if first_term { + write!(f, "")?; // Handle the case where all coefficients are zero + } + + Ok(()) } } @@ -250,6 +281,15 @@ mod tests { use rand_core::{OsRng, RngCore}; impl Fp3 { + /// Creates a new Fp3 element + fn new(coeffs: [u64; 3]) -> Self { + Self { + a0: Fp::new(coeffs[0]), + a1: Fp::new(coeffs[1]), + a2: Fp::new(coeffs[2]) + } + } + /// Generates a random canonical element fn random(mut rng: impl RngCore) -> Self { Self { @@ -260,6 +300,26 @@ mod tests { } } + // DISPLAY + // ================================================================================================ + #[test] + fn test_debug() { + assert_eq!(format!("{:?}", Fp3::zero()), ""); + assert_eq!(format!("{:?}", Fp3::one()), "1"); + assert_eq!( + format!("{:?}", Fp3::new([1, 2, 3])), + "1 + 2u + 3u^2" + ); + assert_eq!( + format!("{:?}", Fp3::new([0, 1, 0])), + "u" + ); + assert_eq!(format!("{:?}", Fp3::new([0, 0, 5])), "5u^2"); + + assert_eq!(format!("{:?}", Fp3::new([0, 5, 7])), "5u + 7u^2"); + assert_eq!(format!("{:?}", Fp3::new([1, 1, 1])), "1 + u + u^2") + + } // BASIC ALGEBRA // ================================================================================================ @@ -442,4 +502,6 @@ mod tests { TWO_ADIC_ROOT_OF_UNITY_P3.exp_vartime(&[two_pow_32 - 1, 0, 0,]) ); } + + } diff --git a/src/fp6.rs b/src/fp6.rs index f097e06..bb8aee1 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -57,29 +57,34 @@ pub struct Fp6 { impl fmt::Debug for Fp6 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let coeffs = [self.c0, self.c1, self.c2, self.c3, self.c4, self.c5]; - + let mut first_term = true; for i in 0..6 { if coeffs[i] == Fp::zero() { continue; } - let coefficient = format!("{}", coeffs[i]); - - if i >= 1 { - if coeffs[i] != Fp::one() { - write!(f, " + {}", coefficient)? - } + if !first_term { + write!(f, " + ")?; + } - if i >= 1 { + if coeffs[i] == Fp::one() && i > 0usize { + write!(f, "u")?; // Display "u" instead of "1u" + } else { + write!(f, "{}", coeffs[i])?; + if i > 0 { write!(f, "u")?; } + } - if i >= 2 { - write!(f, "^{}", i)?; - } - } else { - write!(f, "{coefficient}")?; + if i > 1 { + write!(f, "^{}", i)?; } + + first_term = false; + } + + if first_term { + write!(f, "")?; // Handle the case where all coefficients are zero } Ok(()) @@ -1290,9 +1295,12 @@ mod tests { format!("{:?}", Fp6::new([0, 1, 2, 0, 5, 23])), "u + 2u^2 + 5u^4 + 23u^5" ); + assert_eq!(format!("{:?}", Fp6::new([0, 0, 0, 0, 0, 1])), "u^5"); let a = Fp6::one().neg(); assert_eq!(format!("{:?}", a), "18446744069414584320"); + + assert_eq!(format!("{:?}", Fp6::new([1, 1, 1, 1, 1, 1])), "1 + u + u^2 + u^3 + u^4 + u^5") } #[test] From 8d0798824153235950dbaf2cadf78bbfac29063f Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 03:05:50 +0530 Subject: [PATCH 03/12] Used into to destructure Fp6 --- src/fp6.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fp6.rs b/src/fp6.rs index bb8aee1..db52326 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -56,7 +56,7 @@ pub struct Fp6 { impl fmt::Debug for Fp6 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let coeffs = [self.c0, self.c1, self.c2, self.c3, self.c4, self.c5]; + let coeffs: [Fp; 6] = self.into(); let mut first_term = true; for i in 0..6 { if coeffs[i] == Fp::zero() { From e202261e982b1cb59d2961a753b5301adbef5930 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 03:06:41 +0530 Subject: [PATCH 04/12] fix zero case --- src/fp3.rs | 2 +- src/fp6.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index 2d66ed5..33a473a 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -70,7 +70,7 @@ impl fmt::Debug for Fp3 { } if first_term { - write!(f, "")?; // Handle the case where all coefficients are zero + write!(f, "0")?; // Handle the case where all coefficients are zero } Ok(()) diff --git a/src/fp6.rs b/src/fp6.rs index db52326..2581e3f 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -84,7 +84,7 @@ impl fmt::Debug for Fp6 { } if first_term { - write!(f, "")?; // Handle the case where all coefficients are zero + write!(f, "0")?; // Handle the case where all coefficients are zero } Ok(()) From bcaace970ca44dc6a158ddf3b865a69733de0c47 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 21 Sep 2023 16:04:01 -0400 Subject: [PATCH 05/12] CI: Update workflow trigger --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24de72f..cc5baed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,11 @@ name: CI checks -on: push +on: + push: + branches: [main] + pull_request: + branches: + - "**" jobs: test: From d9d031c07923ff31971f51da093a928ee24d73d2 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 03:55:33 +0530 Subject: [PATCH 06/12] Efficient debug formatting --- src/fp3.rs | 76 ++++++++++++++++++++++-------------------------------- src/fp6.rs | 54 +++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 68 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index 33a473a..654160e 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -43,34 +43,42 @@ pub(crate) struct Fp3 { impl fmt::Debug for Fp3 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let coeffs = [self.a0, self.a1, self.a2]; - let mut first_term = true; - for i in 0..3 { - if coeffs[i] == Fp::zero() { - continue; - } - - if !first_term { - write!(f, " + ")?; - } - if coeffs[i] == Fp::one() && i > 0usize { - write!(f, "u")?; // Display "u" instead of "1u" + let format_term = |coef: Fp, degree: usize| -> String { + if coef == Fp::one() && degree > 0 { + let exp = if degree > 1 { + format!("^{}", degree) + } else { + "".to_string() + }; + format!("u{}", exp) } else { - write!(f, "{}", coeffs[i])?; - if i > 0 { - write!(f, "u")?; - } - } - - if i > 1 { - write!(f, "^{}", i)?; + let exp = if degree > 0 { + format!("u{}", if degree > 1 { format!("^{}", degree) } else { "".to_string() }) + } else { + "".to_string() + }; + format!("{}{}", coef, exp) } + }; - first_term = false; - } + let elem_rep = coeffs + .iter() + .enumerate() + .filter_map(|(i, &coef)| { + if coef == Fp::zero() { + None + } else { + Some(format_term(coef, i)) + } + }) + .collect::>() + .join(" + "); - if first_term { + if elem_rep.is_empty() { write!(f, "0")?; // Handle the case where all coefficients are zero + } else { + write!(f, "{}", elem_rep)?; } Ok(()) @@ -281,15 +289,6 @@ mod tests { use rand_core::{OsRng, RngCore}; impl Fp3 { - /// Creates a new Fp3 element - fn new(coeffs: [u64; 3]) -> Self { - Self { - a0: Fp::new(coeffs[0]), - a1: Fp::new(coeffs[1]), - a2: Fp::new(coeffs[2]) - } - } - /// Generates a random canonical element fn random(mut rng: impl RngCore) -> Self { Self { @@ -304,21 +303,8 @@ mod tests { // ================================================================================================ #[test] fn test_debug() { - assert_eq!(format!("{:?}", Fp3::zero()), ""); + assert_eq!(format!("{:?}", Fp3::zero()), "0"); assert_eq!(format!("{:?}", Fp3::one()), "1"); - assert_eq!( - format!("{:?}", Fp3::new([1, 2, 3])), - "1 + 2u + 3u^2" - ); - assert_eq!( - format!("{:?}", Fp3::new([0, 1, 0])), - "u" - ); - assert_eq!(format!("{:?}", Fp3::new([0, 0, 5])), "5u^2"); - - assert_eq!(format!("{:?}", Fp3::new([0, 5, 7])), "5u + 7u^2"); - assert_eq!(format!("{:?}", Fp3::new([1, 1, 1])), "1 + u + u^2") - } // BASIC ALGEBRA // ================================================================================================ diff --git a/src/fp6.rs b/src/fp6.rs index 2581e3f..9c536a6 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -57,34 +57,42 @@ pub struct Fp6 { impl fmt::Debug for Fp6 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let coeffs: [Fp; 6] = self.into(); - let mut first_term = true; - for i in 0..6 { - if coeffs[i] == Fp::zero() { - continue; - } - - if !first_term { - write!(f, " + ")?; - } - if coeffs[i] == Fp::one() && i > 0usize { - write!(f, "u")?; // Display "u" instead of "1u" + let format_term = |coef: Fp, degree: usize| -> String { + if coef == Fp::one() && degree > 0 { + let exp = if degree > 1 { + format!("^{}", degree) + } else { + "".to_string() + }; + format!("u{}", exp) } else { - write!(f, "{}", coeffs[i])?; - if i > 0 { - write!(f, "u")?; - } - } - - if i > 1 { - write!(f, "^{}", i)?; + let exp = if degree > 0 { + format!("u{}", if degree > 1 { format!("^{}", degree) } else { "".to_string() }) + } else { + "".to_string() + }; + format!("{}{}", coef, exp) } + }; - first_term = false; - } + let elem_rep = coeffs + .iter() + .enumerate() + .filter_map(|(i, &coef)| { + if coef == Fp::zero() { + None + } else { + Some(format_term(coef, i)) + } + }) + .collect::>() + .join(" + "); - if first_term { + if elem_rep.is_empty() { write!(f, "0")?; // Handle the case where all coefficients are zero + } else { + write!(f, "{}", elem_rep)?; } Ok(()) @@ -1286,7 +1294,7 @@ mod tests { #[test] fn test_debug() { assert_eq!(format!("{:?}", Fp6::one()), "1"); - assert_eq!(format!("{:?}", Fp6::zero()), ""); + assert_eq!(format!("{:?}", Fp6::zero()), "0"); assert_eq!( format!("{:?}", Fp6::new([1, 2, 3, 4, 5, 6])), "1 + 2u + 3u^2 + 4u^3 + 5u^4 + 6u^5" From 47b79772f3f4c4a407bcc5f6f6b85dca14336054 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 03:57:00 +0530 Subject: [PATCH 07/12] Remove empty lines --- src/fp3.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index 654160e..ef702c6 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -488,6 +488,4 @@ mod tests { TWO_ADIC_ROOT_OF_UNITY_P3.exp_vartime(&[two_pow_32 - 1, 0, 0,]) ); } - - } From 8d3455082e34f5e6bf8b714e4954b782f61cbff2 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 21:47:48 +0530 Subject: [PATCH 08/12] Add Fp3 format tests --- src/fp3.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/fp3.rs b/src/fp3.rs index ef702c6..9fe7ca7 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -305,6 +305,27 @@ mod tests { fn test_debug() { assert_eq!(format!("{:?}", Fp3::zero()), "0"); assert_eq!(format!("{:?}", Fp3::one()), "1"); + + let a = Fp3 { + a0: Fp::new(0), + a1: Fp::new(0), + a2: Fp::new(7) + }; + assert_eq!(format!("{:?}", a), "7u^2"); + + let b = Fp3 { + a0: Fp::new(1), + a1: Fp::new(0), + a2: Fp::new(11) + }; + assert_eq!(format!("{:?}", b), "1 + 11u^2"); + + let c = Fp3 { + a0: Fp::new(1), + a1: Fp::new(2), + a2: Fp::new(1) + }; + assert_eq!(format!("{:?}", c), "1 + 2u + u^2"); } // BASIC ALGEBRA // ================================================================================================ From dface365cc54494b7af0ba47e39dcb7a04608de3 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 22:05:03 +0530 Subject: [PATCH 09/12] refactor: replace is_empty check with is_zero --- src/fp3.rs | 10 +++++----- src/fp6.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index 9fe7ca7..a0e1f7d 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -75,11 +75,11 @@ impl fmt::Debug for Fp3 { .collect::>() .join(" + "); - if elem_rep.is_empty() { - write!(f, "0")?; // Handle the case where all coefficients are zero - } else { - write!(f, "{}", elem_rep)?; - } + if *self == Fp3::zero() { + return write!(f, "0"); // Handle the case where all coefficients are zero + } + + write!(f, "{}", elem_rep)?; Ok(()) } diff --git a/src/fp6.rs b/src/fp6.rs index 9c536a6..1ae4831 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -89,11 +89,11 @@ impl fmt::Debug for Fp6 { .collect::>() .join(" + "); - if elem_rep.is_empty() { - write!(f, "0")?; // Handle the case where all coefficients are zero - } else { - write!(f, "{}", elem_rep)?; + if self.is_zero().into() { + return write!(f, "0"); // Handle the case where all coefficients are zero } + + write!(f, "{}", elem_rep)?; Ok(()) } From 5432fb2c4831747c53fd0cc914424d8db2831e80 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 22:07:23 +0530 Subject: [PATCH 10/12] Ran cargo fmt --- src/fp3.rs | 21 ++++++++++++++------- src/fp6.rs | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index a0e1f7d..ef45657 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -53,8 +53,15 @@ impl fmt::Debug for Fp3 { }; format!("u{}", exp) } else { - let exp = if degree > 0 { - format!("u{}", if degree > 1 { format!("^{}", degree) } else { "".to_string() }) + let exp = if degree > 0 { + format!( + "u{}", + if degree > 1 { + format!("^{}", degree) + } else { + "".to_string() + } + ) } else { "".to_string() }; @@ -77,8 +84,8 @@ impl fmt::Debug for Fp3 { if *self == Fp3::zero() { return write!(f, "0"); // Handle the case where all coefficients are zero - } - + } + write!(f, "{}", elem_rep)?; Ok(()) @@ -309,21 +316,21 @@ mod tests { let a = Fp3 { a0: Fp::new(0), a1: Fp::new(0), - a2: Fp::new(7) + a2: Fp::new(7), }; assert_eq!(format!("{:?}", a), "7u^2"); let b = Fp3 { a0: Fp::new(1), a1: Fp::new(0), - a2: Fp::new(11) + a2: Fp::new(11), }; assert_eq!(format!("{:?}", b), "1 + 11u^2"); let c = Fp3 { a0: Fp::new(1), a1: Fp::new(2), - a2: Fp::new(1) + a2: Fp::new(1), }; assert_eq!(format!("{:?}", c), "1 + 2u + u^2"); } diff --git a/src/fp6.rs b/src/fp6.rs index 1ae4831..aa20b7d 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -67,8 +67,15 @@ impl fmt::Debug for Fp6 { }; format!("u{}", exp) } else { - let exp = if degree > 0 { - format!("u{}", if degree > 1 { format!("^{}", degree) } else { "".to_string() }) + let exp = if degree > 0 { + format!( + "u{}", + if degree > 1 { + format!("^{}", degree) + } else { + "".to_string() + } + ) } else { "".to_string() }; @@ -92,7 +99,7 @@ impl fmt::Debug for Fp6 { if self.is_zero().into() { return write!(f, "0"); // Handle the case where all coefficients are zero } - + write!(f, "{}", elem_rep)?; Ok(()) @@ -1308,7 +1315,10 @@ mod tests { let a = Fp6::one().neg(); assert_eq!(format!("{:?}", a), "18446744069414584320"); - assert_eq!(format!("{:?}", Fp6::new([1, 1, 1, 1, 1, 1])), "1 + u + u^2 + u^3 + u^4 + u^5") + assert_eq!( + format!("{:?}", Fp6::new([1, 1, 1, 1, 1, 1])), + "1 + u + u^2 + u^3 + u^4 + u^5" + ) } #[test] From ba644571edb455fb66916cf6dac8a7e3992365e2 Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 22:15:36 +0530 Subject: [PATCH 11/12] Refactor: early check for zero --- src/fp3.rs | 8 ++++---- src/fp6.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fp3.rs b/src/fp3.rs index ef45657..321f3e4 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -42,6 +42,10 @@ pub(crate) struct Fp3 { impl fmt::Debug for Fp3 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { + if *self == Fp3::zero() { + return write!(f, "0"); // Handle the case where all coefficients are zero + } + let coeffs = [self.a0, self.a1, self.a2]; let format_term = |coef: Fp, degree: usize| -> String { @@ -82,10 +86,6 @@ impl fmt::Debug for Fp3 { .collect::>() .join(" + "); - if *self == Fp3::zero() { - return write!(f, "0"); // Handle the case where all coefficients are zero - } - write!(f, "{}", elem_rep)?; Ok(()) diff --git a/src/fp6.rs b/src/fp6.rs index aa20b7d..30a4012 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -56,6 +56,10 @@ pub struct Fp6 { impl fmt::Debug for Fp6 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { + if self.is_zero().into() { + return write!(f, "0"); // Handle the case where all coefficients are zero + } + let coeffs: [Fp; 6] = self.into(); let format_term = |coef: Fp, degree: usize| -> String { @@ -96,10 +100,6 @@ impl fmt::Debug for Fp6 { .collect::>() .join(" + "); - if self.is_zero().into() { - return write!(f, "0"); // Handle the case where all coefficients are zero - } - write!(f, "{}", elem_rep)?; Ok(()) From 07bb816ef8a7834af35317a29f4f9ad0fbbad1ed Mon Sep 17 00:00:00 2001 From: RajeshRk18 Date: Fri, 22 Sep 2023 22:53:01 +0530 Subject: [PATCH 12/12] Fix: wasm build check --- src/fp3.rs | 7 +++++++ src/fp6.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/fp3.rs b/src/fp3.rs index 321f3e4..d00b9b5 100644 --- a/src/fp3.rs +++ b/src/fp3.rs @@ -12,6 +12,13 @@ use core::fmt::{self, Formatter}; +#[cfg(not(feature = "std"))] +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; + use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use crate::fp::reduce_u96; diff --git a/src/fp6.rs b/src/fp6.rs index 30a4012..471aa68 100644 --- a/src/fp6.rs +++ b/src/fp6.rs @@ -17,6 +17,13 @@ use core::{ ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; +#[cfg(not(feature = "std"))] +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; + use group::ff::Field; use rand_core::RngCore; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};