Struct ark_r1cs_std::fields::fp::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>
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 addmany<'a, I: Iterator<Item = &'a Self>>(iter: I) -> Self
pub fn addmany<'a, I: Iterator<Item = &'a Self>>(iter: I) -> Self
Add many allocated Fp elements together.
This does not create any constraints and only creates one linear combination.
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 three 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 three 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§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>
§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(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
fn to_bytes(&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(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
fn to_non_unique_bytes(&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>
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.
§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 more