diff --git a/insertion/src/insert_gadget.rs b/insertion/src/insert_gadget.rs index 9f8aa4bf..d4cbf0ec 100644 --- a/insertion/src/insert_gadget.rs +++ b/insertion/src/insert_gadget.rs @@ -27,25 +27,22 @@ impl, const D: usize> CircuitBuilderInsert v: Vec>, ) -> Vec> { let gate = InsertionGate::new(v.len()); - let gate_index = self.add_gate(gate.clone(), vec![]); + let row = self.add_gate(gate.clone(), vec![]); v.iter().enumerate().for_each(|(i, &val)| { self.connect_extension( val, - ExtensionTarget::from_range(gate_index, gate.wires_original_list_item(i)), + ExtensionTarget::from_range(row, gate.wires_original_list_item(i)), ); }); - self.connect( - index, - Target::wire(gate_index, gate.wires_insertion_index()), - ); + self.connect(index, Target::wire(row, gate.wires_insertion_index())); self.connect_extension( element, - ExtensionTarget::from_range(gate_index, gate.wires_element_to_insert()), + ExtensionTarget::from_range(row, gate.wires_element_to_insert()), ); (0..=v.len()) - .map(|i| ExtensionTarget::from_range(gate_index, gate.wires_output_list_item(i))) + .map(|i| ExtensionTarget::from_range(row, gate.wires_output_list_item(i))) .collect::>() } } diff --git a/insertion/src/insertion_gate.rs b/insertion/src/insertion_gate.rs index 442416d3..c727db83 100644 --- a/insertion/src/insertion_gate.rs +++ b/insertion/src/insertion_gate.rs @@ -213,13 +213,9 @@ impl, const D: usize> Gate for InsertionGate< constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = InsertionGenerator:: { - gate_index, + row, gate: self.clone(), }; vec![Box::new(gen.adapter())] @@ -244,15 +240,15 @@ impl, const D: usize> Gate for InsertionGate< #[derive(Debug)] struct InsertionGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: InsertionGate, } impl, const D: usize> SimpleGenerator for InsertionGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); - let local_targets = |inputs: Range| inputs.map(local_target); + let local_targets = |columns: Range| columns.map(local_target); let mut deps = vec![local_target(self.gate.wires_insertion_index())]; deps.extend(local_targets(self.gate.wires_element_to_insert())); @@ -263,12 +259,12 @@ impl, const D: usize> SimpleGenerator for Insert } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let get_local_ext = |wire_range: Range| { debug_assert_eq!(wire_range.len(), D); diff --git a/plonky2/src/gadgets/arithmetic.rs b/plonky2/src/gadgets/arithmetic.rs index b7df3726..fe6f116d 100644 --- a/plonky2/src/gadgets/arithmetic.rs +++ b/plonky2/src/gadgets/arithmetic.rs @@ -243,14 +243,14 @@ impl, const D: usize> CircuitBuilder { while exp_bits_vec.len() < num_power_bits { exp_bits_vec.push(_false); } - let gate_index = self.add_gate(gate.clone(), vec![]); + let row = self.add_gate(gate.clone(), vec![]); - self.connect(base, Target::wire(gate_index, gate.wire_base())); + self.connect(base, Target::wire(row, gate.wire_base())); exp_bits_vec.iter().enumerate().for_each(|(i, bit)| { - self.connect(bit.target, Target::wire(gate_index, gate.wire_power_bit(i))); + self.connect(bit.target, Target::wire(row, gate.wire_power_bit(i))); }); - Target::wire(gate_index, gate.wire_output()) + Target::wire(row, gate.wire_output()) } // TODO: Test diff --git a/plonky2/src/gadgets/interpolation.rs b/plonky2/src/gadgets/interpolation.rs index 7907a337..3479e2a8 100644 --- a/plonky2/src/gadgets/interpolation.rs +++ b/plonky2/src/gadgets/interpolation.rs @@ -88,20 +88,17 @@ impl, const D: usize> CircuitBuilder { evaluation_point: ExtensionTarget, ) -> ExtensionTarget { let gate = G::new(subgroup_bits); - let gate_index = self.add_gate(gate, vec![]); - self.connect(coset_shift, Target::wire(gate_index, gate.wire_shift())); + let row = self.add_gate(gate, vec![]); + self.connect(coset_shift, Target::wire(row, gate.wire_shift())); for (i, &v) in values.iter().enumerate() { - self.connect_extension( - v, - ExtensionTarget::from_range(gate_index, gate.wires_value(i)), - ); + self.connect_extension(v, ExtensionTarget::from_range(row, gate.wires_value(i))); } self.connect_extension( evaluation_point, - ExtensionTarget::from_range(gate_index, gate.wires_evaluation_point()), + ExtensionTarget::from_range(row, gate.wires_evaluation_point()), ); - ExtensionTarget::from_range(gate_index, gate.wires_evaluation_value()) + ExtensionTarget::from_range(row, gate.wires_evaluation_value()) } } diff --git a/plonky2/src/gadgets/random_access.rs b/plonky2/src/gadgets/random_access.rs index ec3c889a..d6377451 100644 --- a/plonky2/src/gadgets/random_access.rs +++ b/plonky2/src/gadgets/random_access.rs @@ -20,21 +20,18 @@ impl, const D: usize> CircuitBuilder { let claimed_element = self.add_virtual_target(); let dummy_gate = RandomAccessGate::::new_from_config(&self.config, bits); - let (gate_index, copy) = self.find_slot(dummy_gate, &[], &[]); + let (row, copy) = self.find_slot(dummy_gate, &[], &[]); v.iter().enumerate().for_each(|(i, &val)| { - self.connect( - val, - Target::wire(gate_index, dummy_gate.wire_list_item(i, copy)), - ); + self.connect(val, Target::wire(row, dummy_gate.wire_list_item(i, copy))); }); self.connect( access_index, - Target::wire(gate_index, dummy_gate.wire_access_index(copy)), + Target::wire(row, dummy_gate.wire_access_index(copy)), ); self.connect( claimed_element, - Target::wire(gate_index, dummy_gate.wire_claimed_element(copy)), + Target::wire(row, dummy_gate.wire_claimed_element(copy)), ); claimed_element diff --git a/plonky2/src/gadgets/split_base.rs b/plonky2/src/gadgets/split_base.rs index d4589476..5ceede66 100644 --- a/plonky2/src/gadgets/split_base.rs +++ b/plonky2/src/gadgets/split_base.rs @@ -54,29 +54,26 @@ impl, const D: usize> CircuitBuilder { "Not enough routed wires." ); let gate_type = BaseSumGate::<2>::new_from_config::(&self.config); - let gate_index = self.add_gate(gate_type, vec![]); + let row = self.add_gate(gate_type, vec![]); for (limb, wire) in bits .iter() .zip(BaseSumGate::<2>::START_LIMBS..BaseSumGate::<2>::START_LIMBS + num_bits) { - self.connect(limb.target, Target::wire(gate_index, wire)); + self.connect(limb.target, Target::wire(row, wire)); } for l in gate_type.limbs().skip(num_bits) { - self.assert_zero(Target::wire(gate_index, l)); + self.assert_zero(Target::wire(row, l)); } - self.add_simple_generator(BaseSumGenerator::<2> { - gate_index, - limbs: bits, - }); + self.add_simple_generator(BaseSumGenerator::<2> { row, limbs: bits }); - Target::wire(gate_index, BaseSumGate::<2>::WIRE_SUM) + Target::wire(row, BaseSumGate::<2>::WIRE_SUM) } } #[derive(Debug)] struct BaseSumGenerator { - gate_index: usize, + row: usize, limbs: Vec, } @@ -95,10 +92,7 @@ impl SimpleGenerator for BaseSumGenerator { acc * F::from_canonical_usize(B) + F::from_bool(limb) }); - out_buffer.set_target( - Target::wire(self.gate_index, BaseSumGate::::WIRE_SUM), - sum, - ); + out_buffer.set_target(Target::wire(self.row, BaseSumGate::::WIRE_SUM), sum); } } diff --git a/plonky2/src/gadgets/split_join.rs b/plonky2/src/gadgets/split_join.rs index 8c7c9c3f..9c9e8d3d 100644 --- a/plonky2/src/gadgets/split_join.rs +++ b/plonky2/src/gadgets/split_join.rs @@ -25,9 +25,9 @@ impl, const D: usize> CircuitBuilder { let mut bits = Vec::with_capacity(num_bits); for &gate in &gates { - for limb_input in gate_type.limbs() { + for limb_column in gate_type.limbs() { // `new_unsafe` is safe here because BaseSumGate::<2> forces it to be in `{0, 1}`. - bits.push(BoolTarget::new_unsafe(Target::wire(gate, limb_input))); + bits.push(BoolTarget::new_unsafe(Target::wire(gate, limb_column))); } } for b in bits.drain(num_bits..) { diff --git a/plonky2/src/gates/arithmetic_base.rs b/plonky2/src/gates/arithmetic_base.rs index 5f73fef0..82f2e8f3 100644 --- a/plonky2/src/gates/arithmetic_base.rs +++ b/plonky2/src/gates/arithmetic_base.rs @@ -113,16 +113,12 @@ impl, const D: usize> Gate for ArithmeticGate constraints } - fn generators( - &self, - gate_index: usize, - local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( ArithmeticBaseGenerator { - gate_index, + row, const_0: local_constants[0], const_1: local_constants[1], i, @@ -174,7 +170,7 @@ impl, const D: usize> PackedEvaluableBase for #[derive(Clone, Debug)] struct ArithmeticBaseGenerator, const D: usize> { - gate_index: usize, + row: usize, const_0: F, const_1: F, i: usize, @@ -190,19 +186,18 @@ impl, const D: usize> SimpleGenerator ArithmeticGate::wire_ith_addend(self.i), ] .iter() - .map(|&i| Target::wire(self.gate_index, i)) + .map(|&i| Target::wire(self.row, i)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let get_wire = - |wire: usize| -> F { witness.get_target(Target::wire(self.gate_index, wire)) }; + let get_wire = |wire: usize| -> F { witness.get_target(Target::wire(self.row, wire)) }; let multiplicand_0 = get_wire(ArithmeticGate::wire_ith_multiplicand_0(self.i)); let multiplicand_1 = get_wire(ArithmeticGate::wire_ith_multiplicand_1(self.i)); let addend = get_wire(ArithmeticGate::wire_ith_addend(self.i)); - let output_target = Target::wire(self.gate_index, ArithmeticGate::wire_ith_output(self.i)); + let output_target = Target::wire(self.row, ArithmeticGate::wire_ith_output(self.i)); let computed_output = multiplicand_0 * multiplicand_1 * self.const_0 + addend * self.const_1; diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index 6b5af067..d8180779 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -120,16 +120,12 @@ impl, const D: usize> Gate for ArithmeticExte constraints } - fn generators( - &self, - gate_index: usize, - local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( ArithmeticExtensionGenerator { - gate_index, + row, const_0: local_constants[0], const_1: local_constants[1], i, @@ -160,7 +156,7 @@ impl, const D: usize> Gate for ArithmeticExte #[derive(Clone, Debug)] struct ArithmeticExtensionGenerator, const D: usize> { - gate_index: usize, + row: usize, const_0: F, const_1: F, i: usize, @@ -175,13 +171,13 @@ impl, const D: usize> SimpleGenerator self.i, )) .chain(ArithmeticExtensionGate::::wires_ith_addend(self.i)) - .map(|i| Target::wire(self.gate_index, i)) + .map(|i| Target::wire(self.row, i)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let extract_extension = |range: Range| -> F::Extension { - let t = ExtensionTarget::from_range(self.gate_index, range); + let t = ExtensionTarget::from_range(self.row, range); witness.get_extension_target(t) }; @@ -194,7 +190,7 @@ impl, const D: usize> SimpleGenerator let addend = extract_extension(ArithmeticExtensionGate::::wires_ith_addend(self.i)); let output_target = ExtensionTarget::from_range( - self.gate_index, + self.row, ArithmeticExtensionGate::::wires_ith_output(self.i), ); diff --git a/plonky2/src/gates/assert_le.rs b/plonky2/src/gates/assert_le.rs index cec7274b..9a5b2845 100644 --- a/plonky2/src/gates/assert_le.rs +++ b/plonky2/src/gates/assert_le.rs @@ -251,13 +251,9 @@ impl, const D: usize> Gate for AssertLessThan constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = AssertLessThanGenerator:: { - gate_index, + row, gate: self.clone(), }; vec![Box::new(gen.adapter())] @@ -354,7 +350,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Debug)] struct AssertLessThanGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: AssertLessThanGate, } @@ -362,7 +358,7 @@ impl, const D: usize> SimpleGenerator for AssertLessThanGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); vec![ local_target(self.gate.wire_first_input()), @@ -371,12 +367,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let first_input = get_local_wire(self.gate.wire_first_input()); let second_input = get_local_wire(self.gate.wire_second_input()); diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index e03a2c5b..adb90988 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -104,13 +104,9 @@ impl, const D: usize, const B: usize> Gate fo constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = BaseSplitGenerator:: { - gate_index, + row, num_limbs: self.num_limbs, }; vec![Box::new(gen.adapter())] @@ -161,18 +157,18 @@ impl, const D: usize, const B: usize> PackedEvaluab #[derive(Debug)] pub struct BaseSplitGenerator { - gate_index: usize, + row: usize, num_limbs: usize, } impl SimpleGenerator for BaseSplitGenerator { fn dependencies(&self) -> Vec { - vec![Target::wire(self.gate_index, BaseSumGate::::WIRE_SUM)] + vec![Target::wire(self.row, BaseSumGate::::WIRE_SUM)] } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let sum_value = witness - .get_target(Target::wire(self.gate_index, BaseSumGate::::WIRE_SUM)) + .get_target(Target::wire(self.row, BaseSumGate::::WIRE_SUM)) .to_canonical_u64() as usize; debug_assert_eq!( (0..self.num_limbs).fold(sum_value, |acc, _| acc / B), @@ -181,7 +177,7 @@ impl SimpleGenerator for BaseSplitGenerator ); let limbs = (BaseSumGate::::START_LIMBS..BaseSumGate::::START_LIMBS + self.num_limbs) - .map(|i| Target::wire(self.gate_index, i)); + .map(|i| Target::wire(self.row, i)); let limbs_value = (0..self.num_limbs) .scan(sum_value, |acc, _| { let tmp = *acc % B; diff --git a/plonky2/src/gates/constant.rs b/plonky2/src/gates/constant.rs index 3ca39d43..14e5dc82 100644 --- a/plonky2/src/gates/constant.rs +++ b/plonky2/src/gates/constant.rs @@ -71,11 +71,7 @@ impl, const D: usize> Gate for ConstantGate { .collect() } - fn generators( - &self, - _gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec>> { vec![] } diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index 51558a21..c8df4c35 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -161,13 +161,9 @@ impl, const D: usize> Gate for Exponentiation constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = ExponentiationGenerator:: { - gate_index, + row, gate: self.clone(), }; vec![Box::new(gen.adapter())] @@ -231,7 +227,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Debug)] struct ExponentiationGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: ExponentiationGate, } @@ -239,7 +235,7 @@ impl, const D: usize> SimpleGenerator for ExponentiationGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); let mut deps = Vec::with_capacity(self.gate.num_power_bits + 1); deps.push(local_target(self.gate.wire_base())); @@ -250,12 +246,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let num_power_bits = self.gate.num_power_bits; let base = get_local_wire(self.gate.wire_base()); diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 861b67c0..a33287e1 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -84,13 +84,13 @@ pub trait Gate, const D: usize>: 'static + Send + S fn eval_filtered( &self, mut vars: EvaluationVars, - gate_index: usize, + row: usize, selector_index: usize, group_range: Range, num_selectors: usize, ) -> Vec { let filter = compute_filter( - gate_index, + row, group_range, vars.local_constants[selector_index], num_selectors > 1, @@ -107,7 +107,7 @@ pub trait Gate, const D: usize>: 'static + Send + S fn eval_filtered_base_batch( &self, mut vars_batch: EvaluationVarsBaseBatch, - gate_index: usize, + row: usize, selector_index: usize, group_range: Range, num_selectors: usize, @@ -116,7 +116,7 @@ pub trait Gate, const D: usize>: 'static + Send + S .iter() .map(|vars| { compute_filter( - gate_index, + row, group_range.clone(), vars.local_constants[selector_index], num_selectors > 1, @@ -136,7 +136,7 @@ pub trait Gate, const D: usize>: 'static + Send + S &self, builder: &mut CircuitBuilder, mut vars: EvaluationTargets, - gate_index: usize, + row: usize, selector_index: usize, group_range: Range, num_selectors: usize, @@ -144,7 +144,7 @@ pub trait Gate, const D: usize>: 'static + Send + S ) { let filter = compute_filter_recursively( builder, - gate_index, + row, group_range, vars.local_constants[selector_index], num_selectors > 1, @@ -158,11 +158,7 @@ pub trait Gate, const D: usize>: 'static + Send + S /// The generators used to populate the witness. /// Note: This should return exactly 1 generator per operation in the gate. - fn generators( - &self, - gate_index: usize, - local_constants: &[F], - ) -> Vec>>; + fn generators(&self, row: usize, local_constants: &[F]) -> Vec>>; /// The number of wires used by this gate. fn num_wires(&self) -> usize; @@ -222,8 +218,8 @@ impl, const D: usize> Debug for GateRef { } /// Map between gate parameters and available slots. -/// An available slot is of the form `(gate_index, op)`, meaning the current available slot -/// is at gate index `gate_index` in the `op`-th operation. +/// An available slot is of the form `(row, op)`, meaning the current available slot +/// is at gate index `row` in the `op`-th operation. #[derive(Clone, Debug, Default)] pub struct CurrentSlot, const D: usize> { pub current_slot: HashMap, (usize, usize)>, @@ -243,16 +239,11 @@ pub struct PrefixedGate, const D: usize> { pub prefix: Vec, } -/// A gate's filter designed so that it is non-zero if `s = gate_index`. -fn compute_filter( - gate_index: usize, - group_range: Range, - s: K, - many_selector: bool, -) -> K { - debug_assert!(group_range.contains(&gate_index)); +/// A gate's filter designed so that it is non-zero if `s = row`. +fn compute_filter(row: usize, group_range: Range, s: K, many_selector: bool) -> K { + debug_assert!(group_range.contains(&row)); group_range - .filter(|&i| i != gate_index) + .filter(|&i| i != row) .chain(many_selector.then(|| UNUSED_SELECTOR)) .map(|i| K::from_canonical_usize(i) - s) .product() @@ -260,14 +251,14 @@ fn compute_filter( fn compute_filter_recursively, const D: usize>( builder: &mut CircuitBuilder, - gate_index: usize, + row: usize, group_range: Range, s: ExtensionTarget, many_selectors: bool, ) -> ExtensionTarget { - debug_assert!(group_range.contains(&gate_index)); + debug_assert!(group_range.contains(&row)); let v = group_range - .filter(|&i| i != gate_index) + .filter(|&i| i != row) .chain(many_selectors.then(|| UNUSED_SELECTOR)) .map(|i| { let c = builder.constant_extension(F::Extension::from_canonical_usize(i)); diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index 46c42113..88f8216c 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -169,13 +169,9 @@ impl, const D: usize> Gate constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = InterpolationGenerator:: { - gate_index, + row, gate: *self, _phantom: PhantomData, }; @@ -205,7 +201,7 @@ impl, const D: usize> Gate #[derive(Debug)] struct InterpolationGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: HighDegreeInterpolationGate, _phantom: PhantomData, } @@ -214,14 +210,14 @@ impl, const D: usize> SimpleGenerator for InterpolationGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| { + let local_target = |column| { Target::Wire(Wire { - gate: self.gate_index, - input, + row: self.row, + column, }) }; - let local_targets = |inputs: Range| inputs.map(local_target); + let local_targets = |columns: Range| columns.map(local_target); let num_points = self.gate.num_points(); let mut deps = Vec::with_capacity(1 + D + num_points * D); @@ -235,12 +231,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let get_local_ext = |wire_range: Range| { debug_assert_eq!(wire_range.len(), D); diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 845da5ab..501227bf 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -261,13 +261,9 @@ impl, const D: usize> Gate for LowDegreeInter constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = InterpolationGenerator:: { - gate_index, + row, gate: *self, _phantom: PhantomData, }; @@ -296,7 +292,7 @@ impl, const D: usize> Gate for LowDegreeInter #[derive(Debug)] struct InterpolationGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: LowDegreeInterpolationGate, _phantom: PhantomData, } @@ -305,14 +301,14 @@ impl, const D: usize> SimpleGenerator for InterpolationGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| { + let local_target = |column| { Target::Wire(Wire { - gate: self.gate_index, - input, + row: self.row, + column, }) }; - let local_targets = |inputs: Range| inputs.map(local_target); + let local_targets = |columns: Range| columns.map(local_target); let num_points = self.gate.num_points(); let mut deps = Vec::with_capacity(1 + D + num_points * D); @@ -326,12 +322,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let get_local_ext = |wire_range: Range| { debug_assert_eq!(wire_range.len(), D); @@ -373,7 +369,7 @@ impl, const D: usize> SimpleGenerator .skip(2) { out_buffer.set_extension_target( - ExtensionTarget::from_range(self.gate_index, self.gate.powers_evaluation_point(i)), + ExtensionTarget::from_range(self.row, self.gate.powers_evaluation_point(i)), power, ); } diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index 09701260..592367aa 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -108,16 +108,12 @@ impl, const D: usize> Gate for MulExtensionGa constraints } - fn generators( - &self, - gate_index: usize, - local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( MulExtensionGenerator { - gate_index, + row, const_0: local_constants[0], i, } @@ -147,7 +143,7 @@ impl, const D: usize> Gate for MulExtensionGa #[derive(Clone, Debug)] struct MulExtensionGenerator, const D: usize> { - gate_index: usize, + row: usize, const_0: F, i: usize, } @@ -158,13 +154,13 @@ impl, const D: usize> SimpleGenerator fn dependencies(&self) -> Vec { MulExtensionGate::::wires_ith_multiplicand_0(self.i) .chain(MulExtensionGate::::wires_ith_multiplicand_1(self.i)) - .map(|i| Target::wire(self.gate_index, i)) + .map(|i| Target::wire(self.row, i)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let extract_extension = |range: Range| -> F::Extension { - let t = ExtensionTarget::from_range(self.gate_index, range); + let t = ExtensionTarget::from_range(self.row, range); witness.get_extension_target(t) }; @@ -173,10 +169,8 @@ impl, const D: usize> SimpleGenerator let multiplicand_1 = extract_extension(MulExtensionGate::::wires_ith_multiplicand_1(self.i)); - let output_target = ExtensionTarget::from_range( - self.gate_index, - MulExtensionGate::::wires_ith_output(self.i), - ); + let output_target = + ExtensionTarget::from_range(self.row, MulExtensionGate::::wires_ith_output(self.i)); let computed_output = (multiplicand_0 * multiplicand_1).scalar_mul(self.const_0); diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index 4cd872d8..06cc9486 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -31,11 +31,7 @@ impl, const D: usize> Gate for NoopGate { Vec::new() } - fn generators( - &self, - _gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec>> { Vec::new() } diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 366e200e..01386cd1 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -374,13 +374,9 @@ impl, const D: usize> Gate for PoseidonGate Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = PoseidonGenerator:: { - gate_index, + row, _phantom: PhantomData, }; vec![Box::new(gen.adapter())] @@ -409,7 +405,7 @@ impl, const D: usize> Gate for PoseidonGate + Poseidon, const D: usize> { - gate_index: usize, + row: usize, _phantom: PhantomData, } @@ -420,14 +416,14 @@ impl + Poseidon, const D: usize> SimpleGenerator (0..SPONGE_WIDTH) .map(|i| PoseidonGate::::wire_input(i)) .chain(Some(PoseidonGate::::WIRE_SWAP)) - .map(|input| Target::wire(self.gate_index, input)) + .map(|column| Target::wire(self.row, column)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; let mut state = (0..SPONGE_WIDTH) @@ -559,7 +555,7 @@ mod tests { let mut builder = CircuitBuilder::new(config); type Gate = PoseidonGate; let gate = Gate::new(); - let gate_index = builder.add_gate(gate, vec![]); + let row = builder.add_gate(gate, vec![]); let circuit = builder.build_prover::(); let permutation_inputs = (0..SPONGE_WIDTH) @@ -569,16 +565,16 @@ mod tests { let mut inputs = PartialWitness::new(); inputs.set_wire( Wire { - gate: gate_index, - input: Gate::WIRE_SWAP, + row, + column: Gate::WIRE_SWAP, }, F::ZERO, ); for i in 0..SPONGE_WIDTH { inputs.set_wire( Wire { - gate: gate_index, - input: Gate::wire_input(i), + row, + column: Gate::wire_input(i), }, permutation_inputs[i], ); @@ -590,8 +586,8 @@ mod tests { F::poseidon(permutation_inputs.try_into().unwrap()); for i in 0..SPONGE_WIDTH { let out = witness.get_wire(Wire { - gate: 0, - input: Gate::wire_output(i), + row: 0, + column: Gate::wire_output(i), }); assert_eq!(out, expected_outputs[i]); } diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index 8a989078..d011fbd7 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -181,12 +181,8 @@ impl + Poseidon, const D: usize> Gate for Pos .collect() } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { - let gen = PoseidonMdsGenerator:: { gate_index }; + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { + let gen = PoseidonMdsGenerator:: { row }; vec![Box::new(gen.adapter())] } @@ -209,7 +205,7 @@ impl + Poseidon, const D: usize> Gate for Pos #[derive(Clone, Debug)] struct PoseidonMdsGenerator { - gate_index: usize, + row: usize, } impl + Poseidon, const D: usize> SimpleGenerator @@ -218,14 +214,13 @@ impl + Poseidon, const D: usize> SimpleGenerator fn dependencies(&self) -> Vec { (0..SPONGE_WIDTH) .flat_map(|i| { - Target::wires_from_range(self.gate_index, PoseidonMdsGate::::wires_input(i)) + Target::wires_from_range(self.row, PoseidonMdsGate::::wires_input(i)) }) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let get_local_get_target = - |wire_range| ExtensionTarget::from_range(self.gate_index, wire_range); + let get_local_get_target = |wire_range| ExtensionTarget::from_range(self.row, wire_range); let get_local_ext = |wire_range| witness.get_extension_target(get_local_get_target(wire_range)); diff --git a/plonky2/src/gates/public_input.rs b/plonky2/src/gates/public_input.rs index 20fc59c8..f970e404 100644 --- a/plonky2/src/gates/public_input.rs +++ b/plonky2/src/gates/public_input.rs @@ -62,11 +62,7 @@ impl, const D: usize> Gate for PublicInputGat .collect() } - fn generators( - &self, - _gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec>> { Vec::new() } diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index 5b4935d9..8a98021a 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -216,16 +216,12 @@ impl, const D: usize> Gate for RandomAccessGa constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { (0..self.num_copies) .map(|copy| { let g: Box> = Box::new( RandomAccessGenerator { - gate_index, + row, gate: *self, copy, } @@ -309,7 +305,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Debug)] struct RandomAccessGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: RandomAccessGate, copy: usize, } @@ -318,7 +314,7 @@ impl, const D: usize> SimpleGenerator for RandomAccessGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); let mut deps = vec![local_target(self.gate.wire_access_index(self.copy))]; for i in 0..self.gate.vec_size() { @@ -328,13 +324,13 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); - let mut set_local_wire = |input, value| out_buffer.set_wire(local_wire(input), value); + let get_local_wire = |column| witness.get_wire(local_wire(column)); + let mut set_local_wire = |column, value| out_buffer.set_wire(local_wire(column), value); let copy = self.copy; let vec_size = self.gate.vec_size(); diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index 2abf8425..98fba207 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -135,14 +135,10 @@ impl, const D: usize> Gate for ReducingGate Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { vec![Box::new( ReducingGenerator { - gate_index, + row, gate: self.clone(), } .adapter(), @@ -168,7 +164,7 @@ impl, const D: usize> Gate for ReducingGate { - gate_index: usize, + row: usize, gate: ReducingGate, } @@ -177,13 +173,13 @@ impl, const D: usize> SimpleGenerator for Reduci ReducingGate::::wires_alpha() .chain(ReducingGate::::wires_old_acc()) .chain(self.gate.wires_coeffs()) - .map(|i| Target::wire(self.gate_index, i)) + .map(|i| Target::wire(self.row, i)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let extract_extension = |range: Range| -> F::Extension { - let t = ExtensionTarget::from_range(self.gate_index, range); + let t = ExtensionTarget::from_range(self.row, range); witness.get_extension_target(t) }; @@ -193,14 +189,13 @@ impl, const D: usize> SimpleGenerator for Reduci &self .gate .wires_coeffs() - .map(|i| Target::wire(self.gate_index, i)) + .map(|i| Target::wire(self.row, i)) .collect::>(), ); let accs = (0..self.gate.num_coeffs) - .map(|i| ExtensionTarget::from_range(self.gate_index, self.gate.wires_accs(i))) + .map(|i| ExtensionTarget::from_range(self.row, self.gate.wires_accs(i))) .collect::>(); - let output = - ExtensionTarget::from_range(self.gate_index, ReducingGate::::wires_output()); + let output = ExtensionTarget::from_range(self.row, ReducingGate::::wires_output()); let mut acc = old_acc; for i in 0..self.gate.num_coeffs { diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index 6655f1d7..14f31404 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -135,14 +135,10 @@ impl, const D: usize> Gate for ReducingExtens .collect() } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { vec![Box::new( ReducingGenerator { - gate_index, + row, gate: self.clone(), } .adapter(), @@ -168,7 +164,7 @@ impl, const D: usize> Gate for ReducingExtens #[derive(Debug)] struct ReducingGenerator { - gate_index: usize, + row: usize, gate: ReducingExtensionGate, } @@ -177,13 +173,13 @@ impl, const D: usize> SimpleGenerator for Reduci ReducingExtensionGate::::wires_alpha() .chain(ReducingExtensionGate::::wires_old_acc()) .chain((0..self.gate.num_coeffs).flat_map(ReducingExtensionGate::::wires_coeff)) - .map(|i| Target::wire(self.gate_index, i)) + .map(|i| Target::wire(self.row, i)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let local_extension = |range: Range| -> F::Extension { - let t = ExtensionTarget::from_range(self.gate_index, range); + let t = ExtensionTarget::from_range(self.row, range); witness.get_extension_target(t) }; @@ -193,7 +189,7 @@ impl, const D: usize> SimpleGenerator for Reduci .map(|i| local_extension(ReducingExtensionGate::::wires_coeff(i))) .collect::>(); let accs = (0..self.gate.num_coeffs) - .map(|i| ExtensionTarget::from_range(self.gate_index, self.gate.wires_accs(i))) + .map(|i| ExtensionTarget::from_range(self.row, self.gate.wires_accs(i))) .collect::>(); let mut acc = old_acc; diff --git a/plonky2/src/iop/ext_target.rs b/plonky2/src/iop/ext_target.rs index ff154af2..4ae92ea1 100644 --- a/plonky2/src/iop/ext_target.rs +++ b/plonky2/src/iop/ext_target.rs @@ -52,9 +52,9 @@ impl ExtensionTarget { res.try_into().unwrap() } - pub fn from_range(gate: usize, range: Range) -> Self { + pub fn from_range(row: usize, range: Range) -> Self { debug_assert_eq!(range.end - range.start, D); - Target::wires_from_range(gate, range).try_into().unwrap() + Target::wires_from_range(row, range).try_into().unwrap() } } diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 5dcd7ffc..265a04ec 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -306,7 +306,7 @@ impl SimpleGenerator for NonzeroTestGenerator { /// Generator used to fill an extra constant. #[derive(Debug, Clone)] pub(crate) struct ConstantGenerator { - pub gate_index: usize, + pub row: usize, pub constant_index: usize, pub wire_index: usize, pub constant: F, @@ -324,9 +324,6 @@ impl SimpleGenerator for ConstantGenerator { } fn run_once(&self, _witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - out_buffer.set_target( - Target::wire(self.gate_index, self.wire_index), - self.constant, - ); + out_buffer.set_target(Target::wire(self.row, self.wire_index), self.constant); } } diff --git a/plonky2/src/iop/target.rs b/plonky2/src/iop/target.rs index de3e4911..d26782da 100644 --- a/plonky2/src/iop/target.rs +++ b/plonky2/src/iop/target.rs @@ -16,8 +16,8 @@ pub enum Target { } impl Target { - pub fn wire(gate: usize, input: usize) -> Self { - Self::Wire(Wire { gate, input }) + pub fn wire(row: usize, column: usize) -> Self { + Self::Wire(Wire { row, column }) } pub fn is_routable(&self, config: &CircuitConfig) -> bool { @@ -27,13 +27,13 @@ impl Target { } } - pub fn wires_from_range(gate: usize, range: Range) -> Vec { - range.map(|i| Self::wire(gate, i)).collect() + pub fn wires_from_range(row: usize, range: Range) -> Vec { + range.map(|i| Self::wire(row, i)).collect() } pub fn index(&self, num_wires: usize, degree: usize) -> usize { match self { - Target::Wire(Wire { gate, input }) => gate * num_wires + input, + Target::Wire(Wire { row, column }) => row * num_wires + column, Target::VirtualTarget { index } => degree * num_wires + index, } } diff --git a/plonky2/src/iop/wire.rs b/plonky2/src/iop/wire.rs index c159820b..dd46afe2 100644 --- a/plonky2/src/iop/wire.rs +++ b/plonky2/src/iop/wire.rs @@ -2,21 +2,26 @@ use std::ops::Range; use crate::plonk::circuit_data::CircuitConfig; -/// Represents a wire in the circuit. +/// Represents a wire in the circuit, seen as a `degree x num_wires` table. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Wire { - /// The index of the associated gate. - pub gate: usize, - /// The index of the gate input wherein this wire is inserted. - pub input: usize, + /// Row index of the wire. + pub row: usize, + /// Column index of the wire. + pub column: usize, } impl Wire { pub fn is_routable(&self, config: &CircuitConfig) -> bool { - self.input < config.num_routed_wires + self.column < config.num_routed_wires } pub fn from_range(gate: usize, range: Range) -> Vec { - range.map(|i| Wire { gate, input: i }).collect() + range + .map(|i| Wire { + row: gate, + column: i, + }) + .collect() } } diff --git a/plonky2/src/iop/witness.rs b/plonky2/src/iop/witness.rs index 6b6a98d5..60bb730b 100644 --- a/plonky2/src/iop/witness.rs +++ b/plonky2/src/iop/witness.rs @@ -315,7 +315,7 @@ impl<'a, F: Field> PartitionWitness<'a, F> { let mut wire_values = vec![vec![F::ZERO; self.degree]; self.num_wires]; for i in 0..self.degree { for j in 0..self.num_wires { - let t = Target::Wire(Wire { gate: i, input: j }); + let t = Target::Wire(Wire { row: i, column: j }); if let Some(x) = self.try_get_target(t) { wire_values[j][i] = x; } diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 1c2282d9..4bda9618 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -218,12 +218,12 @@ impl, const D: usize> CircuitBuilder { ); constants.resize(gate_type.num_constants(), F::ZERO); - let gate_index = self.gate_instances.len(); + let row = self.gate_instances.len(); self.constant_generators .extend(gate_type.extra_constant_wires().into_iter().map( |(constant_index, wire_index)| ConstantGenerator { - gate_index, + row, constant_index, wire_index, constant: F::ZERO, // Placeholder; will be replaced later. @@ -243,7 +243,7 @@ impl, const D: usize> CircuitBuilder { constants, }); - gate_index + row } fn check_gate_compatibility>(&self, gate: &G) { @@ -400,7 +400,7 @@ impl, const D: usize> CircuitBuilder { }) } - /// Find an available slot, of the form `(gate_index, op)` for gate `G` using parameters `params` + /// Find an available slot, of the form `(row, op)` for gate `G` using parameters `params` /// and constants `constants`. Parameters are any data used to differentiate which gate should be /// used for the given operation. pub fn find_slot + Clone>( @@ -524,10 +524,10 @@ impl, const D: usize> CircuitBuilder { // For each "regular" blinding factor, we simply add a no-op gate, and insert a random value // for each wire. for _ in 0..regular_poly_openings { - let gate = self.add_gate(NoopGate, vec![]); + let row = self.add_gate(NoopGate, vec![]); for w in 0..num_wires { self.add_simple_generator(RandomValueGenerator { - target: Target::Wire(Wire { gate, input: w }), + target: Target::Wire(Wire { row, column: w }), }); } } @@ -542,18 +542,18 @@ impl, const D: usize> CircuitBuilder { for w in 0..num_routed_wires { self.add_simple_generator(RandomValueGenerator { target: Target::Wire(Wire { - gate: gate_1, - input: w, + row: gate_1, + column: w, }), }); self.generate_copy( Target::Wire(Wire { - gate: gate_1, - input: w, + row: gate_1, + column: w, }), Target::Wire(Wire { - gate: gate_2, - input: w, + row: gate_2, + column: w, }), ); } @@ -596,7 +596,10 @@ impl, const D: usize> CircuitBuilder { for gate in 0..degree { for input in 0..config.num_wires { - forest.add(Target::Wire(Wire { gate, input })); + forest.add(Target::Wire(Wire { + row: gate, + column: input, + })); } } @@ -677,9 +680,9 @@ impl, const D: usize> CircuitBuilder { .zip(self.constant_generators.clone()) { // Set the constant in the constant polynomial. - self.gate_instances[const_gen.gate_index].constants[const_gen.constant_index] = c; + self.gate_instances[const_gen.row].constants[const_gen.constant_index] = c; // Generate a copy between the target and the routable wire. - self.connect(Target::wire(const_gen.gate_index, const_gen.wire_index), t); + self.connect(Target::wire(const_gen.row, const_gen.wire_index), t); // Set the constant in the generator (it's initially set with a dummy value). const_gen.set_constant(c); self.add_simple_generator(const_gen); diff --git a/plonky2/src/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index 252db425..3bf2e91f 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -89,9 +89,9 @@ impl Forest { let mut partition = HashMap::<_, Vec<_>>::new(); // Here we keep just the Wire targets, filtering out everything else. - for gate in 0..self.degree { - for input in 0..self.num_routed_wires { - let w = Wire { gate, input }; + for row in 0..self.degree { + for column in 0..self.num_routed_wires { + let w = Wire { row, column }; let t = Target::Wire(w); let x_parent = self.parents[self.target_index(t)]; partition.entry(x_parent).or_default().push(w); @@ -144,11 +144,11 @@ impl WirePartition { } let mut sigma = Vec::new(); - for input in 0..num_routed_wires { - for gate in 0..degree { - let wire = Wire { gate, input }; + for column in 0..num_routed_wires { + for row in 0..degree { + let wire = Wire { row, column }; let neighbor = neighbors[&wire]; - sigma.push(neighbor.input * degree + neighbor.gate); + sigma.push(neighbor.column * degree + neighbor.row); } } sigma diff --git a/plonky2/src/util/reducing.rs b/plonky2/src/util/reducing.rs index 991b30e7..5747e197 100644 --- a/plonky2/src/util/reducing.rs +++ b/plonky2/src/util/reducing.rs @@ -155,21 +155,21 @@ impl ReducingFactorTarget { reversed_terms.reverse(); for chunk in reversed_terms.chunks_exact(max_coeffs_len) { let gate = ReducingGate::new(max_coeffs_len); - let gate_index = builder.add_gate(gate.clone(), vec![]); + let row = builder.add_gate(gate.clone(), vec![]); builder.connect_extension( self.base, - ExtensionTarget::from_range(gate_index, ReducingGate::::wires_alpha()), + ExtensionTarget::from_range(row, ReducingGate::::wires_alpha()), ); builder.connect_extension( acc, - ExtensionTarget::from_range(gate_index, ReducingGate::::wires_old_acc()), + ExtensionTarget::from_range(row, ReducingGate::::wires_old_acc()), ); for (&t, c) in chunk.iter().zip(gate.wires_coeffs()) { - builder.connect(t, Target::wire(gate_index, c)); + builder.connect(t, Target::wire(row, c)); } - acc = ExtensionTarget::from_range(gate_index, ReducingGate::::wires_output()); + acc = ExtensionTarget::from_range(row, ReducingGate::::wires_output()); } acc @@ -205,31 +205,24 @@ impl ReducingFactorTarget { reversed_terms.reverse(); for chunk in reversed_terms.chunks_exact(max_coeffs_len) { let gate = ReducingExtensionGate::new(max_coeffs_len); - let gate_index = builder.add_gate(gate.clone(), vec![]); + let row = builder.add_gate(gate.clone(), vec![]); builder.connect_extension( self.base, - ExtensionTarget::from_range(gate_index, ReducingExtensionGate::::wires_alpha()), + ExtensionTarget::from_range(row, ReducingExtensionGate::::wires_alpha()), ); builder.connect_extension( acc, - ExtensionTarget::from_range( - gate_index, - ReducingExtensionGate::::wires_old_acc(), - ), + ExtensionTarget::from_range(row, ReducingExtensionGate::::wires_old_acc()), ); for (i, &t) in chunk.iter().enumerate() { builder.connect_extension( t, - ExtensionTarget::from_range( - gate_index, - ReducingExtensionGate::::wires_coeff(i), - ), + ExtensionTarget::from_range(row, ReducingExtensionGate::::wires_coeff(i)), ); } - acc = - ExtensionTarget::from_range(gate_index, ReducingExtensionGate::::wires_output()); + acc = ExtensionTarget::from_range(row, ReducingExtensionGate::::wires_output()); } acc diff --git a/u32/src/gadgets/arithmetic_u32.rs b/u32/src/gadgets/arithmetic_u32.rs index 2b494a52..9ec0c29f 100644 --- a/u32/src/gadgets/arithmetic_u32.rs +++ b/u32/src/gadgets/arithmetic_u32.rs @@ -131,26 +131,14 @@ impl, const D: usize> CircuitBuilderU32 } let gate = U32ArithmeticGate::::new_from_config(&self.config); - let (gate_index, copy) = self.find_slot(gate, &[], &[]); + let (row, copy) = self.find_slot(gate, &[], &[]); - self.connect( - Target::wire(gate_index, gate.wire_ith_multiplicand_0(copy)), - x.0, - ); - self.connect( - Target::wire(gate_index, gate.wire_ith_multiplicand_1(copy)), - y.0, - ); - self.connect(Target::wire(gate_index, gate.wire_ith_addend(copy)), z.0); + self.connect(Target::wire(row, gate.wire_ith_multiplicand_0(copy)), x.0); + self.connect(Target::wire(row, gate.wire_ith_multiplicand_1(copy)), y.0); + self.connect(Target::wire(row, gate.wire_ith_addend(copy)), z.0); - let output_low = U32Target(Target::wire( - gate_index, - gate.wire_ith_output_low_half(copy), - )); - let output_high = U32Target(Target::wire( - gate_index, - gate.wire_ith_output_high_half(copy), - )); + let output_low = U32Target(Target::wire(row, gate.wire_ith_output_low_half(copy))); + let output_high = U32Target(Target::wire(row, gate.wire_ith_output_high_half(copy))); (output_low, output_high) } @@ -168,22 +156,20 @@ impl, const D: usize> CircuitBuilderU32 _ => { let num_addends = to_add.len(); let gate = U32AddManyGate::::new_from_config(&self.config, num_addends); - let (gate_index, copy) = + let (row, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]); for j in 0..num_addends { self.connect( - Target::wire(gate_index, gate.wire_ith_op_jth_addend(copy, j)), + Target::wire(row, gate.wire_ith_op_jth_addend(copy, j)), to_add[j].0, ); } let zero = self.zero(); - self.connect(Target::wire(gate_index, gate.wire_ith_carry(copy)), zero); + self.connect(Target::wire(row, gate.wire_ith_carry(copy)), zero); - let output_low = - U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy))); - let output_high = - U32Target(Target::wire(gate_index, gate.wire_ith_output_carry(copy))); + let output_low = U32Target(Target::wire(row, gate.wire_ith_output_result(copy))); + let output_high = U32Target(Target::wire(row, gate.wire_ith_output_carry(copy))); (output_low, output_high) } @@ -202,18 +188,18 @@ impl, const D: usize> CircuitBuilderU32 let num_addends = to_add.len(); let gate = U32AddManyGate::::new_from_config(&self.config, num_addends); - let (gate_index, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]); + let (row, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]); for j in 0..num_addends { self.connect( - Target::wire(gate_index, gate.wire_ith_op_jth_addend(copy, j)), + Target::wire(row, gate.wire_ith_op_jth_addend(copy, j)), to_add[j].0, ); } - self.connect(Target::wire(gate_index, gate.wire_ith_carry(copy)), carry.0); + self.connect(Target::wire(row, gate.wire_ith_carry(copy)), carry.0); - let output = U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy))); - let output_carry = U32Target(Target::wire(gate_index, gate.wire_ith_output_carry(copy))); + let output = U32Target(Target::wire(row, gate.wire_ith_output_result(copy))); + let output_carry = U32Target(Target::wire(row, gate.wire_ith_output_carry(copy))); (output, output_carry) } @@ -226,17 +212,17 @@ impl, const D: usize> CircuitBuilderU32 // Returns x - y - borrow, as a pair (result, borrow), where borrow is 0 or 1 depending on whether borrowing from the next digit is required (iff y + borrow > x). fn sub_u32(&mut self, x: U32Target, y: U32Target, borrow: U32Target) -> (U32Target, U32Target) { let gate = U32SubtractionGate::::new_from_config(&self.config); - let (gate_index, copy) = self.find_slot(gate, &[], &[]); + let (row, copy) = self.find_slot(gate, &[], &[]); - self.connect(Target::wire(gate_index, gate.wire_ith_input_x(copy)), x.0); - self.connect(Target::wire(gate_index, gate.wire_ith_input_y(copy)), y.0); + self.connect(Target::wire(row, gate.wire_ith_input_x(copy)), x.0); + self.connect(Target::wire(row, gate.wire_ith_input_y(copy)), y.0); self.connect( - Target::wire(gate_index, gate.wire_ith_input_borrow(copy)), + Target::wire(row, gate.wire_ith_input_borrow(copy)), borrow.0, ); - let output_result = U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy))); - let output_borrow = U32Target(Target::wire(gate_index, gate.wire_ith_output_borrow(copy))); + let output_result = U32Target(Target::wire(row, gate.wire_ith_output_result(copy))); + let output_borrow = U32Target(Target::wire(row, gate.wire_ith_output_borrow(copy))); (output_result, output_borrow) } diff --git a/u32/src/gadgets/multiple_comparison.rs b/u32/src/gadgets/multiple_comparison.rs index b2f9709a..9e39f997 100644 --- a/u32/src/gadgets/multiple_comparison.rs +++ b/u32/src/gadgets/multiple_comparison.rs @@ -29,28 +29,28 @@ pub fn list_le_circuit, const D: usize>( let mut result = one; for i in 0..n { let a_le_b_gate = ComparisonGate::new(num_bits, num_chunks); - let a_le_b_gate_index = builder.add_gate(a_le_b_gate.clone(), vec![]); + let a_le_b_row = builder.add_gate(a_le_b_gate.clone(), vec![]); builder.connect( - Target::wire(a_le_b_gate_index, a_le_b_gate.wire_first_input()), + Target::wire(a_le_b_row, a_le_b_gate.wire_first_input()), a[i], ); builder.connect( - Target::wire(a_le_b_gate_index, a_le_b_gate.wire_second_input()), + Target::wire(a_le_b_row, a_le_b_gate.wire_second_input()), b[i], ); - let a_le_b_result = Target::wire(a_le_b_gate_index, a_le_b_gate.wire_result_bool()); + let a_le_b_result = Target::wire(a_le_b_row, a_le_b_gate.wire_result_bool()); let b_le_a_gate = ComparisonGate::new(num_bits, num_chunks); - let b_le_a_gate_index = builder.add_gate(b_le_a_gate.clone(), vec![]); + let b_le_a_row = builder.add_gate(b_le_a_gate.clone(), vec![]); builder.connect( - Target::wire(b_le_a_gate_index, b_le_a_gate.wire_first_input()), + Target::wire(b_le_a_row, b_le_a_gate.wire_first_input()), b[i], ); builder.connect( - Target::wire(b_le_a_gate_index, b_le_a_gate.wire_second_input()), + Target::wire(b_le_a_row, b_le_a_gate.wire_second_input()), a[i], ); - let b_le_a_result = Target::wire(b_le_a_gate_index, b_le_a_gate.wire_result_bool()); + let b_le_a_result = Target::wire(b_le_a_row, b_le_a_gate.wire_result_bool()); let these_limbs_equal = builder.mul(a_le_b_result, b_le_a_result); let these_limbs_less_than = builder.sub(one, b_le_a_result); diff --git a/u32/src/gadgets/range_check.rs b/u32/src/gadgets/range_check.rs index a6c4a50c..cfbcef57 100644 --- a/u32/src/gadgets/range_check.rs +++ b/u32/src/gadgets/range_check.rs @@ -12,12 +12,9 @@ pub fn range_check_u32_circuit, const D: usize>( ) { let num_input_limbs = vals.len(); let gate = U32RangeCheckGate::::new(num_input_limbs); - let gate_index = builder.add_gate(gate, vec![]); + let row = builder.add_gate(gate, vec![]); for i in 0..num_input_limbs { - builder.connect( - Target::wire(gate_index, gate.wire_ith_input_limb(i)), - vals[i].0, - ); + builder.connect(Target::wire(row, gate.wire_ith_input_limb(i)), vals[i].0); } } diff --git a/u32/src/gates/add_many_u32.rs b/u32/src/gates/add_many_u32.rs index 8bfbdfb7..a96fb5b0 100644 --- a/u32/src/gates/add_many_u32.rs +++ b/u32/src/gates/add_many_u32.rs @@ -232,17 +232,13 @@ impl, const D: usize> Gate for U32AddManyGate constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( U32AddManyGenerator { gate: *self, - gate_index, + row, i, _phantom: PhantomData, } @@ -273,7 +269,7 @@ impl, const D: usize> Gate for U32AddManyGate #[derive(Clone, Debug)] struct U32AddManyGenerator, const D: usize> { gate: U32AddManyGate, - gate_index: usize, + row: usize, i: usize, _phantom: PhantomData, } @@ -282,7 +278,7 @@ impl, const D: usize> SimpleGenerator for U32AddManyGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); (0..self.gate.num_addends) .map(|j| local_target(self.gate.wire_ith_op_jth_addend(self.i, j))) @@ -291,12 +287,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let addends: Vec<_> = (0..self.gate.num_addends) .map(|j| get_local_wire(self.gate.wire_ith_op_jth_addend(self.i, j))) diff --git a/u32/src/gates/arithmetic_u32.rs b/u32/src/gates/arithmetic_u32.rs index 977f86a2..20697f97 100644 --- a/u32/src/gates/arithmetic_u32.rs +++ b/u32/src/gates/arithmetic_u32.rs @@ -193,17 +193,13 @@ impl, const D: usize> Gate for U32ArithmeticG constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( U32ArithmeticGenerator { gate: *self, - gate_index, + row, i, _phantom: PhantomData, } @@ -281,7 +277,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Clone, Debug)] struct U32ArithmeticGenerator, const D: usize> { gate: U32ArithmeticGate, - gate_index: usize, + row: usize, i: usize, _phantom: PhantomData, } @@ -290,7 +286,7 @@ impl, const D: usize> SimpleGenerator for U32ArithmeticGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); vec![ local_target(self.gate.wire_ith_multiplicand_0(self.i)), @@ -300,12 +296,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let multiplicand_0 = get_local_wire(self.gate.wire_ith_multiplicand_0(self.i)); let multiplicand_1 = get_local_wire(self.gate.wire_ith_multiplicand_1(self.i)); diff --git a/u32/src/gates/comparison.rs b/u32/src/gates/comparison.rs index 3ddfcf24..5778600b 100644 --- a/u32/src/gates/comparison.rs +++ b/u32/src/gates/comparison.rs @@ -283,13 +283,9 @@ impl, const D: usize> Gate for ComparisonGate constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { let gen = ComparisonGenerator:: { - gate_index, + row, gate: self.clone(), }; vec![Box::new(gen.adapter())] @@ -397,7 +393,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Debug)] struct ComparisonGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: ComparisonGate, } @@ -405,7 +401,7 @@ impl, const D: usize> SimpleGenerator for ComparisonGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); vec![ local_target(self.gate.wire_first_input()), @@ -414,12 +410,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let first_input = get_local_wire(self.gate.wire_first_input()); let second_input = get_local_wire(self.gate.wire_second_input()); diff --git a/u32/src/gates/range_check_u32.rs b/u32/src/gates/range_check_u32.rs index fe7fb43b..5b8b543f 100644 --- a/u32/src/gates/range_check_u32.rs +++ b/u32/src/gates/range_check_u32.rs @@ -134,15 +134,8 @@ impl, const D: usize> Gate for U32RangeCheckG constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { - let gen = U32RangeCheckGenerator { - gate: *self, - gate_index, - }; + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { + let gen = U32RangeCheckGenerator { gate: *self, row }; vec![Box::new(gen.adapter())] } @@ -168,7 +161,7 @@ impl, const D: usize> Gate for U32RangeCheckG #[derive(Debug)] pub struct U32RangeCheckGenerator, const D: usize> { gate: U32RangeCheckGate, - gate_index: usize, + row: usize, } impl, const D: usize> SimpleGenerator @@ -177,7 +170,7 @@ impl, const D: usize> SimpleGenerator fn dependencies(&self) -> Vec { let num_input_limbs = self.gate.num_input_limbs; (0..num_input_limbs) - .map(|i| Target::wire(self.gate_index, self.gate.wire_ith_input_limb(i))) + .map(|i| Target::wire(self.row, self.gate.wire_ith_input_limb(i))) .collect() } @@ -185,19 +178,12 @@ impl, const D: usize> SimpleGenerator let num_input_limbs = self.gate.num_input_limbs; for i in 0..num_input_limbs { let sum_value = witness - .get_target(Target::wire( - self.gate_index, - self.gate.wire_ith_input_limb(i), - )) + .get_target(Target::wire(self.row, self.gate.wire_ith_input_limb(i))) .to_canonical_u64() as u32; let base = U32RangeCheckGate::::BASE as u32; - let limbs = (0..self.gate.aux_limbs_per_input_limb()).map(|j| { - Target::wire( - self.gate_index, - self.gate.wire_ith_input_limb_jth_aux_limb(i, j), - ) - }); + let limbs = (0..self.gate.aux_limbs_per_input_limb()) + .map(|j| Target::wire(self.row, self.gate.wire_ith_input_limb_jth_aux_limb(i, j))); let limbs_value = (0..self.gate.aux_limbs_per_input_limb()) .scan(sum_value, |acc, _| { let tmp = *acc % base; diff --git a/u32/src/gates/subtraction_u32.rs b/u32/src/gates/subtraction_u32.rs index b362be60..9e00397c 100644 --- a/u32/src/gates/subtraction_u32.rs +++ b/u32/src/gates/subtraction_u32.rs @@ -182,17 +182,13 @@ impl, const D: usize> Gate for U32Subtraction constraints } - fn generators( - &self, - gate_index: usize, - _local_constants: &[F], - ) -> Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { (0..self.num_ops) .map(|i| { let g: Box> = Box::new( U32SubtractionGenerator { gate: *self, - gate_index, + row, i, _phantom: PhantomData, } @@ -265,7 +261,7 @@ impl, const D: usize> PackedEvaluableBase #[derive(Clone, Debug)] struct U32SubtractionGenerator, const D: usize> { gate: U32SubtractionGate, - gate_index: usize, + row: usize, i: usize, _phantom: PhantomData, } @@ -274,7 +270,7 @@ impl, const D: usize> SimpleGenerator for U32SubtractionGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); vec![ local_target(self.gate.wire_ith_input_x(self.i)), @@ -284,12 +280,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let input_x = get_local_wire(self.gate.wire_ith_input_x(self.i)); let input_y = get_local_wire(self.gate.wire_ith_input_y(self.i)); diff --git a/waksman/src/gates/switch.rs b/waksman/src/gates/switch.rs index 12410c59..b9ac8e70 100644 --- a/waksman/src/gates/switch.rs +++ b/waksman/src/gates/switch.rs @@ -154,15 +154,11 @@ impl, const D: usize> Gate for SwitchGate Vec>> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec>> { (0..self.num_copies) .map(|c| { let g: Box> = Box::new(SwitchGenerator:: { - gate_index, + row, gate: *self, copy: c, }); @@ -215,14 +211,14 @@ impl, const D: usize> PackedEvaluableBase for #[derive(Debug)] struct SwitchGenerator, const D: usize> { - gate_index: usize, + row: usize, gate: SwitchGate, copy: usize, } impl, const D: usize> SwitchGenerator { fn in_out_dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); let mut deps = Vec::new(); for e in 0..self.gate.chunk_size { @@ -236,7 +232,7 @@ impl, const D: usize> SwitchGenerator { } fn in_switch_dependencies(&self) -> Vec { - let local_target = |input| Target::wire(self.gate_index, input); + let local_target = |column| Target::wire(self.row, column); let mut deps = Vec::new(); for e in 0..self.gate.chunk_size { @@ -249,12 +245,12 @@ impl, const D: usize> SwitchGenerator { } fn run_in_out(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let switch_bool_wire = local_wire(self.gate.wire_switch_bool(self.copy)); @@ -279,12 +275,12 @@ impl, const D: usize> SwitchGenerator { } fn run_in_switch(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { - gate: self.gate_index, - input, + let local_wire = |column| Wire { + row: self.row, + column, }; - let get_local_wire = |input| witness.get_wire(local_wire(input)); + let get_local_wire = |column| witness.get_wire(local_wire(column)); let switch_bool = get_local_wire(self.gate.wire_switch_bool(self.copy)); for e in 0..self.gate.chunk_size { diff --git a/waksman/src/permutation.rs b/waksman/src/permutation.rs index 9a94b77c..d075b076 100644 --- a/waksman/src/permutation.rs +++ b/waksman/src/permutation.rs @@ -82,30 +82,24 @@ fn create_switch, const D: usize>( let gate = SwitchGate::new_from_config(&builder.config, chunk_size); let params = vec![F::from_canonical_usize(chunk_size)]; - let (gate_index, next_copy) = builder.find_slot(gate, ¶ms, &[]); + let (row, next_copy) = builder.find_slot(gate, ¶ms, &[]); let mut c = Vec::new(); let mut d = Vec::new(); for e in 0..chunk_size { builder.connect( a1[e], - Target::wire(gate_index, gate.wire_first_input(next_copy, e)), + Target::wire(row, gate.wire_first_input(next_copy, e)), ); builder.connect( a2[e], - Target::wire(gate_index, gate.wire_second_input(next_copy, e)), + Target::wire(row, gate.wire_second_input(next_copy, e)), ); - c.push(Target::wire( - gate_index, - gate.wire_first_output(next_copy, e), - )); - d.push(Target::wire( - gate_index, - gate.wire_second_output(next_copy, e), - )); + c.push(Target::wire(row, gate.wire_first_output(next_copy, e))); + d.push(Target::wire(row, gate.wire_second_output(next_copy, e))); } - let switch = Target::wire(gate_index, gate.wire_switch_bool(next_copy)); + let switch = Target::wire(row, gate.wire_switch_bool(next_copy)); (switch, c, d) } diff --git a/waksman/src/sorting.rs b/waksman/src/sorting.rs index 286205b1..1a9805e6 100644 --- a/waksman/src/sorting.rs +++ b/waksman/src/sorting.rs @@ -54,10 +54,10 @@ pub fn assert_le, const D: usize>( num_chunks: usize, ) { let gate = AssertLessThanGate::new(bits, num_chunks); - let gate_index = builder.add_gate(gate.clone(), vec![]); + let row = builder.add_gate(gate.clone(), vec![]); - builder.connect(Target::wire(gate_index, gate.wire_first_input()), lhs); - builder.connect(Target::wire(gate_index, gate.wire_second_input()), rhs); + builder.connect(Target::wire(row, gate.wire_first_input()), lhs); + builder.connect(Target::wire(row, gate.wire_second_input()), rhs); } /// Sort memory operations by address value, then by timestamp value.