Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sragss committed Apr 17, 2024
1 parent 8fca5e6 commit d46cf40
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 99 deletions.
6 changes: 1 addition & 5 deletions jolt-core/src/jolt/vm/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,7 @@ pub struct BytecodeCommitment<G: CurveGroup> {
}

impl<G: CurveGroup> AppendToTranscript for BytecodeCommitment<G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_protocol_name(label);

for commitment in &self.trace_commitments {
Expand Down
26 changes: 8 additions & 18 deletions jolt-core/src/jolt/vm/instruction_lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ pub struct InstructionCommitment<G: CurveGroup> {
}

impl<G: CurveGroup> AppendToTranscript for InstructionCommitment<G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"InstructionCommitment_begin");
for commitment in &self.trace_commitment {
commitment.append_to_transcript(b"trace_commitment", transcript);
Expand Down Expand Up @@ -868,10 +864,7 @@ where
transcript.append_protocol_name(Self::protocol_name());

let trace_length = polynomials.dim[0].len();
let r_eq = transcript.challenge_vector(
b"Jolt instruction lookups",
trace_length.log_2(),
);
let r_eq = transcript.challenge_vector(b"Jolt instruction lookups", trace_length.log_2());

let eq_evals: Vec<F> = EqPolynomial::new(r_eq.to_vec()).evals();
let mut eq_poly = DensePolynomial::new(eq_evals);
Expand Down Expand Up @@ -935,15 +928,12 @@ where
);

// TODO: compartmentalize all primary sumcheck logic
let (claim_last, r_primary_sumcheck) = proof
.primary_sumcheck
.sumcheck_proof
.verify::<G>(
F::zero(),
proof.primary_sumcheck.num_rounds,
Self::sumcheck_poly_degree(),
transcript,
)?;
let (claim_last, r_primary_sumcheck) = proof.primary_sumcheck.sumcheck_proof.verify::<G>(
F::zero(),
proof.primary_sumcheck.num_rounds,
Self::sumcheck_poly_degree(),
transcript,
)?;

// Verify that eq(r, r_z) * [f_1(r_z) * g(E_1(r_z)) + ... + f_F(r_z) * E_F(r_z))] = claim_last
let eq_eval = EqPolynomial::new(r_eq.to_vec()).evaluate(&r_primary_sumcheck);
Expand Down
26 changes: 7 additions & 19 deletions jolt-core/src/jolt/vm/read_write_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,7 @@ pub struct MemoryCommitment<G: CurveGroup> {
}

impl<G: CurveGroup> AppendToTranscript for MemoryCommitment<G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"MemoryCommitment_begin");
for commitment in &self.trace_commitments {
commitment.append_to_transcript(b"trace_commit", transcript);
Expand Down Expand Up @@ -1359,10 +1355,7 @@ where
transcript: &mut ProofTranscript,
) -> Self {
let num_rounds = polynomials.memory_size.log_2();
let r_eq = transcript.challenge_vector(
b"output_sumcheck",
num_rounds,
);
let r_eq = transcript.challenge_vector(b"output_sumcheck", num_rounds);
let eq: DensePolynomial<F> = DensePolynomial::new(EqPolynomial::new(r_eq.to_vec()).evals());

let io_witness_range: Vec<_> = (0..polynomials.memory_size as u64)
Expand Down Expand Up @@ -1441,17 +1434,12 @@ where
commitment: &MemoryCommitment<G>,
transcript: &mut ProofTranscript,
) -> Result<(), ProofVerifyError> {
let r_eq = transcript.challenge_vector(
b"output_sumcheck",
proof.num_rounds,
);
let r_eq = transcript.challenge_vector(b"output_sumcheck", proof.num_rounds);

let (sumcheck_claim, r_sumcheck) = proof.sumcheck_proof.verify::<G>(
F::zero(),
proof.num_rounds,
3,
transcript,
)?;
let (sumcheck_claim, r_sumcheck) =
proof
.sumcheck_proof
.verify::<G>(F::zero(), proof.num_rounds, 3, transcript)?;

let eq_eval = EqPolynomial::new(r_eq.to_vec()).evaluate(&r_sumcheck);

Expand Down
6 changes: 1 addition & 5 deletions jolt-core/src/jolt/vm/timestamp_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ pub struct RangeCheckCommitment<G: CurveGroup> {
}

impl<G: CurveGroup> AppendToTranscript for RangeCheckCommitment<G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"RangeCheckCommitment_begin");
for commitment in &self.commitments {
commitment.append_to_transcript(b"range", transcript);
Expand Down
38 changes: 16 additions & 22 deletions jolt-core/src/lasso/surge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,14 @@ where
instruction.combine_lookups(vals_no_eq, C, M) * eq
};

let (primary_sumcheck_proof, r_z, _) =
SumcheckInstanceProof::<F>::prove_arbitrary::<_, G>(
&sumcheck_claim,
num_rounds,
&mut combined_sumcheck_polys,
combine_lookups_eq,
instruction.g_poly_degree(C) + 1, // combined degree + eq term
transcript,
);
let (primary_sumcheck_proof, r_z, _) = SumcheckInstanceProof::<F>::prove_arbitrary::<_, G>(
&sumcheck_claim,
num_rounds,
&mut combined_sumcheck_polys,
combine_lookups_eq,
instruction.g_poly_degree(C) + 1, // combined degree + eq term
transcript,
);

let sumcheck_openings = PrimarySumcheckOpenings::open(&polynomials, &r_z); // TODO: use return value from prove_arbitrary?
let sumcheck_opening_proof = PrimarySumcheckOpenings::prove_openings(
Expand Down Expand Up @@ -635,25 +634,20 @@ where
transcript.append_protocol_name(Self::protocol_name());
let instruction = Instruction::default();

let r_primary_sumcheck = transcript.challenge_vector(
b"primary_sumcheck",
proof.primary_sumcheck.num_rounds,
);
let r_primary_sumcheck =
transcript.challenge_vector(b"primary_sumcheck", proof.primary_sumcheck.num_rounds);

transcript.append_scalar(
b"sumcheck_claim",
&proof.primary_sumcheck.claimed_evaluation,
);
let primary_sumcheck_poly_degree = instruction.g_poly_degree(C) + 1;
let (claim_last, r_z) = proof
.primary_sumcheck
.sumcheck_proof
.verify::<G>(
proof.primary_sumcheck.claimed_evaluation,
proof.primary_sumcheck.num_rounds,
primary_sumcheck_poly_degree,
transcript,
)?;
let (claim_last, r_z) = proof.primary_sumcheck.sumcheck_proof.verify::<G>(
proof.primary_sumcheck.claimed_evaluation,
proof.primary_sumcheck.num_rounds,
primary_sumcheck_poly_degree,
transcript,
)?;

let eq_eval = EqPolynomial::new(r_primary_sumcheck.to_vec()).evaluate(&r_z);
assert_eq!(
Expand Down
15 changes: 5 additions & 10 deletions jolt-core/src/poly/hyrax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ impl<const RATIO: usize, G: CurveGroup> HyraxCommitment<RATIO, G> {
}

impl<const RATIO: usize, G: CurveGroup> AppendToTranscript for HyraxCommitment<RATIO, G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"poly_commitment_begin");
for i in 0..self.row_commitments.len() {
transcript.append_point(b"poly_commitment_share", &self.row_commitments[i]);
Expand Down Expand Up @@ -252,7 +248,8 @@ impl<const RATIO: usize, G: CurveGroup> BatchedHyraxOpeningProof<RATIO, G> {
// append the claimed evaluations to transcript
transcript.append_scalars(b"evals_ops_val", &openings);

let rlc_coefficients: Vec<_> = transcript.challenge_vector(b"challenge_combine_n_to_one", polynomials.len());
let rlc_coefficients: Vec<_> =
transcript.challenge_vector(b"challenge_combine_n_to_one", polynomials.len());

let _span = trace_span!("Compute RLC of polynomials");
let _enter = _span.enter();
Expand Down Expand Up @@ -319,10 +316,8 @@ impl<const RATIO: usize, G: CurveGroup> BatchedHyraxOpeningProof<RATIO, G> {
// append the claimed evaluations to transcript
transcript.append_scalars(b"evals_ops_val", &openings);

let rlc_coefficients: Vec<_> = transcript.challenge_vector(
b"challenge_combine_n_to_one",
openings.len(),
);
let rlc_coefficients: Vec<_> =
transcript.challenge_vector(b"challenge_combine_n_to_one", openings.len());

let rlc_eval = compute_dotproduct(&rlc_coefficients, openings);

Expand Down
5 changes: 4 additions & 1 deletion jolt-core/src/poly/structured_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use ark_ff::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};

use super::pedersen::PedersenGenerators;
use crate::{lasso::memory_checking::NoPreprocessing, utils::{errors::ProofVerifyError, transcript::ProofTranscript}};
use crate::{
lasso::memory_checking::NoPreprocessing,
utils::{errors::ProofVerifyError, transcript::ProofTranscript},
};

/// Encapsulates the pattern of a collection of related polynomials (e.g. those used to
/// prove instruction lookups in Jolt) that can be "batched" for more efficient
Expand Down
6 changes: 1 addition & 5 deletions jolt-core/src/poly/unipoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl<F: PrimeField> CompressedUniPoly<F> {
}

impl<F: PrimeField> AppendToTranscript for UniPoly<F> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"UniPoly_begin");
for i in 0..self.coeffs.len() {
transcript.append_scalar(b"coeff", &self.coeffs[i]);
Expand Down
6 changes: 1 addition & 5 deletions jolt-core/src/r1cs/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,7 @@ pub struct R1CSCommitment<G: CurveGroup> {
}

impl<G: CurveGroup> AppendToTranscript for R1CSCommitment<G> {
fn append_to_transcript(
&self,
label: &'static [u8],
transcript: &mut ProofTranscript,
) {
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut ProofTranscript) {
transcript.append_message(label, b"R1CSCommitment_begin");
for commitment in &self.io {
commitment.append_to_transcript(b"io", transcript);
Expand Down
11 changes: 5 additions & 6 deletions jolt-core/src/subprotocols/grand_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ impl<F: PrimeField> BatchedGrandProductArgument<F> {
let _enter = span.enter();

// produce a fresh set of coeffs and a joint claim
let coeff_vec: Vec<F> = transcript.challenge_vector(b"rand_coeffs_next_layer", claims_to_verify.len());
let coeff_vec: Vec<F> =
transcript.challenge_vector(b"rand_coeffs_next_layer", claims_to_verify.len());
let claim = (0..claims_to_verify.len())
.map(|i| claims_to_verify[i] * coeff_vec[i])
.sum();
Expand All @@ -254,10 +255,7 @@ impl<F: PrimeField> BatchedGrandProductArgument<F> {
for i in 0..batch.circuits.len() {
transcript.append_scalar(b"claim_prod_left", &claims_poly_A[i]);

transcript.append_scalar(
b"claim_prod_right",
&claims_poly_B[i],
);
transcript.append_scalar(b"claim_prod_right", &claims_poly_B[i]);
}

if sumcheck_type == CubicSumcheckType::Prod
Expand Down Expand Up @@ -322,7 +320,8 @@ impl<F: PrimeField> BatchedGrandProductArgument<F> {
let mut claims_to_verify = claims_prod_vec.to_owned();
for (num_rounds, i) in (0..num_layers).enumerate() {
// produce random coefficients, one for each instance
let coeff_vec = transcript.challenge_vector::<F>(b"rand_coeffs_next_layer", claims_to_verify.len());
let coeff_vec =
transcript.challenge_vector::<F>(b"rand_coeffs_next_layer", claims_to_verify.len());

// produce a joint claim
let claim = (0..claims_to_verify.len())
Expand Down
2 changes: 1 addition & 1 deletion jolt-core/src/subprotocols/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl<F: PrimeField> SumcheckInstanceProof<F> {
poly.append_to_transcript(b"poly", transcript);

//derive the verifier's challenge for the next round
let r_j = transcript.challenge_scalar(b"challenge_nextround",);
let r_j = transcript.challenge_scalar(b"challenge_nextround");
r.push(r_j);

let poly_As_span = trace_span!("Bind leaves");
Expand Down
4 changes: 2 additions & 2 deletions jolt-core/src/utils/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use ark_ff::PrimeField;
use merlin::Transcript;

pub struct ProofTranscript {
inner: Transcript
inner: Transcript,
}

impl ProofTranscript {
pub fn new(label: &'static [u8]) -> Self {
Self {
inner: Transcript::new(label)
inner: Transcript::new(label),
}
}

Expand Down

0 comments on commit d46cf40

Please sign in to comment.