Skip to main content

AllocatedFp

Struct AllocatedFp 

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

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

Source

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>

Source

pub fn from(other: Boolean<F>) -> Self

Constructs Self from a Boolean: if other is false, this outputs zero, else it outputs one.

Source

pub fn value(&self) -> Result<F, SynthesisError>

Returns the value assigned to self in the underlying constraint system (if a value was assigned).

Source

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

Outputs self + other.

This does not create any constraints.

Source

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.

Source

pub fn linear_combination<B1, B2, I1>(this: I1, other: &[B2]) -> Option<Self>
where B1: Borrow<F>, B2: Borrow<Self>, I1: IntoIterator<Item = B1, IntoIter: Clone>,

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.

Source

pub fn inner_product<B1, B2, I1, I2>(this: I1, other: I2) -> Option<Self>
where B1: Borrow<Self>, B2: Borrow<Self>, I1: IntoIterator<Item = B1>, I2: IntoIterator<Item = B2>,

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.

Source

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

Outputs self - other.

This does not create any constraints.

Source

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

Outputs self * other.

This requires one constraint.

Source

pub fn add_constant(&self, other: F) -> Self

Output self + other

This does not create any constraints.

Source

pub fn sub_constant(&self, other: F) -> Self

Output self - other

This does not create any constraints.

Source

pub fn mul_constant(&self, other: F) -> Self

Output self * other

This does not create any constraints.

Source

pub fn double(&self) -> Result<Self, SynthesisError>

Output self + self

This does not create any constraints.

Source

pub fn negate(&self) -> Self

Output -self

This does not create any constraints.

Source

pub fn negate_in_place(&mut self) -> &mut Self

Sets self = -self

This does not create any constraints.

Source

pub fn square(&self) -> Result<Self, SynthesisError>

Outputs self * self

This requires one constraint.

Source

pub fn inverse(&self) -> Result<Self, SynthesisError>

Outputs result such that result * self = 1.

This requires one constraint.

Source

pub fn frobenius_map(&self, _: usize) -> Result<Self, SynthesisError>

This is a no-op for prime fields.

Source

pub fn mul_equals( &self, other: &Self, result: &Self, ) -> Result<(), SynthesisError>

Enforces that self * other = result.

This requires one constraint.

Source

pub fn square_equals(&self, result: &Self) -> Result<(), SynthesisError>

Enforces that self * self = result.

This requires one constraint.

Source

pub fn is_eq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>

Outputs the bit self == other.

This requires two constraints.

Source

pub fn is_neq(&self, other: &Self) -> Result<Boolean<F>, SynthesisError>

Outputs the bit self != other.

This requires two constraints.

Source

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.

Source

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>

Source§

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

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<F: Clone + PrimeField> Clone for AllocatedFp<F>

Source§

fn clone(&self) -> AllocatedFp<F>

Returns a duplicate 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<F: PrimeField> CondSelectGadget<F> for AllocatedFp<F>

Source§

fn conditionally_select( cond: &Boolean<F>, true_val: &Self, false_val: &Self, ) -> Result<Self, SynthesisError>

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<F: Debug + PrimeField> Debug for AllocatedFp<F>

Source§

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

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

impl<F: PrimeField> From<AllocatedFp<F>> for FpVar<F>

Source§

fn from(other: AllocatedFp<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: PrimeField> ThreeBitCondNegLookupGadget<F> for AllocatedFp<F>

Source§

type TableConstant = F

The type of values being looked up.
Source§

fn three_bit_cond_neg_lookup( b: &[Boolean<F>], b0b1: &Boolean<F>, c: &[Self::TableConstant], ) -> Result<Self, SynthesisError>

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<F: PrimeField> ToBitsGadget<F> for AllocatedFp<F>



Source§

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>

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<F: PrimeField> ToBytesGadget<F> for AllocatedFp<F>

Source§

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>

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

impl<F: PrimeField> ToConstraintFieldGadget<F> for AllocatedFp<F>

Source§

fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError>

Converts 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.

Source§

type TableConstant = F

The type of values being looked up.
Source§

fn two_bit_lookup( b: &[Boolean<F>], c: &[Self::TableConstant], ) -> Result<Self, SynthesisError>

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<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> 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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