mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 06:43:07 +00:00
Clipp
This commit is contained in:
parent
7d41785ac6
commit
fe05da6720
@ -11,7 +11,6 @@ use crate::generator::WitnessGenerator;
|
||||
use crate::polynomial::commitment::ListPolynomialCommitment;
|
||||
use crate::proof::{Hash, HashTarget, Proof};
|
||||
use crate::prover::prove;
|
||||
use crate::target::Target;
|
||||
use crate::util::marking::MarkedTargets;
|
||||
use crate::verifier::verify;
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
use env_logger::builder;
|
||||
use itertools::izip;
|
||||
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::circuit_data::CommonCircuitData;
|
||||
use crate::field::extension_field::target::{flatten_target, ExtensionTarget};
|
||||
@ -120,7 +117,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
zeta,
|
||||
alpha,
|
||||
initial_merkle_roots,
|
||||
&proof,
|
||||
proof,
|
||||
challenger,
|
||||
n,
|
||||
&betas,
|
||||
@ -205,7 +202,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.take(common_data.zs_range().end)
|
||||
.map(|&e| self.convert_to_ext(e))
|
||||
.collect::<Vec<_>>();
|
||||
let mut zs_composition_eval = alpha.clone().reduce(&zs_evals, self);
|
||||
let zs_composition_eval = alpha.clone().reduce(&zs_evals, self);
|
||||
|
||||
let g = self.constant_extension(F::Extension::primitive_root_of_unity(degree_log));
|
||||
let zeta_right = self.mul_extension(g, zeta);
|
||||
@ -229,7 +226,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.iter()
|
||||
.map(|&e| self.convert_to_ext(e))
|
||||
.collect::<Vec<_>>();
|
||||
let mut wire_composition_eval = alpha.clone().reduce(&wire_evals, self);
|
||||
let wire_composition_eval = alpha.clone().reduce(&wire_evals, self);
|
||||
let mut alpha_frob = alpha.repeated_frobenius(D - 1, self);
|
||||
let wire_eval = alpha.reduce(&os.wires, self);
|
||||
let wire_eval_frob = alpha_frob.reduce(&os.wires, self);
|
||||
|
||||
@ -447,7 +447,6 @@ mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::field::Field;
|
||||
use crate::fri::FriConfig;
|
||||
use crate::verifier::verify;
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ mod tests {
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::extension_field::FieldExtension;
|
||||
use crate::field::field::Field;
|
||||
use crate::field::interpolation::{interpolant, interpolate};
|
||||
use crate::field::interpolation::interpolant;
|
||||
use crate::verifier::verify;
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
|
||||
@ -170,7 +170,6 @@ impl<F: Field, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::circuit_data::CircuitConfig;
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::gates::base_sum::BaseSumGate;
|
||||
use crate::gates::gate_testing::test_low_degree;
|
||||
|
||||
@ -325,8 +325,6 @@ mod tests {
|
||||
use crate::gates::gmimc::{GMiMCGate, W};
|
||||
use crate::generator::generate_partial_witness;
|
||||
use crate::gmimc::gmimc_permute_naive;
|
||||
use crate::permutation_argument::TargetPartition;
|
||||
use crate::target::Target;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars};
|
||||
use crate::verifier::verify;
|
||||
use crate::wire::Wire;
|
||||
|
||||
@ -157,7 +157,6 @@ mod tests {
|
||||
use crate::circuit_data::CircuitConfig;
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::merkle_proofs::verify_merkle_proof;
|
||||
use crate::merkle_tree::MerkleTree;
|
||||
use crate::verifier::verify;
|
||||
use crate::witness::PartialWitness;
|
||||
@ -169,7 +168,6 @@ mod tests {
|
||||
#[test]
|
||||
fn test_recursive_merkle_proof() -> Result<()> {
|
||||
type F = CrandallField;
|
||||
type FF = QuarticCrandallField;
|
||||
let config = CircuitConfig::large_config();
|
||||
let mut builder = CircuitBuilder::<F, 4>::new(config);
|
||||
let mut pw = PartialWitness::new();
|
||||
@ -177,7 +175,7 @@ mod tests {
|
||||
let log_n = 8;
|
||||
let n = 1 << log_n;
|
||||
let leaves = random_data::<F>(n, 7);
|
||||
let tree = MerkleTree::new(leaves.clone(), false);
|
||||
let tree = MerkleTree::new(leaves, false);
|
||||
let i: usize = thread_rng().gen_range(0, n);
|
||||
let proof = tree.prove(i);
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ mod tests {
|
||||
let leaves = random_data::<F>(n, 7);
|
||||
|
||||
verify_all_leaves(leaves.clone(), n, false)?;
|
||||
verify_all_leaves(leaves.clone(), n, true)?;
|
||||
verify_all_leaves(leaves, n, true)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -145,10 +145,10 @@ impl WirePartitions {
|
||||
debug_assert_eq!(self.indices.len() % degree, 0);
|
||||
let num_routed_wires = self.indices.len() / degree;
|
||||
|
||||
/// Find a wire's "neighbor" in the context of Plonk's "extended copy constraints" check. In
|
||||
/// other words, find the next wire in the given wire's partition. If the given wire is last in
|
||||
/// its partition, this will loop around. If the given wire has a partition all to itself, it
|
||||
/// is considered its own neighbor.
|
||||
// Find a wire's "neighbor" in the context of Plonk's "extended copy constraints" check. In
|
||||
// other words, find the next wire in the given wire's partition. If the given wire is last in
|
||||
// its partition, this will loop around. If the given wire has a partition all to itself, it
|
||||
// is considered its own neighbor.
|
||||
let mut neighbors = HashMap::new();
|
||||
for subset in &self.partition {
|
||||
for n in 0..subset.len() {
|
||||
|
||||
@ -346,7 +346,6 @@ mod tests {
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::field::Field;
|
||||
use crate::generator::generate_partial_witness;
|
||||
use crate::permutation_argument::TargetPartition;
|
||||
use crate::plonk_challenger::{Challenger, RecursiveChallenger};
|
||||
use crate::target::Target;
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
use std::borrow::Borrow;
|
||||
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::circuit_data::CommonCircuitData;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{GateRef, PrefixedGate};
|
||||
use crate::polynomial::commitment::SALT_SIZE;
|
||||
use crate::polynomial::polynomial::PolynomialCoeffs;
|
||||
use crate::target::Target;
|
||||
use crate::util::partial_products::check_partial_products;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
|
||||
/// Holds the Merkle tree index and blinding flag of a set of polynomials used in FRI.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
||||
@ -14,10 +14,8 @@ use crate::proof::Proof;
|
||||
use crate::timed;
|
||||
use crate::util::partial_products::partial_products;
|
||||
use crate::util::{log2_ceil, transpose};
|
||||
use crate::vanishing_poly::{
|
||||
eval_vanishing_poly_base, evaluate_gate_constraints, evaluate_gate_constraints_base, yoba,
|
||||
};
|
||||
use crate::vars::{EvaluationVars, EvaluationVarsBase};
|
||||
use crate::vanishing_poly::eval_vanishing_poly_base;
|
||||
use crate::vars::EvaluationVarsBase;
|
||||
use crate::witness::{PartialWitness, Witness};
|
||||
|
||||
pub(crate) fn prove<F: Extendable<D>, const D: usize>(
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
use crate::circuit_builder::CircuitBuilder;
|
||||
use crate::circuit_data::{CircuitConfig, CommonCircuitData, VerifierCircuitTarget};
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{GateRef, PrefixedGate};
|
||||
use crate::plonk_challenger::RecursiveChallenger;
|
||||
use crate::proof::{HashTarget, ProofTarget};
|
||||
use crate::util::scaling::ReducingFactorTarget;
|
||||
@ -114,17 +112,14 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::field::crandall_field::CrandallField;
|
||||
use crate::field::extension_field::quartic::QuarticCrandallField;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::fri::FriConfig;
|
||||
use crate::gadgets::polynomial::PolynomialCoeffsExtTarget;
|
||||
use crate::merkle_proofs::MerkleProofTarget;
|
||||
use crate::polynomial::commitment::OpeningProofTarget;
|
||||
use crate::proof::{
|
||||
FriInitialTreeProofTarget, FriProofTarget, FriQueryRoundTarget, FriQueryStepTarget,
|
||||
HashTarget, OpeningSetTarget, Proof,
|
||||
OpeningSetTarget, Proof,
|
||||
};
|
||||
use crate::target::Target;
|
||||
use crate::verifier::verify;
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
@ -319,7 +314,6 @@ mod tests {
|
||||
fn test_recursive_verifier() {
|
||||
env_logger::init();
|
||||
type F = CrandallField;
|
||||
type FF = QuarticCrandallField;
|
||||
const D: usize = 4;
|
||||
let config = CircuitConfig {
|
||||
num_wires: 134,
|
||||
@ -336,10 +330,10 @@ mod tests {
|
||||
};
|
||||
let (proof, vd, cd) = {
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config.clone());
|
||||
let two = builder.two();
|
||||
let two = builder.hash_n_to_hash(vec![two], true).elements[0];
|
||||
for i in 0..1000 {
|
||||
let two = builder.mul(two, two);
|
||||
let _two = builder.two();
|
||||
let _two = builder.hash_n_to_hash(vec![_two], true).elements[0];
|
||||
for _ in 0..1000 {
|
||||
let _two = builder.mul(_two, _two);
|
||||
}
|
||||
let data = builder.build();
|
||||
(
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::proof::HashTarget;
|
||||
use crate::target::Target;
|
||||
use crate::witness::{PartialWitness, Witness};
|
||||
use crate::witness::PartialWitness;
|
||||
|
||||
/// Enum representing all types of targets, so that they can be marked.
|
||||
#[derive(Clone)]
|
||||
|
||||
@ -187,10 +187,7 @@ mod tests {
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
let alpha = FF::rand();
|
||||
let alpha = FF::ONE;
|
||||
let vs = (0..n)
|
||||
.map(|i| FF::from_canonical_usize(i))
|
||||
.collect::<Vec<_>>();
|
||||
let vs = (0..n).map(FF::from_canonical_usize).collect::<Vec<_>>();
|
||||
|
||||
let manual_reduce = ReducingFactor::new(alpha).reduce(vs.iter());
|
||||
let manual_reduce = builder.constant_extension(manual_reduce);
|
||||
|
||||
@ -3,11 +3,10 @@ use crate::circuit_data::CommonCircuitData;
|
||||
use crate::field::extension_field::target::ExtensionTarget;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::gates::gate::{Gate, GateRef, PrefixedGate};
|
||||
use crate::gates::gate::PrefixedGate;
|
||||
use crate::plonk_common;
|
||||
use crate::plonk_common::{eval_l_1, eval_l_1_recursively, ZeroPolyOnCoset};
|
||||
use crate::plonk_common::{eval_l_1_recursively, ZeroPolyOnCoset};
|
||||
use crate::target::Target;
|
||||
use crate::util::marking::MarkedTargets;
|
||||
use crate::util::partial_products::{check_partial_products, check_partial_products_recursively};
|
||||
use crate::util::scaling::ReducingFactorTarget;
|
||||
use crate::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
@ -185,108 +184,6 @@ pub(crate) fn eval_vanishing_poly_base<F: Extendable<D>, const D: usize>(
|
||||
plonk_common::reduce_with_powers_multi(&vanishing_terms, alphas)
|
||||
}
|
||||
|
||||
pub(crate) fn yoba<F: Extendable<D>, const D: usize>(
|
||||
common_data: &CommonCircuitData<F, D>,
|
||||
index: usize,
|
||||
x: F,
|
||||
vars: EvaluationVarsBase<F>,
|
||||
local_zs: &[F],
|
||||
next_zs: &[F],
|
||||
partial_products: &[F],
|
||||
s_sigmas: &[F],
|
||||
betas: &[F],
|
||||
gammas: &[F],
|
||||
alphas: &[F],
|
||||
) -> Vec<F> {
|
||||
let max_degree = common_data.quotient_degree_factor;
|
||||
let (num_prods, final_num_prod) = common_data.num_partial_products;
|
||||
|
||||
let constraint_terms =
|
||||
evaluate_gate_constraints_base(&common_data.gates, common_data.num_gate_constraints, vars);
|
||||
|
||||
// The L_1(x) (Z(x) - 1) vanishing terms.
|
||||
let mut vanishing_z_1_terms = Vec::new();
|
||||
// The terms checking the partial products.
|
||||
let mut vanishing_partial_products_terms = Vec::new();
|
||||
// The Z(x) f'(x) - g'(x) Z(g x) terms.
|
||||
let mut vanishing_v_shift_terms = Vec::new();
|
||||
|
||||
for i in 0..common_data.config.num_challenges {
|
||||
let z_x = local_zs[i];
|
||||
let z_gz = next_zs[i];
|
||||
vanishing_z_1_terms.push(eval_l_1(common_data.degree(), x) * (z_x - F::ONE));
|
||||
|
||||
let numerator_values = (0..common_data.config.num_routed_wires)
|
||||
.map(|j| {
|
||||
let wire_value = vars.local_wires[j];
|
||||
let k_i = common_data.k_is[j];
|
||||
let s_id = k_i * x;
|
||||
wire_value + betas[i] * s_id + gammas[i]
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let denominator_values = (0..common_data.config.num_routed_wires)
|
||||
.map(|j| {
|
||||
let wire_value = vars.local_wires[j];
|
||||
let s_sigma = s_sigmas[j];
|
||||
wire_value + betas[i] * s_sigma + gammas[i]
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let quotient_values = (0..common_data.config.num_routed_wires)
|
||||
.map(|j| numerator_values[j] / denominator_values[j])
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// The partial products considered for this iteration of `i`.
|
||||
let current_partial_products = &partial_products[i * num_prods..(i + 1) * num_prods];
|
||||
// Check the numerator partial products.
|
||||
let mut partial_product_check =
|
||||
check_partial_products("ient_values, current_partial_products, max_degree);
|
||||
// The first checks are of the form `q - n/d` which is a rational function not a polynomial.
|
||||
// We multiply them by `d` to get checks of the form `q*d - n` which low-degree polynomials.
|
||||
denominator_values
|
||||
.chunks(max_degree)
|
||||
.zip(partial_product_check.iter_mut())
|
||||
.for_each(|(d, q)| {
|
||||
*q *= d.iter().copied().product();
|
||||
});
|
||||
vanishing_partial_products_terms.extend(partial_product_check);
|
||||
|
||||
// The quotient final product is the product of the last `final_num_prod` elements.
|
||||
let quotient: F = current_partial_products[num_prods - final_num_prod..]
|
||||
.iter()
|
||||
.copied()
|
||||
.product();
|
||||
assert_eq!(
|
||||
quotient,
|
||||
numerator_values.iter().copied().product::<F>()
|
||||
/ denominator_values.iter().copied().product::<F>()
|
||||
);
|
||||
vanishing_v_shift_terms.push(quotient * z_x - z_gz);
|
||||
}
|
||||
|
||||
if vanishing_z_1_terms.iter().any(|x| !x.is_zero()) {
|
||||
dbg!(&vanishing_z_1_terms);
|
||||
}
|
||||
if vanishing_partial_products_terms
|
||||
.iter()
|
||||
.any(|x| !x.is_zero())
|
||||
{
|
||||
dbg!(&vanishing_partial_products_terms);
|
||||
}
|
||||
if vanishing_v_shift_terms.iter().any(|x| !x.is_zero()) {
|
||||
dbg!(&vanishing_v_shift_terms);
|
||||
}
|
||||
if constraint_terms.iter().any(|x| !x.is_zero()) {
|
||||
dbg!(&constraint_terms);
|
||||
}
|
||||
[
|
||||
vanishing_z_1_terms,
|
||||
vanishing_partial_products_terms,
|
||||
vanishing_v_shift_terms,
|
||||
constraint_terms,
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
||||
/// Evaluates all gate constraints.
|
||||
///
|
||||
/// `num_gate_constraints` is the largest number of constraints imposed by any gate. It is not
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::circuit_data::{CommonCircuitData, VerifierOnlyCircuitData};
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field::Field;
|
||||
use crate::plonk_challenger::Challenger;
|
||||
use crate::plonk_common::{eval_zero_poly, reduce_with_powers};
|
||||
use crate::plonk_common::reduce_with_powers;
|
||||
use crate::proof::Proof;
|
||||
use crate::vanishing_poly::eval_vanishing_poly;
|
||||
use crate::vars::EvaluationVars;
|
||||
|
||||
@ -117,7 +117,7 @@ impl<F: Field> PartialWitness<F> {
|
||||
|
||||
pub fn set_hash_target(&mut self, ht: HashTarget, value: Hash<F>) {
|
||||
ht.elements
|
||||
.into_iter()
|
||||
.iter()
|
||||
.zip(value.elements)
|
||||
.for_each(|(&t, x)| self.set_target(t, x));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user