Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kimchi/Expr: combining expressions does not increase the degree #2708

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions kimchi/tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use ark_poly::{domain::EvaluationDomain, univariate::DensePolynomial};
use kimchi::{
circuits::{
berkeley_columns::{
index, witness_curr, BerkeleyChallengeTerm, BerkeleyChallenges, Environment, E,
index, witness, witness_curr, BerkeleyChallengeTerm, BerkeleyChallenges, Environment, E,
},
constraints::ConstraintSystem,
domains::EvaluationDomains,
expr::{constraints::ExprOps, *},
gate::{CircuitGate, GateType},
gate::{CircuitGate, CurrOrNext, GateType},
polynomials::generic::GenericGateSpec,
wires::{Wire, COLUMNS},
},
Expand Down Expand Up @@ -158,3 +158,34 @@ fn test_arithmetic_ops() {
);
assert_eq!(test_4::<Fp, Fp>(Fp::from(5u64)), Fp::from(160u64));
}

#[test]
fn test_combining_constraints_does_not_increase_degree() {
// Combining two constraints of degree 2 gives a degree 2 combined
// constraint.
// In other words, using the challenge `alpha` doesn't increase the degree.
// Testing with Berkeley configuration

let mut expr1: E<Fp> = E::zero();
// (X0 + X1) * X2
expr1 += witness(0, CurrOrNext::Curr);
expr1 += witness(1, CurrOrNext::Curr);
expr1 *= witness(2, CurrOrNext::Curr);
assert_eq!(expr1.degree(1, 0), 2);

// (X2 + X0) * X1
let mut expr2: E<Fp> = E::zero();
expr2 += witness(2, CurrOrNext::Curr);
expr2 += witness(0, CurrOrNext::Curr);
expr2 *= witness(1, CurrOrNext::Curr);
assert_eq!(expr2.degree(1, 0), 2);

let combined_expr = Expr::combine_constraints(0..2, vec![expr1.clone(), expr2.clone()]);
assert_eq!(combined_expr.degree(1, 0), 2);

expr2 *= witness(3, CurrOrNext::Curr);
assert_eq!(expr2.degree(1, 0), 3);

let combined_expr = Expr::combine_constraints(0..2, vec![expr1.clone(), expr2.clone()]);
assert_eq!(combined_expr.degree(1, 0), 3);
}