mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Merge pull request #40 from mir-protocol/move_timed
Move timed! and call from ListPolynomialCommitment
This commit is contained in:
commit
13fc0c2261
@ -1,3 +1,6 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::field::field::Field;
|
use crate::field::field::Field;
|
||||||
use crate::field::lagrange::interpolant;
|
use crate::field::lagrange::interpolant;
|
||||||
use crate::fri::{prover::fri_proof, verifier::verify_fri_proof, FriConfig};
|
use crate::fri::{prover::fri_proof, verifier::verify_fri_proof, FriConfig};
|
||||||
@ -6,9 +9,8 @@ use crate::plonk_challenger::Challenger;
|
|||||||
use crate::plonk_common::reduce_with_powers;
|
use crate::plonk_common::reduce_with_powers;
|
||||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||||
use crate::proof::{FriProof, Hash, OpeningSet};
|
use crate::proof::{FriProof, Hash, OpeningSet};
|
||||||
|
use crate::timed;
|
||||||
use crate::util::{log2_strict, reverse_index_bits_in_place, transpose};
|
use crate::util::{log2_strict, reverse_index_bits_in_place, transpose};
|
||||||
use anyhow::Result;
|
|
||||||
use rayon::prelude::*;
|
|
||||||
|
|
||||||
pub const SALT_SIZE: usize = 2;
|
pub const SALT_SIZE: usize = 2;
|
||||||
|
|
||||||
@ -23,7 +25,31 @@ pub struct ListPolynomialCommitment<F: Field> {
|
|||||||
impl<F: Field> ListPolynomialCommitment<F> {
|
impl<F: Field> ListPolynomialCommitment<F> {
|
||||||
pub fn new(polynomials: Vec<PolynomialCoeffs<F>>, rate_bits: usize, blinding: bool) -> Self {
|
pub fn new(polynomials: Vec<PolynomialCoeffs<F>>, rate_bits: usize, blinding: bool) -> Self {
|
||||||
let degree = polynomials[0].len();
|
let degree = polynomials[0].len();
|
||||||
let lde_values = polynomials
|
let lde_values = timed!(
|
||||||
|
Self::lde_values(&polynomials, rate_bits, blinding),
|
||||||
|
"to compute LDE"
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut leaves = timed!(transpose(&lde_values), "to transpose LDEs");
|
||||||
|
reverse_index_bits_in_place(&mut leaves);
|
||||||
|
let merkle_tree = timed!(MerkleTree::new(leaves, false), "to build Merkle tree");
|
||||||
|
|
||||||
|
Self {
|
||||||
|
polynomials,
|
||||||
|
merkle_tree,
|
||||||
|
degree,
|
||||||
|
rate_bits,
|
||||||
|
blinding,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lde_values(
|
||||||
|
polynomials: &[PolynomialCoeffs<F>],
|
||||||
|
rate_bits: usize,
|
||||||
|
blinding: bool,
|
||||||
|
) -> Vec<Vec<F>> {
|
||||||
|
let degree = polynomials[0].len();
|
||||||
|
polynomials
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
assert_eq!(p.len(), degree, "Polynomial degree invalid.");
|
assert_eq!(p.len(), degree, "Polynomial degree invalid.");
|
||||||
@ -40,19 +66,7 @@ impl<F: Field> ListPolynomialCommitment<F> {
|
|||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect()
|
||||||
|
|
||||||
let mut leaves = transpose(&lde_values);
|
|
||||||
reverse_index_bits_in_place(&mut leaves);
|
|
||||||
let merkle_tree = MerkleTree::new(leaves, false);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
polynomials,
|
|
||||||
merkle_tree,
|
|
||||||
degree,
|
|
||||||
rate_bits,
|
|
||||||
blinding,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leaf(&self, index: usize) -> &[F] {
|
pub fn leaf(&self, index: usize) -> &[F] {
|
||||||
@ -323,10 +337,12 @@ impl<F: Field> OpeningProof<F> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use crate::field::crandall_field::CrandallField;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
use crate::field::crandall_field::CrandallField;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
fn gen_random_test_case<F: Field>(
|
fn gen_random_test_case<F: Field>(
|
||||||
k: usize,
|
k: usize,
|
||||||
degree_log: usize,
|
degree_log: usize,
|
||||||
|
|||||||
@ -12,20 +12,12 @@ use crate::plonk_common::{eval_l_1, evaluate_gate_constraints, reduce_with_power
|
|||||||
use crate::polynomial::commitment::ListPolynomialCommitment;
|
use crate::polynomial::commitment::ListPolynomialCommitment;
|
||||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||||
use crate::proof::Proof;
|
use crate::proof::Proof;
|
||||||
|
use crate::timed;
|
||||||
use crate::util::transpose;
|
use crate::util::transpose;
|
||||||
use crate::vars::EvaluationVars;
|
use crate::vars::EvaluationVars;
|
||||||
use crate::wire::Wire;
|
use crate::wire::Wire;
|
||||||
use crate::witness::PartialWitness;
|
use crate::witness::PartialWitness;
|
||||||
|
|
||||||
macro_rules! timed {
|
|
||||||
($a:expr, $msg:expr) => {{
|
|
||||||
let timer = Instant::now();
|
|
||||||
let res = $a;
|
|
||||||
info!("{:.3}s {}", timer.elapsed().as_secs_f32(), $msg);
|
|
||||||
res
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Corresponds to constants - sigmas - wires - zs - quotient — polynomial commitments.
|
/// Corresponds to constants - sigmas - wires - zs - quotient — polynomial commitments.
|
||||||
pub const PLONK_BLINDING: [bool; 5] = [false, false, true, true, true];
|
pub const PLONK_BLINDING: [bool; 5] = [false, false, true, true, true];
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
pub(crate) mod timing;
|
||||||
|
|
||||||
use crate::field::field::Field;
|
use crate::field::field::Field;
|
||||||
use crate::polynomial::polynomial::PolynomialValues;
|
use crate::polynomial::polynomial::PolynomialValues;
|
||||||
|
|
||||||
13
src/util/timing.rs
Normal file
13
src/util/timing.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! timed {
|
||||||
|
($a:expr, $msg:expr) => {{
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
let timer = Instant::now();
|
||||||
|
let res = $a;
|
||||||
|
info!("{:.3}s {}", timer.elapsed().as_secs_f32(), $msg);
|
||||||
|
res
|
||||||
|
}};
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user