Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/sumcheck/product_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! over remaining variables. For quadratic sumcheck, `h(X)` is degree-2.

use p3_challenger::{FieldChallenger, GrindingChallenger};
use p3_field::{ExtensionField, Field, PackedFieldExtension, PackedValue, dot_product};
use p3_field::{ExtensionField, PackedFieldExtension, PackedValue, TwoAdicField, dot_product};
use p3_util::log2_strict_usize;
use tracing::instrument;

Expand Down Expand Up @@ -71,7 +71,7 @@ use crate::{
/// This occurs after sufficient rounds of folding reduce the polynomial size below the
/// SIMD efficiency threshold.
#[derive(Debug, Clone)]
pub(crate) enum ProductPolynomial<F: Field, EF: ExtensionField<F>> {
pub(crate) enum ProductPolynomial<F: TwoAdicField, EF: ExtensionField<F>> {
/// SIMD-packed representation for large polynomials.
///
/// Each element in `evals` and `weights` is an `EF::ExtensionPacking`, which holds
Expand Down Expand Up @@ -109,7 +109,7 @@ pub(crate) enum ProductPolynomial<F: Field, EF: ExtensionField<F>> {
},
}

impl<F: Field, EF: ExtensionField<F>> ProductPolynomial<F, EF> {
impl<F: TwoAdicField, EF: ExtensionField<F>> ProductPolynomial<F, EF> {
/// Creates a new [`ProductPolynomial`] from extension field evaluations.
///
/// Automatically selects the optimal representation (packed or scalar) based on
Expand Down Expand Up @@ -464,7 +464,7 @@ impl<F: Field, EF: ExtensionField<F>> ProductPolynomial<F, EF> {
///
/// * `sum` - Running sum to update with new constraint contributions.
/// * `constraint` - The constraint to combine into weights.
pub(crate) fn combine(&mut self, sum: &mut EF, constraint: &Constraint<F, EF>) {
pub(crate) fn combine(&mut self, sum: &mut EF, constraint: &Constraint<EF>) {
match self {
Self::Packed { weights, .. } => {
constraint.combine_packed(weights, sum);
Expand Down
14 changes: 7 additions & 7 deletions src/sumcheck/sumcheck_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
///
/// The sumcheck protocol ensures that the claimed sum is correct.
#[derive(Debug, Clone)]
pub struct SumcheckSingle<F: Field, EF: ExtensionField<F>> {
pub struct SumcheckSingle<F: TwoAdicField, EF: ExtensionField<F>> {
/// Paired evaluation and weight polynomials for the quadratic sumcheck.
///
/// This holds both `f(x)` (the polynomial being sumchecked) and `w(x)` (the constraint
Expand All @@ -54,7 +54,7 @@ pub struct SumcheckSingle<F: Field, EF: ExtensionField<F>> {

impl<F, EF> SumcheckSingle<F, EF>
where
F: Field + Ord,
F: TwoAdicField + Ord,
EF: ExtensionField<F>,
{
/// Constructs a new `SumcheckSingle` instance from evaluations in the extension field.
Expand Down Expand Up @@ -110,7 +110,7 @@ where
challenger: &mut Challenger,
folding_factor: usize,
pow_bits: usize,
constraint: &Constraint<F, EF>,
constraint: &Constraint<EF>,
) -> (Self, MultilinearPoint<EF>)
where
F: TwoAdicField,
Expand Down Expand Up @@ -157,7 +157,7 @@ where
folding_factor: usize,
pow_bits: usize,
k_skip: usize,
constraint: &Constraint<F, EF>,
constraint: &Constraint<EF>,
) -> (Self, MultilinearPoint<EF>)
where
F: TwoAdicField,
Expand Down Expand Up @@ -291,7 +291,7 @@ where
challenger: &mut Challenger,
folding_factor: usize,
pow_bits: usize,
constraint: Option<Constraint<F, EF>>,
constraint: Option<Constraint<EF>>,
) -> MultilinearPoint<EF>
where
F: TwoAdicField,
Expand Down Expand Up @@ -337,11 +337,11 @@ where
/// * The verifier's challenge `r` as an `EF` element.
/// * [`ProductPolynomial`] with new compressed polynomial evaluations and weights in the extension field.
/// * Updated sum.
fn initial_round<F: Field, EF: ExtensionField<F>, Challenger>(
fn initial_round<F: TwoAdicField, EF: ExtensionField<F>, Challenger>(
evals: &EvaluationsList<F>,
sumcheck_data: &mut SumcheckData<EF, F>,
challenger: &mut Challenger,
constraint: &Constraint<F, EF>,
constraint: &Constraint<EF>,
pow_bits: usize,
) -> (ProductPolynomial<F, EF>, EF, EF)
where
Expand Down
6 changes: 3 additions & 3 deletions src/sumcheck/sumcheck_single_svo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::{vec, vec::Vec};

use p3_challenger::{FieldChallenger, GrindingChallenger};
use p3_field::{ExtensionField, Field, TwoAdicField};
use p3_field::{ExtensionField, TwoAdicField};

use crate::{
poly::{evals::EvaluationsList, multilinear::MultilinearPoint},
Expand All @@ -21,7 +21,7 @@ pub(crate) const NUM_SVO_ROUNDS: usize = 3;

impl<F, EF> SumcheckSingle<F, EF>
where
F: Field + Ord,
F: TwoAdicField + Ord,
EF: ExtensionField<F>,
{
/// Compute a Sumcheck using the Small Value Optimization (SVO) for the first three rounds and
Expand All @@ -33,7 +33,7 @@ where
challenger: &mut Challenger,
folding_factor: usize,
pow_bits: usize,
constraint: &Constraint<F, EF>,
constraint: &Constraint<EF>,
) -> (Self, MultilinearPoint<EF>)
where
F: TwoAdicField,
Expand Down
32 changes: 15 additions & 17 deletions src/sumcheck/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
constraints::{
Constraint,
evaluator::ConstraintPolyEvaluator,
statement::{EqStatement, SelectStatement},
statement::{DomainStatement, EqStatement},
},
parameters::InitialPhaseConfig,
proof::{InitialPhase, SumcheckData, WhirProof},
Expand Down Expand Up @@ -76,7 +76,7 @@ fn make_constraint<Challenger>(
num_eqs: usize,
num_sels: usize,
poly: &EvaluationsList<F>,
) -> Constraint<F, EF>
) -> Constraint<EF>
where
Challenger: FieldChallenger<F> + GrindingChallenger<Witness = F>,
{
Expand All @@ -85,7 +85,7 @@ where

// Create a new empty eq and select statements of that arity
let mut eq_statement = EqStatement::initialize(num_vars);
let mut sel_statement = SelectStatement::initialize(num_vars);
let mut sel_statement = DomainStatement::initialize(num_vars, num_vars);

// - Sample `num_eqs` univariate challenge points.
// - Evaluate the sumcheck polynomial on them.
Expand Down Expand Up @@ -130,7 +130,7 @@ where
challenger.observe_algebra_element(eval);

// Add the evaluation constraint: poly(point) == eval.
sel_statement.add_constraint(var, eval);
sel_statement.add_constraint(index, eval);
});

// Return the constructed constraint with the alpha used for linear combination.
Expand All @@ -146,7 +146,7 @@ fn make_constraint_ext<Challenger>(
num_eqs: usize,
num_sels: usize,
poly: &EvaluationsList<EF>,
) -> Constraint<F, EF>
) -> Constraint<EF>
where
Challenger: FieldChallenger<F> + GrindingChallenger<Witness = F>,
{
Expand All @@ -155,7 +155,7 @@ where

// Create a new empty eq and select statements of that arity
let mut eq_statement = EqStatement::initialize(num_vars);
let mut sel_statement = SelectStatement::initialize(num_vars);
let mut sel_statement = DomainStatement::initialize(num_vars, num_vars);

// - Sample `num_eqs` univariate challenge points.
// - Evaluate the sumcheck polynomial on them.
Expand Down Expand Up @@ -201,7 +201,7 @@ where
challenger.observe_algebra_element(eval);

// Add the evaluation constraint: poly(point) == eval.
sel_statement.add_constraint(var, eval);
sel_statement.add_constraint(index, eval);
});

// Return the constructed constraint with the alpha used for linear combination.
Expand All @@ -216,7 +216,7 @@ fn read_constraint<Challenger>(
num_vars: usize,
num_eqs: usize,
num_sels: usize,
) -> Constraint<F, EF>
) -> Constraint<EF>
where
Challenger: FieldChallenger<F> + GrindingChallenger<Witness = F>,
{
Expand All @@ -237,16 +237,12 @@ where
}

// Create a new statement that will hold all reconstructed constraints.
let mut sel_statement = SelectStatement::<F, EF>::initialize(num_vars);

// To simulate stir point derivation derive domain generator
let omega = F::two_adic_generator(num_vars);
let mut sel_statement = DomainStatement::initialize(num_vars, num_vars);

// For each point, sample a challenge and read its corresponding evaluation from the proof.
for i in 0..num_sels {
// Simulate stir point derivation
let index: usize = challenger.sample_bits(num_vars);
let var = omega.exp_u64(index as u64);

// Read the committed evaluation corresponding to this point from constraint_evals.
// Sel evaluations are stored after eq evaluations.
Expand All @@ -256,7 +252,7 @@ where
challenger.observe_algebra_element(eval);

// Add the constraint: poly(point) == eval.
sel_statement.add_constraint(var, eval);
sel_statement.add_constraint(index, eval);
}

Constraint::new(
Expand Down Expand Up @@ -510,7 +506,8 @@ fn run_sumcheck_test(
//
// No skip optimization, so the first round is treated as a standard sumcheck round.
let evaluator = ConstraintPolyEvaluator::new(num_vars, folding_factor, None);
let weights = evaluator.eval_constraints_poly(&constraints, &verifier_randomness.reversed());
let weights =
evaluator.eval_constraints_poly::<F, _>(&constraints, &verifier_randomness.reversed());

// CHECK SUM == f(r) * weights(z, r)
assert_eq!(sum, final_folded_value * weights);
Expand Down Expand Up @@ -777,7 +774,7 @@ fn run_sumcheck_test_skips(
//
// Evaluate eq(z, r) using the unified constraint evaluation function.
let evaluator = ConstraintPolyEvaluator::new(num_vars, folding_factor, Some(K_SKIP_SUMCHECK));
let weights = evaluator.eval_constraints_poly(&constraints, &verifier_randomness);
let weights = evaluator.eval_constraints_poly::<F, _>(&constraints, &verifier_randomness);

// FINAL SUMCHECK CHECK
//
Expand Down Expand Up @@ -1006,7 +1003,8 @@ fn run_sumcheck_test_svo(
//
// No skip optimization, so the first round is treated as a standard sumcheck round.
let evaluator = ConstraintPolyEvaluator::new(num_vars, folding_factor, None);
let weights = evaluator.eval_constraints_poly(&constraints, &verifier_randomness.reversed());
let weights =
evaluator.eval_constraints_poly::<F, _>(&constraints, &verifier_randomness.reversed());

// CHECK SUM == f(r) * weights(z, r)
assert_eq!(sum, final_folded_value * weights);
Expand Down
Loading