Skip to content

Commit

Permalink
fix: post merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Aug 30, 2024
1 parent 8bad002 commit 7e50a6e
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 77 deletions.
37 changes: 36 additions & 1 deletion air/src/air/logup_gkr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@ pub trait LogUpGkrEvaluator: Clone + Sync {
E::ZERO
}

/// Generates the data needed for running the univariate IOP for multi-linear evaluation of [1].
///
/// This mainly generates the batching randomness used to batch a number of multi-linear
/// evaluation claims and includes some additional data that is needed for building/verifying
/// the univariate IOP for multi-linear evaluation of [1].
///
/// This is the $\lambda$ randomness in section 5.2 in [1] but using different random values for
/// each term instead of powers of a single random element.
///
/// [1]: https://eprint.iacr.org/2023/1284
fn generate_univariate_iop_for_multi_linear_opening_data<E, H>(
&self,
openings: Vec<E>,
eval_point: Vec<E>,
public_coin: &mut impl RandomCoin<Hasher = H, BaseField = E::BaseField>,
) -> GkrData<E>
where
E: FieldElement<BaseField = Self::BaseField>,
H: ElementHasher<BaseField = E::BaseField>,
{
public_coin.reseed(H::hash_elements(&openings));

let mut batching_randomness = Vec::with_capacity(openings.len() - 1);
for _ in 0..openings.len() - 1 {
batching_randomness.push(public_coin.draw().expect("failed to generate randomness"))
}

GkrData::new(
LagrangeKernelRandElements::new(eval_point),
batching_randomness,
openings,
self.get_oracles().to_vec(),
)
}

/// Returns the periodic values used in the LogUp-GKR statement, either as base field element
/// during circuit evaluation or as extension field element during the run of sum-check for
/// the input layer.
Expand Down Expand Up @@ -196,7 +231,7 @@ pub enum LogUpGkrOracle<B: StarkField> {
/// with the given periodic values. Due to the periodic nature of the values, storing, binding of
/// an argument and evaluating the said multi-linear extension can be all done linearly in the size
/// of the smallest cycle defining the periodic values. Hence we only store the values of this
/// smallest cycle. The cycle is assumed throughout to be a power of 2.
/// smallest cycle. The cycle is assumed throughout to be a power of 2.
#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Eq, Ord)]
pub struct PeriodicTable<E: FieldElement> {
pub table: Vec<Vec<E>>,
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use lagrange::{
};

mod logup_gkr;
pub use logup_gkr::{DummyLogUpGkrEval, LogUpGkrEvaluator, LogUpGkrOracle, PeriodicTable};
pub use logup_gkr::{LogUpGkrEvaluator, LogUpGkrOracle, PeriodicTable};

mod coefficients;
pub use coefficients::{
Expand Down
18 changes: 1 addition & 17 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,7 @@ pub trait Prover {
where
E: FieldElement<BaseField = Self::BaseField>,
{
let mut aux_trace = self.build_aux_trace(main_trace, aux_rand_elements);

if let Some(lagrange_randomness) = aux_rand_elements.lagrange() {
let evaluator = air.get_logup_gkr_evaluator::<E>();
let lagrange_col = build_lagrange_column(lagrange_randomness);
let s_col = build_s_column(
main_trace,
aux_rand_elements.gkr_data().expect("should not be empty"),
&evaluator,
&lagrange_col,
);

aux_trace.merge_column(s_col);
aux_trace.merge_column(lagrange_col);
}

aux_trace
unimplemented!("`Prover::build_aux_trace` needs to be implemented when the trace has an auxiliary segment.")
}

/// Returns a STARK proof attesting to a correct execution of a computation defined by the
Expand Down
3 changes: 1 addition & 2 deletions prover/src/logup_gkr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ impl<E: FieldElement> EvaluatedCircuit<E> {
log_up_randomness: &[E],
) -> CircuitLayer<E> {
let num_fractions = evaluator.get_num_fractions();
let periodic_values =
evaluator.build_periodic_values::<E::BaseField, E>();
let periodic_values = evaluator.build_periodic_values::<E::BaseField, E>();
let mut input_layer_wires =
Vec::with_capacity(main_trace.main_segment().num_rows() * num_fractions);
let mut main_frame = EvaluationFrame::new(main_trace.main_segment().num_cols());
Expand Down
4 changes: 2 additions & 2 deletions prover/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use alloc::vec::Vec;

use air::{
Air, AirContext, Assertion, DummyLogUpGkrEval, EvaluationFrame, FieldExtension, ProofOptions,
TraceInfo, TransitionConstraintDegree,
Air, AirContext, Assertion, EvaluationFrame, FieldExtension, ProofOptions, TraceInfo,
TransitionConstraintDegree,
};
use math::{fields::f64::BaseElement, FieldElement, StarkField};

Expand Down
10 changes: 8 additions & 2 deletions sumcheck/benches/sum_check_high_degree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn setup_sum_check<E: FieldElement>(
MultiLinearPoly<E>,
MultiLinearPoly<E>,
),
PeriodicTable<E>
PeriodicTable<E>,
) {
let n = 1 << log_size;
let table = MultiLinearPoly::from_evaluations(rand_vector(n));
Expand All @@ -94,7 +94,13 @@ fn setup_sum_check<E: FieldElement>(
let r_batch: E = rand_value();
let claim: E = rand_value();

(claim, r_batch, rand_pt, (table, multiplicity, values_0, values_1, values_2), periodic_table)
(
claim,
r_batch,
rand_pt,
(table, multiplicity, values_0, values_1, values_2),
periodic_table,
)
}

#[derive(Clone, Default)]
Expand Down
3 changes: 2 additions & 1 deletion sumcheck/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crypto::{ElementHasher, RandomCoin};
use math::FieldElement;

use crate::{
comb_func, evaluate_composition_poly, EqFunction, FinalLayerProof, FinalOpeningClaim, MultiLinearPoly, RoundProof, SumCheckProof, SumCheckRoundClaim
comb_func, evaluate_composition_poly, EqFunction, FinalLayerProof, FinalOpeningClaim,
MultiLinearPoly, RoundProof, SumCheckProof, SumCheckRoundClaim,
};

/// Verifies sum-check proofs, as part of the GKR proof, for all GKR layers except for the last one
Expand Down
35 changes: 0 additions & 35 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,41 +350,6 @@ where
.map_err(VerifierError::FriVerificationFailed)
}

fn verify_gkr<E: FieldElement, H: ElementHasher<BaseField = E::BaseField>>(
gkr_proof: GkrCircuitProof<E>,
evaluator: &impl LogUpGkrEvaluator<BaseField = E::BaseField>,
public_coin: &mut impl RandomCoin<BaseField = E::BaseField, Hasher = H>,
) -> Result<GkrData<E>, GkrVerifierError> {
let claim = E::ZERO;
let num_logup_random_values = evaluator.get_num_rand_values();
let mut logup_randomness: Vec<E> = Vec::with_capacity(num_logup_random_values);

for _ in 0..num_logup_random_values {
logup_randomness.push(public_coin.draw().expect("failed to generate randomness"));
}

let final_eval_claim =
verify_logup_gkr(claim, evaluator, &gkr_proof, logup_randomness, public_coin)?;

let FinalOpeningClaim { eval_point, openings } = final_eval_claim;

public_coin.reseed(H::hash_elements(&openings));

let mut batching_randomness = Vec::with_capacity(openings.len() - 1);
for _ in 0..openings.len() - 1 {
batching_randomness.push(public_coin.draw().expect("failed to generate randomness"))
}

let gkr_rand_elements = GkrData::new(
LagrangeKernelRandElements::new(eval_point),
batching_randomness,
openings,
evaluator.get_oracles().to_vec(),
);

Ok(gkr_rand_elements)
}

// ACCEPTABLE OPTIONS
// ================================================================================================
// Specifies either the minimal, conjectured or proven, security level or a set of
Expand Down
12 changes: 9 additions & 3 deletions verifier/src/logup_gkr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ pub fn verify_gkr<
C: RandomCoin<Hasher = H, BaseField = E::BaseField>,
H: ElementHasher<BaseField = E::BaseField>,
>(
claim: E,
evaluator: &impl LogUpGkrEvaluator<BaseField = E::BaseField>,
pub_inputs: &A::PublicInputs,
proof: &GkrCircuitProof<E>,
log_up_randomness: Vec<E>,
evaluator: &impl LogUpGkrEvaluator<BaseField = E::BaseField, PublicInputs = A::PublicInputs>,
transcript: &mut C,
) -> Result<FinalOpeningClaim<E>, VerifierError> {
let num_logup_random_values = evaluator.get_num_rand_values();
let mut logup_randomness: Vec<E> = Vec::with_capacity(num_logup_random_values);

for _ in 0..num_logup_random_values {
logup_randomness.push(transcript.draw().expect("failed to generate randomness"));
}

let GkrCircuitProof {
circuit_outputs,
before_final_layer_proofs,
Expand Down
17 changes: 7 additions & 10 deletions winterfell/src/tests/logup_gkr_periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ impl Trace for LogUpGkrPeriodic {
// =================================================================================================

struct LogUpGkrPeriodicAir {
context: AirContext<BaseElement>,
context: AirContext<BaseElement, ()>,
}

impl Air for LogUpGkrPeriodicAir {
type BaseField = BaseElement;
type PublicInputs = ();
type LogUpGkrEvaluator = PeriodicLogUpGkrEval<Self::BaseField>;

fn new(trace_info: TraceInfo, _pub_inputs: Self::PublicInputs, options: ProofOptions) -> Self {
Self {
context: AirContext::with_logup_gkr(
trace_info,
(),
vec![TransitionConstraintDegree::new(1)],
vec![],
1,
Expand All @@ -135,7 +135,7 @@ impl Air for LogUpGkrPeriodicAir {
}
}

fn context(&self) -> &AirContext<Self::BaseField> {
fn context(&self) -> &AirContext<Self::BaseField, ()> {
&self.context
}

Expand Down Expand Up @@ -177,9 +177,10 @@ impl Air for LogUpGkrPeriodicAir {
vec![]
}

fn get_logup_gkr_evaluator<E: FieldElement<BaseField = Self::BaseField>>(
fn get_logup_gkr_evaluator(
&self,
) -> Self::LogUpGkrEvaluator {
) -> impl LogUpGkrEvaluator<BaseField = Self::BaseField, PublicInputs = Self::PublicInputs>
{
PeriodicLogUpGkrEval::new()
}
}
Expand Down Expand Up @@ -338,11 +339,7 @@ impl Prover for LogUpGkrPeriodicProver {
DefaultConstraintEvaluator::new(air, aux_rand_elements, composition_coefficients)
}

fn build_aux_trace<E>(
&self,
main_trace: &Self::Trace,
_aux_rand_elements: &AuxRandElements<E>,
) -> ColMatrix<E>
fn build_aux_trace<E>(&self, main_trace: &Self::Trace, _aux_rand_elements: &[E]) -> ColMatrix<E>
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 0 additions & 2 deletions winterfell/src/tests/logup_gkr_simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use std::{marker::PhantomData, vec, vec::Vec};

use air::{
Expand Down Expand Up @@ -111,7 +110,6 @@ struct LogUpGkrSimpleAir {
impl Air for LogUpGkrSimpleAir {
type BaseField = BaseElement;
type PublicInputs = ();
type LogUpGkrEvaluator = PlainLogUpGkrEval<Self::BaseField>;

fn new(trace_info: TraceInfo, _pub_inputs: Self::PublicInputs, options: ProofOptions) -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion winterfell/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.


mod logup_gkr_simple;

mod logup_gkr_periodic;

0 comments on commit 7e50a6e

Please sign in to comment.