refactor to use snarkvm mul gadget

This commit is contained in:
collin 2021-03-11 16:02:28 -08:00
parent e9e8fae279
commit d4b8bbbe50
11 changed files with 45 additions and 49 deletions

View File

@ -27,7 +27,7 @@ use leo_gadgets::{
use snarkvm_fields::{Field, PrimeField};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div},
arithmetic::{Add, Div, Mul},
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},
arithmetic::{Add, Div, Mul},
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};

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 mul;
pub use self::mul::*;
// pub mod mul;
// pub use self::mul::*;
pub mod neg;
pub use self::neg::*;

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 multiplication of `self` * `other` in the constraint system.
pub trait Mul<F: Field, Rhs = Self>
where
Self: std::marker::Sized,
{
type ErrorType;
fn mul<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 multiplication of `self` * `other` in the constraint system.
// pub trait Mul<F: Field, Rhs = Self>
// where
// Self: std::marker::Sized,
// {
// type ErrorType;
//
// fn mul<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
// }

View File

@ -15,7 +15,6 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{
arithmetic::Mul,
bits::{RippleCarryAdder, SignExtend},
errors::SignedIntegerError,
Int,
@ -28,6 +27,7 @@ use crate::{
use snarkvm_fields::{FpParameters, PrimeField};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::Mul,
boolean::{AllocatedBit, Boolean},
select::CondSelectGadget,
};

View File

@ -14,19 +14,15 @@
// 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::{Mul, Pow},
errors::SignedIntegerError,
Int,
Int128,
Int16,
Int32,
Int64,
Int8,
};
use crate::{arithmetic::Pow, 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,
boolean::Boolean,
select::CondSelectGadget,
};
use snarkvm_r1cs::ConstraintSystem;
macro_rules! pow_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},
arithmetic::{Add, Div, Mul},
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},
arithmetic::{Add, Div, Mul},
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},
arithmetic::{Add, Div, Mul},
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},
arithmetic::{Add, Div, Mul},
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},
arithmetic::{Add, Div, Mul},
boolean::Boolean,
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};