mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 06:13:07 +00:00
Generic tests
This commit is contained in:
parent
adf5c2d4ec
commit
9cd00532ce
@ -9,7 +9,6 @@ use plonky2::fri::FriConfig;
|
||||
use plonky2::gates::constant::ConstantGate;
|
||||
use plonky2::gates::gmimc::GMiMCGate;
|
||||
use plonky2::hash::GMIMC_ROUNDS;
|
||||
use plonky2::polynomial::commitment::EXTENSION_DEGREE;
|
||||
use plonky2::prover::PLONK_BLINDING;
|
||||
use plonky2::witness::PartialWitness;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::fri::FriConfig;
|
||||
use crate::gates::gate::GateRef;
|
||||
use crate::generator::WitnessGenerator;
|
||||
use crate::merkle_tree::MerkleTree;
|
||||
use crate::polynomial::commitment::{ListPolynomialCommitment, EXTENSION_DEGREE};
|
||||
use crate::polynomial::commitment::ListPolynomialCommitment;
|
||||
use crate::proof::{Hash, HashTarget, Proof};
|
||||
use crate::prover::prove;
|
||||
use crate::verifier::verify;
|
||||
|
||||
@ -54,29 +54,25 @@ mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quadratic::QuadraticCrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::extension_field::{flatten, FieldExtension};
|
||||
use crate::field::extension_field::{flatten, Extendable, FieldExtension};
|
||||
use crate::field::fft::ifft;
|
||||
use crate::field::field::Field;
|
||||
use crate::fri::prover::fri_proof;
|
||||
use crate::fri::verifier::verify_fri_proof;
|
||||
use crate::merkle_tree::MerkleTree;
|
||||
use crate::plonk_challenger::Challenger;
|
||||
use crate::polynomial::commitment::EXTENSION_DEGREE;
|
||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||
use crate::util::reverse_index_bits_in_place;
|
||||
use anyhow::Result;
|
||||
use rand::rngs::ThreadRng;
|
||||
use rand::Rng;
|
||||
|
||||
fn test_fri(
|
||||
fn check_fri<F: Field + Extendable<D>, const D: usize>(
|
||||
degree_log: usize,
|
||||
rate_bits: usize,
|
||||
reduction_arity_bits: Vec<usize>,
|
||||
num_query_rounds: usize,
|
||||
) -> Result<()> {
|
||||
type F = CrandallField;
|
||||
type F2 = QuadraticCrandallField;
|
||||
|
||||
let n = 1 << degree_log;
|
||||
let coeffs = PolynomialCoeffs::new(F::rand_vec(n)).lde(rate_bits);
|
||||
let coset_lde = coeffs.clone().coset_fft(F::MULTIPLICATIVE_GROUP_GENERATOR);
|
||||
@ -96,13 +92,18 @@ mod tests {
|
||||
reverse_index_bits_in_place(&mut leaves);
|
||||
MerkleTree::new(leaves, false)
|
||||
};
|
||||
let coset_lde =
|
||||
PolynomialValues::new(coset_lde.values.into_iter().map(|x| F2::from(x)).collect());
|
||||
let coset_lde = PolynomialValues::new(
|
||||
coset_lde
|
||||
.values
|
||||
.into_iter()
|
||||
.map(|x| F::Extension::from(x))
|
||||
.collect(),
|
||||
);
|
||||
let root = tree.root;
|
||||
let mut challenger = Challenger::new();
|
||||
let proof = fri_proof::<F, 2>(
|
||||
let proof = fri_proof::<F, D>(
|
||||
&[&tree],
|
||||
&coeffs.to_extension::<2>(),
|
||||
&coeffs.to_extension::<D>(),
|
||||
&coset_lde,
|
||||
&mut challenger,
|
||||
&config,
|
||||
@ -112,7 +113,7 @@ mod tests {
|
||||
verify_fri_proof(
|
||||
degree_log,
|
||||
&[],
|
||||
F2::ONE,
|
||||
F::Extension::ONE,
|
||||
&[root],
|
||||
&proof,
|
||||
&mut challenger,
|
||||
@ -133,14 +134,13 @@ mod tests {
|
||||
arities
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fri_multi_params() -> Result<()> {
|
||||
fn check_fri_multi_params<F: Field + Extendable<D>, const D: usize>() -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
for degree_log in 1..6 {
|
||||
for rate_bits in 0..3 {
|
||||
for num_query_round in 0..4 {
|
||||
for _ in 0..3 {
|
||||
test_fri(
|
||||
check_fri::<F, D>(
|
||||
degree_log,
|
||||
rate_bits,
|
||||
gen_arities(degree_log, &mut rng),
|
||||
@ -152,4 +152,37 @@ mod tests {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
mod base {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 1;
|
||||
|
||||
#[test]
|
||||
fn test_fri_multi_params() -> Result<()> {
|
||||
check_fri_multi_params::<F, D>()
|
||||
}
|
||||
}
|
||||
|
||||
mod quadratic {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 2;
|
||||
|
||||
#[test]
|
||||
fn test_fri_multi_params() -> Result<()> {
|
||||
check_fri_multi_params::<F, D>()
|
||||
}
|
||||
}
|
||||
|
||||
mod quartic {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 4;
|
||||
|
||||
#[test]
|
||||
fn test_fri_multi_params() -> Result<()> {
|
||||
check_fri_multi_params::<F, D>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ use crate::hash::hash_n_to_1;
|
||||
use crate::merkle_tree::MerkleTree;
|
||||
use crate::plonk_challenger::Challenger;
|
||||
use crate::plonk_common::reduce_with_powers;
|
||||
use crate::polynomial::commitment::EXTENSION_DEGREE;
|
||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||
use crate::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep, Hash};
|
||||
use crate::util::reverse_index_bits_in_place;
|
||||
@ -136,7 +135,6 @@ fn fri_prover_query_round<F: Field + Extendable<D>, const D: usize>(
|
||||
let mut query_steps = Vec::new();
|
||||
let x = challenger.get_challenge();
|
||||
let mut x_index = x.to_canonical_u64() as usize % n;
|
||||
dbg!(x_index, n);
|
||||
let initial_proof = initial_merkle_trees
|
||||
.iter()
|
||||
.map(|t| (t.get(x_index).to_vec(), t.prove(x_index)))
|
||||
|
||||
@ -5,7 +5,7 @@ use crate::fri::FriConfig;
|
||||
use crate::hash::hash_n_to_1;
|
||||
use crate::merkle_proofs::verify_merkle_proof;
|
||||
use crate::plonk_challenger::Challenger;
|
||||
use crate::polynomial::commitment::{EXTENSION_DEGREE, SALT_SIZE};
|
||||
use crate::polynomial::commitment::SALT_SIZE;
|
||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||
use crate::proof::{FriInitialTreeProof, FriProof, FriQueryRound, Hash};
|
||||
use crate::util::{log2_strict, reverse_bits, reverse_index_bits_in_place};
|
||||
@ -35,7 +35,6 @@ fn compute_evaluation<F: Field + Extendable<D>, const D: usize>(
|
||||
.zip(evals)
|
||||
.map(|(y, e)| ((x * y).into(), e))
|
||||
.collect::<Vec<_>>();
|
||||
dbg!(&points);
|
||||
let barycentric_weights = barycentric_weights(&points);
|
||||
interpolate(&points, beta, &barycentric_weights)
|
||||
}
|
||||
|
||||
@ -381,10 +381,7 @@ mod tests {
|
||||
(polys, points)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment() -> Result<()> {
|
||||
type F = CrandallField;
|
||||
|
||||
fn check_polynomial_commitment<F: Field + Extendable<D>, const D: usize>() -> Result<()> {
|
||||
let k = 10;
|
||||
let degree_log = 11;
|
||||
let num_points = 3;
|
||||
@ -395,10 +392,10 @@ mod tests {
|
||||
num_query_rounds: 3,
|
||||
blinding: vec![false],
|
||||
};
|
||||
let (polys, points) = gen_random_test_case::<F, 2>(k, degree_log, num_points);
|
||||
let (polys, points) = gen_random_test_case::<F, D>(k, degree_log, num_points);
|
||||
|
||||
let lpc = ListPolynomialCommitment::new(polys, fri_config.rate_bits, false);
|
||||
let (proof, evaluations) = lpc.open::<2>(&points, &mut Challenger::new(), &fri_config);
|
||||
let (proof, evaluations) = lpc.open::<D>(&points, &mut Challenger::new(), &fri_config);
|
||||
proof.verify(
|
||||
&points,
|
||||
&evaluations.into_iter().map(|e| vec![e]).collect::<Vec<_>>(),
|
||||
@ -408,10 +405,8 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment_blinding() -> Result<()> {
|
||||
type F = CrandallField;
|
||||
|
||||
fn check_polynomial_commitment_blinding<F: Field + Extendable<D>, const D: usize>() -> Result<()>
|
||||
{
|
||||
let k = 10;
|
||||
let degree_log = 11;
|
||||
let num_points = 3;
|
||||
@ -422,10 +417,10 @@ mod tests {
|
||||
num_query_rounds: 3,
|
||||
blinding: vec![true],
|
||||
};
|
||||
let (polys, points) = gen_random_test_case::<F, 2>(k, degree_log, num_points);
|
||||
let (polys, points) = gen_random_test_case::<F, D>(k, degree_log, num_points);
|
||||
|
||||
let lpc = ListPolynomialCommitment::new(polys, fri_config.rate_bits, true);
|
||||
let (proof, evaluations) = lpc.open::<2>(&points, &mut Challenger::new(), &fri_config);
|
||||
let (proof, evaluations) = lpc.open::<D>(&points, &mut Challenger::new(), &fri_config);
|
||||
proof.verify(
|
||||
&points,
|
||||
&evaluations.into_iter().map(|e| vec![e]).collect::<Vec<_>>(),
|
||||
@ -435,10 +430,7 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment() -> Result<()> {
|
||||
type F = CrandallField;
|
||||
|
||||
fn check_batch_polynomial_commitment<F: Field + Extendable<D>, const D: usize>() -> Result<()> {
|
||||
let k0 = 10;
|
||||
let k1 = 3;
|
||||
let k2 = 7;
|
||||
@ -451,15 +443,15 @@ mod tests {
|
||||
num_query_rounds: 3,
|
||||
blinding: vec![false, false, false],
|
||||
};
|
||||
let (polys0, _) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys1, _) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys2, points) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys0, _) = gen_random_test_case::<F, D>(k0, degree_log, num_points);
|
||||
let (polys1, _) = gen_random_test_case::<F, D>(k1, degree_log, num_points);
|
||||
let (polys2, points) = gen_random_test_case::<F, D>(k2, degree_log, num_points);
|
||||
|
||||
let lpc0 = ListPolynomialCommitment::new(polys0, fri_config.rate_bits, false);
|
||||
let lpc1 = ListPolynomialCommitment::new(polys1, fri_config.rate_bits, false);
|
||||
let lpc2 = ListPolynomialCommitment::new(polys2, fri_config.rate_bits, false);
|
||||
|
||||
let (proof, evaluations) = ListPolynomialCommitment::batch_open::<2>(
|
||||
let (proof, evaluations) = ListPolynomialCommitment::batch_open::<D>(
|
||||
&[&lpc0, &lpc1, &lpc2],
|
||||
&points,
|
||||
&mut Challenger::new(),
|
||||
@ -478,10 +470,8 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment_blinding() -> Result<()> {
|
||||
type F = CrandallField;
|
||||
|
||||
fn check_batch_polynomial_commitment_blinding<F: Field + Extendable<D>, const D: usize>(
|
||||
) -> Result<()> {
|
||||
let k0 = 10;
|
||||
let k1 = 3;
|
||||
let k2 = 7;
|
||||
@ -494,15 +484,15 @@ mod tests {
|
||||
num_query_rounds: 3,
|
||||
blinding: vec![true, false, true],
|
||||
};
|
||||
let (polys0, _) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys1, _) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys2, points) = gen_random_test_case::<F, 2>(k0, degree_log, num_points);
|
||||
let (polys0, _) = gen_random_test_case::<F, D>(k0, degree_log, num_points);
|
||||
let (polys1, _) = gen_random_test_case::<F, D>(k1, degree_log, num_points);
|
||||
let (polys2, points) = gen_random_test_case::<F, D>(k2, degree_log, num_points);
|
||||
|
||||
let lpc0 = ListPolynomialCommitment::new(polys0, fri_config.rate_bits, true);
|
||||
let lpc1 = ListPolynomialCommitment::new(polys1, fri_config.rate_bits, false);
|
||||
let lpc2 = ListPolynomialCommitment::new(polys2, fri_config.rate_bits, true);
|
||||
|
||||
let (proof, evaluations) = ListPolynomialCommitment::batch_open::<2>(
|
||||
let (proof, evaluations) = ListPolynomialCommitment::batch_open::<D>(
|
||||
&[&lpc0, &lpc1, &lpc2],
|
||||
&points,
|
||||
&mut Challenger::new(),
|
||||
@ -520,4 +510,82 @@ mod tests {
|
||||
&fri_config,
|
||||
)
|
||||
}
|
||||
|
||||
mod base {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 1;
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment() -> Result<()> {
|
||||
check_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment() -> Result<()> {
|
||||
check_batch_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_batch_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
}
|
||||
|
||||
mod quadratic {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 2;
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment() -> Result<()> {
|
||||
check_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment() -> Result<()> {
|
||||
check_batch_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_batch_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
}
|
||||
|
||||
mod quartic {
|
||||
use super::*;
|
||||
type F = CrandallField;
|
||||
const D: usize = 4;
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment() -> Result<()> {
|
||||
check_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment() -> Result<()> {
|
||||
check_batch_polynomial_commitment::<F, D>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_polynomial_commitment_blinding() -> Result<()> {
|
||||
check_batch_polynomial_commitment_blinding::<F, D>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::merkle_proofs::{MerkleProof, MerkleProofTarget};
|
||||
use crate::polynomial::commitment::{ListPolynomialCommitment, OpeningProof, EXTENSION_DEGREE};
|
||||
use crate::polynomial::commitment::{ListPolynomialCommitment, OpeningProof};
|
||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||
use crate::target::Target;
|
||||
use std::convert::TryInto;
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::field::field::Field;
|
||||
use crate::generator::generate_partial_witness;
|
||||
use crate::plonk_challenger::Challenger;
|
||||
use crate::plonk_common::{eval_l_1, evaluate_gate_constraints, reduce_with_powers_multi};
|
||||
use crate::polynomial::commitment::{ListPolynomialCommitment, EXTENSION_DEGREE};
|
||||
use crate::polynomial::commitment::ListPolynomialCommitment;
|
||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||
use crate::proof::Proof;
|
||||
use crate::timed;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user