From adce3766759aedd5986cce92f139f9b89731435a Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 11 Mar 2021 16:18:00 -0800 Subject: [PATCH] refactor to use snarkvm pow gadget --- gadgets/benches/integer_arithmetic.rs | 2 +- gadgets/src/arithmetic/mod.rs | 4 +- gadgets/src/arithmetic/pow.rs | 56 ++++++++++---------- gadgets/src/signed_integer/arithmetic/pow.rs | 4 +- 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 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index c31358142e..606ab14191 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -18,7 +18,7 @@ use leo_gadgets::{arithmetic::*, Int128, Int16, Int32, Int64, Int8}; use snarkvm_gadgets::traits::utilities::{ alloc::AllocGadget, - arithmetic::{Add, Div, Mul, Neg}, + arithmetic::{Add, Div, Mul, Neg, Pow}, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; diff --git a/gadgets/src/arithmetic/mod.rs b/gadgets/src/arithmetic/mod.rs index 986f5e44f1..9c05b77811 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 pow; -pub use self::pow::*; +// pub mod pow; +// pub use self::pow::*; pub mod sub; pub use self::sub::*; diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs index bb1e8427c9..65951bd425 100644 --- a/gadgets/src/arithmetic/pow.rs +++ b/gadgets/src/arithmetic/pow.rs @@ -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 . - -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; -} +// // 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/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index c9f6e70260..faef2159ff 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -14,12 +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::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, - arithmetic::Mul, + arithmetic::{Mul, Pow}, boolean::Boolean, select::CondSelectGadget, }; diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 3bc93788d1..b2b05ee437 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -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}, + arithmetic::{Add, Div, Mul, Neg, Pow}, boolean::Boolean, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index 4f56547b85..29c0c02aa6 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -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}, + arithmetic::{Add, Div, Mul, Neg, Pow}, boolean::Boolean, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 440cfbd631..e828c31f45 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -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}, + arithmetic::{Add, Div, Mul, Neg, Pow}, boolean::Boolean, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index a46ed15cbc..30a11e5e6a 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -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}, + arithmetic::{Add, Div, Mul, Neg, Pow}, boolean::Boolean, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index a9cd91b092..dfe6753225 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -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}, + arithmetic::{Add, Div, Mul, Neg, Pow}, boolean::Boolean, }; use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};