mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 00:03:10 +00:00
Merge pull request #199 from mir-protocol/rename_connect
Rename `route` and `assert_equal` to `connect`
This commit is contained in:
commit
002a0ffc06
@ -380,7 +380,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
"evaluate final polynomial",
|
||||
proof.final_poly.eval_scalar(self, subgroup_x)
|
||||
);
|
||||
self.assert_equal_extension(eval, old_eval);
|
||||
self.connect_extension(eval, old_eval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -116,9 +116,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
self.route(base, Target::wire(gate_index, gate.wire_base()));
|
||||
self.connect(base, Target::wire(gate_index, gate.wire_base()));
|
||||
exp_bits_vec.iter().enumerate().for_each(|(i, bit)| {
|
||||
self.route(bit.target, Target::wire(gate_index, gate.wire_power_bit(i)));
|
||||
self.connect(bit.target, Target::wire(gate_index, gate.wire_power_bit(i)));
|
||||
});
|
||||
|
||||
Target::wire(gate_index, gate.wire_output())
|
||||
|
||||
@ -67,9 +67,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let wires_addend =
|
||||
ExtensionTarget::from_range(gate, ArithmeticExtensionGate::<D>::wires_ith_addend(i));
|
||||
|
||||
self.route_extension(multiplicand_0, wires_multiplicand_0);
|
||||
self.route_extension(multiplicand_1, wires_multiplicand_1);
|
||||
self.route_extension(addend, wires_addend);
|
||||
self.connect_extension(multiplicand_0, wires_multiplicand_0);
|
||||
self.connect_extension(multiplicand_1, wires_multiplicand_1);
|
||||
self.connect_extension(addend, wires_addend);
|
||||
|
||||
ExtensionTarget::from_range(gate, ArithmeticExtensionGate::<D>::wires_ith_output(i))
|
||||
}
|
||||
@ -421,7 +421,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
// Enforce that x times its purported inverse equals 1.
|
||||
let y_inv = self.mul_extension(y, inv);
|
||||
self.assert_equal_extension(y_inv, one);
|
||||
self.connect_extension(y_inv, one);
|
||||
|
||||
self.mul_add_extension(x, inv, z)
|
||||
}
|
||||
@ -535,8 +535,8 @@ mod tests {
|
||||
};
|
||||
let mul2 = builder.constant_extension(vs.into_iter().product());
|
||||
|
||||
builder.assert_equal_extension(mul0, mul1);
|
||||
builder.assert_equal_extension(mul1, mul2);
|
||||
builder.connect_extension(mul0, mul1);
|
||||
builder.connect_extension(mul1, mul2);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
@ -563,8 +563,8 @@ mod tests {
|
||||
let zt = builder.constant_extension(z);
|
||||
let comp_zt = builder.div_extension(xt, yt);
|
||||
let comp_zt_unsafe = builder.div_extension(xt, yt);
|
||||
builder.assert_equal_extension(zt, comp_zt);
|
||||
builder.assert_equal_extension(zt, comp_zt_unsafe);
|
||||
builder.connect_extension(zt, comp_zt);
|
||||
builder.connect_extension(zt, comp_zt_unsafe);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
@ -594,7 +594,7 @@ mod tests {
|
||||
let zt = builder.constant_ext_algebra(za);
|
||||
let comp_zt = builder.mul_ext_algebra(xt, yt);
|
||||
for i in 0..D {
|
||||
builder.assert_equal_extension(zt.0[i], comp_zt.0[i]);
|
||||
builder.connect_extension(zt.0[i], comp_zt.0[i]);
|
||||
}
|
||||
|
||||
let data = builder.build();
|
||||
|
||||
@ -20,7 +20,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
gate,
|
||||
input: swap_wire,
|
||||
});
|
||||
self.route(zero, swap_wire);
|
||||
self.connect(zero, swap_wire);
|
||||
|
||||
// Route input wires.
|
||||
for i in 0..12 {
|
||||
@ -29,7 +29,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
gate,
|
||||
input: in_wire,
|
||||
});
|
||||
self.route(inputs[i], in_wire);
|
||||
self.connect(inputs[i], in_wire);
|
||||
}
|
||||
|
||||
// Collect output wires.
|
||||
|
||||
@ -17,16 +17,16 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
v.iter().enumerate().for_each(|(i, &val)| {
|
||||
self.route_extension(
|
||||
self.connect_extension(
|
||||
val,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_original_list_item(i)),
|
||||
);
|
||||
});
|
||||
self.route(
|
||||
self.connect(
|
||||
index,
|
||||
Target::wire(gate_index, gate.wires_insertion_index()),
|
||||
);
|
||||
self.route_extension(
|
||||
self.connect_extension(
|
||||
element,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_element_to_insert()),
|
||||
);
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
assert_eq!(inserted.len(), purported_inserted.len());
|
||||
|
||||
for (x, y) in inserted.into_iter().zip(purported_inserted) {
|
||||
builder.route_extension(x, y);
|
||||
builder.connect_extension(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,13 +15,13 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let gate = InterpolationGate::new(interpolation_points.len());
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
for (i, &(p, v)) in interpolation_points.iter().enumerate() {
|
||||
self.route(p, Target::wire(gate_index, gate.wire_point(i)));
|
||||
self.route_extension(
|
||||
self.connect(p, Target::wire(gate_index, gate.wire_point(i)));
|
||||
self.connect_extension(
|
||||
v,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_value(i)),
|
||||
);
|
||||
}
|
||||
self.route_extension(
|
||||
self.connect_extension(
|
||||
evaluation_point,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_evaluation_point()),
|
||||
);
|
||||
@ -76,7 +76,7 @@ mod tests {
|
||||
|
||||
let eval = builder.interpolate(&points_target, zt);
|
||||
let true_eval_target = builder.constant_extension(true_eval);
|
||||
builder.assert_equal_extension(eval, true_eval_target);
|
||||
builder.connect_extension(eval, true_eval_target);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
|
||||
@ -17,16 +17,16 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
v.iter().enumerate().for_each(|(i, &val)| {
|
||||
self.route_extension(
|
||||
self.connect_extension(
|
||||
val,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_list_item(i)),
|
||||
);
|
||||
});
|
||||
self.route(
|
||||
self.connect(
|
||||
access_index,
|
||||
Target::wire(gate_index, gate.wire_access_index()),
|
||||
);
|
||||
self.route_extension(
|
||||
self.connect_extension(
|
||||
claimed_element,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_claimed_element()),
|
||||
);
|
||||
|
||||
@ -11,7 +11,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
pub fn range_check(&mut self, x: Target, n_log: usize) {
|
||||
let gate = self.add_gate(BaseSumGate::<2>::new(n_log), vec![]);
|
||||
let sum = Target::wire(gate, BaseSumGate::<2>::WIRE_SUM);
|
||||
self.route(x, sum);
|
||||
self.connect(x, sum);
|
||||
}
|
||||
|
||||
/// Returns the first `num_low_bits` little-endian bits of `x`.
|
||||
@ -37,7 +37,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
let pow2 = self.constant(F::from_canonical_u64(1 << n_log));
|
||||
let comp_x = self.mul_add(high, pow2, low);
|
||||
self.assert_equal(x, comp_x);
|
||||
self.connect(x, comp_x);
|
||||
|
||||
(low, high)
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@ mod tests {
|
||||
let should_be_x = builder.select_ext(truet, xt, yt);
|
||||
let should_be_y = builder.select_ext(falset, xt, yt);
|
||||
|
||||
builder.assert_equal_extension(should_be_x, xt);
|
||||
builder.assert_equal_extension(should_be_y, yt);
|
||||
builder.connect_extension(should_be_x, xt);
|
||||
builder.connect_extension(should_be_y, yt);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
|
||||
@ -15,7 +15,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let gate_type = BaseSumGate::<B>::new(num_limbs);
|
||||
let gate = self.add_gate(gate_type.clone(), vec![]);
|
||||
let sum = Target::wire(gate, BaseSumGate::<B>::WIRE_SUM);
|
||||
self.route(x, sum);
|
||||
self.connect(x, sum);
|
||||
|
||||
Target::wires_from_range(gate, gate_type.limbs())
|
||||
}
|
||||
@ -41,7 +41,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.clone()
|
||||
.zip(BaseSumGate::<2>::START_LIMBS..BaseSumGate::<2>::START_LIMBS + num_bits)
|
||||
{
|
||||
self.route(limb.borrow().target, Target::wire(gate_index, wire));
|
||||
self.connect(limb.borrow().target, Target::wire(gate_index, wire));
|
||||
}
|
||||
|
||||
self.add_generator(BaseSumGenerator::<2> {
|
||||
@ -106,10 +106,10 @@ mod tests {
|
||||
let two = builder.two();
|
||||
let three = builder.constant(F::from_canonical_u64(3));
|
||||
let five = builder.constant(F::from_canonical_u64(5));
|
||||
builder.route(limbs[0], two);
|
||||
builder.route(limbs[1], three);
|
||||
builder.route(limbs[2], five);
|
||||
builder.route(limbs[3], one);
|
||||
builder.connect(limbs[0], two);
|
||||
builder.connect(limbs[1], three);
|
||||
builder.connect(limbs[2], five);
|
||||
builder.connect(limbs[3], one);
|
||||
|
||||
builder.assert_leading_zeros(xt, 64 - 9);
|
||||
let data = builder.build();
|
||||
@ -143,7 +143,7 @@ mod tests {
|
||||
.iter(),
|
||||
);
|
||||
|
||||
builder.assert_equal(x, y);
|
||||
builder.connect(x, y);
|
||||
|
||||
let data = builder.build();
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
sum,
|
||||
);
|
||||
}
|
||||
self.assert_equal(acc, integer);
|
||||
self.connect(acc, integer);
|
||||
|
||||
self.add_generator(WireSplitGenerator {
|
||||
integer,
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::gates::gate::Gate;
|
||||
use crate::iop::generator::{GeneratedValues, SimpleGenerator, WitnessGenerator};
|
||||
use crate::iop::target::Target;
|
||||
use crate::iop::wire::Wire;
|
||||
use crate::iop::witness::PartialWitness;
|
||||
use crate::iop::witness::{PartitionWitness, Witness};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
@ -210,7 +210,7 @@ impl<F: Extendable<D>, const D: usize, const CHUNK_SIZE: usize> SimpleGenerator<
|
||||
deps
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartialWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
gate: self.gate_index,
|
||||
input,
|
||||
|
||||
@ -78,7 +78,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
gate,
|
||||
input: swap_wire,
|
||||
});
|
||||
self.route(bit.target, swap_wire);
|
||||
self.connect(bit.target, swap_wire);
|
||||
|
||||
let input_wires = (0..12)
|
||||
.map(|i| {
|
||||
@ -90,9 +90,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for i in 0..4 {
|
||||
self.route(state.elements[i], input_wires[i]);
|
||||
self.route(sibling.elements[i], input_wires[4 + i]);
|
||||
self.route(zero, input_wires[8 + i]);
|
||||
self.connect(state.elements[i], input_wires[i]);
|
||||
self.connect(sibling.elements[i], input_wires[4 + i]);
|
||||
self.connect(zero, input_wires[8 + i]);
|
||||
}
|
||||
|
||||
state = HashOutTarget::from_vec(
|
||||
@ -156,9 +156,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for i in 0..4 {
|
||||
self.route(state.elements[i], input_wires[i]);
|
||||
self.route(sibling.elements[i], input_wires[4 + i]);
|
||||
self.route(zero, input_wires[8 + i]);
|
||||
self.connect(state.elements[i], input_wires[i]);
|
||||
self.connect(sibling.elements[i], input_wires[4 + i]);
|
||||
self.connect(zero, input_wires[8 + i]);
|
||||
}
|
||||
|
||||
state = HashOutTarget::from_vec(
|
||||
@ -188,17 +188,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
pub fn assert_hashes_equal(&mut self, x: HashOutTarget, y: HashOutTarget) {
|
||||
for i in 0..4 {
|
||||
self.assert_equal(x.elements[i], y.elements[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn named_assert_hashes_equal(&mut self, x: HashOutTarget, y: HashOutTarget, name: String) {
|
||||
for i in 0..4 {
|
||||
self.named_assert_equal(
|
||||
x.elements[i],
|
||||
y.elements[i],
|
||||
format!("{}: {}-th hash element", name, i),
|
||||
);
|
||||
self.connect(x.elements[i], y.elements[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,30 +173,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Both elements must be routable, otherwise this method will panic.
|
||||
pub fn route(&mut self, src: Target, dst: Target) {
|
||||
self.assert_equal(src, dst);
|
||||
}
|
||||
|
||||
/// Same as `route` with a named copy constraint.
|
||||
pub fn named_route(&mut self, src: Target, dst: Target, name: String) {
|
||||
self.named_assert_equal(src, dst, name);
|
||||
}
|
||||
|
||||
pub fn route_extension(&mut self, src: ExtensionTarget<D>, dst: ExtensionTarget<D>) {
|
||||
pub fn connect_extension(&mut self, src: ExtensionTarget<D>, dst: ExtensionTarget<D>) {
|
||||
for i in 0..D {
|
||||
self.route(src.0[i], dst.0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn named_route_extension(
|
||||
&mut self,
|
||||
src: ExtensionTarget<D>,
|
||||
dst: ExtensionTarget<D>,
|
||||
name: String,
|
||||
) {
|
||||
for i in 0..D {
|
||||
self.named_route(src.0[i], dst.0[i], format!("{}: limb {}", name, i));
|
||||
self.connect(src.0[i], dst.0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +186,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
/// Uses Plonk's permutation argument to require that two elements be equal.
|
||||
/// Both elements must be routable, otherwise this method will panic.
|
||||
pub fn assert_equal(&mut self, x: Target, y: Target) {
|
||||
pub fn connect(&mut self, x: Target, y: Target) {
|
||||
assert!(
|
||||
x.is_routable(&self.config),
|
||||
"Tried to route a wire that isn't routable"
|
||||
@ -220,43 +199,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.push(CopyConstraint::new((x, y), self.context_log.open_stack()));
|
||||
}
|
||||
|
||||
/// Same as `assert_equal` for a named copy constraint.
|
||||
pub fn named_assert_equal(&mut self, x: Target, y: Target, name: String) {
|
||||
assert!(
|
||||
x.is_routable(&self.config),
|
||||
"Tried to route a wire that isn't routable"
|
||||
);
|
||||
assert!(
|
||||
y.is_routable(&self.config),
|
||||
"Tried to route a wire that isn't routable"
|
||||
);
|
||||
self.copy_constraints.push(CopyConstraint::new(
|
||||
(x, y),
|
||||
format!("{} > {}", self.context_log.open_stack(), name),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn assert_zero(&mut self, x: Target) {
|
||||
let zero = self.zero();
|
||||
self.assert_equal(x, zero);
|
||||
}
|
||||
|
||||
pub fn assert_equal_extension(&mut self, x: ExtensionTarget<D>, y: ExtensionTarget<D>) {
|
||||
for i in 0..D {
|
||||
self.assert_equal(x.0[i], y.0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn named_assert_equal_extension(
|
||||
&mut self,
|
||||
x: ExtensionTarget<D>,
|
||||
y: ExtensionTarget<D>,
|
||||
name: String,
|
||||
) {
|
||||
for i in 0..D {
|
||||
self.assert_equal(x.0[i], y.0[i]);
|
||||
self.named_assert_equal(x.0[i], y.0[i], format!("{}: limb {}", name, i));
|
||||
}
|
||||
self.connect(x, zero);
|
||||
}
|
||||
|
||||
pub fn add_generators(&mut self, generators: Vec<Box<dyn WitnessGenerator<F>>>) {
|
||||
@ -554,9 +499,9 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
ArithmeticExtensionGate::<D>::wires_ith_addend(j),
|
||||
);
|
||||
|
||||
self.route_extension(zero, wires_multiplicand_0);
|
||||
self.route_extension(zero, wires_multiplicand_1);
|
||||
self.route_extension(zero, wires_addend);
|
||||
self.connect_extension(zero, wires_multiplicand_0);
|
||||
self.connect_extension(zero, wires_multiplicand_1);
|
||||
self.connect_extension(zero, wires_addend);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -583,7 +528,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.iter()
|
||||
.zip(PublicInputGate::wires_public_inputs_hash())
|
||||
{
|
||||
self.route(hash_part, Target::wire(pi_gate, wire))
|
||||
self.connect(hash_part, Target::wire(pi_gate, wire))
|
||||
}
|
||||
|
||||
info!(
|
||||
|
||||
@ -94,11 +94,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
{
|
||||
let recombined_quotient = scale.reduce(chunk, self);
|
||||
let computed_vanishing_poly = self.mul_extension(z_h_zeta, recombined_quotient);
|
||||
self.named_assert_equal_extension(
|
||||
vanishing_polys_zeta[i],
|
||||
computed_vanishing_poly,
|
||||
format!("Vanishing polynomial == Z_H * quotient, challenge {}", i),
|
||||
);
|
||||
self.connect_extension(vanishing_polys_zeta[i], computed_vanishing_poly);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -119,16 +119,16 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
||||
let gate = ReducingGate::new(max_coeffs_len);
|
||||
let gate_index = builder.add_gate(gate.clone(), Vec::new());
|
||||
|
||||
builder.route_extension(
|
||||
builder.connect_extension(
|
||||
self.base,
|
||||
ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_alpha()),
|
||||
);
|
||||
builder.route_extension(
|
||||
builder.connect_extension(
|
||||
acc,
|
||||
ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_old_acc()),
|
||||
);
|
||||
for (&t, c) in chunk.iter().zip(gate.wires_coeffs()) {
|
||||
builder.route(t, Target::wire(gate_index, c));
|
||||
builder.connect(t, Target::wire(gate_index, c));
|
||||
}
|
||||
|
||||
acc = ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_output());
|
||||
@ -213,7 +213,7 @@ mod tests {
|
||||
let vs_t = vs.iter().map(|&v| builder.constant(v)).collect::<Vec<_>>();
|
||||
let circuit_reduce = alpha_t.reduce_base(&vs_t, &mut builder);
|
||||
|
||||
builder.assert_equal_extension(manual_reduce, circuit_reduce);
|
||||
builder.connect_extension(manual_reduce, circuit_reduce);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
@ -244,7 +244,7 @@ mod tests {
|
||||
.collect::<Vec<_>>();
|
||||
let circuit_reduce = alpha_t.reduce(&vs_t, &mut builder);
|
||||
|
||||
builder.assert_equal_extension(manual_reduce, circuit_reduce);
|
||||
builder.connect_extension(manual_reduce, circuit_reduce);
|
||||
|
||||
let data = builder.build();
|
||||
let proof = data.prove(pw)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user