mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 22:33:06 +00:00
Progress
This commit is contained in:
parent
68bd0f4b3d
commit
185d8faef6
@ -125,17 +125,17 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticG
|
||||
constraints
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_one(
|
||||
&self,
|
||||
_vars: EvaluationVarsBase<F>,
|
||||
_yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
panic!("use eval_unfiltered_base_packed instead");
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
}
|
||||
// fn eval_unfiltered_base_one(
|
||||
// &self,
|
||||
// _vars: EvaluationVarsBase<F>,
|
||||
// _yield_constr: StridedConstraintConsumer<F>,
|
||||
// ) {
|
||||
// panic!("use eval_unfiltered_base_packed instead");
|
||||
// }
|
||||
//
|
||||
// fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
// self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_recursively(
|
||||
&self,
|
||||
|
||||
@ -84,12 +84,13 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
fn eval_filtered(
|
||||
&self,
|
||||
mut vars: EvaluationVars<F, D>,
|
||||
gate_index: usize,
|
||||
selector_index: usize,
|
||||
combination_num: usize,
|
||||
combination_range: (usize, usize),
|
||||
) -> Vec<F::Extension> {
|
||||
let filter = compute_filter(
|
||||
selector_index,
|
||||
combination_num,
|
||||
gate_index,
|
||||
combination_range,
|
||||
vars.local_constants[selector_index],
|
||||
);
|
||||
vars.selector_index = selector_index;
|
||||
@ -104,15 +105,16 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
fn eval_filtered_base_batch(
|
||||
&self,
|
||||
mut vars_batch: EvaluationVarsBaseBatch<F>,
|
||||
gate_index: usize,
|
||||
selector_index: usize,
|
||||
combination_num: usize,
|
||||
combination_range: (usize, usize),
|
||||
) -> Vec<F> {
|
||||
let filters: Vec<_> = vars_batch
|
||||
.iter()
|
||||
.map(|vars| {
|
||||
compute_filter(
|
||||
selector_index,
|
||||
combination_num,
|
||||
gate_index,
|
||||
combination_range,
|
||||
vars.local_constants[selector_index],
|
||||
)
|
||||
})
|
||||
@ -131,13 +133,13 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
mut vars: EvaluationTargets<D>,
|
||||
selector_index: usize,
|
||||
combination_num: usize,
|
||||
combination_range: (usize, usize),
|
||||
combined_gate_constraints: &mut [ExtensionTarget<D>],
|
||||
) {
|
||||
let filter = compute_filter_recursively(
|
||||
builder,
|
||||
selector_index,
|
||||
combination_num,
|
||||
combination_range,
|
||||
vars.local_constants[selector_index],
|
||||
);
|
||||
vars.selector_index = selector_index;
|
||||
@ -236,9 +238,13 @@ impl<F: RichField + Extendable<D>, const D: usize> PrefixedGate<F, D> {
|
||||
|
||||
/// A gate's filter is computed as `prod b_i*c_i + (1-b_i)*(1-c_i)`, with `(b_i)` the prefix and
|
||||
/// `(c_i)` the local constants, which is one if the prefix of `constants` matches `prefix`.
|
||||
fn compute_filter<'a, K: Field>(selector_index: usize, combination_num: usize, constant: K) -> K {
|
||||
(0..combination_num)
|
||||
.filter(|&i| i != selector_index)
|
||||
fn compute_filter<'a, K: Field>(
|
||||
gate_index: usize,
|
||||
combination_range: (usize, usize),
|
||||
constant: K,
|
||||
) -> K {
|
||||
(combination_range.0..combination_range.1)
|
||||
.filter(|&i| i != gate_index)
|
||||
.map(|i| K::from_canonical_usize(i) - constant)
|
||||
.product()
|
||||
}
|
||||
@ -246,10 +252,10 @@ fn compute_filter<'a, K: Field>(selector_index: usize, combination_num: usize, c
|
||||
fn compute_filter_recursively<F: RichField + Extendable<D>, const D: usize>(
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
selector_index: usize,
|
||||
combination_num: usize,
|
||||
combination_range: (usize, usize),
|
||||
constant: ExtensionTarget<D>,
|
||||
) -> ExtensionTarget<D> {
|
||||
let v = (0..combination_num)
|
||||
let v = (combination_range.0..combination_range.1)
|
||||
.filter(|&i| i != selector_index)
|
||||
.map(|i| builder.constant_extension(F::Extension::from_canonical_usize(i)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -36,17 +36,17 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PublicInputGat
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_one(
|
||||
&self,
|
||||
_vars: EvaluationVarsBase<F>,
|
||||
_yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
panic!("use eval_unfiltered_base_packed instead");
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
}
|
||||
// fn eval_unfiltered_base_one(
|
||||
// &self,
|
||||
// _vars: EvaluationVarsBase<F>,
|
||||
// _yield_constr: StridedConstraintConsumer<F>,
|
||||
// ) {
|
||||
// panic!("use eval_unfiltered_base_packed instead");
|
||||
// }
|
||||
//
|
||||
// fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
// self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_recursively(
|
||||
&self,
|
||||
|
||||
@ -8,7 +8,7 @@ pub(crate) fn compute_selectors<F: RichField + Extendable<D>, const D: usize>(
|
||||
mut gates: Vec<GateRef<F, D>>,
|
||||
instances: &[GateInstance<F, D>],
|
||||
max_degree: usize,
|
||||
) -> (Vec<PolynomialValues<F>>, Vec<usize>, Vec<usize>) {
|
||||
) -> (Vec<PolynomialValues<F>>, Vec<usize>, Vec<(usize, usize)>) {
|
||||
let n = instances.len();
|
||||
|
||||
let mut combinations = Vec::new();
|
||||
@ -29,15 +29,20 @@ pub(crate) fn compute_selectors<F: RichField + Extendable<D>, const D: usize>(
|
||||
vec![PolynomialValues::zero(n); combinations.len() + num_constants_polynomials];
|
||||
|
||||
let index = |id| gates.iter().position(|g| g.0.id() == id).unwrap();
|
||||
let combination = |i| combinations.iter().position(|&(a, _)| a <= i).unwrap();
|
||||
let combination = |i| {
|
||||
combinations
|
||||
.iter()
|
||||
.position(|&(a, b)| a <= i && i < b)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let selector_indices = gates
|
||||
.iter()
|
||||
.map(|g| combination(index(g.0.id())))
|
||||
.collect::<Vec<_>>();
|
||||
let combination_nums = selector_indices
|
||||
let combination_ranges = selector_indices
|
||||
.iter()
|
||||
.map(|&i| combinations[i].1 - combinations[i].0)
|
||||
.map(|&i| (combinations[i].0, combinations[i].1))
|
||||
.collect();
|
||||
|
||||
for (j, g) in instances.iter().enumerate() {
|
||||
@ -47,7 +52,7 @@ pub(crate) fn compute_selectors<F: RichField + Extendable<D>, const D: usize>(
|
||||
} = g;
|
||||
let i = index(gate_ref.0.id());
|
||||
let comb = combination(i);
|
||||
polynomials[comb].values[j] = F::from_canonical_usize(i - combinations[comb].0);
|
||||
polynomials[comb].values[j] = F::from_canonical_usize(i);
|
||||
let mut k = 0;
|
||||
let mut constant_ind = 0;
|
||||
while k < constants.len() {
|
||||
@ -60,5 +65,5 @@ pub(crate) fn compute_selectors<F: RichField + Extendable<D>, const D: usize>(
|
||||
}
|
||||
}
|
||||
}
|
||||
(polynomials, selector_indices, combination_nums)
|
||||
(polynomials, selector_indices, combination_ranges)
|
||||
}
|
||||
|
||||
@ -804,7 +804,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
degree_bits,
|
||||
gates,
|
||||
selector_indices,
|
||||
combination_nums,
|
||||
combination_ranges,
|
||||
quotient_degree_factor,
|
||||
num_gate_constraints,
|
||||
num_constants,
|
||||
|
||||
@ -249,7 +249,7 @@ pub struct CommonCircuitData<
|
||||
pub(crate) gates: Vec<GateRef<F, D>>,
|
||||
|
||||
pub(crate) selector_indices: Vec<usize>,
|
||||
pub(crate) combination_nums: Vec<usize>,
|
||||
pub(crate) combination_ranges: Vec<(usize, usize)>,
|
||||
|
||||
/// The degree of the PLONK quotient polynomial.
|
||||
pub(crate) quotient_degree_factor: usize,
|
||||
|
||||
@ -219,8 +219,9 @@ pub fn evaluate_gate_constraints<
|
||||
for (i, gate) in common_data.gates.iter().enumerate() {
|
||||
let gate_constraints = gate.0.eval_filtered(
|
||||
vars.clone(),
|
||||
i,
|
||||
common_data.selector_indices[i],
|
||||
common_data.combination_nums[i],
|
||||
common_data.combination_ranges[i],
|
||||
);
|
||||
for (i, c) in gate_constraints.into_iter().enumerate() {
|
||||
debug_assert!(
|
||||
@ -250,8 +251,9 @@ pub fn evaluate_gate_constraints_base_batch<
|
||||
for (i, gate) in common_data.gates.iter().enumerate() {
|
||||
let gate_constraints_batch = gate.0.eval_filtered_base_batch(
|
||||
vars_batch.clone(),
|
||||
i,
|
||||
common_data.selector_indices[i],
|
||||
common_data.combination_nums[i],
|
||||
common_data.combination_ranges[i],
|
||||
);
|
||||
debug_assert!(
|
||||
gate_constraints_batch.len() <= constraints_batch.len(),
|
||||
@ -284,7 +286,7 @@ pub fn evaluate_gate_constraints_recursively<
|
||||
builder,
|
||||
vars.clone(),
|
||||
common_data.selector_indices[i],
|
||||
common_data.combination_nums[i],
|
||||
common_data.combination_ranges[i],
|
||||
&mut all_gate_constraints
|
||||
)
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user