mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-06 15:53:10 +00:00
Minor fixes
This commit is contained in:
parent
03d761ead6
commit
477fe1ea4a
@ -269,6 +269,10 @@ pub trait Field:
|
||||
fn rand() -> Self {
|
||||
Self::rand_from_rng(&mut OsRng)
|
||||
}
|
||||
|
||||
fn rand_vec(n: usize) -> Vec<Self> {
|
||||
(0..n).map(|_| Self::rand()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over the powers of a certain base element `b`: `b^0, b^1, b^2, ...`.
|
||||
|
||||
@ -77,8 +77,8 @@ mod tests {
|
||||
type F = CrandallField;
|
||||
|
||||
for deg in 0..10 {
|
||||
let domain = (0..deg).map(|_| F::rand()).collect::<Vec<_>>();
|
||||
let coeffs = (0..deg).map(|_| F::rand()).collect();
|
||||
let domain = F::rand_vec(deg);
|
||||
let coeffs = F::rand_vec(deg);
|
||||
let coeffs = PolynomialCoeffs { coeffs };
|
||||
|
||||
let points = eval_naive(&coeffs, &domain);
|
||||
@ -94,7 +94,7 @@ mod tests {
|
||||
let deg = 1 << deg_log;
|
||||
let g = F::primitive_root_of_unity(deg_log);
|
||||
let domain = F::cyclic_subgroup_known_order(g, deg);
|
||||
let coeffs = (0..deg).map(|_| F::rand()).collect();
|
||||
let coeffs = F::rand_vec(deg);
|
||||
let coeffs = PolynomialCoeffs { coeffs };
|
||||
|
||||
let points = eval_naive(&coeffs, &domain);
|
||||
@ -108,8 +108,8 @@ mod tests {
|
||||
|
||||
for deg in 0..10 {
|
||||
let points = deg + 5;
|
||||
let domain = (0..points).map(|_| F::rand()).collect::<Vec<_>>();
|
||||
let coeffs = (0..deg).map(|_| F::rand()).collect();
|
||||
let domain = F::rand_vec(points);
|
||||
let coeffs = F::rand_vec(deg);
|
||||
let coeffs = PolynomialCoeffs { coeffs };
|
||||
|
||||
let points = eval_naive(&coeffs, &domain);
|
||||
|
||||
@ -72,7 +72,7 @@ mod tests {
|
||||
type F = CrandallField;
|
||||
|
||||
let n = 1 << degree_log;
|
||||
let coeffs = PolynomialCoeffs::new((0..n).map(|_| F::rand()).collect()).lde(rate_bits);
|
||||
let coeffs = PolynomialCoeffs::new(F::rand_vec(n)).lde(rate_bits);
|
||||
let coset_lde = coeffs.clone().coset_fft(F::MULTIPLICATIVE_GROUP_GENERATOR);
|
||||
let config = FriConfig {
|
||||
num_query_rounds,
|
||||
|
||||
@ -90,9 +90,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
fn random_data<F: Field>(n: usize, k: usize) -> Vec<Vec<F>> {
|
||||
(0..n)
|
||||
.map(|_| (0..k).map(|_| F::rand()).collect())
|
||||
.collect()
|
||||
(0..n).map(|_| F::rand_vec(k)).collect()
|
||||
}
|
||||
|
||||
fn verify_all_leaves<F: Field>(
|
||||
|
||||
@ -258,7 +258,7 @@ mod tests {
|
||||
// Generate random input messages.
|
||||
let inputs_per_round: Vec<Vec<F>> = num_inputs_per_round
|
||||
.iter()
|
||||
.map(|&n| (0..n).map(|_| F::rand()).collect::<Vec<_>>())
|
||||
.map(|&n| F::rand_vec(n))
|
||||
.collect();
|
||||
|
||||
let mut challenger = Challenger::new();
|
||||
|
||||
@ -32,11 +32,7 @@ impl<F: Field> ListPolynomialCommitment<F> {
|
||||
.chain(if fri_config.blinding {
|
||||
// If blinding, salt with two random elements to each leaf vector.
|
||||
(0..2)
|
||||
.map(|_| {
|
||||
(0..(degree << fri_config.rate_bits))
|
||||
.map(|_| F::rand())
|
||||
.collect()
|
||||
})
|
||||
.map(|_| F::rand_vec(degree << fri_config.rate_bits))
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
@ -150,6 +146,7 @@ impl<F: Field> ListPolynomialCommitment<F> {
|
||||
pub struct OpeningProof<F: Field> {
|
||||
merkle_root: Hash<F>,
|
||||
fri_proof: FriProof<F>,
|
||||
// TODO: Get the degree from `CommonCircuitData` instead.
|
||||
quotient_degree: usize,
|
||||
}
|
||||
|
||||
@ -197,10 +194,6 @@ mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use anyhow::Result;
|
||||
|
||||
fn rand_vec<F: Field>(n: usize) -> Vec<F> {
|
||||
(0..n).map(|_| F::rand()).collect()
|
||||
}
|
||||
|
||||
fn gen_random_test_case<F: Field>(
|
||||
k: usize,
|
||||
degree_log: usize,
|
||||
@ -209,11 +202,11 @@ mod tests {
|
||||
let degree = 1 << degree_log;
|
||||
|
||||
let polys = (0..k)
|
||||
.map(|_| PolynomialCoeffs::new(rand_vec(degree)))
|
||||
.map(|_| PolynomialCoeffs::new(F::rand_vec(degree)))
|
||||
.collect();
|
||||
let mut points = rand_vec::<F>(num_points);
|
||||
let mut points = F::rand_vec(num_points);
|
||||
while points.iter().any(|&x| x.exp_usize(degree).is_one()) {
|
||||
points = rand_vec(num_points);
|
||||
points = F::rand_vec(num_points);
|
||||
}
|
||||
|
||||
(polys, points)
|
||||
|
||||
@ -417,8 +417,8 @@ mod test {
|
||||
type F = CrandallField;
|
||||
let mut rng = thread_rng();
|
||||
let (a_deg, b_deg) = (rng.gen_range(1, 10_000), rng.gen_range(1, 10_000));
|
||||
let a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let b = Polynomial((0..b_deg).map(|_| F::rand()).collect());
|
||||
let a = Polynomial(F::rand_vec(a_deg));
|
||||
let b = Polynomial(F::rand_vec(b_deg));
|
||||
let m1 = a.mul(&b);
|
||||
let m2 = a.mul(&b);
|
||||
for _ in 0..1000 {
|
||||
@ -434,7 +434,7 @@ mod test {
|
||||
let mut rng = thread_rng();
|
||||
let a_deg = rng.gen_range(1, 1_000);
|
||||
let n = rng.gen_range(1, 1_000);
|
||||
let a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let a = Polynomial(F::rand_vec(a_deg));
|
||||
let b = a.inv_mod_xn(n);
|
||||
let mut m = a.mul(&b);
|
||||
m.drain(n..);
|
||||
@ -455,8 +455,8 @@ mod test {
|
||||
type F = CrandallField;
|
||||
let mut rng = thread_rng();
|
||||
let (a_deg, b_deg) = (rng.gen_range(1, 10_000), rng.gen_range(1, 10_000));
|
||||
let a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let b = Polynomial((0..b_deg).map(|_| F::rand()).collect());
|
||||
let a = Polynomial(F::rand_vec(a_deg));
|
||||
let b = Polynomial(F::rand_vec(b_deg));
|
||||
let (q, r) = a.polynomial_long_division(&b);
|
||||
for _ in 0..1000 {
|
||||
let x = F::rand();
|
||||
@ -469,8 +469,8 @@ mod test {
|
||||
type F = CrandallField;
|
||||
let mut rng = thread_rng();
|
||||
let (a_deg, b_deg) = (rng.gen_range(1, 10_000), rng.gen_range(1, 10_000));
|
||||
let a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let b = Polynomial((0..b_deg).map(|_| F::rand()).collect());
|
||||
let a = Polynomial(F::rand_vec(a_deg));
|
||||
let b = Polynomial(F::rand_vec(b_deg));
|
||||
let (q, r) = a.polynomial_division(&b);
|
||||
for _ in 0..1000 {
|
||||
let x = F::rand();
|
||||
@ -483,7 +483,7 @@ mod test {
|
||||
type F = CrandallField;
|
||||
let mut rng = thread_rng();
|
||||
let a_deg = rng.gen_range(1, 10_000);
|
||||
let a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let a = Polynomial(F::rand_vec(a_deg));
|
||||
let b = Polynomial::from(vec![F::rand()]);
|
||||
let (q, r) = a.polynomial_division(&b);
|
||||
for _ in 0..1000 {
|
||||
@ -498,7 +498,7 @@ mod test {
|
||||
let mut rng = thread_rng();
|
||||
let a_deg = rng.gen_range(1, 10_000);
|
||||
let n = rng.gen_range(1, a_deg);
|
||||
let mut a = Polynomial((0..a_deg).map(|_| F::rand()).collect());
|
||||
let mut a = Polynomial(F::rand_vec(a_deg));
|
||||
a.trim();
|
||||
let z_h = {
|
||||
let mut z_h_vec = vec![F::ZERO; n + 1];
|
||||
|
||||
@ -148,7 +148,7 @@ mod tests {
|
||||
|
||||
let k = 8;
|
||||
let n = 1 << k;
|
||||
let poly = PolynomialCoeffs::new((0..n).map(|_| F::rand()).collect());
|
||||
let poly = PolynomialCoeffs::new(F::rand_vec(n));
|
||||
let shift = F::rand();
|
||||
let coset_evals = poly.clone().coset_fft(shift).values;
|
||||
|
||||
|
||||
@ -90,7 +90,8 @@ pub struct FriQueryStep<F: Field> {
|
||||
pub merkle_proof: MerkleProof<F>,
|
||||
}
|
||||
|
||||
/// Evaluations and Merkle proof produced by the prover in a FRI query step.
|
||||
/// Evaluations and Merkle proofs of the original set of polynomials,
|
||||
/// before they are combined into a composition polynomial.
|
||||
// TODO: Implement FriInitialTreeProofTarget
|
||||
pub struct FriInitialTreeProof<F: Field> {
|
||||
pub evals_proofs: Vec<(Vec<F>, MerkleProof<F>)>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user