pub struct AllocatedBool<F: Field> { /* private fields */ }Expand description
Represents a variable in the constraint system which is guaranteed to be either zero or one.
In general, one should prefer using Boolean instead of AllocatedBool,
as Boolean offers better support for constant values, and implements
more traits.
Implementations§
Source§impl<F: Field> AllocatedBool<F>
impl<F: Field> AllocatedBool<F>
Sourcepub fn value(&self) -> Result<bool, SynthesisError>
pub fn value(&self) -> Result<bool, SynthesisError>
Get the assigned value for self.
Sourcepub fn not(&self) -> Result<Self, SynthesisError>
pub fn not(&self) -> Result<Self, SynthesisError>
Performs an XOR operation over the two operands, returning
an AllocatedBool.
Sourcepub fn xor(&self, b: &Self) -> Result<Self, SynthesisError>
pub fn xor(&self, b: &Self) -> Result<Self, SynthesisError>
Performs an XOR operation over the two operands, returning
an AllocatedBool.
Sourcepub fn and(&self, b: &Self) -> Result<Self, SynthesisError>
pub fn and(&self, b: &Self) -> Result<Self, SynthesisError>
Performs an AND operation over the two operands, returning
an AllocatedBool.
Sourcepub fn or(&self, b: &Self) -> Result<Self, SynthesisError>
pub fn or(&self, b: &Self) -> Result<Self, SynthesisError>
Performs an OR operation over the two operands, returning
an AllocatedBool.
Sourcepub fn and_not(&self, b: &Self) -> Result<Self, SynthesisError>
pub fn and_not(&self, b: &Self) -> Result<Self, SynthesisError>
Calculates a AND (NOT b).
Sourcepub fn nor(&self, b: &Self) -> Result<Self, SynthesisError>
pub fn nor(&self, b: &Self) -> Result<Self, SynthesisError>
Calculates (NOT a) AND (NOT b).
Trait Implementations§
Source§impl<F: Field> AllocVar<bool, F> for AllocatedBool<F>
impl<F: Field> AllocVar<bool, F> for AllocatedBool<F>
Source§fn new_variable<T: Borrow<bool>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode,
) -> Result<Self, SynthesisError>
fn new_variable<T: Borrow<bool>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, mode: AllocationMode, ) -> Result<Self, SynthesisError>
Produces a new variable of the appropriate kind (instance or witness), with a booleanity check.
N.B.: we could omit the booleanity check when allocating self
as a new public input, but that places an additional burden on
protocol designers. Better safe than sorry!
Source§fn new_constant(
cs: impl Into<Namespace<F>>,
t: impl Borrow<V>,
) -> Result<Self, SynthesisError>
fn new_constant( cs: impl Into<Namespace<F>>, t: impl Borrow<V>, ) -> Result<Self, SynthesisError>
Source§fn new_input<T: Borrow<V>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
) -> Result<Self, SynthesisError>
fn new_input<T: Borrow<V>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, ) -> Result<Self, SynthesisError>
Self in the ConstraintSystem
cs.Source§fn new_witness<T: Borrow<V>>(
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>
Self in the ConstraintSystem
cs.Source§fn new_variable_with_inferred_mode<T: Borrow<V>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
) -> Result<Self, SynthesisError>
fn new_variable_with_inferred_mode<T: Borrow<V>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, ) -> Result<Self, SynthesisError>
Self in the
ConstraintSystem cs with the allocation mode inferred from cs.
A constant is allocated if cs is None, and a private witness is
allocated otherwise. Read moreSource§impl<F: Clone + Field> Clone for AllocatedBool<F>
impl<F: Clone + Field> Clone for AllocatedBool<F>
Source§fn clone(&self) -> AllocatedBool<F>
fn clone(&self) -> AllocatedBool<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: PrimeField> CondSelectGadget<F> for AllocatedBool<F>
impl<F: PrimeField> CondSelectGadget<F> for AllocatedBool<F>
Source§fn conditionally_select(
cond: &Boolean<F>,
true_val: &Self,
false_val: &Self,
) -> Result<Self, SynthesisError>
fn conditionally_select( cond: &Boolean<F>, true_val: &Self, false_val: &Self, ) -> Result<Self, SynthesisError>
Source§fn conditionally_select_power_of_two_vector(
position: &[Boolean<ConstraintF>],
values: &[Self],
) -> Result<Self, SynthesisError>
fn conditionally_select_power_of_two_vector( position: &[Boolean<ConstraintF>], values: &[Self], ) -> Result<Self, SynthesisError>
values whose index in represented by position.
position is an array of boolean that represents an unsigned integer in
big endian order. Read moreSource§impl<F: Field> From<AllocatedBool<F>> for Boolean<F>
impl<F: Field> From<AllocatedBool<F>> for Boolean<F>
Source§fn from(b: AllocatedBool<F>) -> Self
fn from(b: AllocatedBool<F>) -> Self
impl<F: Eq + Field> Eq for AllocatedBool<F>
impl<F: Field> StructuralPartialEq for AllocatedBool<F>
Auto Trait Implementations§
impl<F> Freeze for AllocatedBool<F>
impl<F> !RefUnwindSafe for AllocatedBool<F>
impl<F> !Send for AllocatedBool<F>
impl<F> !Sync for AllocatedBool<F>
impl<F> Unpin for AllocatedBool<F>
impl<F> !UnwindSafe for AllocatedBool<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more