arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/src/cmp.rs
src/cmp.rsRaw
 1use ark_ff::Field;
 2use ark_relations::r1cs::SynthesisError;
 3
 4use crate::{boolean::Boolean, R1CSVar};
 5
 6/// Specifies how to generate constraints for comparing two variables.
 7pub trait CmpGadget<F: Field>: R1CSVar<F> {
 8    fn is_gt(&self, other: &Self) -> Result<Boolean<F>, SynthesisError> {
 9        other.is_lt(self)
10    }
11
12    fn is_ge(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>;
13
14    fn is_lt(&self, other: &Self) -> Result<Boolean<F>, SynthesisError> {
15        Ok(!self.is_ge(other)?)
16    }
17
18    fn is_le(&self, other: &Self) -> Result<Boolean<F>, SynthesisError> {
19        other.is_ge(self)
20    }
21}