From b513a2042a0feda5deb8f601de3586d983748fbb Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 29 Feb 2024 19:01:07 -0600 Subject: [PATCH] update transcript --- crypto/src/subprotocols/sumcheck.rs | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/crypto/src/subprotocols/sumcheck.rs b/crypto/src/subprotocols/sumcheck.rs index 7c09f3124..628d536f5 100644 --- a/crypto/src/subprotocols/sumcheck.rs +++ b/crypto/src/subprotocols/sumcheck.rs @@ -1,7 +1,7 @@ use core::fmt::Display; use std::marker::PhantomData; -use crate::fiat_shamir::transcript::Transcript; +use crate::fiat_shamir::is_transcript::IsTranscript; use lambdaworks_math::field::element::FieldElement; use lambdaworks_math::field::traits::{IsField, IsPrimeField}; use lambdaworks_math::polynomial::{ @@ -150,7 +150,7 @@ where poly_a: &mut DenseMultilinearPolynomial, poly_b: &mut DenseMultilinearPolynomial, comb_func: E, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> (SumcheckProof, Vec>) where E: Fn(&FieldElement, &FieldElement) -> FieldElement + Sync, @@ -168,10 +168,10 @@ where }; // append round's Univariate polynomial to transcript - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); // Squeeze Verifier Challenge for next round - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = &transcript.sample_field_element(); challenges.push(challenge.clone()); // compute next claim @@ -200,7 +200,7 @@ where poly_b: &mut Vec>, powers: Option<&[FieldElement]>, comb_func: E, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> SumcheckProof where E: Fn(&FieldElement, &FieldElement) -> FieldElement + Sync, @@ -239,10 +239,10 @@ where let round_poly = Polynomial::new(&evals); // TODO append the prover's message to the transcript - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); // Squeeze Verifier Challenge for next round - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = &transcript.sample_field_element(); challenges.push(challenge.clone()); // bound all tables to the verifier's challenege @@ -267,7 +267,7 @@ where poly_b: &mut DenseMultilinearPolynomial, poly_c: &mut DenseMultilinearPolynomial, comb_func: E, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> (SumcheckProof, Vec>) where E: Fn(&FieldElement, &FieldElement, &FieldElement) -> FieldElement + Sync, @@ -291,10 +291,10 @@ where }; // TODO append the prover's message to the transcript - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); // Squeeze Verifier Challenge for next round - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = transcript.sample_field_element(); challenges.push(challenge.clone()); // bound all tables to the verifier's challenege @@ -322,7 +322,7 @@ where poly_c: &DenseMultilinearPolynomial, powers: Option<&[FieldElement]>, comb_func: E, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> (SumcheckProof, Vec>) where E: Fn(&FieldElement, &FieldElement, &FieldElement) -> FieldElement + Sync, @@ -364,10 +364,10 @@ where let round_poly = Polynomial::new(&evals); // TODO: Check if order matters - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); // Squeeze Verifier Challenge for next round - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = &transcript.sample_field_element(); challenges.push(challenge.clone()); // TODO: rayon::join and gate @@ -399,7 +399,7 @@ where poly_c: &mut DenseMultilinearPolynomial, poly_d: &mut DenseMultilinearPolynomial, comb_func: E, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> (SumcheckProof, Vec>) where E: Fn( @@ -486,10 +486,10 @@ where }; // TODO: Does it matter that its before the challenge???? -> Should be I believe - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); // Squeeze Verifier Challenge for next round - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = transcript.sample_field_element(); challenges.push(challenge.clone()); prev_round_claim = round_poly.evaluate(&challenge); @@ -516,7 +516,7 @@ where pub fn prove_single( poly: &mut DenseMultilinearPolynomial, sum: &FieldElement, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> (SumcheckProof, Vec>) { let mut round_uni_polys: Vec>> = Vec::with_capacity(poly.num_vars()); @@ -537,9 +537,9 @@ where }; // TODO: Append poly to transcript -> Modify Transcript - transcript.append(&round_poly.as_bytes()); + transcript.append_bytes(&round_poly.as_bytes()); - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = &transcript.sample_field_element(); challenges.push(challenge.clone()); // grab next claim @@ -570,7 +570,7 @@ where pub fn verify( proof: SumcheckProof, num_vars: usize, - transcript: &mut impl Transcript, + transcript: &mut impl IsTranscript, ) -> Result<(FieldElement, Vec>), SumcheckError> { let mut e = proof.sum.clone(); let mut r: Vec> = Vec::with_capacity(num_vars); @@ -588,9 +588,9 @@ where println!("Oh No"); return Err(SumcheckError::InvalidProof); } - transcript.append(&poly.as_bytes()); + transcript.append_bytes(&poly.as_bytes()); - let challenge = FieldElement::from_bytes_be(&transcript.challenge()).unwrap(); + let challenge = &transcript.sample_field_element(); r.push(challenge.clone()); e = poly.evaluate(&challenge); @@ -655,7 +655,7 @@ mod test { FieldElement::from(3), ]; // point 0,0,0 within the boolean hypercube - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove_cubic"); let (proof, challenges) = Sumcheck::::prove_cubic( &claim, &mut a, @@ -665,7 +665,7 @@ mod test { &mut transcript, ); - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove cubic"); let verify_result = Sumcheck::verify(proof, num_vars, &mut transcript); assert!(verify_result.is_ok()); @@ -718,11 +718,11 @@ mod test { ]; // point 0,0,0 within the boolean hypercube */ - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove_quad"); let (proof, challenges) = Sumcheck::::prove_quadratic(&claim, &mut a, &mut b, comb_func_prod, &mut transcript); - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove_quad"); let verify = Sumcheck::verify(proof, num_vars, &mut transcript).unwrap(); /* @@ -766,10 +766,10 @@ mod test { FieldElement::from(3), ]; // point 0,0,0 within the boolean hypercube - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove_single"); let (proof, challenges) = Sumcheck::::prove_single(&mut a, &claim, &mut transcript); - let mut transcript = DefaultTranscript::new(); + let mut transcript = DefaultTranscript::new(b"prove_single"); let verify_result = Sumcheck::verify(proof, a.num_vars(), &mut transcript); assert!(verify_result.is_ok());