Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
jotabulacios committed Feb 27, 2025
1 parent c29a94d commit b78c3b6
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 128 deletions.
26 changes: 26 additions & 0 deletions crypto/src/sumcheck/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
pub mod prover;
pub mod verifier;

use crate::fiat_shamir::default_transcript::DefaultTranscript;
use crate::fiat_shamir::is_transcript::IsTranscript;
use lambdaworks_math::field::element::FieldElement;

use lambdaworks_math::field::traits::IsField;
use lambdaworks_math::traits::ByteConversion;

pub trait Channel<F: IsField> {
fn append_field_element(&mut self, element: &FieldElement<F>);
fn draw_felt(&mut self) -> FieldElement<F>;
}

impl<F> Channel<F> for DefaultTranscript<F>
where
F: IsField,
FieldElement<F>: ByteConversion,
{
fn append_field_element(&mut self, element: &FieldElement<F>) {
self.append_bytes(&element.to_bytes_be());
}

fn draw_felt(&mut self) -> FieldElement<F> {
self.sample_field_element()
}
}
11 changes: 3 additions & 8 deletions crypto/src/sumcheck/prover.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use crate::fiat_shamir::default_transcript::DefaultTranscript;
use crate::fiat_shamir::is_transcript::IsTranscript;
use alloc::vec::Vec;
use lambdaworks_math::field::element::FieldElement;
use lambdaworks_math::field::traits::IsField;
use lambdaworks_math::polynomial::{
dense_multilinear_poly::DenseMultilinearPolynomial,
Polynomial, // Univariate polynomials
dense_multilinear_poly::DenseMultilinearPolynomial, Polynomial,
};
use lambdaworks_math::traits::ByteConversion;

/// Prover for the Sum-Check protocol using DenseMultilinearPolynomial.
pub struct Prover<F: IsField>
Expand Down Expand Up @@ -37,10 +32,10 @@ where
self.claimed_sum.clone()
}

/// Receives the challenge \( r_j \) from the verifier, fixes the last variable to that value,
/// Receives the challenge r_j from the verifier, fixes the last variable to that value,
/// and returns the univariate polynomial for the next variable.
pub fn round(&mut self, r_j: FieldElement<F>) -> Polynomial<FieldElement<F>> {
// Fix the last variable (using the integrated method in dense_multilinear_poly)
// Fix the last variable
self.poly = self.poly.fix_last_variable(&r_j);
// Obtain the univariate polynomial: sum of evaluations with the last variable fixed to 0 and 1.
let univar = self.poly.to_univariate();
Expand Down
Loading

0 comments on commit b78c3b6

Please sign in to comment.