pub struct AllocatedEmulatedFpVar<TargetF: PrimeField, BaseF: PrimeField> {
pub cs: ConstraintSystemRef<BaseF>,
pub limbs: Vec<FpVar<BaseF>>,
pub num_of_additions_over_normal_form: BaseF,
pub is_in_the_normal_form: bool,
/* private fields */
}
Expand description
The allocated version of EmulatedFpVar
(introduced below)
Fields§
§cs: ConstraintSystemRef<BaseF>
Constraint system reference
limbs: Vec<FpVar<BaseF>>
The limbs, each of which is a BaseF gadget.
num_of_additions_over_normal_form: BaseF
Number of additions done over this gadget, using which the gadget decides when to reduce.
is_in_the_normal_form: bool
Whether the limb representation is the normal form (using only the bits specified in the parameters, and the representation is strictly within the range of TargetF).
Implementations§
Source§impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> AllocatedEmulatedFpVar<TargetF, BaseF>
Sourcepub fn cs(&self) -> ConstraintSystemRef<BaseF>
pub fn cs(&self) -> ConstraintSystemRef<BaseF>
Return cs
Sourcepub fn limbs_to_value(
limbs: Vec<BaseF>,
optimization_type: OptimizationType,
) -> TargetF
pub fn limbs_to_value( limbs: Vec<BaseF>, optimization_type: OptimizationType, ) -> TargetF
Obtain the value of limbs
Sourcepub fn value(&self) -> R1CSResult<TargetF>
pub fn value(&self) -> R1CSResult<TargetF>
Obtain the value of a emulated field element
Sourcepub fn constant(
cs: ConstraintSystemRef<BaseF>,
value: TargetF,
) -> R1CSResult<Self>
pub fn constant( cs: ConstraintSystemRef<BaseF>, value: TargetF, ) -> R1CSResult<Self>
Obtain the emulated field element of a constant value
Sourcepub fn one(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>
pub fn one(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>
Obtain the emulated field element of one
Sourcepub fn zero(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>
pub fn zero(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>
Obtain the emulated field element of zero
Sourcepub fn add(&self, other: &Self) -> R1CSResult<Self>
pub fn add(&self, other: &Self) -> R1CSResult<Self>
Add a emulated field element
Sourcepub fn add_constant(&self, other: &TargetF) -> R1CSResult<Self>
pub fn add_constant(&self, other: &TargetF) -> R1CSResult<Self>
Add a constant
Sourcepub fn sub_without_reduce(&self, other: &Self) -> R1CSResult<Self>
pub fn sub_without_reduce(&self, other: &Self) -> R1CSResult<Self>
Subtract a emulated field element, without the final reduction step
Sourcepub fn sub(&self, other: &Self) -> R1CSResult<Self>
pub fn sub(&self, other: &Self) -> R1CSResult<Self>
Subtract a emulated field element
Sourcepub fn sub_constant(&self, other: &TargetF) -> R1CSResult<Self>
pub fn sub_constant(&self, other: &TargetF) -> R1CSResult<Self>
Subtract a constant
Sourcepub fn mul(&self, other: &Self) -> R1CSResult<Self>
pub fn mul(&self, other: &Self) -> R1CSResult<Self>
Multiply a emulated field element
Sourcepub fn mul_constant(&self, other: &TargetF) -> R1CSResult<Self>
pub fn mul_constant(&self, other: &TargetF) -> R1CSResult<Self>
Multiply a constant
Sourcepub fn negate(&self) -> R1CSResult<Self>
pub fn negate(&self) -> R1CSResult<Self>
Compute the negate of a emulated field element
Sourcepub fn inverse(&self) -> R1CSResult<Self>
pub fn inverse(&self) -> R1CSResult<Self>
Compute the inverse of a emulated field element
Sourcepub fn get_limbs_representations(
elem: &TargetF,
optimization_type: OptimizationType,
) -> R1CSResult<Vec<BaseF>>
pub fn get_limbs_representations( elem: &TargetF, optimization_type: OptimizationType, ) -> R1CSResult<Vec<BaseF>>
Convert a TargetF
element into limbs (not constraints)
This is an internal function that would be reused by a number of other
functions
Sourcepub fn get_limbs_representations_from_big_integer(
elem: &<TargetF as PrimeField>::BigInt,
optimization_type: OptimizationType,
) -> R1CSResult<Vec<BaseF>>
pub fn get_limbs_representations_from_big_integer( elem: &<TargetF as PrimeField>::BigInt, optimization_type: OptimizationType, ) -> R1CSResult<Vec<BaseF>>
Obtain the limbs directly from a big int
Sourcepub fn mul_without_reduce(
&self,
other: &Self,
) -> R1CSResult<AllocatedMulResultVar<TargetF, BaseF>>
pub fn mul_without_reduce( &self, other: &Self, ) -> R1CSResult<AllocatedMulResultVar<TargetF, BaseF>>
for advanced use, multiply and output the intermediate representations
(without reduction) This intermediate representations can be added
with each other, and they can later be reduced back to the
EmulatedFpVar
.
Sourcepub fn new_witness_with_le_bits<T: Borrow<TargetF>>(
cs: impl Into<Namespace<BaseF>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
) -> R1CSResult<(Self, Vec<Boolean<BaseF>>)>
pub fn new_witness_with_le_bits<T: Borrow<TargetF>>( cs: impl Into<Namespace<BaseF>>, f: impl FnOnce() -> Result<T, SynthesisError>, ) -> R1CSResult<(Self, Vec<Boolean<BaseF>>)>
Allocates a new non-native field witness with value given by the
function f
. Enforces that the field element has value in [0, modulus)
,
and returns the bits of its binary representation.
The bits are in little-endian (i.e., the bit at index 0 is the LSB) and the
bit-vector is empty in non-witness allocation modes.
Trait Implementations§
Source§impl<TargetF: PrimeField, BaseF: PrimeField> AllocVar<TargetF, BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> AllocVar<TargetF, BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§fn new_variable<T: Borrow<TargetF>>(
cs: impl Into<Namespace<BaseF>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode,
) -> R1CSResult<Self>
fn new_variable<T: Borrow<TargetF>>( cs: impl Into<Namespace<BaseF>>, f: impl FnOnce() -> Result<T, SynthesisError>, mode: AllocationMode, ) -> R1CSResult<Self>
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<TargetF: PrimeField, BaseF: PrimeField> Clone for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> Clone for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§impl<TargetF: PrimeField, BaseF: PrimeField> CondSelectGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> CondSelectGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§fn conditionally_select(
cond: &Boolean<BaseF>,
true_value: &Self,
false_value: &Self,
) -> R1CSResult<Self>
fn conditionally_select( cond: &Boolean<BaseF>, true_value: &Self, false_value: &Self, ) -> R1CSResult<Self>
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<TargetF: Debug + PrimeField, BaseF: Debug + PrimeField> Debug for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: Debug + PrimeField, BaseF: Debug + PrimeField> Debug for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§impl<TargetF: PrimeField, BaseF: PrimeField> From<&AllocatedEmulatedFpVar<TargetF, BaseF>> for AllocatedMulResultVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> From<&AllocatedEmulatedFpVar<TargetF, BaseF>> for AllocatedMulResultVar<TargetF, BaseF>
Source§fn from(src: &AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self
fn from(src: &AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self
Source§impl<TargetF: PrimeField, BaseF: PrimeField> From<AllocatedEmulatedFpVar<TargetF, BaseF>> for EmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> From<AllocatedEmulatedFpVar<TargetF, BaseF>> for EmulatedFpVar<TargetF, BaseF>
Source§fn from(other: AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self
fn from(other: AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self
Source§impl<TargetF: PrimeField, BaseF: PrimeField> ThreeBitCondNegLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> ThreeBitCondNegLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§type TableConstant = TargetF
type TableConstant = TargetF
Source§fn three_bit_cond_neg_lookup(
bits: &[Boolean<BaseF>],
b0b1: &Boolean<BaseF>,
constants: &[Self::TableConstant],
) -> R1CSResult<Self>
fn three_bit_cond_neg_lookup( bits: &[Boolean<BaseF>], b0b1: &Boolean<BaseF>, constants: &[Self::TableConstant], ) -> R1CSResult<Self>
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<TargetF: PrimeField, BaseF: PrimeField> ToBitsGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> ToBitsGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§fn to_bits_le(&self) -> R1CSResult<Vec<Boolean<BaseF>>>
fn to_bits_le(&self) -> R1CSResult<Vec<Boolean<BaseF>>>
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<TargetF: PrimeField, BaseF: PrimeField> ToBytesGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> ToBytesGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§fn to_bytes_le(&self) -> R1CSResult<Vec<UInt8<BaseF>>>
fn to_bytes_le(&self) -> R1CSResult<Vec<UInt8<BaseF>>>
self
. Read moreSource§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<TargetF: PrimeField, BaseF: PrimeField> ToConstraintFieldGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> ToConstraintFieldGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseF>>>
fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseF>>>
self
to FpVar<ConstraintF>
variables.Source§impl<TargetF: PrimeField, BaseF: PrimeField> TwoBitLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF: PrimeField, BaseF: PrimeField> TwoBitLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>
Source§type TableConstant = TargetF
type TableConstant = TargetF
Source§fn two_bit_lookup(
bits: &[Boolean<BaseF>],
constants: &[Self::TableConstant],
) -> R1CSResult<Self>
fn two_bit_lookup( bits: &[Boolean<BaseF>], constants: &[Self::TableConstant], ) -> R1CSResult<Self>
bits
as a two-bit integer b = bits[0] + (bits[1] << 1)
, and then outputs constants[b]
. Read moreAuto Trait Implementations§
impl<TargetF, BaseF> Freeze for AllocatedEmulatedFpVar<TargetF, BaseF>where
BaseF: Freeze,
impl<TargetF, BaseF> !RefUnwindSafe for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF, BaseF> !Send for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF, BaseF> !Sync for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF, BaseF> Unpin for AllocatedEmulatedFpVar<TargetF, BaseF>
impl<TargetF, BaseF> !UnwindSafe for AllocatedEmulatedFpVar<TargetF, BaseF>
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