Struct ark_r1cs_std::fields::nonnative::AllocatedNonNativeFieldVar
source · pub struct AllocatedNonNativeFieldVar<TargetField: PrimeField, BaseField: PrimeField> {
pub cs: ConstraintSystemRef<BaseField>,
pub limbs: Vec<FpVar<BaseField>>,
pub num_of_additions_over_normal_form: BaseField,
pub is_in_the_normal_form: bool,
/* private fields */
}
Expand description
The allocated version of NonNativeFieldVar
(introduced below)
Fields§
§cs: ConstraintSystemRef<BaseField>
Constraint system reference
limbs: Vec<FpVar<BaseField>>
The limbs, each of which is a BaseField gadget.
num_of_additions_over_normal_form: BaseField
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 TargetField).
Implementations§
source§impl<TargetField: PrimeField, BaseField: PrimeField> AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> AllocatedNonNativeFieldVar<TargetField, BaseField>
sourcepub fn cs(&self) -> ConstraintSystemRef<BaseField>
pub fn cs(&self) -> ConstraintSystemRef<BaseField>
Return cs
sourcepub fn limbs_to_value(
limbs: Vec<BaseField>,
optimization_type: OptimizationType
) -> TargetField
pub fn limbs_to_value(
limbs: Vec<BaseField>,
optimization_type: OptimizationType
) -> TargetField
Obtain the value of limbs
sourcepub fn value(&self) -> R1CSResult<TargetField>
pub fn value(&self) -> R1CSResult<TargetField>
Obtain the value of a nonnative field element
sourcepub fn constant(
cs: ConstraintSystemRef<BaseField>,
value: TargetField
) -> R1CSResult<Self>
pub fn constant(
cs: ConstraintSystemRef<BaseField>,
value: TargetField
) -> R1CSResult<Self>
Obtain the nonnative field element of a constant value
sourcepub fn one(cs: ConstraintSystemRef<BaseField>) -> R1CSResult<Self>
pub fn one(cs: ConstraintSystemRef<BaseField>) -> R1CSResult<Self>
Obtain the nonnative field element of one
sourcepub fn zero(cs: ConstraintSystemRef<BaseField>) -> R1CSResult<Self>
pub fn zero(cs: ConstraintSystemRef<BaseField>) -> R1CSResult<Self>
Obtain the nonnative field element of zero
sourcepub fn add(&self, other: &Self) -> R1CSResult<Self>
pub fn add(&self, other: &Self) -> R1CSResult<Self>
Add a nonnative field element
sourcepub fn add_constant(&self, other: &TargetField) -> R1CSResult<Self>
pub fn add_constant(&self, other: &TargetField) -> 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 nonnative 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 nonnative field element
sourcepub fn sub_constant(&self, other: &TargetField) -> R1CSResult<Self>
pub fn sub_constant(&self, other: &TargetField) -> R1CSResult<Self>
Subtract a constant
sourcepub fn mul(&self, other: &Self) -> R1CSResult<Self>
pub fn mul(&self, other: &Self) -> R1CSResult<Self>
Multiply a nonnative field element
sourcepub fn mul_constant(&self, other: &TargetField) -> R1CSResult<Self>
pub fn mul_constant(&self, other: &TargetField) -> R1CSResult<Self>
Multiply a constant
sourcepub fn negate(&self) -> R1CSResult<Self>
pub fn negate(&self) -> R1CSResult<Self>
Compute the negate of a nonnative field element
sourcepub fn inverse(&self) -> R1CSResult<Self>
pub fn inverse(&self) -> R1CSResult<Self>
Compute the inverse of a nonnative field element
sourcepub fn get_limbs_representations(
elem: &TargetField,
optimization_type: OptimizationType
) -> R1CSResult<Vec<BaseField>>
pub fn get_limbs_representations(
elem: &TargetField,
optimization_type: OptimizationType
) -> R1CSResult<Vec<BaseField>>
Convert a TargetField
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: &<TargetField as PrimeField>::BigInt,
optimization_type: OptimizationType
) -> R1CSResult<Vec<BaseField>>
pub fn get_limbs_representations_from_big_integer(
elem: &<TargetField as PrimeField>::BigInt,
optimization_type: OptimizationType
) -> R1CSResult<Vec<BaseField>>
Obtain the limbs directly from a big int
sourcepub fn mul_without_reduce(
&self,
other: &Self
) -> R1CSResult<AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>>
pub fn mul_without_reduce(
&self,
other: &Self
) -> R1CSResult<AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>>
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
NonNativeFieldVar
.
sourcepub fn new_witness_with_le_bits<T: Borrow<TargetField>>(
cs: impl Into<Namespace<BaseField>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> R1CSResult<(Self, Vec<Boolean<BaseField>>)>
pub fn new_witness_with_le_bits<T: Borrow<TargetField>>(
cs: impl Into<Namespace<BaseField>>,
f: impl FnOnce() -> Result<T, SynthesisError>
) -> R1CSResult<(Self, Vec<Boolean<BaseField>>)>
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<TargetField: PrimeField, BaseField: PrimeField> AllocVar<TargetField, BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> AllocVar<TargetField, BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§fn new_variable<T: Borrow<TargetField>>(
cs: impl Into<Namespace<BaseField>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode
) -> R1CSResult<Self>
fn new_variable<T: Borrow<TargetField>>(
cs: impl Into<Namespace<BaseField>>,
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§impl<TargetField: PrimeField, BaseField: PrimeField> Clone for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> Clone for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§impl<TargetField: PrimeField, BaseField: PrimeField> CondSelectGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> CondSelectGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§fn conditionally_select(
cond: &Boolean<BaseField>,
true_value: &Self,
false_value: &Self
) -> R1CSResult<Self>
fn conditionally_select(
cond: &Boolean<BaseField>,
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<TargetField: Debug + PrimeField, BaseField: Debug + PrimeField> Debug for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: Debug + PrimeField, BaseField: Debug + PrimeField> Debug for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§impl<TargetField: PrimeField, BaseField: PrimeField> From<&AllocatedNonNativeFieldVar<TargetField, BaseField>> for AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> From<&AllocatedNonNativeFieldVar<TargetField, BaseField>> for AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>
source§fn from(src: &AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
fn from(src: &AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
source§impl<TargetField: PrimeField, BaseField: PrimeField> From<AllocatedNonNativeFieldVar<TargetField, BaseField>> for NonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> From<AllocatedNonNativeFieldVar<TargetField, BaseField>> for NonNativeFieldVar<TargetField, BaseField>
source§fn from(other: AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
fn from(other: AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
source§impl<TargetField: PrimeField, BaseField: PrimeField> ThreeBitCondNegLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ThreeBitCondNegLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
§type TableConstant = TargetField
type TableConstant = TargetField
source§fn three_bit_cond_neg_lookup(
bits: &[Boolean<BaseField>],
b0b1: &Boolean<BaseField>,
constants: &[Self::TableConstant]
) -> R1CSResult<Self>
fn three_bit_cond_neg_lookup(
bits: &[Boolean<BaseField>],
b0b1: &Boolean<BaseField>,
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<TargetField: PrimeField, BaseField: PrimeField> ToBitsGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToBitsGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§fn to_bits_le(&self) -> R1CSResult<Vec<Boolean<BaseField>>>
fn to_bits_le(&self) -> R1CSResult<Vec<Boolean<BaseField>>>
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<TargetField: PrimeField, BaseField: PrimeField> ToBytesGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToBytesGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§fn to_bytes(&self) -> R1CSResult<Vec<UInt8<BaseField>>>
fn to_bytes(&self) -> R1CSResult<Vec<UInt8<BaseField>>>
self
. Read moresource§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<TargetField: PrimeField, BaseField: PrimeField> ToConstraintFieldGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToConstraintFieldGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
source§fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseField>>>
fn to_constraint_field(&self) -> R1CSResult<Vec<FpVar<BaseField>>>
self
to FpVar<ConstraintF>
variables.source§impl<TargetField: PrimeField, BaseField: PrimeField> TwoBitLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> TwoBitLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
§type TableConstant = TargetField
type TableConstant = TargetField
source§fn two_bit_lookup(
bits: &[Boolean<BaseField>],
constants: &[Self::TableConstant]
) -> R1CSResult<Self>
fn two_bit_lookup(
bits: &[Boolean<BaseField>],
constants: &[Self::TableConstant]
) -> R1CSResult<Self>
bits
as a two-bit integer b = bits[0] + (bits[1] << 1)
, and then outputs constants[b]
. Read more