From ebcfde1d81892fc16aba4a6cac864c56a232b3a4 Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Thu, 7 Oct 2021 09:25:57 -0700 Subject: [PATCH] updates --- src/gadgets/arithmetic_u32.rs | 42 ++++++++++------------------------- src/gates/arithmetic_u32.rs | 6 ++--- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/gadgets/arithmetic_u32.rs b/src/gadgets/arithmetic_u32.rs index 7c5fe218..213cdffe 100644 --- a/src/gadgets/arithmetic_u32.rs +++ b/src/gadgets/arithmetic_u32.rs @@ -1,15 +1,10 @@ -use std::collections::BTreeMap; use std::marker::PhantomData; use crate::field::field_types::RichField; -use crate::field::{extension_field::Extendable, field_types::Field}; +use crate::field::extension_field::Extendable; use crate::gates::arithmetic_u32::{U32ArithmeticGate, NUM_U32_ARITHMETIC_OPS}; -use crate::gates::switch::SwitchGate; -use crate::iop::generator::{GeneratedValues, SimpleGenerator}; use crate::iop::target::Target; -use crate::iop::witness::{PartitionWitness, Witness}; use crate::plonk::circuit_builder::CircuitBuilder; -use crate::util::bimap::bimap_from_lists; pub struct U32Target(Target); @@ -20,8 +15,7 @@ impl, const D: usize> CircuitBuilder { pub fn add_virtual_u32_targets(&self, n: usize) -> Vec { self.add_virtual_targets(n) - .iter() - .cloned() + .into_iter() .map(U32Target) .collect() } @@ -52,9 +46,6 @@ impl, const D: usize> CircuitBuilder { Some((gate_index, copy)) => (gate_index, copy), }; - let output_low = self.add_virtual_u32_target(); - let output_high = self.add_virtual_u32_target(); - self.connect( Target::wire( gate_index, @@ -73,27 +64,18 @@ impl, const D: usize> CircuitBuilder { Target::wire(gate_index, U32ArithmeticGate::::wire_ith_addend(copy)), z.0, ); - self.connect( - Target::wire( - gate_index, - U32ArithmeticGate::::wire_ith_output_low_half(copy), - ), - output_low.0, - ); - self.connect( - Target::wire( - gate_index, - U32ArithmeticGate::::wire_ith_output_high_half(copy), - ), - output_high.0, - ); + + let output_low = U32Target(Target::wire( + gate_index, + U32ArithmeticGate::::wire_ith_output_low_half(copy), + )); + let output_high = U32Target(Target::wire( + gate_index, + U32ArithmeticGate::::wire_ith_output_high_half(copy), + )); if copy == NUM_U32_ARITHMETIC_OPS - 1 { - let gate = U32ArithmeticGate { - _phantom: PhantomData, - }; - let gate_index = self.add_gate(gate, vec![]); - self.current_u32_arithmetic_gate = Some((gate_index, 0)); + self.current_u32_arithmetic_gate = None; } else { self.current_u32_arithmetic_gate = Some((gate_index, copy + 1)); } diff --git a/src/gates/arithmetic_u32.rs b/src/gates/arithmetic_u32.rs index c05cf72f..b56af0e8 100644 --- a/src/gates/arithmetic_u32.rs +++ b/src/gates/arithmetic_u32.rs @@ -309,8 +309,7 @@ impl, const D: usize> SimpleGenerator .take(num_limbs) .collect(); let output_limbs_f: Vec<_> = output_limbs_u64 - .iter() - .cloned() + .into_iter() .map(F::from_canonical_u64) .collect(); @@ -385,8 +384,7 @@ mod tests { output /= limb_base; } let mut output_limbs_f: Vec<_> = output_limbs - .iter() - .cloned() + .into_iter() .map(F::from_canonical_u64) .collect();