mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Working test
This commit is contained in:
parent
5678c7ebda
commit
d727f84a56
@ -38,7 +38,7 @@ impl<F: OEF<D>, const D: usize> Display for ExtensionAlgebra<F, D> {
|
||||
for i in 1..D - 1 {
|
||||
write!(f, "({})*b^{} + ", self.0[i], i)?;
|
||||
}
|
||||
write!(f, "{}*b^{}", self.0[D - 1], D - 1)
|
||||
write!(f, "({})*b^{}", self.0[D - 1], D - 1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ impl<F: OEF<D>, const D: usize> Mul for ExtensionAlgebra<F, D> {
|
||||
res[(i + j) % D] += if i + j < D {
|
||||
self.0[i] * rhs.0[j]
|
||||
} else {
|
||||
w * self.0[i] * rhs.0[i]
|
||||
w * self.0[i] * rhs.0[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,9 +282,14 @@ mod tests {
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::extension_field::FieldExtension;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::Gate;
|
||||
use crate::gates::gate_testing::test_low_degree;
|
||||
use crate::gates::interpolation::InterpolationGate;
|
||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||
use crate::vars::EvaluationVars;
|
||||
|
||||
#[test]
|
||||
fn wire_indices() {
|
||||
@ -311,4 +316,67 @@ mod tests {
|
||||
type F = CrandallField;
|
||||
test_low_degree(InterpolationGate::<F, 4>::new(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gate_constraint() {
|
||||
type F = CrandallField;
|
||||
type FF = QuarticCrandallField;
|
||||
const D: usize = 4;
|
||||
|
||||
/// Returns the local wires for an interpolation gate for given coeffs, points and eval point.
|
||||
fn get_wires(
|
||||
num_points: usize,
|
||||
coeffs: PolynomialCoeffs<FF>,
|
||||
points: Vec<F>,
|
||||
eval_point: FF,
|
||||
) -> Vec<FF> {
|
||||
let mut v = vec![F::ZERO; num_points * 5 + (coeffs.len() + 3) * D];
|
||||
for j in 0..num_points {
|
||||
v[j] = points[j];
|
||||
}
|
||||
for j in 0..num_points {
|
||||
for i in 0..D {
|
||||
v[num_points + D * j + i] = <FF as FieldExtension<D>>::to_basefield_array(
|
||||
&coeffs.eval(points[j].into()),
|
||||
)[i];
|
||||
}
|
||||
}
|
||||
for i in 0..D {
|
||||
v[num_points * 5 + i] =
|
||||
<FF as FieldExtension<D>>::to_basefield_array(&eval_point)[i];
|
||||
}
|
||||
for i in 0..D {
|
||||
v[num_points * 5 + D + i] =
|
||||
<FF as FieldExtension<D>>::to_basefield_array(&coeffs.eval(eval_point))[i];
|
||||
}
|
||||
for i in 0..coeffs.len() {
|
||||
for (j, input) in
|
||||
(0..D).zip(num_points * 5 + (2 + i) * D..num_points * 5 + (3 + i) * D)
|
||||
{
|
||||
v[input] = <FF as FieldExtension<D>>::to_basefield_array(&coeffs.coeffs[i])[j];
|
||||
}
|
||||
}
|
||||
v.iter().map(|&x| x.into()).collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
/// Get a working row for InterpolationGate.
|
||||
let coeffs = PolynomialCoeffs::new(vec![FF::rand(), FF::rand()]);
|
||||
let points = vec![F::rand(), F::rand()];
|
||||
let eval_point = FF::rand();
|
||||
let gate = InterpolationGate::<F, D> {
|
||||
num_points: 2,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let vars = EvaluationVars {
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(2, coeffs, points, eval_point),
|
||||
};
|
||||
|
||||
assert!(
|
||||
gate.eval_unfiltered(vars.clone())
|
||||
.iter()
|
||||
.all(|x| x.is_zero()),
|
||||
"Gate constraints are not satisfied."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user