mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-04 23:03:08 +00:00
Optimize combination of gate constraints in recursive circuit (#342)
Just passing the "combined constraints" buffer into `eval_filtered_recursively`, so that we can combine a mul by the filter with an add into the buffer. Saves 56 wires.
This commit is contained in:
parent
e9ae9a045f
commit
b2264752de
@ -86,18 +86,20 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Adds this gate's filtered constraints into the `combined_gate_constraints` buffer.
|
||||
fn eval_filtered_recursively(
|
||||
&self,
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
mut vars: EvaluationTargets<D>,
|
||||
prefix: &[bool],
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
combined_gate_constraints: &mut Vec<ExtensionTarget<D>>,
|
||||
) {
|
||||
let filter = compute_filter_recursively(builder, prefix, vars.local_constants);
|
||||
vars.remove_prefix(prefix);
|
||||
self.eval_unfiltered_recursively(builder, vars)
|
||||
.into_iter()
|
||||
.map(|c| builder.mul_extension(filter, c))
|
||||
.collect()
|
||||
let my_constraints = self.eval_unfiltered_recursively(builder, vars);
|
||||
for (acc, c) in combined_gate_constraints.iter_mut().zip(my_constraints) {
|
||||
*acc = builder.mul_add_extension(filter, c, *acc);
|
||||
}
|
||||
}
|
||||
|
||||
fn generators(
|
||||
|
||||
@ -288,24 +288,20 @@ pub fn evaluate_gate_constraints_recursively<F: RichField + Extendable<D>, const
|
||||
num_gate_constraints: usize,
|
||||
vars: EvaluationTargets<D>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let mut all_gate_constraints = vec![vec![]; num_gate_constraints];
|
||||
let mut all_gate_constraints = vec![builder.zero_extension(); num_gate_constraints];
|
||||
for gate in gates {
|
||||
let gate_constraints = with_context!(
|
||||
with_context!(
|
||||
builder,
|
||||
&format!("evaluate {} constraints", gate.gate.0.id()),
|
||||
gate.gate
|
||||
.0
|
||||
.eval_filtered_recursively(builder, vars, &gate.prefix)
|
||||
gate.gate.0.eval_filtered_recursively(
|
||||
builder,
|
||||
vars,
|
||||
&gate.prefix,
|
||||
&mut all_gate_constraints
|
||||
)
|
||||
);
|
||||
for (i, c) in gate_constraints.into_iter().enumerate() {
|
||||
all_gate_constraints[i].push(c);
|
||||
}
|
||||
}
|
||||
let mut constraints = vec![builder.zero_extension(); num_gate_constraints];
|
||||
for (i, v) in all_gate_constraints.into_iter().enumerate() {
|
||||
constraints[i] = builder.add_many_extension(&v);
|
||||
}
|
||||
constraints
|
||||
all_gate_constraints
|
||||
}
|
||||
|
||||
/// Evaluate the vanishing polynomial at `x`. In this context, the vanishing polynomial is a random
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user