Skip to content

Commit

Permalink
fix: eval_table
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Feb 23, 2024
1 parent ebf6a0c commit f4ec232
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/spartan/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,15 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> BatchedRelaxedR1CSSNARKTrait<E>
)
}

let chis_r_x = r_x
.par_iter()
.map(|r_x| EqPolynomial::evals_from_points(r_x))
.collect::<Vec<_>>();

// Evaluate τ(rₓ) for each instance
let evals_tau = zip_with!(iter, (polys_tau, r_x), |poly_tau, r_x| poly_tau
.evaluate(r_x));
let evals_tau = zip_with!(iter, (polys_tau, chis_r_x), |poly_tau, er_x| {
MultilinearPolynomial::evaluate_with_chis(poly_tau.evaluations(), er_x)
});

// Compute expected claim for all instances ∑ᵢ rⁱ⋅τ(rₓ)⋅(Azᵢ⋅Bzᵢ − uᵢ⋅Czᵢ − Eᵢ)
let claim_outer_final_expected = zip_with!(
Expand Down Expand Up @@ -503,7 +509,7 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> BatchedRelaxedR1CSSNARKTrait<E>

// compute evaluations of R1CS matrices M(r_x, r_y) = eq(r_y)ᵀ⋅M⋅eq(r_x)
let multi_evaluate = |M_vec: &[&SparseMatrix<E::Scalar>],
r_x: &[E::Scalar],
chi_r_x: &[E::Scalar],
r_y: &[E::Scalar]|
-> Vec<E::Scalar> {
let evaluate_with_table =
Expand All @@ -520,21 +526,19 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> BatchedRelaxedR1CSSNARKTrait<E>
.sum()
};

let (T_x, T_y) = rayon::join(
|| EqPolynomial::evals_from_points(r_x),
|| EqPolynomial::evals_from_points(r_y),
);
let T_x = chi_r_x;
let T_y = EqPolynomial::evals_from_points(r_y);

M_vec
.par_iter()
.map(|&M_vec| evaluate_with_table(M_vec, &T_x, &T_y))
.map(|&M_vec| evaluate_with_table(M_vec, T_x, &T_y))
.collect()
};

// Compute inner claim ∑ᵢ r³ⁱ⋅(Aᵢ(r_x, r_y) + r⋅Bᵢ(r_x, r_y) + r²⋅Cᵢ(r_x, r_y))⋅Zᵢ(r_y)
let claim_inner_final_expected = zip_with!(
iter,
(vk.S, r_x, r_y, evals_Z, inner_r_powers),
(vk.S, chis_r_x, r_y, evals_Z, inner_r_powers),
|S, r_x, r_y, eval_Z, r_i| {
let evals = multi_evaluate(&[&S.A, &S.B, &S.C], r_x, r_y);
let eval = evals[0] + inner_r * evals[1] + inner_r_square * evals[2];
Expand Down
6 changes: 1 addition & 5 deletions src/spartan/polys/multilinear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ impl<Scalar: PrimeField> MultilinearPolynomial<Scalar> {

/// Evaluates the polynomial with the given evaluations and chi coefficients
pub fn evaluate_with_chis(Z: &[Scalar], chis: &[Scalar]) -> Scalar {
zip_with!(
(chis.into_par_iter(), Z.par_iter()),
|a, b| *a * b
)
.sum()
zip_with!(par_iter, (chis, Z), |a, b| *a * b).sum()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/supernova/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Supernova implementation support arbitrary argumented circuits and running instances.
//! There are two Verification Circuits for each argumented circuit: The primary and the secondary.
//! Each of them is over a Pasta curve but
//! Each of them is over a cycle curve but
//! only the primary executes the next step of the computation.
//! Each circuit takes as input 2 hashes.
//! Each circuit folds the last invocation of the other into the respective running instance, specified by `augmented_circuit_index`
Expand All @@ -10,7 +10,7 @@
//! 1. Ui[] are contained in X[0] hash pre-image.
//! 2. R1CS Instance u is folded into Ui[augmented_circuit_index] correctly; just like Nova IVC.
//! 3. (optional by F logic) F circuit might check `program_counter_{i}` invoked current F circuit is legal or not.
//! 3. F circuit produce `program_counter_{i+1}` and sent to next round for optionally constraint the next F' argumented circuit.
//! 3. F circuit produce `program_counter_{i+1}` and sent to next round to optionally constraint the next F' argumented circuit.
use crate::{
constants::{NIO_NOVA_FOLD, NUM_HASH_BITS},
gadgets::{
Expand Down
1 change: 1 addition & 0 deletions src/supernova/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn get_from_vec_alloc_relaxed_r1cs<E: Engine, CS: ConstraintSystem<<E as Eng
// Since `selector_vec` is correct, only one entry is 1.
// If selector_vec[0] is 1, then all `conditionally_select` will return `first`.
// Otherwise, the correct instance will be selected.
// TODO: reformulate when iterator_try_reduce stabilizes
let selected = a
.iter()
.zip_eq(selector_vec.iter())
Expand Down

0 comments on commit f4ec232

Please sign in to comment.