Skip to content

Commit

Permalink
chore: update var names and simplify some structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Aug 20, 2024
1 parent 1556e76 commit 9885c33
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib2/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl air::LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib8/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl air::LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/fib_small/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl air::LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/mulfib2/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl air::LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fibonacci/mulfib8/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl air::LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lamport/aggregate/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lamport/threshold/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/merkle/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/rescue/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/rescue_raps/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/vdf/exempt/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
2 changes: 1 addition & 1 deletion examples/src/vdf/regular/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl LogUpGkrEvaluator for PlainLogUpGkrEval<BaseElement> {
unimplemented!()
}

fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E]) -> Vec<E>
fn build_query<E>(&self, _frame: &EvaluationFrame<E>, _periodic_values: &[E], _query: &mut [E])
where
E: FieldElement<BaseField = Self::BaseField>,
{
Expand Down
38 changes: 19 additions & 19 deletions prover/src/logup_gkr/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub fn prove_gkr<E: FieldElement>(
prove_intermediate_layers(&mut circuit, public_coin)?;

// build the MLEs of the relevant main trace columns
let main_trace_mls =
let mut main_trace_mls =
build_mls_from_main_trace_segment(evaluator.get_oracles(), main_trace.main_segment())?;

let final_layer_proof =
prove_input_layer(evaluator, logup_randomness, main_trace_mls, gkr_claim, public_coin)?;
prove_input_layer(evaluator, logup_randomness, &mut main_trace_mls, gkr_claim, public_coin)?;

// include the circuit output as part of the final proof
let CircuitLayerPolys { numerators, denominators } = circuit.output_layer().clone();
Expand All @@ -97,12 +97,12 @@ fn prove_input_layer<
>(
evaluator: &impl LogUpGkrEvaluator<BaseField = E::BaseField>,
log_up_randomness: Vec<E>,
mut mls: Vec<MultiLinearPoly<E>>,
gkr_claim: GkrClaim<E>,
multi_linear_ext_polys: &mut[MultiLinearPoly<E>],
claim: GkrClaim<E>,
transcript: &mut C,
) -> Result<FinalLayerProof<E>, GkrProverError> {
// parse the [GkrClaim] resulting from the previous GKR layer
let GkrClaim { evaluation_point, claimed_evaluation } = gkr_claim;
let GkrClaim { evaluation_point, claimed_evaluation } = claim;

transcript.reseed(H::hash_elements(&[claimed_evaluation.0, claimed_evaluation.1]));
let r_batch = transcript.draw().map_err(|_| GkrProverError::FailedToGenerateChallenge)?;
Expand All @@ -114,11 +114,11 @@ fn prove_input_layer<
claim,
r_batch,
log_up_randomness,
&mut mls,
multi_linear_ext_polys,
transcript,
)?;

Ok(FinalLayerProof { proof })
Ok(FinalLayerProof::new(proof))
}

// TODO: Make the multi-linears over the base field and define an operation of folding with a challenge
Expand Down Expand Up @@ -172,10 +172,10 @@ fn prove_intermediate_layers<

// generate the challenge and reduce [p0, p1, q0, q1] to [pr, qr]
let r = transcript.draw().map_err(|_| GkrProverError::FailedToGenerateChallenge)?;
let mut claim = circuit.evaluate_output_layer(r);
let mut claimed_evaluation = circuit.evaluate_output_layer(r);

let mut proof_layers: Vec<SumCheckProof<E>> = Vec::new();
let mut rand = vec![r];
let mut layer_proofs: Vec<SumCheckProof<E>> = Vec::new();
let mut evaluation_point = vec![r];

// Loop over all inner layers, from output to input.
//
Expand All @@ -186,7 +186,7 @@ fn prove_intermediate_layers<
// reduced in terms of the input layer separately in `prove_final_circuit_layer`.
for inner_layer in circuit.layers().iter().skip(1).rev().skip(1) {
// construct the Lagrange kernel evaluated at the previous GKR round randomness
let mut poly_x = EqFunction::ml_at(rand.into());
let mut eq_mle = EqFunction::ml_at(evaluation_point.into());

// construct the vector of multi-linear polynomials
// TODO: avoid unnecessary allocation
Expand All @@ -197,12 +197,12 @@ fn prove_intermediate_layers<

// run the sumcheck protocol
let proof = sum_check_prove_num_rounds_degree_3(
claim,
claimed_evaluation,
&mut left_numerators,
&mut right_numerators,
&mut left_denominators,
&mut right_denominators,
&mut poly_x,
&mut eq_mle,
transcript,
)?;

Expand All @@ -211,7 +211,7 @@ fn prove_intermediate_layers<
let r_layer = transcript.draw().map_err(|_| GkrProverError::FailedToGenerateChallenge)?;

// reduce the claim
claim = {
claimed_evaluation = {
let left_numerators_opening = proof.openings_claim.openings[0];
let right_numerators_opening = proof.openings_claim.openings[1];
let left_denominators_opening = proof.openings_claim.openings[2];
Expand All @@ -229,16 +229,16 @@ fn prove_intermediate_layers<
// collect the randomness used for the current layer
let mut ext = vec![r_layer];
ext.extend_from_slice(&proof.openings_claim.eval_point);
rand = ext;
evaluation_point = ext;

proof_layers.push(proof);
layer_proofs.push(proof);
}

Ok((
BeforeFinalLayerProof { proof: proof_layers },
BeforeFinalLayerProof { proof: layer_proofs },
GkrClaim {
evaluation_point: rand,
claimed_evaluation: claim,
evaluation_point,
claimed_evaluation,
},
))
}
Expand Down
19 changes: 10 additions & 9 deletions sumcheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,20 @@ where

/// A proof for the input circuit layer i.e., the final layer in the GKR protocol.
#[derive(Debug, Clone)]
pub struct FinalLayerProof<E: FieldElement> {
pub proof: SumCheckProof<E>,
pub struct FinalLayerProof<E: FieldElement>(SumCheckProof<E>);

impl<E: FieldElement> FinalLayerProof<E> {
pub fn new(proof: SumCheckProof<E>) -> Self {
Self(proof)
}
}

impl<E> Serializable for FinalLayerProof<E>
where
E: FieldElement,
{
fn write_into<W: ByteWriter>(&self, target: &mut W) {
let Self { proof } = self;
proof.write_into(target);
self.0.write_into(target);
}
}

Expand All @@ -143,9 +146,7 @@ where
E: FieldElement,
{
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
Ok(Self {
proof: Deserializable::read_from(source)?,
})
Ok(Self(Deserializable::read_from(source)?))
}
}

Expand All @@ -170,7 +171,7 @@ pub struct GkrCircuitProof<E: FieldElement> {

impl<E: FieldElement> GkrCircuitProof<E> {
pub fn get_final_opening_claim(&self) -> FinalOpeningClaim<E> {
self.final_layer_proof.proof.openings_claim.clone()
self.final_layer_proof.0.openings_claim.clone()
}
}

Expand All @@ -181,7 +182,7 @@ where
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.circuit_outputs.write_into(target);
self.before_final_layer_proofs.write_into(target);
self.final_layer_proof.proof.write_into(target);
self.final_layer_proof.0.write_into(target);
}
}

Expand Down
12 changes: 5 additions & 7 deletions sumcheck/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ pub fn verify_sum_check_input_layer<E: FieldElement, H: ElementHasher<BaseField
claim: (E, E),
transcript: &mut impl RandomCoin<Hasher = H, BaseField = E::BaseField>,
) -> Result<FinalOpeningClaim<E>, SumCheckVerifierError> {
let FinalLayerProof { proof } = proof;

// generate challenge to batch sum-checks
transcript.reseed(H::hash_elements(&[claim.0, claim.1]));
let r_batch: E = transcript
Expand All @@ -77,17 +75,17 @@ pub fn verify_sum_check_input_layer<E: FieldElement, H: ElementHasher<BaseField

// verify the sum-check proof
let SumCheckRoundClaim { eval_point, claim } =
verify_rounds(reduced_claim, &proof.round_proofs, transcript)?;
verify_rounds(reduced_claim, &proof.0.round_proofs, transcript)?;

// execute the final evaluation check
if proof.openings_claim.eval_point != eval_point {
if proof.0.openings_claim.eval_point != eval_point {
return Err(SumCheckVerifierError::WrongOpeningPoint);
}

let mut numerators = vec![E::ZERO; evaluator.get_num_fractions()];
let mut denominators = vec![E::ZERO; evaluator.get_num_fractions()];
evaluator.evaluate_query(
&proof.openings_claim.openings,
&proof.0.openings_claim.openings,
&log_up_randomness,
&mut numerators,
&mut denominators,
Expand All @@ -99,14 +97,14 @@ pub fn verify_sum_check_input_layer<E: FieldElement, H: ElementHasher<BaseField
let eq_mu = EqFunction::new(evaluation_point_mu.into()).evaluations();
let eq_nu = EqFunction::new(evaluation_point_nu.into());

let eq_nu_eval = eq_nu.evaluate(&proof.openings_claim.eval_point);
let eq_nu_eval = eq_nu.evaluate(&proof.0.openings_claim.eval_point);
let expected_evaluation =
evaluate_composition_poly(&eq_mu, &numerators, &denominators, eq_nu_eval, r_batch);

if expected_evaluation != claim {
Err(SumCheckVerifierError::FinalEvaluationCheckFailed)
} else {
Ok(proof.openings_claim.clone())
Ok(proof.0.openings_claim.clone())
}
}

Expand Down
8 changes: 4 additions & 4 deletions verifier/src/logup_gkr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ pub fn verify_logup_gkr<

// verify all GKR layers but for the last one
let num_layers = before_final_layer_proofs.proof.len();
let mut rand = vec![r];
let mut evaluation_point = vec![r];
for i in 0..num_layers {
let FinalOpeningClaim { eval_point, openings } = verify_sum_check_intermediate_layers(
&before_final_layer_proofs.proof[i],
&rand,
&evaluation_point,
reduced_claim,
transcript,
)?;
Expand All @@ -78,7 +78,7 @@ pub fn verify_logup_gkr<
let rand_sumcheck = eval_point;
let mut ext = vec![r_layer];
ext.extend_from_slice(&rand_sumcheck);
rand = ext;
evaluation_point = ext;
}

// verify the proof of the final GKR layer and pass final opening claim for verification
Expand All @@ -87,7 +87,7 @@ pub fn verify_logup_gkr<
evaluator,
final_layer_proof,
log_up_randomness,
&rand,
&evaluation_point,
reduced_claim,
transcript,
)
Expand Down

0 comments on commit 9885c33

Please sign in to comment.