diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index a7913f11c7..0f72215bda 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -18,9 +18,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; -use leo_gadgets::bits::ComparatorGadget; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::utilities::bits::ComparatorGadget; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index bc1deccf95..eda1055be7 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -18,9 +18,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; -use leo_gadgets::bits::ComparatorGadget; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::utilities::bits::ComparatorGadget; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 3dd23855c5..36e63d41df 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -18,9 +18,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; -use leo_gadgets::bits::ComparatorGadget; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::utilities::bits::ComparatorGadget; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 0bbd4a4219..72fd5c5fdc 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -18,9 +18,9 @@ use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; -use leo_gadgets::bits::comparator::EvaluateLtGadget; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::utilities::bits::EvaluateLtGadget; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 49b157573f..a2affe09b6 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -18,15 +18,13 @@ use crate::{errors::IntegerError, IntegerTrait}; use leo_asg::{ConstInt, IntegerType, Span}; use leo_ast::InputValue; -use leo_gadgets::{ - arithmetic::*, - bits::comparator::{ComparatorGadget, EvaluateLtGadget}, - signed_integer::*, -}; +use leo_gadgets::signed_integer::*; use snarkvm_fields::{Field, PrimeField}; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Neg, Pow, Sub}, + bits::comparator::{ComparatorGadget, EvaluateLtGadget}, boolean::Boolean, eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, select::CondSelectGadget, diff --git a/examples/pedersen-hash/src/main.leo b/examples/pedersen-hash/src/main.leo index 25050216da..e0adfecaec 100644 --- a/examples/pedersen-hash/src/main.leo +++ b/examples/pedersen-hash/src/main.leo @@ -24,3 +24,4 @@ function main() -> group { let hash_input: [bool; 256] = [true; 256]; return pedersen.hash(hash_input) } + diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index a75546d7e4..eada31b5cb 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int128, Int16, Int32, Int64, Int8}; +use leo_gadgets::{Int128, Int16, Int32, Int64, Int8}; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Sub}, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::{Rng, SeedableRng}; diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs deleted file mode 100644 index eada6b2c3b..0000000000 --- a/gadgets/src/arithmetic/add.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::{Field, PrimeField}; -use snarkvm_gadgets::traits::utilities::uint::{UInt, UInt128, UInt16, UInt32, UInt64, UInt8}; -use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; - -/// Returns addition of `self` + `other` in the constraint system. -pub trait Add -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn add>(&self, cs: CS, other: &Self) -> Result; -} - -// Implement unsigned integers -macro_rules! add_uint_impl { - ($($gadget: ident),*) => ($( - impl Add for $gadget { - type ErrorType = SynthesisError; - - fn add>( - &self, - cs: CS, - other: &Self - ) -> Result { - <$gadget as UInt>::addmany(cs, &[self.clone(), other.clone()]) - } - } - )*) -} - -add_uint_impl!(UInt8, UInt16, UInt32, UInt64, UInt128); diff --git a/gadgets/src/arithmetic/div.rs b/gadgets/src/arithmetic/div.rs deleted file mode 100644 index ca1a93c899..0000000000 --- a/gadgets/src/arithmetic/div.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::Field; -use snarkvm_r1cs::ConstraintSystem; - -/// Returns division of `self` / `other` in the constraint system. -pub trait Div -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn div>(&self, cs: CS, other: &Self) -> Result; -} diff --git a/gadgets/src/arithmetic/mod.rs b/gadgets/src/arithmetic/mod.rs deleted file mode 100644 index 469b8cf078..0000000000 --- a/gadgets/src/arithmetic/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -pub mod add; -pub use self::add::*; - -pub mod div; -pub use self::div::*; - -pub mod mul; -pub use self::mul::*; - -pub mod neg; -pub use self::neg::*; - -pub mod pow; -pub use self::pow::*; - -pub mod sub; -pub use self::sub::*; diff --git a/gadgets/src/arithmetic/mul.rs b/gadgets/src/arithmetic/mul.rs deleted file mode 100644 index e99b339d4a..0000000000 --- a/gadgets/src/arithmetic/mul.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::Field; -use snarkvm_r1cs::ConstraintSystem; - -/// Returns multiplication of `self` * `other` in the constraint system. -pub trait Mul -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn mul>(&self, cs: CS, other: &Self) -> Result; -} diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs deleted file mode 100644 index 170014950a..0000000000 --- a/gadgets/src/arithmetic/neg.rs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::bits::RippleCarryAdder; - -use snarkvm_fields::Field; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; - -use std::iter; - -/// Returns a negated representation of `self` in the constraint system. -pub trait Neg -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn neg>(&self, cs: CS) -> Result; -} - -impl Neg for Vec { - type ErrorType = SynthesisError; - - fn neg>(&self, mut cs: CS) -> Result { - // flip all bits - let flipped: Self = self.iter().map(|bit| bit.not()).collect(); - - // add one - let mut one = Vec::with_capacity(self.len()); - one.push(Boolean::constant(true)); - one.extend(iter::repeat(Boolean::Constant(false)).take(self.len() - 1)); - - let mut bits = flipped.add_bits(cs.ns(|| "add one"), &one)?; - let _carry = bits.pop(); // we already accounted for overflow above - - Ok(bits) - } -} diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs deleted file mode 100644 index bb1e8427c9..0000000000 --- a/gadgets/src/arithmetic/pow.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::Field; -use snarkvm_r1cs::ConstraintSystem; - -/// Returns exponentiation of `self` ** `other` in the constraint system. -pub trait Pow -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn pow>(&self, cs: CS, other: &Self) -> Result; -} diff --git a/gadgets/src/arithmetic/sub.rs b/gadgets/src/arithmetic/sub.rs deleted file mode 100644 index ee66603526..0000000000 --- a/gadgets/src/arithmetic/sub.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::Field; -use snarkvm_r1cs::ConstraintSystem; - -/// Returns subtraction of `self` - `other` in the constraint system. -pub trait Sub -where - Self: std::marker::Sized, -{ - type ErrorType; - - fn sub>(&self, cs: CS, other: &Self) -> Result; -} diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs deleted file mode 100644 index ef0a6fc5ad..0000000000 --- a/gadgets/src/bits/comparator.rs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_fields::{Field, PrimeField}; -use snarkvm_gadgets::traits::utilities::{ - boolean::Boolean, - select::CondSelectGadget, - uint::{UInt128, UInt16, UInt32, UInt64, UInt8}, -}; -use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; - -pub trait EvaluateLtGadget { - fn less_than>(&self, cs: CS, other: &Self) -> Result; -} - -// implementing `EvaluateLtGadget` will implement `ComparatorGadget` -pub trait ComparatorGadget -where - Self: EvaluateLtGadget, -{ - fn greater_than>(&self, cs: CS, other: &Self) -> Result { - other.less_than(cs, self) - } - - fn less_than_or_equal>(&self, cs: CS, other: &Self) -> Result { - let is_gt = self.greater_than(cs, other)?; - Ok(is_gt.not()) - } - - fn greater_than_or_equal>(&self, cs: CS, other: &Self) -> Result { - other.less_than_or_equal(cs, self) - } -} - -macro_rules! uint_cmp_impl { - ($($gadget: ident),*) => ($( - /* Bitwise less than comparison of two unsigned integers */ - impl EvaluateLtGadget for $gadget { - fn less_than>(&self, mut cs: CS, other: &Self) -> Result { - - let mut result = Boolean::constant(true); - let mut all_equal = Boolean::constant(true); - - // msb -> lsb - for (i, (a, b)) in self - .bits - .iter() - .rev() - .zip(other.bits.iter().rev()) - .enumerate() - { - // a == 0 & b == 1 - let less = Boolean::and(cs.ns(|| format!("not a and b [{}]", i)), &a.not(), b)?; - - // a == b = !(a ^ b) - let not_equal = Boolean::xor(cs.ns(|| format!("a XOR b [{}]", i)), a, b)?; - let equal = not_equal.not(); - - // evaluate a <= b - let less_or_equal = Boolean::or(cs.ns(|| format!("less or equal [{}]", i)), &less, &equal)?; - - // select the current result if it is the first bit difference - result = Boolean::conditionally_select(cs.ns(|| format!("select bit [{}]", i)), &all_equal, &less_or_equal, &result)?; - - // keep track of equal bits - all_equal = Boolean::and(cs.ns(|| format!("accumulate equal [{}]", i)), &all_equal, &equal)?; - } - - result = Boolean::and(cs.ns(|| format!("false if all equal")), &result, &all_equal.not())?; - - Ok(result) - } - } - - /* Bitwise comparison of two unsigned integers */ - impl ComparatorGadget for $gadget {} - )*) -} - -uint_cmp_impl!(UInt8, UInt16, UInt32, UInt64, UInt128); diff --git a/gadgets/src/bits/mod.rs b/gadgets/src/bits/mod.rs index e4842090db..d1898884dc 100644 --- a/gadgets/src/bits/mod.rs +++ b/gadgets/src/bits/mod.rs @@ -18,11 +18,5 @@ pub mod adder; pub use self::adder::*; -pub mod comparator; -pub use self::comparator::*; - pub mod rca; pub use self::rca::*; - -pub mod sign_extend; -pub use self::sign_extend::*; diff --git a/gadgets/src/bits/sign_extend.rs b/gadgets/src/bits/sign_extend.rs deleted file mode 100644 index 5fd6569334..0000000000 --- a/gadgets/src/bits/sign_extend.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use snarkvm_gadgets::traits::utilities::boolean::Boolean; - -use std::iter; - -/// Sign extends an array of bits to the desired length. -/// Expects least significant bit first -pub trait SignExtend -where - Self: std::marker::Sized, -{ - #[must_use] - fn sign_extend(bits: &[Boolean], length: usize) -> Vec; -} - -impl SignExtend for Boolean { - fn sign_extend(bits: &[Boolean], length: usize) -> Vec { - let msb = bits.last().expect("empty bit list"); - let bits_needed = length - bits.len(); - - let mut result = Vec::with_capacity(length); - result.extend_from_slice(bits); - result.extend(iter::repeat(*msb).take(bits_needed)); - - result - } -} diff --git a/gadgets/src/lib.rs b/gadgets/src/lib.rs index d5ae0dea06..38eed81ac1 100644 --- a/gadgets/src/lib.rs +++ b/gadgets/src/lib.rs @@ -17,8 +17,6 @@ #[macro_use] extern crate thiserror; -pub mod arithmetic; - pub mod bits; pub mod errors; diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index be7ae00cea..57327d434e 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -14,21 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::Add, - bits::RippleCarryAdder, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{bits::RippleCarryAdder, errors::SignedIntegerError, Int, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::{fp_parameters::FpParameters, PrimeField}; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::Add, boolean::{AllocatedBit, Boolean}, }; use snarkvm_r1cs::{Assignment, ConstraintSystem, LinearCombination}; diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index 6f93029abc..656583a643 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -14,20 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Add, Div, Neg, Sub}, - bits::ComparatorGadget, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{errors::SignedIntegerError, Int, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::{Add, Div, Neg, Sub}, + bits::ComparatorGadget, boolean::{AllocatedBit, Boolean}, eq::EvaluateEqGadget, select::CondSelectGadget, diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index fb6b792715..7717287343 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -14,20 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::Mul, - bits::{RippleCarryAdder, SignExtend}, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{bits::RippleCarryAdder, errors::SignedIntegerError, Int, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::{FpParameters, PrimeField}; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::Mul, + bits::SignExtend, boolean::{AllocatedBit, Boolean}, select::CondSelectGadget, }; diff --git a/gadgets/src/signed_integer/arithmetic/neg.rs b/gadgets/src/signed_integer/arithmetic/neg.rs index 3f802878bf..a030f42a50 100644 --- a/gadgets/src/signed_integer/arithmetic/neg.rs +++ b/gadgets/src/signed_integer/arithmetic/neg.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{arithmetic::Neg, errors::SignedIntegerError, signed_integer::*}; +use crate::{errors::SignedIntegerError, signed_integer::*}; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::utilities::arithmetic::Neg; use snarkvm_r1cs::ConstraintSystem; macro_rules! neg_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index 3f6467978f..faef2159ff 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -14,19 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Mul, Pow}, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{errors::SignedIntegerError, Int, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean, select::CondSelectGadget}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Mul, Pow}, + boolean::Boolean, + select::CondSelectGadget, +}; use snarkvm_r1cs::ConstraintSystem; macro_rules! pow_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index fc3ae9a539..df49d4a606 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -14,16 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Add, Neg, Sub}, - errors::SignedIntegerError, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{errors::SignedIntegerError, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::arithmetic::{Add, Neg, Sub}; use snarkvm_r1cs::ConstraintSystem; macro_rules! sub_int_impl { diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index 07b2537748..26cfcaea7c 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -14,17 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - bits::{ComparatorGadget, EvaluateLtGadget}, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::{Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::{boolean::Boolean, select::CondSelectGadget}; +use snarkvm_gadgets::traits::utilities::{ + bits::comparator::{ComparatorGadget, EvaluateLtGadget}, + boolean::Boolean, + select::CondSelectGadget, +}; use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; use std::cmp::Ordering; diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 9efa1f4c7a..96c78d4a30 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int128}; +use leo_gadgets::Int128; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Sub}, + boolean::Boolean, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index c6e5af960b..b50943ce4e 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int16}; +use leo_gadgets::Int16; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Pow, Sub}, + boolean::Boolean, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index fb9fee1c94..e6821b9f24 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int32}; +use leo_gadgets::Int32; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Pow, Sub}, + boolean::Boolean, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 2aee9111c5..5488b0b92c 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int64}; +use leo_gadgets::Int64; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Pow, Sub}, + boolean::Boolean, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index b8eaef23ed..a2480e7e31 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int8}; +use leo_gadgets::Int8; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + arithmetic::{Add, Div, Mul, Pow, Sub}, + boolean::Boolean, +}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng;