mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-06 15:53:10 +00:00
route, assert_equal -> connect
This commit is contained in:
parent
cd1bd9e77b
commit
69a945547a
@ -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))
|
||||
}
|
||||
|
||||
@ -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()),
|
||||
);
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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,13 +188,13 @@ 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]);
|
||||
self.connect(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(
|
||||
self.named_connect(
|
||||
x.elements[i],
|
||||
y.elements[i],
|
||||
format!("{}: {}-th hash element", name, i),
|
||||
|
||||
@ -173,30 +173,20 @@ 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]);
|
||||
self.connect(src.0[i], dst.0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn named_route_extension(
|
||||
pub fn named_connect_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.named_connect(src.0[i], dst.0[i], format!("{}: limb {}", name, i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +197,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"
|
||||
@ -221,7 +211,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
|
||||
/// Same as `assert_equal` for a named copy constraint.
|
||||
pub fn named_assert_equal(&mut self, x: Target, y: Target, name: String) {
|
||||
pub fn named_connect(&mut self, x: Target, y: Target, name: String) {
|
||||
assert!(
|
||||
x.is_routable(&self.config),
|
||||
"Tried to route a wire that isn't routable"
|
||||
@ -238,12 +228,12 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
pub fn assert_zero(&mut self, x: Target) {
|
||||
let zero = self.zero();
|
||||
self.assert_equal(x, zero);
|
||||
self.connect(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]);
|
||||
self.connect(x.0[i], y.0[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,8 +244,8 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, 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.0[i], y.0[i]);
|
||||
self.named_connect(x.0[i], y.0[i], format!("{}: limb {}", name, i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -554,9 +544,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 +573,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!(
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user