remove add trait and uint impls

This commit is contained in:
collin 2021-03-11 14:47:34 -08:00
parent 9a62585c07
commit deb3847b8e
13 changed files with 59 additions and 54 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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];

View File

@ -14,35 +14,35 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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<F: Field, Rhs = Self>
// where
// Self: std::marker::Sized,
// {
// type ErrorType;
//
// fn add<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
// }
/// Returns addition of `self` + `other` in the constraint system.
pub trait Add<F: Field, Rhs = Self>
where
Self: std::marker::Sized,
{
type ErrorType;
fn add<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
}
// Implement unsigned integers
macro_rules! add_uint_impl {
($($gadget: ident),*) => ($(
impl<F: PrimeField> Add<F> for $gadget {
type ErrorType = SynthesisError;
fn add<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Self, Self::ErrorType> {
<$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<F: PrimeField> Add<F> for $gadget {
// type ErrorType = SynthesisError;
//
// fn add<CS: ConstraintSystem<F>>(
// &self,
// cs: CS,
// other: &Self
// ) -> Result<Self, Self::ErrorType> {
// <$gadget as UInt>::addmany(cs, &[self.clone(), other.clone()])
// }
// }
// )*)
// }
//
// add_uint_impl!(UInt8, UInt16, UInt32, UInt64, UInt128);

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
pub mod add;
pub use self::add::*;
// pub mod add;
// pub use self::add::*;
pub mod div;
pub use self::div::*;

View File

@ -14,21 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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};

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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,

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;