ark_r1cs_std::fields::emulated_fp

Struct AllocatedEmulatedFpVar

Source
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>

Source

pub fn cs(&self) -> ConstraintSystemRef<BaseF>

Return cs

Source

pub fn limbs_to_value( limbs: Vec<BaseF>, optimization_type: OptimizationType, ) -> TargetF

Obtain the value of limbs

Source

pub fn value(&self) -> R1CSResult<TargetF>

Obtain the value of a emulated field element

Source

pub fn constant( cs: ConstraintSystemRef<BaseF>, value: TargetF, ) -> R1CSResult<Self>

Obtain the emulated field element of a constant value

Source

pub fn one(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>

Obtain the emulated field element of one

Source

pub fn zero(cs: ConstraintSystemRef<BaseF>) -> R1CSResult<Self>

Obtain the emulated field element of zero

Source

pub fn add(&self, other: &Self) -> R1CSResult<Self>

Add a emulated field element

Source

pub fn add_constant(&self, other: &TargetF) -> R1CSResult<Self>

Add a constant

Source

pub fn sub_without_reduce(&self, other: &Self) -> R1CSResult<Self>

Subtract a emulated field element, without the final reduction step

Source

pub fn sub(&self, other: &Self) -> R1CSResult<Self>

Subtract a emulated field element

Source

pub fn sub_constant(&self, other: &TargetF) -> R1CSResult<Self>

Subtract a constant

Source

pub fn mul(&self, other: &Self) -> R1CSResult<Self>

Multiply a emulated field element

Source

pub fn mul_constant(&self, other: &TargetF) -> R1CSResult<Self>

Multiply a constant

Source

pub fn negate(&self) -> R1CSResult<Self>

Compute the negate of a emulated field element

Source

pub fn inverse(&self) -> R1CSResult<Self>

Compute the inverse of a emulated field element

Source

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

Source

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

Source

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.

Source

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>

Source§

fn new_variable<T: Borrow<TargetF>>( cs: impl Into<Namespace<BaseF>>, f: impl FnOnce() -> Result<T, SynthesisError>, mode: AllocationMode, ) -> R1CSResult<Self>

Allocates a new variable of type 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>

Allocates a new constant of type Self in the ConstraintSystem cs. Read more
Source§

fn new_input<T: Borrow<V>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, ) -> Result<Self, SynthesisError>

Allocates a new public input of type 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>

Allocates a new private witness of type 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>

Allocates a new constant or private witness of type 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 more
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> Clone for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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>

If cond == &Boolean::TRUE, then this returns true_value; else, returns false_value. Read more
Source§

fn conditionally_select_power_of_two_vector( position: &[Boolean<ConstraintF>], values: &[Self], ) -> Result<Self, SynthesisError>

Returns an element of values whose index in represented by position. position is an array of boolean that represents an unsigned integer in big endian order. Read more
Source§

impl<TargetF: Debug + PrimeField, BaseF: Debug + PrimeField> Debug for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> From<&AllocatedEmulatedFpVar<TargetF, BaseF>> for AllocatedMulResultVar<TargetF, BaseF>

Source§

fn from(src: &AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self

Converts to this type from the input type.
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> From<AllocatedEmulatedFpVar<TargetF, BaseF>> for EmulatedFpVar<TargetF, BaseF>

Source§

fn from(other: AllocatedEmulatedFpVar<TargetF, BaseF>) -> Self

Converts to this type from the input type.
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> ThreeBitCondNegLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

type TableConstant = TargetF

The type of values being looked up.
Source§

fn three_bit_cond_neg_lookup( bits: &[Boolean<BaseF>], b0b1: &Boolean<BaseF>, constants: &[Self::TableConstant], ) -> R1CSResult<Self>

Interprets the slice 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 more
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> ToBitsGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

fn to_bits_le(&self) -> R1CSResult<Vec<Boolean<BaseF>>>

Outputs the canonical little-endian bit-wise representation of self. Read more
Source§

fn to_non_unique_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>

Outputs a possibly non-unique little-endian bit-wise representation of self. Read more
Source§

fn to_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>

Outputs the canonical big-endian bit-wise representation of self.
Source§

fn to_non_unique_bits_be(&self) -> Result<Vec<Boolean<F>>, SynthesisError>

Outputs a possibly non-unique big-endian bit-wise representation of self.
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> ToBytesGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

fn to_bytes_le(&self) -> R1CSResult<Vec<UInt8<BaseF>>>

Outputs a canonical, little-endian, byte decomposition of self. Read more
Source§

fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>

Outputs a possibly non-unique byte decomposition of self. Read more
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> ToConstraintFieldGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseF>>>

Converts self to FpVar<ConstraintF> variables.
Source§

impl<TargetF: PrimeField, BaseF: PrimeField> TwoBitLookupGadget<BaseF> for AllocatedEmulatedFpVar<TargetF, BaseF>

Source§

type TableConstant = TargetF

The type of values being looked up.
Source§

fn two_bit_lookup( bits: &[Boolean<BaseF>], constants: &[Self::TableConstant], ) -> R1CSResult<Self>

Interprets the slice bits as a two-bit integer b = bits[0] + (bits[1] << 1), and then outputs constants[b]. Read more

Auto 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>
where BaseF: Unpin, TargetF: Unpin,

§

impl<TargetF, BaseF> !UnwindSafe for AllocatedEmulatedFpVar<TargetF, BaseF>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more