diff --git a/insertion/src/insertion_gate.rs b/insertion/src/insertion_gate.rs index 442416d3..b0413a92 100644 --- a/insertion/src/insertion_gate.rs +++ b/insertion/src/insertion_gate.rs @@ -264,8 +264,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/gates/assert_le.rs b/plonky2/src/gates/assert_le.rs index cec7274b..f028886b 100644 --- a/plonky2/src/gates/assert_le.rs +++ b/plonky2/src/gates/assert_le.rs @@ -372,8 +372,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index 51558a21..2d28825f 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -251,8 +251,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index 46c42113..c9da0726 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -216,8 +216,8 @@ impl, const D: usize> SimpleGenerator fn dependencies(&self) -> Vec { let local_target = |input| { Target::Wire(Wire { - gate: self.gate_index, - input, + row: self.gate_index, + column: input, }) }; @@ -236,8 +236,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 845da5ab..a4ff4418 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -307,8 +307,8 @@ impl, const D: usize> SimpleGenerator fn dependencies(&self) -> Vec { let local_target = |input| { Target::Wire(Wire { - gate: self.gate_index, - input, + row: self.gate_index, + column: input, }) }; @@ -327,8 +327,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 366e200e..391c4ddf 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -426,8 +426,8 @@ impl + Poseidon, const D: usize> SimpleGenerator fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { let local_wire = |input| Wire { - gate: self.gate_index, - input, + row: self.gate_index, + column: input, }; let mut state = (0..SPONGE_WIDTH) @@ -569,16 +569,16 @@ mod tests { let mut inputs = PartialWitness::new(); inputs.set_wire( Wire { - gate: gate_index, - input: Gate::WIRE_SWAP, + row: gate_index, + 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: gate_index, + column: Gate::wire_input(i), }, permutation_inputs[i], ); @@ -590,8 +590,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/random_access.rs b/plonky2/src/gates/random_access.rs index 5b4935d9..9b237fdd 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -329,8 +329,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/plonky2/src/iop/target.rs b/plonky2/src/iop/target.rs index de3e4911..4292dac8 100644 --- a/plonky2/src/iop/target.rs +++ b/plonky2/src/iop/target.rs @@ -17,7 +17,10 @@ pub enum Target { impl Target { pub fn wire(gate: usize, input: usize) -> Self { - Self::Wire(Wire { gate, input }) + Self::Wire(Wire { + row: gate, + column: input, + }) } pub fn is_routable(&self, config: &CircuitConfig) -> bool { @@ -33,7 +36,10 @@ impl Target { 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: gate, + column: input, + }) => gate * num_wires + input, 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..747364c5 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -527,7 +527,10 @@ impl, const D: usize> CircuitBuilder { let gate = 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: gate, + column: w, + }), }); } } @@ -542,18 +545,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 +599,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, + })); } } diff --git a/plonky2/src/plonk/permutation_argument.rs b/plonky2/src/plonk/permutation_argument.rs index 252db425..1f728a51 100644 --- a/plonky2/src/plonk/permutation_argument.rs +++ b/plonky2/src/plonk/permutation_argument.rs @@ -91,7 +91,10 @@ impl Forest { // 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 }; + let w = Wire { + row: gate, + column: input, + }; let t = Target::Wire(w); let x_parent = self.parents[self.target_index(t)]; partition.entry(x_parent).or_default().push(w); @@ -146,9 +149,12 @@ impl WirePartition { let mut sigma = Vec::new(); for input in 0..num_routed_wires { for gate in 0..degree { - let wire = Wire { gate, input }; + let wire = Wire { + row: gate, + column: input, + }; let neighbor = neighbors[&wire]; - sigma.push(neighbor.input * degree + neighbor.gate); + sigma.push(neighbor.column * degree + neighbor.row); } } sigma diff --git a/u32/src/gates/add_many_u32.rs b/u32/src/gates/add_many_u32.rs index 8bfbdfb7..b6664ba4 100644 --- a/u32/src/gates/add_many_u32.rs +++ b/u32/src/gates/add_many_u32.rs @@ -292,8 +292,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/u32/src/gates/arithmetic_u32.rs b/u32/src/gates/arithmetic_u32.rs index 977f86a2..99b8e0cf 100644 --- a/u32/src/gates/arithmetic_u32.rs +++ b/u32/src/gates/arithmetic_u32.rs @@ -301,8 +301,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/u32/src/gates/comparison.rs b/u32/src/gates/comparison.rs index 3ddfcf24..0694031a 100644 --- a/u32/src/gates/comparison.rs +++ b/u32/src/gates/comparison.rs @@ -415,8 +415,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/u32/src/gates/subtraction_u32.rs b/u32/src/gates/subtraction_u32.rs index b362be60..ba788377 100644 --- a/u32/src/gates/subtraction_u32.rs +++ b/u32/src/gates/subtraction_u32.rs @@ -285,8 +285,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); diff --git a/waksman/src/gates/switch.rs b/waksman/src/gates/switch.rs index 12410c59..2fd562ff 100644 --- a/waksman/src/gates/switch.rs +++ b/waksman/src/gates/switch.rs @@ -250,8 +250,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input)); @@ -280,8 +280,8 @@ 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, + row: self.gate_index, + column: input, }; let get_local_wire = |input| witness.get_wire(local_wire(input));