pub enum Boolean {
Is(AllocatedBit),
Not(AllocatedBit),
Constant(bool),
}
Expand description
This is a boolean value which may be either a constant or
an interpretation of an AllocatedBit
.
Variants
Is(AllocatedBit)
Existential view of the boolean variable
Not(AllocatedBit)
Negated view of the boolean variable
Constant(bool)
Constant (not an allocated variable)
Implementations
sourceimpl Boolean
impl Boolean
pub fn get_value(&self) -> Option<bool>
pub fn lc<F: Field>(&self, one: Variable, coeff: F) -> LinearCombination<F>
sourcepub fn constant_u8_vec<F: Field, CS: ConstraintSystem<F>>(
cs: &mut CS,
values: &[u8]
) -> Vec<Self>
pub fn constant_u8_vec<F: Field, CS: ConstraintSystem<F>>(
cs: &mut CS,
values: &[u8]
) -> Vec<Self>
Construct a boolean vector from a vector of u8
sourcepub fn or<'a, F, CS>(
cs: CS,
a: &'a Self,
b: &'a Self
) -> Result<Self, SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
pub fn or<'a, F, CS>(
cs: CS,
a: &'a Self,
b: &'a Self
) -> Result<Self, SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
Perform OR over two boolean operands.
sourcepub fn and<'a, F: Field, CS: ConstraintSystem<F>>(
cs: CS,
a: &'a Self,
b: &'a Self
) -> Result<Self, SynthesisError>
pub fn and<'a, F: Field, CS: ConstraintSystem<F>>(
cs: CS,
a: &'a Self,
b: &'a Self
) -> Result<Self, SynthesisError>
Perform AND over two boolean operands.
sourcepub fn kary_and<F, CS>(cs: CS, bits: &[Self]) -> Result<Self, SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
pub fn kary_and<F, CS>(cs: CS, bits: &[Self]) -> Result<Self, SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
Perform AND over all the given boolean operands.
sourcepub fn enforce_nand<F, CS>(cs: CS, bits: &[Self]) -> Result<(), SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
pub fn enforce_nand<F, CS>(cs: CS, bits: &[Self]) -> Result<(), SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
Asserts that at least one operand is false.
sourcepub fn enforce_in_field<F, CS, NativeF: PrimeField>(
cs: CS,
bits: &[Self]
) -> Result<(), SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
pub fn enforce_in_field<F, CS, NativeF: PrimeField>(
cs: CS,
bits: &[Self]
) -> Result<(), SynthesisError> where
F: Field,
CS: ConstraintSystem<F>,
Asserts that this bit_gadget representation is “in the field” when interpreted in big endian.
sourcepub fn enforce_in_field_le<F: Field, CS: ConstraintSystem<F>>(
cs: CS,
bits: &[Self]
) -> Result<(), SynthesisError>
pub fn enforce_in_field_le<F: Field, CS: ConstraintSystem<F>>(
cs: CS,
bits: &[Self]
) -> Result<(), SynthesisError>
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 kary_nand<F: Field, CS: ConstraintSystem<F>>(
cs: CS,
bits: &[Self]
) -> Result<Self, SynthesisError>
pub fn enforce_smaller_or_equal_than_le<F: Field, CS: ConstraintSystem<F>>(
cs: CS,
bits: &[Self],
element: impl AsRef<[u64]>
) -> Result<Vec<Self>, SynthesisError>
pub fn enforce_smaller_or_equal_than_be<F: Field, CS: ConstraintSystem<F>>(
cs: CS,
bits: &[Self],
element: impl AsRef<[u64]>
) -> Result<Vec<Self>, SynthesisError>
sourcepub fn le_bits_to_fp_var<CS: ConstraintSystem<F>, F: PrimeField>(
cs: CS,
bits: &[Self]
) -> Result<FpGadget<F>, SynthesisError>
pub fn le_bits_to_fp_var<CS: ConstraintSystem<F>, F: PrimeField>(
cs: CS,
bits: &[Self]
) -> Result<FpGadget<F>, SynthesisError>
Convert a little-endian bitwise representation of a field element to FpGadget<F>
Trait Implementations
sourceimpl<F: Field> AllocGadget<bool, F> for Boolean
impl<F: Field> AllocGadget<bool, F> for Boolean
fn alloc_constant<Fn, T, CS: ConstraintSystem<F>>(
_cs: CS,
value_gen: Fn
) -> Result<Self, SynthesisError> where
Fn: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<bool>,
fn alloc<Fn, T, CS: ConstraintSystem<F>>(
cs: CS,
value_gen: Fn
) -> Result<Self, SynthesisError> where
Fn: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<bool>,
fn alloc_input<Fn, T, CS: ConstraintSystem<F>>(
cs: CS,
value_gen: Fn
) -> Result<Self, SynthesisError> where
Fn: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<bool>,
fn alloc_checked<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<V>, CS: ConstraintSystem<F>>(
cs: CS,
f: Fn
) -> Result<Self, SynthesisError>
fn alloc_input_checked<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<V>, CS: ConstraintSystem<F>>(
cs: CS,
f: Fn
) -> Result<Self, SynthesisError>
sourceimpl<F: PrimeField> CondSelectGadget<F> for Boolean
impl<F: PrimeField> CondSelectGadget<F> for Boolean
fn conditionally_select<CS>(
cs: CS,
cond: &Self,
first: &Self,
second: &Self
) -> Result<Self, SynthesisError> where
CS: ConstraintSystem<F>,
fn cost() -> usize
sourceimpl<F: Field> ConditionalEqGadget<F> for Boolean
impl<F: Field> ConditionalEqGadget<F> for Boolean
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self,
condition: &Boolean
) -> Result<(), SynthesisError>
fn cost() -> usize
sourceimpl<F: Field> EqGadget<F> for Boolean
impl<F: Field> EqGadget<F> for Boolean
sourcefn is_eq<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Boolean, SynthesisError>
fn is_eq<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Boolean, SynthesisError>
Output a Boolean
value representing whether self.value() == other.value()
. Read more
fn enforce_equal<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<(), SynthesisError>
fn cost() -> usize
sourceimpl<F: PrimeField> EvaluateEqGadget<F> for Boolean
impl<F: PrimeField> EvaluateEqGadget<F> for Boolean
a == b = !(a XOR b)
fn evaluate_equal<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Boolean, SynthesisError>
sourceimpl From<AllocatedBit> for Boolean
impl From<AllocatedBit> for Boolean
sourcefn from(b: AllocatedBit) -> Boolean
fn from(b: AllocatedBit) -> Boolean
Performs the conversion.
sourceimpl<'a, F: Field> FullAdder<'a, F> for Boolean
impl<'a, F: Field> FullAdder<'a, F> for Boolean
fn add<CS: ConstraintSystem<F>>(
cs: CS,
a: &'a Self,
b: &'a Self,
carry: &'a Self
) -> Result<(Self, Self), SynthesisError>
sourceimpl SignExtend for Boolean
impl SignExtend for Boolean
sourceimpl<F: Field> ToBitsBEGadget<F> for Boolean
impl<F: Field> ToBitsBEGadget<F> for Boolean
fn to_bits_be<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
sourcefn to_bits_be_strict<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
fn to_bits_be_strict<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
sourceimpl<F: Field> ToBitsLEGadget<F> for Boolean
impl<F: Field> ToBitsLEGadget<F> for Boolean
fn to_bits_le<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
sourcefn to_bits_le_strict<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
fn to_bits_le_strict<CS: ConstraintSystem<F>>(
&self,
_: CS
) -> Result<Vec<Boolean>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
sourceimpl<F: Field> ToBytesGadget<F> for Boolean
impl<F: Field> ToBytesGadget<F> for Boolean
sourcefn to_bytes_strict<CS: ConstraintSystem<F>>(
&self,
cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
fn to_bytes_strict<CS: ConstraintSystem<F>>(
&self,
cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
fn to_bytes<CS: ConstraintSystem<F>>(
&self,
_cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
sourceimpl<F: PrimeField> ToConstraintFieldGadget<F> for Boolean
impl<F: PrimeField> ToConstraintFieldGadget<F> for Boolean
sourcefn to_constraint_field<CS: ConstraintSystem<F>>(
&self,
cs: CS
) -> Result<Vec<FpGadget<F>>, SynthesisError>
fn to_constraint_field<CS: ConstraintSystem<F>>(
&self,
cs: CS
) -> Result<Vec<FpGadget<F>>, SynthesisError>
Converts self
to FpGadget<F>
variables.
sourceimpl<F: Field> Xor<F, Boolean> for Boolean
impl<F: Field> Xor<F, Boolean> for Boolean
fn xor<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Self, SynthesisError>
impl Copy for Boolean
impl Eq for Boolean
Auto Trait Implementations
impl RefUnwindSafe for Boolean
impl Send for Boolean
impl Sync for Boolean
impl Unpin for Boolean
impl UnwindSafe for Boolean
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F, T> ConditionalOrEqualsGadget<F> for T where
F: Field,
T: ConditionalEqGadget<F> + CondSelectGadget<F>,
impl<F, T> ConditionalOrEqualsGadget<F> for T where
F: Field,
T: ConditionalEqGadget<F> + CondSelectGadget<F>,
fn conditional_enforce_equal_or<CS: ConstraintSystem<F>>(
cs: CS,
cond: &Boolean,
var: &Self,
first: &Self,
second: &Self,
should_enforce: &Boolean
) -> Result<(), SynthesisError>
fn cost() -> usize
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<F, T> OrEqualsGadget<F> for T where
F: Field,
T: ConditionalOrEqualsGadget<F>,
impl<F, T> OrEqualsGadget<F> for T where
F: Field,
T: ConditionalOrEqualsGadget<F>,
fn enforce_equal_or<CS: ConstraintSystem<F>>(
cs: CS,
cond: &Boolean,
var: &Self,
first: &Self,
second: &Self
) -> Result<(), SynthesisError>
fn cost() -> usize
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more