pub struct AllocatedFp<F: PrimeField> {
pub variable: Variable,
pub cs: ConstraintSystemRef<F>,
/* private fields */
}Expand description
Represents a variable in the constraint system whose value can be an arbitrary field element.
Fields§
§variable: VariableThe allocated variable corresponding to self in self.cs.
cs: ConstraintSystemRef<F>The constraint system that self was allocated in.
Implementations§
Source§impl<F: PrimeField> AllocatedFp<F>
impl<F: PrimeField> AllocatedFp<F>
Sourcepub fn new(
value: Option<F>,
variable: Variable,
cs: ConstraintSystemRef<F>,
) -> Self
pub fn new( value: Option<F>, variable: Variable, cs: ConstraintSystemRef<F>, ) -> Self
Constructs a new AllocatedFp from a (optional) value, a low-level
Variable, and a ConstraintSystemRef.
Source§impl<F: PrimeField> AllocatedFp<F>
impl<F: PrimeField> AllocatedFp<F>
Sourcepub fn from(other: Boolean<F>) -> Self
pub fn from(other: Boolean<F>) -> Self
Constructs Self from a Boolean: if other is false, this outputs
zero, else it outputs one.
Sourcepub fn value(&self) -> Result<F, SynthesisError>
pub fn value(&self) -> Result<F, SynthesisError>
Returns the value assigned to self in the underlying constraint system
(if a value was assigned).
Sourcepub fn add(&self, other: &Self) -> Self
pub fn add(&self, other: &Self) -> Self
Outputs self + other.
This does not create any constraints.
Sourcepub fn add_many<B: Borrow<Self>>(iter: &[B]) -> Option<Self>
pub fn add_many<B: Borrow<Self>>(iter: &[B]) -> Option<Self>
Add many allocated Fp elements together.
This does not create any constraints and only creates one linear combination.
Returns None if you pass an empty iterator.
Sourcepub fn linear_combination<B1, B2, I1>(this: I1, other: &[B2]) -> Option<Self>
pub fn linear_combination<B1, B2, I1>(this: I1, other: &[B2]) -> Option<Self>
Computes the inner product of two iterators of AllocatedFp elements.
This does not create any constraints and only creates one linear combination.
§Panics
Panics if the iterators are of different lengths.
Sourcepub fn inner_product<B1, B2, I1, I2>(this: I1, other: I2) -> Option<Self>
pub fn inner_product<B1, B2, I1, I2>(this: I1, other: I2) -> Option<Self>
Computes the inner product of two iterators of AllocatedFp elements.
This does not create any constraints and only creates one linear combination.
§Panics
Panics if the iterators are of different lengths.
Sourcepub fn sub(&self, other: &Self) -> Self
pub fn sub(&self, other: &Self) -> Self
Outputs self - other.
This does not create any constraints.
Sourcepub fn add_constant(&self, other: F) -> Self
pub fn add_constant(&self, other: F) -> Self
Output self + other
This does not create any constraints.
Sourcepub fn sub_constant(&self, other: F) -> Self
pub fn sub_constant(&self, other: F) -> Self
Output self - other
This does not create any constraints.
Sourcepub fn mul_constant(&self, other: F) -> Self
pub fn mul_constant(&self, other: F) -> Self
Output self * other
This does not create any constraints.
Sourcepub fn double(&self) -> Result<Self, SynthesisError>
pub fn double(&self) -> Result<Self, SynthesisError>
Output self + self
This does not create any constraints.
Sourcepub fn negate_in_place(&mut self) -> &mut Self
pub fn negate_in_place(&mut self) -> &mut Self
Sets self = -self
This does not create any constraints.
Sourcepub fn square(&self) -> Result<Self, SynthesisError>
pub fn square(&self) -> Result<Self, SynthesisError>
Outputs self * self
This requires one constraint.
Sourcepub fn inverse(&self) -> Result<Self, SynthesisError>
pub fn inverse(&self) -> Result<Self, SynthesisError>
Outputs result such that result * self = 1.
This requires one constraint.
Sourcepub fn frobenius_map(&self, _: usize) -> Result<Self, SynthesisError>
pub fn frobenius_map(&self, _: usize) -> Result<Self, SynthesisError>
This is a no-op for prime fields.
Sourcepub fn mul_equals(
&self,
other: &Self,
result: &Self,
) -> Result<(), SynthesisError>
pub fn mul_equals( &self, other: &Self, result: &Self, ) -> Result<(), SynthesisError>
Enforces that self * other = result.
This requires one constraint.
Sourcepub fn square_equals(&self, result: &Self) -> Result<(), SynthesisError>
pub fn square_equals(&self, result: &Self) -> Result<(), SynthesisError>
Enforces that self * self = result.
This requires one constraint.
Sourcepub fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
pub fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
Outputs the bit self == other.
This requires two constraints.
Sourcepub fn is_neq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
pub fn is_neq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
Outputs the bit self != other.
This requires two constraints.
Sourcepub fn conditional_enforce_equal(
&self,
other: &Self,
should_enforce: &Boolean<F>,
) -> Result<(), SynthesisError>
pub fn conditional_enforce_equal( &self, other: &Self, should_enforce: &Boolean<F>, ) -> Result<(), SynthesisError>
Enforces that self == other if should_enforce.is_eq(&Boolean::TRUE).
This requires one constraint.
Sourcepub fn conditional_enforce_not_equal(
&self,
other: &Self,
should_enforce: &Boolean<F>,
) -> Result<(), SynthesisError>
pub fn conditional_enforce_not_equal( &self, other: &Self, should_enforce: &Boolean<F>, ) -> Result<(), SynthesisError>
Enforces that self != other if should_enforce.is_eq(&Boolean::TRUE).
This requires one constraint.
Trait Implementations§
Source§impl<F: PrimeField> AllocVar<F, F> for AllocatedFp<F>
impl<F: PrimeField> AllocVar<F, F> for AllocatedFp<F>
Source§fn new_variable<T: Borrow<F>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode,
) -> Result<Self, SynthesisError>
fn new_variable<T: Borrow<F>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, mode: AllocationMode, ) -> Result<Self, SynthesisError>
Self in the ConstraintSystem cs.
The mode of allocation is decided by mode.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 + PrimeField> Clone for AllocatedFp<F>
impl<F: Clone + PrimeField> Clone for AllocatedFp<F>
Source§fn clone(&self) -> AllocatedFp<F>
fn clone(&self) -> AllocatedFp<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 AllocatedFp<F>
impl<F: PrimeField> CondSelectGadget<F> for AllocatedFp<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: Debug + PrimeField> Debug for AllocatedFp<F>
impl<F: Debug + PrimeField> Debug for AllocatedFp<F>
Source§impl<F: PrimeField> From<AllocatedFp<F>> for FpVar<F>
impl<F: PrimeField> From<AllocatedFp<F>> for FpVar<F>
Source§fn from(other: AllocatedFp<F>) -> Self
fn from(other: AllocatedFp<F>) -> Self
Source§impl<F: PrimeField> ThreeBitCondNegLookupGadget<F> for AllocatedFp<F>
impl<F: PrimeField> ThreeBitCondNegLookupGadget<F> for AllocatedFp<F>
Source§type TableConstant = F
type TableConstant = F
Source§fn three_bit_cond_neg_lookup(
b: &[Boolean<F>],
b0b1: &Boolean<F>,
c: &[Self::TableConstant],
) -> Result<Self, SynthesisError>
fn three_bit_cond_neg_lookup( b: &[Boolean<F>], b0b1: &Boolean<F>, c: &[Self::TableConstant], ) -> Result<Self, SynthesisError>
bits as a two-bit integer b = bits[0] + (bits[1] << 1), and then outputs constants[b] * c, where c = if bits[2] { -1 } else { 1 };. Read moreSource§impl<F: PrimeField> ToBitsGadget<F> for AllocatedFp<F>
impl<F: PrimeField> ToBitsGadget<F> for AllocatedFp<F>
Source§fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
Outputs the unique bit-wise decomposition of self in little-endian
form.
This method enforces that the output is in the field, i.e.
it invokes Boolean::enforce_in_field_le on the bit decomposition.
Source§fn to_non_unique_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_non_unique_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
self. Read moreSource§fn to_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
self.Source§fn to_non_unique_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_non_unique_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
self.Source§impl<F: PrimeField> ToBytesGadget<F> for AllocatedFp<F>
impl<F: PrimeField> ToBytesGadget<F> for AllocatedFp<F>
Source§fn to_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
fn to_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
Outputs the unique byte decomposition of self in little-endian
form.
This method enforces that the decomposition represents
an integer that is less than F::MODULUS.
Source§fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
self. Read moreSource§impl<F: PrimeField> ToConstraintFieldGadget<F> for AllocatedFp<F>
impl<F: PrimeField> ToConstraintFieldGadget<F> for AllocatedFp<F>
Source§fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError>
fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError>
self to FpVar<ConstraintF> variables.Source§impl<F: PrimeField> TwoBitLookupGadget<F> for AllocatedFp<F>
Uses two bits to perform a lookup into a table
b is little-endian: b[0] is LSB.
impl<F: PrimeField> TwoBitLookupGadget<F> for AllocatedFp<F>
Uses two bits to perform a lookup into a table
b is little-endian: b[0] is LSB.
Source§type TableConstant = F
type TableConstant = F
Source§fn two_bit_lookup(
b: &[Boolean<F>],
c: &[Self::TableConstant],
) -> Result<Self, SynthesisError>
fn two_bit_lookup( b: &[Boolean<F>], c: &[Self::TableConstant], ) -> Result<Self, SynthesisError>
bits as a two-bit integer b = bits[0] + (bits[1] << 1), and then outputs constants[b]. Read moreAuto Trait Implementations§
impl<F> Freeze for AllocatedFp<F>where
F: Freeze,
impl<F> !RefUnwindSafe for AllocatedFp<F>
impl<F> !Send for AllocatedFp<F>
impl<F> !Sync for AllocatedFp<F>
impl<F> Unpin for AllocatedFp<F>where
F: Unpin,
impl<F> UnsafeUnpin for AllocatedFp<F>where
F: UnsafeUnpin,
impl<F> !UnwindSafe for AllocatedFp<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<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