pub enum FpVar<F: PrimeField> {
Constant(F),
Var(AllocatedFp<F>),
}
Expand description
Represent variables corresponding to a field element in F
.
Variants§
Constant(F)
Represents a constant in the constraint system, which means that it does not have a corresponding variable.
Var(AllocatedFp<F>)
Represents an allocated variable constant in the constraint system.
Implementations§
Source§impl<F: PrimeField> FpVar<F>
impl<F: PrimeField> FpVar<F>
Sourcepub fn enforce_cmp(
&self,
other: &FpVar<F>,
ordering: Ordering,
should_also_check_equality: bool,
) -> Result<(), SynthesisError>
pub fn enforce_cmp( &self, other: &FpVar<F>, ordering: Ordering, should_also_check_equality: bool, ) -> Result<(), SynthesisError>
This function enforces the ordering between self
and other
. The
constraint system will not be satisfied otherwise. If self
should
also be checked for equality, e.g. self <= other
instead of self < other
, set should_also_check_quality
to true
. This variant
verifies self
and other
are <= (p-1)/2
.
Sourcepub fn enforce_cmp_unchecked(
&self,
other: &FpVar<F>,
ordering: Ordering,
should_also_check_equality: bool,
) -> Result<(), SynthesisError>
pub fn enforce_cmp_unchecked( &self, other: &FpVar<F>, ordering: Ordering, should_also_check_equality: bool, ) -> Result<(), SynthesisError>
This function enforces the ordering between self
and other
. The
constraint system will not be satisfied otherwise. If self
should
also be checked for equality, e.g. self <= other
instead of self < other
, set should_also_check_quality
to true
. This variant
assumes self
and other
are <= (p-1)/2
and does not generate
constraints to verify that.
Sourcepub fn is_cmp(
&self,
other: &FpVar<F>,
ordering: Ordering,
should_also_check_equality: bool,
) -> Result<Boolean<F>, SynthesisError>
pub fn is_cmp( &self, other: &FpVar<F>, ordering: Ordering, should_also_check_equality: bool, ) -> Result<Boolean<F>, SynthesisError>
This function checks the ordering between self
and other
. It outputs
self Boolean
that contains the result - 1
if true, 0
otherwise. The constraint system will be satisfied in any case. If
self
should also be checked for equality, e.g. self <= other
instead of self < other
, set should_also_check_quality
to
true
. This variant verifies self
and other
are <= (p-1)/2
.
Sourcepub fn is_cmp_unchecked(
&self,
other: &FpVar<F>,
ordering: Ordering,
should_also_check_equality: bool,
) -> Result<Boolean<F>, SynthesisError>
pub fn is_cmp_unchecked( &self, other: &FpVar<F>, ordering: Ordering, should_also_check_equality: bool, ) -> Result<Boolean<F>, SynthesisError>
This function checks the ordering between self
and other
. It outputs
a Boolean
that contains the result - 1
if true, 0
otherwise.
The constraint system will be satisfied in any case. If self
should also be checked for equality, e.g. self <= other
instead of
self < other
, set should_also_check_quality
to true
. This
variant assumes self
and other
are <= (p-1)/2
and does not
generate constraints to verify that.
Sourcepub fn enforce_smaller_or_equal_than_mod_minus_one_div_two(
&self,
) -> Result<(), SynthesisError>
pub fn enforce_smaller_or_equal_than_mod_minus_one_div_two( &self, ) -> Result<(), SynthesisError>
Helper function to enforce that self <= (p-1)/2
.
Source§impl<F: PrimeField> FpVar<F>
impl<F: PrimeField> FpVar<F>
Sourcepub fn to_bits_le_with_top_bits_zero(
&self,
size: usize,
) -> Result<(Vec<Boolean<F>>, Self), SynthesisError>
pub fn to_bits_le_with_top_bits_zero( &self, size: usize, ) -> Result<(Vec<Boolean<F>>, Self), SynthesisError>
Decomposes self
into a vector of bits
and a remainder rest
such that
bits.len() == size
, andrest == 0
.
Trait Implementations§
Source§impl<'a, F: PrimeField> Add<F> for &'a FpVar<F>
impl<'a, F: PrimeField> Add<F> for &'a FpVar<F>
Source§impl<F: PrimeField> Add<F> for FpVar<F>
impl<F: PrimeField> Add<F> for FpVar<F>
Source§impl<'a, F: PrimeField> Add for &'a FpVar<F>
impl<'a, F: PrimeField> Add for &'a FpVar<F>
Source§impl<F: PrimeField> Add for FpVar<F>
impl<F: PrimeField> Add for FpVar<F>
Source§impl<'a, F: PrimeField> AddAssign<&'a FpVar<F>> for FpVar<F>
impl<'a, F: PrimeField> AddAssign<&'a FpVar<F>> for FpVar<F>
Source§fn add_assign(&mut self, other: &'a FpVar<F>)
fn add_assign(&mut self, other: &'a FpVar<F>)
+=
operation. Read moreSource§impl<F: PrimeField> AddAssign<F> for FpVar<F>
impl<F: PrimeField> AddAssign<F> for FpVar<F>
Source§fn add_assign(&mut self, other: F)
fn add_assign(&mut self, other: F)
+=
operation. Read moreSource§impl<F: PrimeField> AddAssign for FpVar<F>
impl<F: PrimeField> AddAssign for FpVar<F>
Source§fn add_assign(&mut self, other: FpVar<F>)
fn add_assign(&mut self, other: FpVar<F>)
+=
operation. Read moreSource§impl<F: PrimeField> AllocVar<F, F> for FpVar<F>
impl<F: PrimeField> AllocVar<F, F> for FpVar<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: PrimeField> CondSelectGadget<F> for FpVar<F>
impl<F: PrimeField> CondSelectGadget<F> for FpVar<F>
Source§fn conditionally_select(
cond: &Boolean<F>,
true_value: &Self,
false_value: &Self,
) -> Result<Self, SynthesisError>
fn conditionally_select( cond: &Boolean<F>, true_value: &Self, false_value: &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<P: Fp3Config> CubicExtVarConfig<FpVar<<P as Fp3Config>::Fp>> for Fp3ConfigWrapper<P>
impl<P: Fp3Config> CubicExtVarConfig<FpVar<<P as Fp3Config>::Fp>> for Fp3ConfigWrapper<P>
Source§impl<F: PrimeField> EqGadget<F> for FpVar<F>
impl<F: PrimeField> EqGadget<F> for FpVar<F>
Source§fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>
Boolean
value representing whether self.value() == other.value()
.Source§fn conditional_enforce_equal(
&self,
other: &Self,
should_enforce: &Boolean<F>,
) -> Result<(), SynthesisError>
fn conditional_enforce_equal( &self, other: &Self, should_enforce: &Boolean<F>, ) -> Result<(), SynthesisError>
should_enforce == true
, enforce that self
and other
are equal;
else, enforce a vacuously true statement. Read moreSource§fn conditional_enforce_not_equal(
&self,
other: &Self,
should_enforce: &Boolean<F>,
) -> Result<(), SynthesisError>
fn conditional_enforce_not_equal( &self, other: &Self, should_enforce: &Boolean<F>, ) -> Result<(), SynthesisError>
should_enforce == true
, enforce that self
and other
are not
equal; else, enforce a vacuously true statement. Read moreSource§fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>
fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>
Source§fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>
fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>
Source§impl<F: PrimeField> FieldVar<F, F> for FpVar<F>
impl<F: PrimeField> FieldVar<F, F> for FpVar<F>
Source§fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError>
fn mul_equals(&self, other: &Self, result: &Self) -> Result<(), SynthesisError>
Enforce that self * other == result
.
Source§fn square_equals(&self, result: &Self) -> Result<(), SynthesisError>
fn square_equals(&self, result: &Self) -> Result<(), SynthesisError>
Enforce that self * self == result
.
Source§fn double(&self) -> Result<Self, SynthesisError>
fn double(&self) -> Result<Self, SynthesisError>
self + self
.Source§fn negate(&self) -> Result<Self, SynthesisError>
fn negate(&self) -> Result<Self, SynthesisError>
-self
.Source§fn inverse(&self) -> Result<Self, SynthesisError>
fn inverse(&self) -> Result<Self, SynthesisError>
result
such that self * result == Self::one()
.Source§fn frobenius_map(&self, power: usize) -> Result<Self, SynthesisError>
fn frobenius_map(&self, power: usize) -> Result<Self, SynthesisError>
self
.Source§fn frobenius_map_in_place(
&mut self,
power: usize,
) -> Result<&mut Self, SynthesisError>
fn frobenius_map_in_place( &mut self, power: usize, ) -> Result<&mut Self, SynthesisError>
self = self.frobenius_map()
.Source§fn is_zero(&self) -> Result<Boolean<ConstraintF>, SynthesisError>
fn is_zero(&self) -> Result<Boolean<ConstraintF>, SynthesisError>
Boolean
representing whether self == Self::zero()
.Source§fn is_one(&self) -> Result<Boolean<ConstraintF>, SynthesisError>
fn is_one(&self) -> Result<Boolean<ConstraintF>, SynthesisError>
Boolean
representing whether self == Self::one()
.Source§fn double_in_place(&mut self) -> Result<&mut Self, SynthesisError>
fn double_in_place(&mut self) -> Result<&mut Self, SynthesisError>
self = self + self
.Source§fn negate_in_place(&mut self) -> Result<&mut Self, SynthesisError>
fn negate_in_place(&mut self) -> Result<&mut Self, SynthesisError>
self = -self
.Source§fn square_in_place(&mut self) -> Result<&mut Self, SynthesisError>
fn square_in_place(&mut self) -> Result<&mut Self, SynthesisError>
self = self.square()
.Source§fn mul_by_inverse(&self, d: &Self) -> Result<Self, SynthesisError>
fn mul_by_inverse(&self, d: &Self) -> Result<Self, SynthesisError>
(self / d)
.
The constraint system will be unsatisfiable when d = 0
.Source§fn mul_by_inverse_unchecked(&self, d: &Self) -> Result<Self, SynthesisError>
fn mul_by_inverse_unchecked(&self, d: &Self) -> Result<Self, SynthesisError>
(self / d)
. Read moreSource§fn pow_le(&self, bits: &[Boolean<ConstraintF>]) -> Result<Self, SynthesisError>
fn pow_le(&self, bits: &[Boolean<ConstraintF>]) -> Result<Self, SynthesisError>
self^bits
, where bits
is a little-endian bit-wise
decomposition of the exponent.Source§fn pow_by_constant<S: AsRef<[u64]>>(
&self,
exp: S,
) -> Result<Self, SynthesisError>
fn pow_by_constant<S: AsRef<[u64]>>( &self, exp: S, ) -> Result<Self, SynthesisError>
self^S
, where S is interpreted as an little-endian
u64-decomposition of an integer.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<'a, F: PrimeField> Mul<F> for &'a FpVar<F>
impl<'a, F: PrimeField> Mul<F> for &'a FpVar<F>
Source§impl<F: PrimeField> Mul<F> for FpVar<F>
impl<F: PrimeField> Mul<F> for FpVar<F>
Source§impl<'a, F: PrimeField> Mul for &'a FpVar<F>
impl<'a, F: PrimeField> Mul for &'a FpVar<F>
Source§impl<F: PrimeField> Mul for FpVar<F>
impl<F: PrimeField> Mul for FpVar<F>
Source§impl<'a, F: PrimeField> MulAssign<&'a FpVar<F>> for FpVar<F>
impl<'a, F: PrimeField> MulAssign<&'a FpVar<F>> for FpVar<F>
Source§fn mul_assign(&mut self, other: &'a FpVar<F>)
fn mul_assign(&mut self, other: &'a FpVar<F>)
*=
operation. Read moreSource§impl<F: PrimeField> MulAssign<F> for FpVar<F>
impl<F: PrimeField> MulAssign<F> for FpVar<F>
Source§fn mul_assign(&mut self, other: F)
fn mul_assign(&mut self, other: F)
*=
operation. Read moreSource§impl<F: PrimeField> MulAssign for FpVar<F>
impl<F: PrimeField> MulAssign for FpVar<F>
Source§fn mul_assign(&mut self, other: FpVar<F>)
fn mul_assign(&mut self, other: FpVar<F>)
*=
operation. Read moreSource§impl<P: Fp2Config> QuadExtVarConfig<FpVar<<P as Fp2Config>::Fp>> for Fp2ConfigWrapper<P>
impl<P: Fp2Config> QuadExtVarConfig<FpVar<<P as Fp2Config>::Fp>> for Fp2ConfigWrapper<P>
Source§impl<'a, F: PrimeField> Sub<F> for &'a FpVar<F>
impl<'a, F: PrimeField> Sub<F> for &'a FpVar<F>
Source§impl<F: PrimeField> Sub<F> for FpVar<F>
impl<F: PrimeField> Sub<F> for FpVar<F>
Source§impl<'a, F: PrimeField> Sub for &'a FpVar<F>
impl<'a, F: PrimeField> Sub for &'a FpVar<F>
Source§impl<F: PrimeField> Sub for FpVar<F>
impl<F: PrimeField> Sub for FpVar<F>
Source§impl<'a, F: PrimeField> SubAssign<&'a FpVar<F>> for FpVar<F>
impl<'a, F: PrimeField> SubAssign<&'a FpVar<F>> for FpVar<F>
Source§fn sub_assign(&mut self, other: &'a FpVar<F>)
fn sub_assign(&mut self, other: &'a FpVar<F>)
-=
operation. Read moreSource§impl<F: PrimeField> SubAssign<F> for FpVar<F>
impl<F: PrimeField> SubAssign<F> for FpVar<F>
Source§fn sub_assign(&mut self, other: F)
fn sub_assign(&mut self, other: F)
-=
operation. Read moreSource§impl<F: PrimeField> SubAssign for FpVar<F>
impl<F: PrimeField> SubAssign for FpVar<F>
Source§fn sub_assign(&mut self, other: FpVar<F>)
fn sub_assign(&mut self, other: FpVar<F>)
-=
operation. Read moreSource§impl<'a, F: PrimeField> Sum for FpVar<F>
impl<'a, F: PrimeField> Sum for FpVar<F>
Source§impl<F: PrimeField> ThreeBitCondNegLookupGadget<F> for FpVar<F>
impl<F: PrimeField> ThreeBitCondNegLookupGadget<F> for FpVar<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 FpVar<F>
impl<F: PrimeField> ToBitsGadget<F> for FpVar<F>
Source§fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
self
. Read moreSource§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 FpVar<F>
impl<F: PrimeField> ToBytesGadget<F> for FpVar<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.
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 FpVar<F>
impl<F: PrimeField> ToConstraintFieldGadget<F> for FpVar<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 FpVar<F>
impl<F: PrimeField> TwoBitLookupGadget<F> for FpVar<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 moreimpl<'a, F: PrimeField> FieldOpsBounds<'a, F, FpVar<F>> for &'a FpVar<F>
impl<'a, F: PrimeField> FieldOpsBounds<'a, F, FpVar<F>> for FpVar<F>
Auto Trait Implementations§
impl<F> Freeze for FpVar<F>where
F: Freeze,
impl<F> !RefUnwindSafe for FpVar<F>
impl<F> !Send for FpVar<F>
impl<F> !Sync for FpVar<F>
impl<F> Unpin for FpVar<F>where
F: Unpin,
impl<F> !UnwindSafe for FpVar<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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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