mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-25 18:42:26 +03:00
add signed-integers gadget member to workspace
This commit is contained in:
parent
540c0de69f
commit
b032c2ce45
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -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"
|
||||
|
@ -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
10
gadgets/Cargo.toml
Normal 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" }
|
2
gadgets/src/errors/mod.rs
Normal file
2
gadgets/src/errors/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod signed_integer;
|
||||
pub use self::signed_integer::*;
|
2
gadgets/src/errors/signed_integer.rs
Normal file
2
gadgets/src/errors/signed_integer.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[derive(Debug)]
|
||||
pub enum IntegerError {}
|
3
gadgets/src/lib.rs
Normal file
3
gadgets/src/lib.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod errors;
|
||||
|
||||
pub mod signed_integer;
|
1
gadgets/src/signed_integer/macros.rs
Normal file
1
gadgets/src/signed_integer/macros.rs
Normal file
@ -0,0 +1 @@
|
||||
|
5
gadgets/src/signed_integer/mod.rs
Normal file
5
gadgets/src/signed_integer/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
pub mod signed_integer;
|
||||
pub use self::signed_integer::*;
|
30
gadgets/src/signed_integer/signed_integer.rs
Normal file
30
gadgets/src/signed_integer/signed_integer.rs
Normal 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>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user