add signed-integers gadget member to workspace

This commit is contained in:
collin 2020-07-09 22:39:11 -07:00
parent 540c0de69f
commit b032c2ce45
9 changed files with 65 additions and 2 deletions

9
Cargo.lock generated
View File

@ -540,6 +540,7 @@ dependencies = [
"env_logger",
"from-pest",
"leo-compiler",
"leo-gadgets",
"leo-inputs",
"log",
"rand",
@ -595,6 +596,14 @@ dependencies = [
"thiserror",
]
[[package]]
name = "leo-gadgets"
version = "0.1.0"
dependencies = [
"snarkos-models",
"thiserror",
]
[[package]]
name = "leo-inputs"
version = "0.1.0"

View File

@ -13,11 +13,12 @@ name = "leo"
path = "leo/main.rs"
[workspace]
members = [ "ast", "compiler", "leo-inputs", "types" ]
members = [ "ast", "compiler", "gadgets", "leo-inputs", "types" ]
[dependencies]
leo-compiler = { path = "compiler", version = "0.1.0" }
leo-inputs = { path = "leo-inputs", version = "0.1.0"}
leo-gadgets = { path = "gadgets", version = "0.1.0" }
leo-inputs = { path = "leo-inputs", version = "0.1.0" }
snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }

10
gadgets/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "leo-gadgets"
version = "0.1.0"
authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"
[dependencies]
snarkos-models = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
thiserror = { version = "1.0" }

View File

@ -0,0 +1,2 @@
pub mod signed_integer;
pub use self::signed_integer::*;

View File

@ -0,0 +1,2 @@
#[derive(Debug)]
pub enum IntegerError {}

3
gadgets/src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
pub mod errors;
pub mod signed_integer;

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,5 @@
#[macro_use]
mod macros;
pub mod signed_integer;
pub use self::signed_integer::*;

View File

@ -0,0 +1,30 @@
use crate::errors::IntegerError;
use snarkos_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem};
use std::{cmp::Ordering, fmt::Debug};
/// A signed two's complement integer object
pub trait Int: Debug + Clone + PartialOrd + Eq + PartialEq {
/// Returns true if all bits in this `Int` are constant
fn is_constant(&self) -> bool;
/// Returns true if both `Int` objects have constant bits
fn result_is_constant(first: &Self, second: &Self) -> bool {
first.is_constant() && second.is_constant()
}
/// Add two `Int` objects
fn add<F: PrimeField, CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, IntegerError>;
/// Subtract two `Int` objects
fn sub<F: PrimeField, CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, IntegerError>;
/// Multiply two `Int` objects
fn mul<F: PrimeField, CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, IntegerError>;
/// Divide two `Int` objects
fn div<F: PrimeField, CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, IntegerError>;
/// Exponentiation between two `Int` objects
fn pow<F: PrimeField, CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, IntegerError>;
}