pub struct UInt<const N: usize, T: PrimUInt, F: Field> { /* private fields */ }
Expand description
This struct represent an unsigned N
bit integer as a sequence of N
Boolean
s.
Implementations§
Source§impl<F: Field> UInt<8, u8, F>
impl<F: Field> UInt<8, u8, F>
Sourcepub fn new_input_vec(
cs: impl Into<Namespace<F>>,
values: &[u8],
) -> Result<Vec<Self>, SynthesisError>where
F: PrimeField,
pub fn new_input_vec(
cs: impl Into<Namespace<F>>,
values: &[u8],
) -> Result<Vec<Self>, SynthesisError>where
F: PrimeField,
Allocates a slice of u8
’s as public inputs by first packing them into
elements of F
, (thus reducing the number of input allocations),
allocating these elements as public inputs, and then converting
these field variables FpVar<F>
variables back into bytes.
From a user perspective, this trade-off adds constraints, but improves verifier time and verification key size.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let two = UInt8::new_witness(cs.clone(), || Ok(2))?;
let var = vec![two.clone(); 32];
let c = UInt8::new_input_vec(cs.clone(), &[2; 32])?;
var.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F>
Sourcepub fn saturating_add_in_place(&mut self, other: &Self)
pub fn saturating_add_in_place(&mut self, other: &Self)
Compute *self = self.wrapping_add(other)
.
Sourcepub fn saturating_add(&self, other: &Self) -> Self
pub fn saturating_add(&self, other: &Self) -> Self
Compute self.wrapping_add(other)
.
Sourcepub fn saturating_add_many(operands: &[Self]) -> Result<Self, SynthesisError>where
F: PrimeField,
pub fn saturating_add_many(operands: &[Self]) -> Result<Self, SynthesisError>where
F: PrimeField,
Perform wrapping addition of operands
.
Computes operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...
.
The user must ensure that overflow does not occur.
Source§impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F>
Sourcepub fn wrapping_add_in_place(&mut self, other: &Self)
pub fn wrapping_add_in_place(&mut self, other: &Self)
Compute *self = self.wrapping_add(other)
.
Sourcepub fn wrapping_add(&self, other: &Self) -> Self
pub fn wrapping_add(&self, other: &Self) -> Self
Compute self.wrapping_add(other)
.
Sourcepub fn wrapping_add_many(operands: &[Self]) -> Result<Self, SynthesisError>where
F: PrimeField,
pub fn wrapping_add_many(operands: &[Self]) -> Result<Self, SynthesisError>where
F: PrimeField,
Perform wrapping addition of operands
.
Computes operands[0].wrapping_add(operands[1]).wrapping_add(operands[2])...
.
The user must ensure that overflow does not occur.
Source§impl<const N: usize, F: Field, T: PrimUInt> UInt<N, T, F>
impl<const N: usize, F: Field, T: PrimUInt> UInt<N, T, F>
Sourcepub fn to_fp(&self) -> Result<FpVar<F>, SynthesisError>where
F: PrimeField,
pub fn to_fp(&self) -> Result<FpVar<F>, SynthesisError>where
F: PrimeField,
Converts self
into a field element. The elements comprising self
are
interpreted as a little-endian bit order representation of a field element.
§Panics
Assumes that N
is equal to at most the number of bits in F::MODULUS_BIT_SIZE - 1
, and panics otherwise.
Sourcepub fn from_fp(other: &FpVar<F>) -> Result<(Self, FpVar<F>), SynthesisError>where
F: PrimeField,
pub fn from_fp(other: &FpVar<F>) -> Result<(Self, FpVar<F>), SynthesisError>where
F: PrimeField,
Converts a field element into its little-endian bit order representation.
§Panics
Assumes that N
is at most the number of bits in F::MODULUS_BIT_SIZE - 1
, and panics otherwise.
Sourcepub fn from_bits_le(bits: &[Boolean<F>]) -> Self
pub fn from_bits_le(bits: &[Boolean<F>]) -> Self
Converts a little-endian byte order representation of bits into a
UInt
.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let var = UInt8::new_witness(cs.clone(), || Ok(128))?;
let f = Boolean::FALSE;
let t = Boolean::TRUE;
// Construct [0, 0, 0, 0, 0, 0, 0, 1]
let mut bits = vec![f.clone(); 7];
bits.push(t);
let mut c = UInt8::from_bits_le(&bits);
var.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn from_bytes_be(bytes: &[UInt8<F>]) -> Result<Self, SynthesisError>
pub fn from_bytes_be(bytes: &[UInt8<F>]) -> Result<Self, SynthesisError>
Converts a big-endian list of bytes into a UInt
.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let var = UInt16::new_witness(cs.clone(), || Ok(2 * (u8::MAX as u16)))?;
// Construct u8::MAX * 2
let bytes = UInt8::constant_vec(&(2 * (u8::MAX as u16)).to_be_bytes());
let c = UInt16::from_bytes_be(&bytes)?;
var.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn from_bytes_le(bytes: &[UInt8<F>]) -> Result<Self, SynthesisError>
pub fn from_bytes_le(bytes: &[UInt8<F>]) -> Result<Self, SynthesisError>
Converts a little-endian byte order list of bytes into a UInt
.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let var = UInt16::new_witness(cs.clone(), || Ok(2 * (u8::MAX as u16)))?;
// Construct u8::MAX * 2
let bytes = UInt8::constant_vec(&(2 * (u8::MAX as u16)).to_le_bytes());
let c = UInt16::from_bytes_le(&bytes)?;
var.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
pub fn to_bytes_be(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
Source§impl<const N: usize, T: PrimUInt, ConstraintF: Field> UInt<N, T, ConstraintF>
impl<const N: usize, T: PrimUInt, ConstraintF: Field> UInt<N, T, ConstraintF>
Sourcepub fn rotate_right(&self, by: usize) -> Self
pub fn rotate_right(&self, by: usize) -> Self
Rotates self
to the right by by
steps, wrapping around.
§Examples
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt32::new_witness(cs.clone(), || Ok(0xb301u32))?;
let b = UInt32::new_witness(cs.clone(), || Ok(0x10000b3))?;
a.rotate_right(8).enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn rotate_right_in_place(&mut self, by: usize)
pub fn rotate_right_in_place(&mut self, by: usize)
Rotates self
to the right in place by by
steps, wrapping around.
§Examples
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt32::new_witness(cs.clone(), || Ok(0xb301u32))?;
let b = UInt32::new_witness(cs.clone(), || Ok(0x10000b3))?;
a.rotate_right_in_place(8);
a.enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn rotate_left(&self, by: usize) -> Self
pub fn rotate_left(&self, by: usize) -> Self
Rotates self
to the left by by
steps, wrapping around.
§Examples
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt32::new_witness(cs.clone(), || Ok(0x10000b3))?;
let b = UInt32::new_witness(cs.clone(), || Ok(0xb301u32))?;
a.rotate_left(8).enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn rotate_left_in_place(&mut self, by: usize)
pub fn rotate_left_in_place(&mut self, by: usize)
Rotates self
to the left in place by by
steps, wrapping around.
§Examples
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt32::new_witness(cs.clone(), || Ok(0x10000b3))?;
let b = UInt32::new_witness(cs.clone(), || Ok(0xb301u32))?;
a.rotate_left_in_place(8);
a.enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: Field> UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> UInt<N, T, F>
pub const MAX: Self = _
Sourcepub fn constant(value: T) -> Self
pub fn constant(value: T) -> Self
Construct a constant UInt
from the native unsigned integer type.
This does not create new variables or constraints.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let var = UInt8::new_witness(cs.clone(), || Ok(2))?;
let constant = UInt8::constant(2);
var.enforce_equal(&constant)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn constant_vec(values: &[T]) -> Vec<Self>
pub fn constant_vec(values: &[T]) -> Vec<Self>
Construct a constant vector of UInt
from a vector of the native type
This does not create any new variables or constraints.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let var = vec![UInt8::new_witness(cs.clone(), || Ok(2))?];
let constant = UInt8::constant_vec(&[2]);
var.enforce_equal(&constant)?;
assert!(cs.is_satisfied().unwrap());
Sourcepub fn new_witness_vec(
cs: impl Into<Namespace<F>>,
values: &[impl Into<Option<T>> + Copy],
) -> Result<Vec<Self>, SynthesisError>
pub fn new_witness_vec( cs: impl Into<Namespace<F>>, values: &[impl Into<Option<T>> + Copy], ) -> Result<Vec<Self>, SynthesisError>
Allocates a slice of uN
’s as private witnesses.
Trait Implementations§
Source§impl<const N: usize, T: PrimUInt, ConstraintF: Field> AllocVar<T, ConstraintF> for UInt<N, T, ConstraintF>
impl<const N: usize, T: PrimUInt, ConstraintF: Field> AllocVar<T, ConstraintF> for UInt<N, T, ConstraintF>
Source§fn new_variable<S: Borrow<T>>(
cs: impl Into<Namespace<ConstraintF>>,
f: impl FnOnce() -> Result<S, SynthesisError>,
mode: AllocationMode,
) -> Result<Self, SynthesisError>
fn new_variable<S: Borrow<T>>( cs: impl Into<Namespace<ConstraintF>>, f: impl FnOnce() -> Result<S, 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§fn new_variable_with_inferred_mode<T: Borrow<V>>(
cs: impl Into<Namespace<F>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
) -> Result<Self, SynthesisError>
fn new_variable_with_inferred_mode<T: Borrow<V>>( cs: impl Into<Namespace<F>>, f: impl FnOnce() -> Result<T, SynthesisError>, ) -> Result<Self, SynthesisError>
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 moreSource§impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a UInt<N, T, F>> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a UInt<N, T, F>> for UInt<N, T, F>
Source§fn bitand(self, other: &Self) -> Self::Output
fn bitand(self, other: &Self) -> Self::Output
Outputs self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
(a & &b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<UInt<N, T, F>> for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<UInt<N, T, F>> for &'a UInt<N, T, F>
Source§fn bitand(self, other: UInt<N, T, F>) -> Self::Output
fn bitand(self, other: UInt<N, T, F>) -> Self::Output
Outputs self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
(a & &b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for &'a UInt<N, T, F>
Source§fn bitand(self, other: Self) -> Self::Output
fn bitand(self, other: Self) -> Self::Output
Outputs self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
(a & &b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: Field> BitAnd for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> BitAnd for UInt<N, T, F>
Source§fn bitand(self, other: Self) -> Self::Output
fn bitand(self, other: Self) -> Self::Output
Outputs self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
(a & &b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a T> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a T> for UInt<N, T, F>
Source§fn bitand_assign(&mut self, other: &'a T)
fn bitand_assign(&mut self, other: &'a T)
&=
operation. Read moreSource§impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
Source§fn bitand_assign(&mut self, other: &'a Self)
fn bitand_assign(&mut self, other: &'a Self)
Sets self = self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
a &= &b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: Field> BitAndAssign<T> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> BitAndAssign<T> for UInt<N, T, F>
Source§fn bitand_assign(&mut self, other: T)
fn bitand_assign(&mut self, other: T)
&=
operation. Read moreSource§impl<const N: usize, T: PrimUInt, F: Field> BitAndAssign for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> BitAndAssign for UInt<N, T, F>
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
Sets self = self & other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 & 17))?;
a &= &b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a UInt<N, T, F>> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a UInt<N, T, F>> for UInt<N, T, F>
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<UInt<N, T, F>> for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<UInt<N, T, F>> for &'a UInt<N, T, F>
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt<N, T, F>
Source§fn bitor(self, other: Self) -> Self::Output
fn bitor(self, other: Self) -> Self::Output
Output self | other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 | 17))?;
(a | b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<&'a T> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<&'a T> for UInt<N, T, F>
Source§fn bitor_assign(&mut self, other: &'a T)
fn bitor_assign(&mut self, other: &'a T)
|=
operation. Read moreSource§impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
Source§fn bitor_assign(&mut self, other: &'a Self)
fn bitor_assign(&mut self, other: &'a Self)
|=
operation. Read moreSource§impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<T> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<T> for UInt<N, T, F>
Source§fn bitor_assign(&mut self, other: T)
fn bitor_assign(&mut self, other: T)
|=
operation. Read moreSource§impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign for UInt<N, T, F>
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
Sets self = self | other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(16 | 17))?;
a |= b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt<N, T, F>
Source§fn bitxor(self, other: Self) -> Self::Output
fn bitxor(self, other: Self) -> Self::Output
Outputs self ^ other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(1))?;
(a ^ &b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a T> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a T> for UInt<N, T, F>
Source§fn bitxor_assign(&mut self, other: &'a T)
fn bitxor_assign(&mut self, other: &'a T)
^=
operation. Read moreSource§impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a UInt<N, T, F>> for UInt<N, T, F>
Source§fn bitxor_assign(&mut self, other: &'a Self)
fn bitxor_assign(&mut self, other: &'a Self)
^=
operation. Read moreSource§impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign<T> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign<T> for UInt<N, T, F>
Source§fn bitxor_assign(&mut self, other: T)
fn bitxor_assign(&mut self, other: T)
^=
operation. Read moreSource§impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign for UInt<N, T, F>
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
Sets self = self ^ other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = UInt8::new_witness(cs.clone(), || Ok(17))?;
let c = UInt8::new_witness(cs.clone(), || Ok(1))?;
a ^= b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, ConstraintF: PrimeField> CondSelectGadget<ConstraintF> for UInt<N, T, ConstraintF>
impl<const N: usize, T: PrimUInt, ConstraintF: PrimeField> CondSelectGadget<ConstraintF> for UInt<N, T, ConstraintF>
Source§fn conditionally_select(
cond: &Boolean<ConstraintF>,
true_value: &Self,
false_value: &Self,
) -> Result<Self, SynthesisError>
fn conditionally_select( cond: &Boolean<ConstraintF>, true_value: &Self, false_value: &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<const N: usize, T: PrimUInt, ConstraintF: PrimeField> EqGadget<ConstraintF> for UInt<N, T, ConstraintF>
impl<const N: usize, T: PrimUInt, ConstraintF: PrimeField> EqGadget<ConstraintF> for UInt<N, T, ConstraintF>
Source§fn is_eq(&self, other: &Self) -> Result<Boolean<ConstraintF>, SynthesisError>
fn is_eq(&self, other: &Self) -> Result<Boolean<ConstraintF>, SynthesisError>
Boolean
value representing whether self.value() == other.value()
.Source§fn conditional_enforce_equal(
&self,
other: &Self,
condition: &Boolean<ConstraintF>,
) -> Result<(), SynthesisError>
fn conditional_enforce_equal( &self, other: &Self, condition: &Boolean<ConstraintF>, ) -> Result<(), SynthesisError>
should_enforce == true
, enforce that self
and other
are equal;
else, enforce a vacuously true statement. Read moreSource§fn conditional_enforce_not_equal(
&self,
other: &Self,
condition: &Boolean<ConstraintF>,
) -> Result<(), SynthesisError>
fn conditional_enforce_not_equal( &self, other: &Self, condition: &Boolean<ConstraintF>, ) -> Result<(), SynthesisError>
should_enforce == true
, enforce that self
and other
are not
equal; else, enforce a vacuously true statement. Read moreSource§fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>
fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>
Source§fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>
fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt<N, T, F>
Source§fn not(self) -> Self::Output
fn not(self) -> Self::Output
Outputs !self
.
If self
is a constant, then this method does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(2))?;
let b = UInt8::new_witness(cs.clone(), || Ok(!2))?;
(!a).enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt<N, T, F>
Source§fn not(self) -> Self::Output
fn not(self) -> Self::Output
Outputs !self
.
If self
is a constant, then this method does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(2))?;
let b = UInt8::new_witness(cs.clone(), || Ok(!2))?;
(!a).enforce_equal(&b)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl<T2> for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl<T2> for &'a UInt<N, T, F>
Source§impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl<T2> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl<T2> for UInt<N, T, F>
Source§fn shl(self, other: T2) -> Self::Output
fn shl(self, other: T2) -> Self::Output
Output self << other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = 1u8;
let c = UInt8::new_witness(cs.clone(), || Ok(16 << 1))?;
(a << b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> ShlAssign<T2> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> ShlAssign<T2> for UInt<N, T, F>
Source§fn shl_assign(&mut self, other: T2)
fn shl_assign(&mut self, other: T2)
Sets self = self << other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = 1u8;
let c = UInt8::new_witness(cs.clone(), || Ok(16 << 1))?;
a <<= b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shr<T2> for &'a UInt<N, T, F>
impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shr<T2> for &'a UInt<N, T, F>
Source§impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shr<T2> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shr<T2> for UInt<N, T, F>
Source§fn shr(self, other: T2) -> Self::Output
fn shr(self, other: T2) -> Self::Output
Output self >> other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = 1u8;
let c = UInt8::new_witness(cs.clone(), || Ok(16 >> 1))?;
(a >> b).enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> ShrAssign<T2> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> ShrAssign<T2> for UInt<N, T, F>
Source§fn shr_assign(&mut self, other: T2)
fn shr_assign(&mut self, other: T2)
Sets self = self >> other
.
If at least one of self
and other
are constants, then this method
does not create any constraints or variables.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let mut a = UInt8::new_witness(cs.clone(), || Ok(16))?;
let b = 1u8;
let c = UInt8::new_witness(cs.clone(), || Ok(16 >> 1))?;
a >>= b;
a.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());
Source§impl<const N: usize, T: PrimUInt, F: Field> ToBitsGadget<F> for UInt<N, T, F>
impl<const N: usize, T: PrimUInt, F: Field> ToBitsGadget<F> for UInt<N, T, F>
Source§fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>
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<const N: usize, T: PrimUInt, ConstraintF: Field> ToBytesGadget<ConstraintF> for UInt<N, T, ConstraintF>
impl<const N: usize, T: PrimUInt, ConstraintF: Field> ToBytesGadget<ConstraintF> for UInt<N, T, ConstraintF>
Source§fn to_bytes_le(&self) -> Result<Vec<UInt8<ConstraintF>>, SynthesisError>
fn to_bytes_le(&self) -> Result<Vec<UInt8<ConstraintF>>, SynthesisError>
self
. Read moreSource§fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>
self
. Read moreAuto Trait Implementations§
impl<const N: usize, T, F> Freeze for UInt<N, T, F>where
T: Freeze,
impl<const N: usize, T, F> !RefUnwindSafe for UInt<N, T, F>
impl<const N: usize, T, F> !Send for UInt<N, T, F>
impl<const N: usize, T, F> !Sync for UInt<N, T, F>
impl<const N: usize, T, F> Unpin for UInt<N, T, F>where
T: Unpin,
impl<const N: usize, T, F> !UnwindSafe for UInt<N, T, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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