diff --git a/Cargo.lock b/Cargo.lock index 91de1f5058..2880facf75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 13ca606fca..e7841ca8b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml new file mode 100644 index 0000000000..1f46fe4c33 --- /dev/null +++ b/gadgets/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "leo-gadgets" +version = "0.1.0" +authors = ["The Aleo Team "] +edition = "2018" + +[dependencies] +snarkos-models = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false } + +thiserror = { version = "1.0" } diff --git a/gadgets/src/errors/mod.rs b/gadgets/src/errors/mod.rs new file mode 100644 index 0000000000..3a4d43aad7 --- /dev/null +++ b/gadgets/src/errors/mod.rs @@ -0,0 +1,2 @@ +pub mod signed_integer; +pub use self::signed_integer::*; diff --git a/gadgets/src/errors/signed_integer.rs b/gadgets/src/errors/signed_integer.rs new file mode 100644 index 0000000000..82424b5848 --- /dev/null +++ b/gadgets/src/errors/signed_integer.rs @@ -0,0 +1,2 @@ +#[derive(Debug)] +pub enum IntegerError {} diff --git a/gadgets/src/lib.rs b/gadgets/src/lib.rs new file mode 100644 index 0000000000..334f396850 --- /dev/null +++ b/gadgets/src/lib.rs @@ -0,0 +1,3 @@ +pub mod errors; + +pub mod signed_integer; diff --git a/gadgets/src/signed_integer/macros.rs b/gadgets/src/signed_integer/macros.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/gadgets/src/signed_integer/macros.rs @@ -0,0 +1 @@ + diff --git a/gadgets/src/signed_integer/mod.rs b/gadgets/src/signed_integer/mod.rs new file mode 100644 index 0000000000..3086d1ff60 --- /dev/null +++ b/gadgets/src/signed_integer/mod.rs @@ -0,0 +1,5 @@ +#[macro_use] +mod macros; + +pub mod signed_integer; +pub use self::signed_integer::*; diff --git a/gadgets/src/signed_integer/signed_integer.rs b/gadgets/src/signed_integer/signed_integer.rs new file mode 100644 index 0000000000..f2d26cd14c --- /dev/null +++ b/gadgets/src/signed_integer/signed_integer.rs @@ -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>(&self, cs: CS, other: &Self) -> Result; + + /// Subtract two `Int` objects + fn sub>(&self, cs: CS, other: &Self) -> Result; + + /// Multiply two `Int` objects + fn mul>(&self, cs: CS, other: &Self) -> Result; + + /// Divide two `Int` objects + fn div>(&self, cs: CS, other: &Self) -> Result; + + /// Exponentiation between two `Int` objects + fn pow>(&self, cs: CS, other: &Self) -> Result; +}