From 4f6f2192ab67d9770894517b2e00d891afb64fb9 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Tue, 18 May 2021 16:23:44 +0200 Subject: [PATCH] Minor fixes --- src/field/extension_field/quadratic.rs | 5 +- src/field/extension_field/quartic.rs | 7 +- src/fri/mod.rs | 14 ++-- src/plonk_challenger.rs | 14 ++-- src/polynomial/commitment.rs | 97 ++++++++------------------ 5 files changed, 42 insertions(+), 95 deletions(-) diff --git a/src/field/extension_field/quadratic.rs b/src/field/extension_field/quadratic.rs index a9a9e5b1..acc66def 100644 --- a/src/field/extension_field/quadratic.rs +++ b/src/field/extension_field/quadratic.rs @@ -111,10 +111,7 @@ impl Field for QuadraticCrandallField { // otherwise the FFT doesn't commute with field inclusion. fn primitive_root_of_unity(n_log: usize) -> Self { if n_log <= CrandallField::TWO_ADICITY { - Self([ - CrandallField::primitive_root_of_unity(n_log), - CrandallField::ZERO, - ]) + CrandallField::primitive_root_of_unity(n_log).into() } else { // The root of unity isn't in the base field so we need to compute it manually. assert!(n_log <= Self::TWO_ADICITY); diff --git a/src/field/extension_field/quartic.rs b/src/field/extension_field/quartic.rs index d72fbeb8..49235a06 100644 --- a/src/field/extension_field/quartic.rs +++ b/src/field/extension_field/quartic.rs @@ -149,12 +149,7 @@ impl Field for QuarticCrandallField { // otherwise the FFT doesn't commute with field inclusion. fn primitive_root_of_unity(n_log: usize) -> Self { if n_log <= CrandallField::TWO_ADICITY { - Self([ - CrandallField::primitive_root_of_unity(n_log), - CrandallField::ZERO, - CrandallField::ZERO, - CrandallField::ZERO, - ]) + CrandallField::primitive_root_of_unity(n_log).into() } else { // The root of unity isn't in the base field so we need to compute it manually. assert!(n_log <= Self::TWO_ADICITY); diff --git a/src/fri/mod.rs b/src/fri/mod.rs index 480980ca..d701c421 100644 --- a/src/fri/mod.rs +++ b/src/fri/mod.rs @@ -96,7 +96,7 @@ mod tests { coset_lde .values .into_iter() - .map(|x| F::Extension::from(x)) + .map(F::Extension::from) .collect(), ); let root = tree.root; @@ -155,34 +155,28 @@ mod tests { mod base { use super::*; - type F = CrandallField; - const D: usize = 1; #[test] fn test_fri_multi_params() -> Result<()> { - check_fri_multi_params::() + check_fri_multi_params::() } } mod quadratic { use super::*; - type F = CrandallField; - const D: usize = 2; #[test] fn test_fri_multi_params() -> Result<()> { - check_fri_multi_params::() + check_fri_multi_params::() } } mod quartic { use super::*; - type F = CrandallField; - const D: usize = 4; #[test] fn test_fri_multi_params() -> Result<()> { - check_fri_multi_params::() + check_fri_multi_params::() } } } diff --git a/src/plonk_challenger.rs b/src/plonk_challenger.rs index 98b4a3d2..67957e13 100644 --- a/src/plonk_challenger.rs +++ b/src/plonk_challenger.rs @@ -95,13 +95,6 @@ impl Challenger { (0..n).map(|_| self.get_challenge()).collect() } - pub fn get_n_extension_challenges(&mut self, n: usize) -> Vec - where - F: Extendable, - { - (0..n).map(|_| self.get_extension_challenge()).collect() - } - pub fn get_hash(&mut self) -> Hash { Hash { elements: [ @@ -122,6 +115,13 @@ impl Challenger { F::Extension::from_basefield_array(arr) } + pub fn get_n_extension_challenges(&mut self, n: usize) -> Vec + where + F: Extendable, + { + (0..n).map(|_| self.get_extension_challenge()).collect() + } + /// Absorb any buffered inputs. After calling this, the input buffer will be empty. fn absorb_buffered_inputs(&mut self) { if self.input_buffer.is_empty() { diff --git a/src/polynomial/commitment.rs b/src/polynomial/commitment.rs index 48b63eff..7fc5b96c 100644 --- a/src/polynomial/commitment.rs +++ b/src/polynomial/commitment.rs @@ -511,81 +511,42 @@ mod tests { ) } + macro_rules! tests_commitments { + ($F:ty, $D:expr) => { + use super::*; + + #[test] + fn test_polynomial_commitment() -> Result<()> { + check_polynomial_commitment::<$F, $D>() + } + + #[test] + fn test_polynomial_commitment_blinding() -> Result<()> { + check_polynomial_commitment_blinding::<$F, $D>() + } + + #[test] + fn test_batch_polynomial_commitment() -> Result<()> { + check_batch_polynomial_commitment::<$F, $D>() + } + + #[test] + fn test_batch_polynomial_commitment_blinding() -> Result<()> { + check_batch_polynomial_commitment_blinding::<$F, $D>() + } + }; + } + mod base { - use super::*; - type F = CrandallField; - const D: usize = 1; - - #[test] - fn test_polynomial_commitment() -> Result<()> { - check_polynomial_commitment::() - } - - #[test] - fn test_polynomial_commitment_blinding() -> Result<()> { - check_polynomial_commitment_blinding::() - } - - #[test] - fn test_batch_polynomial_commitment() -> Result<()> { - check_batch_polynomial_commitment::() - } - - #[test] - fn test_batch_polynomial_commitment_blinding() -> Result<()> { - check_batch_polynomial_commitment_blinding::() - } + tests_commitments!(crate::field::crandall_field::CrandallField, 1); } mod quadratic { - use super::*; - type F = CrandallField; - const D: usize = 2; - - #[test] - fn test_polynomial_commitment() -> Result<()> { - check_polynomial_commitment::() - } - - #[test] - fn test_polynomial_commitment_blinding() -> Result<()> { - check_polynomial_commitment_blinding::() - } - - #[test] - fn test_batch_polynomial_commitment() -> Result<()> { - check_batch_polynomial_commitment::() - } - - #[test] - fn test_batch_polynomial_commitment_blinding() -> Result<()> { - check_batch_polynomial_commitment_blinding::() - } + tests_commitments!(crate::field::crandall_field::CrandallField, 2); } mod quartic { use super::*; - type F = CrandallField; - const D: usize = 4; - - #[test] - fn test_polynomial_commitment() -> Result<()> { - check_polynomial_commitment::() - } - - #[test] - fn test_polynomial_commitment_blinding() -> Result<()> { - check_polynomial_commitment_blinding::() - } - - #[test] - fn test_batch_polynomial_commitment() -> Result<()> { - check_batch_polynomial_commitment::() - } - - #[test] - fn test_batch_polynomial_commitment_blinding() -> Result<()> { - check_batch_polynomial_commitment_blinding::() - } + tests_commitments!(crate::field::crandall_field::CrandallField, 4); } }