Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: define auxiliary functions for the batching of sumcheck claims (Arecibo backport) #273

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/spartan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ pub struct PolyEvalWitness<E: Engine> {
}

impl<E: Engine> PolyEvalWitness<E> {
fn pad(W: &[PolyEvalWitness<E>]) -> Vec<PolyEvalWitness<E>> {
fn pad(mut W: Vec<PolyEvalWitness<E>>) -> Vec<PolyEvalWitness<E>> {
// determine the maximum size
if let Some(n) = W.iter().map(|w| w.p.len()).max() {
W.iter()
.map(|w| {
let mut p = vec![E::Scalar::ZERO; n];
p[..w.p.len()].copy_from_slice(&w.p);
PolyEvalWitness { p }
})
.collect()
W.iter_mut().for_each(|w| {
w.p.resize(n, E::Scalar::ZERO);
});
W
} else {
Vec::new()
}
Expand Down Expand Up @@ -94,14 +91,14 @@ pub struct PolyEvalInstance<E: Engine> {
}

impl<E: Engine> PolyEvalInstance<E> {
fn pad(U: &[PolyEvalInstance<E>]) -> Vec<PolyEvalInstance<E>> {
fn pad(U: Vec<PolyEvalInstance<E>>) -> Vec<PolyEvalInstance<E>> {
// determine the maximum size
if let Some(ell) = U.iter().map(|u| u.x.len()).max() {
U.iter()
.map(|u| {
U.into_iter()
.map(|mut u| {
let mut x = vec![E::Scalar::ZERO; ell - u.x.len()];
x.extend(u.x.clone());
PolyEvalInstance { c: u.c, x, e: u.e }
x.append(&mut u.x);
PolyEvalInstance { x, ..u }
})
.collect()
} else {
Expand Down
22 changes: 11 additions & 11 deletions src/spartan/ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ impl<E: Engine> MemorySumcheckInstance<E> {
pub fn new(
ck: &CommitmentKey<E>,
r: &E::Scalar,
T_row: Vec<E::Scalar>,
W_row: Vec<E::Scalar>,
T_row: &[E::Scalar],
W_row: &[E::Scalar],
ts_row: Vec<E::Scalar>,
T_col: Vec<E::Scalar>,
W_col: Vec<E::Scalar>,
T_col: &[E::Scalar],
W_col: &[E::Scalar],
ts_col: Vec<E::Scalar>,
transcript: &mut E::TE,
) -> Result<(Self, [Commitment<E>; 4], [Vec<E::Scalar>; 4]), NovaError> {
Expand Down Expand Up @@ -362,8 +362,8 @@ impl<E: Engine> MemorySumcheckInstance<E> {
((t_plus_r_inv_row, w_plus_r_inv_row), (t_plus_r_row, w_plus_r_row)),
((t_plus_r_inv_col, w_plus_r_inv_col), (t_plus_r_col, w_plus_r_col)),
) = rayon::join(
|| helper(&T_row, &W_row, &ts_row, r),
|| helper(&T_col, &W_col, &ts_col, r),
|| helper(T_row, W_row, &ts_row, r),
|| helper(T_col, W_col, &ts_col, r),
);

let t_plus_r_inv_row = t_plus_r_inv_row?;
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
let u: PolyEvalInstance<E> = PolyEvalInstance::batch(&comm_vec, &tau_coords, &eval_vec, &c);

// we now need to prove three claims
// (1) 0 = \sum_x poly_tau(x) * (poly_Az(x) * poly_Bz(x) - poly_uCz_E(x)), and eval_Az_at_tau + r * eval_Az_at_tau + r^2 * eval_Cz_at_tau = (Az+r*Bz+r^2*Cz)(tau)
// (1) 0 = \sum_x poly_tau(x) * (poly_Az(x) * poly_Bz(x) - poly_uCz_E(x)), and eval_Az_at_tau + r * eval_Bz_at_tau + r^2 * eval_Cz_at_tau = (Az+r*Bz+r^2*Cz)(tau)
// (2) eval_Az_at_tau + c * eval_Bz_at_tau + c^2 * eval_Cz_at_tau = \sum_y L_row(y) * (val_A(y) + c * val_B(y) + c^2 * val_C(y)) * L_col(y)
// (3) L_row(i) = eq(tau, row(i)) and L_col(i) = z(col(i))
let gamma = transcript.squeeze(b"g")?;
Expand Down Expand Up @@ -1139,11 +1139,11 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> for Relax
MemorySumcheckInstance::new(
ck,
&r,
T_row,
W_row,
&T_row,
&W_row,
pk.S_repr.ts_row.clone(),
T_col,
W_col,
&T_col,
&W_col,
pk.S_repr.ts_col.clone(),
&mut transcript,
)
Expand Down
Loading
Loading