From a31de48d880061aaf2227f2be39087c22e9bc671 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Tue, 17 May 2022 11:47:00 +0200 Subject: [PATCH] More changes --- insertion/src/insertion_gate.rs | 10 +++++----- plonky2/src/gadgets/split_join.rs | 4 ++-- plonky2/src/gates/assert_le.rs | 8 ++++---- plonky2/src/gates/exponentiation.rs | 8 ++++---- plonky2/src/gates/interpolation.rs | 12 ++++++------ plonky2/src/gates/low_degree_interpolation.rs | 12 ++++++------ plonky2/src/gates/poseidon.rs | 6 +++--- plonky2/src/gates/random_access.rs | 10 +++++----- plonky2/src/iop/target.rs | 12 +++--------- plonky2/src/plonk/permutation_argument.rs | 18 ++++++------------ u32/src/gates/add_many_u32.rs | 8 ++++---- u32/src/gates/arithmetic_u32.rs | 8 ++++---- u32/src/gates/comparison.rs | 8 ++++---- u32/src/gates/subtraction_u32.rs | 8 ++++---- waksman/src/gates/switch.rs | 16 ++++++++-------- 15 files changed, 68 insertions(+), 80 deletions(-) diff --git a/insertion/src/insertion_gate.rs b/insertion/src/insertion_gate.rs index b0413a92..449449c4 100644 --- a/insertion/src/insertion_gate.rs +++ b/insertion/src/insertion_gate.rs @@ -250,9 +250,9 @@ struct InsertionGenerator, const D: usize> { 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.gate_index, 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 +263,12 @@ impl, const D: usize> SimpleGenerator for Insert } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/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/assert_le.rs b/plonky2/src/gates/assert_le.rs index f028886b..ffe49127 100644 --- a/plonky2/src/gates/assert_le.rs +++ b/plonky2/src/gates/assert_le.rs @@ -362,7 +362,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.gate_index, column); vec![ local_target(self.gate.wire_first_input()), @@ -371,12 +371,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index 2d28825f..54750673 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -239,7 +239,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.gate_index, column); let mut deps = Vec::with_capacity(self.gate.num_power_bits + 1); deps.push(local_target(self.gate.wire_base())); @@ -250,12 +250,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/interpolation.rs b/plonky2/src/gates/interpolation.rs index c9da0726..017ab32f 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -214,14 +214,14 @@ impl, const D: usize> SimpleGenerator for InterpolationGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| { + let local_target = |column| { Target::Wire(Wire { row: self.gate_index, - column: input, + 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 +235,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 a4ff4418..b7172291 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -305,14 +305,14 @@ impl, const D: usize> SimpleGenerator for InterpolationGenerator { fn dependencies(&self) -> Vec { - let local_target = |input| { + let local_target = |column| { Target::Wire(Wire { row: self.gate_index, - column: input, + 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 +326,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/poseidon.rs b/plonky2/src/gates/poseidon.rs index 391c4ddf..41a75530 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -420,14 +420,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.gate_index, column)) .collect() } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + column, }; let mut state = (0..SPONGE_WIDTH) diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index 9b237fdd..d728201c 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -318,7 +318,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.gate_index, column); let mut deps = vec![local_target(self.gate.wire_access_index(self.copy))]; for i in 0..self.gate.vec_size() { @@ -328,13 +328,13 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/iop/target.rs b/plonky2/src/iop/target.rs index 4292dac8..4045e501 100644 --- a/plonky2/src/iop/target.rs +++ b/plonky2/src/iop/target.rs @@ -16,11 +16,8 @@ pub enum Target { } impl Target { - pub fn wire(gate: usize, input: usize) -> Self { - Self::Wire(Wire { - row: gate, - column: input, - }) + pub fn wire(row: usize, column: usize) -> Self { + Self::Wire(Wire { row, column }) } pub fn is_routable(&self, config: &CircuitConfig) -> bool { @@ -36,10 +33,7 @@ impl Target { pub fn index(&self, num_wires: usize, degree: usize) -> usize { match self { - Target::Wire(Wire { - row: gate, - column: 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/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index 1f728a51..3bf2e91f 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -89,12 +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 { - row: gate, - column: 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); @@ -147,12 +144,9 @@ impl WirePartition { } let mut sigma = Vec::new(); - for input in 0..num_routed_wires { - for gate in 0..degree { - let wire = Wire { - row: gate, - column: 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.column * degree + neighbor.row); } diff --git a/u32/src/gates/add_many_u32.rs b/u32/src/gates/add_many_u32.rs index b6664ba4..82440e49 100644 --- a/u32/src/gates/add_many_u32.rs +++ b/u32/src/gates/add_many_u32.rs @@ -282,7 +282,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.gate_index, column); (0..self.gate.num_addends) .map(|j| local_target(self.gate.wire_ith_op_jth_addend(self.i, j))) @@ -291,12 +291,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 99b8e0cf..0c713087 100644 --- a/u32/src/gates/arithmetic_u32.rs +++ b/u32/src/gates/arithmetic_u32.rs @@ -290,7 +290,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.gate_index, column); vec![ local_target(self.gate.wire_ith_multiplicand_0(self.i)), @@ -300,12 +300,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 0694031a..f1756439 100644 --- a/u32/src/gates/comparison.rs +++ b/u32/src/gates/comparison.rs @@ -405,7 +405,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.gate_index, column); vec![ local_target(self.gate.wire_first_input()), @@ -414,12 +414,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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/subtraction_u32.rs b/u32/src/gates/subtraction_u32.rs index ba788377..5dae05ac 100644 --- a/u32/src/gates/subtraction_u32.rs +++ b/u32/src/gates/subtraction_u32.rs @@ -274,7 +274,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.gate_index, column); vec![ local_target(self.gate.wire_ith_input_x(self.i)), @@ -284,12 +284,12 @@ impl, const D: usize> SimpleGenerator } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 2fd562ff..1ca44ad9 100644 --- a/waksman/src/gates/switch.rs +++ b/waksman/src/gates/switch.rs @@ -222,7 +222,7 @@ struct SwitchGenerator, const D: 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.gate_index, column); let mut deps = Vec::new(); for e in 0..self.gate.chunk_size { @@ -236,7 +236,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.gate_index, column); let mut deps = Vec::new(); for e in 0..self.gate.chunk_size { @@ -249,12 +249,12 @@ impl, const D: usize> SwitchGenerator { } fn run_in_out(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 +279,12 @@ impl, const D: usize> SwitchGenerator { } fn run_in_switch(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let local_wire = |input| Wire { + let local_wire = |column| Wire { row: self.gate_index, - column: input, + 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 {