pub struct AllocatedNonNativeFieldVar<TargetField: PrimeField, BaseField: PrimeField> {
pub limbs: Vec<FpGadget<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
limbs: Vec<FpGadget<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
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> AllocatedNonNativeFieldVar<TargetField, BaseField>
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) -> Result<TargetField, SynthesisError>
pub fn value(&self) -> Result<TargetField, SynthesisError>
Obtain the value of a nonnative field element
sourcepub fn constant<CS: ConstraintSystem<BaseField>>(
cs: &mut CS,
value: TargetField
) -> Result<Self, SynthesisError>
pub fn constant<CS: ConstraintSystem<BaseField>>(
cs: &mut CS,
value: TargetField
) -> Result<Self, SynthesisError>
Obtain the nonnative field element of a constant value
sourcepub fn one<CS: ConstraintSystem<BaseField>>(
cs: &mut CS
) -> Result<Self, SynthesisError>
pub fn one<CS: ConstraintSystem<BaseField>>(
cs: &mut CS
) -> Result<Self, SynthesisError>
Obtain the nonnative field element of one
sourcepub fn zero<CS: ConstraintSystem<BaseField>>(
cs: &mut CS
) -> Result<Self, SynthesisError>
pub fn zero<CS: ConstraintSystem<BaseField>>(
cs: &mut CS
) -> Result<Self, SynthesisError>
Obtain the nonnative field element of zero
sourcepub fn add<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
pub fn add<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
Add a nonnative field element
sourcepub fn add_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
pub fn add_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
Add a constant
sourcepub fn sub_without_reduce<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
pub fn sub_without_reduce<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
Subtract a nonnative field element, without the final reduction step
sourcepub fn sub<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
pub fn sub<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
Subtract a nonnative field element
sourcepub fn sub_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
pub fn sub_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
Subtract a constant
sourcepub fn mul<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
pub fn mul<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<Self, SynthesisError>
Multiply a nonnative field element
sourcepub fn mul_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
pub fn mul_constant<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &TargetField
) -> Result<Self, SynthesisError>
Multiply a constant
sourcepub fn negate<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS
) -> Result<Self, SynthesisError>
pub fn negate<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS
) -> Result<Self, SynthesisError>
Compute the negate of a nonnative field element
sourcepub fn inverse<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS
) -> Result<Self, SynthesisError>
pub fn inverse<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS
) -> Result<Self, SynthesisError>
Compute the inverse of a nonnative field element
sourcepub fn get_limbs_representations(
elem: &TargetField,
optimization_type: OptimizationType
) -> Result<Vec<BaseField>, SynthesisError>
pub fn get_limbs_representations(
elem: &TargetField,
optimization_type: OptimizationType
) -> Result<Vec<BaseField>, SynthesisError>
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>::BigInteger,
optimization_type: OptimizationType
) -> Result<Vec<BaseField>, SynthesisError>
pub fn get_limbs_representations_from_big_integer(
elem: &<TargetField as PrimeField>::BigInteger,
optimization_type: OptimizationType
) -> Result<Vec<BaseField>, SynthesisError>
Obtain the limbs directly from a big int
sourcepub fn mul_without_reduce<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>, SynthesisError>
pub fn mul_without_reduce<CS: ConstraintSystem<BaseField>>(
&self,
cs: &mut CS,
other: &Self
) -> Result<AllocatedNonNativeFieldMulResultVar<TargetField, BaseField>, SynthesisError>
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
.
Trait Implementations
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> AllocGadget<TargetField, BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> AllocGadget<TargetField, BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
fn alloc_constant<FN, T, CS: ConstraintSystem<BaseField>>(
cs: CS,
value_gen: FN
) -> Result<Self, SynthesisError> where
FN: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<TargetField>,
fn alloc<FN, T, CS: ConstraintSystem<BaseField>>(
cs: CS,
value_gen: FN
) -> Result<Self, SynthesisError> where
FN: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<TargetField>,
fn alloc_input<FN, T, CS: ConstraintSystem<BaseField>>(
cs: CS,
value_gen: FN
) -> Result<Self, SynthesisError> where
FN: FnOnce() -> Result<T, SynthesisError>,
T: Borrow<TargetField>,
fn alloc_checked<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<V>, CS: ConstraintSystem<F>>(
cs: CS,
f: Fn
) -> Result<Self, SynthesisError>
fn alloc_input_checked<Fn: FnOnce() -> Result<T, SynthesisError>, T: Borrow<V>, CS: ConstraintSystem<F>>(
cs: CS,
f: Fn
) -> Result<Self, SynthesisError>
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> Clone for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> Clone for AllocatedNonNativeFieldVar<TargetField, BaseField>
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> CondSelectGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> CondSelectGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
fn conditionally_select<CS: ConstraintSystem<BaseField>>(
cs: CS,
cond: &Boolean,
first: &Self,
second: &Self
) -> Result<Self, SynthesisError>
fn cost() -> usize
sourceimpl<TargetField: Debug + PrimeField, BaseField: Debug + PrimeField> Debug for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: Debug + PrimeField, BaseField: Debug + PrimeField> Debug for AllocatedNonNativeFieldVar<TargetField, BaseField>
sourceimpl<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>
sourcefn from(other: AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
fn from(other: AllocatedNonNativeFieldVar<TargetField, BaseField>) -> Self
Performs the conversion.
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> ThreeBitCondNegLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ThreeBitCondNegLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
type TableConstant = TargetField
fn three_bit_cond_neg_lookup<CS: ConstraintSystem<BaseField>>(
cs: CS,
bits: &[Boolean],
b0b1: &Boolean,
constants: &[Self::TableConstant]
) -> Result<Self, SynthesisError>
fn cost() -> usize
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> ToBitsBEGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToBitsBEGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
fn to_bits_be<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
sourcefn to_bits_be_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
fn to_bits_be_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> ToBitsLEGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToBitsLEGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
fn to_bits_le<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
sourcefn to_bits_le_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
fn to_bits_le_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<Boolean>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> ToBytesGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> ToBytesGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
fn to_bytes<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
sourcefn to_bytes_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
fn to_bytes_strict<CS: ConstraintSystem<BaseField>>(
&self,
cs: CS
) -> Result<Vec<UInt8>, SynthesisError>
Additionally checks if the produced list of booleans is ‘valid’.
sourceimpl<TargetField: PrimeField, BaseField: PrimeField> TwoBitLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField: PrimeField, BaseField: PrimeField> TwoBitLookupGadget<BaseField> for AllocatedNonNativeFieldVar<TargetField, BaseField>
type TableConstant = TargetField
fn two_bit_lookup<CS: ConstraintSystem<BaseField>>(
cs: CS,
bits: &[Boolean],
constants: &[Self::TableConstant]
) -> Result<Self, SynthesisError>
fn cost() -> usize
Auto Trait Implementations
impl<TargetField, BaseField> RefUnwindSafe for AllocatedNonNativeFieldVar<TargetField, BaseField> where
BaseField: RefUnwindSafe,
TargetField: RefUnwindSafe,
impl<TargetField, BaseField> Send for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField, BaseField> Sync for AllocatedNonNativeFieldVar<TargetField, BaseField>
impl<TargetField, BaseField> Unpin for AllocatedNonNativeFieldVar<TargetField, BaseField> where
BaseField: Unpin,
TargetField: Unpin,
impl<TargetField, BaseField> UnwindSafe for AllocatedNonNativeFieldVar<TargetField, BaseField> where
BaseField: UnwindSafe,
TargetField: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more