refactor to use snarkvm int16 int32 int64 int128 gadgets

This commit is contained in:
collin 2021-03-12 15:03:22 -08:00
parent bec4a15c12
commit 6962e1c2e1
8 changed files with 22 additions and 39 deletions

View File

@ -15,9 +15,8 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::{FormattedError, IntegerType, LeoError, Span, Type};
use leo_gadgets::errors::SignedIntegerError;
use snarkvm_gadgets::errors::SignedIntegerError as SnarkVMSignedIntegerError;
use snarkvm_gadgets::errors::SignedIntegerError;
use snarkvm_r1cs::SynthesisError;
#[derive(Debug, Error)]
@ -69,15 +68,6 @@ impl IntegerError {
Self::new_from_span(message, span)
}
pub fn snarkvm_error(error: SnarkVMSignedIntegerError, span: &Span) -> Self {
let message = format!(
"the integer operation failed due to the signed integer error `{:?}`",
error
);
Self::new_from_span(message, span)
}
pub fn synthesis(error: SynthesisError, span: &Span) -> Self {
let message = format!("integer operation failed due to the synthesis error `{}`", error);

View File

@ -18,7 +18,6 @@
use crate::{errors::IntegerError, IntegerTrait};
use leo_asg::{ConstInt, IntegerType, Span};
use leo_ast::InputValue;
use leo_gadgets::signed_integer::*;
use snarkvm_fields::{Field, PrimeField};
use snarkvm_gadgets::traits::utilities::{
@ -27,7 +26,7 @@ use snarkvm_gadgets::traits::utilities::{
bits::comparator::{ComparatorGadget, EvaluateLtGadget},
boolean::Boolean,
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget},
int::Int8,
int::{Int128, Int16, Int32, Int64, Int8},
select::CondSelectGadget,
uint::*,
};

View File

@ -14,11 +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 leo_gadgets::signed_integer::*;
use snarkvm_gadgets::traits::utilities::{
boolean::Boolean,
int::Int8,
int::{Int128, Int16, Int32, Int64, Int8},
uint::{UInt128, UInt16, UInt32, UInt64, UInt8},
};
use std::fmt::Debug;
@ -85,9 +83,7 @@ macro_rules! match_unsigned_integer {
macro_rules! match_signed_integer {
($integer: ident, $span: ident => $expression: expr) => {
match $integer {
Integer::I8($integer) => Some(Integer::I8(
$expression.map_err(|e| IntegerError::snarkvm_error(e, $span))?,
)),
Integer::I8($integer) => Some(Integer::I8($expression.map_err(|e| IntegerError::signed(e, $span))?)),
Integer::I16($integer) => Some(Integer::I16($expression.map_err(|e| IntegerError::signed(e, $span))?)),
Integer::I32($integer) => Some(Integer::I32($expression.map_err(|e| IntegerError::signed(e, $span))?)),
Integer::I64($integer) => Some(Integer::I64($expression.map_err(|e| IntegerError::signed(e, $span))?)),
@ -138,9 +134,9 @@ macro_rules! match_integers_span {
$expression.map_err(|e| IntegerError::synthesis(e, $span))?,
)),
(Integer::I8($a), Integer::I8($b)) => Some(Integer::I8(
$expression.map_err(|e| IntegerError::snarkvm_error(e, $span))?,
)),
(Integer::I8($a), Integer::I8($b)) => {
Some(Integer::I8($expression.map_err(|e| IntegerError::signed(e, $span))?))
}
(Integer::I16($a), Integer::I16($b)) => {
Some(Integer::I16($expression.map_err(|e| IntegerError::signed(e, $span))?))
}

View File

@ -14,12 +14,10 @@
// 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 leo_gadgets::{Int128, Int16, Int32, Int64};
use snarkvm_gadgets::traits::utilities::{
alloc::AllocGadget,
arithmetic::{Add, Div, Mul, Sub},
int::Int8,
int::{Int128, Int16, Int32, Int64, Int8},
};
use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem};
@ -29,6 +27,7 @@ use std::i128;
use criterion::{criterion_group, criterion_main, Criterion};
// TODO: move these benchmarks to snarkvm?
macro_rules! create_add_bench {
($bench_name:ident, $bench_id:expr, $foo_name:ident, $std_type:ty, $bit_type:ty) => {
fn $bench_name(c: &mut Criterion) {

View File

@ -14,8 +14,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/>.
use crate::{bits::FullAdder, signed_integer::*};
use snarkvm_fields::{Field, PrimeField};
use snarkvm_gadgets::traits::utilities::boolean::Boolean;
use snarkvm_r1cs::{ConstraintSystem, SynthesisError};

View File

@ -14,12 +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/>.
#[macro_use]
extern crate thiserror;
// #[macro_use]
// extern crate thiserror;
pub mod bits;
// pub mod bits;
pub mod errors;
// pub mod errors;
pub mod signed_integer;
pub use self::signed_integer::*;
// pub mod signed_integer;
// pub use self::signed_integer::*;

View File

@ -14,5 +14,5 @@
// 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 signed_integer;
pub use self::signed_integer::*;
// pub mod signed_integer;
// pub use self::signed_integer::*;

View File

@ -14,8 +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/>.
pub mod i128;
pub mod i16;
pub mod i32;
pub mod i64;
// Todo: move these tests to snarkvm.
// pub mod i128;
// pub mod i16;
// pub mod i32;
// pub mod i64;
// pub mod i8;