Small code organization improvements (#206)

* refactor: Deleted a redundant `ScalarMul` helper trait

* refactor: Refactor `to_transcript_bytes`

* refactor: refactor R1CS Shape checking in Spartan checks

- Introduced a new function `check_regular_shape` in `r1cs.rs` to enforce regularity conditions necessary for Spartan-class SNARKs.

* refactor: Refactor sumcheck.rs prove_quad_* for readability

- Extracted the calculation of evaluation points to its new function `compute_eval_points`, enhancing code reusability within `prove_quad` and `prove_quad_batch` functions.
This commit is contained in:
François Garillot
2023-07-21 14:24:47 -04:00
committed by GitHub
parent 87499b3c49
commit a62bccf206
6 changed files with 49 additions and 54 deletions

View File

@@ -6,10 +6,12 @@ use crate::{
};
use core::{
fmt::Debug,
ops::{Add, AddAssign, Mul, MulAssign},
ops::{Add, AddAssign},
};
use serde::{Deserialize, Serialize};
use super::ScalarMul;
/// Defines basic operations on commitments
pub trait CommitmentOps<Rhs = Self, Output = Self>:
Add<Rhs, Output = Output> + AddAssign<Rhs>
@@ -31,12 +33,6 @@ impl<T, Rhs, Output> CommitmentOpsOwned<Rhs, Output> for T where
{
}
/// A helper trait for types implementing a multiplication of a commitment with a scalar
pub trait ScalarMul<Rhs, Output = Self>: Mul<Rhs, Output = Output> + MulAssign<Rhs> {}
impl<T, Rhs, Output> ScalarMul<Rhs, Output> for T where T: Mul<Rhs, Output = Output> + MulAssign<Rhs>
{}
/// This trait defines the behavior of the commitment
pub trait CommitmentTrait<G: Group>:
Clone

View File

@@ -236,11 +236,9 @@ pub trait PrimeFieldExt: PrimeField {
impl<G: Group, T: TranscriptReprTrait<G>> TranscriptReprTrait<G> for &[T] {
fn to_transcript_bytes(&self) -> Vec<u8> {
(0..self.len())
.map(|i| self[i].to_transcript_bytes())
.collect::<Vec<_>>()
.into_iter()
.flatten()
self
.iter()
.flat_map(|t| t.to_transcript_bytes())
.collect::<Vec<u8>>()
}
}