refactor to use snarkvm sub gadget

This commit is contained in:
collin 2021-03-11 16:27:06 -08:00
parent a3a91676bb
commit 522e3b6ea6
12 changed files with 43 additions and 54 deletions

View File

@ -19,7 +19,6 @@ 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::*,
};
@ -27,7 +26,7 @@ use leo_gadgets::{
use snarkvm_fields::{Field, PrimeField};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget},
select::CondSelectGadget,

View File

@ -18,7 +18,7 @@ use leo_gadgets::{arithmetic::*, Int128, Int16, Int32, Int64, Int8};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul},
arithmetic::{Add, Div, Mul, Sub},
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

View File

@ -13,6 +13,6 @@
// 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 sub;
pub use self::sub::*;
//
// pub mod sub;
// pub use self::sub::*;

View File

@ -1,28 +1,28 @@
// 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 <https://www.gnu.org/licenses/>.
use snarkvm_fields::Field;
use snarkvm_r1cs::ConstraintSystem;
/// Returns subtraction of `self` - `other` in the constraint system.
pub trait Sub<F: Field, Rhs = Self>
where
Self: std::marker::Sized,
{
type ErrorType;
fn sub<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
}
// // 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 <https://www.gnu.org/licenses/>.
//
// use snarkvm_fields::Field;
// use snarkvm_r1cs::ConstraintSystem;
//
// /// Returns subtraction of `self` - `other` in the constraint system.
// pub trait Sub<F: Field, Rhs = Self>
// where
// Self: std::marker::Sized,
// {
// type ErrorType;
//
// fn sub<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
// }

View File

@ -17,7 +17,7 @@
#[macro_use]
extern crate thiserror;
pub mod arithmetic;
// pub mod arithmetic;
pub mod bits;

View File

@ -14,21 +14,11 @@
// 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::Sub,
bits::ComparatorGadget,
errors::SignedIntegerError,
Int,
Int128,
Int16,
Int32,
Int64,
Int8,
};
use crate::{bits::ComparatorGadget, errors::SignedIntegerError, Int, Int128, Int16, Int32, Int64, Int8};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Neg},
arithmetic::{Add, Div, Neg, Sub},
boolean::{AllocatedBit, Boolean},
eq::EvaluateEqGadget,
select::CondSelectGadget,

View File

@ -14,9 +14,9 @@
// 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::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};
use snarkvm_gadgets::traits::utilities::arithmetic::{Add, Neg, Sub};
use snarkvm_r1cs::ConstraintSystem;
macro_rules! sub_int_impl {

View File

@ -19,7 +19,7 @@ use leo_gadgets::{arithmetic::*, Int128};
use snarkvm_fields::{One, Zero};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

View File

@ -19,7 +19,7 @@ use leo_gadgets::{arithmetic::*, Int16};
use snarkvm_fields::{One, Zero};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

View File

@ -19,7 +19,7 @@ use leo_gadgets::{arithmetic::*, Int32};
use snarkvm_fields::{One, Zero};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

View File

@ -19,7 +19,7 @@ use leo_gadgets::{arithmetic::*, Int64};
use snarkvm_fields::{One, Zero};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

View File

@ -19,7 +19,7 @@ use leo_gadgets::{arithmetic::*, Int8};
use snarkvm_fields::{One, Zero};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Neg, Pow},
arithmetic::{Add, Div, Mul, Neg, Pow, Sub},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};