Skip to main content

sp1_hypercube/prover/zerocheck/
fix_last_variable.rs

1use std::ops::{Add, Mul};
2
3use slop_algebra::{ExtensionField, Field};
4
5use super::ZeroCheckPoly;
6
7/// This function will set the last variable to `alpha`.
8pub fn zerocheck_fix_last_variable<
9    K: Field,
10    F: Field,
11    EF: ExtensionField<F> + Add<K, Output = EF> + Mul<K, Output = EF> + From<K> + ExtensionField<K>,
12    A,
13>(
14    poly: ZeroCheckPoly<K, F, EF, A>,
15    alpha: EF,
16) -> ZeroCheckPoly<EF, F, EF, A> {
17    let preprocessed_columns =
18        poly.preprocessed_columns.as_ref().map(|mle| mle.fix_last_variable(alpha));
19    let main_columns = poly.main_columns.fix_last_variable(alpha);
20
21    if poly.main_columns.num_real_entries() == 0 {
22        // If the chip is pure padding, it's contribution to sumcheck is just zero, we don't need
23        // to propagate any eq_adjustment or any other data relevant to the sumcheck.
24        return ZeroCheckPoly::new(
25            poly.air_data,
26            poly.zeta,
27            preprocessed_columns,
28            main_columns,
29            poly.eq_adjustment,
30            poly.geq_value,
31            poly.padded_row_adjustment,
32            poly.virtual_geq.fix_last_variable(alpha),
33        );
34    }
35
36    let (rest, last) = poly.zeta.split_at(poly.zeta.dimension() - 1);
37    let last = *last[0];
38
39    // When we are fixing the last variable, we can factor out one of the eq_terms, as it will be a
40    // constant. That constant is equal to (alpha * last) + (1 - alpha) * (1 - last).
41    let eq_adjustment =
42        poly.eq_adjustment * ((alpha * last) + (EF::one() - alpha) * (EF::one() - last));
43
44    let has_non_padded_vars = poly.main_columns.num_real_entries() > 1;
45
46    let geq_value = if has_non_padded_vars {
47        EF::zero()
48    } else {
49        (EF::one() - poly.geq_value) * alpha + poly.geq_value
50    };
51
52    ZeroCheckPoly::new(
53        poly.air_data,
54        rest,
55        preprocessed_columns,
56        main_columns,
57        eq_adjustment,
58        geq_value,
59        poly.padded_row_adjustment,
60        poly.virtual_geq.fix_last_variable(alpha),
61    )
62}