Skip to content

Commit

Permalink
Merge remote-tracking branch 'microsoft/main' into antonio-cesar/less…
Browse files Browse the repository at this point in the history
…-than
  • Loading branch information
Antonio95 committed Sep 23, 2024
2 parents 900e34c + afbf72b commit 997a78d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 167 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ default = []
# Compiles in portable mode, w/o ISA extensions => binary can be executed on all systems.
portable = ["pasta-msm/portable"]
flamegraph = ["pprof/flamegraph", "pprof/criterion"]

[[bench]]
name = "bench"
harness = false
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ Any use of third-party trademarks or logos are subject to those third-party's po
## Examples

Run `cargo run --example EXAMPLE_NAME` to run the corresponding example. Leave `EXAMPLE_NAME` empty for a list of available examples.

## Benchmarks

Run `cargo bench` to run all benchmarks. Run `cargo bench --benches BENCH_NAME` to run a specific benchmark.
29 changes: 29 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate core;

use criterion::{criterion_group, criterion_main, Criterion};
use ff::Field;
use pasta_curves::Fp;

use spartan2::spartan::polys::eq::EqPolynomial;

fn benchmarks_evaluate_incremental(c: &mut Criterion) {
let mut group = c.benchmark_group("evaluate_incremental");
(1..=20).step_by(2).for_each(|i| {
let random_point: Vec<Fp> = (0..2usize.pow(i))
.map(|_| Fp::random(&mut rand::thread_rng()))
.collect();
let random_polynomial = EqPolynomial::new(
(0..2usize.pow(i))
.map(|_| Fp::random(&mut rand::thread_rng()))
.collect(),
);
group.bench_with_input(format!("2^{}", i), &i, |b, &_i| {
b.iter(|| {
random_polynomial.evaluate(random_point.as_slice());
});
});
});
}

criterion_group!(benches, benchmarks_evaluate_incremental);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/provider/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod tests {
fn test_keccak_example() {
let mut hasher = Keccak256::new();
hasher.update(0xffffffff_u32.to_le_bytes());
let output: [u8; 32] = hasher.finalize().try_into().unwrap();
let output: [u8; 32] = hasher.finalize().into();
assert_eq!(
hex::encode(output),
"29045a592007d0c246ef02c2223570da9522d0cf0f73282c79a1bc8f0bb2c238"
Expand Down
163 changes: 0 additions & 163 deletions src/spartan/polynomial.rs

This file was deleted.

4 changes: 3 additions & 1 deletion src/spartan/polys/eq.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! `EqPolynomial`: Represents multilinear extension of equality polynomials, evaluated based on binary input values.
use ff::PrimeField;
use rayon::iter::IntoParallelIterator;
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};

/// Represents the multilinear extension polynomial (MLE) of the equality polynomial $eq(x,e)$, denoted as $\tilde{eq}(x, e)$.
Expand Down Expand Up @@ -35,8 +36,9 @@ impl<Scalar: PrimeField> EqPolynomial<Scalar> {
pub fn evaluate(&self, rx: &[Scalar]) -> Scalar {
assert_eq!(self.r.len(), rx.len());
(0..rx.len())
.into_par_iter()
.map(|i| rx[i] * self.r[i] + (Scalar::ONE - rx[i]) * (Scalar::ONE - self.r[i]))
.fold(Scalar::ONE, |acc, item| acc * item)
.product()
}

/// Evaluates the `EqPolynomial` at all the `2^|r|` points in its domain.
Expand Down
4 changes: 2 additions & 2 deletions src/spartan/sumcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl<G: Group> SumcheckProof<G> {
pub fn prove_quad_batch<F>(
claim: &G::Scalar,
num_rounds: usize,
poly_A_vec: &mut Vec<MultilinearPolynomial<G::Scalar>>,
poly_B_vec: &mut Vec<MultilinearPolynomial<G::Scalar>>,
poly_A_vec: &mut [MultilinearPolynomial<G::Scalar>],
poly_B_vec: &mut [MultilinearPolynomial<G::Scalar>],
coeffs: &[G::Scalar],
comb_func: F,
transcript: &mut G::TE,
Expand Down

0 comments on commit 997a78d

Please sign in to comment.