From 4ea1df82ba5d97e59556810d5ac854ac84cf2a3b Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Mon, 30 Aug 2021 13:14:00 -0700 Subject: [PATCH] fixes --- src/gadgets/permutation.rs | 3 --- src/gates/switch.rs | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/gadgets/permutation.rs b/src/gadgets/permutation.rs index 0de5a025..06c9c711 100644 --- a/src/gadgets/permutation.rs +++ b/src/gadgets/permutation.rs @@ -22,7 +22,6 @@ impl, const D: usize> CircuitBuilder { b.len(), "Permutation must have same number of inputs and outputs" ); - assert_eq!(a[0].len(), b[0].len(), "Chunk sizes must be the same"); match a.len() { // Two empty lists are permutations of one another, trivially. @@ -455,7 +454,6 @@ mod tests { #[test] fn test_permutation_2x2() -> Result<()> { type F = CrandallField; - type FF = QuarticCrandallField; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(config.num_wires); let mut builder = CircuitBuilder::::new(config); @@ -482,7 +480,6 @@ mod tests { #[test] fn test_permutation_4x4() -> Result<()> { type F = CrandallField; - type FF = QuarticCrandallField; let config = CircuitConfig::large_config(); let pw = PartialWitness::new(config.num_wires); let mut builder = CircuitBuilder::::new(config); diff --git a/src/gates/switch.rs b/src/gates/switch.rs index 50104b82..bb9553ad 100644 --- a/src/gates/switch.rs +++ b/src/gates/switch.rs @@ -213,10 +213,7 @@ impl, const D: usize, const CHUNK_SIZE: usize> SimpleGenerator< SwitchGate::::wire_second_input(self.copy, e), )); deps.push(local_target( - SwitchGate::::wire_first_output(self.copy, e), - )); - deps.push(local_target( - SwitchGate::::wire_second_output(self.copy, e), + SwitchGate::::wire_switch_bool(self.copy, e), )); } @@ -231,7 +228,11 @@ impl, const D: usize, const CHUNK_SIZE: usize> SimpleGenerator< let get_local_wire = |input| witness.get_wire(local_wire(input)); - let switch_bool_wire = local_wire(SwitchGate::::wire_switch_bool( + let first_output_wire = local_wire(SwitchGate::::wire_first_output( + self.gate.num_copies, + self.copy, + )); + let second_output_wire = local_wire(SwitchGate::::wire_second_output( self.gate.num_copies, self.copy, )); @@ -239,15 +240,21 @@ impl, const D: usize, const CHUNK_SIZE: usize> SimpleGenerator< let first_input = get_local_wire(SwitchGate::::wire_first_input( self.copy, e, )); - let first_output = get_local_wire(SwitchGate::::wire_first_output( + let second_input = get_local_wire(SwitchGate::::wire_second_input( + self.copy, e, + )); + let switch_bool = get_local_wire(SwitchGate::::wire_switch_bool( self.copy, e, )); - if first_input == first_output { - out_buffer.set_wire(switch_bool_wire, F::ONE); + let (first_output, second_output) = if switch_bool == F::ZERO { + (first_input, second_input) } else { - out_buffer.set_wire(switch_bool_wire, F::ZERO); - } + (second_input, first_input) + }; + + out_buffer.set_wire(first_output_wire, first_output); + out_buffer.set_wire(second_output_wire, second_output); } } }