Enum ark_r1cs_std::bits::boolean::Boolean [−][src]
Represents a boolean value in the constraint system which is guaranteed to be either zero or one.
Variants
Is(AllocatedBit<F>)Existential view of the boolean variable.
Not(AllocatedBit<F>)Negated view of the boolean variable.
Constant(bool)Constant (not an allocated variable).
Implementations
impl<F: Field> Boolean<F>[src]
pub const TRUE: Self[src]
The constant true.
pub const FALSE: Self[src]
The constant false.
pub fn lc(&self) -> LinearCombination<F>[src]
Constructs a LinearCombination from Self’s variables according
to the following map.
Boolean::Constant(true) => lc!() + Variable::OneBoolean::Constant(false) => lc!()Boolean::Is(v) => lc!() + v.variable()Boolean::Not(v) => lc!() + Variable::One - v.variable()
pub fn constant_vec_from_bytes(values: &[u8]) -> Vec<Self>[src]
Constructs a Boolean vector from a slice of constant u8.
The u8s are decomposed in little-endian manner.
This does not create any new variables or constraints.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let t = Boolean::<Fr>::TRUE; let f = Boolean::<Fr>::FALSE; let bits = vec![f, t]; let generated_bits = Boolean::constant_vec_from_bytes(&[2]); bits[..2].enforce_equal(&generated_bits[..2])?; assert!(cs.is_satisfied().unwrap());
pub fn constant(b: bool) -> Self[src]
Constructs a constant Boolean with value b.
This does not create any new variables or constraints.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_r1cs_std::prelude::*; let true_var = Boolean::<Fr>::TRUE; let false_var = Boolean::<Fr>::FALSE; true_var.enforce_equal(&Boolean::constant(true))?; false_var.enforce_equal(&Boolean::constant(false))?;
pub fn not(&self) -> Self[src]
Negates self.
This does not create any new variables or constraints.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; a.not().enforce_equal(&b)?; b.not().enforce_equal(&a)?; a.not().enforce_equal(&Boolean::FALSE)?; b.not().enforce_equal(&Boolean::TRUE)?; assert!(cs.is_satisfied().unwrap());
pub fn xor<'a>(&'a self, other: &'a Self) -> Result<Self, SynthesisError>[src]
Outputs self ^ other.
If at least one of self and other are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; a.xor(&b)?.enforce_equal(&Boolean::TRUE)?; b.xor(&a)?.enforce_equal(&Boolean::TRUE)?; a.xor(&a)?.enforce_equal(&Boolean::FALSE)?; b.xor(&b)?.enforce_equal(&Boolean::FALSE)?; assert!(cs.is_satisfied().unwrap());
pub fn or<'a>(&'a self, other: &'a Self) -> Result<Self, SynthesisError>[src]
Outputs self | other.
If at least one of self and other are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; a.or(&b)?.enforce_equal(&Boolean::TRUE)?; b.or(&a)?.enforce_equal(&Boolean::TRUE)?; a.or(&a)?.enforce_equal(&Boolean::TRUE)?; b.or(&b)?.enforce_equal(&Boolean::FALSE)?; assert!(cs.is_satisfied().unwrap());
pub fn and<'a>(&'a self, other: &'a Self) -> Result<Self, SynthesisError>[src]
Outputs self & other.
If at least one of self and other are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; a.and(&a)?.enforce_equal(&Boolean::TRUE)?; a.and(&b)?.enforce_equal(&Boolean::FALSE)?; b.and(&a)?.enforce_equal(&Boolean::FALSE)?; b.and(&b)?.enforce_equal(&Boolean::FALSE)?; assert!(cs.is_satisfied().unwrap());
pub fn kary_and(bits: &[Self]) -> Result<Self, SynthesisError>[src]
Outputs bits[0] & bits[1] & ... & bits.last().unwrap().
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; let c = Boolean::new_witness(cs.clone(), || Ok(true))?; Boolean::kary_and(&[a.clone(), b.clone(), c.clone()])?.enforce_equal(&Boolean::FALSE)?; Boolean::kary_and(&[a.clone(), c.clone()])?.enforce_equal(&Boolean::TRUE)?; assert!(cs.is_satisfied().unwrap());
pub fn kary_or(bits: &[Self]) -> Result<Self, SynthesisError>[src]
Outputs bits[0] | bits[1] | ... | bits.last().unwrap().
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; let c = Boolean::new_witness(cs.clone(), || Ok(false))?; Boolean::kary_or(&[a.clone(), b.clone(), c.clone()])?.enforce_equal(&Boolean::TRUE)?; Boolean::kary_or(&[a.clone(), c.clone()])?.enforce_equal(&Boolean::TRUE)?; Boolean::kary_or(&[b.clone(), c.clone()])?.enforce_equal(&Boolean::FALSE)?; assert!(cs.is_satisfied().unwrap());
pub fn kary_nand(bits: &[Self]) -> Result<Self, SynthesisError>[src]
Outputs (bits[0] & bits[1] & ... & bits.last().unwrap()).not().
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; let c = Boolean::new_witness(cs.clone(), || Ok(true))?; Boolean::kary_nand(&[a.clone(), b.clone(), c.clone()])?.enforce_equal(&Boolean::TRUE)?; Boolean::kary_nand(&[a.clone(), c.clone()])?.enforce_equal(&Boolean::FALSE)?; Boolean::kary_nand(&[b.clone(), c.clone()])?.enforce_equal(&Boolean::TRUE)?; assert!(cs.is_satisfied().unwrap());
pub fn le_bits_to_fp_var(bits: &[Self]) -> Result<FpVar<F>, SynthesisError> where
F: PrimeField, [src]
F: PrimeField,
Convert a little-endian bitwise representation of a field element to FpVar<F>
pub fn enforce_in_field_le(bits: &[Self]) -> Result<(), SynthesisError>[src]
Enforces that bits, when interpreted as a integer, is less than
F::characteristic(), That is, interpret bits as a little-endian
integer, and enforce that this integer is “in the field Z_p”, where
p = F::characteristic() .
pub fn enforce_smaller_or_equal_than_le<'a>(
bits: &[Self],
element: impl AsRef<[u64]>
) -> Result<Vec<Self>, SynthesisError>[src]
bits: &[Self],
element: impl AsRef<[u64]>
) -> Result<Vec<Self>, SynthesisError>
Enforces that bits is less than or equal to element,
when both are interpreted as (little-endian) integers.
pub fn select<T: CondSelectGadget<F>>(
&self,
first: &T,
second: &T
) -> Result<T, SynthesisError>[src]
&self,
first: &T,
second: &T
) -> Result<T, SynthesisError>
Conditionally selects one of first and second based on the value of
self:
If self.is_eq(&Boolean::TRUE), this outputs first; else, it outputs
second.
// We'll use the BLS12-381 scalar field for our constraints. use ark_test_curves::bls12_381::Fr; use ark_relations::r1cs::*; use ark_r1cs_std::prelude::*; let cs = ConstraintSystem::<Fr>::new_ref(); let a = Boolean::new_witness(cs.clone(), || Ok(true))?; let b = Boolean::new_witness(cs.clone(), || Ok(false))?; let cond = Boolean::new_witness(cs.clone(), || Ok(true))?; cond.select(&a, &b)?.enforce_equal(&Boolean::TRUE)?; cond.select(&b, &a)?.enforce_equal(&Boolean::FALSE)?; assert!(cs.is_satisfied().unwrap());
Trait Implementations
impl<F: Field> AllocVar<bool, F> for Boolean<F>[src]
fn new_variable<T: Borrow<bool>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode
) -> Result<Self, SynthesisError>[src]
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode
) -> Result<Self, SynthesisError>
fn new_constant(
cs: impl Into<Namespace<F>>,
t: impl Borrow<V>
) -> Result<Self, SynthesisError>[src]
cs: impl Into<Namespace<F>>,
t: impl Borrow<V>
) -> Result<Self, SynthesisError>
fn new_input<T: Borrow<V>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> Result<Self, SynthesisError>[src]
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> Result<Self, SynthesisError>
fn new_witness<T: Borrow<V>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> Result<Self, SynthesisError>[src]
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> Result<Self, SynthesisError>
impl<F: Clone + Field> Clone for Boolean<F>[src]
impl<F: Field> CondSelectGadget<F> for Boolean<F>[src]
fn conditionally_select(
cond: &Boolean<F>,
true_val: &Self,
false_val: &Self
) -> Result<Self, SynthesisError>[src]
cond: &Boolean<F>,
true_val: &Self,
false_val: &Self
) -> Result<Self, SynthesisError>
fn conditionally_select_power_of_two_vector(
position: &[Boolean<ConstraintF>],
values: &[Self]
) -> Result<Self, SynthesisError>[src]
position: &[Boolean<ConstraintF>],
values: &[Self]
) -> Result<Self, SynthesisError>
impl<F: Debug + Field> Debug for Boolean<F>[src]
impl<F: Eq + Field> Eq for Boolean<F>[src]
impl<F: Field> EqGadget<F> for Boolean<F>[src]
fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>[src]
fn conditional_enforce_equal(
&self,
other: &Self,
condition: &Boolean<F>
) -> Result<(), SynthesisError>[src]
&self,
other: &Self,
condition: &Boolean<F>
) -> Result<(), SynthesisError>
fn conditional_enforce_not_equal(
&self,
other: &Self,
should_enforce: &Boolean<F>
) -> Result<(), SynthesisError>[src]
&self,
other: &Self,
should_enforce: &Boolean<F>
) -> Result<(), SynthesisError>
fn is_neq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>[src]
fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>[src]
fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>[src]
impl<F: Field> From<AllocatedBit<F>> for Boolean<F>[src]
fn from(b: AllocatedBit<F>) -> Self[src]
impl<BF, P> From<Boolean<<P as CubicExtParameters>::BasePrimeField>> for CubicExtVar<BF, P> where
BF: FieldVar<P::BaseField, P::BasePrimeField>,
&'a BF: FieldOpsBounds<'a, P::BaseField, BF>,
P: CubicExtVarParams<BF>, [src]
BF: FieldVar<P::BaseField, P::BasePrimeField>,
&'a BF: FieldOpsBounds<'a, P::BaseField, BF>,
P: CubicExtVarParams<BF>,
fn from(other: Boolean<P::BasePrimeField>) -> Self[src]
impl<BF, P> From<Boolean<<P as QuadExtParameters>::BasePrimeField>> for QuadExtVar<BF, P> where
BF: FieldVar<P::BaseField, P::BasePrimeField>,
&'a BF: FieldOpsBounds<'a, P::BaseField, BF>,
P: QuadExtVarParams<BF>, [src]
BF: FieldVar<P::BaseField, P::BasePrimeField>,
&'a BF: FieldOpsBounds<'a, P::BaseField, BF>,
P: QuadExtVarParams<BF>,
fn from(other: Boolean<P::BasePrimeField>) -> Self[src]
impl<F: PrimeField> From<Boolean<F>> for FpVar<F>[src]
impl<F: PartialEq + Field> PartialEq<Boolean<F>> for Boolean<F>[src]
impl<F: Field> R1CSVar<F> for Boolean<F>[src]
type Value = bool
The type of the “native” value that Self represents in the constraint
system. Read more
fn cs(&self) -> ConstraintSystemRef<F>[src]
fn value(&self) -> Result<Self::Value, SynthesisError>[src]
fn is_constant(&self) -> bool[src]
impl<F: Field> StructuralEq for Boolean<F>[src]
impl<F: Field> StructuralPartialEq for Boolean<F>[src]
impl<F: Field> ToBitsGadget<F> for Boolean<F>[src]
fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>[src]
fn to_non_unique_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>[src]
fn to_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>[src]
fn to_non_unique_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>[src]
impl<F: Field> ToBytesGadget<F> for Boolean<F>[src]
fn to_bytes(&self) -> Result<Vec<UInt8<F>>, SynthesisError>[src]
Outputs 1u8 if self is true, and 0u8 otherwise.
fn to_non_unique_bytes(&self) -> Result<Vec<UInt8<F>>, SynthesisError>[src]
impl<F: PrimeField> ToConstraintFieldGadget<F> for Boolean<F>[src]
fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError>[src]
Auto Trait Implementations
impl<F> !RefUnwindSafe for Boolean<F>
impl<F> !Send for Boolean<F>
impl<F> !Sync for Boolean<F>
impl<F> Unpin for Boolean<F>
impl<F> !UnwindSafe for Boolean<F>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T> Instrument for T[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>[src]
pub fn in_current_span(self) -> Instrumented<Self>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,