mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-23 04:58:17 +03:00
add evaluate eq gadget for i types
This commit is contained in:
parent
6c0a5ed872
commit
a1f2366fe8
@ -1,13 +0,0 @@
|
|||||||
use crate::errors::IntegerError;
|
|
||||||
|
|
||||||
use snarkos_models::{
|
|
||||||
curves::PrimeField,
|
|
||||||
gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean},
|
|
||||||
};
|
|
||||||
|
|
||||||
///
|
|
||||||
pub trait Cmp<Rhs = Self>
|
|
||||||
where
|
|
||||||
Self: std::marker::Sized,
|
|
||||||
{
|
|
||||||
}
|
|
@ -2,9 +2,6 @@
|
|||||||
pub mod add;
|
pub mod add;
|
||||||
pub use self::add::*;
|
pub use self::add::*;
|
||||||
|
|
||||||
pub mod cmp;
|
|
||||||
pub use self::cmp::*;
|
|
||||||
|
|
||||||
pub mod div;
|
pub mod div;
|
||||||
pub use self::div::*;
|
pub use self::div::*;
|
||||||
|
|
||||||
|
@ -6,5 +6,8 @@ pub use self::arithmetic::*;
|
|||||||
pub mod int_impl;
|
pub mod int_impl;
|
||||||
pub use self::int_impl::*;
|
pub use self::int_impl::*;
|
||||||
|
|
||||||
|
pub mod relational;
|
||||||
|
pub use self::relational::*;
|
||||||
|
|
||||||
pub mod utilities;
|
pub mod utilities;
|
||||||
pub use self::utilities::*;
|
pub use self::utilities::*;
|
||||||
|
40
gadgets/src/signed_integer/relational/eq.rs
Normal file
40
gadgets/src/signed_integer/relational/eq.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use crate::{Int, Int128, Int16, Int32, Int64, Int8};
|
||||||
|
|
||||||
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use snarkos_models::{
|
||||||
|
curves::PrimeField,
|
||||||
|
gadgets::{
|
||||||
|
r1cs::ConstraintSystem,
|
||||||
|
utilities::{boolean::Boolean, eq::EvaluateEqGadget},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
macro_rules! eq_gadget_impl {
|
||||||
|
($($gadget: ident)*) => ($(
|
||||||
|
impl<F: PrimeField> EvaluateEqGadget<F> for $gadget {
|
||||||
|
fn evaluate_equal<CS: ConstraintSystem<F>>(
|
||||||
|
&self,
|
||||||
|
mut cs: CS,
|
||||||
|
other: &Self
|
||||||
|
) -> Result<Boolean, SynthesisError> {
|
||||||
|
let mut result = Boolean::constant(true);
|
||||||
|
for (i, (a, b)) in self.bits.iter().zip(&other.bits).enumerate() {
|
||||||
|
let equal = a.evaluate_equal(
|
||||||
|
&mut cs.ns(|| format!("{} evaluate equality for {}-th bit", <$gadget as Int>::SIZE, i)),
|
||||||
|
b,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
result = Boolean::and(
|
||||||
|
&mut cs.ns(|| format!("{} and result for {}-th bit", <$gadget as Int>::SIZE, i)),
|
||||||
|
&equal,
|
||||||
|
&result,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*)
|
||||||
|
}
|
||||||
|
|
||||||
|
eq_gadget_impl!(Int8 Int16 Int32 Int64 Int128);
|
2
gadgets/src/signed_integer/relational/mod.rs
Normal file
2
gadgets/src/signed_integer/relational/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod eq;
|
||||||
|
pub use self::eq::*;
|
Loading…
Reference in New Issue
Block a user