ark_r1cs_std::uint

Struct UInt

Source
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 Booleans.

Implementations§

Source§

impl<F: Field> UInt<8, u8, F>

Source

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>

Source

pub fn saturating_add_in_place(&mut self, other: &Self)

Compute *self = self.wrapping_add(other).

Source

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

Compute self.wrapping_add(other).

Source

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>

Source

pub fn wrapping_add_in_place(&mut self, other: &Self)

Compute *self = self.wrapping_add(other).

Source

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

Compute self.wrapping_add(other).

Source

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>

Source

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.

Source

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.

Source

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());
Source

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());
Source

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());
Source

pub fn to_bytes_be(&self) -> Result<Vec<UInt8<F>>, SynthesisError>

Source§

impl<const N: usize, T: PrimUInt, ConstraintF: Field> UInt<N, T, ConstraintF>

Source

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());
Source

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());
Source

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());
Source

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>

Source

pub const MAX: Self = _

Source

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());
Source

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());
Source

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>

Source§

fn new_variable<S: Borrow<T>>( cs: impl Into<Namespace<ConstraintF>>, f: impl FnOnce() -> Result<S, 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<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: &'a T) -> Self::Output

Performs the & operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<&'a T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: &'a T) -> Self::Output

Performs the & operation. Read more
Source§

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

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§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: T) -> Self::Output

Performs the & operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd<T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: T) -> Self::Output

Performs the & operation. Read more
Source§

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

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§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitAnd for &'a UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

impl<const N: usize, T: PrimUInt, F: Field> BitAnd for UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the & operator.
Source§

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)

Performs the &= operation. Read more
Source§

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)

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>

Source§

fn bitand_assign(&mut self, other: T)

Performs the &= operation. Read more
Source§

impl<const N: usize, T: PrimUInt, F: Field> BitAndAssign for UInt<N, T, F>

Source§

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 T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: &'a T) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: &'a T) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<&'a UInt<N, T, F>> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: &Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: T) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: T) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr<UInt<N, T, F>> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: UInt<N, T, F>) -> Self::Output

Performs the | operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField> BitOr for &'a UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

impl<const N: usize, T: PrimUInt, F: PrimeField> BitOr for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Self) -> Self::Output

Performs the | operation. Read more
Source§

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)

Performs the |= operation. Read more
Source§

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)

Performs the |= operation. Read more
Source§

impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign<T> for UInt<N, T, F>

Source§

fn bitor_assign(&mut self, other: T)

Performs the |= operation. Read more
Source§

impl<const N: usize, T: PrimUInt, F: PrimeField> BitOrAssign for UInt<N, T, F>

Source§

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<&'a T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: &'a T) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: &'a T) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<&'a UInt<N, T, F>> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: &Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<T> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: T) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<T> for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: T) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor<UInt<N, T, F>> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: UInt<N, T, F>) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> BitXor for &'a UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

impl<const N: usize, T: PrimUInt, F: Field> BitXor for UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

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)

Performs the ^= operation. Read more
Source§

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)

Performs the ^= operation. Read more
Source§

impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign<T> for UInt<N, T, F>

Source§

fn bitxor_assign(&mut self, other: T)

Performs the ^= operation. Read more
Source§

impl<const N: usize, T: PrimUInt, F: Field> BitXorAssign for UInt<N, T, F>

Source§

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: Clone + PrimUInt, F: Clone + Field> Clone for UInt<N, T, F>

Source§

fn clone(&self) -> UInt<N, T, F>

Returns a copy 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<const N: usize, T: PrimUInt, F: PrimeField + From<T>> CmpGadget<F> for UInt<N, T, F>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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>

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<const N: usize, T: Debug + PrimUInt, F: Debug + Field> Debug for UInt<N, T, F>

Source§

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

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

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>

Output a Boolean value representing whether self.value() == other.value().
Source§

fn conditional_enforce_equal( &self, other: &Self, condition: &Boolean<ConstraintF>, ) -> Result<(), SynthesisError>

If should_enforce == true, enforce that self and other are equal; else, enforce a vacuously true statement. Read more
Source§

fn conditional_enforce_not_equal( &self, other: &Self, condition: &Boolean<ConstraintF>, ) -> Result<(), SynthesisError>

If should_enforce == true, enforce that self and other are not equal; else, enforce a vacuously true statement. Read more
Source§

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

Output a Boolean value representing whether self.value() != other.value(). Read more
Source§

fn enforce_equal(&self, other: &Self) -> Result<(), SynthesisError>

Enforce that self and other are equal. Read more
Source§

fn enforce_not_equal(&self, other: &Self) -> Result<(), SynthesisError>

Enforce that self and other are not equal. Read more
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> Not for &'a UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the ! operator.
Source§

impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt<N, T, F>

Source§

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§

type Output = UInt<N, T, F>

The resulting type after applying the ! operator.
Source§

impl<'a, const N: usize, T: PrimUInt, F: PrimeField, T2: PrimUInt> Shl<T2> for &'a UInt<N, T, F>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the << operator.
Source§

fn shl(self, other: T2) -> Self::Output

Performs the << operation. Read more
Source§

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

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§

type Output = UInt<N, T, F>

The resulting type after applying the << operator.
Source§

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)

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>

Source§

type Output = UInt<N, T, F>

The resulting type after applying the >> operator.
Source§

fn shr(self, other: T2) -> Self::Output

Performs the >> operation. Read more
Source§

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

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§

type Output = UInt<N, T, F>

The resulting type after applying the >> operator.
Source§

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)

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>

Source§

fn to_bits_le(&self) -> Result<Vec<Boolean<F>>, SynthesisError>

Outputs the canonical little-endian bit-wise representation of self. Read more
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<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>

Outputs a canonical, little-endian, byte decomposition of self. Read more
Source§

fn to_non_unique_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError>

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

Auto 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> 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, dst: *mut T)

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