Add test_low_degree for other gates

This commit is contained in:
Daniel Lubarov 2021-05-20 05:27:56 -07:00
parent 229784e574
commit 747974558f
8 changed files with 65 additions and 19 deletions

View File

@ -142,13 +142,14 @@ impl<F: Field> SimpleGenerator<F> for ArithmeticGenerator<F> {
}
}
// #[cfg(test)]
// mod tests {
// use crate::{test_gate_low_degree, ArithmeticGate, Tweedledum};
//
// test_gate_low_degree!(
// low_degree_ArithmeticGate,
// Tweedledum,
// ArithmeticGate<Tweedledum>
// );
// }
#[cfg(test)]
mod tests {
use crate::field::crandall_field::CrandallField;
use crate::gates::arithmetic::ArithmeticGate;
use crate::gates::gate_testing::test_low_degree;
#[test]
fn low_degree() {
test_low_degree(ArithmeticGate::new::<CrandallField>())
}
}

View File

@ -89,3 +89,15 @@ impl<F: Field> SimpleGenerator<F> for ConstantGenerator<F> {
PartialWitness::singleton_target(Target::Wire(wire), self.constant)
}
}
#[cfg(test)]
mod tests {
use crate::field::crandall_field::CrandallField;
use crate::gates::constant::ConstantGate;
use crate::gates::gate_testing::test_low_degree;
#[test]
fn low_degree() {
test_low_degree(ConstantGate::get::<CrandallField>())
}
}

View File

@ -1,5 +1,5 @@
use crate::field::field::Field;
use crate::gates::gate::Gate;
use crate::gates::gate::{Gate, GateRef};
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
use crate::util::{log2_ceil, transpose};
use crate::vars::EvaluationVars;
@ -9,7 +9,8 @@ const WITNESS_DEGREE: usize = WITNESS_SIZE - 1;
/// Tests that the constraints imposed by the given gate are low-degree by applying them to random
/// low-degree witness polynomials.
pub(crate) fn test_low_degree<F: Field, G: Gate<F>>(gate: G) {
pub(crate) fn test_low_degree<F: Field>(gate: GateRef<F>) {
let gate = gate.0;
let rate_bits = log2_ceil(gate.degree() + 1);
let wire_ldes = random_low_degree_matrix(gate.num_wires(), rate_bits);

View File

@ -349,6 +349,7 @@ mod tests {
use crate::gmimc::gmimc_permute_naive;
use crate::wire::Wire;
use crate::witness::PartialWitness;
use crate::gates::gate_testing::test_low_degree;
#[test]
fn generated_output() {
@ -411,4 +412,14 @@ mod tests {
});
assert_eq!(acc_new, F::from_canonical_usize(7 * 2));
}
#[test]
fn low_degree() {
type F = CrandallField;
const R: usize = 101;
let constants = Arc::new([F::TWO; R]);
type Gate = GMiMCGate<F, R>;
let gate = Gate::with_constants(constants);
test_low_degree(gate)
}
}

View File

@ -1,3 +1,5 @@
use std::marker::PhantomData;
use crate::circuit_builder::CircuitBuilder;
use crate::field::field::Field;
use crate::gates::gate::{Gate, GateRef};
@ -6,7 +8,6 @@ use crate::target::Target;
use crate::vars::{EvaluationTargets, EvaluationVars};
use crate::wire::Wire;
use crate::witness::PartialWitness;
use std::marker::PhantomData;
/// Performs some arithmetic involved in the evaluation of GMiMC's constraint polynomials for one
/// round. In particular, this performs the following computations:
@ -224,3 +225,15 @@ impl<F: Field> SimpleGenerator<F> for GMiMCEvalGenerator<F> {
witness
}
}
#[cfg(test)]
mod tests {
use crate::field::crandall_field::CrandallField;
use crate::gates::gate_testing::test_low_degree;
use crate::gates::gmimc_eval::GMiMCEvalGate;
#[test]
fn low_degree() {
test_low_degree(GMiMCEvalGate::<CrandallField>::get())
}
}

View File

@ -266,10 +266,7 @@ mod tests {
#[test]
fn low_degree() {
type F = CrandallField;
let gate = InterpolationGate::<F, 4> {
num_points: 4,
_phantom: PhantomData,
};
test_low_degree(gate);
test_low_degree(InterpolationGate::<F, 2>::new(4));
test_low_degree(InterpolationGate::<F, 4>::new(4));
}
}

View File

@ -1,6 +1,5 @@
pub(crate) mod arithmetic;
pub mod constant;
pub(crate) mod fri_consistency_gate;
pub(crate) mod gate;
pub mod gmimc;
pub(crate) mod gmimc_eval;

View File

@ -55,3 +55,15 @@ impl<F: Field> Gate<F> for NoopGate {
0
}
}
#[cfg(test)]
mod tests {
use crate::field::crandall_field::CrandallField;
use crate::gates::gate_testing::test_low_degree;
use crate::gates::noop::NoopGate;
#[test]
fn low_degree() {
test_low_degree(NoopGate::get::<CrandallField>())
}
}