Struct ark_r1cs_std::bits::uint8::UInt8[][src]

pub struct UInt8<F: Field> { /* fields omitted */ }

Represents an interpretation of 8 Boolean objects as an unsigned integer.

Implementations

impl<F: Field> UInt8<F>[src]

pub fn constant_vec(values: &[u8]) -> Vec<Self>[src]

Construct a constant vector of UInt8 from a vector of u8

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

pub fn constant(value: u8) -> Self[src]

Construct a constant UInt8 from a u8

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

pub fn new_witness_vec(
    cs: impl Into<Namespace<F>>,
    values: &[impl Into<Option<u8>> + Copy]
) -> Result<Vec<Self>, SynthesisError>
[src]

Allocates a slice of u8’s as private witnesses.

pub fn new_input_vec(
    cs: impl Into<Namespace<F>>,
    values: &[u8]
) -> Result<Vec<Self>, SynthesisError> where
    F: PrimeField
[src]

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

pub fn from_bits_le(bits: &[Boolean<F>]) -> Self[src]

Converts a little-endian byte order representation of bits into a UInt8.

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

pub fn xor(&self, other: &Self) -> Result<Self, SynthesisError>[src]

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.xor(&b)?.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());

Trait Implementations

impl<ConstraintF: Field> AllocVar<u8, ConstraintF> for UInt8<ConstraintF>[src]

impl<F: Clone + Field> Clone for UInt8<F>[src]

impl<ConstraintF: Field> CondSelectGadget<ConstraintF> for UInt8<ConstraintF>[src]

impl<F: Debug + Field> Debug for UInt8<F>[src]

impl<ConstraintF: Field> EqGadget<ConstraintF> for UInt8<ConstraintF>[src]

impl<F: Field> R1CSVar<F> for UInt8<F>[src]

type Value = u8

The type of the “native” value that Self represents in the constraint system. Read more

impl<F: Field> ToBitsGadget<F> for UInt8<F>[src]

Auto Trait Implementations

impl<F> !RefUnwindSafe for UInt8<F>

impl<F> !Send for UInt8<F>

impl<F> !Sync for UInt8<F>

impl<F> Unpin for UInt8<F>

impl<F> !UnwindSafe for UInt8<F>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,