From deb3847b8ea5845efb7955fe3fdfe538724eec64 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 11 Mar 2021 14:47:34 -0800 Subject: [PATCH] remove add trait and uint impls --- compiler/src/value/integer/integer.rs | 1 + .../pedersen-hash/inputs/pedersen-hash.in | 8 +++ examples/pedersen-hash/src/main.leo | 9 ++- gadgets/src/arithmetic/add.rs | 62 +++++++++---------- gadgets/src/arithmetic/mod.rs | 4 +- gadgets/src/signed_integer/arithmetic/add.rs | 13 +--- gadgets/src/signed_integer/arithmetic/div.rs | 3 +- gadgets/src/signed_integer/arithmetic/sub.rs | 3 +- gadgets/tests/signed_integer/i128.rs | 2 +- gadgets/tests/signed_integer/i16.rs | 2 +- gadgets/tests/signed_integer/i32.rs | 2 +- gadgets/tests/signed_integer/i64.rs | 2 +- gadgets/tests/signed_integer/i8.rs | 2 +- 13 files changed, 59 insertions(+), 54 deletions(-) diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 49b157573f..092927681b 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -27,6 +27,7 @@ use leo_gadgets::{ use snarkvm_fields::{Field, PrimeField}; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::Add, boolean::Boolean, eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, select::CondSelectGadget, diff --git a/examples/pedersen-hash/inputs/pedersen-hash.in b/examples/pedersen-hash/inputs/pedersen-hash.in index 4434b65eb8..598948b21b 100644 --- a/examples/pedersen-hash/inputs/pedersen-hash.in +++ b/examples/pedersen-hash/inputs/pedersen-hash.in @@ -1,4 +1,12 @@ +// syntax 1 [main] +const parameters: [group; 256] = [1; 256]; + + +// syntax 2 +[const] +parameters: [group; 256] = [1; 256]; + [registers] r0: group = (1, 0)group; \ No newline at end of file diff --git a/examples/pedersen-hash/src/main.leo b/examples/pedersen-hash/src/main.leo index 25050216da..ee04517341 100644 --- a/examples/pedersen-hash/src/main.leo +++ b/examples/pedersen-hash/src/main.leo @@ -17,10 +17,13 @@ circuit PedersenHash { } } -// The 'pedersen-hash' main function. -function main() -> group { - let parameters = [1group; 256]; +// syntax 1: const main function input +function main(const parameters: [group; 256]) -> group { let pedersen = PedersenHash::new(parameters); let hash_input: [bool; 256] = [true; 256]; return pedersen.hash(hash_input) } + +// syntax 2: main file global constant +@parameter +const parameters: [group; 256]; diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index eada6b2c3b..f83624c0e3 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -14,35 +14,35 @@ // 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}; +// 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; +// } -/// 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); +// // 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/mod.rs b/gadgets/src/arithmetic/mod.rs index 469b8cf078..35b566b87c 100644 --- a/gadgets/src/arithmetic/mod.rs +++ b/gadgets/src/arithmetic/mod.rs @@ -14,8 +14,8 @@ // 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 add; +// pub use self::add::*; pub mod div; pub use self::div::*; 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..0b1683f8b1 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ - arithmetic::{Add, Div, Neg, Sub}, + arithmetic::{Div, Neg, Sub}, bits::ComparatorGadget, errors::SignedIntegerError, Int, @@ -28,6 +28,7 @@ use crate::{ use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, + arithmetic::Add, boolean::{AllocatedBit, Boolean}, eq::EvaluateEqGadget, select::CondSelectGadget, diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index fc3ae9a539..7ab5b1debe 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ - arithmetic::{Add, Neg, Sub}, + arithmetic::{Neg, Sub}, errors::SignedIntegerError, Int128, Int16, @@ -24,6 +24,7 @@ use crate::{ Int8, }; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::arithmetic::Add; use snarkvm_r1cs::ConstraintSystem; macro_rules! sub_int_impl { diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 9efa1f4c7a..acf18acd25 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -17,7 +17,7 @@ use leo_gadgets::{arithmetic::*, Int128}; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, arithmetic::Add, 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..7770af853a 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -17,7 +17,7 @@ use leo_gadgets::{arithmetic::*, Int16}; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, arithmetic::Add, 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..82c4e00051 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -17,7 +17,7 @@ use leo_gadgets::{arithmetic::*, Int32}; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, arithmetic::Add, 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..50dbf38abc 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -17,7 +17,7 @@ use leo_gadgets::{arithmetic::*, Int64}; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, arithmetic::Add, 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..2b35aaae8a 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -17,7 +17,7 @@ use leo_gadgets::{arithmetic::*, Int8}; use snarkvm_fields::{One, Zero}; -use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, arithmetic::Add, boolean::Boolean}; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng;