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

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

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

Implementations

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

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

Allocates a slice of u8’s as private witnesses.

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

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

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

Allocates a new variable of type Self in the ConstraintSystem cs. The mode of allocation is decided by mode. Read more

Allocates a new constant of type Self in the ConstraintSystem cs. Read more

Allocates a new public input of type Self in the ConstraintSystem cs. Read more

Allocates a new private witness of type Self in the ConstraintSystem cs. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

If cond == &Boolean::TRUE, then this returns true_value; else, returns false_value. Read more

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

Formats the value using the given formatter. Read more

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

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

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

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

Enforce that self and other are equal. Read more

Enforce that self and other are not equal. Read more

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

Returns the underlying ConstraintSystemRef. Read more

Returns the value that is assigned to self in the underlying ConstraintSystem. Read more

Returns true if self is a circuit-generation-time constant.

Outputs the canonical little-endian bit-wise representation of self. Read more

Outputs a possibly non-unique little-endian bit-wise representation of self. Read more

Outputs the canonical big-endian bit-wise representation of self.

Outputs a possibly non-unique big-endian bit-wise representation of self. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.