mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Compiles
This commit is contained in:
parent
f4a29a0249
commit
79ba85eb08
@ -1,23 +1,24 @@
|
||||
use plonky2::field::extension_field::Extendable;
|
||||
use plonky2::field::packed_field::PackedField;
|
||||
use plonky2::field::extension_field::{Extendable, FieldExtension};
|
||||
use plonky2::hash::hash_types::RichField;
|
||||
use plonky2::plonk::config::GenericConfig;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::config::StarkConfig;
|
||||
use crate::constraint_consumer::ConstraintConsumer;
|
||||
use crate::permutation::{get_permutation_batches, PermutationChallenge};
|
||||
use crate::permutation::{
|
||||
get_permutation_batches, PermutationChallenge, PermutationChallengeSet, PermutationInstance,
|
||||
PermutationPair,
|
||||
};
|
||||
use crate::stark::Stark;
|
||||
use crate::vars::StarkEvaluationVars;
|
||||
|
||||
pub(crate) fn eval_vanishing_poly<F, C, S, const D: usize>(
|
||||
stark: S,
|
||||
config: &StarkConfig,
|
||||
vars: StarkEvaluationVars<F, F, S::COLUMNS, S::PUBLIC_INPUTS>,
|
||||
vars: StarkEvaluationVars<F::Extension, F::Extension, { S::COLUMNS }, { S::PUBLIC_INPUTS }>,
|
||||
local_zs: &[F::Extension],
|
||||
next_zs: &[F::Extension],
|
||||
mut consumer: ConstraintConsumer<F>,
|
||||
permutation_challenge_sets: &[PermutationChallenge<F>],
|
||||
mut consumer: ConstraintConsumer<F::Extension>,
|
||||
permutation_challenge_sets: &[PermutationChallengeSet<F>],
|
||||
) where
|
||||
F: RichField + Extendable<D>,
|
||||
C: GenericConfig<D, F = F>,
|
||||
@ -25,17 +26,17 @@ pub(crate) fn eval_vanishing_poly<F, C, S, const D: usize>(
|
||||
[(); S::COLUMNS]:,
|
||||
[(); S::PUBLIC_INPUTS]:,
|
||||
{
|
||||
stark.eval_packed_base(vars, &mut consumer);
|
||||
stark.eval_packed_generic(vars, &mut consumer);
|
||||
}
|
||||
|
||||
fn eval_permutation_checks<F, C, S, const D: usize>(
|
||||
stark: S,
|
||||
config: &StarkConfig,
|
||||
vars: StarkEvaluationVars<F::Extension, F::Extension, S::COLUMNS, S::PUBLIC_INPUTS>,
|
||||
vars: StarkEvaluationVars<F::Extension, F::Extension, { S::COLUMNS }, { S::PUBLIC_INPUTS }>,
|
||||
local_zs: &[F::Extension],
|
||||
next_zs: &[F::Extension],
|
||||
mut consumer: ConstraintConsumer<F>,
|
||||
permutation_challenge_sets: &[PermutationChallenge<F>],
|
||||
consumer: &mut ConstraintConsumer<F::Extension>,
|
||||
permutation_challenge_sets: &[PermutationChallengeSet<F>],
|
||||
) where
|
||||
F: RichField + Extendable<D>,
|
||||
C: GenericConfig<D, F = F>,
|
||||
@ -43,18 +44,42 @@ fn eval_permutation_checks<F, C, S, const D: usize>(
|
||||
[(); S::COLUMNS]:,
|
||||
[(); S::PUBLIC_INPUTS]:,
|
||||
{
|
||||
// TODO: Z_1 check.
|
||||
let permutation_pairs = stark.permutation_pairs();
|
||||
|
||||
let permutation_batches = get_permutation_batches(
|
||||
&permutation_pairs,
|
||||
&permutation_challenge_sets,
|
||||
permutation_challenge_sets,
|
||||
config.num_challenges,
|
||||
stark.permutation_batch_size(),
|
||||
);
|
||||
|
||||
// Each zs value corresponds to a permutation batch.
|
||||
permutation_batches
|
||||
.into_par_iter()
|
||||
.map(|instances| compute_permutation_z_poly(&instances, trace_poly_values))
|
||||
.collect()
|
||||
for (i, instances) in permutation_batches.iter().enumerate() {
|
||||
// Z(gx) * down = Z x * up
|
||||
let (reduced_lhs, reduced_rhs): (Vec<F::Extension>, Vec<F::Extension>) = instances
|
||||
.iter()
|
||||
.map(|instance| {
|
||||
let PermutationInstance {
|
||||
pair: PermutationPair { column_pairs },
|
||||
challenge: PermutationChallenge { beta, gamma },
|
||||
} = instance;
|
||||
column_pairs.iter().rev().fold(
|
||||
(
|
||||
F::Extension::from_basefield(*gamma),
|
||||
F::Extension::from_basefield(*gamma),
|
||||
),
|
||||
|(lhs, rhs), &(i, j)| {
|
||||
(
|
||||
lhs.scalar_mul(*beta) + vars.local_values[i],
|
||||
rhs.scalar_mul(*beta) + vars.local_values[j],
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
.unzip();
|
||||
let constraint = next_zs[i] * reduced_rhs.into_iter().product()
|
||||
- local_zs[i] * reduced_lhs.into_iter().product();
|
||||
consumer.constraint(constraint);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user