mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
PermutationChallenge -> GrandProductChallenge since it's also used for cross-table lookups
This commit is contained in:
parent
2b8c3de10e
commit
c4c3533cff
@ -13,7 +13,7 @@ use crate::all_stark::Table;
|
||||
use crate::config::StarkConfig;
|
||||
use crate::constraint_consumer::ConstraintConsumer;
|
||||
use crate::permutation::{
|
||||
get_permutation_challenge_set, PermutationChallenge, PermutationChallengeSet,
|
||||
get_grand_product_challenge_set, GrandProductChallenge, GrandProductChallengeSet,
|
||||
};
|
||||
use crate::proof::StarkProofWithPublicInputs;
|
||||
use crate::stark::Stark;
|
||||
@ -47,12 +47,12 @@ impl CrossTableLookup {
|
||||
/// Lookup data for one table.
|
||||
#[derive(Clone)]
|
||||
pub struct LookupData<F: Field> {
|
||||
pub(crate) challenges: PermutationChallengeSet<F>,
|
||||
pub(crate) challenges: GrandProductChallengeSet<F>,
|
||||
pub zs_columns: Vec<(PolynomialValues<F>, Vec<usize>)>,
|
||||
}
|
||||
|
||||
impl<F: Field> LookupData<F> {
|
||||
pub(crate) fn new(challenges: PermutationChallengeSet<F>) -> Self {
|
||||
pub(crate) fn new(challenges: GrandProductChallengeSet<F>) -> Self {
|
||||
Self {
|
||||
challenges,
|
||||
zs_columns: vec![],
|
||||
@ -78,7 +78,7 @@ pub fn cross_table_lookup_zs<F: RichField, C: GenericConfig<D, F = F>, const D:
|
||||
cross_table_lookups: &[CrossTableLookup],
|
||||
challenger: &mut Challenger<F, C::Hasher>,
|
||||
) -> Vec<LookupData<F>> {
|
||||
let challenges = get_permutation_challenge_set(challenger, config.num_challenges);
|
||||
let challenges = get_grand_product_challenge_set(challenger, config.num_challenges);
|
||||
cross_table_lookups.iter().fold(
|
||||
vec![LookupData::new(challenges.clone()); trace_poly_values.len()],
|
||||
|mut acc, cross_table_lookup| {
|
||||
@ -89,7 +89,7 @@ pub fn cross_table_lookup_zs<F: RichField, C: GenericConfig<D, F = F>, const D:
|
||||
looked_columns,
|
||||
} = cross_table_lookup;
|
||||
|
||||
for &PermutationChallenge { beta, gamma } in &challenges.challenges {
|
||||
for &GrandProductChallenge { beta, gamma } in &challenges.challenges {
|
||||
let z_looking = partial_products(
|
||||
&trace_poly_values[*looking_table as usize],
|
||||
looking_columns,
|
||||
@ -140,7 +140,7 @@ where
|
||||
{
|
||||
pub(crate) local_z: P,
|
||||
pub(crate) next_z: P,
|
||||
pub(crate) challenges: PermutationChallenge<F>,
|
||||
pub(crate) challenges: GrandProductChallenge<F>,
|
||||
pub(crate) columns: &'a [usize],
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ impl<'a, F: RichField + Extendable<D>, const D: usize>
|
||||
pub(crate) fn from_proofs<C: GenericConfig<D, F = F>>(
|
||||
proofs: &[&StarkProofWithPublicInputs<F, C, D>],
|
||||
cross_table_lookups: &'a [CrossTableLookup],
|
||||
ctl_challenges: &'a PermutationChallengeSet<F>,
|
||||
ctl_challenges: &'a GrandProductChallengeSet<F>,
|
||||
) -> Vec<Vec<Self>> {
|
||||
let mut ctl_zs = proofs
|
||||
.iter()
|
||||
@ -242,7 +242,7 @@ pub(crate) fn verify_cross_table_lookups<
|
||||
>(
|
||||
cross_table_lookups: Vec<CrossTableLookup>,
|
||||
proofs: &[&StarkProofWithPublicInputs<F, C, D>],
|
||||
challenges: PermutationChallengeSet<F>,
|
||||
challenges: GrandProductChallengeSet<F>,
|
||||
config: &StarkConfig,
|
||||
) -> Result<()> {
|
||||
let degrees_bits = proofs
|
||||
|
||||
@ -12,8 +12,8 @@ use plonky2::plonk::config::{AlgebraicHasher, GenericConfig};
|
||||
use crate::all_stark::AllStark;
|
||||
use crate::config::StarkConfig;
|
||||
use crate::permutation::{
|
||||
get_n_permutation_challenge_sets, get_n_permutation_challenge_sets_target,
|
||||
get_permutation_challenge_set,
|
||||
get_grand_product_challenge_set, get_n_grand_product_challenge_sets,
|
||||
get_n_permutation_challenge_sets_target,
|
||||
};
|
||||
use crate::proof::*;
|
||||
use crate::stark::Stark;
|
||||
@ -41,7 +41,7 @@ where
|
||||
challenger.observe_cap(trace_cap);
|
||||
|
||||
let permutation_challenge_sets = permutation_zs_cap.map(|permutation_zs_cap| {
|
||||
let tmp = get_n_permutation_challenge_sets(
|
||||
let tmp = get_n_grand_product_challenge_sets(
|
||||
challenger,
|
||||
num_challenges,
|
||||
stark.permutation_batch_size(),
|
||||
@ -84,7 +84,8 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> A
|
||||
challenger.observe_cap(&proof.proof.trace_cap);
|
||||
}
|
||||
|
||||
let ctl_challenges = get_permutation_challenge_set(&mut challenger, config.num_challenges);
|
||||
let ctl_challenges =
|
||||
get_grand_product_challenge_set(&mut challenger, config.num_challenges);
|
||||
|
||||
AllProofChallenges {
|
||||
cpu_challenges: self.cpu_proof.get_challenges(
|
||||
|
||||
@ -41,12 +41,12 @@ impl PermutationPair {
|
||||
/// A single instance of a permutation check protocol.
|
||||
pub(crate) struct PermutationInstance<'a, T: Copy> {
|
||||
pub(crate) pair: &'a PermutationPair,
|
||||
pub(crate) challenge: PermutationChallenge<T>,
|
||||
pub(crate) challenge: GrandProductChallenge<T>,
|
||||
}
|
||||
|
||||
/// Randomness for a single instance of a permutation check protocol.
|
||||
#[derive(Copy, Clone)]
|
||||
pub(crate) struct PermutationChallenge<T: Copy> {
|
||||
pub(crate) struct GrandProductChallenge<T: Copy> {
|
||||
/// Randomness used to combine multiple columns into one.
|
||||
pub(crate) beta: T,
|
||||
/// Random offset that's added to the beta-reduced column values.
|
||||
@ -55,8 +55,8 @@ pub(crate) struct PermutationChallenge<T: Copy> {
|
||||
|
||||
/// Like `PermutationChallenge`, but with `num_challenges` copies to boost soundness.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct PermutationChallengeSet<T: Copy> {
|
||||
pub(crate) challenges: Vec<PermutationChallenge<T>>,
|
||||
pub(crate) struct GrandProductChallengeSet<T: Copy> {
|
||||
pub(crate) challenges: Vec<GrandProductChallenge<T>>,
|
||||
}
|
||||
|
||||
/// Compute all Z polynomials (for permutation arguments).
|
||||
@ -64,7 +64,7 @@ pub(crate) fn compute_permutation_z_polys<F, C, S, const D: usize>(
|
||||
stark: &S,
|
||||
config: &StarkConfig,
|
||||
trace_poly_values: &[PolynomialValues<F>],
|
||||
permutation_challenge_sets: &[PermutationChallengeSet<F>],
|
||||
permutation_challenge_sets: &[GrandProductChallengeSet<F>],
|
||||
) -> Vec<PolynomialValues<F>>
|
||||
where
|
||||
F: RichField + Extendable<D>,
|
||||
@ -123,7 +123,7 @@ fn permutation_reduced_polys<F: Field>(
|
||||
) -> (PolynomialValues<F>, PolynomialValues<F>) {
|
||||
let PermutationInstance {
|
||||
pair: PermutationPair { column_pairs },
|
||||
challenge: PermutationChallenge { beta, gamma },
|
||||
challenge: GrandProductChallenge { beta, gamma },
|
||||
} = instance;
|
||||
|
||||
let mut reduced_lhs = PolynomialValues::constant(*gamma, degree);
|
||||
@ -147,31 +147,31 @@ fn poly_product_elementwise<F: Field>(
|
||||
product
|
||||
}
|
||||
|
||||
fn get_permutation_challenge<F: RichField, H: Hasher<F>>(
|
||||
fn get_grand_product_challenge<F: RichField, H: Hasher<F>>(
|
||||
challenger: &mut Challenger<F, H>,
|
||||
) -> PermutationChallenge<F> {
|
||||
) -> GrandProductChallenge<F> {
|
||||
let beta = challenger.get_challenge();
|
||||
let gamma = challenger.get_challenge();
|
||||
PermutationChallenge { beta, gamma }
|
||||
GrandProductChallenge { beta, gamma }
|
||||
}
|
||||
|
||||
pub(crate) fn get_permutation_challenge_set<F: RichField, H: Hasher<F>>(
|
||||
pub(crate) fn get_grand_product_challenge_set<F: RichField, H: Hasher<F>>(
|
||||
challenger: &mut Challenger<F, H>,
|
||||
num_challenges: usize,
|
||||
) -> PermutationChallengeSet<F> {
|
||||
) -> GrandProductChallengeSet<F> {
|
||||
let challenges = (0..num_challenges)
|
||||
.map(|_| get_permutation_challenge(challenger))
|
||||
.map(|_| get_grand_product_challenge(challenger))
|
||||
.collect();
|
||||
PermutationChallengeSet { challenges }
|
||||
GrandProductChallengeSet { challenges }
|
||||
}
|
||||
|
||||
pub(crate) fn get_n_permutation_challenge_sets<F: RichField, H: Hasher<F>>(
|
||||
pub(crate) fn get_n_grand_product_challenge_sets<F: RichField, H: Hasher<F>>(
|
||||
challenger: &mut Challenger<F, H>,
|
||||
num_challenges: usize,
|
||||
num_sets: usize,
|
||||
) -> Vec<PermutationChallengeSet<F>> {
|
||||
) -> Vec<GrandProductChallengeSet<F>> {
|
||||
(0..num_sets)
|
||||
.map(|_| get_permutation_challenge_set(challenger, num_challenges))
|
||||
.map(|_| get_grand_product_challenge_set(challenger, num_challenges))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -182,10 +182,10 @@ fn get_permutation_challenge_target<
|
||||
>(
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
challenger: &mut RecursiveChallenger<F, H, D>,
|
||||
) -> PermutationChallenge<Target> {
|
||||
) -> GrandProductChallenge<Target> {
|
||||
let beta = challenger.get_challenge(builder);
|
||||
let gamma = challenger.get_challenge(builder);
|
||||
PermutationChallenge { beta, gamma }
|
||||
GrandProductChallenge { beta, gamma }
|
||||
}
|
||||
|
||||
fn get_permutation_challenge_set_target<
|
||||
@ -196,11 +196,11 @@ fn get_permutation_challenge_set_target<
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
challenger: &mut RecursiveChallenger<F, H, D>,
|
||||
num_challenges: usize,
|
||||
) -> PermutationChallengeSet<Target> {
|
||||
) -> GrandProductChallengeSet<Target> {
|
||||
let challenges = (0..num_challenges)
|
||||
.map(|_| get_permutation_challenge_target(builder, challenger))
|
||||
.collect();
|
||||
PermutationChallengeSet { challenges }
|
||||
GrandProductChallengeSet { challenges }
|
||||
}
|
||||
|
||||
pub(crate) fn get_n_permutation_challenge_sets_target<
|
||||
@ -212,7 +212,7 @@ pub(crate) fn get_n_permutation_challenge_sets_target<
|
||||
challenger: &mut RecursiveChallenger<F, H, D>,
|
||||
num_challenges: usize,
|
||||
num_sets: usize,
|
||||
) -> Vec<PermutationChallengeSet<Target>> {
|
||||
) -> Vec<GrandProductChallengeSet<Target>> {
|
||||
(0..num_sets)
|
||||
.map(|_| get_permutation_challenge_set_target(builder, challenger, num_challenges))
|
||||
.collect()
|
||||
@ -225,7 +225,7 @@ pub(crate) fn get_n_permutation_challenge_sets_target<
|
||||
/// chunk these arguments based on our batch size.
|
||||
pub(crate) fn get_permutation_batches<'a, T: Copy>(
|
||||
permutation_pairs: &'a [PermutationPair],
|
||||
permutation_challenge_sets: &[PermutationChallengeSet<T>],
|
||||
permutation_challenge_sets: &[GrandProductChallengeSet<T>],
|
||||
num_challenges: usize,
|
||||
batch_size: usize,
|
||||
) -> Vec<Vec<PermutationInstance<'a, T>>> {
|
||||
@ -254,7 +254,7 @@ where
|
||||
{
|
||||
pub(crate) local_zs: Vec<P>,
|
||||
pub(crate) next_zs: Vec<P>,
|
||||
pub(crate) permutation_challenge_sets: Vec<PermutationChallengeSet<F>>,
|
||||
pub(crate) permutation_challenge_sets: Vec<GrandProductChallengeSet<F>>,
|
||||
}
|
||||
|
||||
pub(crate) fn eval_permutation_checks<F, FE, P, C, S, const D: usize, const D2: usize>(
|
||||
@ -298,7 +298,7 @@ pub(crate) fn eval_permutation_checks<F, FE, P, C, S, const D: usize, const D2:
|
||||
.map(|instance| {
|
||||
let PermutationInstance {
|
||||
pair: PermutationPair { column_pairs },
|
||||
challenge: PermutationChallenge { beta, gamma },
|
||||
challenge: GrandProductChallenge { beta, gamma },
|
||||
} = instance;
|
||||
let mut factor = ReducingFactor::new(*beta);
|
||||
let (lhs, rhs): (Vec<_>, Vec<_>) = column_pairs
|
||||
@ -320,7 +320,7 @@ pub(crate) fn eval_permutation_checks<F, FE, P, C, S, const D: usize, const D2:
|
||||
pub struct PermutationCheckDataTarget<const D: usize> {
|
||||
pub(crate) local_zs: Vec<ExtensionTarget<D>>,
|
||||
pub(crate) next_zs: Vec<ExtensionTarget<D>>,
|
||||
pub(crate) permutation_challenge_sets: Vec<PermutationChallengeSet<Target>>,
|
||||
pub(crate) permutation_challenge_sets: Vec<GrandProductChallengeSet<Target>>,
|
||||
}
|
||||
|
||||
pub(crate) fn eval_permutation_checks_recursively<F, S, const D: usize>(
|
||||
@ -366,7 +366,7 @@ pub(crate) fn eval_permutation_checks_recursively<F, S, const D: usize>(
|
||||
.map(|instance| {
|
||||
let PermutationInstance {
|
||||
pair: PermutationPair { column_pairs },
|
||||
challenge: PermutationChallenge { beta, gamma },
|
||||
challenge: GrandProductChallenge { beta, gamma },
|
||||
} = instance;
|
||||
let beta_ext = builder.convert_to_ext(*beta);
|
||||
let gamma_ext = builder.convert_to_ext(*gamma);
|
||||
|
||||
@ -15,7 +15,7 @@ use plonky2::plonk::config::GenericConfig;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::config::StarkConfig;
|
||||
use crate::permutation::PermutationChallengeSet;
|
||||
use crate::permutation::GrandProductChallengeSet;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AllProof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> {
|
||||
@ -32,7 +32,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> A
|
||||
pub(crate) struct AllProofChallenges<F: RichField + Extendable<D>, const D: usize> {
|
||||
pub cpu_challenges: StarkProofChallenges<F, D>,
|
||||
pub keccak_challenges: StarkProofChallenges<F, D>,
|
||||
pub ctl_challenges: PermutationChallengeSet<F>,
|
||||
pub ctl_challenges: GrandProductChallengeSet<F>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -121,7 +121,7 @@ pub struct CompressedStarkProofWithPublicInputs<
|
||||
|
||||
pub(crate) struct StarkProofChallenges<F: RichField + Extendable<D>, const D: usize> {
|
||||
/// Randomness used in any permutation arguments.
|
||||
pub permutation_challenge_sets: Option<Vec<PermutationChallengeSet<F>>>,
|
||||
pub permutation_challenge_sets: Option<Vec<GrandProductChallengeSet<F>>>,
|
||||
|
||||
/// Random values used to combine STARK constraints.
|
||||
pub stark_alphas: Vec<F>,
|
||||
@ -133,7 +133,7 @@ pub(crate) struct StarkProofChallenges<F: RichField + Extendable<D>, const D: us
|
||||
}
|
||||
|
||||
pub(crate) struct StarkProofChallengesTarget<const D: usize> {
|
||||
pub permutation_challenge_sets: Option<Vec<PermutationChallengeSet<Target>>>,
|
||||
pub permutation_challenge_sets: Option<Vec<GrandProductChallengeSet<Target>>>,
|
||||
pub stark_alphas: Vec<Target>,
|
||||
pub stark_zeta: ExtensionTarget<D>,
|
||||
pub fri_challenges: FriChallengesTarget<D>,
|
||||
|
||||
@ -24,7 +24,7 @@ use crate::constraint_consumer::ConstraintConsumer;
|
||||
use crate::cross_table_lookup::{cross_table_lookup_zs, CTLCheckVars, LookupData};
|
||||
use crate::permutation::PermutationCheckVars;
|
||||
use crate::permutation::{
|
||||
compute_permutation_z_polys, get_n_permutation_challenge_sets, PermutationChallengeSet,
|
||||
compute_permutation_z_polys, get_n_grand_product_challenge_sets, GrandProductChallengeSet,
|
||||
};
|
||||
use crate::proof::{AllProof, StarkOpeningSet, StarkProof, StarkProofWithPublicInputs};
|
||||
use crate::stark::Stark;
|
||||
@ -148,7 +148,7 @@ where
|
||||
|
||||
// Permutation arguments.
|
||||
let permutation_challenges = stark.uses_permutation_args().then(|| {
|
||||
get_n_permutation_challenge_sets(
|
||||
get_n_grand_product_challenge_sets(
|
||||
challenger,
|
||||
config.num_challenges,
|
||||
stark.permutation_batch_size(),
|
||||
@ -290,7 +290,7 @@ fn compute_quotient_polys<'a, F, P, C, S, const D: usize>(
|
||||
trace_commitment: &'a PolynomialBatch<F, C, D>,
|
||||
permutation_zs_commitment_challenges: Option<(
|
||||
&'a PolynomialBatch<F, C, D>,
|
||||
&'a Vec<PermutationChallengeSet<F>>,
|
||||
&'a Vec<GrandProductChallengeSet<F>>,
|
||||
)>,
|
||||
lookup_data: &LookupData<F>,
|
||||
public_inputs: &[F],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user